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

int main(){
    string s;
    cin >> s[0] >> s[1] >> s[2];

    int cnt = 0;
    if(s[0] == '1') ++cnt;
    if(s[1] == '1') ++cnt;
    if(s[2] == '1') ++cnt;

    cout << cnt << endl;
}

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

namespace ABC124A
{
    class Program
    {
        static void Main(string[] args)
        {

            {
                var word = Console.ReadLine().Split();
                int a = int.Parse(word[0]);
                int b = int.Parse(word[1]);
                int max = 0;
                for (int i = 0; i < 2; i++)
                {
                    if (a < b)
                    {
                        max += b;
                        b--;
                        continue;
                    }
                     if (b <= a)
                    {
                        max += a;
                        a--;
                        continue;
                    }
                }
                    Console.WriteLine(max);
                    Console.ReadKey();



                }
            }
        }
    }



Measured memory_bytes: 11092
<?php

$N = trim(fgets(STDIN));
$count = 0;
$len_check = [];
for($i=1; $i<=$N; $i++){
    $digit = count(str_split($i));
    
    if($digit % 2 === 1){
        $count += 1;
    }
    
}
echo $count;
?>

Measured memory_bytes: 16176
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>

template <class Tp>
Tp gcd(Tp a, Tp b, Tp& x, Tp& y) {
  x = Tp(0);
  y = Tp(1);
  for (Tp u = y, v = x; a;) {
    Tp q = b/a;
    std::swap(x -= q*u, u);
    std::swap(y -= q*v, v);
    std::swap(b -= q*a, a);
  }
  return b;
}

template <class Tp>
Tp modinv(Tp a, Tp mod) {
  Tp x, y;
  gcd(a, mod, x, y);
  x %= mod;
  if (x < 0) x += mod;
  return x;
}

template <class Tp>
Tp modadd(Tp a, Tp b, Tp mod) {
  a += b % mod;
  if (a < 0) a += mod;
  if (a >= mod) a -= mod;
  return a;
}

template <class Tp>
Tp modadd(const std::initializer_list<Tp>& adds, Tp mod) {
  Tp res = 0;
  for (const auto& add: adds) {
    res += add % mod;
    if (res < 0) res += mod;
    if (res >= mod) res -= mod;
  }
  return res;
}

template <class Tp>
Tp modsub(Tp a, Tp b, Tp mod) {
  a -= b % mod;
  if (a < 0) a += mod;
  if (a >= mod) a -= mod;
  return a;
}

template <class Tp>
Tp modmul(const std::initializer_list<Tp>& muls, Tp mod) {
  Tp res = 1;
  for (const auto& mul: muls) (res *= mul) %= mod;
  return res;
}

template <class Tp>
Tp modpow(Tp base, intmax_t iexp, Tp mod) {
  Tp res = 1;
  for (Tp dbl = base; iexp; iexp >>= 1) {
    if (iexp & 1) res = res * dbl % mod;
    dbl = dbl * dbl % mod;
  }
  return res;
}

class modchoose {
  std::vector<intmax_t> fact, fact_inv;
  intmax_t mod;

public:
  modchoose(intmax_t N, intmax_t mod): mod(mod) {
    fact.resize(N+1);
    fact_inv.resize(N+1);
    fact[0] = 1;
    for (intmax_t i = 1; i <= N; ++i)
      fact[i] = fact[i-1] * i % mod;

    fact_inv[N] = modinv(fact[N], mod);
    for (intmax_t i = N; i--;)
      fact_inv[i] = fact_inv[i+1] * (i+1) % mod;
  }

  intmax_t operator ()(intmax_t n, intmax_t r) const {
    intmax_t res = fact[n] * fact_inv[r] % mod;
    (res *= fact_inv[n-r]) %= mod;
    return res;
  }
};

constexpr intmax_t mod = 1e9+7;

intmax_t pomae(intmax_t N, intmax_t M, intmax_t K) {
  intmax_t res = 0;
  for (intmax_t d = 1; d < M; ++d) {
    (res += modmul({d, (M-d), N, N}, mod)) %= mod;
  }
  modchoose ncr(N*M, mod);
  (res *= ncr(N*M-2, K-2)) %= mod;
  return res;
}

int main() {
  intmax_t N, M, K;
  scanf("%jd %jd %jd", &N, &M, &K);

  intmax_t res = 0;
  (res += pomae(N, M, K)) %= mod;
  (res += pomae(M, N, K)) %= mod;

  printf("%jd\n", res);
}


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

using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;




const int INF = 1000000;
const int mod = 1e9 + 7;




struct team {
	int num, ac, t;
	vi miss;
	team(int num) : num(num){
		ac = t = 0;
		miss = vi(11, 0);
	}
	team(int num, int a) : num(num){
		ac = t = 0;
		miss = vi(a + 1, 0);
	}
	bool operator < (team T) {
		if (ac != T.ac) return ac > T.ac;
		if (t != T.t) return t < T.t;
		return num < T.num;
	}
	void accept(int n, int time) {
		ac++;
		t += miss[n] * 1200 + time;
	}
	void wrong(int n) {
		miss[n]++;
	}
};

bool cmp(team t1, team t2) {
	return t1 < t2;
}

int main() {
	int t, p, r;
	while (cin >> t >> p >> r) {
		if (t == 0 && p == 0 && r == 0) break;
		vector<team> v;
		rep(i, t) v.push_back(team(i + 1, p));
		int tid, pid, time;
		string mes;
		rep(i, r) {
			cin >> tid >> pid >> time >> mes;
			if (mes == "CORRECT") v[tid - 1].accept(pid, time);
			else v[tid - 1].wrong(pid);
		}
		sort(all(v), cmp);
		rep(i, t) {
			cout << v[i].num << " " << v[i].ac << " " << v[i].t << endl;
		}
	}
}

Measured memory_bytes: 1264
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;
typedef long long ll;
const int maxn = 1e9;

