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

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

    vector<vector<bool>> s(h, vector<bool>(w, false));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            char c;
            cin >> c;
            if(c == '#'){
                s[i][j] = true;
            }
        }
    }

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(!s[i][j]){
                continue;
            }
            bool ok = false;
            if(i > 0 && s[i-1][j]){
                ok = true;
            }
            if(j > 0 && s[i][j-1]){
                ok = true;
            }
            if(i < h-1 && s[i+1][j]){
                ok = true;
            }
            if(j < w-1 && s[i][j+1]){
                ok = true;
            }
            if(!ok){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define acc(v) accumulate(v.begin(), v.end(), 0)

using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;

int main()
{
	int n;
	cin >> n;
	cout << 1000 * (n / 500) + 5*(n % 500 / 5) << endl;
}


Measured memory_bytes: 256
import itertools

n,m = map(int,input().split())

k = [list(map(int,input().split())) for i in range(m)]

p = list(map(int,input().split()))

switch = [1,0]
comb = []

for x in itertools.product([1,0], repeat=n):
    comb.append(x)
    
c = 0

for i in range(len(comb)):
    light = 0
    
    for j in range(m):
        temp = 0
        for r in range(k[j][0]):
            if comb[i][k[j][r+1]-1] == 1:
                temp += 1
        
        if temp%2 == p[j]:
            light += 1
    
    if light == m:
        c += 1

print(c)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
      	int n;
      	cin>>n;
    	int a[n],b[n],c[n-1];
      	for(int i=1;i<=n;i++){
        	cin>>a[i];	
        }
      	int bb=0;
      	for(int i=1;i<=n;i++){
        	cin>>b[i];
          	bb+=b[i];
        }
      	for(int i=1;i<=n-1;i++){
        	cin>>c[i];	
        }
      	vector<int>v;
      	for(int i=1;i<=n-1;i++){
        	if(a[i]-a[i+1]==-1)
              	v.push_back(a[i]);
        }
      int vv=0;
      	for(int i=0;i<v.size();i++){
        	int x =v[i];	
          	vv+=c[x];
        }
  	cout<<bb+vv<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
int x,y,t;
char op;
while(scanf("%d %s %d",&x,&op,&y)){
	if(op=='+'){
		t=x+y;
		printf("%d\n",t);
	}
	if(op=='-'){
		t=x-y;
		printf("%d\n",t);
	}
	if(op=='*'){
		t=x*y;
		printf("%d\n",t);
	}
	if(op=='/'){
		t=x/y;
		printf("%d\n",t);
	}
		else if(op=='?'){
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 600
import sys
input = sys.stdin.readline
N, M, V, P = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

ng = -1
ok = N - P
#print(a)
def check(x):
  vs = M * V
  p = N
  for i in range(N):
    if a[i] > a[x] + M:
      p = i - 1
      break
  #print(x, vs, p)
  if p < N - P: return False
  #print(x, vs)
  for i in range(N - P + 1, N):
    vs -= M
  #print(x, vs)
  for i in range(N - P + 1):
    vs -= min(max(a[x] + M - a[i], 0), M)

  #print(x, vs)
  return vs <= 0

while ok - ng > 1:
  m = (ok + ng) // 2
  if check(m):
    ok = m
  else: ng = m
print(N - (ng + 1))

Measured memory_bytes: 58736
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

template <typename T> map<T, int> coordinate_compression(vector<T> x) {
    sort(x.begin(), x.end());
    x.erase(unique(x.begin(), x.end()), x.end());
    map<T, int> res;
    for (int v : x) res[v] = res.size();
    return res;
}

// Binary Indexed Tree
template <class T> struct BIT {
    vector<T> d;
    BIT(int n) { init(n); }
    void init(int n) { d.assign(n + 1, 0); }
    // a: 1-indexed
    inline void add(int a, T x) {
        for (int i = a; i < (int)d.size(); i += i & -i) d[i] = d[i] + x;
    }
    // [1, a]
    // a: 1-indexed
    inline T sum(int a) {
        T res = 0;
        for (int i = a; i > 0; i -= i & -i) res = res + d[i];
        return res;
    }
    // [a, b)
    // a, b: 1-indexed
    inline T sum(int a, int b) {
        return sum(b - 1) - sum(a - 1);
    }
};

void _main() {
    int N, K;
    cin >> N >> K;
    vector<int> a(N), cum(N + 1, 0), v = {0};
    REP (i, N) {
        cin >> a[i];
        cum[i + 1] = cum[i] + a[i];
        v.push_back(cum[i + 1] - K * (i + 1));
    }
    auto cc = coordinate_compression(v);
    BIT<int> bit(cc.size());
    int ans = 0;
    REP (i, v.size()) {
        ans += bit.sum(cc[v[i]]);
        bit.add(cc[v[i]], 1);
    }
    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 19184
x, y = gets.chomp.split(" ").map(&:to_i)
n = (2 * y - x) / 3
m = (2 * x - y) / 3

$MOD = 10 ** 9 + 7

$fact = [1, 1]
$factinv = [1, 1]
$inv = [0, 1]

def comInit()
    max = 10 ** 6
    2.upto(max) do |i|
        $fact << $fact[i-1] * i % $MOD
        $inv << $MOD - $inv[$MOD % i] * ($MOD / i) % $MOD
        $factinv << $factinv[i-1] * $inv[i] % $MOD
    end
end

def com(n, k)
    comInit()
    return 0 if n < k
    return 0 if n < 0 || k < 0
    return $fact[n] * ($factinv[k] * $factinv[n-k] % $MOD) % $MOD
end

if (x+y) % 3 == 0 then
    puts com(n+m, n)
else
    puts 0
end

Measured memory_bytes: 29184
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end()
using namespace std;

int main() {
int N, K, Ans = 0;cin >> N >> K;
vector<int> V(N);

for(int i = 0; i < N; i++){
cin >> V[i];
}
sort(V.begin(), V.end());
for(int i = 0; i < K; i++){
Ans += V[i];}cout << Ans;
}

Measured memory_bytes: 3632
def d_teleporter():
    N, K = [int(i) for i in input().split()]
    A = [int(i) - 1 for i in input().split()]  # 0-origin

    visit_list, visit_dict = list(), dict()
    current_city = 0
    for i in range(min(K, N)):  # N 回移動すればループはわかる
        current_city = A[current_city]
        if current_city in visit_dict:  # ループを検出した
            j = visit_list.index(current_city)  # ここからループ
            current_city = visit_list[j + (K - j - 1) % (i - j)]
            return current_city + 1
        else:
            visit_list.append(current_city)
            visit_dict[current_city] = current_city
    return current_city + 1

print(d_teleporter())

Measured memory_bytes: 32332
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define INF 2e9
#define IMAX 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long llong;

int main()
{
	// AGC039_A
	string S;
	cin >> S;
	llong K;
	cin >> K;

	llong len = S.size();

	llong inarow = 1;
	bool firstFlg = true;
	llong firstinarow = 0;
	llong lastinarow = 0;
	llong total = 0;

	char prev = S[0];
	FOR(idx, 1, len - 1) {
		char c = S[idx];
		if (c == prev) {
			++inarow;
		} else {
			// 途切れたときにtotal足す
			total += inarow / 2;
			if (firstFlg) {
				firstinarow = inarow;
				firstFlg = false;
			}
			// カウントリセット
			inarow = 1;
		}
		prev = c;
	}

	// 末尾
	lastinarow = inarow;
	if (firstFlg) {
		// 単一文字の場合は文字数/2がそのまま答え
		total = K * len / 2;
	} else {
		// 複数文字
		total += inarow / 2;
		total *= K;
		// 最終文字判定
		if (S[0] == S[len - 1]) {
			// 先頭と末尾の連続数が奇数のときだけK-1を足して補正
			if (firstinarow % 2 == 1 && lastinarow % 2 == 1) {
				total += (K - 1);
			}
		}
	}



	cout << total << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll s;
    cin >> s;
    cout << s / 3600 << ':' << (s / 60) % 60 << ':' << s % 60 << endl;
    return 0;
}



Measured memory_bytes: 3096
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
using namespace std;

int n, m,l;
string s;


int main() {
	cin >> n >> m>>l;
	for (int i = 0; i < 10; i++)
	{
		l = n * l - m;
		cout << l << endl;
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define LL long long
using namespace std;

char str[20];

int main() {
	scanf("%s", str);
	int n = strlen(str);
	int sum = 1 << n - 1;
	LL ans = 0;
	for (int i = 0; i < sum; ++i) {
		LL cur = 0;
		for (int j = 0; j < n; ++j) {
			cur = cur * 10 + str[j] - '0';
			if (i & (1 << j)) {
				ans += cur;
				cur = 0;
			}
		}
		ans += cur;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
#include <queue>
#include <cmath>
#include <iomanip>
#include <array>
#include <string>
#include <stack>
#include <cassert>
#include <memory>
#include <random>
#include <fstream>
#include <cfloat>
#include <complex>
using namespace std;
int main() {
	int a, b, c; cin >> a >> b >> c;
	int k; cin >> k;
	while (b <= a) {
		b <<= 1;
		--k;
	}
	while (c <= b) {
		c <<= 1;
		--k;
	}
	if (k >= 0) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
}

Measured memory_bytes: 3628
#include <iostream>

using namespace std;


int main(){
    
    int n;
    int t[100001];
    int sum = 0;
    int m;
    int p[100001];
    int x[100001];
    
    cin >> n;
    
    for(int i = 0; i < n; i++){
        
        cin >> t[i];
        sum += t[i]; // <- 合計時間がすでに格納
    }
    
   
    
    
    cin >> m;
    
    for(int i = 0; i < m; i++){
        int tmp;
        cin >> p[i]; // <- どの問題に効くかを示すキー
        cin >> tmp;
        x[i] = t[p[i] - 1] - tmp; // <- どれだけ短縮されるか
    }
    
     //cout << "test:" << sum << endl;
    
    for(int i = 0; i < m; i++){
        cout << (sum - x[i]) << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
using namespace std;

#define _gp(l) const auto gcu{getchar##l}; const auto pcu{putchar##l}
#ifdef __linux
_gp(_unlocked);
#else
_gp();
#endif
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template<typename T>
#define _HT template<typename H,typename... T>
_T _DEF(T,in,int c){T n{};int m{1};while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_DEF(int,in,){return in<int>(gcu());}
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
_T _SCAN(T &n){int c{gcu()};return c==EOF?false:(n=in<T>(c),true);}
_DEF(bool, scan, int &c){c=gcu();gcu();return c!=EOF;}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_SCAN(string &s){int c;s{};for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=(char)c;}}
_OUT(string s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p{b};T m=n<0?pcu('-'),-1:1;if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _OUT(vector<T> v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
_HT _OUT(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _OUTL(T&&... t){out(move(t)...);outl();}
struct range{int e,b{0},s{1};range(int _b,int _e,int _s):e(_e),b(_b),s(_s){}range(int _b,int _e):e(_e),b(_b){}range(int _e):e(_e){}
	struct it{int v,s;it(int _v,int _s):v(_v),s(_s){}operator int()const{return v;}operator int&(){return v;}int operator*()const{return v;}it& operator++(){v+=s;return *this;}};
	it begin(){return{b, s};}it end(){return{e,s};}};

int main() {
	int n {in()}, m {n + 1}, r {}, t {};
	vector<int> q(m);
	for (int i {}; i < n; i++) {
		q[min(m, in() - 1)]++;
		q[min(m, in())]--;
	}
	for (int i: range(m))
		if ((t += q[i]) >= i)
			r = i;
	outl(r);
}


Measured memory_bytes: 2616
N,A,B,C=gets.chomp.split.map(&:to_i)
l=[]

N.times { l << gets.to_i }
ans = Float::INFINITY
1.upto(4**N-1) do |i|
  t=i
  a,b,c=0,0,0
  a_cnt,b_cnt,c_cnt=0,0,0
  N.times do |j|
    case t&3
    when 0
    when 1
      a += l[j]
      a_cnt+=1
    when 2
      b += l[j]
      b_cnt+=1
    when 3
      c += l[j]
      c_cnt+=1
    end
    t = t >> 2
  end
  if [a,b,c].min > 0
    tmp = (A-a).abs + (a_cnt-1)*10 + (B-b).abs + (b_cnt-1)*10 + (C-c).abs + (c_cnt-1)*10
    ans = tmp if ans > tmp
  end
end

puts ans

Measured memory_bytes: 3836
#include<iostream> 
#include<vector> 
#include<algorithm> 
using namespace std; 
#define lld long long int
#define X 1000000007
#define fast();  ios_base::sync_with_stdio(false); cin.tie(0);
# define rec(i,n) for(int i=0;i<n;i++) 
#define w(t) int t; cin>>t; while(t--)
int main()
{
    fast(); 
    int n,w; 
     cin>>n>>w; 
     lld a[n],b[n]; 
     rec(i,n)
      cin>>a[i]>>b[i]; 
      lld dp[n+1][w+1]; 
       rec(i,n+1)
       rec(j,w+1)
         dp[i][j]=0; 
         
        for(int i=1;i<n+1;i++)
            for(int j=1;j<w+1;j++)
           {  
           if((j-a[i-1])>=0)
   dp[i][j]=max(dp[i-1][j],dp[i-1][j-a[i-1]]+b[i-1]); 
       else 
          dp[i][j]=dp[i-1][j]; 
           }
       cout<<dp[n][w]; 	
	return 0;
}

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

int N, M, Q;

vector<vector<int>> sum;
int buildSumTable(vector<int> L, vector<int> R) {
	sum = vector<vector<int>>(N + 1, vector<int>(N + 1, 0));
	for (int i = 0; i < M; i++)
	{
		sum[L[i]][R[i]]++;
	}

	for (int i = 1; i <= N; i++)
	{
		for (int j = 1; j <= N; j++)
		{
			sum[i][j] += sum[i - 1][j];
			sum[i][j] += sum[i][j - 1];
			sum[i][j] -= sum[i - 1][j - 1];
		}
	}
}

int getSumRange(int L, int R) {
	int ans = sum[R][R] - sum[R][L - 1] - sum[L - 1][R] + sum[L - 1][L - 1];
	return ans;
}

int main() {
	cin >> N >> M >> Q;
	vector<int> L(M);
	vector<int> R(M);
	for (int i = 0; i < M; i++)
	{
		cin >> L[i] >> R[i];
	}
	vector<int> p(Q);
	vector<int> q(Q);
	for (int i = 0; i < Q; i++)
	{
		cin >> p[i] >> q[i];
	}
	buildSumTable(L, R);

	for (int i = 0; i < Q; i++)
	{
		int ans = getSumRange(p[i], q[i]);
		cout << ans << endl;
	}
}


Measured memory_bytes: 5120
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

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


int main(){
	int n,m;
	cin >> n >> m;
	int l[100000],r[100000];
	for(int i=0;i<m;i++){
		cin >> l[i] >> r[i];
	}

	sort(l,l+m);
	sort(r,r+m);

	if(r[0]-l[m-1]>=0){
		cout << r[0]-l[m-1]+1 << endl;
	}else{
		cout << "0" << endl;
	}

	return 0;
}

Measured memory_bytes: 1024
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		int n = int.Parse(Console.ReadLine());
    long answer = long.MaxValue;
		long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);

    for(int i = 1; i <= 100; i++)
    {
      long answerMemo = 0;
      for(int j = 0; j < n; j++)
      {
        answerMemo += (nums[j]-i)*(nums[j]-i);
      }

      answer = Math.Min(answerMemo,answer);
    }

		Console.WriteLine(answer);
	}
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define F first
#define S second
#define pss pair<string,string>
#define pcc pair<char,char>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define piii pair<int,pii>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define vs vector<string>
#define vl vector<ll>
#define vs vector<string>
#define vll vector<pll>
#define vss vector<pss>
#define vcc vector<pcc>
#define MP make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=n-1;i>=0;i--)
#define Very_fast std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int N = 1e5+5;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
inline ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll lowbit(ll x){return (x&-x);}
int n;
int main()
{
	string s;
	cin>>s;
	if(s.size()%2==1)
	{
		puts("No");
		return 0;
	}
	for(int i=0;i<s.size();i+=2)
	{
		if(s[i]=='h'&&s[i+1]=='i')
		{
			
		}
		else{
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
const ll MOD = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1000100;

int N,a,b;
int A[MAXN];
int f2[MAXN];
string S;
int C[MAXN];

bool is2(){
  if (min(C[0]+C[2], C[1]+C[3]))return 0;
  if (C[1])for (int i=0;i<N;++i)--A[i];
  int pp=0;
  int tot=0;
  for(int i=0;i<N;++i){
    if (A[i]==2){
      if (pp==0)tot++;
    }
    pp += f2[N-1-i];
    pp -= f2[i+1];
  }
  if (tot%2==1)return 1;
  return 0;
}

int main(){
  cin>>N>>S;
  for (int i=0;i<N;++i)A[i] = S[i] - '0';
  for (int i=0;i<N;++i)C[A[i]]++;
  ll pp = 0;
  ll tot = 0;
  for (int jump=1;jump<=N;jump*=2)for(int i=jump;i<=N;i+=jump)++f2[i];

  for(int i=0;i<N;++i){
    if (A[i]%2==1){
      if (pp==0)tot++;
    }
    pp += f2[N-1-i];
    pp -= f2[i+1];
  }
  if (tot%2==1){
    cout<<1;
    return 0;
  }
  if (is2()){
    cout<<2;
    return 0;
  }
  cout<<0;
  return 0;
}

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

int main() {
	cout<<setprecision(12);
	int n,k;cin>>n>>k;
	double ans=0;
	double power=1;
	int k2=k;
	while(k2>n){
		k2=(k2-1)/2+1;
		power*=2;
	}
	for(int i=n;i>0;i--){
		if(i>=k){
			ans+=1/double(n);
		}else{
			if(i<k2){
				k2=(k2-1)/2+1;
				power*=2;
			}
			ans+=(1/power)/n;
		}
//		cout<<ans<<' '<<i<<endl;
	}

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

Measured memory_bytes: 256
n = gets.chomp.to_i - 1
ab = 'abcdefghijklmnopqrstuvwxyz'

keta_shikiis = [26, 702, 18278, 475254, 12356630, 321272406, 8353082582, 217180147158, 5646683826134, 146813779479510, 3817158266467286]
#        1000000000000001
ruijos = [141167095653376, 5429503678976, 208827064576, 8031810176, 308915776, 11881376, 456976, 17576, 676, 26]
name = []

keta_index = keta_shikiis.bsearch_index{|v| v > n }
n -= keta_shikiis[keta_index - 1] if keta_index > 0

if n == 0
  puts 'a' * (keta_index + 1)
else
  # p [n, ruijos.length, keta_index, ruijos.length - keta_index - 1]
  ruijos[ruijos.length - keta_index .. -1].each{|r|
    # p [n, r]
    if n < r
      name.push('a')
      next
    end
    dig = n / r
    name.push(ab[dig])
    # p [n, r, dig, name]
    n -= dig * r
  }
  # p n
  name.push(ab[n])

  puts name.join('')
end


Measured memory_bytes: 14288
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;


void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a;
    string s;
    cin >> a >>s;
    if(a>=3200) cout << s;
    else cout <<"red";
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

int N, K;
vector<ll> x, y;
vector<char> c;
vector<vector<int>> imos;

void setrect(int i, int j){
    if(i<0 || j < 0  ) return;

    imos[ max(0, i+1-K) ][ max(0, j+1-K) ]++;
    imos[ max(0, i+1-K) ][ min(2*K, j+1) ]--;
    imos[ min(2*K, i+1) ][ max(0, j+1-K) ]--;
    imos[ min(2*K, i+1) ][ min(2*K, j+1) ]++;
}

void setimos(int a){
    int i = y[a], j = x[a];
    setrect(i, j);
    setrect(i+2*K, j);
    setrect(i+K, j-K);
    setrect(i-K, j-K);
    setrect(i+K, j+K);
    setrect(i-K, j+K);
    setrect(i+2*K, j+2*K);
    setrect(i, j+2*K);
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    cin >> N >> K;
    x.resize(N);
    y.resize(N);
    c.resize(N);
    imos.resize(4*K, vector<int>(4*K, 0));
    rep(i, N) cin >> x[i] >> y[i] >> c[i];

    rep(i, N) if(c[i] == 'W') y[i] += K;
    rep(i, N) { x[i] %= 2*K; y[i] %= 2*K; }

    rep(i, N) setimos(i);

    rep(i, 2*K) repr(j, 1, 2*K) imos[i][j] += imos[i][j-1];
    rep(j, 2*K) repr(i, 1, 2*K) imos[i][j] += imos[i-1][j];
    int ans = 0;
    rep(i, 2*K) rep(j, 2*K) chmax(ans, imos[i][j]);
    cout << ans << endl;

}

Measured memory_bytes: 64640
//Author: Lixiang
#include<stdio.h>
#include<algorithm>
using namespace std;
const int maxn=200001;
struct C{
	int cnt[maxn],N,K;
	void init(){
		scanf("%d%d",&N,&K);
		for(int i=1,t;i<=N;i++)
			scanf("%d",&t),cnt[t]++;
		sort(cnt+1,cnt+maxn);
	}
	void work(){
		int sum=0;
		for(int i=maxn-1,j=1;i>=1&&j<=K;i--,j++)
			sum+=cnt[i];
		printf("%d\n",N-sum);
	}
}sol;
int main(){
	sol.init();
	sol.work();
	return 0;
}


Measured memory_bytes: 896
#include<iostream>
using namespace std;
int main(){
  string s,t; cin >> s >> t;
  int n= s.size();
  for(int i=0;i<n;i++){
    //cout << s << endl;
    char c = *(s.end()-1); // ()ないとバグる.
    s.pop_back();
    //cout << s << endl;
    s.insert(s.begin(),c);
    //cout << s << endl;
    if(s==t){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    vector<int> d(N);
    for (int& x : d) cin >> x;
    sort(d.begin(), d.end());
    int res = d[N / 2] - d[N / 2 - 1];
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
int main()
{
    char ch1[20]="Sunny";
    char ch2[20]="Cloudy";
    char ch3[20]="Rainy";
    char str[20];
    gets(str);
    if(strcmp(str,ch1)==0)
        printf("Cloudy");
    else if(strcmp(str,ch2)==0)
        printf("Rainy");
    else if(strcmp(str,ch3)==0)
        printf("Sunny");


}


Measured memory_bytes: 128
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int[][] s = new int[h][w];
		for (int i = 0; i < h; ++i) {
			char[] S = new char[w];
			S = sc.next().toCharArray();
			for (int j = 0; j < w; ++j) {
				if (S[j] == '#') {
					s[i][j] = 1;
				}
			}
		}
		int[][] map = new int[h - 1][w - 1];
		for (int i = 0; i + 1 < h; ++i) {
			for (int j = 0; j + 1 < w; ++j) {
				if ((s[i][j] + s[i + 1][j] + s[i + 1][j + 1] + s[i][j + 1]) % 2 != 0) {
					++map[i][j];
				}
			}
		}
		int ans = solver(map);
		ans = Math.max(ans, h);
		ans = Math.max(ans, w);
		System.out.println(ans);
	}

	int solver(int[][] map) {
		int h = map.length;
		int w = map[0].length;
		int[][] cum = new int[2][w];
		int ans = 2;
		for (int i = 0; i < h; ++i) {
			for (int j = 0; j < w; ++j) {
				int c = map[i][j];// c==0で使用可能
				if (c == 0) {
					cum[i % 2][j] = (i > 0 ? cum[(i - 1) % 2][j] : 0) + 1;
				} else {
					cum[i % 2][j] = 0;
				}
			}
			ans = Math.max(ans, calc(cum[i % 2], w));

		}
		return ans;
	}

	int calc(int[] cum, int w) {
		int ans = 2;
		ArrayDeque<List<Integer>> stack = new ArrayDeque<>();
		for (int j = 0; j < w; ++j) {
			ans = Math.max(ans, cum[j]);
			int d = j;
			while (!stack.isEmpty() && (cum[j] == 0 || stack.peekLast().get(0) > cum[j])) {
				List<Integer> pair = stack.pollLast();
				ans = Math.max(ans, (pair.get(0) + 1) * (j - pair.get(1) + 1));
				d = Math.min(d, pair.get(1));
			}
			if (cum[j] == 0)
				continue;
			stack.addLast(Arrays.asList(cum[j], d));
		}
		while (!stack.isEmpty()) {
			List<Integer> pair = stack.pollLast();
			ans = Math.max(ans, (pair.get(0) + 1) * (w - pair.get(1) + 1));
		}
		return ans;
	}

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

Measured memory_bytes: 158380
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
typedef vector<LL> VEC;
typedef vector<VEC> VVEC;
typedef  pair<LL,LL> P;


const LL INF=1<<30;
const LL MOD=1000000007;




int main(){
    string s;
    cin>>s;
    int ans=0;
    for(int i=0;i<s.size();++i){
        if (s[i] == 'A' || s[i] == 'T' || s[i] == 'G' || s[i] == 'C')
            {
                int j = i;
                int sum = 0;
                while((s[j]=='A'||s[j] == 'T'||s[j] == 'G'||s[j] == 'C')&&j<s.size())
                {
                    j++;
                    sum++;
                    i++;
                }
                ans=max(ans,sum);
    }


    
}
    cout<<ans<<endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); ++i)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define INF 1e9

void init()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
}

int main()
{
    init();
    int A,B,C,k;
    int a,b,c;
    cin>>A>>B>>C;
    cin>>k;
    int flag=0;
    for(int i=0;i<pow(3,k);i++){
        a=A;b=B;c=C;
        int temp=i;
        for(int j=0;j<k;j++){
            if(temp%3==0)a*=2;
            if (temp % 3 == 1)b *= 2;
            if (temp % 3 == 2)c *= 2;
            temp/=3;
        }
        if(a<b&&b<c){
            cout<<"Yes"<<endl;
            flag=1;
            return 0;
        }
    }
    if(flag==0)cout<<"No"<<endl;

}


Measured memory_bytes: 4056
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <sstream>
#include <tuple>
#include <vector>

using namespace std;
using namespace chrono;

#ifdef DEBUG
	#define LOCAL_INPUT_FILE
#else
	//~ #define USE_FILE_IO
#endif

#ifdef USE_FILE_IO
	#define INPUT_FILE "input.txt"
	#define OUTPUT_FILE "output.txt"
	#define cin ____cin
	#define cout ____cout
	ifstream cin(INPUT_FILE);
	ofstream cout(OUTPUT_FILE);
#else
	#ifdef LOCAL_INPUT_FILE
		#define cin ____cin
		ifstream cin("input.txt");
	#endif
#endif

const int infinity = (int)1e9 + 42;
const int64_t llInfinity = (int64_t)1e18 + 256;
const int mod = 998'244'353; 
const long double eps = 1e-8;

mt19937_64 randGen(system_clock().now().time_since_epoch().count());

inline void raiseError(string errorCode) {
	cerr << "Error : " << errorCode << endl;
	exit(42);
}

inline int64_t d2m(int64_t a) {
	if (a % 2 != 0) a += mod;
	return a/2;
}

inline void konvolve(vector<int64_t> &v, int l, int r, bool inv) {
	if (l == r) {
		return;
	}
	int m = (l + r) / 2;
	assert(m-l+1 == r-m);
	for (int i = l, j = m+1; i <= m; ++i, ++j) {
		int64_t x = v[i], y = v[j];
		if (inv) {
			v[i] = d2m((x+y) % mod);
			v[j] = d2m((x-y+mod) % mod);
		} else {
			v[i] = (x+y) % mod;
			v[j] = (x-y+mod) % mod;
		}
	}
	konvolve(v, l, m, inv);
	konvolve(v, m+1, r, inv);
}

signed main() {
	#ifndef USE_FILE_IO
		ios_base::sync_with_stdio(false);
	#endif
	int n; cin >> n;
	
	const int64_t pw = (int64_t)1e18 % mod;
	vector<int64_t> ps(n+1);
	ps[0] = pw;
	for (int i = 1; i <= n; ++i) {
		ps[i] = ps[i-1] * pw % mod;
	}
	
	int k = 1;
	while (k < n) k *= 2;
	
	auto graph = [&]() {
		int m; cin >> m;
		
		vector< vector<int> > g(n);
		set<int, greater<> > avail;
		for (int i = 0; i < m; ++i) {
			int a, b; cin >> a >> b; --a; --b;
			g[a].push_back(b);
			g[b].push_back(a);
		}
		for (int i = 0; i < n; ++i) {
			avail.insert(i);
		}
		
		vector<int64_t> res;
		vector<char> used(n, false);
		while (!avail.empty()) {
			set<int, greater<> > navail;
			int64_t ans = 0;
			for (int i : avail) {
				if (used[i]) {
					navail.insert(i);
					continue;
				}
				for (int j : g[i]) {
					used[j] = true;
				}
				ans += ps[i];
				ans %= mod;
			}
			res.push_back(ans);
			for (int i : avail) {
				if (navail.count(i)) continue;
				for (int j : g[i]) {
					used[j] = false;
				}
			}
			avail = navail;
		}
		
		res.resize(k, 0);
		konvolve(res, 0, k-1, false);
		return res;
	};
	
	auto a = graph();
	auto b = graph();
	auto c = graph();
	for (int i = 0; i < k; ++i) {
		a[i] *= b[i] * c[i] % mod;
		a[i] %= mod;
	}
	konvolve(a, 0, k-1, true);
	cout << a[0] << endl;
	
	return 0;
}


Measured memory_bytes: 15132
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.A
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadLong();
            while (N > 0)
            {
                N -= 1000;
            }
            return N * -1;
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 27448
#include <iostream>
#include <string>
#include<iomanip>
#include <algorithm>
#include <map>
#include <vector>
#include<queue>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include <map>
#include<string.h>
#include<sstream>
#include<stack>
#include <iostream>
#define ll long long
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 2e5 + 5, inf = 1e9 + 7;
const double ep = 0.0000000001;
const double pi = 3.14159265359;
ll fact[N], inv[N];
ll fp(ll x, ll y)
{
	if (!y)
		return 1;
	ll res = fp(x, y / 2);
	res = (res*res) % inf;
	if (y & 1)
		return (res*x) % inf;
	return res;
}
void calc()
{
	fact[0] = inv[0] = 1;
	for (int i = 1; i < N; i++)
	{
		fact[i] = (fact[i - 1] * i) % inf;
		inv[i] = fp(fact[i], inf - 2)%inf;
	}
}
ll ncr(ll n, ll r)
{
	return (((fact[n] * inv[n - r]) % inf)*inv[r])%inf;
}
 
	ll n,arr[1000005],sum1=0,k,sum2=0;
int main() {
	calc();
	cin >> n>>k;
	for (int i = 0; i < n; ++i) {
		cin >> arr[i];
	}
	sort(arr, arr + n,greater<ll>());
	for (int i = 0; i < n; ++i) {
	if (n - (i + 1) < k - 1)
			break;
	    ll  p = ((arr[i] % inf) * ((ncr(n - (i + 1), k - 1)) % inf)) % inf;
		sum1=(sum1%inf) +p;
 
	}
	sort(arr, arr + n);
	for (int i = 0; i < n; ++i) {
		if (n -(i+1) < k - 1)
			break;
		sum2 =(sum2%inf) +((arr[i]%inf) * ((ncr(n -(i+1), k - 1))%inf))%inf;
	} 
ll ans = sum1 -sum2;
while(ans<0) ans+=inf;
	cout << (ans)%inf;
	return 0;
 
}
 

Measured memory_bytes: 4352
def main():
    N = int(input())

    S = []
    for _ in range(N):
        x, l = map(int, input().split())
        S.append([x-l, x+l])
    S.sort(key=lambda x:x[1])

    r = -10**10
    ans = 0
    for s in S:
        if s[0] >= r and s[1] >= r:
            r = s[1]
            ans += 1

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 21380
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    const double PI=acos((double)-1);
    const double eps=1e-14;
    vector<pair<double, pair<int,int> > > z(n);
    int i,j;
    for(i=0; i<n; i++) {
        int x,y;
        scanf("%d%d", &x, &y);
        double t=0;
        if(x!=0 || y!=0) {
            t=atan2((double)y,(double)x);
            if(t<-PI+eps) t+=2*PI;
        }
        z[i]=make_pair(t, make_pair(x,y));
    }
    sort(z.begin(), z.end());

    vector<double> sx(n+1,0), sy(n+1,0);
    for(i=0; i<n; i++) {
        sx[i+1]=sx[i]+z[i].second.first;
        sy[i+1]=sy[i]+z[i].second.second;
    }

    vector<double> args;
    args.push_back(-PI-eps*2);
    for(i=0; i<n; i++) {
        double tmp=z[i].first;
        args.push_back(tmp);
        args.push_back(tmp>=0? tmp-PI: tmp+PI);
    }
    args.push_back(PI+eps*2);
    
    double ans=0;
    for(i=0; i<(int)args.size(); i++) {
        j=lower_bound(z.begin(),z.end(),make_pair(args[i]-eps, make_pair(0,0)))-z.begin();
        int k=lower_bound(z.begin(),z.end(),make_pair(args[i]+PI-eps, make_pair(0,0)))-z.begin();
        double sumx=sx[k]-sx[j];
        double sumy=sy[k]-sy[j];
        double ans0=sumx*sumx+sumy*sumy;
        ans=MAX(ans,ans0);

        sumx=sx[n]-sumx;
        sumy=sy[n]-sumy;
        ans0=sumx*sumx+sumy*sumy;
        ans=MAX(ans,ans0);
    }
    printf("%.16lf\n", sqrt(ans));

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi 2*acos(0.0)
#define f first
#define s second
#define pb push_back
#define gap ' '
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mod 1000000007
#define N 100005
int n;
vector<int> g[N];
ll dp[N][3];
ll solve(int u,int p,int t)
{
    if(dp[u][t]!=-1) return dp[u][t];
    dp[u][t]=1;
    if(t==0)
    {
        for(int v : g[u])
        {
            if(v==p) continue;
            dp[u][t]=(dp[u][t]*(solve(v,u,0)+solve(v,u,1))%mod)%mod;
        }
    }
    else{
        for(int v : g[u])
        {
            if(v==p) continue;
            dp[u][t]=(dp[u][t]*solve(v,u,0))%mod;
        }
    }
    return dp[u][t]%mod;
}
int main()
{
    cin>>n;
    for(int i=1;i<n;i++)
    {
        int u,v;
        cin>>u>>v;
        g[u].pb(v);
        g[v].pb(u);
    }
    memset(dp,-1,sizeof dp);
    cout<<(solve(1,-1,0)+solve(1,-1,1))%mod<<endl;
}


Measured memory_bytes: 19712
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    while(cin >> n >> m && n && m){
        vector<vector<int>> p(n, vector<int>(m));
        for(int i = 0; i < m; i++){
            for(int j = 0; j < n; j++){
                cin >> p[j][i];
            }
        }
        int ans = 0;
        for(auto&& i : p){
            ans = max(ans, accumulate(begin(i), end(i), 0));
        }
        cout << ans << "\n";
    }
}


Measured memory_bytes: 3264
n = int(input())
li = [(list(map(int,input().split()))) for _ in range(n-1)]

for i in range(n-1):
    tm = 0 #時刻を表す
    for j in range(i,n-1):
        if tm < li[j][1]: #開通していない
            tm = li[j][1]
        elif tm%li[j][2] != 0: #発車していない
            tm += li[j][2]-(tm%li[j][2])
        else:
            pass

        tm += li[j][0]

    print(tm)
print(0)


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

#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;

typedef long long ll;
const ll MOD=1e9+7;
using pear = pair<int,int>;

int main(){
  int n; cin>>n;
 int ans = 0,min = n+1;
 rep(i,n){
     int now; cin>>now;
     if(now< min){
         ans++;
         min = now;
     }
 }
 cout<<ans<<endl;
}


Measured memory_bytes: 256
import copy
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
cost = 0
for i in range(n+1):
    cost += abs(a[i]-a[i+1])
for i in range(1, n+1):
    ans = copy.deepcopy(cost)
    if a[i-1] <= a[i] and a[i+1] <= a[i]:
        ans -= 2*abs(a[i]-max(a[i-1], a[i+1]))
    elif a[i-1] >= a[i] and a[i+1] >= a[i]:
        ans -= 2*abs(a[i]-min(a[i-1], a[i+1]))
    print(ans)

Measured memory_bytes: 92916
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  int A[a][b];
  for(int i = 0; i< a;i++){
      for(int j = 0; j < b;j++){
          cin >> A[i][j];
      }
  }
  int B[b];
  for(int i = 0; i< b;i++){
      cin >> B[i];
  }
  
  for(int i = 0; i<a;i++){
      int count=0;
      for(int j = 0; j < b;j++){
           count += A[i][j] * B[j];
      }
      cout << count << endl;
  }
}


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

using namespace std;

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    vector<int> le, ri;
    for (int i = 0; i < n; i++) {
        int a;
        scanf("%d", &a);
        if (a < 0) le.push_back(-a);
        else ri.push_back(a);
    }
    sort(le.begin(), le.end());
    sort(ri.begin(), ri.end());

    int res = 2000000000;
    for (int i = 0; i <= k && i <= le.size(); i++) {
        int j = k-i;
        if (ri.size() < j) continue;
        int l = 0;
        if (i > 0) l = le[i-1];
        int r = 0;
        if (j > 0) r = ri[j-1];
        res = min(res, min(l, r) + l + r);
    }
    printf("%d\n", res);
}

Measured memory_bytes: 1020
#include<bits/stdc++.h>
#define ll long long int
#define loop(i,a,b) for(i=a;i<b;i++)
#define mod 1000000007
#define pb push_back
#define lim 100001

using namespace std;
int main()
{
	ll a[5],i;
	loop(i,0,5) cin>>a[i];

	loop(i,0,5) if(!a[i])
	break;
	cout<<i+1<<endl;
	return 0;


}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define MMOD(i) ((i%MOD)+MOD)%MOD;
#define all(v) v.begin() , v.end()
#define vec(i,j) vector<vector<ll>>(i,vector<ll>(j,0))
const ll INF=99999999999999;
const ll MOD=1000000007;
const ll MAX_N=100010;
ll a,b,c,d,e,f,x,y,z,k,m,n,l,h,w,t,ans=0,sum;
vp p;
string s;
ll solve(){
    x=0;
    rep(i,n){
        x+=p[i].second;
        //cout<<x<<" "<<p[i].first<<endl;
        if(x>p[i].first)return 0;
    }
    return 1;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    rep(i,n){
        cin>>a>>b;
        p.emplace_back(b,a);
    }
    sort(all(p));
    if(solve()==1){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    
}

Measured memory_bytes: 6512
#include<bits/stdc++.h>
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n+1];
     int dp[n+1];
    for(int i=0;i<=n;i++)
    dp[i]=1000000007;
    for(int i=1;i<=n;i++)
     cin>>a[i];
    dp[1]=0;
   dp[2]=abs(a[1]-a[2]);
    if(n==2)
    {cout<< dp[2]<<endl;return 0;}
    for(int i=3;i<=n;i++)
     {
         for(int j=i-2;j<i;j++)
          dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
     }
     cout<<dp[n]<<endl;
}

Measured memory_bytes: 1024
I, O, T, J, L, S, Z = map(int, raw_input().strip().split())

ans = O
ans += 2*(I/2)
ans += 2*(J/2)
ans += 2*(L/2)

if (I % 2 == 1) and (J % 2 == 1) and (L % 2 == 1):
  ans += 3
elif (I % 2 == 1) and (J % 2 == 1) and L > 0:
  ans += 1
elif (I % 2 == 1) and (L % 2 == 1) and J > 0:
  ans += 1
elif (J % 2 == 1) and (L % 2 == 1) and I > 0:
  ans += 1

print ans

Measured memory_bytes: 2568
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
for i in range(-1,-n-1,-1):
  if b[i]>=a[i]:
    if a[i-1] - (b[i] - a[i]) >= 0:
      a[i-1] = a[i-1] - (b[i] - a[i])
      ans += b[i]
    else:
      ans += a[i]+a[i-1]
      a[i-1] = 0
  else:
    ans += b[i]
print(ans)

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

int main() {
   char n[4];
   cin >> n;
   
   for(int bit = 0;bit < (1 << 3);bit++) {
      ll a = n[0] - '0';
      rep(i, 3) {
         if(bit & (1<<i)) {
            a += n[i+1]- '0';
         }else {
            a -= n[i+1] - '0';
         }
         
      }
      if(a == 7) {
         cout << n[0] - '0';
         rep(i,3) {
            if(bit & (1<<i)) {
               cout << "+";
               cout << n[i+1] - '0';
            }else {
               cout << "-";
               cout << n[i+1] - '0';
            }
         }
         cout << "=" << 7 << endl;
         return 0;
      }
   }
}


Measured memory_bytes: 3644
import Data.IntMap.Lazy (IntMap,fromSet,(!))
import qualified Data.IntSet as IntSet
import Data.Ix
import Data.Function

import Debug.Trace

main :: IO()
main = do
    _ <- getLine
    lrs <- getContents
    mapM_ (print . countRange . map read . words) (lines lrs)
        where
            countRange [l,r]
                | l <= r = memocount r - memocount (l - 1)
                | otherwise = 0
            memocount :: Int -> Int
            memocount = ((fromSet count $ IntSet.fromList [0..100000]) !)
                where
                    count 0 = 0
                    count 1 = 0
                    count n = (if is2017Like n then 1 else 0) + memocount (n - 1)
            is2017Like 2 = False
            is2017Like 3 = True
            is2017Like n = mod n 4 == 1 && isPrime n && isPrime ((n + 1) `div` 2)
            isPrime n = null [i | i <- takeWhile (\x -> x * x <= n) primes, mod n i == 0]
            primes = 2 : 3 : primes'
                where
                    primes' = 5 : f 1 7 primes'
                    f m s (p : ps) = [n | n <- ns, gcd m n == 1] ++ f (m * p) (p * p) ps
                        where ns = [x + y | x <- [s, s + 6 .. p * p - 2], y <- [0, 4]]


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

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

using S = ll;
S op(S a, S b) {
  return max(a, b);
}
S e() {
  return 0;
}

void solve(long long N, long long K, std::vector<long long> A) {
  atcoder::segtree<S, op, e> seg(300010);
  REP(i, N) {
    auto x = seg.prod(max(0ll, A[i] - K), min(300005ll, A[i] + K + 1));
    seg.set(A[i], x + 1);
  }
  cout << seg.all_prod() << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, K, std::move(A));
  return 0;
}


Measured memory_bytes: 16256
#include <iostream>

using namespace std;
#define int long long

signed   main()
{
    int n , a , b , c , d;
    cin >> n >> a >> b >> c >> d;
    a = abs(a-b);
    b = 0;
    for(int i = 0; i <= n; i ++) {
        int l = a + c*i , r = a + d*i;
        int l1 = b + c*(n-i-1) , r1 = b + d*(n-i-1);
        if(l <= l1 && l1 <= r) {
            cout << "YES";
            return 0;
        }
        if(l <= r1 && r1 <= r) {
            cout << "YES";
            return 0;
        }
    }
    cout << "NO";
    return 0;
}


Measured memory_bytes: 256
package main

import (
    "fmt"
)

func main(){
    // Your code here!
    
    var a ,b int
    fmt.Scan(&a)
    fmt.Scan(&b)

    ans := ""
    
    if a*b%2 == 0{
        ans = "No"
    } else {
        ans = "Yes"
    }
    
    fmt.Println(ans)
}


Measured memory_bytes: 512
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

h=ii()
num = 1
cnt=0
while h >0:
    if h >1:
        h = floor(h/2)
        cnt+=num
        num*=2
    else:
        h-=1
        cnt+=num

print(cnt)
        
    


Measured memory_bytes: 65388