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

vector<int> adj[200005];
bool vis[200005];
int cnt=0;

void dfs(int src,int par)
{
    vis[src]=true;
    for(auto x: adj[src])
    {
        if(vis[x]==false){
            cnt++;
            vis[x]=true;
            dfs(x,src);
        }
    }
}

int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0; i<m; i++)
    {
        int a,b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    int ans=0;
    for(int i=1; i<=n; i++)
    {
        if(vis[i]==false){
            cnt=1;
            dfs(i,i);
            ans = max(ans,cnt);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 24056
#include <stdio.h>

int main(void){
    int c1,c2,c3,i;
    int n =0;
    
    while (scanf("%d %d %d", &c1, &c2, &c3) != EOF) {
        for(i=1; i<=10; i++){
          if(i!=c1 && i!=c2 && i!=c3 && c1+c2+i<=20)
              n++;
        }
        if (n >= 4) {
            printf("YES\n");
        }
        
        else {
            printf("NO\n");
        }
            n = 0;
        
        
    }
    
    return 0;
}

Measured memory_bytes: 580
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define LLIandI pair<long long int , int>
#define ll long long

int main(){
    while(1){
    int W,H;
    scanf("%d %d\n",&W,&H);
    if(W==0)break;
    int c[100][100];//W,H<=50
    bool f[100][100];
    rep(i,H){
        rep(j,W){
            scanf("%d",&c[i][j]);
            f[i][j]=false;
        }
    }
    queue< pair<int,int> > q;
    int count=0;
    rep(i,H)rep(j,W){
        if(f[i][j])continue;
        if(c[i][j]==0)continue;
        count++;
        //printf("x=%d y=%d",i,j);
        q.push( mp(i,j) );
        while(!q.empty()){
            pair<int,int> p=q.front();
            q.pop();
            int py=p.first;int px=p.second;
            if(f[py][px])continue;
            if(c[py][px]==0)continue;
            f[py][px]=true;
            if(py>0)q.push( mp(py-1,px) );
            if(py<H-1)q.push( mp(py+1,px) );
            if(px>0)q.push( mp(py,px-1) );
            if(px<W-1)q.push( mp(py,px+1) );
            if(py>0&&px>0)q.push( mp(py-1,px-1));
            if(py>0&&px<W-1)q.push( mp(py-1,px+1));
            if(py<H-1&&px>0)q.push( mp(py+1,px-1));
            if(py<H-1&&px<W-1)q.push( mp(py+1,px+1));

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


Measured memory_bytes: 2852
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>

using namespace std;

bool compare(const pair<string, int>&i, const pair<string, int>&j)
{
    return i.second > j.second;
}
bool compare1(const pair<string, int>&i, const pair<string, int>&j)
{
    return i.first < j.first;
}


int n;
string s[105];
int p[105];
vector<pair<string, int> >V;
map<int, int>M;

char in[105];
pair<pair<string,int>,int> pd[110];

int main(){
  cin >> n;
  
  for(int i = 0; i < n; ++i){
    int t;
    cin >> in >> t;
    string tmp = in;
    //V.push_back(make_pair(s[i], p[i]));
    pd[i]=make_pair(make_pair(in, -t),i);
    //M[p[i]] = i;
    
  }
  //sort(V.begin(), V.end(), compare);
  //sort(V.begin(), V.end(), compare1);
  sort(pd, pd + n);
  
  for(int i = 0; i < n; ++i){
    cout << pd[i].second + 1 << endl;
  }
}

Measured memory_bytes: 256
import sys


def alg_combination_mod(n, r, mod):
    r = min(n - r, r)
    if r == 0:
        return 1
    else:
        denominator = 1
        for i in range(n, n - r, -1):
            denominator = (denominator * i) % mod
        molecule = 1
        for i in range(1, r + 1):
            molecule = (molecule * i) % mod
        return denominator * pow(molecule, mod - 2, mod) % mod


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, a, b = list(map(int, input().rstrip('\n').split()))
    all_cnt = pow(2, n, mod) + mod
    a_cnt = alg_combination_mod(n, a, mod)
    b_cnt = alg_combination_mod(n, b, mod)
    print((all_cnt - a_cnt - b_cnt - 1) % mod)


if __name__ == '__main__':
    solve()


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

int main() {
	double n;
   cin>>n;
  int kisuu;
  rep(i,n){
  	if(i%2==1){
    	kisuu++;
    }
    
    
  }
  double kotae=kisuu/n;
  cout<<kotae<<endl;
}

Measured memory_bytes: 256
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty |) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty | $n:expr) => {
        (0..$n).map(|_| get!($t |)).collect::<Vec<_>>()
    };
}

fn main() {
    let N = get!(usize);
    let As = get!(i64; N);
    let mut A_with_i = As.iter().enumerate().collect::<Vec<_>>();
    A_with_i.sort_by_key(|&(_, &A)| -A);
    for i in 0..N {
        if i == A_with_i[0].0 {
            println!("{}", A_with_i[1].1);
        } else {
            println!("{}", A_with_i[0].1);
        }
    }
}


Measured memory_bytes: 13820
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt();
    cout<<(n*(n+1))/2<<endl;
    
    return 0;   
}


 
 


Measured memory_bytes: 256
// In the name of God

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2*(int)1e5+5;
int a[N], b[N], n;
priority_queue<pair<int,int>> pq;
signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	for(int i=0;i<n;i++) cin >> a[i];
	for(int i=0;i<n;i++) cin >> b[i];
	for(int i=0;i<n;i++) pq.push(make_pair(b[i], i));
	int ans = 0;
	int last = -1;
	while(!pq.empty()) {
		auto tp = pq.top();
		pq.pop();
		if(tp.second==last) {
			cout << -1;
			exit(0);
		}
		int l = tp.second==0?b[n-1]:b[tp.second-1];
		int r = tp.second==n-1?b[0]:b[tp.second+1];
		ans += (tp.first)/(l+r);
		b[tp.second]%=(l+r);
		while(b[tp.second]<a[tp.second]) {
			b[tp.second]+=l+r;
			ans--;
		}
		if(b[tp.second]!=a[tp.second]) pq.push(make_pair(b[tp.second], tp.second));
		last=tp.second;
	}
	cout << ans;
	return 0;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    int l, r;
    int maxL = 0;
    int minR = 100000;
    for (int i = 0; i < m; i++)
    {
        cin >> l >> r;
        maxL = max(maxL, l);
        minR = min(minR, r);
    }

    int ans = min(minR, n) - max(1, maxL) + 1;
    ans = max(ans, 0);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
#include <stdio.h>
using namespace std;
int N, A[50];
int solve(int i, int m) {
	if (m == 0) return 1;
	if (i >= N) return 0;
	int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
	return res;
}
int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}
	int Q;
	scanf("%d", &Q);
	int M;
	for (int i = 0; i < Q; i++) {
		scanf("%d", &M);
		if (solve(0, M)) cout << "yes" << endl;
		else cout << "no" << endl;
	}

}



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

using namespace std;
#define int long long
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int h, w, m;
    cin >> h >> w >> m;
    int row[h+1] = {0}, col[w+1] = {0};
    int i, j;
    vector<int> vec[h+1];
    for(i=1;i<=m;i++)
    {
        int x, y;
        cin >> x >> y;
        row[x]++, col[y]++;
        vec[x].push_back(y);
    }
    vector<pair<int, int>> r, c;
    for(i=1;i<=h;i++)
        r.push_back({row[i], i});
    for(i=1;i<=w;i++)
        c.push_back({col[i], i});
    sort(r.begin(), r.end());
    sort(c.begin(), c.end());
    vector<int> nr, nc;
    int idr = r.size()-1;
    int valr = r.back().first;
    while(idr >= 0 && r[idr].first == r.back().first)
        nr.push_back(r[idr].second), idr--;
    int valc = c.back().first;
    int idc = c.size()-1;
    while(idc >= 0 && c[idc].first == c.back().first)
        nc.push_back(c[idc].second), idc--;
    int sum = valr + valc;
    sort(nr.begin(), nr.end());
    sort(nc.begin(), nc.end());
    int ok = 1;
    vector<int> nvec[h+1];
    for(auto j : nr)
    {
        for(auto ele : vec[j])
            if(binary_search(nc.begin(), nc.end(), ele))
                nvec[j].push_back(ele);
        if(nvec[j].size() != nc.size())
            ok = 0;
    }
    
    sum-=ok;
    cout << sum;
}

