stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<bits/stdc++.h> //Ithea Myse Valgulious

namespace chtholly{

typedef long long ll;

#define re0 register int

#define rel register ll

#define rec register char

#define gc getchar

#define pc putchar

#define p32 pc(' ')

#define pl puts("")

/*By Citrus*/

inline int read(){

  int x=0,f=1;char c=gc();

  for (;!isdigit(c);c=gc()) f^=c=='-';

  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');

  return f?x:-x;

  }

template <typename mitsuha>

inline bool read(mitsuha &x){

  x=0;int f=1;char c=gc();

  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';

  if (!~c) return 0;

  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');

  return x=f?x:-x,1;

  }

template <typename mitsuha>

inline int write(mitsuha x){

  if (!x) return 0&pc(48);

  if (x<0) pc('-'),x=-x;

  int bit[20],i,p=0;

  for (;x;x/=10) bit[++p]=x%10;

  for (i=p;i;--i) pc(bit[i]+48);

  return 0;

  }

inline char fuhao(){

  char c=gc();

  for (;isspace(c);c=gc());

  return c;

  }

}using namespace chtholly;

using namespace std;

const int yuzu=1e5;

typedef ll fuko[yuzu|10];

fuko a;

int main(){

int i,n=read(),k=read();

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

ll llx=1e18;

for (i=k;i<=n;++i) llx=min(llx,min(abs(a[i-k+1]),abs(a[i]))+a[i]-a[i-k+1]);

write(llx);

}

// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<iostream>

#include<algorithm>

using namespace std;

int n,m,a[1000000],ans,x,y;

int main(){

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

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

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

        }

        ans=1000000000;

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

                x=a[i];

                y=a[i+m-1];

                if(x>0){

                        ans=min(ans,y);

                        continue;

                }

                if(y<0){

                        ans=min(ans,-x);

                        continue;

                }

                ans=min(ans,y-2*x);

                ans=min(ans,-x+2*y);

        }

        printf("%d",ans);

}

// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define ll long long

using namespace std;



ll int pos[100005],sum[100005];



int main(void)

{

    int n,k;

    cin >>n>>k;

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

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

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

    }



    ll int ans=1e17;

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

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

    }



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



    return 0;

}

// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
// 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;

}






















































































// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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);

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>



using namespace std;



int main()

{

    int N, P;

    cin >> N >> P;



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







    return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>

int main()

{

    int N,P;

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

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

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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");

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}




// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}




// Optimized solution to the same problem (faster):
#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];

    }

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}




// Optimized solution to the same problem (faster):
#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];

    }

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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 = 1000100010001000100LL;

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

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

#define rept(i, j, n) for(int i=(j); 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<int> next(n);

    rep(i, n){

        int a; cin >> a; a--;

        next[i] = a;

    }

    vector<int> seen(n,-1); //最短距離

    seen[0] = 0; int cur = 0; bool roop = false;

    rep(i, k){

        int nx = next[cur];

        if(seen[nx]== -1){

            seen[nx] = seen[cur]+1;

            cur = nx;

        }

        else{

            roop = true;

            break;

        }

    }

    if(roop){

        ll len = seen[cur]+1 - seen[next[cur]];

        ll rs = k - seen[next[cur]];

        rep(i, rs % len+1){

            cur = next[cur];

        }

    }

    cout << cur+1 << ln;



}

// Fastest known solution for this problem: