akhauriyash/Code-Regression huggingface dataset:
class UnionFind():
    def __init__(self, n):
        self.parents = [-1] * n

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

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

        if x == y:
            return

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

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

n, m = map(int, input().split())
uf = UnionFind(n)

for i in range(m):
    a, b = map(int, input().split())
    uf.union(a-1,b-1)

cnt = 0
for item in uf.parents:
    if item < 0:
        cnt += 1

print(cnt-1)

Measured memory_bytes: 74900
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace atcoder_sharp
{
    class ProgramC
    {
        const int MaxN = 100000;

        static void Main(string[] args)
        {
            int[][] v = new int[3][];
            BigInteger[][] s = new BigInteger[3][];

            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < 3; i++)
            {
                v[i] = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                s[i] = new BigInteger[n];

                Array.Sort(v[i]);

                if (i == 0)
                {
                    for (int j = 0; j < n; j++)
                    {
                        s[i][j] = j + 1;
                    }
                }
                else
                {
                    for (int j = 0, k = -1; j < n; j++)
                    {
                        while (k + 1 < n && v[i - 1][k + 1] < v[i][j])
                        {
                            k++;
                        }

                        s[i][j] = 0;
                        if (j > 0)
                        {
                            s[i][j] += s[i][j - 1];
                        }
                        if (k >= 0)
                        {
                            s[i][j] += s[i - 1][k];
                        }
                    }
                }
            }

            Console.WriteLine(s[2][n - 1]);
        }
    }
}


Measured memory_bytes: 46472
#include<bits/stdc++.h>
using namespace std;
//define
typedef pair<int,int>pi;
#define elif else if
#define int long long
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define Rep(x,y) for(int k=x;k<y;k++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define vint vector<int>
#define vvint vector<vector<int>>
#define vtr vector<string>
#define vvtr vector<vector<string>>
#define vhar vector<char>
#define vvhar vector<vector<char>>
#define mod 100000007
#define elif else if
#define str string

signed main(){
  int N,M,O,P=0,c=0,c2=0,crash=0,nowtab=1;
  double D,D2;
  char C;
  str S,T,U;
  cin>>N;
  vint mochi(N);
  rep(0,N)cin>>mochi[i];
  sort(all(mochi));
  rep(0,N-1){
    if(mochi[i]!=mochi[i+1]){
      c++;
    }
  }
  cout<<c+1<<endl;
}


Measured memory_bytes: 256
n = int(input())
weights = list(map(int, input().split()))

min_diff = 100000
for i in range(1, n):
    s1 = sum(weights[:i])
    s2 = sum(weights[i:])
    diff = abs(s1 - s2)
    if(min_diff > diff):
        min_diff = diff

print(min_diff)


Measured memory_bytes: 2940
import math
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
inputs = [A, B, C, D, E]
howManyTimes = []
for num in inputs:
    howManyTimes.append(math.ceil(N / num))
bottleneck = howManyTimes.index(max(howManyTimes))

print(4 + howManyTimes[bottleneck])


Measured memory_bytes: 3060
using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());

            for (var i = 0; i <= N / 4; i++)
            {
                var M = N - 4 * i;

                for (var j = 0; j <= M / 7; j++)
                {
                    var total = 4 * i + 7 * j;
                    if (total == N)
                    {
                        Console.WriteLine("Yes");
                        return;
                    }
                }
            }

            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 13140
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#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++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  ll n ,m ; cin >>n>>m;
  if(2*n>m){
    cout<<m/2<<endl;
    return 0;
  }
  ll l=m/4-n/2;
  ll a=max({min(n+l,(m-2*l)/2),min(n+l+1,(m-2*l-2)/2),min(n+l-1,(m-2*l+2)/2)});
  cout <<min(n+l,(m-2*l)/2)<<endl;
}

Measured memory_bytes: 256
// while (clock()<=69*CLOCKS_PER_SEC)
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(),x.end()
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define erase_duplicates(x) sort(all(x)); (x).resize(distance((x).begin(), unique(all(x))));


using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<
T,
null_type,
less<T>,
rb_tree_tag,
tree_order_statistics_node_update>;

//X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego)
//X.order_of_key(k); - zwraca liczbę elementów ostro mniejszych niż k

typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<LL> VLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long double LD;
typedef pair<LD,LD> PLD;
typedef vector<LD> VLD;
typedef vector<PLD> VPLD;

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(...)
#define cerr if(0)cout
#endif

const int maxn = (1e6)+7;
const int maxk = 20;
const int inf = (1e9)+7;
const LL LLinf = ((LL)1e18)+7LL;
const LD eps = 1e-9;
const LL mod = 1e9+7;

// ***************************** CODE ***************************** //

int dlu(int a, int b)
{
  // dbg(a, b);
  if(a <= b) return b - a + 1;
  return 0;
}

int main()
{
	_upgrade
  int n;
  cin>>n;
  VPII wek, wek2;
  for(int i = 1;i <= n;i++)
  {
    int l, p;
    cin>>l>>p;
    wek.pb({l, p});
  }
  sort(all(wek), [](PII a, PII b)
  {
    if(a.fi != b.fi)
      return a.fi > b.fi;
    return a.se < b.se;
  });
  wek2 = wek;
  int prawo = inf;
  VPII cur;
  int res = 0;
  for(auto s : wek)
  {
    if(s.se < prawo)
      cur.pb(s);
    prawo = min(prawo, s.se);
  }
  for(int i = 1;i < SZ(wek);i++)
  {
    wek[i].fi = max(wek[i].fi, wek[i - 1].fi);
    wek[i].se = min(wek[i].se, wek[i - 1].se);
  }
  int curp = 0;
  int curk = inf;
  for(int i = SZ(wek2) - 1;i >= 0;i--)
  {
    res = max(res, dlu(max(curp, i > 0 ? wek[i - 1].fi : 0), min(curk, i > 0 ? wek[i - 1].se : inf)) + wek2[i].se - wek2[i].fi + 1);
    curp = max(curp, wek2[i].fi);
    curk = min(curk, wek2[i].se);
  }
  sort(all(cur));
  for(int i = 0;i + 1 < SZ(cur);i++)
  {
    res = max(res, dlu(cur.back().fi, cur[i + 1].se) + dlu(cur[i].fi , cur[0].se));
  }
  cout<<res;
	return 0;
}


Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>
#include <limits>
using namespace std;

