akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace CP
{
    class Atria
    {

        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            var dic = new Dictionary<long, int>();
            for (int i = 0; i < n; i++)
            {
                long tmp = long.Parse(ReadLine());
                try
                {
                    dic.Add(tmp,1);
                }
                catch (Exception)
                {
                    dic[tmp]++;
                }
            }
            WriteLine(
                dic.Values.Count(x => x%2 != 0)
                );
        }
    }
}


Measured memory_bytes: 23392
#include <iostream>
#include <string>

using namespace std;

int main() {

   string ring, find;

   cin >> ring;

   ring += ring;

   cin >> find;

   if (ring.find(find) == string::npos) {
      cout << "No";
   } else {
      cout << "Yes";
   }

   cout << endl;

   return 0;

}

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

int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	for(int i=0;i<N;i++){
		cin >> a.at(i);
	}
	sort(a.begin(), a.end(),greater<int>());

	int x,y;
	x=0;
	y=0;
	for(int j=0;j<N;j++){
		if(j%2==0) x+=a.at(j);
		else y+=a.at(j);
	}
	cout << x-y << endl;
}

Measured memory_bytes: 3588
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <limits>
using namespace std;
// 素因数分解
typedef pair<long long, long long> P;
vector<P> prime_factorize(long long n)
{
vector<P> res;
for (long long p = 2; p * p <= n; ++p)
{
if (n % p != 0)
continue;
int num = 0;
while (n % p == 0)
{
++num;
n /= p;
}
res.push_back(make_pair(p, num));
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
// 因数分解
long long gcd(long long x, long long y)
{
  if (y == 0)
  {
    return x;
  }
  else
  {
    return gcd(y, x % y);
  }
}
const int MOD = 1000000007;
typedef long long int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)

int main()
{
    double L;
    cin >> L;
    L /= 3.0;
    double ans = pow(L, 3);
    cout <<fixed<<setprecision(10)<< ans << endl;
    return 0;
}

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

int main() {
  int n;	//時間
  int a;	//1時間当たりの料金
  int b;	//時間によらない料金
  
  cin >> n >> a >> b;
  
  int p1 = n * a;
  int p2 = b;
  
  if (p1 < p2) {
    cout << p1 << endl;
  }
  else {
    cout << p2 << endl;
  }
}

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

long NumOfDividableInteger(long k, long x) {
  if (k == -1) {
    return 0;
  }
  return k / x + 1;
}

int main() {
  long a, b ,x;
  std::cin >> a >> b >> x;
  long ans;
  ans = NumOfDividableInteger(b, x) - NumOfDividableInteger(a-1, x);
  std::cout << ans << std::endl;
}

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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

void solve() {
    int n, m;
    string s, t;

    set<string> word_set;

    map<string, int> blue_count;
    cin >> n;
    rep(0, n) {
        cin >> s;
        blue_count[s]++;
        word_set.insert(s);
    }

    map<string, int> red_count;
    cin >> m;
    rep(0, m) {
        cin >> t;
        red_count[t]++;
        word_set.insert(t);
    }

    int max_x = 0;
    for (string s : word_set) {
        max_x = max(max_x, blue_count[s] - red_count[s]);
    }

    cout << max_x << endl;
}

int main() {
    solve();

    return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3

import sys


def generate_buidlings(building, floor, room):
    empty_buildings = {
            key: [[0 for col in range(room)] for row in range(floor)]
            for key in range(1, building+1)
    }
    return empty_buildings


def occupy_buildings(empty_buildings):
    occupied_buildings = generate_buidlings(4, 3, 10)
    n = int(sys.stdin.readline())

    for i in range(n):
        lst = [int(num) for num in sys.stdin.readline().split()]
        occupied_buildings[lst[0]][lst[1]-1][lst[2]-1] += lst[3]

    return occupied_buildings


def print_residents():
    separator = '####################'
    occupied_buildings = occupy_buildings(generate_buidlings(4, 3, 10))

    for idx, (key, value) in enumerate(occupied_buildings.items()):
        for floor in value:
            print(' %s %s %s %s %s %s %s %s %s %s' % tuple(floor))
        if idx < 3:
            print(separator)


def main():
    print_residents()


if __name__ == '__main__':
    main()

Measured memory_bytes: 7788
INF = 10 ** 20
$k = gets.to_i
$rounds = gets.split.map(&:to_i)

def rest_children(n)
  $rounds.each do |round|
    n -= n % round
  end
  n
end

from = (1..INF).bsearch { |i| rest_children(i) >= 2 }
to = (1..INF).bsearch { |i| rest_children(i) >= 3 }

if rest_children(from) == 2
  puts "#{from} #{to - 1}"
else
  puts -1
end


Measured memory_bytes: 13084
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <queue>
#define ll long long
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second
#define mp make_pair
#define forn(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
    string t,s;
    cin>>s>>t;
    t+=s;
    cout<<t<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

constexpr ll max(ll a,ll b){
if(a>=b)return a;
if(a<b)return b;
}

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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
  ll ans=9999999999999;
  ll A,B,C,X,Y;

  cin>>A>>B>>C>>X>>Y;


  FOR(i,0,1000000){
    ll tmp=999999999999;
//cout<<i<<" "<<ans<<endl;
    tmp=i*C;

    tmp=tmp+max((X-i/2),0)*A;

    tmp=tmp+max((Y-i/2),0)*B;
//cout<<i<<" "<<ans<<endl;
    ans=min(ans,tmp);
  }


cout<<ans<<endl;
return 0;

}
 


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

using namespace std;

using ll = long long;

int main(){
    ll n, ans = 0, pos, ans1 = 0, pos1; cin >> n;
    ll arr[100001] = {0}, arr1[100001] = {0};
    for(ll i = 0; i < n; ++i){
        ll tmp; cin >> tmp;
        if(i % 2 == 0){
            arr[tmp]++;
            if(arr[tmp] > ans)ans = arr[tmp], pos = tmp;
        }else{
            arr1[tmp]++;
            if(arr1[tmp] > ans1)ans1 = arr1[tmp], pos1 = tmp;
        }
    }
    sort(arr, arr + 100001, greater<ll>());
    sort(arr1, arr1 + 100001, greater<ll>());
    if(pos1 == pos){
        cout << min(n / 2 - arr[0] + n / 2 - arr1[1], n / 2 - arr1[0] + n / 2 - arr[1]);
    }else{
        cout << n / 2 - arr[0] + n / 2 - arr1[0];
    }
    return 0;
}


Measured memory_bytes: 1792
import sys


def main():
    A,B=input().split()
    A=int(A)
    B=int(B.replace(".",""))
    m=str(A*B)

    if len(m)<=2:
        print("0")
    else:
        res=int(m[:len(m)-2])
        print(res)

if __name__ == "__main__":
    main()

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

#define ff first
#define ss second
#define mp make_pair

using namespace std;

typedef long long ll;

const int MOD = 1e9+7;
char mat[1005][1005];
int dp[1005][1005];
bool mark[1005][1005];

int f(int i, int j) {
	if(i + j == 0) return 1;
	if(mark[i][j]) return dp[i][j];
	mark[i][j] = true;
	int ret = 0;
	if(i-1 >= 0 and mat[i-1][j] != '#')
		ret = f(i-1, j);
	if(j-1 >= 0 and mat[i][j-1] != '#')
		ret += f(i, j-1);

	if(ret >= MOD) ret -= MOD;
	return dp[i][j] = ret;
}

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

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

	printf("%d\n", f(n-1,m-1));

    return 0;
}

