akhauriyash/Code-Regression huggingface dataset:
//AOJ-GRL-2-A
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

struct UnionFind{
    vector<int> par;
    vector<int> siz;

    UnionFind(int n) : par(n), siz(n, 1){
        iota(par.begin(), par.end(), 0);
    }

    int root(int x){
        if(par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
    }

    bool same(int x, int y){
        return root(x) == root(y);
    }

    int size(int x){
        return siz[root(x)];
    }
};

template <typename T>
struct edge{
    int from, to;
    T cost;
    edge(int from, int to, T cost = 1) : from(from), to(to), cost(cost){}
    bool operator < (const edge & e) const{
        return cost < e.cost;
    }
};

template <typename T>
T Kruskal(int V, vector<edge<T>> & es){
    sort(es.begin(), es.end()); //reverseすると最大全域木
    UnionFind uf(V);
    T res = 0;
    for(edge<T> e : es){
        if(!uf.same(e.from, e.to)){
            uf.unite(e.from, e.to);
            res += e.cost;
        }
    }
    return res;
}

signed main(){
    int V,e;
    cin >> V >> e;
    vector<edge<ll>> es;
    int s,t;
    ll w;
    REP(i,e){
        cin >> s >> t >> w;
        es.emplace_back(s, t, w);
    }
    cout << Kruskal(V, es) << endl;
    return 0;
}


Measured memory_bytes: 4940
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int A,B,C;
  cin >> A >> B >> C;
  if(A==B&&B!=C) cout << "Yes" << endl;
  else if(A==C&&A!=B) cout << "Yes" << endl;
  else if(A!=B&&B==C) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

#define LL long long
#define VLL vector<long long>
	string strnum = "0123456789";
	string alpS = "abcdefghijklmnopqrstuvwxyz";
	string alpL = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	int sizealp = (int)(alpS.size());
	int mod = 1e9 + 7;
#define SORT(x) sort(x.begin(),x.end())
#define REVE(x) reverse(x.begin(),x.end())
#define rep(i,n) for(int i=0;i<n;i++)
#define COUT(x) cout<<x<<endl
	double pai = 3.1415926535;
	string atc = "atcoder";
	typedef pair<long long, long long> data_t;

int main() {
	int N;
	cin >> N;
	vector<int> V(N), C(N);
	rep(i, N)
		cin >> V[i];
	rep(i, N)
		cin >> C[i];
	int ans=0;
	rep(i, N) {
		if (V[i] - C[i] > 0)
			ans += V[i] - C[i];
	}
	COUT(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int N;
vector<int> a,b;

int main(){
    cin >> N;
    a.resize(N);
    b.resize(N);
    rep(i,N) cin >> a[i];
    rep(i,N) cin >> b[i];

    int ans = 0;
    rep(k,29){
        int T = (1 << k);
        vector<int> B(N);
        rep(i,N) B[i] = b[i] % (1<<(k+1));
        sort(all(B));
        int cnt = 0;
        rep(i,N){
            int A = a[i] % (1<<(k+1));
            int idx1 = lower_bound(B.begin(),B.end(),T-A) - B.begin();
            int idx2 = lower_bound(B.begin(),B.end(),2*T-A) - B.begin();
            int idx3 = lower_bound(B.begin(),B.end(),3*T-A) - B.begin();
            int idx4 = lower_bound(B.begin(),B.end(),4*T-A) - B.begin();
            cnt += idx2-idx1;
            cnt += idx4-idx3;
        }
        if(cnt%2){
            ans |= (1<<k);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 2672
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let mut a = read_vec::<usize>();
    a.sort();
    a.reverse();
    let asum = a.iter().sum::<usize>();
    if a[m - 1] * 4 * m < asum {
        println!("No");
    } else {
        println!("Yes");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
# import numpy as np

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

N,M = map(int,input().split())
A = [0 for i in range(N)]
B = [0 for i in range(M)]
for i in range(N):
    A[i] = input()
for i in range(M):
    B[i] = input()

ans = False
for y in range(N-M+1):
    for x in range(N-M+1):
        for i in range(M):
            for j in range(M):
                if A[x+i][y+j] == B[i][j]:
                    pass
                else:
                    break
            else:
                continue
            break
        else:
            ans = True

if ans:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 5524
package main

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

func check(e error) {
	if e != nil {
		log.Fatalf("error: %v", e)
	}
}

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	input := strings.Split(stdin.Text(), " ")

	a, err := strconv.Atoi(input[0])
	check(err)
	b, err := strconv.Atoi(input[1])
	check(err)

	if product := a * b; product%2 == 0 {
		fmt.Println("Even")
	} else {
		fmt.Println("Odd")
	}
}

Measured memory_bytes: 640
'use strict'
function Main(input) {
  const arr = input.split(" ");
  let count5 = 0, count7 = 0;
  
  for(const a of arr){
    if(a == 5){
      count5++;
    }else if(a == 7){
      count7++;
    }
  };

  console.log(count5 === 2 && count7 === 1 ? 'YES' : 'NO');
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
S = input()
T = input()

slist = [-1]*26
tlist = [-1]*26

for i in range(len(S)):
	if (slist[ord(S[i])-97] == -1 and tlist[ord(T[i])-97] == -1):
		slist[ord(S[i])-97] = ord(T[i])-97
		tlist[ord(T[i])-97] = ord(S[i])-97
	else:
		if (slist[ord(S[i])-97] != ord(T[i])-97 or tlist[ord(T[i])-97] != ord(S[i])-97):
			print("No")
			exit()
print("Yes")

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

#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<30)
#define INFLL (1LL<<62LL)

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

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

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int N, M;
  map<int, int> cnt;
  cin >> N >> M;

  rep(i, M) {
    int a, b;
    cin >> a >> b;
    if (a > b) swap(a, b);

    if (a == 1) cnt[b]++;
    if (b == N) cnt[a]++;
  }

  for (auto & p : cnt) {
    if (p.second == 2) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <iomanip>
#include <math.h>
#include <map>
#include <list>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <sstream>
#include <bitset>
#include <string.h>
// #include <limits.h>

#define FOR(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define FORUL(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define FORULE(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define FOREACH(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#if defined(_MSC_VER) || __cplusplus > 199711L
#define AUTOVAR(newvar,v) auto newvar = (v)
#else
#define AUTOVAR(newvar,v) __typeof(newvar) r = (v)
#endif
#define PB(x) push_back(x)
#define MP(x,y) make_pair((x),(y))
#define MEMSET(m,v) memset(m,v,sizeof(m))

typedef long long        ll;
typedef unsigned long long    ull;

#define INTMAX  99999999

#define DEBUG 1

#if DEBUG
#define DOUT cout<<"["<<__LINE__<<"]:"
#else
#define DOUT 0 && cout
#endif

using namespace std;

#define MAX_N 10000
#define MAX_K 10

int N,K;
vector<bool> D;


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

	cin >> N >> K;
	D.resize(10,true);
	FOR(i,K) {
		int n;
		cin >> n;
		D[n] = false;
	}
	int n = N;
	bool result = true;
	while(true) {
		int m = n;
		result = true;
		while(m>0) {
			if(!D[m%10]) {
				result = false;
				break;
			}
			m /= 10;
		}
		if(result == true) {
			break;
		}
		n++;
	}
	
	cout << n << endl;

	return 0;
}
 

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }

lint N, A;
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> N;
	bool flag = true;
	REP(i, N) {
		cin >> A;
		flag &= (A % 2 == 0);
	}
	cout << (flag ? "second" : "first");
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

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


int n;
string s;

int main(){
	cin >> s;
	n = s.size();
	
	int cnt = 0;
	for(int i = 0; i < n; i++){
		if(s[i] == '0') cnt++;
	}
	cout << min(cnt, n-cnt) * 2 << endl;
	
	return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
#define all(x) (x).begin(), (x).end()

using namespace std;

using Matrix = vector<vector<long long> >;


long long mod = 1e9 + 7;

const int MSIZE = 50;

void Mult(Matrix& A, Matrix& B, Matrix& C) {
    int n = A.size();
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            C[i][j] = 0;
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                C[i][k] += A[i][j] * B[j][k];
                C[i][k] %= mod;
            }
        }
    }
}

void FastPow(Matrix& A, int n, long long p) {
    Matrix C = A;
    Matrix D(n, vector<long long> (n, 0));
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            A[i][j] = (i == j);
        }
    }

    while (p) {
        if (p & 1) {
            Mult(A, C, D);
            A = D;
        }
        Mult(C, C, D);
        C = D;
        p >>= 1;
    }
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    long long p;
    cin >> n >> p;
    Matrix A;
    A.assign(n, vector<long long>(n, 0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> A[i][j];
        }
    }
    FastPow(A, n, p);
    long long answer = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            answer += A[i][j];
            answer %= mod;
        }
    }
    cout << answer << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll a, b, c, k;

int main() {
	cin >> a >> b >> c >> k;
	if (k < a) {
		cout << k << endl;
	}
	else if (k <= a + b) {
		cout << a << endl;
	}
	else {
		cout << 2 * a + b - k << endl;
	}
	return 0;
}

Measured memory_bytes: 3592
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())