Measured memory_bytes: 54692
def main
  digit, restriction_num = gets.chomp.split(' ').map(&:to_i)
  candidate_answer = Array.new(digit, nil) 
  
  restriction_num.times do |_i|
    idx, num = gets.chomp.split(' ').map(&:to_i)
    if candidate_answer[idx-1] && candidate_answer[idx-1] != num
      raise 'Restric Error'
    else
      candidate_answer[idx-1] = num
    end
  end

  candidate_answer.fill do |i|
    if i.zero? && candidate_answer[i].nil? && digit != 1
      1
    else
      candidate_answer[i].to_i 
    end
  end

  raise 'Head is zero Error' if candidate_answer[0].zero? && digit != 1
    
  puts candidate_answer.join('').to_i
  
  rescue 
    puts '-1'
end

main

Measured memory_bytes: 1788
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	ll ans = n*(n-1)/2;
	cout << ans << endl;
    return 0;
}

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

int main(){
	string s;
	cin >> s;
	int l = -1, r = -1;
	for(int i = 0; i < s.size(); i++)
		if(s[i] == 'A'){
			l = i;
			break;
		}
	for(int i = s.size()-1; i >= 0; i--)
		if(s[i] == 'Z'){
			r = i;
			break;
		}
	if(l == -1 || r == -1 || r < l)
		cout << 0 << endl;
	else
		cout << r - l + 1 << endl;
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{
    int l, r, d, wa, i;
    scanf("%d %d %d",&l ,&r ,&d);
    wa = 0;
    while (l <= r)
    {
        if (l % d == 0)
        {
            wa = wa + 1;
        }
        l++;
    }
    
    // for ( i = l; i < (r + 1); i++)
    // {
    //     if (i % d == 0)
    //     {
    //         wa = wa + 1;
    //     }
        
    // }
    printf("%d", wa);
    return 0;
}

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

void Mheap(int *,int);

int H;

int main(){
  int i,*A;

  scanf("%d",&H);
  A=(int *)malloc(sizeof(int)*(H+1));

  for(i=1;i<=H;i++) scanf("%d",&A[i]);

  for(i=H/2;i>=1;i--) Mheap(A,i);

  for(i=1;i<=H;i++) printf(" %d",A[i]);
  printf("\n");

  return 0;
}

void Mheap(int *A,int i){
  int l,r,largest,swap;

  l = i*2;
  r = i*2+1;

  if(l <= H && A[l] > A[i]) largest = l;
  else largest=i;
  if(r <= H && A[r]>A[largest]) largest = r;

  if(largest != i){
    swap=A[largest];
    A[largest]=A[i];
    A[i]=swap;

    Mheap(A,largest);
  }
}


    
  



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

unsigned long long to(string w , int base){
	unsigned long long ans = 0;
	for(int i = 0 ; i < w.size() ; i++) ans = ans * base + (w[i] >= 'A' ? w[i] - 'A' + 10 : w[i] - '0');
	return ans;
}

map<int,int> factor(int n){
	map<int,int> w;
	for(int i = 2 ; i*i<=n ; i++)
		while(n%i==0) w[i]++ , n /= i;
	if(n!=1) w[n]++;
	return w;
}
int main(){
	int n;
	string m;
	while(cin >> n >> m && n){
		unsigned long long v = to(m,n) , ans = ULLONG_MAX;
		map<int,int> r = factor(n);
		for( map<int,int>::iterator it = r.begin() ; it != r.end() ; ++it){
			int a = it->first;
			int d = it->second;
			unsigned long long t = v;
			unsigned long long ok = 0;
			while(t){ ok += (t / a) ; t /= a;}
			ans = min(ok / d , ans);
		}
		cout << ans << endl;
	}
}

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



int main(){
    ll n;
    cin >> n;
    ll a[n],b[n];
    P c[n];
    for(ll i=0;i<n;i++){
        cin >> a[i] >> b[i];
        c[i].first=a[i]+b[i];
        c[i].second=i;
    }
    sort(c,c+n,greater<P>());
    ll res=0;
    for(ll i=0;i<n;i++){
        if(i%2==0){
            res+=a[c[i].second];
        }
        else if(i%2==1){
            res-=b[c[i].second];
        }
    }
    cout << res << endl;
    return 0;
}  


Measured memory_bytes: 6696
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

struct node{
	int proh;
	int to[4];
	int fail;
	node(){
		proh = 0;
		memset(to, -1, sizeof to);
		fail = 0;
	}
};

int w, h;
char field[52][52];
vector<node> ac;

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

void addptn(const char *ptn){
	int x = 1, f = 0;
	for(; *ptn; ++ptn){
		int d = 0;
		switch(*ptn){
		case 'L':
			d = 0;
			break;
		case 'U':
			d = 1;
			break;
		case 'R':
			d = 2;
			break;
		case 'D':
			d = 3;
			break;
		}

		int y = ac[x].to[d];
		if(y == -1){
			y = ac.size();
			ac[x].to[d] = y;
			ac.push_back(node());
		}
		x = y;
	}
	ac[x].proh = 1;
}

int getproh(int p){
	if(!ac[p].proh){
		ac[p].proh = getproh(ac[p].fail);
	}
	return ac[p].proh;
}

int solve(){
	memset(field, '#', sizeof field);

	ac.assign(2, node());
	fill(ac[0].to, ac[0].to + 4, 1);
	ac[0].proh = -1;

	for(int i = 1; i <= h; ++i){
		scanf("%s", field[i] + 1);
		field[i][w + 1] = '#';
	}

	int n;
	char ptn[16];
	scanf("%d", &n);
	for(int i = 0; i < n; ++i){
		scanf("%s", ptn);
		addptn(ptn);
	}

	queue<int> q;
	q.push(1);
	while(!q.empty()){
		int p = q.front();
		q.pop();
		
		for(int i = 0; i < 4; ++i){
			int t = ac[p].to[i];
			if(t != -1){
				q.push(t);
				
				int f = ac[p].fail;
				while(ac[f].to[i] == -1){
					f = ac[f].fail;
				}
				ac[t].fail = ac[f].to[i];
			}
		}
	}

	const int yofs = 52;
	const int pofs = yofs * yofs;

	int sy, sx;
	for(int y = 1; y <= h; ++y)
	for(int x = 1; x <= w; ++x){
		if(field[y][x] == 'S'){
			sy = y;
			sx = x;
		}
	}

	vector<char> vis(pofs * ac.size());
	q.push(sy * yofs + sx + pofs);
	vis[q.front()] = 1;
	q.push(-1);
	int ret = 1;
	while(q.size() > 1){
		int st = q.front();
		q.pop();
		if(st == -1){
			q.push(-1);
			++ret;
			continue;
		}

		int y = st % pofs / yofs;
		int x = st % yofs;
		int p = st / pofs;

		for(int i = 0; i < 4; ++i){
			int ny = y + dy[i], nx = x + dx[i];
			if(field[ny][nx] == '#'){ continue; }
			int np = p;
			while(ac[np].to[i] == -1){
				np = ac[np].fail;
			}
			np = ac[np].to[i];
			if(getproh(np) == 1){
				continue;
			}
			int nst = np * pofs + ny * yofs + nx;
			if(vis[nst]){ continue; }
			vis[nst] = 1;
			if(field[ny][nx] == 'G'){
				return ret;
			}
			q.push(nst);
		}
	}
	return -1;
}

int main(){
	while(scanf("%d%d", &h, &w), h){
		printf("%d\n", solve());
	}
}

Measured memory_bytes: 1268
#include <bits/stdc++.h> 
 
#define INF (1<<31)//INT_MAX/2
#define MOD 1000000007
 
using ll  = long long;
using ull = unsigned long long;
 
int main(int argc, char *argv[])
{
    std::string S;
    std::cin >> S;

    std::string str;

    for (int i = 0; i < S.size(); i++) {
        if (i % 2 == 0) {
            str.push_back(S[i]); 
        }
    }

    std::cout << str << std::endl;
    return 0;
}

Measured memory_bytes: 512
#include <string>
#include <iostream>

using namespace std;
int main() {
    // freopen("in.txt","r",stdin);
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int sum = 0;
    if(k>=a) {
        sum += a;
        k-=a;
        if(k>=b) {
            k-=b;
            if(k>=0) {
                sum -= k;
            }
        }
    } else {
        sum += k;
    }
    cout << sum << endl;

}

Measured memory_bytes: 3188
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


class UnionFind:
    def __init__(self, node: int) -> None:
        self.n = node
        self.par = [i for i in range(self.n)]
        self.rank = [0 for i in range(self.n)]
        self.elms = [1 for i in range(self.n)]

    def find(self, x: int) -> int:
        if x == self.par[x]:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x: int, y: int) -> bool:
        if self.isSame(x, y):
            # print("x and y has already united")
            return False

        rx = self.find(x)
        ry = self.find(y)

        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = self.par[ry]
            self.elms[ry] += self.elms[rx]
        else:
            self.par[ry] = self.par[rx]
            self.elms[rx] += self.elms[ry]

            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

        return True

    def isSame(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)