int main(){
    string s;
    cin >> s;
    string ans;
    for(size_t i = 0; i < s.size(); i++)
    {
        if(s[i] == 'B'){
            if(i == 0) continue;
            else if(ans == "") continue;
            else ans.erase(ans.end()-1);
        }
        else{
            ans += s[i];
        }
    }
    
    
    cout << ans << endl;
    return 0;
}

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

int main()
{
    // 入力を受け取る
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    // 計算する
    int ans = (H - h) * (W - w);
    // 答えを出力する
    cout << ans << endl;
}

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


int main(void){
	int n;
	char *s;
	char tmp;
	int count=0;

	scanf("%d",&n);
	s = (char*)malloc(n*sizeof(char));
	scanf("%s",s);

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

		tmp = s[i];
	}

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


Measured memory_bytes: 2120
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << "\n"
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef complex<double> Point;
typedef Point Vector;
typedef pair<Point, Point> Segment;
constexpr double EPS = (1e-9L);
double dot(const Point& p1, const Point& p2) { return (conj(p1) * p2).real(); }
double cross(const Point& p1, const Point& p2) { return (conj(p1) * p2).imag(); }
constexpr bool eq(double a) { return abs(a) < EPS; }
Point project(Segment s, Point p) {
	Vector base = s.fi - s.se;
	double r = dot(p - s.fi, base) / norm(base);
	return s.fi + base * r;
}
Point reflect(Segment s, Point p) {
	return p + (project(s, p) - p) * 2.0;
}
int main() {
	cout << setprecision(10) << fixed;
	double x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
	Segment s(Point(x1, y1), Point(x2, y2));
	int q; cin >> q;
	Point p1;
	double xp, yp;
	rep(i, 0, q) {
		cin >> xp >> yp;
		p1 = reflect(s, Point(xp, yp));
		cout << p1.real() << " " << p1.imag() << "\n";
	}
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  string S;
  for(int i = 0;i < N;i++){
    cin >> S;
    if(S == "Y"){
      cout << "Four" << endl;
      break;
    }
    if(i == N-1){
      if(S != "Y"){
        cout << "Three" << endl;
      }
    }
    else{
      continue;
    }

  }
  
  
}

Measured memory_bytes: 256
n, k, q = map(int, input().split())
a_s = [int(input()) for _ in range(q)]

pts = [k for _ in range(n)]
pts = [p - len(a_s) for p in pts]

for a in a_s:
	pts[a - 1] = pts[a - 1] + 1

for p in pts:
	if p > 0:
		print('Yes')
	else:
		print('No')


Measured memory_bytes: 11820
from collections import defaultdict, deque, Counter
def inpl(): return list(map(int, input().split()))