n,m = map(int, input().split())
pl = list(map(int, input().split()))
uf = UnionFind(n+1)
for _ in range(m):
    x,y = map(int, input().split())
    uf.union(x,y)

ans = 0
for i,p in enumerate(pl):
    if uf.same(i+1,p): ans += 1

print(ans)

Measured memory_bytes: 84908
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{   
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end());
    ll cnt = 0;
    ll ans = 0;
    rep(i,n){
        if(a[i] == a[i+1]){
            cnt++;
        }else{
            cnt++;
            if(cnt%2 == 1) ans++;
            cnt = 0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4116
#include <iostream>
#include <algorithm>
#include <cmath>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define FORE(i,a,b) for (int i=(int)(a);i<=(int)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REPE(i,n) FOR(i,0,n)

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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int> job_list[100001];

  REP(i,N) {
    int a,b; cin >> a >> b;
    job_list[a].push_back(b);
  }

  priority_queue<int> pq;
  int ans = 0;
  FORE(i,1,M) {
    for (auto x : job_list[i]) pq.push(x);
    if (0 < pq.size()) {
      ans += pq.top();
      pq.pop();
    }
  }
  cout << ans;

  return 0;
}

Measured memory_bytes: 5632
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.HashSet;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String N=sc.next();
    String M=sc.next();
    String[] str = M.split("");

    if(N.concat(str[str.length-1]).equals(M)){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }



  }
}


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

