akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807
#define MAX_N 100000

void dfs(int a, int dsum);

int n,a,b,c,q,k,x,y,memo[100001];
bool hb[100001];
vector<pair<int,int>> v[100001];
vector<int> ans;

signed main() {
    cin >> n;
    rep(i,n-1) {
        cin >> a >> b >> c;
        v[a].pb(mp(b,c))
        v[b].pb(mp(a,c))
    }
    cin >> q >> k;
    dfs(k,0);
    rep(i,q) {
        cin >> x >> y;
        ans.pb(memo[x]+memo[y]);
    }
    rep(i,q) cout << ans[i] << endl;
}


void dfs(int a, int dsum) {
    memo[a] = dsum;
    hb[a] = true;
    if (v[a].size()) rep(i,v[a].size()) if (!hb[v[a][i].fi]) dfs(v[a][i].fi,dsum+v[a][i].se);
}



Measured memory_bytes: 15348
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string.h>
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#define Max 100005*2
#define INF 1000000000000000000
#define getMax(a,b) a<b?b:a
#define getMin(a,b) a<b?a:b
using namespace std;



int main(){

	int n,min[Max],x,c=1;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&x);
		if(i == 0)
			min[i] = x;
		else{
			min[i] = getMin(min[i-1],x);
			c = (x <= min[i-1])?(c+1):c;
		}
	}

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

	return 0;
}

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

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

struct Edge {
    int from, to;
    cost_t cost;
    Edge(int from, int to, cost_t cost) : from(from), to(to), cost(cost) {}
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;

vector<int> articulation_points(Graph& g){
    int n = g.size();
    vector<int> pre(n,-1);
    vector<int> low(n);
    vector<int> res;
    int k=0;
    function<int(int,int,int)> dfs=[&](int v,int prev,int org){
        low[v] = pre[v];
        bool isok=true;
        int cnt = 0;
        for(auto& e:g[v]){
            if(e.to==prev) continue;
            if(pre[e.to]==-1){
                pre[e.to] = k++;
                low[v] = min(low[v], dfs(e.to,v,org));
                isok = isok && low[e.to]<pre[v];
                cnt++;
            }
            else low[v] = min(low[v], pre[e.to]);
        }
        
        if(v==org){
            if(g[v].size()!=1 && cnt>1) res.push_back(v);
        }
        else if(!isok) res.push_back(v);
        return low[v];
    };
    // if connected -> dfs(0,-1,0);
    for(int i=0;i<n;i++){
        if(pre[i]==-1){
            pre[i]=k++;
            dfs(i,-1,i);
        }
    }
    return res;

}
int main(){
    int V,E;
    cin>>V>>E;
    Graph g(V);
    for(int i=0;i<E;i++){
        int s,t;
        cin>>s>>t;
        g[s].push_back(Edge(s,t,0));
        g[t].push_back(Edge(t,s,0));
    }
    auto res= articulation_points(g);
    sort(res.begin(),res.end());
    for(auto v:res){
        cout<<v<<endl;
    }
    return 0;
}



Measured memory_bytes: 6052
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ll d, c[26], s[365][26], t[365], ans = 0, m, x, y, v, old[2];
  ll ra[100000];
  for (int i = 0; i < 100000; i++) {
    ra[i] = (floor(20 / (log(i % 100000 + 20) / log(20)))) - 4;
  }
  set<ll> se[26];
  srand(time(NULL));
  cin >> d;
  for (int i = 0; i < 26; i++) {
    cin >> c[i];
    se[i].insert(0);
  }
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s[i][j];
    }
  }
  for (int i = 0; i < d; i++) {
    x = -10000000000000;
    y = -1;
    for (int j = 0; j < 26; j++) {
      if (x < s[i][j] + (i + 1 - *se[j].rbegin()) * c[j]) {
        y = j;
        x = s[i][j] + (i + 1 - *se[j].rbegin()) * c[j];
      }
    }
    t[i] = y;
    se[t[i]].insert(i + 1);
    ans += s[i][t[i]];
    for (int j = 0; j < 26; j++) {
      ans -= (i + 1 - *se[j].rbegin()) * c[j];
    }
  }
  for (int i = 0; i < 26; i++) {
    se[i].insert(d + 1);
  }
  for (int i = 0; i < 4500000; i++) {
    y = ra[rand() % 100000];
    x = rand() % (d - y) + 1;
    y += x;
    v = 0LL;
    v += s[x - 1][t[y - 1]] - s[x - 1][t[x - 1]] + s[y - 1][t[x - 1]] -
         s[y - 1][t[y - 1]];
    set<ll>::iterator it = se[t[x - 1]].find(x);
    it--;
    ll z = *se[t[x - 1]].upper_bound(x);
    v -= c[t[x - 1]] * (z - x) * (x - *it);
    se[t[x - 1]].erase(x);
    it = se[t[y - 1]].find(y);
    it--;
    z = *se[t[y - 1]].upper_bound(y);
    v -= c[t[y - 1]] * (z - y) * (y - *it);
    se[t[y - 1]].erase(y);
    it = se[t[y - 1]].lower_bound(x);
    it--;
    v += c[t[y - 1]] * (*se[t[y - 1]].lower_bound(x) - x) * (x - *it);
    it = se[t[x - 1]].lower_bound(y);
    it--;
    v += c[t[x - 1]] * (*se[t[x - 1]].lower_bound(y) - y) * (y - *it);
    if (v > 0LL) {
      ans += v;
      se[t[x - 1]].insert(y);
      se[t[y - 1]].insert(x);
      ll temp = t[x - 1];
      t[x - 1] = t[y - 1];
      t[y - 1] = temp;
    } else {
      se[t[x - 1]].insert(x);
      se[t[y - 1]].insert(y);
    }
  }
  for (int i = 0; i < d; i++) {
    cout << t[i] + 1 << endl;
  }
}

