akhauriyash/Code-Regression huggingface dataset:
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int W, H;
  while (cin >> W >> H, W) {
    vs v(H);
    rep(i, H) cin >> v[i];
    vvi dp(H, vi(W));
    int b = 0, w = 0;
    rep(i, H) rep(j, W) {
      dp[i][j] = 2 * (v[i][j] == 'B') + (v[i][j] == 'W');
      b -= v[i][j] == 'B';
      w -= v[i][j] == 'W';
    }
    rep(_, W * H) rep(i, H) rep(j, W) {
      if (v[i][j] != '.') continue;
      if (i > 0) dp[i][j] |= dp[i - 1][j];
      if (j > 0) dp[i][j] |= dp[i][j - 1];
      if (i < H - 1) dp[i][j] |= dp[i + 1][j];
      if (j < W - 1) dp[i][j] |= dp[i][j + 1];
    }
    rep(i, H) rep(j, W) {
      b += dp[i][j] == 2;
      w += dp[i][j] == 1;
    }
    cout << b << ' ' << w << endl;
  }
}

Measured memory_bytes: 3152
#include<bits/stdc++.h>
  
#define lol long long
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed(x) fixed<<setprecision(x)
using namespace std;
using pii=pair<int,int>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
const lol inf=(1LL<<60);
const lol Mod=(1e9)+7;
const lol mod=998244353;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
bool line(lol x,lol y,lol nx,lol ny){return (x<nx&&y<ny&&x>=0&&y>=0);}
lol n,m,k;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >>n;
  lol a,b;cin >>a>>b;
  vector<int> x(n);
  for(auto&&o:x) cin>>o;
  lol sum=x[0];
  lol ans=0;
  for(int i=1;i<n;i++){
    ans+=min(b,(x[i]-sum)*a);
    sum=x[i];
  }
  cout <<ans<<'\n';
  return (0);
}


Measured memory_bytes: 3700
#include <stdio.h>
#define N 500000

int data[N+1], n;

void swap(int* a, int* b){
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

void maxHeapify(i){
  int l = 2*i;
  int r = 2*i+1;
  int valM;
  if(l <= n && data[l] > data[i]) valM = l;
  else valM = i;
  if(r<=n && data[r] > data[valM]) valM = r;
  if(valM != i){
    swap(&data[i], &data[valM]);
    maxHeapify(valM);
  }
}

void buildMaxHeap(){
  int i;
  for(i=n/2;i>0;i--) maxHeapify(i);
}

main(){
  int i;
  scanf("%d", &n);
  for(i=1;i<=n;i++) scanf("%d", &data[i]);
  buildMaxHeap();
  for(i=1;i<=n;i++) printf(" %d", data[i]);
  printf("\n");
  return 0;
}



Measured memory_bytes: 3684
import java.util.Scanner;
public class Main {
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			while(sc.hasNext()) {
				int m = sc.nextInt();
				int nmin = sc.nextInt();
				int nmax = sc.nextInt();
				if(m + nmin + nmax == 0) break;
				
				int [] p = new int[m+1];
				for(int i=1; i<=m; i++) {
					p[i] = sc.nextInt();
				}
				
				int gap = 0;
				int n = 0;
				for(int i=nmin; i<=nmax; i++) {
					if(gap <= p[i] - p[i+1] && n < i) {
						gap = p[i] - p[i+1];
						n = i;
					}
				}
				System.out.println(n);
			}
		}
	}
}


Measured memory_bytes: 57104
#include<iostream>
#include<sstream>
#include<iomanip>
#include<bitset>
#include<map>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define lli long long int
#define uli unsigned long long int
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define mmax 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
using namespace std;
int main(){
  lli i=0,j=0;
  lli n,T,ans=1001;
  cin>>n>>T;
  vector<lli> c(n),t(n);
  rep(i,0,n){
    int a,b;
    cin>>a>>b;
    if(b<=T){
      c.at(i-j)=a;
      t.at(i-j)=b;
      //cout<<c.at(i-j)<<' '<<t.at(i-j)<<endl;
    }
    else ++j;
  }
  if(j==n){
    ou("TLE");
    return 0;
  }
  rep(i,0,c.size()){
    if(c.at(i)==0)
      break;
    ans=min(ans,c.at(i));
    //ou(c.at(i));
  }
  ou(ans);
}

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

typedef long long ll;

ll n;
ll x;
ll a[100005];