ll N;
pair<string, pair<ll, ll> > A[105];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> N;
    for (ll i = 0; i < N; i++) {
        cin >> A[i].first >> A[i].second.first;
        A[i].second.first *= -1;
        A[i].second.second = i+1;
    }
    
    sort(A, A+N);
    for (ll i = 0; i < N; i++) {
        cout << A[i].second.second << "\n";
    }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define inf 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
lol a,b,c,d;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >>a;
  if(a%2==1){
      cout <<"0\n";
      return 0;
  }
  lol ans=0;
  b=5;
  while(a>=b){
      ans+=a/(b*2);
      b*=5;
  }
  cout <<ans<<'\n';
  return (0);
}


Measured memory_bytes: 384
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <stack>
#include <utility>
#include <vector>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	pair<int, int> a;
	for (int& i : A) {
		cin >> i;
		if (0 < i) ++a.first;
		else ++a.second;
	}
	sort(A.begin(), A.end(), [](int& a, int& b)->bool { return abs(a) < abs(b); });
	stack<int> b, c;
	vector<pair<int, int>> d;
	if (0 == a.first) {
		b.push(A.front() - A.back());
		d.emplace_back(A.front(), A.back());
		for (int i = 1; i < N - 1; ++i) c.push(A[i]);
	}
	else if (0 == a.second) {
		c.push(A.front() - A.back());
		d.emplace_back(A.front(), A.back());
		for (int i = 1; i < N - 1; ++i) b.push(A[i]);
	}
	else {
		for (int& i : A) {
			if (0 < i) b.push(i);
			else c.push(i);
		}
	}
	while (!c.empty()) {
		a = make_pair(b.top(), c.top());
		b.pop();
		c.pop();
		if (b.empty()) {
			b.push(a.first - a.second);
			d.push_back(a);
		}
		else {
			c.push(a.second - a.first);
			d.emplace_back(a.second, a.first);
		}
	}
	cout << b.top() << endl;
	for (pair<int, int>& i : d) cout << i.first << ' ' << i.second << endl;
}