int main()
{
    char t;
    while((t=getchar())!=EOF)
    {
        if(t=='1') printf("9");
        else if(t=='9') printf("1");
        else printf("%c",t);
    }
    return 0;
}


Measured memory_bytes: 764
n, m = [int(elem) for elem in input().split()]
a = [elem for elem in input().split()]
a = sorted(a, reverse=True)

num_dict = {"1":2, "2":5, "3":5, "4":4, "5":5, "6":6, "7":3, "8":7, "9":6}
dp = ["" for _ in range(n+1)]

for i in range(n+1):
    for strnum in a:
        if i - num_dict[strnum] < 0:
            continue
        if i - num_dict[strnum] == 0 and dp[i] == "":
            dp[i] = strnum
        pre_strnum = dp[i - num_dict[strnum]]
        if pre_strnum != "":
            if len(pre_strnum) + 1 > len(dp[i]):
                dp[i] = pre_strnum + strnum

print("".join(sorted(dp[n], reverse=True)))

Measured memory_bytes: 29684
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#undef int
#define mk make_pair
#define pb push_back
typedef pair<int, int> pii;
const int mod = 1000000007;
const int INF = 1000000009;
const long long INFL = 1000000000000000018ll;

int N, a[100100], b[100100];
bool fre[100100], fre2[100100];

signed main()
{
    cin >> N;
    bool flag = false;
    fre[0] = true;
    fre2[N - 1] = true;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        if(i > 0){
            if(a[i] < a[i - 1]){
                flag = true;
            }
            if(a[i] > a[i - 1]){
                fre[i] = true;
            }
        }
    }
    for(int i = 0; i < N; i++){
        cin >> b[i];
        if(i > 0){
            if(b[i] > b[i - 1]){
                flag = true;
            }
            if(b[i] < b[i - 1]){
                fre2[i - 1] = true;
            }
        }
    }
    if(a[N - 1] != b[0]){
        flag = true;
    }
    for(int i = 0; i < N; i++){
        if(fre[i] && fre2[i]){
            if(a[i] != b[i]){
                flag = true;
            }
        }
        else if(fre[i]){
            if(a[i] > b[i]){
                flag = true;
            }
        }
        else if(fre2[i]){
            if(a[i] < b[i]){
                flag = true;
            }
        }
    }
    if(flag){
        printf("0\n");
        return 0;
    }
    int ans = 1;
    for(int i = 0; i < N; i++){
        if(fre[i] || fre2[i])continue;
        ans = ans * min(a[i], b[i]) % mod;
    }
    cout << ans << endl;


    return 0;
}
/*



*/


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

using namespace std;
int n,a,b,ans; 
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a>>b;
		for(int j=a;j<=b;j++)
		ans++;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a,b,c;
		a = sc.nextInt();
		b = sc.nextInt();
		c = sc.nextInt();

	if(a==b&&b==c){
		System.out.println("Yes");
	}else{
		System.out.println("No");
	}
	}}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<long long> fib(n + 1, 1);
  for (int i = 2; i <= n; i++){
    fib[i] = fib[i - 1] + fib[i - 2];
  }
  cout << fib[n] << endl;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define fir first
#define sec second
#define rep(i,a,b) for (int i = (a); i <= (b); ++ i)
#define rrp(i,a,b) for (int i = (a); i >= (b); -- i)
#define gc() getchar()
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc(); !isdigit(tmp); tmp = gc())
    key = (tmp == '-');
  for (; isdigit(tmp); tmp = gc())
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

