akhauriyash/Code-Regression huggingface dataset:
n=int(input())
G=[]
for i in range(n):
    L=list(map(int,input().split()))
    G.append(L[2:])
    for j in range(len(G[-1])):
        G[-1][j]-=1

Forder=[-1]*n
Lorder=[-1]*n
ptr=1
def dfs(v):
    #print(v)
    #print(G[v])
    #print()
    global ptr

    Forder[v]=ptr
    ptr+=1

    for next in G[v]:
        if Forder[next]!=-1:
            continue
        dfs(next)
    
    Lorder[v]=ptr
    ptr+=1

#while True:
#    #print(Forder,Lorder)
#    for i in range(n):
#        if Forder[i]!=-1 and Lorder[i]!=-1:
#            pass
#        else:
#            dfs(i)
#            continue
#
#        if i==n-1:
#            break
#    else:
#        continue
#    break
#
#for i in range(n):
#    print(i+1,Forder[i],Lorder[i])

##########
for i in range(n):
    if Forder[i]==-1 or Lorder[i]==-1:
        dfs(i)

for i in range(n):
    print(i+1,Forder[i],Lorder[i])


Measured memory_bytes: 5660
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N;
char S[1010101];
int Q, K[75];

i64 nc[1010101], cs[1010101];

i64 solve(int W)
{
	i64 ret = 0;
	int u = 0;
	for (int i = 0; i < N; ++i) {
		if (S[i] == 'D') {
			int r = min(N, i + W);
			ret += cs[r] - cs[i] - u * (nc[r] - nc[i]);
		} else if (S[i] == 'M') {
			++u;
		}
	}
	return ret;
}

int main()
{
	scanf("%d%s%d", &N, S, &Q);
	for (int i = 0; i < Q; ++i) scanf("%d", K + i);

	int u = 0;
	for (int i = 0; i < N; ++i) {
		if (S[i] == 'M') ++u;
		if (S[i] == 'C') {
			nc[i + 1] = 1;
			cs[i + 1] = u;
		}
	}
	for (int i = 1; i <= N; ++i) {
		nc[i] += nc[i - 1];
		cs[i] += cs[i - 1];
	}

	for (int i = 0; i < Q; ++i) {
		printf("%lld\n", solve(K[i]));
	}
	return 0;
}


Measured memory_bytes: 17024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
#define BIG 2000000007
 
#define MOD 1000000007
typedef unsigned long long ull;
typedef   signed long long sll;
 
typedef struct {
	int a;
	int b;
} hw;
 
#define N_MAX 100000
#define M_MAX 100000
 
ull n, m, k;
ull h, w;
ull va, vb, vc, vd;
ull a[N_MAX];
// sll a[N_MAX];
ull b[N_MAX];
// ull dp[N_MAX][M_MAX + 1];
char s[N_MAX + 1];
// char t[N_MAX + 1];
// hw arr[N_MAX];
 
void swap_adj(ull *a, ull *b){
	ull tmp = *b;
	*b = *a;
	*a = tmp;
	return;
}

ull divide(ull a, ull b){
	ull x = MOD - 2;
	ull ans = 1;
	while (x) {
		if (x & 1) ans = (ans * b) % MOD;
		b = (b * b) % MOD;
		x /= 2;
	}
	return (a * ans) % MOD;
}
 
int digits(ull x){
	int i = 1;
	while (x >= 10) {
		x /= 10;
		i++;
	}
	return i;
}
 
int min(ull x, ull y){
	return (x < y) ? x : y;
}
 
ull gcd(ull x, ull y){
	if (x < y) {
		return gcd(y, x);
	} else if (y == 0) {
		return x;
	} else {
		return gcd(y, x % y);
	}
}
 
ull bitpow(ull a, ull x){
	ull result = 1;
	while (x) {
		if (x & 1) {
			result *= a;
			result %= MOD;
		}
		x /= 2;
		a = (a * a) % MOD;
	}
	return result;
}

int comp(const void *left, const void *right){
	if ((*(int*)left) < (*(int*)right)) {
		return -1;
	} else if ((*(int*)left) > (*(int*)right)) {
		return +1;
	} else {
		return 0;
	}
}

// int nextroute(int arr[]){
// 	int i = n - 1;
// 	int j, x;
// 	while (arr[i - 1] > arr[i]) i--;

// 	x = n;
// 	for (j = i; j < n; j++) {
// 		if (arr[j] < arr[i - 1]) continue;
// 		if (x == n || arr[x] > arr[j]) x = j;
// 	}
// 	arr[i - 1] ^= arr[x];
// 	arr[x] ^= arr[i - 1];
// 	arr[i - 1] ^= arr[x];

// 	qsort(&arr[i], n - i, sizeof(int), comp);
// 	return 0;
// }

ull solve(){
	int i, j;

	ull index = 0;
	ull times = 0;

	for (;;) {
		if (b[index]) {
			puts("-1");
			return 1;
		}
		b[index] = 1;
		index = a[index];
		times++;
		if (index == 1) {
			printf("%llu", times);
			return 0;
		}
	}

	return 0;
}
 
