akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int main() {
    int N, M, C; cin >> N >> M >> C;
    vector<int> B(M);
    for (int i = 0; i < M; ++i) cin >> B[i];
    int res = 0;
    for (int i = 0; i < N; ++i) {
        int sum = C;
        for (int j = 0; j < M; ++j) {
            int a; cin >> a; sum += a * B[j];
        }
        if (sum > 0) ++res;
    }
    cout << res << endl;
}














Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
string s;
int K;

int main() {
  INCANT;
  cin >> K >> s;
  if (s.size()<=K) {
    cout << s << endl;
    return 0;
  }
  rep(i, K) cout << s[i];
  cout << "...";
  cout <<  "\n";
  return 0;
}

Measured memory_bytes: 3652
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#define N 110000
using namespace std;
struct node{int y,nex;}a[N];
int n,f[N],fir[N],len,num,A[N];
void ins(int x,int y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
void dfs(int x)
{
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		dfs(y);
	}
	num=0;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		A[++num]=f[y];
	}
	sort(A+1,A+num+1);
	for(int i=1;i<=num;i++) f[x]=max(f[x],A[num-i+1]+i);
}
int main()
{
	scanf("%d",&n);
	for(int i=2;i<=n;i++)
	{
		int x;scanf("%d",&x);
		ins(x,i);
	}
	dfs(1);
	printf("%d\n",f[1]);
	return 0;
}

Measured memory_bytes: 4992
N, K = list(map(int, input().split()))
mod = 10**9+7
ans = [0]*(K+1)
s = 0
for i in range(K, 0, -1):
    ans[i] = pow(K//i, N, mod)
    for j in range(2*i, K+1, i):
        ans[i] -= ans[j]
    s += ans[i]*i%mod
print(s%mod)


Measured memory_bytes: 69020
#include<bits/stdc++.h>
using namespace std;
char iomap[1005][1005];
int step[1005][1005];
int n,m;
queue<pair<int,int> > qu;
int dx[4]={-1,1,0,0};
int dy[4]={0,0,-1,1};
bool islegal(int x,int y)
{
	return (x>=0&&x<n&&y>=0&&y<m&&step[x][y]==-1);
}
void bfs()
{
	while(!qu.empty())
	{
		int x=qu.front().first,y=qu.front().second;
		qu.pop();
		for(int i=0;i<4;i++)
		{
			int xx=x+dx[i],yy=y+dy[i];
			if(!islegal(xx,yy))
				continue;
			qu.push(make_pair(xx,yy));
			step[xx][yy]=step[x][y]+1;
		} 
	}
}
int main()
{
	cin>>n>>m;
	memset(step,-1,sizeof(step));
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
		{
			cin>>iomap[i][j];
			if(iomap[i][j]=='#')
			{
				qu.push(make_pair(i,j));
				step[i][j]=0;
			}
		}
	bfs();
	int ans=-1;
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			ans=max(ans,step[i][j]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 13328
def solve(t):
    res = 0
    length = 0
    n = len(t)
    used = [0] * n
    # insert 1 greedy
    for i in range(n):
        if t[i] == "1":
            length += 1
            res += (length + 1) // 2
            used[i] = 1

    # insert 0 greedy
    cnt_temp = 0
    for i in range(n):
        if used[i]:
            cnt_temp += 1
        elif cnt_temp % 2 == 1:
            # add 0 if it is 2, 4, 6 th
            cnt_temp += 1
            length += 1
            res += (length + 1) // 2
            used[i] = 1

    cnt_unused = n - sum(used)
    switch_count = 0
    # split by other 0
    st = 0
    cnt_1_even = 0
    cnt_1_odd = 0
    for i in range(n):
        if used[i] == 0:
            switched = (switch_count + 1) // 2
            non_switched = cnt_unused - switched
            res += cnt_1_even * non_switched + cnt_1_odd * switched
            st = i + 1
            switch_count += 1
            cnt_1_even = 0
            cnt_1_odd = 0
        if t[i] == "1":
            if (i - st) % 2 == 0:
                cnt_1_even += 1
            else:
                cnt_1_odd += 1

    # add last
    switched = (switch_count + 1) // 2
    non_switched = cnt_unused - switched
    res += cnt_1_even * non_switched + cnt_1_odd * switched

    return res


def main():
    t = input()
    res = solve(t)
    print(res)


def test():
    assert solve("1101") == 5
    assert solve("0111101101") == 26


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 10720
#include <iostream>
using namespace std;
int main(void)
{
    int a, b;
    while (std::cin >> a >> b)
    {
        int s = a + b;
        int n = 1;
        while (0 < s / 10)
        {
            n++;
            s = s / 10;
        }
        cout << n << endl;
    }
    return 0;
}



Measured memory_bytes: 3016
N, K, Q = map(int,input().split())
A = [int((input())) for i in range(Q)]
pt = [K for i in range(N)]

import collections
ct = collections.Counter(A)

for i in range(N):
    if K - (Q - ct[i+1]) >= 1:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 12740
#include<stdio.h>
#define MAX 100000

typedef struct{
    char name[100];
    int time;
} queue;
 
void enqueue(queue );
queue dequeue(void);
 
int head=0,end=0;
   queue Q[MAX];
 
    int main(void){
      int num,i,quantum,sum=0,f;
    queue q;
 
        scanf("%d%d",&num,&quantum);
        for(i=0;i<num;i++){
            scanf("%s%d",q.name,&q.time);
            enqueue(q);
        }
	f=1;
        while(f){
	  if(head == end){
	  break;
	  }
            if(Q[head].time > quantum){
                q = dequeue();
                q.time =q.time- quantum;
                enqueue(q);
                sum =sum+ quantum;
            }

            else{
                q = dequeue();
                printf("%s %d\n",q.name,(q.time+sum));
                sum =sum+ q.time;
            }
        }
return 0;
}

queue dequeue(){
    queue N;
    N = Q[head];
 
    if(head+1 == MAX){
      head = 0;
    }
    else head++;
    return N;
}
void enqueue(queue q){
Q[end] = q;
 if(end+1 == MAX){
   
  end = 0;
 }
else end++;
}

Measured memory_bytes: 10756
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define INF 1e9

int main()
{
  int N;
  cin >> N;

  int dp[200000];
  for (int i = 1; i <= N; i++) {
    dp[i] = INF;
  }

  dp[0] = 0;
  for (int i = 0; i <= N; i++) {
    int k = 1;
    while (k <= N) {
      dp[i + k] = min(dp[i] + 1, dp[i + k]);
      k *= 6;
    }
    k = 1;
    while (k <= N) {
      dp[i + k] = min(dp[i] + 1, dp[i + k]);
      k *= 9;
    }
  }
  cout << dp[N] << endl;
  return 0;
}

Measured memory_bytes: 896
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        int a, b, c;
        try(Scanner sc = new Scanner(System.in)){
            a = Integer.parseInt(sc.next());
            b = Integer.parseInt(sc.next());
            c = Integer.parseInt(sc.next());
        }
        
        int temp = a;
        a = b;
        b = temp;
        
        temp = a;
        
        a = c;
        c = temp;
        
        System.out.printf("%s %s %s", a, b, c);
    }
}

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

using namespace std;
typedef long long ll;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)

