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

using namespace std;
const int MAX=3000+3;
typedef long long ll;
int N;
ll a[MAX], dp[MAX][MAX];

//ll solve(int p, int q, int t=0) {
//  if(p>q) return 0;
//
//  if(dp[p][q] != -1) {
//    return dp[p][q];
//  }
//  if(t) {
//    return dp[p][q] = min(solve(p+1, q, 0) - a[p], solve(p, q-1, 0) - a[q]);
//  } else {
//    return dp[p][q] = max(solve(p+1, q, 1) + a[p], solve(p, q-1, 1) + a[q]);
//  }
//}

ll solve(int l, int r, int t){

    if(l > r) return 0;
    ll &ret=dp[l][r];
    if(ret!=-1) return ret;

    if(t){
        ret=min(solve(l+1, r, 0)-a[l], solve(l, r-1, 0)-a[r]);
    } else {
        ret=max(solve(l+1, r, 1)+a[l], solve(l, r-1, 1)+a[r]);
    }

    return ret;

}


int main(){
    scanf("%d",&N);
    memset(dp, -1, sizeof(dp));
    for(int i=0;i<N;i++) scanf("%lld",&a[i]);
    printf("%lld\n",solve(0, N-1, 0));
    return 0;
}


Measured memory_bytes: 74496
#include <stdio.h>
int main() {
	int n, a[100000], cnt = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < n; i++) {
		if (a[a[i] - 1] - 1 == i) {
			cnt++;
		}
	}
	printf("%d\n", cnt / 2);
	return 0;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main(){
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    if (a + b <= 2 * c) cout << a * x + b * y << endl;
    else{
        int v1 = 2 * c * min(x, y) + abs(x - y) * (x > y?a:b);
        int v2 = 2 * c * max(x, y);
        cout << min(v1, v2) << endl;
    }
}

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

#define MAX 100005
#define NIL -1

struct Node{int p, l, r;}; //構造体 parent, left, right (left-child right-sibling representation)

Node T[MAX];
int n, D[MAX];

