akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

int main()
{
    std::size_t N;
    std::cin >> N;
    std::vector<std::string> S(N);
    for(auto& s : S)
    {
        std::cin >> s;
    }
    std::sort(S.begin(), S.end());
    S.erase(std::unique(S.begin(), S.end()), S.end());
    std::cout << S.size() << std::endl;

    return 0;
}


Measured memory_bytes: 9524
#include <cstdio>

int A, B, C;
int cnt[11];

int main()
{
  scanf( "%d%d%d", &A, &B, &C );
  ++cnt[A], ++cnt[B], ++cnt[C];

  if( cnt[5] == 2 && cnt[7] == 1 )
    puts("YES");
  else
    puts("NO");

  return 0;
}

Measured memory_bytes: 128
import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long N, long Q, string S, long[] l, long[] r) {
    auto acc = new long[](N);
    auto s = S.array;
    foreach (i; 0 .. N - 1) {
        acc[i + 1] = acc[i];
        if (s.startsWith("AC"))
            acc[i + 1]++;
        s.popFront;
    }

    foreach (li, ri; zip(l, r)) {
        writeln(acc[ri - 1] - acc[li - 1]);
    }
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    long Q;
    Q = input.front.to!long;
    input.popFront;

    string S;
    S = input.front.to!string;
    input.popFront;

    long[] l = new long[](cast(size_t) (Q));
    long[] r = new long[](cast(size_t) (Q));
    foreach (i; 0 .. cast(size_t) (Q)) {
        l[i] = input.front.to!long;
        input.popFront;
        r[i] = input.front.to!long;
        input.popFront;
    }

    static if (is(ReturnType!solve == void))
        solve(N, Q, S, l, r);
    else
        solve(N, Q, S, l, r).writeln;
}


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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  for (int i=0; i<N; i++) cin >> h[i];
  sort(h.begin(), h.end());
  int ans = 1e9;
  for (int i=0; i<N-K+1; i++){
    ans = min(ans, h[i+K-1]-h[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10 ** 7)

h, w = map(int, input().split())
maze = [[-1 for i in range(w)] for j in range(h)]
used = [[-1 for i in range(w)] for j in range(h)]


ans = 0
for i in range(h):
    maze[i] = list(map(int, input().split()))

ans = []

for y in range(h):
    if y%2==0:
        for x in range(w):
            if maze[y][x]%2==0:
                continue
            else:
                if x<w-1:
                    ans.append([y+1,x+1,y+1,x+1+1])
                    maze[y][x+1]+=1
                elif y<h-1:
                    ans.append([y+1,x+1,y+1+1,x+1])
                    maze[y+1][x]+=1

    else:
        for x in reversed(range(w)):
            if maze[y][x]%2==0:
                continue
            else:
                if x>0:
                    ans.append([y+1,x+1,y+1,x+1-1])
                    maze[y][x-1]+=1
                elif y<h-1:
                    ans.append([y+1,x+1,y+1+1,x+1])
                    maze[y+1][x]+=1

print(len(ans))

for i in range(len(ans)):
    print(*ans[i], sep=' ')


Measured memory_bytes: 95012
#include <iostream>
#include <string>
#include <vector>
#include <sstream>

using namespace std;

void heisei() {
	cout << "Heisei" << endl;
}

void TBD() {
	cout << "TBD" << endl;
}

int main() {
	string t, s;
	cin >> t;
	stringstream ss;
	ss << t;
	int y, m, d;
	getline(ss,s,'/');
	y = stoi(s);
	getline(ss,s,'/');
	m = stoi(s);
	getline(ss,s,'/');
	d = stoi(s);

	if(y < 2019) {
		heisei();
	} else if(y == 2019) {
		if(m < 4) {
			heisei();
		} else if(m == 4) {
			if(d <= 30) {
				heisei();
			} else {
				TBD();
			}
		} else {
			TBD();
		}
	} else {
		TBD();
	}
}


Measured memory_bytes: 888
import java.util.*;

public class Main{
  
  public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int A = Integer.parseInt(sc.next());
    int B = Integer.parseInt(sc.next());
   
    if(A <= 8 && B <= 8){
      System.out.println("Yay!");
    }else{
      System.out.println(":(");
    }    
  }  
}

Measured memory_bytes: 35736
S = input()[::-1]
l = ["dream", "dreamer", "erase", "eraser"]
for i in range(len(l)):
    l[i] = l[i][::-1]

cut = 0
for n in range(len(S)):
    if cut == len(S):
        break

    for m in range(len(l)):
        if S[cut:cut + len(l[m])] == l[m]:
            cut += len(l[m])
            break

print("YES" if cut == len(S) else "NO")

Measured memory_bytes: 3188
s = gets.chomp.split("")
ans = []
("a".."z").each do |alphabet|
  max = 0
  current = 0
  s.each do |c|
    if c == alphabet
      max = current if max < current
      current = 0
    else
      current += 1
    end
  end
  max = current if max < current
  ans << max
end
puts ans.min


Measured memory_bytes: 1788
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int INF=1e9;
const double eps=1e-9;
const int maxn=1e5+10;
char str[maxn];
inline int read(){
	int x=0,flag=1;
	char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')flag=-1,ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return x*flag;
}
int main(){
	int i,j,k,m,n;
	scanf("%s",str+1);
	int len=strlen(str+1);
	int ans1,ans2;
	ans1=len,ans2=len;
	for(i=1;i<=len;i++){
		if(str[i]=='1')ans1=min(ans1,max(len-i,i-1));
		else ans2=min(ans2,max(len-i,i-1));
	}
	printf("%d\n",max(ans1,ans2));
	return 0;
}


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

#define inRange(x,a,b) a <= x && x < b

int h, w;
char mat[50][50];
bool visit[50][50] = {};
int dx[4] = {-1,0,0,1};
int dy[4] = {0,1,-1,0};

int main(){
    cin >> h >> w;

    int white = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> mat[i][j];
            if(mat[i][j] == '.')    white++;
        }
    }
    
    int dist = -1;
    queue<pair<pair<int,int>,int>> q;

    if(mat[0][0] == '.')    q.push({{0,0}, 0});
    
    while(!q.empty()){
        pair<pair<int,int>,int> x = q.front();    q.pop();
        if(x.first.first == h-1 && x.first.second == w-1){
            dist = x.second;
            break;
        }

        if(visit[x.first.first][x.first.second])    continue;

        visit[x.first.first][x.first.second] = true;

        for(int i = 0; i < 4; i++){
            int ni = x.first.first + dx[i];
            int nj = x.first.second + dy[i];
            if(inRange(ni, 0, h) && inRange(nj, 0, w) && !visit[ni][nj] && mat[ni][nj] == '.'){
                q.push({{ni,nj}, x.second+1});
            }
        }
    }

    cout << (dist == -1 ? -1 : white-dist-1) << endl;

    return 0;
}

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

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var s = Console.ReadLine();
            var t = Console.ReadLine();
            var count = s.Length < t.Length;
            if (!count)
            {
                Console.WriteLine("No");
            }
            var match = true;
            for (var i = 0; i < s.Length; i++)
            {
                match = s[i] == t[i];
                if (!match) break;
            }
            Console.WriteLine(match ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 25876
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)


