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

int h,w,k;
int v[11][1001];


int f(int mask){
    int sz=__builtin_popcount(mask)+1;
    vi vv[sz];
    for(int i=0;i<sz;i++)vv[i]=vi(w,0);
    for(int i=0;i<w;i++)vv[0][i]=v[0][i];
    
    int kk=0;
    for(int i=0;i<(h-1);i++){
        if((mask&(1LL<<i))==0){
            for(int ii=0;ii<w;ii++)vv[kk][ii]+=v[i+1][ii];
        }else{
            kk++;
            for(int ii=0;ii<w;ii++)vv[kk][ii]+=v[i+1][ii];
        }
    }

    int cuts=sz-1;
    int sum[sz]={0};
    for(int i=0;i<w;i++){
        int flg=0;
        for(int j=0;j<sz;j++){
            //sum[j]=(j?sum[j-1]:0)+vv[j][i];
            //cout<<j<<" "<<i<<" "<<sum[j]<<" "<<vv[j][i]<<"\n";
            sum[j]+=vv[j][i];
            if(sum[j]>k){
                flg=1;
            }
        }
        for(int j=0;j<sz && flg;j++){
            sum[j]=vv[j][i];
            if(sum[j]>k)return INF;
            
        }
        cuts+=flg;
    }
    
//    for(int i=0;i<sz;i++){
//        for(int j=0;j<w;j++){
//            cout<<vv[i][j]<<" ";
//        }
//        cout<<"\n";
//    }
//    cout<<cuts<<"\n\n\n";
    
    return cuts;
}

signed main(){
    //FASTER;
    cin>>h>>w>>k;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            char c;cin>>c;
            v[i][j]=(c=='1');
        }
    }
    int ans=INF;
    for(int i=0;i<(1LL<<(h-1));i++){//
        ans=min(ans,f(i));
    }
    cout<<ans;
}

Measured memory_bytes: 384
#include<map>
#include<list>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define in inline
#define ri register int
using namespace std;
int a,b;
in void Negative(){
	printf("Negative");
	putchar('\n');
}
in void Positive(){
	printf("Positive");
	putchar('\n');
}
int main(){
	scanf("%d%d",&a,&b);
	if((a<=0)&&(b>=0)){//这样一定会乘0，答案是0 
		printf("Zero");
		putchar('\n');
		return ~~(0-0);//卖个萌求通过 
	}
	if(a<0){
		if((abs(a)-abs(b)+1)&1) Negative();//一个负数的绝对值就是在0和它之间有多少负数，这是求a到b之间的负数个数 
		else Positive();
	} 
	else Positive();//a和b都大于0，正数相乘是正数 
	return ~~(0-0);
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[200100];
		for(int i = 0 ; i < n ; i++) {
			a[i] = sc.nextInt();
		}
		Map<Integer, Integer> map = new HashMap<>();

		for(int i = 0 ; i < n ; i++) {
			b[a[i]]++;
		}
		Arrays.sort(b);
		Set<Integer> set = new HashSet<Integer>();
		for(int i = 0 ; i < n ; i++) {
			set.add(a[i]);
		}
		if(set.size() <= k) {
			System.out.println(0);
			return;
		}
		int size = set.size();
		long ans = 0;
		int i = 0;
		while(size > k) {
			if(b[i] != 0) {
				for(;;) {
					b[i]--;
					ans++;
					if(b[i] == 0) {
						break;
					}
				}
				size--;
			}
			i++;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 82612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N, M;
    cin >> N >> M;
    vvc<ll> G(N);
    rep(i, M) {
        ll s, t;
        cin >> s >> t;
        s--, t--;
        G[s].eb(t);
    }

    vc<ld> E(N), T(N);
    repr(i, N - 1) {
        repa(to, G[i]) E[i] += E[to], chmax(T[i], E[to]);
        E[i] /= G[i].size();
        E[i] += 1;
    }
    
    ld ans = E[0];
    vc<ld> tmpE = E;
    rep(n, N - 1) {
        if (G[n].size() <= 1) continue;
        ll gsize = G[n].size();
        tmpE[n] = ((E[n] - 1) * gsize - T[n]) / (gsize - 1) + 1;
        repr(i, n) {
            tmpE[i] = 0;
            repa(to, G[i]) tmpE[i] += tmpE[to];
            tmpE[i] /= G[i].size(), tmpE[i] += 1;
        }
        chmin(ans, tmpE[0]);
        copy(all(E), tmpE.begin());
    }

    cout << ans << endl;
}

Measured memory_bytes: 5944
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#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 X, Y, Z;
  cin >> X >> Y >> Z;
  cout << Z << ' ' << X << ' ' << Y << endl;
  return 0;
}

Measured memory_bytes: 3092
// start: 23:15
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>

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

using namespace std;

typedef pair<double, double> xy;