int main()
{
    ll ans = 0;

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

    for (ll i = 1; i < n; i++) {
        ll diff = (a[i - 1] + a[i]) - x;

        if (diff > 0) {
            if (a[i] > diff) {
                a[i] -= diff;
                ans += diff;
            } else {
                diff -= a[i];
                ans += a[i];
                a[i] = 0;

                a[i - 1] -= diff;
                ans += diff;
            }
        }
    }

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


Measured memory_bytes: 1152
"""
AtCoder :: Beginner Contest 174 :: Alter Altar
https://atcoder.jp/contests/abc174/tasks/abc174_d
"""
import sys


def solve(altar):
    """Solve puzzle."""
    soln = 0
    left = 0
    right = len(altar) - 1
    while left < right:
        while left < len(altar) and altar[left] == 'R':
            left += 1
        while right >= 0 and altar[right] == 'W':
            right -= 1
        if left < right:
            altar[left], altar[right] = altar[right], altar[left]
            soln += 1
    return soln


def main():
    """Main program."""
    N = int(sys.stdin.readline())
    altar = [c for c in sys.stdin.readline().strip()]
    print(solve(altar))


if __name__ == '__main__':
    main()


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

typedef vector<int> vi;
#define ll long long
#define loop(i,n) for(int i=0; i<n; i++)
#define loop1(i,n) for(int i=1; i<=n; i++)
#define loopi(i,s,e) for(int i=s; i < e; i++)
#define loopiRev(i,s,e) for(int i=s; i >= e; i--)
#define PI 3.14159265359
#define x first
#define y second
#define point pair<double,double>
#define len(s)   (int)s.length()
#define sz(v)    (int)v.size()
#define all(a)   a.begin(),a.end()
#define clr(x, val)	memset((x), (val), sizeof(x))

void initialize(vector<int> &F, int n){
    F = vector<int> (n+1, 0);

    for(int i=2; i*i  <= n; i++){
        if(F[i] == 0)
            for(int k=i*i; k <=n ; k+= i)
                if(F[k] == 0) F[k] = i;
    }
}

//you don't know math, unless you can do math!
int l,n;
vector<int> cuts;
ll dp[1100][1100];

ll solve(int i, int j){
    ll &ret= dp[i][j];
    if(ret != -1)
        return ret;

    int cur= lower_bound(cuts.begin(), cuts.end(), i+1) - cuts.begin();
    if(cur == cuts.size() || cuts[cur] >= j)
        return ret= 0;



    ret= 10000000;
    while(cur < n && cuts[cur] < j){
        ret = min(ret, solve(i, cuts[cur]) + solve(cuts[cur], j) + j - i);
        cur++;
    }

    return ret;
}
int main() {
    //freopen("input.txt" , "r" , stdin) ;
    //freopen("output.txt" , "w" , stdout) ;

    cin.tie(0);
    cin.sync_with_stdio(0);

    int a,b,c; cin>>a>>b>>c;
    int gcd = __gcd(a,b);

    if(c%gcd == 0)
        cout<<"YES";
    else
        cout<<"NO";

}


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

int main()
{
  int n;
  cin >> n;
  vector<int64_t> a(n), b(n), c(n);
  for (auto i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (auto i = 0; i < n; i++) {
    cin >> b[i];
  }
  int64_t minus = 0;
  int64_t minus_cnt = 0;
  for (auto i = 0; i < n; i++) {
    c[i] = a[i] - b[i];
    if (c[i] < 0) {
      minus += c[i];
      minus_cnt++;
    }
  }
  sort(begin(c), end(c), greater<>());
  int64_t ans = 0;
  for (auto i = 0; i < n; i++) {
    if (minus >= 0) break;
    if (c[i] <= 0) break;
    minus += c[i];
    ans++;
  }
  if (minus < 0) {
    cout << "-1" << endl;
  } else {
    cout << ans + minus_cnt << endl;
  }
}


Measured memory_bytes: 3064
N, K = map(int, input().split())
S = input()

ans = ""
for i in range(N):
  if i == K-1:
    if S[i] == 'A':
      ans += 'a'
    elif S[i] == 'B':
      ans += 'b'
    else:
      ans += 'c'
  else:
    ans += S[i]
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,int> mypair;
int main(void){
int n;
cin>>n;
vector<mypair> p(n);
int a,b;
for(int i=0;i<n;i++){
cin>>a>>b;
p[i]=mypair(a,b);
}
sort(p.begin(),p.end());
int ans=0;
ans+=p[n-1].second+p[n-1].first;
cout<<ans<<endl;

return 0;
}

Measured memory_bytes: 1024
s = input()
num = 0
for i in s:
    if num % 2 == 0:
        if i in ["R", "U", "D"]:
            pass
        else:
            print("No")
            break
    else:
        if i in ["L", "U", "D"]:
            pass
        else:
            print("No")
            break
    num += 1
else:
    print("Yes")


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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved

int main(){
    long long n,x,t;
    cin>>n>>x>>t;

    cout<<(long long )ceil((double)n/x)*t<<endl;
    return 0;

}
/*


*/


Measured memory_bytes: 3712
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		long b = scan.nextLong();
		long x = scan.nextLong();
		long n = b/x;
		long m;
		if (a!=0) {
			if (a%x==0) {				
				m = a/x-1;
			} else {
				m = a/x;
			}
		} else {
			m = -1;
		}
		long c = n-m;
		System.out.println(c);
	}
}


Measured memory_bytes: 23764
r, c = map(int, input().split())
a = []

for i in range(r):
    a.append(list(map(int, input().split())))
    a[i].append(sum(a[i]))

for i in range(r):
    print(" ".join(list(map(str, a[i]))))

col_sum = []
for j in range(c+1):
    su = 0
    for i in range(r):
        su += a[i][j]
    col_sum.append(su)
print(" ".join(list(map(str, col_sum))))


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

int gcd(long long u, long long v){
    long long t;
    while(u > 0){
        if(u < v){t = u; u = v; v = t;}
        u = u - v;
    }
    return v;
}

