akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
    if(s=="SAT"){
        cout<<1;
    }
    else if(s=="MON"){
        cout<<6;
    }
    else if(s=="TUE"){
        cout<<5;
    }
    else if(s=="WED"){
        cout<<4;
    }
    else if(s=="THU"){
        cout<<3;
    }
    else if(s=="FRI"){
        cout<<2;
    }
    else if(s=="SUN"){
        cout<<7;
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;
char v[55][55];
int main() {
    int h,w;
    scanf("%d%d",&h,&w);
    for(int i=1;i<=h;i++)
        scanf("%s",v[i]+1);
    bool f=true;
    for(int i=1;i<=h;i++)
        for(int j=1;j<=w;j++)
            if(v[i][j]=='#'&&v[i+1][j]!='#'&&v[i-1][j]!='#'&&v[i][j+1]!='#'&&v[i][j-1]!='#')
                f=false;
    printf("%s\n",f?"Yes":"No");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>
#include <stack>

using namespace std;
const long long P = 1000000007;

vector<long long> vc;

int main() {
  string s;
  cin >> s;
  int a = count(s.begin(),s.end(),'a');
  int b = count(s.begin(),s.end(),'b');
  int c = count(s.begin(),s.end(),'c');
  if(abs(a-b) >= 2 || abs(b-c) >= 2 || abs(c-a) >= 2) {
    cout << "NO" << endl;
  }else {
    cout << "YES" << endl;
  }
  return 0;
}


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

int main(){

string s;
cin >> s;

int count =0;
rep(i,s.size()){
  if(i%2==0 and s.at(i)=='L'){
    count++;
    break;
  }
  else if (i%2==1 and s.at(i)=='R'){
    count++;
    break;
  }
}

if(count ==0 )cout << "Yes" << endl;
else cout << "No" << endl;
return 0;

}

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

int main(void) {
  int N;
  cin >> N;
  vector<long long> x(N);
  vector<long long> y(N);
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i];
  }

  int ans = N;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i == j) continue;
      int cost = N;
      long long p = x[i] - x[j];
      long long q = y[i] - y[j];
      for (int k = 0; k < N; k++) {
        for (int l = 0; l < N; l++) {
          if (x[l] - x[k] == p && y[l] - y[k] == q) {
            cost--;
          }
        }
      }
      ans = min(cost, ans);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;


void Main(){
    ll N, a;
    sll(N);
    vector<ll> xs(N,0);
    rep(i, N){
        sll(a);
        xs[i] = a;
    }

    sort(xs.begin(), xs.end());
    ll ans = 100000000000000;
    rep(i, 101){
        ll dist = 0;
        rep(j, N){
            dist += (i-xs[j]) * (i-xs[j]);
        }
        ans = min(ans, dist);
    }

    cout << ans <<endl;

}

int main(){
    Main();
}

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

int main()
{
    // int x = 0;
    int N;
    cin >> N;
    string S;
    cin >> S;
    //   int N = S.size();
    vector<int> X(N + 1);
    X[0] = 0;
    rep(i, N)
    {
        if (S[i] == 'I')
            X[i + 1] = X[i] + 1;
        else
            X[i + 1] = X[i] - 1;
    }
    sort(X.rbegin(), X.rend());
    cout << X[0] << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        UnionFind uf = new UnionFind(n);
        
        int[][] xy = new int[m][2];
        for (int i = 0; i < m; i++) {
            int x = sc.nextInt() - 1;
            int y = sc.nextInt() - 1;
            xy[i][0] = x;
            xy[i][1] = y;
        }
        
        int[] size = new int[n];
        Arrays.fill(size, 1);
        long[] answer = new long[m];
        answer[m - 1] = (long)n * (n - 1) / 2;
        
        for (int i = m - 1; i > 0 ; i--) {
            int x = xy[i][0];
            int y = xy[i][1];
            if (uf.same(x, y)) {
                answer[i - 1] = answer[i];
                continue;
            }
            
            int rx = uf.root(x);
            int ry = uf.root(y);
            answer[i - 1] = answer[i] - size[rx] * size[ry];
            int sizex = size[rx];
            int sizey = size[ry];
            size[rx] += sizey;
            size[ry] += sizex;
            uf.unite(x, y);
        }
        
        for (long a : answer) {
            System.out.println(a);
        }
    }
    
    public static class UnionFind {
        int[] par;
        int connectedComponent;
    
        UnionFind(int n) {
            par = new int[n];
            connectedComponent = n;
            for (int i = 0; i < n; i++) {
                par[i] = i;
            }
        }
    
        int root(int x) {
            if (par[x] == x) return x;
            return par[x] = root(par[x]);
            // 1-2-4の場合、4の親=2を4の根=1に繋ぎ変えた上で親を返す
            // ↑根まで辿る深さを減らす為
            // return a = b;とは、aにbを代入し、aを返すという意味
        }
    
        void unite(int x, int y) {
            int rx = root(x);
            int ry = root(y);
            if (rx != ry) {
                par[ry] = rx;
                connectedComponent--;
            }
        }
    
        boolean same(int x, int y) {
            int rx = root(x);
            int ry = root(y);
            return rx == ry;
        }
        
        void printPar() {
            System.out.println(Arrays.toString(par));
        }
    }
}