// 三角形の面積を求める
double triangle(double x1, double y1, double x2, double y2, double x3, double y3) {
    // 正規化（ベクトルに変換）
    // 掛け算
    // 1/2
    double  v1x = x3 - x1,
            v1y = y3 - y1,
            v2x = x2 - x1,
            v2y = y2 - y1;
    return 0.5 * abs(v1x * v2y - v1y * v2x);
}

// 多角形の面積を求める
double polygon(int edge, vector<xy> points) {
    double sum = 0.0;
    xy base = points[0];
    for ( int i = 1; i < edge - 1; i++ ) {
        xy  p1 = points[i],
            p2 = points[i+1];
        sum += triangle(base.first, base.second, p1.first, p1.second, p2.first, p2.second);
    }
    return sum;
}


int main() {
    vector<xy> ps(21);

    int i = 0;
    double x, y;

    // EOFまで入力
    while(scanf("%lf,%lf", &x, &y) != EOF) ps[i++] = make_pair(x, y);

    // 小数点6桁まで出力
    printf("%.6f\n", polygon(i, ps));

    return 0;
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()

string A, B;
int n;

const int maxn = 2005;
int l[maxn], r[maxn];

void solve(){
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            int to = (i - j + n) % n;
            if(B[to] == '1'){
                l[i] = j;
                break;
            }
        }
    }
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            int to = (i + j) % n;
            if(B[to] == '1'){
                r[i] = j;
                break;
            }
        }
    }
    int ans = 1e9;
    for(int offset = 0;offset < n;offset++){
        vector<pi> v;
        for(int i = 0;i < n;i++){
            int to = (i - offset + n) % n;
            if(A[i] != B[to]){
                v.push_back({l[i], i});
            }
        } 
        if(v.size() == 0){
            ans = min(ans, offset);
            continue;
        }
        sort(v.begin(), v.end());
        int R = 0;
        int L = max(v.back().fi, offset);
        ans = min(ans, L + L - offset + (int)v.size());
        for(int i = sz(v) - 1;i >= 0;i--){
            int id = v[i].se;
            R = max(R, r[id]);
            if(i == 0){
                L = 0;
            }else{
                L = v[i - 1].fi;
            } 
            L = max(L, offset);
            ans = min(ans, L + R * 2 + L - offset + (int)v.size());
        }
    }
    for(int offset = 0;offset < n;offset++){
        vector<pi> v;
        for(int i = 0;i < n;i++){
            int to = (i + offset) % n;
            if(A[i] != B[to]){
                v.push_back({r[i], i});
            }
        } 
        if(v.size() == 0){
            ans = min(ans, offset);
            continue;
        }
        sort(v.begin(), v.end());
        int L = 0;
        int R = max(v.back().fi, offset);
        ans = min(ans, R + R - offset + (int)v.size());
        for(int i = sz(v) - 1;i >= 0;i--){
            int id = v[i].se;
            L = max(L, l[id]);
            if(i == 0){
                R = 0;
            }else{
                R = v[i - 1].fi;
            } 
            R = max(R, offset);
            ans = min(ans, L + R * 2 + L - offset + (int)v.size());
        }
    }
    cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> A >> B;
    n = A.length();
    bool hasone = false;
    for(int i = 0;i < n;i++){
        if(B[i] == '1')
            hasone = true;
    }
    if(!hasone){
        if(A == B){
            cout << 0 << endl;
        }else{
            cout << -1 << endl;
        }
    }else{
        solve();
    }
    return 0;
}


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

bool comp(tuple<string, int,int> a, tuple<string, int,int> b){
    if(get<0>(a)!=get<0>(b)) return get<0>(a)<get<0>(b);
    else return get<1>(a)>get<1>(b);
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin>>n;

vector<tuple<string,int,int>> sp(n);
string s;
int p;

rep(i,n){
    cin>>s>>p;
    sp[i]=mt(s,p,i+1);
}
sort(sp.begin(),sp.end(),comp);

for(auto a:sp){
    cout<<get<2>(a)<<endl;
}
//system("pause");
return 0;
}


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

public class Main {
    public static void main(String args[]) throws IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String list[] = br.readLine().split(" ");
	int count = 0;
	if (list[0].equals(list[1])) {
	    count++;
	}

	if (list[1].equals(list[2])) {
	    count++;
	}

	if (list[0].equals(list[2])) {
	    count++;
	}

	if (count == 1)
	    System.out.println("Yes");
	else
	    System.out.println("No");
    }
}