int main(){
// ここに処理を記述

    int N;
    cin >> N;

    vector< pair<int, int> > A;
    int temp = 0;
    for(int i=0; i<N; i++){
        cin >> temp;
        A.push_back( make_pair(temp, i+1) );
    }

    sort(A.begin(), A.end());

    FOR(i,0,N){
        cout << A[i].second << " ";
    }
return 0;
}

Measured memory_bytes: 1780
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            int A = int.Parse(Console.ReadLine());

            string[] s = Console.ReadLine().Split(' ');

            for (int i = 0; i < A; i++)
            {
                Console.Write(s[0][i]);
                Console.Write(s[1][i]);
            }

            Console.WriteLine();
        }
    }
}



Measured memory_bytes: 11092
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>

ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll now;

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n;
    rep(i,n)cin>>a[i];
    while(1){
        if(ans==1000000||now==1)break;
        ll to;
        to=a[now]-1;
        now=to;
        ans++;
    }
    if(ans==1000000)Cout(-1);
    else Cout(ans);
    return 0;
}


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

#define CO const
#define IN inline
typedef long long int64;

template<class T> IN T read(){
	T x=0,w=1;char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-') w=-w;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*w;
}
template<class T> IN T read(T&x){
	return x=read<T>();
}

CO int mod=1e9+7;
IN int add(int a,int b){
	return (a+=b)>=mod?a-mod:a;
}
IN int mul(int a,int b){
	return (int64)a*b%mod;
}
IN int fpow(int a,int b){
	int ans=1;
	for(;b;b>>=1,a=mul(a,a))
		if(b&1) ans=mul(ans,a);
	return ans;
}

CO int N=51;
int fac[N],ifac[N];
int F[N][N][N];

int main(){
	int n=read<int>();
	fac[0]=1;
	for(int i=1;i<=n;++i) fac[i]=mul(fac[i-1],i);
	ifac[n]=fpow(fac[n],mod-2);
	for(int i=n-1;i>=0;--i) ifac[i]=mul(ifac[i+1],i+1);
	F[n][0][0]=1;
	for(int i=n-1;i>=0;--i)
		for(int x=0;x<=n-i;++x)for(int y=0;y<=n-i-x;++y){
			for(int a=0;a<=n-i-x-y;++a)for(int b=0;b<=n-i-x-y-a;++b)
				if(x-a+b>=0 and y+a-b>=0)
					F[i][x][y]=add(F[i][x][y],mul(F[i+x+y][a][b],mul(ifac[x-a+b],ifac[y+a-b])));
		}
	int ans=mul(fac[n],F[0][1][0]);
	printf("%d\n",ans);
	return 0;
}


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

#define ll long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;

ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
int main() {
    //COMint();
    ll L=in();
    ll R=in();
    int ans;ans=2019;
    vector<int> v;
    for(int i=L;i<L+2019;i++){
        if(i<=R){
            v.push_back(i%2019);
            //debug(i%2019);
        }
    }
    REP(i,v.size()-1){
        for(int j=i+1;j<v.size();j++){
            ans=min(ans,(v[i]*v[j])%2019);
        }
    }
    print(ans);
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
using namespace std;

int main(void){

  
  int a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;
  int sum=0;
  int sum1=0;

    if(x==0 || y==0){
        sum=a*x+b*y;
    }else{
      if(a+b>2*c){
          if(x<y){
              sum=x*2*c+(y-x)*b;
              sum1=2*c*y;
              if(sum1<sum)sum=sum1;
          }else{
              sum=y*2*c+(x-y)*a;
              sum1=2*c*x;
              if(sum1<sum)sum=sum1;
          }
      }else{
          sum=a*x+b*y;
      }
  }
  cout<<sum<<endl;

}

Measured memory_bytes: 256
n,m,c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for j in range(n)]

