akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1e+9 + 7;

//マクロ
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 10000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main()
{
  int n;
  cin >> n;
  string s;
  cin >> s;
  map<char, vector<int>> mp;
  rep(i, n)
  {
    mp[s[i]].push_back(i);
  }
  string sample = "RGB";
  vector<int> r = mp[sample[0]];
  vector<int> g = mp[sample[1]];
  vector<int> b = mp[sample[2]];
  ll ans = 0;
  rep(i, r.size())
  {
    int R = r[i];
    rep(j, g.size())
    {
      int G = g[j];
      int mx, mn, md;
      md = INF;
      int tmpMx = max(R, G);
      int tmpMn = min(R, G);
      mx = tmpMx + tmpMx - tmpMn;
      mn = max(tmpMn - (tmpMx - tmpMn), 0);
      if ((tmpMx + tmpMn) % 2 == 0)
      {
        md = (tmpMn + tmpMx) / 2;
      }
      rep(k, b.size())
      {
        if (b[k] == mn || b[k] == mx || b[k] == md)
        {
          continue;
        }
        ans++;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}

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

int main() {
  string S;
  cin >> S;
  if (S[0] == S[1] || S[1] == S[2] || S[2] == S[3]) {
    cout << "Bad" << endl;
  }
  else {
    cout << "Good" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;
const ll MAX_L = 55;

ll buns[MAX_L];
ll paty[MAX_L];
ll total[MAX_L];

void init_burger()
{
    buns[0] = 0;
    paty[0] = 1;
    total[0] = 1;
    
    bool overflow = false;
    rep(i, 1, MAX_L)
    {
        paty[i] = (paty[i - 1] + 1) * 2  - 1;
        buns[i] = buns[i - 1] * 2  + 2;
        total[i] = paty[i] + buns[i];
    }
}

ll ans = 0;

void solve(ll n, ll x)
{
    // cout << n << ' ' << x << ' ' << ans << endl;
    if (x == 0) return;
    if (n == 0)
    {
        ++ans;
        return;
    }

    if (x >= total[n])
    {
        ans += paty[n];
    }
    else if (x >= 2 + total[n - 1])
    {
        ans += paty[n-1] + 1;
        solve(n-1, x - total[n-1] - 2);
    }
    else if (x == 1 + total[n - 1])
        ans += paty[n-1];
    else
    {
        solve(n-1, x-1);
    }
    return;
}

int main()
{
    init_burger();

    ll n, x;
    cin >> n >> x;

    solve(n, x);
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long int
using namespace std;
int main(void)
{
	int w,h,c,x;
	cin>>w>>h>>c;
	int a,b;
	if(w<h) swap(w,h);
	a=w,b=h;
	while(1) {
		if(a%b==0) {
			int ki=b;
			cout<<(w/ki)*(h/ki)*c<<endl;
			break;
		}
		x=a%b;
		a=b;
		b=x;
	}
}	

Measured memory_bytes: 3100
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	int x, y;
	cin >> x >> y;
	int sum = 0;
	if (x == 3)sum += 100000;
	else if (x == 2)sum += 200000;
	else if (x == 1)sum += 300000;

	if (y == 3)sum += 100000;
	else if (y == 2)sum += 200000;
	else if (y == 1)sum += 300000;

	if (x == 1 && y == 1)sum += 400000;
	cout << sum << endl;
	return 0;
}



Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin>>N;
  vector<vector<ll>> edge(N);
  for(int i=1;i<N;i++){
    ll a,b;
    cin>>a>>b;
    a--; b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  ll K;
  cin>>K;
  vector<pll> A(K);
  cin>>A;
  priority_queue<pll,vector<pll>,greater<pll>> Q;
  vector<ll> dp(N,MOD);
  auto dpdo=
    [&](ll u,ll p){
      if(dp[u]>p){dp[u]=p; Q.push({p,u});}
    };
  for(auto &I:A){
    I.F--;
    dpdo(I.F,I.S);
  }
  while(!Q.empty()){
    pll tp=Q.top(); Q.pop();
    if(dp[tp.S]!=tp.F){continue;}
    ll u=tp.S;
    for(auto &I:edge[u]){
      dpdo(I,dp[u]+1);
    }
  }
  for(int i=0;i<N;i++){
    for(auto &I:edge[i]){
      if(abs(dp[i]-dp[I])!=1){cout<<"No"<<endl; return 0;}
    }
  }
  for(auto &I:A){
    if(dp[I.F]!=I.S){cout<<"No"<<endl; return 0;}
  }
  cout<<"Yes"<<endl;
  for(auto &I:dp){cout<<I<<endl;}

  return 0;
}


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

int main()
{
  string a,b;
  cin>>a>>b;
  int c;
  if(a.at(0)==b.at(0)){
    c=c+1;
  }
  if(a.at(1)==b.at(1)){
    c=c+1;
  }
  if(a.at(2)==b.at(2)){
    c=c+1;
  }
  cout<<c<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int n;
	scanf("%d", &n);

	int a[3], cnt = 0;
	for (int i = 0; i < n; i++) {
		a[0] = a[1];
		a[1] = a[2];
		scanf("%d", &a[2]);

		if (i > 1) {
			if ((a[0] < a[1] && a[1] < a[2]) ||
				(a[0] > a[1] && a[1] > a[2])) cnt++;
		}
	}

	printf("%d\n", cnt);
}


Measured memory_bytes: 128
z[4000],*a=z,*b=z+2000,m,i,j;main(n){for(;scanf("%d",&n),n;m=!printf("%d\n",m))for(i=++n;i--;j=a,a=b,b=j)for(j=n;j--;)m=fmax(m,b[j]=i<n-1&&getchar()>45?1+fmin(fmin(b[j+1],a[j+1]),a[j]):0);exit(0);}

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

int main()
{
    int A, B;
    cin >> A >> B;
    A--; B--;
    vector<string> res(100, string(50, '.') + string(50, '#'));
    int i=0;
    int j=0;
    while(B>0){
        res[i][j] = '#';
        B--;
        if(j==48){ j=0; i+=2;}
        else     { j+=2;}
    }
    i=0;
    j=51;
    while(A>0){
        res[i][j] = '.';
        A--;
        if(j==99){ j=51; i+=2;}
        else     { j+=2;}
    }

    cout << "100 100" << endl;
    for(auto s : res) cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/math/common_factor_rt.hpp>

#define rep_ui(k,n)      for(ui  i = (k); i < (n); ++i)
#define rep_si(k,n)      for(int i = (k); i < (n); ++i)
#define rep_ul(k,n)      for(ul  i = (k); i < (n); ++i)
#define rep_sl(k,n)      for(ll  i = (k); i < (n); ++i)
#define rep_ui_down(k,n) for(ui  i = (k); i > (n); --i)
#define rep_si_down(k,n) for(int i = (k); i > (n); --i)
#define rep_ul_down(k,n) for(ul  i = (k); i > (n); --i)
#define rep_sl_down(k,n) for(ll  i = (k); i > (n); --i)

#define rep_uj(k,n)      for(ui  j = (k); j < (n); ++j)
#define rep_sj(k,n)      for(int j = (k); j < (n); ++j)
#define rep_uj_down(k,n) for(ui  j = (k); j > (n); --j)
#define rep_sj_down(k,n) for(int j = (k); j > (n); --j)

#define rep(k,n)         rep_ui(k,n)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
  for (auto it = vc.begin(); it != vc.end(); ++it)
  {
    if (std::next(it) == vc.end())
      os << *it;
    else
      os << *it << ' ';
  }
  return os;
}

template<class T1, class T2>
inline
std::ostream & operator<<(std::ostream & os, const std::pair<T1, T2> & p)
{
  return os << p.first << ' ' << p.second;
}

void solve(void)
{
  using std::string;
  using std::vector;
  using std::map;
  using std::pair;
  using std::cin;
  using std::cout;
  double_t X{}, T{}; std::cin >> T >> X;

  cout << T/X << '\n';
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/agc038/tasks/agc038_a

# 条件を満たすものは必ず存在するのか？ 制約により存在しそう。→かならず存在する
# 条件を満たすにはどうならべたらいいのか？
# →例えば以下のようにすれば良い
# 条件を満たす行を設定する。この行をB個繰り返す。行の01を反転させて残りを埋める(片方を固定したらもう片方は独立に決定できるイメージ)

H, W, A, B = map(int, input().split())
base = '0' * A + '1' * (W - A)
fliped = '1' * A + '0' * (W - A)

for _ in range(B):
    print(base)
for _ in range(H - B):
    print(fliped)


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

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


	int cnt = 0;
	for(int i=0;i<str.size();i++){
		if(str[i] == 'o'){
			cnt++;
		}
	}

	cnt += 15 - str.size();

	if(cnt >= 8){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}

	return 0;
}

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

int main() {
    std::string s = "";
    std::cin >> s;

    for (int i = 0; i < s.length(); i++) {
        if (i % 2 == 0) {
          std::cout << s[i];
        }
    }
    std::cout << std::endl;
    return 0;
}


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

vector<bool> H(16777216, false);

int getkey(string str) {
	int key = 0;
	for (int i = 0; i < str.size(); i++) {
		if (str[i] == 'A')
			key += 1 * pow(4, i);
		else if (str[i] == 'C')
			key += 2 * pow(4, i);
		else if (str[i] == 'G')
			key += 3 * pow(4, i);
		else
			key += 4 * pow(4, i);
	}
	return key;
}

void insert(int key) {
	H[key] = true;
}

bool find(int key) {
	return H[key];
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string s, key;
		cin >> s >> key;
		if (s == "insert") {
			insert(getkey(key));
		} else {
			cout << (find(getkey(key)) ? "yes" : "no") << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 4768
import java.util.*;

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

        if (N - 2*K + 1 >= 0) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 22612
#include <stdio.h>

int main(void){
  char c;
  scanf("%c", &c);

  if(c == 'S'){
    printf("Cloudy\n");
  }else if(c == 'C'){
    printf("Rainy\n");
  }else{
    printf("Sunny\n");
  }

  return 0;
}


Measured memory_bytes: 128
#[allow(dead_code)]
fn main() {
    let (n, r) = i::u2();
    println!("{}", if n >= 10 { r } else { r + 100 * (10 - n) });
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


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


int main()
{
    int N;
    unordered_map<string, int> map;

    cin >> N;

    string key;
    rep(i, N) {
        cin >> key;
        map[key]++;
    }

    cout << "AC x " << map["AC"] << endl;
    cout << "WA x " << map["WA"] << endl;
    cout << "TLE x " << map["TLE"] << endl;
    cout << "RE x " << map["RE"] << endl;

    return 0;
}

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

int main(){
  string S,N;
  cin >> S >> N;
  if(S[0] == N[2] && S[1] == N[1] && S[2] == N[0]){
     cout << "YES" << endl;
  }
  else{
cout << "NO" << endl;
  }
}


Measured memory_bytes: 3584
#include <iostream>
 
using namespace std;
 
int p, q, a, n;

int solve(int tp, int tq, int sa, int sn, int pre){
  if(tp==0) return 1;
  if(sn > n) return 0;
  int res=0;
  for(int i=pre;sa*i<=a;i++) if(tp*i >= tq) res+=solve(tp*i-tq, tq*i, sa*i, sn+1, i);
  return res;
}

int main(){
  while(cin >> p >> q >> a >> n && (p|q|a|n)) cout << solve(p, q, 1, 1, 1) << endl;
}

Measured memory_bytes: 864
#include <iostream>

using namespace std;

int main()
{
	int N, D, X, *pA;
	cin >> N >> D >> X;
	pA = new int[N];
	for (int i = 0; i < N; i++)
		cin >> pA[i];
	int res = 0;
	for (int i = 0; i < N; i++)
		res += ((D - 1) / pA[i] + 1);
	cout << X + res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <math.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <climits>
using namespace std;
/* Print pair */
template <typename T,typename S>
ostream & operator << (ostream &os , const pair<T,S> &v) {
    os << "(" ;
    os << v.first << "," << v.second << ")" ;
    return os ;
}
/* Print vector */
template <typename T>
ostream & operator << (ostream &os , const vector<T> &v) {
    os << "[" ;
    int sz = v.size() ;
    for(int i = 0 ; i < sz ; ++i) {
        os << v[i] ;
        if(i!=sz-1)os << "," ;
    }
    os << "]\n" ;
    return os ;
}
/* Print set */
template <typename T>
ostream & operator << (ostream &os , const set<T> &v) {
    T last = *v.rbegin() ;
    os << "[" ;
    for(auto it : v) {
        os << it  ;
        if(it != last) os << "," ;
    }
    os << "]\n" ;
    return os ;
}
/* Print Map */
template <typename T,typename S>
ostream & operator << (ostream &os , const map<T,S> &v) {
    for(auto it : v) {
        os << it.first << " : " << it.second << "\n" ;
    }
    return os ;
}
//debug
#define TRACE

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



int n;
long long s[555555];
long long a[555555];
long long ans;
int main(){;
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		s[i]=s[i-1]+x;
		a[i]=a[i-1]^x;
	}
	int l=1;
	for (int r=1;r<=n;r++){
		for (;(s[r]-s[l-1])!=(a[r]^a[l-1]);l++);
		ans+=r-l+1;
	}
	printf("%lld\n",ans);
} 


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

int main(){
  string s;
  cin >> s;
  if( s.at(2) == s.at(3) && s.at(4) == s.at(5) ){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 101

void insertionSort(int *, int);

int main(){
  int i, n, A[N];
  scanf("%d", &n);
  for(i=0; i<n; i++)scanf("%d", &A[i]);

  insertionSort(A, n);

  return 0;
}

void insertionSort(int *A, int n){
  int i, j, v;

  for(i=0; i<n; i++){
    printf("%d", A[i]);
    if(i == n-1)printf("\n");
    else printf(" ");
  }
  
  for(i=1; i<n; i++){
    v = A[i];
    j = i-1;
    while(j >= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;

    for(j=0; j<n; j++){
      printf("%d", A[j]);
      if(j == n-1)printf("\n");
      else printf(" ");
    }
    
  }
}



Measured memory_bytes: 2036
/*
	Auth: Loxilante
	Time: 2020/09/26
	Prog: ACLB-A
	Lang: cpp
*/
#include <bits/extc++.h>
#define rep(i, l, r) for(int i = l; i < r; i++)
#define hrp(i, l, r) for(int i = l; i <= r; i++)
#define rev(i, r, l) for(int i = r; i >= l; i--)
#define ms(n, t) memset(n, t, sizeof(n))
#define pb push_back
#define int ll
#ifndef JOEON
#define D(...) 97
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn = int> inline tn next(void) { tn k; cin>>k; return k; }
signed main(void)
{
	clock_t Begin = clock();

	#ifdef JOEON
//		freopen("C:\\Users\\Joeon\\Desktop\\IN.txt", "r", stdin);
//		freopen("C:\\Users\\Joeon\\Desktop\\OUT.txt", "w", stdout);
	#endif
	
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n = next();
	rep(i, 0, n) cout<<"ACL";
	cout<<endl;
	
	clock_t InputFinished = clock();
	
	
	
	clock_t End = clock();
	
	D((double)(End-Begin)/CLOCKS_PER_SEC);
	D((double)(End-InputFinished)/CLOCKS_PER_SEC);
	
	return 0;
}
/*

 */

Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main
{
	public static void main(String[] args) {
		new Thread(null, new Runnable() {
			public void run() {
                solve();
            }
        }, "1", 1 << 26).start();
	}
	static void solve () {
		FastReader fr =new FastReader();	PrintWriter op =new PrintWriter(System.out);
 
 		int n =fr.nextInt() ,a[] =new int[n+1] ,i =1 ,j =-1 ,k ,cyc[] =new int[n+2] ;
 		long ct =fr.nextLong() ,len ;	boolean mrk[] =new boolean[n+1] ;
 		
 		for (k =1 ; k<=n ; ++k)	a[k] =fr.nextInt() ;
 		
 		while (!mrk[i]) {
 			cyc[++j] =i ;	mrk[i] =true ;	i =a[i] ;
 		}
 		for (k =0 ; k<=j ; ++k) {
 			if (cyc[k]==i)	break;
 		}
 		len =j-k+1 ;
 		
 		if (ct <= k)	op.println(cyc[(int)ct]) ;
 		else {
 			ct -= k ;	ct %= len ;	k += ct ;
 			op.println(cyc[k]) ;
 		}
		op.flush();	op.close();
	}
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br =new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st==null || (!st.hasMoreElements())) 
			{
				try
				{
					st =new StringTokenizer(br.readLine());
				}
				catch(IOException e)
				{
					e.printStackTrace();
				}
				
			}
			return st.nextToken();
		}

		String nextLine() {
			String str ="";

			try
			{
				str =br.readLine();
			}
			catch(IOException e)
			{
				e.printStackTrace();
			}

			return str;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next()) ;
		}
	}
}

Measured memory_bytes: 55428
import sys
import math
import itertools
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
import bisect

N = i()
T,A = I()
H = l()
h = copy(H)
H.sort()
B = (T-A)/0.006
i = bisect.bisect_left(H,B)
if  abs((T-H[i-1]*0.006)-A)> abs(A-(T-H[i]*0.006)):
    print(h.index(H[i])+1)
else:
    print(h.index(H[i-1])+1)

Measured memory_bytes: 5056
use proconio::input;
use proconio::marker::{Bytes, Chars};

// x ** n % mods を求める
pub fn mod_pow(x: i64, n: i64, mods: i64) -> i64 {
    if n == 0 {
        return 1;
    }
    let mut res = mod_pow(x * x % mods, n / 2, mods);
    if n % 2 == 1 {
        res = res * x % mods;
    }
    return res;
}

// (1/n) % mods を求める
pub fn mod_inv(n: i64, mods: i64) -> i64 {
    return mod_pow(n, mods-2, mods);
}

// nCk % mods を求める
pub fn mod_comb(n: i64, k: i64, mods: i64) -> i64 {
    let sum1 = (n-k+1..n+1).fold(1, |ac, x| ac * x % mods);
    let sum2 = (1..k+1).fold(1, |ac, x| ac * x % mods);
    return sum1 * mod_inv(sum2, mods) % mods;
}

// nCk の組み合わせを列挙する
pub fn combination(n: usize, k: usize) -> Vec<Vec<usize>> {
    let mut ans = Vec::new();
    if k == 1 {
        for i in 1..n+1 {
            let mut tmp = Vec::new();
            tmp.push(i);
            ans.push(tmp);
        }
    }
    else {
        for iter in combination(n-1, k-1) {
            let max = iter.iter().max().unwrap();
            for j in *max+1..n+1 {
                let mut tmp = iter.clone();
                tmp.push(j);
                ans.push(tmp);
            }
        }
    }
    ans
}


fn main() {
    input!{
        a: usize,
        mut b: usize,
        mut c: usize,
        k: usize,
    }
    let mut count = 0;
    while b <= a {
        b *= 2;
        count += 1;
    }
    while c <= b {
        c *= 2;
        count += 1;
    }
    if count <= k {
        println!("Yes");
    }
    else {
        println!("No");
    }
}


Measured memory_bytes: 2160
// In the name of Allah the Most Merciful.

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

typedef long long ll;

vector<int>edges[200005] , store , v;
int cur = 0 , st[200005] , en[200005];
ll tree[800005] , lazy[800005];

void dfs(int u , int par = -1)
{
    cur++;
    st[u] = cur;
    for(auto v : edges[u]){
        if(v!=par)dfs(v , u);
    }
    en[u] = cur;
}

void build(int node , int st , int en)
{
    if(st==en){
        tree[node] = 0;
        return ;
    }
    int mid = (st+en)/2;
    build(2*node , st , mid);
    build(2*node+1 , mid+1 , en);
    tree[node] = tree[2*node] + tree[2*node+1];
}

void update(int node, int start, int end, int l, int r, ll val)
{
    if(lazy[node] != 0)
    {
        tree[node] += (end - start + 1) * lazy[node];
        if(start != end)
        {
            lazy[node*2] += lazy[node];
            lazy[node*2+1] += lazy[node];
        }
        lazy[node] = 0;
    }
    if(start > end or start > r or end < l)
        return;
    if(start >= l and end <= r)
    {

        tree[node] += (end - start + 1) * val;
        if(start != end)
        {
            lazy[node*2] += val;
            lazy[node*2+1] += val;
        }
        return;
    }
    int mid = (start + end) / 2;
    update(node*2, start, mid, l, r, val);
    update(node*2 + 1, mid + 1, end, l, r, val);
    tree[node] = tree[node*2] + tree[node*2+1];
}

ll query(int node , int st ,int en , int idx)
{
    if(lazy[node] != 0)
    {
        tree[node] += (en - st + 1) * lazy[node];
        if(st != en)
        {
            lazy[node*2] += lazy[node];
            lazy[node*2+1] += lazy[node];
        }
        lazy[node] = 0;
    }
    if(st==en){
        return tree[node];
    }
    int mid = (st+en)/2;
    if(idx<=mid)return query(2*node , st , mid , idx);
    return query(2*node+1 , mid+1 , en , idx);
}

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

    int n , q;
    cin >> n >> q;
    for(int i=0;i<n-1;i++){
        int in1 , in2;
        cin >> in1 >> in2;
        edges[in1].emplace_back(in2);
        edges[in2].emplace_back(in1);
    }
    dfs(1);
    build(1 , 1 , n);
    while(q--){
        ll in1 , in2;
        cin >> in1 >> in2;
        update(1 , 1 , n , st[in1] , en[in1] ,  in2);
    }
    for(int i=1;i<=n;i++){
        if(i>1)cout << " ";
        cout << query(1 , 1 , n , st[i]);
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 36736
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main()
{
	int R[MAX], n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> R[i];
	}

	int maxv = -2000000000;
	int minv = R[0];
	
	for (int i = 1; i < n; i++) {
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}
	cout << maxv << endl;

    return 0;
}

Measured memory_bytes: 3876
#include<stdio.h>

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

Measured memory_bytes: 600
#include<stdio.h>
#include<ctype.h>
#include<string.h>
int main(void){
    char search[21], word[21];
    int count = 0;
    int i;
    
    scanf("%s", search);
    while(1){
        scanf("%s", word);
        if(strcmp(word, "END_OF_TEXT") == 0) break;
        for(i = 0; word[i]!='\0'; i++){
            word[i] = tolower(word[i]);
        }
        if(strcmp(word, search) == 0){
            count++;
        }
    }
    printf("%d\n", count);
    return 0;
}


Measured memory_bytes: 2596
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);   
bitset<4000003> b;
int a[12345];
int main(){
    std::ios::sync_with_stdio(false);
    int n,i,sumi=0;
    cin>>n;
    rep(i,n){
    	cin>>a[i];
    	sumi+=a[i];
    }
    sumi++;
    sumi/=2;
    b[0]=1;
    rep(i,n){
    	b|=b<<a[i];
    }
    while(1){
    	if(b[sumi]){
    		cout<<sumi<<endl;
    		return 0;
    	}
    	sumi++;
    }

    return 0;  
    
}



Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <random>
#include <string>
#include <bitset>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <cstring>
#include <cstdlib>
#include <cctype>

#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPR(i, n) for(int i = n; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define FORR(i, m, n) for(int i = m; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define INF 999999999

using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

llong pow(int x, int n) {
    llong ans = x;
    if (n == 0) return 1;

    for(int i = 0; i < n - 1; i++) {
        ans *= x;
    }

    return ans;
}

void swap(int *X, int *Y){
    int t = *X; *X = *Y; *Y = t;
}

int main() {
    int h, w, d, q, a;
    int ans[90001];
    vector<pair<int, pair<int, int> > > M;
    cin >> h >> w >> d;
    REP(i, h) {
        REP(j, w) {
            cin >> a;
            M.push_back(make_pair(a, make_pair(i, j)));
        }
    }

    sort(M.begin(), M.end());
    for (int j = d + 1; j <= h * w; ++j) {
        ans[j] = ans[j - d] + abs(M[j - 1].second.first - M[j - 1 - d].second.first) +  abs(M[j - 1].second.second - M[j - 1 - d].second.second);
    }

    cin >> q;
    int l, r;
    REP(i, q) {
        cin >> l >> r;
        cout << ans[r] - ans[l] << endl;
    }

    return 0;
}

Measured memory_bytes: 2676
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll x, y;
  cin >> x >> y;
  if (abs(x - y) <= 1) puts("Brown");
  else puts("Alice");
  return 0;
}


Measured memory_bytes: 256
using namespace std;

#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define ll long long
#define ii pair<int, int>
#define vi vector<int>

#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FOD(i, b, a) for (int i = b; i >= a; i--)

const int N = 2e5 + 10;
int n, m;
int a[N][3];
int main() {
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    scanf("%d %d", &n, &m);
    while (m--) {
        int u, v;
        scanf("%d %d", &u, &v);
        if (u >v) swap(u, v);
        if (u==1) a[v][0] = 1;
        if (v==n) a[u][1] = 1;
    }
    for (int i = 2; i < n; i++)
    if (a[i][0] && a[i][1]) {
        printf("POSSIBLE");
        return 0;
    }
    printf("IMPOSSIBLE");
    return 0;
}
/**/


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  char N;
  cin >> N;
  if (N == 'a' || N == 'i' || N == 'u' || N == 'e' || N == 'o')
    COUT("vowel");
  else
    COUT("consonant");
  return 0;
}

Measured memory_bytes: 3656
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 998244353;
long long INF = 1000000000000000;
#define MAX_V 330

typedef long long ll;

ll spow(ll a, ll b) {
  if (b == 1) return a % MOD;
  if (b == 0) return 1;
  ll c = spow(a, b / 2);
  if (b % 2 == 0) return (c * c) % MOD;
  else return (a * (c * c % MOD)) % MOD;
}

int main(void) {
  ll n; cin >> n;
  ll d[100010], c[100010] = {}, ma = 0;
  rep(i, n) {
    cin >> d[i];
    ma = max(ma, d[i]);
    c[d[i]]++;
  }
  if (!(c[0] == 1 && d[0] == 0)) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = 1;
  for (int i = 1; i <= ma; i++) {
    if (c[i - 1] == 0 || c[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
    ans *= spow(c[i - 1], c[i]);
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
void solve()
{
	int s, l;
	scanf("%d %d", &s, &l);
	if(l>=s)
	{
		printf("unsafe\n");
	}
	else
	{
		printf("safe\n");
	}
}
int main()
{
	solve();
	return 0;
}

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

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

  int n;
  cin >> n;
  vector<int> c(n - 1), s(n - 1), f(n - 1);

  for (int i = 0; i < n - 1; i++) {
    cin >> c.at(i) >> s.at(i) >> f.at(i);
  }

  for (int i = 0; i < n - 1; i++) {
    int pastTime = s.at(i) + c.at(i);
    for (int j = i + 1; j < n - 1; j++) {
      pastTime = s.at(j) < pastTime ? pastTime : s.at(j);

      int freq = f.at(j);

      int waitTrainTime = pastTime % freq == 0
                              ? 0
                              : (((pastTime + freq) / freq) * freq) - pastTime;
      pastTime += waitTrainTime + c.at(j);
    }

    cout << pastTime << endl;
  }
  cout << 0 << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	int k;
	string s;
	cin>>k>>s;
	if(s.length()<=k) cout<<s<<endl;
	else{
		for(int i=0;i<k;i++){
			cout<<s[i];
		}
		cout<<"...";
	}
	return 0;
} 

Measured memory_bytes: 3588
#include "bits/stdc++.h"
using namespace std;
 
int main() {
    int n,m;
    cin >> n >> m;
    int left = 1,right = n;
    for(int i = 0;i<m;i++){
        int l,r;
        cin >> l >> r;
        if(l > left)left = l;
        if(r< right)right = r;
    }
  	if(right < left)cout << 0;
    else cout << right - left + 1;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define    For(i,n) for(int i=0;i<n;i++)
#define    fors(i,s) for(int i=0;i<s.size();i++)
#define    nl     "\n"
#define    End    return 0
#define    gt     greater<int>()
#define    ll     long long int

int main()
{
   int n,c=0;
    cin>>n;
    int a[n];
    for(int i=1;i<=n;i++)
    {
       cin>>a[i];
        if(i%2==1 and (a[i]*a[i])%2==1)c++;
    }
    cout<<c;

}


Measured memory_bytes: 3632
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	var n int
	fmt.Scan(&n)

	a := make([]int, n)
	b := make([]int, n)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	for i := 0; i < n; i++{

		sc.Scan()
		x, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		y, _ := strconv.Atoi(sc.Text())
		a[i] = x+y
		b[i] = x-y
	}

	sort.Ints(a)
	sort.Ints(b)

	ansa := a[n-1] - a[0]
	ansb := b[n-1] - b[0]

	fmt.Println(max(ansa, ansb))
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


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

int solve(int n) {
	for (int i = 1; i < 11; i++) {
		if(1000*i-n>0) {
			return 1000*i-n;
			break;
		}
		else if(1000*i-n == 0 ){
			return 1000*i-n;
			break;
		}
	}	
}

int main() {
	int n;
	cin >> n;
	cout << solve(n) << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,a1,a2,t;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    a1=max(a,c);
    a2=min(b,d);
    t=a2-a1;
    if(t>0)
        printf("%d",t);
    else
        printf("0");
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
#include<cmath>
#include<stack>
#include<tuple>
#include<numeric>
#include<cassert>

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
#define DEBUG false

using namespace std;

using ll = long long;
using P = pair<int,int>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60;
const int MAX_N=302;
const ll lmod = 1e9+7;

struct uft{
  int par[MAX_N],rank[MAX_N],size[MAX_N];
  void init(int n){
    rep(i,n){
      par[i]=i;
      rank[i]=0;
      size[i]=1;
    }
    return ;
  }
  int find(int x){
    if(par[x]==x) return x;
    else  return par[x]=find(par[x]);
  }
  void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)  return ;
    if(rank[x]<rank[y]){
      par[x]=y;
    }else{
      par[y]=x;
      if(rank[x]==rank[y])  ++rank[x];
    }
    size[x]=size[y]=size[x]+size[y];
    return ;
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
};

uft u;

struct edge{ll cost;int to;};
vector<edge> e1[MAX_N];
ll d1[MAX_N];

void dijkstra(vector<edge> graph[],ll d[],int start){
  priority_queue<P,vector<P>,greater<P>> que;
  fill(d,d+MAX_N,INF);
  d[start]=0;
  que.push(P(0,start));
  while(!que.empty()){
    P p=que.top(); que.pop();
    int v=p.second; //行き先
    if(d[v]<p.first)  continue;
    rep(i,graph[v].size()){
      edge e=graph[v][i];
      if(d[v]+e.cost<d[e.to]){
        d[e.to]=d[v]+e.cost;
        que.push(P(d[e.to],e.to));
      }
    }
  }
  return ;
}


ll d[MAX_N][MAX_N];
int N;
using T = pair<ll,P>;
priority_queue<T,vector<T>,greater<T>> que;

int main(){
  cin >> N ;
  rep(i,N) rep(j,N){
    ll a;
    scanf("%lld",&a);
    if(i<j){
      que.push(T(a,P(i,j)));
    }
    d[i][j] = a;
  }
  u.init(N);
  ll ans = 0;
  while(!que.empty()){
    ll a;
    P p;
    int i,j;
    tie(a,p) = que.top();
    que.pop();
    tie(i,j) = p;
    if(!u.same(i,j)){
      ans += a;
      edge ee1,ee2;
      ee1.cost = a; ee2.cost = a;
      ee1.to = i; ee2.to = j;
      e1[j].pb(ee1); e1[i].pb(ee2);
    }else{
      dijkstra(e1,d1,i);
      if(a>d1[j]){
        cout << "-1" << endl;
        return 0;
      }else if(a<d1[j]){
        ans += a;
        edge ee1,ee2;
        ee1.cost = a; ee2.cost = a;
        ee1.to = i; ee2.to = j;
        e1[j].pb(ee1); e1[i].pb(ee2);
      }
    }
    u.unite(i,j);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
#define rep(it,st,en) for(int it=(st);it<(int)(en);++it)
#define allof(c) (c).begin(), (c).end()
#define mt make_tuple
#define mp make_pair
#define pb push_back
#define X first
#define Y second
typedef long long int ll; 
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
const int INF=(int)1e9; 
const double EPS=(ld)1e-7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    if(s.substr(0,4) == "YAKI") cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
void ans(bool b){ cout << (b ? "Yes" : "No") << endl; }
void ans2(bool b){ cout << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill((T*)array, (T*)(array+N), val);
}
template<typename T> void vdeb(T v){
    cout << "#vector set debug" << endl;
    for(auto vv : v) cout << vv << " ";
    cout << endl;
}
template<typename T1, typename T2> void adeb(T1 arr[], T2 n){
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}
template<typename T1> void mdeb(T1 mp){
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};


ll dp[60][60][2510];

class CTakAndCards {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n, a;
        int x[100];
        in >> n >> a;
        rep(i, n){
            in >> x[i];
        }

        Fill(dp, 0);
        reps(i, 0, n){
            dp[i][0][0] = 1;
        }
        reps(i, 0, n-1){
            reps(j, 1, n){
                reps(k, 1, 2500){
                    dp[i + 1][j][k] += dp[i][j][k];
                    if (k - x[i] >= 0) {
                        dp[i + 1][j][k] += dp[i][j - 1][k - x[i]];
                    }
                }
            }
        }

        ll res = 0;
        reps(j, 1, n){
            res += dp[n][j][j*a];
            //out << j sp dp[n][j][j*a] << endl;
        }
        out << res << endl;

        //adeb(dp[n][1], 12);
	}
};


int main() {
	CTakAndCards solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 70784
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

static const ll MAX = 100001;

ll n, a[MAX+1], l[MAX];

int main() {
    
    ll n;
    cin >> n;
    for (ll i=0;i<n;i++){
        cin >> a[i];
    }
    l[0] = a[0];
    ll length = 1;

    for (ll i=1;i<n;i++){
        if (l[length-1] < a[i]){
            l[length++] = a[i];
        }else{
            *lower_bound(l, l+length, a[i]) = a[i];
        }
    }

    cout << length << endl;

}





Measured memory_bytes: 4648
from sys import stdin
import collections
def ip(): return [int(i) for i in stdin.readline().split()]
def sp(): return [str(i) for i in stdin.readline().split()]

# 4 6
# 1 2
# 1 3
# 1 4
# 2 3
# 2 4
# 3 4

def find(d,x):
    root = x
    while root != d[root]:
        root = d[root]

    while x != root:
        nxt = d[x]
        d[x] = root
        x = nxt
    return d,root


def merge(d,s,x,y):
    d,x = find(d,x)
    d,y = find(d,y)
    if x == y: return d,s
    if s[x] > s[y]:
        s[x] += s[y]
        d[y] = d[x]
    else:
        s[y] += s[x]
        d[x] = d[y]
    return d,s


n,m = ip()
d = {i+1: i+1 for i in range(n)}
s = {i+1: 1 for i in range(n)}
seen = set()
for _ in range(m):
    # print(d,s)
    x,y = ip()
    if (x,y) in seen or (y,x) in seen: continue
    seen.add((x,y))
    seen.add((y,x))
    d,s = merge(d,s,x,y)
ans = 0
for i in s:
    ans = max(ans, s[i])
print(ans)


Measured memory_bytes: 109300
import scala.io.StdIn.readLine

object Main {
  def main(args: Array[String]) {
    val l = readLine.split(" ").map(_.toInt)
    if (l(0) == l(1)) println("a == b")
    else if
    (l(0) < l(1)) println("a < b")
    else println("a > b")
  }

}

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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

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>; 
typedef long long  ll;
typedef vector<ll> VL;
typedef pair<ll,ll> PLL;
#define pb push_back
#define F first
#define S second
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(ll i=x;i<y;i++)
#define frr(i,x,y) for(ll i=x-1;i>=y;i--)
#define inf 10000000000000000
const ll mod=998244353;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

void solve()
{
	ll n;
	cin>>n;
	ll sum=n*(n+1)/2;
	fr(i,1,n+1)
	{
		if(i%3==0||i%5==0)
		{
			sum-=i;
		}
	}
	cout<<sum<<endl;
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
	solve();
	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
template <class T>
using Vec2 = vector<vector<T>>;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <class T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <class T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
ll pow2(const int n){return (1LL << n);}
void co() { cout << endl; }
template <class Head, class... Tail>
void co(Head&& head, Tail&&... tail) {
    cout << head << ' ';
    co(forward<Tail>(tail)...);
}
void ce() { cerr << endl; }
template <class Head, class... Tail>
void ce(Head&& head, Tail&&... tail) {
    cerr << head << ' ';
    ce(forward<Tail>(tail)...);
}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const int n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18L+1;
constexpr ll MOD = 1e9L+7;
constexpr ll MOD_N = 998244353;
constexpr ld EPS = 1e-11;
const double PI = acos(-1);

int main(void){
    ll h, w, m;
    cin >> h >> w >> m;
    set<P> st;
    Vec cnt1(h), cnt2(w);
    rep(i, m){
        ll x, y;
        cin >> x >> y;
        --x, --y;
        cnt1[x]++;
        cnt2[y]++;
        st.insert({x, y});
    }

    Vec maxh, maxw;
    ll max1 = -LINF, max2 = -LINF;
    rep(i, h) chmax(max1, cnt1[i]);
    rep(i, w) chmax(max2, cnt2[i]);
    rep(i, h){
        if (cnt1[i] == max1) maxh.push_back(i);
    }
    rep(i, w){
        if (cnt2[i] == max2) maxw.push_back(i);
    }

    if(maxh.size() * maxw.size() > m){
        co(max1 + max2);
        return 0;
    }

    for(ll i : maxh){
        for(ll j : maxw){
            if(st.find({i, j}) == st.end()){
                // ce(i, j);
                co(max1 + max2);
                return 0;
            }
        }
    }

    co(max1 + max2 - 1);
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  int l = (s.length() - 1) / 2;
  string rs = s, fs = s.substr(0, l), ss = s.substr(l + 1, l), rfs = fs, rss = ss;
  reverse(rs.begin(), rs.end());
  reverse(rfs.begin(), rfs.end());
  reverse(rss.begin(), rss.end());
  cout << ((s == rs && fs == rfs && ss == rss) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3608