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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


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

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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

const int N = 12;
int n, m, x, c[N], a[N][N], u[N];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> x;
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  int sol = (int) 1e9;
  for (int mask = 0; mask < (1 << n); mask++) {
    int now = 0;
    for (int i = 0; i < n; i++) {
      if (mask & (1 << i)) {
        now += c[i];
        for (int j = 0; j < m; j++) {
          u[j] += a[i][j];
        }
      }
    }
    bool ok = 1;
    for (int j = 0; j < m; j++) {
      if (u[j] < x) {
        ok = 0;
      }
      u[j] = 0;
    }
    if (ok) {
      sol = min(sol, now);
    }
  }
  if (sol == (int) 1e9) {
    sol = -1;
  }
  cout << sol << "\n";
  return 0;
}


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

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,x;
    cin>>n>>x;
    ll a[n];
    int num=0;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=1;i<n;i++){
        if(a[i]+a[i-1]>=x)num=i;
    }
    if(!num){
        cout << "Impossible"<<endl;
        return 0;
    }
    cout<<"Possible"<<endl;
    for(int i=1;i<num;i++){
        cout << i<<endl;
    }
    for(int i=n-1;i>num;i--){
        cout << i<<endl;
    }

    cout << num<<endl;
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int n,p[20],s[1<<20],s1[1<<10];

int main(){
	while(cin>>n){
		if(!n)return 0;
		int n2=n/2;
		fill(s1,s1+(1<<n2),0);
		int sum=0,dif=1e+9;
		for(int i=0;i<n;i++){cin>>p[i];sum+=p[i];}
		if(n<11){
			fill(s,s+(1<<n),0);
			for(int i=0;i<1<<n;i++){
				int sss=0;
				for(int j=0;j<n;j++)if((i/(1<<j))%2)sss+=p[j];
				dif=min(dif,abs(sss*2-sum));
			}
			cout<<dif<<endl;
		}
		else{
		for(int i=0;i<1<<n2;i++){
			for(int j=0;j<n2;j++)if(i>>j&1)s1[i]+=p[j];
		}
		sort(s1,s1+(1<<n2));
		int ans=1e+9;
		for(int i=0;i<1<<(n-n2);i++){
			int ss=0;
			
			for(int j=0;j<n-n2;j++)if(i>>j&1)ss+=p[j+n2];
			ans=min(ans,min(abs((*lower_bound(s1,s1+(1<<n2),(sum)/2-ss)+ss)*2-sum),abs((*(lower_bound(s1,s1+(1<<n2),(sum)/2-ss)-1)+ss)*2-sum)));
			ans=min(ans,abs((*(lower_bound(s1,s1+(1<<n2),(sum)/2-ss)+1)+ss)*2-sum));
		}
		cout<<ans<<endl;
		}
	}
}

Measured memory_bytes: 0
/**
 *      purpose : AGC 11 A
 *      author  : kyomukyomupurin
 *      created : 2018-11-21 03:37:03
**/

#include <iostream>
#include <algorithm>
using namespace std;
typedef int64_t int64;
#define print(x) cout << (x) << '\n'

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n, c, k; scanf("%d %d %d", &n, &c, &k);
    int t[n];
    for (int i = 0; i < n; ++i) scanf("%d", &t[i]);

    sort(t, t + n);

    int ans = 0;
    int beg = 0;
    while (beg < n){
        int end = beg;
        while (end - beg + 1 < c && t[end + 1] - t[beg] <= k){
            ++end;
            if (end == n - 1) break;
        }
        ++ans; beg = end + 1;
        if (beg == n - 1){
            ++ans; break;
        }
    }
    print(ans);
    
    return 0;
}

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

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

  copy(vc.begin(), vc.end(), vc2.begin());
  sort(vc2.begin(), vc2.end(), greater<int>());
  for (auto i : vc) {
    if (i == vc2[0]) cout << vc2[1] << "\n";
    else cout << vc2[0] << "\n";
  }

  return 0;
}


Measured memory_bytes: 3200
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(true){
			String a = sc.next();
			if(a.equals("0"))break;
			int b,sum=0;
			for(int i=0;i<a.length();i++){
				b = a.charAt(i) - '0';
				sum += b;
			}
			System.out.println(sum);
		}
	}
}



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

