akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
    ll n;
    cin >> n;
    deque<ll> d;
    for(ll i = 1;i<=n;i++){
        ll a;
        cin >> a;
        if(i%2)d.push_back(a);
        else d.push_front(a);

    }
    if(n%2 == 0){
        for(ll i : d)cout << i << " ";
        cout << "\n";
    }else{
        reverse(d.begin(),d.end());
        for(ll i : d)cout << i << " ";
        cout << "\n";
    }
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 3840
import sys
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

input = sys.stdin.readline

cost = []
row = []
col = []

n, m, l = list(map(int, input().split()))

for _ in range(m):
    a, b, c = map(int, input().split())
    cost.append(c)
    row.append(a-1)
    col.append(b-1)

q = int(input())
st = [list(map(int, input().split())) for _ in range(q)]

csr = csr_matrix((cost, (row, col)), shape = (n, n))
path = floyd_warshall(csr, directed=False)

cost = []
row = []
col = []

for i in range(n):
    for j in range(n):
        if path[i][j] <= l:
            cost.append(1)
            row.append(i)
            col.append(j) 

csr = csr_matrix((cost, (row, col)), shape = (n, n))
path = floyd_warshall(csr, directed=False)

INF = float('inf')

for s,t in st:
    ans = path[s-1][t-1]
    if ans == INF:
        print(-1)
    else:
        print(int(ans) - 1)






Measured memory_bytes: 38408
#pragma warning(disable:4996)
//#define _CRT_NONSTDC_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
#include <math.h>
#include <bitset>
#include <fstream>
#include <numeric>
#include <sstream>
#include <algorithm>
#include <string>
#include <cstring>
#include <iomanip>
#include <unordered_map>
#include <ctime>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
 
 
using namespace std;
typedef long long ll;
typedef long double ld;
                        
#define all(x)   (x).begin(), (x).end()           /*sorting STL */
#define fastio	 ios_base::sync_with_stdio(0);  cin.tie(nullptr);  cout.tie(nullptr)
 
#define TRIPmin(a, b, c) 	min(a, min(b, c))
#define TRIPmax(a, b, c)    max(a, max(b, c))
#define fillchar(a,x) 		memset(a, x, sizeof (a))
 
//#define mod		(1000000000+7)
 
/***********************************************************************/
 
int main() {
    ll n, ans = 0;
    ld d;
    cin >> n >> d;
    for(int i = 1; i <= n; i++) {
        ld x, y;
        cin >> x >> y;
        ld tmp = sqrt(x*x + y*y);
        if(tmp <= d) ans++;
    }
    cout << ans;
    return 0;
}

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