Measured memory_bytes: 98988
function Main(input) {
    input = input.split("\n");
    const n = input[0];
    let array = [];
    for(let i = 0; i < n; i++ ){
        array[i] = input[i+1];
    }

    let c0 = 0 ,c1 = 0 ,c2 = 0 ,c3 = 0;

    for(let i = 0; i < n; i++ ){
        if(array[i] === 'AC'){
            c0++;
        }
        if(array[i] === 'WA'){
            c1++;
        }
        if(array[i] === 'TLE'){
            c2++;
        }
        if(array[i] === 'RE'){
            c3++;
        }
    }

    console.log('AC x ' + c0);
    console.log('WA x ' + c1);
    console.log('TLE x ' + c2);
    console.log('RE x ' + c3);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

const int MOD = 1000000007;
const int INF = 1000000000;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

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

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}

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 A, B;
  cin >> A >> B;
  int ans = 0;
  REP(i, A) ans += i;
  REP(i, B) ans += i;
  print(ans);
  return 0;
}


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

#define int long long
const int mod = 1e9 + 7, N = 2005;
int n, dp[N], s;

int solve(int sum) {
    if (sum > s) return 0;
    if (sum == s) return 1;
    int res = 0, &ans = dp[sum];
    if (~ans) return ans;
    for (int i = 3; i <= s; i++) {
        res += (solve(sum + i));
        res %= mod;
    }
    return ans = res;
}
int32_t main() {
    for (int i = 0; i < N; i++) {
        dp[i] = -1;
    }
    cin >> s;
    cout << solve(0);
}


Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <iterator>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    if(a<=c&&c<=b)cout<<"Yes";else cout<<"No";
}


Measured memory_bytes: 256
n = gets.to_i
h = gets.split.map(&:to_i)
dp = Array.new(n, 0)
dp[1] = (h[1] - h[0]).abs
2.upto(n - 1) do |i|
  if (dp[i - 1] + (h[i] - h[i - 1]).abs) < (dp[i - 2] + (h[i] - h[i - 2]).abs)
    dp[i] = dp[i - 1] + (h[i] - h[i - 1]).abs
  else
    dp[i] = dp[i - 2] + (h[i] - h[i - 2]).abs
  end
end
puts dp[n - 1]

Measured memory_bytes: 8844
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
int dp[10005],n,w,a[205];
int main(){
    cin >> n >> w;
    for(int i=1;i<=n;i++) cin >> a[i];
    sort(a+1,a+n+1);
    int res = 0,sum = 0;
    for(int i=1;i<=n&&sum<=w;i++){
        memset(dp,0,sizeof(dp));
        dp[sum] = 1;
        for(int j=i+1;j<=n;j++){
            for(int k=w-a[j];k>=sum;k--){
                if(dp[k]){
                    dp[k+a[j]] += dp[k];
                    if(dp[k+a[j]] >= mod) dp[k+a[j]]-=mod;
                }
            }
        }
        for(int j=max(0,w-a[i]+1);j<=w;j++) res = (res+dp[j])%mod;
        sum += a[i];
    }
    if(sum <= w) res++;
    cout << (res%mod) << endl;
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(ll i = 0;i < n;i++) cin >> a[i];
    
    ll q;
    cin >> q;
    
    for(ll i = 0;i < q;i++){
        ll k;
        cin >> k;
        
        cout << equal_range(a.begin(), a.end(), k).first - a.begin() << ' ' <<  equal_range(a.begin(), a.end(), k).second - a.begin() << endl;
    }
}


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

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

	vector<int> a(n);
	vector<int> b(n);
	vector<int> c(m);
	vector<int> d(m);
	for(int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	for(int i = 0; i < m; i++) {
		cin >> c[i] >> d[i];
	}
	for(int i = 0; i < n; i++) {
		int tmp = (1E8) * 5;
      	int count = 100;
		for(int j = 0; j < m; j++) {
			if((abs(a[i] - c[j]) + abs(b[i] - d[j])) < tmp)
			{
              tmp = abs(a[i] - c[j]) + abs(b[i] - d[j]);
              count = j;
			}
		}
		cout << count + 1 << endl;
	}
}


Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n,t;
	std::cin >> n >> t;
	std::vector<int> a(n);
	rep(i,n) std::cin >> a[i];
	int sum = 0;
	int start=0;int end=t;
	rep(i,n) {
		if(a[i]<=end) {
			end=a[i]+t;
		} else {
			sum+=end-start;
			start=a[i];
			end=a[i]+t;
		}
	}
	sum+=end-start;
	print(sum);

	return 0;
}


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