int main()
{
    int n; cin >> n;
    int count = 0;
    int num = 0;
    for (int i = 1; i <= n; i+=2)
    {
        count = 0;
        for (int j = 1; j <= i; j += 2)
        {
            if(i%j == 0)count ++;
        }
        if(count == 8)num++;
        
    }
    cout << num << endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
//cout << fixed << setprecision(8) << a << endl;
#define Fast_Input ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define pb push_back
#define mem(a, b)     memset(a, b, sizeof(a))
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef long long ll;
typedef tree<int,null_type,greater<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
/*sort(v.begin(), v.end(),
     [](const pair<int, int>& x, const pair<int, int>& y)
{
    if (x.first != y.first)
        return x.first < y.first;
    return x.second < y.second;
});
*/
int const fx[]= {+1,+0,-1,+1};
int const fy[]= {-1,+1,+0,+0};
const int inf = numeric_limits<int>::max();
const int mx=2e5;
const ll mod=1e9+7;
int par[mx+5];
int fin(int r)
{
    if(par[r]==r)return r;
    par[r]=fin(par[r]);
    return par[r];
}
int main()
{
    int n,m,x,y,u,v,i;
    cin >> n >> m;
    for(i=1;i<=n;i++)par[i]=i;
    while(m--)
    {
        cin >> x >> y;
        u=fin(x);
        v=fin(y);
        if(u!=v)par[u]=v;
    }
    map<int,int>mp;
    int maxi=-1;
    for(i=1;i<=n;i++)
    {
        mp[fin(i)]++;
        if(mp[fin(i)]>maxi)
            maxi=mp[fin(i)];
    }
    cout << maxi << endl;
    return 0;
}




Measured memory_bytes: 13788
#include <iostream> 
#include <queue>
#include <cstring>
char board[1005][1005];
#define pii pair<int, int>
using namespace std;

int ShortestPath[1005][1005];
int R, C;
int dx[]={-1, 0, 1, 0};
int dy[]={0, -1, 0, 1};

bool inside(int r, int c){
    return 0<=r && r<R && 0<=c &&c<C;
}

int bfs(){
    queue<pii> a;
    memset(ShortestPath, -1, sizeof(ShortestPath));
    
    for(int i=0; i<R; i++){
        for(int j=0; j<C; j++){
            if(board[i][j]=='#'){
                ShortestPath[i][j]=0;
                a.push(make_pair(i, j));
            }
        }
    }
    int ans = 0;
    while(!a.empty()){
        pii now = a.front(); a.pop();
        int row = now.first;
        int col = now.second;
        
        ans = max(ans, ShortestPath[row][col]);

        for(int x=0; x<4; x++){
            int vr = row+dx[x];
            int vc = col+dy[x];
            if(!inside(vr, vc))continue;
            if(ShortestPath[vr][vc]!=-1)continue;
            ShortestPath[vr][vc] = ShortestPath[row][col] + 1;
            a.push(make_pair(vr, vc));
        }
    }
    return ans;
}

int main(){
    cin >> R >> C;
    for(int i=0; i<R; i++){
        for(int j=0; j<C; j++){
            cin >> board[i][j];
        }
    }
    cout << bfs() << endl;
}

Measured memory_bytes: 16168
s = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
k = list(map(int, s.split(",")))
print(k[int(input())-1])

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define MOD 998244353

const int MAX = 200010;
vector<long long> fac(MAX,1),finv(MAX,1),inv(MAX,1);
void init() {
  for(int i = 2;i < MAX;i++) {
    fac.at(i) = fac.at(i-1) * i % MOD;
    inv.at(i) = MOD - inv.at(MOD%i) * (MOD/i) % MOD;
    finv.at(i) = finv.at(i-1) * inv.at(i) % MOD;
  }
}

long long comb(int n,int k) {
  if(n < k || n < 0 || k < 0) return 0;
  return fac.at(n)*(finv.at(k)*finv.at(n-k)%MOD)%MOD;
}

long long Pow(long long a,long long n) {
  long long p = 1;
  while(n > 0) {
    if(n&1) p = p*a%MOD;
    a = a*a%MOD;
    n >>= 1;
  }
  return p;
}

int main() {
  
  long long N,M,K;
  cin >> N >> M >> K;

  init();
  long long ans = 0;
  for(int i = 0;i <= K;i++) {
    ans += (comb(N-1,i)*M%MOD)*Pow(M-1,N-i-1)%MOD;
    ans %= MOD;
  }

  cout << ans << endl;

}


Measured memory_bytes: 7868
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define pb push_back
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ll long long
using namespace std;
int main(){
  string s;
  cin >> s;
  int n = s.size();
  int cnt01 = 0;
  REP(i,n){
    if (i % 2 == 0) {
      cnt01 += s[i] == '0' ? 1 : 0;
    } else {
      cnt01 += s[i] != '0' ? 1 : 0;
    }
  }
  cout << min(cnt01, n - cnt01) << endl;
  return 0;
}


Measured memory_bytes: 512
count = 0
flag = 0
leng = int(input())
list = []
for i in range(1, leng + 1):
  a,b=input().split()
  list.append((int(a), int(b)))
for j in range(0, leng):
  if(list[j][0] == list[j][1]):
    count = count + 1
  else:
    count = 0
  if(count == 3):
    flag = 1
    
if(flag == 1):
  print("Yes")
else:
  print("No")

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

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

  vector<ll> A(N);
  rep(i,N) {
    cin >> A[i];
    A[i] -= i + 1;
  }
  sort(A.begin(), A.end());

  vector<ll> S(N+1, 0);
  rep(i,N) S[i+1] = S[i] + A[i];

  ll ans = -1;
  for(int i = 0; i < N; i++) {
    ll T = S[N] - 2*S[i] + (2*i - N)*A[i];
    if(ans == -1) ans = T;
    ans = min(ans, T);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
int main(){
  int n;
  while(cin>>n,n){
    int p[44],t[44];
    p[0]=t[0]=0;
    for(int i=1;i<=n;i++)cin>>p[i]>>t[i];
    int dp[44][4];
    for(int i=0;i<44;i++)
      for(int j=0;j<4;j++)
	dp[i][j]=INF;
    dp[0][0]=0;
    int ff=0;
    for(int i=1;i<=n;i++){
      int f=0;
      for(int j=0;j<4;j++){
	if(t[i-1]+p[i-1]*(j+1)+p[i]<=t[i]&&dp[i-1][j]!=INF){
	  dp[i][1]=min(dp[i][1],dp[i-1][j]+p[i-1]+p[i]);
	  f=1;
	}
	if(j==0)continue;
	if(t[i-1]+abs(p[i]-p[i-1])*(j)<=t[i]&&dp[i-1][j-1]!=INF){
	  dp[i][j]=min(dp[i][j],dp[i-1][j-1]+abs(p[i]-p[i-1]));
	  f=1;
	}
      }
      
      if(!f){
	cout<<"NG "<<i<<endl;
	ff++;
	break;
      }
    }
    if(ff)continue;
    int ans=INF;
    for(int i=0;i<4;i++)ans=min(ans,dp[n][i]);
    cout<<"OK "<<ans+p[n]<<endl;
  }
  return 0;
}




Measured memory_bytes: 3092
#include <algorithm>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod 1000000007
#define int long long
#define double long double
#define INF INT_MAX
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, m, s[2010], t[2010];
int dp[2010][2010];
signed main() {
	cin >> n >> m;
	REP(i, n)cin >> s[i];
	REP(i, m)cin >> t[i];
	dp[0][0] = 1;
	REP(i, n)dp[i][0] = 1;
	REP(i, m)dp[0][i] = 1;
	if (s[1] == t[1])dp[1][1] = 2;
	else dp[1][1] = 1;
	REP(i, n) {
		REP(j, m) {
			if (i == 1 && j == 1)continue;
			if (s[i] == t[j]) {
				dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
			}
			else dp[i][j] = dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
			dp[i][j] += mod;
			dp[i][j] %= mod;
		}
	}
	cout << dp[n][m] << endl;
}

Measured memory_bytes: 31744
#include <bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define cont continue
#define rep(i, n) for(int i = 0 ; i < (n) ; i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF = 987654321;

int T;
map<ll, ll> m;
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);


  for(int i = 0 ; i < 5 ; i++) {
    ll x;
    cin >> x;
    m.insert(mp(x, 1));
  }

  for(int i = 0 ; i < 100 ; i++) {
    if(m.find(i) == m.end()) {
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3652
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n, q, cnt = 0, isExist;
		int[] S = new int[100000], T = new int[50000];
		
		n = sc.nextInt();
		for(int i = 0; i < n; i++){
			S[i] = sc.nextInt();
		}
		
		q = sc.nextInt();
		for(int i = 0; i < q; i++){
			T[i] = sc.nextInt();
		}
		
		for(int i = 0; i < q; i++){
			isExist = binarySearch(T[i], S, n);
			if(isExist == 1){
				cnt ++;
			}
		}
		
		System.out.println(cnt);
	}
	
	public static int binarySearch(int t, int[] S, int len){
		int first = 0, last = len - 1, middle;
		int isExist = 0;
		
		while(isExist == 0 && first <= last){
			middle = (first + last) / 2;
			if(S[middle] == t){
				isExist = 1;
			}
			else if(t < S[middle]){
				last = middle - 1;
			}
			else if(S[middle] < t){
				first = middle + 1;
			}
		}
		
		return isExist;
	}
}

Measured memory_bytes: 69648
N = int(input())
A = [int(input()) for _ in range(N)]
A = sorted(A)
B = list(reversed(A))
ans = -1
#print(A)
#print(B)
if(N % 2 == 0):
    k = N//2
    typeN = -(2*sum(A[:k])+A[k]) + (2*sum(B[:k])+B[k])
    ans = typeN
else:
    k = N//2
    typeW = (2*sum(B[:k-1])+B[k-1]+B[k]) - (2*sum(A[:k]))
    typeM = (2*sum(B[:k])) - (2*sum(A[:k-1])+A[k-1]+A[k])
    ans = max(typeW,typeM)
print(ans)

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

#define fst first
#define snd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
}

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;
const ll _INF = 1e18+7;
const int mxn = 2007;