Measured memory_bytes: 6272
#include<cstdio>
#include<vector>
#include<algorithm> // sort
#include<functional> // pair


using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vll=vector<ll>;
using vvll=vector<vll>;
using pii=pair<int,int>;
using vpii=vector<pii>;


int main(void)
{
	int n, m;

	while(scanf("%d%d", &n, &m)==2)
	{
		vpii ab(m);

		for(int i=0;i<m;i++)
		{
			scanf("%d%d", &ab[i].first, &ab[i].second);
		}

		sort(ab.begin(), ab.end());
		int mark=0;
		int ans=1;
		for(int i=1;i<m;i++)
		{
			if(ab[mark].second>ab[i].second)
			{
				mark=i;
			}
			if(ab[i].first>=ab[mark].second)
			{
				ans++;
				mark=i;
			}
		}
		printf("%d\n", ans);
	}

	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cctype>
#define int long long
using namespace std;
int read()
{
    int X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}
char a[1000],b[1000],c[1000];
signed main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>a>>b>>c;
	cout<<a[0]<<b[0]<<c[0];
    return 0;
}



Measured memory_bytes: 256
# https://atcoder.jp/contests/abc142/tasks/abc142_c
n = int(input())
a = list(map(int, input().split()))
#### TLE ####
# ans = [str(a.index(i + 1) + 1) for i in range(n)]
# print(" ".join(ans))

b = [" "] * n
for i in range(n):
    b[a[i]-1] = str(i+1)

print(" ".join(b))


Measured memory_bytes: 14972
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
typedef pair<int, int> P;
typedef pair<P, int>PP;
const long long inf = 1ll << 61;
int N;
int hantei(int k) {
	int res = N;
	while (res%k == 0)res /= k;
	return res%k == 1 ? 1 : 0;
}