count_ = 0
for i in range(n):
  sum_=0
  for j in range(m):
    sum_+=a[i][j]*b[j]
  if sum_>-c: count_+=1
print(count_)

Measured memory_bytes: 3060
# C
n = int(input())
b = list(map(int, input().split()))
a = [0 for i in range(n+1)]
a[0] = b[0]
for i in range(n-2):
    a.append(min(b[i], b[i+1]))
a.append(b[-1])
print(sum(a))

Measured memory_bytes: 38256
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String args[]) {
        int n = 0;
        int k = 0;
        long MOD = 1000*1000*1000 + 7;
        int[] arr = null;
        try (Scanner scanner = new Scanner(System.in)) {
            n = scanner.nextInt();
            k = scanner.nextInt();
            arr = new int[n];
            for(int i = 0; i < n ;i++) {
                arr[i] = scanner.nextInt();
            }
        }
        
        long[] dp = new long[k + 1];
        dp[0] = 1;
        // This will cause TLE as we are running n * k^2
        // for(int i = 0; i < n; i++) {
        //     int cap = arr[i];
        //     for(int used = k; used >=0 ; used--) {
        //         for(int candy = 1; candy <= Math.min(cap, k - used); candy++) {
        //             dp[candy + used] = (dp[candy + used] + dp[used])%MOD; 
        //         }
        //     }   
        // }
        
        // We can remove last loop of K by having one more array to have range updated
        // and dp in seperate loop not nested
        for(int i = 0; i < n; i++) {
            int cap = arr[i];
            long[] rangeUpdate = new long[k + 1];
            for(int used = k; used >=0 ; used--) {
                int rangeStart = used + 1;
                int rangeEnd = used + Math.min(cap, k - used);
                if(rangeStart <= rangeEnd){
                    rangeUpdate[rangeStart] += dp[used];
                    if(rangeEnd + 1 <= k)
                        rangeUpdate[rangeEnd + 1] -= dp[used];
                        
                }
            }
            
            long prefixSum = 0;
            for(int j = 0; j <= k; j++) {
                prefixSum += rangeUpdate[j];
                dp[j] = (dp[j] + prefixSum)%MOD;
            }
        }
        // System.out.println(Arrays.toString(dp));
        System.out.println(dp[k]);
        
    }
    
}

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

using namespace std;

#define int ll
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

int dp[105][150010];

signed main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr); 
    cerr.tie(nullptr);    

    int n, W;
    cin >> n >> W;

    vi w(n + 1), v(n + 1);
    for (int i = 0; i < n; ++i){
        cin >> w[i] >> v[i];
    }

    for (int i = 0; i <= n; ++i){
        for (int j = 0; j <= 150005; ++j)
            dp[i][j] = INT32_MAX;
    }

    for (int i = 0; i <= n; ++i){
        for (int j = 150000; j >= 0; --j){
            dp[i][j] = INT32_MAX;

            if (!j){
                dp[i][j] = 0;
                continue;
            }

            if (!i){
                dp[i][j] = INT32_MAX;
                continue;
            }

            dp[i][j] = min(dp[i][j + 1], dp[i - 1][j]);
            dp[i][j] = min(dp[i][j], dp[i - 1][max(0ll, j - v[i - 1])] + w[i - 1]);
        }
    }

    for (int j = 150000; j >= 0; --j){
        if (dp[n][j] <= W)
            return cout << j << '\n', 0;
    }
}

Measured memory_bytes: 119040
#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define me0(a) memset(a,0,sizeof(a))
#define me1(a) memset(a,-1,sizeof(a))
#define op freopen("in.txt", "r", stdin)
#define pii pair<int,int>
#define mp(x,y) make_pair(x,y)
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long LL;
void read(int& val) { int x = 0; int bz = 1; char c; for (c = getchar(); (c<'0' || c>'9') && c != '-'; c = getchar()); if (c == '-') { bz = -1; c = getchar(); }for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48; val = x * bz; }
const int maxn = 1e6+10;

int x[maxn];

int main(){
    fo(i,1,5){
        cin>>x[i];
        if(x[i]==0){
            cout<<i<<endl;return 0;
        }
    }
}

Measured memory_bytes: 3548
my ($n) = split(' ', <>);
my @x = split(' ', <>);

my @sorted = sort { $a <=> $b } @x;
my $a = $sorted[$n/2 - 1];
my $b = $sorted[$n/2];

for my $x (@x) {
    print (($x <= $a ? $b : $a)."\n");
}


Measured memory_bytes: 51504
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define pb push_back
#define popb pop_back
#define mt make_tuple 
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second 
#define ull unsigned long long  
#define pii pair<int, int>
#define piii pair<int,pii>
#define beg begin
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define fill(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define int ll
using ll = long long;
const int N = 3*1e5 +5 ;
const int mod = 1e9 + 7 ;
const int inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace __gnu_pbds;
using namespace std;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

#ifdef AaryanS
#define mycout cout
#define mycerr cerr 
#endif

#ifndef AaryanS
#define mycout if(false) cout
#define mycerr if(false) cerr
#endif

vector<int> dp(N,inf) , a; 
int k;
void solve()
{
	int n ;
	cin >> n >> k ;
	a.resize(n);
	for(auto &it : a) cin >> it; 
	dp[0] = 0 ;
	for(int i = 0 ; i < n ; ++i)
		for(int j = 1 ; j <= k && i+j < n ; ++j)
			dp[i+j] = min(dp[i+j], dp[i] + abs(a[i+j] - a[i])); 
	cout << dp[n-1] ;
}   

     
int32_t main(int32_t argc, char *argv[])
{
    double t1 = clock() ;
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        //cout << endl ;
    }
    mycerr << "Time : " << 1000 *(clock() - t1)/CLOCKS_PER_SEC << " ms\n" ;
    return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    char a[50],b[50];
    cin>>a>>b;
    int l,k,i,j;
    l=strlen(a);
    k=strlen(b);
if(l-k==0)
       {

        for(i=0;i<k;i++)
        {
            cout<<a[i]<<b[i];
        }
        cout<<endl;
       }
       else
       {

        for(i=0;i<k;i++)
        {
            cout<<a[i]<<b[i];
        }
        cout<<a[l-1]<<endl;

       }

}


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