int main() {
  ll K,X;

  cin>>K>>X;
  if(500*K>=X){
    cout<<"Yes"<<endl;
  }
  else{
  cout<<"No"<<endl;
  }
return 0;
  
  }


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


// 和
struct LazySegmentTree {
private:
    int n;
    vector<ll> node, lazy;
public:
    LazySegmentTree(vector<ll> v) {
        int sz = (int)v.size();
        n = 1;
        while (n < sz) n *= 2;

        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);

        for (int i=0; i<sz; ++i) node[i+n-1] = v[i];
        for (int i=n-2; i>=0; --i) node[i] = node[i*2+1] + node[i*2+2];
    }

    // ll get(int i) {
    //     return node[i + n - 1];
    // }

    void eval(int k, int l, int r) {
        if (lazy[k] != 0) {
            node[k] += lazy[k];

            if (r - l > 1) {
                lazy[2*k+1] += lazy[k] / 2;
                lazy[2*k+2] += lazy[k] / 2;
            }

            lazy[k] = 0;
        }
    }

    void add(int a, int b, ll x, int k=0, int l=0, int r=-1) {
        if (r < 0) r = n;

        eval(k, l, r);

        if (r <= a or b <= l) return;

        if (a <= l and r <= b) {
            lazy[k] += (r - l) * x;
            eval(k, l, r);
        }
        else {
            add(a, b, x, 2*k+1, l, (l+r)/2);
            add(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = node[2*k+1] + node[2*k+2];
        }
    }

    ll getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if (r < 0) r = n;
        if (r <= a or b <= l) return 0;

        eval(k, l, r);
        if (a <= l and r <= b) return node[k];
        ll vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }
};

