akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

typedef pair<int, int> P;
int h, w;
vector<string> maze(30);
int ans = 0;

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

void bfs(int sx, int sy) {
  queue<P> que;
  vector<vector<int>> dist(h, vector<int>(w, -1));
  que.push(P(sx, sy));
  dist[sx][sy] = 0;
  while(que.size()) {
    P p = que.front();
    que.pop();
    rep(k, 4) {
      int nx = p.first + dx[k], ny = p.second + dy[k];
      if(0 <= nx && nx < h && 0 <= ny && ny < w
         && maze[nx][ny] != '#' && dist[nx][ny] == -1) {
        que.push(P(nx, ny));
        dist[nx][ny] = dist[p.first][p.second] + 1;
      }
    }
  }
  rep(i, h) rep(j, w) if(dist[i][j] > ans) ans = dist[i][j];
}

int main(void) {
  cin >> h >> w;
  rep(i, h) cin >> maze[i];
  rep(i, h) {
    rep(j, w) {
      if(maze[i][j] == '.')
        bfs(i, j);
    }
  }
  cout << ans << endl;
  return 0;
}

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

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str):
    if S == "AAA" or S == "BBB":
        print(NO)
    else:
        print(YES)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int N;
  cin >> N;
  int A, B;
  cin >> A >> B;
  int cnt=0;
  for(int i=1; i<=N; i++){
    int sum = 0;
    int j = i;
    while(j>0){
      sum += j%10;
      j /= 10;
    }
    if(A<=sum && sum<=B){
      cnt += i;
    }
    
  }
  cout << cnt << endl;  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    int n,d;cin>>n>>d;
    int ans = n/(2*d+1);
    if(n%(2*d+1)!=0)ans++;
    cout << ans << endl;
}



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

int main(void)
{
    while (1)
    {
        int x, y;
        cin >> x >> y;
        if (x == 0 && y == 0)
            break;
        if (x > y)
            swap(x, y);
        cout << x << " " << y << endl;
    }

    return 0;
}

Measured memory_bytes: 2992
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>


#define rep(i,p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;