int main() {

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

if (a < b)          cout << "a < b" << endl; 
else if ( a > b)    cout << "a > b" << endl; 
else if (a == b)    cout << "a == b" << endl; 
}


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

struct StDtl
{
  int m_nLeft;

  StDtl(int nLeft) :
    m_nLeft(nLeft)
  { }
};

struct StSum
{
  int m_nLeft;
  int m_nRight;
  int m_nArea;

  StSum(int nLeft, int nRight, int nArea) :
    m_nLeft(nLeft), m_nRight(nRight), m_nArea(nArea)
  { }
};

void fnCroSecSet(stack<StDtl> &rskStDtl, vector<StSum> &rvStSum, int &rnTotalArea)
{
  string sCrossSect;
  cin >> sCrossSect;

  for (int i = 0; i < sCrossSect.size(); i++)
  {
    if (sCrossSect[i] == '\\')
    {
      StDtl oDtl(i);
      rskStDtl.push(oDtl);
    }
    else if (sCrossSect[i] == '/')
    {
      if (rskStDtl.size() > 0)
      {
        int nLeft = rskStDtl.top().m_nLeft; rskStDtl.pop();
        int nSum = i - nLeft; 
        rnTotalArea += nSum;

        while (rvStSum.size()  &&
               nLeft < rvStSum.back().m_nLeft  &&
               rvStSum.back().m_nRight < i       )
        {
          nSum += rvStSum.back().m_nArea;
          rvStSum.pop_back();
        }
        StSum oSum(nLeft, i, nSum);
        rvStSum.push_back(oSum);
      }
      else;
    }
  }
}

void  fnCroSecGet(const vector<StSum> &cnrvStSum, int nTotalArea)
{
  cout << nTotalArea << endl;
  cout << cnrvStSum.size();
  if (cnrvStSum.size() > 0)
  {
    cout << " ";
    for (auto itvStSum = begin(cnrvStSum); itvStSum != end(cnrvStSum); ++itvStSum)
    {
      if (itvStSum != begin(cnrvStSum)) cout << " ";
      cout << itvStSum->m_nArea;
    }
  }
  cout << endl;
}

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

  stack<StDtl> skStDtl;
  vector<StSum> vStSum;
  int iTtlAra = 0;

  fnCroSecSet(skStDtl, vStSum, iTtlAra);
  fnCroSecGet(vStSum, iTtlAra);

  return 0;
}

Measured memory_bytes: 3312
n,m,c = gets.split(" ").map(&:to_i)
b = gets.split(" ").map(&:to_i)
a = []
while as = gets do
    as = as.split(" ").map(&:to_i)
    a.push(as)
end

i = 0
count = 0
while n-1 >= i do
    an = a[i]
    sum = 0
    bi = 0
    an.each do |a|
        sum = (a * b[bi]) + sum
        bi = bi + 1
    end
    count = count + 1 if (sum + c) > 0
    i = i + 1
end

puts count




Measured memory_bytes: 1788
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

struct pond{
	int am;
	int md;
};

int main(){
	string s;
	stack<int> st;
	deque<pond> qu;
	int total=0;
	cin >> s;
	for(int i=0;i<s.length();++i){
		if(s[i]=='\\'){
			st.push(i);
		} else {
			if(s[i]=='/' && !st.empty()){
				pond p;
				p.md=st.top();
				st.pop();
				p.am=i-p.md;
				total+=p.am;
				while(!qu.empty()){
					pond p2=qu.back();
					if(p.md < p2.md){
						p.am+=p2.am;
						qu.pop_back();
					} else {
						break;
					}
				}
				qu.push_back(p);
			}
		}
	}
	cout << total << endl;
	int len=qu.size();
	if(!len){
		cout << len;
	} else {
	cout << len << " ";
	}
	for(int i=0;i<len-1;++i){
		pond tmp=qu.front();
		cout << tmp.am << " ";
		qu.pop_front();
	}
	if(!qu.empty()){
		pond tmp=qu.front(); 
	    cout << tmp.am;
	}
	cout << endl;
	qu.pop_front();
	return 0;
}

Measured memory_bytes: 1324
#include <iostream>
#include <vector>
#include <string>
#include<algorithm> 
#include <cmath>

using namespace std;

int main()
{
  long long int n;
  cin >>n;
  
  long long int min;
  
  long double r=sqrt(n);
  int root=r;
  
 
  
  for(long long int i=root;;i--){
    if(n%i==0){min=i+(n/i);break;}
  }
    
  cout << min-2;}
  

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class B
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var r = new List<long>();
		var h = Read();
		var n = h[0];
		var a = Read();

		var st = new ST(n);
		for (int i = 0; i < n; i++)
			st.Add(i, a[i]);

		for (int i = 0; i < h[1]; i++)
		{
			var q = Read();
			if (q[0] == 0)
				st.Add(q[1], q[2]);
			else
				r.Add(st.Subsum(q[1], q[2]));
		}
		Console.WriteLine(string.Join("\n", r));
	}
}