Measured memory_bytes: 4836
S = input().rstrip("")
N = len(S)

O = S[:int((N-1)/2)]
P = S[int((N+3)/2)-1:]


if  N % 2 == 0:
    print("No")

else:
    if S == S[::-1]:
        if O == O[::-1]:
            if P == P[::-1]:
                print("Yes")
            else:
                print("No")
        else:
            print("No")
    else:
        print("No")

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

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

    int q, k = 0;
    cin >> q;
    priority_queue<ll, vector<ll>, less<ll>> l;
    priority_queue<ll, vector<ll>, greater<ll>> r;

    ll ac = 0;
    ll bx = 0, al = 0, ar = 0;

    rep(i, q)
    {
        int x;
        cin >> x;
        if (x == 1)
        {
            k++;
            ll a, b;
            cin >> a >> b;
            bx += b;

            if (k % 2)
            {
                if (k == 1)
                    ac = a;
                ll x = 0;
                if (ac >= a)
                {
                    l.push(a);
                    x = l.top();
                    l.pop();
                    al += x - a;
                    al += (x - ac) * (ll)l.size();
                    ar -= (x - ac) * (ll)r.size();
                }
                else
                {
                    r.push(a);
                    x = r.top();
                    r.pop();
                    ar += a - x;
                    al += (x - ac) * (ll)l.size();
                    ar -= (x - ac) * (ll)r.size();
                }
                ac = x;
            }
            else
            {
                if (a > ac)
                {
                    r.push(a);
                    l.push(ac);
                    ar += a - ac;
                }
                else
                {
                    r.push(ac);
                    l.push(a);
                    ll x = l.top();
                    al += ac - a;
                    ar += (ac - x) * (ll)r.size();
                    al -= (ac - x) * (ll)l.size();
                    ac = x;
                }
            }
        }
        else
        {
            cout << ac << ' ' << bx + al + ar << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3828
using System.IO;
using System.Linq;
using System;

class E { static void Main() => new J(); }
class J
{
	int F() => int.Parse(Console.ReadLine());
	int[] G() => Console.ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	public J()
	{
		Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
		var S = Console.ReadLine();
		var N = S.Length;
		var e = 26;
		var next = new int[N + 2, e + 1];
		for (var c = 0; c <= e; c++) next[N + 1, c] = next[N, c] = N + 1;
		for (var i = N - 1; i >= 0; i--)
		{
			var x = S[i] - 'a';
			next[i, x] = i + 1;
			for (var c = x + 1; c <= e; c++) next[i, c] = next[next[i, c - 1], c - 1];
			if (x != 0) next[i, 0] = next[next[i, e], 0];
			for (var c = 1; c < x; c++) next[i, c] = next[next[i, c - 1], c - 1];
			for (var c = 1; c < x; c++) next[i, c] = Math.Min(next[i, c], next[next[i, e], c]);
		}
		var log = 2;
		while ((1 << log) <= N + 3) log++;
		var dp = new int[N + 2, log];
		for (var i = 0; i < N + 2; i++) dp[i, 0] = next[i, e];
		for (var p = 1; p < log; p++) for (var i = 0; i < N + 2; i++) dp[i, p] = dp[dp[i, p - 1], p - 1];
		var Q = F();
		for (var q = 0; q < Q; q++)
		{
			var I = G();
			var l = I[0] - 1;
			var r = I[1];
			for (var i = log - 1; i >= 0; i--) if (dp[l, i] <= r) l = dp[l, i];
			Console.WriteLine(l == r ? "Yes" : "No");
		}
		Console.Out.Flush();
	}
}

Measured memory_bytes: 108468
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	int x;
	scanf("%d",&x);
	if(x<1200) printf("ABC\n");
	else if(x<2800) printf("ARC\n");
	else printf("AGC\n");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

bool solve(int i, int m, int n, int *A){
    if (m == 0){
        return true;
    } else if (i >= n){
        return false;
    }
    return solve(i + 1, m, n, A) || solve(i + 1, m - A[i], n, A);
}

int main(){
    int n, q, m;
    int *A;

    scanf("%d", &n);
    A = new int[n];
    for (int i = 0; i < n; i++) scanf("%d", &A[i]);
    scanf("%d", &q);
    for (int i = 0; i < q; i++){
        scanf("%d", &m);
        if (solve(0, m, n, A)){
            printf("yes\n");
        } else {
            printf("no\n");
        }
    }

    delete[] A;
    return 0;
}



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

int n,a,ar[52];
long long dp[52][52][2600],ans;
bool visited[52][52][2600];

long long recursion(int i,int layer,int sum) {

//    cout<<i<<" "<<layer<<" "<<sum;
    if(visited[i][layer][sum])
     return dp[i][layer][sum];

    if(sum==1LL*layer*a){

//        cout<<" dhukse";
        dp[i][layer][sum]++;
    }

//    cout<<endl;
    visited[i][layer][sum]=1;

    long long& x=dp[i][layer][sum];

    for(int j=i+1; j<=n; j++)
        x+=recursion(j,layer+1,sum+ar[j]);

    return x;
}

int main() {

    while(cin>>n>>a) {

        for(int i=1; i<=n; i++)
            scanf("%d",ar+i);

        memset(dp,0,sizeof(dp));
        memset(visited,0,sizeof(visited));

        ans=0;

        for(int i=1; i<=n; i++)
            ans+=recursion(i,1,ar[i]);


        cout<<ans<<endl;

    }


    return 0;
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    vector<int> v;
    int n;
    for(int i=0; i<10; i++) {
        cin >> n;
        v.push_back(n);
    }
    sort(v.begin(), v.end());
    cout << v[9] << endl;
    cout << v[8] << endl;
    cout << v[7] << endl;
    
    return 0;
}

Measured memory_bytes: 1220
#include <iostream>

using namespace std;

int main ()
{
	long x, y;
	while(1)
	{
		cin >> x >> y;
		if(x == 0 && y == 0)
			break;
		if(x > y)
			cout << y << " " << x << endl;
		else
			cout << x << " " << y << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

int main(void) {
	
	int t, n, i;
	int s, f;
	int sum;
	
	while(1){
		sum = 0;

		scanf("%d", &t);
		if(t == 0)	break;
		
		scanf("%d", &n);
	
		for(i = 0; i < n; i++) {
			scanf("%d%d", &s, &f);
			sum += (f - s);
		}
		
		if( t <= sum ){
			printf("OK\n");
		}else{
			printf("%d\n", (t - sum));
		}
	}	
	return 0;
}

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

int main() {
  int A = 1, N, K;
  cin >> N >> K;
  
  for (int i = 0; i < N; i++) {
    if (A < K)
      A *= 2;
    else
      A += K;
  }
  
  cout << A;
}


Measured memory_bytes: 256
def m():
    X = int(input())
    length = 1001
    plus = [pow(i, 5) for i in range(0, length)]
    minas = [pow(i, 5) for i in range(-(length-1), 1)]
    minas.reverse()

    for i in range(length):
        for s in range(length):
            if (plus[i] - plus[s]) == X:
                return f'{i} {s}'

        for t in range(length):
            if (plus[i] - minas[t]) == X:
                return f'{i} {-t}'

    for i in range(length):
        for s in range(length):
            if (minas[i] - plus[s]) == X:
                return f'{-i} {s}'

        for t in range(length):
            if (minas[i] - minas[t]) == X:
                return f'{-i} {-t}'


print(m())


Measured memory_bytes: 64824
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
//ll s[500500];
const int N=1e7+5;
ll f[N],n,ans;
int main(){
   for(int i=1;i<N;i++){
        for(int j=i;j<N;j+=i)f[j]++;
   }
   cin>>n;
   for(int i=1;i<=n;i++)ans+=f[i]*i;
    cout<<ans<<"\n";
}




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

int main()
{
  int n; cin >> n;
  int min = INT_MAX, count = 0;
  for (int i = 0, p; i < n; ++i)
  {
    cin >> p;
    if (p < min)
    {
      min = p;
      ++count;
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
fn main() {
	proconio::input!{
		n: usize,
		a: [usize; n],
	}

	let mut col: [usize; 9] = [0; 9];

	for i in 0..n {
		if a[i] >= 3200 {
			col[8] += 1;
		}
		else if a[i] >= 2800 {
			col[7] += 1;
		}
		else if a[i] >= 2400 {
			col[6] += 1;
		}
		else if a[i] >= 2000 {
			col[5] += 1;
		}
		else if a[i] >= 1600 {
			col[4] += 1;
		}
		else if a[i] >= 1200 {
			col[3] += 1;
		}
		else if a[i] >= 800 {
			col[2] += 1;
		}
		else if a[i] >= 400 {
			col[1] += 1;
		}
		else {
			col[0] += 1;
		}
	}

	let mut min = 0;
	for i in 0..8 {
		if col[i] > 0 {
			min += 1;
		}
	}

	let max = min+col[8];
	if min == 0 {
		min = 1;
	}
	println!("{} {}", min, max);
}



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

template<typename T> T gcd(T a, T b) {
    if(!b) return a;
    return gcd(b, a % b);
}
template<typename T> T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

template<typename T> void chmin(T& a, T b) { a = (a > b) ? b : a; }
template<typename T> void chmax(T& a, T b) { a = (a < b) ? b : a; }
int in() { int x; scanf("%d", &x); return x; }

using namespace std;

typedef long long Int;
typedef unsigned long long uInt;
typedef unsigned uint;

int main(void) {
    int N;
    map<string, int> cnt;
    long long ans = 0;

    cin >> N;

    for (int i = 0; i < N; i++) {
        string S;
        cin >> S;

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

        cnt[S] += 1;
    }

    for (auto it : cnt) {
        ans += it.second * ((long long) it.second - 1) / 2;
    }

    cout << ans << endl;
    
    return 0;
}


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

int main(){
    int N, K;

    //input
    cin >> N >> K;

    char S[N+1];

    cin >> S;

    S[K - 1] += 'a' - 'A';

    cout << S << endl;

    return 0;
}


Measured memory_bytes: 256
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
var mod = 1e9+7;
function modinv(a){for(var b=mod,u=1,v=0,t;b;v=t)t=a/b|0,a-=t*b,u-=t*v,t=a,a=b,b=t,t=u,u=v;u%=mod;return u<0?u+mod:u;}
function abmod(){for(var a=arguments,r=a[0],i=1;i<a.length;)r=((r>>16)*a[i]%mod*65536+(r&65535)*a[i++])%mod;return r;}
function inv(a){
  var n = a.length;
  var m = 0;
  for(var i = 1; i < n; i <<= 1){
    var b = [];
    for(var j = 0; j < n;){
      var l = j, r = Math.min(n,l+i), l2 = r, r2 = Math.min(n,r+i);
      while(j < r2){
        if(l === l2)b[j]=a[r++];
        else if(r === r2)b[j]=a[l++];
        else if(a[l] > a[r]){m+=l2-l;b[j]=a[r++];}
        else b[j]=a[l++];
        j++;
      }
    }
    a = b;
  }
  return m;
}

console.log(main());
function main(){
  var n = o.a();
  var k = o.a();
  var a = o.l();
  var ans = inv(a);
  ans = abmod(ans,k);
  a.sort((a,b)=>b-a);
  var b = inv(a);
  ans += abmod(b,k-1,k,modinv(2));
  return ans%mod;
}

Measured memory_bytes: 9420
/*######################################################
#########~~~~~####~~~~###~~##~~##~~##~~##~~##~~#########
#########~~##~~##~~##~~##~~~#~~##~~~#~~##~~##~~#########
#~~~~~~##~~~~~###~~~~~~##~~#~~~##~~#~~~##~~##~~##~~~~~~#
#########~~######~~##~~##~~##~~##~~##~~##~~##~~#########
#########~~######~~##~~##~~##~~##~~##~~###~~~~##########
######################################################*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

#pragma GCC optimize("O3")
#define rtn return
#define endl '\n'
#define F first
#define S second
#define mt make_tuple
#define pb push_back
#define int long long
#define value_at find_by_order
#define index_of order_of_key
#define fill(a, v) memset(a,v,sizeof(a))
#define copy(a, b) memcpy(b,a,sizeof(a))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i, n) for(int i=0;i<(int)n;++i)
#define per(i, n) for(int i=(int)n-1;i>=0;--i)
#define rep1(i, n) for(int i=1;i<=(int)n;++i)
#define per1(i, n) for(int i=(int)n;i>=1;--i)
#define loop(i, begin, end) for(int i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " = " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " = " << arg1 << " |";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef string str;
typedef long double db;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<db> vdb;

template<class T, class V> void remin(T &a, V b) { a > b ? a = b : a = a; }
template<class T, class V> void remax(T &a, V b) { a < b ? a = b : a = a; }
template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 1e18;
const db EPS = 1e-15;
const int MOD = 1e9 + 7;
const int N = 1e5 + 7;

//

int32_t main() {
  FAST_IO;
  db n;
  cin >> n;
  db f = n / 3;
  cout << fixed << setprecision(10) << f * f * f << '\n';
  rtn 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

typedef int keytype;

//quicksort(<#keytype *a#>, <#int first#>, <#int last#>)

void quicksort(keytype a[], int first, int last){
    int i, j;
    keytype x, t;
    
    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort(a, first , i - 1);
    if (j + 1 < last) quicksort(a, j + 1, last);
}

int gcd(int x, int y){
    if (y == 0) return x;
    else        return gcd(y, x % y);
}

int main() {
    char a[6];
    int c,d,e,f;
    for (int i=0;i<6; i++) {
        scanf("%c",&a[i]);
    }
    c=a[2];
    d=a[3];
    e=a[4];
    f=a[5];
    if (c==d && e==f) {
        printf("Yes");
    }else{
        printf("No");
    }
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <cmath>
#include <random>
#include <cctype>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define MK make_pair
#define PB push_back
#define VI vector<int>
#define VII vector<int,int>
#define MSI map<string,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define W1 while(1);
const int MOD = 1000000007;
int main()
{
	int n;
	VI v;
	int m;
	cin >> n;
	REP(i, n)
	{
		int temp;
		cin >> temp;
		v.PB(temp);
	}
	cin >> m;
	REP(i, m)
	{
		int temp1, temp2;
		cin >> temp1 >> temp2;
		VI tempv;
		tempv = v;
		tempv.at(temp1 - 1) = temp2;
		int ans = 0;
		REP(i,n)
		{
			ans += tempv[i];
		}
		cout << ans << endl;
	}
	return 0;
}

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

const int mxN=101, mxW=1e5+1;
ll n, W, v[mxN], w[mxN], dp[mxW];

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> W;
    for (int i=0; i<n; ++i)
        cin >> w[i] >> v[i];
    for (int j=0; j<n; ++j)
        for (int i=W; i>=0; --i)
            if (i-w[j]>=0)
                dp[i]=max(dp[i], dp[i-w[j]]+v[j]);
    cout << dp[W] << '\n';
}


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

#define ll long long
#define ar array
#define endl "\n"
#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

void solve(){
  string s;
  cin >> s;
  ll zero = 0, one = 0;
  for(char x: s){
    if(x == '1')
      ++one;
  }
  zero = s.size() - one;
  cout << 2 * min(zero, one) << endl;
}

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


Measured memory_bytes: 3764
local n = io.read("*n")
local parent, child, childpush = {}, {}, {}
local depth = {}
for i = 1, n do
  child[i] = {}
  depth[i] = 0
  childpush[i] = 0
end
parent[1] = 0
for i = 2, n do
  local a = io.read("*n")
  parent[i] = a
  table.insert(child[a], i)
end
local tasks = {}
for i = 1, n do
  if #child[i] == 0 then
    table.insert(tasks, i)
  end
end
local function sortfunc(x, y)
  return depth[x] > depth[y]
end
local mma = math.max
while 0 < #tasks do
  local c = tasks[#tasks]
  table.remove(tasks)
  local p = parent[c]
  childpush[p] = childpush[p] + 1
  if childpush[p] == #child[p] then
    table.sort(child[p], sortfunc)
    local d = 0
    for i = 1, #child[p] do
      d = mma(d, i + depth[child[p][i]])
    end
    depth[p] = d
    if 1 < p then
      table.insert(tasks, p)
    end
  end
end
print(depth[1])


Measured memory_bytes: 11380
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int n, s[100], ans;

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        ans += s[i];
    }
    if (ans % 10 == 0) {
        sort(s, s + n);
        for (int i = 0; i < n; i++) {
            if (s[i] % 10 != 0) {
                ans -= s[i];
                break;
            }
        }
        if (ans % 10 == 0) ans = 0;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long int ll;

int main(){
    int N;
    cin >> N;
    vector<int> L;

    for(int i=0;i<N;i++){
        int Li;
        cin >> Li;
        L.emplace_back(Li);
    }

    sort(L.begin(),L.end(),greater<int>());
    for(auto v : L){
        //printf("[]%d\n",v);
    }

    int ans=0;

    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            for(int k=j+1;k<N;k++){
                int a=L[i], b=L[j], c=L[k];
                if(a/2<c){
                    ans++;//printf("あ:%d,%d,%d\n",a,b,c);
                    continue;
                }
                if(abs(b-c)<a && a<b+c){
                    ans++;//printf("い:%d,%d,%d\n",a,b,c);
                }
            }
        }
    }  

    cout << ans << endl;

}

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

typedef long int lint;
typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<long, long> pll;

#define EACH(t, c) for (auto&& t : c)
#define ALL(c) begin(c), end(c)
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl '\n'
#define fk first
#define sv second

const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}, dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

  cin >> n >> x;

  int m[n];
  int res = 0;
  int minM = INF;
  REP(i, n) {
    cin >> m[i];
    x -= m[i];
    res++;
    minM = min(m[i], minM);
  }

  res += x / minM;

  cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include <iomanip>
#include <bits/stdc++.h>
#include <fstream>
#include <map>
using namespace std;
typedef long long ll;
//#define INF 1000000000000 //10^12:極めて大きい値,∞
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    ll n,zero=0;
    cin >> n;
    long long temp;
    vector<long long> a;
    long long ans=1;
    
    REP(i,n){
        cin >> temp;
        a.push_back(temp);
        if(temp == 0){
            zero++;
        }
    }
    if(zero != 0){
        cout << 0 << endl;
        return 0;
    }
    REP(i,n){
        if(a[i] <= 1000000000000000000/ans){
            ans *= a[i];
        }
        else{
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4316
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type_a,class Type_b> bool chmax(Type_a &a,const Type_b &b){if(a<b){a=b;return true;}return false;}
template<class Type_a,class Type_b> bool chmin(Type_a &a,const Type_b &b){if(a>b){a=b;return true;}return false;}
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int n;
set<string> ans;

void dfs(int num,vi tmp,int use){
	if(num==n){
		string res;
		char key='b';
		map<int,char> mp;
		REP(i,n){
			if(tmp[i]==0){
				res+='a';
			}else if(mp[tmp[i]]==0){
				mp[tmp[i]]=key-'a';
				res+=key++;
			}else{
				res+=('a'+mp[tmp[i]]);
			}
		}
		ans.insert(res);
		return;
	}
	
	REP(i,use+1){
		tmp[num]=i;
		//line(tmp);
		if(i+1>use) dfs(num+1,tmp,use+1);
		else dfs(num+1,tmp,use);
	}
}

int main(){
	cin>>n;
	
	vi tmp(n,0);
	int use=1;
	dfs(1,tmp,use);
	
	for(auto elem:ans){
		cout<<elem<<endl;
	}
}


Measured memory_bytes: 14208
#include<bits/stdc++.h>
#define ll long long
#define nes ios_base :: sync_with_stdio(0); cin.tie(0);
using namespace std;
const ll mo=1e9+7;
ll mod(ll n){
	return (n+mo)%mo;
}
ll fac(ll n){
	ll res=0;
	for(ll i=1;i<=(ll)sqrt(n);++i){
		if(n%i==0){
			if(n/i!=i) res+=2;
			else res+=1;
		}
	}
	return (ll)(2*res);
}
int main(){
	nes;
	ll n;
	cin>>n;
	set<ll>se;
	ll count=0;
	for(ll i=2;i<n;++i){
		ll j=1;
		ll des=i*j;
		while(des<=n-1){
			++count;
			des=i*(++j);
		}
	}
	cout<<count+n-1;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n - 1);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  for (int i = 0; i < n; i++) cin >> b.at(i);
  for (int i = 0; i < n - 1; i++) cin >> c.at(i);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += b.at(a.at(i) - 1);
    if (i > 0 && a.at(i) == a.at(i - 1) + 1)
      sum += c.at(a.at(i) - 2);
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
//************************
//*  Date: 2018.10.19    *
//*  Problem:            *
//*  Author: xuziyuan    * 
//************************

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,k,val[100010];
vector <int> g[100010];

int main()
{
	memset(val,-1,sizeof(val));
	cin>>n;
	rep(i,n-1)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		g[x].pb(y);
		g[y].pb(x);
	}
	cin>>k;
	multiset <pii> s;
	rep(i,k)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		s.insert({y,x});
		val[x]=y;
	}
	while(!s.empty())
	{
		pii t=*s.begin();
		s.erase(s.begin());
		rep(i,g[t.se].size())
		{
			if(val[g[t.se][i]]==-1)
			{
				val[g[t.se][i]]=t.fi+1;
				s.insert({t.fi+1,g[t.se][i]});
			}
		}
	}
	repn(i,n)
	{
		rep(j,g[i].size())
		{
			if(abs(val[i]-val[g[i][j]])!=1)
			{
				puts("No");
				rt0;
			}
		}
	}
	puts("Yes");
	repn(i,n) cout<<val[i]<<endl;
	rt0;
}

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

using namespace std;

char str[2][100010];

int qsum[2][100010];

int main()  {
    scanf("%s",str[0]);
    scanf("%s",str[1]);
    int n = strlen(str[0]);
    for ( int d=0 ; d<2 ; d++ )
    {
        int n = strlen(str[d]);
        for ( int c=0 ; c<n ; c++ )
        {
            qsum[d][c+1] = qsum[d][c];
            if ( str[d][c] == 'A' ) qsum[d][c+1]++;
        }
    }
    int q;
    scanf("%d",&q);
    int a,b,x,y;
    for ( int c=1 ; c<=q ; c++ )
    {
        scanf("%d%d%d%d",&a,&b,&x,&y);
        int A = qsum[0][b] - qsum[0][a-1];
        //printf ("%d %d %d\n",qsum[0][b],qsum[0][a-1],b);
        int B = b-a+1 - A;
        int A2 = qsum[1][y] - qsum[1][x-1];
        int B2 = y-x+1 - A2;
        //printf("%d %d %d %d\n",A,B,A2,B2);
        A -= A2;
        B -= B2;
        A -= B;
        if ( A % 3 == 0 )   printf("YES\n");
        else    printf("NO\n");
    }
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000001

int main() {
    int n;cin >> n;
    n /= 2;
    vector<int> e(100001),o(100001);
    for(int i = 0; i < n*2; i++) {
        int v;cin >> v;
        if(i%2==0){
            o[v]++;
        }
        else e[v]++;
    }

    int a=0,b=0,c=0,d=0;
    for(int i = 0; i < 100001; i++) {
        if(e[i]>a){
            c=i;
            a=e[i];
        }
    }
    for(int i = 0; i < 100001; i++) {
        if(o[i]>b){
            d=i;
            b=o[i];
        }
    }

    int x=a+b;
    if(c==d){
        sort(e.begin(),e.end());
        sort(o.begin(),o.end());
        x=max(a+o[99999],b+e[99999]);
    }
    cout << n*2-x << endl;

    return 0;
}

Measured memory_bytes: 4032
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;
typedef long long int ll;

int main()
{
	ll x;
	scanf("%lld",&x);
	ll ret=x/11LL*2LL;
	if(x%11!=0)
	{
		if(x%11<=6) ret++;
		else ret+=2LL;
	}
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 128
def run():
  N = int(input())
  As = list(map(int, input().split()))
  for A in As:
    if A%2 == 0:
      if (A%3 == 0) or (A%5 == 0):
        pass
      else:
        print('DENIED')
        break
  else:
    print('APPROVED')
    

if __name__ == '__main__':
  run()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }

using ll = long long;
const ll mod = LLONG_MAX;

int main(){

  string s;
  cin>>s;
  bool flag=false;
  bool flag2=false;
  if(s[0]==s[s.size()-1]){
    flag=true;
  }

  if(s.size()%2==0){
    flag2=true;
  }

  if(flag^flag2){
    cout<<"Second"<<endl;
  }else{
    cout<<"First"<<endl;
  }

}


Measured memory_bytes: 512
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順
#include <map>

using namespace std;
using ll = long long int;

int main(){
    int N,D;cin>>N>>D;
    int ans = 0;
    for(int i=0;i<N;i++){
        int x,y;cin>>x>>y;
        if(sqrt(pow(x,2)+pow(y,2))<=D) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3660
def solve(S):
    n = len(S) - 1
    result = 0
    for i in range(2**n):
        sum_i = 0
        now = 0
        for j in range(n+1):
            now = now * 10 + int(S[j])
            if j < n:
                if ((i >> j) & 1):
                    sum_i += now
                    now = 0
            else:
                sum_i += now
        result += sum_i
    return result
S = input()
print(solve(S))

Measured memory_bytes: 9100
s=input()
if int(s[:2])>0 and int(s[:2])<=12 and int(s[2:])>0 and int(s[2:])<=12:
	print('AMBIGUOUS')
elif int(s[:2])>0 and int(s[:2])<=12:
	print('MMYY')
elif int(s[2:])>0 and int(s[2:])<=12:
	print('YYMM')
else:
	print('NA')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
using ll = long long;
using namespace std;

ll dp[10010][110], v[110], w[110], n, W;

int main(){
    cin >> n >> W;
    FOR(i, 1, n + 1){
        cin >> v[i] >> w[i];
    }
    REP(i, 10010){
        REP(j, 110){
            dp[i][j] = 0;
        }
    }
    FOR(i, 1, W + 1){
        FOR(j, 1, n + 1){
            if(i - w[j] >= 0){
                if(dp[i - w[j]][j - 1] + v[j] >= dp[i][j - 1]){
                    dp[i][j] = dp[i - w[j]][j - 1] + v[j];
                }else{
                    dp[i][j] = dp[i][j - 1];
                }
            }else{
                dp[i][j] = dp[i][j - 1];
            }
        }
    }
    cout << dp[W][n] << endl;
}

Measured memory_bytes: 11700
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define per(i,s,n) for(int i=n-1;i>=s;i--)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;

int p(ll a,map<ll,ll> o){
  ll n=a;
  int ans=0;
  for(ll i=2;i*i<=a;i++){
    if(o[i]!=0 && a%i==0) {
      n/=i;
      ans++;
    }
  }
  
  if(n==a&&a!=1) ans++;
  
  return ans;
}

int main(){
  ll n;
  cin>>n;
  ll ans=0;
  ll now=n;
  map<ll,ll> m;
  for(ll i=2;i*i<now;i++){
    while(n%i==0){     
      n/=i;
      m[i]++;
    }
    int c=1;
    while(c*(c+1)/2<=m[i]){
      ans++;
      c++;
      
    }
    //if(m[i]>0) cout<<i<<" "<<ans<<endl;
  }
  
  
  if(n>1){
    ans++;
  }
  
  //cout<<m[6079]<<endl;
  
  cout<<ans<<endl;
}






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

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if((a+b) > (c+d)) cout<<"Left"<<endl;
    else if((a+b)<(c+d)) cout<<"Right"<<endl;
    else if((a+b) == (c+d)) cout<<"Balanced"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N;
  cin >> N;
  int x = N%10;

  if(x == 3) cout << "bon" << endl;
  else if(x==0||x==1||x==6||x==8) cout << "pon" << endl;
  else cout << "hon" << endl;
  
  return 0;
}


Measured memory_bytes: 3632
input_line = gets.chomp.split(" ")
n = input_line[0].to_i
l = input_line[1].to_i
result = 0
if l >= 0 then
  for i in l+1 .. l+n-1 do
    result += i
  end
elsif l < 0 && l+n-1 >=0 then
  for i in l .. l+n-1 do
    result += i
  end
else 
  for i in l .. l+n-2 do
    result += i
  end
end
puts result
#puts input_line[0]
#puts input_line[1]

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

int main() {
  int N,u,v;cin>>N>>u>>v;
  u--;v--;
  vector<vector<int>> tree(N,vector<int>());
  rep(i,N-1) {
    int a,b;cin>>a>>b;
    a--;b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  vector<bool> u_done(N,false),v_done(N,false);
  vector<int> u_dis(N,0),v_dis(N,0);
  u_done[u] = true;
  v_done[v] = true;
  queue<int> uq,vq;
  uq.push(u);
  vq.push(v);
  while(!uq.empty()) {
    int now = uq.front();
    uq.pop();
    for(auto nxt : tree[now]) {
      if(!u_done[nxt]) {
	u_done[nxt]= true;
	u_dis[nxt] = u_dis[now] + 1;
	uq.push(nxt);
      }
    }
  }
  // rep(i,N) {
  //   cout<<u_dis[i]<<endl;
  // }
  vector<int> leaf;
  while(!vq.empty()) {
    int now = vq.front();
    vq.pop();
    int chi_siz = 0;
    for(auto nxt : tree[now]) {
      if(!v_done[nxt]) {
	chi_siz++;
	v_done[nxt]= true;
	v_dis[nxt] = v_dis[now] + 1;
	vq.push(nxt);
      }
    }
    // cout<<now<<" "<<chi_siz<<endl;
    if(chi_siz == 0) leaf.push_back(now);
  }
  int ans = 0;
  for(auto lf : leaf) {
    // cout<<lf<<endl;
    if(u_dis[lf] < v_dis[lf]) {
      ans = max(ans,v_dis[lf]-1);
    }
  }
  cout<<ans<<endl;
}
 


Measured memory_bytes: 9980
#!/usr/bin/env python3
# n,m = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(sys.stdin.readline() for _ in range(n)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# n = int(sys.stdin.readline())
# INF = float("inf")
import sys,collections

N,K = map(int,sys.stdin.readline().split())
A = tuple(map(int,sys.stdin.readline().split())) # single line with multi param

d = {}
a = []
n = 1
i = 0
while True:
    #print(n)
    d[n] = i
    i += 1
    a.append(n)
    n = A[n-1]
    if n in d:
        break
pre = d[n]
cycle = a[pre:]
#print(pre,a,cycle)
if K < pre:
    print(a[K])
else:
    print(a[pre+(K-pre)%(len(cycle))])


Measured memory_bytes: 40444
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        a : i32,
        b : i32,
        c : i32
    }
    println!("{}", if (b / a) < c {b / a} else {c});
}


Measured memory_bytes: 4352
n = int(input())
a = map(int,raw_input().split())

for i in range(n):
    v = a[i]
    j = i - 1
    while j >= 0 and a[j] > v:
        a[j+1] = a[j]
        j -= 1
    a[j+1] = v
    print " ".join(map(str,a))

Measured memory_bytes: 6380
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <math.h>
#include <fstream>


using namespace std;

int main()
{
int hako[6],hako2[4];
int i,a1=0,a2=0,a3=0,a4=0,x;
int count =0;

for(i=0;i<6;i++){
	cin>>hako[i];
}

for(i=0;i<4;i++){
	hako2[i]=0;
}
for(i=0;i<6;i++){
	if(hako[i]==1)hako2[0]+=1;
	if(hako[i]==2)hako2[1]+=1;
	if(hako[i]==3)hako2[2]+=1;
	if(hako[i]==4)hako2[3]+=1;
}

for(i=0;i<4;i++){
	if(hako2[i]==1)count += 1;
}
if(count==2){
	cout<<"YES"<<endl;
}
else{
	cout<<"NO"<<endl;
}
return 0;
}	


Measured memory_bytes: 256
N ,M = map(int , input().split())
max_L = []
min_R = []
gate_number = [i for i in range(1, M+1)]
for j in range(M):
    L , M = map(int,input().split())
    max_L.append(L)
    min_R.append(M)
print(len([s for s in range(max(max_L) , min(min_R) + 1)]))

Measured memory_bytes: 16392
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	ll n;
	string s1,s2;
	cin>>n>>s1>>s2;
	ll mod=1e9+7;
	ll ans,now;
	if(s1[0]==s2[0]){
		ans=3;
		now=1;
	}else{
		ans=6;
		now=2;
	}
	for(int i=now;i<n;i++){
		if(s1[i]==s2[i]){
			if(s1[i-1]==s2[i-1]){
				ans*=2;
				ans%=mod;
			}
		}else{
			if(s1[i-1]==s2[i-1]){
				ans*=2;
				ans%=mod;
			}else{
				ans*=3;
				ans%=mod;
			}
			i++;
		}
	}
	cout<<ans;
	return 0;
}

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

using namespace std;

int main(void){
    int N;
    string S;
    cin>>N;
    cin>>S;
    char a[100001];
    for(int i=0;i<S.length();++i){
       int tmp = S[i] - 'A';
       tmp = (tmp+N)%26;
       putchar('A'+tmp);
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int a, b; cin >> a >> b;
    if (a == b) {
        cout << a << endl;
        return 0;
    }
    if (a < b) swap(a, b);
    while (1) {
        int flg = 0;
        while (a > b) {a -= b; flg = 1;}
        while (a < b) {b -= a; flg = 1;}
        if (flg == 0) break;
    }
    //cout << a << " " << b << endl;
    cout << min(a, b) << endl;
}



Measured memory_bytes: 3184
#include "bits/stdc++.h"
using namespace std;

int main() {
	int D, C[26];
	cin >> D;
	for (int i = 0; i < 26; i++) cin >> C[i];
	vector<int> L(26, -1);
	vector<vector<int> > S(D, vector<int>(26));
	for (int i = 0; i < D; i++) {
		for (int j = 0; j < 26; j++) cin >> S[i][j];
	}
	for (int i = 0; i < D; i++) {
		long long MAX = -1000000000000000, ID = -1;
		for (int j = 0; j < 26; j++) {
			if (MAX < S[i][j] + C[j] * (i - L[j])) MAX = S[i][j] + C[j] * (i - L[j]), ID = j;
		}
		L[ID] = i;
		cout << ID + 1 << endl;
	}
}

Measured memory_bytes: 3684
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication9
{
    class Program
    {
        static void Main(string[] args)
        {
            
            
            String[] str = Console.ReadLine().Split(' ');
            int H = int.Parse(str[0]);
            int W = int.Parse(str[1]);
            while (H != 0 || W != 0)
            {
                for (int i = 0; i < H; i++)
                {
                    for (int j = 0; j < W; j++)
                    {
                        Console.Write("#");
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
                str = Console.ReadLine().Split(' ');
                H = int.Parse(str[0]);
                W = int.Parse(str[1]);

            }



        }
    }
}

Measured memory_bytes: 5300
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

bottom = 2
res = a[0]-1

for i in range(1,n):
    if a[i] == bottom: bottom=a[i]+1
    b = (a[i] - 1) // bottom
    res += b


print(res)

Measured memory_bytes: 7080
#include<utility>
#include<iostream>
#include<vector>
#include<cassert>
using namespace std;

int n,m,h,d;
vector<string> F;


bool judge(vector<string> f){
  int now = m;
  for(int i=0;i<f.size();i++){
    assert(now!=0);
    if(f[i][now-1]=='1'){
      now = now-1;
    }else if(f[i][now]=='1'){
      now = now+1;
    }
    //cout<<F[i]<<" "<<f[i]<<" "<<now<<endl;
  }
  return now == h;
}

pair<int,int> solve(){
  if(judge(F))return make_pair(0,0);
  for(int i=0;i<F.size();i++){
    for(int j=1;j<F[i].size()-1;j++){
      vector<string> tmp = F;
      if(tmp[i][j-1]!='1'&&tmp[i][j+1]!='1'){
        tmp[i][j]='1';
        if(judge(tmp)){
          return make_pair(i+1,j);
        }
      }
    }
  }
  return make_pair(-1,0);
}


int main(){
  while(cin>>n,n!=0){
    cin>>m>>h>>d;
    F.clear();
    for(int i=0;i<d;i++){
      string s;
      cin>>s;
      s = "*"+s+"*";
      F.push_back(s);
    }
    pair<int,int> ans = solve();
    if(ans.first==0){
      cout<<0<<endl;
    }else if(ans.first==-1){
      cout<<1<<endl;
    }else{
      cout<<ans.first<<" "<<ans.second<<endl; 
    }
  }
}

Measured memory_bytes: 1220
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = 1;
        int i = 0;

        while(C < B) {
            C = C + A - 1;
            i++;
        }
        System.out.println(i);
    }
}

Measured memory_bytes: 25172
N, A, B, K = map(int, input().split())
mod = 998244353

# 階乗 & 逆元計算
factorial = [1]
inverse = [1]
for i in range(1, N+2):
    factorial.append(factorial[-1] * i % mod)
    inverse.append(pow(factorial[-1], mod-2, mod))


# 組み合わせ計算
def nCr(n, r):
    if n < r:
        return 0
    elif r == 0:
        return 1
    return factorial[n] * inverse[r] * inverse[n - r] % mod


ans = 0
for r in range(N+1):
    b = (K - A*r) / B
    # 青で塗る箇所が整数ならば
    if b == (K-A*r) // B and 0 <= b <= N:
        ans += nCr(N, r) * nCr(N, int(b)) % mod

print(ans % mod)


Measured memory_bytes: 80880