typedef long long ll;

ll N;
map<pair<ll, ll>, pair<ll, ll>> C;
ll X;
const ll MOD = 1000000007;
vector<ll> Pow;
ll Res;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
  cin >> N;
  for (ll i = 0; i < N; ++i) {
    ll a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      ++X;
      continue;
    }
    if (b < 0 || (a < 0 && b == 0)) {
      a *= -1;
      b *= -1;
    }
    bool reg = a <= 0;
    if (reg) {
      ll oldb = b;
      b = -a;
      a = oldb;
    }
    ll g = gcd(a, b);
    a /= g;
    b /= g;
    ++(reg ? C[{a, b}].first : C[{a, b}].second);
  }
  Res = 1;
  Pow.resize(N + 1);
  Pow[0] = 1;
  for (ll i = 1; i <= N; ++i) Pow[i] = 2 * Pow[i - 1] % MOD;
  for (auto abmn : C) {
    ll m, n;
    tie(m, n) = abmn.second;
    (Res *= (Pow[m] + Pow[n] + MOD - 1)) %= MOD;
  }
  if (X) (Res += X) %= MOD;
  cout << (Res + MOD - 1) % MOD << endl;
  return 0;
}


Measured memory_bytes: 20224
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll K;
    cin >> K;

    ll N = 50;
    ll loop = K / N;
    ll sub = K % N;
    vector<ll> a(N, N-1+loop);

    Rep (i, sub) {
        Rep (j, N) {
            if (j == i) {
                a[j] += N;
            } else {
                a[j]--;
            }
        }
    }

    cout << N << "\n";
    Rep (i, N) {
        if (i != 0) cout << " ";
        cout << a[i];
    }
    cout << "\n";

}

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

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

	int N, H;
	scanf("%d %d", &N, &H);

	vector<int> A(N), B(N);
	for (int i = 0; i < N; i++) {
		scanf("%d %d", &A[i], &B[i]);
	}

	sort(A.begin(), A.end());
	sort(B.begin(), B.end());

	int count = 0;
	for (int i = N - 1; i >= 0; i--) {
		if (B[i] > A[N - 1]) {
			count++;
			H -= B[i];
		} else {
			break;
		}
		if (H <= 0) {
			goto finish;
		}
	}

	count += ((H - 1) / A[N - 1] + 1);

finish:

	printf("%d", count);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
using namespace std;
const constexpr int INF = 1e9;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
const constexpr ll MOD = 1e9 + 7;
const int BITSIZE = 100010;

struct Less{
    bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
        return x.first < y.first;
    }
};
struct More {
	bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
		return x.first > y.first;
	}
};

int GCD(int a, int b){
    if(a<b) swap(a, b);
    if(b==0) return a;
    return GCD(b, a%b);
}
//1-indexed
int bit[100010];

int bit_query(int i) {
	int res = 0;
	for (; i >= 1; i -= i & -i) res = max(res, bit[i]);
	return res;
}

void bit_set(int x, int v) {
	for (; x <= BITSIZE; x += x & -x) {
		bit[x] = max(bit[x], v);
	}
}

ll pow_mod(ll a, ll b){
    ll sum =1;
    while(b>0){
        if(b&1){
            sum *= a%MOD;
        }
        a = a* a%MOD;
        b >>= 1;
    }
    return sum;
}



int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int x; cin >> x;
    if(x<=111) cout << 111 << endl;
    else if(x<=222) cout << 222 << endl;
    else if(x<=333) cout << 333 << endl;
    else if(x<=444) cout << 444 << endl;
    else if(x<=555) cout << 555 << endl;
    else if(x<=666) cout << 666 << endl;
    else if(x<=777) cout << 777 << endl;
    else if(x<=888) cout << 888 << endl;
    else if(x<=999) cout << 999 << endl;
    cout << endl;
    
    
	return 0;
}

Measured memory_bytes: 384
import java.lang.*;
import java.io.*;
import java.util.*;

class Main{
	public static void main(String args[]) throws FileNotFoundException{
		Scanner sc=new Scanner(System.in);
		String buf;
		buf=sc.nextLine();
		int n=Integer.parseInt(buf);
		buf=sc.nextLine();
		String[] sbuf=buf.split(" ");
		int[] num=new int[n];
		
		for(int i=0; i<sbuf.length; i++){
			num[i]=Integer.parseInt(sbuf[i]);
		}
		
		int a=0;
		for(int i=0; i<num.length; i++){
			while(num[i]%2==0){
				num[i]/=2;
				a+=1;
			}
		}
		
		System.out.println(a);
	}

	static void disp(int[] data){
		for(int i=0; i<data.length; i++){
				System.out.printf("%d ",data[i]);
		}
			System.out.println();
	}
}


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

