akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  i64 N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  // Reverse it.
  if (S[0] == 'L') {
    REP(i, N) { S[i] = (S[i] == 'L') ? 'R' : 'L'; }
  }

  i64 unhappy = 0;
  for (int i = 0; i < N - 1; ++i) {
    if (S[i] == 'R' && S[i + 1] == 'L') {
      if (K > 0) {
        --K;
        for (int j = i + 1; j < N; ++j) {
          if (S[j] == 'R') {
            i = j - 1;
            break;
          }
          S[j] = 'R';
        }
      } else {
        unhappy += 2;
      }
    }
  }
  if (S[N - 1] == 'R') ++unhappy;
  cout << (N - unhappy) << endl;
}


Measured memory_bytes: 3724
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
int n,a,cntx,cnt2,cnt4;
bool yes;
int main(){
	scanf("%d",&n);
	while(n--){
		scanf("%d",&a);
		if(a%4==0) cnt4++;
		else if(a%2==0) cnt2++;
		else cntx++;
	}
	if(cnt2==0){
		if(cnt4>=cntx-1) yes=1;
	}
	else if(cnt4>=cntx) yes=1;
	if(yes) puts("Yes");
	else puts("No");
	return 0;
}

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

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0LL, sizeof(x))
#define mm(x) memset((x), -1LL, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define Bit(n) (1LL << (n))
#define Bitset(a, b) (a) |= (1LL << (b))
#define Bitunset(a, b) (a) &= ~(1LL << (b))
#define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL)
#define Bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} Accelerate_Cin;

