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

int main(void) {
    int a,b,k;

    cin >> a >> b >> k;

    for(int i=a; i<= min(b, a+k-1) ; i++) cout << i << endl;
    for(int i = max(b-k+1, a+k); i<=b ; i++) cout << i << endl;

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func scanInts(n int) []int {
	sl := make([]int, n)
	for i := range sl {
		sl[i] = scanInt()
	}
	return sl
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	a, b := scanInt(), scanInt()
	var cnt int
	for i := a; i <= b; i++ {
		if i < 0 {
			cnt++
		}
		if i == 0 {
			fmt.Println("Zero")
			return
		}
		if i > 0 {
			break
		}
	}
	if cnt%2 == 0 {
		fmt.Println("Positive")
	} else {
		fmt.Println("Negative")
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}


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

int main()
{
ll n , m ;
cin >> n >> m ;
vector<ll> a(n);
rep(i, n){
  cin >> a[i];
}
vector<ll> b(m);
rep(i, m){
  cin >> b[i];
}
sort(a.rbegin(),a.rend());
sort(b.rbegin(),b.rend());
rep(i,n-1)if(a[i]==a[i+1])ans=0;
rep(i,m-1)if(b[i]==b[i+1])ans=0;
a.push_back(-1);
b.push_back(-1);
if(a[0]!=n*m||b[0]!=n*m)ans=0;
ll in=0,im=0;
for (ll i = n*m; i > 0; i--)
{
  while(i<a[in]&&in!=n)in++;
  while(i<b[im]&&im!=m)im++;
  if(a[in]==i&&b[im]==i)continue;
  else if(a[in]==i)ans=(ans*im)%mo;
  else if(b[im]==i)ans=(ans*in)%mo;
  else{
    if(in*im-n*m+i<=0)ans=0;
    else ans=(ans*(in*im-n*m+i))%mo;
  }
}

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

Measured memory_bytes: 384
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt

getInt = readInt <$> BS.getLine

main = do
  n <- getInt
  let ns = show n
  let l = length ns
  if l == 1
    then print n
    else do
      let d = read [(head ns)] :: Int
      let m = (n + 1) `mod` 10
      if m == 0
        then print $ (l -1) * 9 + d
        else print $ (l -1) * 9 + (d - 1)


Measured memory_bytes: 3932
#include <iostream>
#include <vector>
#include <string.h>

using namespace std;
typedef pair<int, int> P;
bool field[21][21];

void solve()
{
	int N;
	while(cin >> N, N)
	{
		memset(field, 0, sizeof(bool) * 21 * 21);
		vector<P> Vec(N);
		for(int i = 0; i < N; ++i)
		{
			cin >> Vec[i].first >> Vec[i].second;
		}
		int M;
		cin >> M;
		P pos;
		pos.first = 10;
		pos.second = 10;
		char str;
		int move;
		for(int i = 0; i < M; ++i)
		{
			cin >> str >> move;
			switch(str)
			{
				case 'N': for(int j = 0; j < move; ++j)
						  {
							  ++pos.second;
							  field[pos.first][pos.second] = true;
						  }break;
				case 'E': for(int j = 0; j < move; ++j)
						  {
							  ++pos.first;
							  field[pos.first][pos.second] = true;
						  }break;
				case 'S':for(int j = 0; j < move; ++j)
						  {
							  --pos.second;
							  field[pos.first][pos.second] = true;
						  }break;
				case 'W': for(int j = 0; j < move; ++j)
						  {
							  --pos.first;
							  field[pos.first][pos.second] = true;
						  }break;
			}
		}
		bool flag = true;
		for(int i = 0; i < N; ++i)
		{
			if(field[Vec[i].first][Vec[i].second] == false)
			{
				flag = false;
				break;
			}
		}
		if(flag)
		{
			cout << "Yes" << endl;
		}
		else
		{
			cout << "No" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
#include <iostream>
#include<stdio.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<tuple>
#include<bitset>

#define MOD 1000000007
using namespace std;

int main()
{
	int N;	cin >> N;
	vector<pair<long long int,long long int>> val(N);
	vector<long long int> dx(N * (N - 1) / 2);
	vector<long long int> dy(N * (N - 1) / 2);

	int x, y;
	for (int i = 0; i < N; i++)
	{
		cin >> x >> y;
		val[i] = make_pair(x, y);
	}

	sort(val.begin(), val.end());	//x座標でソート


	int cnt = 0;
	for (int i = 0; i < N; i++)
	{
		for (int j = i + 1; j < N; j++)
		{
			dx[cnt] = val[j].first - val[i].first;
			dy[cnt] = val[j].second - val[i].second;
			cnt++;
		}
	}

	vector<long long int> xzahyo(N);
	vector<long long int> yzahyo(N);
	for (int i = 0; i < N; i++)
	{

		xzahyo[i] = val[i].first;
		yzahyo[i] = val[i].second;

	}


	int ans = 0;


	for (int j = 0; j < dx.size(); j++)
	{
		int count = 0;
		for (int i = 0; i < N; i++)
		{
			long long int x = xzahyo[i];
			long long int y = yzahyo[i];
			for (int k = 0; k < N; k++)
			{
				if ((x + dx[j]) == xzahyo[k] && y + dy[j] == yzahyo[k])	count++;
			}
		}
		ans = max(ans, count);
	}

	cout << (N - ans);
	return 0;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"
int main()
{
	int i,n,q,c=0;
	cin>>n>>q;
	string s;
	cin>>s;
	vi p(n+3);
	p[0] = 0;
	p[1] = 0;
	for(i=0; i<n ; i++){
		if(s[i-1]=='A' && s[i] == 'C') c++;
		p[i+1] = c;
		}
	//for0(i,n+1) cout<<p[i]<<nw;
	while(q--){
		int l,r,c=0;
		cin>>l>>r;
		cout<<p[r] - p[l]<<nw;
		}
	
	return 0;
}

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


signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    cout << fixed << setprecision(20);

    int n,m;
    cin>>n>>m;
    int k[n];
    vector<vector<double>> s(n),h(n);
    for(int i=0;i<n;i++){
        cin>>k[i];
        for(int j=0;j<k[i];j++){
            int a,b;
            cin>>a>>b;
            s[i].push_back(a);
            h[i].push_back(b);
        }
    }

    double totori[n][m+1]={};
    for(int i=0;i<n;i++){
        int now = 0;
        double he = 0;
        for(int j=1;j<=m;j++){
            totori[i][j] = totori[i][j-1] + 1.0/s[i][now];
            he += 1.0/s[i][now];
            if(abs(he - h[i][now]) < 0.01){
                now++;
                he=0;
            }
            if(now == k[i]){
                for(int l=j+1;l<=m;l++){
                    totori[i][l] = totori[i][j];
                }
                break;
            }
        }
    }

    // //debag
    // for(int i=0;i<n;i++){
    //     for(int j=0;j<=m;j++){
    //         cout<<totori[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    double dp[n+1][m+1]={};
    for(int i=0;i<n;i++){
        for(int now=0;now<=m;now++){
            for(int use=0;use+now<=m;use++){
                dp[i+1][use+now] = max(max(dp[i][use+now],dp[i+1][use+now]),dp[i][now] + totori[i][use]);
            }
        }
    }
    double ans=0;
    for(int i=0;i<=m;i++){
        ans = dp[n][i];
    }
    //cout << ans << endl;
    cout << dp[n][m] << endl;
}


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

// #define multitest 1
// #define Debug 1
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif

typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;

const int nax = 1e5 + 10;
ll dp[nax];

template <typename T>
void add_self(T &a, T b)
{
	a += b;
	a += mod;
	a %= mod;
}

void solve()
{
	int n, k, x;
	cin >> n >> k;
	dp[0] = 1;
	for (int i = 0; i < n; ++i)
	{
		cin >> x;
		vector<ll> fake(k + 1);
		for (int used = k; used >= 0; --used)
		{
			ll temp = dp[used];
			int l = used + 1;
			int r = used + min(x, k - used);
			if (l <= r)
			{
				add_self(fake[l], temp);
				if (r + 1 <= k)
					add_self(fake[r + 1], -temp);
			}
		}
		ll sum = 0;
		db("here",k);
		for (int i = 0; i <= k; ++i)
		{
			db("Hi");
			add_self(sum, fake[i]);
			add_self(dp[i], sum);
			db(dp[i], i);
		}
	}
	cout << dp[k];
}

int main()
{
#ifndef Debug
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	while (t--)
		solve();
	return 0;
}

Measured memory_bytes: 1792
import sys
s = input()
while len(s)>7:
    if s[:6]=="dreamd":
        s = s.replace("dream","",1)
        continue
    if s[:6]=="erased":
        s = s.replace("erase","",1)
        continue
    if s[:6]=="eraser":
        s = s.replace("eraser","",1)
        continue
    if s[:6]=="erasee":
        s = s.replace("erase","",1)
        continue
    if s[:8]=="dreamerd":
        s = s.replace("dreamer","",1)
        continue
    if s[:8]=="dreamera":
        s = s.replace("dream","",1)
        continue
    if s[:8]=="dreamere":
        s = s.replace("dreamer","",1)
        continue
    break
if s in ["dream","dreamer","erase","eraser"]:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n;
    cin >> n;
    vector <int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(all(a));
    
    vector <ii> ans;
    for (int i = 1; i < n - 1; ++i) {
        if (a[i] >= 0) {
            ans.app(mp(a[0], a[i]));
            a[0] -= a[i];
        }
    }   
    ans.app(mp(a.back(), a[0]));
    a.back() -= a[0];
    for (int i = 1; i < n - 1; ++i) {
        if (a[i] < 0) {
            ans.app(mp(a.back(), a[i]));
            a.back() -= a[i];
        }   
    }   
    
    cout << ans.back().f - ans.back().s << endl;
    for (auto e : ans)
        cout << e.f << ' ' << e.s << endl;
}

Measured memory_bytes: 4336
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
void ABC70(void);
void ABC71(void);
void ABC72(void);
void ABC73(void);
void ABC74(void);
void ABC75(void);
void ABC76(void);
void ABC77(void);
void ABC78(void);
void ABC79(void);

int main(void){
    ABC70();
}

void ABC70(){
    int a,b,c,d,ans;
    cin>>a>>b>>c>>d;
    ans=min(b,d)-max(a,c);
    if(ans>0)cout<<ans<<endl;
    else cout<<0<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define loop(i,a,b) for(i=a;i<b;i++)
#define max_size 100
#define pb push_back
using namespace std;

int main()
{ll n,m,k,i;
  cin>>n>>m>>k;
  ll a[n],b[m];

  vector<ll> v;

  loop(i,0,n) cin>>a[i];

  ll s=0;
  v.pb(0);

  loop(i,0,m) {cin>>b[i];s+=b[i];
    v.pb(s);

  }
   s=0;auto it=upper_bound(v.begin(),v.end(),k);it--;
   ll ans=it-v.begin();

  loop(i,0,n) {

    k-=a[i];
    if(k<0) break;

    auto it=upper_bound(v.begin(),v.end(),k);it--;
    ans=max(ans,i+1+(ll)(it-v.begin()));

  }

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

Measured memory_bytes: 8208
#include <bits/stdc++.h>
using namespace std; 
int N, K; 
vector<int> E[100010]; 
int D[100010]; 
int mn[100010]; int mx[100010]; 
int INF = 1145141919; 
int ans[100010] = {}; 
void dfs1(int now, int parent, int dist){
	D[now] = dist; 
	for(int i = 0; i < E[now].size(); i++){
		if(E[now].at(i) == parent) continue; 
		dfs1(E[now].at(i), now, dist + 1); 
	}
}
void dfs2(int now, int parent){
	int m = -INF; int M = INF;
	for(int i = 0; i < E[now].size(); i++){
		if(E[now].at(i) == parent) continue; 
		dfs2(E[now].at(i), now); 
		m = max(m, mn[E[now].at(i)]); 
		M = min(M, mx[E[now].at(i)]); 
		mn[now] = max({-INF, m - 1, mn[now]}); 
		mx[now] = min({INF, M + 1, mx[now]}); 
	}	
}
void dfs3(int now, int parent, int value){
	if(!ans[now]) ans[now] = value;
	for(int i = 0; i < E[now].size(); i++){ 
		if(E[now].at(i) == parent) continue;
		if(value - 1 >= mn[E[now].at(i)] && value - 1 <= mx[E[now].at(i)]){
			dfs3(E[now].at(i), now, value - 1); 
		}
		else dfs3(E[now].at(i), now, value + 1);  
	}	
}
int main(){
	cin >> N; 
	for(int i = 0; i < N-1; i++){
		int a, b; cin >> a >> b;  
		a--; b--; 
		E[a].push_back(b); 
		E[b].push_back(a); 
	}
	fill(mn, mn + N, -INF); 
	fill(mx, mx + N, INF); 
	dfs1(0, -1, 0); 
	cin >> K; 
	int odd = 0; int even = 0; 
	for(int i = 0; i < K; i++){
		int v, p; cin >> v >> p; 
		v--; 
		mn[v] = p; mx[v] = p; 
		if(abs(D[v] - p) % 2) odd ++; 
		else even ++; 
		ans[v] = p; 
	}
	if(odd != 0 && even != 0){
		cout << "No" << endl; return 0; 
	}
	dfs2(0, -1); 
	for(int i = 0; i < N; i++){
		if(mn[i] > mx[i]){
			cout << "No" << endl; return 0; 
		}
	}
	cout << "Yes" << endl; 
	dfs3(0, -1, mn[0]); 
	for(int i = 0; i < N; i++) cout << ans[i] << endl; 
}

Measured memory_bytes: 15744
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;



int main(void) {
    ll N, K;
    cin >> N >> K;
    ll a[MAX];
    ll i, j;
    ll cnt[44]={};
    
    for(i=0; i<N; i++) {
        cin >> a[i];
        
        for(j=0; j<40; j++) {
            if(1&a[i]>>j) cnt[j]++;
        }
    }
    
    ll ans=0;
    for(j=-1; j<40; j++) {
        if(j!=-1 && !(1&K>>j)) continue;
        
        ll mask=(K>>(j+1))<<(j+1);
        for(i=0; i<j; i++) {
            if(cnt[i]<=N-cnt[i])
                mask+=1LL<<i;
        }
        
        
        ll t=0;
        for(i=0; i<N; i++)
            t+=mask^a[i];
        
        chmax(ans, t);
    }
    
    pt(ans);
    
}







Measured memory_bytes: 1024
class ExponentiationTable
  
  def initialize(x, mod = nil )
    @x = x
    @mod = mod
    @table = [x]
  end
  
  def pow(n)
    res = 1
    i = 0
    while n > 0
      if (n & 1) != 0
        res *= @table[i]
        res %= @mod if @mod
      end
      i += 1
      @table[i] ||= ( @table[i-1] ** 2) 
      @table[i] %= @mod if @mod
      n >>= 1
    end
    # p @table
    res
  end
end

mod = 1_000_000_007

gets

h = Hash.new{|h, k| h[k] = [0, 0] }
genten_iwashi = 0

$<.read.split.map(&:to_i).each_slice(2) do |(a,b)|

  if 0 == a | b
    genten_iwashi += 1
  else
    f = a.zero? || (a > 0 && b > 0) || (a < 0 && b < 0)
    r = ( f ? Rational(a,b) : -Rational(b,a) )
    h[r][ f ? 0 : 1 ] += 1
  end
end

ans = 1
heiwa_iwashi = 0
two = ExponentiationTable.new(2, mod)

h.values.each do |(s, t)|
  if s == 0 || t == 0
    heiwa_iwashi += (s + t)
  else
    ans *= ( two.pow(s) + two.pow(t) - 1)
    ans %= mod
  end
end
ans = ( ans * two.pow(heiwa_iwashi) ) % mod
ans = ( ans - 1 + genten_iwashi ) % mod

puts ans

Measured memory_bytes: 70524
#include<iostream>
using namespace std;
int main(){
    long long n,k;
    cin>>n>>k;
    long long num,odd_num,even_num;
    if(k%2==1){
        long long ans=n/k;
        ans=ans*ans*ans;
        cout<<ans<<endl;
    }
    else{
        long long half=k/2;
        long long ans=n/half;
        if(ans%2==0){
            odd_num=ans/2;
            even_num=ans/2;
        }
        else{
            odd_num=ans/2+1;
            even_num=ans/2;
        }
        long long disp;
        disp=odd_num*odd_num*odd_num+even_num*even_num*even_num;
        cout<<disp<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>
 
using namespace std;
 
int main(){
 
char a[3];
  int b[3];
  int i;
  
  cin >> a;
  
 for(i = 0;i<=2;i++)
   b[i] = a[i] - '0';
  
  cout<<b[0] + b[1] + b[2]<<endl;
  
  return 0;
}

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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
using ll = long long;
const ll INF = 1e18L + 5;
const ll MOD = 1e9 + 7;
const int nax = 1e5 + 5;


int main(){
	ll n;
	cin >> n;
	ll result = INF;
	for(int i = 1; i <= pow(n ,0.5); ++i) {
		if(n % i == 0) {
			result = min(result, i + n/i);
		}
	}
	printf("%lld\n", result - 2);
}

 


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

using namespace std;

typedef long long ll;

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

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

  ll ans = 0;
  for(int i = 1; i <= k; i++) {
    for (int j = 1; j <= k; j++) {
      for (int c = 1; c <= k; c++) {
        ans += gcd(i, gcd(j, c));
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion
template <typename T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

#define INF INT32_MAX
// 入力
int N;
long long h[100010];

// メモ用の DP テーブル
long long dp[100010];

long long rec(int i)
{
    // DP の値が更新されていたらそのままリターン
    if (dp[i] < INF)
        return dp[i];

    // 足場 0 のコストは 0
    if (i == 0)
        return 0;

    // i-1, i-2 それぞれ試す
    long long res = INF;
    chmin(res, rec(i - 1) + abs(h[i] - h[i - 1])); // 足場 i-1 から来た場合
    if (i > 1)
        chmin(res, rec(i - 2) + abs(h[i] - h[i - 2])); // 足場 i-2 から来た場合

    // 結果をメモしながら、返す
    return dp[i] = res;
}

int main()
{
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i)
        cin >> h[i];

    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 100010; ++i)
        dp[i] = INF;

    // 答え
    cout << rec(N - 1) << endl;
}

Measured memory_bytes: 4864
using System;

namespace dowa6_A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] s = new string[n];
            int[] t = new int[n];

            for(int i = 0; i < n; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                s[i] = input[0];
                t[i] = int.Parse(input[1]);
            }

            string x = Console.ReadLine();

            int count = 0;
            int target = 0;

            for(int j = 0; j < n; j++)
            {
                if(x == s[j])
                {
                    target = j;
                }
            }

            for(int k = target + 1 ; k < n; k++)
            {
                count += t[k];
            }

            Console.WriteLine(count);

        }
    }
}


Measured memory_bytes: 13140
fun c112(args: Array<String>) {
    val xyhList = args.drop(1).map { city -> city.split(" ").map { it.toInt() } }

    fun abs(a: Int, b: Int): Int = if (a - b >= 0) a - b else b - a

    (0..100).forEach { cx ->
        (0..100).forEach { cy ->
            val base = xyhList.first { it[2] != 0 }
            val ch = base[2] + abs(base[0], cx) + abs(base[1], cy)
            if (xyhList.all {
                        ch == it[2] + abs(it[0], cx) + abs(it[1], cy)
                                || (it[2] == 0 && abs(it[0], cx) + abs(it[1], cy) >= ch)
                    }) {
                println("$cx $cy $ch")
            }
        }
    }

}

fun main(args: Array<String>) {
    c112(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

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

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  COMinit();
  ll n, m, k;
  cin >> n >> m >> k;
  ll ans = 0;
  FOR(d, 1, n) {
    ans += ((d * (n - d)) % MOD) * (m * m % MOD);
    ans %= MOD;
  }
  FOR(d, 1, m) {
    ans += ((d * (m - d)) % MOD) * (n * n % MOD);
    ans %= MOD;
  }
  ans *= COM(n * m - 2, k - 2);
  ans %= MOD;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 12160
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(){
	int N;
	int a,b;
	int a_score,b_score;

	while(scanf("%d",&N)){
		if(N==0){break;}
		a_score=0;
		b_score=0;
		for(int i=0;i<N;i++){
			scanf("%d %d",&a,&b);
			if(a>b){
				a_score+=(a+b);
			}else if(a<b){
				b_score+=(a+b);
			}else{
				a_score+=a;
				b_score+=b;
			}
		}
		printf("%d %d\n",a_score,b_score);
	}

	return 0;
}


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

int main(){
  map<int, int> bingo;
  vector<bool> n(9);
  for (int i = 0; i < 9; i++){
    int Ai;
    cin >> Ai;
    bingo[Ai] = i;
    n.at(i) = false;
  }
  int N;
  cin >> N;
  for (int i = 0; i < N; i++){
    int Bi;
    cin >> Bi;
    if (bingo.count(Bi)){
      n.at(bingo[Bi]) = true;
    }
  }
  bool ans = false;
  if ((n.at(0) && n.at(3) && n.at(6)) || (n.at(1) && n.at(4) && n.at(7)) || (n.at(2) && n.at(5) && n.at(8)) || (n.at(0) && n.at(1) && n.at(2)) || (n.at(3) && n.at(4) && n.at(5)) || (n.at(6) && n.at(7) && n.at(8)) || (n.at(0) && n.at(4) && n.at(8)) || (n.at(2) && n.at(4) && n.at(6)))
    ans = true;
  if (ans){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
    
}



Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        String s = sc.next();
        
        List<Character> list = new ArrayList<>();
        for (int i = 0; i < s.length(); i++) {
			list.add(s.charAt(i));
		}

        String ans = "None";
        for (char i = 'a'; i <= 'z'; i++) {
			if (list.contains(i)) {
				continue;
			} else {
				ans = String.valueOf(i);
				break;
			}
		}
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 27684
#include <bits/stdc++.h>
using namespace std;
#define testing 0
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << endl
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<endl
#define dbv(v) cerr << #v << ":"; for (auto i : v) cerr << i << ' '; cerr << endl
#define dbvp(v) cerr << #v << ":"; for (auto i : v) cerr << "{"  << i.f << ',' << i.s << "} "; cerr << endl
#define dba(a,ss,ee) cerr << #a << ":"; FOR(i,ss,ee) cerr << a[i] << ' '; cerr << endl
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define inf (int)1e9
#define oo (ll)1e18
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "hi\n";
typedef pair <int, int> pi;
typedef pair <ll,ll> pl;
typedef pair <pi, int> pii;
typedef tuple<int,int,int> ti3;
string lts(ll x) {stringstream s; s << x; return s.str(); }
ll stl(string x) {stringstream s(x); ll temp; s >> temp; return temp; }
string cts(char x) {string s(1,x); return s;}
const int MOD = 1e9 + 7;
template <typename T> void maxself(T& a, T b) {
	a = max(a, b);
}
template <typename T> void minself(T& a, T b) {
	a = min(a, b);
}
#define MAXN 
#if !testing
	#define cerr if(0)cout
#endif

ll n,k;
vector <int> v, f;

bool check(ll score) {
	ll cnt = k;
	FOR(i,0,n-1) {
		ll d = score/f[i];
		//db(d);
		if (d<v[i]) cnt-=v[i]-d;
		//db(cnt);
	}
	if (cnt>=0)return 1;
	else return 0;
}

int32_t main() {
	IAMSPEED
	// set testing to 0 when submitting to judge
	cin >> n >> k;
	FOR(i,1,n) {
		int x; cin >> x;
		v.pb(x);
	}
	FOR(i,1,n) {
		int x; cin >> x;
		f.pb(x);
	}
	sort(all(v));
	sort(all(f), greater<int>());
	check(0);
	//exit(0);
	ll lo = -1, hi = oo;
	while (lo < hi - 1) {
		ll mid = lo + (hi-lo)/2;
		if (check(mid)) {
			hi = mid;
		} else {
			lo = mid;
		}
	}
	cout << hi;
}


Measured memory_bytes: 2548
#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 MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;
//const int INF=(1<<30);


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

  vector<set<int> > ss(26);

  REP(i,s.size()){
    int t =  s[i] - 'a';
    ss[t].insert(i);
  }


  int q;
  cin >> q;
  REP(i,q){
    int type;
    cin >> type;
    if(type==1){
      int t;
      char c;
      cin >> t >> c;
      t--;
      ss[s[t] - 'a'].erase(t);
      s[t] = c;
      ss[s[t] - 'a'].insert(t);
    }else{
      int l,r;
      cin >> l >> r;
      l--;r--;
      int ans=0;
      REP(j,26){
        auto itr = ss[j].lower_bound(l);
        if(itr == ss[j].end())continue;
        if(*itr <= r){
          ans++;
//          cout << j << ":" << endl;
        }else{
        }
      }
      cout << ans << endl;
    }
  }

}



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

typedef long long ll;
const ll mod = 1e9 + 7;
const ll inf = 184467440737095516;

ll n;

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

	cin >> n;
	if (n % 2 == 0){
		n /= 2;
	} 
	else{
		n /= 2;
		n++;
	}
	cout << n << '\n';
}
  

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
even_A = []
answer = True
for i in A:
    if i % 2 == 0:
        even_A.append(i)

for i in even_A:
    if i % 3 != 0 and i % 5 != 0:
        answer = False

if answer:
    print('APPROVED')
else:
    print('DENIED')

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bits/stdc++.h>
#include <stack>
#include <map>
#include <ctype.h>

using namespace std;

#define loop(i,n) for (i = 0; i < n; ++i) 
#define loop2(i,k,n) for (i = k; i <= n; ++i) 
#define loopb(i,k,n) for (i = k; i >= n; --i)
#define remove_space(x) x.erase(remove(x.begin(), x.end(), ' '), x.end())
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false);

    int n1, n2;
    cin >> n1 >> n2;

    if(n1 > 9 || n2 > 9){
    	cout << -1;
    }

    else{
    	cout << n1 * n2;
    }
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
signed main(){
    int N; cin >> N;
    vector<int>a(N);
    vector<short>box(N,0);
    for(auto & e : a) cin >> e;
    vector<int>ans;
    for(int i = N; i >= 1; --i){
        int tmp = 0;
        for(int j = 2; i * j <= N; ++j){
            tmp += box[i * j - 1];
        }
        tmp %= 2;
        if(tmp != a[i - 1]){ box[i - 1] = 1;}
    }
    cout << accumulate(box.begin(),box.end(),0LL) << endl;
    for(int i =0; i < box.size();++i){
        if(box[i]) cout << i + 1 << endl;
    }
    
}



Measured memory_bytes: 2816
loop do
  d_w_h = gets.split.map(&:to_i)
  break if d_w_h.all?(&:zero?)

  n = gets.to_i
  x, y = d_w_h.sort.take(2)

  n.times do
    diameter = gets.to_i * 2
    puts Math.sqrt(x**2 + y**2) < diameter ? 'OK' : 'NA'
  end
end

Measured memory_bytes: 8632
import java.io.*;
import java.util.*;


public class Main {
    static long mod = 1000000000+7;
    static int n,a,b,k;
    public static void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //String[] buf = reader.readLine().split(" ");
        n = sc.nextInt(); k = sc.nextInt();
        System.out.println(n-k+1);

    }
}



Measured memory_bytes: 21844
def main():
    N = input()
    CS = [c for c in input().strip()]

    wtotal = 0
    rtotal = 0
    for c in CS:
        if c == "W":
            wtotal += 1
        elif c == "R":
            rtotal += 1
        else:
            raise Exception()

    left = -1
    right = len(CS)

    op = 0
    w = 0
    r = 0
    while True:
        # print(f"L:{left}  R:{right}  w:{w}  r:{r}  op:{op}")
        if w > r:
            right -= 1
            if CS[right] == "R":
                r += 1
        else:
            left += 1
            if CS[left] == "W":
                w += 1

        if w > 0 and r > 0:
            op += 1
            w -= 1
            r -= 1

        if right == left or right == 0 or left == len(CS) - 1:
            break

    change = op
    print(min(wtotal, rtotal, change))


main()


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

int main(){
  string str;
  stack<char> s;
  while(getline(cin,str)){
    bool f = true;
    if(str == ".")break;
    while(!s.empty())s.pop();
    for(int i = 0;i < str.length();i++){
      if(str[i] == '(' || str[i] == '[') s.push(str[i]);
      else if(!s.empty()){
	if(str[i] == ')'){
	  if(s.top() == '(') s.pop();
	  else f = false;
	}else if(str[i] == ']'){
	  if(s.top() == '[') s.pop();
	  else f = false;
	}
      }
      else if(s.empty() && (str[i] == ')' || str[i] == ']')) f = false;
    }
    if(s.empty() && f == true) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
using namespace std;

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

    int val;

    int i;
    int maxIndex = 0;
    int max2Index = 0;
    int max = 0;
    int max2 = 0;
    for(i = 0; i < n; i ++)
    {
    	cin >> val;
    	if(val > max)
    	{
    		max2 = max;
    		max2Index = maxIndex;
    		max = val;
    		maxIndex = i;
    	}
    	else if(val > max2)
    	{
    		max2 = val;
    		max2Index = i;
    	}
    }

    for(i = 0; i < n; i ++)
   	{
   		if(i == maxIndex)
   			cout << max2 << endl;
   		else
   			cout << max << endl;
   	}
}

Measured memory_bytes: 1664
package main

import (
	"fmt"
)

func main() {
	var s, t string
	fmt.Scan(&s, &t)

	sm := make(map[string]int)
	tm := make(map[string]int)
	for i := 0; i < len(s); i++ {
		ss := string(s[i])
		st := string(t[i])
		if sm[ss] != tm[st] {
			fmt.Println("No")
			return
		}
		sm[ss] = i + 1
		tm[st] = i + 1
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  vector<int> vec(N);
  for(int i=0;i<N-1;i++){
    int a,b;
    cin>>a;
    b=vec.at(a-1);
    b++;
    vec.at(a-1)=b;
  }
  for(int j=0;j<N;j++){
    cout<<vec.at(j)<<endl;
  }
}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N,M;
    cin >>N>>M;
    vector<ll> A(M);
    ll sum =0;
    rep(i,M){
        cin>>A[i];
        sum+=A[i];
    }
    


    cout << max(N-sum,ll(-1)) << endl;


    return 0;
    

}

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

std::string s, t;

bool check(std::string::iterator);

int main()
{
    std::cin >> s >> t;
    std::string min = "###";
    for (int i = 0; i + t.size() <= s.size(); i++)
    {
        if (!check(s.begin() + i)) continue;
        std::string tmp = s;
        for (int j = 0; j < t.size(); j++)
            tmp[i + j] = t[j];
        for (auto & e : tmp)
            if (e == '?') e = 'a';
        if (min[0] == '#' || tmp < min)
            min = tmp;
    }
    if (min == "###") printf("UNRESTORABLE\n");
    else std::cout << min << std::endl;

    return 0;
}

bool check(std::string::iterator it)
{
    for (int i = 0; i < t.size(); i++)
    {
        if (*it != '?' && *it != t[i])
            return false;
        it++;
    }
    return true;
}

Measured memory_bytes: 256
N=int(input())
a=[0]*45
k=0
for i in range(1,10):
     for j in range(i,10):
               a[k]=i*j
               k+=1
printed=False
for i in a:
     if N==i:
          print("Yes")
          printed=True
          break
if printed==False:
     print("No")


Measured memory_bytes: 3060
n = gets.to_i
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)

pls = []
mns = 0
res = 0
n.times do |i|
  if b[i] > a[i]
    res += 1
    mns += b[i] - a[i]
  elsif b[i] < a[i]
    pls << i
  end
end
  
pls.sort_by! {|i| (a[i] - b[i]) }
while mns > 0 && !pls.empty?
  i = pls.pop
  mns -= a[i] - b[i]
  res += 1
end

puts (mns > 0)? "-1" : res

Measured memory_bytes: 28660
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int h, w;
  scanf("%d %d", &h, &w);

  llong c[20][20];
  REP(i,10){
    REP(j,10){
      scanf("%lld", &c[i][j]);
    }
  }

  
  int a[200][200] = {};
  REP(i,h){
    REP(j,w){
      scanf("%d", &a[i][j]);
    }
  }

  REP(k,10){
    REP(i,10){
      REP(j,10){
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
      }
    }
  }


  llong ans = 0;
  REP(i,h){
    REP(j,w){
      if(a[i][j] != -1 && a[i][j] != 1){
        ans += c[a[i][j]][1];
      }
    }
  }

  printf("%lld\n", ans);

  return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <string>
using namespace std;
int main(){
    struct A{
        int east;
        int west;
    };
    int n;
    cin >> n;
    string s;
    cin >> s;
    A a[n];
    a[0].east=0;
    a[0].west=0;
    for (int i=1; i<n+1; i++){
        if (s[i-1]=='W'){
            a[i].east=a[i-1].east;
            a[i].west=a[i-1].west+1;
        }
        else{
            a[i].east=a[i-1].east+1;
            a[i].west=a[i-1].west;
        }
    }
    int ans=1e9;
    for (int i=0; i<n; i++){
        int cand=a[i].west+a[n].east-a[i+1].east;
        ans=min(ans,cand);
    }
    cout << ans <<endl;
}

Measured memory_bytes: 2948
import java.io.*;
import java.util.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		
		int N = sc.nextInt();
		int W = sc.nextInt();
		int[] v = new int[N+1];
		int[] w = new int[N+1];
		for(int i = 1; i <= N; i++){
			v[i] = sc.nextInt();
			w[i] = sc.nextInt();
		}
		
		int[][] dp = new int[N+1][W+1];
		for(int i = 0; i <= N; i++){
			for(int j = 0; j <= W; j++){
				if(i + 1 <= N){
					dp[i+1][j] = Math.max(dp[i+1][j], dp[i][j]);
				}
				if(j + w[i] <= W){
					dp[i][j + w[i]] = Math.max(dp[i][j + w[i]], dp[i][j] + v[i]);
				}
				if(i + 1 <= N && j + w[i+1] <= W){
					dp[i+1][j + w[i+1]] = Math.max(dp[i+1][j + w[i+1]], dp[i][j] + v[i+1]);
				}
			}
		}
		
		System.out.println(dp[N][W]);
	}
}

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}



Measured memory_bytes: 29348
#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

int vowel(char c){
	if(65 <= c && c <= 90){
		return (int)c + 32;
	}
	else if(97 <= c && c <= 122){
		return (int)c;
	}
	else{
		return 0;
	}
}

int main(){
	string s;
	int cnt[26];
	for(int i; i < 26; i++){
		cnt[i] = 0;
	}
	while(getline(cin, s) != 0){
		for(int i = 0; i < s.length(); i++){
			int c = vowel(s[i]);
			if(c != 0){
				int n = c - 97;
				cnt[n]++;
			}
		}
	}
	for(int i; i < 26; i++){
		cout << (char)(i + 97) << " : " << cnt[i] << "\n";
	}
}


Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

int main(){
    int n;
    cin>>n;
    int ans=INF;
    for(int i=1;i<=n/2;i++){
        int a=i;
        int b=n-a;
        int tmp=0;
        while(a>0){
            tmp+=a%10;
            a/=10;
        }
        while(b>0){
            tmp+=b%10;
            b/=10;
        }
        ans=min(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
    string s;
    cin >> s;

    int count = 0;
    if (s.at(0) == '1') {
        count++;
    }
    if (s.at(1) == '1') {
        count++;
    }
    if (s.at(2) == '1') {
        count++;
    }
    cout << count << endl;
}

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

int main() {
	int n, x;
	cin >> n >> x;
	int count = 1;
	for (int i = 0, l, d = 0; i < n; i++) {
		cin >> l;
		d += l;
		if (d <= x)
			count++;
		else
			break;
	}
	cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int64_t H;
int64_t A;
cin>>H;
for(int i=0;i<40;i++){
if(std::pow(2,i)<=H && H<std::pow(2,i+1)){
A=std::pow(2,i+1)-1;
}
}
cout<<A<<endl;
}



Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;

class Solve{
    static void Main(string[] args){
        _ = Console.ReadLine();
        int answer = Console.ReadLine().Split()
                                       .Min(a => {int ai = int.Parse(a), c = 0; while ((ai & 1) == 0) {ai >>= 1; c++;} return c;});
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}}

Measured memory_bytes: 28248
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 string a, b;
  cin >> a >> b;
  int c, d;
  cin >> c >> d;
  string e;
  cin >> e;
  if (a == e) {
    cout << c - 1 << " " << d << endl;
  }
  else {
    cout << c << " " << d - 1 << endl;
  }
}

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

typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

string s;

int main() {
	cin >> s;
	int fln = 0, fls = 0, fle = 0, flw = 0;
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == 'N')
			fln = 1;
		else if (s[i] == 'E')
			fle = 1;
		else if (s[i] == 'S')
			fls = 1;
		else
			flw = 1;
	}
	if (fln != fls || fle != flw) {
		cout << "No\n";
	}
	else {
		cout << "Yes\n";
	}
	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stdio.h>
#include <math.h>

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> pii;

typedef queue<int> qi;
typedef queue<string> qs;


#define rep(i, n) for(int i=0; i<(n); ++i)
#define repp(i, a, b) for(int i = (a); i <= (b); i++)
#define repm(i, a, b) for(int i = (a); i >= (b); i--)

#define all(v) v.begin(), v.end()
//sort( all(v) )　などと使える

int main(){
    int n, k; cin >> n >> k;
    vector<int> l(n); rep(i, n) cin >> l[i];
    sort(all(l));
    reverse(all(l));

    int sum = 0;
    rep(i, k) sum += l[i];

    cout << sum << endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
for i in range(0,n):
    if a[i]%2 == 0:
        if a[i]%10 != 0:
            if a[i]%6 != 0:
                print("DENIED")
                break
    if i == n-1:
        print("APPROVED")

Measured memory_bytes: 3060
import bisect
from collections import defaultdict
n,m = map(int,input().split())
p = [list(map(int, input().split())) for _ in range(m)]
 
a = defaultdict(list)
for x,y in sorted(p):
    a[x].append(y)
for x,y in p:
    
    z=bisect.bisect(a[x],y)
    print("{0:06d}{1:06d}".format(x,z))

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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;

Int gcd(Int x, Int y){
	if(y == 0)
		return x;
	return gcd(y, x % y);
}

Int lcm(Int x, Int y){
	return x * y / gcd(x, y);
}

bool sosuu(int x){
	bool b = 1;
	if(x == 1) b = 0;
	for(int i = 2; i * i <= x; i++){
		if(x % i == 0) {
			b = 0;
			break;
		}
	}
	return b;
}

int a, b, c, x;

int main(){
	cin >> a >> b >> c >> x;
	
	int cnt = 0;
	
	for(int i = 0; i <= a; i++){
		for(int j = 0; j <= b; j++){
			for(int k = 0; k <= c; k++){
				if(i*500 + j*100 + k*50 == x)
					cnt++;
			}
		}
	}
	
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 256