int main() {
  string s,t;
  cin >>s >>t;
  int cnt = 0;
  rep(i,s.size()){
    if(s[i]!=t[i]) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3836
# 人の解答
s=input()
k=int(input())

# 1文字だけからなる場合
if len(set(list(s)))==1:
  print((len(s)*k)//2)
  exit()

# それ以外
t=[1]
for i in range(1,len(s)):
  if s[i-1]==s[i]:
    t[-1]+=1
  else:
    t.append(1)

a=0
for i in t:
  a+=(i//2)*k

# 両端がともに奇数の場合のみ，置換する文字を追加
if s[0]==s[-1]:
  if t[0]%2==t[-1]%2==1:
    a+=k-1

print(a)


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

int main() {
  int n;
  cin >> n;
  priority_queue<double, vector<double>, greater<double> > v;

  double a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push(a);
  }
  double p, q;

  while(true){
    p = v.top();
    v.pop();
    if (v.empty()){
        break;
    }
    q = v.top();
    v.pop();
    v.push((double)((p+q)/2));
  }

  cout << p << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Node{
	int table[26];
	bool finish_FLG;
};

Node nodes[200001];

int node_index = 1,N,length;
ll dp[100001];
char buf[100001];

ll recursive(int start_pos){

	if(dp[start_pos] != -1)return dp[start_pos];

	stack<int> S;

	int tmp_ch,tmp_node_index = 0,ch_loc = start_pos,depth = 0;

	while(true){
		tmp_ch = buf[ch_loc]-'a';

		if(nodes[tmp_node_index].table[tmp_ch] == -1)break;

		tmp_node_index = nodes[tmp_node_index].table[tmp_ch];
		depth++;

		if(nodes[tmp_node_index].finish_FLG){
			S.push(start_pos+depth);
		}

		ch_loc++;

		if(buf[ch_loc] == '\0')break;
	}

	dp[start_pos] = 0;

	while(!S.empty()){
		dp[start_pos] += recursive(S.top());
		dp[start_pos] %= MOD;
		S.pop();
	}

	dp[start_pos] %= MOD;

	return dp[start_pos];
}

int main(){

	for(int i = 0; i <= 200000; i++){
		for(int k = 0; k < 26; k++)nodes[i].table[k] = -1;
		nodes[i].finish_FLG = false;
	}

	scanf("%d",&N);

	int tmp_ch,tmp_node_index,ch_loc;

	for(int loop = 0; loop < N; loop++){
		scanf("%s",buf);

		tmp_node_index = 0;
		ch_loc = 0;

		while(true){
			tmp_ch = buf[ch_loc]-'a';

			if(nodes[tmp_node_index].table[tmp_ch] == -1){
				nodes[tmp_node_index].table[tmp_ch] = node_index;
				tmp_node_index = node_index;
				node_index++;
			}else{
				tmp_node_index = nodes[tmp_node_index].table[tmp_ch];
			}
			ch_loc++;
			if(buf[ch_loc] == '\0'){
				nodes[tmp_node_index].finish_FLG = true;
				break;
			}
		}
	}

	scanf("%s",buf);

	for(length = 0; buf[length] != '\0'; length++);
	for(int i = 0; i < length; i++)dp[i] = -1;
	dp[length] = 1;

	printf("%lld\n",recursive(0));

	return 0;
}

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

int main(void){
  char s[20];
  scanf("%s",s);
  if(s[0]=='Y' && s[1]=='A' && s[2]=='K' && s[3]=='I') printf("Yes\n");
  else printf("No\n");
  return 0;
}


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

typedef long long ll;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007


#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(int i=a;i<b;i++)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}


int main()
{
   su;
   ll n,m,x,y,sum=0;
   cin>>n>>m;
   pll p[n];
   lo(i,0,n)
   {
     cin>>x>>y;
     p[i]={x,y};
   }
   sort(p,p+n);
   for(int i=0;i<n;i++)
   {
     if(m<=0)
      break;
     else if(p[i].S<=m)
     {
       sum+=p[i].F*p[i].S;
       m-=p[i].S;
     }
     else
     {
       sum+=m*p[i].F;
       m=0;
     }
   }
   cout<<sum<<nl;
   return 0;
}


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

int N, A[1 << 18], S;

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> A[i];

	for (int i = 1; i <= N; i++) {
		for (int j = i + 1; j <= N; j++) S += A[i] * A[j];
	}
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
	ios::sync_with_stdio(false);
	ll a, b;
	cin >> a >> b;
	ll c = (a + b) / 2LL;
	if (abs(a - c) == abs(b - c))
		cout << c << endl;
	else
		cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ls(x) (x)<<1
#define rs(x) (x)<<1|1
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl '\n'
#define lcm(a,b) (a*b)/__gcd(a,b)
#define Case(i,ans) cout<<"Case "<<i<<": "<<ans<<endl;
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) (x)&(-x)
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) (x)%mo_num
#define vc vector
#define vct vector<int>
#define fa(i,V) for(auto i:V)
#define out(i) cout<<i<<endl;
#define fi first
#define sc second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
//#define P pair<int,int>
using namespace std;
const int INF=1e17+5;
const int maxn=2e5+5;
const int mo_num=1e9+7;
int n,m,a[maxn],b[maxn],ans;
int32_t main()
{
    IOS
    cin>>n;
    fun(i)
    {
        cin>>a[i];
    }
    fd(i,n,1)
    {
        int sum=0;
        for(int j=i;j<=n;j+=i)
        {
            if(b[j])sum++;
        }
        if(sum%2!=a[i]) {
            b[i] = 1;
            ans++;
        }
    }
    out(ans)
    if(ans)
        fu(i,1,n)
        {
            if(b[i])cout<<i<<" ";
        }
    return 0;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = pow(10, 9) + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divCeil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << A << endl; exit(0);}

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

  string ans;
  if (S == "Sunny")
    ans = "Cloudy";
  else if (S == "Cloudy")
    ans = "Rainy";
  else if (S == "Rainy")
    ans = "Sunny";

  cout << ans << endl;
}

Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n,k;
  cin>>n>>k;
  vector<int> x(n);
  for(int i=0; i<n; i++){
    cin>>x.at(i);
  }

  long long int ans=0;
  for(int i=0; i<n; i++){
    int pre=min(x.at(i),abs(x.at(i)-k));
    pre*=2;
    ans+=pre;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
N = int(input())
n = 0
k = 0
even = True
if N > 0:
    while N > 0:
        if N & 1:
            if even:
                if n & 1 << k:
                    n = n + (5<<k)
                else:
                    n = n + (1<<k)
            else:
                if n & 1 << k:
                    n = n - (1<<k)
                else:
                    n = n + (3<<k)
        even = not even
        N = N >> 1
        k += 1
else:
    N = -N
    while N > 0:
        if N & 1 != 0:
            if even:
                if n & 1 << k:
                    n = n - (1<<k)
                else:
                    n = n + (3<<k)
            else:
                if n & 1 << k:
                    n = n + (5<<k)
                else:
                    n = n + (1<<k)
        even = not even
        N = N >> 1
        k += 1
print(bin(n)[2:])

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

#define pb push_back
typedef long long ll;

int n, a[200005],b[200005];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    for(int i = 0;i <n; i ++){
        int tem = n-i-1;
        if(i%2==0){
            b[i/2] = a[tem];
        }
        else{
            b[n-(i+1)/2]= a[tem];
        }
    }
    for(int i = 0; i < n; i++)cout<<b[i]<<' ';

    return 0;
}


Measured memory_bytes: 3712
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
g = []
for i in range(n): g.append([])
for i in range(n-1):
    x, y = na()
    x -= 1
    y -= 1
    g[x].append(y)
    g[y].append(x)

dp = [0] * n
ep = [0] * n
des = [0] * n

def enumfif(n, mod):
    f = [0] * (n+1)
    invf = [0] * (n+1)
    f[0] = 1
    for i in range(1, n+1):
        f[i] = f[i-1] * i % mod

    a = f[n]
    b = mod
    p, q = 1, 0
    while b > 0:
        c = a//b
        d = a; a = b; b = d % b
        d = p; p = q; q = d-c*q
    invf[n] = p + mod if p < 0 else p
    for i in range(n-1,-1,-1):
        invf[i] = invf[i+1] * (i+1) % mod
    return f, invf

def C(n, r, mod, fif):
    if n < 0 or r < 0 or r > n:
        return 0
    return fif[0][n] * fif[1][r] * fif[1][n-r] % mod

mod = 1000000007
fif = enumfif(200005, mod)

sys.setrecursionlimit(200005)

def dfs(cur, pre, g):
    val = 1
    de = 0
    for e in g[cur]:
        if e == pre: continue
        dfs(e, cur, g)
        de += des[e]
        val = val * dp[e] * C(de, des[e], mod, fif) % mod
    dp[cur] = val
    des[cur] = de + 1

def dfs2(cur, pre, g):
    # print(cur, pre)
    for e in g[cur]:
        if e == pre: continue
        val = dp[cur] * fif[1][n-1] * fif[0][n-des[e]-1] * fif[0][des[e]] % mod
        dp[e] = val * C(n-1, n-des[e], mod, fif) % mod
        # val = dp[cur] * fif[1][n-1] * fif[0][n-des[e]-1] * fif[0][des[e]] * invl(dp[e], mod) % mod
        # dp[e] = dp[e] * val * C(n-1, n-des[e], mod, fif) % mod
        dfs2(e, cur, g)

def invl(a, mod):
    b = mod
    p = 1; q = 0
    while b > 0:
        c = a // b
        a, b = b, a%b
        p, q = q, p-c*q
    return p + mod if p < 0 else p


dfs(0, -1, g)
dfs2(0, -1, g)
for val in dp:
    print(val)


Measured memory_bytes: 146916
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define rep(n) for(int i=0;i<n;i+=1)
#define fill(c,v) memset(c,v,sizeof(c));
#define prarr(a,n) rep(n) cout<<a[i]<<" \n"[i==n-1]; 
#define sc(a) scanf("%d",&a);
#define scl(a) scanf("%lld",&a);
#define scf(a) ascanf("%f",&a);
#define ff first
#define ss second
#define pu push_back
#define inf 1000000001
#define MOD 1000000007 
#define INF 100000000000001
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin>>n;
    int x,y;
    for(int x = 0 ; x <= 25 ; x++)
    {
    	for(int y = 0; y < 15; y++)
    	{
    		if(4*x+7*y==n)
    		{
    			printf("%s\n","Yes" );
    			return 0;
    		}
    	}
    }
    printf("%s\n","No" );
    return 0;

}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int a,b,c,d,s,t=0,n,m;
    cin>>n>>m;
    int x[m]={0};
    for(a=0;a<n;a++){
        cin>>s;
        for(b=0;b<s;b++){
            cin>>c;
            x[c-1]++;
        }
    }
    for(d=0;d<m;d++){
        if(x[d]==n){
            t++;
        }
    }
    cout<<t;
}


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