int main(){
    long long K;
    cin >> K;
    long long a,b,c;
    long long sum = 0;
    long long sub;
    for(a = 1; a <= K; a++){
        for(b = 1; b <= K; b++){
            for(c = 1; c <= K; c++){
                sub = gcd(a,b);
                sum += gcd(sub,c);
            }
        }
    }
    cout << sum << endl;
    system("pause");
    return 0;
}

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

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

    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());

    cout << ((s < t) ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)


typedef long long int ll;
typedef double D;      // ??§?¨?????????????double???long double?????????
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;


const int INF = (1<<30) - 1;
const D EPS = 1e-9;

#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

int H, W;
vector<string> field;
int dh[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dw[] = {0, 1, 1, 1, 0, -1, -1, -1};

void func(int h, int w, int d, map<string, int>& memo){
    int sh = h, sw = w;
    string s = "";
    
    do{
        s += field[h][w];
        if(s.length() >= 2)
            memo[s]++;
        h = (h+dh[d]+H)%H;
        w = (w+dw[d]+W)%W;
    }while(sh!=h || sw!=w);
}
void solve(){
    map<string, int> memo;
    
    for(int h=0; h<H; h++){
        for(int w=0; w<W; w++){
            for(int i=0; i<8; i++){
                func(h, w, i, memo);
            }
        }
    }
    
    string ans = "";
    for(auto p: memo){
        if(p.second < 2) continue;
        
        if(ans.length() < p.first.length() || (ans.length() == p.first.length() && p.first < ans))
            ans = p.first;
    }
    if(ans.length() == 0)
        cout << 0 << endl;
    else
        cout << ans << endl;
}

//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.precision(16);
    //cout.setf(ios::fixed);
    
    while(cin>>H>>W, H|W){
        field = vector<string>(H);
        
        for(int i=0; i<H; i++)
            cin >> field[i];
        solve();
    }
    
    return 0;
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<int> A(N);
  REP(i, N){
    cin >> A[i];
  }
  deque<int> B;
  if(N%2 == 0){
    REP(i, N){
      if(i%2 == 1){
        B.push_front(A[i]);
      }else{
        B.push_back(A[i]);
      }
    }
  }else{
    REP(i, N){
      if(i%2 == 0){
        B.push_front(A[i]);
      }else{
        B.push_back(A[i]);
      }
    }
  }
  REP(i, N){
    cout << B.front();
    if(i != N-1){
      cout << " ";
    }else{
      cout << endl;
    }
    B.pop_front();
  }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

int main(){
    int N, K;
    cin >> N >> K;
    cout << N - (K-1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }




int main() {
	int n;
	cin >> n;
	vector < vector<pair<int, int>>> t(n);
	rep(i, n-1) {
		int u, v, w;
		cin >> u >> v >> w;
		u--; v--;
		t[u].push_back(make_pair(v, w));
		t[v].push_back(make_pair(u, w));
	}
	vector<int> ans(n);
	vector<int> already(n);
	stack<int> next;
	ans[0] = 0;
	already[0] = 0;
	next.push(0);
	while (next.size()) {
		int x = next.top();
		next.pop();
		if (already[x] == 1) {
			continue;
		}
		already[x] = 1;
		rep(i, t[x].size()) {
			auto y = t[x][i];
			if (y.second % 2 == 0) {
				ans[y.first] = ans[x];
			}
			else {
				ans[y.first] = (ans[x] + 1) % 2;
			}
			next.push(y.first);
		}
	}
	rep(i, n) {
		cout << ans[i] << endl;
	}
	return 0;
}



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

using namespace std;

int main()
{
  int N, K;
  cin >> N >> K;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }

  vector<bool> dp(K + 1);
  dp[0] = false;
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j < N; j++) {
      if (i + a[j] <= K) dp[i + a[j]] = dp[i + a[j]] | !dp[i];
    }
  }
  if (dp[K]) cout << "First" << endl;
  else cout << "Second" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <queue>
using namespace std;
#define ll long long
ll a[200010];
int main()
{
    ll n ,t;
    ll sum = 0;
    cin>>n>>t;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(i >= 2){
            sum += min((a[i]-a[i-1]),t);
        }
    }
    sum += t;
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 200005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}
vector<ll> L;
vector<ll> H;

bool valid(ll pos, ll i, ll j, ll sameH, ll sameL, ll isFirst) {

  if (i < j)
    return false;
  if (sameH && (i > H[pos]))
    return false;
  if (sameL && (j < L[pos]))
    return false;

  if (isFirst) {
    if (i == 1)
      return i == j;
  }
  return true;
}

ll recur(ll posH, ll sameH, ll sameL, ll isFirst);
ll solve(ll pos, ll i, ll j, ll sameH, ll sameL, ll isFirst) {

  ll nsameH;
  if (sameH && i == H[pos])
    nsameH = 1;
  else
    nsameH = 0;

  ll nsameL;
  if (sameL && j == L[pos])
    nsameL = 1;
  else
    nsameL = 0;

  if (i) {
    if (isFirst)
      isFirst = 0;
  }

  return recur(pos + 1, nsameH, nsameL, isFirst);
}
ll n;

ll dp[70][2][2][2];

