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

const int maxn=10*1e4+10;
int n,x[maxn],y[maxn],n2,posi[maxn];
struct node{
	int pos,id;
	bool operator< (node o)const{
		return pos<o.pos;
	}
}p[maxn];
int dfn,pre[maxn],low[maxn],scccnt,scc[maxn],stk[maxn],top;
vector<int> g[maxn];

inline void chkmin(int&a,int b){
	if(a>b)a=b;
}
void dfs(int pos,int fa){
	pre[pos]=low[pos]=++dfn;
	stk[top++]=pos;
	for(int i=0,v;i<g[pos].size();++i)
		if((v=g[pos][i])!=fa)
			if(!pre[v]){
				dfs(v,pos);
				chkmin(low[pos],low[v]);
			}
			else if(!scc[v])
				chkmin(low[pos],pre[v]);
	if(low[pos]>=pre[pos]){
		++scccnt;
		do
			scc[stk[--top]]=scccnt;
		while(stk[top]!=pos);
	}
}
namespace st{
	int rt,cnt,lson[maxn],rson[maxn];
	int build(int l,int r){
		int rt=++cnt;
		if(l==r){
			g[rt].push_back(p[l].id^1);
			return rt;
		}
		int mid=l+r>>1;
		lson[rt]=build(l,mid);
		rson[rt]=build(mid+1,r);
		g[rt].push_back(lson[rt]);
		g[rt].push_back(rson[rt]);
		return rt;
	}
	void update(int rt,int l,int r,int x,int y,int pos){
		if(l==x&&r==y){
			g[pos].push_back(rt);
			return;
		}
		int mid=l+r>>1;
		if(y<=mid)
			update(lson[rt],l,mid,x,y,pos);
		else if(x>mid)
			update(rson[rt],mid+1,r,x,y,pos);
		else{
			update(lson[rt],l,mid,x,mid,pos);
			update(rson[rt],mid+1,r,mid+1,y,pos);
		}
	}
}
inline bool judge(int dis){
	for(int i=0;i<n2;++i)
		g[i].clear();
	for(int i=0;i<n2;++i){
		int tmp=upper_bound(posi,posi+n2,posi[i]-dis)-posi;
		if(tmp<i)
			st::update(st::rt,0,n2-1,tmp,i-1,p[i].id);
	}
	for(int i=0;i<n2;++i){
		int tmp=lower_bound(posi,posi+n2,posi[i]+dis)-posi-1;
		if(tmp>i)
			st::update(st::rt,0,n2-1,i+1,tmp,p[i].id);
	}
	memset(pre,0,sizeof(pre));dfn=0;
	memset(scc,0,sizeof(scc));scccnt=0;
	for(int i=0;i<=st::cnt;++i)
		if(!pre[i])
			dfs(i,-1);
	for(int i=0;i<n;++i)
		if(scc[i<<1]==scc[i<<1|1])
			return false;
	return true;
}

int main(){
	scanf("%d",&n);n2=2*n;
	for(int i=0;i<n;++i)
		scanf("%d%d",&x[i],&y[i]);
	for(int i=0;i<n;++i){
		p[i<<1].pos=x[i],p[i<<1].id=i<<1;
		p[i<<1|1].pos=y[i],p[i<<1|1].id=i<<1|1;
	}
	sort(p,p+n2);
	for(int i=0;i<n2;++i)
		posi[i]=p[i].pos;
	st::cnt=n2-1;
	st::rt=st::build(0,n2-1);
	int l=0,r=1e9;
	while(l<r){
		int mid=l+r+1>>1;
		if(judge(mid))
			l=mid;
		else
			r=mid-1;
	}
	printf("%d\n",l);
	return 0;
}

Measured memory_bytes: 16256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,ans=1e18,num=0,m=0;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        m+=a[i];
        if(!(i%2)){
            if(m<=0){
                num+=(1-m);
                m=1;
            }
        }
        else{
            if(m>=0){
                num+=(m+1);
                m=-1;
            }
        }
    }
    ans=min(ans,num);
    num=m=0;
    for(int i=0;i<n;i++){
        m+=a[i];
        if(!(i%2)){
            if(m>=0){
                num+=(m+1);
                m=-1;
            }
        }
        else{
            if(m<=0){
                num+=(1-m);
                m=1;
            }
        }
    }
    cout <<min(ans,num)<<endl;
    return 0;
}




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

int main() {
  string s;
  cin >> s;
  if(s.at(5) == '1') {
    cout << "TBD" << endl;
  }else if(s.at(6) == '1' || s.at(6) == '2' || s.at(6) == '3' || s.at(6) == '4') {
    cout << "Heisei" << endl;
  }else{
    cout << "TBD" << endl;
  }
}

Measured memory_bytes: 256
def dfs(bri1): #始点入力
    for l in land[bri1-1]:
        if seen[l-1] == 0 and not (bri1==bri[0] and l==bri[1]):
            seen[l-1] = 1
            dfs(l)

N,M = map(int,input().split())
data = [0]*M
land = [[] for i in range(N)] #i+1番目の島とつながっているところ
for i in range(M):
    a,b = map(int,input().split())
    data[i] = [a,b]
    land[a-1].append(b)
    land[b-1].append(a)