signed main() {
	cin >> N;
	int n = N - 1;
	vector<int>y;
	for (int i = 1; i*i <= n; i++) {
		if (n%i == 0) {
			if(i!=1)y.push_back(i);
			if (i*i != n)y.push_back(n / i);
		}
	}
	for (int i = 1; i*i <= N; i++) {
		if (N%i == 0) {
			if (i != 1)y.push_back(i);
			if (i*i != N)y.push_back(N / i);
		}
	}
	sort(y.begin(), y.end());
	y.erase(unique(y.begin(), y.end()), y.end());
	int cnt = 0;
	for (int e : y) {
		cnt += hantei(e);
	}
	cout << cnt << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int N, K;
    cin >> N >> K;
    if ((N - 1) % (K - 1))
    {
        cout << (N - 1) / (K - 1) + 1 << endl;
    }
    else
    {
        cout << (N - 1) / (K - 1) << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int n;

void solve(){
    int ans=(n%2)?(n+1)/2:n/2;
    printf("%d\n",ans);
}

int main()
{
    cin >> n;
    solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int a, b, c;
  cin >> a >> b >> c;

  int ans = min(c, b / a);
  cout << ans << endl;
}


Measured memory_bytes: 3496
#include <iostream>
#include <map>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int ret = 0;
  map<int,int> m;
  for (int i=1; i<=N; i++) {
    int l = i % 10;
    if (l == 0) continue;
    int r = i;
    while (r >= 10) {
      r /= 10;
    }
    m[r*10 + l]++;
  }
  for (auto& it : m) {
    int a = (it.first / 10) + (it.first % 10) * 10;
    if (m.find(a) == m.end()) continue;
    int n = it.second * m[a];
    //cout << it.first << ' ' << n << endl;
    ret += n;
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	char d[4] = {0};
	rep (i, 4) cin >> d[i];

	bool res = false;
	bool curr = true;

	rep (i, 3) curr &= (d[i] == d[(i+1)%4]); // (d[0] == d[1] && d[1] == d[2] && d[2] == d[3]);
	res |= curr;

	curr = true;
	rep (i, 2) curr &= (d[i] == d[(i+1)%4]); // (d[0] == d[1] && d[1] == d[2]);
	res |= curr;

	curr = true;
	rep (i, 2) curr &= (d[i+1] == d[i+2]); // (d[1] == d[2] && d[2] == d[3]);	
	res |= curr;

	cout << (res ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

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

	vector<ll> a;
	for (int i = 0; i < n; i++){
		ll tmp;
		cin >> tmp;
		a.push_back(tmp);
	}

	sort(a.begin(), a.end());
	ll sum = 0;
	for(ll i: a)
		sum += i;

	cout << a[0] << " " << a[n - 1] << " " << sum << endl;

	return 0;
}




Measured memory_bytes: 3280
public class Main
{
    public static void main(String... args)
    {
        for (int left = 1; left <= 9; left++) {
            for (int right = 1; right <= 9; right++) {
                System.out.println(String.format("%dx%d=%d", left, right, left * right));
            }
        }
    }
}

Measured memory_bytes: 17028
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("atcoder-problems/agc024_a.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  ll a, b ,c , k;
  cin >> a >> b >> c >> k;

  ll ans = 0;
  if (k % 2 != 0) {
    ans = b - a;
  } else {
    ans = a - b;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
// eddy1021
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
#define mod9 1000000009LL
#define mod7 1000000007LL
#define INF  1023456789LL
#define INF16 10000000000000000LL
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else 
#define debug(...)
#endif
inline LL getint(){
  LL _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline LL add( LL _x , LL _y , LL _mod = mod7 ){
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline LL sub( LL _x , LL _y , LL _mod = mod7 ){
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline LL mul( LL _x , LL _y , LL _mod = mod7 ){
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
LL mypow( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 1LL;
  LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = mul( _ret , _a , _mod );
  return _ret;
}
LL mymul( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 0LL;
  LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = add( _ret , _a , _mod );
  return _ret;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
void sleep( double sec = 1021 ){
  clock_t s = clock();
  while( clock() - s < CLOCKS_PER_SEC * sec );
}
#define Bye exit(0)
int __ = 1 , _cs;
/*********default*********/
#define N 1021
void build(){

}
LL n , a[ N ];
LL dp[ N ] , bk[ N ] , bst , bl , br , tk;
void init(){
  n = getint();
  for( LL i = 1 ; i <= n ; i ++ )
    a[ i ] = getint();
  bst = a[ 1 ];
  bl = br = 1;
  for( LL i = 1 ; i <= n ; i ++ ){
    dp[ i ] = a[ i ];
    bk[ i ] = 0;
    for( LL j = 1 ; j < i ; j ++ ){
      if( i % 2 != j % 2 ) continue;
      LL tdp = dp[ j ] + a[ i ];
      if( tdp > dp[ i ] ){
        dp[ i ] = tdp;
        bk[ i ] = j;
      }
    }
    if( dp[ i ] > bst ){
      bst = dp[ i ];
      tk = 0;
      br = i;
      LL now = i;
      while( now ){
        bl = now;
        tk ++;
        now = bk[ now ];
      }
    }
  }
}
vector<int> op;
void go( int nl , int nr ){
  if( nl == nr ) return;
  int dlt = (nr - bk[ nr ] - 1) / 2;
  while( dlt -- )
    op.push_back( bk[ nr ] - nl + 3 );
  go( nl , bk[ nr ] );
}
void solve(){
  printf( "%lld\n" , bst );
  for( LL i = n ; i > br ; i -- )
    op.push_back( i );
  for( LL i = 1 ; i < bl ; i ++ )
    op.push_back( 1 );
  go( bl , br );
  while( -- tk )
    op.push_back( 2 );
  printf( "%d\n" , (int)op.size() );
  for( int x : op )
    printf( "%d\n" , x );
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


Measured memory_bytes: 256
N, M = map(int, input().split())
l = [[] for _ in range(N)]
for i in range(M):
    p, s = input().split()
    l[int(p) - 1].append(s)

correct = 0
penalty = 0
for ll in l:
    if 'AC' not in ll:
        continue

    correct += 1
    penalty += ll.index('AC')

print(correct, penalty)

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

using namespace std;

int main() {
    int N;
    int result = 0;
    
    cin >> N;
    
    vector<int> h(N);

    int tmp = 0;
    int i = 0;
    while(cin >> tmp) {
        h[i] = tmp;
        i ++;
        if(i >= N) {
            break;
        }
    }

    result += h[0];

    for(int i = 1; i < h.size(); i++) {
        tmp = h[i] - h[i-1];

        if(tmp > 0) {
            result += tmp;
        } 

    }

    cout << result << endl;


}

Measured memory_bytes: 256
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define vi vector<ll>
#define pii pair<ll,ll>
#define bc __builtin_popcountll
#define vvi vector<vi> 
#define vpii vector<pair<ll,ll>>
#define mll unordered_map<ll,ll>
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define fo(i,a,b) for(i=a;i<=b;i++)
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define fb1(i,n) for(ll i=n;i>0;i--)
#define endd cout<<'\n';
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define all(x) x.begin(), x.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
//*X.find_by_order()-->returns an iterator to the k-th largest element (counting from zero)
//X.order_of_key()-->the number of items in a set that are strictly smaller than our item.
struct cmp
{
	bool operator() (ll a,ll b){
		return (a>b);
	}
};
ll mod=1000000007;
const ll N=100005;
int main()
{
fast;
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max(a*c,max(a*d,max(b*c,b*d)));
    return 0;
}

Measured memory_bytes: 3664
a, b, c = map(int,input().split())
top = max(a,b,c)

time = (top - a)//2 + (top - b)//2 + (top - c)//2
rest = (top - a)%2 + (top - b)%2 + (top - c)%2

if rest == 1:
    time += 2
elif rest == 2:
    time += 1

print(time)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            int a = int.Parse(line[0]);
            int b = int.Parse(line[1]);
            int c = int.Parse(line[2]);

            if (c == b + a || b == a + c || a == b + c)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

        }
    }
}


Measured memory_bytes: 2648
using System;

namespace sample1
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			for (int i = 1; i <= 9; i++)
			{
				for (int k = 1; k <= 9; k++)
				{
					Console.WriteLine(i + "x" + k + "=" + i * k);
				}
			}
		}
	}
}


Measured memory_bytes: 15804
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define test ll t; cin>>t; while(t--)
typedef long long int ll;
void add_self(ll &x,ll y){
    x+=y;
    if(x>=mod){
        x%=mod;
    }
}
int main() {
    FIO;
    //test
    {
        ll n,k,x;
        cin>>n>>k;
        vector<ll>prefix(k+1),dp(k+1,0);
        dp[0]=1;
        for(int i=0;i<n;i++){
            cin>>x;
            for(int j=0;j<=k;j++){
                prefix[j]=0;
            }
            // We will be dealing with states
            for(int j=0;j<k;j++){
                prefix[j+1]+=dp[j];
                if(j+x+1<=k){
                    prefix[j+x+1]-=dp[j];
                }
            }
            for(int j=1;j<=k;j++){
                prefix[j]+=prefix[j-1];
            }
            for(int j=0;j<=k;j++){
                add_self(dp[j],prefix[j]);
            }
        }
        cout<<dp[k]<<endl;
    }
	return 0;
}


Measured memory_bytes: 4776
# coding: utf-8

N = int(input())
guidebook = dict()

for i in range(N):
    d = input().split()
    ci = d[0]
    pi = int(d[1])
    restaurants = guidebook.get(ci, dict())
    restaurants[pi] = i+1
    guidebook[ci] = restaurants

# print(guidebook)
city_names = sorted(guidebook.keys())
for cn in city_names:
    restaturants = guidebook[cn]
    # print(restaturants.keys())
    r_keys = list(restaturants.keys())
    r_keys.sort(reverse=True)
    for r_key in r_keys:
        print(restaturants[r_key])
    

Measured memory_bytes: 3064
using System;
using System.Linq;

namespace ABC139C
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = CIN.Long();
            long[] H = CIN.LongArray();

            int ans = 0;
            int cur = 0;

            for (int i = 1; i < N; i++)
            {
                if (H[i] <= H[i - 1])
                {
                    cur++;
                    ans = Math.Max(cur, ans);
                }
                else
                {
                    cur = 0;
                }
            }
            Console.WriteLine(ans);
        }
    }

    internal static class CIN
    {
        public static string String()
        {
            return Console.ReadLine();
        }

        public static int Int()
        {
            return int.Parse(Console.ReadLine());
        }

        public static int[] IntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        public static long Long()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] LongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] DoubleArray()
        {
            return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
        }
    }
}