const int N = 200000, MP = 30;
int pw2[MP + 1], A = 0, B = 1, cnt = 2, c3, tpw2[MP + 1];
int val[2][MP + 1];
int mul01(int a,int b) {
  int ta = ++ cnt, tb = ++ cnt, ret = ++ cnt, tmp = ++ cnt;
  // a + b + (a <= b) + (b <= a)
  // (0,0): 2, (0, 1):2, (1,1): 4
  printf("+ %d %d %d\n", a, pw2[0], ta);
  printf("+ %d %d %d\n", b, pw2[0], tb);
  printf("+ %d %d %d\n", a, b, ret);
  printf("< %d %d %d\n", a, tb, tmp);
  printf("+ %d %d %d\n", ret, tmp, ret);
  printf("< %d %d %d\n", b, ta, tmp);
  printf("+ %d %d %d\n", ret, tmp, ret);
  printf("< %d %d %d\n", c3, ret, ret);
  return ret;
}
int mul2k(int a,int k) {
  int ret = ++ cnt;
  printf("+ %d %d %d\n", a, ret, ret);
  rep (i, 1, k) printf("+ %d %d %d\n", ret, ret, ret);
  return ret;
}
int main() {
  cout << 40523 << endl;
  rep (i, 0, MP) pw2[i] = ++ cnt;
  {
    int tmp = ++ cnt;
    printf("< 2 %d %d\n", A, pw2[0]);
    printf("< 2 %d %d\n", B, tmp);
    printf("+ %d %d %d\n", pw2[0], tmp, pw2[0]);
    printf("< 2 %d %d\n", pw2[0], pw2[0]);
  }
  rep (i, 1, MP) {
    printf("+ %d %d %d\n", pw2[i-1], pw2[i-1], pw2[i]);
  }
  // rep (i, 0, MP) cerr << pw2[i] << ' ';
  // cerr << endl;
  c3 = ++ cnt;
  printf("+ %d %d %d\n", pw2[0], pw2[1], c3);
  // let A = A + 1, B = B + 1
  printf("+ %d %d %d\n", A, pw2[0], A);
  printf("+ %d %d %d\n", B, pw2[0], B);
  // get binary form of A, B
  rep (i, 0, MP) tpw2[i] = ++ cnt;
  rep (p, 0, 1) {
    rep (i, 0, MP) printf("+ %d %d %d\n", 2, pw2[i], tpw2[i]);
    rrp (i, MP, 0) {
      val[p][i] = ++ cnt;
      printf("< %d %d %d\n", tpw2[i], p, val[p][i]);
      int tmp = mul2k(val[p][i], i);
      rep (j, 0, i-1) printf("+ %d %d %d\n", tpw2[j], tmp, tpw2[j]);
    }
  }
  // rrp (i, MP, 0) cerr << val[0][i] << ' ';
  // cerr << endl;
  // multiplication
  rep (a, 0, 30) rep (b, 0, 30) {
    int c = mul01(val[0][a], val[1][b]);
    int tc = mul2k(c, a + b);
    printf("+ %d %d %d\n", 2, tc, 2);
  }
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define foi(i,k,n) for(int i = (int)k; i < (int)n; ++i)
using namespace std;
typedef long long ll;
const int MAXN = 21;
const int MOD = 1000000000 + 7;
int N;
int memo[MAXN][1<<MAXN];
int can[MAXN];
vector<int> bit_on[1<<MAXN];

int dp(int u, int bm) {
    if(u == N) return 1;
    int& ans = memo[u][bm];
    if(ans == -1) {
        ans = 0;
        int cpbm = bm & can[u];
        for(const int& x : bit_on[cpbm]) {
            ans = (ans + dp(1 + u, bm & ~(1 << x)));
            if(ans >= MOD) ans -= MOD;
        }
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    cin >> N;
    foi(i,0,N) {
        int& bm = can[i] = 0;
        foi(j,0,N) {
            int x; cin >> x;
            if(x == 1) bm |= (1 << j);
        }
    }
    foi(i,1,1<<MAXN) {
        vector<int>& pos = bit_on[i];
        for(int x = i, b = 0; x; ++b, x >>= 1) {
            if(x & 1) {
                pos.emplace_back(b);
            }
        }
    }
    memset(memo, -1, sizeof memo);
    cout << dp(0, (1 << N) - 1) << '\n';
    return 0;
}


Measured memory_bytes: 373120
N = int(input())
A_in = list(map(int, input().split()))
A_sub = A_in
A_sub_sum = 0
j = 0

while True:
    for i in range(N):
        A_sub_sum += float(A_sub[i] % 2)
    if A_sub_sum == 0:
        for i in range(N):
            A_sub[i] /= 2
        j += 1
    else: break
print(j)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 

  int main(){
      lint n,k;
      cin>>n>>k;
      lint a[n];
      rep(i,n)cin>>a[i];
      int left=0; int right=1000000000;
      while(right-left>1){
          int mid=(left+right)/2;
          lint count=0;
          double eps=0.000001;
          rep(i,n){
              lint x=a[i]/(mid+eps);
              count+=x;
          }
          if(count<=k)right=mid;
          else left=mid;
      }
      cout<<right<<endl;
  }

Measured memory_bytes: 5092
//デコードの結果を出力。エンコードの結果ではない！
//AOJerの中で最も注意力がない。
#include<iostream>
#include<vector>
#include<set>
#include<string>
#include<stdio.h>
#include<string.h>
using namespace std;

string input;
int used[200];
set<string> output;

char encode(char c, int dep) {
	//すでに置き換えられていたら、何もしない。
	if( used[(int)c] < dep)
		return c;
	//置き換えられていない時のやつ
	if( c == 'a' )
		return c;
	return c - 1;
}

void dfs( string data, int dep, int mdep ) {
	if( dep == mdep ){
		output.insert(data);
	}
	//data[dep]を決める。encode(data[dep]) == input[dep]となるようにする。
	//iをエンコードしてcになるなら、cをデコードするとiが出る。
	for(char i = 'a'; i <= 'z'; i++) {
		char c = encode(i, dep);
		/*if( data == "jcd" && i == 'j' ) {
			cout << "debug" << " c = " << c  << " used[i] = " << used[i] << endl;
		}*/
		if( c == input[dep] ) {
			//cout << dep << " "  << i << " " << c << endl;
			int t = used[(int)i];
			used[(int)i] = min(used[(int)i], dep);	//最初に使った場所を覚えておく。(使ったかどうかだけだと、ibcjkの復号でjcdjlのようなものが出なくなる。理由はよく分からないけど…)
			dfs(data + i, dep+1, mdep);
			used[(int)i] = t;
		}
	}
}

int main(){
	int i, j;
	while( cin >> input ){
		if(input[0] == '#') break;
		for(int i = 0; i < 200; i++ )
			used[i] = 514;
		//元の文字列を列挙
		string s;
		dfs(s, 0, (int)input.length() );
		//出力
		cout << output.size() << endl;
		if(output.size() <= 10) {
			for( set<string>::iterator it = output.begin(); it != output.end(); it++ ) {
				cout << *it << endl;
			}
		} else {
			int cnt, mcnt = 5;
			//前の5要素を昇順に出力(begin()は先頭、end()は最後+1 )
			cnt = 0;
			for( set<string>::iterator it = output.begin(); cnt < mcnt; it++ ) {
				cout << *it << endl;
				cnt++;
			}
			
			//後の5要素を昇順に出力(rbegin()は最後、rend()は先頭-1 )
			cnt = 0;
			set<string> revset;
			for( set<string>::reverse_iterator rit = output.rbegin(); cnt < mcnt; rit++ ) {
				revset.insert(*rit);
				cnt++;
			}
			for( set<string>::iterator it = revset.begin(); it != revset.end(); it++ ) {
				cout << *it << endl;
				cnt++;
			}
		}
		//あとしまつ
		output.clear();
	}
	return 0;
}

Measured memory_bytes: 3164
use whiteread::parse_line;

fn main() {
    let n: usize = parse_line().unwrap();
    let a1: Vec<u32> = parse_line().unwrap();
    let a2: Vec<u32> = parse_line().unwrap();
    let mut ans = 0;

    for i in 0..n {
        let cnt1: u32 = a1[0..=i].iter().sum();
        let cnt2: u32 = a2[i..n].iter().sum();
        ans = ans.max(cnt1 + cnt2);
    }
    println!("{}", ans);
}


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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

struct Node {
    Node *parent;
    Node *left;
    Node *right;
    int key;

    Node() : parent(nullptr), left(nullptr), right(nullptr), key(2000000001) {}
    Node(Node* p, Node* l, Node* r, int k) : parent(p), left(l), right(r), key(k) {}

    void insert(int k) {
        if (key == 2000000001) { key = k; }
        else if (k <= key) {
            if (left != nullptr) { left->insert(k); }
            else { left = new Node(this, nullptr, nullptr, k); }
        } else {
            if (right != nullptr) { right->insert(k); }
            else { right = new Node(this, nullptr, nullptr, k); }
        }
    }
};

void in_print(Node* node) {
    if (node->left != nullptr) { in_print(node->left); }
    cout << " " << node->key;
    if (node->right != nullptr) { in_print(node->right); }
}

void pre_print(Node* node) {
    cout << " " << node->key;
    if (node->left != nullptr) { pre_print(node->left); }
    if (node->right != nullptr) { pre_print(node->right); }
}

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

    Node* tree = new Node();

    rep(i, 0, n) {
        char s[20];
        scanf("%s", s);

        if (s[0] == 'i') {
            int x;
            cin >> x;
            tree->insert(x);
        } else {
            in_print(tree);
            cout << endl;
            pre_print(tree);
            cout << endl;
        }
    }
}


Measured memory_bytes: 26596
#include <limits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdint>

using namespace std;

int digit_sum_max(const string& number)
{
    if(number.size() == 1)
        return number[0] - '0';
    
    if(number[1] == '9')
        return (number[0] - '0') + digit_sum_max(number.substr(1));

    return (number[0] - '0' - 1) + 9 * (number.size() - 1);
}

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

    cout << digit_sum_max(n) << '\n';
    return 0;
}