int main() {
  char character;
  cin >> character;
  
  if (character == 'a' || character == 'e' || character == 'i' || character == 'o' || character == 'u') {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
use proconio::{input, marker::Usize1};

struct DP {
    dp: Vec<u64>,
    dpn: usize,
}

impl DP {
    fn new(n: usize) -> DP {
        let mut dpn = 1;
        while dpn < n {
            dpn <<= 1;
        }
        DP {
            dp: vec![0; 2 * dpn - 1],
            dpn: dpn,
        }
    }

    fn update_max(&mut self, i: usize, v: u64) {
        let mut i = i + self.dpn - 1;
        self.dp[i] = v;
        while i > 0 {
            i = (i - 1) / 2;
            self.dp[i] = self.dp[2 * i + 1].max(self.dp[2 * i + 2]);
        }
    }

    fn get_max(&self, e: usize, k: usize, rng: Option<(usize, usize)>) -> u64 {
        let (l, r) = if let Some(rng) = rng { rng } else { (0, self.dpn) };
        if l >= e || r <= 0 {
            0
        } else if r <= e {
            self.dp[k]
        } else {
            let m = (l + r) / 2;
            let vl = self.get_max(e, 2 * k + 1, Some((l, m)));
            let vr = self.get_max(e, 2 * k + 2, Some((m, r)));
            vl.max(vr)
        }
    }
}

fn main() {
    input! {
        n: usize,
        h: [Usize1; n],
        a: [u64; n],
    }

    let mut dp = DP::new(n);
    dp.update_max(h[0], a[0]);
    for i in 1..n {
        let m = dp.get_max(h[i] + 1, 0, None);
        dp.update_max(h[i], m + a[i]);
    }

    println!("{}", dp.get_max(n, 0, None));
}


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

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

  vector<double> x(N);
  vector<string> u(N);

  for (int i = 0; i < N; i++) {
    cin >> x.at(i) >> u.at(i);
  }

  double res = 0.0;
  for (int i = 0; i < N; i++) {
    if (u.at(i) == "BTC") {
      res += x.at(i) * 380000.0;
    } else {
      res += x.at(i);
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int K, S, X, Y, Z, count = 0, i, j, k;
	scanf("%d %d", &K, &S);
	for (i = 0; i <= K; i++) {
		if (i == S) {
			count++;
			break;
		}
		for (j = 0; j <= K; j++) {
			if (i + j == S) {
				count++;
				break;
			} else if (S - (i + j) <= K) {
				count++;
			}
		}
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <list>
#include <string>

using namespace std;

int main()
{
    string s;
	list<char> ss;
    int n;

    cin >> s;
    cin >> n;

    for( int i=0; i<s.length(); i++ ){
        ss.push_back(s[i]);
    }

    int count = 0;

    for( int i=0; i<n; i++ ){
        int t;
        cin >> t;
        if( t == 1 ){
            count++;
        }else{
            int f;
            char c;
            cin >> f;
            cin >> c;

            if( ( f + count ) % 2 == 1 ){
                ss.push_front(c);
            }else{
                ss.push_back(c);
            }
        }
    }

    string result = "";

    if( count % 2 == 1 ){
        for( auto it=ss.rbegin(); it != ss.rend(); ++it ){
            result.push_back(*it);
        }
    }else{
        for( auto it=ss.begin(); it != ss.end(); ++it ){
            result.push_back(*it);
        }
    }

    cout << result;

}


Measured memory_bytes: 10428
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>

using namespace std;

int u[400],v[400];
string w[400];

int main(){
    int n,m,s,e;
    char str[7];
    string dist[40];
    bool visited[40],change,inf;
    
    while(true){
        scanf("%d %d %d %d",&n,&m,&s,&e);
        
        if(n == 0) break;
        
        for(int i = 0;i < m;++i){
            scanf("%d %d %s",&u[i],&v[i],str);
            w[i] = string(str);
        }
        
        memset(visited,0,sizeof visited);
        
        dist[e] = "";
        visited[e] = true;
        change = true;
        inf = false;
        
        for(int it = 0;it <= 6*n && change;++it){
            change = false;
            
            for(int i = 0;i < m;++i){
                if(visited[ v[i] ]){
                    string aux = w[i] + dist[ v[i] ];
                    
                    if(!visited[ u[i] ] || aux < dist[ u[i] ]){
                        dist[ u[i] ] = aux;
                        change = true;
                        if(it >= n - 1 && u[i] == s) inf = true;
                    }
                    
                    visited[ u[i] ] = true;
                }
            }
        }
        
        if(inf || !visited[s]) puts("NO");
        else cout << dist[s] << '\n';
    }
    
    return 0;
}

Measured memory_bytes: 1500
#include <iostream>
#include <bits/c++io.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <vector>
#include <sstream>
using namespace std;

int main()
{
string a,b;int x=0,z;double y;
cin>>a>>b;
 stringstream geek(a+b);
geek >> x;
y=sqrt(x*1.0);
z=y;
if(y/z==1.0)
   cout<<"Yes"<<endl;
else
    cout<<"No"<<endl;
}


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

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

  ll a;cin>>a;
  a = a + a*a + a*a*a;
  cout<<a<<endl;
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector < pair<pair<string, int>, int> >a;

    for (int i = 1; i <= n; i++){
        string s;
        int p;
        cin >> s >> p;
        p = -p;
        a.push_back(make_pair(make_pair(s, p), i));
    }

    sort(a.begin(), a.end());

    for (int i = 0; i < n; i++){
        cout << a[i].second << endl;
    }

    
}

Measured memory_bytes: 504
#include <iostream>
#include <vector>

typedef long long ll;
using namespace std;

vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> res;

  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      ll num = 0;
      while (n % i == 0) {
        num++;
        n /= i;
      }
      res.push_back(make_pair(i, num));
    }
  }

  if (n != 1) {
    res.push_back(make_pair(n, 1));
  }

  return res;
}

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


int main() {
  ll A, B;
  cin >> A >> B;

  // AとBの公約数は、AとBの最大公約数の約数
  ll g = gcd(A, B);
  vector<pair<ll, ll>> primeFactors = prime_factorize(g);

  cout << primeFactors.size() + 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long
#define int long long
#define ld long double
#define endl '\n'
const int mod= 1e9+7;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define trace(x) cerr << #x << " is " << x << endl;
#define all(x) x.begin(),x.end()
#define reset(x,val) memset(x,val,sizeof(x))
#define flush fflush(stdout)
#define sz(a) a.size()
#define pii pair<int,int>
using namespace std;
const int N=100005;
int dp[N],h[N];
void smin(int &x,int y)
{
 x=min(x,y);
}
int32_t main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)cin>>h[i];
    dp[1]=0;
    dp[2]=abs(h[2]-h[1]);
    for(int i=3;i<=n;i++)
    dp[i]=INT_MAX;
    for(ll i=3;i<=n;i++)
    {
     int left=i-k;
     if(left<1)left=1;
     for(ll j=i-1;j>=left;j--)
     smin(dp[i],dp[j]+abs(h[i]-h[j])); 
    }
    cout<<dp[n]<<endl;
    return 0;
}