ll fact[mxn];

ll fpow(ll x, ll y){
	ll res = 1;
	while (y){
		if (y&1) res = (res*x)%INF;
		x = (x*x)%INF;
		y >>= 1;
	}
	return res;
}

ll c(ll x, ll y){
	return fact[x]*(fpow(fact[x-y], INF-2)*fpow(fact[y], INF-2)%INF)%INF;
}

int main(){
	setIO();
	fact[0] = 1;
	for (int i = 1; i < mxn; i++)
		fact[i] = (fact[i-1]*i)%INF;
	ll n, ans = 0; cin >> n;
	for (int i = 1; i <= n/3; i++){
		ans = (ans+c(n-2*i-1, i-1))%INF;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#include <map>
#include <cmath>
#define MOD_P 1000000007
#define ll long long
using namespace std;



int main()
{
	int n;
	double sum = 0;
	cin >> n;
	priority_queue<int> que;
	bool flag = true;

	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		que.push(-tmp);
	}

	while (!que.empty()) {
		//printf("(%f+%d)/2\n", sum, -que.top());
		sum -=  (double)que.top();
		if (flag) {
			flag = false;
		} else {
			sum /= 2.0;
		}
		//printf("%f\n", sum);
		que.pop();
	}

	printf("%f", sum);

	return 0;
}

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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin>>n;
vector<vector<int>>a(2,vector<int>(n,0));
rep(i,2){
    rep(j,n)cin>>a[i][j];
}
vector<vector<ll>>s(2,vector<ll>(n,0));
s[0][0]=a[0][0];
s[1][n-1]=a[1][n-1];
reps(i,n,1){
    s[0][i]=s[0][i-1]+a[0][i];
    s[1][n-1-i]=s[1][n-1-i+1]+a[1][n-1-i];
}
ll max_val=-1;
rep(i,n){
    max_val=max(max_val,s[0][i]+s[1][i]);
}
cout<<max_val<<endl;
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int pass(int t)
{
    int c = 0;
    while(1)
    {
        t /= 2;
        c++;
        if(t%2!=0)
        {
            return c;
            break;
        }

    }
}
int main()
{
    long int n,a[2000],t,max,c=0,g=0;
    cin>>n;
    for(int i = 0; i < n; i++)
    {
        cin>>a[i];
        if(a[i]%2!=0)
        {
            g = 1;
        }
    }

    max = 1000000000;

    if(g==1)
    {
        cout<<"0\n";
    }
    else
    {
        for(int i = 0; i < n; i++)
        {
            t = a[i];
           g =  pass(t);

            if(g < max)
            {
                max = g;
            }
        }

        cout<<max<<endl;
    }




}


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

using namespace std;
vector<int> v[100001];

int dfs(int p){
  vector<int> vv;
  for(int i=0;i<(int)v[p].size();i++){
    int res=dfs(v[p][i]);
    vv.push_back(res);
  }
  sort(vv.begin(),vv.end());
  for(int i=1;i<vv.size();i++)
    if(vv[i-1]>=vv[i])vv[i]=vv[i-1]+1;
  if(vv.size()==0)return 0;
  return vv[vv.size()-1]+1;
}

int main(){
  int n;
  cin>>n;
  for(int i=1,a;i<n;i++)cin>>a,v[a-1].push_back(i);
  cout<<dfs(0)<<endl;   
  return 0;
}


Measured memory_bytes: 15104
n,m,x = gets.strip.split.map(&:to_i)
  ca = []
  n.times { ca.append gets.strip.split.map(&:to_i) }
  
  xx = ca.inject(Array.new(m+1,0)){|r,i| [r,i].transpose.map { |ele| ele.inject(:+) } }
  cmin = xx.shift
  if xx.min < x
    p -1
    return
    exit
  end
  1.upto(2**n-2) do |i|
    xx = Array.new(m+1,0)
    n.times do |j|
      if (i>>j)&1 != 0
        xx = [xx,ca[j]].transpose.map { |ele| ele.inject(:+) }
      end
    end
    if xx[0] < cmin and xx[1..].min >= x
      cmin = xx[0]
    end
  end
  p cmin


Measured memory_bytes: 14332
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
struct r{
	char s[17];
	int p,num;
}a[107];
int cmp(r a,r b)
{
	int tem=strcmp(a.s,b.s);
	if(tem<0) return 1;
	else if(tem>0) return 0;
	else
	{
		if(a.p>=b.p) return 1;
		else return 0;
	}
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%s %d",a[i].s,&a[i].p);
		a[i].num=i+1;
	}
	sort(a,a+n,cmp);
	for(int i=0;i<n;i++) printf("%d\n",a[i].num);
}

