akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                    \
  ifstream in("abc173/abc173_e.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main() {
  INPUT_FILE CIN_OPTIMIZE;

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

  vector<ll> p(0);
  vector<ll> m(0);
  vector<ll> c(0);
  rep(i, N) {
    ll d;
    cin >> d;
    if (d >= 0) {
      p.push_back(d);
    } else if (d < 0) {
      m.push_back(d);
    }
    c.push_back(d);
  }

  mint ans = 1;
  bool ok = true;
  int P = p.size();
  int M = m.size();
  if (P > 0) {
    if (N == K) {
      ok = M % 2 == 0;
    } else {
      ok = true;
    }
  } else {
    ok = K % 2 == 0;
  }

  if (!ok) {
    sort(c.begin(), c.end(), [](ll x, ll y) { return abs(x) < abs(y); });
    rep(i, K) { ans *= c[i]; }
  } else {
    sort(p.begin(), p.end());
    sort(m.rbegin(), m.rend());
    if(K % 2 == 1) {
      // 奇数のときは、予め正の数を１つとっておく
      ans *= p.back();
      p.pop_back();
    }

    // ペアを作る
    vector<ll> pair(0);
    while(p.size() >= 2) {
      ll x = p.back();
      p.pop_back();
      x *= p.back();
      p.pop_back();
      pair.push_back(x);
    }
    while(m.size() >= 2) {
      ll x = m.back();
      m.pop_back();
      x *= m.back();
      m.pop_back();
      pair.push_back(x);
    }

    sort(pair.rbegin(), pair.rend());
    rep(i, K/2) { ans *= pair[i]; }
  }

  cout << ans << endl;
}

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

void fnInput(int& rnTrgSu, int& rnTrgKin)
{
  cin >> rnTrgSu >> rnTrgKin;
}

int fnRcsSch(int nPos, int nTrgSu, int nTrgKin, vector<int>& rvnNumMoney)
{
  vector<int> vnMoney{10000, 5000, 1000};

  if (nTrgKin < 0)  return -1;
  if (nPos == rvnNumMoney.size() - 1)
  {
    rvnNumMoney[nPos] = nTrgSu;
    if (nTrgKin - vnMoney[nPos] * nTrgSu == 0)
      return 1;
    else
      return 0;
  }

  for (int i = 0; i <= nTrgSu; i++)
  {
    rvnNumMoney[nPos] = i;
    int nRtn = fnRcsSch(nPos + 1, nTrgSu - i, nTrgKin - vnMoney[nPos] * i, rvnNumMoney);
    if      (nRtn == -1)  return 0;
    else if (nRtn)        return 1;
  }

  return 0;
}

int fnExhSch(int nTrgSu, int nTrgKin)
{
  vector<int> vnNumMoney(3);

  if (fnRcsSch(0, nTrgSu, nTrgKin, vnNumMoney))
    cout << vnNumMoney[0] << " " << vnNumMoney[1] << " " << vnNumMoney[2] << endl;
  else
    cout << -1 << " " << -1 << " " << -1 << endl;
}

int main()
{
  int nTrgSu, nTrgKin;
  
  fnInput(nTrgSu, nTrgKin);
  fnExhSch(nTrgSu, nTrgKin);

  return 0;
}
 

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

const ll MOD = 1e9 + 7;

void prime_factorization(ll num, map<ll, ll>& prime_factors)
{
    if (num < 2) {
        return;
    }

    for (ll i = 2; i * i <= num;) {
        if (num % i == 0) {
            num /= i;
            prime_factors[i]++;
        } else {
            i++;
        }
    }
    prime_factors[num]++;
}

