akhauriyash/Code-Regression huggingface dataset:
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U> inline void cmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> inline void cmin(T &a, U b) { if (a > b) a = b; }
constexpr char el = '\n';
template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) os << v[i] << (i+1 != v.size() ? " " : ""); return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for(T &i : v) is >> i; return is; }
struct IoSetup {
  IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); }
} io_setup;
#line 2 "c.cpp"

int main() {
  ll h, w, k;
  cin >> h >> w >> k;
  vector<string> board(h);
  cin >> board;

  ll ans = 0;
  rep(ybit, 1LL<<h) {
    rep(xbit, 1LL<<w) {
      vector<vector<bool>> is_red(h, vector(w, false));
      rep(i, h) {
        if (ybit >> i & 1) {
          rep(j, w) {
            is_red[i][j] = true;
          }
        }
      }
      rep(j, w) {
        if (xbit >> j & 1) {
          rep(i, h) {
            is_red[i][j] = true;
          }
        }
      }
      ll cnt = 0;
      rep(i, h) {
        rep(j, w) {
          if (!is_red[i][j] and board[i][j] == '#') {
            cnt++;
          }
        }
      }
      if (cnt == k) ans++;
    }
  }

  cout << ans << el;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef vector<int> vint;
typedef vector<float> vfloat;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vstr> vvstr;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int n, T;
    cin >> n >> T;
    vint t(n);
    rep(i, n) cin >> t[i];
    
    int ans;
    ans = T;
    int erapsed = t[0] + T;
    srep(i, n, 1) {
        if (erapsed <= t[i]) ans += T;
        else ans += T - (erapsed - t[i]);
        erapsed = t[i] + T;
    }

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

Measured memory_bytes: 1024
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
void print_int(int n)
{
    printf("%d\n",n);
}

void swap(int * a, int * b)
{
    int t = *a;
    *a = *b;
    *b = t;
}

void sort(int a[], int n)
{
    for(int i = 1; i < n; i++)
    {
        int j = i-1;
        while(j >= 0 && a[j+1] > a[j])
        {
            swap(&a[j+1],&a[j]);
            j--;
        }
        
    }
    
}

void print_list(int a[], int n)
{
    for(int i = 0; i < n; i++)
    {
        print_int(a[i]);
    }
    
}



int main(void)
{
    int a,b,c,f = 0;
    scanf("%d %d %d",&a,&b,&c);
    if(a < b)
    {
        for(int i = a; i < b; i++)
        {
            if(i == c)
                f = 1;
        }
        
        
        
    }
    else
    {
        for(int i = a; i > b; i--)
        {
            if(i == c)
                f = 1;
        } 
         
    }
    
    if(f)
        printf("Yes\n");
    else
    {
        printf("No\n");
    }
    


    
    return 0;
}



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

int main(){
	int n;cin>>n;
	pair<int,int> t[n];
	rep(i,n) cin>>t[i].second>>t[i].first;

	sort(t,t+n);

	int s[n+1];s[0]=0;
	rep(i,n) s[i+1]=s[i]+t[i].second;

	bool ans=1;
	rep(i,n){
		if(s[i+1]>t[i].first){
			cout<<"No"<<"\n";
			return 0;
		}
	}
	cout<<"Yes"<<"\n";
	
}


Measured memory_bytes: 2560
#include <stdio.h>
#define MAX 500000
#define SENTINEL 2000000000

void merge(int *, int, int, int, int);
void mergeSort(int *, int, int, int);

int L[MAX/2+2],R[MAX/2+2];
int cnt;

int main(){
  int A[MAX],n,i;
  cnt = 0;

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

  mergeSort(A,n,0,n);

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

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

  return 0;
}

void merge(int A[], int n, int left, int mid, int right){
  int n1 = mid - left;
  int n2 = right - mid;
  for(int i=0; i<n1; i++) L[i] = A[left + i];
  for(int i=0; i<n2; i++) R[i] = A[mid + i];
  L[n1] = R[n2] = SENTINEL;
  int i=0, j=0;
  for(int k=left; k<right; k++){
    cnt++;
    if(L[i] <= R[j]){
      A[k] = L[i++];
    } else{
      A[k] = R[j++];
    }
  }
}

void mergeSort(int A[], int n, int left, int right){
  if(left+1 < right){
    int mid = (left + right) / 2;
    mergeSort(A, n, left, mid);
    mergeSort(A, n, mid, right);
    merge(A, n, left, mid, right);
  }
}



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

int main(){
  int amida[1000][100];// [m][n]
  while(1)
    {
      memset(amida,0,sizeof(amida));
      int n,m,a;
      cin >> n >> m >> a;
      if( n+m+a == 0 ) break;
      
      int h,p,q;
      for(int i=0;i < m;i++){
	cin >> h >> p >> q;
	amida[h-1][p-1] = q;
	amida[h-1][q-1] = p;
      }
      for(int i=999;i > -1;i--){
	if(amida[i][a-1]) a = amida[i][a-1];
      }
      cout << a << endl;
    }
  return 0;
}



Measured memory_bytes: 3500
main = interact $ unlines . map show . itp1_10_d . map (map read . words) . tail . lines

itp1_10_d [vx,vy] = [md 1, md 2, md 3, mdi]
 where
  md p = (sum (zipWith (\x y -> abs (x-y) ** p) vx vy)) ** (1/p)
  mdi = maximum (map abs (zipWith subtract vx vy))

Measured memory_bytes: 4320
#include <stdio.h>
#include <stdlib.h>

int judge(int i, int n, char *s, char *t, char animal) {
  if (i == n) {
    if ((t[i - 1] == 'S' && s[i - 1] == 'o') || (t[i - 1] == 'W' && s[i - 1] == 'x')) {
      if (t[i - 2] != t[0])
	return -1;
    } else {
      if (t[i - 2] == t[0])
	return -1;
    }
    if ((t[0] == 'S' && s[0] == 'o') || (t[0] == 'W' && s[0] == 'x')) {
      if (t[i - 1] != t[1])
	return -1;
    } else {
      if (t[i - 1] == t[1])
	return -1;
    }
    return 0;
  }
  
  t[i] = animal;
  
  if ((t[i] == 'S' && s[i] == 'o') || (t[i] =='W' && s[i] == 'x'))
    return judge(i + 1, n, s, t, t[i - 1]);
  else {
    if (t[i - 1] == 'S')
      return judge(i + 1, n, s, t, 'W');
    else
      return judge(i + 1, n, s, t, 'S');
  }
}

int main() {
  long int n;
  char *s, *t;
  
  scanf("%ld\n", &n);
  s = (char *)malloc(sizeof(char) * (n + 1));
  t = (char *)malloc(sizeof(char) * (n + 1));
  scanf("%s", s);
  t[n] = '\0';
  t[0] = 'S';
  if (judge(1, n, s, t, 'S') == 0)
    printf("%s\n", t);
  else if (judge(1, n, s, t, 'W') == 0)
    printf("%s\n", t);
  else {
    t[0] = 'W';
    if (judge(1, n, s, t, 'S') == 0)
      printf("%s\n", t);
    else if (judge(1, n, s, t, 'W') == 0)
      printf("%s\n", t);
    else
      printf("-1\n");
  }
  free(s);
  free(t);
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    int n;
    cin >> n;
    if(n==1) cout << 1 << endl;
    else if(n<4) cout << 2 << endl;
    else if(n<8) cout << 4 << endl;
    else if(n<16) cout << 8 << endl;
    else if(n<32) cout << 16 << endl;
    else if(n<64) cout << 32 << endl;
    else  cout << 64 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <assert.h>
#include <cstdio>

// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

inline bool chmin(ll &a, ll b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

inline bool chmax(ll &a, ll b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

//桁数取得
template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}
//整数乗
ll llpow(ll a, ll n)
{
    if (n == 0)
    {
        return 1;
    }
    else
    {
        ll rep = a;
        for (ll i = 1; i < n; i++)
        {
            rep *= a;
        }
        return rep;
    }
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

template <typename T>
T amarinasi(T a, T b)
{
    if (a % b == 0)
    {
        return a / b;
    }
    else if (a % b > 0)
    {
        return a / b + 1;
    }
    else
    {
        return a / b - 1;
    }
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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

int main()
{
    std::cout << std::fixed << std::setprecision(10);
    ll a, b, h, w;
    cin >> a >> b >> h >> w;
    static const double pi = 3.141592653589793;
    double kakudo1 = (2 * pi * h) / (double)12 + ((double)0.261799387799 * w * 2) / 60;
    double kakudo2 = (2 * pi * w) / (double)60;
    double kakudo;
    if (kakudo1 > kakudo2)
    {
        kakudo = kakudo1 - kakudo2;
    }
    else
    {
        kakudo = kakudo2 - kakudo1;
    }
    double ans = a * a + b * b - 2 * a * b * cos(kakudo);
    cout << sqrt(ans) << endl;
}


Measured memory_bytes: 4292
#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <map>

using namespace std;

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

    int n;
    cin >> n;
    
    int i = 1;
    int ans = 0;
    
    while(1)
    {
        if (1000 * i >= n)
        {
            ans = 1000 * i - n;
            break;
        } else {
            i++;
        }
    }
    
    cout << ans << endl;
    
}


Measured memory_bytes: 3628
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int a, b, c;
    cin >> a >> b >> c;
    int d = a - b;
    if (c <= d)
        cout << 0 << endl;
    else
        cout << c - d << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}

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

  ll a, b, c ; cin >> a >> b >> c;
  if((b-a) == (c-b)) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long a = sc.nextLong();
    long b = sc.nextLong();
    long k = n/(a+b);
    
    if(a==0){
    System.out.print("0");
    }else if(n%(a+b)<=a){
    System.out.println(a*k+n%(a+b));
    }else{
    System.out.println(a*k+a);
}
}
}

Measured memory_bytes: 35732
#include <stdio.h>

#define sq(x) ((x) * (x))

int N;
int a[101];
int ans = 1 << 30;

int main(void)
{
	int i, j;

	scanf("%d", &N);
	for (i = 0; i < N; ++i)
	{
		scanf("%d", &a[i]);
	}

	for (j = -100; j <= 100; ++j)
	{
		int tmp = 0;
		for (i = 0; i < N; ++i)
		{
			tmp += sq(a[i] - j);
		}
		if (tmp < ans) ans = tmp;
	}
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 1732
#include <stdio.h>
int main(void){
    /* 変数宣言，ちゃんと初期化しよう */
    int N = 0;
    int K = 0;
    int ans = 0;
    /* 変数宣言終わり */
    
    /* 入力を受け付ける部分*/
    
    // %dはdecimalの略．つまり，入力を10進数として扱うよという意味．
    scanf("%d %d", &N, &K);
    
    /* 入力を受け付ける部分終わり*/
    
    
    /* 何か処理*/
    ans = N % K ;
    
    if(ans == 0){
      /* 真の場合の処理 */
      ans = 0;
    }else{
      /* 偽の場合の処理 */
      ans = 1;
    }
    
    for(int i = 0; i < 10; i++){ 
      // i = 0,1,2,3,4,5,6,7,8,9のとき処理される
      
    }
    
    /* 何か処理終わり*/
    
    
    /* 出力する部分*/
    
    printf("%d", ans); // %dの部分にansの値が表示される
    
    /* 出力する部分*/
    
    
    
    return 0;
}


Measured memory_bytes: 128
l = int(input())
tmp = list(map(int, input().split()))
lst = list(map(lambda x: x if x > 0 else x*-1, tmp))

minus = list(filter(lambda x: x < 0, tmp))

ans = 0
if len(minus) % 2 == 0:
    ans = sum(lst)
else:
    ans = sum(lst) - (abs(min(lst))*2)

print(ans)


Measured memory_bytes: 14208
#include <iostream>
#define ll long long
using namespace std;

const ll inf = 0x7f7f7f7f7f7f7f7f;
const int MAXN = 100;
int x[MAXN], y[MAXN];

int main(void){
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < n; i++){
		cin >> x[i] >> y[i];
	}
	ll sol = inf;
	for(int i = 0; i < n; i++){
		for(int j = i + 1; j < n; j++){
			if(m >= 3){
				for(int k = j + 1; k < n; k++){
					if(m == 3){
						ll x1 = min(x[i], min(x[j], x[k]));
						ll x2 = max(x[i], max(x[j], x[k]));
						ll y1 = min(y[i], min(y[j], y[k]));
						ll y2 = max(y[i], max(y[j], y[k]));
						int cnt = 0;
						for(int h = 0; h < n; h++){
							if(x[h] >= x1 && x[h] <= x2 && y[h] >= y1 && y[h] <= y2) cnt++;
						}
						if(cnt >= m) sol = min(sol, (x2 - x1) * (y2 - y1));
					}else{
						for(int l = k + 1; l < n; l++){
							ll x1 = min(x[i], min(x[j], min(x[k], x[l])));
							ll x2 = max(x[i], max(x[j], max(x[k], x[l])));
							ll y1 = min(y[i], min(y[j], min(y[k], y[l])));
							ll y2 = max(y[i], max(y[j], max(y[k], y[l])));
							int cnt = 0;
							for(int h = 0; h < n; h++){
								if(x[h] >= x1 && x[h] <= x2 && y[h] >= y1 && y[h] <= y2) cnt++;
							}
							if(cnt >= m) sol = min(sol, (x2 - x1) * (y2 - y1));
						}
					}
				}
			}else{
				ll x1 = min(x[i], x[j]);
				ll x2 = max(x[i], x[j]);
				ll y1 = min(y[i], y[j]);
				ll y2 = max(y[i], y[j]);
				sol = min(sol, (y2 - y1) * (x2 - x1));
			}
		}
	}
	cout << sol << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
int a, b, t;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a>>b>>t;
    int temp=t/a;
    int ans=temp*b;
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    map<ll, ll> b;
    in_arr(int, a, n);
    ll sum = 0;
    ++b[sum % m];
    rep(i, n){
        sum += a[i];
        ++b[sum % m];
    }
    sum = 0;
    repi(i, b){
        ll c = i->second;
        sum += c * (c - 1) / 2;
    }
    cout << sum << endl;
    return 0;
}


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

int const N = 2e5 + 7;

int n, m, k;
long long A[N] = {}, B[N] = {};

int binser(int num)
{
	int lt = 1, rt = m+1;
	while (lt < rt)
	{
		int mid = (lt + rt) / 2;
		if (B[mid] <= num) lt = mid + 1;
		else rt = mid;
	}
	return lt-1;
}

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

	for (int i = 1; i <= n; ++i)
	{
		cin >> A[i]; A[i] += A[i-1];
	}
	for (int i = 1; i <= m; ++i)
	{
		cin >> B[i]; B[i] += B[i-1];
	}

	int res = 0;
	for (int i = 0; i <= n; ++i)
	{
		if (A[i] > k)
			break;
		res = max(res, i + binser(k - A[i]));
	}
	cout << res << '\n';
	return 0;
}

