akhauriyash/Code-Regression huggingface dataset:
fn main() {
  let (n, x): (u64, u64) = get::tuple();

  let ans = 3 * (n - gcd(n,x));
  println!("{}", ans)
}

fn gcd(x: u64, y: u64) -> u64 {
  let mut a = x;
  let mut b = y;
  let mut c;
  while a != 0 && b != 0 {
    c = b;
    b = a % b;
    a = c;
  }
  std::cmp::max(a, b)
}

#[allow(dead_code)]
mod get {
  use std::io::*;
  use std::str::*;

  pub fn val<T: FromStr>() -> T {
    let mut buf = String::new();
    stdin().read_line(&mut buf).ok();
    buf.trim().parse::<T>().ok().unwrap()
  }

  pub fn vals<T: FromStr>(n: usize) -> Vec<T> {
    let mut vec: Vec<T> = vec![];
    for _ in 0 .. n {
      vec.push(val());
    }
    vec
  }

  pub fn tuple<T1: FromStr, T2: FromStr>() -> (T1, T2) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).ok();
    let mut it = buf.trim().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    (x, y)
  }

  pub fn tuples<T1: FromStr, T2: FromStr>(n: usize) -> Vec<(T1, T2)> {
    let mut vec: Vec<(T1, T2)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple());
    }
    vec
  }

  pub fn tuple3<T1: FromStr, T2: FromStr, T3: FromStr>() -> (T1, T2, T3) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).ok();
    let mut it = buf.trim().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    let z = it.next().unwrap().parse::<T3>().ok().unwrap();
    (x, y, z)
  }

  pub fn tuple3s<T1: FromStr, T2: FromStr, T3: FromStr>(n: usize) -> Vec<(T1, T2, T3)> {
    let mut vec: Vec<(T1, T2, T3)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple3());
    }
    vec
  }

  pub fn list<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).ok();
    buf.trim().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect()
  }

  pub fn lists<T: FromStr>(h: usize) -> Vec<Vec<T>> {
    let mut mat: Vec<Vec<T>> = vec![];
    for _ in 0 .. h {
      mat.push(list());
    }
    mat
  }
}


Measured memory_bytes: 4352
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, m; cin >> n >> m;
  vector<vector<int> > a(m);
  while (n--) {
    int ai, b; cin >> ai >> b;
    if (m - ai >= 0) a[m - ai].emplace_back(b);
  }
  long long ans = 0;
  priority_queue<int> que;
  for (int i = m - 1; i >= 0; --i) {
    for (int e : a[i]) que.emplace(e);
    if (!que.empty()) {
      ans += que.top();
      que.pop();
    }
  }
  cout << ans << '\n';
  return 0;
}


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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int    n;
string s;
int    x[27], y[27], ans;

inline int cnt() {
    int num = 0;
    for (int i = 0; i < 27; i++) {
        if (x[i] > 0 && y[i] > 0) num++;
    }
    return num;
}

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    cin >> n >> s;

    // 処理
    // 全体のカウント
    rep(i, n) { x[s[i] - 'a']++; }

    rep(i, n) {
        // Xは右側
        // 全体のカウントからi番目まで存在する文字の数を引く
        x[s[i] - 'a']--;

        // Yは左側
        // Yはiまで存在する文字の数を増やしていく
        y[s[i] - 'a']++;

        // cnt関数に渡して最大値を比較取得する。
        ans = max(ans, cnt());
    }

    // 出力
    cout << ans << endl;

    return 0;
}


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

class MultipleArray
{
public:
	long long n;
	vector<long long> a;
	vector<long long> b;
	MultipleArray();
	~MultipleArray();
	void exec();
};

MultipleArray::MultipleArray(){
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		long long tmpA, tmpB;
		cin >> tmpA >> tmpB;
		a.push_back(tmpA);
		b.push_back(tmpB);
	}
}

MultipleArray::~MultipleArray(){}

void MultipleArray::exec(){
	long long sum = 0;
	for (int i = n-1; i >= 0 ; --i)
	{
		int tmp = (a[i] + sum) % b[i];
		if(tmp == 0) continue;
		sum += b[i]  - tmp;
	}
	cout << sum << endl;
}

int main(){
	MultipleArray solution = MultipleArray();
	solution.exec();
}


Measured memory_bytes: 2036
#https://atcoder.jp/contests/abc098/tasks/arc098_a
n=int(input())
s=input()

"""ans=100000000000
for i in range(n):
    count=0
    for j in range(n):
        if i==j:
            continue

        if (i<j)&(s[j]=="E"):
            count+=1
        elif (j<i)&(s[j]=="W"):
            count+=1

    ans=min(ans,count)

print(ans)"""#O(N^2)

count_W=[]
for i in range(n):
    count_W.append(0)

if s[0]=="W":
    count_W[0]=1
else:
    count_W[0]=0

for i in range(1,n):
    if s[i]=="W":
        count_W[i]=count_W[i-1]+1
    else:
        count_W[i]=count_W[i-1]

for i in range(n):
    if i==0:
        ans=(n-1)-(count_W[n-1]-count_W[0])
    else:
        ans=min(ans,count_W[i-1]+(n-1-i)-(count_W[n-1]-count_W[i]))