Measured memory_bytes: 27356
program main
  implicit none

  integer(16) :: n, i
  integer(16), allocatable :: a(:,:), dp(:,:)

  read(*,*) n
  allocate(a(3,n))
  allocate(dp(3,n))
  read(*,*) a

  do i = 1, n
     dp(1,i) = 0
     dp(2,i) = 0
     dp(3,i) = 0
  end do

  dp(1,1) = a(1,1)
  dp(2,1) = a(2,1)
  dp(3,1) = a(3,1)

  do i = 2, n
     dp(1,i) = max(dp(1,i), dp(2,i-1) + a(1,i))
     dp(1,i) = max(dp(1,i), dp(3,i-1) + a(1,i))
     dp(2,i) = max(dp(2,i), dp(1,i-1) + a(2,i))
     dp(2,i) = max(dp(2,i), dp(3,i-1) + a(2,i))
     dp(3,i) = max(dp(3,i), dp(1,i-1) + a(3,i))
     dp(3,i) = max(dp(3,i), dp(2,i-1) + a(3,i))
  end do

  write(*,*) max(dp(1,n), dp(2,n), dp(3,n))

end program main


Measured memory_bytes: 10112
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void solve()
{
    int64_t N;
	std::cin >> N;
	std::vector<int64_t> A(N + 1), B(N);

	for (int64_t i = 0; i < N + 1; i++)
	{
		std::cin >> A[i];
	}
	for (int64_t i = 0; i < N; i++)
	{
		std::cin >> B[i];
	}

	int64_t ans = 0;
	for (int64_t i = 0; i < N; i++)
	{
		int64_t beat = std::min(A[i], B[i]);
		ans += beat;
		A[i] -= beat;
		B[i] -= beat;

		int64_t beat_next = std::min(A[i + 1], B[i]);
		ans += beat_next;
		A[i + 1] -= beat_next;
		B[i] -= beat_next;
	}

	std::cout << ans << std::endl;

}

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