Measured memory_bytes: 1792
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#define MAXN 2005
#define p 1000000007
#define INF 0x3f3f3f3f
#define rint register int
#define LL long long
#define LD long double
using namespace std;

int n, m, ans=1, a[MAXN], b[MAXN], num[MAXN*MAXN], tag[MAXN*MAXN][2], pre[MAXN*MAXN][2];

int main()
{
    scanf("%d%d", &n, &m);
    for(rint i=1; i<=n; ++i)
    {
	scanf("%d", &a[i]);
	tag[a[i]][0]++;
	pre[a[i]][0]++;
	if(tag[a[i]][0]==2) {printf("0\n"); return 0;}
    }
    for(rint i=1; i<=m; ++i)
    {
	scanf("%d", &b[i]);
	tag[b[i]][1]++;
	pre[b[i]][1]++;
	if(tag[a[i]][1]==2) {printf("0\n"); return 0;}
    }
    for(rint i=1; i<=n*m; ++i)
    {
	if(tag[i][1] && tag[i][0]) num[i]=1;
	else if(tag[i][0])
	{
	    num[i]=m-pre[i-1][1];
	}
	else if(tag[i][1])
	{
	    num[i]=n-pre[i-1][0];
	}
	else num[i]=(n-pre[i-1][0])*(m-pre[i-1][1])-n*m+i;
	pre[i][0]+=pre[i-1][0];
	pre[i][1]+=pre[i-1][1];
    }
    for(rint i=1; i<=n*m; ++i) ans=1LL*ans*num[i]%p;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 16512
for roop in range(int(raw_input())):
    h,m = map(int,raw_input().split(":"))
    s = 60*h + m
    l = 12*m
    if l < s: l,s = s,l
    arg = l - s if l - s < 180*2 else 360*2-(l-s)
    if   arg < 30*2: print "alert"
    elif arg < 90*2: print "warning"
    else           : print "safe"

Measured memory_bytes: 4220
n, k = map(int, input().split())
v = list(map(int,input().split()))	
 
best = 0

for i in range(min(n, k) + 1):
  for j in range(min(i + 1, k - i + 1)):
    for m in range(i + 1):
      out = list(v[0:m]) + list(v[:-(i-m+1):-1])
      out.sort()
      best = max(best, sum(out[j::]))
 
print(best)
 

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<string>
#include<set>
#include<vector>
#include<stack>

using namespace std;

const int maxn = 200005;
typedef long long ll;
const ll inf = 10000000000LL;

int n,m;
int ind[maxn];
ll dis[maxn];
bool flag;
int ans[maxn];
int pos[maxn];
int cnt;

struct edge{
    int to;
    int c;
};

vector<edge> G[maxn];

bool topsort(){
    stack<int> s;
    cnt=0;
    for(int i=1;i<=n;i++)
        if(ind[i]==0) s.push(i);
    while(!s.empty()){
        int u=s.top();
        s.pop();
        ans[++cnt]=u;
//        cout<<"--- "<<u<<endl;
        for(int i=0;i<G[u].size();i++){
            int v=G[u][i].to;
            if((--ind[v])==0) s.push(v);
        }
    }
    if(cnt<n) return false;
    else return true;
}

void dfs(int u,ll d){
    dis[u]=d;
    for(int i=0;i<G[u].size();i++){
        int v=G[u][i].to;
        int c=G[u][i].c;
        if(dis[v]==-1){
            dfs(v,dis[u]+c);
        }else{
            if(dis[v]!=dis[u]+c) {
                flag=false;
            }
        }
    }
}

int main(){
    scanf("%d%d",&n,&m);
    while(m--){
        int l,r,d;
        scanf("%d%d%d",&l,&r,&d);
        edge e;
        e.to=r;
        e.c=d;
        ind[r]++;
        G[l].push_back(e);
        e.to=l;
        e.c=-d;
        G[r].push_back(e);
    }
    flag=topsort();
//    cout<<"flag "<<flag<<endl;
    if(!flag) {
        printf("No\n");
        exit(0);
    }
    memset(dis,-1,sizeof(dis));
    for(int i=1;i<=n;i++){
        if(dis[i]==-1) dfs(i,inf);
    }
    if(flag) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 17408
import sys
import  math
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

A,B,H,M=nm()

time=60*H+M
max_t=60*12
max_h=60

dx=A*math.cos(math.radians(360*time/max_t))-B*math.cos(math.radians(360*M/max_h))
dy=A*math.sin(math.radians(360*time/max_t))-B*math.sin(math.radians(360*M/max_h))

print(math.sqrt(dx*dx+dy*dy))


Measured memory_bytes: 9532
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        int A = in.nextInt();
        int B = in.nextInt();
        int C = in.nextInt();

        int totalAnti = A + B;

        int res = B + Math.min(totalAnti, C) + (totalAnti < C ? 1 : 0);

        System.out.print(res);

    }

}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] cnt = new int[9];
		for(int i = 0 ; i < n ; i++) {
			a[i] = sc.nextInt();
			if(1 <= a[i] && a[i] <= 399) cnt[0]++;
			else if(400 <= a[i] && a[i] <= 799) cnt[1]++;
			else if(800 <= a[i] && a[i] <= 1199) cnt[2]++;
			else if(1200 <= a[i] && a[i] <= 1599) cnt[3]++;
			else if(1600 <= a[i] && a[i] <= 1999) cnt[4]++;
			else if(2000 <= a[i] && a[i] <= 2399) cnt[5]++;
			else if(2400 <= a[i] && a[i] <= 2799) cnt[6]++;
			else if(2800 <= a[i] && a[i] <= 3199) cnt[7]++;
			else cnt[8]++;
		}
		int min = 0;
		int max = 0;
		for(int i = 0 ; i < 8 ; i++) {
			if(cnt[i] >= 1) min++;
		}
		min = Math.max(1, min);
		if(n == cnt[8]) max = cnt[8];
		else max = min + cnt[8];
		System.out.println(min + " " + max);
	}
}


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

