akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <stack>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int,int> > vp;
vector<pair<double,int> > member;
const double eps=1e-9;
typedef pair<int,int> p;
int dp[400][400];
int rest[400][400];
int main()
{
  int n;
  cin >> n;
  vector<int> s(n+5);
  vector<int> l(n+5);
  vector<int> p(n+5);
  for(int i=0;i<n;i++)
    {
      cin >> s[i] >> l[i] >> p[i];
    }
  int m;
  cin >> m;
  vector<int> score(m+5);
  bool clear=true;
  for(int i=0;i<m;i++)
    {
      int length;
      cin >> length;
      memset(dp,0,sizeof(dp));
      memset(rest,0,sizeof(rest));
      for(int j=0;j<n;j++)
	{
	  for(int k=0;k<=length;k++)
	    {
	      int mu=s[j];
	      if(k<mu)
		{
		  dp[j+1][k]=dp[j][k];
		  rest[j+1][k]=rest[j][k];
		}
	      else
		{
		  dp[j+1][k]=max(dp[j][k],dp[j+1][k-mu]+p[j]);
		  if(dp[j+1][k]>dp[j][k]) rest[j+1][k]=rest[j+1][k]+(l[j]-s[j]);
		  else rest[j+1][k]=rest[j][k];
		}
	      
	    }
	}
      int tmpmax=0;
      for(int j=0;j<=length;j++)
	{
	  if(rest[n][j]>=length-j) tmpmax=max(tmpmax,dp[n][j]);
	}
      if(tmpmax==0) 
	{
	  clear=false;
	  break;
	}
      else
	{
	  score[i]=tmpmax;
    	}
    }
  if(!clear) cout << -1 << endl;
  else
    {
      for(int i=0;i<m;i++)
	{
	  cout << score[i] << endl;
	}
    }
  
  return 0;
}
      



Measured memory_bytes: 4332
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define sz(x) (int)x.size()
#define newl "\n"
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vll vector<pll>
#define coutp cout << fixed << setprecision(12)
#define mem(x, val) memset(x, val, sizeof(x))
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define all(v) (v).begin(), (v).end()

const ld pi = 3.14159265359;
ll INF = 1e18 + 10;
ll MOD = 998244353;
ll mod = 1e9 + 7;

inline ll add(ll a, ll b, ll m)
{
    if ((a + b) >= m)
        return (a + b) % m;
    return a + b;
}

inline ll mul(ll a, ll b, ll m)
{
    if ((a * b) < m)
        return a * b;
    return (a * b) % m;
}

ll power(ll x, ll y, ll m)
{
    ll res = 1;
    x = x % m;
    if (x == 0)
        return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % m;
        y = y >> 1;
        x = (x * x) % m;
    }
    return res;
}

void solve()
{
    ll n;
    cin>>n;
    vector<char> x(26);
    for(int i=0;i<26;i++) {
        x[i] = 'a'+i;
    } 
    vi a;
    //n--;

    while(n>0) {
        ll rem = n%26;
        if(rem==0) {
            a.pb(26);
            n--;
        }
        else
            a.pb(rem);
        n/=26;
        //if(n==0) a.pb(0);
    }

    reverse(all(a));
    for(int i=0;i<sz(a);i++) {
        cout<<x[a[i]-1];
    }
}


int main()
{
    fastio;
    int t;

    t = 1;
    //cin >> t;
    //int test=t;
    while (t-- > 0)
    {
        //cout<<"Case #"<<(test-t)<<": ";
        solve();
        cout << newl;
    }

    return 0;
}