void print(int u){ //uの節点番号, 親番号, 深さ, 節点の種類, 子のリストを出力する関数
    int i, c;
    cout << "node " << u << ": "; //uの節点番号を出力
    cout << "parent = " << T[u].p << ", "; //uの親番号を出力
    cout << "depth = " << D[u] << ", "; //uの深さを出力
    
    if(T[u].p == NIL) cout << "root, "; //親が存在しないということは, 根である
    else if(T[u].l == NIL) cout << "leaf, "; //最も左の子が存在しないということは, 葉である
    else cout << "internal node, "; //根でも葉でもないということは, 内部である
    
    cout << "[";
    
    for(i = 0, c = T[u].l; c != NIL; i++, c = T[c].r){ //c!=NILならば, まだ右側に子がいる, c = T[c].rとすれば, cは右隣の子を表すことになる
        if(i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
    
}


int rec(int u, int p){ //recursiveに深さを求めていく
    D[u] = p;
    if(T[u].r != NIL) rec(T[u].r, p); //右の兄弟に同じ深さを設定
    if(T[u].l != NIL) rec(T[u].l, p+1); //最も左の子に自分の深さ+1を設定
    
}

int main(){
    int i, j, d, v, c, l, r;
    cin >> n; //節点の個数を入力
    
    for(i = 0; i < n; i++) T[i].p = T[i].l = T[i].r = NIL;
    
    for(i = 0; i < n; i++){ //
        
        cin >> v >> d; //vは節点番号を表し, dはvの子の数を表す
        
        for(j = 0; j < d; j++){
            cin >> c;
            
            if(j == 0) T[v].l = c; //０番目の子は一番左に来る
            else T[l].r = c; //それ以外の場合はcが一番右に来る
            l = c;
            T[c].p = v; //cの親はvである
        }
    }
    
    int s;
    for(i = 0; i < n; i++){
        if(T[i].p == NIL) s = i;
        
    }
    
    rec(s,0);
    
    for(i = 0; i < n; i++) print(i);
    return 0;
}


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

int main()
{
    int n,indx;
    double v,t,a,m=1e5+5;
    cin>>n>>t>>a;
    for(int i=1;n--;i++)
    {
        cin>>v;
        double d=t-(v*0.006);
        if(m>abs(d-a))
        {
            m=abs(d-a);
            indx=i;
        }
    }
    cout<<indx<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <functional>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define rem(i,n,x) for(int i=n;i>x;i--)
#define SORT(x) sort(x.begin(),x.end())
#define REV(x) reverse(x.begin(),x.end())
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define setp(x) setprecision(x)
using LL = long long;
using ULL = unsigned long long;

LL sub_min(LL a, LL b) {
	while (a != b && a != 1) {
		if (a < b) swap(a, b);
		a %= b;
		if (a == 0) return b;
	}
	return a;
}

int main() {
	int n;
	cin >> n;
	vector<LL> a(n);
	rep(i, 0, n) cin >> a[i];

	SORT(a);
	LL hp_min = a[0];
	rep(i,1,n) {
		LL num = sub_min(hp_min, a[i]);
		hp_min = min(hp_min, num);
	}

	cout << hp_min << endl;

	return 0;
}

Measured memory_bytes: 1024
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 10e9;
const int MAX_V = 201;

void ChristmasEve(){
	int k, n;
	cin >> n >> k;
	int t[100010];

	for (size_t i = 0; i < n; i++)
	{
		cin >> t[i];
	}
	sort(t, t + n);

	int res = INF;
	for (size_t i = 0; i < n - k + 1; i++)
	{
		int rem = t[i + k - 1] - t[i];
		res = min(res, rem);
	}
	cout << res << endl;
}
int main() {
	ChristmasEve();
	return 0;
}



Measured memory_bytes: 640
import sys
a = str(input())
for i in range(len(a)-1):
    if(a[i+1] == a[0]):
        t = i+1
        break
    t = 8

if(t == 1):
    if(a[2] == a[3] and a[1] != a[2]):
        print("Yes")
    else:
        print("No")
elif(t == 2):
    if(a[1] == a[3] and a[0] != a[1]):
        print("Yes")
    else:
        print("No")
elif(t == 3):
    if(a[1] == a[2] and a[0] != a[1]):
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,T,A; cin >> N >> T >> A;
    vector<double> H(N);
    for(int i=0;i<N;i++){
        cin >> H[i];
    }
    int ans = 1;
    double temp = abs(T-H[0]*0.006-A);
    for(int i=1;i<N;i++){
        if(temp > abs(T-H[i]*0.006-A)){
            temp = abs(T-H[i]*0.006-A);
            ans = i+1;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    long ans = 0;
    Deque<Long> q = new ArrayDeque<Long>();
    for(int i=1;i<10;i++){
      q.add((long)i);
    }
    int count = 0;
    long x = 0;
    while(true){
      x = q.poll();
      if(x%10!=0){
        q.add(x*10+(x%10)-1);
      }
      q.add(x*10+x%10);
      if(x%10!=9){
        q.add(x*10+x%10+1);
      }
      count += 1;
      if(count==k){
        ans = x;
        break;
      }
    }

    System.out.println(ans);



  }
}

Measured memory_bytes: 30932
#include <iostream>
#include <iomanip>
#include <climits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <unordered_map>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <random>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#define INF (int)1e8
#define _INF (int)-1e8
#define INFLL (long long)1e15
#define _INFLL (long long)-1e15
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> P;

/*******************************************************/

//solve x, y s.t. mx+ny=gcd(m,n)
class Extended_Euclid {
private:
	ll m, n;
	vvll mx_multiply(vvll mx1, vvll mx2) {
		vvll ret(mx1.size(), vll(mx2[0].size(), 0));
		Loop(i, mx1.size()) {
			Loop(j, mx1[0].size()) {
				Loop(k, mx2[0].size()) {
					ret[i][j] += mx1[i][k] * mx2[k][j];
				}
			}
		}
		return ret;
	}
public:
	ll x, y, gcd;
	Extended_Euclid(ll M, ll N) {
		m = M;
		n = N;
		vll r(100), k(100);
		bool swapflag = false, mflag = false, nflag = false;
		if (m < n) { swap(m, n); swapflag = true; }
		if (m < 0) { m *= -1; mflag = true; }
		if (n < 0) { n *= -1; nflag = true; }
		r[0] = m;
		r[1] = n;
		int h = 1;
		while (1) {
			k[h - 1] = r[h - 1] / r[h];
			r[h + 1] = r[h - 1] % r[h];
			if (r[h + 1] == 0) break;
			h++;
		}
		gcd = r[h];
		vvll mx(2, vll(2, 1));
		mx[0][0] = 0;
		mx[1][1] = (-1) * k[0];
		Loop1(i, h - 1) {
			vvll _mx(2, vll(2, 1));
			_mx[0][0] = 0;
			_mx[1][1] = (-1) * k[i];
			mx = mx_multiply(_mx, mx);
		}
		x = mx[0][0];
		y = mx[0][1];
		if (nflag) { n *= -1; y *= -1; }
		if (mflag) { m *= -1; x *= -1; }
		if (swapflag) { swap(m, n); swap(x, y); }
	}
};

//A[x] = x! O(x)
vll mod_factlist(ll x, ll mod) {
	if (x < 0) return{};
	else {
		vll ret((int)x + 1);
		ret[0] = 1;
		Loop1(i, (int)x) ret[i] = ret[i - 1] * i % mod;
		return ret;
	}
}

//x^y O(log y)
ll mod_pow(ll x, ll y, ll mod) {
	if (y == 1) return x;
	else {
		ll ans = mod_pow(x, y / 2, mod);
		ans = ans * ans % mod;
		if (y % 2 == 1) ans = ans * x % mod;
		return ans;
	}
}

//???1/x O(log x)
ll mod_inv(ll x, ll mod) {
	Extended_Euclid ee(x, mod * (-1));
	ll ret = ee.x;
	if (ret < 0) ret += (ret / mod*(-1) + 1) * mod;
	return ret;
}

int main() {
	ll a, b; cin >> a >> b;
	Extended_Euclid ee(a, b);
	cout << ee.x << " " << ee.y << endl;
}

Measured memory_bytes: 3160
#include<iostream>
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;
const int N=200005;
int n,k,a[N],tot,ans;
map<int,int>mp;
struct qwe
{
	int h,s;
}b[N];
bool cmp(const qwe &a,const qwe &b)
{
	return a.s<b.s;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(!mp[a[i]])
			b[++tot].h=a[i];
		mp[a[i]]++;
	}
	for(int i=1;i<=tot;i++)
		b[i].s=mp[b[i].h];
	sort(b+1,b+1+n,cmp);
	for(int i=1;i<=n-k;i++)
		ans+=b[i].s;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 11904
#include <stdio.h>
int main(){
    int a;
    int b;
    int c;
    scanf("%d",&a);
    
        b=a%10;
        if(b==9){
            printf("Yes");
            
        }
        else if((a-b)%9==0){
             printf("Yes");
            
        }
        else{
             printf("No");
            
        }

    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> data(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> data.at(i).at(j);
    }
  }

  vector<bool> latitude(W,0);
  vector<bool> longitude(H,0);
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if(data.at(i).at(j) == '.') {
        if(j == W - 1) longitude.at(i) = 1;
      }
      else break;
    }
  }
  
  for (int j = 0; j < W; j++) {
    for (int i = 0; i < H; i++) {
      if(data.at(i).at(j) == '.') {
        if(i == H - 1) latitude.at(j) = 1;
      }
      else break;
    }
  }
  
  for (int i = 0; i < H; i++) {
    if (longitude.at(i) == 1);
    else {
      for (int j = 0; j < W; j++) {
        if (latitude.at(j) == 1);
        else cout << data.at(i).at(j);
      }
    cout << endl;
    }
  }
}

Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod=998244353 ;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	static int ans[1024][1024]={};
	int h,i,j;
	for(h=0;h<=9;h++){
		int K=(1<<h);
		for(i=0;i<K;i++){
			for(j=0;j<K;j++){
				ans[i+K][j]=ans[i][j];
				ans[i][j+K]=ans[i][j];
				ans[i+K][j+K]=1-ans[i][j];
			}
		}
	}
	int n,m;cin>>n>>m;
	for(i=1;i<(1<<n);i++){
		for(j=1;j<(1<<m);j++){
			cout<<(ans[i][j]+ans[i-1][j]+ans[i][j-1]+ans[i-1][j-1])%2;
		}
		cout<<endl;
	}
}

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