Measured memory_bytes: 6756
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

int main(){
    string s ;
    cin >> s ;
    for (size_t i = 0; i < s.size()-1; i++)
    {
        if (s.at(i) != s.at(i+1))
        {
            cout << "Yes" << endl ;
            return 0;
        }
        
    }
    cout << "No" << endl ;
}

Measured memory_bytes: 256
/*                                  deepyadav442 --> :     c++14     <--                                */
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
/*                                           input                    */
#define si(i) scanf("%d",&i)
#define sii(i,j) scanf("%d%d",&i,&j)
#define siii(i) scanf("%lld",&i)
/*                                           output                   */
#define pi(i) printf("%d",i)
#define pii(i,j) printf("%d%d",i,j)
#define piii(i) printf("%lld",i)
#define space printf(" ")
#define newline printf("\n")
/*                                          loops &stls                      */
#define loop(i,s,n) for(i=s;i<n;i++)
#define looprev(i,s,n) for(i=s;i>=n;i--)
#define itervec vector<int>::iterator itv
#define iterrev vector<int>::reverse_iterator it
#define itermap map<string,int>::iterator itm
#define pb(S) push_back(S)
#define mp(i,j) make_pair(i,j)
#define f first
#define s second
#define MAX(a,b) 	(a>b) ? (a) : (b)
#define MIN(a,b) 	(a<b) ? (a) : (b)
using namespace std;
int main()
{
    int arr[10];
    si(arr[0]),si(arr[1]),si(arr[2]);
    sort(arr,arr+3);
    pi(arr[0]+arr[1]);
    space;
    return 0;
}