Measured memory_bytes: 23124
use std::io::Read;
use std::collections::LinkedList;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iterator = buf.split_whitespace();


    let mut ll = LinkedList::new();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    for _i in 0..n {
        let command = iterator.next().unwrap();

        if command == "insert" {
            let key: u64 = iterator.next().unwrap().parse().unwrap();
            ll.push_front(key)
        } else if command == "delete" {
            let key: u64 = iterator.next().unwrap().parse().unwrap();
            let position = ll.iter().position(|&it| it == key);
            if let Some(position) = position {
                let mut tail = ll.split_off(position);
                tail.pop_front();
                ll.append(&mut tail);
            }
        } else if command == "deleteFirst" {
            ll.pop_front();
        } else if command == "deleteLast" {
            ll.pop_back();
        }
    }

    let mut result = String::new();
    for k in ll {
        result += &format!("{} ", k);
    }

    println!("{}", result.trim());
}



Measured memory_bytes: 62260
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    string A, L = "", R = "";
    int Q;
    cin >> A >> Q;

    int cnt = 0;
    rep(i, Q) {
        int q;
        cin >> q;
        if (q == 1) cnt = (cnt + 1) % 2;
        else {
            int f;
            string c;
            cin >> f >> c;
            if (f == 1) {
                if (cnt) {
                    R += c;
                }
                else {
                    string tmp = c + L;
                    L = tmp;
                }
            }
            else {
                if (cnt) {
                    string tmp = c + L;
                    L = tmp;
                }
                else {
                    R += c;
                }
            }
        }
    }

    string ans = "";
    if (cnt) {
        reverse(all(R));
        reverse(all(A));
        reverse(all(L));
        ans += R + A + L;
    }
    else ans += L + A + R;

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4424
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=(a);i<=(b);++i)
#define rep(i,n) rep2(i,0,n-1)
int INF=1000000000;

