akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};

int div_ceil(int a, int b){
    return (a + (b - 1)) / b;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,k;
  cin >> n >> k;
  int a;
  int idx;
  REP(i,n){
      cin >> a;
      if (a==1){
          idx = i;
      }
  }
  cout << div_ceil(n-1,k-1) << endl;
}


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

int main()
{
   int m,n,k;
   int max;
   scanf("%d%d%d",&m,&n,&k);
   if(m>=n)
    max=m;
   else
    max=n;
    if(k%max==0)
    printf("%d",k/max);
    else
        printf("%d",k/max+1);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll fifth(ll x) {
    return x * x * x * x * x;
}

int main() {
    ll x; cin >> x;
    for (ll a = -1000; a <= 1000; a++) {
        for (ll b = -1000; b <= 1000; b++) {
            if (fifth(a) - fifth(b) == x) {
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }
}



Measured memory_bytes: 3636
// i hope i get better                                                           
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int sz=3e5+9;
ll a[sz];
ll cs[65][sz];
ll mod=1e9+7;
ll add(ll a,ll b){return ((a%mod+b%mod)%mod+mod)%mod;}
ll mul(ll a,ll b){return (a%mod*b%mod)%mod;}
ll ans;
int n;

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	for(int i=n;i>=1;i--){
		for(int j=0;j<60;j++){
			cs[j][i]=cs[j][i+1]+((a[i]>>j)&1);
		}
	}
	for(int i=1;i<n;i++){
		ll tot=n-i;
		for(int j=0;j<60;j++){
			ll cnt=cs[j][i+1];
			if((a[i]>>j)&1) ans=add(ans,mul(1ll<<j,tot-cnt));
			else ans=add(ans,mul(1ll<<j,cnt));
		}
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 144640
//ABC165 A

import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int K=sc.nextInt();
    int A=sc.nextInt();
    int B=sc.nextInt();
    int ans=1;

    for(int i=1; i<=B; i++){
      ans=K*i;
      if(ans%K==0 && ans>=A && ans<=B){
        System.out.println("OK");
        break;
      }else if(i==B){
        System.out.println("NG");
      }
    }


  }
}


Measured memory_bytes: 35620
import sys
input = sys.stdin.readline

N,M,K=map(int,input().split())
mod=10**9+7

def Combi2(a,b):#aは大きいが、bは小さいとき
    if b>a:
        return 0
    ANS=1
    for i in range(min(b,a-b)):
        ANS=ANS*(a-i)*pow(min(b,a-b)-i,mod-2,mod)%mod

    return ANS%mod

SUM_N=SUM_M=0
for i in range(N):
    SUM_N+=i*(N-i)

for i in range(M):
    SUM_M+=i*(M-i)

#print((SUM_N*(M**2)+SUM_M*(N**2))/Combi2(N*M,2)*Combi2(N*M,K)*K*(K-1)//2%mod)
print((SUM_N*(M**2)+SUM_M*(N**2))*pow(Combi2(N*M,2),mod-2,mod)*Combi2(N*M,K)*K*(K-1)*pow(2,mod-2,mod)%mod)


Measured memory_bytes: 40428
#include<algorithm>
#include<cmath>
#include<climits>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

	vector<ll> x(N);
	rep(i, N) cin >> x[i];

	ll ans = 1000000000;

	reple(i, 0, N - K)
	{
		ll l = x[i];
		ll r = x[K - 1 + i];

		chmin(ans, abs(r - l) + abs(l));
		chmin(ans, abs(r - l) + abs(r));
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
#define M 1046527
#define NIL -1
#define L 14

char H[M][L];

int getChar(char ch){
if(ch=='A')return 1;
else if(ch=='C')return 2;
else if(ch=='G')return 3;
else if(ch=='T')return 4;
else return 0;
}

long long getkey(char str[]){
long long sum=0,p=1,i;
for(i=0;i<strlen(str);i++){
sum+=p*(getChar(str[i]));
p*=5;
}
return sum;
}

int h1(int key){
return key%M;
}

int h2(int key){
return 1+(key%(M-1));
}

int find(char str[]){
long long key,i,h;
key=getkey(str);
for(i=0; ;i++){
h=(h1(key)+i*h2(key))%M;
if(strcmp(H[h],str)==0)return 1;
else if(strlen(H[h])==0)return 0;
}
return 0;
}

int insert(char str[]){
long long key,i,h;
key=getkey(str);
for(i=0; ; i++){
h=(h1(key)+i*h2(key))%M;
if(strcmp(H[h],str)==0)return 1;
else if(strlen(H[h])==0){
strcpy(H[h],str);
return 0;
}
}
return 0;
}

int main(){
int i,n,h;
char str[L],com[9];

for(i=0;i<M;i++)H[i][0]='\0';
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%s %s",com,str);

if(com[0]=='i'){
insert(str);
}
else{
if(find(str)){
printf("yes\n");
}
else{
printf("no\n");
}
}
}

return 0;
}

Measured memory_bytes: 14916
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 
	
void solve(){
   double n;
   while(cin >> n){
	   if (n <= 48.0) cout <<"light fly" << endl;
	    else if (n <= 51.0) cout << "fly" << endl;
        else if (n <= 54.0) cout << "bantam" << endl;
        else if (n <= 57.0) cout << "feather" << endl;
        else if (n <= 60.0) cout << "light" << endl;
        else if (n <= 64.0) cout << "light welter" << endl;
        else if (n <= 69.0) cout << "welter" << endl;
        else if (n <= 75.0) cout << "light middle" << endl;
        else if (n <= 81.0) cout << "middle" << endl;
        else if (n <= 91.0) cout << "light heavy" << endl;
        else{cout << "heavy" << endl;}
   }
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}



Measured memory_bytes: 3144
#include<bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
#define N 1000000
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
struct P{int x,y;}a[N]; int f[N];
inline bool cmp(P x,P y){return x.y==y.y?x.x<y.x:x.y<y.y;}
int main()
{	int n,m,k,ans=1e9;cin>>n>>m>>k;
	for(rint i=1;i<=k;i++) scanf("%d%d",&a[i].x,&a[i].y);
	sort(a+1,a+k+1,cmp); f[1]=1;
	for(rint i=1,j=1,p=1;i<=m;i++)
	{	int st=f[i];
		while(j<=k&&a[j].y<=i) j++;
		while(j<=k&&a[j].y==i+1&&a[j].x<=f[i]) j++;
	//	debug(a[i].x);debug(a[i].y);
		while(j<=k&&a[j].y==i+1&&a[j].x==f[i]+1) f[i]++,j++;
		while(p<=k&&a[p].y==i){if(a[p].x>st)
		{	ans=min(ans,st-1+a[p].x-st-1);
	//		if(i==2) debug(a[p].x);
		}
	//	debug(a[p].x);debug(a[p].y);
		p++;}
		f[i+1]=f[i]+1; ans=min(ans,st-1+n-st);
	//	debug(f[i]);
	//	debug(i);debug(n);debug(st);debug(ans);fgx;
	}
	cout<<ans+1;
	return 0;
}


Measured memory_bytes: 5120
# -*- coding: utf-8 -*-


def main():
    n, m = map(int, input().split())
    mod = 10 ** 9 + 7
    broken = [False for _ in range(n + 1)]
    dp = [0 for _ in range(n + 2)]
    dp[n] = 1

    for i in range(m):
        ai = int(input())
        broken[ai] = True

    # See:
    # https://www.youtube.com/watch?v=L8grWxBlIZ4
    for j in range(n - 1, -1, -1):
        if broken[j]:
            continue

        dp[j] = dp[j + 1] + dp[j + 2]
        dp[j] %= mod

    print(dp[0])


if __name__ == '__main__':
    main()


Measured memory_bytes: 7832
char buf[20000];sz;
inline int rd()
{
	int ret=0;
	for(;;)
	{
		char k=buf[sz++];
		if(k<'0')break;
		ret=ret*10+k-'0';
	}
	return ret;
}
int d[3001];
const int mod=998244353;
main()
{
	read(0,buf,20000);
	int N=rd();
	int S=rd();
	int ans=0;
	for(int i=0;i<N;i++)
	{
		++d[S];
		for(int j=rd(),k=0;j<=S;j++,k++)
		{
			d[k]+=d[j];
			d[k]-=mod*(d[k]>=mod);
		}
		ans+=d[0];
		if(ans>=mod)ans-=mod;
	}
	printf("%d",ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nuintptr)
	
using namespace std;


typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;

 
const int MAX = 1e6+10;
const ll inf = 1e9+10;





int main(){
	fastio;
	ll x,y;
	cin>>x>>y;
	if(y>=2*x && (y%2==0) && y<=4*x) cout<<"Yes\n";
	else cout<<"No\n";
}	

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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  string s, t;
  cin >> s >> t;

  REP(i, t.size()) {
    t = t.substr(1, t.size()-1) + t[0];
    if(s == t) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

  return 0;
}


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007


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

int main(){
	int n,x;cin >> n >> x;
	vector<int> v(n);
	int mi = 100000000;
	REP(i,n){
		cin >> v[i];
		mi = min(mi,v[i]);
		x -= v[i];
	}
	
	cout << x / mi + n << endl;
	
	
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            if (0 == N)
            {
                WriteLine(0);
                return;
            }
            var str = string.Empty;
            while (N != 0)
            {
                var r = N % 2;
                if (r < 0) r += 2;
                N = (N - r) / (-2);
                str += ((char)('0' + r)).ToString();
            }
            WriteLine(str.Reverse().ToArray());
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 28300
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
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 int dx[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int dy[8] = { 1, 1, 1, 0, 0, -1, -1, -1 };
const int lr[4] = { 0, 1, 0, -1 };
const int ud[4] = { 1, 0, -1, 0 };



//LOVE Ayane Sakura



using namespace std;



int main() {
	int X;
	cin >> X;
	int ans = 0;
	ans += (X / 500) * 1000;
	X -= (X / 500) * 500;
	ans += (X / 5) * 5;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  if (N % 2 == 1){
    for (int i = 0; i < M; i++){
      cout << i + 1 << ' ' << (N - 1) - i << endl;
    }
  } else if (N % 4 == 2){
    for (int i = 0; i < M; i++){
      if (i < (N - 1) / 4){
        cout << i + 1 << ' ' << N - i << endl;
      } else {
        cout << i + 1 << ' '  << N - 1 - i << endl;
      }
    }
  } else {
    for (int i = 0; i < M; i++){
      if (i <= (N - 2) / 4){
        cout << i + 1 << ' ' << N - i << endl;
      } else {
        cout << i + 1 << ' '  << N - 1 - i << endl;
      }
    }
  }
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int n;
string s;
int dp[5001][5001];
int mx=0;
int main(){
    cin>>n>>s;
    rep(i,n){
        for(int j=i+1;j<n;++j){
            if(s[i]!=s[j]) dp[i][j]=0;
            else{
                dp[i+1][j+1]=max(dp[i][j]+1,dp[i+1][j+1]);
                mx=max(min(dp[i+1][j+1],j-i),mx);
            }
        }
    }
    cout<<mx<<endl;
    return 0;
}

Measured memory_bytes: 96768
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int k;
	cin >> k;
	
	queue<ll> q;
	for(ll i = 1; i <= 9; ++i) {
		q.push(i);
	}
	
	ll ans = 0LL;
	for(int i = 0; i < k; ++i) {
		ll x = q.front();
		q.pop();
		ans = x;
		if( x % 10 != 0 ) q.push(10 * x + x % 10 - 1);
		
		q.push(10 * x + x % 10);
		
		if( x % 10 != 9 ) q.push(10 * x + x % 10 + 1);
	}
	
	cout << ans << endl;
	
	return 0;
}


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

int main() {
  int N; cin >> N;
  map<int, int> M;
  for (int i = 0; i < N; i++) {
    int a; cin >> a;
    if (M.count(a)) M[a]++;
    else M[a] = 1;
  }
  int ans = M.size();
  int even = 0;
  for (auto p : M) {
    if (p.second % 2 == 1) continue;
    even++;
  }
  if (even % 2 == 1) ans--;
  cout << ans << endl;
}

Measured memory_bytes: 4992
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <math.h>
#include <climits>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <map> 
#include <set>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
const ll MD = 1000000007;

/* sample input

*/
//union find
#define MAX_N 100005
long long par[MAX_N];
long long nrank[MAX_N];

void init(long long n) {
	for (long long i = 0; i < n; i++) {
		par[i] = i;
		nrank[i] = 0;
	}
}

long long find(long long x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void unite(long long x, long long y) {
	x = find(x);
	y = find(y);
	if (x == y) return;

	if (nrank[x] < nrank[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (nrank[x] == nrank[y]) nrank[x]++;
	}
}

bool same(long long x, long long y) {
	return find(x) == find(y);
}

ll n, m;
ll p[100005];
ll x[100005], y[100005];
ll answer = 0;

int main()
{

	cin >> n >> m;
	for (ll i = 0; i < n; i++) {
		cin >> p[i];
	}

	init(n);
	for (ll i = 0; i < m; i++) {
		cin >> x[i]>>y[i];
		unite(x[i], y[i]);
	}

	for (ll i = 0; i < n; i++) {
		if (same(i + 1,p[i]) ){
			answer++;
		}
	}

	cout << answer << endl;

	return 0;
}

Measured memory_bytes: 4096
import java.util.Scanner;

public class Main {

	public static int get_max_profit(int[] a) {
		if (a.length == 0)
			return 0;
		int max = Integer.MIN_VALUE;
		int min = a[0];
		for (int i = 1; i < a.length; i++) {
			max = Math.max(a[i] - min, max);
			min = Math.min(a[i], min);
		}
		return max;
	}

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = s.nextInt();
		}
		System.out.println(get_max_profit(a));
	}

}



Measured memory_bytes: 100940
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[][] grid = new int[3][3];
		for(int i = 0; i < 3; i++) {
			for(int j = 0; j < 3; j++) {
				grid[i][j] = sc.nextInt();
			}
		}
		for(int i = 1; i < 3; i++) {
			for(int j = 0; j < 3; j++) {
				grid[i][j] -= grid[0][j];
			}
		}
		boolean ans = false;
		if(grid[1][0] == grid[1][1] && grid[1][1] == grid[1][2] && grid[2][0] == grid[2][1] && grid[2][1] == grid[2][2])
			ans = true;
		if(ans) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 23252
n = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(n[int(input())-1])

Measured memory_bytes: 3064
#include<stdio.h>
int main(void)
{
int n,p,d1,d2,g,a,cpu,d;
scanf("%d",&n);
while(n!=0)
{
	cpu=0;
	d=0;
	for(a=0;a<n;a++){
		scanf("%d %d %d",&p,&d1,&d2);
		g=d1+d2;
		if(cpu<g){
			cpu=g;
			d=p;
		}
	}
	printf("%d %d\n",d,cpu);
	scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	char c;
	cin>>c;
	if(c=='A')c='T';
	else if(c=='T')c='A';
	if(c=='G')c='C';
	else if(c=='C')c='G';
	cout<<c;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define vl vector<ll>
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define sz size()
#define en end()
#define ro return 0
#define br break
#define con continue;
#define all(x) (x).be , (x).en
#define rall(x) (x).rbegin() , (x).rend()
#define acc(x) accumulate((x).be , (x).en , 0)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define forr(i,a,b) for(ll i=a;i<b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
int main()
{
    ios;
    ll a , b ;
    cin >> a >> b;
    if(a>=b) {
            swap(a , b);
    }
    if((a == 1 and b ==3) or (a==1 and b == 1) or (a==3 and b==3)){
        cout << "Yes\n";
        ro;
    }
    else cout <<"No\n";
    ro;
}























Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#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> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cerr<<' ';cerr<<elem;}cerr<<endl;}

/*二項係数(mod付き)*/
struct Combination{
	const int num=51e4;			//要素数(適宜変更する).
	const int mod=1e9+7;
	vector<llong> fact,inv,finv;//階乗,逆元,逆元の階乗.
	
	Combination():fact(num),inv(num),finv(num){
		fact[0]=fact[1]=1;
		inv[1]=1;
		finv[0]=finv[1]=1;
		for(int i=2;i<num;++i){
			fact[i]=fact[i-1]*i%mod;
			inv[i]=mod-inv[mod%i]*(mod/i)%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	
	int nCk(int n,int k){
		if(n<k) return 0;
		if(n<0 or k<0) return 0;
		return fact[n]*(finv[k]*finv[n-k]%mod)%mod;
	}
	int big_nCk(int n,int k){//nが大きい場合に使用.
		llong res=1LL;
		REP(i,k) res=res*(n-i)%mod;
		res=res*finv[k]%mod;
		return res;
	}
	int nHk(int n,int k){return nCk(n+k-1,n-1);}//重複組み合わせ.
};

//解説参考.
int main(){
	int n,k;
	cin>>n>>k;
	
	Combination ob;
	llong ans=0;
	int num=min(k,n-1);
	REP(i,num+1){//i:=0~cnt. c(i)=0の場合の組み合わせ数を数え上げ.
		llong cnt=(llong)ob.nCk(n,i)*ob.nHk(n-i,i)%MOD;//(人数が0の部屋の組の数)*(残りm人を他の部屋に割り振る場合の数).
		ans=(ans+cnt)%MOD;
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 15136
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
const ll MOD=1e+9+7;
struct mint{
  ll x;
  mint(ll x=0):x(x%MOD){}
  mint& operator+=(const mint a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator-=(const mint a){
    if((x += MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator*=(const mint a){
    (x*=a.x)%=MOD;
    return *this;
  }
  mint operator+(const mint a) const{
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const{
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const{
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const{
    if(!t) return 1;
    mint a = pow(t>>1);
    a*=a;
    if(t&1) a*=*this;
    return a;
  }
  
  //for prime mod
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint a){
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const{
    mint res(*this);
    return res/=a;
  }
};
const int NMAX=200010;
mint fact[NMAX],infac[NMAX];
void Make_Fact(){
  fact[0]=fact[1]=1;
  for(int i=2;i<=NMAX-1;++i){
    fact[i]=fact[i-1]*(mint)i;
  }
}
void Make_InvFact(){
  infac[0]=infac[1]=1;
  for(int i=2;i<=NMAX-1;++i){
    infac[i]=infac[i-1]/(mint)i;	
  }
}
mint Comb(int n,int k){
  if(n<0||k<0||n-k<0) return 0;
  return fact[n]*infac[k]*infac[n-k];
}

int main()
{
  int n;
  cin >> n;
  vector<ll> c(n);
  rep(i,n){
    cin >> c[i];
  }
  sort(c.begin(), c.end());

  vector<mint> pow2(n+1);
  pow2[0].x = 1;
  rep1(i,n){
    pow2[i] = pow2[i-1]*(mint)2;
  }

  Make_Fact();
  Make_InvFact();
  
  vector<mint> cof(n);
  // rep(i,n){
  //   rep(j,i+1){
  //     cof[i] += (mint)(j+1)*Comb(i,j);
  //   }
  // }
  cof[0].x = 1;
  rep1(i,n-1){
    cof[i] = (mint)(i+2)*pow2[i-1];
  }

  
  // rep(i,n){
  //   cout << cof[i].x << "\n";
  // }


  mint res;
  rep(i,n){
    res += (mint)c[i]*pow2[i]*cof[n-1-i];
  }

  res *= pow2[n];
  
  cout << res.x << "\n";
  
  return 0;
}


Measured memory_bytes: 8064
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <cmath>

#define	MOD 1000000007;
#define PI 3.14159265358979323846;
#define rep(i,n) for(ll i = 0;i<(ll)n;i++)
using namespace std;
typedef long long ll;
static const int MAX = 50;
static const long long INFTYL = 9223372036854775807;
ll mod = 1000000007;

vector<pair<int, int>> v;
int main()
{
	int N;
	cin >> N;

	ll a[50];

	int positiveCount = 0;
	int negativeCount = 0;
	rep(i, N) {
		cin >> a[i];
		if (a[i] >= 0) {
			positiveCount++;
		}
		else if (a[i] < 0) {
			negativeCount++;
		}
	}

	if (N != positiveCount && N != negativeCount) {
		ll maxValue = 0;
		ll maxIndex = 0;
		rep(i, N) {
			if (maxValue < abs(a[i])) {
				maxValue = abs(a[i]);
				maxIndex = i;
			}
		}

		if (a[maxIndex] >= 0) {
			positiveCount = N;
		}
		else {
			negativeCount = N;
		}

		ll tmpMax = a[maxIndex];
		rep(i, N) {
			a[i] += tmpMax;
			v.push_back(make_pair(maxIndex + 1, i + 1));
			//rep(i, N)cout << a[i] << " ";
			//cout << endl;
		}
	}

	if (N == positiveCount) {
		rep(i, N - 1) {
			if (a[i] > a[i + 1]) {
				a[i + 1] = a[i + 1] + a[i];
				v.push_back(make_pair(i + 1, i + 1 + 1));
				/*			rep(i, N)cout << a[i] << " ";
							cout << endl*/;
			}
		}
	}
	else if (N == negativeCount) {
		for (int i = N - 2; i >= 0; i--) {
			if (a[i] > a[i + 1]) {
				a[i] = a[i + 1] + a[i];
				v.push_back(make_pair(i + 1 + 1, i + 1));
				//rep(i, N)cout << a[i] << " ";
				//cout << endl;
			}
		}
		//rep(i, N - 1) {
		//	if (a[i] > a[i + 1]) {
		//		a[i] = a[i + 1] + a[i];
		//		v.push_back(make_pair(i + 1 + 1, i + 1));
		//		rep(i, N)cout << a[i] << " ";
		//		cout << endl;
		//	}
		//}
	}

	cout << v.size() << endl;
	rep(i, v.size()) {
		cout << v[i].first << " " << v[i].second << endl;
	}
	return 0;
}

Measured memory_bytes: 256
class SegTree:
    X_unit = 0
    X_f = max

    def __init__(self, N):
        self.N = N
        self.X = [0] * (N + N)

    def build(self, seq):
        for i, x in enumerate(seq, self.N):
            self.X[i] = x
        for i in range(self.N - 1, 0, -1):
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def set_val(self, i, x):
        i += self.N
        self.X[i] = x
        while i > 1:
            i >>= 1
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def fold(self, L, R):
        L += self.N
        R += self.N
        vL = self.X_unit
        vR = self.X_unit
        while L < R:
            if L & 1:
                vL = self.X_f(vL, self.X[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.X_f(self.X[R], vR)
            L >>= 1
            R >>= 1
        return self.X_f(vL, vR)

N,K = map(int,input().split())
ST = SegTree(300030)
for i in range(N):
    A = int(input())
    l = max(0,A-K)+1
    r = min(A+K,300000)+2
    M = ST.fold(l,r)
    ST.set_val(A+1,M+1)
print(ST.X[1])

Measured memory_bytes: 77500
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
const int MAX_N = 1000001;

const int N = 1000001;
int eulerPhi(int n) {
  static int lookup = 0, p[N], f[N];
  if (!lookup) {
    REP(i,N) p[i] = 1, f[i] = i;
    for (int i = 2; i < N; ++i) {
      if (p[i]) {
        f[i] -= f[i] / i;
        for (int j = i+i; j < N; j+=i)
          p[j] = 0, f[j] -= f[j] / i;
      }
    }
    lookup = 1;
  }
  return f[n];
}

int main(){
  static ll ans[MAX_N] = {};
  ans[1] = 2, ans[2] = 3;
  for(int i = 3; i < MAX_N; i++){
    ans[i] = ans[i - 1] + eulerPhi(i);
  }
  int T;
  cin>>T;
  while(T--){
    int n; cin>>n;
    cout<<ans[n]<<endl;
  }
  return 0;
}

Measured memory_bytes: 16780
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

const int INF = 1 << 30;

int main(){
	int d, g;
	scanf("%d%d", &d, &g);
	vector<pair<int, int> > p;
	for(int i = 0; i < d; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		p.push_back(make_pair(a, b));
	}
	int ans = INF;
	for(int i = 0; i < (1 << d); i++) {
		int sum = 0, last = -1;
		int cnt = 0;
		for(int j = 0; j < d; j++) {
			if(i & (1 << j)) {
				sum += 100 * (j + 1) * p[j].first + p[j].second;
				cnt += p[j].first;
			}else{
				last = j;
			}
		}
		if(sum < g) {
			int point = 100 * (last + 1);
			int need = (g - sum + point - 1) / point;
			if(need >= p[last].first) continue;
			cnt += need;
		}
		ans = min(ans, cnt);
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FFOR(i,a,b) for(int i=(a);i<=(b);i++)
#define REP(i,b) FOR(i,0,b)
#define RREP(i,b) FFOR(i,1,b)
#define PB push_back
#define F first
#define S second
#define BE(c) c.begin(),c.end()
using namespace std;
typedef long long  LL;
typedef LL ut;
typedef long double ld;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef vector<ut> VI;
typedef pair<ut,pr> ppr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
typedef priority_queue<ppr,Vppr,greater<ppr> > PpprQ;
const int SIZE=5+1e+6;
const LL INF=1LL<<60;
const ld eps=1e-6;
const LL p=7+1e+9;
PpprQ qu;
PQ legi;
LL least[SIZE];
LL N,M,K,D,SS,a,b,c;
int main(){
	cin >> N >> M >> K >> D >> SS;
	REP(i,SIZE)
		least[i]=0;
	if(N>M ){
		cout << D*K << endl;
		return 0;
	}
	REP(i,M){
		scanf("%lld %lld %lld",&a,&b,&c);
		qu.push(ppr(a,pr(b,c)));
	}
	FOR(i,1,N+1) legi.push(pr(0,i));

	LL legid=0,score=0;
	LL loops=0;
	qu.push(ppr(SS+D,pr(INF,INF)));
	while(!qu.empty() && legid<K){
		LL target=qu.top().S.S;
		LL times=qu.top().S.F;
		LL start=qu.top().F;
		qu.pop();
		//if(50000<loops++) return 0;
		if(target==INF){
			while(!legi.empty() && legi.top().F!=least[legi.top().S]){

			 //if(50000<loops++) return 0;
			 legi.pop();
			}
			if(!legi.empty()) start=max(start,legi.top().F);
			else start=start;
			score=start;
			qu.push(ppr(start+D,pr(INF,INF)));
			legid++;
		}
		else{
			target=min(target,SIZE-1LL);
			least[target]=max(least[target],start)+times;
			legi.push(pr(least[target],target));
			}
	}
	cout << score-SS << endl;
	return 0;
}

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

#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;


void solve(){
	int a, b;
	cin>>a>>b;
	cout<<max(2*a-1 , max(2*b-1, a + b))<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
     t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


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

const int N = 15;

int h,w,f=1;
char c[N][N];
int cnt[N],b[N][N];

void DFS(int x,int y){
	b[x][y]=1;
	if(x==h && y==w) return;
	if(c[x][y+1]=='#' && c[x+1][y]=='#'){ f=0;return; }
	if(c[x][y+1]=='#') { DFS(x,y+1);return; }
	if(c[x+1][y]=='#') { DFS(x+1,y);return; }
	f=0;return;
}
int main(){
	cin>>h>>w;
	for(int i=1;i<=h;i++) scanf("%s",c[i]+1);
	
	DFS(1,1);
	
	if(!b[h][w]) f=0;
	for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) if((c[i][j]!='#' && b[i][j])|| (c[i][j]=='#' && !b[i][j])) f=0;
	
	if(f) puts("Possible");
	else puts("Impossible");
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int v,d;
  int *a;
  while(cin>>v>>d){
    a=new int[v+2];
    a[0]=a[1]=1;
    for(i=2;i<v+2;i++)
      a[i]=(a[i-1]+a[i-2])%1001;
    sort(a,a+v+2);
    j=1;
    for(i=3;i<v+2;i++){
      if(a[i]-a[i-1]>=d)
	j++;
    }
    delete[]a;
    cout<<j<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main(){
    int N, M;
    int AC = 0;
    int WA = 0;
    cin >> N >> M;
    vector<int>WAn(N);
    vector<int>ACn(N);
    rep(i, M){
        int p; string S;
        cin >> p >> S;
        --p;
        if(S=="WA") WAn[p]++;
        else{
            ACn[p]++;
            if(ACn[p]==1){
                AC++;
                WA += WAn[p];
        }
    }
    }
     cout << AC << " " << WA << endl;

}


Measured memory_bytes: 1024
N = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))

total_satisfaction = 0

size = len(a_list)

previous_cuisine_number = None

for i in range(size):
    cuisine_number = a_list[i]
    cuisine_number_index = cuisine_number - 1
    satisfaction = b_list[cuisine_number_index]
    total_satisfaction += satisfaction
    if previous_cuisine_number is not None and previous_cuisine_number == cuisine_number - 1:
        total_satisfaction += c_list[previous_cuisine_number - 1]
    previous_cuisine_number = cuisine_number

print(total_satisfaction)


Measured memory_bytes: 3064
//A - Rated for Me
#include<iostream>
using namespace std;
int main(void){
	int i,j;
	scanf("%d",&i);
	if(i>=2800) printf("AGC");
	if(i>=1200&&i<2800) printf("ARC");
	if(i<1200) printf("ABC");
	return 0;
}

Measured memory_bytes: 256
s = int(input())

x1 = y1 = 0
x2, y2 = 10**9, 1
x3 = (10**9 - s % 10**9) % 10**9
y3 = (s + x3) // 10 ** 9

print(x1, y1, x2, y2, x3, y3)


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
 
using namespace std;
 
int main() {
	int n, m[100], x, count = 0;
	cin >> n >> x;
	for (int i = 0; i < n; i++){
		cin >> m[i];
		x -= m[i];
		count++;
	}
	sort(m, m + n);
	for (; x >= m[0];x -= m[0]){
		count++;
	}
	cout << count << endl;
}
 

Measured memory_bytes: 256
# B - Tap Dance

S = str(input())
ans = 'Yes'
for i in range(1, len(S) + 1):
    if i % 2 != 0 and S[i - 1] == 'L':
        ans = 'No'
    if i % 2 == 0 and S[i - 1] == 'R':
        ans = 'No'

print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,int> pll;

int main() {
    #ifndef LOCAL
        fastIO;
    #endif
    int n,posicion;
    ll k;
    cin >> n >> k;
    int direcciones[n+1];
    bool visitados[n+1];
    memset(visitados,0,sizeof(visitados));
    visitados[1]= true;
    vector<int> recorrido;
    vector<int> ciclo;
    for(int i=1;i<n+1;i++){
        cin >> direcciones[i];
    }
    recorrido.push_back(1);
    posicion=direcciones[1];
    while(!visitados[posicion]){
        visitados[posicion]=true;
        recorrido.push_back(posicion);
        posicion=direcciones[posicion];
    }
    while(visitados[posicion]){
        visitados[posicion]=false;
        ciclo.push_back(posicion);
        posicion=direcciones[posicion];
    }
    if(k<recorrido.size()){
        posicion=1;
        k=k%recorrido.size();
        while(k>0){
            posicion=direcciones[posicion];
            k--;
        }
    }else{
        posicion=direcciones[recorrido[recorrido.size()-1]];
        k-=recorrido.size();
        k=k%ciclo.size();
        while(k>0){
            posicion=direcciones[posicion];
            k--;
        }
    }
    cout << posicion << endl;
    return 0;
}


Measured memory_bytes: 6460
# C - Sentou
def main():
    n, t = map(int, input().split())
    s = list(map(int, input().split()))
    cnt = n*t

    for i in range(n-1):
        if s[i+1] - s[i] < t:
            cnt -= s[i]+t-s[i+1]
    else:
        print(cnt)


if __name__ ==  "__main__":
    main()

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


int tmp(const void *l, const void *r) {
  return strcmp((char *)l, (char *)r);
}

int main (int argc, char* argv[]) {
  long long n;
  scanf("%lld", &n);
  char s[n][12];
  for (int i = 0; i < n; i++) {
    scanf("%s", s[i]);
    qsort(s[i], 10, sizeof(char), tmp);
  }

  qsort(s, n, sizeof(s[0]), tmp);

  long long ans = 0
    , j = 0
    , k = 0
    , l = 0;
  while (j < n) {
    if (strcmp(s[j], s[k+1]) == 0) {
      ans++;
      ans += l;
      k++;
      l++;
    } else {
      j = k + 1;
      k = j;
      l = 0;
    }
  }

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

  return 0;
}


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

void solve() {
	int d, t, s;
	cin >> d >> t >> s;
	((float)t >= (float)d / (float)s) ? cout << "Yes" << endl : cout << "No" << endl;
}

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

Measured memory_bytes: 3640
#include<stdio.h>
#include<stdlib.h>

int main(){

  int i,j,k,tmp;
  int N,M,X,Y;
  scanf("%d %d %d %d",&N,&M,&X,&Y);
  int x[N],y[M];
  
  for(i=0;i<N;i++)
    scanf("%d ",&x[i]);
  
  for(i=0;i<M;i++)
    scanf("%d ",&y[i]);
  
  for (i=0; i<M; ++i) {
    for (j=i+1; j<M; ++j) {
      if (y[i] < y[j]) {
        tmp =  y[i];
        y[i] = y[j];
        y[j] = tmp;
      }
    }
  }
  
  for (i=0; i<N; ++i) {
    for (j=i+1; j<N; ++j) {
      if (x[i] > x[j]) {
        tmp =  x[i];
        x[i] = x[j];
        x[j] = tmp;
      }
    }
  }
  
  if(x[N-1] >= y[M-1]){
    puts("War");
  	return 0;
  }
 
  for(i= x[N-1]+1;i <= y[M-1];i++)
  if(i > X && i <= Y ){
    puts("No War");
    return 0;
  }
  
  puts("War");
  return 0;
}



Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int takahasi=0;
		takahasi = a-1;
		if(b>=a) {
			takahasi++;
		}
		System.out.println(takahasi);
	}

}


Measured memory_bytes: 21716
N, K = map(int, input().split())
xys = []
for i in range(N):
  x, y = map(int, input().split())
  xys.append((x, y))
xs = sorted(map(lambda xy: xy[0], xys))
ys = sorted(map(lambda xy: xy[1], xys))
rs = []
for i in range(N):
  for j in range(i+1, N):
    x1 = xs[i]
    x2 = xs[j]
    for k in range(N):
      for l in range(k+1, N):
        y1 = ys[k]
        y2 = ys[l]
        n = len([(x, y) for x, y in xys if x1 <= x <= x2 and y1 <= y <= y2])
        #xys2 = filter(lambda xy: x1 <= xy[0] <= x2 and y1 <= xy[1] <= y2, xys)
        if n >= K:
          r = (x2-x1)*(y2-y1)
          rs.append(r)
r = min(rs)
print(r)


Measured memory_bytes: 119260
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main(){
  ll a,b;
  cin>>a>>b;
  ll flag = 0;
  if(a==b)flag = 1;
  if(flag==1){
      cout << "Yes" << endl;
  }
  else{
      cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int S;
  cin >> S;
  vector<int> n(4);
  for(int i = 3; i >= 0; i--){
    n.at(i) = S % 10;
    S = S / 10;
  }
  int check = 0;
  for(int i = 0; i < 3; i++){
    if(n.at(i) == n.at(i+1)){
      check = 1;
    }
  }
  if(check)
    cout << "Bad" << endl;
  else
    cout << "Good" << endl;
}

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

typedef long long ll;
#define  endl '\n'
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll a,b; cin>>a>>b;
    a*=b;
    cout<<a;




}

Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<map>
using namespace std;
int main(){
  string s,ans_a,ans_b;
  map<string,int> word;
  int max = 0,len = 0;
  while(cin >>s) word[s]++;
  for(map<string,int>::iterator i=word.begin(); i!=word.end(); i++){
    if(max < i->second){
      max = i->second;
      ans_a = i->first;
    }
    if(len < (i->first).size()){
      len = (i->first).size();
      ans_b = i->first;
    }
  }
  cout <<ans_a<<" "<<ans_b<<endl;
  return 0;
}

Measured memory_bytes: 1196
import java.util.*;

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

        String str = sc.next();

        int ans = 0;

        for(int i = 0; i < 4; i++){
            if(str.charAt(i) == '+'){
                ans++;
            }
            else{
                ans--;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <queue>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

struct NODE{
	int a,b,c;
	NODE(int x,int y,int z){ a = x , b = y , c = z;}
};

#define INF (1<<21)
int n,U , unit[20];
char done[1<<20];
int main(){
	while(cin >> n >> U , n){
		
		int graph[21] = {0};
		memset(done,0,sizeof(done));
		for(int i = 0 ; i < n ; i++){
			int k;
			cin >> unit[i] >> k;
			for(int j = 0 ; j < k ; j++){
				int a; cin >> a;
				graph[i] |= (1<<a);
			}
		}
		queue<NODE> Q;
		Q.push(NODE(0,0,0));
		done[0] = 1;
		while(Q.size()){
			NODE q = Q.front(); Q.pop();
			if(q.b >= U){cout << q.c << endl; break;} 
			for(int i = 0 ; i < n ; i++){
				if( !(q.a >> i & 1) && (q.a & graph[i]) == graph[i])
					if(!done[q.a | (1<<i)])Q.push(NODE( q.a | (1<<i) , q.b + unit[i] , q.c+1)) , done[q.a|(1<<i)] = true;
			}
		}
		
	}
}

Measured memory_bytes: 4248
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			if ((n | m) == 0)
				break;
			Integer[] ps = new Integer[n];
			int sum = 0;
			for (int i = 0; i < n; i++) {
				ps[i] = sc.nextInt();
				sum += ps[i];
			}
			Arrays.sort(ps, new Comparator<Integer>() {
				public int compare(Integer a, Integer b) {
					return b - a;
				}
			});
			for (int i = 0; i < ps.length / m; i++) {
				sum -= ps[i*m+m-1];
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 13000
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <memory>
#include <cstring>
#include <cassert>
#include <numeric>
#include <sstream>
#include <complex>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define REP2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(S) (S).begin(), (S).end()

template <typename T, typename E>
ostream &operator<<(std::ostream &os, const std::pair<T, E> &p){
  return os << "(" << p.first << ", " << p.second << ")";
}

typedef long long ll;

const ll INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1010;

ll gcd(ll u, ll v){
  return v == 0 ? u : gcd(v, u % v);
}

ll lcm(ll u,  ll v){
  ll d = gcd(u, v);
  u /= d;
  if (INF / u < v){
    return INF;
  } else {
    return u * v;
  }
}

ll lcm(const vector<ll> &a, int mask){
  ll res = 1;
  REP(i, a.size()){
    if (mask & (1 << i)) res = lcm(res, a[i]);
  }
  return res;
}


int main(){
  ios::sync_with_stdio(false);

  ll n, m;
  while (cin >> n >> m && n + m){
    vector<ll> a(n);
    vector<ll> p(n);
    
    REP(i, n) cin >> a[i];
    REP(i, n) cin >> p[i];
    

    double res = 0;
    REP(mask, 1 << n) if (mask){
      double prob = 1.0;
      REP(i, n) if (mask & (1 << i)){
        prob *= (double)p[i] / 100;
      }
      
      if (__builtin_popcountll(mask) % 2 == 1){
        res += prob * (m / lcm(a, mask));
      } else {
        res -= prob * (m / lcm(a, mask));
      }
    }
    printf("%.20lf\n", res);
  }
  return 0;
  }

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
int f[3001][3001];
char a[3001],b[3001];
void ff(int i,int j)
{
	if(i==0||j==0)
		return;
	if(a[i-1]==b[j-1])
		ff(i-1,j-1);
	else if(f[i][j-1]>=f[i-1][j])
		ff(i,j-1);
	else
		ff(i-1,j);
	if(a[i-1]==b[j-1])
		printf("%c",a[i-1]);
}
int main()
{
	int i,j,l1,l2;
	scanf("%s",a);
	scanf("%s",b);
	l1=strlen(a);
	l2=strlen(b);
	for(i=1;i<=l1;i++)
	{
		for(j=1;j<=l2;j++)
		{
			if(a[i-1]!=b[j-1])
				f[i][j]=max(f[i-1][j],f[i][j-1]);
			else
				f[i][j]=f[i-1][j-1]+1;
		}
	}
	ff(l1,l2);
	return 0;
}

Measured memory_bytes: 35456