print(ans)

Measured memory_bytes: 62428
using System;
class rivange
{
    static void Main()
    {   
        int a = int.Parse(Console.ReadLine()), b = int.Parse(Console.ReadLine());
        int[] c = new int[a];
        for(int i = 0; i < a; i++)
        {
            c[i] = i+1;
        }
        int[,] d = new int[b,2];
        for(int i = 0; i < b; i++)
        {
            string []e = Console.ReadLine().Split(',');
            d[i, 0] = int.Parse(e[0])-1;
            d[i, 1] = int.Parse(e[1])-1;
        }
        for(int i = 0; i < b; i++)
        {
            int e = c[d[i, 0]];
            c[d[i, 0]] = c[d[i, 1]];
            c[d[i, 1]] = e;
        }
        for (int i = 0; i < a; i++)
        {
            Console.WriteLine(c[i]);
        }
    }
}

Measured memory_bytes: 8912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans=0;
const ll INF = 1LL << 60;
int main()
{
ll n , x , d ;
cin >> n >> x >> d ;
if(d==0){
cout << ((x==0)?1:n+1) << endl;
return 0;
}
if(d<0){d*=-1;x*=-1;}
map<ll,vector<pair<ll,ll>>> m;
auto mod = [&](ll modx) {modx%=d;modx+=d;modx%=d;return modx; };
rep(i,n+1){
  ll aa=(i*(i-1)/2)*d+i*x;
  ll bb=((n-1+n-i)*i/2)*d+i*x;
  m[mod(i*x)].emplace_back(min(aa,bb),max(aa,bb));
}
for(auto r:m){
  auto &rc=r.second;
  sort(rc.begin(),rc.end());
  ll p=-INF;
  for(auto rr:rc){
    if(rr.second<=p)continue;
    ans+=(rr.second-max(p,rr.first))/d ;
    if(p<rr.first)ans++;
    p=rr.second;
  }
}
cout << ans << endl;
return 0;
}


Measured memory_bytes: 22144
// abc133-b
object Main extends App {
  val Array(n, d) = io.StdIn.readLine.split(" ").map(_.toInt)
  val ps = for (_ <- 1 to n) yield io.StdIn.readLine.split(" ").map(_.toInt)

  def calculate_distance(arr1: Array[Int], arr2: Array[Int]): Double = {
    math.sqrt((0 until d).map(i => arr1(i) - arr2(i)).map(i => i*i).sum)
  }

  def is_integer(double: Double): Boolean =
    if (double%1==0) true else false

  def rec(target: List[Array[Int]], count: Int): Int = target match {
    case head::Nil => count
    case head::tail => {
      val matched = tail.count(p => is_integer(calculate_distance(head, p)))
      rec(tail, count+matched)
    }
  }

  val result = rec(ps.toList, 0)
  println(result)

}

Measured memory_bytes: 55108
#include <iostream>

using namespace std;