using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");
main(){
    int n;
    cin>>n;
    char s[n][n];
    rep(i,n){
        rep(j,n){
            cin>>s[i][j];
        }
    }
    int ans=0;
    rep2(i,-n,n){
        bool flag=0;
            rep(k1,n){
                rep(k2,n){
                    int a=(k2+i+n)%n,b=(k1-i+n)%n;
                    if(s[k1][k2]!=s[a][b])
                    {flag=1; break;}
                }
                if(flag)break;

            }
            if(!flag) ans+=n-abs(i);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define rFORe(i, a, n) for(int (i) = (int)(n); (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 1, (n))
#define REPo(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rREPe(i, n) rFORe((i), 1, (n))
#define rREPo(i, n) rFORe((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define vc(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

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

int main() {
  int k, a, b;
  cin >> k >> a >> b;
  if (a <= b/k*k) cout << "OK" << endl;
  else cout << "NG" << endl;

  return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<deque>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvi;

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n); i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define toLower(c)  c+0x20
#define toUpper(c)  c-0x20
#define pb  push_back
#define eb  emplace_back

const int INF = 1e9;
const long long LLINF = 1e18;
const int MOD = 1000000007;

int main(){
  float n;  cin >> n;
  cout << ((int)n%2==1 ? (n+1)/2/n : n/2/n) << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

  if(n==100)n += 1;

  switch (d){
  case 0:
    cout << n << endl;
    break;
  case 1:
    cout << n*100 << endl;
    break;
  case 2:
    cout << n*10000 << endl;
    break;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>

#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1844674407370955161
typedef long long unsigned int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

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

template<typename T>
T lcm(T a,T b){
	T g = gcd(a, b);
	return a * b / g;
}

void clear( std::queue<pair<int,int> > &q )
{
   std::queue<pair<int,int> > empty;
   std::swap( q, empty );
}
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
template<typename T>
std::vector<T> enum_div(T n)//nの約数を列挙
{
	std::vector<T> ret;
	for(T i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}


class DisjointSet{
    public:
        vector<int> rank, p;

        DisjointSet(){
        }

        DisjointSet(int size){
            rank.resize(size, 0);
            p.resize(size, 0);
            for (int i = 0; i < size;i++){
                makeSet(i);
            }
        }
        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
        }

        bool same(int x,int y){
            return findSet(x) == findSet(y);
        }
        void unite(int x,int y){
            link(findSet(x), findSet(y));
        }
        void link(int x,int y){
            if(rank[x]>rank[y]){
                p[y] = x;
            }else{
                p[x] = y;
                if(rank[x]==rank[y]){
                    rank[y]++;
                }
            }
        }
        int findSet(int x){
            if(x!=p[x]){
                p[x] = findSet(p[x]);
            }
            return p[x];
        }
};

int main()
{
  int N,M;
  cin >> N>>M;
  int out[N+1];
  REP(i,0,N+1){
    out[i] = 0;
  }
  int a[M];
  REP(i,0,M){
    cin >> a[i];
    out[a[i]] = 1;
  }
  ll dp[N+1];
  REP(i,0,N+1){
    dp[i] = 0;
  }
  dp[0] = 1;
  if(out[1]==1){
    dp[1] = 0;
  }else{
    dp[1] = 1;
  }

  REP(i, 2, N+1)
  {
    if(out[i]!=1){
      dp[i] = dp[i - 1]%MOD + dp[i - 2]%MOD;
      dp[i] %= MOD;
    }
  }

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

Measured memory_bytes: 1792
//#include <cstdio>
#include <iostream>

#include <cstring>

#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cassert>

using namespace std;

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

struct Edge {
   int u, v;
   int color;
   int other(int x) const {
      return x == u ? v : u;
   }
};

vector<Edge> edges;
VVI tree;

void dfs(int u, int p = -1, int pcol = 0) {
   int k = 0;
   for (int eid : tree[u]) {
      Edge& e = edges[eid];
      int v = e.other(u);
      if (v == p) continue;
      do k++; while (k == pcol);
      e.color = k;
   }
   for (int eid : tree[u]) {
      Edge& e = edges[eid];
      int v = e.other(u);
      if (v == p) continue;
      dfs(v, u, e.color);
   }
}

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   int N;
   cin >> N;
   tree = VVI(N);
   for (int j = 1; j < N; ++j) {
      int u, v;
      cin >> u >> v;
      --u, --v;
      int eid = edges.size();
      edges.push_back({u, v, 0});
      tree[u].push_back(eid);
      tree[v].push_back(eid);
   }

   dfs(0);
   int max_colors = 0;
   for (Edge e : edges)
      max_colors = max(max_colors, e.color);

   cout << max_colors << '\n';
   for (Edge e : edges)
      cout << e.color << '\n';

   return 0;
}


Measured memory_bytes: 7220
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <string.h>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i > 0; i--)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t int64;

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

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

using namespace std;


class D {
	int64 n;
public:
	D()
	{
		cin >> n;
	}
	void solve()
	{
		if (n == 1)
		{
			cout << 0 << endl;
		}
		else
		{
			cout << ((n) * (n - 1) / 2) << endl;
		}
	}
};


int main()
{
	D solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

def main():
    X, Y, Z, K = map(int, readline().rstrip().split())
    A = list(map(int, readline().rstrip().split()))
    B = list(map(int, readline().rstrip().split()))
    C = list(map(int, readline().rstrip().split()))

    ab = [a + b for a in A for b in B]
    ab = sorted(ab, reverse=True)[:K]

    abc = [v + c for v in ab for c in C]
    print(*sorted(abc, reverse=True)[:K], sep='\n')


if __name__ == '__main__':
    main()

Measured memory_bytes: 139260
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a = 0;
	int maxsss = 0;
	string s;
	cin >> s;
	for (int i = 0; i < s.size();i++) {
		if (s.at(i)=='A'|| s.at(i) == 'C'|| s.at(i) == 'G'|| s.at(i) == 'T') {a++;}
		else {a = 0;}
		maxsss = max(maxsss, a);
	}
	cout << maxsss << endl;
}

Measured memory_bytes: 256
let change n m d =
  let dp = Array.make_matrix (m + 1) (n + 1) max_int in
  for i = 0 to m do dp.(i).(0) <- 0 done;
  for i = 1 to m do
    for j = 1 to n do
      dp.(i).(j) <-
        if j >= d.(i-1) && dp.(i).(j - d.(i-1)) + 1 < dp.(i-1).(j)
        then dp.(i).(j - d.(i-1)) + 1
        else dp.(i-1).(j);
    done
  done;
  dp.(m).(n)

let () =
  let (n, m) = Scanf.scanf "%d %d " (fun n m -> (n, m)) in
  let d = Array.init m (fun _ -> Scanf.scanf "%d " (fun i -> i)) in
  change n m d |> Printf.printf "%d\n"

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

int main(){
  char **data, **data2;//data=bubble data2=selection
  char sub[3];
  int num, i, j, flag=1 ,judge=0;

  //input data
  scanf("%d",&num);
  data=(char **)malloc(sizeof(char *)*num);
  data2=(char **)malloc(sizeof(char *)*num);
  for(i=0;i<num;i++){
    data[i]=(char *)malloc(sizeof(char)*3);
    data2[i]=(char *)malloc(sizeof(char)*3);
    scanf("%s",data[i]);
  }

  //copy data to data2
  for(i=0;i<num;i++){
    for(j=0;j<3;j++) data2[i][j]=data[i][j];
  }
  


  

  //bubble sort
  while(flag==1){//flag==1 sort is not finish
    flag=0;

    for(i=num-1;i>0;i--){
      if(data[i][1]<data[i-1][1]){
	//data[i][1]<->data[i-1][1]
	strcpy(sub,data[i]);
	strcpy(data[i],data[i-1]);
	strcpy(data[i-1],sub);

	flag=1;

	//same number change judge
	if(data[i][1]==data[i-1][1]) judge=1;
      }
      
    }
    
  }

  //output bubble sort result
  for(i=0;i<num-1;i++) printf("%s ",data[i]);
  printf("%s\n",data[i]);

  //output judge result
  if(judge==0) printf("Stable\n");//bubble sort is always stable sort
  else printf("Not stable\n");



  

 
  //selection sort
  for(i=0;i<num;i++){
    flag=i;

    for(j=i;j<num;j++) //search minimum data(=data2[flag])
      if(data2[j][1]<data2[flag][1]) flag=j;
	

    if(flag!=i){
      //data2[i][1]<->data2[flag][1]
      strcpy(sub,data2[i]);
      strcpy(data2[i],data2[flag]);
      strcpy(data2[flag],sub);
      
    }
    
  }

  //output selection sort result
  for(i=0;i<num-1;i++) printf("%s ",data2[i]);
  printf("%s\n",data2[i]);


  judge=0;//reflesh judge
  
  //judge stable sort(compair bubble sort result)
  for(i=0;i<num;i++){
    if(strcmp(data[i],data2[i])!=0) judge=1;
  }

  //output judge result
  if(judge==0) printf("Stable\n");//slection sort is not always stable sort
  else printf("Not stable\n");

  for(i=0;i<num;i++){
    free(data[i]);
    free(data2[i]);
  }
  free(data);
  free(data2);
  
  return 0;
}



Measured memory_bytes: 2100
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
  string s;
  vector<int> alpha(26);
  while (cin >> s) {
    rep(i, s.size()) {
      char c = s[i];
      if ('a' <= c && c <= 'z')
        alpha[c - 'a']++;
      if ('A' <= c && c <= 'Z')
        alpha[c - 'A']++;
    }
  }

  rep(i, alpha.size()) cout << char(i + 'a') << " : " << alpha[i] << endl;
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll=long long ;
int main()
{
    int n;
    cin>>n;
    vector<int> a(n),b(n);
    rep(i,n) cin>>a[i];
    b=a;
    sort(b.begin(),b.end());
    rep(i,n){
        if(a[i]==b[n-1]) cout<<b[n-2]<<endl;
        else cout<<b[n-1]<<endl;
    }
}

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

long long gcd(long long a, long long b){
  if(a%b == 0) return b;
  return gcd(b, a%b);
}

int main(){
  int n;
  cin >> n;
  double ans, res=0;
  for(int i=0; i<n; i++){
    double a;
    cin >> a;
    res += 1.0/a;
  }
  ans = 1.0/res;
  cout << ans << endl;
  return 0;
}


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

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] input = br.readLine().split(" ");
        int a = Integer.parseInt(input[0]);
        int b = Integer.parseInt(input[1]);
        int c = Integer.parseInt(input[2]);
        int d = Integer.parseInt(input[3]);
        if(Math.abs(a-c) <= d || (Math.abs(a-b) <= d && Math.abs(b-c) <= d)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21204
#include <stdio.h>
int main()
{
    char w1[4];
    char h1[4];
    // 初期化
    memset( w1, 0x00, sizeof(w1) );
    memset( h1, 0x00, sizeof(h1) );

    // 文字列受取
    scanf("%255s %255s", w1, h1);

    // 数値変換
    int w = atol(w1);
    int h = atol(h1);

    int y1 = w * h;
    int y2 = (w+h) << 1;

    // 答え表示
    printf( "%d %d\n", y1, y2 );
}



Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
#define trace1(a) cout << a << 'n';
#define trace2(a, b) cout << a << ' ' << b << 'n';
#define trace3(a, b, c) cout << a << ' ' << b << ' ' << c << 'n';
#define trace4(a, b, c, d) cout << a << ' ' << b << ' ' << c << ' ' << d << 'n';
#define trace5(a, b, c, d, e) cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << 'n';
#define trace6(a, b, c, d, e, f) cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << ' ' << f << 'n';
#define range(n) for(int i = 0; i < n; i++)
#define printArr(harry, tam) range(tam) cout << harry[i] << " n"[i == tam -1];
#define maxn -2000000 //negative value to break code and force you to put right constraint
#define mod 1000000007
#define md(x) (x) % mod;
#define sc scanf
#define pr printf
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ps push
#define prt(x) cout << (#x) << " is " << (x) << endl
#define EPS 1e-9
#define INF 1000000000
#define INFd 1e9
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<double> vd;
int arr[60][60];
bool visit[60][60];
int dist[60][60];
int n,m;
bool is(int x,int y)
{
    if(arr[x][y]==0||x<0||x>=n||y<0||y>=m)
      return false;
    return true;
}
void bfs(int x,int y)
{
    visit[x][y]=true;
    queue<pair<int,int>> q;
    q.push(mp(x,y));
    dist[x][y]=0;
    while(!q.empty())
    {
        pair<int,int>node=q.front();
        q.pop();
          x=node.fi;
           y=node.se;
           if(!visit[x+1][y]&&is(x+1,y))
           {
             q.push(mp(x+1,y));
             visit[x+1][y]=true;
             dist[x+1][y]=dist[x][y]+1;
             
           }
           if(!visit[x][y-1]&&is(x,y-1))
           {
             q.push(mp(x,y-1));
             visit[x][y-1]=true;
              dist[x][y-1]=dist[x][y]+1;
             
           }
           if(!visit[x][y+1]&&is(x,y+1))
           {
             q.push(mp(x,y+1));
             visit[x][y+1]=true;
              dist[x][y+1]=dist[x][y]+1;
           }
           if(!visit[x-1][y]&&is(x-1,y))
           {
             q.push(mp(x-1,y));
             visit[x-1][y]=true;
              dist[x-1][y]=dist[x][y]+1;
           }
    }
}
int main()
{
  
  for(int i=0;i<60;i++)
	for(int j=0;j<60;j++)
		dist[i][j]=INF;
  memset(visit,false,sizeof visit);
  cin>>n>>m;
  ll cnt=0;
 
  for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
           char ch;
           cin>>ch;
           if(ch=='#'){
             arr[i][j]=0;cnt++;}
            else
              arr[i][j]=1;
        }
    }
    bfs(0,0);
    if(dist[n-1][m-1]==INF)
        cout<<-1;
    else
    {
        cout<<n*m-dist[n-1][m-1]-1-cnt;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int   //used int to avoid mle
#define ulli unsigned long long int 
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define spl set<pll>
#define msl multiset <lli>
#define msp multiset <pll>
#define pll pair<lli, lli>
#define mll map<lli, lli>              //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x)
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define fbo find_by_order //returns iterator
#define fok order_of_key //return index
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
lli mod=998244353;
//string s=bitset<32>(n).to_string();
typedef tree<lli,null_type,less<lli>,rb_tree_tag, // change both to lli if set is req insted of multiset
tree_order_statistics_node_update> indexed_set;
lli power(lli x, lli y, lli p)   
{  
    lli res = 1;     // Initialize result  ! 
    x = x % p; // Update x if it is more than or  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
} 

int main()
{
	lli k,n;
	cin>>k>>n;
	lli a[n];
	for(lli i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	lli temp=0;
	for(lli i=0;i<n-1;i++)temp=max(temp,a[i+1]-a[i]);
	cout<<min(k-temp,a[n-1]-a[0]);
	
	
	
	
	
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main()
  {int N, S{}; cin >> N;
  vector<pair<string, int>> ps(N); for (auto &[s, t] : ps) {cin >> s >> t; S += t;}
  string X; cin >> X; for (auto [s, t] : ps) {S -= t; if (s == X) break;}
  cout << S;}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int d;
  cin >> d;
  vector<int> c(26);
  int i,j,k;
  rep(i,26) cin >> c[i];
  vector<vector<int>> s(d,vector<int>(26));
  rep(i,d)rep(j,26) cin >> s[i][j]; 
  vector<int> t(d);
  /*rep(i,d)
  {
    int ind = -1;
    int val = -1;
    rep(j,26)
    {
      if(s[i][j] > val)
      {
        val = s[i][j];
        ind = j;
      }
    }
    t[i] = ind;
  }*/
  vector<int> las(26,0);
  vector<int> rowans(26,0);
  int sums = 0;
  int kans = 0;
  rep(i,d)
  {
    int vind = -1;
    int vval = -100000000;
    rep(j,26)
    {
      vector<int> klas(26);
      klas = las;
      klas[j] = i+1;
      sums += s[i][j];
      vector<int> krowans(26);
      krowans = rowans;
      rep(k,26)
      {
        krowans[k] += c[k]*(i+1-klas[k]);
      }
      int ks = sums;
      rep(k,26) ks -= krowans[k];
      if(vval < ks)
      {
        vval = ks;
        vind = j;
      }
      sums -= s[i][j];
    }
    t[i] = vind;
    las[t[i]] = i+1;
    sums += s[i][t[i]];
    kans += s[i][t[i]];
    rep(j,26)
    {
      kans -= c[j]*(i+1-las[j]);
      rowans[j] += c[j]*(i+1-las[j]);
    }
  }
  //int m = 100000;
  /*
  double tmp = 100000000.0;
  double alpha = 0.9999;
  int inds = 0;
  while(tmp >= 0.01)
  {
    inds++;
    int tans = 0;
    int tod,q;
    tod = rand()%d;
    q = rand()%26;
    int bq = t[tod];
    sums -= s[tod][bq];
    sums += s[tod][q];
    int browq = rowans[bq];
    int rowq = rowans[q];
    t[tod] = q; //change
    rowans[q] = 0;
    rowans[bq] = 0;
    rep(j,26)
    {
      las[j] = 0;
    }
    rep(j,d)
    {
      las[t[j]] = j+1;
      rowans[bq] += c[bq]*(j+1-las[bq]);
      rowans[q] += c[q]*(j+1-las[q]);
    }
    tans = sums;
    rep(j,26) tans -= rowans[j];
    double prob = ((double)rand())/32767.0;
    int dis = kans-tans;
    if(tans >= kans)
    {
      kans = tans;
    }
    else if(prob <= exp(-(double)dis/(double)tmp))
    {
      kans = tans;
      //if(inds%1000 == 0)cout << kans << ' ' << tmp << endl;
    }
    else
    {
      rowans[bq] = browq;
      rowans[q] = rowq;
      t[tod] = bq;
    }
    tmp *= alpha;
    //cout << tmp << endl;
  }*/
  rep(i,d)
  {
    cout << t[i]+1 << "\n";
  }
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define SE second
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define mp make_pair
#define ll long long
#define LLI long long int
#define REP(i,a,b) for(long long i=a;i<b;i++)
#define PER(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define Arrays(a, size) sort((a), (a)+(size))
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
using namespace std;

int _dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
int _dy[] = { 0, 1, 0, -1, 1, -1, 1, -1 };

ll a[100001];
//vector<int> a;
ll n,m;
int main(){
    cin>>n>>m;
    for(ll i=0;i<m;i++){
        ll r,l;
        cin>>r>>l;
        a[r-1]+=1;
        a[l]-=1;
    }
    ll sum=0;
    ll temp=0;
    for(ll i=0;i<n;i++){
        temp+=a[i];
        if(temp==m)sum++;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
int main(void){
	int n,m,i,ans=0;
	cin>>n>>m;
	int x[m],sa[m-1];
	for(i=0;i<m;i++)cin>>x[i];
	sort(x,x+m);
	for(i=1;i<m;i++)sa[i-1]=x[i]-x[i-1];
	sort(sa,sa+m-1);
	for(i=0;i<m-n;i++)ans+=sa[i];
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def modpow(a, n, mod):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n >>= 1
    return res


def modinv(a, mod):
    return modpow(a, mod - 2, mod)


def main():
    x, y = map(int, input().split())
    if (2 * y - x) % 3 != 0 or  (2 * x - y) % 3 != 0 or (2 * x - y) < 0 or (2 * y - x)  < 0:
        print(0)
        exit()
    p = (2 * y - x) // 3
    q = (2 * x - y) // 3
    
    ans = 1
    for i in range(1, p + q + 1):
        ans = (ans * i) % MOD
    
    v,z=1,1
    for i in range(1, p + 1):
        v = (v * i) % MOD
        
    for i in range(1, q + 1):
        z = (z * i) % MOD
    
    vz = (v*z)%MOD
    ans = ans*modinv(vz,MOD) % MOD
    print(ans)



if __name__ == '__main__':
    main()


Measured memory_bytes: 72300
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include<queue>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;
typedef pair<int, int> P;
const ll INF = ll(1e18)+1;

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

   ll ans = INF;
   for(int p = 1; p <= 100; p++){
      ll sum = 0;
      for(int i = 0; i < n; i++){
         sum += pow(x[i]-p, 2);
      }
      ans = min(ans, sum);
   }
   cout << ans << endl;
   return 0;
}


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

int main() {
	int N;
	int L;
	int abs_min = 999;
	int b = 0;
	int ans = 0;
	cin >> N >> L;
	vector <int> a(N + 1);

	//if (L < 0 && N + L > 0) {
	//	cout << 0 << endl;
	//	return 0;
	//}

	for (int i = 1; i <= N; i++) {
		a.at(i) = L + i - 1;
		ans += a.at(i);
		if (abs_min > abs(a.at(i))) {
			abs_min =abs(a.at(i));
			b = i;
		}
	}

	cout << ans - a.at(b) << endl;


	return 0;
}

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

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define PB push_back
typedef long long ll;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	int ans = 0;
	int tmp;
	vector <int> a;
	cin >> n;
	rep(i, 0, n){
		cin >> tmp;
		a.PB(tmp);
	}
	rep(i, 0, n){
		if (a[a[i] - 1] - 1 == i)ans++;
	}
	ans /= 2;
	cout << ans << endl;



	return 0;
}


Measured memory_bytes: 892
#include <algorithm>
#include <iostream>

using namespace std;

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

  int ans = 1111111111;
  for (int f = 0; f <= 1; f++) {
    bool n = (bool)f;
    int tmp = 0;
    for (int i = 0; i < s.size(); i++) {
      if (n != (bool)(s[i] - '0')) {
        tmp++;
        // cout << f << ":" << i << "," << s[i] << " " << n << ","
        //      << (bool)(s[i] - '0') << endl;
      }
      n = !n;
    }
    ans = min(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
	string s;
	cin>>s;
	int i=0,left=s.size()-1;
	int cnt=0;
	bool ok=true;
	while(left>i){
		//cout<<"#"<<s[i]<<" "<<s[left]<<" "<<i<<" "<<left<<endl;
		bool done=false;
		if(s[i]==s[left]){
			i++;
			left--;	
			done=true;
		}
		else if(s[i]=='x'){
			cnt++;
			i++;
			done=true;
		}
		else if(s[left]=='x'){
			cnt++;
			left--;
			done=true;
		}
		if(done==false){
			ok=false;
			break;
		}
	}
	if(ok)cout<<cnt<<endl;
	else cout<<"-1"<<endl;
	return 0;
}


Measured memory_bytes: 512
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

int dp[100001][101][2];

int main(){
  string s; int m; cin >> s >> m;
  int n=s.size();
  dp[0][0][0]=1;
  rep(i,n)rep(j,m)rep(k,2){
    int nd=s[i]-'0';
    int nk;
    rep(d,10){
      int nj=(j+d)%m;
      if(d>nd){
        if(k==0) continue;
        if(k==1) nk=1;
      }
      if(d==nd){
        if(k==0) nk=0;
        if(k==1) nk=1;
      }
      if(d<nd) nk=1;
      dp[i+1][nj][nk]+=dp[i][j][k];
      dp[i+1][nj][nk]%=mod;
    }
  }
  ll ans=dp[n][0][0]+dp[n][0][1];
  ans--;
  if(ans<0) ans+=mod;
  cout << ans << endl;
}

Measured memory_bytes: 8448
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "{ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "}";

    return os;
}

ll pow_mod(ll a, ll p) {
    ll res = 1;
    while(p) {
        if (p & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        p >>= 1;
    }

    return res;
}


ll mod_inv(ll a, ll m) {
    ll b = m, u = 0, v = 1;
    while(a) {
        ll t = b / a;
        swap(b -= t * a, a);
        swap(u -= t * v, v);
    }

    return (u % m + m) % m;
}

ll gcd(ll a, ll b) {
    if(b == 0) return a;
    return gcd(b, a%b);
}

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#ifdef LOCAL
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

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

    string N;
    cin >> N;
    reverse(N.begin(), N.end());

    int M = N.size();
    ll c0 = 0, c1 = 10;

    REP(i, M) {
        int s = N[i] - '0';

        ll c00 = min(c0 + s, c1 + s + 1);

        ll c11 = min(c0 + 10 - s, c1 + 10 - s - 1);

        c0 = c00;
        c1 = c11;
    }

    cout << min(c0, c1 + 1) << endl;

}


Measured memory_bytes: 1948
loop do
  n, m = gets.split.map(&:to_i)
  break if (n + m).zero?
  
  scene   = n.times.map {gets.split.map(&:to_i)}
  picture = m.times.map {gets.split.map(&:to_i)}
  
  pictures = []
  4.times do
    pictures << picture 
    picture = picture.reverse.transpose    #右回転
  end
  
  check = ->{
    result = []
    (0..n - m).each do |y|
      (0..n - m).each do |x|
        pictures.each do |pic|
          catch :jump {
            nx = ny = nil
            m.times do |dy|
              m.times do |dx|
                next if pic[dy][dx] == -1
                nx, ny = x + dx, y + dy unless nx
                throw :jump if pic[dy][dx] != scene[y + dy][x + dx]
              end
            end
            result << [nx + 1, ny + 1]
          }
        end
      end
      return result unless result.empty?
    end
    "NA"
  }
  result = check.()
  
  if result != "NA"
    result = result.sort! {|a, b| (a[1] <=> b[1]).nonzero? || a[0] <=> b[0]}[0].join(" ")
  end
  puts result
end


Measured memory_bytes: 7476
#include<stdio.h>

int main(void)
{
        int i,j,max,tmp,index,sum;
        int n,k;

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

        int l[n];
        for(i=0;i<n;i++)
                scanf("%d",&l[i]);


        for(i=0;i<n-1;i++){
                max = l[i];
                for(j=i+1;j<n;j++){
                        if(max<l[j]){
                                max = l[j];
                                index = j;
                        }
                }
                if(max>l[i]){
                        tmp = l[i];
                        l[i] = max;
                        l[index] = tmp;
                }
        }


        sum = 0;
        for(i=0;i<k;i++){
                sum += l[i];
        }

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

        return 0;
}


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

int main() {
    int n, m;
    while (cin >> n >> m, n | m) {
        int a[n];
        for (int i = 0; i < n; i++) cin >> a[i];
        int f = 1, ans = -1;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                if (a[i] + a[j] <= m) {
                    ans = max(ans, a[i] + a[j]);
                    f = 0;
                }
            }
        }
        if (f)
            cout << "NONE" << endl;
        else 
            cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3044
import java.util.*;

public class Main {
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Set<String> set = new HashSet<>();
	    
		for (int i = 0; i < N; ++i) {
    	   set.add(sc.next());
		}
		
		System.out.println(set.size());
	}
}

Measured memory_bytes: 78372