int main(void){
	int i, j;
	int x;

	scanf("%llu%llu", &h, &w);

	for (i = 0; i < w + 2; i++) {
		putchar('#');
	}
	putchar('\n');
	for (i = 0; i < h; i++) {
		scanf("%s", s);
		printf("#%s#\n", s);
	}
	for (i = 0; i < w + 2; i++) {
		putchar('#');
	}
	putchar('\n');

	// solve();

	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <utility>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <climits>
#include <vector>
#include <set>
#include <string>
#include <numeric>


#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define DEBUG freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define int long long
using namespace std;

signed main() {
    FAST_IO;
    //DEBUG;

    int n;
    cin >> n;
    int a[n], b[n], c[n];
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];
    int dp[n + 1][3];
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    for (int i = 1; i < n; i++) {
        dp[i][0] = a[i] + max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] = b[i] + max(dp[i - 1][0], dp[i - 1][2]);
        dp[i][2] = c[i] + max(dp[i - 1][1], dp[i - 1][0]);
    }
    cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]});
    return 0;
}

Measured memory_bytes: 4992
/* Written by Filip Hlasek 2017 */
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <iostream>

#define FOR(i, a, b)   for (int i = (a); i <= (b); i++)
#define FORD(i, a, b)  for (int i = (a); i >= (b); i--)
#define REP(i, b)      for (int i =  0 ; i <  (b); i++)

using namespace std;

#define MAXN 111111
int cnt[MAXN];

int main(int argc, char *argv[]) {
  int N;
  scanf("%d", &N);
  REP(i, N) {
    int a;
    scanf("%d", &a);
    cnt[a]++;
  }
  int ans = 0;
  REP(i, MAXN - 1) ans = max(ans, cnt[i] + cnt[i + 1] + cnt[i + 2]);
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=j; i<=k; i++)
#define FFOR(i, j, k) for(int i=j; i<k; i++)
#define DFOR(i, j, k) for(int i=j; i>=k; i--)
#define bug(x) cerr<<#x<<" = "<<x<<'\n'
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
#define taskname "D"
const ll base=1000000007;
ll f[200001];
ll r[200001];
ll power(ll a, int x){
    if(x==0) return 1;
    ll t=power(a, x/2);
    t=(t*t)%base;
    if(x%2) t=(t*a)%base;
    return t;
}
inline ll C(int n, int k){///nCk
    return (((f[n]*r[k])%base)*r[n-k])%base;
}
ll ans=0;
ll h, w, a, b;
int main(){
    #ifdef Megumin
        if(fopen(taskname".inp", "r"))
            freopen(taskname".inp", "r", stdin);
    #endif // Megumin
    f[0]=1;
    FOR(i, 1, 200000) f[i]=(f[i-1]*i)%base;
    FOR(i, 0, 200000) r[i]=power(f[i], base-2);
    read(h);
    read(w);
    read(a);
    read(b);
    a=h-a;
    FFOR(i, 0, a){/// number of D to take before get b R, after this go to (i+1, b+1)
        ans=(ans+C(i+b-1, i)*C(h+w-i-b-2, h-i-1))%base;
    }
    write(ans);
}

Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <cmath>

using namespace std;    
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

int main(){

    ll n;
    cin >> n;

    long double n_max = sqrt( (long double)n ) + 1;
    ll ans = 0;
    for(ll i = 1; i <= n_max; i++){
        if(i * i <= n){
            ans = i * i;
        }
    }    
    cout << ans << endl;
}

Measured memory_bytes: 256
#pragma target("avx")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define rep(i,b,e) for(ll i=b; i<e; i++)
#define be(vec) vec.begin(),vec.end()
#define print(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define scan(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

std::vector<int> ans;
void dfs(int x){
	rep(i, 1, x+1){
		if(i*(i+1)/2>=x){
			ans.push_back(i);
			if(i>1) dfs(x-i);
			break;
		}
	}
	return;
}

int main(){
	int n;
	scanf("%d", &n);
	dfs(n);
	for(int a: ans) printf("%d\n", a);
	return 0;
}


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

int main()
{
	string s;
	int a,b;
	cin>>a>>b;
	cin>>s;
	if (s.size()!=a+b+1 || s[a]!='-'){
		cout<<"No"<<endl;
		return 0;
	}
	for(int i=0;i<s.size();i++)
		if (i!=a)
			if (s[i]>'9' || s[i]<'0'){
				cout<<"No"<<endl;
				return 0;
			}
	cout<<"Yes"<<endl;
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    repd(i, 1, n + 1)
    {
        int ans0 = 0;
        repd(j, 1, i + 1)
        {
            if (j % 2 == 1 && i % j == 0)
                ans0++;
        }
        if (ans0 == 8)
            ans++;
    }
    cout << ans << endl;
    return 0;
}

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

	string s;
	cin >> s;
	if (s[0] != 'A') {
		cout << "WA";
		return 0;
	}
	
	int kol = 0;
	for (int i = 2; i < s.size()-1; i ++) {
		if (s[i] == 'C') kol ++;
	}
	
	if (kol != 1) {
		cout << "WA";
		return 0;
	}
	
	kol = 0;
	for (int i = 0; i < s.size(); i ++) {
		if (s[i] >= 'A' && s[i] <= 'Z') kol ++;
	}
	
	if (kol != 2) {
		cout << "WA";
		return 0;
	}
	cout << "AC";

	return 0;
}

Measured memory_bytes: 256
h, w, k = map(int, input().split())
C = []
for _ in range(h): C.append(input())
ans = 0
for bit in range(1<<(h+w)):
    c = 0
    for i in range(w, h+w):
        for j in range(w):
            if bit>>i & 1 and bit>>j & 1: c += C[i-w][j] == '#'
    if c == k: ans += 1