int main() {
	int d;
	long long ans;
	while (cin >> d) {
		ans = 0;
		for (int i = d; i < 600; i = i + d) {
			ans += d * i * i;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define		CH		ch=(getchar())

inline		int		IN(){
	int x=0,f=1;char ch;
	for (CH;ch>'9'||ch<'0';CH) if (ch=='-') f=-1;
	for (;ch>='0'&&ch<='9';CH) (x*=10)+=ch-'0';
	return x*f;
}

int i,j,k,l,n,m;
long long K,f[105],x,y;

int main(){
	scanf("%lld",&K);
	puts("50");
	x=K/50;
	for (i=1;i<=50;i++) f[i]=x+49;
	y=K%50;
	for (i=1;i<=y;i++) f[i]++;
	for (i=y+1;i<=50;i++) f[i]-=y;
	for (i=1;i<=50;i++) printf("%lld ",f[i]); 
}


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

int main(){
  string S;
  cin >> S;
  int judge = 0;
  for(int i=0;i<S.size()-1;i++){
    if(S[i] == S[i+1]){
      judge = 1;
    }
  }
  if(judge == 1){
    cout << "Bad" << endl;
  }else{
    cout << "Good" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll h, w; cin >> h >> w;

    string maze[h];
    rep(i, h){
        cin >> maze[i];
    }

    ll cnt[h][w] = {};

    ll di[4] = {1, 0, -1, 0};
    ll dj[4] = {0, 1, 0, -1};

    ll ans = 0;

    // start loop
    rep(is, h){
        rep(js, w){

            if(maze[is][js] == '#') continue;

            rep(i, h){
                rep(j, w){
                    cnt[i][j] = 1e9;
                }
            }

            cnt[is][js] = 0;
            queue<P> que;
            que.push({is,js});

            // bfs
            while(!que.empty()){

                P p_old = que.front();
                que.pop();
                ll iold = p_old.first;
                ll jold = p_old.second;

                rep(dir, 4){

                    ll inew = iold + di[dir];
                    ll jnew = jold + dj[dir];

                    if(inew < 0 || h <= inew) continue;
                    if(jnew < 0 || w <= jnew) continue;
                    if(maze[inew][jnew] == '#') continue;
                    if(cnt[inew][jnew] != 1e9){
                        if(cnt[inew][jnew] <= cnt[iold][jold] + 1) continue;
                    }

                    // cout << inew << " " << jnew << endl;

                    cnt[inew][jnew] = cnt[iold][jold] + 1;

                    que.push({inew, jnew});
                }
            }

            // check max
            ll temp_max = 0;

            rep(i, h){
                rep(j, w){
                    if(cnt[i][j] >= 1e9) continue;

                    temp_max = max(temp_max, cnt[i][j]);
                }
            }

            ans = max(ans, temp_max);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <memory>
#include <sstream>

class stack {
public:
    stack(int size) : top_(0), size_(size),
                      array_(std::make_unique<int[]>(size)) {}

    bool is_full() { return this->top_ == this->size_; }

    bool is_empty() { return this->top_ == 0; }

    void push(int x) {
        if (this->is_full()) {
            throw std::runtime_error("this stack is full.");
        }
        this->array_[this->top_] = x;
        this->top_++;
    }

    int pop() {
        if (this->is_empty()) {
            throw std::runtime_error("this stack is empty.");
        }
        this->top_--;
        return this->array_[this->top_];
    }


private:
    int top_;
    int size_;
    std::unique_ptr<int[]> array_;
};

int main() {
    stack s(1000);
    std::string str;
    while (std::cin >> str) {
        if (str == "+") {
            auto rhs = s.pop();
            auto lhs = s.pop();
            s.push(lhs + rhs);
        }
        else if (str == "-") {
            auto rhs = s.pop();
            auto lhs = s.pop();
            s.push(lhs - rhs);
        }
        else if (str == "*") {
            auto rhs = s.pop();
            auto lhs = s.pop();
            s.push(lhs * rhs);
        }
        else {
            int x;
            std::stringstream ss(str);
            ss >> x;
            s.push(x);
        }
    }

    auto ans = s.pop();
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 3164
import java.util.Scanner;

public class Main {

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

		int n = scan.nextInt();

		double avg = 0;
		double[] x = new double[n];
		double[] y = new double[n];

		for(int i = 0; i < n; i++) {
			x[i] = scan.nextDouble();
			y[i] = scan.nextDouble();
		}

		double sum = 0;
		//全ての辺の長さの総和
		for(int i = 0; i < n - 1; i++) {
			for(int j = i+1; j < n; j++) {
				sum += Math.pow((x[i] - x[j])*(x[i] - x[j]) + (y[i] - y[j])*(y[i] - y[j]), 0.5);
			}
		}
		
		avg = sum * 2 / n;

		System.out.println(avg);

	}

}


Measured memory_bytes: 24276
#include <bits/stdc++.h>
#include <string>
using namespace std;
void heap(int a, int b, string* s);
void swap(int a,int b, string* s);
int main()
{
    int n;
    int m = 1;
    string* s;
    cin >> n;
    s = new string[n];
    for(int i=0; i<n; i++)
    {
        cin >> s[i];
    }
    for(int i=(n-2)/2; i>=0; i--)
    {
        heap(i,n-1,s);
    }
    for(int i=n-1; i>0; i--)
    {
        swap(0,i,s);
        heap(0,i-1,s);
    }
    for(int i=1; i<n; i++)

    {
        if(s[i]!=s[i-1])
        {
            m++;
        }
    }
    cout << m;
    return 0;
}
void heap(int a, int b, string* s)
{
    int c;
    string d;
    d=s[a];
    while(true)
    {
        c=2*a+1;
        if(c>b)
            break;
        if(c!=b)
        {
            if(s[c+1]>s[c])
            {
                c++;
            }
        }
        if(d>=s[c])
            break;
        s[a]=s[c];
        a=c;
    }
    s[a]=d;
}
void swap(int a,int b, string* s)
{
    string t = s[a];
    s[a]=s[b];
    s[b]=t;
}



Measured memory_bytes: 9872
# ABC103D
# 貪欲法：区間スケジューリング問題に帰着
# ソートして喧嘩している遠い島(b[i])の最も近いところから貪欲に選んでいく
# ex) 1-10, 2-5, 6-8
# なら2-5, 6-8を選ぶ．
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]
ab.sort(key=lambda x: x[1])
##print(ab)
ans = 1             # 一つ目分
tmp = ab[0][1] - 0.1      # 一つ目の橋は必ず壊すので
for i in range(1, M):
    if ab[i][0] < tmp < ab[i][1]:   # 直近で壊した橋が喧嘩している島の間にある時は何もしない
        pass
    else:                           # 間にない時は新しく橋を壊す
        ans += 1
        tmp = ab[i][1] - 0.1

print(ans)

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < n; i++)

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

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input values
    int N;
    cin >> N;

    vector<vector<int>> a(N, vector<int>(3, 0));
    rep (i, N) {
        rep (j, 3) {
            cin >> a[i][j];
        }
    }

    // dp table
    vector<vector<int>> dp(100100, vector<int>(3, 0));
    
    // init dp table

    // init condition

    // loop
    rep (i, N) {
        rep (j, 3) {
            rep (k, 3) {
                if (j == k) {
                    continue;
                }
                chmax(dp[i+1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    ll ans = max(dp[N][0], max(dp[N][1], dp[N][2]));

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

Measured memory_bytes: 11264
import java.util.Scanner;

class Main {
	public static void main(String[] $) {
		Scanner sc = new Scanner(System.in);
		int[] a= {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};
		int k=sc.nextInt();
		System.out.println(a[k-1]);
	}
}

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

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
constexpr int loose = 0;
constexpr int tight = 1;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve(){
	ll n,W;
	cin>>n>>W;
	Array w(n),v(n);
	REP(i,n) cin>>w[i]>>v[i];

	Matrix dp(n+1, Array(W+1,0));//iこまでみて、重さjのときの最大の価値

	REP(i,n){
		REP(j,W+1){
			chmax(dp[i+1][j], dp[i][j]);//とらない
			if(j+w[i]<=W) chmax(dp[i+1][j+w[i]],dp[i][j]+v[i]);//とる
		}
	}
	
	ll ans=0;
	REP(i,W+1) chmax(ans,dp[n][i]);
	cout<<ans<<en;
	
}

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

    solve();
    return 0;
}

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

int main(){
  int n;
  while(cin >> n, n){
    vector<int> V(n);
    for(int i = 0 ; i < n ; i++) cin >> V[i];
    
    int ans = 1e9;
    for(int i = 0 ; i < (1<<n) ; i++){
      int A = 0, B = 0;
      for(int j = 0 ; j < n ; j++){
	if((i>>j) & 1) A += V[j];
	else B += V[j];
      }
      ans = min(ans, abs(A-B));
    }
    cout << ans << endl;
  }  
  return 0;
}

Measured memory_bytes: 1192
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

typedef long long ll;
using namespace std;

int main() {
  ll A;
  double B;
  cin >> A >> B;
  ll ans = A * (ll)(B * 100 + 0.6);
  cout << ans / 100 << endl;
  return 0;
}

Measured memory_bytes: 3692
import java.io.*;

class Main {
	public static void main(String[] arg)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int turn = Integer.parseInt(br.readLine());
		int p1 = 0,p2 = 0;
		for(int i=0; i<turn; i++){
			String[] ani = br.readLine().split(" ");
			if(ani[0].compareToIgnoreCase(ani[1]) > 0){
				p1 += 3;
			}
			else if(ani[0].compareToIgnoreCase(ani[1]) ==0){
				p1 += 1;
				p2 += 1;
			}
			else if(ani[0].compareToIgnoreCase(ani[1]) < 0){
				p2 += 3;
			}
		}
		System.out.println(p1+" "+p2);
	}
}

Measured memory_bytes: 20104
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std ;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define per(i,b,a) for(int i=b; i>=a; i--)
#define sz(v) (int)v.size()
#define len(s) (int)s.length()
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
typedef pair<int, int> pi ;
typedef vector<pair<int,int> > vpi ;
typedef vector<int> vi ;
typedef long long ll ;
typedef double db ;
typedef long double ldb ;
const int mod = 1e9 + 7;
const int cmod = 998244353 ;
const ll inf = 1e17 + 5;
const db cpi = 3.14159265358 ;
ll powmod(ll a, ll b) { ll ret = 1 ; while(b) { if(b&1) ret = (ret*a)%mod ;  a = (a*a)%mod ; b >>= 1 ; }  return ret ; }
const int maxn = 1e5 + 5 ;
int n ;
int m ;
int cnt[maxn] ;
bool chk[maxn] ;
int main()
{
    ios::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    cin >> n >> m ;
    rep(i,0,n-1) cnt[i] = 1, chk[i] = false ;
    chk[0] = true ;
    while(m--)
    {
        int x, y ;
        cin >> x >> y ;
        x-- ;
        y-- ;
        if(chk[x]) chk[y] = true ;
        if(cnt[x] == 1 && chk[x] == true) chk[x] = false ;
        cnt[y]++ ;
        cnt[x]-- ;
    }
    int res = 0 ;
    rep(i,0,n-1) if(chk[i]) res++ ;
    cout << res << "\n" ;
    return 0 ;
}


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

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

    cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n, q) = readLine()!!.split(" ").map { it.toInt() }

    // 木を上からたどって足して行けばおしまいでは？？
    val c = Array(n) { mutableListOf<Int>() }

    // O(N)
    for (i in 0 until n - 1) {
        val (a, b) = readLine()!!.split(" ").map { it.toInt() }
        c[a - 1].add(b - 1)
    }

    // O(Q)
    val point = IntArray(n)
    for (i in 0 until q) {
        val (p, x) = readLine()!!.split(" ").map { it.toInt() }
        point[p - 1] += x
    }

    // ルートから深さ優先探索で値を付与
    // O(N)
    val score = LongArray(n)
    fun scoring(index: Int, nowS: Long) {

        val nowS_next = nowS + point[index]

        score[index] = nowS_next

        for (n in c[index]) {
            scoring(n, nowS_next)
        }

        return
    }

    scoring(0, 0L)

    println(score.joinToString(" "))
}

Measured memory_bytes: 158048
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define SZ(x) (long long)x.size()
#define endl '\n'
#define FAST                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define tc                                                                     \
  int tc;                                                                      \
  cin >> tc;                                                                   \
  while (tc--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define REPO(i, b, a) for (int i = b - 1; i >= a; i--)
#define REPI(i, a, b) for (int i = a; i <= b; i++)
#define MOD 1000000007

int32_t main() {
  FAST;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("output.txt", "w", stderr);
#endif
  int n;
  cin >> n;
  int ans = 0;
  REP(i, 1, n) {
    ans += n / i;
    if (n % i == 0)
      ans--;
  }
  cout << ans;
  return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<pair<pair<string, int>, int> > p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i].first.first >> p[i].first.second;
        p[i].first.second = p[i].first.second * (- 1);
        p[i].second = i + 1;
    }

    sort(p.begin(), p.end());
    for (int i = 0; i < n; i++) {
        cout << p[i].second << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second

using namespace std;
int main()
{
   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   
   int arr[5];
   
   int j=0;
   
   for(int i=0;i<5;i++)
   {
       cin>>arr[i];
       
       if(arr[i]==0)
       j=i+1;
   }
   
   cout<<j<<endl;
   


   return 0;
}


Measured memory_bytes: 3612
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = Integer.parseInt(sc.next());
        int w = Integer.parseInt(sc.next());
        int[][] c = new int[10][10];
        for(int i=0; i<10; i++) {
            for(int j=0; j<10; j++) {
                c[i][j] = Integer.parseInt(sc.next());
            }
        }
        
        int[] cost = new int[10];
        for(int k=0; k<10; k++) {
            for(int i=0; i<10; i++) {
                for(int j=0; j<10; j++) {
                    if(i == k) continue;
                    c[i][j] = Math.min(c[i][j], c[i][k]+c[k][j]);
                }
            }
        }
        
        int[][] a = new int[h][w];
        long ans = 0;
        for(int i=0; i<h; i++) {
            for(int j=0; j<w; j++) {
                a[i][j] = Integer.parseInt(sc.next());
                if(a[i][j] == -1 || a[i][j] == 1) continue;
                ans += c[a[i][j]][1];
            }
        }
        System.out.println(ans);
     }
}


Measured memory_bytes: 39252
#include<iostream>
#include<cstdio>
using namespace std;
struct edge{int to,next;}e[400005];int tot=0,last[200005],sz1[200005],sz2[200005],maxx[200005],ans[200005];
inline void adde(int u,int v) {e[++tot]=(edge){v,last[u]},last[u]=tot;return;}
inline void inse(int u,int v) {adde(u,v),adde(v,u);return;}
void dfs1(int root,int fa,int lim,int* sz) {sz[root]=1;
    for (register int i=last[root];i;i=e[i].next) if (e[i].to^fa&&e[i].to<lim) dfs1(e[i].to,root,lim,sz),sz[root]+=sz[e[i].to];
    return;
}void dfs2(int root,int fa) {maxx[root]=max(maxx[fa],root);
    for (register int i=last[root];i;i=e[i].next) if (e[i].to^fa) dfs2(e[i].to,root);
    if (maxx[root]==root) dfs1(root,fa,maxx[fa],sz1),dfs1(root,fa,maxx[root],sz2);return;
}void dfs3(int root,int fa) {
    if (root^1) {
        if (maxx[root]==root) ans[root]=sz1[root];
        else if(maxx[fa]==fa) ans[root]=sz2[root]-sz1[root];ans[root]+=ans[fa];
    }for (register int i=last[root];i;i=e[i].next) if (e[i].to^fa) dfs3(e[i].to,root);return;
}int main() {int n,u,v;
    scanf("%d",&n);for (register int i=1;i<n;++i) scanf("%d%d",&u,&v),inse(u,v);
    dfs2(1,0),dfs3(1,0);for (register int i=2;i<=n;++i) printf("%d ",ans[i]);return 0;
}

Measured memory_bytes: 21120
#include <bits/stdc++.h>
using namespace std;
char s1[7];
int main()
{
	scanf("%s",s1);
	if(s1[2]==s1[3] && s1[4]==s1[5])
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int N,A,B;
  cin >> N >> A >> B;
  long long int ans = 0;
  ans += (N/(A+B))*A;
  if(N%(A+B)>A){
    ans +=A;
  }else {
    ans +=N%(A+B);
  }
  cout << ans;
}


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

#define y1 dmytxdy
#define fi first
#define se second
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;

bool chkmin(int &x,int y){return x>y?x=y,1:0;}
bool chkmax(int &x,int y){return x<y?x=y,1:0;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n;
int a[100005];

int main(){
	n=readint();
	for(int i=1;i<=n;i++) a[i]=readint();
	sort(a+1,a+n+1); reverse(a+1,a+n+1);
	int opt=n,rg;
	for(int i=1;i<=n;i++){
		if(i>a[i]){
			opt=i-1;
			break;
		}
	}
	rg=opt;
	for(int i=opt+1;i<=n;i++) if(opt<=a[i]) rg=i;
	if((rg-opt)%2==0&&(a[opt]-opt)%2==0) printf("Second\n");
	else printf("First\n");
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  string s;
  cin >> s;
  cout << s.substr(0, s.size()-8) << endl;
  return 0;
}


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

int n;
string u;
double x;
double sum = 0;

int main() {
    cin >> n;

    for (int i = 0; i < n; ++i)
    {
        cin >> x >> u;
        if (u == "BTC")
        {
            x = x*380000.0;
        }
        sum += x;
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
N = gets.strip.to_i
ws = gets.split.map(&:to_i)

min = 1000000000
0.upto(N-2) do |t|
  s1 = ws[0, t+1]
  s2 = ws[t+1, N]
  diff = (s1.inject(:+) - s2.inject(:+)).abs
  min = diff if diff < min
end
puts min


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define  fo(i,a,b) for(ll i=a;i<b;i++)
#define rfo(i,a,b) for(ll i=a;i>=b;i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)

#define err() cout<<"----------"<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define pb push_back
#define deb(x) cout<< #x << " = "<<x<<endl;
#define F first
#define S second
#define MP make_pair
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589
const ll MOD=1e9+7;
ll mod(ll x)
{
   return (x%MOD+MOD)%MOD;
   // works for neg and pos values of x.
}
void solve()
{
   ll n;
   cin>>n;
   ll a[n+1],count=0;
   fo(i,1,n+1)
   {
        cin>>a[i];
   }
   for(ll i=1;i<=n;i+=2)
   {
        if(a[i]%2!=0)
        {
            count+=1;
        }
   }
   cout<<count<<endl;

}
int main()
{

    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
//  clock_t time_req;
//  time_req = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }

// time_req = clock()-time_req;
//  cout<<"Time taken: "<<(float)time_req/CLOCKS_PER_SEC<<"s"<<endl;

    return 0;
}

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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if(a + b >= 10)
        cout << "error" << endl;
    else
        cout << a + b << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char str1[100];
char str2[100];
int main()
{
	int n;
	scanf("%d",&n);
	scanf("%s",str1);
	scanf("%s",str2);
	for(int i=0;i<n;i++)
		printf("%c%c",str1[i],str2[i]);
	return 0;
} 

Measured memory_bytes: 256
<?php
// https://paiza.jp/challenges/179/show

class Util
{
    public static function input($isSplitSpace = false)
    {
        $input = trim(fgets(STDIN));
        if (!$isSplitSpace) {
            return $input;
        }

        return explode(' ', $input);
    }

    public static function arrToStr($arr)
    {
        return implode(" ", $arr);
    }
}

class Bench
{
    private $_startTime;

    public function __construct()
    {
        $this->_startTime = microtime(true);
    }

    public function getTime()
    {
        return microtime(true) - $this->_startTime;
    }

    public function printBench()
    {
        echo sprintf("Time[s]: %f  MemoryUsage: %s" . PHP_EOL, $this->getTime(), memory_get_peak_usage());
    }
}

// START
$n = Util::input();
$arr = Util::input(true);

insertionSort($arr, $n);
/**
1 insertionSort(A, N) // N個の要素を含む0-オリジンの配列A
2   for i が 1 から N-1 まで
3     v = A[i]
4     j = i - 1
5     while j >= 0 かつ A[j] > v
6       A[j+1] = A[j]
7       j--
8     A[j+1] = v
 */
function insertionSort($arr, $n)
{
    for ($i = 0; $i < $n; ++$i) {
        $v = $arr[$i];
        $j = $i - 1;
        while ($j >= 0 && $arr[$j] > $v) {
            $arr[$j + 1] = $arr[$j];
            $j -= 1;
        }
        $arr[$j + 1] = $v;

        echo Util::arrToStr($arr) . PHP_EOL;
    }
}



Measured memory_bytes: 9368
#include <bits/stdc++.h>
#define ll long long
#define rw freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
#define pb push_back
#define F first
#define S second
#define pf push_front
#define lp(i,a,b) for (int i=a;i<=(int)b;++i)
#define lp2(i,a,b) for (int i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define p(x) cout<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define EPS 1e-6
// to convert string to number use int a = stoi(string);
// to convert number to string use string s = to_string(int);
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define clr(c,x) memset(c,x,sizeof(c));
using namespace std;
const int N=2e5+5,mod=(int)1e9+7;
string s;
int main()
{
#ifdef ONLINE_JUDGE
    FAST;
#endif
    cin>>s;
    lp(i,0,s.size()-1)
    {
        if (s[i]==s[i+1]&&i+1<(int)s.size())
            return cout<<i+1<<" "<<i+2<<"\n",0;
        if (s[i]==s[i+2]&&i+2<(int)s.size())
            return cout<<i+1<<" "<<i+3<<"\n",0;
    }
    cout<<-1<<" "<<-1<<"\n";
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
    
int main()  {
    string s;
    cin>>s;
    for(int i=1;i<s.length();i++)
        if(s[i]==s[i-1])
        {
            cout<<i<<" "<<i+1;
            return 0;
        }
    for(int i=2;i<s.length();i++)
        if(s[i-2]==s[i])
        {
            cout<<i-1<<" "<<i+1;
            return 0;
        }
    cout<<"-1 -1";
    return 0;
}

Measured memory_bytes: 3736
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long ll;

int main(void){
  int x=5;
  rep(i,5){
    cin>>x;
    if(x==0)cout<<i+1<<endl;
  }
}
  


Measured memory_bytes: 3536
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;
#define ll int
#define f(i, n) for (ll i = 0; i < n; i++)
#define ff(i, n) for (ll i = 1; i <= n; i++)

vector<vector<ll>>a(1000000),a2(1000000),a3(1000000);ll finish[1000002];ll vis[1000002],vis2[1000002];ll c=0;ll pp=0;ll arr[1000002];
stack<ll>s;
void dfs(ll st)
{
    // cout<<st<<" ";

    f(i,a[st].size())
    {
        if(vis[a[st][i]]==0)
        {
            vis[a[st][i]]=1;
            dfs(a[st][i]);

        }

    }
    s.push(st);
    finish[st]=c;
    c++;

}
ll dp[1000000];
int main() {

    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);

ll n,m;cin>>n>>m;
f(i,m)
{
    ll x,y;
    cin>>x>>y;
    a[x].push_back(y);

}
ff(i,n) {
    if(vis[i]==0) {
        vis[i] = 1;
        dfs(i);
    }
}
while(s.size()!=0) {
 ll i=s.top();s.pop();
//cout<<i<<" ";
    f(j, a[i].size()) {
        dp[a[i][j]] = max(dp[a[i][j]], dp[i] + 1);
    }
}
cout<<*(max_element(dp+1,dp+n+1));

return 0;
}


Measured memory_bytes: 85376
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define INF 1000000000007
 

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;


struct pp{
    ll a,b,c,d;
};

const int N=100;
pp p[N];
ll maxi=0;
ll a[N];

// ll ncr(ll n,ll r)
// {
//    ll res=1;
//    ll maxi=max(r,n-r);
//    ll mini=min(r,n-r);
//    ll i;
//    for(i=maxi+1;i<=n;i++)
//    {
//        res*=i;
//    }
//    for(i=1;i<=mini;i++)
//    {
//        res/=i;
//    }

//    return res;

// }




void go(ll cno,ll ind,ll n,ll m,ll q)
{
    if(ind==n)
    {
          a[ind]=cno;
          ll i;
          ll tans=0;
          for(i=0;i<q;i++)
          {
              ll f1=p[i].a;
              ll f2=p[i].b;
              if(a[f2]-a[f1]==p[i].c)
              {
                  tans+=p[i].d;
              }
          }  
        //   for(i=1;i<=n;i++){
        //       cout<<a[i]<<" ";
        //   }
        //   cout<<"\n";
          maxi=max(maxi,tans);
    }
    else{
         a[ind]=cno;
         ll i;
         for(i=cno;i<=m;i++)
         {
             go(i,ind+1,n,m,q);
         }

    }
}

void solve()
{
   ll n,m,q;
   cin>>n>>m>>q;

   
   ll i;

   for(i=0;i<q;i++)
   {
       cin>>p[i].a>>p[i].b>>p[i].c>>p[i].d;
   }
   

   for(i=1;i<=m;i++)
   {
       go(i,1,n,m,q);
   }

   cout<<maxi<<"\n";

  
}


int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


while(t--)
{
solve();
} 


return 0;
}

Measured memory_bytes: 3632
N,K,Q=map(int,input().split())
#print(N,K,Q)
ac = [int(0) for _ in range(N)]
for a in range(Q):
  an=int(input())
  ac[an-1]+=1

for a in range(N):
#  print(ac[a])
  if K+ac[a]>Q:
    print("Yes")
  else:
    print("No")


Measured memory_bytes: 4620
#define _CRT_SECURE_NO_WARNINGS
#define REL

#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <string>
#include <set>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <cassert>
#include <complex>
#include <stack> 
#include <random>

using namespace std;

typedef int64_t i64;
typedef long long LL;
typedef long long ll;
typedef long double LD;
typedef complex <LD> cld;
typedef unsigned int uint;
typedef complex <double> cd;
typedef unsigned long long ULL;

#define endl "\n"
#define dendl "\n\n"
#define mp make_pair
#define mt make_tuple
#define size(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

/////////////////////////////////////////////////////////////////////

template <typename T>
T sqr(T a) {
	return a * a;
}

template <typename T>
int sign(T a) {
	if (a == 0)
		return 0;
	return (a > 0 ? 1 : -1);
}

template <typename T>
bool uax(T& a, const T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T>
bool uin(T& a, const T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T1, typename T2>
istream& operator >> (istream& in, pair<T1, T2>& p) {
	in >> p.first >> p.second;
	return in;
}

template <typename T1, typename T2>
ostream& operator << (ostream& out, pair<T1, T2>& p) {
	out << p.first << ' ' << p.second;
	return out;
}

mt19937_64 rnd(0);

const int LOG = 60;
const int N = (int)3e5 + 7;
const int MAXN = (int)3e6 + 7;
const int MOD = (int)998244353;
const int INF = (int)1e9 + 7;
const int CONST = 450;
const LL LINF = (i64)1e17;
const LD PI = 3.1415926535897932384626433832795;
const LD EPS = 1;

/////////////////////////////////////////////////////////////////////

LL k;
int n, up[LOG][N];

void solve() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> up[0][i];
		up[0][i]--;
	}
	for (int i = 1; i < LOG; i++) {
		for (int j = 0; j < n; j++)
			up[i][j] = up[i - 1][up[i - 1][j]];
	}
	int u = 0;
	for (int i = LOG - 1; i >= 0; i--) {
		if (k >= (1LL << i)) {
			u = up[i][u];
			k -= 1LL << i;
		}
	}
	cout << u + 1;
}

int main() {
	double start = clock();
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	cout << fixed << setprecision(20);
	cerr << fixed << setprecision(20);
#else
	cout << fixed << setprecision(20);
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	rnd.seed(time(0));
#endif

	int t = 1;
	for (int i = 0; i < t; i++) {
		solve();
	}

#ifdef _DEBUG
	cout << endl << "Time is " << (clock() - start) / 1000.0;
#endif
}

Measured memory_bytes: 50760
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
int main() {
  ll x;
  cin >> x;
  ll y=100,ans=0;
  while(y<x) {
    y*=1.01;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3644
s=input()

def month(n):
    if 1 <= n <= 12:
        return True
    else:
        return False


if int(s[0:2]) == 0:
    if month(int(s[2:4])) :
        print("YYMM")
        exit()
    else:
        print("NA")
        exit()

if int(s[2:4]) == 0:
    if month(int(s[0:2])):
        print("MMYY")
        exit()
    else:
        print("NA")
        exit()


if month(int(s[0:2])):
    if month(int(s[2:4])):
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if month(int(s[2:4])):
            print("YYMM")
    else:
        print("NA")


Measured memory_bytes: 9180
#include <stdio.h>

bool func(double n)
{
    int x=n;
    if(x==n) return true;
    else return false;
}

int main()
{
    int n;
    scanf("%d",&n);
    double a=n;
    for(int i=1;i<10;i++)
    {
        if(func(a/i)&&n/i<10) {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
}

Measured memory_bytes: 128
N,X=map(int,input().split())
x = list(map(int,input().split()))
if not X in x:
    x.append(X)
x.sort()
d = []
for i in range(len(x)-1):
    d.append( x[i+1] - x[i] )

def GCD(a,b):
    if a%b==0: return b
    return GCD(b,a%b)

g = d[0]
for i in range( len(d)-1 ):
    g = GCD(g,d[i+1])
print(g)


Measured memory_bytes: 14252
/**
 * DPL_1_A
 * 17D8101036D Vincent Fango 9/26
 * id: deepmint
 */
#include <bits/stdc++.h>
#define INF INT_MAX
using namespace std;


int main() {
    int n, m;
    cin >> n >> m;
    vector<int> d;

    for (int i = 0; i < m; i++) {
        int x;
        cin >> x;
        d.push_back(x);
    }

    int dp[100000];
    dp[0] = 0;

    for (int i = 1; i <= n; i++) dp[i] = INF;


    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < m; j++) {
            if (d[j] <= i) {
                int s = dp[i - d[j]];
                if (s != INF && s + 1 < dp[i]) dp[i] = s + 1;
            }
        }
    }
    cout << dp[n] << endl;

    return 0;
}
/**
 *
 */


Measured memory_bytes: 3364
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;


int n,m,q;
vector<int> a,b,c,d;
int ans;

void dfs(vector<int> A){

  if(A.size() == n+1){

    int ii;
    int val = 0;

    for(ii=0;ii<q;ii++){
      if((A[b[ii]] - A[a[ii]]) == c[ii]){
        val += d[ii];
      }
    }

    //cout << "val:" << val << endl;

    ans = max(ans,val);
    
    //for(ii=1;ii<=n;ii++){
    //  cout << a[ii] ;
    //  
    //}
    

    //cout << endl;
    
    return ;
  }

  A.push_back(A.back());

  while(A.back() <= m){
    dfs(A);
    A.back()++;
  }
  
}

int main(){
  int ii,jj,kk,ll,mm,nn,oo,pp,qq,rr;
  vector<int> ret;



  cin >> n >> m >> q;

  a = b = c = d = vector<int>(q);

  for(ii=0;ii<q;ii++){
    cin >> a[ii] >> b[ii] >> c[ii] >> d[ii];
  }

  ans = -1;
  
  dfs(vector<int>(1,1));

  cout << ans << endl;
  
  //lll cnt = 0;
  //for(ii=1;ii<=m;ii++){
  //  for(jj=ii;jj<=m;jj++){
  //    for(kk=jj;kk<=m;kk++){
  //      cout << "ii:" << ii << "jj:" << jj << "kk:" << kk << endl;
  //      cnt++;
  //    }
  //  }
  //}
  //
  //for(ii=1;ii<=m;ii++){
  //  vector<int> num(n);
  //  for(jj=1;jj<=n;jj++){
  //    num[jj] = ii;
  //    
  //  }
  //}
  //cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3584