int main()
{
    int a, b;
    cin >> a >> b;
    if (a * b % 2 == 0)
    {
        cout << "Even" << endl;
    }
    else
    {
        cout << "Odd" << endl;
    }
    return 0;
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

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

double count(int k, int p)
{
    double r = 0;
    while (p < k)
    {
        r++;
        p *= 2;
        //cout << p << endl;
    }
    return r;
}

int main()
{
    double N;
    int K;
    double ans = 0.;
    cin >> N >> K;
    for (int i = 1; i <= N; i++)
    {
        if (i >= K)
            ans += 1 / N;
        else
        {
            double r = count(K, i);
            ans += pow(0.5, r) / N;
            //cout << pow(0.5, r) << endl;
            //cout << r << endl;
        }
    }
    cout << setprecision(15) << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,l,r) for(int i=l;i<=r;i++)
#define of(i,l,r) for(int i=l;i>=r;i--)
#define fe(i,u) for(int i=head[u];i;i=e[i].next)
#define el putchar('\n')
#define ta putchar('	')
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
inline void open(const char *s)
{
	#ifndef ONLINE_JUDGE
	char str[20];
	sprintf(str,"%s.in",s);
	freopen(str,"r",stdin);
//	sprintf(str,"%s.out",s);
//	freopen(str,"w",stdout);
	#endif
}
namespace IO{
const int S=(1<<20)+10;
char buf[S],*H,*T;
inline char Get()
{
	if(H==T)T=(H=buf)+fread(buf,1,S,stdin);
	if(H==T)return -1;return *H++;
}
inline int rd()
{
	static int x,f;
	x=0;f=1;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
	return f>0?x:-x;
}
}using IO::rd;
const int N=200010;
int n,head[N],tot=0,d[N];
struct edge{int v,w,next;}e[N<<1];
ll dep[N];
vector<pii>a[N];
#define fi first
#define se second

inline void add(int u,int v,int w){e[++tot]=edge{v,w,head[u]};head[u]=tot;}

void dfs(int u,int fat)
{
	fe(i,u){
		int v=e[i].v;if(v==fat)continue;
		dep[v]=dep[u]+e[i].w;dfs(v,u);++d[u];
	}
}

inline void ins(vector<pii>&vi,pii x)
{
	if(vi.size()&&vi.back().se<=x.se)return;
	while(vi.size()&&vi.back().fi==x.fi&&vi.back().se>x.se)vi.pop_back();
	vi.push_back(x);
}

inline int serch1(pii x,vector<pii>&vi,int u,ll K)
{
	if(!vi.size())return -1;
	int l=0,r=vi.size()-1;
	while(l<=r){
		int mid=(l+r)>>1;
		if(vi[mid].fi+x.se-dep[u]-dep[u]<=K)l=mid+1;
		else r=mid-1;
	}
	return l-1;
}
inline int serch2(pii x,vector<pii>&vi,int u,ll K)
{
	if(!vi.size())return -1;
	int l=0,r=vi.size()-1;
	while(l<=r){
		int mid=(l+r)>>1;
		if(vi[mid].se+x.fi-dep[u]-dep[u]<=K)r=mid-1;
		else l=mid+1;
	}
	return l==(int)vi.size()?-1:r+1;
}

inline void merge(int u,int ls,int rs,ll K)
{
	if(a[ls].size()>a[rs].size())swap(ls,rs);
	static vector<pii>tmp1,tmp2;tmp1.clear();tmp2.clear();
	for(auto x:a[ls]){
		int res1=serch1(x,a[rs],u,K);
		if(~res1)tmp1.emplace_back(x.fi,a[rs][res1].se);
		int res2=serch2(x,a[rs],u,K);
		if(~res2)tmp2.emplace_back(a[rs][res2].fi,x.se);
	}
	int t1=0,t2=0;
	while(t1<(int)tmp1.size()&&t2<(int)tmp2.size()){
		pii x=tmp1[t1],y=tmp2[t2];
		if(x.fi==y.fi){
			++t1;++t2;
			ins(a[u],x);
			ins(a[u],y);
		}
		else if(x.fi<y.fi){
			ins(a[u],x);++t1;
		}
		else{
			ins(a[u],y);++t2;
		}
	}
	while(t1<(int)tmp1.size())ins(a[u],tmp1[t1++]);
	while(t2<(int)tmp2.size())ins(a[u],tmp2[t2++]);
}

void dfs1(int u,int fat,ll K)
{
	if(!d[u])return a[u].emplace_back(dep[u],dep[u]),void();
	int ls=0,rs=0;
	fe(i,u){
		int v=e[i].v;if(v==fat)continue;
		dfs1(v,u,K);
		if(!ls)ls=v;
		else rs=v;
	}
	merge(u,ls,rs,K);
}

inline bool check(ll K)
{
	fo(i,1,n)a[i].clear();
	dfs1(1,0,K);
	if(!a[1].size())return 0;
	return 1;
}

int main()
{
	n=rd();
	fo(i,2,n){
		int x=rd(),y=rd();
		add(i,x,y);
		add(x,i,y);
//		cout<<x<<' '<<i<<' '<<y<<endl;
	}
	dfs(1,0);
	ll l=0,r=1e12;////////////////////////////////////////////////
	while(l<=r){
		ll mid=(l+r)>>1;
		if(check(mid))r=mid-1;
		else l=mid+1;
	}
	printf("%lld\n",r+1);
	return 0;
}


Measured memory_bytes: 35428
#include<bits/stdc++.h>
#define rep(i,k,n) for(ll i= (ll) k;i< (ll) n;i++)
#define all(v) (v).begin(), (v).end()
#define SZ(v) (int)((v).size())
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long long INF = 1e18L + 1;
const int IINF = 1e9 + 1;

using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define DBG(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int main() {
	#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	#endif
	int n, a, b;
	cin >> n >> a >> b;
	if (abs(b - a) % 2 == 0) {
		cout << "Alice";
	} else {
		cout << "Borys";
	}
}


Measured memory_bytes: 256
A = input()
a,b = (A.split(' '))
B = input()
c,d = (B.split(' '))
e = int(c)
f = int(d)
C = input()

if a == C:
    print('{} {}'.format(e-1,f))
else:
    print('{} {}'.format(e,f-1))


Measured memory_bytes: 3060
import java.util.Scanner;

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

		String a = sc.next();
		String b = sc.next();
		String h = "H";
		String d = "D";

		if (a.equals(h)) {
			if (b.equals(h)) {
				System.out.println("H");
			} else if (b.equals(d)) {
				System.out.println("D");
			}
		} else if (a.equals(d)) {
			if (b.equals(h)) {
				System.out.println("D");
			} else if (b.equals(d)) {
				System.out.println("H");
			}
		}
	}
}