/*   fast input output
inline ll input() //for input integers call it long long int n=input();
{
    ll n=0;
    char ch=getchar_unlocked();
    while( ch < '0' || ch > '9' )
    {
        ch=getchar_unlocked();
    }
    while( ch >= '0' && ch <= '9' )
    {
        n = (n<<3)+(n<<1) + ch-'0', ch=getchar_unlocked();
    }
    return n;
}
inline void output(ll n)     //for output call output(count) and then for space use put('\n');
{
    char b[35];
    ll i=0;
    do
    {
        b[i++]=n%10+48;
        n=n/10;
    }while(n!=0);
    --i;
    while(i>=0)
    putchar_unlocked(b[i--]);
}
inline void faststring(char *str)  //for entering a string use faststring(p);
{
    register char c = 0;
    register long long i = 0;
    while (c < 33)
    c = getchar_unlocked();
    while (c != '\n')
    {
        str[i] = c;
        c = getchar_unlocked();
        ++i;
    }
    str[i] = '\0';
}


*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  
  if(S.at(0) == S.at(1) || S.at(1) == S.at(2) || S.at(2) == S.at(3)){
  	cout << "Bad" << endl;
  }else{
  	cout << "Good" <<  endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String a[] = sc.next().split("");
        String b[] = sc.next().split("");
        
        if(a[0].equals(b[2]) && a[2].equals(b[0]) && a[1].equals(b[1])) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

int main(int argc, char **argv)
{
	ll a, b, c, k; cin >> a >> b >> c >> k;
	ll res{0};

	if (a + b >= k)
		std::cout << min(a, k) << std::endl;
	else
	{
		std::cout << -(k - (a + b)) + a<< std::endl;
	}
}


Measured memory_bytes: 3624
#include <cstdio>
#include <algorithm>
using namespace std;

const int INF = 1000000000;

int main()
{
  int n, v1, v2;
  scanf("%d", &n);

  int m[n + 1][n + 1], p[n + 1];
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++)
      m[i][j] = INF;

  for (int i = 0; i <= n; i++)
    m[i][i] = 0;

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

  for (int l = 2; l <= n; l++)
    for (int i = 1; i <= n - l + 1; i++)
    {
      int j = i + l - 1;
      for (int k = i; k < j; k++)
        m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
    }

  printf("%d\n", m[1][n]);
  return 0;
}

Measured memory_bytes: 2748
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(n,v) cout<<#v<<":";for(int i=0;i<n;i++)cout<<v[i]<<" ";cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

int main(){
    int n;cin>>n;
    vector<tuple<ll,ll,ll>> v;
    rep(i,n){
        ll a,b;
        cin>>a>>b;
        v.push_back(make_tuple(a+b,a,b));
    }
    sort(ALL(v));
    ll choku=0,aoki=0;
    rep(i,n){
        //choku
        if(i%2==0){
            choku+=get<1>(v[n-i-1]);
        }
        else{
            aoki+=get<2>(v[n-i-1]);
        }
    }
    cout<<choku-aoki<<endl;
    return 0;
}

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

int main() {
	string S; cin >> S;
	vector<string>K;
	string T = "";
	for (int i = 0; i < S.size(); i++) {
		T.push_back(S.at(i));
		if (K.empty()){
			K.push_back(T);
			T = "";
		}
		else {
			if (K.back() != T) {
				K.push_back(T);
				T = "";
			}
		}
	}
	cout << K.size() << endl;
}

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

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

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

        if x == y:
            return

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

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

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

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

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

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

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

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



n,m=map(int,input().split())
p = [int(i)-1 for i in input().split() ]

uf = UnionFind(n)
for i in range(m):
    x,y = map(int,input().split())
    uf.union(x-1,y-1)

print(sum(uf.same(i,p[i]) for i in range(n) ) )

Measured memory_bytes: 84808
N,M,X,Y = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
max_X = max(X,max(x))
min_Y = min(Y,min(y))

if max_X<min_Y:
    print("No War")
else:print("War")


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

int main()
{
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
    return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
 
  if (a < b) {
    cout << 2*b - 1 << endl;
  }
  else if (a > b) {
    cout << 2*a - 1 << endl;
  }
  else if (a == b) {
    cout << 2*a << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int a;
    cin>>a;
    int arr[3][a], dp[3][a];
    for (int i=0; i<a; i++){
        for (int j=0; j<3; j++){
            cin>>arr[j][i];
            dp[j][i]=0;
        }
    }
    dp[0][0]=arr[0][0], dp[1][0]=arr[1][0], dp[2][0]=arr[2][0];
    for (int i=0; i<a-1; i++){
        for (int j=0; j<3; j++){
            for (int k=0; k<3; k++){
                if (k==j) continue;
                dp[k][i+1]=max(dp[k][i+1], dp[j][i]+arr[k][i+1]);
            }
        }
    }
    cout<<max(dp[0][a-1], max(dp[1][a-1], dp[2][a-1]))<<endl;
}

Measured memory_bytes: 2560
def comb(n, k)
  res = 1
  i = n
  while i >= n-k+1
    res *= i
    i -= 1
  end
  while k > 0
    res /= k
    k -= 1
  end
  res
end
MOD = 10**9+7
n, m = gets.split.map(&:to_i)
i = 2
f = Hash.new(0)
while i * i <= m
  while m % i == 0
    m /= i
    f[i] += 1
  end
  i += 1
end
f[m] = 1 if m != 1
ans = 1
f.each do |k,v|
  ans *= comb(n+v-1, v)
  ans %= MOD
end
p ans


Measured memory_bytes: 1788
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include "bits/stdc++.h"

using namespace std;

typedef unsigned long long ll;
typedef int                     integer;
#define int                     long long
#define ii                      pair<int,int>
#define vii                     vector<pair<int,int>>
#define vi                      vector<int>
#define vvi                     vector<vector<int>>
#define f(a,b,c)                for(int a=b;a<c;a++)
#define s(x)                    in>>x
#define s2(x,y)                 in>>x>>y
#define s3(x,y,z)               in>>x>>y>>z
#define s4(x,y,z,w)             in>>x>>y>>z>>w
#define p(x)                    out<<x<<endl
#define p2(x,y)                 out<<x<<" "<<y<<endl
#define pl(x)                   out<<x
#define p2l(x,y)                out<<x<<" "<<y
#define p1d(a,n)                for(int ix=0;ix<n;ix++) out<<a[ix]<<" "; out<<endl
#define p2d(a,n,m)              for(int ix=0;ix<n;ix++){ for(int jx=0;jx<m;jx++) out<<a[ix][jx]<<" "; out<<endl;}
#define range(v)                v.begin(),v.end()
#define w(x)                    while(x--)
#define rst(x)                  memset(x, -1, sizeof(x))
#define UNVISITED               -1
#define VISITED                 0
#define EXPLORED                2

class BIMissYou {
public:
	void solve(std::istream& in, std::ostream& out) {
        string s;
        s(s);
        f(i,0,s.size()) out<<'x';
        out<<endl;
	}
};


integer main() {
	BIMissYou solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int n = N%10;
    if(n==3) cout << "bon\n";
    else if(n==0 || n==1 || n==6 || n==8) cout << "pon\n";
    else cout << "hon\n";
}

Measured memory_bytes: 3648
#ABC088C
import sys

c=[map(int,raw_input().split()) for i in xrange(3)]
a=[0,0,0]
b=[0,0,0]
b[0],b[1],b[2]=c[0][0]-a[0],c[0][1]-a[0],c[0][2]-a[0]
a[1],a[2]=c[1][0]-b[0],c[2][0]-b[0]
for i in xrange(3):
 for j in xrange(3):
  if c[i][j]!=a[i]+b[j]:
   print 'No'
   sys.exit()
print 'Yes'


Measured memory_bytes: 2692
from collections import defaultdict

N = int(input())
d = defaultdict(lambda: 0)
for i in range(N):
    d[input()] += 1

print('AC x ' + str(d['AC']))
print('WA x ' + str(d['WA']))
print('TLE x ' +str(d['TLE']))
print('RE x ' + str(d['RE']))


Measured memory_bytes: 9428
#include <stdio.h>

int main(void)
{
  int x[3];
  int pick;
  int sum;
  int i;
  scanf("%d%d%d%d", &x[0], &x[1], &x[2], &pick);
  i = 1;
  sum = 0;
  while(1){
    if (x[0] != 0 && pick > 0){
      sum++;
      x[0]--;
      pick--;
    }else break;
  }
  while(1){
    if (x[1] != 0 && pick > 0){
      x[1]--;
      pick--;
    }else break;
  }
  while(1){
    if (x[2] != 0 && pick > 0){
      sum--;
      x[2]--;
      pick--;
    }else break;
  }
  printf("%d\n", sum);
  
  return (0);
  
  
}

Measured memory_bytes: 1732
integer N,baseline
integer,allocatable,dimension(:)::H
logical check
read*,N
allocate(H(N))
read*,H
check=.true.
baseline=H(1)-1
do i=2,N
  if(H(i)>=baseline+1)baseline=H(i)-1
  if(H(I) < baseline)check=.false.
end do
print"(A)",merge("Yes","No ",check)
end

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <queue>
using namespace std;

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

int main(){
    int a,b; cin >> a >> b;
    printf("%.16lf\n", (double) a / (double) b);
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
	int n;
	cin >> n;
	cout<<n/3600<<':'<<n%3600/60<<':'<<n%60<<endl;
	return 0;
}


Measured memory_bytes: 3100
n,m=list(map(int,input().split()))
graph=[[] for _ in range(n)]
res=0
for i in range(m):
  a,b=list(map(int,input().split()))
  graph[a-1].append(b)
  graph[b-1].append(a)

def solve(s,p):
  global res
  dp=format(s,'08b')[::-1]
  if s == (1<<n)-1 :
    res += 1
    return res
  for u in graph[p-1]:
    if dp[u-1] == '1':
      continue
    res = solve(s|(1<<(u-1)),u)
  return res

print(solve(1,1))

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

int main(){
  int N;
  while(cin >> N, N){
    vector<int> HP(N);
    for(int i = 0; i < N; ++i){
      cin >> HP[i];
    }
    int M;
    cin >> M;
    vector<int> single_d, single_mp, all_d, all_mp;
    string name, target;
    int mp, damege;
    for(int i = 0; i < M; ++i){
      cin >> name >> mp >> target >> damege;
      if(target == "Single"){
        single_d.push_back(damege);
        single_mp.push_back(mp);
      }else{
        all_d.push_back(damege);
        all_mp.push_back(mp);
      }
    }
    long long int INF = 1e10, n = 2e5;
    vector<int> dp1(n,INF), dp2(n,INF);
    dp1[0] = 0;
    dp2[0] = 0;
    for(int i = 0; i < single_d.size(); ++i){
      for(int j = 0; j < n; ++j){
        if(dp1[j] >= INF) continue;
        if(j + single_d[i] < n)
          dp1[j + single_d[i]] = min(dp1[j + single_d[i]], dp1[j] + single_mp[i]);
        else
          dp1[n-1] = min(dp1[n-1], dp1[j] + single_mp[i]);
      }
    }
    for(int i = n-2; i >= 0; --i) dp1[i] = min(dp1[i], dp1[i+1]);
    for(int i = n-2; i >= 0; --i) dp2[i] = min(dp2[i], dp2[i+1]);
    
    for(int i = 0; i < all_d.size(); ++i){
      for(int j = 0; j < n; ++j){
        if(dp2[j] >= INF) continue;
        if(j + all_d[i] < n)
          dp2[j + all_d[i]] = min(dp2[j + all_d[i]], dp2[j] + all_mp[i]);
        else
          dp2[n-1] = min(dp2[n-1], dp2[j] + all_mp[i]);
      }
    }
    long long int ans = INF;
    for(int i = 0; i < n; ++i){
      if(dp2[i] >= INF) continue;
      long long int t = dp2[i];
      for(int j = 0; j < N; ++j){
        t += dp1[max(0,HP[j] - i)];
      }
      ans = min(ans,t);
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 4464
n=int(input())
s=list(input())
t=[0]*int(n/2)
if n%2==0:
  for k in range(0,int(n/2)):
    t[k]=s[k]
  t=t*2
  if t==s:
    print("Yes")
  else:
    print("No")

else:
  print("No")

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

void A(){
    ll N,K; cin >> N >> K;
    vector<ll> A(N); for(auto& in:A) cin >> in;
    vector<ll> x(200001);
    set<ll> s;
    for(int i = 0; i < N;i++){
        x[A[i]]++;
        s.insert(A[i]);
    }
    sort(x.begin(),x.end());
    ll ans = 0;
    for(int i = 0; i <= 200000;i++){
        if(s.size() <= K) break;
        if(x[i] == 0) continue;
        ans += x[i];
        s.erase(*s.begin());
    }
    cout << ans << endl;
}

void B(){
    ll N; cin >> N;
    vector<ll> a(N); for(auto& in:a) cin >> in;
    map<ll,ll> mp;
    for(int i = 0; i < N;i++) mp[a[i]]++;
    ll ans = 0;
    for(auto p:mp){
        if(p.first < p.second) ans += (p.second-p.first);
        if(p.second < p.first) ans += p.second;
    }
    cout << ans << endl;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    //A();
    B();
    return 0;
}


Measured memory_bytes: 7040
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);

int f(int x){
  if(x%2 == 0) return x/2;
  else return 3*x + 1;
}

int main(){
  int s;
  cin >> s;
  const int INF = 1000005;
  vector<int> a(INF);

  REP(i,INF){
    if(i == 0){
      a[i] = s;
      continue;
    }
    a[i] = f(a[i-1]);
  }

  vector<int> b(INF);

  REP(i,INF) b[i] = 0;

  REP(i,INF){
    ++b[a[i]];
    if(b[a[i]] > 1){
      cout << i + 1 << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 11068
#include <iostream>
#include <math.h>
using namespace std;

int main(){
    long long A, B, N;
    cin >> A >> B >> N;
    if(N >= B){
        cout << (A * (B - 1)) / B - A * ((B - 1) / B);
    }
    else cout << (A * N) / B - A * (N / B);
}

Measured memory_bytes: 3560
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n, m, a;
		while ((n = in.nextInt()) != 0) {
			m = in.nextInt();
			a = in.nextInt();
			int max = 0;
			int[][] amida = new int[1000][n + 1];
			for (int i = 0; i < m; i++) {
				int h = in.nextInt() - 1;
				int p = in.nextInt();
				int q = in.nextInt();
				amida[h][p] = q;
				amida[h][q] = p;
				max = Math.max(h, max);
			}
			for (int h = max; h >= 0; h--) {
				if (amida[h][a] != 0) {
					a = amida[h][a];
				}
			}
			System.out.println(a);
		}
		in.close();
	}

}

Measured memory_bytes: 71056
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

class UnionFind {
    int n;
    vector<int> uni;
    int forest_size;
public:
    vector<int> dp;
    explicit UnionFind(int n) : n(n), uni(static_cast<u32>(n), -1), forest_size(n), dp(n) {};

    int root(int a){
        if (uni[a] < 0) return a;
        else return (uni[a] = root(uni[a]));
    }

    bool unite(int a, int b) {
        a = root(a);
        b = root(b);
        if(a == b) return false;
        if(uni[a] > uni[b]) swap(a, b);
        uni[a] += uni[b];
        dp[a] += dp[b];
        uni[b] = a;
        forest_size--;
        return true;
    }
    int size(){ return forest_size; }
    int size(int i){ return -uni[root(i)]; }
    bool same(int a, int b) { return root(a) == root(b); }
};

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind uf(n+m);
    for (int i = 0; i < m; ++i) {
        uf.dp[i+n]++;
    }
    for (int i = 0; i < k; ++i) {
        int a, x, y;
        scanf("%d %d %d", &a, &x, &y);
        x--; y--;
        if(a == 1){
            uf.unite(x, y);
        }else {
            uf.unite(x, y+n);
        }
        if(uf.dp[uf.root(x)] >= 2){
            printf("%d\n", i+1);
            return 0;
        }
    }
    puts("0");
    return 0;
}


Measured memory_bytes: 4380
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

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

    map<char, vector<int>> m;
    for(int i=0; i<s.length(); i++){
        m[s[i]].push_back(i);
    }

    for(int i=0; i<t.length(); i++){
        if(m[t[i]].empty()){
            cout << -1 << endl;
            return 0;
        }
    }

    int tid = 0;
    int sid = 0;
    ll ans = 1;
    while(tid != t.length()){
        // cout << sid << " " << tid << endl;
        auto it = lower_bound(m[t[tid]].begin(), m[t[tid]].end(), sid);
        if(it == m[t[tid]].end()){
            ans = ans + s.length();
            sid = 0;
            it = lower_bound(m[t[tid]].begin(), m[t[tid]].end(), sid);
        }
        sid = *it + 1;
        tid++;
    }

    cout << ans + sid-1 << endl;

    return 0;
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,b; 
    cin >> a >> b;
    if(a != 1 and b != 1) cout << 1 << "\n";
    if(a != 2 and b != 2) cout << 2 << "\n";
    if(a != 3 and b != 3) cout << 3 << "\n";    
}

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

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {

		int N = nextInt();
		int[] A = new int[N+1];
		boolean[] flg = new boolean[N+1];
		for(int i=1;i<A.length;i++){
			A[i]=nextInt();
		}
		Arrays.fill(flg, true);

		int ans = 0;
		int idx=A[1];
		flg[1]=false;
		for(int i=1;i<=N;i++){
			if(flg[idx]){
				flg[idx]=false;
				ans++;
				if(idx==2){
					break;
				}
				idx=A[idx];

			}else{
				break;
			}
		}

		if(flg[2]){
			ans=-1;
		}
		System.out.println(ans);
	}

	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


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

ll INF = 1LL << 60;
using G = vector<map<int, int>>;

int 
main() {
  int N; cin >> N;
  vector<ll> num(100001);
  ll acum = 0;
  rep(i, 0, N){
    ll tmp; cin >> tmp;
    num[tmp]++;
    acum += tmp;
  }

  int Q; cin >> Q;
  vector<pair<int, int>> q(Q);
  rep(i, 0, Q) cin >> q[i].first >> q[i].second;

  rep(i, 0, Q){
    int B = q[i].first;
    int C = q[i].second;
    num[C] += num[B];
    acum = acum + (num[B] * (C - B));
    num[B] = 0;
    cout << acum << endl;
  }

}

Measured memory_bytes: 4648
#include <iostream>
#include <math.h>

using namespace std;

int main() {
    int N;
    std::cin>>N;
    int a[N];
    int sum=0;
    int max =0;
    for(int i=0;i<N;i++){
        cin>>a[i];
        sum+=a[i];
        if(a[i]> max) max=a[i];
    }
    
    sum = sum-max/2;
    cout << sum << endl;
}


Measured memory_bytes: 256
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#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
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}


long double ans = 0,a;

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

	
	int n;
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> a;
		ans+= (1.0000/a);
	}
	ans = 1.0000/ans;
	cout << fixed << setprecision(10)  << ans << endl;

return 0;
}
///....


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:1024000000")
#pragma warning( disable : 6031)
#pragma warning( disable : 4244)
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdint>
#include <climits>
#include <cassert>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <chrono>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef vector<ll> vll;
typedef vector<vector<long long>> vvll;
typedef tuple<int, int, int> tiii;
const long long mod = int(1e8);
const double eps9 = 1e-9;


int main() {
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
	string s;
	cin >> s;
	int res = 0;
	for (int i = 0; i < sz(s) / 2; i++)
	{
		if (s[i] != s[sz(s) - 1 - i])
			res++;
	}
	cout << res;
	return 0;
}

Measured memory_bytes: 256
import collections
import functools
import sys


sys.setrecursionlimit(10 ** 9 + 7)

@functools.lru_cache(maxsize=None)
def c(x, y):
    if y == 0 or x == y:
        return 1
    else:
        return c(x - 1, y - 1) + c(x - 1, y)


n, a, b = map(int, input().split())
v = list(map(int, input().split()))

v.sort(reverse=True)
avg = sum(v[:a]) / a

counter = collections.Counter(v)
if v[0] == v[a - 1]:
    x = counter[v[0]]
    comb = sum(c(x, y) for y in range(a, min(x, b) + 1))
else:
    comb = 1
    for z, y in collections.Counter(v[:a]).items():
        x = counter[z]
        comb *= c(x, y)

print(avg)
print(comb)


Measured memory_bytes: 39920
#include <bits/stdc++.h>
using namespace std;
int h[100011]  , dp[100011];

int main() {
	int n ; 
	scanf("%d" , &n) ; 
	for (int i =0 ; i<n ; ++i) {
		scanf("%d" , &h[i]) ; 
	}
	dp[0] =  0;
	dp[1] = abs(h[1]-h[0]) ; 
	for (int i = 2 ; i<n ; ++i){
		int mn1 = abs(h[i]- h[i-1]) ;
		int mn2 = abs(h[i]- h[i-2]) ; 
		dp[i] = min(mn1+dp[i-1] , mn2+dp[i-2]) ; 
	}
	printf("%d\n" , dp[n-1]) ; 
	return 0;
}

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

using namespace std;

int p[100010];
int n,m;
int cnt[100010];
int ans;

int fifa(int x)
{
	int t=x;
	while(p[t]!=t)
	{
		t=p[t];
	}
	while(p[x]!=t)
	{
		int tmp=p[x];
		p[x]=t;
		x=tmp;
	}
	return t;
}

void join(int x,int y)
{
	int px=fifa(x);
	int py=fifa(y);
	if(px!=py)
	{
		p[px]=py;
	}
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		p[i]=i;
	}
	for(int i=1;i<=m;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		join(a,b);
	}
	for(int i=1;i<=n;i++)
	{
		if(fifa(i)==i)
		{
			ans++;
		}
	}
	printf("%d\n",ans-1);
	return 0;
}


Measured memory_bytes: 4152