cnt = 0
for i in range(M):
    bri = data[i]
    seen = [0]*N
    dfs(bri[0])
    if sum(seen) != N:
        cnt += 1

print(cnt)

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

int main(){
  vector<vector<int>> A(3,vector<int>(3));
  vector<vector<bool>> C(3,vector<bool>(3,false));
  bool a=false;
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> A.at(i).at(j);
    }
  }
  int N;
  cin >> N;
  for(int i=0;i<N;i++){
    int B;
    cin >> B;
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        if(B==A.at(j).at(k)){
          C.at(j).at(k)=true;
        }
      }
    }
  }
  for(int i=0;i<3;i++){
    if(C.at(i).at(0) && C.at(i).at(1) && C.at(i).at(2)){
      a=true;
    }
  }
  for(int i=0;i<3;i++){
  	if(C.at(0).at(i) && C.at(1).at(i) && C.at(2).at(i)){
      a=true;
    }
  }
  if(C.at(0).at(0) && C.at(1).at(1) && C.at(2).at(2)){
    a=true;
  }
  else if(C.at(0).at(2) && C.at(1).at(1) && C.at(2).at(0)){
    a=true;
  }
  if(a){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}   

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, h;
  cin >> n >> h;
  
  vector<int> a(n), b(n);
  for(int i = 0; i < n; i++) cin >> a.at(i) >> b.at(i);
  
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  
  int damage = 0, ans = 0;
  for(int i = n - 1; i >= 0; i--){
    if(a.at(n - 1) <= b.at(i)){
      damage += b.at(i);
      ans++;
    }
    else break;
    if(damage >= h){
      cout << ans << "\n";
      return 0;
    }
  }
  
  while(damage < h){
    damage += a.at(n - 1);
    ans++;
  }
  
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 1024
N = int(input())
A = [0] * N
X = [[0]*N for _ in range(N)]
Y = [[0]*N for _ in range(N)]

for i in range(N):
    a = int(input())
    A[i] = a
    for j in range(a):
        x,y = map(int,input().split())
        X[i][j] = x-1
        Y[i][j] = y

ans = 0
for i in range(1 << N):
    flg = True
    for j in range(N):
        if i >> j & 1 ^ 1:
            # 不親切な人ならば、証言を見ても意味がない
            continue
        for k in range(A[j]):
            if i >> X[j][k] & 1 ^ Y[j][k]:
                flg = False
                break
        if not flg: break
    if flg: ans = max(ans,str(bin(i))[2:].count('1'))
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n,d;
  while(1){
    cin>>d>>n;
    if(d==0)break;
    vector<vi> dp(205,vi(105,-1));
    vi a(n),e(n),r(n);
    rep(i,n){
      cin>>a[i]>>e[i]>>r[i];
      if(a[i]+e[i]+r[i]==0)i--,n--;
    }
    dp[0][0]=0;
    rep(i,201)rep(j,101)if(dp[i][j]>=0){
      int k;
      rep(k,n)if(r[k]<=j){
	dp[i+1][min(j+e[k],100)]=max(dp[i+1][min(j+e[k],100)],dp[i][j]+a[k]);
	if(dp[i+1][min(j+e[k],100)]>=d){
	  cout<<i+1<<endl;
	  goto END;
	}
      }
    }
    cout<<"NA"<<endl;
  END:;
  }

}



Measured memory_bytes: 3232
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            while(true){
                int n = sc.nextInt();
                int x = sc.nextInt();
                int count = 0;

                if(n==0 && x==0){
                    break;
                }
                for(int i=1;i<=n;i++){
                    for(int j=1;j<i;j++){
                        for(int k=1;k<j;k++){
                            if(i+j+k==x){
                                count++;
                            }
                        }
                    }
                }
                System.out.printf("%d\n",count);
            }
    }
}


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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll A;
  double B;
  IN(A,B);
  ll B_ = (ll)(B*100+0.01);
  OUT((A*B_)/100);

  return 0;
}

Measured memory_bytes: 3776
#include <stdio.h>

int		hit(int n, int *b)
{
	int i;
	i = 0;
	while (b[i])
	{
		if (n == b[i])
			return (1);
		i++;
	}
	return (0);
}