Measured memory_bytes: 256
from sys import stdin
import math
import fractions
from collections import deque

INF = 10 ** 10

N = int(stdin.readline().rstrip())
abc = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N)]
# add dummy
abc = abc + [[-INF, -INF, -INF]]

# i日目に(0, 1, 2):=(a, b, c)の行動を行った時の幸福度の最大値
dp = [[-INF] * 3 for _ in range(N+10)]

a, b, c = abc[0]
dp[0][0] = a
dp[0][1] = b
dp[0][2] = c

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i+1][j] =  max(dp[i+1][j], dp[i][k]+abc[i+1][j])

print(max(dp[N-1]))


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

int main() {
int i ,N ,l ,r ,s ,j;
  j = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> l >> r;
    s = r - l + 1;
    j = j + s;
  }
  cout << j << endl;
}

Measured memory_bytes: 3564
from sys import stdin

n,c,k = [int(x) for x in stdin.readline().rstrip().split()]
li = [int(stdin.readline().rstrip()) for _ in range(n)]
li.sort()
time = li[0]
people = 0
bus_num = 1

for i in li:
    people += 1
    if i-time > k or people > c:
        bus_num += 1
        time = i
        people = 1
print(bus_num)

Measured memory_bytes: 7384
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;
using System.Numerics;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {
            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }


        public static long gcd(long x, long y)
        {
            if (y < x) gcd(y, x);
            while (y != 0)
            {
                var z = x % y;
                x = y;
                y = z;
            }
            return x;
        }
        public static long keta(long x)
        {
            var z = 1;
            while (x > 0)
            {
                x /= 10;
                z++;
            }
            return z;
        }
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var n = Read();
            var c = ReadLine().ToArray();
            long r = 0;
            for (int i = 0; i < n; i++)
            {
                if (c[i] == 'R') r++;
            }
            long ans = 0;
            for (int i = 0; i< r; i++)
            {
                if (c[i] == 'W') ans++;
            }
            WriteLine(ans);
          
            Console.Out.Flush();
        }
    }
}



Measured memory_bytes: 19552
#include <bits/stdc++.h>
using namespace std;
#define N 100009
#define INF 1000000009
#define MOD 1000000007
typedef long long int ll;
#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%lld%lld",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pf(x) printf("%d",x);
#define pf2(x,y) printf("%d %d\n",x,y);
#define pf3(x,y,z) printf("%d %d %d\n",x,y,z);
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define tr(x) cout<<x<< endl;
#define tr2(x,y) cout<<x<<" "<<y<<" " << endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(x,y,z,a) cout<<x<<" "<<y<<" "<<z<<  " " << a << " " << endl;
ll dp[109][N],ans;
ll a[N],b[N];
int main(){
    int i,j,n,m,t,k,x,y;
    cin >> n >> m;
    for(i=1; i<=n; i++){
        sd2(a[i],b[i]);
    }
    for(i=0; i<=n; i++){for(j=0; j<N; j++){dp[i][j]=INF;}}
    dp[0][0]=0;
    for(i=1; i<=n; i++){
        for(j=0; j<b[i]; j++){dp[i][j]=dp[i-1][j];}
        for(j=b[i]; j<N; j++){
            dp[i][j]=min(dp[i][j],dp[i-1][j-b[i]]+a[i]);
            dp[i][j]=min(dp[i][j],dp[i-1][j]);
            if(dp[i][j]<=m)ans=max(ans,1ll*j);
            // if(dp[i][j]<INF)tr3(i,j,dp[i][j]);
        }
    }
    tr(ans);
}