Measured memory_bytes: 256
fun main(args:Array<String>):Unit {
    repeat(readLine()!!.trim().toInt()){
        val str = readLine()!!.trim().split(' ')
        val (shift, kasuu) = str.first().shiftWhileZero()
        if (str.size == 2){
            println("$kasuu * 10^${-shift} ${str.last()}")
        }else{
            val e = prefixToExpoent(str[1])
            println("${kasuu} * 10^${e-shift} ${str.last()}")
        }
    }
}
fun String.shiftWhileZero():Pair<Int, String> {
    val shift = this.indexOf('.')
    return when(shift){
        -1 -> Pair(-this.length + 1, this[0] + "." + this.substring(1))
        else -> {
            val removed = this.filterNot{it == '.'}.dropWhile { it == '0' }
            val fromRight = this.length - shift
            if (removed.length != 1) Pair(fromRight - removed.length, removed[0] + "." + removed.substring(1))
            else Pair(fromRight - removed.length, removed)
        }
    }

}
fun prefixToExpoent(prefix:String):Int {
    val map = mapOf(
            Pair("yotta", 24),
            Pair("zetta", 21),
            Pair("exa", 18),
            Pair("peta", 15),
            Pair("tera", 12),
            Pair("giga", 9),
            Pair("mega", 6),
            Pair("kilo", 3),
            Pair("hecto", 2),
            Pair("deca", 1),
            Pair("deci", -1),
            Pair("centi", -2),
            Pair("milli", -3),
            Pair("micro", -6),
            Pair("nano", -9),
            Pair("pico", -12),
            Pair("femto", -15),
            Pair("ato", -18),
            Pair("zepto", -21),
            Pair("yocto", -24)
            )
    return map[prefix]!!
}


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

int main(){
  int N;
  cin >> N;
  int t=0;
  priority_queue<int,vector<int>,greater<int> > min;
  min.push(N);
  for(int i=0;i<=N;i++){
    int sum=0;
    int t=i;
    while(t>0){
      sum+=t%6;
      t/=6;
    }
    t=N-i;
    while(t>0){
      sum+=t%9;
      t/=9;
    }
    min.push(sum);
  }
  cout << min.top() << endl;
  return 0;
}


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

using namespace std;

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

int main(){
  int n;
  cin >> n;
  uint64_t r = 0;
  REP(i, n + 1){
    if(i % 3 != 0 && i % 5 != 0) r += i;
  }
  cout << r << endl;
  return 0;
}

Measured memory_bytes: 3620
from os.path import commonprefix as cp
import math
INF, MOD = float("inf"), 1e9 + 7
MAX, MIN = -INF, INF
dx1, dy1, dx2, dy2 = [-1, 0, 1, 0], [0, -1, 0, 1], [-1, 0, 1, -1, 1, -1, 0, 1], [-1, -1, -1, 0, 0, 1, 1, 1]

def get_int():
    return int(input())

def get_int_list():
    return list(map(int, input().split()))

while(True):
    try:
        prefixs = ["remaerd", "maerd", "resare", "esare"]
        s = input()[::-1]
        while(len(s)):
            flag = True
            for p in prefixs:
                if cp([s, p]) == p:
                    flag = False
                    s = s[len(p):]
                    break
            if flag:
                print("NO");
                exit()
        print("YES")
    except EOFError:
        exit()


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<double,double > mp;
double inf =  1e9;
#define EPS 1e-4

int main(){
	int n;
	cin>>n;
	vector<mp> a(n);
	double uy = inf,dy = 0;
	for(int i=0;i<n;i++){
		double x,r;
		cin>>x>>r;
		a[i] = mp(x,r);
		//lx = max(lx,x-r);
		//rx = min(rx,x+r);
		uy = min(uy,r);
	}
	while(uy-dy>EPS){
		double lx = 0;
		double rx = inf;
		double y = (uy + dy)/2;
		for(int i=0;i<n;i++){
		    double r = a[i].second;
		    double x = a[i].first;
		    lx = max(lx,x-sqrt(r*r-y*y) );
		    rx = min(rx,x+sqrt(r*r-y*y) );
		}
		if(lx > rx){
			uy = y;
		}else{
			dy = y;
		}

	}
//	cout<< (uy+dy)/2 << endl;
	printf("%0.10lf\n",(uy+dy)/2);
	return 0;
}