Measured memory_bytes: 3448
#include <stdio.h>

int main(void){
    int n;
    scanf("%d", &n);
    int c[n];
    int v[n];
    for(int i = 0;i < n;i++){
        scanf("%d", &v[i]);
    }
    for(int i = 0;i < n;i++){
        scanf("%d", &c[i]);
    }
    int max = 0;
    for(int i = 0;i < n;i++){
        if(v[i] > c[i]){
            max = max + v[i] - c[i];
        }
    }
    printf("%d\n", max);
    return 0;
}

Measured memory_bytes: 128
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #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()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            ll n,k;
            cin>>n>>k;
            ll ans=min(n%k,(k-n%k));
            cout<<ans<<endl;
        }
        return 0;
    }


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <queue>

using namespace std;
int n, m;
vector<int> vege;

const int INF = 1 << 29;

int main(void)
{
	while(cin >> n >> m && n && m)
	{
		vege.resize(n);
		for (int i = 0; i < n; i++)
		{
			cin >> vege[i];
		}

		sort(vege.begin(), vege.end(), greater<int>());
		int sum = accumulate(vege.begin(), vege.end(), 0);
		for (int i = 1; i - 1 < n / m; i++)
		{
			sum -= vege[i * m - 1];
		}
		cout << sum << endl;
	}
	return 0;
}

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

void p(long current, long min, long ans) {
    cout << "(cur, min, ans) = " << current << ", " << min << ", " << ans
         << endl;
}

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

    int n;
    cin >> n;

    long Rmax = -1000000000;
    long Rcur;
    cin >> Rcur;
    long Rmin = Rcur;

    for (int i = 0; i < n - 1; i++) {
        cin >> Rcur;
        Rmax = max(Rmax, Rcur - Rmin);
        Rmin = min(Rmin, Rcur);
        // p(Rcur, Rmin, Rmax);
    }
    cout << Rmax << endl;
    return 0;
}


Measured memory_bytes: 3228
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  string s;
  std::cin >> s;

  if(s[0]=='9' || s[1]=='9')printf("Yes\n");
  else printf("No\n");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
const int N = 100;
int grid[N+1][N+1];
bool vis[N+1][N+1];
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	memset(grid, 0, sizeof(grid));
	memset(vis, false, sizeof(vis));
	int n; cin >> n;
	for (int i = 0; i < n; i++){
		int x,y,h; cin >> x >> y >> h;	
		grid[x][y] = h;
		vis[x][y] = true;
	}
	
	int cx, cy, realH;
	
	bool found = false;
	for (int i = 0; i < N+1; i++){
		for (int j = 0; j < N+1; j++){
			int fakeH = 0;
			bool extrap = false;
			for (int x = 0; x < N+1; x++){
				for (int y = 0; y < N+1; y++){
					if (grid[x][y]){
							fakeH = grid[x][y] + abs(x-i) + abs(y-j);
							extrap = true;
							break;
					}
				}
				if (extrap) break;
			}
				
			
			bool valid = true;
			for (int x = 0; x < N+1; x++){
				for (int y = 0; y < N+1; y++){
					if (vis[x][y]){
						if (max(0,fakeH-abs(x-i)-abs(y-j)) != grid[x][y]){
							valid = false;
							break;
						}
					}
				}
				if (!valid) break;
			}
			
			if (valid){
				found = true;
				cx = i;
				cy = j;
				realH = fakeH;
				break;
			}
		}
		if (found) break;
	}
	
	cout << cx << " " << cy << " " << realH << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2,tmp3;