Measured memory_bytes: 80640
#include <bits/stdc++.h>
using namespace std;
int N;
vector<int> A, B, C;

void read() {
  cin >> N;
  int a, b, c;
  for (int i = 0; i < N; i++) {
    cin >> a >> b >> c;
    A.push_back(a);
    B.push_back(b);
    C.push_back(c);
  }
}

int main() {
  read();

  vector<tuple<long long, long long, long long>> DP;
  DP.push_back(make_tuple(0, 0, 0));
  for (int i = 0; i < N; i++) {
    int a = A.at(i);
    int b = B.at(i);
    int c = C.at(i);

    auto dp = DP.at(i);
    auto prev_a = get<0>(dp);
    auto prev_b = get<1>(dp);
    auto prev_c = get<2>(dp);

    DP.push_back(make_tuple(a + max(prev_b, prev_c), b + max(prev_c, prev_a),
                            c + max(prev_a, prev_b)));
  }

  auto dp = DP.back();
  auto a = get<0>(dp);
  auto b = get<1>(dp);
  auto c = get<2>(dp);
  cout << max(a, max(b, c)) << endl;
}


Measured memory_bytes: 6244
s = input()
t = input()

dp = [[0] * (len(t) + 1) for _ in range(len(s) + 1)]

for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = dp[i][j] + 1
        else:
            dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])

ret_rev = ""

i, j = len(s) - 1, len(t) - 1
while i >= 0 and j >= 0:
    if s[i] == t[j]:
        ret_rev += s[i]
        i, j = i - 1, j - 1
    elif dp[i + 1][j] == dp[i][j]:
        i, j = i - 1, j
    else: # i.e. dp[i][j + 1] == dp[i][j]
        i, j = i, j - 1

ret = ret_rev[::-1]

print(ret)

Measured memory_bytes: 112732
/*\
 * ...
 * ......
 * In the name of ALLAH
 * ......
 * ...
\*/

#include <bits/stdc++.h>

using namespace std;
#define Size(x) ((int)(x).size())
#define pb push_back
#define LD_OUT setprecision(12) << fixed
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const int INF = 1e9 + 10 , MN = 1e5 + 10;

int n , arr[MN];

int main()
{
	ios_base :: sync_with_stdio(false) ,cin.tie(0) , cout.tie(0);
	cin >> n ;
	for(int i=0;i<n;++i) cin >> arr[i];
	int mn = *min_element(arr , arr+n);
	int mx = *max_element(arr , arr+n);
	if(mx - mn > 1) return cout << "No\n" , 0;
	if(mx == mn){
		if(mn == n-1 || mn <= n/2) cout << "Yes\n";
		else cout << "No\n";
		return 0;
	}
	int cnt = 0;
	for(int i=0;i<n;++i) if(arr[i] == mn) ++cnt;
	if(mn < cnt + (n-cnt)/2 && cnt <= mn) return cout << "Yes\n" , 0;
	cout << "No\n";
	return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<vector>
#include<map>
using namespace std;
#define mod 998244353
map<long long,int> tp;
char s[105];
vector<int> st[105];
int dp(vector<int> s);
int solve(vector<int> s)
{
	int sz=s.size(),as=0;
	if(sz==1)return 1+s[0];
	int s2=st[sz].size();
	for(int i=0;i<s2;i++)
	{
		int v=st[sz][i];
		vector<int> vl;
		for(int j=1;j<=v;j++)
		{
			int mx=1;
			for(int k=j-1;k<sz;k+=v)mx&=s[k];
			vl.push_back(mx);
		}
		as=(as+dp(vl))%mod;
	}
	return as;
}
int dp(vector<int> s)
{
	int sz=s.size();
	if(!sz)return 1;
	if(sz==1)return 1+s[0];
	long long vl=-1;
	if(sz<=50)
	{
		vl=0;
		for(int i=0;i<sz;i++)vl=vl*2+s[i];
		vl=vl*64+sz;
	}
	else vl=sz+(1ll<<60);
	if(tp[vl])return tp[vl];
	int as=0;
	for(int i=0;i<sz;i++)
	{
		vector<int> s1,s2;
		for(int j=0;j<=i;j++)s1.push_back(s[j]);
		for(int j=i+1;j<sz;j++)s2.push_back(s[j]);
		as=(as+1ll*solve(s1)*dp(s2))%mod;
	}
	if(vl!=-1)tp[vl]=as;
	return as;
}
int main()
{
	for(int i=1;i<=100;i++)for(int j=i*2;j<=100;j+=i)st[j].push_back(i);
	scanf("%s",s+1);vector<int> st1;
	for(int i=1;s[i];i++)st1.push_back(s[i]-'0');
	printf("%d\n",dp(st1));
}

Measured memory_bytes: 3328
def main():
    K, T = map(int, input().split())
    a = list(map(int, input().split()))

    previous_value = -1
    result = []
    for i in range(K):
        max_a = -1
        for (index, value) in enumerate(a):
            if max_a < value and previous_value != index and value > 0:
                max_a = value
                next_value = index
        a[next_value] -= 1
        result.append(next_value)
        previous_value = next_value

    r = 0
    for i in range(K-1):
        if result[i] == result[i+1]:
            r+=1
    print(r)



if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef  long long unsigned ull;
constexpr long long mod = 1000000007;
ull n, a[300000],d[60][2];

int main(){
cin>>n;
for (ull i=0; i<n; i++){
  cin>>a[i];
  for (ull j=0; j<60; j++){
    //d[j][(a[i] & ((ull) 1 << j)) ? 1 : 0]++;
    d[j][(a[i]&((ull) 1<<j)) ?1:0]++;


  }
}
ull ans=0;
ull count=1;
for (int j=0; j<60; j++){
  ull temp;
  temp=(d[j][0]*d[j][1])%mod;
  ans+=count*temp;
  ans=ans%mod;
  count=(count*2)%mod;

}

cout<<ans;
}


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

using namespace std;

uint64_t count_AB(const string &s)
{
  uint64_t count = 0;
  
  for (uint64_t i = 0; i < s.size() - 1; ++i) {
    if (s[i] == 'A' && s[i + 1] == 'B') { ++count; }
  }
  
  return count;
}

int main()
{
  uint64_t N;
  cin >> N;
  
  vector<string> s(N);
  vector<uint64_t> d(N, 0);
  uint64_t S = 0;
  
  uint64_t xa = 0, by = 0, ba = 0;
  
  for (uint64_t n = 0; n < N; ++n) {
    cin >> s[n];
    
    d[n] = count_AB(s[n]);
    S += d[n];
    
    if (s[n][0] == 'B' && s[n][s[n].size() - 1] == 'A') { 
      ++ba;
    } else if (s[n][0] == 'B') {
      ++by;
    } else if (s[n][s[n].size() - 1] == 'A') { 
      ++xa;
    }
  }
  
  if (ba > 0) { S += ba - 1; }
  if (ba > 0 && xa > 0) { ++S; --xa; }
  if (ba > 0 && by > 0) { ++S; --by; }
  S += min(xa, by);
  cout << S << endl;
  
  return 0;
}

Measured memory_bytes: 896
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>
#include<time.h>
typedef long long int ll;
//#include<bits/stdc++.h>


using namespace std;





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

    vector<ll>h(n);
    vector<ll>p(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i]; p[i] = 99999999999;
    }
    p[0] = 0;

    for (int i = 0; i < n - 2; i++) {
        p[i + 1] = min(p[i + 1], p[i] + abs(h[i] - h[i + 1]));
        p[i + 2] = min(p[i + 2], p[i] + abs(h[i] - h[i + 2]));
    }
    p[n - 1] = min(p[n - 1], p[n - 2] + abs(h[n-1] - h[n-2]));
    cout << p[n - 1] << endl;
   

    return 0;

}