Measured memory_bytes: 21844
def examA():
    N, M = LI()
    l = 1; r = N
    for _ in range(M):
        L, R = LI()
        l = max(L,l)
        r = min(R,r)
    ans = max(0,r-l+1)
    print(ans)
    return

def examB():
    N = I()
    S = [I()for _ in range(N)]
    rest = []
    for s in S:
        if s%10==0:
            continue
        rest.append(s)
    if sum(S)%10==0:
        if not rest:
            print(0)
            return
        ans = sum(S) - min(rest)
    else:
        ans = sum(S)
    print(ans)
    return

def examC():
    N, K = LI()
    K -= 1
    A = LI()
    L = A.index(1)
    #print(L)
    ans = (N-1+K-1)//K
    print(ans)
    return

def examD():
    def ketadp(a):
        n = len(a)
        dp = defaultdict(int)
        dp[0, 0, 0, 0, 0] = 1
        for i, less, has3, has5, has7 in itertools.product(range(n), (0, 1), (0, 1), (0,1), (0,1)):
            max_d = 7 if less else int(a[i])
            for d in range(max_d + 1):
                if d==0 and has3==0 and has5==0 and has7==0:
                    dp[i + 1, 1, has3, has5, has7] += dp[i, less, has3, has5, has7]
                if not (d==3 or d==5 or d==7):
                    continue
                less_ = less or d < max_d
                has3_ = has3 or d == 3
                has5_ = has5 or d == 5
                has7_ = has7 or d == 7
                dp[i + 1, less_, has3_, has5_, has7_] += dp[i, less, has3, has5, has7]

        ans = sum(dp[n, less, 1, 1, 1] for less in (0, 1))
        return ans
    N = SI()
    ans = ketadp(N)
    print(ans)
    return