signed main() {
  int N;
  cin >> N;
  vector<int> v(N);
  map<int, int> mp;
  for (int i = 0; i < N; i++) {
    cin >> v[i];
    mp[v[i]]++;
  }
  sort(ALL(v));
  UNIQUE(v);

  if (v.size() > 2) {
    cout << "No" << endl;
    return 0;
  }

  if (abs(v[0] - v[1]) >= 2) {
    cout << "No" << endl;
    return 0;
  }

  if (v.size() == 2) {
    if (mp[v[1]] >= 2 * (v[1] - mp[v[0]])) {
      if (mp[v[0]] < v[1]) {
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    } else {
      cout << "No" << endl;
    }
    return 0;
  }

  if (N == v[0] + 1) {
    cout << "Yes" << endl;
  } else if (N >= v[0] * 2) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

ll five(ll x) { return x * x * x * x * x; }

int main() {
    ios::sync_with_stdio(false);

    ll X; cin >> X;
    for(ll a = -3e3; a <= 3e3; a++) {
        for(ll b = -3e3; b <= 3e3; b++) {
            if(five(a) - five(b) == X) {
                cout << a << " " << b << "\n";
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  ll n;
  cin >> n;
  
  ll res = 0;
  for (int i = 0; i < n; i++){
    ll a, b;
    cin >> a >> b;
    
    res += b - a + 1;
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
var str:array[1..52]of char;
    n,k,i:integer;
begin
  readln(n,k);
  for i:=1 to n do read(str[i]);
  if str[k]='A' then str[k]:='a';
  if str[k]='B' then str[k]:='b';
  if str[k]='C' then str[k]:='c';
  for i:=1 to n do write(str[i]);
end.


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

int main(){
    string s;
    cin >> s;
    string a = s.substr(0,2), b = s.substr(2);
    int y = stoi(a), m = stoi(b);
    bool c = y <= 12 && y != 0;
    bool d = m <= 12 && m != 0;
    if(c&&d)    cout << "AMBIGUOUS" << endl;
    else if(c)  cout << "MMYY" << endl;
    else if(d)  cout << "YYMM" << endl;
    else        cout << "NA" << endl;
    return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define inf 1e18
#define pi acos(-1.0)
#define mod 998244353

int main(void)
{
    fastio;

    int n,a,b;
    cin >> n >> a >> b;

    if(n==2)cout << "Borys";
    else if((b-a-1)%2)cout << "Alice";
    else cout << "Borys";

    return 0;
}


Measured memory_bytes: 3672
n = int(input())
h = list(map(int, input().split()))
dp=[0]*(n+1)
dp[1]=0
dp[2]=abs(h[0]-h[1])
for i in range(3,n+1):
    dp[i]=min(dp[i-2]+abs(h[i-3]-h[i-1]),dp[i-1]+abs(h[i-2]-h[i-1]))
print(dp[-1])

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

int main() {

	int N, A, B;

	cin >> N;
	
	if (N==2) {
		cin >> A >> B;
		cout << A + B << endl;
	}
	else {
		cout << "Hello World" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
fun intList() = readLine()?.split(" ")?.map(String::toInt) ?: TODO()
fun main() {
    val n = readLine()?.toInt() ?: return
    val a = intList()
    val m = 1000000007L
    var t = 3L
    if (a.first() != 0) {
        println("0")
        return
    }
    val numbers = hashMapOf<Int, Int>()
    numbers[0] = 1
    a.drop(1).forEach {
        val b = numbers.getOrPut(it) { 0 }
        numbers[it] = b + 1
        if (it == 0) {
            t = t * (3 - b) % m
        } else {
            t = t * (numbers.getOrDefault(it - 1, 1) - b) % m
        }
    }
    println(t.toString())
}


Measured memory_bytes: 59872
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < (int)vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

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

	int N, K;
	cin >> N >> K;

	int ans = 1;
	for (int i = 0; i < N; i++) {
		if (ans < K) ans *= 2;
		else ans += K;
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a, b, c;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	
	if (a+b+c ==17) {
		if (a == 5) {
			if (b == 5 && c == 7 || b == 7 && c == 5) {
				printf("YES\n");
			} else {
				printf("NO\n");
			}
		} else if (a == 7) {
				if (b==5&&c==5) {
					printf("YES\n");
				} else { 
					printf("NO\n"); 
				}
		}
	} else {
		printf("NO\n");
	}


	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
#define mp make_pair
#define int long long
#define mod 1000000007
#define DEBUG cout<<"Hello1\n";
#define all(v) (v).begin(),(v).end()
#define clr(x) memset(x,0,sizeof(x))
#define deb(...) debug(#__VA_ARGS__, __VA_ARGS__);
const int N = 1e6 + 5;
const double pi =  acosl(-1);
const long long inf = 1e18 + 5;
using namespace std;
template<typename T> void debug(string s, T x) {cout << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cout << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}
template<class T> void print_container(T &container) { for (auto &t : container) { cout << t << " ";} cout << endl;}
template<class T> void printArr(T &a , int n) { for (int i = 0; i < n; i++) {cout << a[i] << " ";} cout << endl;}
typedef long long ll;
typedef pair<int, int> pii;

//Template Ends
string n;

void solve() {
	cin >> n;

	ll sum = 0;

	for (char c : n) {
		sum += c - '0';
	}

	if (sum % 9) {
		cout << "No\n";
	} else {
		cout << "Yes\n";
	}

}

int32_t main() {
	IOS;



	solve();

	return 0;
}




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

class Main{
	public static void main(String[] args){
		solve();
	}
	public static void solve(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int i=0;i<n;i++){
			int x = sc.nextInt();
			if(map.containsKey(x)){
				int y = map.get(x);
				map.put(x, y+1);
			}
			else{
				map.put(x, 1);
				list.add(x);
			}
		}
		int count = 0;
		for(int i=0;i<list.size();i++){
			int x = list.get(i);
			int y = map.get(x);
			if(x<=y){
				count += y - x;
			}
			else{
				count += y;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 65268
package main

import "fmt"

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	var n, l int
	fmt.Scan(&n, &l)

	ans := 0
	d := 1000
	var e int
	for i := 1; i <= n; i++ {
		t := l + i - 1
		ans += t
		if v := abs(t); v < d {
			d = v
			e = t
		}
	}
	ans -= e
	fmt.Println(ans)
}


Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	VVI c(4, VI(4)); rep(i, 3)rep(j, 3)cin >> c[i][j];
	VI a(4), b(4);
	a[0] = 0;
	rep(i, 3)b[i] = c[0][i];
	FOR(i, 1, 3)a[i] = c[i][0] - b[0];
	bool flag = true;
	rep(i, 3)rep(j, 3) {
		if (c[i][j] != a[i] + b[j])flag = false;
	}
	puts(flag ? "Yes" : "No");
}

Measured memory_bytes: 256
A, B, C = input().split()
flag = 0

if A == B and A != C:
  flag = 1

if A == C and A != B:
  flag = 1
  
if B == C and B != A:
  flag = 1
  
if flag == 1:
  print("Yes")
elif flag == 0:
  print("No")

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

bool judge(int x, vector<int> d){
    bool ans = true;
    while (x > 0){
        rep(i, d.size()){
            if (x % 10 == d[i]) ans = false;
        }
        x /= 10;
    }
    return ans;
}

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> d(k);
    rep(i, k) cin >> d[i];
    for(int i = n; i < 1000000; i++){
        if (judge(i, d)){
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    for (int i = 0; i < (int)S.size(); i += 2) {
        if (S[i] != 'h' || S[i + 1] != 'i') {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  int n;
  ll k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) { cin >> a[i]; }
  ll sum = accumulate(a.begin(), a.end(), (ll)0);
  set<ll> candidates;
  for (ll i = 1; i * i <= sum; ++i) {
    if (sum % i == 0) {
      candidates.insert(i);
      candidates.insert(sum/i);
    }
  }
  ll ans = 1;
  for (ll x : candidates) {
    vector<ll> mods(n);
    rep(i, n) mods[i] = a[i] % x; 
    sort(mods.begin(), mods.end());
    ll down_sum = accumulate(mods.begin(), mods.end(), (ll)0);
    int r = down_sum/x;
    int l = n - r;
    ll need = 0;
    rep(i, l) { need += mods[i]; }
    if (need <= k) ans = max(ans, x);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
#define MOD 1000000007

ll factr[100010], frf[100010], frfr[100010], ans[100010];

ll modpow(ll x, ll y) {
	ll ans = 1;
	while (y) {
		if (y & 1)ans *= x;
		x *= x;
		ans %= MOD;
		x %= MOD;
		y /= 2;
	}
	return ans;
}

ll moddiv(ll x, ll y) {
	return x * modpow(y, MOD - 2) % MOD;
}

int main() {
	ll N;
	cin >> N;
	factr[0] = 1, frf[0] = 1, frfr[0] = 0;
	for (int i = 1;i < 100010;i++) {
		factr[i] = factr[i - 1] * i;
		factr[i] %= MOD;
		frf[i] = frf[i - 1] * moddiv(1, i);
		frfr[i] = (frfr[i - 1] + frf[i]) % MOD;
	}

	N--;
	ans[0] = factr[N];
	for (ll i = 1;i < N;i++) {
		ans[i] = ans[i - 1] + moddiv(factr[N], i + 1);
	}
	ll fans = 0;
	N++;
	vector<ll> X(N);
	for (int i = 0;i < N;i++) {
		cin >> X[i];
	}
	for (int i = 0;i < N - 1;i++) {
		fans += (X[i + 1] - X[i]) * ans[i];
		fans %= MOD;
	}
	cout << fans << endl;
}

Measured memory_bytes: 4096
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String x = s.substring(0,2);
    String l = s.substring(2,4);
    int y = Integer.parseInt(x);
    int m = Integer.parseInt(l);
    // System.out.println(y + " " + m);
    if(0<y && y<=12 && 0<m && m<=12){
      System.out.println("AMBIGUOUS");
    }else if(0<m && m<=12){
      System.out.println("YYMM");
    }else if(0<y && y<=12){
      System.out.println("MMYY");
    }else{
      System.out.println("NA");
    }
  }
}


Measured memory_bytes: 21844
#include <iostream>
using namespace std;
int main(){
  int n,m,x;
  cin >> n >> m >> x;
  int to_zero = 0, to_n = 0;
  for(int i = 0; i < m; ++i){
    int a;
    cin >> a;
    if(a < x) ++to_zero;
    else ++to_n;
  }
  cout << (to_zero < to_n ? to_zero : to_n) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1LL<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1LL<<(i))))
#define setbit1(n,i) ((n)|(1LL<<(i)))
#define togglebit(n,i) ((n)^(1LL<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define fi first
#define se second
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d%d",&a,&b)
#define PI (acos(-1))
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD (1000000007)
#define asz 500005
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define pf push_front
int main(){
    fastread;
    ll r;
    cin>>r;
    double d=2.0000000*PI*r;
    cout<<d;
}


Measured memory_bytes: 3792
//#include <bits/stdc++.h> 
#include <iostream>
#include <vector> 
#include <float.h>
#include <cfloat>
#include <string>
#include <ctype.h>
#include <algorithm>
#include <errno.h>
#include <cerrno>
#include <assert.h>
#include <cassert> 
#include <map>
#include <memory.h>
#include <cctype>
#include <ctype.h>
#include <math.h>
#include <vector> 
#include <cstdio> 
#include <set>
#include <string.h>
#include <stdio.h>
#include <new>
#include <ctime> 
#include <memory>
#include <cmath>
#include <queue>
#include <cstring>
#define ll long long
#define fo(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define br break
#define ct continue
#define pb push_back
#define mp make_pair 
#define pi 3.141592653589793238462643383279502884197169
#define F first
#define S second
#define pii pair<int,int>  
#define em empty()
#define vei vector<int>
#define ves vector<string>
#define qui queue<int> 
#define qu queue
#define large 1243456576
using namespace std;
int a[150000],ans=large; 
int main(){
    int n,m;
    cin>>n>>m;
    fo(i,0,n){
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i+m-1<n;i++){
        ans=min(ans,a[i+m-1]-a[i]);
    }
    cout<<ans<<endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 888
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner scn = new Scanner(System.in)) {
			final long N = scn.nextLong();
			if (N % 2 == 1) {
				System.out.println(0);
			} else {
				long ret = 0;
				for (long l = N / 5; l > 0; l /= 5) {
					ret += l / 2;
				}
				System.out.println(ret);
			}
		}
	}
}


Measured memory_bytes: 21716
#include <algorithm>
#include <cstdio>
#include <vector>

static const size_t n_max = 100000;
static size_t parents[n_max];
static int depths[n_max];
static std::vector<size_t> children[n_max];

void rec(size_t i, int d) {
  depths[i] = d;
  for (auto&& c : children[i])
    rec(c, d + 1);
}

int main() {
  size_t n;
  scanf("%zu\n", &n);
  std::fill(parents, parents + n, size_t(-1));
  for (size_t i = 0; i < n; i++) {
    size_t j, k;
    scanf("%zu%zu", &j, &k);
    for (size_t l = 0; l < k; l++) {
      size_t c;
      scanf("%zu", &c);
      children[j].push_back(c);
      parents[c] = j;
    }
  }
  rec(std::find(parents, parents + n, size_t(-1)) - parents, 0);
  for (size_t i = 0; i < n; i++) {
    printf("node %zu: parent = %d, depth = %d, %s, [",
           i, int(parents[i]), depths[i],
           parents[i] == size_t(-1) ? "root" : children[i].size() ? "internal node" : "leaf");
    if (children[i].size()) {
      for (size_t j = 0; j < children[i].size() - 1; j++)
        printf("%zu, ", children[i][j]);
      printf("%zu]\n", children[i][children[i].size()-1]);
    } else
      puts("]");
  }
  return 0;
}

Measured memory_bytes: 7384
#include<cstdio>


int main(void)
{
	int n;

	while(scanf("%d", &n)==1)
	{
		int ans=0;

		for(int i=0;i<=100/4;i++)
		{
			for(int j=0;j<=100/7;j++)
			{
				if(i*4+j*7==n) ans=1;
			}
		}

		printf("%s\n", ans?"Yes":"No");
	}

	return 0;
}


Measured memory_bytes: 128
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

fn main() {
  let n = read::<i32>();
  let m = read::<i32>();
  let c = read::<i32>();
  let mut b = vec![];
  let mut ans = 0;

  let mut a: Vec<Vec<i32>> = vec![];

  for _ in 0..m {
    let b_i = read::<i32>();
    b.push(b_i)
  }

  for _ in 0..n {
    let mut a_s = vec![];
    for _ in 0..m {
      let a_i = read::<i32>();
      a_s.push(a_i);
    }
    a.push(a_s);
  }

  for i in a {
    let mut result = 0;
    for j in 0..m {
      result += i[j as usize] * b[j as usize];
    }
    if result + c > 0 {
      ans += 1;
    }
  }

  println!("{:?}", ans);
}



Measured memory_bytes: 4352
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }

#include <set>
void solve() {
  int n;
  cin >> n;
  cout << n * n * n << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int m, d;
    cin >> m >> d;
    int cnt = 0;
    for (int i = 4; i <= m; ++i)
    {
        for (int j = 2; j * 10 <= d; ++j)
        {
            if (i % j == 0)
            {
                int k = i / j;
                if (k >= 2 && k < 10)
                {
                    if (j * 10 + k <= d)
                    {
                        //cout << "i:" << i << " j:" << j << endl;
                        cnt++;
                    }
                }
            }
        }
    }
    /*
    条件
    JK<D
    J*K==M
    J>=2
    K>=2
    */
    cout << cnt;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using uInt = long long unsigned int;
using Double = long double;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    Int pow(Int p, Int k) {
        Int ret = 1;
        rep(i, 0, k) ret *= p;
        return ret;
    }

    void solve() {
        Int K;
        cin >> K;
//        vector<Int> neri;
        set<Int> st;

        Int digit = 0;
        while (st.size() < K) {
            for (int b = 1; b < 10; ++b) {
                Int lb = 0;
                Int ub = pow(3, digit);
                for (Int mask = 0; mask < ub; ++mask) {
                    Int tmp = mask;
                    Int val = b;
                    bool ok = true;
                    rep(_, 0, digit) {
                        Int t = tmp % 3;
                        t--;
                        Int n = (val % 10) + t;
                        if (n < 0 || n > 9) {
                            ok = false;
                            break;
                        }
                        val = val * 10 + n;


                        tmp /= 3;
                    }
                    if (ok) {
//                        neri.push_back(val);
                        st.insert(val);
                    }
                }
            }
            digit++;
        }
//        sort(all(neri));

//        cout << *(st.begin() + K) << endl;
        vector<Int> v(st.begin(), st.end());
        cout << v[K - 1] << endl;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    Solve().solve();


    return 0;
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll N;
    cin >> N;
    ll x = 1;
    rep(i,48){
        x *= 2;
    }
    ll sub_N = N + x;
    vector<ll> vec(35);
    rep(i,35){
        vec[i] = 0;
    }
    ll N_sub = 0;
    ll cnt_sub1 = 1;
    ll cnt_sub2 = 2;
    rep(i,35){
        if ((N_sub + cnt_sub1 + x) % cnt_sub2 == sub_N % cnt_sub2){
            vec[i] = 1;
            N_sub += cnt_sub1;
        }
        else{
            vec[i] = 0;
        }
        cnt_sub1 *= -2;
        cnt_sub2 *= 2;
    }
    int cnt_0 = 0;
    if (N == 0){
        cout << vec[34] << endl;
    }
    else{
        rep(i, 35){
            if (cnt_0 == 0 && vec[34 - i] == 0){
                continue;
            }
            else if (vec[34 - i] == 1){
                cnt_0++;
                cout << vec[34 - i];
            }
            else{
                cout << vec[34 - i];
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
map<char, int> dict;
int main(){
    dict['I'] = 1;
    dict['V'] = 5;
    dict['X'] = 10;
    dict['L'] = 50;
    dict['C'] = 100;
    dict['D'] = 500;
    dict['M'] = 1000;
    string str;
	    
    while(cin >> str){
	int res = 0;
	char now = str[0];
	int cnt = 1;
	for(int i = 1;i < str.size();i++){
	    if(str[i] == now)cnt++;
	    else{
		if(dict[str[i]] > dict[now])res -= cnt * dict[now];
		else res += cnt * dict[now];
		now = str[i];
		cnt = 1;
	    }
	}
	res += cnt * dict[now];
	cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 1184
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
int dx[4] = {0,1,0,-1};
int dy[4] = {1, 0, -1, 0};

int main(){
  int A,B, C, D;
  cin >> A >> B >> C >> D;

  cout << max(0, min(B,D) - max(A,C)) <<endl;

  return 0;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define pb push_back
#define N 100009
#define inf 1e18
int mod=1e9+7;
//int mod=998244353;
#define P pair<int,int>
#define F first
#define S second
#define ll long long
#define all(v) v.begin(),v.end()

#define ordered_set tree<P, null_type,less<P>, rb_tree_tag,tree_order_statistics_node_update> 

void solve(){
	string s,t;
	cin>>s>>t;
	t=t.substr(0,t.size()-1);
	if(s==t)cout<<"Yes\n";
	else cout<<"No\n";
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;//cin>>t;
	while(t--){
		solve();
	}
    return 0;
}

Measured memory_bytes: 3652
# 2019/9/17 8:31-

def get_answer(input_list):
    w = ["Sunny", "Cloudy", "Rainy"]
    index = w.index(input_list[0])
    return w[(index + 1) % len(w)]



if __name__ == "__main__":
    input_list = []
    while True:
        try:
            input1 = input()
            if not input1:
                break
            if len(input1) == 0:
                break
            input_list.append(input1)
        except EOFError:
            break
    print(get_answer(input_list))



Measured memory_bytes: 3060
n = int(input())
a = [int(input()) for _ in range(n)]
dp = [[] for _ in range(n+1)]
for i in range(n+1):
    dp[i] += [-1 for _ in range(10010)]
dp[0][0] = 1
for i in range(n):
    for j in range(10010):
        if dp[i][j] == 1:
            dp[i+1][j] = 1
            dp[i+1][j+a[i]] = 1
ans = 0
for i in range(10010):
    if dp[n][i] == 1:
        if i % 10 != 0:
            ans = max(ans,i)
print(ans)

Measured memory_bytes: 11508
#include<bits/stdc++.h>
#define ll long long 
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
signed main(){
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  while(a>0){
    c = c - b;
    if(c<=0){
      cout<<"Yes\n";
      return 0;
    }
    a = a - d;
  }
  cout<<"No\n";
  return 0;
}

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

int main() {
  uint32_t A = 0, B = 0, C = 0;
  std::cin >> A >> B >> C;

  std::vector<bool> remain(B, false);
  uint32_t i = 1;
  while (!remain[(A * i) % B]) {
    remain[(A * i) % B] = true;
    i++;
  }

  std::cout << (remain[C] ? "YES" : "NO") << std::endl;

  return 0;
}

Measured memory_bytes: 256
/*----------------by syr----------------*/
/*
  -----  -----  -----
  |   |  |---|    _/
  |   |  | \_    /
  -----  |   \  -----

  |---\  \   /  |\  /|
  |   |   \_/   | \/ |
  |   |   / \   |    |
  |---/  /   \  |    |
*/
#include<bits/stdc++.h>

using namespace std;

#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i,x,y) for(int i=(x);i<(y);++i)
#define REP(i,x,y) for(int i=(x);i<=(y);++i)
#define x0 x0123456789
#define y0 y0123456789
#define x1 x1234567890
#define y1 y1234567890
#define x2 x2345678901
#define y2 y2345678901
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;
typedef pair<int,int> pii;

const int INF=1e9+7;

int n,k;

int main(){
	scanf("%d%d",&n,&k);
	if(n&1){
		if(k>(n+1)/2) puts("NO");
		else puts("YES");
	}else{
		if(k>n/2) puts("NO");
		else puts("YES");
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
    int main(){
        int antennas[5], k;
        int aux = 1;
     
        for (int i = 0; i < 5; i++){
            scanf("%d", &antennas[i]);
        }
     
        scanf("%d", &k);
     
        for (int i = 0; i<5; i++){
            for (int j = 0; j<i; j++){
                if ((antennas[j] - antennas[i]) > k || (antennas[i] - antennas[j]) > k){
                    aux =0;
                }
            }
        }
     
        if (aux){
            printf("Yay!\n");
        } else {
            printf(":(\n");
        }
     
        return 0;
    }

Measured memory_bytes: 1648
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main() {
    ll a;
    long double b;
    ll c;
    cin >> a >> b;
    c = a * ll (b * 100 + 0.001) /100;
    cout << c << endl;
}

Measured memory_bytes: 3212
uses
  SysUtils,
  Classes;

var
	a, i, j, t : Integer;
	atype : array of Integer;
	str : String;
	strlist : TStringList;
begin
	readln(a);
	setLength(atype, a);
	
	readln(str);
	strlist := TStringList.Create;
	try
		strlist.Delimiter := ' ';
		strlist.DelimitedText := str;
		for i := 0 to a - 1 do
			atype[i] := StrToInt(strlist.Strings[i]);
	finally
		strlist.free;
		end;
		
	for i := 0 to a - 1 do
		begin
		for j := a - 1 downto i + 1 do
			begin
				if atype[j - 1] > atype[j] then
					begin
					t := atype[j - 1];
					atype[j - 1] := atype[j];
					atype[j] := t;
					end;
			end;
		end;
		t := atype[a -1] - atype[0];
		writeLn(t);
end.

Measured memory_bytes: 288
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<set>
using namespace std;
#define lowbit(x) (x)&(-x)
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define per(i,a,b) for (int i=a;i>=b;i--)
#define maxd 1000000007
typedef long long ll;
const int N=100000;
const double pi=acos(-1.0);
int n,tot=0,pri[1001000],a[10100],tax[10100];
bool ispri[10100];
set<int> ans; 

int read()
{
	int x=0,f=1;char ch=getchar();
	while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
	while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
	return x*f;
}

void sieve(int n)
{
	rep(i,2,n)
	{
		if (!ispri[i]) pri[++tot]=i;
		int j;
		for (j=1;j<=tot && i*pri[j]<=n;j++)
		{
			ispri[i*pri[j]]=1;
			if (i%pri[j]==0) break;
		}
	}
}

int gcd(int x,int y)
{
	if (!y) return x;else return gcd(y,x%y);
}

bool chk(int p)
{
	if (a[0]%p) return 0;
	rep(i,0,p-2) tax[i]=0;
	rep(i,0,n) tax[i%(p-1)]=(tax[i%(p-1)]+a[i])%p;
	rep(i,0,p-2) if (tax[i]) return 0;
	return 1;
}

int main()
{
	n=read();sieve(n);
	per(i,n,0) a[i]=read();
	int now=0;
	rep(i,0,n)
	{
		if (a[i])
		{
			if (!now) now=abs(a[i]);
			else now=gcd(abs(a[i]),now);
		}
	}
	now=abs(now);
	
	int rest=now,i;
	for (i=2;i*i<=now;i++)
	{
		if (rest%i) continue;
		while (rest%i==0) rest/=i;
		ans.insert(i);
	}
	
	if (rest>1) ans.insert(rest);
	rep(i,1,tot) if (chk(pri[i])) ans.insert(pri[i]);
	set<int>::iterator it=ans.begin();
	while (it!=ans.end())
	{
		printf("%d\n",*it);
		it++;
	}
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const long long N = 1e3 + 17;
ll cnt, ans, lnt, sum, n, l1, x, y, a[N], mx, b[N][N];
pair<ll,ll>pr[N];
vector<ll>v,v2,v3;
map<ll,ll>mp;
bool used[N], t1, t2;
vector<string>sv;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n >> x >> y;
    for(ll i = 0; i < x; i ++)
    {
        cin >> a[i];
    }
    for(ll i = 0; i < n; i ++)
    {
        for(ll j = 0; j < x; j ++)
        {
            cin >> b[i][j];
        }
    }
    for(ll i = 0; i < n; i ++)
    {
        sum = 0;
        for(ll j = 0; j < x; j ++)
        {
            sum += b[i][j] * a[j];
        }
        if(sum + y > 0)
        {
            cnt ++;
        }
    }
    cout << cnt;
    //cout << "\nTime Elapsed : " << clock () * 1.0 / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define vi vector<int>
using namespace std;

//int gcd(int a, int b){
//	return b==0 ? a : gcd(b, a%b);
//}

int32_t main(void){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	int arr[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	cin>>t;
	cout<<arr[t-1];
}





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

const int64_t inf = 1LL << 40;

int64_t a[5000], dp1[5000][5001], dp2[5000][5001], size[5000], merged1[5001], merged2[5001];
vector<int> graph[5000];

template <typename T>
void ChangeMin(T& var, T t) { var = min(var, t); }

void DFS(int root, int parent) {
  for (int num = 0; num <= 5000; num++) dp1[root][num] = dp2[root][num] = inf;

  size[root] = 1;

  dp1[root][1] = a[root] > 0 ? a[root] : inf;
  dp2[root][1] = a[root];

  for (int to : graph[root]) {
    if (to == parent) continue;

    DFS(to, root);

    for (int num = 1; num <= size[root] + size[to]; num++) merged1[num] = merged2[num] = inf;

    for (int num1 = 1; num1 <= size[root]; num1++) {
      for (int num2 = 1; num2 <= size[to]; num2++) {
        // 繋げない
        if (dp1[to][num2] < inf) {
          ChangeMin(merged1[num1 + num2], dp1[root][num1]);
          ChangeMin(merged2[num1 + num2], dp2[root][num1]);
        }
        if (dp2[to][num2] < 0) {
          ChangeMin(merged1[num1 + num2], dp1[root][num1]);
          ChangeMin(merged2[num1 + num2], dp2[root][num1]);
        }

        // 繋げる
        ChangeMin(merged1[num1 + num2 - 1], dp1[root][num1] + dp1[to][num2]);
        ChangeMin(merged2[num1 + num2 - 1], dp2[root][num1] + dp2[to][num2]);
      }
    }
    size[root] += size[to];
    for (int num = 1; num <= size[root]; num++) {
      dp1[root][num] = merged1[num];
      dp2[root][num] = merged2[num];
    }
  }
}

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

  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }

  DFS(0, -1);

  for (int num = 1; num <= n; num++) {
    if (dp1[0][num] < inf or dp2[0][num] < 0) {
      cout << num - 1 << endl;
      break;
    }
  }

  return 0;
}

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

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
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; }
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define endl "\n"
#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007
//グリッドグラフの範囲チェック
bool range_validation(int y,int x,int h,int w){
    return y>=0 && y<h && x>=0 && x < w;
}
//ビットカウント
int popcount(long bits){
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

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

vector<ll> sieve(ll n){
  vector<bool> is_prime(n+1,true);
  vector<ll> res;
  for(int i=2;i<=n;i++){
    if(is_prime[i]){
      res.push_back(i);
      for(int j=2*i;j<=n;j+=i){
        is_prime[j] = false;
      }
    }
  }
  return res;
}

vector<ll> divisor(ll n){
  vector<ll> list;
  for(int i=1;i*i<=n;i++){
    if(n%i==0){
      list.push_back(i);
      if(n/i != i){
        list.push_back(n/i);
      }
    }
  }
  return list;
}

umap<int,int> prime_factor(ll n){
  umap<int,int> fac;
  for(int i=2;i*i<=n;i+=2){
    if(n%i == 0){
      int count = 0;
      while(n%i == 0){
        count++;
        n /= i;
      }
      fac[i] = count;
    }
  }
  if(n!=1)fac[n] = 1;
  return fac;
}

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int n;
  cin >> n;
  int a[n];
  REP(i,n){
    cin >> a[i];
    a[i]--;
  }
  int light = 0;
  vector<bool> already(n,false);
  REP(i,n){
    if(light == 1){
	  cout << i << endl;
      break;
    }else if(already[light]){
      cout << -1 << endl;
      break;
    }else {
      already[light] = true;
      light = a[light];
      
    }
  }
  return 0;
}


Measured memory_bytes: 4012
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
string s;
vector<int> st;
int k,ans,n,cnt;
int main(void){
    cin>>s>>k;
    n=s.size();
    if(s.size()<k){
        cout<<0<<endl;
        return 0;
    }
    for(int i=0;i<s.size();i++){
        if(s[i]-'0'>0)st.push_back(i+1);
        if(st.size()>3)cnt+=(s[i]-'0');
    }
    if(k==1){
        ans=(s[0]-'0')+(s.size()-1)*9;
    }
    else if(k==3){
        if(st.size()>=3){
            ans+=((s[st[2]-1]-'0'));
            ans+=(n-st[2])*9;
        }
        if(st.size()>=2){
            ans+=((s[st[1]-1]-'0')-1)*(n-st[1])*9;
            ans+=(n-st[1])*(n-st[1]-1)/2*9*9;
        }
        ans+=((s[st[0]-1]-'0')-1)*(n-st[0])*(n-st[0]-1)/2*9*9;
        ans+=(n-st[0])*(n-st[0]-1)*(n-st[0]-2)/6*9*9*9;
    }
    else{
        if(st.size()>=2){
            ans+=((s[st[1]-1]-'0'));
            ans+=(n-st[1])*9;
        }
        //cout<<ans<<endl;
        ans+=((s[st[0]-1]-'0')-1)*(n-st[0])*9;
        ans+=(n-st[0])*(n-st[0]-1)/2*9*9;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;
int main(void){
    // Your code here!
    string s;
    cin >> s;
    int x[25] = {};
    
    for(int i = 0; i < s.size(); i++){
        int c = s[i];
        x[c - 'a']++;
    }
    
    for(int i =0; i < 25; i++){
        if(x[i] % 2){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
# Begin Header {{{
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement
# }}} End Header
# _________コーディングはここから！！___________
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
ans = 0
for x in combinations(l, 3):
    if x[0]!=x[1] and x[0]!=x[2] and x[1]!=x[2]:
        if x[0] + x[1] > x[2]:
            ans+=1
print(ans)

Measured memory_bytes: 9408
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

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

  int ans=0;
  for(int i=1;i<n-1;i++){
    if(p[i-1]<p[i]&&p[i]<p[i+1]) ans++;
    else if(p[i-1]>p[i]&&p[i]>p[i+1]) ans++;
  }

  cout<<ans<<endl;

  return 0;
}


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

int main()
{
   long long int n;
   cin>>n;
   long long int a[n];
   for(int i=0;i<n;i++)cin>>a[i];
   sort(a,a+n, greater<int>());
   if(n%2==0)
   {
       long long int sum=0;
       sum+=a[0];
       long long int k=n/2;
       for(int i=1;i<=k-1;i++)sum+=(2*a[i]);
       cout<<sum<<endl;
   }
   if(n&1)
   {
       long long int sum=0;
       sum+=a[0];
       int k=n/2 -1;
       for(int i=1;i<=k;i++)sum+=(2*a[i]);
       sum+=a[n/2];
       cout<<sum<<endl;
       
       
   }
}

Measured memory_bytes: 5196
/*
Author : Xinyuan
*/
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int  ll;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int nxt() {int x;scanf("%d", &x);return x;}


int main(){
    VI num(nxt());
    generate(all(num), nxt);
    sort(all(num));
    REP(i, num.size()) if(i && num[i-1] == num[i]) {
        printf("NO");
        return 0;
    }
    printf("YES");
    return 0;
}



Measured memory_bytes: 1024
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  int n,m;
  cin >> n >> m;
  int ans = 0;
  ans = n*(n-1)/2+m*(m-1)/2;
  cout << ans << endl;
  return 0;
}


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

int main()
{
	long int n,m;
    vector<pair<long int,long int> > ab;
    cin>>n>>m;
    for(long int i=0;i<n;i++){
        long int a,b;
        cin>>a>>b;
        ab.push_back(make_pair(a,b));
    }

    sort(ab.begin(),ab.end());
    long int v=0,money=0;
    for(long int i=0;i<n;i++){
        if(v+ab[i].second>=m){
            for(;v<m;v++){
                money+=ab[i].first;
            }
            break;
        }else{
            v+=ab[i].second;
            money+=ab[i].first*ab[i].second;
        }
    }

    cout<<money<<endl;

	return 0;
}


Measured memory_bytes: 2420
#!/usr/bin/ruby
def x(s) s.size>1&&s[0..0]=='X' end
while(l=gets)do
	if l.length<2 then raise l end
	raise l unless l.chomp=~/^([0-9X]+)\+([0-9X]+)=([0-9X]+)$/
	s=(x($1)||x($2)||x($3))?1:0
	a=$1+'+'+$2+'=='+$3
	puts 'NA' if s.step(9){|i|if eval(a.gsub('X',i.to_s)) then p i;break end}
end

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

int main() {
   string t = "CODEFESTIVAL2016";
   string s;
   cin >> s;
   int cnt = 0;
   rep (i, t.size()) {
      if (s[i] != t[i])cnt++;
   }
   cout << cnt << endl;

   return 0;
}

Measured memory_bytes: 764