const ll mod = 998244353;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}
int main(){
  ll n;
  cin >> n;
  vector<pair<double,double>> vec(n);
  vector<vector<double>> dis(n,vector<double>(n,0));
  double x,y;
  rep(i,n){
    cin >> x >> y;
    vec[i] = make_pair(x,y);
  }
  ll ans = 0;
  ll mul = n * (n-1);
  double sum = 0;
  rep(i,n){
    REP(j,i+1,n){
      x = (vec[i].first -vec[j].first) * (vec[i].first -vec[j].first) + (vec[i].second -vec[j].second) * (vec[i].second -vec[j].second);
      x = sqrt(x);
      dis[i][j] = x;
      sum += 2 * x;
    }
  }
  sum /= mul;
  sum *= (n-1);
  printf("%.10f",sum);
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
typedef long long ll;

const int P=998244353;
int n,f[200005][3][4],Sum,Ans;
char s[200005];

int main()
{
	scanf("%s",s+1),n=strlen(s+1),f[0][0][0]=1;
	bool Flag=true;
	for(int i=1;i<=n;++i)if(s[i]!=s[1])Flag=false,i=n;
	if(Flag)return puts("1"),0;
	if(n==2)return puts("2"),0;
	for(int i=1;i<=n;++i)Sum=(Sum+s[i]-'a')%3;
	if(!Sum&&n==3)return puts("3"),0;
	for(int i=2;i<=n;++i)if(s[i]==s[i-1])Flag=true,i=n;
	for(int i=0;i<n;++i)
		for(int j=0;j<3;++j)
			for(int k=0;k<4;++k)
				for(int l=0;l<3;++l)
				{
					int kk=l;
					if(k==3||(i&&k==l))kk=3;
					(f[i+1][(j+l)%3][kk]+=f[i][j][k])%=P;
				}
	printf("%d\n",(f[n][Sum][3]+!Flag)%P);
	return 0;
}

Measured memory_bytes: 9728
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#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 SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN2(n,a);
  z = 1;
  REP(i,n){
    if(z*2 < z+a) z *= 2;
    else z += a;
  }
  OUT(z);
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <cmath>
#include <algorithm>

std::set<int> s;
std::vector<int> v;
int x, n, c, ans;
int main() {
  std::cin >> x >> n;
  for (int i = 0; i <= 101; i++) {
    s.insert(i);
  }
  for (int i = 0; i < n; i++) {
    std::cin >> c;
    s.erase(c);
  }
  int t = 1000;
  for (auto m: s) {
    int u = std::abs(m - x);
    if (u < t) {
      v.clear();
      t = u;
      ans = m;
      v.push_back(ans);
    }
    else if (u == t) {
      v.push_back(m);
    }
  }
  if (v.size() >= 2) {
    std::cout << *std::min_element(v.begin(), v.end()) << std::endl;
    return 0;
  }
  std::cout << ans << std::endl;
  
}

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

int main(){
  string S;
  cin >> S;
  int n = S.size();
  int cmax,max;
  cmax = 0;
  max = 0;
  for(int i = 0;i < n;i++){
    if(S.at(i) == 'R')cmax++;
    if(S.at(i) == 'S')cmax = 0;
    if(cmax > max)max = cmax;
  }
  cout << max;

}

Measured memory_bytes: 3624
#include <iostream>
using namespace std;
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<(n);i++)
int main(void){
    int N;
    cin >> N;
    long long int a=1;
    REP(i,N){
        a = (a*(i+1))%MOD;
    }
    cout << a;
    return 0;
}


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

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int a,b;
  cin>>a>>b;
  if(a>0 && b>0){
    cout<<"Positive";
  }else if(a<=0 && b>=0){
    cout<<"Zero";
  }else {
    int n=b-a;
    if(n%2==0){
      cout<<"Negative";
    }else{
      cout<<"Positive";
    }
  }




}



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

using namespace std;

#define intt long long

const intt INF = 1e18L + 5;

int n, W;