def examE():
    N = I()
    A = [I()for _ in range(N)]
    que = deque()
    que.append(A[0])
    for a in A[1:]:
        cur = bisect.bisect_left(que,a)
        if cur==0:
            que.appendleft(a)
        else:
            que[cur-1] = a
    ans = len(que)
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int,readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examE()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Measured memory_bytes: 10436
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
//#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

char str[305][305];
int  a[305][305];

void solve()
{
    int n;
    scanf("%d", &n);
    int i, j, k;
    for (i = 0; i < n; i++) {
        scanf("%s", str[i]);
    }
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            for (k = 0; k < n; k++) {
                int i2 = (i + k) % n, j2 = (j + k) % n;
                if (str[i2][j] != str[i][j2]) {
                    break;
                }
            }
            a[i][j] = k;
        }
    }

    int cnt = 0;
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            for (k = 0; k < n; k++) {
                int i2 = (i + k) % n, j2 = (j + k) % n;
                if (a[i2][j2] < n - k) {
                    break;
                }
            }
            if (k == n) cnt++;
        }
    }
    printf("%d\n", cnt);

    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>

using namespace std;
 
int main(){
    int a, b, intans1, intans2;
    double fans;
    cin >> a >> b;

    if (a==0 || b==0) {
        return 0;
    }

    intans1 = a / b;
    intans2 = a % b;
    fans = static_cast<double>(a) / static_cast<double>(b);

    cout << intans1 << ' ' << intans2 << ' ';
    printf("%.5lf\n", fans);
    return 0;
}

Measured memory_bytes: 1240
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

A,B = inpl()

if (A*B)%2 == 0:
	print('No')
else:
	print('Yes')


Measured memory_bytes: 4848
# -*- coding: utf-8 -*-

def main():
    N, M =  [int(i) for i in input().split()]
    cities = []

    for i in range(M):
        p, y = map(int, input().split())
        cities.append([p, y, i])

    cities.sort()
    ans = []

    num = 0
    before = cities[0][0]

    for i in range(M):
        if before != cities[i][0]:
            num = 1
            before = cities[i][0]
        else:
            num += 1
        ans.append([cities[i][0], num, cities[i][2]])

    ans.sort(key=lambda x:x[2])
    for a in ans:
        s = str(a[0]).zfill(6) + str(a[1]).zfill(6)
        print(s)



if __name__ == "__main__":
    main()


Measured memory_bytes: 37920
#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f;
const ll mod = 998244353LL;
clock_t TIME_START, TIME_END;
void program_end()
{
#ifdef ONLINE
    printf("\nTime used: %.6lf(s)\n", ((double)TIME_END - TIME_START) / CLOCKS_PER_SEC);
    system("pause");
#endif
}
int n, m;
vector<int> e[N];
int p[N];
bool vis[N];
queue<int> q;
void bfs()
{
    while (!q.empty())
    {
        int u = q.front();
        q.pop();
        vis[u] = 1;
        for (auto v : e[u])
        {
            if (vis[v])
                continue;
            p[v] = u;
            vis[v] = 1;
            q.push(v);
        }
    }
}

void solve()
{
    cin >> n >> m;
    for (int i = 1; i <= m; ++i)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        e[x].push_back(y);
        e[y].push_back(x);
    }
    q.push(1);
    bfs();
    for (int i = 1; i <= n; ++i)
        if (!vis[i])
            return puts("No"), void();
    puts("Yes");
    for (int i = 2; i <= n; ++i)
        cout << p[i] << '\n';
}

int main()
{
    TIME_START = clock();
    int Test = 1;
    // cin >> Test;
    while (Test--)
        solve();
    TIME_END = clock();
    program_end();
    return 0;
}

Measured memory_bytes: 19980
#include<cstdio>
using namespace std;
typedef long long int ll;

int N;