R, G, B, N = inpl()
ans = 0
for r in range(N//R + 1):
    for g in range(N//G + 1):
        tmp = N - R*r - G*g
        if tmp < 0:
            break
        if (tmp%B == 0):
            ans += 1
print(ans)

Measured memory_bytes: 40688
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll p, ll n, ll m) {
	if (n == 0) return 1;
	else if (n == 1) return p % m;
	else if (n % 2 == 1) return p * pow_mod(p, n - 1, m) % m;
	else {
		ll tmp = pow_mod(p, n / 2, m);
		return (tmp * tmp) % m;
	}
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

ll com_mod(ll n, ll k, ll m) {
	if (k == 0) return 1;
	else {
		ll x = 1;
		ll y = 1;
		for (ll i = 0; i < k; i++) {
			x = (x * (n - i)) % m;
			y = (y * (i + 1)) % m;
		}
		ll res = (x * pow_mod(y, m - 2, m)) % m;
		return res;
	}
}

int main() {
	int a, b; cin >> a >> b;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return 0;
}

Measured memory_bytes: 3520
from collections import deque


def solve(h, w, s_list):

    g = dict()
    for i in range(h):
        for j in range(w):
            if s_list[i][j] == ".":
                g[i * 100 + j] = dict()

    for i in range(h):
        for j in range(w - 1):
            if s_list[i][j] == "." and s_list[i][j + 1] == ".":
                g[i * 100 + j][i * 100 + j + 1] = 1
                g[i * 100 + j + 1][i * 100 + j] = 1

    for i in range(h - 1):
        for j in range(w):
            if s_list[i][j] == "." and s_list[i + 1][j] == ".":
                g[i * 100 + j][i * 100 + j + 100] = 1
                g[i * 100 + j + 100][i * 100 + j] = 1

    d_max = 0
    for x in g.keys():
        d_dict = {v: 10000 for v in g.keys()}
        queue = deque([x])
        d_dict[x] = 0
        while len(queue) > 0:
            p = queue.popleft()
            for q in g[p].keys():
                if d_dict[q] > d_dict[p] + 1:
                    d_dict[q] = d_dict[p] + 1
                    queue.append(q)
        d_max = max(d_max, max(d_dict.values()))

    return d_max


def main():
    h, w = map(int, input().split())
    s_list = []
    for _ in range(h):
        s = input()
        s_list.append(s)
    res = solve(h, w, s_list)
    print(res)


def test():
    assert solve(3, 3, ["...", "...", "..."]) == 4
    assert solve(3, 5, ["...#.", ".#.#.", ".#..."]) == 10


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 3564
#include <iostream>
#include <cstdio>
#include <cstring>
#define NDEBUG
#include <cassert>
#include <cctype>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?c=getchar():0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
const int O=1000000007;
int gcd(int a,int b){
	return b?gcd(b,a%b):a;
}
inline int fpow(int x,int n){
	int a=1;
	for(;n;n>>=1,x=(lint)x*x%O){
		if(n&1){
			a=(lint)a*x%O;
		}
	}
	return a;
}
inline int inv(int x){
	return fpow(x,O-2);
}
const int N=210;
int c[N][N];
int k,f[N],g[N],pw[N],ans=1;
namespace G{
	const int N=55,E=110*2;
	int to[E],bro[E],head[N],e=0;
	int dfn[N],tim=0;
	int esize[E],estat[E];
	int estk[N],ss=0;
	inline void init(){
		memset(head,-1,sizeof(head));
		memset(dfn,0,sizeof(dfn));
		memset(estat,0,sizeof(estat));
	}
	inline void ae(int u,int v){
		to[e]=v,bro[e]=head[u],esize[e]=1,head[u]=e++;
	}
	inline void add(int u,int v){
		ae(u,v),ae(v,u);
	}
	void dfs(int x,int fa){
		dfn[x]=++tim;
		for(int i=head[x],v;~i;i=bro[i]){
			if((v=to[i])!=fa){
				if(dfn[v]==0){
					estk[ss++]=i;
					ans=(lint)ans*k%O;
					dfs(v,x);
					if(estk[ss-1]==i){
						ss--;
					}
				}else if(dfn[v]<dfn[x]){
					int last=i,e,stat=1;
					do{
						e=estk[--ss];
						if(estat[e]){
							stat=2;
							ans=(lint)ans*inv((estat[e]==1?f:g)[esize[e]])%O;
						}else{
							ans=(lint)ans*inv(k)%O;
						}
						esize[e]+=esize[last],last=e;
					}while(dfn[v]<dfn[to[e^1]]);
					estat[e]=stat;
					estk[ss++]=e;
					ans=(lint)ans*(stat==1?f:g)[esize[e]]%O;
				}
			}
		}
	}
}
inline void gmath(int n,int k){
	pw[0]=1;
	for(int i=1;i<=n;i++){
		pw[i]=(lint)pw[i-1]*k%O;
	}
	for(int i=1;i<=n;i++){
		lint tmp=0;
		for(int j=0;j<i;j++){
			tmp+=pw[gcd(i,j)];
		}
		f[i]=tmp%O*inv(i)%O;
	}
	memset(c,0,sizeof(c));
	for(int i=0,ti=n+k;i<=ti;i++){
		c[i][0]=1;
		for(int j=1;j<=i;j++){
			c[i][j]=(c[i-1][j-1]+c[i-1][j])%O;
		}
	}
	for(int i=1;i<=n;i++){
		g[i]=c[i+k-1][k-1];
	}
}
int main(){
	int n=ni,m=ni;
	G::init();
	gmath(m,k=ni);
	for(int i=1;i<=m;G::add(ni,ni),i++);
	for(int i=1;i<=n;i++){
		if(G::dfn[i]==0){
			G::dfs(i,0);
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
int main(void){
	char b;
	scanf("%c",&b);
	switch(b){
		case 'A' : puts("T"); break;
		case 'T' : puts("A"); break;
		case 'G' : puts("C"); break;
		case 'C' : puts("G"); break;
	}
	return 0;
}

Measured memory_bytes: 128
# ABC176 D Wizard 
# 地図系。ワープ有　01BFS??

from collections import deque
H,W = map(int,input().split())
sx,sy = map(int,input().split())
gx,gy = map(int,input().split())
sx,sy,gx,gy = sx-1,sy-1,gx-1,gy-1

C=[list(input()) for i in range(H)]
inf = float("inf")

for i in range(H):
    for j in range(W):
        if C[i][j] == ".":
            C[i][j] =0
        else:
            C[i][j]=1

d0=[[1,0],[0,1],[-1,0],[0,-1]]
d1=[[-2,-2],[-2,-1],[-2,0],[-2,1],[-2,2],[-1,-2],[-1,-1],[-1,1],[-1,2],\
   [0,-2],[0,2],[1,-2],[1,-1],[1,1],[1,2],[2,-2],[2,-1],[2,0],[2,1],[2,2]]

dist = [[inf]*W for i in range(H)]
dist[sx][sy]=0
que=deque([[0,sx,sy]])

while que:
    L,x,y = que.popleft()
    for dx,dy in d0:
        nx,ny=x+dx,y+dy
        if 0<=nx<H and 0<=ny<W and L < dist[nx][ny] and C[nx][ny]==0:
            dist[nx][ny] = L
            que.appendleft([L,nx,ny])
            
    for dx,dy in d1:
        nx,ny=x+dx,y+dy
        if 0<=nx<H and 0<=ny<W and L+1 < dist[nx][ny] and C[nx][ny]==0:
            dist[nx][ny] = L+1
            que.append([L+1,nx,ny])
ans=dist[gx][gy]
if ans==inf:print(-1)
else: print(ans)

Measured memory_bytes: 178636
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {

    input!(
       n: usize,
       h: [i64;n]
    );

     let mut costs = vec![-1;n];
    let mut index = 0;
    
    loop {
       
        let current_h = h[index];
        let current_cost = if costs[index] == -1 {0} else {costs[index]};

        let one_hop = h[index + 1];
        let one_hop_cost = (current_h - one_hop).abs() + current_cost;
        if costs[index + 1] == -1 || costs[index + 1] > one_hop_cost {
             costs[index + 1] = one_hop_cost;
        }

        if index + 2 == n {
            println!("{:?}",costs[index + 1]);
            return
        }

        let two_hop = h[index + 2];
        let two_hop_cost = (current_h - two_hop).abs() + current_cost;
        
        if costs[index + 2] == -1 || costs[index + 2] > two_hop_cost {
             costs[index + 2] = two_hop_cost;
        }

        index = index + 1;
    };

}



Measured memory_bytes: 6396
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String str;
		char ch;
		int num;
		int answer = 1;

		num = scan.nextInt();
		str = scan.next();
		ch = str.charAt(0);

		for(int i = 1; i < num; i++) {
			if(str.charAt(i) != ch) {
				answer++;
				ch = str.charAt(i);
			}
		}

		System.out.println(answer);

	}
}


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

int main() {
    int n; cin >> n; int m = n;
    int d = 0;
    if (n == 3) {
        cout << "Yes" << endl;
        cout << "1 2\n2 3\n3 4\n4 5\n5 6\n";
        return 0;
    }
    for (int i = 0; i < 20; i++) {
        if ((1 << i) == n) {
            cout << "No" << endl;
            return 0;
        }
        if ((1 << i) > n) {
            d = (1 << i) / 2;
            break;
        }
    }
    cout << "Yes" << endl;
    if (n % 2 == 0) {
        int u = m ^ (d+1);
        vector<int> c; c = {u};
        for (int i = d+1; i >= 2; i--) {
            if (i == u) continue;
            c.emplace_back(i);
        }
        int p = c.size();
        for (int i = 0; i < p; i++) {
            c.emplace_back(c[i]+n);
        }
        for (int i = 0; i < c.size()-1; i++) {
            cout << c[i] << " " << c[i+1] << endl;
        }
        cout << m << " " << c[0] << endl;
        cout << m+n << " " << c[1] << endl;
        m--;
        cout << 1 << " " << c[1] << endl;
        cout << 1+n << " " << c[2] << endl;
        for (int i = d+3; i <= m; i+=2) {
            cout << i-1 << " " << i << endl;
            cout << i << " " << c[1] << endl;
            cout << c[2] << " " << i-1+n << endl;
            cout << i-1+n << " " << i+n << endl;
        }
    } else {
        vector<int> c;
        for (int i = d+1; i >= 2; i--) {
            c.emplace_back(i);
        }
        int p = c.size();
        for (int i = 0; i < p; i++) {
            c.emplace_back(c[i]+n);
        }
        for (int i = 0; i < c.size()-1; i++) {
            cout << c[i] << " " << c[i+1] << endl;
        }
        cout << 1 << " " << c[0] << endl;
        cout << 1 + n << " " << c[1] << endl;
        for (int i = d+3; i <= m; i+=2) {
            cout << i-1 << " " << i << endl;
            cout << i << " " << c[0] << endl;
            cout << c[1] << " " << i-1+n << endl;
            cout << i-1+n << " " << i+n << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3448
#include<bits/stdc++.h>
using namespace std;
#define TRACE
#define M 1000000007
#define oo 1000000000000000007
#define F first
#define S second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
#define pb push_back
#define M6 5000009
#define M5 500009
#define pi 3.14159265
#define epsilon 1e-6

ll n,m,A[M5],vis[201];
vector<ll> g[201];

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

    ll tc=1,t=0,i,j,k,a,b,c;
    //cin>>tc;
    while(t++<tc){
        string s;
        cin>>n;
        for(i=1;i<=n;i++) {
            cin>>s;
            for(j=1;j<=n;j++) {
                if(s[j-1]=='1') g[i].pb(j);
            }
        }
        ll nn=-1;
        for(i=1;i<=n;i++) {
            queue<pll> qu;
            qu.push({i,1});
            vis[i]=1; 
            ll cnt=0,ans=0,flag=0;

            while(!qu.empty()) {
                pll cur=qu.front();
                qu.pop();
                cnt++,ans=max(ans,cur.S);
                for(auto u:g[cur.F]) {
                    
                    if(vis[u]==0){
                        qu.push({u,cur.S+1});
                        vis[u]=cur.S+1;
                    }
                    else if(vis[u]!=cur.S+1 && vis[u]!=cur.S-1) {
                        //cout<<cur.F<<" "<<u<<" "<<vis[u]<<"\n";
                        flag=1;
                    }
                }
            }
            memset(vis,0,sizeof(vis));
            if(cnt==n&&flag==0) nn=max(nn,ans);
        }
        cout<<nn;
    }
    return 0;
}

Measured memory_bytes: 640
t = input()
s = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
for i in range(26):
  if s[i] == t:
    if i==25:
      print(s[0])
    else:
      print(s[i+1])

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

int main() {
    int n;
    cin >> n;
    int a[101010], r[101010], l[101010];
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
        l[i] = __gcd(a[i], l[i-1]);
    }
    for(int i = n; i >= 1; --i){
        r[i] = __gcd(r[i+1], a[i]);
    }
    int ans = 0;
    for(int i = 1; i <= n; ++i){
        ans = max(ans, __gcd(l[i-1], r[i+1]));
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 4768
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <list>
#include <bitset>

using namespace std;

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;
typedef pair<int,ii> iii;

int sum(int x)
{
	int res = 0;
	while(x)
	{
		res += x%10;
		x /= 10;
	}
	return res;
}

int main()
{
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// freopen("input.in", "r", stdin);
	int n; scanf("%d", &n);
	int res = 1e9;
	for(int i = 1; i < n; i++)
	{
		res = min(sum(i)+sum(n-i),res);
	}
	printf("%d\n", res);
	return 0;
}	















Measured memory_bytes: 256
while 1:
  n = int(input())
  if n == 0:
    break
  x = [0 for i in range(10)] 
  for i in range(n):
    c = int(input())
    x[c] += 1

  for i in range(10):
    count = '*' * x[i] 
    if len(count) == 0:
      print("-")
    else:
      print(count)


Measured memory_bytes: 5628
using System;

public class my
{
	public static void Main()
	{
		long n = my.GetLong();
		
		long[] R = new long[n];
		
		R[0] = my.GetLong();
		long minv = R[0];	//R[j]???????°????
		long maxv = long.MinValue;	// ??????????????§???
		
		for(int j = 1; j < n; j++ ) {
			R[j] = my.GetLong();
			maxv = Math.Max(maxv, R[j] - minv);
			minv = Math.Min(minv, R[j]);
		}

		Console.WriteLine(maxv);
	}
	
	private static long GetLong()
	{
		return long.Parse(Console.ReadLine());
	}
}

Measured memory_bytes: 12288
from math import ceil
def isok(x):
    res=0
    for i in range(N):
        H=h[i]-B*x
        if H<=0:
            continue
        res+=ceil(H/(A-B))
    return True if res<=x else False

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

ng,ok=-1,10**10
while(ok-ng>1):
    mid=(ok+ng)//2
    if isok(mid):
        ok=mid
    else:
        ng=mid
print(ok)

Measured memory_bytes: 80836
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp18 {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());

            int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            int[] ans = Enumerable.Repeat(0, N).ToArray();

            for (int i = N - 1; i >= 0; i--) {
                int S = 0;
                for (int j = 1; (j * i + (j - 1)) < N; j++) {
                    S += ans[j * i + (j - 1)];
                }
                if (S % 2 != a[i]) {
                    ans[i] = 1;
                }
            }

            //Console.WriteLine(string.Join(" ", a));

            var last = new List<int>();
            int cnt = 0;

            for (int i = 0; i < N; i++) {
                if (ans[i] != 0) {
                    last.Add(i + 1);
                    cnt++;
                }
            }

            //Console.WriteLine(string.Join(" ", ans));

            Console.WriteLine(cnt);

            if (last.Count() != 0) {
                Console.WriteLine(string.Join(" ", last));
            }
        }
    }
}


Measured memory_bytes: 30556
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    // AtCoder
    // template
    ll n;
    cin >> n;
    map<string, ll> mp;
    rep(i, n) {
        string s;
        cin >> s;
        sort(all(s));
        mp[s]++;
    }
    ll ans = 0;
    for(auto &p : mp) {
        ll cnt = p.second;
        ans += cnt * (cnt - 1) / 2;
    }
    cout << ans;
}

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

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

    int N;
    cin >> N;
    vector<int> blocks(0);
    for(int i = 0; i < N; i++){
        int a = 0;
        cin >> a;
        blocks.push_back(a);
    }
    int answer = 0;
    int current = 1;
    for(int i = 0; i < N; i++){
        if(blocks.at(i) == current){
            current++;
        }else{
            answer++;
        }
    }
    if(current == 1){
        cout << -1 << endl;
    }else{
        cout << answer << endl;
    }
    return 0;
}

Measured memory_bytes: 1400
import java.util.*;
public class Main {
        static Scanner sc = new Scanner(System.in);
        static void myout(Object t){System.out.println(t);}//standard output
        static void myerr(Object t){System.err.println(t);}//standard error
        static String getStr(){return sc.next();}
        static int getInt(){return Integer.parseInt(getStr());}
        static long getLong(){return Long.parseLong(getStr());}
        static boolean isNext(){return sc.hasNext();}
        static String[] mySplit(String str){return str.split("");}
        public static void main(String[] args){
          long N = getLong();
          long output = (long)( Math.ceil((double)N / 11) )*2;
          long amari = N % 11;
          if(amari != 0 && amari <= 6){
            output--;
          }
          myout(output);
        }
        //便利メソッド追加枠ここから

        //便利メソッド追加枠ここまで
}


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

int main()
{
  int n;
  while (cin >> n, n){
    pair<pair<int, int>, pair<int, char> > ppiic[11];
    for (int i = 0; i < n; i++){
      char c;
      ppiic[i].first = make_pair(0, 0);
      cin >> c;
      ppiic[i].second = make_pair(i, c);
      for (int j = 0; j < n - 1; j++){
        int num;
        cin >> num;
        if (num == 0) ppiic[i].first.first--;
        else if (num == 1) ppiic[i].first.second++;
      }
    }
    sort(ppiic, ppiic + n);

    for (int i  = 0; i < n; i++){
      cout << ppiic[i].second.second << '\n';
    }
  }
}

Measured memory_bytes: 2932
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

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

    ll jud = 0;

    rep(i,n-1){
        jud = max(jud,a[i+1] -a[i]);
    }

    jud = max(jud,a[0] + k - a[n-1]);

    cout << k - jud << endl;
}

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

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ms(v, x) memset((v), (x), sizeof(v))
#define all(v) (v).begin(), (v).end()
#define ff first
#define ss second
#define iopt ios::sync_with_stdio(false); cin.tie(0)