class ST
{
	int kMax;
	List<long[]> vs = new List<long[]> { new long[1] };
	public ST(int n)
	{
		for (int c = 1; c < n; vs.Add(new long[c <<= 1])) ;
		kMax = vs.Count - 1;
	}

	(int k, int i)[] GetLevels(int i)
	{
		var r = new List<(int, int)>();
		for (int k = kMax; k >= 0; --k, i >>= 1) r.Add((k, i));
		return r.ToArray();
	}

	(int k, int i)[] GetRange(int minIn, int maxEx)
	{
		var r = new List<(int, int)>();
		for (int k = kMax, f = 1; k >= 0 && minIn < maxEx; --k, f <<= 1)
		{
			if ((minIn & f) != 0) r.Add((k, (minIn += f) / f - 1));
			if ((maxEx & f) != 0) r.Add((k, (maxEx -= f) / f));
		}
		return r.ToArray();
	}

	public long Get(int i) => vs[kMax][i];
	public void Set(int i, long v) => Add(i, v - vs[kMax][i]);

	public void Add(int i, long v)
	{
		foreach (var (k, j) in GetLevels(i)) vs[k][j] += v;
	}

	public long Subsum(int minIn, int maxEx) => GetRange(minIn, maxEx).Sum(x => vs[x.k][x.i]);
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;

typedef pair<int,int>Pi;
typedef pair<long long,long long>P;
typedef pair<long long,P>PP;
typedef pair<P,P>PPP;

const long long MOD=1e9+7;
const long long INF=5e18;
const int di[4]={1,0,-1,0};
const int dj[4]={0,1,0,-1};

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()

int a,b,k;
int now;

void input(){
	cin>>a>>b>>k;
	return;
}

void solve(){
	for(int i=min(a,b);i>=1;i--){
		if(a%i==0&&b%i==0){
			now++;
			if(now==k){
				cout<<i<<endl;
				return;
			}
		}
	}
	return;
}

int main(){
	input();
	solve();
	return 0;
}

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

#define int long long

int memo[87];

int luca(int n) {
    if(memo[n]!=0) return memo[n];
    if(n==0) return 2;
    if(n==1) return 1;
    return memo[n] = luca(n-1) + luca(n-2);
}

signed main() {
    int n;
    cin >> n;
    cout << luca(n) << endl;
    return 0;
}



Measured memory_bytes: 256
import std.functional,
       std.algorithm,
       std.bigint,
       std.string,
       std.traits,
       std.array,
       std.range,
       std.stdio,
       std.conv;

void main() {
  string[] XY = readln.chomp.split.to!(string[]);
  string X = XY[0],
         Y = XY[1];

  if (X < Y) {
    writeln("<");
  } else if (X > Y) {
    writeln(">");
  } else {
    writeln("=");
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
using namespace std;

const int MOD = 1000000007;
typedef long long ll;

vector<char> t(200000),d(200000);


bool f1(int index,int N, string s, vector<char> t, vector<char> d,int Q) {
  int now=index;
  for(int i=0;i<Q;i++){
    if(now==-1)break;
    if(now==N)break;
    if(s[now]==t[i]){
      if(d[i]=='L'){
        now-=1;
      }else{
        now+=1;
      }
    }
  }
  if(now==-1){
    return true;
  }else{
    return false;
  }
}

bool f2(int index,int N, string s, vector<char> t, vector<char> d,int Q) {
  int now=index;
  for(int i=0;i<Q;i++){
    if(now==-1)break;
    if(now==N)break;
    if(s[now]==t[i]){
      if(d[i]=='L'){
        now-=1;
      }else{
        now+=1;
      }
    }
  }
  if(now==N){
    return true;
  }else{
    return false;
  }
}


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,Q,ans;
  string s;
  cin>>N>>Q;
  ans=N;
  cin>>s;
  for(int i=0;i<Q;i++){
    cin>>t[i]>>d[i];
  }
  
  int ng1 = N, ok1 = -1;
  while (ng1 - ok1 > 1) {
    int mid = (ng1 + ok1) / 2;
    (f1(mid,N,s,t,d,Q) ? ok1 : ng1) = mid;
  }

  if (ok1 == -1){
    ans-=0;
  }else{
    ans-=(ok1+1);
  }

  int ng2 = -1, ok2 = N;
  while (ok2 - ng2 > 1) {
    int mid = (ng2 + ok2) / 2;
    (f2(mid,N,s,t,d,Q) ? ok2 : ng2) = mid;
  }

  if (ok2 == N){
    ans-=0;
  }else{
    ans-=(N-ok2);
  }


  cout << ans << endl;
}


Measured memory_bytes: 1556
import sys


N = int(sys.stdin.readline())
points = []
for _ in range(N):
    x, y = map(int, sys.stdin.readline().split())
    points.append((x, y))

f1 = []
f2 = []
for (x, y) in points:
    f1.append(x-y)
    f2.append(x+y)

ans = max(max(f1) - min(f1), max(f2) - min(f2))
print(ans)

Measured memory_bytes: 110724
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <numeric>
#include <vector>
using namespace std;
#define MAXSIZE 200
#define MAXL 100
#define NUM 1000000007
typedef long long int lli;

int main(){
    int n, a;
    cin >> n >> a;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        ans += min(x, a - x) * 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<iostream>
 
using namespace std;
 
typedef long long ll;
 
const int N = 2000006;
 
int m,k;

vector<int> v[22];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	cin>>m>>k;
	
	if( k >= (1<<m) ){
		cout<<-1;
		return 0;
	}
	if( m == 1 ){
		if(k == 0){
			cout<<"0 0 1 1";
		}else{
			cout<<-1;
		}
		return 0;
	}
	
	if(m == 0){
		cout<<"0 0";
		return 0;
	}
	
	v[1].push_back(0);
	v[1].push_back(1);
	v[1].push_back(2);
	v[1].push_back(3);
	
	int idx = 1;
	
	for(int i=2;i<m;i++){
		for(int j=(1<<i);j<(1<<(i+1));j++){
			v[i].push_back(j);
			if(j == k) idx = i;
		}
	}
	
	for(int i=1;i<m;i++){
		if(i == idx)continue;
		for(int x:v[i]){
			cout<<x<<" ";
		}
	}
	cout<<k<<" ";
	for(int i=m-1;i>0;i--){
		if(i == idx)continue;
		reverse(v[i].begin(),v[i].end());
		for(int x:v[i]){
			cout<<x<<" ";
		}
	}
	
	for(int x:v[idx]){
		if(x == k)continue;
		cout<<x<<" ";
	}
	
	cout<<k<<" ";
	
	reverse(v[idx].begin(),v[idx].end());
	
	for(int x:v[idx]){
		if(x == k)continue;
		cout<<x<<" ";
	}
	
	return 0;
}


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

int main()
{
  int N, A;
  string op;
  cin >> N >> A;

  if (N % 500 == 0)
  {
    cout << "Yes" << endl;
  }
  else if (N % 500 <= A)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[201];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	int ans=0;
	for(int i=2;i<=n;i++)
		if(a[i]==a[i-1])ans++,a[i]=n+1;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 764
n=int(input())
a=[]
for i in range(n):
    a.append(int(input())-1)
ans=1
i=0
b=[]
while(1):
    if ans==n:
        print(-1)
        exit()
    elif a[i]==1:
        print(ans)
        exit()
    else:
        ans+=1
        i=a[i]

Measured memory_bytes: 7316
using System;
class ProgramA
    {
        static void Main(string[] args)
        {
            
            string input = Console.ReadLine();
            ulong[] line = new ulong[10000000];
            ulong count = 1;
            ulong count_line = 0;
            ulong sum = 0;
            ulong start = 1;
          
            if(input.Length == 1)
            {
                Console.WriteLine("1");
                return;
            }

            
            for(int i = 1; i < input.Length;i++)
            {
                if(input[i] == input[i - 1])
                {
                    count++;
                }
                else
                {
                    line[count_line] = count;
                    count = 1;
                    count_line++;
                }
              
                if(i == input.Length - 1)
                {
                    line[count_line] = count;
                    count_line++;
                }
            }

            for(ulong i = 0;i < count_line;i++)
            {
                ulong plus = line[i] - 1;
                sum += (plus + 1) * plus / 2;
            }

            if(input[0] == '>')
            {
                start = 2;
                sum += line[0];
            }

            for(ulong i = start;i <= count_line;i = i + 2)
            {
                if(line[i] > line[i - 1])
                    sum += line[i];
                else
                    sum += line[i - 1];
            }
          
            Console.WriteLine(sum);
        }
    }

Measured memory_bytes: 15200
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner i=new Scanner(System.in);
		int a=i.nextInt();
		int b=i.nextInt();
		int c=i.nextInt();
		if(a<b&&b<c)System.out.println("Yes");
		else System.out.println("No");
		}
	}

Measured memory_bytes: 17160
#include <bits/stdc++.h>
using namespace std;
enum {W, S, E, N};
const int dx[] = {0, 1, 0, -1};
const int dy[] = {-1, 0, 1, 0};
struct P {
	int x, y, ang;
	P(){}
	P(int x, int y, int ang) : x(x), y(y), ang(ang) {}
	bool operator < (const P &t) const {
		return ang < t.ang;
	}
};

int n, m;
bool grid[32][32];
bool pre[32][32];
bool goal[32][32];
vector<P> ps;

void solve()
{
	int res = 0;
	while (ps.size()){
		if (++res >= 180){
			puts("NA");
			return;
		}
		
		for (int i = 0; i < ps.size(); i++){
			//printf("%d %d %d\n", i, ps[i].x, ps[i].y);
			
			for (int t = -1; t < 3; t++){
				int dir = (ps[i].ang + t + 4) % 4;
				int nx = ps[i].x + dx[dir];
				int ny = ps[i].y + dy[dir];
				if (!grid[nx][ny]){
					ps[i].ang = dir;
					break;
				}
			}
		}
		sort(ps.begin(), ps.end());
		for (int i = 0; i < ps.size(); i++){
			int nx = ps[i].x + dx[ps[i].ang];
			int ny = ps[i].y + dy[ps[i].ang];
			if (grid[nx][ny]) continue;
			pre[ps[i].x][ps[i].y] = true;
			grid[nx][ny] = true;
			ps[i].x = nx;
			ps[i].y = ny;
			if (goal[nx][ny]){
				ps.erase(ps.begin() + i--);
			}
		}
		for (int i = 1; i <= n; i++){
			for(int j = 1; j <= m; j++){
				if (pre[i][j]) grid[i][j] = false;
				if (goal[i][j]) grid[i][j] = false;
				pre[i][j] = false;
				
				//printf("%c", grid[i][j] ? '#' : ' ');
			}
			//puts("");
		}
	}
	printf("%d\n", res);
}

int main()
{
	while (scanf("%d %d", &m, &n), m){
		memset(grid, true, sizeof(grid));
		memset(goal, false, sizeof(goal));
		memset(pre, false, sizeof(pre));
		ps.clear();
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= m; j++){
				char c;
				scanf(" %c", &c);
				if (c == '#'){
					grid[i][j] = true;
					continue;
				}
				else if (c == 'X'){
					goal[i][j] = true;
					grid[i][j] = false;
				}
				else if (c == 'W'){
					grid[i][j] = true;
					ps.push_back(P(i, j, W));
				}
				else if (c == 'S'){
					grid[i][j] = true;
					ps.push_back(P(i, j, S));
				}
				else if (c == 'E'){
					grid[i][j] = true;
					ps.push_back(P(i, j, E));
				}
				else if (c == 'N'){
					grid[i][j] = true;
					ps.push_back(P(i, j, N));
				}
				else {
					grid[i][j] = false;
				}
			}
		}
		solve();
	}
}

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