int main() {
    ll N, D, A;
    cin >> N >> D >> A;
    vector<pair<ll, ll>> p(N);
    vector<ll> tmpp(N);
    rep(i, N) {
        cin >> p[i].first >> p[i].second;
        tmpp[i] = p[i].first;
    }
    sort(p.begin(), p.end());
    sort(tmpp.begin(), tmpp.end());
    vector<ll> tmptmp(N, 0);
    rep(i, N) {
        tmptmp[i] = p[i].second;
    }

    LazySegmentTree lst(tmptmp);

    ll ans = 0;
    rep(i, N) {
        ll tmp = lst.getsum(i, i+1);
        if (tmp <= 0) continue;

        // 何回攻撃するか
        tmp = (tmp / A) + bool(tmp % A);
        auto itr = upper_bound(tmpp.begin(), tmpp.end(), p[i].first + 2*D);
        if (itr == tmpp.end()) {
            // もうなかった場合
            ans += tmp;
            lst.add(i, N, -A*tmp);
        }
        else {
            itr--;

            int idx = itr - tmpp.begin();
            //cout << p[i].first << ", " << idx << ", " << -A*tmp << endl;
            lst.add(i, idx+1, -A * tmp);
            ans += tmp;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 16256
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N, D;
  cin >> N >> D;
  int a = 1;
  if (N > 0) {
    for (int i; i < N; i ++) {
    a = a * 100;
    }
  }
  if (D != 100) cout << a * D << endl;
  else cout << (D + 1) * a << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	int cur = 1;
	int ans = 0;
	while(cur<b)
	{
		ans++;
		cur = cur + a-1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 1000000007;

int main() {
	int N;
	cin >> N;
	if (N % 1000 == 0)cout << 0 << endl;
	else {
		cout << 1000 - N % 1000 << endl;
	}
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
using matrix = vector<vector<uint>>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

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

    int N, M = 0;
    cin >> N;
    vector<int> x(N);
    for (int i = 0; i < N; ++i)
        cin >> x[i];
    while (N >> M)
        M++;

    int L;
    cin >> L;

    vector<vector<ll>> nxt(M, vector<ll>(N, N - 1));
    for (int i = 0; i < N; ++i)
        nxt[0][i] = upper_bound(x.begin(), x.end(), x[i] + L) - x.begin() - 1;
    for (int i = 0; i + 1 < M; ++i)
        for (int j = 0; j < N; ++j)
            nxt[i + 1][j] = nxt[i][nxt[i][j]];

    int Q;
    cin >> Q;
    for (int i = 0; i < Q; ++i) {
        int a, b, res = 0;
        cin >> a >> b;
        a--, b--;
        if (a == b) {
            cout << res << '\n';
            continue;
        }

        if (a > b)
            swap(a, b);

        for (int j = M - 1; j >= 0; --j) {
            if (nxt[j][a] < b) {
                a = nxt[j][a];
                res += (1 << j);
            }
        }
        cout << res + 1 << '\n';
    }

    return 0;
}


Measured memory_bytes: 14720
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	s := nextStr()

	x := 0
	xmax := 0
	for i := 0; i < n; i++ {
		if s[i] == 'I' {
			x++
			xmax = max(xmax, x)
		} else {
			x--
		}
	}

	fmt.Println(xmax)

}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// ---- readfunc
func scanInit() {
	const cap = 64 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


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

typedef long long ll;
ll INF = 1000000000000000;
using Graph = vector<vector<pair<ll,ll>>>;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
vector.erase(vector.begin() + index);
}

int N,A[10];

ll dfs(int n,ll a,ll b){
  if(n == N){
    return a + b;
  }
  return dfs(n+1,a,b*10+A[n]) + dfs(n+1,a+b,A[n]);
}

int main(){
 string S;
 cin >> S;
 N = S.size();
 for(int i = 0;i < N;i++){
   A[i] = S[i] - '0';
 }
 cout << dfs(1,0,A[0]) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>

const int N=510;

int G[N][N];

void solve(int n,int m,int dn)
{
	int B0=(n/dn)*m,A0=n*m-B0;
	int a=A0-B0*(dn-1),K=A0/a+1;

	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(i%dn==0)G[i][j]=-K*(dn-1);
			else G[i][j]=K-1;
}

int n,m,dn,dm;

int main()
{
	scanf("%d%d%d%d",&n,&m,&dn,&dm);
	if(n%dn==0 && m%dm==0)printf("No\n");
	else 
	{
		printf("Yes\n");
		if(n%dn==0)
		{
			solve(m,n,dm);
			int fuck=std::max(n,m);
			for(int i=1;i<=fuck;i++)
				for(int j=1;j<=i;j++)
					std::swap(G[i][j],G[j][i]);
		}
		else solve(n,m,dn);
		
		for(int i=1;i<=n;i++,printf("\n"))
			for(int j=1;j<=m;j++)printf("%d ",G[i][j]);
	}
	return 0;
}


Measured memory_bytes: 2304
n,m=map(int,input().split())
if m%2!=0:
  print((n//m)**3)
else:
  if n//(m//2)%2==0:
    print((n//m)**3+(n//(m//2)//2)**3)
  else:
    print (int((n//m)**3+((n//(m//2)//2)+1)**3))

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

typedef long long int ll;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("o.txt","w",stdout);
   int n,ans=0,div=0;
   cin>>n;
   for(int i=1;i<=n;i++)
   {
       div=0;
       for(int j=1;j<=i;j++)
       {
           if(i%j==0) div++;
       }
       if(div==8) ans++;
       i++;
   }
   cout<<ans;
    return 0;
}



Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n, d;
    cin >> n >> d;
    int distance = (d*2)+1;
    int ans = 0;
    while((n-distance)>0){
        n=n-distance;
        ans++;
    }
    cout << (ans+1);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define lg long long
#define db double
#define lb(x) ((x)&-(x))
#define ft first
#define sd second
 
#define LLLINE cerr<<"@@@@@@@@@@@@@@@@@@@@"<<endl
 
template <class _T_>
void read(_T_& d){
	d=0;int f=1;char c=getchar();
	for(;c<'0'||c>'9';c=getchar())if(c=='-')f*=-1;
	for(;c>='0'&&c<='9';c=getchar())d=d*10+c-'0';
	d*=f;
}
 
/************************************************/
#define MN 2000005
 
int fr[MN],nex[MN],vi[MN],tot=0;
int sn[MN];
int n;
int vd[MN];
int tt[MN];
int res;
void add(int x,int y){
	vi[++tot]=y;nex[tot]=fr[x];fr[x]=tot;++sn[x];
}
void dfs(int x,int fa){
	for(int i=fr[x];i;i=nex[i])if(vi[i]!=fa){
		dfs(vi[i],x);
		if(vd[vi[i]])++vd[x];
		tt[x]+=tt[vi[i]];
	}
	if(vd[x]<sn[x]-1){
		res+=sn[x]-1-vd[x];
		tt[x]+=sn[x]-1-vd[x];
		vd[x]=sn[x]-1;
	}
	//cerr<<x<<' '<<sn[x]<<' '<<vd[x]<<' '<<tt[x]<<' '<<res<<endl;
}
int main(){
	read(n);
	if(n==1)return puts("0"),0;
	if(n==2)return puts("1"),0;
	for(int i=2;i<=n;++i)sn[i]=-1;
	for(int i=1,x,y;i<n;++i){
		read(x);read(y);++x;++y;
		add(x,y);add(y,x);
	}
	dfs(1,1);
	for(int i=2;i<=n;++i){
		if(vd[i]==sn[i]-1&&res==tt[i]){++res;break;}
	}
	printf("%d",res);
	return 0;
}

Measured memory_bytes: 15744
#include <bits/stdc++.h>
#define ll long long
#define MAX 1000005
using namespace std;
ll n, m, i ,j ,k ,l, ans, tmp, res;
ll arr[MAX], brr[MAX];
vector<ll> v;
string s;

int main()
{
	
		cin>>s;
		s[3]='8';
		cout<<s;
	
return 0;
}
 

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 10;
ll a[N], b[N];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    for (int i = 1; i <= n; ++i)
        cin >> b[i];
    sort(a + 1, a + 1 + n, greater<ll>());
    sort(b + 1, b + 1 + n);
    ll l = 0, r = 1e13;
    while (l < r)
    {
        ll md = (l + r) / 2;
        ll cnt = 0;
        for (int i = 1; i <= n; ++i)
        {
            ll t = md / b[i];
            cnt += max(a[i] - t, 0ll);
        }
        if (cnt <= m)
            r = md;
        else
            l = md + 1;
    }
    cout << l;
}


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

int n,q;
vector<int> ans;
vector<vector<int>> g (200010);

void dfs(int v,int p=-1){
    for(auto cp : g.at(v)){
        if(cp == p) continue;
        ans.at(cp) += ans.at(v);
        dfs(cp,v);
    }
}

int main() {
    cin >> n >> q;
    ans.resize(n);
    g.resize(n);
    queue<int> que;
    for(int i=0; i<n-1; i++){
        int a,b;
        cin >>a >> b;
        a--; b--;
        g.at(a).push_back(b);
        g.at(b).push_back(a);
    }
    for(int i=0; i<q; i++){
        int p,x;
        cin >> p >> x;
        p--;
        ans.at(p) += x;
    }
    dfs(0);
    for(int i=0; i<n; i++){
        cout << ans.at(i) << " ";
    }
}

Measured memory_bytes: 26624
#![allow(dead_code)]
use std::io;

fn main() {
    solve_a();
}

fn solve_a() {
    let mut cord = String::new();
    io::stdin().read_line(&mut cord).unwrap();
    let ps: Vec<_> = cord.trim()
        .split_whitespace()
        .map(|s| s.parse::<f64>().unwrap())
        .collect();

    let x1 = ps[0];
    let y1 = ps[1];
    let x2 = ps[2];
    let y2 = ps[3];

    let len2 = (x2 - x1).powi(2) + (y2 - y1).powi(2);
    println!("{:.4}", len2.sqrt().abs());
}



Measured memory_bytes: 5072
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    s = 0
    for i, a in enumerate(A):
        if i==0:
            continue
        
        if A[i-1] > A[i]:
            h = A[i-1] - A[i]
            A[i] += h
            s+=h
    print(s)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 93296
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

ll D;
int N,M;
vector<ll>d;

int main(){
  while(scanf("%lld", &D) && D){
    scanf("%d%d", &N, &M);
    d.resize(N+1);
    d[0] = 0;
    for(int i=0;i<N-1;i++) scanf("%lld", &d[i+1]);
    d[N] = D;
    sort(d.begin(), d.end());
    ll res = 0;
    for(int i=0;i<M;i++){
      ll k;
      scanf("%lld", &k);
      vector<ll>::iterator it = lower_bound(d.begin(), d.end(), k);
      res += min(abs(k-*(it-1)), abs(k-*it));
    }
    printf("%lld\n", res);
  }
  return 0;
}

Measured memory_bytes: 1796
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	private	static	BufferedReader	br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}
 
    /**
     * @param args
     */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[][][]	map = null;

		while((map = parseMap()) != null) {
			int	x = 0;
			int	y = 0;
			while(true) {
				int[]	next = map[y][x];
				if (next == null) {
					System.out.println(x + " " + y);
					break;
				} else {
					if (next[2] == 1) {
						System.out.println("LOOP");
						break;
					} else {
						x = next[0];
						y = next[1];
						next[2] = 1;
					}
				}
			}
		}
	}

	private static int[] parseSize() {
		String	str  = null;
		int[]	size = null;

		if ((str = parseStdin()) != null) {
			String[]	lines = str.split(" ");
			if (!lines[0].equals("0") && !lines[1].equals("0")) {
				size    = new int[2];
				size[0] = Integer.parseInt(lines[0]);
				size[1] = Integer.parseInt(lines[1]);
			}
		}
 
		return size;
	}

	private static int[][][] parseMap() {
		int[][][]	map  = null;
		int[]		size = parseSize();

		if (size != null) {
			String	str = null;

			map = new int[size[0]][size[1]][];
			for (int y = 0; y < size[0]; y++) {
				if ((str = parseStdin()) != null) {
					for (int x = 0; x < size[1]; x++) {
						switch ((int)str.charAt(x)) {
						case	(int)'>':
							map[y][x]    = new int[3];
							map[y][x][0] = x+1;
							map[y][x][1] = y;
							break;
						case	(int)'<':
							map[y][x]    = new int[3];
							map[y][x][0] = x-1;
							map[y][x][1] = y;
							break;
						case	(int)'^':
							map[y][x]    = new int[3];
							map[y][x][0] = x;
							map[y][x][1] = y-1;
							break;
						case	(int)'v':
							map[y][x]    = new int[3];
							map[y][x][0] = x;
							map[y][x][1] = y+1;
							break;
						default:
							break;
						}
					}
				}
			}
		}
 
		return map;
	}

	private static String parseStdin() {
        String  stdin = null;
        
        try {
        	String  tmp = br.readLine();
        	if (tmp != null) {
            	if (!tmp.isEmpty()) {
            		stdin = tmp;
            	}
        	}
        }
        catch (IOException e) {}
 
        return stdin;
	}
}

Measured memory_bytes: 18788
n, k, q = gets.chomp.split(' ').map(&:to_i)
array = gets.chomp.split(' ').map(&:to_i)
sorted_array = array.sort.uniq
answer = 1_000_000_000

sorted_array.each do |i|
  r = 0
  candidate_array = []
  while r < n
    index = array[r...n].index { |v| v < i } || n - r
    candidate_array += array[r, index].sort.first(index - k + 1) if index + 1 > k
    r += index + 1
  end
  break if candidate_array.size < q
  candidate_array.sort!
  answer = [answer, candidate_array[q-1]-candidate_array[0]].min
end
puts answer

Measured memory_bytes: 7672
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back()
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    int n; cin >> n;
    vector<ll> a(n),b(n);
    rep(i,n) cin >> a[i] >> b[i];
    sort(ALL(a)); sort(ALL(b));
    ll med1,med2;
    if(n%2==0){
        med1=(a[n/2-1]+a[n/2])/2;
        med2=(b[n/2-1]+b[n/2])/2;
        ll ans=(med2-med1)*2+1;
        if((a[n/2-1]+a[n/2])%2==1) ans--;
        if((b[n/2-1]+b[n/2])%2==1) ans++;
        cout << ans << endl;
    }else{
        med1=a[n/2];
        med2=b[n/2];
        cout << med2-med1+1 << endl;
    }
}


Measured memory_bytes: 6428
N,M = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(M)]

cs = [[] for i in range(N+1)]
for i,(p,y) in enumerate(src):
    cs[p].append((y,i))
for cc in cs:
    cc.sort()

ans = [None] * M
for p in range(len(cs)):
    for i,(_,j) in enumerate(cs[p]):
        s = str(p).zfill(6) + str(i+1).zfill(6)
        ans[j] = s
print(*ans, sep='\n')

Measured memory_bytes: 47772
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;

int n;
int x[MAXN+2];

ll l[MAXN+2],r[MAXN+2];

void run() {
	scanf("%d",&n); FORE(i,1,n) scanf("%d",&x[i]); x[0]=x[n+1]=0;

	l[0]=0; FOR(i,1,n+2) l[i]=l[i-1]+abs(x[i]-x[i-1]);
	r[n+1]=0; for(int i=n;i>=0;--i) r[i]=r[i+1]+abs(x[i]-x[i+1]);

	FORE(i,1,n) {
		ll cur=l[i-1]+r[i+1]+abs(x[i-1]-x[i+1]);
		printf("%lld\n",cur);
	}
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 3200
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll n,m,c,ans;
void solve()
{
    string s;cin>>s;n=s.size();
    ll ar[n];
    ar[0]=0;
    int i=0;
    if(s[i]=='A'||s[i]=='C'||s[i]=='T'||s[i]=='G')
        ar[i]=1;
    ans=ar[i];
    for(i=1;i<n;i++)
    {
        ar[i]=ar[i-1];
        if(s[i]=='A'||s[i]=='C'||s[i]=='T'||s[i]=='G')
            ar[i]++;
        else
            ar[i]=0;
        ans=max(ans,ar[i]);
    }
    cout<<ans<<endl;
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}


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

int main()
{

	std::string s,t;
	cin >> s ;
    cin >> t;
    int size = s.size();
     bool jud =false;
    for(int i =0;i<size;i++)
    {
      if(s[0]==t[i] &&jud==false) {
          for(int j =0;j <size;j++)
          {
            if(s[j]==t[(j+i)%size])
            {
               jud =true;
            }
            else{
             
              jud =false;
               break;
            }
          }
      }
      
    }
  
	if(jud ==false)cout<<"No";
  	else cout<<"Yes";
  
	return 0;
}

Measured memory_bytes: 256
using System;

namespace _0051
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = int.Parse(Console.ReadLine());
            for (int i = 0; i < count; i++)
            {
                string a = Console.ReadLine();
               // int suji = int.Parse(a);
                int max = 0, min = 0;
                int[] keta = new int[a.Length];
                for (int k = 0; k < a.Length; k++)
                {
                    keta[k] = int.Parse(a.Substring(k, 1));
                }
                Array.Sort(keta);
                for (int k = 0; k < a.Length; k++)
                {
                    max += ((int)Math.Pow(10, k) * keta[k]);
                    min += ((int)Math.Pow(10, k) * keta[a.Length - 1 - k]);
                }

                Console.WriteLine(max-min);
            }

        }
    }
}

Measured memory_bytes: 9328
// B.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
	int n, a;
	cin >> n;
	bool ans = true;
	for (int i = 0; i < n; ++i) {
		cin >> a;
		if ((a % 2) == 0 && ((a % 3) != 0 && (a % 5) != 0)) {
			ans = false;
		}
	}
	cout << (ans ? "APPROVED" : "DENIED") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf INT_MAX
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(int *)a-*(int *)b;
}

int main(void){
	int n=in(),i,a[100001],f[100001]={},t,ans=0;
	for(i=1;i<=n;i++){
		a[i]=in();
	}
	t=1;
	while(1){
		if(f[t]){
			puts("-1");
			return 0;
		}
		if(t==2){
			break;
		}
		ans++;
		f[t]=1;
		t=a[t];
	}
	print(ans);
	return 0;
}


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

using namespace std;
// using Graph = vector<vector<ll>>;

typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

const ll MOD = 1000000007;
const ll INF = 1e18; //1*10^18
const double PI = 3.14159265;

int ctoi(char c)
{
  if (c >= '0' && c <= '9')
  {
    return c - '0';
  }
  return 0;
}

ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; }
//最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//最小公倍数