//131 A
int main(void) {
	string s;
	cin >> s;
	char before = s[0];
	string ans = "Good";
	rep(i, 1, 4) {
		if (s[i] == before) {
			ans = "Bad";
			break;
		}
		before = s[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int a[100005];
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	while (m--) {
		int s, t;
		scanf("%d%d", &s, &t);
		a[s - 1]++, a[t - 1]++;
	}
	for (int i = 0; i < 100005; i++) {
		if (a[i] % 2) {
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	return 0;
}

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

int main() {
    ll N; cin >> N;
    int ans = 1000;
    for (ll i = 1; i*i <= N; i++){
        if(N % i != 0)continue;
        ll big = N / i;
        string s = to_string(big);
        int ss = s.size();
        ans = min(ans, ss);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3736
#include<bits/stdc++.h>
 using namespace std;
#define INF 1000000000
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long LL;
LL K;
LL a[51];
int main(){
    cin>>K;
    REP(i,50){
        a[i]=49;
    }
    REP(i,(K%50)){
        a[i]++;
    }
    REP(i,50){
        if(a[i]!=50){
           a[i]-=(K%50);
        }
    }
    REP(i,50){
        a[i]+=(K/50);
    }
    cout<<50<<endl;
    REP(i,50){
        cout<<a[i];
        if(i!=49){
           cout<<" ";
        }else{
           cout<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
//#define NDEBUG
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <utility>
#include <vector>

namespace n91 {

using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

struct rep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr rep(const usize f, const usize l) noexcept
      : f(std::min(f, l)), l(l) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
struct revrep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr revrep(const usize f, const usize l) noexcept
      : f(l - 1), l(std::min(f, l) - 1) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) noexcept {
  if (a < b) {
    return b - a;
  } else {
    return a - b;
  }
}
template <class T> void chmin(T &a, const T &b) noexcept {
  if (b < a) {
    a = b;
  }
}
template <class T> void chmax(T &a, const T &b) noexcept {
  if (a < b) {
    a = b;
  }
}
template <class F> class fix_point : private F {
public:
  explicit constexpr fix_point(F &&f) : F(std::forward<F>(f)) {}

  template <class... Args>
  constexpr decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, std::forward<Args>(args)...);
  }
};
template <class F> constexpr decltype(auto) make_fix(F &&f) {
  return fix_point<F>(std::forward<F>(f));
}
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}

} // namespace n91

#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>

namespace n91 {

void main_() {
  /*
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  //*/
  const usize h = scan<usize>();
  const usize n = scan<usize>();
  std::vector<u32> dp(h + 1, std::numeric_limits<u32>::max() / 2);
  dp[0] = 0;
  for (const usize l : rep(0, n)) {
    const usize a = scan<usize>();
    const u32 b = scan<u32>();
    for (const usize i : rep(a, h + 1 + a)) {
      chmin(dp[std::min(i, h)], dp[i - a] + b);
    }
  }
  std::cout << dp[h] << std::endl;
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <math.h>
#define ll long long
using namespace std;
#define N 100009



struct Num{
    ll a;
    ll b;
};




int cmp(const void * n1, const void * n2)
{
	if (((Num*)n1)->b > ((Num *)n2)->b)
	{
		return 1;
	}
	else if (((Num*)n1)->b < ((Num*)n2)->b)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}

int main(){
    ll n,s,t;
    cin>>n;
    struct Num num[n];
    for (ll i=0; i<n; i++){
        cin>>s>>t;
        num[i].a=s;
        num[i].b=t;
    }
    
    int p = sizeof num / sizeof( Num );
    //cout<<p;
    qsort(num,p,sizeof(Num),cmp);
    
    ll u=0;
    bool ans=true;
    
    for (ll i=0; i<n; i++){
        u+=num[i].a;
        if (u>num[i].b){
            ans=false;
            break;
        }
    }
    if (ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 6524
#include <iostream>
#include <cstdlib>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <climits>
#include <utility>
using namespace std;
int main()
{
	string x,y;
	cin >> x >> y;
	int l1=x.length(), l2=y.length();
	vector<vector<int>> llcs(l1+1, vector<int> (l2+1));
	for(int i=0;i<=l1;i++)
	{	
		llcs[i][0]=0;
	}
	for(int j=0;j<=l2;j++)
	{
		llcs[0][j]=0;
	}
	for(int i=1;i<=l1;i++)
	{	
		for(int j=1;j<=l2;j++)
		{
			if(x[i-1]==y[j-1])
			{
				llcs[i][j]=llcs[i-1][j-1]+1;
			}
			else
			{
				llcs[i][j]=max(llcs[i-1][j],llcs[i][j-1]);
			}
		}
	}
	int l=llcs[x.length()][y.length()];
	char lcs[l+1];
	lcs[l]='\0';
	int i=l1,j=l2;
	while(i>=1 && j>=1)
	{
		if(x[i-1]==y[j-1])
		{
			lcs[l-1]=x[i-1];
			i--;
			j--;
			l--;
		}
		else
		{
			if(llcs[i][j-1]>llcs[i-1][j])
			{
				j--;
			}
			else
			{
				i--;
			}
		}
	}
	cout << lcs;
}




Measured memory_bytes: 35584
#include<stdio.h>

#define MAX 100000
#define NIL -1
 
struct node{ 
  int p, l, r;
};
struct node T[MAX];

void depth(int);
void print(int);

int n, H, D[MAX];

int main()
{
  int i, j, d, v, c, l, r;
 
  scanf("%d", &n);
 
  for ( i = 0; i < n; i++ ) {
    T[i].p = NIL;
    T[i].l = NIL;
    T[i].r = NIL;
  }
 
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &v, &d);
    for ( j = 0; j < d; j++ ){
      scanf("%d", &c);
      T[c].p = v;
      if(j >= 1)
	T[r].r = c;
      if(j == 0)
	T[v].l = c;
      r = c;
      }
  }
   
 
  for ( i = 0; i < n; i++ ){
    if(T[i].p == NIL) {
      D[i] = 0; 
      depth(i); 
      break;
    }
  }
 
  for ( i = 0; i < n; i++ ) {
    print(i);
  }
  return 0;
}

void depth(int u)
{
  int d = 0;

  if(T[u].r != NIL){   
    D[T[u].r] = D[u];
    depth(T[u].r);
  }
  if(T[u].l != NIL){ 
    D[T[u].l] = D[u]+1;
    depth(T[u].l);
  }
}
 
void print(int u)
{
  int a;

  printf("node %d: parent = %d, depth = %d,", u, T[u].p, D[u]);
  if(T[u].p == NIL)
    printf(" root, ");
  else if(T[u].l == NIL) 
    printf(" leaf, ");
  else 
    printf(" internal node, ");
  printf("[");
  a = u;
  if(T[a].l != NIL) { 
    printf("%d", T[a].l);   
    if(T[T[a].l].r == NIL) 
      printf("]\n");
    else 
      printf(", ");
    a = T[a].l;
    while(T[a].r != NIL){
      printf("%d", T[a].r);
      if(T[T[a].r].r == NIL) 
	printf("]\n");
      else 
	printf(", ");
      a = T[a].r;
    }
  }
  else
    printf("]\n"); 
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef int I;
int main() {
    lli n,m,sum=0,i;
    cin>>n>>m;
   vector<int>a(m);
   if(n>=m)
   cout<<0<<"\n";
   else{
    for(i=0;i<m;i++)
     cin>>a[i];
     sort(a.begin(),a.end());
     vector<int>v(m-1);
     for(i=0;i<m-1;i++)
       v[i]=a[i+1]-a[i];
    sort(v.begin(),v.end());
    for(i=0;i<m-n;i++)
    sum=sum+v[i];
    cout<<sum<<"\n";
   }
}
  

Measured memory_bytes: 3972
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define MOD 1000000007ULL;
#define rep(i,n) for(int i=0;i<n;i++)





int main() {
	ll H,W;
  	cin>>H>>W;
  	string A[H];
  	rep(i,H) cin>>A[i];
  	int count=0;
  	rep(i,H){
     	rep(j,W){
         	if(A[i][j]=='#') count++; 
        }
    }
  
  	if(count==H+W-1) cout<<"Possible"<<endl;
  	else cout<<"Impossible"<<endl;
  
}

Measured memory_bytes: 3612
unittest
{
	assert( [ "9 3", "0001000100" ].solve == "1 3 2 3" );
	assert( [ "5 4", "011110" ].solve == "-1" );
	assert( [ "6 6", "0101010" ].solve == "6" );
}



import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto m = 0L;
	input.front.formattedRead!"%s %s"( n, m );
	input.popFront;
	auto s = input.front.to!( dchar[] );
	
	long[] anss;
	auto i = n;
	LOOP: while( 0 < i )
	{
		foreach_reverse( j; 1L .. m + 1 )
		{
			if( 0 <= i - j && s[ i - j ] == '0' )
			{
				anss ~= j;
				i -= j;
				continue LOOP;
			}
		}
		return "-1";
	}
	return anss.to!( string[] ).retro.join( " " );
}


Measured memory_bytes: 7980
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll m;

    for(ll i=1;i*i<=n;i++){
        m=i;
    }
    for(ll i=m;i>=1;i--){
        if(n%i==0){
            cout << (i-1)+(n/i-1) <<endl;
            return 0;
        }
    }
    return 0;
}


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

int main(){
	
	int a,b; //a:street going north and south, b:street going east and west
	while(std::cin >> a >> b){
		if(a == 0 && b == 0) break;
		
		int n; // number of junction under construction
		std::cin >> n;
		
		std::vector<std::vector<int>> junction(b, std::vector<int>(a,0));

		for(int i=0; i<n; ++i){
			int x,y;  //junction under construction
			std::cin >> x >> y;
			junction[y-1][x-1] = -1;
		}
		
		// count school road
		junction[0][0] = 1;
		for(int i=0; i<b; ++i){
			for(int j=0; j<a; ++j){
				if( junction[i][j] != -1){
					if(i != 0 && junction[i-1][j] != -1){
						junction[i][j] += junction[i-1][j];
					}
					if(j != 0 && junction[i][j-1] != -1){
						junction[i][j] += junction[i][j-1];
					}
				}
			}
		}
		
		/*
		for(auto row_it = junction.begin(); row_it != junction.end(); ++row_it){
			for(auto col_it = row_it->begin(); col_it != row_it->end(); ++col_it){
				std::cout << *col_it << std::endl;
			}
		}
		*/
		
		std::cout << junction[b-1][a-1] << std::endl;
	}
	
	return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < (int)(x); i++)
#define pb push_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<typename T>
void print(T &arr){
    ll sz = sizeof(arr)/sizeof(arr[0]);
    for(int i = 0;i < sz-1;i++){cout << arr[i] << ' ';}
    cout << arr[sz-1] << endl;
}


int main(){
    ll k; cin >> k;
    vvl a(50,vector<ll>(50));
    rep(i,50){
        rep(j,50){
            if(j == 0)a[j][i] = i;
            else{
                a[j][i] = a[j-1][i]-1;
            }
            if(a[j][i] < 0)a[j][i] += 51;
        }
    }
    rep(i,50){
        a[k%50][i] += k/50;
    }
    print(50);
    print(a[k%50]);

}

Measured memory_bytes: 256
use std::collections::HashMap;


const MOD: u64 = 1000000007;

fn main() {
    let n: usize = read();

    println!("{:?}", solve(n));
}


fn solve(n: usize) -> u64 {
    let mut g = G::new(n);
    
    g.dfs(0, "TTT".to_string())
}


#[derive(Debug)]
struct G {
    n: usize,
    memo: Vec<HashMap<String, u64>>,
}

impl G {
    fn new(n: usize) -> Self {
        G {
            n: n,
            memo: vec![HashMap::new(); n + 1],
        }
    }


    fn dfs(&mut self, cur: usize, last3: String) -> u64 {
        if let Some(ret) = self.memo[cur].get(&last3) {
            return *ret
        }

        if cur == self.n {
            return 1
        }

        let mut ret = 0;
        for c in "AGCT".chars() {
            let last4 = {
                let mut tmp = last3.clone();
                tmp.push(c);
                tmp
            };

            if Self::check(&last4) {
                ret = (ret + self.dfs(cur + 1, splt_off(&last4, 1))) % MOD;
            }
        }
        self.memo[cur].insert(last3, ret);
        ret
    }
    
    fn check(last4: &String) -> bool {
        let mut ret = true;
        for i in 0..4 {
            unsafe {
                let mut t = last4.clone();
                let mut t = t.as_mut_vec();

                if i >= 1 {
                    // (t[i - 1], t[i]) = (t[i], t[i - 1]);
                    let tmp = t[i];
                    t[i] = t[i - 1];
                    t[i - 1] = tmp;
                }

                if is_sub_string(&String::from_utf8_unchecked(t.to_vec()), &"AGC".to_string()) {
                    ret = false;
                    break;
                }
            }
        }

        ret
    }
}


fn is_sub_string(s: &String, key: &String) -> bool {
    s.matches(key).collect::<Vec<&str>>().len() >= 1
}

fn splt_off(s: &String, mid: usize) -> String {
    let (_, last) = s.split_at(mid);
    last.to_string()
}


fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;

using ll = long long;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s1, s2;
    cin >> n >> s1 >> s2;
    ll ans;
    bool last;
    int t;
    if(s1[0] == s2[0]){
        ans = 3;
        last = true;
        t = 1;
    }else{
        ans = 6;
        last = false;
        t = 2;
    }
    for(int i = t; i < n; i++){
        if(last){
            if(s1[i] == s2[i]){
                ans *= 2;
                last = true;
            }else{
                ans *= 2;
                i++;
                last = false;
            }
        }else{
            if(s1[i] == s2[i]){
                last = true;
            }else{
                ans *= 3;
                i++;
                last = false;
            }
        }
        ans %= MOD;
    }
    cout << ans << endl;
}

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

int main(){
  bool b[3];
  for(int i=0;i<3;i++)cin >> b[i];
  if(b[2])cout << "Open\n";
  else if(!b[0])cout << "Close\n";
  else if(b[1])cout << "Open\n";
  else cout << "Close\n";
}

Measured memory_bytes: 1124
#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;
#define int long long
#define endl '\n'
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	vector<int> a(n + 1), b(n);
	for(int i = 0 ; i <= n ; i ++)
		cin >> a[i];
	int ans = 0;
	for(int i = 0 ; i < n ; i ++)
		cin >> b[i];
	vector<int> c, d;
	c = a, d = b;
	for(int i = 0 ; i < n ; i ++){
		if(a[i] && b[i]){
			int dec = min(a[i], b[i]);
			a[i] -= dec;
			b[i] -= dec;
			ans += dec;
		}
		if(a[i + 1] && b[i]){
			int dec = min(a[i + 1], b[i]);
			a[i + 1] -= dec;
			b[i] -= dec;
			ans += dec;
		}
	}
	
	cout << ans;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int d,t,s; cin >> d >> t >> s;
  if(d <= s*t){
    cout << "Yes";
  }else{
    cout << "No";
  }
  cout << "\n";
  return 0;
}


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

using namespace std;

using ll = long long;

#define clr(a) (a.clear())
#define sz(x) (int)x.size()
#define mem(a,b) memset(a, b, sizeof(a))
#define Unique(store) store.resize(unique(store.begin(),store.end())-store.begin())
#define pb push_back
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);

#define X first
#define Y second

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

const ll inf = 1;
const ll mod = 1E9;


#define SZ 100010



int main() {
#if defined JESI
//        freopen("1.txt", "r", stdin);
//        freopen("2.txt", "w", stdout);
#endif

    ios::sync_with_stdio(false);

    int n;
    string s;
    cin >> n >> s;

    int first = 0, last = 0, val = 0;

    for (int i = 0; i < n; i++) {
        if (s[i] == '(') val++;
        else {
            if (val) val--;
            else first++;
        }
    }

    last += val;

    while (first) cout << "(", first--;
    cout << s;
    while (last) cout << ")", last--;
    cout << endl;

    return 0;
}






Measured memory_bytes: 256
N = int(input())
S = input()

def z_algorithm_no_overlap(S_):
    N_ = len(S_)
    Z_ = [0] * N_
    L_ = R_ = 0
    for i in range(1, N_):
        if i > R_:
            L_ = R_ = i
            while R_ < N_ and S_[R_-L_] == S_[R_]:
                R_ += 1
            Z_[i] = R_ - L_
            R_ -= 1
        else:
            k = i - L_
            if Z_[k] < R_ - i + 1:
                Z_[i] = Z_[k]
            else:
                L_ = i
                while R_ < N_ and S_[R_-L_] == S_[R_]:
                    R_ += 1
                Z_[i] = R_ - L_
                R_ -= 1
    for i, z in enumerate(Z_):
        if z > i:
            Z_[i] = i
    return Z_
        
print(max(max(z_algorithm_no_overlap(S[i:])) for i in range(N-1)))

Measured memory_bytes: 49372
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	count4 := 0
	count2 := 0
	for i := 0; i < n; i++ {
		a := nextInt()
		if a%4 == 0 {
			count4++
		} else if a%2 == 0 {
			count2++
		}
	}
	if count4*2+count2/2*2 >= n-1 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func next() string {
	scanner.Scan()
	return scanner.Text()
}
func nextInt() int {
	i, err := strconv.Atoi(next())
	if err != nil {
		fmt.Println(err)
	}
	return i
}


Measured memory_bytes: 2176
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        long x = sc.nextLong();
        PriorityQueue<Long> queue = new PriorityQueue<>();
        parent : for (int i = 2; i <= Math.sqrt(x); i++) {
            for (int j = 2; j < Math.sqrt(i); j++) {
                if (i % j == 0) {
                    continue parent;
                }
            }
            if (queue.contains((long)i)) {
                continue;
            }
            if (x % i == 0) { // 最小の因数を求める
                int v = i;
                while (x % v == 0) {
                    x /= v;
                    queue.add((long)v);
                    v *= i;
                }
                while (x % i == 0) {
                    x /= i;
                }
            }
        }
        if (x > 1 && !queue.contains(x)) {
            boolean isOK = true;
            for (int j = 2; j < Math.sqrt(x); j++) {
                if (x % j == 0) {
                    isOK = false;
                    break;
                }
            }
            if (isOK) {
                queue.add(x);
            }
        }

        System.out.println(queue.size());
    }
}

Measured memory_bytes: 37668
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Numerics;

namespace abc166
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            if (File.Exists("input.txt"))
            {
                Console.SetIn(new StreamReader("input.txt"));
            }
			solve_abc166C();
			Console.Out.Flush();

        }
        public static void solve_abc166C()
        {
            int[] nm = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int n = nm[0];
            int m = nm[1];
            int[] h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            Dictionary<int, int> g = new Dictionary<int, int>();
            for (int i = 1; i <= n; i++)
            {
                g.Add(i, 0);
            }
            int cnt = 0;
            while (m-- > 0)
            {
                int[] ab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                if (h[ab[0] - 1] > h[ab[1] - 1])
                {
                    if (g[ab[0]] >= 0)
                    {
                        g[ab[0]]++;
                    }
                    g[ab[1]] = -1;
                }
                else if (h[ab[1] - 1] > h[ab[0] - 1])
                {
                    if (g[ab[1]] >= 0)
                    {
                        g[ab[1]]++;
                    }
                    g[ab[0]] = -1;
                }
                else
                {
                    g[ab[0]] = -1;
                    g[ab[1]] = -1;
                }
            }
            foreach (var item in g)
            {
                if (item.Value >= 0)
                {
                    cnt++;
                }
            }
            Console.WriteLine(cnt);
        }

        public static void solve_abc166B()
        {
            int[] nk = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int n = nk[0];
            int k = nk[1];
            int[] cnt = new int[n];
            while (k-- > 0)
            {
                int d = Convert.ToInt32(Console.ReadLine());
                int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                for (int i = 0; i < d; i++)
                {
                    cnt[a[i] - 1]++; 
                }
            }
            int sum = 0;
            for (int i = 0; i < cnt.Length; i++)
            {
                if (cnt[i] == 0)
                {
                    sum++;
                }
            }
            Console.WriteLine(sum);
        }

        public static void solve_abc166A()
        {
            string s = Console.ReadLine();
            if (s == "ABC")
            {
                Console.WriteLine("ARC");
            }
            else
            {
                Console.WriteLine("ABC");
            }
        }
    }
}


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