print(ans)


Measured memory_bytes: 8992
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
ll fast_pow(ll a, ll b) {
    ll ans = 1, base = a;
    while(b) {
        if(b & 1)
            ans *= base;
        base *= base;
        b >>= 1;
    }
    return ans;
}
ll r;

int main() {
    scanf("%lld", &r);
    printf("%lld", 3 * fast_pow(r, 2));
    return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int cnt = 1;
        while (sc.hasNext()) {
            int x = sc.nextInt();
            if (x == 0) {
                System.out.println(cnt);
                break;
            }
            cnt++;
        }
        sc.close();
    }
}

Measured memory_bytes: 35484
object Scanner {
  private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0
  @inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
  @inline private def hasNextByte(): Boolean =
    if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else { true }
  @inline private def hasNext(): Boolean = {
    while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
    hasNextByte()
  }
  @inline private def readByte(): Byte =
    if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else { -1 }
  def next(): String = {
    if(!hasNext()) ???
    val sb = new StringBuilder; var b = readByte()
    while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
    sb.toString
  }
  def nextInt(): Int = {
    val n = nextLong()
    if (n < Int.MinValue || Int.MaxValue < n) ???
    n.toInt
  }
  def nextLong(): Long = {
    if(!hasNext()) ???
    var minus = false; var b = readByte()
    if (b == '-') { minus = true; b = readByte() }
    def go (b: Byte, n: Long = 0): Long =
      if ('0' <= b && b <= '9') { go(readByte(), n * 10 + b - '0') }
      else if (minus) { -n } else { n }
    go(b)
  }
  def nextDouble(): Double = next.toDouble
}

object Main extends App {
  val a,b = Scanner.nextInt()
  if (a<=8 && b<=8){
    println("Yay!")
  } else {
    println(":(")
  }
}

Measured memory_bytes: 25508
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <string>
#include <cctype>
#include <cstdio>
#include <math.h>
using f32 = float;
using f64 = double;
using f80 = __float80;
constexpr int64_t INF = 1'010'000'000'000'000'017LL;

constexpr int64_t MOD = 1'000'000'007LL;

constexpr f64 EPS = 1e-12;