#define ll long long
using namespace std;

const ll mod = 1e9 + 7;
ll Calc_pow(ll x, ll pow)
{
	if (pow == 0) return 1;
	ll a = Calc_pow(x, pow / 2);
	a = a * a % mod;
	if (pow % 2 == 1) a *= x;
	return a % mod;
}

ll Devide(ll n)
{
	return Calc_pow(n % mod, mod - 2) % mod;
}

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

	vector<ll> sum(n + 1);
	for (int i = 1; i <= n; i++)
	{
		sum[i] = Devide(i) + sum[i - 1];
		sum[i] %= mod;
	}

	ll fact = 1;
	for (int i = 1; i <= n; i++)
	{
		fact *= i;
		fact %= mod;
	}

	ll ret = 0;
	for (int i = 0; i < n; i++)
	{
		ll t = sum[i + 1] + sum[n - i] - 1;
		t %= mod;
		ret += (a[i] * t % mod) * fact % mod;
		ret %= mod;
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 1792
//途中で0があると積は0担ってしまうので一旦全て入力しきったあとでないと判断できない
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a;
  cin >> a;
  if(a == 25)cout<<"Christmas"<<endl;
  else if(a == 24)cout<<"Christmas Eve"<<endl;
  else if(a == 23)cout<<"Christmas Eve Eve"<<endl;
  else if(a == 22)cout<<"Christmas Eve Eve Eve"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



struct Info{
	Info(ll arg_loc,ll arg_count){
		loc = arg_loc;
		count = arg_count;
	}
	ll loc,count;
};

#define SIZE 1000005

ll A[SIZE];
ll table[SIZE];
map<ll,ll> MAP;
bool is_prime[SIZE];
vector<Info> info[10005];


ll mod_pow(ll x,ll count, ll mod){

	if(count == 0)return 1;
	ll ret = mod_pow((x*x)%mod,count/2,mod);
	if(count%2 == 1){

		ret = (ret*x)%mod;
	}
	return ret;
}


ll extgcd(ll a,ll b,ll &x,ll &y){
	ll d = a;
	if(b != 0){
		d = extgcd(b,a%b,y,x);
		y -= (a/b)*x;
	}else{
		x = 1;
		y = 0;
	}
	return d;
}

ll mod_inverse(ll a,ll m){
    ll x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}

int main(){

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

		is_prime[i] = true;
		table[i] = 0;
	}

	is_prime[0] = false;
	is_prime[1] = false;

	for(int i = 2; i < SIZE; i++){
		if(is_prime[i]){
			for(int k = 2*i;k < SIZE; k += i){
				is_prime[k] = false;
			}
		}
	}

	vector<ll> PRIME;
	for(int i = 2; i < SIZE; i++){
		if(is_prime[i]){
			MAP[i] = PRIME.size();
			PRIME.push_back(i);
		}
	}



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

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

		scanf("%lld",&A[i]);
		ll tmp = A[i];

		for(int k = 0; PRIME[k]*PRIME[k] <= A[i]; k++){

			if(tmp%PRIME[k] != 0)continue;

			ll count = 0;

			while(tmp > 0 && tmp%PRIME[k] == 0){
				count++;
				tmp /= PRIME[k];
			}
			table[k] = max(table[k],count);
			info[i].push_back(Info(k,count));

		}
		if(is_prime[tmp]){

			table[MAP[tmp]] = max(table[MAP[tmp]],1LL);
			info[i].push_back(Info(MAP[tmp],1));
		}
	}

	ll base = 1;
	for(int i = 0; i < PRIME.size(); i++){

		base *= mod_pow(PRIME[i],table[i],MOD);
		base %= MOD;
	}

	ll ans = 0;

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

		ll tmp = base*mod_inverse(A[i],MOD);
		tmp %= MOD;

		ans += tmp;
		ans %= MOD;
	}

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

	return 0;
}