int gcd(int a, int b) { return b == 0 ? a : gcd(b, a%b); }
int power(int x, int p, int MOD) {
    if(p == 0) return 1%MOD;
    if(p == 1) return x%MOD;
    int res = power(x, p/2, MOD);
    res = (long long)res*res%MOD;
    if(p&1) res = (long long)res*x%MOD;
    return res;
}

typedef pair<int, int> ii;
typedef long double LD;
typedef vector<int> vi;

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

  vector<int> a(n);
  vector<int> x(n);
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }

  int ans = 0;
  int ptr = n-1;
  for(int i = n-1; i >= 0; i--) {
    int cur = max(i-ptr, 0LL);
    if(a[i] == cur) continue;
    else if(a[i] < cur) {
      cout << -1 << endl;
      return 0;
    } else {
      ptr = i - a[i];
      ans += a[i];
      if(ptr < 0) {
        cout << -1 << endl;
        return 0;
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <cstdio>

#define fol(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
    vector<int>Num(100001,0);
    int n,a;
    cin >>n;
    fol(i,n){
        cin >> a;
        Num[a]++;
        if (a!=0)Num[a-1]++;
        Num[a+1]++;
    }
    sort(Num.rbegin(),Num.rend());
    cout << Num[0] <<endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=1e5+5;

int n, k;
int a[N], cache[N];

int dp(int cur)
{
	int &ans=cache[cur];
	if(ans!=-1)
		return ans;
	ans=0;
	for(int i=1;i<=n;i++)
	{
		if(cur-a[i]<0)
			break;
		ans|=(dp(cur-a[i])==0);
	}
	return ans;
}

int32_t main()
{
	IOS;
	memset(cache, -1, sizeof(cache));
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	if(dp(k))
		cout<<"First";
	else
		cout<<"Second";
	return 0;
}


Measured memory_bytes: 4224
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
char in[210000];
int main(){
	scanf("%s",in);
	int n=strlen(in);
	long long ret=0;
	int A=0;
	for(int i=0;i<n;i++){
		if(in[i]=='A'){
			A++;
		}else if(in[i]=='B'&&in[i+1]=='C'){
			ret+=A;
			i++;
		}else{
			A=0;
		}
	}printf("%lld\n",ret);
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{
  static long t[];
  static long l[];
  static long h[];

  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);

    String s;
    String sl[];

    int d[] = new int[10];
    int c[] = {999999, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    for(int i = 0; i <= 9; i++)
    {
      d[i] = 999999;
    }

    s = r.readLine();
    sl = s.split(" ");
    int n = Integer.parseInt(sl[0]);
    int m = Integer.parseInt(sl[1]);

    s = r.readLine();
    sl = s.split(" ");
    for(int i = 0; i < m; i++)
    {
      int v = Integer.parseInt(sl[i]);
      d[v] = c[v];
    }

    int dp[] = new int[n + 1];
    for(int i = 1; i <= n; i++)
    {
      dp[i] = -999999;
      for(int j = 1; j <= 9; j++)
      {
        if(i - d[j] >= 0 && dp[i - d[j]] >= 0)
        {
          dp[i] = Math.max(dp[i], dp[i - d[j]] + 1);
        }
      }
    }

    int z = dp[n];
    int q = n;
    while(q > 0)
    {
      for(int i = 9; 1 <= i; i--)
      {
        if(q - d[i] >= 0 && dp[q - d[i]] == dp[q] - 1)
        {
          System.out.print(i);
          q -= d[i];
          break;
        }
      }
    }

  }

}

Measured memory_bytes: 22484
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a[210000];
int k,n;
int main()
{
	scanf("%d%d",&n,&k);
	ll ans=1ll<<62;int pos;
	for(int i=1;i<=n;i++)
	{
		ll x;
		scanf("%lld",&x);
		if(x==0){k--;a[i]=x,pos=i;continue;}
		a[i]=x;
		if(a[i-1]<0&&x>0)
		{
			a[i]=0;n++;
			a[++i]=x;pos=i-1;
		}
	}
	if(k==0){printf("0\n");return 0;}
	if(a[1]>0){printf("%lld\n",a[k]);return 0;}
	if(a[n]<0){printf("%lld\n",abs(a[n-k+1]));return 0;}
	for(int i=0;i<=k;i++)
	{
		if(pos-k+i<1)continue;
		if(pos+i>n)break;
		int l=pos-k+i,r=pos+i;
		ans=min(ans,min(abs(a[l]),abs(a[r]))*2+max(abs(a[l]),abs(a[r])));
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 896
from bisect import bisect

n = int(input())
s = input()
location = [[] for _ in range(10)]
for i, c in enumerate(map(int, s)):
    location[c].append(i)
location = [loc for loc in location if loc]
last_indices = [loc[-1] for loc in location]

ans = 0
for loc_x in location:
    i = loc_x[0]
    for loc_y in location:
        ji = bisect(loc_y, i)
        if ji >= len(loc_y):
            continue
        j = loc_y[ji]
        ans += sum(j < li for li in last_indices)
print(ans)


Measured memory_bytes: 4456
import math
import itertools

n = int(input())
li = []
for i in range(n):
    x, y = map(int, input().split())
    li.append([x, y])

z = []
cnt = 0
for v in itertools.permutations(li):
    cnt += 1
    for i in range(n-1):
        z.append(math.sqrt((v[i][0] - v[i+1][0])**2 + (v[i][1] - v[i+1][1])**2))
print(sum(z)/cnt)

Measured memory_bytes: 12084
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<utility>

using namespace std;

int main(){
    int n, ans = 0;
    cin >> n;
    string str, t;
    vector<pair<string, string>> s;
    for(int i = 0; i < n; i++){
        cin >> str;
        s.push_back({str, str});
    }
    cin >> t;
    for(int i = 0; i < n; i++){
        int iq = 0;
        while((iq = s[i].first.find("?", iq)) != string::npos){
            s[i].first.replace(iq, 1, "a");
            s[i].second.replace(iq, 1, "z");
        }
    }
    int l = n + 1, r = 1;
    for(int i = 0; i < n; i++){
        if(s[i].first <= t) r++;
        if(s[i].second >= t) l--;
    }
    for(int i = l; i <= r; i++){
        cout << i;
        if(i != r) cout << " ";
    }
    cout << endl;
    return 0;
}

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


def solve(S: str):
    s = S

    g_str = s[1::2]
    k_str = s[0::2]

    if "R" in g_str:
        print("No")
    elif "L" in k_str:
        print("No")
    else:
        print("Yes")

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
n = int(input())
aaa = list(map(int, input().split()))
q = int(input())
mmm = list(map(int, input().split()))
suma = sum(aaa)
def solve(i,m):
  global n,aaa,suma
  if m<0 or m>suma:
    return False
  if m==0:
    return True
  if i >= n:
    return False
  return solve(i+1,m) or solve(i+1,m-aaa[i])
mina = min(aaa)
for m in mmm:
  if m < mina or m>suma:
    print("no")
  else:
    if solve(0,m):
      print("yes")
    else:
      print("no")
  


Measured memory_bytes: 5628
# sys.stdin.readline
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())
        B = list(map(int, input().split()))

        A = []
        for i in range(N):
            if i == 0:
                A.append(B[i])
            elif i == N - 1:
                A.append(B[i - 1])
            else:
                A.append(min(B[i - 1], B[i]))
        print(sum(A))


# Run main
if __name__ == '__main__':
    AtCoder().main()


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

#define UNDEF -1

struct node{
	int parent = 0;
	int left = 0;
	int right = 0;
	int depth = 0;
};

int height(vector<node> tree, const int id){
	if (tree[id].left == UNDEF && tree[id].right == UNDEF) return 0;
	if (tree[id].left == UNDEF) return height(tree, tree[id].right) + 1;
	if (tree[id].right == UNDEF) return height(tree, tree[id].left) + 1;
	int r = height(tree, tree[id].right);
	int l = height(tree, tree[id].left);
	return r > l ? r + 1 : l + 1;
}

int main(){

	int n;
	cin >> n;
	int id, left, right, prec;
	node nullnode;
	nullnode.parent = UNDEF;
	nullnode.left = UNDEF;
	nullnode.right = UNDEF;
	nullnode.depth = 0;
	vector<node> tree(n, nullnode);
	for (int i = 0; i < n; i++){
		cin >> id >> left >> right;
		tree[id].left = left;
		tree[id].right = right;
		if (left != UNDEF) tree[left].parent = id;
		if (right != UNDEF) tree[right].parent = id;
	}

	for (int i = 0; i < n; i++){
		int cur = i;
		while (tree[cur].parent != UNDEF){
			cur = tree[cur].parent;
			tree[i].depth++;
		}
	}

	//node 0: parent = -1, sibling = -1, degree = 2, depth = 0, height = 3, root

	for (int i = 0; i < n; i++){
		cout << "node " << i;
		cout << ": parent = " << (tree[i].depth == 0 ? -1 : tree[i].parent);
		cout << ", sibling = " << (tree[i].depth == 0 ? -1 : (tree[tree[i].parent].left == i ? tree[tree[i].parent].right : tree[tree[i].parent].left));
		cout << ", degree = " << ((int)(tree[i].right != UNDEF) + (int)(tree[i].left != UNDEF));
		cout << ", depth = " << tree[i].depth;
		cout << ", height = " << height(tree, i) << ", ";
		if (tree[i].depth == 0){
			cout << "root";
		}
		else if (tree[i].left == UNDEF && tree[i].right == UNDEF){
			cout << "leaf";
		}
		else{
			cout << "internal node";
		}
		cout << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3148
#include <stdio.h>
int main(void){
 int N,i,j=0,k=0,A[N];
 scanf("%d",&N);
 for(i=0;i<N;i++){
  scanf("%d",&A[i]);
 }
 while(1){
 for(i=0;i<N;i++){
  if(A[i]%2==1) j++;
 }
 if(j>0) break;
 for(i=0;i<N;i++){
 A[i]=A[i]/2;
 }
 k++;
 }
 printf("%d",k);
 return 0;
}

Measured memory_bytes: 128
#include<iostream>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define MAX_V 500000
using namespace std;
struct node{
  int id,key;
  node *parent,*left,*right;
  node():key(0),parent(NULL),left(NULL),right(NULL){}
};
node nodes[MAX_V]{};
int id=0;
node* make_binary_tuple(int key){
  nodes[id].key=key;
  return &nodes[id++];
}
node* find_node(node* root, int key){
  if(root==NULL) return NULL;
  if(key>root->key) return find_node(root->right,key);
  if(key<root->key) return find_node(root->left,key);
  return root;
}
bool contain(node* root, int key){
  return find_node(root,key)!=NULL;
}

void printPreorder(node* n){
  cout<<" "<<n->key;
  if(n->left!=NULL) printPreorder(n->left);
  if(n->right!=NULL) printPreorder(n->right);
}
void printInorder(node* n){
  if(n->left!=NULL) printInorder(n->left);
  cout<<" "<<n->key;
  if(n->right!=NULL) printInorder(n->right);
}

node* tree_insert(node* root, int key){
  node* z=make_binary_tuple(key);
  node* y=NULL;
  node* x=root;
  while(x!=NULL){
    y=x;
    if(z->key<x->key)
      x=x->left;
    else
      x=x->right;
  }
  z->parent=y;
  if(y==NULL)
    root=z;
  else if(z->key<y->key)
    y->left=z;
  else
    y->right=z;
  return root;
}
node* tree_minimum(node* x){
  while(x->left!=NULL)
    x=x->left;
  return x;
}
node* tree_successor(node* x){
  if(x->right!=NULL)
    return tree_minimum(x->right);
  node *y=x->parent;
  while(y!=NULL&&x==y->right){
    x=y;
    y=y->parent;
  }
  return x;
}
node* tree_delete(node* root, int key){
  node* z = find_node(root, key);
  if(z==NULL) return root;
  node *x=NULL,*y=NULL;
  if(z->left==NULL||z->right==NULL)
    y=z;
  else
    y=tree_successor(z);
  if(y->left!=NULL)
    x=y->left;
  else
    x=y->right;
  if(x!=NULL)
    x->parent=y->parent;
  if(y->parent==NULL)
    root=x;
  else if(y==y->parent->left)
    y->parent->left=x;
  else
    y->parent->right=x;
  if(y!=z)
    z->key=y->key;
  return root;
}
int main(){
  node* root=NULL;
  int n; cin>>n;
  REP(i,n){
    string s; cin>>s;
    if(s=="insert"){
      int key; cin>>key;
      root = tree_insert(root,key);
    } else if(s=="print"){
      printInorder(root); cout<<"\n";
      printPreorder(root); cout<<"\n";
    } else if(s=="find"){
      int key; cin>>key;
      if(contain(root,key)) cout<<"yes\n";
      else cout<<"no\n";
    } else if(s=="delete"){
      int key; cin>>key;
      root=tree_delete(root,key);
    }
  }
}

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

struct RollingHash2D{
  typedef unsigned long long ull;
  
  struct RollingHash{
    typedef unsigned long long ull;
    string S;
    ull B;
    int len;
    vector<ull> hash,p;
    RollingHash(){}
    RollingHash(string S_,ull B_=1000000007LL):
      S(S_),B(B_),len(S.length()),hash(len+1),p(len+1){
      hash[0]=0;p[0]=1;
      for(int i=0;i<len;i++){
	hash[i+1]=hash[i]*B+S[i];
	p[i+1]=p[i]*B;
      }
    }
    //S[l,r)
    ull find(int l,int r){
      return hash[r]-hash[l]*p[r-l];
    }
  };
  
  vector<string> S;
  int h,w,r,c;
  ull B;
  vector<ull> p;
  vector<vector<ull> > hash;
  vector<RollingHash> rh;
  RollingHash2D(){}
  RollingHash2D(vector<string> S_,int r_,int c_,ull B_=1000000009LL):
    S(S_),h(S_.size()),w(S_[0].size()),r(r_),c(c_),B(B_),
    p(h+1),hash(h+1,vector<ull>(w-c+1,0)),rh(h){
    for(int i=0;i<h;i++) rh[i]=RollingHash(S[i]);
    p[0]=1;
    for(int i=0;i<h;i++) p[i+1]=p[i]*B;
    for(int j=0;j<w-c+1;j++){
      hash[0][j]=0;		    
      for(int i=0;i<h;i++)
	hash[i+1][j]=hash[i][j]*B+rh[i].find(j,j+c);
    }
  }
  //[i,i+r) * [j,j+c)
  ull find(int i,int j){
    return hash[i+r][j]-hash[i][j]*p[r];
  }
};

int main() {
  int H, W;
  cin >> H >> W;
  
  vector<string> T(H);
  for ( int i = 0; i < H; i++ ) cin >> T[i];

  int R, C;
  cin >> R >> C;
  
  vector<string> P(R);
  for ( int i = 0; i < R; i++ ) cin >> P[i];

  RollingHash2D rht(T, R, C), rhp(P, R, C);
  for ( int i = 0; i <= H-R; i++ ) {
    for ( int j = 0; j <= W-C; j++ ) {
      if ( rht.find(i, j) == rhp.find(0, 0) )
	cout << i << " " << j << endl;      
    }
  }
  
  return 0;
}



Measured memory_bytes: 38416
#include<bits/stdc++.h>
#define N 100000
using namespace std;
vector<int>adj[N];
void dfs(int i,int &mx,int cur){
	mx=max(mx,cur);
	if(adj[i].size()==0){return;}
	for(int j=0;j<adj[i].size();j++){
		dfs(adj[i][j],mx,cur+1);
	}	
}void topo(vector<bool>&vis,stack<int>&s,int i){
	vis[i]=true;
	for(int j=0;j<adj[i].size();j++){
		if(!vis[adj[i][j]]){topo(vis,s,adj[i][j]);}
	}s.push(i);
}
int main(){
int n,m;cin>>n>>m;
vector<bool>ori;
for(int i=0;i<n;i++){ori.push_back(true);}
for(int i=0;i<m;i++){int a,b;cin>>a>>b;a--;b--;adj[a].push_back(b);ori[b]=false;}
int mx=0;vector<bool>vis;stack<int>s;
for(int i=0;i<n;i++){vis.push_back(false);}
for(int i=0;i<n;i++){
if(ori[i]){
	topo(vis,s,i);
}
}
vector<int>toposort;
for(int i=0;i<n;i++){
	toposort.push_back(s.top());s.pop();
}vector<int>dist(n);
for(int i=0;i<n;i++){
if(ori[i]){
	dist[i]=0;
}else{
	dist[i]=INT_MIN;
}
}
for(int i=0;i<n;i++){
	for(int j=0;j<adj[toposort[i]].size();j++){
		dist[adj[toposort[i]][j]]=max(dist[adj[toposort[i]][j]],dist[toposort[i]]+1);
	}
}
for(int i=0;i<n;i++){if(mx<dist[i]){mx=dist[i];}}
cout<<mx;
}


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

signed main(){
	int A, B;
	scanf("%d%d", &A, &B);
	if(A == B){
		printf("Draw\n");
	}
	else if(A == 1){
		printf("Alice\n");
	}
	else if(B == 1){
		printf("Bob\n");
	}
	else if(A > B){
		printf("Alice\n");
	}
	else{
		printf("Bob\n");
	}
	return 0;
}

Measured memory_bytes: 3744