#define mp              make_pair
#define pb              push_back
#define ff              first
#define ss              second
#define inc(A,B)        A=(A+(B))%MOD
#define mul(A,B)        (ll(A)*ll(B)%ll(MOD))
#define sub(a,b)        (((a)-(b)+MOD)%MOD)

typedef pair < int ,int > pii;
typedef long long ll;
typedef complex < ll > pt;

const int MAX_N = 200005;
const int MOD = 1e9 + 7;

int n;
int arr[MAX_N];

int main() {

//  freopen ( "in.txt" , "r" , stdin );
//  freopen ( "out.txt" , "w" , stdout );

  scanf ( "%d", &n );
  for ( int i = 0; i < n; ++i ) {
    scanf ( "%d", arr+i );
    arr[i] -= i+1;
  }

  sort ( arr, arr+n );
  ll res = 0;
  for ( int i = 0; i < n; ++i )
    res += (ll) abs ( arr[i]-arr[n/2] );
  printf ( "%lld", res );

  return 0;

}


Measured memory_bytes: 1024
import math
n, d = map(int, input().split())
coord = []
for i in range(n):
    x, y = map(int, input().split())
    coord.append([x, y])

count = 0
for i in range(len(coord)):
    if math.sqrt(coord[i][0] ** 2 + coord[i][1] ** 2) <= d:
        count += 1

print(count)