Measured memory_bytes: 4396
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = [int(input().rstrip('\n')) for _ in range(n)]
    b = sorted(a, reverse=True)
    for i in a:
        if i == b[0]:
            print(b[1])
        else:
            print(b[0])


if __name__ == '__main__':
    slove()


Measured memory_bytes: 59824
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <ctime>

using namespace std;
#define RN cout << "\r\n";
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef long long int ll;
typedef pair<ll, ll> P;

// combination
const int MAX = 510000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// gcd, lcm
ll gcd(ll a, ll b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

ll getScore(vector<bool> givingList) {
    ll ans = 0;
    for (bool b : givingList) {
        if (b) {
            ans++;
        }
    }
    return ans;
}

int main() {
    ll N, x;
    vector<ll> kids;
    cin >> N >> x;
    REP(i, N) {
        int a;
        cin >> a;
        kids.push_back(a);
    }
    sort(kids.begin(), kids.end());
    ll index = 0, ans = 0;
    while(x > 0 && index < N) {
        x -= kids[index];
        index++;
        ans++;
    }
    if (x == 0) {
        cout << ans;
        return 0;
    } else {
        cout << ans - 1;
        return 0;
    }
}


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

using namespace std;

int main() {
  string s;
  cin >> s;
  int count = 0;
  for (int i = s.size() - 1; i >= 0; i--) {
    const char c = s[i];
    count += c - '0';
  }
  cout << (count % 9 == 0 ? "Yes" : "No");
}


Measured memory_bytes: 3684
#include<iostream>
#include<set>
#include<string>
#include<string.h>
using namespace std;
int n;
typedef set<string>set_t;
set_t A;
string s,str,yes_no;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        if(strcmp(s.c_str(),"insert")==0)
        {
            cin>>str;
            A.insert(str);
        }
        if(strcmp(s.c_str(),"find")==0)
        {
            cin>>str;
            if(A.count(str)==0)
                yes_no="no";
            if(A.count(str)==1)
                yes_no="yes";
            cout<<yes_no<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 32652
def a(n,x):
    if n<0:
        return n+1
    elif n >= x:
        return n-1
    else:
        return n
def f():
    h,w = map(int,input().split())
    s = []
    for i in range(h):
        s.append(list(input()))
    for i in range(h):
        for j in range(w):
            if s[i][j]=='#':
                if s[a(i-1,h)][j]=='.' and s[a(i+1,h)][j]=='.' and s[i][a(j-1,w)]=='.' and s[i][a(j+1,w)]=='.':
                    return 'No'
    return 'Yes'

print(f())


Measured memory_bytes: 3064
#include <cstdio>
#include <vector>
#include <set>
#include <map>

using namespace std;

long long a[100000];
int b[100001];

int main() {
    int n, ans = 0, sum = 0;
    long long i, j;
    vector <long long> v;
    map <long long, long long> p;
    map <long long, long long> pair;
    map <long long, int> mp;
    map <long long, int>::iterator it;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) scanf("%lld", &a[i]);
    
    for (i = 2; i <= 100000; i++) {
        if (b[i] > 0) continue;
        
        v.push_back(i);
        p[i * i] = i;
        
        for (j = i * i; j <= 100000; j += i) b[j] = 1;
    }
    
    for (i = 0; i < n; i++) {
        long long x = 1, y = 1;
        
        for (j = 0; v[j] < 2500 && a[i] > 1; j++) {
            if (a[i] % v[j] == 0) {
                int c = 0;
                
                while (a[i] % v[j] == 0) {
                    c++;
                    a[i] /= v[j];
                }
                
                c %= 3;
                
                if (c == 1) {
                    x *= v[j];
                    y *= v[j] * v[j];
                } else if (c == 2) {
                    x *= v[j] * v[j];
                    y *= v[j];
                }
            }
        }
        
        if (a[i] > 1) {
            if (p.count(a[i])) {
                x *= a[i];
                y *= p[a[i]];
            } else {
                x *= a[i];
                y *= a[i] * a[i];
            }
        }
        
        mp[x]++;
        pair[x] = y;
    }
    
    for (it = mp.begin(); it != mp.end(); it++) {
        if (it->first == 1) {
            ans++;
        } else {
            if (mp.count(pair[it->first])) {
                sum += max(it->second, mp[pair[it->first]]);
            } else {
                ans += it->second;
            }
        }
    }
    
    printf("%d\n", ans + sum / 2);
    
    return 0;
}


Measured memory_bytes: 14592
#include <bits/stdc++.h>
#define ll long long
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
using namespace std;
unordered_set<ll>s;
ll n;
void solve(){
    for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            ll temp=n;
            ll nxt=i;
            while(temp%nxt==0){
                s.insert(nxt);
                temp=temp/nxt;
                nxt=nxt*i;
            }
            while(temp%i==0)temp=temp/i;
        n=temp;  
        }
    }
    if(n>=2)s.insert(n);
    return ;
}

int main() {
   fast
   cin>>n;
   solve();
 cout<<s.size();
   return 0;
}
 
 


Measured memory_bytes: 3660
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int a, b, c;
  cin >> a >> b >> c;
  if (a==b+c || b==c+a || c==a+b) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