int main(){
	scanf("%d", &N);
	if(N == 1){
		printf("Hello World\n");
	}else{
		int A, B;
		scanf("%d", &A);
		scanf("%d", &B);
		printf("%d\n", A + B);
	}
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
typedef long long ll;

ll gcd(ll a, ll b) {
  ll t;
  while( b ) {
    t = a % b;
    a = b;
    b = t;
  }
  return a;
}

int main(void) {
  ll a, b;
  while(scanf("%lld%lld", &a, &b) != EOF) {
    printf("%lld %lld\n", gcd(a, b), a / gcd(a, b) * b);
  }
  return 0;
}


Measured memory_bytes: 2664
#include<stdio.h>
#include<stdlib.h>
long long gcd(long long m,long long n)
{
   return n?gcd(n,m%n):m;
}
 
int main()
{
  long long num1,num2;
   while(scanf("%lld %lld",&num1,&num2)!=EOF)
   {
  long long g=gcd(num1,num2);
   printf("%lld %lld\n",g,num1*num2/g);
   }
   return 0;
}



Measured memory_bytes: 1724
#include<iostream>

using namespace std;

int main(){
  int x[3010]={0};
  int y[3010]={0};

  int i;

  int temp;
  
  for(i=0;i<=3000;i++){
    cin >> x[i] >> y[i];
    if(x[i]==0 && y[i]==0)
      break;
  }

  for(i=0;;i++){
    if(x[i]>y[i]){
      temp = x[i];
      x[i] = y[i];
      y[i] = temp;
    }

    if(x[i]==0 &&  y[i]==0)
      break;
    
    cout << x[i] << " " << y[i] << endl;
  }
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a); i<=int(b); i++)
#define REPC(i,a,b,c) for(int i=(a); i<=int(b); i+=c)
#define f first
#define s second
#define mp make_pair
#define pb push_back
using namespace std;

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

int lcm(int a, int b){
    ll c = 1LL * a * b / __gcd(a,b);
    return c;
}

vector<int> pr[1000001];

void process(){
    REP(i,2,1000000){
        if(pr[i].empty()){
            REPC(j,i,1000000,i) pr[j].pb(i);
        }
    }
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    process();
    bool oks=true;
    int n,a;
    cin >> n;
    unordered_map<int,int> x;
    int gc;
    REP(i,0,n-1){
        cin >> a;
        if(i==0) gc=a;
        else gc=__gcd(gc, a);
        if(oks){
            for(int i: pr[a]){
                if(x[i]){
                    oks=false;
                    break;
                }
                x[i]++;
            }
        }
    }
    if(gc>1) cout << "not coprime";
    else if(oks) cout << "pairwise coprime";
    else cout << "setwise coprime";
    return 0;
}

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

int main()
{
    int N;
    cin >> N;
    map<int, int> time;
    for (int i = 0; i < N; i++) {
        cin >> time[i];
    }
    int M;
    cin >> M;
    int arr[M][3];
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < 2; j++) {
            cin >> arr[i][j];
        }
        arr[i][2] = 0;
    }

    for (int i = 0; i < M; i++) {
        int temp = time[arr[i][0] - 1];
        time[arr[i][0] - 1] = arr[i][1];
        for (int j = 0; j < N; j++) {
            arr[i][2] += time[j];
        }
        time[arr[i][0] - 1] = temp;
    }

    for (int i = 0; i < M; i++) {
        cout << arr[i][2] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define get0(x)     (get<0>(x))
#define get1(x)     (get<1>(x))
#define get2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       9223372036854775807LL
#define LLMIN       -9223372036854775808LL
#define IMAX        2147483647
#define IMIN        -2147483648
typedef long long LL;
using namespace std;

int main(void){
    string S;
    cin>>S;
    REP(i,SZ(S)-1)
        if(S.substr(i,2)=="AC"){
            cout<<"Yes"<<endl;
            return 0;
        }
    cout<<"No"<<endl;
     return 0;
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int N;
int A[100010];
int SL[100010], SR[100010];

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

	cin >> N;
	rep(i, 0, N)
	{
		cin >> A[i];
	}

	rep(i, 1, N)
	{
		SL[i] = SL[i - 1] + abs(A[i] - A[i - 1]);
	}
	rrep(i, 0, N - 1)
	{
		SR[i] = SR[i + 1] + abs(A[i] - A[i + 1]);
	}

	rep(i, 0, N)
	{
		if (i == 0)
		{
			cout << abs(A[1]) + SR[1] + abs(A[N - 1]) << endl;
		}
		else if (i == N - 1)
		{
			cout << abs(A[0]) + SL[N - 2] + abs(A[N - 2]) << endl;
		}
		else
		{
			cout << abs(A[0]) + SL[i - 1] + SR[i + 1] + abs(A[N - 1]) + abs(A[i - 1] - A[i + 1]) << endl;
		}
	}
	

	return 0;
}

Measured memory_bytes: 3584
#include<cstdio>

#define INF 0x3f3f3f3f

using namespace std;

int main(){
	//freopen("in","r",stdin);

	int n;
	scanf("%d",&n);
	int m = INF;
	int res = 0;
	for(int i = 0;i < n;i++){
		int a;
		scanf("%d",&a);
		if(a <= m) m = a, res++;
	}
	printf("%d\n", res);
}

Measured memory_bytes: 128
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;
//
//ll matrix_chain_multiplications(vector<int>& p) {
//    int n = p.size() - 1; // num of matrix
//    vector<vll> dp(n + 1, vll(n + 1, INF));
//
//    // init
//    FOR(i, 1, n + 1) dp[i][i] = 0;
//
//    FOR(l, 2, n + 1) {
//        FOR(i, 1, n - l + 2) {
//            int j = i + l - 1;
//            FOR(k, i, j) {
//                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + p[i - 1] * p[k] * p[j]);
//            }
//        }
//    }
//
//    return dp[1][n];
//}

// 0-indexed
ll matrix_chain_multiplications(vector<int>& p) {
    int n = p.size() - 1; // num of matrix
    vector<vll> dp(n, vll(n, INF)); // dp[l][r] = minimum cost of [l, r], 0 <= l, r < n

    // init
    FOR(i, 0, n) dp[i][i] = 0;

    FOR(l, 2, n + 1) { // l = 2 ~ n
        REP(i, n - l + 1) {
            int j = i + l - 1;
            FOR(k, i, j) {
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + p[i] * p[k + 1] * p[j + 1]);
            }
        }
    }

    return dp[0][n - 1];
}


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

    int n; cin >> n;

    vi p(n + 1);
    REP(i, n) cin >> p[i] >> p[i + 1];

    print(matrix_chain_multiplications(p));
}


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