constexpr f64 PI = asin(-1.0);
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using vi = vector<int>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vs = vector<string>;
using vl = vector<LL>;
using vvl = vector<vl>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
#define REP(i, n) for (LL i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (LL i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
#define fst first
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define sw swap
#define UP(x) transform(x.begin(), x.end(), x.begin(), ::toupper);
#define LOW(x) transform(x.begin(), x.end(), x.begin(), ::tolower);
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
int main()
{
    int n,d;
    cin >> n >> d;
    if(n%(2*d+1)==0){
        cout << n / (2 * d + 1);
    }else{
        cout << n / (2 * d + 1)+1;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ull unsigned ll
#define pb push_back
#define popb pop_back
#define mt make_tuple
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair <int,int>
#define piii pair <pii,int>
#define piiii pair <pii,pii>
#define plll pair <pair <ll, ll>, ll>
#define rep0(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rep(i,x,y) for(ll i=x;i<=y;i++)
#define reprev(i,n) for(ll i=n;i>=0;i--)
#define all(c) c.begin(),c.end()
#define print(a) rep0(i,a.size()) cout << a[i] << " "
#define hi() cout << "\nHello, I am error. Can you find me? :):):)\n"
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_eppoch().count())
 
using namespace __gnu_pbds;
using namespace std;
using ordered_set =  tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>;

const int mod = 1e9+7;
const long double pi = acos(-1);

ll power(ll x, ll y){
	x %= mod;
	if(y == 0) return 1;
	if(y == 1) return x;
	ll num = power(x,y/2) % mod;
	if(y%2 == 0) return (num*num)%mod;
	else return (((num*num)%mod)*x)%mod;
}

void solve(){

	long double n;
	cin >> n;
	long double v = (n/3)*(n/3)*(n/3);
	cout << fixed << setprecision(15) << v;

	return;
}

int main(){

	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int TC = 1,t = 0;
	// cin >> TC;
	while(t++ < TC){
		// cout << "Case #" << t << ": ";
		solve();
		// cout << "\n";
	}

	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

	return 0; 
}

Measured memory_bytes: 256
from bisect import bisect_left

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

def combination(n, r): #nCrを求める
    if n - r < r:
        r = n - r
    tmp = 1
    for i in range(n - r + 1, n + 1):
        tmp *= i
    for i in range(1, r + 1):
        tmp //= i
    return tmp
# print (a)

j = bisect_left(a, a[-1]//2)
# print (j)
tmp = abs(a[j]/a[-1] - 1/2)
ans1 = a[-1]
ans2 = a[j]
if j != 0:
    if tmp >= abs(a[j - 1]/a[-1] - 1/2):
        ans2 = a[j - 1]

print (ans1, ans2)    

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

typedef long long ll;

ll N, L;
ll Sum, Min = 1ll << 60;

int main() {
  cin >> N >> L;
  for (ll i = 0; i < N; ++i) {
    ll x = L + i;
    Sum += x;
    if (abs(Min) > abs(x)) Min = x;
  }
  cout << Sum - Min << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())


n = II()
a = LI()
cnt = 0
while all(num % 2 == 0 for num in a):
    cnt += 1
    a = list(map(lambda x: x // 2, a))
print(cnt)


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

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if(a == b){
        cout << c << endl;
    }else if(b == c){
        cout << a << endl;
    }else{
        cout << b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <limits>
#include <map>
#include <vector>
#include <queue>
#define LL long long
#define ft first
#define sd second
#define pb push_back
#define mp(x,y) make_pair(x,y)
//#define int LL
using namespace std;
//const int N   = ;
//const int mod = ;
const int INF =numeric_limits<int >::max();
#define For(n) for (int i=1;i<=n;++i)
#define rep(i,n) for (int i=1;i<=n;++i)
#define repp(i,x,y) for (int i=x;i<=y;++i)
void read(int &x)
{
	x=0;
	char ch=getchar();
	int f=1;
	while (!isdigit(ch)) (ch=='-'?f=-1:0),ch=getchar();
	while ( isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	x*=f;
}

void write(int x)
{
	if (x<0) putchar('-'),x=-x;
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
int n,x,t;
signed main()
{
	read(n);read(x);read(t) ;
	printf("%lld",1ll*((n-1)/x+1)*t);
	
	return 0;
}




Measured memory_bytes: 3724
import collections
def resolve():
    N = int(input())
    A = tuple(map(int, input().split()))
    C = collections.Counter(A)
    ans = 0
    for i in C.values():
        ans += i * (i-1) // 2

    for a in A:
        print(ans - (C[a] - 1))

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 27036
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
  int i, n, a, b, c, d, sum1, sum2, max, ans;
  vector<int> data;

  cin >> n >> a >> b >> c;
  for(i=0; i<n; ++i){
    cin >> d;
    data.push_back(d);
  }

  sort(data.begin(), data.end());
  for(i=data.size()-1, sum1=c, sum2=a, max=c/a; i>=0; --i){
    sum1 += data[i];
    sum2 += b;
    ans = sum1/sum2;
    if(max < ans) max = ans;
  }

  cout << max << endl;
  return 0;
}

Measured memory_bytes: 0
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let n = i.read::<usize>();
    let a = i.read_vec::<usize>(n);
    let b = i.read_vec::<usize>(n);

    if let Some(r) = solve(&a, &b) {
        writeln!(o, "{}", r).unwrap();
    } else {
        writeln!(o, "{}", -1).unwrap();
    }
}
fn solve(a: &[usize], b: &[usize]) -> Option<usize> {
    let mut c_need = 0;
    let mut c_extra = Vec::new();
    let mut result = 0;
    for i in 0..a.len() {
        let a = a[i];
        let b = b[i];
        if a < b {
            c_need += b - a;
            result += 1;
        }
        if a > b {
            c_extra.push(a - b);
        }
    }
    c_extra.sort();
    let mut c = 0;
    while c < c_need {
        if let Some(c_extra) = c_extra.pop() {
            c += c_extra;
            result += 1;
        } else {
            return None;
        }
    }
    Some(result)
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        pub fn read<T: FromStr>(&mut self) -> T {
            self.read_line().parse().ok().unwrap()
        }
        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }

        pub fn read_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            self.read_line()
                .split(' ')
                .take(n)
                .map(|x| x.parse().ok().unwrap())
                .collect()
        }
    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }

}


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

using namespace std;
const int mod = 1e9 + 7;

int main() {
    int n; cin >> n; int arr[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    long long int suffix[n]; suffix[n - 1] = arr[n - 1];
    for (int i = n - 2; i >= 0; i--) {
        suffix[i] = (suffix[i + 1] + arr[i]) % mod;
    }
    long long int ans = 0;
    for (int i = 0; i < n - 1; i++) {
        ans += (1LL * arr[i] * suffix[i + 1]) % mod;
    }
    cout << ans % mod;
    return 0;
}

Measured memory_bytes: 5864
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(int i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> P;
typedef long double ld;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<P> xl(n);
    rep (i, n) {
        ll x, l;
        cin >> x >> l;
        xl[i].first = x + l;
        xl[i].second = x - l;
    }
    sort(all(xl));
    rep (i, n) eprintf("(%d %d)", xl[i].first, xl[i].second);
    ll r = xl[0].first, ans = 1;
    rep (i, n) {
        if (xl[i].second >= r) {
            ans++;
            r = xl[i].first;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1792
cnt = int(input())
nums = list(input().split(" "))
current = 0
maxCnt = 0

for i in range(cnt - 1):
  if int(nums[i]) >= int(nums[i+1]):
    current += 1
  else:
    if maxCnt < current:
    	maxCnt = current
    current = 0

if maxCnt < current:
  maxCnt = current

print(maxCnt)

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

using namespace std;

bool check(string &s, int l, int r) {
    for (int i = l; i <= r-l; i++) {
        if (s[l+i] != s[r-i]) {
            return false;
        }
    }
    return true;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    string s;
    cin >> s;
    int n = s.length();
    auto ans = check(s, 0, n-1) && check(s, 0, (n-1)/2 - 1) && check(s, (n+3)/2 - 1, n-1);
    cout << (ans ? "Yes" : "No") << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define INF 1000000000000
#define MOD 1000000007
#define DEBUG(x) cerr<<'>'<<#x<<':'<<x<< endl
using namespace std;

ll power_binary(ll base, ll power)
{
    ll ans = 1;
    base %= MOD;
    while(power > 0)
    {
        if(power & 1)
        {
            ans = (ans * base) % MOD;
        }
        power >>= 1;
        base = (base * base) % MOD;
    }
    return ans;
}


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin >> n;
    ll a[100005] = {0};
    for(ll i = 0; i <= n; i++)
    {
        cin >> a[i];
    }    
    ll dp[100005] = {0};
    bool possible = true;
    if(a[0] != 0)
        possible = false;
    if(n == 0 && a[0] == 1)
        possible = true;
    ll limit[100005] = {0}; //limit of filled nodes in each layer
    limit[0] = 1; 
    for(ll i = 1; i <= n; i++)
    {
        limit[i] = min((ll)1e18, (2*limit[i - 1]) - a[i]);
    }
    dp[n] = a[n];
    for(ll i = n - 1; i >= 0; i--)
    {
        if(limit[i] < ceil((ll)dp[i + 1]/2))
            possible = false;
        ll remaining = limit[i];
        ll max_fill = (ll)min(remaining, dp[i + 1]);
        ll empty = a[i];
        dp[i] = max_fill + empty;
    }
    if(!possible)
    {
        cout << -1 << endl;
        return 0;
    }
    ll sum = 0;
    for(ll i = 0; i <= n; i++)
    {
        sum += dp[i];
    }
    if(possible)
        cout << sum << endl;
    else 
        cout << "-1" << endl;
    return 0;
}


Measured memory_bytes: 6036
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    ll k, n;
    cin >> k >> n;
    vector<ll> a;
    a.push_back(0);
    rep(i, n){
        ll tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    ll over = k - a[n - 1];
    // vector<ll> sumc(n + 1, 0);
    // rep(i, n){
    //     sumc[i + 1] = sumc[i] + a[i]; 
    // }
    // vector<ll> ra = a;
    // reverse(all(ra));
    // ll now = k;
    // vector<ll> suma(n + 1, 0);

    // for(int i = 0; i < n; i++){
    //     suma[i + 1] = suma[i] + (now - ra[i]);
    // }

    ll ans = INF;
    for(int i = 1; i <= n; i++){
        if(i == 1){
            ans = min(ans, (a[n] - a[i]) + a[i - 1]);
        } else {
            ans = min(ans, (k - a[i]) + a[i - 1]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ub upper_bound
//#define int long long
#define vbe(sdk) sdk.begin(),sdk.end()
#define pb push_back
#define loop(i,a,b) for(int i=a;i<b;++i)
#define rloop(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define mod 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
#define pi 3.14159265358979323846
using namespace std;
int arr1[26],arr2[26][26];
void solve()
{
   int n;
   cin>>n;
   double a[n];
   double s=0;
   loop(i,0,n)
   {
       cin>>a[i];
       s+=a[i];
   }
   s=s/n;
   int x=ceil(s);
   int y=floor(s);
  // cout<<x<<y<<"\n";
  int s1=0,s2=0;
  loop(i,0,n)
  {
      s1+=((x-a[i])*(x-a[i]));
  }
  loop(i,0,n)
  {
      s2+=((y-a[i])*(y-a[i]));
  }
  if(s1<s2)
  {
      cout<<s1<<"\n";
  }
  else
  {
      cout<<s2<<"\n";
  }
  
}

signed main(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
        //  int t;
        // cin>>t;
        // while(t--){
            solve();
    //    }
    return 0;
}




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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
#define LL long long
#define MOD 1000000007

//cout << (c)?"Yay!":":(" << endl;

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    int n, d;
    cin >> n >> d;
    vector<vector<int>> a;
    rep(i, n)
    {
        vector<int> b(d);
        rep(j, d)
                cin >>
            b[j];
        a.push_back(b);
    }
    int count = 0;
    rep(i, n)
    {
        REP(j, i + 1, n)
        {

            long long int sum = 0;

            rep(k, d)
            {
                sum += pow(a[i][k] - a[j][k], 2);
            }

            REP(k, 1, 150)
            {
                if (k * k == sum)
                {
                    count++;
                    break;
                }
            }
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
    int a, b, c, d, e, f, g, h, i, j, m;
    scanf("%d %d %d %d %d %d %d %d %d %d",&a,&b,&c,&d,&e,&f,&g,&h,&i,&j);
    m = a + b + c + d + e + f + g + h + i + j;
    printf("%d\n",m);
    return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<vector>
using namespace std;
const static long long MOD = 1e9+7;
int main(){
    int n;
    cin>>n;

	vector<int>IsPrime(n+1,1);
	IsPrime[0]=0;IsPrime[1]=0;
	for(int i=2;i*i<=n;i++)if(IsPrime[i])for(int j=i*2;j<=n;j+=i)IsPrime[j]=0;
    vector<long long>e;
    long long tmp=0;

    for(int i = 2; i <= n; i++,tmp=0)
    {
        if(IsPrime[i]){
            for(int j=i;j<=n;j*=i)tmp+=(long long)n/j;
            e.push_back(tmp);
        }
        
    }

    long long ans;
    if(e.empty())ans=1;
    else{
    ans=e.back()+1;
    e.pop_back();
    }

    for(;!e.empty();e.pop_back())ans=(ans*(e.back()+1)%MOD)%MOD;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let n = read_as_vec::<usize>()[0];

    let mut v: Vec<u64> = vec![0;n+1];
    v[0] = 2;
    v[1] = 1;
    for i in 2..n+1{
        v[i] = v[i-1] + v[i-2];
    }

    println!("{}", v[n]);
}


Measured memory_bytes: 4352
SA = input()
SB = input()
SC = input()
turn = 0
d = {'a': 0, 'b': 1, 'c': 2}
while True:
    if turn == 0:
        if SA == "":
            print("A")
            break
        card = SA[0]
        turn = d[card]
        SA = SA[1:]
    elif turn == 1:
        if SB == "":
            print("B")
            break
        card = SB[0]
        turn = d[card]
        SB = SB[1:]
    else:
        if SC == "":
            print("C")
            break
        card = SC[0]
        turn = d[card]
        SC = SC[1:]


Measured memory_bytes: 3064
N = gets.to_i
a = gets.to_i
if a != 0
  puts -1; exit
end
ans = 0
(N-1).times{
  b = gets.to_i
  case 
  when b - a > 1
    puts -1; exit
  when b - a < 1
    ans += a
  end
  a = b
}
p ans+a

Measured memory_bytes: 4092
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
#include <queue>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int a[n];
    for (int i = 0 ; i < n ; i++) cin >> a[i];
    sort(a, a + n);
    int x = 0, y = 0;
    for (int i = 0 ; i < n ; i++) {
        if (i % 2 == 0) x += a[i];
        else y += a[i];
    }
    cout << abs(x - y);
}

Measured memory_bytes: 3656
package main

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

//============================================================
var sc = bufio.NewScanner(os.Stdin)

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

func readStr() string {
	sc.Scan()

	return sc.Text()
}

func readInt() int {
	i, _ := strconv.Atoi(readStr())

	return i
}

func readFloat() float64 {
	f, _ := strconv.ParseFloat(readStr(), 64)

	return f
}

//=============================================================

func main() {
	setScSplit()

	N := readInt()
	s := make([]int, N)

	for i := 0; i < N; i++ {
		d := readInt()
		s[i] = d
	}

	sort.Sort(sort.Reverse(sort.IntSlice(s)))

	res := 1
	for i := 1; i < N; i++ {
		if s[i-1] != s[i] {
			res++
		}
	}

	fmt.Println(res)
}

Measured memory_bytes: 640
import java.util.Scanner;

class Main {

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

    public static void main(String[] args) {
        int[] a = new int[4];
        for (int i = 0; i < 4; i++) {
            a[i] = sc.nextInt();
        }
        if (Math.abs(a[1] - a[0]) <= a[3] && Math.abs(a[2] - a[1]) <= a[3]
            || Math.abs(a[2] - a[0]) <= a[3]) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    vector<vector<ll>> roads;
    ll N, M;
    cin >> N >> M;
    roads.resize(N);
    for(ll i = 0;i < M;i++) {
        ll a, b;
        cin >> a >> b;
        roads[a - 1].push_back(b);
        roads[b - 1].push_back(a);
    }
    for(auto &i: roads) cout << i.size() << endl;
    return 0;
}


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

    int n,i,j,k;
    int a,b;
    cin>>a>>b;
    for(i=1;i<=1250;i++)
    {
        if(floor(i*0.08)==a && floor(i*0.1)==b) {
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}


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

const int INF = 2100100100;

int R, C;
vector<vector<char>> maze; // 迷路の内容を保存する配列
vector<vector<int>> dist;  // 距離を記録しておく配列
int sx, sy, gx, gy;

int main() {
    cin >> R >> C;
    cin >> sy >> sx;
    cin >> gy >> gx;
    sy--; // 0始まりに直す
    sx--;
    gy--;
    gx--;

    dist.assign(R, vector<int>(C, INF));  // 初期化
    maze.assign(R, vector<char>(C, '.')); // 初期化

    for (int i = 0; i < R; i++)
    {
        for (int j = 0; j < C; j++)
            cin >> maze[i][j];
    }

    deque<pair<int, int>> que;
    que.emplace_front(make_pair(sy, sx)); // sから探索する
    dist[sy][sx] = 0;
    while (que.size() != 0){                                     // キューの要素がなくなったら終了
        pair<int, int> now = que.front(); // 現在の状態
        que.pop_front();

        int dy[4] = {0, 0, 1, -1}; // dx,dy は次の探索場所への距離を表す（４方向分）
        int dx[4] = {1, -1, 0, 0};
        for (int i = 0; i < 4; i++){
            int ny = now.first + dy[i];  // 次の探索場所の行番号
            int nx = now.second + dx[i]; // 次の探索場所の列番号
            if (ny < 0 || R <= ny || nx < 0 || C <= nx)
                continue; // 迷路の外に出るならスルー
            if (maze[ny][nx] == '#')
                continue; // 障害物があればスルー
            //if (dist[ny][nx] != INF) continue;                     //探索済みならスルー
            if (dist[ny][nx] > dist[now.first][now.second]){
                que.push_front(make_pair(ny, nx));
            }
            dist[ny][nx] = min(dist[ny][nx], dist[now.first][now.second]);
        }
        for (int i = -2; i <= 2; i++){
            for (int y = -2; y <= 2; y++){
                int ny = now.first + i;  // 次の探索場所の行番号
                int nx = now.second + y; // 次の探索場所の列番号
                if (ny < 0 || R <= ny || nx < 0 || C <= nx)
                    continue; // 迷路の外に出るならスルー
                if (maze[ny][nx] == '#')
                    continue; // 障害物があればスルー
                //if (dist[ny][nx] != INF) continue;                     //探索済みならスルー
                if (dist[ny][nx] > dist[now.first][now.second] + 1){
                    que.push_back(make_pair(ny, nx));
                }
                dist[ny][nx] = min(dist[now.first][now.second] + 1, dist[ny][nx]);
            }
        }
    }

    if (dist[gy][gx] > 1e7){
        cout << -1 << endl;
        return 0;
    }
    cout << dist[gy][gx] << endl;

    return 0;
}

Measured memory_bytes: 8560
#include<iostream>
main()
{
	int n,m;std::cin>>n>>m;
	int a[100][100]={},b[100][100]={};
	for(int i=0;i<n;i++)for(int j=0;j<n;j++)if(i!=j)b[i][j]=1<<28;
	for(int i=0;i<m;i++)
	{
		int u,v,c;
		std::cin>>u>>v>>c;u--,v--;
		a[u][v]=a[v][u]=b[u][v]=b[v][u]=c;
	}
	for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)b[i][j]=std::min(b[i][j],b[i][k]+b[k][j]);
	int c=0;
	for(int i=0;i<n;i++)for(int j=i+1;j<n;j++)if(a[i][j]>b[i][j])c++;
	std::cout<<c<<"\n";
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int c = scanner.nextInt();
    System.out.println(ans(c));
  }
  
  public static int ans(int c) {
    int h = 0;
    if(c == 0) { 
      return 0;
    } else {
      int fh = c/500;
      c = c%500;
      int f = c/5;
      h = fh*1000 + f*5;
      return h;
    }
  }
}


Measured memory_bytes: 23508
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);++i)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int gcd(int a,int b) { return b ? gcd(b,a%b) : a;}
int lcm(int a,int b) { return a/gcd(a,b)*b;}
void printb(unsigned int v) {
  unsigned int mask = (int)1 << (sizeof(v) * CHAR_BIT - 1);
  do putchar(mask & v ? '1' : '0');
  while (mask >>= 1);
}
void putb(unsigned int v) {putchar('0'), putchar('b'), printb(v), putchar('\n');}
#define ALL(W) (W).begin(),(W).end()

signed main(){
  int N,ans=1145141919;
  cin >> N;
  string s;
  int le=0,lw=0,re=0,rw=0;
  cin >> s;
  rep(i,N){
    if(s[i]=='E') re++;
    else rw++;
  }
  rep(i,N){
    if(s[i]=='E') re--;
    else rw--;
    if(0<i){
      if(s[i-1]=='E') le++;
      else lw++;
    }
    chmin(ans,lw+re);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 900
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
string n;
int ns;
string t[500000];
int pos;
int use[30];

bool che(string x,int cnt){
rep(i,26)use[i]=0;

rep(i,cnt){
	int tmp=x[i]-'a';
	if(!use[tmp]&&tmp>0){
		x[i]--;
		use[tmp]=1;
	}
}
	for(int i=0;i<cnt;i++)if(x[i]!=n[i])return 0;
	return 1;
	//return x==n;
}

void dfs(int now,string x){
	if(ns==now){

		if(che(x,ns))t[pos++]=x;
		return;
	}

	if(che(x+n[now],now+1))
	dfs(now+1,x+n[now]);

	if(n[now]!='z'){
		char a=n[now];
		a++;
		if(che(x+a,now+1))
		dfs(now+1,x+a);
	}

}

int main(){
while(cin>>n,n!="#"){

ns=n.size();
dfs(0,"");
cout<<pos<<endl;
if(pos<=10){
	rep(i,pos)cout<<t[i]<<endl;
}

else{
	rep(i,5)cout<<t[i]<<endl;
	for(int i=pos-5;i<pos;i++)cout<<t[i]<<endl;
}
rep(i,pos)t[i]="";
pos=0;
}
	return 0;
}


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

using namespace std;

const int MaxN = 100005;

int n;
pair<int, int> a[MaxN];
long long Res[MaxN];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i].first;
        a[i].second = i;
        Res[i] = 0;
    }
    sort(a + 1, a + n + 1, greater<pair<int, int>>());
    int Min = a[1].second;
    for (int i = 1; i <= n; i++)
    {
        Min = min(Min, a[i].second);
        Res[Min] += 1LL * (a[i].first - a[i + 1].first) * i;
    }
    for (int i = 1; i <= n; i++)
    {
        cout << Res[i] << '\n';
    }
    return 0;
}


Measured memory_bytes: 2688
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

const int N = 1000;

int B[2 * N][2 * N];
int W[2 * N][2 * N];

int getB(int a, int b, int x, int y) {
  if(a > x || b > y) return 0;
  return B[x][y] - (a?B[a - 1][y]:0) - (b?B[x][b - 1]:0) + ((a&&b)?B[a - 1][b - 1]:0);
}

int getW(int a, int b, int x, int y) {
  if(a > x || b > y) return 0;
  return W[x][y] - (a?W[a - 1][y]:0) - (b?W[x][b - 1]:0) + ((a&&b)?W[a - 1][b - 1]:0);
}

int main() {
  int n,k;
  S2(n,k);
  int mod = 2 * k;
  int b = 0, w = 0;
  rep(i,0,n) {
    int x,y;
    S2(x,y);
    string c;
    cin >> c;
    if(c == "W") {
      W[x % mod][y % mod]++;
      w++;
    } else {
      B[x % mod][y % mod]++;
      b++;
    }
  }

  rep(i,0,mod) rep(j,0,mod) {
    W[i][j] += (i?W[i - 1][j]:0) + (j?W[i][j - 1]:0) - (i&&j?W[i - 1][j - 1]:0);
    B[i][j] += (i?B[i - 1][j]:0) + (j?B[i][j - 1]:0) - (i&&j?B[i - 1][j - 1]:0);
  }
  int ans = 0;
  rep(i,0,k+1) rep(j,0,k+1) {
    int tmpB = 0, tmpW = 0;
    tmpB += getB(0, 0, i - 1, j - 1);
    tmpB += getB(i, j, i + k - 1, j + k - 1);
    tmpB += getB(i + k, 0, 2 * k - 1, j - 1);
    tmpB += getB(i + k, j + k, 2 * k - 1, 2 * k - 1);
    tmpB += getB(0, j + k, i - 1, 2 * k - 1);

    tmpW += getW(0, 0, i - 1, j - 1);
    tmpW += getW(i, j, i + k - 1, j + k - 1);
    tmpW += getW(i + k, 0, 2 * k - 1, j - 1);
    tmpW += getW(i + k, j + k, 2 * k - 1, 2 * k - 1);
    tmpW += getW(0, j + k, i - 1, 2 * k - 1);

    ans = max(ans, tmpB + w - tmpW);
    ans = max(ans, tmpW + b - tmpB);
  }
  P(ans);
  return 0;
}


Measured memory_bytes: 31488
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

#define Fo(i, l, r) for (int i = l; i <= r; ++ i)
#define For(i, n) for (int i = 0; i < n; ++ i)

const int maxn = 3e2 + 10;
const int Mod = 1e9 + 7;

void Chkadd(int &x, const int &y)
{
	if ((x += y) >= Mod) x -= Mod;
}

struct Node
{
	int l, x;
	Node *next;
} pool[maxn], *p = pool, *head[maxn];

void AddNode()
{
	int fr;
	scanf("%d%d%d", &p->l, &fr, &p->x);
	p->next = head[fr];
	head[fr] = p ++;
}

int f[maxn][maxn][maxn];

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	memset(head, 0, sizeof head);
	for (int i = 1; i <= m; ++ i) AddNode();
	f[0][0][0] = 1;
	int ans = 0;
	Fo(i, 0, n)
	{
		for (Node *lim = head[i]; lim; lim = lim->next)
		{
			if (lim->x > 1) f[i][0][0] = 0;
			For(j, i) For(k, j)
			{
				if (lim->x == 1)
					if (lim->l <= j) f[i][j][k] = 0; else;
				else if (lim->x == 2)
					if (lim->l <= k || lim->l > j) f[i][j][k] = 0; else;
				else
					if (lim->l > k) f[i][j][k] = 0;
			}
		}
		if (i == n)
		{
			Chkadd(ans, f[i][0][0] % Mod);
			For(j, i) For(k, j) Chkadd(ans, 2ll * f[i][j][k] % Mod);
			break;
		}
		int &t = f[i][0][0];
		Chkadd(f[i + 1][0][0], t);
		if (i) Chkadd(f[i + 1][i][0], t);
		For(j, i) For(k, j)
		{
			int &t = f[i][j][k];
			Chkadd(f[i + 1][j][k], t);
			Chkadd(f[i + 1][i][k], t);
			Chkadd(f[i + 1][i][j], t);
		}
	}
	ans = 3ll * ans % Mod;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 112896
#include <bits/stdc++.h>
using namespace std; 
int main(){
	int N; long long int K; 
	cin >> N >> K; 
	long long int A[100010] = {}; 
	for(int i = 0; i < N; i++){
		cin >> A[i]; 
	}
	long long int count[45] = {}; // 下位ibit目が1の個数
	long long int ans[45] = {}; // 下位ibit目で初めてK以下が確定する
	for(int i = 0; i < N; i++){
		for(int j = 0; j < 40; j++){
			if((A[i] >> j) & 1) count[j] ++; 
		}
	}
	for(int i = 0; i < 40; i++){
		if(!((K >> i) & 1)) continue; 
		for(int j = 0; j < i; j++){
			ans[i] += (max(count[j], N - count[j]) << j); 
		}
		ans[i] += ((count[i]) << i); 
		for(int j = i+1; j < 40; j++){
			ans[i] += ((((K >> j) & 1) ? (N - count[j]) : count[j]) << j); 
		}
	}
	long long int ansK = 0; 
	for(int j = 0; j < 40; j++){
		ansK += ((((K >> j) & 1) ? (N - count[j]) : count[j]) << j);
	}
	long long int kotae = ansK; 
	for(int i = 0; i < 40; i++){
		kotae = max(kotae, ans[i]); 
	}
	cout << kotae << endl; 
}

Measured memory_bytes: 1024
n, b = (int(i) for i in input().split())  
l = [input() for i in range(n)] 
z = [-1,0,1]

for i in range(n):
  for ii in range(b):
    if l[i][ii] == "#":
      print("#",end="")
    else:
      print(sum([l[x+i][xx+ii] == "#" for x in z for xx in z if 0 <= x+i < n and 0 <= xx+ii < b]),end="")
  print("")

Measured memory_bytes: 3444