Measured memory_bytes: 4712
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define mod 1000000007
#define endl '\n'
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

ll x[10],y[10];
double dist(ll i, ll j)
{
    double dx = x[i]-x[j];
    double dy = y[i]-y[j];

    return pow(dx*dx + dy*dy, 0.5);
}


int main()
{

     ll n,i,j;
     cin>>n;
     for(i=1;i<=n;i++)
     {
         cin>>x[i]>>y[i];
     }
     double sum=0.0;
     vector<ll>v(n);
     for(i=0;i<n;i++)
     {
         v[i]=i+1;
     }
     do{
        for(i=0;i<n-1;i++)
        {
            sum+=dist(v[i],v[i+1]);
        }
     }
     while(next_permutation(v.begin(),v.end()));
     ll fact=1;
     for(i=2;i<=n;i++)
     {
         fact*=i;
     }
     cout << fixed << setprecision(10) << sum / fact << endl;
}


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

int main() {
  int N;
  cin >>N;
  if(N%1110<10)
    cout <<"Yes"<<endl;
  else if(N%1000%111==0)
    cout <<"Yes"<<endl;
  else
    cout <<"No"<<endl;
  
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<algorithm>
#include<vector>
#include<queue>
#define ll long long
ll read()
{
	ll tmp=0;char c=getchar(),f=1;
	while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9'){tmp=tmp*10+c-48;c=getchar();}
	return tmp*f;
}
using namespace std;
int main()
{
	ll a=read(),b=read();
	if(a<b)printf("0\n");else printf("%lld\n",a-b);
	return 0;
}

Measured memory_bytes: 128
n,m=map(int,input().split())
h=list(map(int,input().split()))
good=[True]*n
for i in range(m):
    a,b=map(int,input().split())
    a-=1;b-=1
    if h[a]<h[b]:
        good[a]=False
    elif h[b]<h[a]:
        good[b]=False
    elif h[b]==h[a]:
        good[a]=False
        good[b]=False
print(good.count(True))

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

using namespace std;

typedef long long int64;

int main()
{
  int64 A, B, C, D, E, F, G;
  cin >> A >> B >> C >> D >> E >> F >> G;

  int64 z = 0;
  int64 ss = min({D, E, A});

  for(int i = 0; i <= ss; i++) {
    int64 a = A, b = B, c = C, d = D, e = E, f = F, g = G;
    int64 ret = 0;
    int64 get;
    get = i;
    d -= get;
    e -= get;
    a -= get;
    ret += get * 3;
    get = d >> 1;
    ret += get * 2;
    get = e >> 1;
    ret += get * 2;
    get = a >> 1;
    ret += get * 2;
    z = max(z, ret);
  }

  cout << z + B << endl;
}


Measured memory_bytes: 256
import kotlin.math.min

fun main() = Thread(null, ::abc174d, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()

@OptIn(ExperimentalStdlibApi::class)
fun abc174d() {
    val n = readLine()!!.toInt()
    val line = readLine()!!

    val firstR = line.indexOf("R")
    val lastW = line.indexOf("W")

    val wCount = line.count { it == 'W' }
    val rCount = line.count { it == 'R' }
    val answer = if (wCount == 0 || rCount == 0) 0 else {
        minOf(wCount, rCount, min(
            line.slice(0 until rCount).count { it == 'W' },
            line.slice((line.lastIndex - wCount + 1)..line.lastIndex).count { it == 'R' }
        ))
    }

    println(answer)
}


Measured memory_bytes: 41816
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
 
int minCost(int h[],int k,int n)
{
    int arr[n],j;
    arr[n-1]=0;
    for(int i=n-2;i>=0;i--)
    {
        int ans=INT_MAX;
        for(j=1;j<=k;j++)
        {
            if (j+i<n)
                ans=min(ans,abs(h[i]-h[i+j])+arr[i+j]);
        }
        arr[i]=ans;
    }
    return arr[0];
}
 
 
void solve()
{
    int n,k;
	cin>>n>>k;
	int h[n];
	for(int i=0;i<n;i++)
	    cin>>h[i];
    cout<<minCost(h,k,n)<<"\n";
}
 
int main()
{
	solve();
	return 0;
}

Measured memory_bytes: 1024
fun main(args: Array<String>) {
    val (w, a, b) = readInputLine().split(" ").map { it.toInt() }
    
    if (a + w < b) {
        println(b - a - w)
    } else if (b + w < a) {
        println(a - b - w)
    } else {
        println(0)
    }
}
 
fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 36012
///...................SUBHASHIS MOLLICK...................///
///.....DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING....///
///.............ISLAMIC UNIVERSITY,BANGLADESH.............///
///....................SESSION-(14-15)....................///
#include<bits/stdc++.h>
using namespace std;
#define sf(a) scanf("%d",&a)
#define sf2(a,b) scanf("%d %d",&a,&b)
#define sf3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pf(a) printf("%d",a)
#define pf2(a,b) printf("%d %d",a,b)
#define pf3(a,b,c) printf("%d %d %d",a,b,c)
#define sfl(a) scanf("%lld",&a)
#define sfl2(a,b) scanf("%lld %lld",&a,&b)
#define sfl3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pfl(a) printf("%lld",a)
#define pfl2(a,b) printf("%lld %lld",a,b)
#define pfl3(a,b,c) printf("%lld %lld %lld",a,b,c)
#define nl printf("\n")
#define   timesave              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define MPI map<int,int>mp;
#define fr(i,n) for(i=0;i<n;i++)
#define fr1(i,n) for(i=1;i<=n;i++)
#define frl(i,a,b) for(i=a;i<=b;i++)
#define tz 100000
#define clr0(a) memset(a,0,sizeof(a))
#define clr1(a) memset(a,-1,sizeof(a))
/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697
*/
//freopen("Input.txt","r",stdin);
//freopen("Output.txt","w",stdout);
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
const int INF = 1001001001;
int ar[200005],ans[200005];
vector<int>val(220000,INF);
vector<int>vec[200005];
stack<pair<int,int> > st;
void dfs(int u,int par)
{
    for(int ii=0;ii<vec[u].size();ii++)
    {
        int v=vec[u][ii];
        if(v!=par)
        {
            int ind = lower_bound(val.begin(), val.end(), ar[v]) - val.begin();
            st.push({ind, val[ind]});
            val[ind] = ar[v];
            ans[v] =lower_bound(val.begin(), val.end(), INF) - val.begin();
            dfs(v,u);
            val[st.top().first] = st.top().second;
            st.pop();
        }
    }
}
main()
{
    timesave;
    int n,u,v,i;
    cin>>n;
    for(i=0; i<n; i++)
    {
        cin>>ar[i];
    }
    for(i=1; i<n; i++)
    {
        cin>>u>>v;
        u--,v--;
        vec[u].push_back(v);
        vec[v].push_back(u);
    }
    val[0]=ar[0];
    ans[0]=1;
    dfs(0,-1);
    for(i=0; i<n; i++)
        cout<<ans[i]<<endl;
}





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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int r;
    cin >> r;
    if (r < 1200) cout << "ABC" << endl;
    else if (r < 2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;
    return 0;
}


Measured memory_bytes: 3612
var
        i,n,s,max,min:longint;
        x:array [0..1000] of char;
begin
readln(n);
for i:=1 to n do
        begin
        read(x[i]);
        if x[i]='(' then inc(s)
        else dec(s);
        if s<min then min:=s;
        end;
s:=0;
for i:=n downto 1 do
        begin
        if x[i]='(' then inc(s)
        else dec(s);
        if s>max then max:=s;
        end;
for i:=1 to abs(min) do write('(');
for i:=1 to n do write(x[i]);
for i:=1 to max do write(')');
end.

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // System.out.println("input a number: ");
        int d = sc.nextInt();

        String result = "Christmas";
        for (int i = 24; i >= d && i>=22; i--) {
            result += " Eve";
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int

using namespace std;

int main()
{
  int n, m;
  cin >> n >> m;
  priority_queue<ll, vector<ll>, greater<ll>> q;

  REP(i, n)
  {
    ll a;
    cin >> a;
    q.push(a);
  }

  pair<ll, int> cb[100000];
  REP(i, m)
  {
    int b;
    ll c;
    cin >> b >> c;
    cb[i] = make_pair(c, b);
  }

  sort(cb, cb + m, greater<pair<ll, int>>());

  REP(i, m)
  {
    while (cb[i].second > 0)
    {
      ll a = q.top();
      if (cb[i].first > a)
      {
        a = cb[i].first;
        cb[i].second--;
        q.pop();
        q.push(a);
      }
      else
      {
        break;
      }
    }
  }

  ll result = 0;
  while (!q.empty())
  {
    result += q.top();
    q.pop();
  }
  cout << result << endl;
}


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

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define rer(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int inf = 1000000000;
const int mod = 1000000007;
const double eps = 1e-9;
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1};

int main() {
	// cin.tie(0); // tie
	// ios::sync_with_stdio(false); // sync
	int n;
	while (cin >> n, n) {
		int ans = 0;
		for (int i = 1; i < n; ++i) {
			int sum = 0;
			for (int j = i; sum < n; ++j) sum += j;
			if (sum == n) ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            new Main().solve(sc);
        }
    }

    void solve(Scanner sc) {
        int n =sc.nextInt();
        long all = 0;
        int[] as = new int[n + 2];
        as[0] = as[n + 1] = 0;
        for (int i = 1; i <= n; i++) {
            as[i] = sc.nextInt();
            all += Math.abs(as[i] - as[i - 1]);
        }
        all += Math.abs(as[n + 1] - as[n]);

        for (int i = 1; i <= n; i++) {
            int d = Math.abs(as[i] - as[i - 1]) + Math.abs(as[i + 1] - as[i]);
            int a = Math.abs(as[i + 1] -  as[i - 1]);
            System.out.println(all - d + a);
        }
    }
}


Measured memory_bytes: 66064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>
#include <cstdio>

int main() {
	long long n, k;

	std::cin >> n >> k;

	std::vector<bool> v(n, false);

	for (long long i = 0; i < k; i++)
	{
		long long d;
		std::cin >> d;

		for (long long j = 0; j < d; j++)
		{
			long long a;
			std::cin >> a;
			v[a - 1] = true;
		}
	}

	long long ans = 0;
	for (long long i = 0; i < n; i++)
	{
		if (v[i] == false) {
			ans++;
		}
	}

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 3624
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        long k = scanner.nextLong();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = scanner.nextInt()-1;
        }
        List<Integer> list = new ArrayList<>();
        HashSet<Integer> set = new HashSet<>();
        list.add(0);
        set.add(0);
        int cur = 0;
        int loopheadindex = 0;
        for(int i = 1; i < n+1; i++){
            cur = a[cur];
            if(set.contains(cur)){
                loopheadindex = list.indexOf(cur);
                break;
            }
            list.add(cur);
            set.add(cur);
        }
        if(k < loopheadindex){System.out.println(list.get((int)k)+1);}
        else{
            int looplength = list.size()-loopheadindex;
            int ansindex = (int)((k - loopheadindex)%looplength);
            System.out.println(list.get(ansindex + loopheadindex) + 1);
        }
    }
}



Measured memory_bytes: 67228
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define REPA(x, v) for(auto&& x:v)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(v.rbegin(),v.rend())
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    ll D,T,S;
    cin >> D >> T >> S;
    Yes(D<=(T*S));
}

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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<std::vector<char> > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<std::vector<double> > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