int main(){
  int n;
  cin>>n;
  vector<int> p(n), q(n);
  rep(i,n) cin>>p[i];
  rep(i,n) cin>>q[i];
  vector<int> a(n);
  rep(i,n) a[i]=i+1;
  
  map<vector<int>,int> mp;
  do{
    mp[a]=mp.size();
  }while(next_permutation(a.begin(),a.end()));
  int ans=abs(mp[p]-mp[q]);
  cout<<ans<<endl;
}



Measured memory_bytes: 5248
#include <iostream>
#include <iomanip>
#include <cmath>

int main(int argc, char const* argv[])
{
	double x1, y1, x2, y2;
	std::cin >> x1 >> y1 >> x2 >> y2;

	double x = std::abs( x1 - x2 );
	double y = std::abs( y1 - y2 );

	std::cout << std::setprecision(20) << std::sqrt( x * x + y * y ) << std::endl;

	return 0;
}

Measured memory_bytes: 3268
#include<iostream>

using namespace std;

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

int main(){
	int n;
	while(cin>>n && n){
		if(is_prime(n)){
			cout<<0<<endl;
			continue;
		}
		else{
			int ans=1;
			for(int i=n+1;!is_prime(i);i++)ans++;
			for(int i=n-1;!is_prime(i);i--)ans++;
			cout<<ans+1<<endl;
		}
	}
}

Measured memory_bytes: 3052
#include <set>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip> //fixed << setprecision(10)

using namespace std;

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

typedef long long ll;
typedef vector<int> vi;

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

    int cnt = 0;
    for (int i = 1; i <= n; i++){
        if (s[i] != s[i - 1]){
            cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 512
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int[] G => ReadLine().Split().Select(int.Parse).ToArray();
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	int V, Mod;
	List<int>[] es;
	int[] par;
	long[] dp0, dp1;
	void Solve()
	{
		var I = G;
		V = I[0];
		Mod = I[1];
		es = new List<int>[V];
		par = new int[V];
		dp0 = new long[V];
		dp1 = new long[V];
		for (var u = 0; u < V; u++) es[u] = new List<int>();
		for (var e = 0; e < V - 1; e++)
		{
			I = G;
			es[I[0] - 1].Add(I[1] - 1);
			es[I[1] - 1].Add(I[0] - 1);
		}
		DFS1(0, -1);
		DFS2(0);
		DFS3(0);
		for (var u = 0; u < V; u++) WriteLine(dp0[u] * (dp1[u] + 1) % Mod);
	}
	void DFS1(int u, int p)
	{
	a0:
		par[u] = p;
		es[u].Remove(p);
		var i = 0;
	a1:
		if (i < es[u].Count)
		{
			DFS1(es[u][i], u);
		a2:
			i++;
			goto a1;
		}
	}
	long DFS2(int u)
	{
	b0:
		dp0[u] = 1L;
		var i = 0;
	b1:
		if (i < es[u].Count)
		{
			DFS2(es[u][i]);
		b2:
			dp0[u] = dp0[u] * (dp0[es[u][i]] + 1) % Mod;
			i++;
			goto b1;
		}
		return dp0[u];
	}
	void DFS3(int u)
	{
	c0:
		{
			var W = es[u].Count;
			var x = new long[W + 1];
			var y = new long[W + 1];
			x[0] = y[W] = 1;
			for (var i = 0; i < W; i++) x[i + 1] = x[i] * (dp0[es[u][i]] + 1) % Mod;
			for (var i = W - 1; i >= 0; i--) y[i] = y[i + 1] * (dp0[es[u][i]] + 1) % Mod;
			for (var i = 0; i < W; i++) dp1[es[u][i]] = (dp1[u] + 1) * x[i] % Mod * y[i + 1] % Mod;
			x = y = null;
		}
		var j = 0;
	c1:
		if (j < es[u].Count)
		{
			DFS3(es[u][j]);
		c2:
			j++;
			goto c1;
		}
	}
}


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

const long long INF = 1LL << 60;

int main() {
  int N; cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; i++) cin >> H[i];

  vector<long long> DP(N, INF);
  DP[0] = 0;
  for (int i = 1; i < N; i++) {
    if (i == 1) DP[i] = DP[0] + abs(H[i] - H[i - 1]);
    DP[i] = min(DP[i - 2] + abs(H[i] - H[i - 2]), DP[i - 1] + abs(H[i] - H[i - 1]));
  }
  cout << DP[N - 1] << endl;
}


Measured memory_bytes: 1408
#include <cstdio>
#include <complex>
#include <iostream>
#include <utility>
#include <vector>
#define EPS (1e-10)
#define X real()
#define Y imag()
using namespace std;
typedef complex<double> P;
typedef pair<P, double> Rope;