Measured memory_bytes: 4848
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define Rep(i,a,n) for(int i = a;i<n;i++)
#define ll long long  
const long long MOD = 1000000007LL;
int main(){
    int n;
    cin >> n;
    int a;
    int ans = 0;
    rep(i,n){
        cin >> a;
        ans+=(a-1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#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 X;
	cin >> X;
	ll ans = 0, temp = 100;
	while(temp < X)
	{
		temp += temp / 100;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3624
inf = 1000000000

def main():
    n = int(input())
    num_list = list(map(int, input().split()))

    num_list.sort()

    ans = inf

    for i in range(1,101):
        tmp = 0
        for j in range(n):
            tmp += (num_list[j] - i) ** 2
        ans = min(ans, tmp)

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38768
#include <iostream>
using namespace std;
void maxHeapify(int *arr, int i, int n){
    int left = 2 * i;
    int right = 2 * i + 1;
    int largest = i;
    if (left <= n && arr[left] > arr[i])
        largest = left;
    if (right <= n && arr[right] > arr[largest])
        largest = right;
    if (largest != i){
        int temp = arr[i];
        arr[i] = arr[largest];
        arr[largest] = temp;
        
        maxHeapify(arr, largest, n);
    }
}
void buildMaxHeap(int *arr, int n){
    for(int i = n/2; i >= 1; i--){
        maxHeapify(arr, i, n);
    }
}
int main(){
    unsigned long long int n, m;
    cin >> n;
    cin >> m;
    unsigned long long int sum = 0;
    int *prices = new int[n + 1];
    for(int i = 1; i <= n; i++){
        cin >> prices[i];
        sum += prices[i];
    }
    buildMaxHeap(prices, n);
    for(int i = m; i > 0; i--){
        sum -= prices[1];
        prices[1] /= 2;
        sum += prices[1];
        maxHeapify(prices, 1, n);
    }
    cout << sum;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)
#define all(c) c.begin(),c.end()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>

void Acout(int A[],int N){
    rep(i,N){
        if(i)cout<<" ";
        cout<<A[i];
    }
    cout<<endl;
}

int selectionsort(int A[],int N){
    int ns=0;
    rep(i,N-1){
        int min=i;
        for(int j=i;j<N-1;j++){
            for(int j=i;j<N;j++){
            if(A[min]>A[j])min=j;
            }   
        swap(A[i],A[min]);
        if(i!=min)ns++;
        }
    }
    return ns;
}

int main(){
    int N;
    cin>>N;
    int A[N];
    rep(i,N)cin>>A[i];
    int ns;

     ns = selectionsort(A,N);
     Acout(A,N);
     cout<<ns<<endl;
}


Measured memory_bytes: 3104
#define rep(i,n) for (int i=0; i<(int)(n); ++i)

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

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    for (int i=0; i<N; ++i) cin >> A.at(i);

    // 配列を昇順に並び替える
    sort(A.rbegin(),A.rend());

    // 配列の合計をカウントする
    double sum = 0.0;
    for(int i=0; i<N; ++i) sum += A.at(i);

    if(double((A.at(M-1)/sum)) >= double(1.0/(4.0*M))) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Random;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		FastScanner sc=new FastScanner();
		PrintWriter pw=new PrintWriter(System.out);
		int D=sc.nextInt();
		String ans="";
		if(D==25) {
			ans="Christmas";
		}else if(D==24) {
			ans="Christmas Eve";
		}else if(D==23) {
			ans="Christmas Eve Eve";
		}else if(D==22) {
			ans="Christmas Eve Eve Eve";
		}
		pw.println(ans);
		pw.close();
	}

	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public int nextInt() {
    	return Integer.parseInt(next());
    }
    
    public long nextLong() {
    	return Long.parseLong(next());
    }
}

Measured memory_bytes: 22228
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
 
const int MAX_H = 11, MAX_W = 1010;
int last[MAX_H][MAX_H][MAX_W], pref[MAX_W][MAX_H];
int h, w, k;
int tab[MAX_W][MAX_H];
int dp[MAX_W];
 
int query(int red, int l, int r) {
    if(l == 0) {
        return pref[red][r];
    } else {
        return pref[red][r] - pref[red][l - 1];
    }
}
 
signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> h >> w >> k;
    for(int i = 0; i < h; i ++) {
        string s;
        cin >> s;
        for(int j = 0; j < w; j ++) {
            tab[j][i] = s[j] - '0';
        }
    }
    for(int i = 0; i < w; i ++) {
        pref[i][0] = tab[i][0];
        for(int j = 1; j < h; j ++) {
            pref[i][j] = pref[i][j - 1] + tab[i][j];
        }
    }
    for(int l = 0; l < h; l ++) {
        for(int r = l; r < h; r ++) {
            int xl = 0, xr = -1, sum = 0;
            while(true) {
                while(xr < w - 1 && sum + query(xr + 1, l, r) <= k) {xr ++; sum += query(xr, l, r); last[l][r][xr] = xl;}
                if(xr == w - 1) {break;}
                while(sum + query(xr + 1, l, r) > k) {sum -= query(xl, l, r); xl ++;}
            }
        }
    }
    ll ans = mod;
    for(int mask = 1; mask < (1 << h); mask += 2) {
        fill_n(dp, MAX_W, mod);
        bool impos = false;
        for(int i = 0; i < w; i ++) {
            ll sum = 0;
            for(int j = 0; j < h; j ++) {
                if(mask & (1 << j)) {
                    sum = 0;
                }
                sum += tab[i][j];
                if(sum > k) {impos = true; break;}
            }
            if(impos) {break;}
            if(i == 0) {dp[i] = 0; continue;}
            int prv = -1, mn = 0;;
            for(int j = 0; j < h; j ++) {
                if(mask & (1 << j)) {
                    if(prv != -1) {
                        chkmax(mn, last[prv][j - 1][i]);
                    }
                    prv = j;
                }
            }
            chkmax(mn, last[prv][h - 1][i]);
            if(mn == 0) {
                dp[i] = 0;
            } else {
                dp[i] = dp[mn - 1] + 1;
            }
        }
        chkmin(ans, dp[w - 1] + __builtin_popcount(mask) - 1);
    }
    cout << ans << endl;
    return 0;
}
 

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

#define int int64_t

using namespace std;

#define MAX 200005

int n, m, dp[MAX];
vector<int> v[MAX];

int f(int i)
{
    if (dp[i] > 0)
        return dp[i];
    int be = 0;
    for (auto j = v[i].begin(); j != v[i].end(); j++)
        be = max(be, f(*j) + 1);
    return dp[i] = be;
}

signed main()
{
    scanf("%lld %lld", &n, &m);
    for (int i = 0; i < m; i++)
    {
        int x, y;
        scanf("%lld %lld", &x, &y);
        v[x].push_back(y);
    }
    int be = 0;
    for (int i = 1; i <= n; i++)
        be = max(be, f(i));
    printf("%lld\n", be);
}


Measured memory_bytes: 11520
import java.util.*;
public class Main {
    public static long gcd(long x,long y){
        if(x < y) return gcd(y, x);
        if(y == 0) return x;
        return gcd(y, x % y);
    }
    public static long lcm(long x,long y){                                                              
        return x*y/gcd(x,y);                                                                                                                                                                                                                
    }
    public static long fac(long x){
        if(x==0) return 1;
        return x*fac(x-1);
    }
    public static long per(long x,long y){
        return fac(x)/fac(x-y);      
    }
    public static long com(long x,long y){
        return per(x,y)/fac(y);      
    }
    public static long com2(long x,long y){
        if(y==0 || y==x) return 1;
        if(x < y) return 0;
        return com2(x-1,y-1)+com2(x-1,y);
    }
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();       
		long [] in = new long [a]; 
        long [] l = new long [a+1];
        long [] r = new long [a+1];
        long [] ans = new long [a];
        for(int i=0;i<a;i++){
                             in[i] = sc.nextLong();
                            }
		l[0]= 0;
        r[a]= 0;
        for(int i=1;i<=a;i++){l[i]=gcd(l[i-1],in[i-1]);}
        for(int i=a-1;i>=0;i--){r[i]=gcd(r[i+1],in[i]);}
        for(int i=0;i<a;i++){ans[i]=gcd(l[i],r[i+1]);}
        long b = 0;
        for(int i=0;i<a;i++){b=Math.max(b,ans[i]);                                              
                            }       
		System.out.println(b);
	}
}