bool solve(int n, v_bool &v)
{
    while(n) {
        if(v[n%10]) {  
            return false;
        }
        n /= 10;
    }

    return true;
}

int main(void)
{
    int n, k; 
    cin >> n >> k;
    
    v_bool v(10, false);
    irep(i, k) {
        int d;
        cin >> d;
        v[d] = true;
    }

    while(1) {
        if(solve(n, v)) {
            cout << n << endl;
            return 0;
        } else {
            n++;
        }
    }

    return 0;
}
/** atcoder **/


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>
#include<numeric>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define SUM(a) accumulate(all(a),0LL)
#define pb push_back
#define endl '\n'
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, cnt = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok = true, flag = false;
ll dx[5] = { 1,-1,0,0,0 }, dy[5] = { 0,0,1,-1,0 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 222222


ll x[1111], y[1111];

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

  
  cin >> n;
  rep(i, n) cin >> x[i] >> y[i];
  tmp = abs(x[0] + y[0]) % 2;
  rep(i, n) if (abs(x[i] + y[i]) % 2 != tmp) ok = false;
  if (!ok) {
	cout << "-1" << endl;
	return 0;
  }
  if (tmp == 0) {
	cout << "32" << endl;
	rrep(i, 31) cout << (1 << i) << " ";
	cout << "1 " << endl;
  }
  else {
	cout << "31" << endl;
	rrep(i, 31) cout << (1 << i) << " ";
	cout << endl;
  }

  rep(i, n) {
	ll a = x[i] + y[i], b = x[i] - y[i];
	rrep(j, 31) {
	  if (a >= 0 && b >= 0) {
		cout << "R"; a -= (1 << j); b -= (1 << j);
	  }
	  else if (a >= 0 && b < 0) {
		cout << "U"; a -= (1 << j); b += (1 << j);
	  }
	  else if (a < 0 && b >= 0) {
		cout << "D"; a += (1 << j); b -= (1 << j);
	  }
	  else {
		cout << "L"; a += (1 << j); b += (1 << j);
	  }
	}
	if (tmp == 0) {
	  if (a >= 0 && b >= 0) cout << "R";
	  else if (a >= 0 && b < 0) cout << "U";
	  else if (a < 0 && b >= 0) cout << "D";
	  else cout << "L";
	}
	cout << endl;
  }



  return 0;
}