#define int long long
#define pb push_back
#define range(v) v.begin(),v.end()
#define mod (int)(1e9 + 7)
#define inf (int)(1e15)
#define N (int)(2e5 + 10)

using namespace std;


auto solve() {
	int a;
	cin >> a;
	return a + a * a + a * a * a;
}

int32_t main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
	int t_c = 1;
//	cin >> t_c;
	while (t_c--) {
		auto ans = solve();
		cout << ans << endl;
	}
}

Measured memory_bytes: 3636
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <complex>
using namespace std;
 
#define FOR(i,a,b) for(LL i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
 
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
 
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 705;



map<pair<string, string>, int> M;

int main()
{
	//freopen("In.txt", "r", stdin);
	int n;
	string s;
	cin >> n >> s;
	
	FOR(msk, 0, 1 << n) {
		string R = "", B = "";
		FOR(i, 0, n) {
			if (msk & (1 << i)) R += s[i];
			else B += s[i];
		}
		M[MP(R, B)]++;
	}
	
	LL ans = 0;
	
	FOR(msk, 0, 1 << n) {
		string R = "", B = "";
		FOR(i, 0, n) {
			if (msk & (1 << i))R += s[n + n - i - 1];
			else B += s[n + n - i - 1];
		}
		ans += M[MP(R, B)];
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 91904
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  string A[n];
  for(int i=0;i<n;i++) cin>>A[i];
  string C[n];
  for(int i=0;i<n;i++) C[i]=A[i];
  int ans=0;
  for(int i=0;i<n;i++){
    for(int j=n-1;j>i;j--){
      if(C[j][1]<C[j-1][1]){
    swap(C[j],C[j-1]);
      }
    }
  }
  string x[10],y[10];
  for(int i=0;i<n;i++){
    x[A[i][1]-'0']+=A[i][0];
    y[C[i][1]-'0']+=C[i][0];
  }
  ans=1;
  for(int i=0;i<10;i++) ans&=x[i]==y[i]; 
  for(int i=0;i<n;i++) cout<<C[i]<<" \n"[i==n-1];
  cout<<(ans?"Stable":"Not stable")<<endl;
   
  for(int i=0;i<n;i++) C[i]=A[i];
  for(int i=0;i<n;i++){
    int minj=i;
    for(int j=i;j<n;j++){
      if(C[j][1]<C[minj][1]){
    minj=j;
      }
    }
    if(i!=minj) swap(C[i],C[minj]);
  }
   
  for(int i=0;i<10;i++) x[i]=y[i]="";
  for(int i=0;i<n;i++){
    x[A[i][1]-'0']+=A[i][0];
    y[C[i][1]-'0']+=C[i][0];
  }
  ans=1;
  for(int i=0;i<10;i++) ans&=x[i]==y[i]; 
  for(int i=0;i<n;i++) cout<<C[i]<<" \n"[i==n-1];
  cout<<(ans?"Stable":"Not stable")<<endl;
   
  return 0;
}


Measured memory_bytes: 3184
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  int n; cin >> n;
  const int MAX = 100005;
  vector<int> cntl(MAX, 0), cntr(MAX, 0);
  rep(i, n) {
    int u; cin >> u;
    if (i % 2 == 0) cntl[u]++;
    else cntr[u]++;
  }

  vector<pair<int,int>> x, y;
  for (int i = 1; i <= MAX; i++) {
    if (cntl[i] > 0) x.push_back(make_pair(-cntl[i], i));
    if (cntr[i] > 0) y.push_back(make_pair(-cntr[i], i));
  }
  sort(x); sort(y);

  if (x[0].second == y[0].second) {
    int x1 = x[0].first;
    int y1 = y[0].first;
    int x2 = x.size() > 1 ? x[1].first : 0;
    int y2 = y.size() > 1 ? y[1].first : 0;
    outl(min(n + x1 + y2, n + x2 + y1));
  } else {
    outl(n + x[0].first + y[0].first);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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

int a,b;
const int h=100,w=100;
char g[h][w];

int main() {
  cin >> a >> b;
  a--; b--;

  REP(i,h) REP(j,w) g[i][j] = i<h/2 ? '#' : '.';

  for (int i=0; i<h; i+=2) {
    if (h/2+(h/2)%2+2 == i) swap(a,b);
    for (int j=0; j<w; j+=2) {
      if (a==0) break;
      g[i][j] = g[i][j] == '.' ? '#' : '.';
      a--;
    }
  }

  cout << h << " " << w << endl;
  REP(i,h) REP(j,w) {
    cout << g[i][j];
    j == w-1 && cout << endl;
  }
}

Measured memory_bytes: 3624
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <numeric>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF (LL)1e15
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*************** using variables ***************/
int n;
vector<LL> t;
/**********************************************/

LL euclidean(LL a, LL b){
    if(a < b) swap(a, b);
    LL r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

LL gcd(LL a, LL b){
    return euclidean(a, b);
}

LL lcm(LL a, LL b){
    LL g = gcd(a, b);
    return a / g * b;
}

int main(){
    cin >> n;
    t.resize(n+5);
    REP(i, n) cin >> t[i];

    LL ans = 1;
    REP(i, n){
        ans = lcm(ans, t[i]);
    }

    cout << ans << endl;
}


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

int main()
{
  int n,m;
  scanf("%d%d",&n,&m);
  if(m==n-1){
    printf("0\n");
    return 0;
  }
  static vector<ll> a(n);
  for(int i=0;i<n;i++){
    scanf("%lld",&(a[i]));
  }
  vector<vector<int> > e(n);
  for(int t=0;t<m;t++){
    int x,y;
    scanf("%d%d",&x,&y);
    e[x].push_back(y);
    e[y].push_back(x);
  }
  vector<int> vis(n,0);
  vector<vector<ll> > A;
  for(int i=0;i<n;i++){
    if(vis[i])continue;
    vis[i]=1;
    vector<ll> c(1,a[i]);
    queue<int> Q;
    Q.push(i);
    while(!Q.empty()){
      int j=Q.front();Q.pop();
      for(int x=0;x<e[j].size();x++){
	int k=e[j][x];
	if(!vis[k]){
	  vis[k]=1;
	  Q.push(k);
	  c.push_back(a[k]);
	}
      }
    }
    sort(c.begin(),c.end());
    A.push_back(c);
  }
  int K=A.size();
  long long ans=0;
  vector<int> b;
  for(int t=0;t<K;t++){
    ans+=A[t][0];
    for(int x=1;x<A[t].size();x++){
      b.push_back(A[t][x]);
    }
  }
  if(b.size()<K-2){
    puts("Impossible");
  }
  else{
    sort(b.begin(),b.end());
    for(int t=0;t<K-2;t++){
      ans+=b[t];
    }
    printf("%lld\n",ans);
  }
  return 0;
}


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

int N;
int x[10], y[10];

double dist(int i, int j) {
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx * dx + dy * dy, 0.5);
}

void solve() {
    cin >> N;
    for(int i = 1; i <= N; i++) cin >> x[i] >> y[i];
    double sum = 0.0;
    vector<int> v(N);
    for(int i = 0; i < N; i++) v[i] = i + 1;
    do {
        for(int i = 0; i < N - 1; i++) sum += dist(v[i], v[i+1]);
    } while(next_permutation(v.begin(), v.end()));
    int Factorial = 1;
    for(int i = 2; i <= N; i++) Factorial *= i;
    cout << fixed << setprecision(10) << sum / Factorial << endl;
    return;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int  long long int
#define fi first
#define se second
#define pb push_back
#define soo(v) sort(v.rbegin(),v.rend())
#define so(v) sort(v.begin(),v.end())
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
//#define endl '\n'
#define dbv(v) cout<<endl;cout<<#v<<"-->> ";for(auto it:v){cout<<it<<" ";}cout<<endl;
#define dbm(m)cout<<endl;cout<<#m<<"-->> ";for(auto it:m){cout<<it.fi<<" "<<it.se.fi<<" "<<it.se.se<<endl;}
#define dbs(s)cout<<endl;cout<<#s<<"-->> ";for(auto it:s){cout<<it<<" ";}cout<<endl;
#define mod 1000000007
#define db1(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl;
#define mx 1e18
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v)  *min_element(v.begin(),v.end())
#define double long double
#define re(s) reverse(s.begin(),s.end())
#define io std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
int powe(int x,int n)
{
  if(n==0)return 1;
  if(n%2==0)
    return powe((x%mod*x%mod)%mod,n/2)%mod;
  return (x%mod*powe((x%mod*x%mod)%mod,(n-1)/2))%mod;
}
int gcd(int A,int B)
{
  if(B==0)return A;
  return gcd(B,A%B);
}

int32_t main()
{
  io
int n;cin>>n;
int p=0;
if(n%10==7)p=1;
n/=10;
if(n%10==7)
  p=1;
n/=10;
if(n%10==7)
p=1;
if(p)cout<<"Yes"<<endl;
else cout<<"No"<<endl;

}

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

using namespace std;

int main() {
  int S;

  cin>>S;

  int SF, SB;

  SF = S/100;
  SB = S - SF*100;

  if((SF>=1 && SF<=12) && (SB>=1 && SB<=12)) {
    cout<<"AMBIGUOUS"<<endl;
  } else if(SB>=1 && SB<=12) {
    cout<<"YYMM"<<endl;
  } else if(SF>=1 && SF<=12) {
    cout<<"MMYY"<<endl;
  } else {
    cout<<"NA"<<endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define LL long long
#define PI 3.14159265359
template<class T> inline void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

int main(void) {
	int A, B, C, D;
	cin >> A >> B >> C >> D;

	chmin(A, B);
	chmin(C, D);
	
	cout << A + C << endl;

	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map{|i| i.to_i}

ans = 0
x = true
while x == true
  ans += 1
  for i in 0..n-1 do
    if a[i] % 2 == 0
      a[i] = a[i] / 2
    else
      ans -= 1
      x = false
      break
    end
  end
end

puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
  int n;
  cin >> n;
  vector<int> h(n), dp(n, INT_MAX);
  rep(i, n) cin >> h[i];
  dp[0] = 0;
  for (int i = 1; i < n; i++) {
    dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
    if (i >= 2) dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
  }
  cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int nPr(int n, int r) {
	r = n - r;
	int sum = 1;
	int i;
	for (i = n; i >= r + 1; i--)sum *= i;
	return sum;
}
//int nCr1(int n, int r)
//int nCr2(int n, int r) 
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}

using namespace std;
#pragma endregion
signed main() {
	int H, W, N;
	cin >> H >> W >> N;
	cout << CEIL(N,max(H,W)) << endl;
}

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

#define iter(i, n) for (int i = 1; i <= n; ++i)
#define forw(i, a, b) for (int i = a; i <= b; ++i)
#define NR 110


int n, m, sx[NR][NR], sy[NR][NR], eX, eY;
char s[NR][NR];
int f[NR][NR][NR][NR];

inline int count_x(int x, int l, int r) { return l > r ? 0 : sx[x][r] - sx[x][l - 1]; }
inline int count_y(int y, int l, int r) { return l > r ? 0 : sy[y][r] - sy[y][l - 1]; }

int main() {
	scanf("%d%d", &n, &m);
	iter(i, n) {
		scanf("%s", s[i] + 1);
		iter(j, m) {
			sx[i][j] = sx[i][j - 1] + (s[i][j] == 'o');
			if (s[i][j] == 'E') eX = i, eY = j;
		}
	}
	iter(i, m) iter(j, n) sy[i][j] = sy[i][j - 1] + (s[j][i] == 'o');
	int ans = 0;
	forw(i, 0, n - eX + 1) {
		forw(j, 0, min(n - i, eX)) {
			forw(k, 0, m - eY + 1) {
				forw(p, 0, min(m - k, eY)) {
					int &w = f[i][j][k][p];
					if (i > 0)
						w = max(w, f[i-1][j][k][p] + ((eX - i) <= j ? count_x(i, max(k + 1, eY - p), min(m - p, eY + k)) : 0));
					if (j > 0)
						w = max(w, f[i][j-1][k][p] + (((n - j + 1) - eX) <= i ? count_x(n - j + 1, max(k + 1, eY - p), min(m - p, eY + k)) : 0));
					if (k > 0)
						w = max(w, f[i][j][k-1][p] + ((eY - k) <= p ? count_y(k, max(eX - j, i + 1), min(n - j, eX + i)) : 0));
					if (p > 0)
						w = max(w, f[i][j][k][p-1] + (((m - p + 1) - eY) <= k ? count_y(m - p + 1, max(eX - j, i + 1), min(n - j, eX + i)) : 0));
					ans = max(ans, w);
					//printf("f[%d][%d][%d][%d]=%d\n", i,j,k,p,f[i][j][k][p]);
				}
			}
		}
	}

	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 236160
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <utility>
#include <iomanip>
#include <queue>

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

using namespace std;


int main(){
    
    int X;
    cin>>X;
    if(X>=30){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

}


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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int cnt = 0;
  vector<int> a(n);
  if(s.at(0) == 'I'){
      a.at(0) = 1;
    }
    else {
      a.at(0) = -1;
    }
  for(int i=1;i<n;i++){
    if(s.at(i) == 'I'){
      a.at(i) = a.at(i-1) +1;
    }
    else {
      a.at(i) = a.at(i-1) -1;
    }
  }
  sort(a.begin(),a.end());
  if(cnt >= a.at(n-1)){
    a.at(n-1) = 0;
  }
  cout << a.at(n-1) << endl;
  
  return 0;
}
      


Measured memory_bytes: 256
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;

    vector<pair<int, int>> a;
    if (s.front() == '0') {
        a.push_back({1, 0});
    }
    for (int i = 0; i < n - 1; i++) {
        int cnt = 1;
        while (s[i] == s[i + 1]) {
            cnt++;
            i++;
        }
        a.push_back({s[i] - '0', cnt});
    }
    if (n == 1 || s[n - 1] != s[n - 2]) {
        a.push_back({s.back() - '0', 1});
    }
    if (s.back() == '0') {
        a.push_back({1, 0});
    }

    int ro = a.size();
    int w = 2 * k + 1, ans = 0;
    for (int i = 0; i < ro; i += 2) {
        int tem = 0, cro = min(i + w, ro);

        for (int j = i; j < cro; j++) {
            tem += a[j].second;
        }

        ans = max(ans, tem);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1528
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		while(true){
			String tmp = br.readLine();
			
			if(tmp == null){
				break;
			}
			
			int left = Integer.parseInt(tmp);
			
			int[] weigh = {1,2,4,8,16,32,64,128,256,512};
			
			Stack<Integer> stack = new Stack<Integer>();
			int i = weigh.length - 1;
			while (left > 0){
				if(left >= weigh[i]){
					stack.push(weigh[i]);
					left -= weigh[i];
				}
				
				i--;
			}
			
			int num = stack.size();
			for(int j = 0; j < num; j++){
				if(j == 0){
					System.out.print(stack.pop());
				}
				else {
					System.out.print(" "+stack.pop());
				}
			}
			System.out.println();
		}
	}

}

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

int N;
vector<pair<int, int>> edges[100000];
int ans[100000];

void dfs(int i, int par){
    for(auto& p : edges[i]) if(p.first != par){
        ans[p.first] = (ans[i] + p.second) % 2;
        dfs(p.first, i);
    }
}

int main(){
    cin >> N;
    for(int i=0; i<N-1; i++){
        int a, b, c;
        cin >> a >> b >> c;
        edges[a-1].push_back({b-1, c%2});
        edges[b-1].push_back({a-1, c%2});
    }

    dfs(0, -1);
    for(int i=0; i<N; i++) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 8320
from itertools import groupby as gb
l=[(a,len(list(b))) for a,b in gb(list(input()))]
ans=0
now=0
if l[0][0]=="T":
    ans+=l[0][1]
    now+=1
pres=0
for (k,x),(k1,y) in zip(l[now::2],l[now+1::2]):
    #print(ans,pres)
    if x+pres>=y:pres=(x+pres-y)
    else:
        ans+=y-x-pres
        pres=0
print(ans+pres+(0 if l[-1][0]=="T" else l[-1][1]))

Measured memory_bytes: 11808