int main() {

	cin >> n >> W;

	vector <int> v(n + 1), w(n + 1);
	for (int i = 1; i <= n; i ++) {
		cin >> w[i] >> v[i];
	}

	int V = 0;
	for (int i = 1; i <= n; i ++) {
		V += v[i];	
	}

	vector <intt> dp(V + 1, INF);
	// dp[i] -> the minimum total weight of knapsack with value exactly i
	dp[0] = 0;
	for (int k = 1; k <= n; k ++) {
		for (int x = V; x >= 0; x --) {
			if (x - v[k] >= 0) {
				dp[x] = min(dp[x], w[k] + dp[x - v[k]]);
			}
		}
	}

	int ans = 0;
	for (int i = 0; i <= V; i ++) {
		if (dp[i] <= W) {
			ans = max(ans, i);
		}
	}

	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second

int ans=0,used[10];
void dfs(int n,int s){
  if(s<0)return;
  if(n==0 && s==0){
    ++ans;
    return;
  }
  for(int i=0;i<=9;i++){
    if(used[i])continue;
    used[i]=true;
    dfs(n-1,s-n*i);
    used[i]=false;
  }
}
  
int memo[11][900];

main(){
  rep(i,10)used[i]=i;
  int p=0;
  do{
    ++p;
    int sum=0;
    rep(i,10){
      sum+=used[i]*(i+1);
      memo[i+1][sum]++;
    }
  }while(next_permutation(used,used+10));

  int n,s;
  while(cin>>n>>s){
    int t=1,f=10-n;
    while(f)t*=f--;
    if(s>=900)cout<<0<<endl;
    else cout<<memo[n][s]/t<<endl;
  }

}

Measured memory_bytes: 788
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            long a = cin.ReadInt;
            long b = cin.ReadInt;
            long c = cin.ReadInt;
            long d = cin.ReadInt;

            long ans = Max(a*c, Max(a*d, Max(b*c, b*d)));
            Console.WriteLine(ans);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}


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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define trav(a, x) for (auto& a : x)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;
#define INF (1ll<<60)

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    string s;
    cin >> s;
    int sz = SZ(s);
    REP(c, 26) {
        int start = 0;
        REP(i, sz) {
            if (s[i] != 'a' + c) continue;
            int cnt = 1;
            int j = i + 1;
            for (; j < sz; j++) {
                if (s[j] != 'a' + c) continue;
                cnt++;
                int k = j - i + 1;
                if (cnt > k / 2) {
                    cout << i + 1 << ' ' << j + 1 << '\n';
                    return 0;
                }
                break;
            }
            i = j - 1;
        }
    }
    cout << "-1 -1\n";

}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long dp[55][3000];
int x[55];
int main() {
	int n, a;
	cin >> n >> a;
	for (int i = 1; i <= n; i++) {
		cin >> x[i];
	}
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int k = 50; k >= 0; k--) {
			for (int j = 2600; j >= 0; j--) {
				dp[k + 1][j + x[i]] += dp[k][j];
			}
		}
	}
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += dp[i][i * a];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4824
gets
arr = gets.chomp.split(' ').map(&:to_i).sort
hash = Hash.new(0)
arr.each { |i| hash[i] += 1 }
dup_hash = hash.filter { |_, v| v != 1 }
hash.each do |j, _|
  (j * 2).step(1000001, j) { |k| hash.delete(k) }
end
dup_hash.each { |k, _| hash.delete(k) }
puts hash.count