Measured memory_bytes: 256
//q5.cpp

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 1010

int m[SIZE][SIZE];
int dp[SIZE][SIZE];
vector<pair<int,pair<int,int> > > vec;

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

int main(){
  int h,w;

  scanf("%d%d",&h,&w);

  for(int i=0;i<=h+1;i++){
    for(int j=0;j<=w+1;j++){
      m[i][j] = INF;
    }
  }
  
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      scanf("%d",&m[i][j]);
      vec.push_back({m[i][j],{i,j}});
    }
  }

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

  for(int i=0;i<h*w;i++){
    int y = vec[i].second.first;
    int x = vec[i].second.second;

    if(dp[y][x] == 0){
      dp[y][x] = m[y][x];
      
      for(int j=0;j<4;j++){
        if(m[y][x] > m[y+dy[j]][x+dx[j]]) dp[y][x] = 0;
      }
    }

    if(dp[y][x] == -1){
      for(int j=0;j<4;j++){
        if(m[y][x] < m[y+dy[j]][x+dx[j]]) dp[y+dy[j]][x+dx[j]] = -1;
      }
    }

    if(dp[y][x] > 0){
      for(int j=0;j<4;j++){
        if(m[y][x] < m[y+dy[j]][x+dx[j]]){
          if(dp[y+dy[j]][x+dx[j]] == 0) 
            dp[y+dy[j]][x+dx[j]] = dp[y][x];
          else if(dp[y+dy[j]][x+dx[j]] > 0 && dp[y+dy[j]][x+dx[j]] != dp[y][x]) 
            dp[y+dy[j]][x+dx[j]] = -1;
        }
      } 
    }
  }

  int ans = 0;
  
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      if(dp[i][j] == -1) ans++;
    }
  }
  
  printf("%d\n",ans);
  
  return 0;
}

Measured memory_bytes: 22640