n, m = li()
uf = UnionFind(n)

ans = [n*(n-1)//2]
ab = []

for _ in range(m):
    ab.append(list(li_()))

for a, b in ab[::-1]:
    if uf.isSame(a, b):
        ans.append(ans[-1])

    else:
        ans.append(ans[-1] - uf.elms[uf.par[a]]*uf.elms[uf.par[b]])
        uf.unite(a, b)
        uf.find(a)
        uf.find(b)

for ansi in ans[-2::-1]:
    print(ansi)

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

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

  string s;
  cin >> s;

  int now, goal;

  now = b-1;
  goal = d-1;
  while(now < goal) {
    if(s[now-1] == '.' && s[now+1] == '.') break;
    if(s[now+1] == '.') now++;
    else if(s[now+1] == '#') {
      if(s[now+2] == '.') now += 2;
      else {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  int b_b = now;
  if(c < d) {
    // now = b-1;
    // goal = d-1;
  }else{
    s[b_b] = '#';
    now = a-1;
    goal = c-1;
  }
  while(now < goal) {
    if(s[now+1] == '.') now++;
    else if(s[now+1] == '#') {
      if(s[now+2] == '.') now += 2;
      else {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  // cout << now << goal << endl;
  s[goal] = '#';

  if(c > d) {
    now = b_b;
    goal = d-1;
    // cout << 'a' << endl;
  }else {
    now = a-1;
    goal = c-1;
    // cout << 'b' << endl;
  }
  while(now < goal) {
    // cout << "now1: " << now+1 << endl;
    if(s[now+1] == '.') now++;
    else if(s[now+1] == '#') {
      if(s[now+2] == '.') now += 2;
      else {
        cout << "No" << endl;
        return 0;
      }
    }
    // cout << "now2: " << now+1 << endl;
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<l_l> vpl;
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=1;i<=(n);i++)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
template<class T> inline bool chmin(T& a,T b){
if(a>b){
a=b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a,T b){
if(a<b){
a=b;
return true;
}
return false;
}
int main(){
    cout<<fixed;
    cout<<setprecision(10);
    ll x;cin>>x;
    ll a=100;
    ll ans=0;
    while(a<x){
        a=a+a/100;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<ld> vld;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i)
#define TS to_string
#define ALL(v) (v).begin(), (v).end()
#define endl "\n"

ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------

//-----------------------------------------
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n;
  cin >> n;
  vector<ll> vec(n);
  REP(i,n) vec[i] = i+1;

  do{
    REP(i,n){
      if(i) cout << " ";
      cout << vec[i];
    }
    cout << endl;
  }while(next_permutation(ALL(vec)));

  return 0;
}




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

int main() {
  ll n;cin >> n;
  map<ll,ll> m;
  rep(i,n){
    ll num;cin >> num;
    ++m[num];
    if( i == 0 && num != 0 ){
      cout << 0 << endl;
      return 0;
    }
  }

  ll ans = 1;
  for( auto p : m ){

    if( p.first == 0 && p.second != 1 ){
      cout << 0 << endl;
      return 0;
    }

    if( p.first == 0 ) continue;
    if( m[p.first-1] == 0 ){
      cout << 0 << endl;
      return 0;
    }
    
    rep(i,p.second){
      ans *= m[p.first-1];
      ans %= dv;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9740
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node
{
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

Node* find(Node *u, int k) {
	while (u != NIL && k != u->key) {
		if (k < u->key) u = u->left;
		else u = u->right;
	}
	return u;
}

void insert(int k) {
	Node *y = NIL;
	Node *x = root;
	Node *z;

	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while (x != NIL) {
		y = x;
		if (z->key < x->key) {
			x = x->left;
		}
		else
		{
			x = x->right;
		}
	}

	z->parent = y;
	if (y == NIL) {
		root = z;
	}
	else {
		if (z->key < y->key) {
			y->left = z;
		}
		else {
			y->right = z;
		}
	}
}

void inorder(Node *u) {
	if (u == NIL) return;
	inorder(u->left);
	printf(" %d", u->key);
	inorder(u->right);
}

void preorder(Node *u) {
	if (u == NIL) return;
	printf(" %d", u->key);
	preorder(u->left);
	preorder(u->right);
}

int main() {
	int n, i, x;
	string com;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		cin >> com;
		if (com == "insert") {
			scanf("%d", &x);
			insert(x);
		}
		else if (com == "find")
		{
			scanf("%d", &x);
			Node *t = find(root, x);
			if (t != NIL)printf("yes\n");
			else printf("no\n");
		}
		else if (com == "print") {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}
	return 0;
}


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

constexpr int kMod = 998244353;

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

  int n, s;
  cin >> n >> s;
  vector<int> a(n);
  for (int& e: a)
    cin >> e;

  vector<vector<int>> f(n + 1, vector<int>(s + 1));
  f[0][0] = 1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= s; ++j) {
      if (!f[i][j]) continue;
      f[i + 1][j] = (f[i + 1][j] + 2LL * f[i][j]) % kMod;
      if (j + a[i] <= s) f[i + 1][j + a[i]] = (f[i + 1][j + a[i]] + f[i][j]) % kMod;
    }
  }

  cout << f[n][s] << '\n';
}

Measured memory_bytes: 38528
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define endl "\n"
#define MAXN 10000001
#define pb push_back
#define mod 1000000007
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int dx8[]={1,-1,0,0,1,1,-1,-1};
int dy8[]={0,0,1,-1,1,-1,1,-1};
int spf[MAXN];

ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinvfermat(ll a, ll m)
{
	return binexp(a, m - 2, m);
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}
ll n,m;
ll c;

vector<ll> v[200001];
ll vis[200001];
void dfs(ll node){
	vis[node]=1;
	c++;

	
	for(auto i:v[node]){
		if(vis[i]==0){
			

			dfs(i);

		}
	}
}
void sieve()
{
	int i,j;
	for(i=0;i<MAXN;i++)
	spf[i]=i;
	for(i=4;i<MAXN;i+=2)
	spf[i]=2;
	for(i=3;i*i<MAXN;i++)
	{
		if(spf[i]==i)
		{
			for(j=i*i;j<MAXN;j+=i)
			{
				if(spf[j]==j)spf[j]=i;
			}
		}
	}
}

void solve(){
	ll n;
	cin>>n;
	vector<ll> v(n),a(n);
	for(ll i=0;i<n;i++){
		cin>>v[i];
		a[i]=v[i];


	}
	bool check=true;

	unordered_map<ll,ll> m;
	for(ll i=0;i<n;i++){
		for(ll j=2;j*j<=v[i];j++){
			if(a[i]%j==0){

				if(m[j]!=0){
					check=false;
					break;

				}
				while(a[i]%j==0){
					m[j]++;
					a[i]=a[i]/j;

				}



			}
		}
		if(a[i]>1){
			if(m[a[i]]!=0){
				check=false;

			}
			else{
				m[a[i]]++;

			}
		}

		if(check==false)break;

	}
	ll g=__gcd(v[0],v[1]);
	for(ll i=2;i<n;i++){
		g=__gcd(g,v[i]);

	}
	if(check){
		cout<<"pairwise coprime"<<endl;

	}
	else{
		if(g==1){
			cout<<"setwise coprime"<<endl;

		}
		else
			cout<<"not coprime"<<endl;

	}









return;
}




int main()
{  
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
    fast;
    ll t;
    t=1;
  // cin>>t;
    while(t--){
    	solve();
    }
    
   
  



#ifndef ONLINE_JUDGE
	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
return 0;
}

Measured memory_bytes: 23508
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <limits>
#include <utility>
#include <algorithm>

typedef long long ll;

ll solve(ll x, const ll k)
{
    ll min = x;

    if (x / k >= 1) {
        x %= k;
        min = x;
    }

    while(1) {
        if (x / k >= 1) {
            x %= k;
        } else {
            x = llabs(x - k);
        }
        if (min == x) {break;} //ループした
        if (x < min) {min = x;}
    }

    return min;
}

int main(int argc, char *argv[])
{
    ll n, k;

    std::cin >> n >> k;

    ll ans = solve(n, k);

    std::cout << ans << std::endl;

    return 0;
}


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

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

    rep(i,n){
        if(s.at(i-1)==s.at(i))ans--;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int N = 8e5 + 9, INF = 0x3f3f3f3f;

#define L (x<<1)
#define R (x<<1|1)
int mi[N][2], p[N], n, pp[N];
bool vis[N];

void update(int x) {
	mi[x][0] = p[mi[L][0]] < p[mi[R][0]] ? mi[L][0] : mi[R][0];
	mi[x][1] = p[mi[L][1]] < p[mi[R][1]] ? mi[L][1] : mi[R][1];
}

void Build (int x, int l, int r) {
	if (l == r) {
		if (l & 1) mi[x][1] = l, mi[x][0] = 0;
		else mi[x][0] = l, mi[x][1] = 0;
		return ;
	}
	int mid = (l + r) >> 1;
	Build(L, l, mid);
	Build(R, mid + 1, r);
	update(x);
}

int Query (int x, int l, int r, int ql, int qr, bool o) {
	if (ql > qr || ql > n) return INF;
	if (l == ql && r == qr) return mi[x][o];
	int mid = (l + r) >> 1;
	if (qr <= mid) return Query (L, l, mid, ql, qr, o);
	if (ql > mid) return Query (R, mid + 1, r, ql, qr, o);
	int al = Query(L, l, mid, ql, mid, o), ar = Query(R, mid + 1, r, mid + 1, qr, o);
	return p[al] < p[ar] ? al : ar;
}

struct it {
	int l, r, al, ar;
	it (int l, int r) : l(l), r(r) {
		al = Query(1, 1, n, l, r, l & 1), ar = Query(1, 1, n, al + 1, r, (l & 1) ^ 1);
	}
	bool operator < (const it &rhs) const { return p[al] > p[rhs.al]; }
};

priority_queue<it>Q;

int main () {
	scanf("%d", &n);
	p[0] = INF;
	for (int i = 1; i <= n; ++i) scanf("%d", &p[i]), pp[p[i]] = i;
	Build(1, 1, n);
	Q.push(it(1, n));
	int l, r, al, ar;
	while (!Q.empty()) {
		l = Q.top().l; r = Q.top().r; al = Q.top().al; ar = Q.top().ar; Q.pop();
		printf("%d %d ", p[al], p[ar]);
		if (l < al) Q.push(it(l, al - 1));
		if (ar < r) Q.push(it(ar + 1, r));
		if (al + 1 < ar) Q.push(it(al + 1, ar - 1));
	}
	return 0;
}

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

typedef long long ll;
const int mod = 1e9 + 7;

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

    string S;
    cin >> S;

    vector<int> nums;
    int now = 1;
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == (char)('0' + now)) cnt++;
        else {
            nums.push_back(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    nums.push_back(cnt);

    // if (nums.size() % 2 == 0) nums.push_back(0);

    // rep(i, nums.size()) {
    //     cout << nums[i] << endl;
    // }
    // return 0;

    int add = 2 * K + 1;
    int ans = 0;
    for (int i = 0; i < nums.size(); i += 2) {
        int tmp = 0;
        int left = i;
        int right = min(i + add, (int)nums.size());
        for (int j = left; j < right; j++) {
            tmp += nums[j];
        }
        ans = max(tmp, ans);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#ifndef M_E
#define M_E 2.71828182845904523536
#endif

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(x)
#endif

#define pln(x) cout << (x) << endl
#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> T& chmin(T &a, const U &b){return a = (a<=b?a:b);}
template <typename T, typename U> T& chmax(T &a, const U &b){return a = (a>=b?a:b);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

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

  int N;
  while(cin >> N){
    vector<LLI> a(N); cin >> a;

    LLI ans = 0;

    int p = 1;
    REP(i,N){
      if(i == 0){
	ans += a[i] - 1;
	a[i] = 1;
      }else if(a[i] > p){
	ans += (a[i]+p-1)/p-1;
      }

      if(a[i] == p) ++p;
    }

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


Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
 
int main(void)
{
  int h,w,H,W,x;
  
  scanf("%d %d",&H,&W);
  scanf("%d %d",&h,&w);
  
  x=(H*W)-(W*h)-(H*w)+(h*w);
  
  printf("%d",x);
  
  return 0;
  
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
using namespace std;
 
class Dice{
public:
    long r[6];
    Dice(){};
    void roll(long a, long b, long c, long d){swap(r[a], r[b]);swap(r[b], r[c]);swap(r[c], r[d]);}
    void spin(char c){if (c == 'W') roll(0, 2, 5, 3); else roll(0, 1, 5, 4);}
};
 
int main(){
    char SWS[8]={"NNNWNNN"};
    int n;
    cin >> n;
    //vector<Dice> D(n);
    Dice D[100];
    for (int i = 0; i < n ; i++) for (int j = 0; j < 6; j++) cin >> D[i].r[j];
    for (int i = 0; i < n - 1; i++){
        for (int j = i + 1; j < n; j++){
            for (int k = 0; k < 8; k++){
                if (D[i].r[1] == D[j].r[1]) break;
                D[j].spin(SWS[k]);
            }
            for (int k = 0; k < 4; k++){
                int ans = 0;
                for (int l = 0; l < 6; l++) if (D[i].r[l] == D[j].r[l]) ans++;
                if (ans == 6){cout << "No" << endl; return 0;}
                D[j].spin('W');
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using ll = long long;
using P = pair<ll,ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()
 


int main(){
  ll N,sum=0;
  cin >> N;
  vec A(N,0),B(N,0),Ans(N),S(N+1,0);
  rep(i,N){
    ll a;
    cin >> a;
    A.at(a-1)++;
  }
  rep(i,N){
    S.at(i+1)=S.at(i)+A.at(i);
  }
  rep(i,N){
    ll a;
    cin >> a;
    B.at(a-1)++;
  }
  priority_queue<P> D,F;
  rep(i,N){
    D.push(P(A.at(i)+B.at(i),i));
  }
  if(D.top().first>N){
    cout << "No" << endl;
    return 0;
  }
  set<ll> C;
  rep(i,N){
    C.insert(i);
  }
  queue<ll> E;
  while(!D.empty()){
    P a=D.top();
    F.push(a);
    D.pop();
    rep(i,S.at(D.top().second+1)-S.at(D.top().second)){
      E.push(S.at(D.top().second)+i);
    }
  }
  rep(i,S.at(F.top().second+1)-S.at(F.top().second)){
      E.push(S.at(F.top().second)+i);
    }
  while(!F.empty()){
    P a=F.top();
    F.pop();
    rep(i,B.at(a.second)){
      while(E.front()<S.at(a.second+1)&&E.front()>=S.at(a.second)){
        ll b=E.front();
        E.pop();
        E.push(b);
      }
      Ans.at(E.front())=a.second+1;
      E.pop();
    }
    
  }
  cout << "Yes" << endl;
  rep(i,N){
    cout << Ans.at(i) << " ";
  }
  cout << endl;
    
}

Measured memory_bytes: 30504
# solve
def solve(n, block):
    max_up = 0
    max_down = 0
    for i in range(n-1):
        if block[i] < block[i+1]:
            max_up = max(max_up, block[i+1]-block[i])
        elif block[i] > block[i+1]:
            max_down = max(max_down, block[i]-block[i+1])

    return (max_up, max_down)

# main function
if __name__ == '__main__':
    t = int(input())

    for i in range(t):
        n = int(input())
        tmp_block = input().split()

        block = []
        for j in range(n):
            block.append(int(tmp_block[j]))

        max_up, max_down = solve(n, block)
        print(max_up, max_down)

Measured memory_bytes: 6720
package main

import "fmt"

func main() {
	var r, g, b int
	fmt.Scan(&r, &g, &b)

	ans := r * 100 + g * 10 + b

	if ans % 4 == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

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

int main(){
  int X,N;
  cin >> X >> N;
  vector<int> p;
  for( int i = 0; i < N; ++i ){
    int tmp;
    cin >> tmp;
    p.emplace_back(tmp);
  }

  int min_dist = INT_MAX;
  int min = 0;
  for( int i = 0; i <= 101; ++i ){
    if( find(p.begin(), p.end(), i ) != p.end() ){
      continue;
    }

    if( min_dist > abs( X-i ) ){
      min = i;
      min_dist = abs( X-i );
    }
  }

  cout << min << endl;

}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int n,l,q,a[100005],pre[100005],nxt[100005],pp[100005],nn[100005],pc[100005],nc[100005];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	scanf("%d%d",&l,&q);
	for(int i=1;i<=n;i++)
	{
		pre[i]=lower_bound(a+1,a+n+1,a[i]-l)-a;
		nxt[i]=lower_bound(a+1,a+n+1,a[i]+l+1)-a-1;
	}
	for(int i=1;i<=n;i++)
	{
		int nw=i,cst=0;
		while(cst<300)
		{
			if(nw==1)break;
			nw=pre[nw];
			cst++;
		}
		pp[i]=nw;
		pc[i]=cst;
		nw=i,cst=0;
		while(cst<300)
		{
			if(nw==n)break;
			nw=nxt[nw];
			cst++;
		}
		nn[i]=nw;
		nc[i]=cst;
	}
	while(q--)
	{
		int l,r;
		scanf("%d%d",&l,&r);
		if(l<r)
		{
			int nw=l,cc=0;
			while(nn[nw]<r)
			{
				cc+=nc[nw];
				nw=nn[nw];
			}
			while(nw<r)
			{
				cc++;
				nw=nxt[nw];
			}
			printf("%d\n",cc);
		}
		else
		{
			int nw=l,cc=0;
			while(pp[nw]>r)
			{
				cc+=pc[nw];
				nw=pp[nw];
			}
			while(nw>r)
			{
				cc++;
				nw=pre[nw];
			}
			printf("%d\n",cc);
		}
	}
	return 0;
}

Measured memory_bytes: 3584
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    A = []
    for i in range(N):
        A.append(read_ints())
    base = [0]*(2**N)
    for i in range(2**N):
        for j in range(N):
            for k in range(j):
                if i & (1<<j) and i & (1<<k):
                    base[i] += A[j][k]
    dp = [0]*(2**N)
    for i in range(2**N):
        j = i
        while j > 0:
            dp[i] = max(dp[i], dp[i-j]+base[j])
            j = (j-1)&i
    return dp[2**N-1]


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 45348
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var A, B int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d", &A, &B)

	if max(A, B) <= 8 {
		fmt.Println("Yay!")
	} else {
		fmt.Println(":(")
	}
}

func max(ns ...int) int {
	ret := math.MinInt64
	for _, n := range ns {
		if n > ret {
			ret = n
		}
	}
	return ret
}


Measured memory_bytes: 640
fn main() {
    let max = |a, b| if a < b { b } else { a };
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    let line: Vec<isize> = line.trim().split_whitespace().flat_map(str::parse).collect();
    let (a, b, c) = (line[0], line[1], line[2]);

    println!("{}", max(0, c - a + b));
}

Measured memory_bytes: 4352
d = gets.to_i
c = gets.split(' ').map{|s| s.to_i}
a = []
d.times do |i|
  a[i] = gets.split(' ').map{|s| s.to_i}
end

#p a[0]
 
d.times do |i|
  puts a[i].index(a[i].max) + 1
#	puts (rand(26) + 1)
end

Measured memory_bytes: 14400
N,K = map(int,input().split())
ans = 0
if K == 0:
  print(N**2)
  exit()
for b in range(K+1,N+1): #bを一個ずつチェックK+1からNまで
  amari = b-K
  loop = N//b
  nokori = max(N%b+1-K,0)
  temp = loop*amari + nokori
  #print(b,amari,loop,nokori,temp)
  ans += temp
print(ans)

Measured memory_bytes: 9172
#include<iostream>
#include<cmath>

using namespace std;
using ll = long long;

ll result(ll hp) {
	if (hp == 1) {
		return 1;
	}
	else {
		return 2 * result(hp / 2) + 1;
	}
}

void solve2() {
	ll H;
	cin >> H;
	cout << result(H) << endl;
}

void solve1() {
	ll H, n, ans;
	cin >> H;

	n = (int)log2(H);
	ans = pow(2, n + 1) - 1;

	cout << ans << endl;
}

int main(void) {
	//solve1();
	solve2();
}

Measured memory_bytes: 256
/*
g++ -std=c++14 -O2 -Wall a.cpp -o a && a
*/

//  io
#include <iostream>
//#include <fineam> //http://www.cplusplus.com/reference/fineam/fineam/
//#include <cstdio>
#include <iomanip> //http://www.cplusplus.com/reference/iomanip/
#include <limits>
//  util
#include <string>
#include <cstring>
#include <algorithm>
//#include <utility>
//#include <functional> //http://www.cplusplus.com/reference/functional/
//#include <cstdlib>
#include <cmath>
//#include <complex>
//#include <random>
//#include <bitset>
//  containers https://en.cppreference.com/w/cpp/container
#include <vector>
#include <queue>
#include <set>
//#include <map>
//#include <unordered_set>
//#include <unordered_map>
//  time
//#include <ctime>
//#include <chrono>
//                  https://en.cppreference.com/w/cpp/header/chrono
//                  http://www.cplusplus.com/reference/chrono/

using namespace std;
typedef vector<int> arri;
typedef vector<float> arrf;
typedef pair<int, int> pairi;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 0x7fffffffffffffff;
const ll infneg = -0x7fffffffffffffff;

//file input routed to stdinout
/*
std::ifineam inFile("input.txt");
std::ofineam outFile("output.txt");
std::cin.rdbuf(inFile.rdbuf());
std::cout.rdbuf(outFile.rdbuf());
*/

int LCSRe[5005][5005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    string in;
    cin >> n >> in;

    memset(LCSRe, 0, sizeof(LCSRe));

    int res_length = 0;

    int index = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = i + 1; j <= n; j++)
        {
            if (in[i - 1] == in[j - 1] &&
                LCSRe[i - 1][j - 1] < (j - i))
            {
                LCSRe[i][j] = LCSRe[i - 1][j - 1] + 1;

                if (LCSRe[i][j] > res_length)
                {
                    res_length = LCSRe[i][j];
                    index = max(i, index);
                }
            }
            else
                LCSRe[i][j] = 0;
        }
    }

    cout << res_length;
}

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

vector <long long> v[1000000];

//stack <long long> pus, wyn;

//queue <long long> qu;

long long int  x[1000000], y, z, czy=0, w, n, m=1000000007;
char s[10][10];

int main()
{
    long long int a, b, c, d, k, i, j, q, t, p;

//    q=1;


//    scanf("%lld", &q);
//    for(t=0; t<q; t++)
    {
        scanf("%lld", &n);
        for(i=0; i<n-1; i++)
        {
            scanf("%lld%lld", &a, &b);
            a--;
            b--;
            if(a>b)swap(a, b);
            v[b].push_back(a);
        }

        a=0;
        w=0;

        for(i=0; i<n; i++)
        {
            b=0;
            a+=i+1;
            for(j=0; j<v[i].size(); j++)
            {
                a-=v[i][j]+1;
            }
            w+=a;
        }

        printf("%lld\n", w);
    }

    return(0);
}


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

#define all(x) (x).begin(),(x).end()
#define pb push_back
#define pf push_front
#define sz(x) (int)(x).size()
#define lb lower_bound 
#define ub upper_bound 
#define mp make_pair
#define fi first
#define se second
#define setbits(x) __builtin_popcount(x)
#define zerobits(x) __builtin_ctz(x)
#define setbitsll(x) __builtin_popcountll(x)
#define zerobitsll(x) __builtin_ctzll(x)
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef vector<string> vs;
typedef unsigned long long ull;
typedef long double ld;
typedef map<int,int> mii;

const int MOD = 1e9+7;
const ld PI = acos((ld)-1);

void solve () {
	int n;
	cin >> n;
	int arr[n];
	for (int i = 0;i < n;++i) {
		cin >> arr[i];
	}
	int ans = 0;
	for (int i = 0;i < n-2;++i) {
		for (int j = i+1;j < n-1;++j) {
			for (int k = j+1;k < n;++k) {
				if ((arr[i] != arr[j] && arr[j] != arr[k] && arr[i] != arr[k]) && (arr[i]+arr[j] > arr[k] && arr[j]+arr[k] > arr[i] && arr[i]+arr[k] > arr[j])) {
					++ans;
				}
			}
		}
	}
	cout << ans << '\n';
}

int main () {
#ifndef ONLINE_JUDGE
	freopen("input1.txt","r",stdin);
	freopen("output1.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;
}



Measured memory_bytes: 3648
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        RainFlowsintoDams solver = new RainFlowsintoDams();
        solver.solve(1, in, out);
        out.close();
    }

    static class RainFlowsintoDams {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long[] dams = new long[n];
            for (int i = 0; i < n; i++) {
                dams[i] = 2 * in.nextLong();
            }

            long[] mountains = new long[n];
            mountains[0] = 0;
            for (int j = 1; j < n; j++) {
                int pos = j;
                mountains[pos] = dams[pos - 1] - mountains[pos - 1];
            }
            if (mountains[0] + mountains[n - 1] == dams[n - 1]) {
                for (int k = 0; k < n; k++) {
                    out.print(mountains[k] + " ");
                }
            } else {
                mountains[0] = Math.abs(dams[n - 1] - mountains[n - 1]) / 2;
                for (int j = 1; j < n; j++) {
                    int pos = j;
                    mountains[pos] = dams[pos - 1] - mountains[pos - 1];
                }
                for (int k = 0; k < n; k++) {
                    out.print(mountains[k] + " ");
                }
            }

        }

    }
}



Measured memory_bytes: 62132
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long LL;

int n, K, dp[5][105][3];
char str[105];

int dfs(int m, int use, int limit) {
    if(use > K) return 0;
    if(m > n) return use == K;
    if(dp[use][m][limit] != -1) return dp[use][m][limit];
    int up = limit == 1? str[m]-'0':9, ans = 0;
    for(int i = 0; i <= up; ++i)
        ans += dfs(m+1, use+(i!=0), limit&&i==up); 
    return dp[use][m][limit] = ans;
}

void run_case() {
    cin >> (str+1) >> K;
    n = strlen(str+1);
    memset(dp, -1, sizeof(dp));
    cout << dfs(1, 0, 1);
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    //cout.setf(ios_base::showpoint);cout.precision(8);
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 256