int main() {

  int N;
  cin >> N;
  
  if(N%10==7 || (N/10)%10==7 || N/100==7){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}



Measured memory_bytes: 3560
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
using namespace std;

struct aa{
	int x;
	int y;
	int t;
	aa(int a,int b,int c){
		x=a;
		y=b;
		t=c;
	}
};

int inks[3][5][5]={
	{
		{0,0,0,0,0},
		{0,0,1,0,0},
		{0,1,1,1,0},
		{0,0,1,0,0},
		{0,0,0,0,0},
	},
	{
		{0,0,0,0,0},
		{0,1,1,1,0},
		{0,1,1,1,0},
		{0,1,1,1,0},
		{0,0,0,0,0},
	},
	{
		{0,0,1,0,0},
		{0,1,1,1,0},
		{1,1,1,1,1},
		{0,1,1,1,0},
		{0,0,1,0,0},
	},
};

bool ok(const vector<vector<int>>&v,int ink_x,int ink_y,int ink_id){
	for(int dy=0;dy<5;++dy){
		for(int dx=0;dx<5;++dx){
			if(inks[ink_id][dy][dx]){
				int ax=ink_x-2+dx;
				int ay=ink_y-2+dy;

				if(ax<0||ax>=10||ay<0||ay>=10)return false;
				if(v[ay][ax]<=0)return false;
			}
		}
	}
	return true;
}

vector<aa>solve(int now_x,int now_y,int rest,vector<vector<int>>&v){
	if(rest==0){
		bool ok=true;
		for(int i=0;i<10;++i){
			for(int j=0;j<10;++j){
				if(v[i][j])ok=false;
			}
		}
		aa k=aa(-1,-1,-1);
		if(ok)return vector<aa>();
		else return vector<aa>(1,aa(-1,-1,-1));
	}
	if(now_y==10){
		return vector<aa>(1,aa(-1,-1,-1));
	}
	if(now_y>=3&&now_x==0){
		for(int y=0;y<now_y-2;++y){
			for(int x=0;x<10;++x){
				if(v[y][x])return vector<aa>(1,aa(-1,-1,-1));
			}
		}
	}
	
	for(int ink_id=0;ink_id<=2;++ink_id){
		if(ok(v,now_x,now_y,ink_id)){
			for(int dy=0;dy<5;++dy){
				for(int dx=0;dx<5;++dx){
					if(inks[ink_id][dy][dx]){
						int ax=now_x-2+dx;
						int ay=now_y-2+dy;

						if(ax<0||ax>=10||ay<0||ay>=10)assert(false);
						if(v[ay][ax]<=0)assert(false);

						v[ay][ax]--;
					}
				}
			}
			vector<aa>aas=solve(now_x,now_y,rest-1,v);
			for(int dy=0;dy<5;++dy){
				for(int dx=0;dx<5;++dx){
					if(inks[ink_id][dy][dx]){
						int ax=now_x-2+dx;
						int ay=now_y-2+dy;
						v[ay][ax]++;
					}
				}
			}
			if(aas.size()==1&&aas[0].x==-1)continue;
			else{
				aas.push_back(aa(now_x,now_y,ink_id));
				return aas;
			}
		}
	}
	int next_x=now_x+1;
	int next_y=now_y;
	if(next_x==10){
		next_x=0;
		next_y=next_y+1;
	}
	return solve(next_x,next_y,rest,v);
}

int main() { 
	int N;cin>>N;
	vector<vector<int>>v(10,vector<int>(10));
	for(int i=0;i<10;++i){
		for(int j=0;j<10;++j){
			cin>>v[i][j];
		}
	}
	auto p=solve(0,0,N,v);
	for(int i=0;i<p.size();++i){
		cout<<p[i].x<<" "<<p[i].y<<" "<<p[i].t+1<<endl;
	}
	//cout<<"0"<<endl;
	return 0;
}


Measured memory_bytes: 3148
import java.util.Scanner;
import java.util.Arrays;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b[] = new int[a+1];
    int c[] = new int[a+1];
    for(int i = 1;i < b.length;i++){
      b[i] = sc.nextInt();
    }
    for(int j = 1;j < b.length;j++){
      c[b[j]] = j;
    }
    for(int x = 1;x < b.length;x++){
      System.out.print(c[x]+ " ");
    }
  }
}

Measured memory_bytes: 65552
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
    char n[4];
    cin >> n;
    int ans = 0;
    for(int i = 0;i<4; i++)
    {
        //cout << n[i] << endl;
        if(n[i] == '2'){
            ans++;
        } 
    }

    //cout << ans << endl;
    printf("%d", ans);

    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long int;
#define show(s)     cout<<s<<endl