int main(){
  string  N;
  cin >> N;
  bool a=false;
  for(int i=0;i<3;i++){
    if(N.at(i)=='7'){
      a=true;
      break;
    }
  }
  if(a){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3628
#include <iostream>
#include<iomanip>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF  int(1e6+1)
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main()
{
	int n;
	cin >> n;
	string s, t;
	cin >> s >> t;
	rep(i, 0, n)cout << s[i] << t[i];
	cout << endl;
}



Measured memory_bytes: 3608
# coding: utf-8
# Your code here!
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    for i in range(W):
        print("#",end="")
    print()
    for j in range(H-2):
        for k in range(W):
            if k==0 or k==W-1:
                print("#",end="")
            else:
                print(".",end="")
        print()
    for i in range(W):
        print("#",end="")
    print()
    print()


Measured memory_bytes: 7008
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cctype>
#include <algorithm>

static int N;
static int u_table[CHAR_MAX][12];

static char u_expr[1024];
static char* e;


static void u_init(void) {
	int K;

	scanf("%d%d", &N, &K);
	for (int i = 0; i < K; ++i) {
		char p;
		int h;

		scanf(" %c %d", &p, &h);
		for (int k = 0; k < N; ++k) {
			u_table[p][k] = k;
		}
		for (int j = 0; j < h - 1; ++j) {
			for (int k = 0; k < N - 1; ++k) {
				int d;

				scanf(" %d", &d);
				if (d) {
					std::swap(u_table[p][k], u_table[p][k + 1]);
				}
			}
		}
	}
}


static void u_apply(int* functional, int* out) {
	int func[12], old[12];

	for (int i = 0; i < N; ++i) {
		old[i] = out[i];
		func[i] = functional[i];
	}
	for (int i = 0; i < N; ++i) {
		out[i] = old[func[i]];
	}
}


static void u_solve(int* out);


static void u_term(int* out) {
	if (*e == '(') {
		++e;
		u_solve(out);
		++e;
	}
	else if (isdigit(*e)) {
		int unit[12];

		int rep = 0;
		for (; isdigit(*e); ++e) {
			rep = rep * 10 + (*e - '0');
		}
		u_term(unit);
		for (int i = 0; i < N; ++i) {
			out[i] = i;
		}
		for (; rep > 0; rep /= 2) {
			if (rep % 2 == 1) {
				u_apply(unit, out);
			}
			u_apply(unit, unit);
		}
	}
	else {
		for (int i = 0; i < N; ++i) {
			out[i] = u_table[*e][i];
		}
		++e;
	}
}


static void u_solve(int* out) {
	u_term(out);
	while (*e == '+') {
		++e;

		int rvalue[12];
		u_term(rvalue);
		u_apply(rvalue, out);
	}
}


int main(int argc, char* argv[]) {
	int E;

	u_init();
	scanf(" %d", &E);
	for (int i = 0; i < E; ++i) {
		int out[12];

		scanf(" %s", u_expr);
		e = u_expr;
		u_solve(out);
		for (int i = 0; i < N; ++i) {
			if (i) {
				fputc(' ', stdout);
			}
			printf("%d", out[i] + 1);
		}
		puts("");
	}

	return EXIT_SUCCESS;
}



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

int N, M, L[200000], R[200000];

multiset<int> solve(){
    map<int, vector<int>> mp;
    for(int i=0; i<N; i++) mp[L[i]].push_back(R[i]);
    multiset<int> st;
    for(auto& pp : mp){
        int l = pp.first;
        for(int r : pp.second){
            auto it = st.lower_bound(l);
            if(it != st.begin()) st.erase(prev(it));
            st.insert(r);
        }
    }
    return st;
}

int main(){
    cin >> N >> M;
    for(int i=0; i<N; i++) cin >> L[i] >> R[i];
    auto res = solve();
    int64_t len = res.size();
    if(len%2 == 0){
        for(int i=0; i<N; i++){
            swap(L[i], R[i]);
            L[i] = M-L[i];
            R[i] = M-R[i];
        }
        res = solve();
    }
    int64_t ans = (len-1)*M + *res.begin();
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 35976
#include <cstdio>
#include <iostream>
#include <algorithm>

int main(){
    int num[3];
    scanf("%d %d %d", &num[0], &num[1], &num[2]);

    std::sort(num, num+3);
    int ans = num[2]*10 + num[1] + num[0];

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
void inputer();
int X, A;
int a[100000];
int main() {
	cin >> X >> A;

	//inputer();

	if (X < A) {
		cout << 0;
	}
	else {
		cout << 10;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
ll MOD=1000000007;
int inf=1000000000;
ll INF=10000000000000000;

int main(){
    int n,m;
    cin >> n >> m;
    vector<pp> a(n);
    rep(i,n){
        int g,h;
        cin >> g >> h;
        a.at(i).first=g;
        a.at(i).second=h;
    }
    sort(a.begin(),a.end());
    int o=0;
    int ans=0;
    std::priority_queue<int> q;
    rep(i,m+1){
        while (true){
            if (o==a.size()) break;
            if (a.at(o).first<=i) q.push(a.at(o).second);
            else break;
            o++; 
        }
        if (q.empty()) continue;
        int y=q.top();
        q.pop();
        ans+=y;
        //cout << y;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1660
#include <stdio.h>

int main(void)
{
	int x, y;
	for(;;) {
		scanf("%d %d", &x, &y);
		if(x==0 && y==0) break;
		if(x<y) printf("%d %d\n", x, y);
		else printf("%d %d\n", y, x);
	}
		
	return 0;
}


Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int main(void) {
	int n, i, a[200003], mo[200003] = {}, p, lp, lo;
	ll k;

	scanf("%d%lld", &n, &k);
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		a[i]--;
	}

	for (i = 0; i < n; i++) {
		mo[i] = -1;
	}

	mo[0] = 0;
	p = 0;
	while (k > 0) {
		if (mo[a[p]] >= 0) {
			break;
		}
		mo[a[p]] = mo[p] + 1;
		p = a[p];
		k--;
	}

	if (k == 0) {
		printf("%d\n", p + 1);
		return 0;
	}

	lo = mo[p] - mo[a[p]] + 1;

	p = a[p];
	k = (k - 1) % lo;
	for (i = 0; i < k; i++) {
		p = a[p];
	}

	printf("%d\n", p + 1);

	return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int a,b,c;
    cin >> a >> b >> c;
    cout << c/max(a,b)+(c%max(a,b) > 0);
    return 0;
}


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

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

    char c = S[0];
    bool yes = false;
    for(int i=1;i<S.length();++i)
    {
        if(c==S[i])
        {
            continue;
        }
        else
        {
            yes = true;
            break;
        }
    }

    if(yes)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    

}


Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
const int N=200005;
struct node { int l,r; } v[N];
int s[N],i,j,k,n,m,z,an,R;
char c;

inline char getc()
{
	#define VV 10000000
	static char s[VV],*l=s,*r=s;
	if (l==r)
		l=s,r=s+fread(s,1,VV,stdin);
	return l==r?0:*l++;
}

int read(){ int z=0; do c=getc(); while (c<'0'||c>'9'); while (c>='0'&&c<='9') z*=10,z+=c-'0',c=getc(); return z; }

bool cmp(node a,node b){ return a.l<b.l; }

priority_queue <int,vector<int>, greater <int> > q;

void solve()
{
	n=read(),m=read();
	for (i=1;i<=n;++i) v[i]=(node){read(),read()},++s[v[i].r];
	sort(v+1,v+n+1,cmp),v[n+1].l=m+1;
	for (j=1;!v[j].l;++j);
	for (i=1;j<=n;++j)
	{
		if (i<=v[j].l)
			++i,++an,--s[v[j].r],q.push(v[j].r);
		else
		{
			z=q.top();
			if (z<v[j].r)
				++s[z],q.pop(),--s[v[j].r],q.push(v[j].r);
		}
	}
	R=i-1;
	for (i=j=m;j;--j)
		z=min(s[j],i-max(R,j-1)),
		i-=z,an+=z;
}

int main()
{
	solve();
	printf("%d\n",n-an);
	return 0;
}

Measured memory_bytes: 7544
#include "stdio.h"
#include "iostream"
 
using namespace std;
 
int main(){
  
  int N, A; cin >> N >> A;
  int b = N % 500;
  if(b <= A){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<numeric>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<ctype.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
int dy[4]={0,1,0,-1};
//----------program from here----------

int main(){
  int N=0,K=0;
  cin >> N >> K;
  cout << (N%K?1:0) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/integer/common_factor_rt.hpp>
using namespace std;
using ll=long long;
const int MOD=1000000007;

int main() {
  int n,m;
  cin >> n >> m;
  map<int,int> ma;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    vector<int> a(k);
    for(int j=0;j<k;j++){
      cin >> a.at(j);
      ma[a.at(j)]++;
    }
  }
  int ans=0;
  for (auto p : ma) {
  auto k = p.first;
  auto v = p.second;
  if(v==n)
  ans++;
}
cout << ans << endl;
}

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;
struct Edge{ll from, to, cost;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

/*
ll dp[100][10];

ll dpf(ll keta, ll state){
  if(visited[keta][state]==1){
    return dp[keta][state];
  }else{
    visited[keta][state]=1;
    if(keta==1){
      if(state>>0 & 1 and state>>1 & 0 and state>>  ) dp[keta][state]=1;
      if(state>>1 & 1) dp[keta][state]=1;
      if(state>>2 & 1) dp[keta][state]=1;
    }
  }
}
*/

vector<string> cand;
ll Nlen;
void dfs(string s, ll keta){
  if(keta == Nlen){
    cand.push_back(s);
  }else{
    if(s!=""){
      cand.push_back(s);
    }
    dfs(s+"3", keta+1);
    dfs(s+"5", keta+1);
    dfs(s+"7", keta+1);
  }
}



/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N;
  cin >> N;
  string S = to_string(N);
  Nlen = S.size();
  dfs("", 0);
  //cout << cand.size();
  ll ans = 0;
  rep(i, cand.size()){
    bool flag[] = {false, false, false};
    if(stoi(cand[i])<=N){
      rep(j, cand[i].size()){
        if(cand[i][j]=='3')flag[0]=true;
        if(cand[i][j]=='5')flag[1]=true;
        if(cand[i][j]=='7')flag[2]=true;
      }
    }
    if(flag[0] and flag[1] and flag[2]){
      ans += 1;
      //cout << cand[i] << endl;
    }
  }

  cout << ans;
  return 0;
}


Measured memory_bytes: 2172
#include<bits/stdc++.h>
#define F first
#define S second
#define int long long
#define double long double
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,int> Pi;
typedef pair<P,P> PP;
double eps=1e-8;
int mod=1e9+7;
int inf=1LL<<55;

priority_queue<P,vector<P>,greater<P> > pq;

template <typename T>
int Count(const vector<T> &v, T l,T r){
  //counting [l,r]
  auto L = lower_bound(v.begin(), v.end(), l );
  auto R = upper_bound(v.begin(), v.end(), r );
  // [l,r) change upper -> lower
  return R-L;
}

signed main(){
  int k,a,b;
  cin>>k>>a>>b;

  int ans=k+1;
  k-=a-1;
  if(k>=0&&b-a>0)ans=max(ans,(b-a)*(k/2)+k%2+a);

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


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define INF         1e9
#define EPS         1e-9
#define REP(i,n)    for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(lint i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(lint i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define R_UP(a,b)   (((a)+(b)-1)/(b))
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP        cout << fixed << setprecision(8)
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }

int gcd(int x, int y) {
	return y == 0 ? x : gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int main() {
	int n = in();
	vector<int>a(n);
	REP(i, n) {
		a[i] = in();
	}
	int ans = 1;
	REP(i, n) {
		ans = lcm(ans, a[i]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

using namespace std;

typedef long long ll;

#define f first
#define s second

int sum, n, v[100];
string s[52], a;



int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i] >> v[i];
  }
  cin >> a;
  for (int i = n; i >= 1; i--) {
    if (s[i] == a)
      break;
    sum += v[i];
  }
  cout << sum;
  return 0;
}


Measured memory_bytes: 256
# 貪欲法で得た解に対して、局所探索法(改良ver)

import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

D = I()
c = [0] + LI()
s = [0] + [[0] + LI() for _ in range(D)]

last = [[0]*27 for _ in range(D+1)]
t = [0]

for i in range(1,D+1):
    r = 0
    manzoku = 0
    for j in range(1,27):
        m = s[i][j]
        for k in range(1,27):
            if k != j:
                m -= c[k]*(i-last[i-1][k])
            else:
                continue
        if j == 1:
            r = 1
            manzoku = m
        else:
            if manzoku < m:
                manzoku = m
                r = j
    t.append(r)
    for j in range(1,27):
        if j == r:
            last[i][j] = i
        else:
            last[i][j] = last[i-1][j]


dq = []
for i in range(1,D+1):
    for j in range(1,27):
        dq.append([i,j])

from copy import deepcopy

for d,q in dq:
    t0 = t[d]
    manzoku = s[d][q] - s[d][t0]
    for j in range(d,D+1):
        if j == d:
            last[d][t0] = last[d-1][t0]
            manzoku -= c[t0] * (d - last[d][t0])
            last[d][q] = d
            manzoku += c[q] * (d - last[d-1][q])
        else:
            if last[j][t0] == d:
                last[j][t0] = last[d-1][t0]
                manzoku -= c[t0] * (d - last[d][t0])
            if last[j][q] == last[d-1][q]:
                last[j][q] = d
                manzoku += c[q] * (d - last[d-1][q])
    if manzoku > 0:
        t[d] = q
    else:
        for j in range(d,D+1):
            if j == d:
                last[d][t0] = d
                last[d][q] = last[d-1][q]
            else:
                if last[j][t0] == last[d-1][t0]:
                    last[j][t0] = d
                if last[j][q] == d:
                    last[j][q] = last[d-1][q]

del t[0]

print(*t,sep='\n')

Measured memory_bytes: 77328
using System;
using System.Linq;
using System.Collections.Generic;

class Mondai
{
    static void Main()
    {
        var HW = Console.ReadLine().Split(' ').Select(n => Int32.Parse(n)).ToArray();
        var H = HW[0];
        var W = HW[1];
        var array = new char[H,W];
        for (int height=0; height < H;++height)
        {
            var S = Console.ReadLine().ToCharArray();
            for (int width=0; width < W;++width) array[height, width] = S[width];
        }

        var yokoArray = new int[H, W];
        for (int height = 0; height < H;++height)
        {
            for (int width=0; width < W;++width)
            {
                if (array[height, width] == '#') continue;
                if (yokoArray[height, width] != 0) continue;
                var count = 0;
                var w = width;
                while (array[height, w] == '.')
                {
                    count++;
                    w++;
                    if (W <= w) break;
                }
                for (int k = 0; k < count; ++k) yokoArray[height, width + k] = count;
            }
        }

        var tateArray = new int[H, W];
        for (int width = 0; width < W; ++width)
        {
            for (int height = 0; height < H; ++height)
            {
                if (array[height, width] == '#') continue;
                if (tateArray[height, width] != 0) continue;
                var count = 0;
                var h = height;
                while (array[h, width] == '.')
                {
                    count++;
                    h++;
                    if (H <= h) break;
                }
                for (int k = 0; k < count; ++k) tateArray[height + k, width] = count;
            }
        }

        var max = int.MinValue;
        for (int i = 0; i < H; ++i) {
            for (int j = 0; j < W; ++j) {
                var rayCount = yokoArray[i, j] + tateArray[i, j] - 1;
                if (max < rayCount) max = rayCount;
            }
        }
        Console.WriteLine(max);
    }
}


Measured memory_bytes: 56256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

long long div_round_up(long long a, long long b)
{
	return (a + b - 1) / b;
}

int main()
{
	int N;
	long long A, B;
	cin >> N >> A >> B;
	vector<int> h(N);
	for (int i = 0; i < N; ++i) {
		cin >> h[i];
	}

	auto can = [&](int m) {
		vector<long long> a(N);
		for (int i = 0; i < N; ++i) {
			a[i] = max(0LL, div_round_up(h[i] - m * B, A - B));
		}
		return accumulate(a.begin(), a.end(), 0LL) <= m;
	};

	int l = 0;
	int u = 1000 * 1000 * 1000;
	while (l < u) {
		int m = (l + u) / 2;
		if (can(m)) {
			u = m;
		}
		else {
			l = m + 1;
		}
	}
	cout << u << endl;
}


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

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

Measured memory_bytes: 3636
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;

int main()
{
	int n;
    scanf("%d",&n);
	int sum=0,a,b;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&a,&b);
	    sum+=b-a+1;
	}
	printf("%d",sum);
    return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
using namespace std;
const int N = 2e5 + 5;

int main(void)
{
    int n;
    cin >> n;
    int a[N];
    rep(i, n)
    {
        cin >> a[i];
    }
    int ct = 0;
    for (int i = 0; i < n - 2; ++i)
    {
        for (int j = i + 1; j < n - 1; ++j)
        {
            for (int k = j + 1; k < n; ++k)
            {
                if (a[i] != a[j] && a[j] != a[k] && a[k] != a[i] &&
                    a[i] + a[j] > a[k] && a[i] + a[k] > a[j] && a[j] + a[k] > a[i])
                {
                    ++ct;
                }
            }
        }
    }
    cout << ct << endl;
}

Measured memory_bytes: 3624
#include <iostream>

int main(){
	double a,b,c;
	bool ispass = false;
	std::cin >> a >> b >> c;
	if(a == b && a != c) {
		ispass = true;
	} else if(a == c && a != b) {
		ispass = true;
	} else if(b == c && a != b) {
		ispass = true;
	}

	if(ispass){
		std::cout << "Yes" << std::endl;
	} else {
		std::cout << "No" << std::endl;
	}

}


Measured memory_bytes: 256
#define LOCAL

#undef _GLIBCXX_DEBUG

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

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL
#define LLINF 100000000000000005LL
#define INF (int)1e9+1
#define pb push_back

// Copied from Gennady-Korotkevich's template

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
	return '"' + s + '"';
}

string to_string(const char* s) {
	return to_string((string)s);
}

string to_string(bool b) {
	return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}\n";
	return res;
}

template <size_t N>
string to_string(bitset<N> v) {
	string res = "";
	for (size_t i = 0; i < N; i++) {
		res += static_cast<char>('0' + v[i]);
	}
	return res;
}

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 += "}\n";
	return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

template <typename A, typename B, typename C, typename D, typename E>
string to_string(tuple<A, B, C, D, E> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + "," + to_string(get<4>(p)) + ")";
}

void debug_out() {
	cerr << endl;
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "\n[" << #__VA_ARGS__ << "]:\n", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

// End of Gennady-Korotkevich's template 

using llong = long long;
using PII = pair<int, int>;
using db = double;

int main() {
	IOS;
	int n; cin >> n;
	vector<int> a(n), b(n), c(n);
	for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];
	vector<vector<int>> dp(n, vector<int> (3));
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	for (int i = 1; i < n; i++) {
		dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
		dp[i][1] = max(dp[i - 1][2], dp[i - 1][0]) + b[i];
		dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i];
	}
	cout << max({ dp[n - 1][0], dp[n - 1][1], dp[n - 1][2] });
}

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

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

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

constexpr int nax = 1000 * 1000 + 105;
constexpr int infty = 1000 * 1000 * 1000 + 5;
constexpr int mod = 1000 * 1000 * 1000 + 7;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  for (int i = 1; i < (int) s.size(); i++) {
    if (s[i - 1] == 'A' and s[i] == 'C') {
      printf("Yes\n");
      return 0;
    }
  }
  printf("No\n");
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int read()
{
	char s;
	int k=0,base=1;
	while((s=getchar())!='-'&&s!=EOF&&!(s>='0'&&s<='9'));
	if(s==EOF)exit(0);
	if(s=='-')base=-1,s=getchar();
	while(s>='0'&&s<='9')
	{
		k=k*10+(s-'0');
		s=getchar();
	}
	return k*base;
}
void write(int x)
{
	if(x<0)
	{
		putchar('-');
		write(-x);
	}
	else
	{
		if(x/10)write(x/10);
		putchar(x%10+'0');
	}
}
char ch;
int n;
int main()
{
	while (scanf("%c",&ch)!=EOF)
	{
		n++;
		if (n%2==1) printf("%c",ch);
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> ans(N + 1, 0);
  for (long long i = 1; i <= N; i++){
    for (long long j = 1; j <= N; j++){
      if (i * i + j * j + i * j <= N){
        for (long long k = 1; k <= N; k++){
          long long tmp = i * i + j * j + k * k + i * j + j * k + k * i;
          if (tmp <= N){
            ans[tmp]++;
          } else {
            break;
          }
        }
      }
    }
  }
  for (int i = 1; i <= N; i++){
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ll long long
#define ld long double
//#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];

int main() {
  int N; cin >> N;
  map<string, int> T;
  char lastl;
  int ans = 1;
  rep(i, N) {
    string S; cin >> S;
    if ( i != 0) {
      char firstl = S[0];
      if (lastl != firstl) {
        ans = 0;
      }
    }
    lastl = S[S.size()-1];
    T[S]++;
  }

  if (ans) {
    for (auto p: T) {
      if (p.second != 1) {
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
    return 0;
  } else {
    cout << "No" << endl;
    return 0;
  }
  return 0;
}


Measured memory_bytes: 256
while expr = gets
  if expr.chomp == ""
    break
  end
 
  flag = false
  a1, a2, ans =  expr.chomp.split(/[\+|=]/)

  (0..9).each do |i|
    if i == 0 && ((a1[0] == 'X' && a1.length > 1) ||
                  (a2[0] == 'X' && a2.length > 1) ||
                  (ans[0] == 'X' && ans.length > 1))
      next
    end
    
    val_a1 = a1.gsub("X", i.to_s).to_i
    val_a2 = a2.gsub("X", i.to_s).to_i
    val_ans = ans.gsub("X", i.to_s).to_i

    if (val_a1 + val_a2 == val_ans)
      puts i
      flag = true
      break
    end
  end

  if !flag
    puts "NA"
  end
end

Measured memory_bytes: 8812
iscoprime(P, i) = !any(x -> i % x == 0, P)

function sieve(n)
    p = trues(n)
    p[1] = false
    for i in 2:Int(ceil(sqrt(n)))
        if p[i]
            j = 0
            while i*(j+2) <= n
                p[i*(j+2)] = false
                j += 1
            end
        end
    end
    findall(x->x, p)
end

function factor(n)
    i = 1
    res = Tuple{Int, Int}[]
    for a in 2:sqrt(n)
        n%a != 0 && continue
        ex = 0
        while n%a == 0
            ex += 1
            n /= a
        end

        push!(res, (a, ex))
    end
    n != 1 && push!(res, (n, 1))
    
    return res
end

function main()
    n = parse(Int, readline())
    

    fc = factor(n)
    ans = 0
    for (p, c) in fc
        cnt = c
        x = 1
        while x <= cnt
            cnt -= x
            x += 1
            ans += 1
        end
    end

    println(ans)
end

main()


Measured memory_bytes: 182000
#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 (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int 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)

int main()
{
    int n;cin >> n;
    vector<int> v(n+1);
    for (int i = 1; (1 << i) <= n;i++){
        for (int j = 1; i * j <= n;j++){
            if ((1 << i) * j>n)
                break;
            v[(1 << i) * j] = i;
        }
    }
    int ans = 0;
    int out = 1;
    for (int i = 0; i < n+1;i++){
        if(v[i]>ans){
            ans = v[i];
            out = i;
        }
    }
    cout << out << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define fo(i,n)         for(i=0;i<n;i++)
#define Fo(i,k,n)       for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define deb(x)          cout << #x << "=" << x << endl
#define deb2(x, y)      cout << #x << "=" << x << "," << #y << "=" << y << endl
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const int N = 3e5, M = N;
//=======================

vi g[N];

void solve() {
	int i, j, n, m;
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	m = max({a * c, a * d, b * c, b * d});
	cout << m;
}

int32_t main()
{
	FIO;
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	solve();
	return 0;
}

void ipgraph(int n, int m) {
	int i, u, v;
	while (m--) {
		cin >> u >> v;
		u--, v--;
		g[u].pb(v);
		g[v].pb(u);
	}
}

void dfs(int u, int par) {
	for (int v : g[u]) {
		if (v == par) continue;
		dfs(v, u);
	}
}

Measured memory_bytes: 10688
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextFloat64() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func abs(x int) int {
	if x < 0 {
		return -1 * x
	} else {
		return x
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	//sc.Buffer(nil, 100000000)

	n, x, t := nextFloat64(), nextFloat64(), nextFloat64()

	ans := math.Ceil(n/x) * t
	fmt.Println(int(ans))
}


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

int main() {
	int k[200] = {};
	int n;


	for (int i = 0; i < 3; i++) {
		int t;
		cin >> t;
		k[t] = 1;
	}

	int count;
	for (int i = 0; i < 101; i++) {
		count += k[i];
	}

	cout << count << endl;



	return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
#include<chrono>
 
using namespace std;
using namespace std::chrono;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define REP(i,a,b) for(i=a;i<=b;i++)
#define RAP(i,a,b) for(i=a;i>=b;i--)
ll mod=1000000007;
const int MX=0x3f3f3f;

int main(){
	IOS;
    int n,i;
    cin>>n;
    int a[n],b[n],c[n];
    REP(i,0,n-1) cin>>a[i]>>b[i]>>c[i];
    int dp[n][3];
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    REP(i,1,n-1) {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
    return 0;
}

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

#define ll long long

int main() {
  int h, w;

  while (true) {
    cin >> h >> w;
    if (h == 0 && w == 0) break;
    for (int i = 0; i < h; i ++) {
      for (int j = 0; j < w; j++) {
        cout << "#";
      }
      cout << "\n";
    }
    cout << "\n";
  }
  cout << flush;
    
  return 0;
}
  

Measured memory_bytes: 1112
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<ctime>
#include<climits>
#include<queue>
#define ll long long
using namespace std;
const ll N=5010,M=210;
ll sum[N][N],n,m,a[N],b[N][M],_sum[N],ans=LLONG_MIN,x[N],y[N];
ll q[N],head,tail;
int main()
{
	ll i,j,k,t;
	scanf("%lld%lld",&n,&m);
	for(i=2;i<=n;i++) scanf("%lld",&a[i]),_sum[i]=_sum[i-1]+a[i];
	for(i=1;i<=n;i++) for(j=1;j<=m;j++) scanf("%lld",&b[i][j]);
	for(i=1;i<=m;i++)
	{
		head=tail=0;
		x[1]=1;
		q[tail++]=1;
		for(j=2;j<=n;j++) 
		{
			while(tail!=head && b[q[tail-1]][i]<b[j][i]) tail--; 
            x[j]=(head==tail?1:q[tail-1]+1),q[tail++]=j;
		}
	    head=tail=0;
		y[n]=n;
		q[tail++]=n;
		for(j=n-1;j>=1;j--) 
		{
			while(tail!=head && b[q[tail-1]][i]<b[j][i]) tail--; 
            y[j]=(head==tail?n:q[tail-1]-1),q[tail++]=j;
		}
		for(j=1;j<=n;j++)
		{
			sum[x[j]][j]+=b[j][i];
			sum[j+1][y[j]+1]+=b[j][i];
			sum[x[j]][y[j]+1]-=b[j][i];
			sum[j+1][j]-=b[j][i];
		}
	}
	for(i=1;i<=n;i++) for(j=1;j<=n;j++) sum[i][j]+=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
	for(i=1;i<=n;i++) for(j=i;j<=n;j++) ans=max(ans,sum[i][j]-(_sum[j]-_sum[i]));
	cout<<ans<<endl; 
	return 0;
}

Measured memory_bytes: 204416
#include <iostream>
#include <cmath>
#include <limits>
using namespace std;

int main()
{
  int e;
  while (cin >> e && e != 0) {
    int ans = numeric_limits<int>::max();
    for (int z = 0; z*z*z <= e; z++) {
      const int c = e - z*z*z;
      const int y1 = int(sqrt(double(c)));
      const int m = min(c+z, c-y1*y1+y1+z);
      ans = min(ans, m);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0