stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
// In The Name Of God

#include <bits/stdc++.h>



#define sqr(A) ((A) * (A))

#define X first

#define Y second

#define MP make_pair

#define bsz  __builtin_popcount

#define all(A) A.begin(), A.end()

using namespace std;

typedef long long ll;

typedef long double ld;

typedef pair<int, int> pii;

const int MOD = 1e9 + 7;

const int MOD2 = 1e9 + 9;

const int PR = 727;

const int INF = INT_MAX;

const ll LINF = LLONG_MAX;



const int N = 1e5 + 20;

ll n, k, ans = LINF, a[N];



int main() {

	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	cin >> n >> k;

	for (int i = 0; i < n; i++)

		cin >> a[i];

	for (int i = 0; i < n - k + 1; i++) {

		if (a[i] > 0)

			ans = min(ans, a[i + k - 1]);

		if (a[i + k - 1] <= 0)

			ans = min(ans, abs(a[i]));

		if (a[i] < 0 && 0 < a[i + k - 1])

			ans = min({ans, 2LL * abs(a[i]) + a[i + k - 1], 2LL * a[i + k - 1] + abs(a[i])});

	}

	cout << ans << endl;

}






















































































// Faster C++ solution for the same problem (measured speedup: 5.39049654180777x):
#include<cstdio>

#include<cstring>

#include<algorithm>

typedef long long ll;

ll Min(ll a,ll b){return a<b?a:b;}

ll Abs(ll a){return a>0?a:-a;}

inline ll read()

{

	ll x=0,f=1;char c=getchar();

	while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}

	while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}

	return x*f;

}

ll n,k,a[100005],l,ans=9999999999999999;

int main()

{

	n=read();k=read();

	for(ll i=1;i<=n;i++) a[i]=read();

	l=n+1;

	a[l]=1;

	for(ll i=1;i<=n;i++) if(a[i]>=0){l=i;break;}

	if(n-l+1>=k) ans=a[l+k-1];

	for(ll i=l-1,r=n;i>=1;i--)

	{

		if(n-i+1<k) continue;

		if(l-i+(a[l]==0)==k)

		{

			ans=Min(ans,Abs(a[i]));

			break;

		}

		while(r-i+1>k) r--;

		//printf("%d %d %lld\n",i,r,a[r]+Abs(a[i])+Min(Abs(a[i]),a[r]));

		ans=Min(ans,a[r]+Abs(a[i])+Min(Abs(a[i]),a[r]));

	}

	printf("%lld",ans);

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int x[200000];

int main()

{

    int k,n,i,j,len=0,Min=1000000000;

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

    for(i=0;i<n;i++){

        scanf(" %d",&x[i]);

    }

    for(i=0;i<=n-k;i++){

        if(x[i]<0&&x[i+k-1]>0){

            if(-x[i]>x[i+k-1])  len=2*x[i+k-1]-x[i];

            else len=x[i+k-1]-2*x[i];

        }

        else if(x[i]<0) len=-x[i];

        else len=x[i+k-1];

        if(Min>len){

            Min=len;

        }

    }

    printf("%d",Min);

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.253126696516996x):
#include<cstdio>

#include<cstring>

#include<algorithm>

typedef long long ll;

ll Min(ll a,ll b){return a<b?a:b;}

ll Abs(ll a){return a>0?a:-a;}

inline ll read()

{

	ll x=0,f=1;char c=getchar();

	while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}

	while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}

	return x*f;

}

ll n,k,a[100005],l,ans=9999999999999999;

int main()