int main() {

    int N,M,C;

    cin >> N >> M >> C;
    vector<int> B(M);
    rep(i,M)    cin >> B[i];

    int ans = 0;
    rep(i,N){
        int s = 0;
        int A;
        rep(j,M){
            cin >> A;
            s += B[j]*A;
        }
        s += C;
        if(s > 0)   ans++;
    }
    show(ans);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  vector<int> sticks(N);
  for (int n = 0; n < N; n++) {
    cin >> sticks.at(n);
  }
  
  int count = 0;
  for (int n = 0; n < N - 2; n++) {
    int a = sticks.at(n);
    for (int i = n + 1; i < N - 1; i++) {
      int b = sticks.at(i);
      for (int j = i + 1; j < N; j++) {
        int c = sticks.at(j);
        if (a != b && b != c && c != a) {
          vector<int> abc = {a, b, c};
          int maxnum = max(a, max(b, c));
          int two = 0;
          for (int k = 0; k < 3; k++) {
            if (abc.at(k) != maxnum) {
              two += abc.at(k);
            }
          }
          
          if (two > maxnum) {
            count++;
          }
        }
      }
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 3596
//#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};
vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  string s;cin>>s;
  vector<ll>w(n+1),r(n+1);
  rep(i,0,n){
    if(s[i]=='R')r[i]++;
    else w[i+1]++;
  }
  rrep(i,0,n)r[i]+=r[i+1];
  rep(i,0,n)w[i+1]+=w[i];
  res=INF;
  rep(i,0,n+1){
    chmin(res,max(w[i],r[i]));
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 6788
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;

using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a < c&&c < b || b < c&&c < a) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 384
n = int(input())
a = [int(_) for _ in input().split()]

def add_dict(dict, n):
    if n in dict.keys():
        dict[n] += 1
    else:
        dict[n] = 1
    return dict

dict = {}
for ai in a:
    dict = add_dict(dict, ai)
    dict = add_dict(dict, ai+1)
    dict = add_dict(dict, ai-1)

print(max(dict.values()))

Measured memory_bytes: 19784
// 若 x 为有用的，则比 x 大的都是有用的。可简单证明，想想就懂！
#include <bits/stdc++.h>
#define rep(i, x, y) for (long long i = x; i <= y; i++)
using namespace std;

const int N = 5e3 + 10;
int n, K, a[N], rest, f[N];

int main() {
    cin >> n >> K;
    rep(i, 1, n) {
        cin >> a[i];
        a[i] = min(a[i], K), rest += a[i];
    }
    sort(a + 1, a + n + 1);
    // if (a[1] == K) { puts("0"); return 0; }
    f[0] = 1;
    for (int i = n; i >= 1; i--) {
        bool ff = 0;
        for (int j = K - 1; j >= max(K - rest, 0); j--)
            if (f[j]) { ff = 1; break; }
        if (!ff) { printf("%d\n", i); return 0; }
        for (int j = K; j >= a[i]; j--) f[j] |= f[j - a[i]];
        rest -= a[i];
    }
    puts("0");
    return 0;
}


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

int main(){
  long long int n;
  cin >> n;
  long long int j,k,m = 100000;
  for(int i = 1; i <= sqrt(n); i++){
    if(n%i==0){
      k = n/i;
      for(j = 1; k>=10 ;j++){
        k = k/10;
      }
      if(m>j){
        m = j;
      }
    }
  }
  cout << m << endl;
}

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


int main()
{
	string str, task, p, strrev;
	int q, a, b;

	cin >> str;
	cin >> q;

	for (int i = 0; i < q; i++){
		cin >> task >> a >> b;
		if (task == "print"){
			cout << str.substr(a, b - a + 1) << endl;
		}
		else if (task == "reverse"){
			string strin;
			strrev = str.substr(a, b - a + 1);
			for (int i = strrev.size() - 1; i >= 0; i--){
				strin = strin + strrev[i];
			}
			str = str.replace(a, b - a + 1, strin);
		}
		else if (task == "replace"){
			cin >> p;
			str = str.replace(a, b-a+1, p);
		}
	}
	
	return 0;
}


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

int main(){
  int n,m;
  cin >> n >> m;
  int a,b;
  bool judge = false;
  vector<int> ans(n,0);
  vector<bool> alr(n,false);
  bool huka = false;
  
  for(int i=0;i<m;i++){
    cin >> a >> b;
    //初めてなら入れる
    if(alr[a-1]==false){
      alr[a-1] = true;
      ans[a-1] = b;     
    }
    //既出かつ異なるなら不可
    if(alr[a-1]&&ans[a-1]!=b){
      judge = true;
    }
    //一番左の数字が０は不可
    if(a==1&&b==0&&n!=1) huka = true;
  }
  if(ans[0]==0&&n!=1) ans[0] = 1;
  if(huka||judge) cout << -1 << endl;
  else {
    for(int i=0;i<n;i++){
      cout << ans[i];
    }
  }
}
    



Measured memory_bytes: 3596
N,K =map(int,input().split())
A=list(map(int,input().split()))

n=[1]
t=1
#通った場所は0,まだ通ってない場所は-1
ord=[-1]*(N+1)
ord[0]=0

while True:
    t=A[t-1]
    if ord[t] == 0:
        f=n.index(t)
        break
    n.append(t)
    ord[t]=0

k=len(n)-f

if K>=f:
    print(n[f+(K-f)%k])

else:
    print(n[K])
  

Measured memory_bytes: 32376
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= int(b); i++)
#define per(i, a, b) for (int i = (a); i >= int(b); i--)
#define fir first
#define sec second
#define tct template<class type>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const int maxn = 1 << 15, mod = 1e9 + 7;
int n, m, a[20], f[maxn + 5];

inline void red(int &x) { x += x >> 31 & mod; }
tct inline void cmax(type &x, type y) { x < y ? x = y : 0; }
tct inline void cmin(type &x, type y) { x > y ? x = y : 0; }

int main() {
	scanf("%d %d", &n, &m);
	int sum = 1;
	rep(i, 1, m) sum = ll(2) * sum % mod;
	for (int i = 0, x, y; i < m; i++) {
		scanf("%d %d", &x, &y);
		a[x] |= 1 << (y - 1);
	}
	f[0] = 1;
	rep(msk, 1, (1 << n) - 1) {
		for (int old = msk; old; old = (old - 1) & msk) {
			if ((old & 1) ^ (old >> 1 & 1)) continue;
			int pi = 1;
			rep(j, 1, n) {
				if ((msk ^ old) >> (j - 1) & 1) pi = ll((1 << __builtin_popcount(a[j] & old)) - 1) * pi % mod;
				else if (old >> (j - 1) & 1) pi = ll((1 << __builtin_popcount(a[j] & (msk ^ old)))) * pi % mod;
			}
			f[msk] = (f[msk] + ll(pi) * f[msk ^ old]) % mod;
		}
	}
	red(sum -= f[(1 << n) - 1]);
	printf("%d\n", sum);
	return 0;
}

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

#define ll long long
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define x first
#define y second
const int MAXM=2e5+1;

int n,m;
int a[MAXM],b[MAXM];
vector<int> ans;
vector<int> edges[MAXM];

void bfs(){
	queue<int> q;
	for (int i=0; i<n; i++)
		ans.pb(-1);
	q.push(0);
	while (!q.empty()){
		int X=q.front();
		q.pop();
		for (int i=0; i<edges[X].size(); i++)
			if (ans[edges[X][i]]==-1){
				ans[edges[X][i]]=X+1;
				q.push(edges[X][i]);
			}
	}
}

int main(){
	ios::sync_with_stdio(false);
   	cin.tie(0);
   	
	cin>>n>>m;
	for (int i=0; i<m; i++){
		cin>>a[i]>>b[i];
		edges[a[i]-1].pb(b[i]-1);
		edges[b[i]-1].pb(a[i]-1);
	}
	bfs();
	for (int i=1; i<n; i++)
		if (ans[i]==-1){
			cout<<"No"<<endl;
			return 0;
		}
	cout<<"Yes"<<endl;
	for (int i=1; i<n; i++)
		cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 14072
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

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

	int a;
  cin>>a;
  cout<<shosu(9)<<((double)a-a/2)/a<<endl;
}


Measured memory_bytes: 256
#!/usr/bin/python
# -*- coding: utf-8 -*-

A,B,M = map(int,input().split())

a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
xyc = []
for _ in range(0,M):
    xyc.append([int(x) for x in input().split()])

ans = 0

ans = min(a) + min(b)

coupon = []

for i in range(0,M):
    coupon.append(a[xyc[i][0]-1] + b[xyc[i][1]-1] - xyc[i][2])

ans = min(ans,min(coupon))

print(ans)

Measured memory_bytes: 86232
list = [[[0 for room in range(10)] for floor in range(3)] for building in range(4)]

n = int(input())
for _ in range(n):
    b, f, r, v = map(int, input().split())
    list[b-1][f-1][r-1] += v

temp = 0
for building in list:
    if not temp == 0:
        print('#'*20)
    temp += 1
    for floor in building:
        for room in floor:
            print(f' {room}', end='')
        print()


Measured memory_bytes: 5632
#include <algorithm>
#include <cmath>
#include <iostream>

using namespace std;

using ll = long long;
using ld = long double;

ll sx, sy, tx, ty;

int main() {
  cin >> sx >> sy >> tx >> ty;
  for (int i = 0; i < (tx - sx); i++) {
    cout << "R";
  }
  for (int i = 0; i < (ty - sy); i++) {
    cout << "U";
  }
  for (int i = 0; i < (tx - sx); i++) {
    cout << "L";
  }
  for (int i = 0; i < (ty - sy); i++) {
    cout << "D";
  }
  cout << "D";
  for (int i = 0; i < (tx - sx) + 1; i++) {
    cout << "R";
  }
  for (int i = 0; i < (ty - sy) + 1; i++) {
    cout << "U";
  }
  cout << "L";
  cout << "U";
  for (int i = 0; i < (tx - sx) + 1; i++) {
    cout << "L";
  }
  for (int i = 0; i < (ty - sy) + 1; i++) {
    cout << "D";
  }
  cout << "R" << endl;
}

Measured memory_bytes: 256
# coding: cp932
MOD = 1000000007

def prepare(n)
  # n! の計算
  f = 1
  for m in 1..n
    f = mul(f, m)
  end

  fn = f
     
  # n!^-1 の計算
  inv = power(f, MOD - 2)

  # n!^-1 - 1!^-1 の計算
  invs = [1] * (n + 1)
  invs[n] = inv
  n.downto(1) do |m|
    inv = mul(inv, m)
    invs[m - 1] = inv
  end
     
  return [fn, invs]
end

def nCr(n,r)
  fn, invs = prepare(n)

  ans = fn
  #for i in (n-r+1)..n
  #  ans = mul(ans, i)
  #end

  ans = mul(ans, invs[r])
  ans = mul(ans, invs[n-r])
  #for i in 1..r
  #  ans = div(ans, i)
  #end

  return ans
end

def mul(a, b)
    return ((a % MOD) * (b % MOD)) % MOD
end

def power(x, y)
  if y == 0
  	1
  elsif y == 1
    x % MOD
  elsif y % 2 == 0
    power(x, y/2)**2 % MOD
  else
    power(x, y/2)**2 * x % MOD
  end
end

def div(a, b)
  mul(a, power(b, MOD-2))
end

def add(a, b)
  (a + b) % MOD
end

def manhattan(n1, m1, n2, m2)
  add((n1-n2).abs, (m1-m2).abs)
end

# puts nCr(100, 7)

N, M, K = readline.split(' ').map(&:to_i)

NM = N*M

if N>M
  N, M = M, N
end

# sum_(i,j) combination(n-2, k-2) * manhattan(i,j)
weight = nCr(NM-2, K-2)

sum = 0
for n in 0...N
  rowsum = mul(
    div(
      add(div(mul(M-1, M),2),
          div(mul(mul(M-1, M), 2*M-1), 6)),
      2),
    N)

  lhssum = div(mul(n, n+1), 2)
  rhssum = div(mul(N-n-1, N-n), 2)

  lrsum = mul(add(lhssum, rhssum), div(mul(M-1, M), 2))

  sum = add(sum, mul(rhssum, M))
  sum = add(sum, lrsum)
  sum = add(sum, rowsum)

  # $stderr.printf("sum=%d, lhssum=%d, rhssum=%d, rowsum=%d\n", sum, lhssum, rhssum, rowsum)
end


# for m in 0...M
#   for n in 0...N
#     rhssum = div(mul(N-n-1, N-n), 2)
#     lhssum = div(mul(n, n+1), 2)
#     rowsum = mul(div(mul(M-m-1, M-m), 2), N)
#     # $stderr.printf("m=%d, n=%d, rhssum=%d, lhssum=%d, rowsum=%d\n", m, n, rhssum, lhssum, rowsum)

#     sum = add(sum, rowsum)
#     sum = add(sum, mul(rhssum, M-m))
#     sum = add(sum, mul(lhssum, M-m-1))
#   end
# end

# for i in 0...NM
#   ni = i % M
#   mi = i / M
#   for j in i...NM
#     nj = j % M
#     mj = j / M
#     sum = add(sum, manhattan(ni, mi, nj, mj))
#   end
# end

puts mul(sum, weight)


Measured memory_bytes: 3324