void main_()
{
    ll N;
    cin >> N;

    map<ll, ll> prime_factors;
    for (ll i = 1; i <= N; ++i) {
        prime_factorization(i, prime_factors);
    }
    ll ans = 1;
    for (auto&& pf : prime_factors) {
        ans *= (pf.second + 1);
        ans %= MOD;
    }

    cout << ans << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    string s; cin >> s;
    int n = s.size();
    rep(i, n-1){
        if(s[i] == s[i+1]){
            cout << i+1 << " " << i+2 << endl;
            return;
        }
    }
    rep(i, n-2){
        if(s[i] == s[i+2]){
            cout << i+1 << " " << i+3 << endl;
            return;
        }
    }
    cout << -1 << " " << -1 << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4608
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PB push_back
#define PPB pop_back
#define MP make_pair
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define test(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define loop(i,start,end) for(ll i=start; i<end; i++)
#define rloop(j,start,end) for(ll j=start-1; j>=end; j--)

int main()
{   
    IOS;

    ll n;
    cin>>n;

    double p[n+1],dp[n+1][n+1],ans=0.0;
    loop(i,1,n+1)
        cin>>p[i];

    memset(dp,0,sizeof(dp));
    dp[0][0]=1.0;


    //dp calculates-> i coins tosses me j heads.
    loop(i,1,n+1)
    {
        loop(j,0,n+1)
        {
            if(j==0)
                dp[i][j]=(dp[i-1][j])*(1-p[i]);
            else
                dp[i][j]=(dp[i-1][j-1]*p[i]) + (dp[i-1][j]*(1-p[i]));
        }
    }

    // loop(i,0,n+1)
    // {    
    //     loop(j,0,n+1)
    //         test(dp[i][j]);
    //     d1("");
    // }

    //d1((.036+.096+.336)+.144);
    ll moreH=(n+1)/2;
    
    loop(i,moreH,n+1)
        ans+=dp[n][i];

    cout<<fixed<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 70656
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;

const int V = 1e5;
const int N = 100;

int main()
{
    ios_base ::sync_with_stdio(false);
    cin.tie(NULL);
    int n, w, inp1, inp2, max_val = 0;
    vector<pair<int, int>> arr;
    cin >> n >> w;
    for (int i = 0; i < n; i++)
    {
        cin >> inp1 >> inp2;
        arr.push_back({inp1, inp2});
        max_val += inp2;
    }
    unsigned long long dp[N + 1][V + 1];
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= max_val; j++)
        {
            dp[i][j] = LONG_MAX;
        }
    }
    for (int i = 0; i <= n; i++)
        dp[i][0] = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j <= max_val; j++)
        {
            if (j == 0)
                dp[i][j] = 0;
            else if (j >= arr[i - 1].second)
                dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - arr[i - 1].second] + arr[i - 1].first);
            else
                dp[i][j] = dp[i - 1][j];
        }
    }
    int res;
    for (int i = max_val; i >= 0; i--)
    {
        if (dp[n][i] <= w)
        {
            res = i;
            break;
        }
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 79232
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<climits>
#include<cfloat>
#include<cstdio>

using namespace std;

double EPS = 1e-10;
const double PI = acos(-1);

double add(double a, double b){
  if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}

struct point{
  double x, y;
  point(){}
  point(double x,double y) : x(x) , y(y){}

  point operator + (point p){
    return point(add(x,p.x), add(y,p.y));
  }

  point operator - (point p){
    return point(add(x,-p.x), add(y,-p.y));
  }

  point operator * (double d){
    return point(x*d,y*d);
  }

  bool operator < (const point &p) const {
    if(p.x != x)return x<p.x;
    return y < p.y;
  }
};

typedef vector<point> Polygon;

double cross(point a, point b) {
  return (a.x * b.y - a.y * b.x);
}

double dist(point a,point b){
  return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
}

Polygon convex_hull(Polygon ps, int n){
  sort(ps.begin(),ps.end());
  int k=0;
  Polygon qs(n*2);

  for(int i=0;i<n;i++){
    while(k>1&&cross(qs[k-1]-qs[k-2],ps[i]-qs[k-1])<0)k--;
    qs[k++]=ps[i];
  }

  for(int i=n-2,t=k;i>=0;i--){
    while(k>t&&cross(qs[k-1]-qs[k-2],ps[i]-qs[k-1])<0)k--;
    qs[k++]=ps[i];
  }
  qs.resize(k-1);
  return qs;
}


double convex_diameter(Polygon ps){
  Polygon qs=convex_hull(ps,ps.size());
  int n=qs.size();
  if(n==2)return 0.0;

  int i=0,j=0;
  for(int k=0;k<n;k++){
    if(qs[k]<qs[i])i=k;
    if(qs[j]<qs[k])j=k;
  }
  double res=0;
  int si=i,sj=j;
  while(i!=sj || j!=si){
    res=max(res,dist(qs[i],qs[j]));
    if(cross(qs[(i+1)%n]-qs[i],qs[(j+1)%n]-qs[j])<0)i=(i+1)%n;
    else j=(j+1)%n;
  }
  return res;
}

int main(void){

  int n;
  cin >> n;
  Polygon pol(n);

  for(int i=0;i<n;i++)cin >> pol[i].x >> pol[i].y;

  printf("%.10f\n",convex_diameter(pol));

  return 0;
}

Measured memory_bytes: 3116
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <map>
#include <queue>
#include <stack>
#include <set>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
//#define repitr(itr, st) for(auto itr = st.begin(); itr != st.end(); ++itr)
#define P_B push_back
#define PO_B pop_back
#define E_B emplace_back
#define M_P make_pair
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << endl
#define print(x) printf("%d\n", x)

using namespace std;
using ll = long long;
using Pii = pair<int,int>;
using Pll = pair<ll,ll>;
using VI = vector<int>;
using VL = vector<ll>;
using VVI = vector<vector<int> >;
using VVL = vector<vector<ll> >;
//int dx[4] = {1, 0, -1, 0};
//int dy[4] = {0, 1, 0, -1};
//const ll LINF = (ll)1e18 - 1;
//const int INF = 1e9 - 1;
//int:±2*10^9くらい　ll:±9*10^18くらい



void Main(){
	int N;
	cin >> N;
	vector<stack<Pll> > A(N+1, stack<Pll> ());
	vector<int> B(N+1, -1);

	rep(i, N-1){
		ll u, v, w;
		cin >> u >> v >> w;
		A[u].push(M_P(v, w));
		A[v].push(M_P(u, w));
	}

	stack<int> S;
	S.push(1);
	B[1] = 0;

	int col = 0;
	while(!S.empty()){
		int s;
		s = S.top();
		S.pop();
		while(!A[s].empty()){
			int np, nw;
			np = A[s].top().fi;
			nw = A[s].top().se;
			A[s].pop();
			S.emplace(np);
			B[np] = (B[s] + nw) % 2;
		}
	}

	rep(i, N){
		print(B[i+1]);
	}

}

int main()
{
	cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();

  return 0;
}


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

int main() {
  string O, M;
  cin >> O >> M;
  for(int i=0; i<M.size(); i++) {
    cout << O[i] << M[i];
  }
  if(O.size()>M.size()) {
    cout << O[O.size()-1];
  }
  return 0;
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

int main()
{
    string S;
    cin >> S;
    int res = 0;
    for(int i = 0, i_len=S.size(); 2*i < i_len; ++i) {
        int j = i_len - 1 - i;
        if(S[i] != S[j]) ++res;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
a = [0] * 3
b = [0] * 3

for i in range(3):
    a[i],b[i] = map(int,input().split())
    
count = [0] * 4
for i in range(3):
    for j in range(1,5):
        if(a[i] == j):
            count[j-1] += 1
        if(b[i] == j):
            count[j-1] += 1
        
if max(count) > 2:
    print('NO')
else:
    print('YES')
    

Measured memory_bytes: 3060
// template {{{

#include <bits/stdc++.h>
using namespace std;

#define loop(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) loop(i, 0, n)
#define rloop(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define rrep(i, n) rloop(i, 0, n)
#define eb emplace_back
#define ef emplace_front
#define pb pop_back
#define pf pop_front
#define all(c) std::begin(c), std::end(c)
#define mp std::make_pair
#define mt std::make_tuple
#define fi first
#define se second
#define popcnt __builtin_popcountll

using uint = unsigned;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<double, double>;
using tp = tuple<int, int, int>;
using tp4 = tuple<int, int, int, int>;
using tp5 = tuple<int, int, int, int, int>;

template<typename T>
using max_pq = priority_queue<T, vector<T>, less<T>>;

template<typename T>
using min_pq = priority_queue<T, vector<T>, greater<T>>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 10;
const ll LLINF = 1e18 + 10;

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

template<typename T>
inline T sq(T x){ return x * x; }

template<typename T, typename U>
inline bool chmax(T &x, U y){ if (x >= y) return false; x = y; return true; }

template<typename T, typename U>
inline bool chmin(T &x, U y){ if (x <= y) return false; x = y; return true; }

template<typename T>
inline void sort(T &c){ std::sort(std::begin(c), std::end(c)); }

template<typename T>
inline void reverse(T &c){ std::reverse(std::begin(c), std::end(c)); }

template<typename T>
inline void unique(T &c){ std::sort(std::begin(c), std::end(c)); c.erase(std::unique(all(c)), std::end(c)); }

// }}}

const int t[] = {0, 60, 70, 80};
bool f[5][5];
int a[5][5];
int dp[17][65536];

int calc(int p, int st)
{
	if (~dp[p][st]) return dp[p][st];
	if (p == 16) return 0;
	
	int res = 0;
	int ds = 0;
	int x = p / 4, y = p % 4;
	rep(i, 4){
		chmax(res, ds + calc(p + 1, (st * 4 + i) % 65536));
		rep(dx, 2) rep(dy, 2){
			if (f[x + dx][y + dy]){
				ds -= t[a[x + dx][y + dy]];
				++a[x + dx][y + dy] %= 4;
				ds += t[a[x + dx][y + dy]];
			}
		}
	}

	return dp[p][st] = res;
}

int main()
{
	int n;
	scanf("%d", &n);
	while (n--){
		rep(i, 5) rep(j, 5) scanf("%d", &a[i][j]), a[i][j]--;
		rep(i, 5) rep(j, 5) f[i][j] = a[i][j] >= 0;
		int sum = 0;
		rep(i, 5) rep(j, 5){
			if (f[i][j]) sum += t[a[i][j]];
		}
		memset(dp, -1, sizeof(dp));
		printf("%d\n", sum + calc(0, 0));
	}
}

Measured memory_bytes: 7572
let s = read_line ();;
let n = String.length s;;
let chs = Array.to_list @@ Array.init n (fun i -> s.[i]);;
let () =
  let len = List.length @@ List.sort_uniq compare chs in
  let ans = if n = len then "yes" else "no" in
  print_endline ans;;


Measured memory_bytes: 384
import java.util.*;

class Main {
	public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
      	int n = Integer.parseInt(sc.next());
      	//int[] A = new int[n];
      	//for (int i = 0; i < n; i++) {A[i] = Integer.parseInt(sc.next());}
      	String str;
      	if (n >= 30) {
          str = "Yes";
        } else {str = "No";}
      	System.out.println(str);
    }
}

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

using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define ALL(a) (a).begin(),(a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;
struct Edge{
  ll to,id;
};
typedef vector<vector<ll>> Graph;
typedef vector<pii> vpii;

int main() {
  ll N,A,B; cin>>N>>A>>B;
  if(N==1&&A!=B) {cout<<0<<endl; return 0;}
  if(A>B) {cout<<0<<endl; return 0;}
  cout<<(B*(N-1)+A)-(A*(N-1)+B)+1<<endl;
}


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

const int N = 100007;

vector<int> adj[100007];
vector<int> distdp(N,0);
vector<bool> visited(N,false);

int dfs(int v){
	visited[v]=true;
	int depth = 0;

	for(auto it:adj[v]){
		if(visited[it]){
			distdp[v]=max(distdp[v],1+distdp[it]);
		}
		else{
			depth=max(depth,1+dfs(it));
		}
	}

	distdp[v]=max(distdp[v],depth);
	return distdp[v];
}

int main() {

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
	
    ios_base::sync_with_stdio(0);
    int n,m;
    cin >> n >> m;
    for(int i=0;i<m;i++){
    	int u,v;
    	cin >> u >> v;
    	adj[u].push_back(v);
    }
    for(int i=1;i<=n;i++){
    	if(!visited[i]){
    		int t = dfs(i);
    	}
    }
    int ans = 0;
    for(int i=1;i<=n;i++){
    	ans = max(ans,distdp[i]);
    }
    cout << ans << "\n";




    return 0;
}


Measured memory_bytes: 11772
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        String S = in.next();
        int[] right = new int[26];
        for(int i=0;i<N;i++){
            right[S.charAt(i)-'a']++;
        }
        int[] left=new int[26];
        int result = Integer.MIN_VALUE;
        for(int j=0;j<N-1;j++){
            char cur = S.charAt(j);
            left[cur-'a']++;
            right[cur-'a']--;
            int sum=0;
            for(int k=0;k<26;k++){
                if(left[k]>0&&right[k]>0) sum++;
            }
            result = Math.max(result,sum);
        }
        System.out.println(result);

    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<algorithm>
#include<bitset>
using namespace std;
int main(){
    int h,w;
    while(cin>>h>>w,h||w){
        bitset<10000>bs[10];
        for(int i=0;i<h;i++)
            for(int j=0;j<w;j++){
                int f;
                cin>>f;
                bs[i][j]=f;
            }
        int Max=0;

        for(int i=0;i<(1<<10);i++){
            for(int j=0;j<10;j++){
                if((i>>j)&1)bs[j]=~bs[j];
            }

            int sum=0;
            for(int j=0;j<w;j++){
                int z=0,o=0;
                for(int k=0;k<h;k++){
                    if(bs[k][j])z++;
                    else o++;
                }
                sum+=max(z,o);
            }


            for(int j=0;j<10;j++){
                if((i>>j)&1)bs[j]=~bs[j];
            }
            Max=max(Max,sum);
        }
        cout<<Max<<endl;
    }
}

Measured memory_bytes: 1172
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using LayoutKind = System.Runtime.InteropServices.LayoutKind;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;


static class P
{
    static void Main()
    {
        var nx = Console.ReadLine().Split().Select(int.Parse).ToArray();
        long X = nx[1];
        //ちゅーごくじょーよてーり
        //オーダーによってSの終端が決定する
        //まず影響するのは降順のみなことは自明に分かって、
        //で、「次」を選ぶことができる順番は
        //「確率」「期待値」
        //aを取り除いた場合、その後に適用できるのはそれ以前全て。

        List<int> s = Console.ReadLine().Split().Select(int.Parse).OrderByDescending(x => x).ToList();
        ModInt[] dp = new ModInt[X + 1];
        dp[X] = 1;
        ModInt remain = s.Count - 1;
        foreach (var mod in s)
        {
            ModInt[] newDP = new ModInt[X + 1];

            for (int i = 0; i < dp.Length; i++)
            {
                newDP[i % mod] += dp[i];
                newDP[i] += dp[i] * remain;
            }
            remain--;
            dp = newDP;
        }
        ModInt res = 0;
        for (int i = 0; i < dp.Length; i++)
        {
            res += dp[i] * i;
        }
        Console.WriteLine(res);
    }
}


struct ModInt
{
    const int MOD = 1000000007;
    long Data;
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public ModInt(long data) { if ((Data = data % MOD) < 0) Data += MOD; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static implicit operator long(ModInt modInt) => modInt.Data;
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static implicit operator ModInt(long val) => new ModInt(val);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator +(ModInt a, ModInt b)
    {
        long res = a.Data + b.Data;
        return new ModInt() { Data = res >= MOD ? res - MOD : res };
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator -(ModInt a, ModInt b)
    {
        long res = a.Data - b.Data;
        return new ModInt() { Data = res < 0 ? res + MOD : res };
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator *(ModInt a, ModInt b) => new ModInt(a.Data * b.Data);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator /(ModInt a, ModInt b) => a * Power(b, MOD - 2);

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    static ModInt Power(ModInt n, long m)
    {
        ModInt res = 1;
        while (m > 0)
        {
            if ((m & 1) == 1) res *= n;
            n *= n;
            m >>= 1;
        }
        return res;
    }
}


Measured memory_bytes: 31344
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  else if (A + B == C + D) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

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

using namespace std;

#define FOR(i,n) for(int i=0; i<n; ++i)
#define FORR(i,a,n) for(int i=a; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

const int INF = 0x3f3f3f3f;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
 
//int in() { int x; scanf("%d", &x); return x; }
//ll lin() { ll x; scanf("%lld", &x); return x; }
//void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

int main(void){
    std::ios_base::sync_with_stdio(false);
    cin.tie(0);

	string str;
	cin >> str;

	ll sumOfDigits = 0;
	for(char& c : str){
		int i = c - '0';
		sumOfDigits += i;
	}

	if(sumOfDigits%9 == 0){
		cout << "Yes";
	} else {
		cout << "No";
	}

    return 0;
}












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

#define X first
#define Y second
#define SZ(x) ((int) (x).size())

using namespace std;
template <typename T> void read(T & x) {
	int f = 1; char ch; x = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); x *= f;
}

const int NX = 101234;

int n, a[NX << 1];

bool check(int x)
{
	for (int i = 0; i < n - 1; i++)
	{
		int p = n + i, q = n - i;
		if(min(a[p], a[p + 1]) >= x || min(a[q], a[q - 1]) >= x)
			return true;
		if(max(a[p], a[p + 1]) < x || max(a[q], a[q - 1]) < x)
			return false;
	}
	return a[1] >= x; 	
}
int main() {
	read(n);
	for (int i = 1; i < n * 2; i++)
		read(a[i]);
		
	int l = 1;
	int r = *max_element(a + 1, a + 2 * n);
	int ans = 0;
	while (l <= r) 
	{
		int mid = l + r >> 1;
		if(check(mid))
		{
			ans = mid;
			l = mid + 1;
		} else 
			r = mid - 1;
	}
	
	cout << ans << "\n";
	return 0;
}





Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <iostream>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>

using namespace std;
const int mod=1000000007;

vector<int> st;
vector<long long int> v;


long long int C (long long int n)
{
    if (n<2) {
        return 0;
    }
    else
        return n*(n-1)/2;
}



int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    long long int n,m,k,q,d,x,l,a,b,c;
    cin>>n;
    vector<long long int> vec(2*n);
    unordered_map<long long int, long long int> map;
    for (int i=0; i<n; i++) {
        cin>>vec[i];
        vec[i+n]=vec[i];
    }
    long long int ans=0;
    for (int i=1; i<n; i++) {
        ans-=C(map[vec[i]]);
        map[vec[i]]++;
        ans+=C(map[vec[i]]);
    }
    for (int i=n; i<2*n; i++) {
        cout<<ans<<"\n";
        ans-=C(map[vec[i-n+1]]);
        map[vec[i-n+1]]--;
        ans+=C(map[vec[i-n+1]]);
        ans-=C(map[vec[i]]);
        map[vec[i]]++;
        ans+=C(map[vec[i]]);
    }
    
    
    return 0;
}


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

int main()
{
  int n, m, k;

  cin >> n >> m;
  int card[200], num[200];

  for (int i = 0; i < 2 * n; i++) card[i] = i;
    
  while (m--){
    for (int i = 0; i < 2 * n; i++) num[i] = card[i];
    cin >> k;

    if (k == 0){
      for (int i = 0; i < n * 2; i++){
        if (i % 2 == 0){
          card[i] = num[i / 2];
        }
        else {
          card[i] = num[i / 2 + n];
        }
      }
    }
    else {
      for (int i = 0; i < 2 * n - k; i++){
        card[i] = num[k + i];
      }
      for (int i = 0; i < k; i++){
        card[i + 2 * n - k] = num[i];
      }
    }
  }

  for (int i = 0; i < 2 * n; i++){
    cout << card[i] + 1 << endl;
  }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define range(x,l,r) (l<=x && x<r)
#define chmax(a,b) (a = max(a,b))
using namespace std;

const int dy[] = {0,1,0,-1}, dx[] = {1,0,-1,0};
int dp[2][50][50][1<<12];
int vis[1<<12];

inline int visit(int bit){
  if(vis[bit]>=0)return vis[bit];

  int y=0, x=0, b=bit;
  rep(i,6){
    y += dy[b&3], x += dx[b&3]; b>>=2;
    if(y==0 && x==0)return vis[bit] = 1;
  }
  return vis[bit] = 0;
}

int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int h,w,k;
  string g[50];
  cin >> h >> w >> k;
  rep(i,h)cin >> g[i];

  memset(vis,-1,sizeof(vis));
  memset(dp,-1,sizeof(dp));
  dp[0][0][0][0] = isdigit(g[0][0])?(int)(g[0][0]-'0'):0;

  rep(t,k+1){
    int ck = t&1, nk = 1-ck;
    rep(y,h)rep(x,w){
      if(g[y][x] == '#')continue;
      rep(bit,1<<12){
	if(dp[ck][y][x][bit]<0)continue;

	rep(d,4){
	  if(t==k && d>1)break;
	  int ny = y+dy[d], nx = x+dx[d];
	  if(!range(ny,0,h) || !range(nx,0,w))continue;
	  if(g[ny][nx] == '#')continue;

	  int nbit = ((bit<<2)|d) & ((1<<12)-1);
	  int item = isdigit(g[ny][nx])?(int)(g[ny][nx]-'0'):0;
	  if(visit(nbit))item = 0;

	  if(d<2){
	    chmax(dp[ck][ny][nx][nbit], dp[ck][y][x][bit] + item);
	  }else{
	    chmax(dp[nk][ny][nx][nbit], dp[ck][y][x][bit] + item);
	  }
	}
      }
    }
  }

  int res = 0;
  rep(bit,1<<12)chmax(res, dp[k&1][h-1][w-1][bit]);
  cout << res << endl;
}

Measured memory_bytes: 81240
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int W = sc.nextInt();
    int h = sc.nextInt();
    int w = sc.nextInt();
    System.out.println((H-h)*(W-w));
  }
}


Measured memory_bytes: 21844
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')
import time

#A
def A():
    s = S()
    t = S()
    ans = 0
    for i in range(3):
        if s[i] == t[i]:
            ans += 1
    print(ans)
    return

#B
def B():
    a, b = LI()
    ans = 0
    b -= 1
    while b > 0:
        b -= a - 1
        ans += 1
    print(ans)

    return

#C
def C():
    n = II()
    h = LI()
    i = 0
    ans = 0
    while i < n:
        down = i+1
        while down < n:
            if h[down - 1] >= h[down]:
                down += 1
            else:
                break
        ans = max(ans, down - i - 1)
        i = down
    print(ans)
    return

#D
def D():
    n = II()
    print(n * (n - 1) // 2)
    return

#E
def E():
    start = time.time()
    n = II()
    a = LIR_(n)
    ans = 0
    tern = [0] * n
    while 1:
        ans += 1
        f = True
        c = defaultdict(int)
        for i in range(n):
            if c[i]:
                continue
            if tern[i] == n - 1:
                continue
            rival = a[i][tern[i]]
            if c[rival]:
                continue
            if tern[rival] == n - 1:
                continue
            if a[rival][tern[rival]] == i:
                c[i] += 1
                c[rival] += 1
                tern[rival] += 1
                tern[i] += 1
                f = False
        if time.time() - start >= 1:
            print(n * (n - 1) // 2)
            return
        if f:
            if tern == [n - 1] * n:
                print(ans-1)
                return
            else:
                print(-1)
                return
    return

#F
def F():
    return

#Solve
if __name__ == '__main__':
    E()


Measured memory_bytes: 35952
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ALL(x) (x).begin(), (x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL
using ll = int64_t;
template<typename T>
using vec = vector<T>;
using P = pair<ll, ll>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
	fill((T *)array, (T *)(array + N), val);
}

const ll INF = 1e7;
const ll MOD = 1e9 + 7;
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//ll pas[5001][5002];


ll v, e;
ll d[15][15];
ll dp[1ll << 15][15];

ll rec(ll s, ll u, ll k){
    if(dp[s][u] >= 0)return dp[s][u];
    if(s == (1ll << v) - 1 && u == k)return dp[s][u] = 0;
    ll res = INF;
    for(int i = 0;i < v;i++){
        if(!(s >> i & 1)){
            res = min(res, rec(s | 1 << i, i, k) + d[u][i]); 
        }
    }
    return dp[s][u] = res;
}

int main(){
	cin >> v >> e;
    for(int i = 0;i < v;++i){
        for(int j = 0;j < v;j++)d[i][j] = INF;
    }
    for(int i = 0;i < e;++i){
        ll s, t, x;
        cin >> s >> t >> x;
        d[s][t] = x;
    }
	ll ans = INF;
    for(int i = 0;i < v;++i){
        memset(dp, -1 ,sizeof(dp));
		ll tmp = rec(0,i,i);
        if(tmp < 1e5)ans = tmp;
    }
	if(ans == INF)dump(-1);
	else dump(ans);
}



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

#define boost ios_base::sync_with_stdio(false), cin.tie(NULL);

using namespace std;
const int N = 2e6 + 41;
const int mod = 1e9 + 7;
const long long INF = 1e18 + 12;
const int inf = 1e9;

int cnt[N];

int main () {
	boost;
	int n, k, a;
	cin >> n >> k;
	set <pair <int, int>> s;
	for (int i = 1 ; i <= n ; ++ i) {
		cin >> a;
		s.erase ({cnt[a], a});
		cnt[a]++;
		s.insert ({cnt[a], a});
	}
	int ans = 0;
	k = s.size() - k;
	while (k > 0 && s.size()) {
		--k;
		ans += s.begin()->first;
		s.erase (s.begin());
	}
	cout << ans;
}

Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const int INF = 1001001001;

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  vector<int> dp(n, INF);
  dp[0] = 0;
  for(int i = 1; i < n; ++i){
    for(int j = 1; j <= k && i - j >= 0; ++j) {
      dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
    }
  }
  cout << dp[n - 1] << endl;
}

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

int max(int a, int b)
{
    return a > b ? a : b;
}

int main() {

    int comb,e;
    while(cin >> e && e > 0)
    {
        comb = 0;

        int max_comb = 0, counter = 0;
        for(int i = 1;;i++)
        {
            max_comb += i;
            counter++;
            if(e < max_comb)
                break;
        }
        
        for(int i = 2; i<counter;i++)
        {
            if(i%2 == 0)
            {
                if(e%i != 0 && e*2 % i == 0 && 1.0*e/i > i/2.0)
                {
                    comb++;
                }
                
            }
            else
            {
                if(e%i == 0 && e/i > i /2.0)
                {
                    comb++;
                }
            }
        }
        
        
        cout << comb << endl;
    }
    return 0;
}

Measured memory_bytes: 3016
a,b=map(int,input().split())
ans=0
for i in range(1,a+1):
  for j in range(10,b+1):
    k=str(j)
    if int(k[0])<2 or int(k[1])<2:
      continue
    else:
      if int(k[0])*int(k[1])==i:
        ans+=1
        
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef vector<pii> vpii;
typedef tree<pii, null_type, less<pii>, rb_tree_tag,
    tree_order_statistics_node_update> ost;

const int N=110000;
ll n, l, x[N], w[N], xe[N];
ll np, yyp[N], nn, yyn[N];

ll getx(ll k) {
    ll q=k/2;
    if((w[0]==1 && k%2==0) || (w[0]==l-1 && k%2==1))
        return -l*(q/nn)+yyn[q%nn];
    return l*(q/np)+yyp[q%np];
}

void outp(ll pos, ll dis) {
    ll i, j;
    for(i=0; i<n; i++) if(xe[i]==pos) break;
    if(dis && i<n-1 && xe[i+1]==xe[i]) i++;
    for(j=0; j<n; j++) {
        printf("%lld\n", xe[i]);
        i=(i+1)%n;
    }
}

int main() {
    ll i, t, kl, kr, km, x1, x2;
    scanf("%lld%lld%lld", &n, &l, &t);
    for(i=0; i<n; i++) {
        scanf("%lld%lld", &x[i], &w[i]);
        if(w[i]==2) w[i]=l-1;
        xe[i]=(x[i]+w[i]*t)%l;
    }
    sort(xe, xe+n);
    for(i=0; i<n; i++) if(w[i]==l-1) yyp[np++]=x[i];
    if(w[0]==1) yyn[nn++]=x[0];
    for(i=n-1; i>0; i--) if(w[i]==1) yyn[nn++]=-l+x[i];
    if(np==0 || nn==0) {
        outp((x[0]+w[0]*t)%l, 0);
        return 0;
    }
    kl=0; kr=2*t+1;
    while(kl<kr) {
        km=(kl+kr)/2;
        x1=getx(km);
        x2=getx(km+1);
        if(abs(x1-x2)>2*t) kr=km;
        else kl=km+1;
    }
    x1=getx(kl);
    if((w[0]==1 && kl%2==0) || (w[0]==l-1 && kl%2==1)) x2=1;
    else x2=l-1;
    outp((x1%l+l+x2*t)%l, (x2==1));
    return 0;
}

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

int main() {
    int n,x;
    cin>>n>>x;
    vector<int> a(n);
    for(int i = 0;i < n;++i) {cin>>a[i];}
    ll ans=0;
    for(int i = 1;i < n;++i) {
        if(a[i-1]+a[i]>x){
            if(a[i-1]+a[i]-x<=a[i]){
                ans+=a[i-1]+a[i]-x;
                a[i]-=a[i-1]+a[i]-x;
            }
            else {
                ans+=a[i];
                a[i]=0;
                ans+=a[i-1]-x;
                a[i-1]=x;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product#accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
def run():
    N = int(input()) % 10
    if N in [2,4,5,7,9]:
        print('hon')
    elif N in [0,1,6,8]:
        print('pon')
    else:
        print('bon')

if __name__ == "__main__":
    run()

Measured memory_bytes: 9184
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.insert(0, 0)
# print(a)
if a[1] == 1:
    print(1)
else:
    reached = {i: 0 for i in range(1, n+1)}
    now = 1
    count = 0
    while reached[now] == 0:
        reached[now] = count
        now = a[now]
        count += 1
    roop = count - reached[now]
    if k < reached[now]:
        index = k
    else:
        index = (k - reached[now]) % roop + reached[now]
    # print(reached, count)
    # print(roop, index)
    for key, value in reached.items():
        if value == index:
            print(key)
            break



Measured memory_bytes: 40500
#include <bits/stdc++.h>
#define rep(i, l, r) for (register int i = l; i <= r; i++)
#define per(i, r, l) for (register int i = r; i >= l; i--)
#define srep(i, l, r) for (register int i = l; i < r; i++)
#define sper(i, r, l) for (register int i = r; i > l; i--)
#define erep(i, x) for (register int i = h[x]; i; i = e[i].next)
#define erep2(i, x) for (register int& i = cur[x]; i; i = e[i].next)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define fi first
#define se second
#define ui unsigned int
#define ld long double
#define ll long long int 
#define pb push_back
#define pc putchar
#define lowbit(x) (x & -x)
#define maxr 2000020
#define maxn 400020
#define maxm
#define maxs
#define maxb
#define M 1000000007
#define mo(x) (x = (x >= M) ? (x - M) : x)
#define gc() ((p1 == p2 && (p2 = (p1 = buffer) + fread(buffer, 1, maxr, stdin), p1 == p2)) ? EOF : *p1++)
using namespace std;

char buffer[maxr], *p1, *p2;
template <class T> void read(T& x){
	char ch = gc(); x = 0; bool f = 1;
	while (!('0' <= ch && ch <= '9') && ch != '-') ch = gc();
	if (ch == '-') f = 0, ch = gc();
	while ('0' <= ch && ch <= '9') x = (x << 1) + (x << 3) + ch - '0', ch = gc();
	x = (f) ? x : -x;
}
int _num[20];
template <class T> void write(T x){	
	if (!x) {putchar('0'), putchar('\n'); return;}
	if (x < 0) putchar('-'), x = -x;
	int c = 0;
	while (x) _num[++c] = x % 10, x /= 10;
	while (c) putchar('0' + _num[c--]); 
	putchar('\n');
}

int n, a[maxn], _n, _a[maxn], dp[maxn], c[maxn], pre[maxn];

int main(){
	scanf("%d", &_n); rep(i, 1, _n) scanf("%d", _a + i); 
	rep(i, 1, _n) {
		int now = _a[i]; a[++n] = now;
		while (i <= _n && _a[i] == now) i++; i--;
	}
	
	rep(i, 1, n){
		dp[i] = c[a[i]], pre[i] = pre[i - 1] + dp[i], mo(pre[i]);
		//c[a[i + 1]] += pre[i] + 1, mo(c[a[i + 1]]);
		c[a[i]] += pre[i - 1] + 1, mo(c[a[i]]);
	} 
	printf("%d\n", pre[n] + 1);
	return 0;
}


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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;

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

	LL A, B, C;
	cin >> A >> B >> C;

	LL ans = 0;
	if(C <= A + B){
		ans = B + C;
	}
	else{
		ans = B + A + 1 + B;
	}
	printf("%lld\n", ans);
	return 0;
}

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

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

int n, k;
int d[11];

inline int nextCombination(int comb)
{
  int x = comb & -comb, y = comb + x;
  return (((comb & ~y) / x) >> 1) | y;
}

template<typename T> inline void _tostr(const T t, string& s){ostringstream o;o<<t;s=o.str();}
template<typename T> inline string _tostr(const T t){ostringstream o;o<<t;return o.str();}
template<typename T> inline void _toint(const string s, T& n){istringstream i(s);i>>n;}
template<typename T> inline T _toint(const string s){istringstream i(s);T n;i>>n;return n;}


int main(int argc, char *argv[])
{
  while(cin >> n, n){
    cin >> k;
    rep(i, n) cin >> d[i];

    vector<string> res;

    for(int comb = (1 << k) - 1; comb < (1 << n); comb = nextCombination(comb)){
      vector<int> vec;
      rep(mask, n) if(comb & 1 << mask) vec.push_back(mask);
      do{
        string s = "";
        rep(i, k) s += _tostr(d[vec[i]]);
        res.push_back(s);
      }while(next_permutation(vec.begin(), vec.begin() + k));
    }

    sort(res.begin(), res.end());
    res.erase(unique(res.begin(), res.end()), res.end());
    cout << res.size() << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1380
def func(A, B, C):
    if A % 2 == 1 or B % 2 == 1 or C % 2 == 1:
        return 0
    if A == B and B == C:
        return -1
    return func((B+C)//2, (C+A)//2, (A+B)//2) + 1


A, B, C = map(int, input().split())

ans = func(A, B, C)

print(ans)

Measured memory_bytes: 9180
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

deque<int> dq;
map<int,int> ma;
bool marked[100001];
void rem(int x)
{
	ma[x]--;
	if(ma[x]==0) ma.erase(x);
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	dq.resize(n);
	for(int i =0; i < n; i++) 
	{
		cin>>dq[i];
		ma[dq[i]]++;
	}
	int ans = ma.size();
	if(ans%2==0) ans--;
	cout<<ans<<'\n';
	return 0;
	while(!dq.empty())
	{
		cerr<<ma.size()<<' '<<dq.size()<<'\n';
		if(ma.size()==dq.size())
		{
			cout<<ma.size()<<'\n';
			return 0;
		}
		int a[3];
		a[0]=dq.front();
		dq.pop_front();
		a[1]=dq.front();
		dq.pop_front();
		a[2]=dq.front();
		dq.pop_front();
		cerr<<a[0]<<' '<<a[1]<<' '<<a[2]<<'\n';
		sort(a,a+3);
		//cerr<<a[0]<<' '<<a[1]<<' '<<a[2]<<'\n';
		rem(a[0]);
		rem(a[2]);
		rem(a[1]);
		if(!marked[a[1]])
		{
			marked[a[1]]=1;
			dq.push_back(a[1]);
		}
		else
		{
			dq.push_front(a[1]);
		}
		
		ma[a[1]]++;
	}
}


Measured memory_bytes: 5376
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>


#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;

using namespace std;

ll modd = 1000 * 1000 * 1000 + 7;



int main()   {


      ios_base::sync_with_stdio(false);

      cout.precision(17);
      mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
      uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no



//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(n);
        cout << 1-n << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>
using namespace std;
#define All(v) (v).begin(),(v).end()
const long long mod = 1000000007;
const long long inf = mod*mod;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
signed main(){
    int n,a;
    cin>>n;
    map<int,int> d;
    for(int i=0;i<n;i++){
        cin>>a;
        d[a]++;
    }
    int res = 0;
    for(auto v:d){
        if(v.first<=v.second){
            res+=v.second-v.first;
        }
        else{
            res+=v.second;
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ll N, A, B;
    cin>>N>>A>>B;
    ll ans = 0;
    ll lst;
    cin>>lst;
    for(int i=1;i<N;i++){
        ll tmp;
        cin>>tmp;
        ans += min((tmp-lst)*A, B);
        lst = tmp;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define PI 3.14159265359
#define ROOP(n) for(int i = 0;i < n;i++)
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> employeeNumber(N,0);
  int A;
  
  for(int i = 0;i < N - 1;i++){
    cin >> A;
    employeeNumber.at(A - 1)++;
  }
  ROOP(N){
    cout << employeeNumber.at(i) << endl;
  }
}

Measured memory_bytes: 3996