{

	n=read();k=read();

	for(ll i=1;i<=n;i++) a[i]=read();

	l=n+1;

	a[l]=1;

	for(ll i=1;i<=n;i++) if(a[i]>=0){l=i;break;}

	if(n-l+1>=k) ans=a[l+k-1];

	for(ll i=l-1,r=n;i>=1;i--)

	{

		if(n-i+1<k) continue;

		if(l-i+(a[l]==0)==k)

		{

			ans=Min(ans,Abs(a[i]));

			break;

		}

		while(r-i+1>k) r--;

		//printf("%d %d %lld\n",i,r,a[r]+Abs(a[i])+Min(Abs(a[i]),a[r]));

		ans=Min(ans,a[r]+Abs(a[i])+Min(Abs(a[i]),a[r]));

	}

	printf("%lld",ans);

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

static const int N = 1e5 + 10;

static const int inf = 0x3f3f3f3f;

ll n, k, a[N];



int main ()

{

	cin >> n >> k;

	for (int i = 1; i <= n; ++i)

		cin >> a[i];

	ll ans = inf;

	for (ll i = k; i <= n; ++i)

	{

		ll l = i - k + 1;

		ll r = i;

		if (a[l] * a[r] < 0)

		ans = min(ans, min(abs(a[l]), abs(a[r])) * 2 + max(abs(a[l]), abs(a[r])));

		else

		ans = min (ans, max(abs(a[l]), abs(a[r])));

//		cout << ans << endl;

	}

	cout << ans;

}

// Faster C++ solution for the same problem (measured speedup: 5.216510371782426x):
#include<cstdio>

#include<cmath>

#include<algorithm>

using namespace std;

int ans=2e9,a[100005];

int main()

{

	int n,k;

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

	for(int i=1;i<=n;i++)

	{

		scanf("%d",a+i);

	}

	for(int i=1;i<=n-k+1;i++)

	{

		ans=min(ans,a[i+k-1]-a[i]+min(abs(a[i+k-1]),abs(a[i])));

	}

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

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

static const int N = 1e5 + 10;

static const int inf = 0x3f3f3f3f;

ll n, k, a[N];



int main ()

{

	cin >> n >> k;

	for (int i = 1; i <= n; ++i)

		cin >> a[i];

	ll ans = inf;

	for (ll i = k; i <= n; ++i)

	{

		ll l = i - k + 1;

		ll r = i;

		if (a[l] * a[r] < 0)

		ans = min(ans, min(abs(a[l]), abs(a[r])) * 2 + max(abs(a[l]), abs(a[r])));

		else

		ans = min (ans, max(abs(a[l]), abs(a[r])));

//		cout << ans << endl;

	}

	cout << ans;

}

// Faster C++ solution for the same problem (measured speedup: 5.316490565893984x):
#include <cstdio>

#include <algorithm>

const int MAXN = 1e5 + 10;



int N, K, X[MAXN];



namespace FastIO {

	template <typename T>

	void read(T & x) {

		x = 0; register char ch = getchar(); register int f = 0;

		for (; ch < '0' || ch > '9'; f |= ch == '-', ch = getchar());

		for (; ch >= '0' && ch <= '9'; x = (x << 3) + (x << 1) + (ch ^ '0'), ch = getchar());

		if (f) x = ~x + 1;

	}

}



int main() {

	using FastIO::read;

	read(N), read(K);

	int ans = 0x7f7f7f7f;

	for (int i = 0; i < N; i++) read(X[i]);

	for (int i = N - 1; i + 1 >= K; i--) {

		// printf("i=%d, i-K+1=%d\n", i, i-K+1);

		int l = X[i - K + 1], r = X[i];

		if (l <= 0 && r >= 0) ans = std::min(ans, std::min(-l * 2 + r, r * 2 - l));

		else ans = std::min(ans, std::max(std::abs(l), std::abs(r)));

	}

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

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



const int N = 1e5 + 5;



int n, k;

long long x[N];



int main(void) {

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

	for (int i = 1; i <= n; ++ i) {

		scanf("%lld", &x[i]);

	}

	

	long long ans = 1e17;

	for (int i = 1; i <= n; ++ i) {

		int j = i + k - 1; if (j > n) break;

		long long cur = abs(x[j] - x[i]);

		ans = min(ans, cur + min(abs(x[i]), abs(x[j])));

	}

	cout << ans << endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.321182573019353x):
#include <cstdio>

#include <algorithm>

const int MAXN = 1e5 + 10;



int N, K, X[MAXN];



namespace FastIO {

	template <typename T>

	void read(T & x) {

		x = 0; register char ch = getchar(); register int f = 0;

		for (; ch < '0' || ch > '9'; f |= ch == '-', ch = getchar());

		for (; ch >= '0' && ch <= '9'; x = (x << 3) + (x << 1) + (ch ^ '0'), ch = getchar());

		if (f) x = ~x + 1;

	}

}



int main() {

	using FastIO::read;

	read(N), read(K);

	int ans = 0x7f7f7f7f;

	for (int i = 0; i < N; i++) read(X[i]);

	for (int i = N - 1; i + 1 >= K; i--) {

		// printf("i=%d, i-K+1=%d\n", i, i-K+1);

		int l = X[i - K + 1], r = X[i];

		if (l <= 0 && r >= 0) ans = std::min(ans, std::min(-l * 2 + r, r * 2 - l));

		else ans = std::min(ans, std::max(std::abs(l), std::abs(r)));

	}

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

	return 0;

}
// Slower C++ solution:
#include <cstdio>

#include <string.h>

#include <iostream>

#include <math.h>

using namespace std;

int main(){

		int N,K;

		cin >> N >> K;

		int s[N];

		for(int i=0; i<N ;i++){

				cin >> s[i];

		}

		int min;

		for(int i=0;i<N-K+1;i++){

				int d;

				d=fmin(fabs(s[i]),fabs(s[K+i-1]))+fabs(s[K+i-1]-s[i]);

				min = fmin(min,d);

				if(i==0)min=d;

		}

		cout << min << endl;

}


// Faster C++ solution for the same problem (measured speedup: 4.839162464056668x):
#include <cstdio>

#include <math.h>

using namespace std;

int main(){

		int N,K;

		scanf("%d %d",&N,&K);

		int s[N];

		for(int i=0; i<N ;i++){

			scanf("%d",&s[i]);

		}

		int min;

		for(int i=0;i<N-K+1;i++){

				int d;

				d=fmin(fabs(s[i]),fabs(s[K+i-1]))+fabs(s[K+i-1]-s[i]);

				min = fmin(min,d);

				if(i==0)min=d;

		}

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

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



long long int N, K, A[364364], B, L;



int main(){

    scanf("%lld%lld", &K, &N);

    if(K == 1){

        for(int i = 0; i < (N + 1) / 2; ++i)cout << "1 ";

        return 0;

    }

    if(K & 1){

        fill(A, A + 364364, K / 2 + 1);

        B = N / 2;

        L = N;

        for(int i = 0; i < B; ++i){

            if(--A[L - 1]){

                for(; L < N; ++L){

                    A[L] = K;

                }

            }else{

                --L;

            }

        }

        for(int i = 0; i < N; ++i){

            if(A[i] == 0)return 0 & puts("");

            cout << A[i] << " ";

        }

    }else{

        cout << (K >> 1) << " ";

        for(int i = 0; ++i < N;)cout << K << " ";

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 2.2453219602520025x):
#include<bits/stdc++.h>

using namespace std;



long long int K, N, A[303030], L, R;



int main(){

    scanf("%lld%lld", &K, &N);

    if(K ^ 1){

        if(K & 1){

            fill(A, A + N, (K + 1) / 2);

            L = N;

            for(R = N / 2 + 1; --R;)if(--A[--L])for(; L < N; A[++L] = K);

            for(int i = 0; i < N; cout << A[i++] << " ")if(!A[i])return 0 & puts("");

        }else{

            cout << K / 2 << " ";

            for(; --N; cout << K << " ");

        }

    }else for(N = (N + 3) / 2; --N; cout << "1 ");

    return 0;

}
// Slower C++ solution:
#include <iostream>



using namespace std;



int main()

{

    int N, P;

    cin >> N >> P;



    cout << (N-P)+1 << endl;







    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.261477091739559x):
#include <stdio.h>

int main()

{

    int N,P;

    scanf("%d %d",&N,&P);

    printf("%d\n",N-P+1);

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define lowbit(x) ((x) & -(x))



typedef long long ll;

const int N = 100054, Z = N * 2;



ll L;

int n, cnt = 1, d[Z][2];

char s[N];



void append(char *s) {

	char *p = s; int t = 1, id;

	for (; *p; ++p)

		id = *p & 1, t = (d[t][id] ? d[t][id] : (d[t][id] = ++cnt));

}



ll dfs(int t, ll dep) {return t ? dfs(d[t][0], dep - 1) ^ dfs(d[t][1], dep - 1) : lowbit(dep + 1);}



int main() {

	scanf("%d%lld", &n, &L);

	for (int i = 0; i < n; ++i) scanf("%s", s), append(s);

	puts(dfs(1, L) ? "Alice" : "Bob");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.222307583673606x):
#include<cstdio>

#include<cstring>

typedef long long ll;

const int MAXN = 100000;

struct node{

	node *ch[2];

}pl[MAXN + 5], *NIL=&pl[0], *ncnt=&pl[0], *root=&pl[0];

ll lowbit(ll x) {return x & (-x);}

void insert(char *S) {

	int len = strlen(S); node *nw = root;

	for(int i=0;i<len;i++) {

		if( nw->ch[S[i]-'0'] == NIL )

			nw->ch[S[i]-'0'] = (++ncnt), ncnt->ch[0] = ncnt->ch[1] = NIL;

		nw = nw->ch[S[i]-'0'];

	}

}

ll res; char s[MAXN + 5];

void dfs(node *rt, ll l) {

	if( rt->ch[0] == NIL && rt->ch[1] == NIL )

		return ;

	if( rt->ch[0] == NIL ) res ^= lowbit(l);

	else dfs(rt->ch[0], l-1);

	if( rt->ch[1] == NIL ) res ^= lowbit(l);

	else dfs(rt->ch[1], l-1);

}

int main() {

	root->ch[0] = root->ch[1] = NIL;

	int N; ll L; scanf("%d%lld", &N, &L);

	for(int i=1;i<=N;i++)

		scanf("%s", s), insert(s);

	dfs(root, L);

	if( res ) puts("Alice");

	else puts("Bob");

}
// Slower C++ solution:
#include <cstdio>

#include <cstdlib>

#include <cmath>

#include <iostream>

#include <sstream>

#include <string>

#include <cstring>

#include <map>

#include <set>

#include <vector>

#include <stack>

#include <queue>

#include <deque>

#include <utility>

#include <algorithm>

#include <cassert>



using namespace std;



typedef long long int LLI;

typedef pair<int,int> PII;



#define _ ios_base::sync_with_stdio(0);

#define debug

#define x first

#define y second

#define MXN 100005



const int inf = 0x3f3f3f3f;

const int mod = 1e9+7;

const double eps = 1e-8; 





int main() { _

    int n, t, k, mx;

    LLI sum;

    while (cin >> n >> t) {

        mx = -1;

        sum = 0;

        for (int i = 0; i < n; ++i) {

            cin >> k;

            mx = max(mx, k);

            sum += k;

            if (sum <= t) cout << int(1+ceil((double)(t+0.5 - sum)/(double)mx)) << "\n";

            else cout << "1\n";

        }

    }



    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 4.692002152723696x):
#include <cstdio>

#include <cstdlib>

#include <cmath>

#include <algorithm>

using namespace std;

typedef long long LL;



int main()

{

	LL n, t;

	while (~scanf("%lld%lld", &n, &t)) {

		LL sum = 0, MaX = 0;

		for (int i = 1; i <= n; i++) {

			LL x; scanf("%lld", &x);

			sum += x; MaX = max(MaX, x);

			LL ans = 1;

			if (t >= sum) ans = (LL)floor((t - sum) * 1.0 / MaX) + 2;

			printf("%lld\n", ans);

		}

	}	

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <bits/stdc++.h>



using namespace std;

const int maxn = 1e5 +10;

typedef long long ll;

int n;

ll t;

ll ans[maxn] , a[maxn] , ok[maxn];

ll sum[maxn];

int main()

{

    cin >> n >> t;

    for(int i = 1; i <= n ; i ++){

        scanf("%lld" , &a[i]);

        sum[i] = sum[i-1] + a[i-1];

    }

    memset(ok , 0 , sizeof(ok));

    ll num = t / a[1] + 1;

    ll cha = 0;

    ans[1] = num;

    //ll lastT = (num-1)*a[1];



    for(int i = 2 ; i <= n ; i ++){

        cha = cha + a[i-1] - a[i];

        cha = max(0ll , cha);

        ans[i] = (t - sum[i]) / (a[i] + cha) + 1;

        if((t - sum[i]) % (a[i] + cha) >= a[i])ans[i] ++;

    }

    for(int i = 1 ; i <= n ; i++){

        if(ans[i] <= 0)ans[i] = 1;

        printf("%lld\n" , ans[i]);

    }

    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 1.8049784534322744x):
#include<bits/stdc++.h>

#define ULL unsigned long long int

#define LL long long int

using namespace std;

LL num[100007],mx[100007];

int main()

{

    LL n,t;

    cin>>n>>t;

    cin>>num[0];

    mx[0]=num[0];

    for(LL i=1;i<n;i++)

    {

        cin>>num[i];

        mx[i]=max(mx[i-1],num[i]);

    }

    LL uptime=0;

    for(LL i=0;i<n;i++)

    {

        uptime+=num[i];

        if(i==0)

        {

            cout<<t/num[i]+1<<endl;

        }

        else

        {

            if(uptime>t)

                cout<<1<<endl;

            else

                cout<<(t-uptime)/mx[i]+2<<endl;

        }

    }

    return 0;

}
// Slower C++ solution:
#include <iostream>

#include <string>

#include <cstring>

#include <algorithm>

#include <ostream>

#include <fstream>

#include <cstdio>

#include <vector>

#include <queue>

#include <stack>

#include <map>

#include <set>

typedef unsigned long long ll;

using namespace std;

const int maxn = 100000 + 7;

ll num[maxn];

ll stu[maxn];

ll sum[maxn];

int main()

{

    int n;

    ll t;

    memset(sum,0,sizeof(sum));

    scanf("%d%lld",&n,&t);

    ll maxx = 0;

    sum[0] = 0;

    ll pos;

    for(int i = 1;i<=n;i++){

        scanf("%lld",&stu[i]);

        sum[i] = sum[i-1] + stu[i];

        maxx = max(maxx,stu[i]);

        if(i==1){num[i] = (t - sum[i-1])/stu[i] + 1;continue;}

        if(t>=sum[i]){

            ll time = t-sum[i];

            num[i] = time/maxx + 2;

        }

        else {num[i] = 1;continue;}

    }

    for(int i = 1;i<=n;i++){

        printf("%lld\n",num[i]);

    }

    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 1.798533416877804x):
#include<bits/stdc++.h>

#define ULL unsigned long long int

#define LL long long int

using namespace std;

LL num[100007],mx[100007];

int main()

{

    LL n,t;

    cin>>n>>t;

    cin>>num[0];

    mx[0]=num[0];

    for(LL i=1;i<n;i++)

    {

        cin>>num[i];

        mx[i]=max(mx[i-1],num[i]);

    }

    LL uptime=0;

    for(LL i=0;i<n;i++)

    {

        uptime+=num[i];

        if(i==0)

        {

            cout<<t/num[i]+1<<endl;

        }

        else

        {

            if(uptime>t)

                cout<<1<<endl;

            else

                cout<<(t-uptime)/mx[i]+2<<endl;

        }

    }

    return 0;

}
// Slower C++ solution:
#include <iostream>

#include <bits/stdc++.h>



using namespace std;

const int maxn = 1e5 +10;

typedef long long ll;

int n;

ll t;

ll ans[maxn] , a[maxn] , ok[maxn];

ll sum[maxn];

int main()

{

    cin >> n >> t;

    for(int i = 1; i <= n ; i ++){

        scanf("%lld" , &a[i]);

        sum[i] = sum[i-1] + a[i-1];

    }

    memset(ok , 0 , sizeof(ok));

    ll num = t / a[1] + 1;

    ll cha = 0;

    ans[1] = num;

    //ll lastT = (num-1)*a[1];



    for(int i = 2 ; i <= n ; i ++){

        cha = cha + a[i-1] - a[i];

        cha = max(0ll , cha);

        ans[i] = (t - sum[i]) / (a[i] + cha) + 1;

        if((t - sum[i]) % (a[i] + cha) >= a[i])ans[i] ++;

    }

    for(int i = 1 ; i <= n ; i++){

        if(ans[i] <= 0)ans[i] = 1;

        printf("%lld\n" , ans[i]);

    }

    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 1.8259246743215938x):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll N=1e5+10;

ll a[N];

int main()

{

    //freopen("i.txt","r",stdin);

    ll n,t,ans;

    scanf("%lld %lld",&n,&t);

     for(ll i=0;i<n;i++)

        scanf("%lld",&a[i]);

    ll ma=a[0],sum=a[0];

    printf("%lld\n",t/ma+1);

    for(ll i=1;i<n;i++)

    {

        if(ma>=a[i])

        {

            ans=(t-sum)/ma+1;

            if((t-sum)/ma*ma+sum+a[i]<=t)ans++;

            //cout<<ans<<'*'<<endl;

        }

        else

        {

            ans=(t-sum)/a[i]+1;

        }

        printf("%lld\n",t-sum>0?ans:1);

        ma=max(ma,a[i]);

        sum+=a[i];

    }

}
// Slower C++ solution:
#include <iostream>

#include <string>

#include <cstring>

#include <algorithm>

#include <ostream>

#include <fstream>

#include <cstdio>

#include <vector>

#include <queue>

#include <stack>

#include <map>

#include <set>

typedef unsigned long long ll;

using namespace std;

const int maxn = 100000 + 7;

ll num[maxn];

ll stu[maxn];

ll sum[maxn];

int main()

{

    int n;

    ll t;

    memset(sum,0,sizeof(sum));

    scanf("%d%lld",&n,&t);

    ll maxx = 0;

    sum[0] = 0;

    ll pos;

    for(int i = 1;i<=n;i++){

        scanf("%lld",&stu[i]);

        sum[i] = sum[i-1] + stu[i];

        maxx = max(maxx,stu[i]);

        if(i==1){num[i] = (t - sum[i-1])/stu[i] + 1;continue;}

        if(t>=sum[i]){

            ll time = t-sum[i];

            num[i] = time/maxx + 2;

        }

        else {num[i] = 1;continue;}

    }

    for(int i = 1;i<=n;i++){

        printf("%lld\n",num[i]);

    }

    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 1.8194048450963007x):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll N=1e5+10;

ll a[N];

int main()

{

    //freopen("i.txt","r",stdin);

    ll n,t,ans;

    scanf("%lld %lld",&n,&t);

     for(ll i=0;i<n;i++)

        scanf("%lld",&a[i]);

    ll ma=a[0],sum=a[0];

    printf("%lld\n",t/ma+1);

    for(ll i=1;i<n;i++)

    {

        if(ma>=a[i])

        {

            ans=(t-sum)/ma+1;

            if((t-sum)/ma*ma+sum+a[i]<=t)ans++;

            //cout<<ans<<'*'<<endl;

        }

        else

        {

            ans=(t-sum)/a[i]+1;

        }

        printf("%lld\n",t-sum>0?ans:1);

        ma=max(ma,a[i]);

        sum+=a[i];

    }

}
// Slower C++ solution:
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

using pii =  pair<int, int>;

using pll =  pair<long long, long long>;

constexpr char ln =  '\n';

constexpr long long MOD = 1000000007LL;

constexpr long long INF = 1000000009LL;

#define all(x) (x).begin(),(x).end()

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

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

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







int main() {

    ll n, k; cin >> n >> k;

    vector<ll> A(n+10); A.push_back(-1);

    rep(i, n) cin >> A[i+1];



    vector<ll> visited(200200, -1);

    visited[1] = 0;

    vector<ll> pass; pass.push_back(1);



    ll rp = 0, nrp = 0, cur = 1;

    for(ll i=1; i<=min(n, k); i++){

        ll next = A[cur];

        if(visited[next] == -1){

            pass.push_back(next);

            visited[next] = i;

            cur = next;

        }else{

            rp = i - visited[next];

            nrp = pass.size() - rp;

            break;

        }

    }

    if(rp == 0) rp = pass.size();

    ll x = (k - nrp) % rp;

    cout << pass[nrp + x] << ln;

}


// Faster C++ solution for the same problem (measured speedup: 1.442348472317377x):
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

using pii =  pair<int, int>;

using pll =  pair<long long, long long>;

constexpr char ln =  '\n';

constexpr long long MOD = 1000000007LL;

constexpr long long INF = 1000000009LL;

#define all(x) (x).begin(),(x).end()

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

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

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







int main() {

    int n; ll k; cin >> n >> k;

    vector<int> A(n);

    rep(i, n) cin >> A[i], A[i]--;



    vector<int> first_visited(200200, -1); //その町に最初に訪れた時にテレポーターを使った回数

    first_visited[0] = 0;

    vector<int> pass; pass.push_back(0); //同じ町に二度訪れるまでの経路



    //ループが始まるまでの経路を作成

    //rp:　pass内の閉路の長さ 　nrp: 閉路でない経路の長さ  cur: 現在地

    int rp = 0, nrp = 0, cur = 0; 

    for(int cnt=1; cnt<=k; cnt++){

        int to = A[cur]; 

        if(first_visited[to] == -1){ //次の街をまだ訪れていない場合は経路を追加してそこに移動する

            pass.push_back(to);

            first_visited[to] = cnt;

            cur = to;

        }else{ //同じ町を二度訪れる場合はループ終了 

            rp = cnt - first_visited[to];

            nrp = pass.size() - rp;

            break;

        }

    }

    if(rp == 0) rp = pass.size(); //閉路を見つける前にループが終わった場合の処理



    int ans = nrp + (k - nrp) % rp;

    cout << pass[ans] + 1 << ln;

}