Measured memory_bytes: 64300
#include <stdio.h>
#include <string.h>
#include <ctype.h>
//#include <DEBUG.h>
#ifndef LL
#define LL long long
#endif
#ifndef uLL
#define uLL unsigned long long
#endif
#ifndef uL
#define uL unsigned int
#endif
#ifndef iL
#define iL int
#endif
#ifndef iS
#define iS short
#endif
#ifndef uS
#define uS unsigned short
#endif
#ifndef uC
#define uC unsigned char
#endif
#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))
#define abs(a) (((a)<0)?(-(a)):(a))
#define sgn(a) (((a)<0)?(1):(0))
#define movs(a,b,l) (memmove((a),(b),sizeof(*(b))*(l)))
#define stosb(a,b,l) (memset((a),(b),sizeof(*(a))*(l)))
LL num[100000];
char str[10000];
int main()
{
	//freopen("in.in","r",stdin);
	LL a,b,c,i,j,k,n,m,ans[8],ans2;
	scanf("%lld",&n);
	ans2=0;ans[0]=0;ans[1]=0;ans[2]=0;ans[3]=0;
	for (i=1;i<=n;i++)
	{
		RE:scanf("%s",str);
		if (isupper(*str)==0) {goto RE;}
		for (j=0;str[j]>0;j++){if ((str[j]=='A')&&(str[j+1]=='B')) {ans2+=1;};}
		a=(str[0]=='B');
		b=(str[j-1]=='A');
		ans[2*a+b]+=1;
	}
	//printf("%lld %lld %lld %lld\n",ans[1],ans[2],ans[3],ans2);
	a=max(ans[1],ans[2]);
	b=min(ans[1],ans[2]);
	if (a==b)
	{
		if (a>0)
		{
			printf("%lld\n",ans2+b+ans[3]);
		}
		else
		{
			printf("%lld\n",ans2+max(ans[3]-1,0));
		}
	}
	else
	{
		if (ans[3]>0)
		{
				printf("%lld\n",ans2+b+ans[3]);
		}
		else
		{
			printf("%lld\n",ans2+b);
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void){
    char s[200];
    char p[100];
    int l,i = 0,j,k;
    scanf("%s\n",s);
    scanf("%s\n",p);
    while(s[i] != '\0') i++;
    l = i;
    for(i = l;i<l*2;i++){
    s[i] = s[i - l];
    }
    for(i = 0;i < l*2;i++){
        if(s[i] == p[0]){
            j = 0;
            k = i;
            while(s[k] == p[j]){
                    j++;
                    k++;
                    if(p[j] == '\0'){
                        printf("Yes\n");
                        return 0;
                    }
            }
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <map>
#include <tuple>
#include <cmath>
#include <cstdio>
#include <cassert>
#include <functional>
#define _LIBCPP_DEBUG 0
using namespace std;
using ll = long long;

int main(void)
{
    int n;
    cin >> n;
    
    vector<int> a(n);

    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i);
    }
    
    for (int  i = 0; i < n-1; i++)
    {
        if (a.at(i + 1) - a.at(i) >0)
        {
            a.at(i + 1)--;
        }

        if (a.at(i)>a.at(i+1))
        {
            cout << "No" << endl;
            return 0;
        }
        
    }
    
    cout << "Yes" << endl;
}


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

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

    int N, T;
    cin >> N >> T;
    vector<ll> A(N), B(N);
    rep(i, N) { cin >> A[i] >> B[i]; }

    ll dp1[N + 5][T + 5];
    memset(dp1, 0, sizeof(dp1));
    rep(i, N) {
        rep(j, T) {
            if (j - A[i] >= 0)
                dp1[i + 1][j] = max(dp1[i + 1][j], dp1[i][j - A[i]] + B[i]);
            dp1[i + 1][j] = max(dp1[i + 1][j], dp1[i][j]);
        }
    }

    ll dp2[N + 5][T + 5];
    memset(dp2, 0, sizeof(dp2));
    for (int i = N; i >= 1; i--) {
        for (int j = 0; j <= T - 1; j++) {
            dp2[i][j] = dp2[i + 1][j];
            if (j - A[i - 1] >= 0)
                dp2[i][j] = max(dp2[i][j], dp2[i + 1][j - A[i - 1]] + B[i - 1]);
        }
    }

    ll ans = 0;
    for (int i = 0; i <= N - 1; i++) {
        for (int j = 0; j < T; j++) {
            ll tmp = dp1[i][T - 1 - j] + dp2[i + 2][j];
            tmp += B[i];
            ans = max(tmp, ans);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 144744
#include <iostream>
#include <vector>
#include <string>

using namespace std;
 
int main()
{
    int n;
    cin>>n;
     
    vector<string> A(n),A2(n);
    for(int i=0;i<n;i++){
        cin>>A[i];
        A2[i]=A[i];
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<n-1;j++){
            if(A[j][1]>A[j+1][1]){
                swap(A[j],A[j+1]);
            }
        }
    }
     
    for(int i=0;i<n-1;i++) cout<<A[i]<<" ";
    cout<<A[n-1]<<endl<<"Stable"<<endl;

    for(int i=0;i<n;i++){
        int minj=i;
        for(int j=i;j<n;j++){
            if(A2[j][1]<A2[minj][1]){
                minj=j;
            }
        }
        swap(A2[i],A2[minj]);
    }
     
    for(int i=0;i<n-1;i++) cout<<A2[i]<<" ";
    cout<<A2[n-1]<<endl;
    if(A==A2) cout<<"Stable"<<endl;
    else cout<<"Not stable"<<endl;
    
    return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    int n, m; cin>>n>>m;
    vector<int> p(m);
    for(int i=0; i<m; i++) cin>>p[i];
    vector<ll> a(n), b(n), c(n);
    for(int i=0; i<n-1; i++) cin>>a[i]>>b[i]>>c[i];

    vector<ll> imos(n+10, 0);
    for(int i=0; i<m-1; i++){
        int l = min(p[i], p[i+1]);
        int r = max(p[i], p[i+1]);
        imos[l]++;
        imos[r]--;
    }

    for(int i=0; i<n; i++){
        imos[i+1] += imos[i];
    }

    ll ans=0;
    for(int i=0; i<n; i++){
        ans += min(a[i] * imos[i+1], c[i] + b[i] * imos[i+1]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 6220