Measured memory_bytes: 41104
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e2;
const int INF=1e9;
int N,M;
vector<int> g[size];
int len[size][size]={};
int d[size];
void dijkstra(int a){//O(E+NlogN)
    priority_queue<pair<int,int>> pq;
	rep(i,0,N){
		d[i]=INF;
		pq.push(make_pair(-d[i],i));
	}
	d[a]=0;pq.push(make_pair(0,a));
	int v,temp;
	while(!pq.empty()){
		v=pq.top().second;
		pq.pop();
		for(int u:g[v]){
			temp=d[v]+len[v][u];
			if(d[u]>temp){
				d[u]=temp;
				pq.push(make_pair(-d[u],u));
			}
		}
	}return;
}
int main(){
	cin>>N>>M;
	vector<pair<int,int>> edge(M);
	rep(i,0,M){
		int a,b,c;
		cin>>a>>b>>c;a--;b--;
		g[a].push_back(b);
		g[b].push_back(a);
		len[a][b]=c;len[b][a]=c;
		edge[i].first=a;
		edge[i].second=b;
	}
	int ans=0;
	rep(i,0,M){
		int a=edge[i].first,b=edge[i].second;
		dijkstra(a);
		if(d[b]<len[a][b]) ans++;
	}cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <climits>

using namespace std;

typedef unsigned long long ull;

ull dp[101][10001];

int main() {
  ull N, W;
  cin>>N>>W;
  vector<ull> v(N, 0);
  vector<ull> w(N, 0);
  int sum_v = 0;
  for (int i=0;i<N;++i){
    cin>>v[i]>>w[i];
    sum_v += v[i];
  }

  for (int i=0;i<N;++i) {
    for (int j=1;j<=sum_v;++j) {
      dp[i][j] = ULLONG_MAX;
    }
  }

  dp[0][v[0]] = w[0];

  for (int i=1;i<N;++i) {
    for (int j=0;j<=sum_v;++j) {
      if (dp[i-1][j-v[i]] == ULLONG_MAX) {
        dp[i][j] = dp[i-1][j];
      }
      else {
        dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i]]+w[i]);
      }
    }
  }

  for (int i = sum_v; i >= 0; --i) {
    if (i == 0 || (dp[N-1][i] <= W)) {
      cout<<i<<endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 10932
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  int N, K;
  cin >> N >> K;
  vi A(N);
  rep(i, 0, N) {
    cin >> A[i];
    A[i]--;
  }

  int pref_len = 0;
  int loop_len = 0;
  int loop_beg = -1;
  {
    int v = 0;
    vi dist(N, INF);
    dist[v] = 0;
    while (1) {
      int nx = A[v];
      if (dist[nx] < dist[v] + 1) {
        pref_len = dist[nx];
        loop_beg = nx;
        loop_len = dist[v] + 1 - dist[nx];
        break;
      }
      dist[nx] = dist[v] + 1;
      v = nx;
    }
  }

  int v = 0;
  if (pref_len < K) {
    v = loop_beg;
    K -= pref_len;
    K %= loop_len;
  }
  rep(i, 0, K) { v = A[v]; }
  cout << v + 1 << endl;
  return (0 ^ _ ^ 0);
}



Measured memory_bytes: 6368
import math
N = int(input())
A = list(map(int, input().split()))
B = [0] * N
for i in range(N):
    B[A[i] -1] = i + 1
for i in range(N):
    if i != N - 1:
        print(B[i], end = " ")
    else:
        print(B[i])

Measured memory_bytes: 14024
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    string S;
    cin >> S;
    int s=0,n=0,w=0,e=0;
    
    for(int i=0;i<S.length();i++){
        if(S[i]=='S') s++;
        if(S[i]=='N') n++;
        if(S[i]=='W') w++;
        if(S[i]=='E') e++;
    }
    if(s>0&&n>0&&w>0&&e>0){
        cout << "Yes";
    }else if(s>0 && n>0 &&w==0 && e==0){
        cout << "Yes";
    }else if(w>0 && e>0 && s==0 && n==0){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int m,n;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
char a[57][57];
 
int main(void) {
 int h, w;
 cin >> h >> w;
 
 string a[50];
 
 for (int i = 0; i < h; ++i)
    cin >> a[i];
 
 const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
 const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
 
 for (int i = 0; i < h; ++i)
    {
 for (int j = 0; j < w; ++j)
     {
 if (a[i][j] == '#') continue;
 
 int cnt = 0;
 for (int d = 0; d < 8; ++ d) {
 const int ni = i + dy[d];
 const int nj = j + dx[d];
 
 if (ni < 0 or h <= ni)
    continue;
 if (nj < 0 or w <= nj)
 continue;
 if (a[ni][nj] == '#') cnt++;
 }
 
 a[i][j] = char(cnt + '0');
 
 }
 }
 
 for (int i = 0; i < h; ++i) cout << a[i] << endl;
return 0;
}

Measured memory_bytes: 256
<?php 
fscanf(STDIN,"%s",$str);
$array = preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY);

if ($array[0] != 2){
    $array[0]=2;
}
if ($array[1] != 0){
    $array[1]=0;
}
if ($array[2] != 0){
    $array[2]=1;
}
if ($array[3] != 8){
    $array[3]=8;
}


$day = '';
foreach($array as $moji){
    $day = $day.$moji;
}
echo $day;
?>

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int N; cin >> N;
    vi A(N+2, 0); REP1(i, N) cin >> A[i];
    int sum = 0;
    REP1(i, N+1) sum += abs(A[i] - A[i-1]);

    REP1(i, N)
    {
        cout <<  sum - abs(A[i] - A[i-1]) - abs(A[i+1] - A[i]) + abs(A[i+1] - A[i-1]) << endl;
    }
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 1664
#include<stdio.h>
int strlng(char a[])
{
    int i;
    for(i=1; a[i]!='\0'; i++)
    {

    }
    return i;
}
int main()
{
    char w[1000], temp;
    int i, j, ln, count, flag=0;
    scanf("%s", w);
    ln = strlng(w);
    //printf("%d\n", ln);
    for(i=0; i<ln; i++)
    {
        temp = w[i];
        count = 0;
        for(j=0; j<ln; j++)
        {
            if(temp == w[j])
            {
                count++;
            }
        }
        if(count%2 != 0)
        {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <functional>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;
typedef pair<int, int> P;

#define pi 3.141592653589793)
#define mod 1000000007

int A, B, X;

void solve() {
	cin >> A >> B >> X;
	cout << (A + B >= X && A <= X ? "YES" : "NO") << endl;
}

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

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

int main(){
    int k,s;
    cin >> k >> s;
    int cnt = 0;
    for (int i = 0;i <= k;i++){
        for (int j  = 0;j <= k;j++){
                if (s - (i + j) <= k && s- (i + j) >= 0){
                    cnt++;
                }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)

num = Array.new(n)

m.times do
    s, c = gets.split.map(&:to_i)
    s -= 1

    if num[s]
        if num[s] != c
            puts -1
            exit
        end
    else
        num[s] = c
    end
end

if n != 1 && num[0] == 0
    puts -1
else
    if !num[0]
        num[0] = n == 1 ? 0 : 1
    end
    
    puts num.map{|e| e ? e : 0}.join
end


Measured memory_bytes: 1788
n, m = [int(x) for x in input().split()] # nは頂点の数、mは辺の数
g = [[] for _ in range(n)] # 隣接リスト

for _ in range(m):
    a, b = [int(x) for x in input().split()]
    g[a-1].append(b)
    g[b-1].append(a)

from collections import deque

def bfs(u):
    queue = deque([u])
    d = [None] * n # uからの距離の初期化
    d[u-1] = 0 # 自分との距離は0
    while queue:
        v = queue.popleft()
        for i in g[v-1]:
            if d[i-1] is None:
                d[i-1] = d[v-1] + 1
                queue.append(i)
    return d

d = bfs(1)
for i in range(n):
    if d[i] == 0:
        print('Yes')
    else:
        for j in g[i]:
            if d[i]-1==d[j-1]:
                print(j)
                break

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

int main(){
	int n,c,k;
	cin >> n >> c >> k;
	vector<int> t(n);
	for(int i=0; i<n; i++) cin >> t[i];
	sort(t.begin(), t.end(), greater<int>());
	int ans = 0;
	while(!t.empty()){
		int rem = t.size();
		int limit = t.back()+k;
		int tmpc = min(c, rem);
		int num;
		if(t[rem-tmpc] <= limit){
			num = tmpc;
		}else{
			for(int i=1; i<tmpc; i++){
				if(t[rem-1-i] > limit){
					num = i;
					break;
				}
			}
		}
		t.erase(t.end()-num, t.end());
		ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640