double cross(P a, P b){
  return a.X*b.Y - a.Y*b.X;
}

Rope integrate2(Rope x, Rope y){
  P s = x.first, t = y.first;
  double a = x.second, b = y.second, c_square = norm(s-t);
  if(c_square < EPS) return Rope(s,min(a,b));
  double k = (a*a - b*b + c_square)/c_square/2.0;
  P p = (1-k)*s + k*t;
  double h_square = a*a - norm(p-s);
  return Rope(p, sqrt(max(h_square,0.0)));
}

Rope integrate3(Rope x, Rope y, Rope z){
  //??????????????¬????????¨??????
  P s = x.first, t = y.first, u = z.first;
  double a = x.second, b = y.second, c = z.second;
  if(norm(s-t) < EPS) return integrate2(z, Rope(s,min(a,b)));
  if(norm(t-u) < EPS) return integrate2(x, Rope(t,min(b,c)));
  if(norm(u-s) < EPS) return integrate2(y, Rope(u,min(c,a)));
  double px = ((norm(t) - norm(s) + a*a - b*b)*(u.Y-s.Y) - (norm(u) - norm(s) + a*a - c*c)*(t.Y-s.Y)) / 2.0 / cross(t-s,u-s);
  double py = ((norm(t) - norm(s) + a*a - b*b)*(u.X-s.X) - (norm(u) - norm(s) + a*a - c*c)*(t.X-s.X)) / 2.0 / cross(u-s,t-s);
  P p = P(px, py);
  double h_square = a*a - norm(p-s);
  return Rope(p, sqrt(max(h_square, 0.0)));
}

double solve(vector<Rope> r){
  int n = r.size();
  double ret = -1;
  for(int i = 0; i < n; ++i){
    for(int j = i; j < n; ++j){
      for(int k = j; k < n; ++k){
	Rope x = integrate3(r[i], r[j], r[k]);//?????¬????????????????????¨??????
	double h = x.second;
	P p = x.first;
	bool f = true;
	for(int l = 0; l < n; ++l){
	  if(h*h + norm(p-r[l].first) > r[l].second*r[l].second + EPS){
	    f = false;
	    break;
	  }
	}
	if(f) ret = max(ret, h);
      }
    }
  }
  return ret;
}


int main(){
  int n;
  while(cin >> n, n){
    vector<Rope> R(n);
    double x, y, l;
    for(int i = 0; i < n; ++i){
      cin >> x >> y >> l;
      R[i] = Rope(P(x,y),l);
    }
    printf("%.10lf\n", solve(R));
  }
  return 0;
}

Measured memory_bytes: 3236
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
#include <chrono>
#include<unordered_map>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(u) (u).begin(),(u).end()

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef tuple<int, int, int> TIII;
typedef vector<int> VI;

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

void fast_io() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const int MN = 1e9;

int main()
{
    fast_io();

    map<PII, int> M;

    int N;
    scanf("%d", &N);
    REP(i, N)
    {
        double A;
        scanf("%lf", &A);
        LL llA = llround(A * MN);

        // wylicz ile zawieraja 2 i 5
        int x = 0, y = 0;
        while (llA % 2 == 0)
        {
            x++;
            llA /= 2;
        }
        while (llA % 5 == 0)
        {
            y++;
            llA /= 5;
        }

        M[MP(x, y)]++;
    }

    LL res = 0;
    // zobacz ile jest par, ktore maja sume x >= 0 i sume y >= 0
    for (const auto &p : M)
    {
        if (p.first.first >= 9 && p.first.second >= 9)
            res += p.second*(LL)(p.second - 1) / 2;

        auto it = M.find(p.first); it++;
        while (it != M.end())
        {
            if (p.first.first + it->first.first >= 18 && p.first.second + it->first.second >= 18)
                res += p.second*(LL)it->second;

            it++;
        }
    }

    printf("%lld\n", res);

    return 0;
}

// FOR GNU C++ use the following pattern:
// Uncomment the code below and change your main into main2
// It does not build in MS C++
// But it does increase the stack size from 256 MB on CF and uses GNU C++

//#include <Processthreadsapi.h>
//#include <iostream>
//#include <Synchapi.h>
//#include <windows.h>
//#include <process.h>
//
//DWORD WINAPI MyThreadFunction(LPVOID lpParam) {
//    main2(nullptr);
//    return 0;
//}
//int main() {
//    auto h = CreateThread(nullptr, 1024 << 20, MyThreadFunction, nullptr, STACK_SIZE_PARAM_IS_A_RESERVATION, nullptr);
//    WaitForSingleObject(h, INFINITE);
//}

Measured memory_bytes: 3236
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter

from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
#dequeを使うときはpython3を使う、pypyはダメ
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds

#mod = 10**9+7
#w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

N = int(input())
#N, K = map(int, input().split())
#L = [int(input()) for i in range(N)]
A = list(map(int, input().split()))
#S = [list(map(int, input().split())) for i in range(N)]

Am=copy(A)
for i, a in enumerate(A):
    Am[i]=i+1-a
Am.sort()

ans=0
for i, a in enumerate(A):
    x=a+i+1
    count=bisect_right(Am,x)-bisect_left(Am,x)

    ans+=count
print(ans)


Measured memory_bytes: 93004