Measured memory_bytes: 39148
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("o3")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2.0)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define addf(T) [](T a, T b){return (a + b);}
#define minf(T) [](T a, T b){return min(a, b);}
#define maxf(T) [](T a, T b){return max(a, b);}


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acos(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

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

ll lcm(ll number1, ll number2) {
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int n, k;
	scanf("%d%d", &n, &k);
	vector<double> a(n);
	rep(i, n) {
		scanf("%lf", &a[i]);
		a[i] = allsum(1.0, a[i], a[i]) / a[i];
	}
	double ans = 0, tmp = 0;
	rep(i, k)tmp += a[i];
	ans = tmp;
	rep(i, n - k) {
		tmp -= a[i];
		tmp += a[k + i];
		ans = max(ans, tmp);
	}
	printdb(ans);

	Please AC;
}


Measured memory_bytes: 1792
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int a,b,c;
	std::cin >> a >> b >> c;
	print(a*b/2);
	return 0;
}


Measured memory_bytes: 256
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (N, D) = read!(usize, usize);
    let w = 2 * D + 1;
    println!("{}", (N + w - 1) / w)
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N, M;
  cin >> N >> M;
  priority_queue<int> que;
  rep(i,N){
    int a;
    cin >> a;
    que.push(a);
  }

  rep(i,M){
    int p = que.top(); que.pop();
    if(p > 0){
      p >>= 1;
    }
    que.push(p);
  }

  ll ret = 0;
  while(!que.empty()){
    int p = que.top(); que.pop();
    ret += p;
  }
  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 892
program canh_toan;
uses math;
const minn=0;
      maxn=trunc(1e5)+5;
var n:longint;
    k:int64;
    a,b:array [minn..maxn] of int64;
procedure sort(l,r:int64);
var i,j,k,tg:int64;
begin
i:=l;j:=r;tg:=a[random(r-l+1)+l];
repeat
while (a[i]<tg) do inc(i);
while (tg<a[j]) do dec(j);
if not(i>j) then
   begin
     k:=a[i];a[i]:=a[j];a[j]:=k;
     k:=b[i];b[i]:=b[j];b[j]:=k;
     inc(i);
     dec(j);
   end;
until i>j;
if (l<j) then sort(l,j);
if (i<r) then sort(i,r);
end;
procedure main();
var i:longint;
begin
readln(n,k);
for i:=1 to n do readln(a[i],b[i]);
sort(1,n);
b[0]:=0;
for i:=1 to n do b[i]:=b[i]+b[i-1];
i:=1;
while (b[i]<k) do inc(i);
write(a[i]);
end;
BEGIN
  main();
END.

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

int main() {
	// your code goes here
	string a;
	string b;
	cin >> a;
	cin >>b;
	int i=0;
	/*int lena,lenb;
	while(a[i] != '\0')
	{
	    ++i;
	    
	}
	lena = i;
	i=0;
	while(b[i] != '\0')
	{
	    ++i;
	    
	}
	lenb = i;
	for(i=0;i<(lena + lenb);i++)
	{
	    
	}*/
	cout << b << a <<  "\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 4000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

///////////////////////////



int main() {
	
	ll N;
	cin >> N;
	vector<ll> a(N + 1);
	repn(i, N) cin >> a[i];

	ll ans = 0;
	repn(i, N) if (a[a[i]] == i) { ans++; }
	cout << ans / 2;

	system("PAUSE");
}


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

using namespace std;

int main(void){
	int h,a;
  	cin >> h >> a;
  	int x[a];
  	for(int i=0;i<a;i++){
    	cin >> x[i];
    }
  	sort(x,x+a,[](int aa, int bb) {
        return aa > bb;   
    });
  	for(int i=0;i<a;i++){
    	h-=x[i];
      	if(h<=0){
        	break;
        }
    }
  	if(h<=0){cout << "Yes" << endl;}
  	else{cout << "No" << endl;}
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int r,d,x;
  cin >> r >> d >> x;
  int x2[11];
  x2[0] = r * x - d;
  cout << x2[0] << endl;
  for(int i=1;i<10;++i) {
    x2[i] = r * x2[i-1] - d;
    cout << x2[i] << endl;
  }
}

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

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

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

fn main() {
    input!{
        h: usize,
        w: usize,
        n: usize,
        sr: usize,
        sc: usize,
        mut s: chars,
        mut t: chars
    }
    s.reverse();
    t.reverse();
    let mut l = 1;
    let mut r = w;
    let mut u = 1;
    let mut d = h;
    for i in 0..n {
        match t[i] {
            'L' => {if r < w {r += 1;}},
            'R' => {if l > 1 {l -= 1;}},
            'U' => {if d < h {d += 1;}},
            'D' => {if u > 1 {u -= 1;}},
            _ => {}
        }
        match s[i] {
            'L' => {l += 1;},
            'R' => {r -= 1;},
            'U' => {u += 1;},
            'D' => {d -= 1;},
            _ => {}
        }
        if l > r || u > d {
            break;
        }
    }
    println!("{}", if l <= sc && sc <= r && u <= sr && sr <= d {"YES"} else {"NO"});
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define pii pair<int, int> 
#define mod 1000000007
ll power(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b%2!=0) res=(res*a);
        a=(a*a);
        b/=2;
        if(res>INT_MAX){
            return INT_MAX;
        }
    }
    return res;
}
ll ncr(ll n,ll k){
    if(k==0||k==n) return 1ll;
    if(k>n-k) k=n-k;
    ll pro=1;
    for(ll i=0;i<k;i++){
        pro=(pro*(n-i))%mod;
        pro/=(i+1);
    }
    return (pro%mod);
}
vector<int> prime;
void seive(){
    vector<bool > isprime(101,true);
    for(int i=2;i*i<=100;i++){
        if(isprime[i]){
            for(int j=i*i;j<=100;j+=i){
                isprime[j]=false;
            }
        }
    }
    for(int i=2;i<=100;i++){
        if(isprime[i]) prime.push_back(i);
    }
}
int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    vector<ll> arr(n);
    for(int i=0;i<n;i++) cin>>arr[i];
    ll minn=1e18;
    for(int i=-100;i<=100;i++){
        ll sum=0;
        for(int j=0;j<n;j++){
            sum+=(i-arr[j])*(i-arr[j]);
        }
        minn=min(minn,sum);
    }
    cout<<minn;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 1000