Measured memory_bytes: 17396
#include <bits/stdc++.h>
using namespace std;
// x^y≡x^(y%(p-1))mod p
// but there is a condition that x needs to be coprime to p
///assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
typedef long long int ll;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
#define  pb push_back
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fo(i,a,b) for(ll i = a; i<=b;i+=1)
#define rf(i,a,b)  for(ll i=a;i>=b;i--)
#define vll vector<ll>
#define tests() int test_cases ; cin >> test_cases ; while(test_cases--)
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define MAXN 100010
#define MOD 1000000007
#define mod 998244353
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define sp " "
#define MS(x,y) fill_n(*x, sizeof x / sizeof **x, y);
#define mem(x,y) memset(x,y,sizeof(x));
#define INF 1000000000000000000
#define IO                 \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0);
#define debug(x) cerr << (#x) << " is " << (x) << endl;

#ifndef ONLINE_JUDGE
#define cerr if(true)cerr
#endif

template<int D, typename T>
struct Vec : public vector<Vec<D - 1, T>> {
static_assert(D >= 1, "Vector dimension must be greater than zero!");
template<typename... Args>
	Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {
	}
};
template<typename T>
struct Vec<1, T> : public vector<T> {
	Vec(int n = 0, const T& val = T()) : vector<T>(n, val) {
	}
};