ll recur(ll posH, ll sameH, ll sameL, ll isFirst) {

  if (posH == n) {
    return 1;
  }
  ll &ans = dp[posH][sameH][sameL][isFirst];
  if (ans != -1)
    return ans;

  ans = 0;
  for (ll i = 0; i < 2; i++) {
    for (ll j = 0; j < 2; j++) {
      if (valid(posH, i, j, sameH, sameL, isFirst)) {
        ans += solve(posH, i, j, sameH, sameL, isFirst);
      }
    }
  }

  ans %= mod;
  return ans;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll l, r;
  cin >> l >> r;

  while (l) {
    L.push_back(l % 2);
    l /= 2;
  }

  while (r) {
    H.push_back(r % 2);
    r /= 2;
  }

  while (L.size() != H.size())
    L.push_back(0);

  reverse(L.begin(), L.end());

  reverse(H.begin(), H.end());

  n = H.size();
  memset(dp, -1, sizeof(dp));
  cout << recur(0, 1, 1, 1) << en;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

template<class T> class max_flow {
    int MAX_V;
    vector<vector<tuple<int, T, int>>>G;
    vector<bool>used;

public:
    //初期化
    max_flow(int _v) :MAX_V(_v) {
        G.resize(MAX_V);
    }
    //関数
    void add_edge(int from, int to, T cap) {
        G[from].emplace_back(to, cap, (int)G[to].size());
        G[to].emplace_back(from, 0, (int)G[from].size() - 1);
    }
    //増加パスをDFSで探す
    int dfs(int v, int t, int f) {
        if (v == t)return f;
        used[v] = true;
        rep(i, 0, G[v].size()) {
            int to = get<0>(G[v][i]), rev = get<2>(G[v][i]);
            T& cap = get<1>(G[v][i]);
            if (!used[to] && cap > 0) {
                int d = dfs(to, t, min(f, cap));//経路中の最小コスト
                if (d > 0) {
                    cap -= d;
                    get<1>(G[to][rev]) += d;
                    return d;
                }
            }
        }
        return 0;
    }
    //sからtへの最大流
    int flow(int s, int t) {
        int res = 0;
        for (;;) {
            used.resize(MAX_V, false);
            int f = dfs(s, t, INF);
            if (f == 0)return res;
            res += f;
            used.clear();
        }
    }
};

int main() {
	init();

    int V, E; cin >> V >> E;
    max_flow<int>fl(V);
    rep(i, 0, E) {
        int a, b, c; cin >> a >> b >> c;
        fl.add_edge(a, b, c);
    }
    int ans = fl.flow(0, V - 1);
    cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<ll> p(n);
    rep(i, n) cin >> p[i];
    ll ans = 0;
    reps(i, 1, n - 1) {
        if ((p[i] > p[i - 1]) && (p[i] < p[i + 1])) ans++;
        else if ((p[i] < p[i - 1]) && (p[i] > p[i + 1])) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <bitset>
#include <map>
#include <utility>
using namespace std;

string itob(int n) {
  ostringstream oss;
  oss << bitset<5>(n);
  return oss.str();
}

int main() {
  map<char, string> ctob = {
    { ' ', itob(26) },
    { '.', itob(27) },
    { ',', itob(28) },
    { '-', itob(29) },
    { '\'', itob(30) },
    { '?', itob(31) }
  };
  for(char c = 'A'; c <= 'Z'; ++c) {
    ctob[c] = itob(c - 'A');
  }

  map<string, char> btoc = {
    { "101", ' ' },
    { "000000", '\'' },
    { "000011", ',' },
    { "10010001", '-' },
    { "010001", '.' },
    { "000001", '?' },
    { "100101", 'A' },
    { "10011010", 'B' },
    { "0101", 'C' },
    { "0001", 'D' },
    { "110", 'E' },
    { "01001", 'F' },
    { "10011011", 'G' },
    { "010000", 'H' },
    { "0111", 'I' },
    { "10011000", 'J' },
    { "0110", 'K' },
    { "00100", 'L' },
    { "10011001", 'M' },
    { "10011110", 'N' },
    { "00101", 'O' },
    { "111", 'P' },
    { "10011111", 'Q' },
    { "1000", 'R' },
    { "00110", 'S' },
    { "00111", 'T' },
    { "10011100", 'U' },
    { "10011101", 'V' },
    { "000010", 'W' },
    { "10010010", 'X' },
    { "10010011", 'Y' },
    { "10010000", 'Z' }
  };

  for(string S; getline(cin, S); ) {
    string bin;
    for(char c : S)
      bin += ctob[c];
    string ans;
    for(int i = 0; i < (int)bin.size(); ) {
      for(int j = 1; i + j <= (int)bin.size(); ++j) {
        string sub = bin.substr(i, j);
        if(btoc.count(sub)) {
          ans.push_back(btoc[sub]);
          i += j;
          goto next;
        }
      }
      break;
next:
      ;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1224
// AOJ 1156
// Twirling Robot
// 2016/6/9

#include<iostream>
#include<vector>
#include<stdio.h>
#include<stdlib.h>
#define MAX_W_H 30
#define INF 1000000
using namespace std;

// ??????:[0] = E, [1] = S, [2] = W, [3] = N
// ??????:[0] = Straight, [1] = Right, [2] = Back, [3] = Left
int f[4][4] = {{0, 1, 2, 3}, {3, 0, 1, 2}, {2, 3, 0, 1}, {1, 2, 3, 0}}; // [?¬???????????????????][???????????????????????????] = ???????????????

// ??????(i, j, k) == ???????????????(j, i)??????????????????????????????k????????????????????¶???

int w, h;
int map[MAX_W_H][MAX_W_H];
int d[MAX_W_H][MAX_W_H][4];	// ??????(0, 0, 0)?????????????°??????????
int instr_cost[4];		// ?????????????????????
bool used[MAX_W_H][MAX_W_H][4];	// ?????§?????????????????????????????°

bool in_map(int x, int y)
{
  return (0 <= x && x < w && 0 <= y && y < h);
}

void dijkstra(void)		// ??????(0, 0, 0)?????????????????????????°???????????±???????
{
  int dir[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; // [0]=E, [1]=S, [2]=W, [3]=N
  while(true)
    {
      int x = -1, y = -1, di = -1;
      for(int i = 0; i < h; i++)
	for(int j = 0; j < w; j++) 
	  for(int k = 0; k < 4; k++)// ???????????????????????? and ?§?????????????????????????????°??????? == ???????????¢????¢????????????????
	    if(!used[i][j][k] && ((x == -1 && y == -1 && di == -1) || (d[i][j][k] < d[y][x][di])))
	      x = j, y = i, di = k;

      if(x == -1 && y == -1 && di == -1)
	break;

      used[y][x][di] = true;

      // ??????(y, x, di)??¨??£??\???????????????"?§??????????????????¢"?????´??°
      for(int i = 0; i < 4; i++)
	{
	  int xx = x + dir[i][0];
	  int yy = y + dir[i][1];
	  int c;
	  if(!in_map(xx, yy))
	    continue;

	  int inst = f[di][i]; // d = ??????(x, y)????????????????????????, i = ??????(x, y)??????????????????(xx, yy)?????????, inst = ?§??????????????????????
	  if(inst == map[y][x])
	    c = 0;
	  else
	    c = instr_cost[inst];

	  d[yy][xx][i] = min(d[yy][xx][i], d[y][x][di] + c);
	}
    }
}

int main(void)
{
  int ans = INF;
  while(cin >> w >> h, (w && h))
    {
      for(int i = 0; i < MAX_W_H; i++)
	for(int j = 0; j < MAX_W_H; j++)
	  for(int k = 0; k < 4; k++)
	    {
	      d[i][j][k] = INF;
	      used[i][j][k] = false;
	    }


      d[0][0][0] = 0;

      for(int i = 0; i < h; i++)
	for(int j = 0; j < w; j++)
	  cin >> map[i][j];

      for(int i = 0; i < 4; i++)
	cin >> instr_cost[i];

      dijkstra();


      for(int i = 0; i < 4; i++)
	ans = min(ans, d[h - 1][w - 1][i]);

      cout << ans << endl;

      ans = INF;
    }
  return 0;
}

Measured memory_bytes: 1180
//Radhe Radhe
#include<bits/stdc++.h>
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
using namespace std;

int main()
{
    fast_io
    ll i,t,n,j,k,sum=0,cpn;
    string s;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);

    cout<<a[n-1]-a[0]<<endl;

    return 0;
}





Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

bool fc(vector<int> a, int k, int mid){
  int tot = 0;
  rep(i, a.size()){
    tot += (a.at(i)+mid-1)/mid - 1;
  }
  return tot <= k;
}

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  int ng = 0, ok = 1e9+5;
  while(ok - ng > 1){
    int mid = (ok+ng)/2;
    if(fc(a, k, mid) == true) ok = mid;
    else ng = mid;
  }
  cout << ok << endl;
  return 0;
}

Measured memory_bytes: 4844
#include <iostream>
#include <algorithm>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define sq(x) ((x) * (x))
#define err(x) cerr << "["#x"]  " << (x) << "\n";
#define errv(x) {cerr << "["#x"]  [";for(const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
#define errvn(x, n) {cerr << "["#x"]  [";for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define errf() cerr << "\n\n";

#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getrnd(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

template <typename T1, typename T2>
bool relax(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

template <typename T1, typename T2>
bool strain(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

// :::::::::::::::::::::::::::::::

const int N = 1e5 + 3;
const ll MOD = 1e9 + 7;

ll dp[N][2], was[N];
list<int> graph[N];

void mul(ll& a, ll b) {
    a = (a * b) % MOD;
}

void dfs(int v) {
    if (was[v]) return;
    
    was[v] = 1;
    dp[v][0] = dp[v][1] = 1;
    for (int& to : graph[v]) {
        if (was[to] == 0) {
            dfs(to);
            
            mul(dp[v][0], dp[to][0] + dp[to][1]);
            mul(dp[v][1], dp[to][0]);
        }
    }
}

void solve() {
    int n;
    cin >> n;
    
    for (int i = 0; i < n - 1; ++i) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        
        graph[x].emplace_back(y);
        graph[y].emplace_back(x);
    }
    
    dfs(0);
    cout << (dp[0][0] + dp[0][1]) % MOD << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    srand(time(0));
    
    int t = 1;
//    cin >> t;
    while (t--)
        solve();
    
    return 0;
}


Measured memory_bytes: 17408
import sys
sys.setrecursionlimit(10**6)

N, M = map(int, input().split())
G = [[] for i in range(N)]

for m in range(M):
    a, b = map(lambda x: int(x)-1, input().split())
    G[a].append(b)
    G[b].append(a)
visited = set()
ans1, ans2 = [], []

ans1.append(str(1))
visited.add(0)
def dfs(n, ans):
    for ni in G[n]:
        if ni not in visited:
            ans.append(str(ni+1))
            visited.add(ni)
            dfs(ni, ans)
            break


dfs(0, ans1)
dfs(0, ans2)


print(len(ans1) + len(ans2))
print(" ".join(ans2[::-1] + ans1))


Measured memory_bytes: 114340
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

char solve(string s){
	ll n=SZ(s);
	fore(i,0,n)s[i]--;
	fore(i,0,n){
		//fore(j,0,n-i)cout<<s[j]; cout<<"\n";
		if(i==n-1)return s[0];
		char b[n-1-i];
		fore(j,0,n-i)b[j]=abs(s[j+1]-s[j])+'0';
		fore(j,0,n-i)s[j]=b[j];
	}
}

ll v[1000006];
ll sv[1000006];

ll dos(ll n){
	if(n==0)return 0;
	ll res=0;
	while(n%2==0){
		n/=2;
		res++;
	}
	return res;
}

ll comb(ll n, ll k){
	return sv[n]-sv[n-k]-sv[k]==0;
}

int main(){FIN;
	/*ll t; cin>>t;*/
	/*ll res[3]={0,0,0};
	//while(t--){
		fore(i,0,3){
			fore(j,0,3){
				fore(k,0,3){
					fore(ii,0,3){
						fore(jj,0,3){
							string s;
							s+='0'+i;
							s+='0'+j;
							s+='0'+k;
							s+='0'+ii;
							s+='0'+jj;
							cout<<s<<" "<<solve(s)<<"\n";
							res[solve(s)-'0']++;	
						}
					}
				}
			}
		}
	//}
	fore(i,0,3)cout<<res[i]<<" ";*/
	ll n; cin>>n;
	string s; cin>>s;
	fore(i,0,n)v[i]=dos(i),s[i]--;
	fore(i,1,n)sv[i]=sv[i-1]+v[i];
	//cout<<"HOLAAA"<<endl;
	ll res=0,res2=0,d=0;
	fore(i,0,n){
		res+=comb(n-1,i)*((s[i]-'0')%2);
		res2+=comb(n-1,i)*(s[i]=='2');
		d+=(s[i]=='1');
		res%=2; res2%=2;
	}
	//cout<<"HOLAAA"<<endl;
	//cout<<solve(s)<<" ";
	if(res==1){
		cout<<1; return 0;
	}else if(res2==1&&d==0){
		cout<<2; return 0;
	}else cout<<0;
	
	return 0;
}

Measured memory_bytes: 16924
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long ll;
int main(){
  int n;
 
  bool flag = true;
  cin >> n;
  vector<ll> h(n);
  rep(i,n) cin >> h[i];
  ll max_n = h[0];
  for(int i=1;i<n;i++) {
    if(max_n - 1 > h[i]){ flag = false;break;}
    max_n = max(max_n, h[i]);
  }
  if(flag) cout << "Yes\n";
  else cout << "No\n"; 
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int l;
    cin >> l;
    if (l==2) {
        printf("2 2\n");
        printf("1 2 0\n1 2 1\n");
        return 0;
    }
    l--; 
    int keta = 0;
    while (l>>keta) {
        keta++;
    }
    int n = keta;
    
    int m = (n-1)*2 + __builtin_popcount(l);
    int num = 0;
    cout << n << " " << m << endl;
    if (m>60) return -1;
    
    rep(i, n-1) {
        cout << i+1 << " " << i+2 << " " << 0 << endl;
        cout << i+1 << " " << i+2 << " " << (1<<(n-2-i)) << endl;
        num += 2;
    }
    /*
    int x = 1<<(keta-1);
    for (int i=keta-2; i>=0; i--) {
        if ((l>>i&1)==0) continue;
        cout << 1 << " " << 1+(keta-1-i) << " " << x <<  endl;
        x += 1<<i;
    }

    
    cout << 1 << " " << n << " " << x << endl;
    */
    int x = 0;
    for (int i=keta-1; i>=0; i--) {
        if ((l>>i&1)==0) continue;
        x += 1<<i;
        int index = i-1;
        while (index>=0) {
            if (l>>index&1) break;
            index--;
        }
        if (index<0) index = 0;
        cout << 1 << " " << keta-index << " " << x << endl;
        num++;
    }
    if (num!=m) return -1;
    

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int count = 0;
    for(int i = 1; i <= K; i++){
        for(int j = 1; j <= K; j++){
            if((i % 2 == 0 && j % 2 == 1) || (i % 2 == 1 && j % 2 == 0)){
                count ++;
            }
        }
    }

    cout << count/2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.1415926;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
#define vci vector<ll>
#define vcs vector<string>
#define vcp vector<pair<ll, ll>>
#define vct vector<tuple<ll, ll, ll>>
using namespace std;
//vector<vector<ll>> vv(n, vector<ll>(n));
 
typedef int Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}
 
int main()
{
	ll n;
	cin >> n;
	cout << "ABC" << n << endl;
}

Measured memory_bytes: 256
let rec read_int_list len =
	if len <= 0 then []
	else begin
		let n = read_int () in
		n :: read_int_list (len - 1)
	end

let solve max_passenger max_wait_time arrival_times =
	let rec loop bus_count passenger_count first_arrival_time times =
		match times with
		| [] -> bus_count
		| t :: ts ->
			if (passenger_count < max_passenger) && (t <= first_arrival_time + max_wait_time) then
				loop bus_count (passenger_count + 1) first_arrival_time ts
			else
				loop (bus_count + 1) 1 t ts
	in
	let t :: ts = List.sort compare arrival_times in
	loop 1 1 t ts

let () =
	let [n; c; k] =
		read_line ()
		|> Str.split (Str.regexp " ")
		|> List.map int_of_string
	in
	let t = read_int_list n in
	solve c k t
	|> print_int
	|> print_newline


Measured memory_bytes: 11264
#a,bの最大公約数
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

n = int(input())
a = list(map(int,input().split()))

#b[i]:a[0]~a[i]までのgcd,c[i]:a[i]~a[-1]までのgcd
b = [0]*n
c = [0]*n
for i in range(n):
    if i == 0:
        b[0] = a[0]
        c[-1] = a[-1]
        continue
    b[i]=gcd(b[i-1],a[i])
    c[n-1-i]=gcd(c[n-i],a[n-1-i])

res = max(b[n-2],c[1])
for i in range(1,n-1):
    res = max(res,gcd(b[i-1],c[i+1]))
print(res)


Measured memory_bytes: 14428
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>


using namespace std;
#define out(s) cout<<(s)<<endl;
using ll = long long;

int main()
{
	string A, B, C;
	cin >> A >> B >> C;
	char next = 'a';
	while (true) {
		if (next == 'a') {
			if (A.size() == 0)break;
			next = A[0];
			A = A.substr(1);
		}
		else if (next == 'b') {
			if (B.size() == 0)break;
			next = B[0];
			B = B.substr(1);
		}
		else {
			if (C.size() == 0)break;
			next = C[0];
			C = C.substr(1);
		}
	}
	next = toupper(next);
	out(next);
	return 0;
}

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

typedef long long ll;

#define v(T) vector<T>
#define ttt(T) tuple<T, T, T>
#define pb push_back
#define mp make_pair
#define rep(i, s, n) for(int i=s;i<n;i++)
#define repeq(i,s,n) for(int i=s;i<=n;i++)
#define poiu(n) for(int i=0; i < n; i++)
#define MOD (int)10e9+7
#define endl '\n'

template<typename T>
void max_self(T& a, T b) { a=a>b?a:b; }
template<typename T>
void min_self(T& a, T b) { a=a<b?a:b; }

using namespace std;

int n;


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

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

    for(int i=0; i<k; i++) {
        cout << s << ' ';
    }
    if(s==1000000000) {
        for(int i=0; i<n-k;i++) 
            cout << 1 << ' ';
    } else {
        for(int i = 0; i < n-k; i++)
            cout << 1000000000 << ' ';
    }
    cout << endl;
    


    return 0;

}



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

int main()
{
    int i[32] = {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};
    int k;
    std::cin >> k;
    std::cout << i[k - 1] << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF (1ll<<60)
typedef long long ll;
using namespace std;

ll k;
vector<ll> v(10010);

ll upper(ll x, ll a){
    if (x % a == 0){
        return x;
    } else {
        return x - x % a + a;
    }
}

ll downer(ll x, ll a){
    return x - x % a;
}

int main(){
    cin >> k;
    v.resize(k);

    for (ll i = 0; i < k; i++){
        cin >> v[i];
    }
    
    ll left= 2;
    ll right = 2;
    bool flag = true;
    for (ll i = k-1; i >= 0; i--){
        if (upper(left, v[i]) <= right && left <= downer(right, v[i])){
            left = upper(left, v[i]);
            right = downer(right, v[i]) + (v[i] - 1);
        } else {
            flag = false;
            break;
        }
        // cout << left << " " << right << endl;
    }

    if (flag){
        cout << left << " " << right << endl;
    } else {
        cout << -1 << endl;
    }

}

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

int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    int idx = n/2;
    cout << v[idx] - v[idx-1] << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int MAXN=310;
char s[MAXN][MAXN];
int f[MAXN<<1][MAXN<<1];
int n,ans;
int main()
{
	scanf("%d",&n);
	for (int i=0;i<n;i++) scanf("%s",s[i]);
	for (int i=0;i<(n*2-1);i++)
	{
		for (int j=0;j<(n*2-1);j++)
		 {
		 	for (int k=0;k<n&&(i+k<n*2-1)&&(j-k>=0);k++)
		 	if (s[i%n][j%n]!=s[(i+k)%n][(j-k)%n])
		 	{
                 int l,r;
                 l=i+k-n+1; r=j-n+1;
                 if (l<0&&r<0)
                 {
                 	int t=max(abs(l),abs(r)); l+=t; r+=t;
                 }
                 else 
                 if (l<0)
                 {
                       r+=abs(l); l=0;
                 }
                 else if (r<0) {
                 	l+=abs(r); r=0;
                 }
                 f[l][r]++;
                 f[i+1][j-k+1]--;
		 	}
		 }
	}
	for (int i=0;i<(n*2-1);i++)
	{
		for (int j=0;j<(n*2-1);j++) {
			f[i][j]=(i&&j?f[i-1][j-1]:0)+f[i][j];
			if (f[i][j]==0&&i<n&&j<n) ans++; 
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
#include<deque>
#include<cstdio>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*pi*/const double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,i=0;while(n/10>0){i++;d++;}return d;}
llfor;ll ans=0;////////////////////////////////////////////////////////////
int main(){
 ll n;
 cin>>n;
 ll s[n+10];
 rep(i,0,n)scanf("%1lld",&s[i]);
 ll cnt=0;
 ans=0;
 ll k;
 rep(i,0,1000){
  rep(j,0,n){
   if(cnt==0&&s[j]==(i/100)%10){
    cnt++;
    continue;
   }
   if(cnt==1&&s[j]==(i/10)%10){
    cnt++;
    continue;
   }
   if(cnt==2&&s[j]==(i%10)){
    ans++;
   // cout<<i<<" "<<j<<" "<<s[j]<<" "<<i%10<<endl;
    cnt=0;
    break;
   }
  }
  cnt=0;
 }
 pr(ans);
return 0;}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;
const bool debug = 0;
//------------------------------//

int main() {
	int x, a, b;
	cin >> x >> a >> b;
	if (abs(x - a) > abs(x - b)) puts("B");
	else puts("A");
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<typename T>bool chkmax(T &a,T b){
	if(a<b){a=b;return 1;}
	else return 0;
}
template<typename T>T read(){
	T x=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
	for(;isdigit(c);c=getchar())x=(x<<3)+(x<<1)+(c^48);
	return x*f;
}
const int maxn=1<<15;
int n,m,S,sum,ans=2e9,c[15][15],p[maxn],dp[maxn][15];
void init(){
	memset(dp,-1,sizeof dp);
	S=1<<n;
	for(int s=0;s<S;++s)
		for(int i=0;i<n;++i){
			if(((s>>i)&1)==0)continue;
			for(int j=i+1;j<n;++j)
				if((s>>j)&1)p[s]+=c[i][j];
		}
	dp[1][0]=0;
}
void solve(){
	n=read<int>(),m=read<int>();
	for(int u,v,w;m--;){
		u=read<int>()-1;
		v=read<int>()-1;
		w=read<int>();
		c[u][v]=c[v][u]=w;
		sum+=w;
	}
	init();
	for(int s=0;s<S;++s){
		for(int i=0;i<n;++i){
			if(!~dp[s][i])continue;
			int x=((S-1)^s)|(1<<i);
			for(int t=x;~t;--t)
				t&=x,chkmax(dp[s|t][i],dp[s][i]+p[t]);	
			for(int j=0;j<n;++j)if((~(s>>j)&1)&&c[i][j]){
				chkmax(dp[s|(1<<j)][j],dp[s][i]+c[i][j]);
			}
		}
	}
	for(int i=0;i<S;++i)
		ans=min(ans,sum-dp[i][n-1]);
	printf("%d\n",ans);
}
int main(){
	solve();
	
	return 0;
}

Measured memory_bytes: 2304
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<sstream>

using namespace std;

int main()
{
	int num;
	string sent, sub;

	while(cin >> num)
	{
		if(!num) break;
		cin >> sent;
		for(int i = 0; i < num; i++)
		{
			sub.clear();
			int cnt = 1;
			for(int j = 0; j < sent.size(); j++)
			{
				if(sent[j] == sent[j+1])
				{
					cnt++;
				}
				else
				{
					stringstream ss;
					ss << cnt;
					sub += ss.str();
					sub += sent[j];
					cnt = 1;
				}
			}
			sent = sub;
		}
		cout << sent << endl;
	}
}

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


using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  long long n;
  cin >> n;
  int ans = 100;
  for(long long i = 1; i * i <= n; i++){
    if(n % i){
      continue;
    }
    string a = to_string(i), b = to_string(n / i);
    ans = min(ans, max<int>(a.size(), b.size()));
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())
#define mp make_pair

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef pair<int, int> P;
//typedef pair<int, pair<int, int> > PP;
//const int MAX=;



int main(){
	int N;
	cin>>N;
	ll a[50];
	rep(i,N)cin>>a[i];
	
	ll ans=0;
	while(true){
		ll b[50];
		ll s=0;
		rep(i,N){
			b[i]=a[i]/(ll)N;
			s+=b[i];
		}
		ans+=s;
		rep(i,N) a[i]=a[i]%(ll)N+s-b[i];
//      	rep(i,N)cout<<a[i]<<" ";
//      	cout<<endl;
		
		sort(a, a+N);
		if(a[N-1]<N)break;
		if(a[0]>=N){
          	ll t=(a[0]-(ll)N+1);
			ans+=t*(ll)N;
			rep(i,N)a[i]-=t;
		}
//      	rep(i,N)cout<<a[i]<<" ";
//      	cout<<endl;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256