ll powll(ll a, ll n)
{ //O(log n)
  ll res = 1;
  while (n > 0)
  {
    if (n & 1) //(n & 1)=(n % 2 !=0)
    {
      res = res * a;
    }
    a = a * a;
    n >>= 1; //(n & 1)=(n % 2 !=0)
  }
  return res;
}

ll modpow(ll a, ll n, ll mod) //O(log n)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1) //(n & 1)=(n % 2 !=0)
    {
      res = res * a % mod;
    }
    a = a * a % mod;
    n >>= 1; //(n>>=1)=(n/2)
  }
  return res;
}

int ReturnDigit(ll num)
{
  string number = to_string(num);
  return number.length();
}

const ll MAX = 1e4;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit()
{
  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;
  }
}

// 二項係数計算
long long 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;
}

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;
  }
};

string s[500000];
int main()
{
  // srand((unsigned int)time(NULL));//--> rand()
  ll i, j, k, l, ans = 1;
  ll n;
  cin >> n;
  for (i = 0; i < n; i++)
  {
    cin >> s[i];
  }
  sort(s + 0, s + n);

  for (i = 1; i < n; i++)
  {
    if (s[i] != s[i - 1])
    {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 19268
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(){
  int N; cin >> N;
  vector<tuple<string,int,int> > sp(N);
  
  string s;
  int p;
  rep(i,N){
    cin >> s >> p;
    sp[i] = make_tuple(s,100-p,i+1);
  }
  
  sort(sp.begin(), sp.end());
  
  rep(i,N){
    cout << get<2>(sp[i]) << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(void){
    int N;
    string C;
    cin >> N >> C;
    int w=0, r=0, r_origin=0;
    rep(i,N) if(C.at(i)=='R') r_origin++;
    rep(i,r_origin) if(C.at(i)=='W') w++;

    cout << w << endl;

    return 0;
}

Measured memory_bytes: 3756
using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using System.Text;
 
namespace AtCoder {
    public class Program {
        static int[] getKeys() {
            var Keys = Console.ReadLine().Split(' ');
            int N = Keys.Length;
            int[] Ns = new int[N];
            for (int i = 0; i < N; i++) {
                Ns[i] = int.Parse(Keys[i]);
            }
            return Ns;
        }
        static int[] getKeys(char delimiter) {
            var Keys = Console.ReadLine().Split(delimiter);
            int N = Keys.Length;
            int[] Ns = new int[N];
            for (int i = 0; i < N; i++) {
                Ns[i] = int.Parse(Keys[i]);
            }
            return Ns;
        }
        public static void Show<T>(T[,] map) {
            int H = map.GetLength(0);
            int W = map.GetLength(1);
            Console.WriteLine("-------------------------");
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    Console.Write(map[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine("-------------------------");
        }
        public static void Show<T>(T[,] map, string delimiter) {
            int H = map.GetLength(0);
            int W = map.GetLength(1);
            Console.WriteLine("-------------------------");
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    Console.Write(map[i, j] + delimiter);
                }
                Console.WriteLine();
            }
            Console.WriteLine("-------------------------");
        }
        public static void Show<T>(IEnumerable<T> ts) {
            foreach (var item in ts) {
                Console.Write(item + " ");
            }
            Console.WriteLine();
        }
        public static void Show<T>(IEnumerable<T> ts, string delimiter) {
            foreach (var item in ts) {
                Console.Write(item + delimiter);
            }
            Console.WriteLine();
        }
 
 
        static void Main() {
            var Key = getKeys();
            Console.WriteLine((double)Key[0] / Key[1]);
        }
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }

    sort(a.begin(), a.end(), greater<int> ());
    int alice = 0;
    int bob = 0;

    for(int i = 0; i < N; i++){
        if(i % 2 == 0) { alice += a[i]; }
        else{ bob += a[i]; }  
    }

    cout << alice - bob;

    return 0;


}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

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


int main(){
  int n;
  cin>>n;
  
  vector<vector<int>> vec(n, vector<int>(n,0));
  
  int x,y,z;
  rep(i,n){
    cin>>x>>y;
    rep(j,y){
      cin>>z;
      vec[x-1][z-1]=1;
    }
  }
  
  rep(i,n){
    rep(j,n){
      if(j) cout<<" ";
      cout<<vec[i][j];
    }
    cout<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 3196
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}
ll nCr (ll n, ll r){
    ll ans = 1;
    for(ll i = n ; i > n-r ; i --){
        ans *= i;
    }
    for(ll i = 1 ; i<= r; i ++){
        ans /= i;
    }
    return ans ;
}

int nPr (int n,int r){
    int ans = 1;
    for(int i = n ; i > n-r ; i --){
        ans *= i;
    }
    return ans ;
}




using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> a(n),b(n),c(n);
    REP(i,n){
        cin >> a[i] >> b[i] >> c[i];
    }

    vector<vector<int>> dp(n,vector<int>(3));
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    FOR(i,1,n){
        dp[i][0] = max(dp[i-1][1]+a[i], dp[i-1][2] + a[i]);
        dp[i][1] = max(dp[i-1][0]+b[i], dp[i-1][2] + b[i]);
        dp[i][2] = max(dp[i-1][1]+c[i], dp[i-1][0] + c[i]);
    }
    cout << max({dp[n-1][0],dp[n-1][1],dp[n-1][2]}) <<endl;

   

}





Measured memory_bytes: 9844
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)


void solve(long long K){
    if(K % 2 == 0){ // even
        cout << (K/2)*(K/2) << endl;
    } else{
        cout << (K/2) * (K/2 + 1) << endl;
    }
}

int main(){

    long long K;
    scanf("%lld",&K);
    solve(K);
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

ll *seen;
ll *a;

ll func(ll s) {
    ll u = a[s];
    if (seen[u] != -1) {
        return u;
    }

    seen[u] = seen[s]+1;
    return func(u);
}

int main() {
    ll k;
    ll n;  cin >> n >> k;
    a = new ll[n];
    seen = new ll[n];
    seen[0] = 0;
    for (int i = 1; i < n; i++)
        seen[i] = -1;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }

    ll r = func(0);
    
    ll cnt = 0;
    for (ll i = 0; i < n; i++) {
        if (seen[i] == -1)
            cnt++;
    }

    if (k <= seen[r]) {
        ll ans = 0;
        for (ll i = 0; i < k; i++)
            ans = a[ans];
        cout << ans+1 << endl;
        return 0;
    }
    
    k -= seen[r];
    ll l = n-(seen[r]+cnt);
    
    ll y = k%l;
    ll ans = r;
    for (ll i = 0; i < y; i++) {
        ans = a[ans];
    }

    cout << ans+1 << endl;

    return 0;
}

Measured memory_bytes: 6764
#include <iostream>
#include <cmath>

int main()
{
  int N;
  std::cin >> N;
  long long a[N];
  for ( int i = 0; i < N; i++ ) std::cin >> a[i];
  long long max = a[0];
  long long min = a[0];
  for ( int i = 1; i < N; i++ ) {
    if ( a[i] > max ) max = a[i];
    if ( a[i] < min ) min = a[i];
  }

  std::cout << max - min << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <limits.h>
#include <utility>
#include <map>
#include <algorithm>
using namespace std;
using P=pair<int,int>;
using ll=long long;
int main(){
    ll a;
    cin>>a;
    string s;
    cin>>s;
    cout<<a*stoi(s.substr(0,1)+s.substr(2,2))/100<<endl;
    
}



Measured memory_bytes: 3636
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        List<List<Integer>> xLists = new ArrayList<>();
        List<List<Integer>> yLists = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            List<Integer> x = new ArrayList<>();
            List<Integer> y = new ArrayList<>();
            for (int j = 0; j < a[i]; j++) {
                x.add(sc.nextInt());
                y.add(sc.nextInt());
            }
            xLists.add(x);
            yLists.add(y);
        }

        int ans = 0;
        for (int i = 0; i < (1 << n); i++) {
            Set<Integer> honests = new HashSet<>();
            for (int j = 0; j < n; j++) {
                if ((1 & (i >> j)) == 1) {
                    honests.add(j + 1);
                }
            }
            boolean correct = true;
            for (int j = 0; j < n; j++) {
                List<Integer> xlist = xLists.get(j);
                List<Integer> ylist = yLists.get(j);
                boolean isHonest = honests.contains(j + 1);
                if (!isHonest) {
                    continue;
                }
                for (int k = 0; k < a[j]; k++) {
                    int x = xlist.get(k);
                    int y = ylist.get(k);
                    if (y == 0 && !honests.contains(x) || y == 1 && honests.contains(x)) {
                        continue;
                    }
                    correct = false;
                    break;
                }
                if (!correct) {
                    break;
                }
            }
            if (correct) {
                ans = Math.max(honests.size(), ans);
            }
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 36904
from sys import stdin
from collections import deque

sect = stdin.readline().lstrip("/_").rstrip("\n\\_")
stack = deque()
res = deque()

for i in range(len(sect)):
    if sect[i] == "\\":
        stack.append(i)
    elif sect[i] == "/":
        if len(stack) != 0:
            b = stack.pop()
            if len(res) == 0:
                res.append( (b, i-b) )
            elif b > res[-1][0]:
                res.append( (b, i-b) )
            else: # 水たまりを結合
                sum_L = i-b
                while len(res) != 0:
                    if res[-1][0] > b:
                    	sum_L += res[-1][1]
                    	res.pop()
                    else:
                    	break

                res.append((b, sum_L))

res = [x[1] for x in res]
print(sum(res))
print(len(res), *res)


Measured memory_bytes: 6772
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}

long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }


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

    vector <int>A(N);
    rep(i,N)cin >> A[i];

    long long ans = 0;
    for(int i = 0; i<N-1; i++){
        if(A[i]>A[i+1]){
            ans += A[i]-A[i+1];
            A[i+1] +=A[i]-A[i+1];
        }
    }

    cout << ans << endl;



}



Measured memory_bytes: 3980
// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
#define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 200005
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 1e9;
ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll knapsack(ll ind, ll w, ll val[], ll wt[], ll n, vector<vector<ll>>& dp)
{
	if (ind >= n)
		return 0;
	if (w == 0)
		return 0;
	if (dp[ind][w] != -1)
		return dp[ind][w];
	if (wt[ind] <= w)
	{
		ll left = val[ind] + knapsack(ind + 1, w - wt[ind], val, wt, n, dp);
		ll right = knapsack(ind + 1, w, val, wt, n, dp);
		return dp[ind][w] = max(left, right);
	}
	else
		return dp[ind][w] = knapsack(ind + 1, w, val, wt, n, dp);
}
signed main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	fast
	ll n, w;
	cin >> n >> w;
	ll wi[n], vi[n];
	loop(i, n)	cin >> wi[i] >> vi[i];
	vector<vector<ll>> dp(n, vector<ll>(w + 1, -1));
	cout << knapsack(0, w, vi, wi, n, dp) << END;



//#ifndef ONLINE_JUDGE
//	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
//#endif
	return 0;
}


Measured memory_bytes: 79488