ll power(ll x, ll y,ll p) 
{ 
    ll res = 1;     // Initialize result 
    x = x % p;
    if (y==0)return 1;
    if(x==0)return 0;   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p;    
        y = y>>1; // y = y/2 
        x = (x*x) % p;  // Change x to x^2 
    } 
    return res; 
}
int gcd(int a, int b) { if (a == 0)return b;return gcd(b % a, a);} 

ll modinv(ll a,ll p){return power(a,p-2,p);}

int solve(){
    ll n,k;
    cin>>n>>k;
    vll a(n+1);
    f(i,0,n){
        cin>>a[i+1];
    }
    ll idx  = 1;
    vll path;
    // path.pb(1);
    Vec<1,bool> vis(n+1,false);
    // vis[1] = true;
    // vis[1] = true;
    stack<ll> stk;
    while(vis[idx]==false){
        path.pb(idx);
        stk.push(idx);
        vis[idx] = true;
        idx = a[idx];
    }
    ll length = 0;
    while(stk.top()!=idx){
        length++;
        stk.pop();
    }
    length++;
    ll cnt = path.size();
    ll con = cnt-length;
    // deb(con)deb(cnt)
    // deb(length)
    if (k<=con)
    {
        cout<<path[k]<<endl;;
    }
    else 
    cout<<path[con+(k-con)%length];
    return 0;
}
int main()
{
    IO;
    #ifndef ONLINE_JUDGE 
    freopen("input.txt", "r", stdin); 
    freopen("out.txt", "w", stdout); 
    #endif 
    int T=1;
	// cin >> T;
	f(c,0,T){
		solve();
	}
    return 0;
}// make_pair make_tuple  tuple<int,int,int> continue resize insert count size else true isValid second first

Measured memory_bytes: 7988
import java.util.*;

public class Main{

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int m = sc.nextInt();

    Set<Integer> list = new HashSet<>();

//    List<Integer>[] lists = new ArrayList[n];

    public static void main(String[] args){
        new Main().run();
    }

    void run() {

//        for (int i=0; i<n; i++) lists[i] = new ArrayList<>();

        int[] h = new int[n];

        for (int i=0; i<n; i++) {
            h[i] = sc.nextInt();
        }

        for (int i=0; i<m; i++) {
            int a = sc.nextInt()-1;
            int b = sc.nextInt()-1;
            if (h[a] < h[b]) list.add(a);
            else if (h[b] < h[a]) list.add(b);
            else {
                list.add(a);
                list.add(b);
            }
        }

        System.out.println(n - list.size());

//        for (int i=0; i<m; i++) {
//            int a = sc.nextInt()-1;
//            int b = sc.nextInt()-1;
//            lists[a].add(b);
//            lists[b].add(a);
//        }

        int cnt = 0;

//        for (int i=0; i<n; i++) {
//            int base = h[i];
//
//        }
    }
}


Measured memory_bytes: 63864
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <limits>
#include <algorithm>
#include <memory>
#include <climits>
#include <iomanip>

constexpr long long MOD = 1000000007;

void dfs(const std::vector<std::vector<int>>& edges, int cur, std::vector<bool>& memo)
{
  memo[cur] = true;
  for (auto& v: edges[cur])
  {
    if (!memo[v])
    {
      dfs(edges, v, memo);
    }
  }
}

int main()
{
  int N, M;
  std::cin >> N >> M;
  std::vector<std::vector<int>> edges(N);
  while (M--)
  {
    int x, y, z;
    std::cin >> x >> y >> z;
    --x;
    --y;
    edges[x].push_back(y);
    edges[y].push_back(x);
  }
  std::vector<bool> memo(N, false);
  int ans = 0;
  for (int i = 0; i < N; ++i)
  {
    if (!memo[i])
    {
      ++ans;
      dfs(edges, i, memo);
    }
  }
  std::cout << ans << std::endl;
  return 0;
}



Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second)
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) (find(all(v),x)!=v.end())
#define incls(s,c) (s.find(c)!=string::npos)
#define lb(a,x) distance((a).begin(),lower_bound(all(a),(x)))
#define ub(a,x) distance((a).begin(),upper_bound(all(a),(x)))
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(all(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; cin >> x; return x;}
inline ll lin() { ll x; cin >> x; return x;}
inline char chin() { char x; cin >> x; return x;}
inline string stin() { string x; cin >> x; return x;}
inline double din() { double x; cin >> x; return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  int n = in();
  vi dp(n+1);
  dp[0] = dp[1] = 1;
  srep(i,2,n+1) dp[i] = dp[i-1] + dp[i-2];
  cout << dp[n] << endl;
  return 0;
}


Measured memory_bytes: 3104