int		main(void)
{
	int A[3][3];
	int i = 0;
	int j;
	while (i < 3)
	{
		j = 0;
		while (j < 3)
			scanf("%d", &A[i][j++]);
		i++;
	}
	int N;
	scanf("%d", &N);
	int b[N];
	i = 0;
	while (i < N)
		scanf("%d", &b[i++]);
	i = 0;

	if (hit(A[0][0] ,b) && hit(A[1][0], b) && hit(A[2][0], b))
	{
		printf("Yes");
	}
	else if (hit(A[0][1] ,b) && hit(A[1][1], b) && hit(A[2][1], b))
	{
		printf("Yes");
	}
	else if (hit(A[0][2] ,b) && hit(A[1][2], b) && hit(A[2][2], b))
	{
		printf("Yes");
	}

	else if (hit(A[0][0] ,b) && hit(A[0][1], b) && hit(A[0][2], b))
	{
		printf("Yes");
	}
	else if (hit(A[1][0] ,b) && hit(A[1][1], b) && hit(A[1][2], b))
	{
		printf("Yes");
	}
	else if (hit(A[2][0] ,b) && hit(A[2][1], b) && hit(A[2][2], b))
	{
		printf("Yes");
	}
	else if (hit(A[0][0] ,b) && hit(A[1][1], b) && hit(A[2][2], b))
	{
		printf("Yes");
	}
	else if (hit(A[0][2] ,b) && hit(A[1][1], b) && hit(A[2][0], b))
	{
		printf("Yes");
	}
	else
		printf("No");
	return (0);
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll D, N;
    cin >> D >> N;
    ll ans = 0;
    rep(i, N) {
        ans += pow(100, D);
    }
    if (N == 100) ans += pow(100, D);
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

int a, b, c;

bool yes_no(int x, int y, int z){
  for(int i = 0; i < y; i++){
    if((x * i) % b == c){
      return true;
    }
  }
  return false;
}

int main(){
  cin >> a >> b >> c;
  if(yes_no(a, b, c)){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}


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

using namespace std;

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

    pair< pair<string,int>, int> s[n];

    for(int i=0; i<n; i++)
    {
        cin>>s[i].first.first>>s[i].first.second;
        s[i].first.second *= -1;
        s[i].second = i+1;
    }
    sort(s, s+n);
    for(int i=0; i<n; i++)
    {
        //cout<<s[i].first.first<<" "<<s[i].first.second<<" "<<s[i].second<<endl;
        cout<<s[i].second<<"\n";
    }

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(X: int, Y: int, Z: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    import heapq
    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)
    h = []
    heapq.heappush(h, [-(A[0]+B[0]+C[0]), 0, 0, 0])
    ans = []
    used = set()
    used.add((0, 0, 0))
    for _ in range(K):
        e, i, j, k = heapq.heappop(h)
        ans.append(-e)
        if i+1 < X and not (i+1, j, k) in used:
            used.add((i+1, j, k))
            heapq.heappush(h, [-(A[i+1]+B[j]+C[k]), i+1, j, k])
        if j+1 < Y and not (i, j+1, k) in used:
            used.add((i, j+1, k))
            heapq.heappush(h, [-(A[i]+B[j+1]+C[k]), i, j+1, k])
        if k+1 < Z and not (i, j, k+1) in used:
            used.add((i, j, k+1))
            heapq.heappush(h, [-(A[i]+B[j]+C[k+1]), i, j, k+1])
    for elem in ans:
        print(elem)





#def solve(X: int, Y: int, Z: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]"):
#    AB = []
#    for a in A:
#        for b in B:
#            AB.append(a+b)
#    AB.sort(reverse=True)
#    C.sort(reverse=True)
#    AB = AB[:K]
#    C = C[:K]
#    ABC = []
#    for ab in AB:
#        for c in C:
#            ABC.append(ab+c)
#    ABC.sort(reverse=True)
#    for i in range(K):
#        print(ABC[i])
#    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(X)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(Y)]  # type: "List[int]"
    C = [int(next(tokens)) for _ in range(Z)]  # type: "List[int]"
    solve(X, Y, Z, K, A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 53980
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

ll extgcd(ll a,ll b,ll &x,ll &y){
	if(b==0){
		x=1;
		y=0;
		return a;
	}
	ll g=extgcd(b,a%b,x,y);
	ll nextx=y,nexty=x-(a/b)*y;
	x=nextx;y=nexty;
	return g;
}

ll fact[200010];
ll invfact[200010];

ll nCr(int n,int r){
	ll ret=fact[n];
	(ret*=invfact[n-r])%=MOD;
	(ret*=invfact[r])%=MOD;
	return ret;
}

int main(){
	int H,W,A,B;
	cin>>H>>W>>A>>B;
	fact[0]=1;
	for(ll i=1;i<=200000;i++){
		fact[i]=(fact[i-1]*i)%MOD;
	}
	for(ll i=0;i<=200000;i++){
		ll x,y;
		ll g=extgcd(fact[i],MOD,x,y);
		while(x<0) x+=MOD;
		x%=MOD;
		invfact[i]=x;
	}
	ll ans=0;
	for(int i=B;i<W;i++){
		ll tmp =nCr((H-A-1)+i,H-A-1);
		(tmp*=nCr((A-1)+(W-i-1),A-1))%=MOD;
		(ans+=tmp)%=MOD;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL)
#define endl "\n"
#define ll long long
#define N ((int)(3e5 + 5))
#define MOD ((int)(1e9 + 7))


using namespace std;


/*fast io
ios_base::sync_with_stdio(false);
cin.tie(NULL);
*/



int main()
{
    fastio;
    string str;
    cin>>str;
    for(int i = 0 ; i<str.length() ; i++){
        if(i+1 < str.length() && str[i] == str[i+1]){
            cout<<i+1<<" "<<i+2<<endl;
            return 0;
        }
        if(i+2 < str.length() && str[i] == str[i+2]){
            cout<<i+1<<" "<<i+3<<endl;
            return 0;
        }
    }
    cout<<"-1 -1\n";
    return 0;
}


Measured memory_bytes: 3736
N, M = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(N)]

sl = sorted(l)
buy = 0
ans = 0
for i in range(N):
    for j in range(sl[i][1]):
        if buy < M:
            ans += sl[i][0]
            buy += 1
        else:
            break

print(ans)

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int n;cin >> n;
    ll res = 0;
    rep1(i,n){
        res+=i;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

typedef struct{
  char suit;
  char value;
}Card;

void bubbleSort(Card [], int);
void selectionSort(Card [], int);
void swap(char *, char *);
void print(Card [], int);
int stable(Card [], Card [], int);

int main(){
  Card C1[101], C2[101];
  int n, i;
  char ch;

  scanf("%d%c", &n, &ch);
  for ( i = 0; i < n; i++ ){
    scanf("%c%c%c", &C1[i].suit, &C1[i].value, &ch);
    C2[i] = C1[i];
  }
  
  bubbleSort(C1, n);
  selectionSort(C2, n);
  if(stable(C1, C2, n) == 0) printf("Not stable\n");
  else printf("Stable\n");
  
  return 0;
}

void bubbleSort(Card C[], int n){
  int i, j;
  
  for(i = 0; i < n; i++){
    for(j = n - 1; j > i; j--){
      if (C[j].value < C[j - 1].value){
	swap(&C[j].suit, &C[j - 1].suit);
	swap(&C[j].value, &C[j - 1].value);
      }
    }
  }
  
  print(C, n);
  printf("Stable\n");
}

void selectionSort(Card C[], int n){
  int i, j, mini;

  for(i = 0; i < n; i++){
    mini = i;
    for(j = i; j < n; j++){
      if(C[j].value < C[mini].value) mini = j;
    }
    if(i != mini){
      swap(&C[i].suit, &C[mini].suit);
      swap(&C[i].value, &C[mini].value);
    }
  }

  print(C, n);
}

void swap(char *p, char *q){
  char swap;
  swap = *p;
  *p = *q;
  *q = swap;
}

int stable(Card C1[], Card C2[], int n){
  int i;
  char result;
  for(i = 0; i < n; i++){
    if(C1[i].suit != C2[i].suit) return 0;
  }
  return 1;
}

void print(Card C[], int n){
  int i;
  for(i = 0; i < n; i++){
    printf("%c%c", C[i].suit, C[i].value);
    if(i != n - 1)printf(" ");
  }
  printf("\n");
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int N;
    cin >> N;
    int A;
    
    string ans = "APPROVED";
    
    for(int i = 0; i < N;i++){
        cin >> A;
        if(A%2==0){
            if(A%3!=0&&A%5!=0)ans ="DENIED";
        }
    }
    cout << ans <<endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
    #include <filesystem>
    namespace fs = std::filesystem;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

ll N,M;
vector<ll> A;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path __p = __FILE__;
        fs::path __input, __output;
        __input = __output = __p.parent_path();
        __input += string("/input/") + string(__p.stem()) + string(".txt");
        __output += string("/output/") + string(__p.stem()) + string(".txt");
        freopen(__input.c_str(), "r", stdin);
        freopen(__output.c_str(), "w", stdout);
    #endif
    cin >> N >> M;
    for (int i = 0; i < N; i++)
    {
        ll a; cin >> a;
        a %= M;
        A.push_back(a);
    }
}

// しゃくとり法で行けそうで行けない。
int solve(){
    unordered_map<ll,ll> cnt;
    ll sum=0LL;
    cnt[sum]++;
    for (int i = 0; i < N; i++)
    {
        sum += A[i];
        sum %= M;
        cnt[sum]++;
    }
    ll ans=0;
    for(auto c:cnt) {
        ans += (c.second-1)*c.second/2;
        }
    cout << ans << endl;
    
    return 0;
}   

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


Measured memory_bytes: 4468
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define N 500000
#define INFTY 1000000001

int n,cnt=0;
int L[N],R[N];

void merge(int *,int,int,int);
void mergeSort(int *,int,int);

int main(){
  int i,A[N];
  scanf("%d",&n);

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

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

  return 0;
}


void merge(int *A,int left,int mid,int right){
  int n1,n2,i,j,k;
  n1=mid-left;
  n2=right-mid;

  for(i=0;i<n1;i++){
    L[i]=A[left+i];
  }
  for(i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
  L[n1]=INFTY;
  R[n2]=INFTY;
  i=0;
  j=0;

  for(k=left;k<right;k++){
    cnt++;
    if(L[i]<=R[j]){
      A[k]=L[i];
      i=i+1;
    }
    else{
      A[k]=R[j];
      j=j+1;
    }
  }
}

void mergeSort(int *A,int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}



Measured memory_bytes: 5688
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    string s;
    cin>>s;
    if (s.size()==2)
        cout<<s<<endl;
    else
    {
        reverse(s.begin(),s.end());
        cout<<s<<endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
char a[100000000];
int main()
{
    cin>>a;
    int n=0;
    int la=strlen(a);
    for(int i=0;i<la;i++)
    {
        if(a[i]=='C')
        n=1;
        if(a[i]=='F'&&n==1)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

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

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

	int n;
	cin >> n;
	int chk = n / 111;
	if (n % 111) ++chk;
	cout << (chk * 111) << '\n';
	return 0;
}

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

using namespace std;

int main() {
    // 入力値
    int N, Y;
    cin >> N >> Y;

    vector<int> res = {-1, -1, -1};

    // Y == 10000 * x + 5000 * y + 1000 * z
    // N == x + y + z

    // xの最大値を求める
    // O(N^2) 200 * 200 = 40,000 計算量の最大値は大体、「10^8 = 100,000,000」のため計算量的には問題なさそう
    for (int x = 0; x <= N; x++) {
        for (int y = 0; y <= (N - x); y++) {
            if ((Y == 10000 * x + 5000 * y + 1000 * (N - x - y))) {
                res = {x, y, N - x - y};
            }
        }
    }

    // 出力値
    cout << res.at(0) << ' ' << res.at(1) << ' ' << res.at(2) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

int main(){
    int x,y;
    for(;;){
        cin >> x >> y;
        if(x==0 && y==0) return 0;
        if(x>y) swap(x,y);
        cout << x << ' ' << y << endl;
    }
}


Measured memory_bytes: 3080
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define pii pair<ll,ll>
#define vi(x) vector<x>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;

signed main()
{
    fast;
    
    string s,t;
    ll i,j,ans=LLONG_MAX;
    cin>>s>>t;
    for(i=0;i<s.length();i++)
    {
    	if(i+t.length() <= s.length())
    	{
    		ll ha =0;
    		for(j=i;j<i+t.length();j++)
    		{
    			if(s[j]!=t[j-i]) ha++;
    		}
    		ans = min(ans,ha);
    	}
    	else break;
    }
    cout<<ans;
}

Measured memory_bytes: 3644
#include <stdio.h>
 
int main(void){
  int r,d,x;
  	scanf("%d%d%d",&r,&d,&x);
  int i=0;
  for(i=0;i<10;++i){
    printf("%d\n",r*x-d);
    x=r*x-d;
  }
}

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

using namespace std;

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

#define INF 		2000000007
#define MOD			10e9+7
#define MAX 		100005

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;


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

	string answer;
	int flag = 0;

	if(T.length() > S.length()){puts("UNRESTORABLE");return 0;}

	for(int i=S.length()-T.length()+1;i>=0;--i){
		int f = 1;
		REP(j,T.length()){
			if(S[i+j] !='?' && S[i+j] != T[j]){
				f=0;break;
			}
		}
		if(f){
			REP(j,T.length()){
				S[i+j] = T[j];
			}
			flag = 1;
			break;
		}
	}
	if(flag)
		REP(i,S.length())if(S[i]=='?')S[i]='a';

	cout << (flag ? S : "UNRESTORABLE") << endl;

	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int debug=0;

int main(void){
	double ax, ay, bx, by, cx, cy, px, py;
	double a, b, c, ap, bp, cp;
	double tmp;
	double s2, sa2, sb2, sc2;
	double s, sa, sb, sc;

	while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &ax, &ay, &bx, &by, &cx, &cy, &px, &py) != -1){
		//ツ各ツ静シツ閉ェツづ個陳キツつウツづーツ計ツ算
		a = sqrt(fabs((bx - cx) * (bx - cx) + (by - cy) * (by- cy)));
		b = sqrt(fabs((ax - cx) * (ax - cx) + (ay - cy) * (ay- cy)));
		c = sqrt(fabs((ax - bx) * (ax - bx) + (ay - by) * (ay- by)));
		ap = sqrt(fabs((ax - px) * (ax - px) + (ay - py) * (ay- py)));
		bp = sqrt(fabs((bx - px) * (bx - px) + (by - py) * (by- py)));
		cp = sqrt(fabs((cx - px) * (cx - px) + (cy - py) * (cy- py)));

		if(debug) printf("[length]a = %.2f, b == %.2f, c = %.2f, ap = %.2f, bp = %.2f, cp = %.2f\n", a, b, c, ap, bp, cp);

		//heron
		tmp = (a + b + c) / 2;
		s2 = tmp * (tmp - a) * (tmp - b) * (tmp - c);
		s = sqrt(s2);
		if(debug) printf("s = %lf\n", s);

		tmp = (a + bp + cp) / 2;
		sa2 = tmp * (tmp - a) * (tmp - bp) * (tmp - cp);
		sa = sqrt(sa2);

		tmp = (b + ap + cp) / 2;
		sb2 = tmp * (tmp - b) * (tmp - ap) * (tmp - cp);
		sb = sqrt(sb2);

		tmp = (c + ap + bp) / 2;
		sc2 = tmp * (tmp - c) * (tmp - ap) * (tmp - bp);
		sc = sqrt(sc2);

		if(debug) printf("sa + sb + sc = %lf\n", sa + sb + sc);

		if(fabs(sa + sb + sc - s) < 0.000000001){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
	return 0;
}

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

int main(){

    int n;
    int count=0;

       
    cin >> n;
	vector<int> p(n); 
    for(int i=0; i<n; i++) cin >> p[i];
    
    
    for(int i=1;i<=n-2;i++){
        
        
        if((p[i-1]<p[i] && p[i]<p[i+1]) || (p[i-1]>p[i] && p[i]>p[i+1])){
            count++;
        }
        
    }
    
    cout << count;
 
}

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

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

    ll N, M;
    cin >> N >> M;
    vector<P> V(N);
    for (int i = 0; i < N; ++i) {
        ll A, B;
        cin >> A >> B;
        V.at(i) = make_pair(A, B);
    }
    sort(V.begin(), V.end());
    ll cost = 0, cnt = 0;
    for (auto &p : V) {
        if (cnt == M) break;
        cost += p.first * min(M - cnt, p.second);
        cnt = min(M, cnt + p.second);
    }
    cout << cost << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	//ios::sync_with_stdio(false);
	//cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n, t;
	cin >> n >> t;
	vll a(n);
	for (ll i = 0; i < n; i++) cin >> a[i];

	vll b = a; // b[i] := 町iまででの最安値
	for (ll i = 1; i < n; i++) {
		b[i] = min(b[i], b[i - 1]);
	}

	map<ll, ll> mp;
	for (ll i = 0; i < n; i++) {
		ll gain = a[i] - b[i];
		mp[gain]++;
	}

	cout << ((--mp.end()) -> second) << endl;
}


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

int main(){
  int H,W,D,temp,ans;
  cin>>H>>W>>D;
  int d[90001];
  vector<pair<int,int>>A(90001);
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>temp;
      A[temp].first=i;
      A[temp].second=j;
    }
  }
  
  for ( int i = D +1; i <= H * W ; i ++){
    d[ i ]= d [i - D ]+ abs(A[i].first-A[i-D].first)+abs(A[i].second-A[i-D].second);
  }

  int Q,L,R;
  cin>>Q;

  for(int i=0;i<Q;i++){
    ans=0;
    cin>>L>>R;
    if(L==R){
      cout<<0<<endl;
      continue;
    }
    ans=d[R]-d[L];
    cout<<ans<<endl;
  }
  
  return 0;
}



Measured memory_bytes: 4256
n = int(input())
z = []
y = 0
for i in range(n):
  line = input().split(" ")
  if int(line[0])==int(line[1]):
    z.append(i)

for i in range(len(z)-2):
  if z[i]==z[i+1]-1:
    if z[i+1]==z[i+2]-1:
      y += 1
if y > 0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9136
#include<bits/stdc++.h> 
using namespace std;
 
typedef long long int ll;
typedef pair<int,int> pii;

#define ff first
#define ss second
#define vi vector<int>
#define fo(n) for(int i = 0;i < int(n);i++)
#define foo(a,b) for(int i = int(a);i <= int(b);i++)
#define mk make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define fastio ios_base:: sync_with_stdio(false)


const int MAXN = 1e6;
const int mod = 1e9 + 7;
const int inf = 1e9;



int main(){	
	fastio;
	int l,r;
	cin >> l >> r;

	int num_mul = floor(r/2019) - ceil(l/2019);

	if(num_mul > 0){
		cout << 0 << endl;
	}

	else{
		ll ans = inf;

		for(int i = l;i < r;i++){
			for(int j = i+1;j <= r;j++){
				ll val = (ll)i*j;
				ans = min(ans, val%2019);
			}
		}

		cout << ans << endl;
	}

	return 0;
 }	

Measured memory_bytes: 256
// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <set>
#include <string>
#include <vector>

// namespace
using namespace std;

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VB> VVB;

// container
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define SORT(c) sort((c).begin(), (c).end())
#define GSORT(c) sort((c).begin(), (c).end(), greater<decltype((c).front())>())
#define SZ(x) ((int)(x).size())
#define MEMSET(c, v) memset((c), v, sizeof(c))

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// constant
// const ll MOD = 1e9 + 7;
// const int INF = 1e9;
// const ll INF = 1e15;
// const int dx[4] = {0, -1, 1, 0};
// const int dy[4] = {-1, 0, 0, 1};
// const int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;


// --------------------------------------------------------


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

  int n;
  cin >> n;
  VI a(n);
  REP(i, n) {
    cin >> a[i];
  }

  REP(i, (n + 1) / 2) {
    cout << a[n - i * 2 - 1] << " ";
  }

  REP(i, n / 2) {
    cout << a[i * 2 + n % 2] << " ";
  }

  cout << endl;

  return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <cstring>
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;


int main() {
	int n,ans=0;
	cin >> n;
	if (n % 2 == 0)ans = n / 2;
	else ans = (n + 1) / 2;
	cout << ans << endl;
	
	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long n,k;
    cin >> n >> k;
    long a[n+1];
    for(int i=1;i<=n;i++)cin >> a[i];
    
    vector<int>distance(n+1,-1);
    distance[1] = -1;
    int now = 1;
    int loopfirst = 0;
    int looplength = 0;
    int tmp = 0;
    while(distance[now] == -1){
        distance[now] = tmp;
        now = a[now];
        tmp++;
    }
    loopfirst = now;
    looplength = tmp - distance[now];


    if(distance[now] >= k){
        for(int i=1;i<=n;i++){
            if(distance[i] == k){
                cout << i << endl;
                break;
            }
        }
    }else{
        k -= distance[now];
        k %= looplength;
        while(k>0){
            k--;
            now = a[now];
        }
        cout << now << endl;
    }
}


Measured memory_bytes: 5636
#include "iostream"
#include "random"
#include "ctime"
#include "chrono"
#include "string"
#include "bitset"
#include "algorithm"
#include "map"

using namespace std;


int main() {
	int N;
	cin >> N;
	while (N) {
		vector<pair<string, string>>v(N);
		for (int i = 0; i < N; i++) {
			cin >> v[i].first >> v[i].second;
		}
		map<string, int>m;
		sort(v.begin(), v.end());
		int ans = 0;
		for (auto i : v) {
			if (m.empty()) {
				m[i.second]++;
				ans++;
				continue;
			}
			if ((*m.begin()).first <= i.first) {
				m[(*m.begin()).first]--;
				if ((*m.begin()).second == 0) {
					m.erase(m.begin());
				}
				m[i.second]++;
			}
			else {
				m[i.second]++;
				ans++;
			}
		}
		cout << ans << endl;
		cin >> N;
	}
	return 0;
}


Measured memory_bytes: 4196
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

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

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

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

    vector<ll> H(N, 0);
    rep (i, N) { cin >> H[i]; }

    vector<bool> X(N, true);

    rep (i, M)
    {
        ll a, b;
        cin >> a >> b;
        --a;
        --b;

        if (H[a] <= H[b])
        {
            X[a] = false;
        }

        if (H[b] <= H[a])
        {
            X[b] = false;
        }
    }

    ll ans = 0;
    rep (i, N) { ans += X[i] ? 1 : 0; }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4052
#include<stdio.h>
#include<string.h>
int main ()
{
    char A[20],B[20],C[20];
    int x,y,z;
    scanf("%s %s %s",&A,&B,&C);
    x=strlen(A)-1;
    y=strlen(B)-1;
    if((A[x]==B[0]) && (B[y]==C[0]) )
        printf("YES");
    else printf("NO");
    return 0;
}


Measured memory_bytes: 1732
n=int(input())
a=[int(x) for x in input().split()]
arr=[]
minn=2*(10**5)+1
for i in range(n):
    if a[i]<minn:
        minn=a[i]
    arr.append(minn)
#print(arr)
co=0
for i in range(len(arr)):
    if arr[i]>=a[i]:
        co+=1
print(co)

Measured memory_bytes: 25768
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d,e,k;
	cin>>a>>b>>c>>d>>e>>k;
	if(b-a<=k&&c-a<=k&&d-a<=k&&e-a<=k&&c-b<=k&&d-b<=k&&e-b<=k&&d-c<=k&&e-c<=k&&e-d<=k){
		cout<<"Yay!"; 
	}
	else{
		cout<<":(";
	}
	return 0;
} 

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

using namespace std;

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

    int n, k, ans = 0;
    
    cin >> n >> k;
    
    vector<int> p;
    
    for (int i=0; i<n; i++)
    {
        int x;
        cin >> x;
        p.push_back(x);
    }
    
    sort(p.begin(), p.end());
    
    for (int i=0; i<k; i++) ans += p[i];
    
    cout << ans << endl;
    
    
}


Measured memory_bytes: 3640
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

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

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.

	LL a, b;
	string ans;

	cin >> a >> b;
	if (a > 0) {
		ans = "Positive";
	}
	else if (b >= 0) {
		ans = "Zero";
	}
	else {
		if (abs(a - b) % 2 == 0) {
			ans = "Negative";
		}
		else {
			ans = "Positive";
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
use proconio::{input, fastout};
use std::cmp::max;

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        hx: [usize; n],
        ab: [(usize, usize); m]
    }

    let mut ma = vec![0; n];
    
    for (a, b) in ab.into_iter() {
        let a = a-1;
        let b = b-1;

        ma[a] = max(ma[a], hx[b]);
        ma[b] = max(ma[b], hx[a]);
    }

    let mut count = 0;

    for (h, ma) in hx.iter().zip(ma.iter()) {
        if h > ma {
            count += 1;
        }
    }

    println!("{}", count);
}

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

int main() {
  int N, H, W;
  cin >> N >> H >> W;
  int a, b;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    if (a >= H && b >= W) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3600
import java.util.*

fun main(args: Array<String>) {
    val scn = Scanner(System.`in`)
    val N = scn.nextInt()

    var P = ""
    var Q = ""

    for(i in 1..N){
        P += scn.nextInt().toString()
    }
    for(j in 1..N){
        Q += scn.nextInt().toString()
    }

    var ele = ""
    for(i in 1..N){
        ele += i.toString()
    }
    var allList = mutableListOf<Int>()

    permutation(ele, "", allList)
    allList.sort()

    var a = 0
    var b = 0
    var cnt = 1
    for(e in allList){
        if(e==P.toInt()) a = cnt
        if(e==Q.toInt()) b = cnt

        if(a!=0 && b!= 0) break

        cnt++
    }

    println(Math.abs(a-b))
}

fun permutation(q: String, ans: String, ret:MutableList<Int>) { // Base Case
    if (q.length <= 1) {
        ret.add( (ans+q).toInt() )
    } else {
        for (i in 0 until q.length) {
            permutation(
                q.substring(0, i) + q.substring(i + 1),
                ans + q[i],
                ret
            )
        }
    }
}

Measured memory_bytes: 48068
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,-1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,1,1,-1,-1};
const int INF = 1e9;
const long long LINF = 1e18;
const double EPS = 4*1e-8;
#define PB push_back
#define mk make_pair
#define fr first
#define sc second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef vector<int> vi;
typedef pair<string, int> Psi;
typedef pair<ll, ll> Pll;

vi ng;

struct edge{
	int to;
	ll cost;
	edge(){}
	edge(int to,ll cost){
		this->to = to;
		this->cost = cost;
	}
	bool operator<(const edge &a)const{
		return cost > a.cost;
	}
};

vector < edge > G[100010];

int main(){
	int N,M,K,S;
	scanf("%d%d%d%d",&N,&M,&K,&S);

	ll P,Q;
	scanf("%lld%lld",&P,&Q);

	rep(i,K){
		int c;
		scanf("%d",&c);
		--c;
		ng.PB(c);
	}

	sort(ng.begin(),ng.end());

	/*rep(i,ng.size()){
		printf("ng : %d\n",ng[i]);
	}*/

	rep(i,M){
		int a,b;
		scanf("%d%d",&a,&b);
		--a;--b;
		G[b].PB(edge(a,P));
		G[a].PB(edge(b,P));
	}


	queue < Pii > Queue;
	int memo[100001] = {0};
	ll dijk[100001];

	rep(i,100001){
		dijk[i] = LINF;
	}

	rep(i,ng.size()){
		Queue.push(Pii(ng[i],S));
	}

	while(!Queue.empty()){
		Pii p = Queue.front();Queue.pop();

		if(memo[p.fr] != 0)continue;
		memo[p.fr] = 1;
		if(binary_search(ng.begin(),ng.end(),p.fr) == true){
			memo[p.fr] = 2;
		}

		if(p.sc == 0)continue;

		rep(i,G[p.fr].size()){
			Queue.push(Pii(G[p.fr][i].to,p.sc-1));
		}

	}

	/*rep(i,N){
		printf("[%d] : %d\n",i,memo[i]);
	}*/

	priority_queue < edge > pq;
	pq.push(edge(0,0));

	while(!pq.empty()){
		edge e = pq.top();pq.pop();

		if(dijk[e.to] != LINF)continue;
		dijk[e.to] = e.cost;

		rep(i,G[e.to].size()){
			if(G[e.to][i].to == N-1){
				pq.push(edge(N-1,e.cost));
			}
			if(memo[G[e.to][i].to] != 0){
				if(memo[G[e.to][i].to] == 2)continue;
				pq.push(edge(G[e.to][i].to,Q + e.cost));
			}
			else pq.push(edge(G[e.to][i].to,P + e.cost));
		}

	}

	printf("%lld\n",dijk[N-1]);


	return 0;
}

Measured memory_bytes: 17616
#include <iostream>
#define max(a,b) (a>b)?a:b
#define ll long long
using namespace std;

int main() {
    ll N,M,K,d,j;
    cin >> N >> M >> K;
    ll ar1[N+1]={},ar2[M+1]={};
    for(ll i=1;i<=N;i++)
    {
        cin >> d;
        ar1[i] = ar1[i-1]+d;
    }
    for(ll i=1;i<=M;i++)
    {
        cin >> d;
        ar2[i] = ar2[i-1]+d;
    }
    // cout << ar1[N] << ar2[M];
    j=M;
    ll ans=0;
    for(ll i=0;i<=N;i++)
    {
        if(ar1[i]>K)
            break;
        while(ar1[i]+ar2[j]>K)
            j--;
        ans = max(ans,i+j);
    }
    cout << ans;
	return 0;
}


Measured memory_bytes: 6716
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 2e5 + 5;

int n,d;
int a[MAXN];

bool check(int mid)
{
	ll res = 0;
	for(int i=1; i<=n; ++i)
		res += (a[i] + mid - 1) / mid - 1;
	return res <= d;
}

int main(void)
{
	scanf("%d%d",&n,&d);
	for(int i=1; i<=n; ++i) scanf("%d",&a[i]);
	
	int l=1, r=1e9;
	while(l<r)
	{
		int mid=(l+r)>>1;
		if(check(mid)) r=mid;
		else l=mid+1;
	}
	printf("%d",l);
	return 0;
}

Measured memory_bytes: 4496
N, K = map(int, input().split())
S = input()

if len(set(S)) == 1:
  print(len(S))
  exit(0)
  

nums = []
if S[0] != '1':
  nums.append(0)

current = S[0]
count = 1
for i, s in enumerate(list(S)):
  if i == len(S)-1:
    nums.append(count)
    break
  if S[i+1] != s:
    nums.append(count)
    count = 1
    current = s
  else:
    count += 1

if S[len(S)-1] != '1':
  nums.append(0)

sums = [0]
for index, i in enumerate(nums):
  sums.append(sums[index] + i)
  
res = 0
for left in range(0, len(sums), 2):
  right = left + K*2 + 1
  if right > len(sums):
    right = len(sums) - 1
  res = max(res, sums[right] - sums[left])
  
print(res)

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

int main(){
    int r;
    cin >> r;
    cout << r * r << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int a,b;
  char op;
  while(1)
    {
      scanf("%d %c %d",&a,&op,&b);
      if(op=='?') break;
      else if(op== '+') printf("%d\n",a+b);
      else if(op== '-') printf("%d\n",a-b);
      else if(op== '*') printf("%d\n",a*b);
      else if(op== '/') printf("%d\n",a/b);
    }
  return 0;
}

Measured memory_bytes: 600