int main(){
  int M[N][N];
  int n,u,i,k,v,j;

  scanf("%d",&n);
  for(i = 0;i<n;i++){

  
    for(j = 0;j<n;j++){
      M[i][j] = 0;
    }
  }

  for(i = 0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j = 0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }

  for(i = 0;i<n;i++){
    for(j = 0;j<n;j++){
      if(j >= 1){
	printf(" ");
      }
      printf("%d",M[i][j]);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2136
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define llu unsigned long long int
#define sa(a,n,t) for(int ii=0;ii<n;ii++) scanf("%"#t"",&(a)[ii])
#define rep(i,n) for(int i=0;i<n;i++) 
#define reps(i,a,n) for(int i=a;i<n;i++) 
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rreps(i,a,n) for(int i=n-1;i>=a;i--)
#define validl(i,a,b) ((i>=a)&&(i<=b))?1:0
#define validmat(x,y,a,b,c,d) (validl(x,a,b) && validl(y,a,b))?1:0
#define validmn(x,y,m,n) validmat(x,y,0,m,0,n)
#define valid(i,n) validl(i,0,n)
#define v(t) vector<t>
#define vv(t) vector<vector<t> >
#define mk make_pair
#define pb push_back
#define pa(a,n,t)  for(int i=0;i<n;i++) printf("%"#t"",a[i])
#define p2 pair<int,int>
#define p3 pair<p2,int>
#define fi first
#define se second
#define sd(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld",a)
#define pd(a) printf("%d",a)
#define sf(a) scanf("%lf",&a)
#define pf(a) printf("%lf",a)
#define nline printf("\n")
#define ss(a) scanf("%s",a)
#define ps(a) printf("%s",a)
#define sc(a) scanf("%c",&a)
#define pc(a) printf("%c",&a)
#define mf(m,f) m.find(f)!=m.end()
#define pp3(m) cout<<m.fi.fi<<" "<<m.fi.se<<" "<<m.se<<" "
#define pp2(m) cout<<m.fi<<" "<<m.se<<" "
#define debug 0
/*v(int) adj[200001];
void dfs(int i,int p){
    rep(j,adj[i].size()){
        if(p!=adj[i][j])
            dfs(adj[i][j],i);
    }
}*/
int main()
{
  int t;
  //sd(t);
  //rep(tt,t){
    //cout<<"Case #"<<tt+1<<": ";
    string s;
    cin>>s;
    if(s=="ABC")
        cout<<"ARC";
    else
    {
            cout<<"ABC";
    }
    
    nline;
  //}
  return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  
  int ret = 1;
  
  for (int i = 0; i < N; i++) {
    if ((ret * 2) < (ret + K)) {
      ret *= 2;
    } else {
      ret += K;
    }
  }
  
  cout << ret << endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
    using namespace std;
    #define rep(i, n) for (int i = 0; i < (int)(n); i++)
     
    int main() {
      int N;
      bool x = 0;
      string iro;
      cin >> N;
      
      rep ( i , N ) {
        cin >> iro;
        if ( iro == "Y" ) {
		x = 1;
        }
      }
      if (x) {
        cout << "Four" << endl;
      }
      else {
        cout << "Three" << endl;
      }
    }

Measured memory_bytes: 256
n = gets.to_i
ps = gets.chomp.split.map(&:to_i)
cnt = 0
ps_sort = ps.sort
ps_sort.each_with_index do |p_sort,i|
  if p_sort != ps[i]
    cnt += 1
  end
end
puts (cnt == 2 || cnt == 0) ? "YES" : "NO"

Measured memory_bytes: 1788