Measured memory_bytes: 3588
/*zxj*/
#include<iostream> 
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<sstream>
#define sf scanf
#define pf printf
#define pfn printf("\n");
#define pfk printf(" ");
#define pf0 printf("0");
#define pf1 printf("1");
#define ll long long
#define sfd(n) scanf("%d",&n);
#define sfdd(n,m) scanf("%d%d",&n,&m);
#define sfld(n) scanf("%lld",&n);
#define sfldd(n,m) scanf("%lld%lld",&n,&m);
#define sflf(n) scanf("%lf",&n);
#define sflff(n,m) scanf("%lf%lf",&n,&m);
#define sfc(n) scanf("%c",n);
#define sfcc(n,m) scanf("%c%c",n,m);
#define sfs(n) scanf("%s",n);
#define sfss(n,m) scanf("%s%s",n,m);
#define pfd(n) printf("%d",n);
#define pfld(n) printf("%lld",n);
#define pflf(n) printf("%lf",n);
#define pfc(n) printf("%c",n);
#define pfs(n) printf("%s",n);
using namespace std;
#define csh(a,n) memset(a,n,sizeof(a));
int main(){
	int n;
	cin>>n;
	string arr;
	cin>>arr;
	if(n>=3200){
		cout<<arr<<endl;
	}
	else{
		cout<<"red"<<endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin>>n>>s;
  int ans=0;
  for(int i=0; i<n-2; i++){
    if(s.substr(i,3)=="ABC")ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

const double INF = 1e9;
int n, k;

double C(double x, double y, vector<complex<double>>& p) {
	vector<double> dis(n);
	complex<double> s(x, y);
	rep(i, n) { dis[i] = abs(p[i] - s); }
	sort(all(dis), greater<double>());

	double sum = 0;
	rep(i, k) { sum += dis[i]; }
	return sum;
}

complex<double> ternarySearch(vector<complex<double>>& p, double t) {
	double right_x = 10000, left_x = -1000 + t;
	double right_y = 10000, left_y = -1000 + t;
	rep(i, 100) {
		//show(i) cout << right_x << ' ' << left_x << endl;
		//cout << right_y << ' ' << left_y << endl;
		double llr_x = (left_x * 2 + right_x) / 3;
		double rll_x = (left_x + right_x * 2) / 3;
		double llr_y = (left_y * 2 + right_y) / 3;
		double rll_y = (left_y + right_y * 2) / 3;

		pair<double, int> r[4];
		r[0] = make_pair(C(llr_x, llr_y, p), 0);
		r[1] = make_pair(C(llr_x, rll_y, p), 1);
		r[2] = make_pair(C(rll_x, rll_y, p), 2);
		r[3] = make_pair(C(rll_x, llr_y, p), 3);


		double mini = 1e10; int idx;
		rep(i,4){
			if(mini > r[i].first){
				mini = r[i].first;
				idx = r[i].second;
			}
		}
		//show(mini);

		switch (idx) {
			case 0:
				right_x = rll_x;
				right_y = rll_y;
				break;
			case 1:
				right_x = rll_x;
				left_y = llr_y;
				break;
			case 2:
				left_x = llr_x;
				left_y = llr_y;
				break;
			case 3:
				left_x = llr_x;
				right_y = rll_y;
				break;
		}
	}
	return complex<double>(left_x, left_y);
}

signed main() {
	cin >> n >> k;
	vector<complex<double>> p;
	rep(i, n) {
		double x, y;
		cin >> x >> y;
		p.emplace_back(x, y);
	}

	double a = 1e9;
	rep(i, 1000){
		auto s = ternarySearch(p, -10 * i);
		// cout << a << ' ' << b << endl;
		vector<double> ans(n);
		rep(i, n) { ans[i] = abs(s - p[i]); }
		sort(all(ans), greater<double>());
		double sum = 0;
		rep(i, k) sum += ans[i];
		a = min(a, sum);
	}
	cout << fixed << setprecision(10) << a << endl;
}



Measured memory_bytes: 3336
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n;
    cin >> n;

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

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

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 26548
import java.util.Scanner;

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

        while(true){
            int H =sc.nextInt();
            int W =sc.nextInt();
            if(H==0 && W==0){
                break;
            }

            for(int j=0;j<W;j++){
                System.out.printf("#");
            }
            System.out.printf("\n");
            for(int i=0;i<H-2;i++){
                System.out.printf("#");
                for(int j=0;j<W-2;j++){
                    System.out.printf(".");
                }
                System.out.printf("#\n");
            }
            for(int j=0;j<W;j++){
                System.out.printf("#");
            }
            System.out.printf("\n\n");
        }
    }
}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n,a,b; cin >> n >> a >> b;

  int ans = 0;
  
  for(int i = 1;i<=n;i++){
    int tmp = 0;
    string s;
    s = to_string(i);
    rep(j,s.size()){
      int x = s[j]-'0';
      tmp+=x;
    }
    if(a<=tmp && tmp<=b) ans+=i;
  }

  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3688
x, y = gets.split.map(&:to_i)
g1 = [1, 3, 5, 7, 8, 10, 12]
g2 = [4, 6, 9, 11]
g3 = [2]
f = false
if g1.include?(x) && g1.include?(y)
  f = true
elsif g2.include?(x) && g2.include?(y)
  f = true
elsif g3.include?(x) && g3.include?(y)
  f = true
end
puts f ? "Yes" : "No"


Measured memory_bytes: 1788
def AtoZ(s) : 
  for i in range(len(s)) : 
    if s[i] =='A' : 
      addr_a = i
      break
  for j in range(len(s)) : 
    if s[len(s) - j - 1] == 'Z' : 
      addr_z  = len(s) - j - 1
      break
      
  return addr_z - addr_a + 1

s = input()

print(AtoZ(s))

Measured memory_bytes: 3512
n=int(input())
A=[int(i) for i in input().split()]
B=[0]*60
C=[0]*60
ans=0
mod=10**9+7
for i,a in enumerate(A):
  for j in range(60):
    if a%2==0:
      C[j]+=B[j]
    else:
      C[j]+=i-B[j]
      B[j]+=1
    a//=2
for i in range(60):
  ans=(ans+C[i]*(2**i))%mod
print(ans)


Measured memory_bytes: 122936
let rd = Int(readLine()!)!
func sumDigits(_ num: Int) -> Int {
  var num = num
  var sum = 0
  while num > 0 {
    sum += num%10
    num /= 10
  }
  return sum
}

var min = 100
for i in 1 ... rd/2+1 {
  var j = rd - i
  if sumDigits(i) + sumDigits(j) < min {
    min = sumDigits(i) + sumDigits(j)
  }
}
print(min)

Measured memory_bytes: 7732
#include <bits/stdc++.h>
using namespace std;
int main(){
 
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  
  for(int i=0; i<n; i++) {
      int s=0;
      cin >> s;
      a[i].first  = s;
      a[i].second = i+1;
      
  }
  
  sort(a.begin(), a.end());
  
  for(int i=0; i<n; i++) {
      cout << a[i].second << " ";
  }
  
  cout << endl;
 
}

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

int main()
{
	int n = 100;

	vector<vector<int>> G(n,vector<int>(n,0));
	int a,b;
	cin >> a >> b;
	for(int i = 0;i<n/2;i++)for(int j = 0;j<n;j++)G[i][j]=1;

	a--;
	b--;

	for(int i = 0;i<n/2;i+=2)
	{
		for(int j = 0;j<n;j+=2)
		{
			if(b)
			{
				G[i][j] = 0;
				b--;
			}
		}
	}

	for(int i = n/2+1;i<n;i+=2)
	{
		for(int j = 0;j<n;j+=2)
		{
			if(a)
			{
				a--;
			G[i][j] = 1;
			}
		}
	}
	cout << 100 << ' ' << 100 << endl;

	for(int i = 0;i<n;i++)
	{
		for(int j = 0;j<n;j++)
		{
			if(G[i][j])cout <<'.';
			else cout << '#' ;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3640
/*
	2204: Final Examination!
*/
#include	<iostream>
#include	<algorithm>

using namespace std;

int main(void) {
	int n, buf_sum, top, worst, buf_score;

	while (1) {
		cin >> n;
		if (n == 0) { break; }

		top = -1; worst = -1;
		for (int i = 0; i < n; i++) {
			buf_sum = 0;
			for (int j = 0; j < 5; j++) {
				cin >> buf_score;
				buf_sum += buf_score;
			}
			top = top == -1 ? buf_sum : max(top, buf_sum);
			worst = worst == -1 ? buf_sum : min(worst, buf_sum);
		}
		cout << top << ' ' << worst << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
def main():
    import sys
    input = sys.stdin.readline
    N, M = map(int, input().split())
    C = [0]*(N+1)
    for i in range(M):
        a, b = map(int, input().split())
        C[a]+=1
        C[b]+=1
    for i in range(N+1):
        if C[i] % 2 == 1:
            return "NO"
    return "YES"

print(main())


Measured memory_bytes: 3828
array = [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]
i = int(input())
print(array[i-1])

Measured memory_bytes: 38256
a = [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 = int(input())

print(a[k - 1])

Measured memory_bytes: 3316
N = int(input())

for i in range(N):
    if i == 0:
        P = list(map(int, input().split()))
        continue
    P.append(int(input().split()[1]))

INF = 2 ** 32 - 1
dp = [[INF] * N for _ in range(N)]

for ij in range(N):
    dp[ij][ij] = 0

for l in range(1, N):
    for i in range(N):
        j = i + l
        if j >= N:
            continue
        for k in range(i, j):
            dp[i][j] = min(dp[i][k] + dp[k+1][j] + P[i] * P[j+1]*P[k+1],
                           dp[i][j])

print(dp[0][-1])



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

int o(int x) {
	if (x < 0) return x * -1;
	else return x;
}

int q(int x, int y) {
	if (x < y) return y;
	else return x;
}

int main() {
	v(a);
	v(b);
	if (o(a - b) % 2 == 1) cout << "IMPOSSIBLE" << endl;
	else cout << o(q(a, b) - o(a - b) / 2) << endl;
}

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

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

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

void Main() {
    char C;
    cin >> C;
    cout << (char)(C + 1) << endl;
}


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

int main(){
    int n, m;
    cin >> n >> m;
    vi food(m, 0);
    rep(i, n){
        int k;
        cin >> k;
        rep(j, k){
            int tmp;
            cin >> tmp;
            food[tmp-1]++;
        }
    }
    int cnt = 0;
    rep(i, m){
        if(food[i] == n) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

int main(){

    int N;
    cin >> N;
    
    int ans = 0;

    for(int i=1;i<=N;i++){
        if(to_string(i).length()%2==1)ans++;
    }

    cout << ans <<endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 100010
#define lowbit(i) i&-i
using namespace std;
typedef long long ll;
int n;
int l=0,r=0;
int a[maxn],pre[maxn*10],t[maxn*10];
int readint(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
void add(int i){
	while(i<=maxn*2){
		t[i]++;
		i+=lowbit(i);
	}
}
ll query(int i){
	ll ret=0;
	while(i>0){
		ret+=t[i];
		i-=lowbit(i);
	}
	return ret;
}
bool check(int mid){
	for(int i=1;i<=2*maxn;i++) t[i]=0;
	pre[0]=0;
	for(int i=1;i<=n;i++) pre[i]=pre[i-1]+(a[i]>=mid?1:-1);
	ll sum=0;
	for(int i=0;i<=n;i++){
		sum+=query(pre[i]+maxn);
		add(pre[i]+maxn);
	}
	return sum>=1ll*n*(n+1)/4;
}
int main(){
	n=readint();
	for(int i=1;i<=n;i++){
		a[i]=readint();
		r=max(r,a[i]);
	}
	int mid;
	while(l<=r){
		mid=(l+r)>>1;
		if(check(mid))
			l=mid+1;
	    else
			r=mid-1;
	}
	printf("%d",r);
	return 0;
}


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

ll R, D, X;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> R >> D >> X;
    for (ll i = 1; i <= 10; i++) {
        X = R*X - D;
        cout << X << "\n";
    }
    
}

Measured memory_bytes: 256
#include<stdio.h>

static const int MAX = 500;
static const int INFTY = (1<<21);

main(){
  int n, i, j, e, sum;
  int key,pi[MAX],v[MAX],u,c[MAX],M[MAX][MAX];
 
  scanf("%d", &n);

  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      scanf("%d", &e);
      M[i][j] = (e==-1)?INFTY:e;
    }
  }

  for(i=0;i<n;i++){
    c[i]=INFTY;
    pi[i]=-1;
    v[i]=0;
  }
  c[0]=0;
  while(1){
    key=INFTY;
    u=-1;
    for(i=0;i<n;i++){
      if(key>c[i] && !v[i]){
	u=i;
	key=c[i];
      }
    }
    if(u==-1)break;
    v[u]=1;
    for(j=0;j<n;j++){
      if(M[u][j]<c[j] && !v[j]){
	pi[j]=u;
	c[j]=M[u][j];
      }
    }
  }
  sum = 0;
  
  for ( i = 0; i < n; i++ ){
    if ( pi[i] != -1 ) sum += M[i][pi[i]];
  }

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

  return 0;
}

Measured memory_bytes: 804
import math
 
DISTANCE_NUM=0
 
N,D=map(int,input().split())
 
for _ in range(N):
  x,y=map(int,input().split())
  distance=math.sqrt(x**2+y**2)
  
  if distance <= D:
    DISTANCE_NUM+=1
    
print(DISTANCE_NUM)

Measured memory_bytes: 9184
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
int a[105],b[105];
int main()
{
	int n,x,ans;
	scanf("%d",&n);
	for(int i = 1;i <= n; i++)
	{
			scanf("%d",&x);
			a[i] = a[i - 1] + x;
	}
	for(int i = 1;i <= n; i++)
	{
		scanf("%d",&x);
		b[i] = b[i - 1] + x;
	}
	int max = 0;
	for(int i = 1;i <= n; i++)
	{
		ans = a[i] +(b[n] - b[i - 1]);
		if(ans > max)
			max = ans;
	}
	printf("%d\n",max);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int v[10],d[10];
int main(){
  int n,k,a,cnt=0;
  scanf("%d%d",&n,&k);
  for(int i=0;i<n;i++){
    scanf("%d",&a);
    v[a]++;
  }
  for(int i=n;i<1000000;i++){
    int m=i,flag=0,num;
    while(m){
      num=m%10;
      m/=10;
      if(v[num]){
        flag=1;break;
      }
    }
    if(!flag){
      printf("%d\n",i);break;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <queue>

using namespace std;

#define ll long long
constexpr ll inf = 1e9+7;

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

    int c[3][3];
    for (int i = 0; i < 3; i++)
        for (int j = 0; j < 3; j++) cin>>c[i][j];

    int a[3][3];
    for (int i = 1; i < 3; i++)
        for (int j = 0; j < 3; j++) a[i][j] = c[i][j] - c[i-1][j];

    for (int i = 1; i < 3; i++) {
        if (!(a[i][0] == a[i][1] && a[i][1] == a[i][2])) {
            cout<<"No"<<endl;
            return 0;
        }
    }
    
    for (int i = 1; i < 3; i++)
        for (int j = 0; j < 3; j++) a[j][i] = c[j][i] - c[j][i-1];

    for (int i = 1; i < 3; i++) {
        if (!(a[0][i] == a[1][i] && a[1][i] == a[2][i])) {
            cout<<"No"<<endl;
            return 0;
        }
    }

    cout<<"Yes"<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define M 2000 
int a[M],n,i,S[M];
void solve(int p,int t){
  if(t==0){
    S[i]=1;
  }
  if(t>0 && p<n){
    solve(p+1,t-a[p]);
    solve(p+1,t);
  }
}
main(){
  int q,m[M];
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++)
    scanf("%d",&m[i]); 
  for(i=0;i<q;i++)
    S[i]=0;
  for(i=0;i<q;i++){
    solve(0,m[i]);
  }
  for(i=0;i<q;i++){
    if(S[i]==1)
      printf("yes\n");
    else
      printf("no\n");
  }
  return 0; 
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main implements Runnable {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Thread(null, new Main(), "", 128 * 1024 * 1024).start();
    }

    static int[][] cumSum;

    public void run() {
        try (Scanner in = new Scanner(System.in)) {
            int n = in.nextInt(), k = in.nextInt(), k2 = k * 2;
            int[][] w = new int[k2][k2];
            for (int i = 0; i < n; i++) {
                int x = in.nextInt(), y = in.nextInt();
                if (in.next().charAt(0) == 'B') {
                    y += k;
                }
                w[y % k2][x % k2]++;
            }

            cumSum = new int[k2 + 1][k2 + 1];
            for (int i = 1; i <= k2; i++) {
                for (int j = 1; j <= k2; j++) {
                    cumSum[i][j] = cumSum[i - 1][j] + cumSum[i][j - 1] - cumSum[i - 1][j - 1] + w[i - 1][j - 1];
                }
            }

            int max = 0;
            for (int i = 0; i < k2; i++) {
                for (int j = 0; j < k2; j++) {
                    int y0 = k2, x0 = k2;
                    int y1 = Math.min(i + k, k2), x1 = Math.min(j + k, k2);
                    int y2 = i, x2 = j;
                    int y3 = Math.max(i - k, 0), x3 = Math.max(j - k, 0);
                    int y4 = 0, x4 = 0;

                    int sum = sum(y1, y0, x1, x0)
                              + sum(y1, y0, x3, x2)
                              + sum(y2, y1, x2, x1)
                              + sum(y2, y1, x4, x3)
                              + sum(y3, y2, x3, x2)
                              + sum(y3, y2, x1, x0)
                              + sum(y4, y3, x4, x3)
                              + sum(y4, y3, x2, x1);
                    max = Math.max(sum, max);
                }
            }
            System.out.println(max);
        }
    }

    private int sum(int ya, int yb, int xa, int xb) {
        return cumSum[ya][xa] + cumSum[yb][xb] - cumSum[yb][xa] - cumSum[ya][xb];
    }
}


Measured memory_bytes: 108984
#include<bits/stdc++.h>
using namespace std;
int main () {
  long long A, B, K;
  cin >> A >> B >> K;
  if (A < K) {
    cout << 0 << ' ' << max(0LL, B + A - K) << endl;
  }else cout << A - K << ' ' << B << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

int main()
{
	int pat[][3] = {
		{ 0, 1, 2 },
		{ 3, 4, 5 },
		{ 6, 7, 8 },
		{ 0, 3, 6 },
		{ 1, 4, 7 },
		{ 2, 5, 8 },
		{ 0, 4, 8 },
		{ 2, 4, 6 },
	};

	char buf[16];
	char s[16];
	while (cin.getline(buf, sizeof(buf)), *buf != '0')
	{
		s[0] = '\0';
		strcat(s, buf);
		for (int i = 0; i < 2; ++i)
		{
			cin.getline(buf, sizeof(buf));
			strcat(s, buf);
		}

		char win = '+';
		for (int i = 0; i < 8 && win == '+'; ++i)
			if (s[pat[i][0]] == s[pat[i][1]] && s[pat[i][1]] == s[pat[i][2]])
				win = s[pat[i][0]];

		if (win != '+')
			printf("%c\n", win);
		else
			puts("NA");
	}

	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

int main(void){
  int c[3][3];
  int i,j;
  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      scanf("%d",&c[i][j]);
    }
  }
  for(i=0;i<2;i++){
    for(j=0;j<2;j++){
      if(!(c[i][j]-c[i][j+1]==c[i+1][j]-c[i+1][j+1])){
        printf("No\n");
        return 0;
      }
    }
  }
  printf("Yes\n");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <queue>
#define MX 999999999999999
using namespace std;
typedef long long ll;

ll N;
ll ar[440000];
ll D[440000][11];

struct st {
    ll point, cnt, S;
};

int main() {
    cin >> N;
    for(int x=0; x<N; x++) {
        cin >> ar[x];
        for(int d=0;d<4; d++) {
            D[x][d] = -MX;
        }
    }
    queue <st> Q;
    bool chk = true;
    ll ans = 0;
    if(N%2 ==0) {
        Q.push({0,0,ar[0]});
        Q.push({1,1,ar[1]});
        while(!Q.empty()) {
            st F = Q.front();
            Q.pop();
            if(F.point >= N) continue;
            if(D[F.point][F.cnt] > F.S) continue;
            D[F.point][F.cnt] = F.S;
            if(F.point == N-1 && F.cnt == 1) {
                if(chk) {
                    ans = F.S;
                    chk = false;
                }
                if(F.S > ans ) {
                    ans = F.S;
                }
            }
            if(F.point == N-2 && F.cnt == 0) {
                if(chk) {
                    ans = F.S;
                    chk = false;
                }
                if(F.S > ans) {
                    ans = F.S;
                }
            }

            if(F.cnt == 0) {
                Q.push({F.point+3, F.cnt + 1, F.S + ar[F.point+3]});
            }
            Q.push({F.point+2, F.cnt, F.S + ar[F.point+2]});
        }
        cout<<ans;
    }
    else {
        Q.push({0,0,ar[0]});
        Q.push({1,1,ar[1]});
        Q.push({2,0,ar[0]+ar[2]});
        Q.push({2,2,ar[2]});
        while(!Q.empty()) {
            st F = Q.front();
            Q.pop();
            if(F.point >= N) continue;
            if(D[F.point][F.cnt] > F.S) continue;
            D[F.point][F.cnt] = F.S;
            
            if(F.point == N-1 && F.cnt ==2) {
                if(chk) {
                    ans = F.S;
                    chk = false;
                }
                if(F.S > ans) {
                    ans = F.S;
                }
            }
            if(F.point == N-2 && F.cnt == 1)  {
                if(chk) {
                    ans = F.S;
                    chk = false;
                }
                if(F.S > ans) {
                    ans = F.S;
                }
            }
            if(F.point == N-3 && F.cnt == 0) {
                if(chk) {
                    ans = F.S;
                    chk = false;
                }
                if(F.S > ans) {
                    ans = F.S;
                }
            }

            if(F.cnt == 0 || F.cnt == 1) {
                Q.push({F.point+3, F.cnt + 1, F.S + ar[F.point+3]});
            }
            Q.push({F.point+2, F.cnt, F.S + ar[F.point+2]});
        }
        cout<<ans;
    }
}

Measured memory_bytes: 22408
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int solve(string& s, string& t){
  int L = s.size();
  int M = t.size();
  int dp[101][101][31] = {};
  REP(i, M){
    REP(j, L)if(s[j] == t[i]){
      for(int k = 1; i - k * j >= 0 && k <= 100; k++){
        dp[i][k][j] += (j >= 1) ? dp[i - k][k][j - 1] : 1;
      }
    }
  }
  /*
  FOR(k, 1, 11){
    printf("interval = %d\n", k);
    REP(i, M){
      printf("i = %d c = %c: ", i, t[i]);
      REP(j, L) printf("%d ", dp[i][k][j]);
      putchar('\n');
    }
  }
  */
  int ans = 0;
  REP(i, M)REP(k, 101) ans += dp[i][k][L - 1];
  return ans;
}

int main(){
  int N;
  cin>>N;
  string s;
  cin>>s;
  int ans = 0;
  REP(i, N){
    string t; cin>>t;
    if(solve(s, t)) ans++;
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  ll N, K, S;
  cin >> N >> K >> S;

  vector<ll> ans(N);
  rep(i, K){
    ans[i] = S;
  }

  ll other;
  if(S == 1e9){
    other = 1e9-1;
  }else{
    other = 1e9;
  }

  rep(i, K, N){
    ans[i] = other;
  }


  rep(i, N){
    cout << ans[i] << " ";
  }
  cout << endl;


  return 0;
}


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

ll gcd(ll x,ll y){return y ? gcd(y,x%y) : x; }//最大公約数

vector<pair<ll,int>>factorize(ll n){//素因数分解
  vector<pair<ll,int>>res;//答は関数と同じ型
  for (ll i=2;i*i<=n;i++){//エラトステネスの篩
    if(n%i)continue;//余りが出ればtrueなので何もしない
    res.emplace_back(i,0);//割り切れたら因数とする
    while(n%i==0){//割り切れる間、
      n/=i;//何度もiで割る
      res.back().second++;//割り切れる回数だけ、因数の次数を上げる
    }
  }
  if (n!=1) res.emplace_back(n,1);//素数なら素数の1乗
  return res;//答を返す
}

int main(){
  ll a,b;
  cin>>a>>b;
  ll g=gcd(a,b);//最大公約数の約数の個数+1が本問の答
  auto f=factorize(g);//最大公約数を因数分解し、因数の個数を調べる
  ll ans=f.size()+1;//約数の個数+1
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
<?php
$max = trim(fgets(STDIN));
for( $i=0; $i<$max; $i++ )
{
  $wordList[] = trim(fgets(STDIN));
}

$count = count( $wordList );
$unique = array_unique( $wordList );

if( $count != count($unique) ) 
{
  echo 'No';
  die;
}

$word = array_shift($wordList);
$word = str_split($word);
$before = $word[ count($word)-1 ];
foreach( $wordList as $word )
{
  $word = str_split($word);
  if( $before != $word[0] )
  {
    echo 'No';
    die;
  }

  $before = $word[ count($word)-1 ];
}

echo 'Yes';


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i=0; i<N; i++) {
        cin >> A[i];
    }
    
    bool flag = false;
    int cnt = 0;
    while (1) {
        for (int i=0; i<N; i++){
            if (A[i] % 2 != 0) {
                flag = true;
                break;
            } else {
                A[i] /= 2;
            }
        }
        if (flag) break;
        else cnt++;
    }
    
    cout << cnt << endl;
    
    
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

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

    vector<int> t(n);
    int sum = 0;
    for(int in=0;in<n;in++) {
        cin >> t.at(in);
        sum += t.at(in);
    }

    int m;
    cin >> m;
    vector<int> p(m);
    vector<int> x(m);
    for(int im=0;im<m;im++) {
        cin >> p.at(im) >> x.at(im);
        p.at(im)--;
    }
    for(int im=0;im<m;im++) {
        cout << sum - t.at(p.at(im)) + x.at(im) << endl;
    }
    return 0;
}


Measured memory_bytes: 3656
fun main(args: Array<String>) = abc155c()

fun abc155c() {
    val n = readLine()!!.toInt()
    val list = (1..n).map { readLine()!! }

    val map = list.groupBy { it }.map { it.key to it.value.size }
    val max = map.maxBy { it.second }!!.second

    val answer = StringBuilder()

    val sorted = map.filter { it.second == max }.map { it.first }.sorted().toTypedArray()
    for (it in sorted) {
        answer.appendln(it)
    }

    print(answer)
}


Measured memory_bytes: 114124
from collections import deque


N,M = map(int, input().split())



es = [[] for _ in range(3*N)]
for _ in range(M):
    u,v = map(int, input().split())
    u,v = u-1, v-1
    es[u].append(N + v)
    es[N + u].append(2*N + v)
    es[2*N + u].append(v)

S,T = map(int, input().split())

q = deque()
q.append(S-1)
INF = float("inf")
dist = [INF] * (3*N)
dist[S-1] = 0

while q:
    curr = q.popleft()
    
    for nxt in es[curr]:
        if dist[nxt] == INF:
            dist[nxt] = dist[curr] + 1
            if nxt == T-1:
                print(dist[nxt] // 3)
                
                exit()
            
            q.append(nxt)

print(-1)


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

using namespace std;

int main(){
  
  int K,X;
  cin>>K>>X;
  
  for(int i=1;i<K;i++){
    cout<<X-(K-i)<<" ";
  }
  
  cout<<X;
  
  for(int i=K-1;i>0;i--){
  cout<<" "<<X+(K-i);
  }
  
  return 0;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ld long double
#define int long long
using namespace std;
const int N = 1e5 + 10;
const int mod = 1e9 + 7;
const int inf = 1e17;
int Dx[] = {0, 1, -1, 0, -1, 1, 1, -1};
int Dy[] = {1, 0, 0, -1, -1, 1, -1, 1};
bool co(pair<string,int> &a, pair<string,int> &b){
	if(a.first == b.first){
		return a.second > b.second;
	}return a.first < b.first;
}
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	map<int,int> mp;
	vector<pair<string,int>> v(n);
	for(int i = 0; i < n; i++){
		cin >> v[i].first >> v[i].second;
		mp[v[i].second] = i + 1;
	}
	sort(v.begin(), v.end(), co);
	for(int i = 0; i < n; i++){
		cout << mp[v[i].second] << " ";
	}
}

Measured memory_bytes: 256
a,b,c,k=map(int,input().split())
ans=0
while k>0:
    if a>0 :
        new=min(k,a)
        k-=new
        ans+=new
        a-=new
        
    if b>0:
        new=min(k,b)
        k-=new
        b-=new
        
    if c>0:
        new=min(k,c)
        k-=new
        ans-=new
        c-=new
print(ans)

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

int main(void){
  string St;
  string es = "es";
  string s = "s";
  cin >> St;
  if (St.at(St.size()-1) == 's'){
    cout << St + es << endl;
  }else{
    cout << St + s << endl;
  }
  return 0;
}

Measured memory_bytes: 3628
n = int(input())
a = list(map(int, input().split()))
if n == 0 and a[0] == 0:
    print(-1)
    exit()
if n != 0 and a[0] >= 1:
    print(-1)
    exit()
if n == 0 and a[0] >= 2:
    print(-1)
    exit()
ar = list(reversed(a))
#print(ar)
com = [ar[0]]
for i in range(n):
    com.append(com[i] + ar[i+1])
#print(com)
com.reverse()
ans = 1
val = 1
for i in range(1,n+1):
    val *= 2
    ans += min(val,com[i])
    val -= a[i]
    if (i < n and val <= 0) or (i == n and val < 0):
        print(-1)
        exit()
print(ans)


Measured memory_bytes: 84904
#include<iostream>
#include<cstdio>
#include<algorithm>
#define ll long long
#define N 200010
using namespace std;
int n,m,cnt,ans,mo=1e9+7,x[N],y[N],c[N],mx[N],sum;
bool fl;
void add(int &a,int b){a+=b;if(a>=mo)a-=mo;}
struct bit
{
	int v[N];
	void clear()
	{
		for(int i=1;i<=n;i++)v[i]=0;
	}
	void mdf(int k,int vv)
	{
		for(;k<=n;k+=k&-k)add(v[k],vv);
	}
	int qy(int l,int r)
	{
		int s=0;
		l=min(l-1,n);r=min(r,n);
		for(;l;l-=l&-l)add(s,mo-v[l]);
		for(;r;r-=r&-r)add(s,v[r]);
		return s;
	}	
}bt,bc;
int pw(int i,int k)
{
	int a=1;
	while(k)
	{
		if(k&1)a=(ll)a*i%mo;
		i=(ll)i*i%mo;k>>=1;
	}
	return a;
}
int main()
{
	int i,s,a,b,j,k,ine2=pw(2,mo-2);
	scanf("%d",&n);sum=1;
	for(i=1;i<=n;i++)scanf("%d",&x[i]),c[x[i]]++;
	for(i=n;i;i--)
	{
		c[i-1]+=c[i];c[i]-=n-i;
		if(c[i]<1){fl=1;break;}
		sum=(ll)sum*c[i]%mo;
		y[i]=(ll)(c[i]-1)*pw(c[i],mo-2)%mo;
	}
	if(fl){printf("0");return 0;}
	for(i=n;i;i--)
	{
		if(!y[i+1])mx[i]=i;
		else mx[i]=mx[i+1];
	}
	for(i=2;i<=n;i++)
	if(y[i-1])y[i]=(ll)y[i-1]*y[i]%mo;
	
	for(i=1;i<=n;i++)if(!y[i])y[i]=1;
	for(i=n;i;i--)
	{
		k=bt.qy(x[i],mx[x[i]]);
		add(ans,(ll)k*pw(y[x[i]],mo-2)%mo*sum%mo*ine2%mo);
		bt.mdf(x[i],y[x[i]]);
	}
	bt.clear();
	for(i=1;i<=n;i++)
	{
		k=bt.qy(x[i]+1,mx[x[i]]);j=bc.qy(x[i]+1,n);
		add(ans,((ll)j*sum%mo+mo-(ll)k*pw(y[x[i]],mo-2)%mo*sum%mo*ine2%mo)%mo);
		bt.mdf(x[i],y[x[i]]);bc.mdf(x[i],1);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int H, W, d;

char c[4] = {'R', 'Y', 'G', 'B'};

int color(int x, int y) {
  int nx = x+y;
  int ny = x-y + 500 * d;
  int ans = 0;
  if ((nx/d)%2 == 0) {
    ans += 2;
  }
  if ((ny/d)%2 == 0) {
    ans += 1;
  }
  return ans;
}

int main () {
  cin >> H >> W >> d;
  int ans[510][510];
  for (auto i = 0; i < H; ++i) {
    for (auto j = 0; j < W; ++j) {
      ans[i][j] = color(i, j);
    }
  }
  for (auto i = 0; i < H; ++i) {
    for (auto j = 0; j < W; ++j) {
      cout << c[ans[i][j]];
      if (j == W-1) {
        cout << endl;
      }
    }
  }
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

int main(){
    i64 h,count=1,ans=0;
    cin>>h;
    while(h!=0){
        h/=2;
        ans+=count;
        count*=2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define dd double
#define f0(i, n) for(int i = 0; i < n; i++)
#define fab(i,a,b) for(int i=a;i<b;i++)
#define f1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second





int main() {


	ios_base::sync_with_stdio(false);
	cin.tie(NULL);



//ios_base& scientific (ios_base& str);
	ll h, w;
	cin >> h >> w;

	ll dp[h + 1][w + 1];
	char a[h + 1][w + 1];

	for (ll i = 1; i <= h; i++) {

		for (ll j = 1; j <= w; j++) {

			cin >> a[i][j];
		}
	}

	for (int i = 1; i <= h; i++) {

		for (int j = 1; j <= w; j++) {

			if (i == 1 and j == 1) {
				dp[i][j] = 1;
			}
			else if (a[i][j] == '#') {
				dp[i][j] = 0;
			}
			else if (i == 1) {
				dp[i][j] = dp[i][j - 1];
			}
			else if (j == 1) {
				dp[i][j] = dp[i - 1][j];
			}
			else {

				dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
			}
		}
	}

	cout << dp[h][w] << endl;




	return 0;
}

Measured memory_bytes: 9088
//




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


#define spdio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pp pop_back()
#define pf push_front
#define ppf pop_front()
#define ff first
#define ss second
#define mp make_pair
#define fr(i,j,n) for(ll i=j; i<n; i++)
#define rfr(i,j,n) for(ll i=n-1; i>=j; i--)
#define pll pair<ll,ll>
#define plb pair<ll,bool>
#define psl pair<string,ll>
#define psb pair<string,bool>
#define srt(v) sort((v).begin(),(v).end())
#define ub(v,val) upper_bound((v).begin(),(v).end(),(val))-(v).begin()
#define lb(v,val) lower_bound((v).begin(),(v).end(),(val))-(v).begin()


typedef long double ld;
typedef long long int ll;


//getline(cin,string);
const ll inf = (ll) 1e18 + 19;
const ll mod = (ll) 1e9  +  7;




ll ncr(ll n,ll r) {
    ll val=1,i,j,p=2;
    rfr(i,n-r+1,n+1) {
        val*=i;
        while(val%p==0 && p<=r) {
            val/=p;
            p+=1;
        }
    }
    if(p<r) {
        fr(i,p,r+1) val/=i;
    }
    return val;
}



ll fun(ll n,ll i,ll j,ll a[][3],vector <vector <ll> > &dp) {
    if(i>=n) return 0;
    if(dp[i][j]!=-1) return dp[i][j];
    ll k,val=-inf;
    fr(k,0,3) {
        if(k==j) continue;
        val=max(val,a[i][j]+fun(n,i+1,k,a,dp));
    }
    return dp[i][j]=val;
}




void cazz() {
    ll t=1,i=0,j,n;
    //cin>>t;
    while(t--) {
        cin>>n;
        ll a[n][3];
        fr(i,0,n) {
            fr(j,0,3) cin>>a[i][j];
        }
        vector <vector <ll> > dp(n+1,vector <ll> (3,-1));
        fun(n,0,0,a,dp);
        fun(n,0,1,a,dp);
        fun(n,0,2,a,dp);
        cout<<max(dp[0][1],max(dp[0][2],dp[0][0]))<<"\n";
    }
}




int main() {
    spdio;
	cazz();
	return 0;
}


Measured memory_bytes: 20372
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
    int sum,f=0;
    cin>>sum;
    if(sum%4==0)
    {
        cout<<"Yes"<<endl;
        f=1;
    }
    else
    {
        int k=sum/4,i=0,num;
        while(i<=k)
        {
            num=i*4;
            int t=sum-num;
            if(t%7==0)
            {
                cout<<"Yes"<<endl;
                f=1;
                break;
            }
            else
            {
                num=0;
            }
            i++;
        }
    }
    if(f==0)
        cout<<"No"<<endl;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.bigint, std.typecons, std.algorithm, std.array, std.math, std.range, std.functional;
 
void main() {
    auto S = sort(readln.chomp.map!(c => cast(int)(c - 'a')).array).uniq;
    auto res = iota('z' - 'a' + 1).filter!(c => !S.canFind(c));
    writeln(res.empty ? "None" : (cast(char)(res.front + 'a')).to!string);
}

Measured memory_bytes: 2712
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <vector>
#include <queue>
using namespace std;
//________
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define err(...) fprintf(stderr, __VA_ARGS__ )
#define show(x) cerr << #x << ':' << (x) << endl
#define outl(x) cout << (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
inline bool inside(int y, int x, int H, int W){return(y>=0 && x>=0 && y<H && x<W);}
const int dx[] = {1, 0, -1, 0,  1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1,  -1, 1, 1, -1};
#define Size 1000111
#define INF  0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define NIL -1
//________


signed main()
{
   FAST();
   int N, H;
   int a;
   int b[100005];

   int maxv = -1;

   cin >> N >> H;
   rep(i, N){
      cin >> a >> b[i];
      chmax(maxv, a);
   }
   sort(b, b+N, greater<int>());

   int cnt = 0;
   for(int i=0; i<N && b[i] > maxv && H>0; ++i){
      ++cnt;
      H -= b[i];
   }
   if(H > 0){
      cnt += (H + maxv -1) / maxv;
   }
   outl(cnt);
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう
//a=0x61=97 '0'=0x30=48
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
typedef long double  ld;
typedef string str;
typedef pair<int,int> pairii;
typedef vector<int> veci;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
int main() {
  int n;cin>>n;
  if(n<30)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main() {
    map<string, int> m;
    int q; cin >> q;
    while (q--) {
        int com; cin >> com;
        if (com == 0) {
            string key; int x;
            cin >> key >> x;
            m[key] = x;
        } else if (com == 1) {
            string key; cin >> key;
            cout << m[key] << endl;
        } else if (com == 2) {
            string key; cin >> key;
            m.erase(key);
        }
    }
    return 0;
}


Measured memory_bytes: 27816
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn = 110;
char a[maxn][maxn];
int vis[maxn][maxn], m , n,d[4][2] = {{0 , 1},{0 , -1},{1 , 0} ,{-1 ,0}};
void _fill(int x , int y){
    for(int i = 0 ; i < 4;i++){
        int xx = x + d[i][0];
        int yy = y + d[i][1];
        if(xx >= 0 && xx < n && yy >= 0 && yy < m){
            if(!vis[xx][yy]&&a[xx][yy] == a[x][y]){
                vis[xx][yy] = 1;
                _fill(xx , yy);
            }
        }
    }
}
void solve(){
    int res = 0;
    memset(vis,0,sizeof(vis));
    for(int i = 0 ; i < n;i++){
        for(int j = 0 ; j < m;j++){
            if(!vis[i][j]){
                res++;
                vis[i][j] = 1;
                _fill(i , j);
            }
        }
    }
    printf("%d\n",res);
}
int main()
{
    while(~scanf("%d%d",&n,&m)){
        if(n == 0 && m == 0) {break;}
        for(int i = 0 ; i < n;i++){scanf("%s",a[i]);}
        solve();
    }
}

Measured memory_bytes: 1560
INF = 10 ** 9
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  copy import deepcopy
from bisect import bisect_left

class SegmentTree():

    def __init__(self,init_val,func,unit): #init_valは長さnの配列 O(2*n)
        n = len(init_val)
        self.unit = unit #unitは単位元
        self.size = pow(2,n - 1).bit_length() #n以上の最小の2のべき乗
        self.seg = [self.unit] * (2 * self.size) #セグメントツリー本体
        self.f = func #セグ木により異なる関数
        
        for i in range(n):
            self.seg[i + self.size - 1] = init_val[i] 
        
        for i in range(self.size - 2,-1,-1):
            self.seg[i] = self.f(self.seg[2 * i + 1],self.seg[2 * i + 2])
    
    def update(self,k,x): #k番目の要素をxに変更する O(logN)
        k += self.size - 1
        self.seg[k] = x
        while k:
            k = (k - 1)//2
            self.seg[k] = self.f(self.seg[2 * k + 1],self.seg[2 * k + 2])
    
    def query(self,p,q): #[p,q)のクエリに答える　半開区間であることに注意 O(logN)
        if q <= p:
            return self.unit

        p += self.size - 1 
        q += self.size - 2
        res = self.unit

        while q - p > 1:

            if (p&1) == 0:
                res = self.f(res,self.seg[p])

            if (q&1) == 1:
                res = self.f(res,self.seg[q])
                q -= 1

            p //= 2
            q = (q - 1)//2
        
        if p == q:
            res = self.f(res,self.seg[p])
        else:
            res = self.f(self.f(res,self.seg[p]),self.seg[q])
        
        return res


def main():
    n = int(input())
    H = list(map(int,input().split()))
    A = list(map(int,input().split()))
    
    dp = SegmentTree([0] * (n + 1),max,0)
    ans = 0
    for i in range(n):
        before_beaty = dp.query(0,H[i])
        if dp.query(H[i],H[i] + 1) < A[i] + before_beaty:
            dp.update(H[i],before_beaty + A[i])
            ans = max(ans,before_beaty + A[i])
    
    print(ans)
if __name__ == '__main__':
    main() 

Measured memory_bytes: 123084