akhauriyash/Code-Regression huggingface dataset:
def reverse(num):
    test_num = 0
    while (num > 0):
        remainder = num % 10
        test_num = (test_num * 10) + remainder
        num = num // 10
    return test_num

a,b = list(map(int,input().split()))
c = 0
for i in range(a,b+1):
    if i == reverse(i):
        c+=1
print(c)

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

long long n;
int x, m;

int next(int a) {
    return (long long) a * a % m;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> x >> m;
    vector<int> a;
    vector<bool> used(m, 0);
    int cur = x;
    for (; !used[cur]; cur = next(cur)) {
        used[cur] = 1;
        a.push_back(cur);
    }
    vector<int> preperiod;
    int from = 0;
    while (a[from] != cur) {
        preperiod.push_back(a[from]);
        from++;
    }
    vector<int> period;
    for (int i = from; i < a.size(); i++)
        period.push_back(a[i]);
    long long ans = 0;
    int min_ = min<long long>(n, preperiod.size());
    n -= min_;
    for (int i = 0; i < min_; i++)
        ans += preperiod[i];
    long long full = n / period.size();
    for (int x : period)
        ans += full * x;
    n %= period.size();
    for (int i = 0; i < n; i++)
        ans += period[i];
    cout << ans;
    return 0;
}


Measured memory_bytes: 3824
//
// Created by yamunaku on 2020/06/13.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    //CFS;
    int n, k;
    cin >> n >> k;
    vi a(n);
    rep(i, n){
        cin >> a[i];
    }
    rep(t, k){
        vi b(n + 1);
        rep(i, n){
            b[max(i - a[i], 0)]++;
            b[min(i + a[i], n-1) + 1]--;
        }
        bool ok = true;
        a[0] = b[0];
        if(a[0] < n)ok = false;
        repl(i, 1, n){
            b[i] += b[i - 1];
            a[i] = b[i];
            if(a[i] < n)ok = false;
        }
        if(ok) break;
    }
    rep(i, n){
        cout << a[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
#define P pair<int,int>
#define All(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
typedef long long ll;
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const ll LINF = 1e18;
int main() {
	int n, m;
	cin >> n;
	string s[n + 1] = {};
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	sort(s, s + n + 1);
	cin >> m;
	string w[m];
	for (int i = 0; i < m; i++) {
		cin >> w[i];
	}
	sort(s, s + n + 1);
	reverse(s, s + n + 1);
	int cnt = 1;
	int ans = 0;
	cout << endl;
	// for (int i = 0; i < n; i++) {
	// 	cout << s[i] << endl;
	// }
	for (int i = 0; i < n; i++) {
		if (s[i] == s[i + 1]) {
			//cout << i << " " << cnt << endl;
			cnt++;
		} else {
			//cout << i << " " << cnt << endl;
			for (int j = 0; j < m; j++) {
				if (w[j] == s[i]) {
					cnt--;
				}
			}
			//cout << "i " << i <<  "s[i] " << s[i] << endl;
			//cout << "cnt:" << cnt << " " << "ans:" << ans << endl;
			ans = max(ans, cnt);
			cnt = 1;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
class ModInt:
    def __init__(self, num, mod):
        self.num = num
        self.mod = mod

    def __str__(self):
        return str(self.num)

    def __repr__(self):
        return "ModInt(num: {}, mod: {}".format(self.num, self.mod)

    def __add__(self, other):
        ret = self.num + other.num
        ret %= self.mod
        return ModInt(ret, self.mod)

    def __sub__(self, other):
        ret = self.num - other.num
        ret %= self.mod
        return ModInt(ret, self.mod)

    def __mul__(self, other):
        ret = self.num * other.num
        ret %= self.mod
        return ModInt(ret, self.mod)

    def pow(self, times):
        pw = pow(self.num, times, self.mod)
        return ModInt(pw, self.mod)

    def inverse(self):
        return self.pow(self.mod - 2)

    def __truediv__(self, other):
        num = self * other.inverse()
        return ModInt(num, self.mod)


h, w, a, b = map(int, input().split())
mod = 10 ** 9 + 7

fact = [ModInt(1, mod)]
inv = [ModInt(1, mod).inverse()] * (h + w - 1)


def comb(n, r):
    return fact[n] * inv[r] * inv[n-r]


for i in range(1, h + w - 1):
    fact.append(fact[-1] * ModInt(i, mod))

inv[h+w-2] = fact[-1].inverse()
for i in range(h + w - 2, 0, -1):
    inv[i-1] = inv[i] * ModInt(i, mod)

ans = ModInt(0, mod)
for hi in range(h - a):
    ans += comb(hi + b - 1, hi) * comb(h - hi - 1 + w - b - 1, w - b - 1)

print(ans)


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

typedef long long ll;
const int maxn = 4e5 + 3;
const int maxln = 20;

int n, q;
struct node {
    int s;
    ll ds;
    node *l, *r;
} np[maxn * maxln], nil{0, 0, &nil, &nil}, *nl[maxn];

int npl;
node * alloc(node *k) {
    return &(np[npl++] = *k);
}

void insert(node **p, int k, const int &v, const ll &w) {
    for(int l = 0, r = 2 * n + 3; r - l > 1;) {
        *p = alloc(*p);
        (*p)->s += v;
        (*p)->ds += w;
        int mid = (l + r) / 2;
        p = k < mid ? &(*p)->l : &(*p)->r;
        (k < mid ? r : l) = mid;
    }
    *p = alloc(*p);
    (*p)->s += v;
    (*p)->ds += w;
}

node * query(node *p, int k) {
    if(k < 0 || k >= 2 * n + 3)
        return &nil;
    for(int l = 0, r = 2 * n + 3; r - l > 1 && p != &nil;) {
        int mid = (l + r) / 2;
        p = k < mid ? p->l : p->r;
        (k < mid ? r : l) = mid;
    }
    return p;
}

std::vector<std::tuple<int, int, int>> E[maxn];

int p[maxn], fa[maxn][maxln];
ll depth[maxn];

void dfs(int u) {
    for(int i = 0; i < E[u].size(); ++i) {
        int v = std::get<0>(E[u][i]);
        int c = std::get<1>(E[u][i]);
        int d = std::get<2>(E[u][i]);
        if(v == p[u])
            continue;
        p[v] = u;
        fa[v][0] = u;
        depth[v] = depth[u] + 1;
        nl[v] = nl[u];
        insert(&nl[v], c, 1, d);
        dfs(v);
    }
}

int lca(int u, int v) {
    if(depth[u] < depth[v])
        std::swap(u, v);
    for(int i = maxln - 1; depth[u] > depth[v] && i >= 0; --i) {
        if(depth[fa[u][i]] >= depth[v])
            u = fa[u][i];
    }
    if(u == v)
        return u;
    for(int i = maxln - 1; i >= 0; --i) {
        if(fa[u][i] != fa[v][i]) {
            u = fa[u][i];
            v = fa[v][i];
        }
    }
    return p[u];
}

ll Q(int u, int v, int c, ll d) {
    int w = lca(u, v);
    ll ans = nl[u]->ds + nl[v]->ds - 2ll * nl[w]->ds;
    auto *p = query(nl[u], c), *q = query(nl[v], c), *r = query(nl[w], c);
    ans -= p->ds + q->ds - 2ll * r->ds;
    ans += (p->s + q->s - 2ll * r->s) * d;
    return ans;
}

int main() {
    scanf("%d%d", &n, &q);
    for(int i = 0; i < n - 1; ++i) {
        int u, v, c, d;
        scanf("%d%d%d%d", &u, &v, &c, &d);
        E[u].emplace_back(v, c, d);
        E[v].emplace_back(u, c, d);
    }
    nl[0] = nl[1] = &nil;
    dfs(1);
    for(int j = 1; j < maxln; ++j)
    for(int i = 1; i <= n; ++i)
        fa[i][j] = fa[fa[i][j - 1]][j - 1];
    for(int i = 0; i < q; ++i) {
        int x, y, u, v;
        scanf("%d%d%d%d", &x, &y, &u, &v);
        printf("%lld\n", Q(u, v, x, y));
    }
    return 0;
}

Measured memory_bytes: 96312
#include <iostream>
#include <algorithm>

using namespace std;

int N;
int n[4];

int calc(int op) 
{
	int t = n[0];
	for (int i = 0; i < 3; i++, op >>= 1) {
		if (op & 1) t += n[i + 1];
		else t -= n[i + 1];
	}
	return t;
}

void solve()
{
	int x;
	for (x = 0; x < 8 && calc(x) != 7; x++);
	cout <<  n[0];
	for (int i = 0; i < 3; i++, x >>= 1) {
		if (x & 1) cout << "+";
		else cout << "-"; 
		cout << n[i + 1];
	}
	cout << "=7\n";
}


int main()
{
	cin >> N;
	for (int i = 0; i < 4; i++, N /= 10) n[3 - i] = N % 10;
	solve();
	return 0;
}

Measured memory_bytes: 256
// #define debug
#ifdef debug
#include <time.h>
#include "/home/majiao/mb.h"
#endif


#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#define MAXN 10005
#include <map>
#include <unordered_set>
#define ll long long int

using namespace std;

int n, m, tree[MAXN<<2], tmp;

void push_up(int rt) { tree[rt] = tree[rt<<1] + tree[rt<<1|1]; }

void build(int rt, int lef, int rig) {
	if(lef == rig) {
		scanf("%d ", tree+rt);
		return ;
	}
	int mid = (lef + rig) >> 1;
	build(rt<<1, lef, mid);
	build(rt<<1|1, mid+1, rig);
	push_up(rt);
}

void update(int rt, int lef, int rig, int idx, int val) {
	if(lef == rig) {
		tmp = tree[rt];
		tree[rt] = val;
		return ;
	}
	int mid = (lef + rig) >> 1;
	if(idx <= mid) update(rt<<1, lef, mid, idx, val);
	else update(rt<<1|1, mid+1, rig, idx, val);
	push_up(rt);
}

int query(int rt, int lef, int rig, int L, int R) {
	if(L<=lef && rig<=R) return tree[rt];
	int mid = (lef + rig) >> 1, ret = 0;
	if(L <= mid) ret += query(rt<<1, lef, mid, L, R);
	if(mid <= R) ret += query(rt<<1|1, mid+1, rig, L, R);
	return ret;
}

int main() {
#ifdef debug
	freopen("test", "r", stdin);
	clock_t stime = clock();
#endif
	scanf("%d\n", &n);
	build(1, 1, n);
	int q;
	scanf("%d ", &q);
	while(q--) {
		int x, y;
		scanf("%d %d ", &x, &y);
		update(1, 1, n, x, y);
		printf("%d\n", query(1, 1, n, 1, n));
		update(1, 1, n, x, tmp);
	}







#ifdef debug
	clock_t etime = clock();
	printf("rum time: %lf 秒\n",(double) (etime-stime)/CLOCKS_PER_SEC);
#endif 
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s,t;
  cin >> n >> s >> t;
  s.reserve(n * 2);
  for(int i = n; i > 0; i--){
    s.insert(i, t, i - 1, 1);
  }
  cout << s << endl;
}

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

#define N 100000

int main(void){
    vector<bool> prime(N+1,true);
    prime[0]=prime[1]=false;
    for (size_t i = 0; i <= sqrt(N); i++)
    {
        if (prime[i])
        {
            for (size_t j = 2; i*j <= N; j++)
            {
                prime[i*j]=false;
            }
        }
    }
    int likeCnt[N]={};
    for (size_t i = 1; i <= N; i++)
    {
        likeCnt[i]=likeCnt[i-1];
        if (i%2==1&&prime[i]&&prime[(i+1)/2])
        {
            likeCnt[i]++;
        }
    }
    /**************************************/
    int q;
    cin >> q;
    int l[q],r[q];
    for (size_t i = 0; i < q; i++)
    {
        cin >>l[i]>>r[i];
    }
    for (size_t i = 0; i < q; i++)
    {
        cout << likeCnt[r[i]]-likeCnt[l[i]-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    string s;
    cin >> s;
    int l=0,c=0,r=0;
    int answer[100000]={0};
    while(r<s.length()){
        while(s[r] == 'R'){
            r++;
        }
        c = r;
        while(s[r] == 'L'){
            r++;
        }
        answer[c-1]=(r-l)/2;
        answer[c] = (r-l)/2;
        if((r-l)%2){
            if(c-l > r-c){
                if((c-l)%2){
                    answer[c-1]++;
                }else{
                    answer[c]++;
                }
            }
            else if(c-l < r-c){
                if((r-c)%2){
                    answer[c]++;
                }else{
                    answer[c-1]++;
                }
            }
        }
        l = r;
    }
    REP(i,s.length()){
        cout << answer[i] << " ";
    }
    cout << endl;
    return 0;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n) { cin >> a[i]; }
    map<ll, ll> m;
    rep(i, n) {
        int num = a[i];
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
    }

    ll all = 0;
    for (auto iter = m.begin(); iter != m.end(); iter++) {
        ll num = iter->second;
        all += num * (num - 1) / 2;
    }

    rep(i, n) {
        ll size = m[a[i]];
        if (size < 2) {
            cout << all << endl;
        } else {
            cout << all - (size * (size - 1) / 2) +
                        ((size - 1) * (size - 2) / 2)
                 << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 12032
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pll pair<ll,ll>
#define pint pll
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll beki[200020];
ll l[200020],r[200020];

int main(){
  ll a,b;
  cin >> a >> b;
  rep(i,100010){
    if(floor((double)i*0.08)==a && floor((double)i*0.10)==b){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
<?php
list($n, $k) = ints();
$a = ints();
$gcd = gcdAll($a);
if ($k % gcdAll($a) === 0 && $k <= max($a)) echo 'POSSIBLE';
else echo 'IMPOSSIBLE';
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
// 最大公約数（2つ）
function gcd($m, $n)
{
    if (!$n) return $m;
    return gcd($n, $m % $n);
}

// 最大公約数（3つ以上）
function gcdAll($arr)
{
    $gcd = array_pop($arr);
    foreach ($arr as $a) {
        $gcd = gcd($gcd, $a);
    }
    return $gcd;
}

// 最小公倍数（2つ）
function lcm($m, $n)
{
    return (int) ($m / gcd($m, $n) * $n); // オーバーフローしないように先に割り算
}

// 最小公倍数（3つ以上）
function lcmAll($arr)
{
    $lcm = array_pop($arr);
    foreach ($arr as $a) {
        $lcm = lcm($lcm, $a);
    }
    return $lcm;
}


Measured memory_bytes: 27260
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	char S[105];
	scanf("%s",S);

	ll K;
	scanf("%lld",&K);

	ll tmp = 0;
	for(int i = 0; S[i] != '\0'; i++){
		if(S[i] == '1'){

			tmp++;
			if(tmp == K){
				printf("1\n");
				return 0;
			}
		}else{

			printf("%c\n",S[i]);
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 3832
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] line = sc.nextLine().split(" ");
		int N = Integer.parseInt(line[0]);
		int W = Integer.parseInt(line[1]);

		int[] w = new int[N + 1];
		int[] v = new int[N + 1];
		for (int i = 0; i < N; i++) {
			line = sc.nextLine().split(" ");
			w[i] = Integer.parseInt(line[0]);
			v[i] = Integer.parseInt(line[1]);
		}

		long[][] dp = new long[N + 1][W + 1];
		for (int i = N - 1; i >= 0; i--) {
			for (int j = 0; j <= W; j++) {
				if (j < w[i]) dp[i][j] = dp[i + 1][j];
				else dp[i][j] = Math.max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
			}
		}
		System.out.println(dp[0][W]);
	}
}

Measured memory_bytes: 125780
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL
typedef struct Node{
  int key;
  struct Node *right,*left,*parent;
}Node;

Node *root;

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

void insert(int k){
  Node *y=NIL;
  Node *x=root;
  Node *z;
  z=malloc(sizeof(Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;
  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }else{
    if(z->key < y->key){
      y->left=z;
    }else{
      y->right=z;
    }
  }
}

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

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

int main(){
  int n,i,x;
  char com[20];

  scanf("%d",&n);

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

Measured memory_bytes: 19364
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define LL long long
#define INF 100000000
#define mod 1000000007
using namespace std;
int keta(int n,int k){return (n/int(pow(10,double(k-1)))) % 10;} //nの下からk桁目
ll gcd(ll n,ll m){
	if(n<m){ll a=m;m=n;n=a;}
	ll r=n%m;
	while(r!=0){
		n=m;
		m=r;
		r=n%m;
	}
	return m;
}
ll lcm(ll n,ll m){
	return n*m/gcd(n,m);
}

int main(){
	int n;
	cin>>n;
	vector<int> a;
	a.resize(n);
	rep(i,n){
		cin>>a[i];
	}
	int b=0;
	int ans=0;
	rep(i,n){
		if(a[i]==i+1){
			if(b==0){
				ans++;
				b++;
			}else{
				b=0;
			}
		}else{
			b=0;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 768
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>

using namespace std;

typedef long long ll;

int n,q;
char s[200010],t[200010],d[200010];

bool is_vnz(int i){
    int p=i;
    for (int j=0;j<q;j++){
        if(s[p]==t[j]&&d[j]=='L'){
            if(p==1) return 1;
            else p--;
        } else if(s[p]==t[j]&&d[j]=='R'){
            if(p==n) return 0;
            else p++;
        }
    }
    return 0;
}

bool is_vnn(int i){
    int p=i;
    for (int j=0;j<q;j++){
        if(s[p]==t[j]&&d[j]=='L'){
            if(p==0) return 0;
            else p--;
        } else if(s[p]==t[j]&&d[j]=='R'){
            if(p==n) return 1;
            else p++;
        }
    }
    return 0;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n>>q;
    s[0]='_';
    for(int i=1;i<=n;i++) cin>>s[i];
    s[n+1]='_';
    for(int i=0;i<q;i++) cin>>t[i]>>d[i];
    
    int ll=0,lr=n+1,rl=0,rr=n+1;
    while(lr-ll!=1){
        int m=(ll+lr)/2;
        if(is_vnz(m)) ll=m;
        else lr=m;
    }
    while(rr-rl!=1){
        int m=(rl+rr)/2;
        if(is_vnn(m)) rr=m;
        else rl=m;
    }
    
    cout<<rr-ll-1<<endl;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL)
typedef long long ll;
const ll mod = 1e9 + 7;
const ll N = 1e5 + 7;
int parent[N];
int sz[N];
int ans[N];

int find(int n) {
	if (parent[n] == n)
		return n;
	return find(parent[n]);
}


void join(int a, int b) {
	a = find(a);
	b = find(b);
	if (a == b)
		return;

	if (sz[a] < sz[b])
		swap(a, b);
	parent[b] = a;
	sz[a] += sz[b];
}

int main() {
	fastIO;
	int n, m, k;
	cin >> n >> m >> k;
	for (int i = 1; i <= n; i++) {
		parent[i] = i;
		sz[i] = 1;
	}
	vector<pair<int, int>> friends, blocks;
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		friends.push_back({ u, v });
		join(u, v);
	}
	for (int i = 0; i < k; i++) {
		int u, v;
		cin >> u >> v;
		blocks.push_back({ u, v });
	}
	for (int i = 1; i <= n; i++) {
		ans[i] = sz[find(i)]-1;
	}
	for (auto i : friends) {
		if (find(i.first) == find(i.second)) {
			ans[i.first]--;
			ans[i.second]--;
		}
	}
	for (auto i : blocks) {
		if (find(i.first) == find(i.second)) {
			ans[i.first]--;
			ans[i.second]--;
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << ' ';
	}
}

Measured memory_bytes: 6248
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll n, m;
  cin >> n >> m;
  vector <vector <ll>> v(n, vector <ll> ());
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    a--; b--;
    v.at(a).push_back(b); v.at(b).push_back(a);
  }
  vector <ll> d(n, INF);
  queue <ll> q;
  vector <ll> res(n);
  d.at(0) = 0;
  q.push(0);
  while (q.size()) {
    ll p = q.front(); q.pop();
    rep(i, v.at(p).size()) {
      ll tmp = v.at(p).at(i);
      if (d.at(tmp) == INF) {
        d.at(tmp) = d.at(p) + 1;
        q.push(tmp);
        res.at(tmp) = p + 1;
      }
    }
  }
  rep(i, n) {
    if (!i) cout << "Yes" << endl;
    else cout << res.at(i) << endl;
  }
}

Measured memory_bytes: 13620
n=[int(k) for k in raw_input().split(" ")][0]
  
def gen_primes(n):
    """ Generate prime numbers until n
    """
    # Maps composites to primes witnessing their compositeness.
    # This is memory efficient, as the sieve is not "run forward"
    # indefinitely, but only as long as required by the current
    # number being tested.
    #
    D = {}
    Dr={}
    
    # The running integer that's checked for primeness
    q = 2
    while q<=n:
        if q not in D:
            # q is a new prime.
            # Yield it and mark its first multiple that isn't
            # already marked in previous iterations
            #
            Dr[q]=None
            D[q * q] = [q]
        else:
            # q is composite. D[q] is the list of primes that
            # divide it. Since we've reached q, we no longer
            # need it in the map, but we'll mark the next 
            # multiples of its witnesses to prepare for larger
            # numbers
            # 
            for p in D[q]:
                D.setdefault(p + q, []).append(p)
            del D[q]
        q += 1
    return Dr.keys()


def decompprime(n,primesorted):
    r={}
    j=0
    i=0
    while n>1 and i*i<n:
        i=primesorted[j]
        ri=0
        while n%i==0:
            n/=i
            ri+=1
        if ri>0:
            r[i]=ri
        j+=1
    if n>1:
        r[n]=1
    return r


def isqrt(x):
    if x < 0:
        raise ValueError('square root not defined for negative numbers')
    n = int(x)
    if n == 0:
        return 0
    a, b = divmod(n.bit_length(), 2)
    x = 2**(a+b)
    while True:
        y = (x + n//x)//2
        if y >= x:
            return x
        x = y
        
def divisors(dcp):
    nn=len(dcp)
    init={1:[0]*nn}
    dxs=sorted(dcp.keys())
    for kk in range(nn):
        k=dxs[kk]
        ninit={}
        kj=1
        for j in range(dcp[k]+1):
            for jj in init.keys():
                ninit[jj*kj]=init[jj][:]
                ninit[jj*kj][kk]+=j
            kj*=k
        init=ninit
     #   print init
    return init

ps=sorted(gen_primes(201))
res=0
for i in range(1,n+1,2):
    divs=divisors(decompprime(i,ps))
    if len(divs)==8:
       # print i
        res+=1
print res


Measured memory_bytes: 2696
def resolve():
    n, x = map(int, input().split())
    l = list(map(int, input().split()))

    bound = [0]
    for i in range(1, n+1):
        bound.append(l[i-1]+bound[i-1])
    ans = 0
    for i in range(n+1):
        if bound[i] <= x:
            ans += 1
    print(ans)
resolve()

Measured memory_bytes: 38384
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val k = readLine()!!.toInt()
    val x = readLine()!!.toInt()
    val y = readLine()!!.toInt()
    var result = 0
    for (i in 1..n) {
        result += if (i <= k) x else y
    }
    println(result)
}


Measured memory_bytes: 30044
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep2(i, m, n) for(int i=(int)m; i<(int)n; i++)
#define ALL(vec) vec.begin(), vec.end()
typedef long long ll;
typedef long double ld;

// 「上の桁から見る」「配るDP」．模範解答を参考にした．

int main(){
    string S;
    int K;
    cin >> S >> K;
    int L = S.size();

    ll dp[1000][4][2];
    rep(i, L+1) rep(j, K+1) rep(k, 2) dp[i][j][k] == 0;
    dp[0][0][0] = 1;

    rep(i, L) rep(j, K+1) rep(k, 2) rep(l, 10){
        int x = S[i] - '0';
        if(k == 0 && l > x) continue;

        int ii, jj, kk;
        ii = i + 1;
        jj = (l == 0) ? j : (j+1);
        kk = (k == 0 && l == x) ? 0 : 1;

        if(jj > K) continue;
        dp[ii][jj][kk] += dp[i][j][k];
    }
    cout << dp[L][K][0] + dp[L][K][1] << endl;
}

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

/*
struct Edge
{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
*/

using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

const int MOD = 1000000007;

class mint
{
    ll x;

public:
    mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
    mint operator-() const
    {
        return mint(-x);
    }

    mint &operator+=(const mint &a)
    {
        if ((x += a.x) >= MOD)
            x -= MOD;
        return *this;
    }

    mint &operator-=(const mint &a)
    {
        if ((x += MOD - a.x) >= MOD)
            x -= MOD;
        return *this;
    }

    mint &operator*=(const mint &a)
    {
        (x *= a.x) %= MOD;
        return *this;
    }

    mint operator+(const mint &a)
    {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint &a)
    {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint &a)
    {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const
    {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const
    {
        return pow(MOD - 2);
    }

    mint &operator/=(const mint &a)
    {
        return (*this) *= a.inv();
    }

    mint operator/(const mint &a)
    {
        mint res(*this);
        return res /= a;
    }

    friend ostream &operator<<(ostream &os, const mint &m)
    {
        os << m.x;
        return os;
    }
};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<ll> A(N);
    for (auto &it : A)
        cin >> it;
    vector<ll> S(N + 1);
    for (int i = 0; i < N; i++) {
        S[i + 1] = S[i] + A[i];
        S[i + 1] %= MOD;
    }
    mint ans = 0;
    for (int i = 0; i < N; i++) {
        mint tmp = A[i] * (S[N] - S[i + 1]);
        ans += tmp;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6332
from heapq import heappush, heappop
import sys
def solve(readline=sys.stdin.readline, write=sys.stdout.write):
    N, M, L = map(int, readline().split())
    if N == 0:
        return 0
    G = [[] for i in range(N)]
    for i in range(M):
        a, b, d, e = map(int, readline().split())
        a -= 1; b -= 1
        G[a].append((b, d, e))
        G[b].append((a, d, e))

    INF = 10**9
    cost = [[INF]*(L+1) for i in range(N)]
    que = [(0, 0, 0)]
    cost[0][0] = 0
    while que:
        c, v, l = heappop(que)
        dv = cost[v][l]
        if c < dv:
            continue
        if v == N-1:
            break
        for w, d, e in G[v]:
            cw = cost[w]
            if l + d <= L and dv < cw[l + d]:
                cw[l + d] = dv
                heappush(que, (dv, w, l+d))
            if dv + e < cw[l]:
                cw[l] = dv + e
                heappush(que, (dv + e, w, l))
    write("%d\n" % min(cost[N-1]))
    return 1

while solve():
    ...



Measured memory_bytes: 6700
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long x = sc.nextLong();
    long y = sc.nextLong();
    long mul_num = x;
    int count = 1;
    while(true) {
      mul_num *= 2;
      if(mul_num > y) {
        break;
      }
      count++;
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 21844
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
using namespace std;

#define abs(N) ((N>0)?N:-1*N)
#define print(S) (cout << S)
#define println(S) (cout << S << endl)

int main(int argc, char const *argv[])
{
  long N,M,buf;
  unsigned long long res=0;
  map<long,long> m;

  cin >> N >> M;
  long A[N];
  long long sum = 0;
  m.insert(make_pair(0,1));
  for (long i = 0; i < N; ++i)
  {
    cin >> buf;
    A[i] = buf % M;
    sum = (sum+buf) % M;
    if(m.find(sum) == m.end()){
    	m.insert(make_pair(sum,1));
    }else{
    	m[sum]++;
    }
//    print(sum);
//    print(",");
  }

  for (auto itr = m.begin(); itr!= m.end();itr++) {
	  long c;
//	  printf("[%d,%d]\n",(*itr).first,(*itr).second);
	  c = (*itr).second;
	  res += c*(c-1)/2;
  }



  println(res);

  return 0;
}


Measured memory_bytes: 4992
import java.util.*

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

fun solve(){
    val (n,k) = readints()
    var ans = k
    for(i in 0 until n - 1) ans *= k - 1
    println(ans)
}

fun read() = readLine()!!
fun reads() = readLine()!!.split(" ")
fun readint() = readLine()!!.toInt()
fun readints() = readLine()!!.split(" ").map{it.toInt()}
fun readlong() = readLine()!!.toLong()
fun readlongs() = readLine()!!.split(" ").map{it.toLong()}

Measured memory_bytes: 36372
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

public class Hello{
    
    private static int N;
    private static int K;
    
    public static void Main(){
        var line = Console.ReadLine().Split(' ');
        N = int.Parse(line[0]);
        K = int.Parse(line[1]);
        var sequence = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        int sum = sequence.Sum();
        var candidate = new List<int>();
        for(int i=1;i<=sum;i++){
            if(sum%i==0){
                candidate.Add(i);
            }
        }
        int ans = 0;
        foreach(int cand in candidate.OrderByDescending(x => x)){
            if(PlusOrMinus(0,sequence.Select(x => x%cand).Where(x => x!=0).OrderBy(x => x).ToArray(),0,0,cand,true)){
                ans = cand;
                break;
            }
        }
        Console.WriteLine(ans);
    }
    private static bool PlusOrMinus(int index, int[] arr, int plus, int minus, int cand, bool isPlus){
        if(arr.Length<=0){
            return true;
        }
        if(plus<minus){
            return false;
        }
        if(index==arr.Length){
            if(plus==minus && plus<=K){
                return true;
            }else{
                return false;
            }
        }
        if(isPlus){
            return PlusOrMinus(index+1,arr,plus+arr[index],minus,cand,true) || PlusOrMinus(index+1,arr,plus+arr[index],minus,cand,false);
        }else{
            return PlusOrMinus(index+1,arr,plus,minus+cand-arr[index],cand,false);
        }
    }
}

Measured memory_bytes: 17568
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;
import java.util.stream.Collectors;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();
    String s = sc.next();

    int l = 0;
    int r = 1;
    int ans = 0;
    while (l < s.length()) {
      while (r < s.length() && s.charAt(l) == s.charAt(r)) r++;
      ans++;
      l = r;
      r = l + 1;
    }
    os.println(ans);
  }

}

Measured memory_bytes: 24404
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int R = sc.nextInt();
        int G = sc.nextInt();
        int B = sc.nextInt();
        int N = sc.nextInt();
        //Rr + Gg + Bb = N
        int ans = 0;
        for(int b = 0; b < N + 1; b++) {
            int M = N - B * b;
            if (M < 0) break;
            for (int g = 0; g < N + 1; g++) {
                int L = M - G * g;
                if (L < 0) break;
                if (L%R == 0) ans++;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21716
#include<iostream>
#include<algorithm>

using namespace std;

int main(void){

	int n,a2,a5,tmp;

	while(1){
		cin>>n;
		if(n==0) break;
		a2=0,a5=0;
		for(int i=1;i<=n;i++){
			tmp=i;
			while(tmp%2==0){
				a2++;
				tmp/=2;
			}
			while(tmp%5==0){
				a5++;
				tmp/=5;
			}
		}
		cout<<min(a2,a5)<<endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  string T;
  
  cin >> S >> T;
  
  long long s,t;
  s=S.size();
  t=T.size();
  
  
  int count=0;
  for(int i=0;i<s;i++){
    if(S.at(i)!=T.at(i)){
      count++;
    }
  }
  
  cout << count << endl;
  
}

Measured memory_bytes: 3908
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Set<Integer> s = new HashSet<>();
        for(int i=0;i<n;i++){
            s.add(scanner.nextInt());
        }
        System.out.println(s.size());
    }
}

Measured memory_bytes: 23124
#include<stdio.h>

int main(){
 int i,j;
 int A[4];
 int B[4];
 int cnt1;
 int cnt2;

 while(scanf("%d",&A[0])!=EOF)
 {

   cnt1=0;
   cnt2=0;
   for(i=1;i<4;i++)scanf("%d",&A[i]);
   for(i=0;i<4;i++)scanf("%d",&B[i]);

   /*hit*/
   for(i=0;i<4;i++)
     if(A[i]==B[i])cnt1++;

   printf("%d ",cnt1);

   /*blow*/
   for(i=0;i<4;i++)
   {
     for(j=0;j<4;j++)
     {
       if( i!=j && B[i]==A[j] )
         cnt2++;
     }
   }

   printf("%d\n",cnt2);

 }

return 0;
}


Measured memory_bytes: 2040
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
//#define double long double

using namespace std;

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;
}

const int MOD = 1e9 + 7;
const ll INF = 1e9;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 100020;

template <class Abel> struct BIT {
	const Abel UNITY_SUM = 0;
	vector<Abel>dat;
	BIT(int n):dat(n+1,UNITY_SUM){}
	void init(int n) { dat.assign(n + 1, UNITY_SUM); }

	inline void add(int a, Abel x) {
		for (int i = a; i < (int)dat.size(); i += i & -i)
			dat[i] = dat[i] + x;
	}
	inline Abel sum(int a) {
		Abel res = UNITY_SUM;
		for (int i = a; i > 0; i -= i & -i)
			res = res + dat[i];
		return res;
	}
	inline Abel sum(int a, int b) {
		return sum(b - 1) - sum(a - 1);
	}
};

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

	ll N; cin >> N;
	vector<int>a(N); REP(i, N)cin >> a[i];
	int low = 0, high = 1 << 30;
	const int geta = N + 1;
	while (high - low > 1) {
		int mid = (low + high) / 2;
		ll num = 0;
		BIT<ll>bit(N * 2 + 10);
		int sum = 0;
		bit.add(sum + geta, 1);
		REP(i, N) {
			int val;
			if (a[i] <= mid)val = 1; else val = -1;
			sum += val;
			num += bit.sum(1, sum + geta);
			bit.add(sum + geta, 1);
		}
		if (num > (N + 1) * N / 2 / 2)high = mid;
		else low = mid;
	}
	print(high);
}



Measured memory_bytes: 2664
import heapq
def dijkstra(n, edge, dist, s):
    min_dist = [float('inf')] * n
    min_dist[s] = 0
    next_v = []
    heapq.heappush(next_v, (0, s))
    path = [-1] * n
    
    while True:
        if len(next_v) == 0: break
        d, v = heapq.heappop(next_v)
        
        for u in edge[v]:
            if min_dist[u] > min_dist[v] + dist[v][u]:
                min_dist[u] = min_dist[v] + dist[v][u]
                heapq.heappush(next_v, (min_dist[u], u))
                path[u] = v
                
    return min_dist, path

n, m = map(int, input().split())
dist = [[float('inf') for _ in range(n)] for _ in range(n)]
edge = [[] for _ in range(n)]

for _ in range(m):
    a, b, c = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
    dist[a-1][b-1] = c
    dist[b-1][a-1] = c

for i in range(n): dist[i][i] = 0

e = set()
for i in range(n):
    md, path = dijkstra(n, edge, dist, i)
    for i, p in enumerate(path):
        if p == -1: continue
        if i <= p: e.add((i, p))
        else: e.add((p, i))

print(m - len(e))

Measured memory_bytes: 3444
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;



#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

ll debugFlag = false;
template<typename T> void debug(T&);
template<typename T> void debug(T&, bool);
template<typename T> void debug(vector<T>&);
template<typename T> void debug(vector<T>&, bool);
template<typename T, typename U> void debug(pair<T, U>&);
template<typename T, typename U> void debug(pair<T, U>&, bool);

template<typename T>
void debug(T& obj) {
	debug(obj, true);
}

template<typename T>
void debug(T& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << obj;
	if (lnFlag) cout << endl;
}

template<typename T>
void debug(vector<T>& obj) {
	debug(obj, true);
}

template<typename T>
void debug(vector<T>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "[";
	rep(i, obj.size()) {
		if (i != 0) cout << ",";
		debug(obj[i], false);
	}
	cout << "]";
	if (lnFlag) cout << endl;
}

template<typename T, typename U>
void debug(pair<T, U>& obj) {
	debug(obj, true);
}

template<typename T, typename U>
void debug(pair<T, U>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "(";
	debug(obj.first, false);
	cout << ",";
	debug(obj.second, false);
	cout << ")";
	if (lnFlag) cout << endl;
}

void solve() {

	ll S;
	cin >> S;

	ll x1 = ceil(sqrt(S));

	ll y2 = x1;
	ll y1 = x1 * y2 - S;

	cout << 0 << " " << 0 << " " << x1 << " " << y1 << " " << 1 << " " << y2;


}


int main(int argc, char* argv[]) {
	if (argc == 2 && string(argv[1]) == "debug") debugFlag = true;
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 888
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
struct Edge{ll from, to, cost;};
struct node{ll cost, to;
  bool friend operator>(node a, node b){
    return a.cost>b.cost;
  }
};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

ll X, Y, Z, K;
llvec A, B, C, AB;

bool chk(ll m){//和がm以上の組み合わせの個数がK個未満か判定する
  ll ans = 0;
  rep(i, Z){
    ans += (ll)(AB.end() - lower_bound(ALL(AB), m-C[i]));
    if(ans>=K)return false;
  }
  //cout <<"\t"<< m<<" "<< ans<<endl;
  return ans < K ;
}

/**************************************
** A main function starts from here  **
***************************************/
int main(){
  cin >> X >> Y >> Z >> K;
  A=llvec(X);
  B=llvec(Y);
  C=llvec(Z);
  AB=llvec(X*Y);
  rep(i, X) cin >> A[i];
  rep(i, Y) cin >> B[i];
  rep(i, Z) cin >> C[i];

  rep(i, X){
    rep(j, Y){
      AB[i*Y+j]=A[i]+B[j];
      //cout << AB[i*Y+j] << endl;
    }
  }
  sort(ALL(A));
  sort(ALL(B));
  sort(ALL(C));
  sort(ALL(AB));

  ll ok = 3e10+1;
  ll ng = 0;
  while(abs(ok-ng)>1){
    ll m = (ok + ng) / 2;
    if(chk(m))ok=m;
    else ng=m;
    //cout << ok << " " << ng <<endl;
  }

  priority_queue<ll> q;
  for(ll i = Z-1;i>=0;i--){
    ll tmp = C[i];
    for(ll j=X*Y-1;j>=0;j--){
      if(tmp + AB[j]<ng)break;
      q.push(tmp+AB[j]);
    }
    if(tmp<ng)continue;
  }

  rep(i, K){
    cout << q.top() << endl;
    q.pop();
  }
  return 0;
}


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

using namespace std;

int gcd_euclid(int u, int v) {
  int r;
  while (0 != v) {
    r = u % v; u = v; v = r; /* swap */
  }
  return u;
}

int main(){
  int n,x;
  vector<int> y;
  cin >> n >> x;
  for(int i = 0; i<n; i++){
    int temp;
    cin >> temp;
    y.push_back(temp);
  }
  y.push_back(x);
  std::sort(y.begin(), y.end() );

  vector<int> dif;
  for(int i = 0; i<n; i++){
    int temp;
    temp = y[i+1]-y[i];
    dif.push_back(temp);
  }

  int ans = 0;

  if(dif.size() == 1){
    ans = dif[0];
  }
  else{
    for(int i = 0; i<n; i++){
      if(i == 0){
        ans = gcd_euclid(dif[0],dif[1]);
      }
      else{
        ans = gcd_euclid(ans,dif[i+1]);
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
	string s;
	vector<string> words={"dream","dreamer","erase","eraser"};
	int num;
bool dfs(int i){
	bool ret=false;
	if(i==num)return true;
	for(auto&& w:words){
		if(i+w.size()<=num && s.substr(i,w.size())==w){
		ret=ret or dfs(i+w.size());
		}
	}	
	return ret;

	}


int main(){
	cin >>s;
	num=s.size();
	cout<<(dfs(0)?"YES":"NO")<<endl;

}

Measured memory_bytes: 2432
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

N = gif
x = gi
tx = x.sort
b1 = (N-1)/2
b2 = (N+1)/2
B = (tx[b1]+tx[b2])/2
rep N do |i|
  puts B >= x[i] ? tx[b2] : tx[b1]
end


Measured memory_bytes: 23780
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
ll int large=(ll int)1e13+7;
ll int mod=(ll int)1e9+7;
ll int const N=(ll int)1e5+10;

ll int mod_exp(ll int x,ll int n)
{
    ll int result=1;
    while(n>0)
    {
        if(n%2==1)
            result=(result*x)%mod;
        x=(x*x)%mod;
        n=n/2;
    }
    return result;
}

ll int mod_inverse(ll int a)
{
    return mod_exp(a,mod-2);
}


ll int finde(ll int a,ll int par[])
{
    if(par[a]<0)
        return a;
    ll int res=finde(par[a],par);
    par[a]=res;
    return res;
}

void unione(ll int a,ll int b,ll int par[])
{
    if((a=finde(a,par))==(b=finde(b,par)))
    return;
    else
    {
       par[a]+=par[b];
       par[b]=a;
    }
}


int main()
{
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
ll int T,i,j,ij;
T=1;
//cin>>T;
while(T--)
{
  string s,t;
  cin>>s>>t;
  ll int ans=0;
  rep(i,0,s.size())
  if(s[i]!=t[i])
    ans++;
  cout<<ans;

}
return 0;
}
















Measured memory_bytes: 3780
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

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

int main(int argc, const char * argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin >> N;
    
    vector<double> v(N);
    rep(i, N)cin >> v[i];
    
    sort(v.begin(), v.end());
    
    double value = v[0];
    rep(i, N-1)
    {
        value = (value + v[i + 1]) / 2;
    }
    
    cout << value << endl;
    
    return 0;
}

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

int main()
{
  string code = "CODEFESTIVAL2016";
  string str; cin >> str;
  int cnt = 0;
  for (int i = 0; i < str.size(); ++i)
	if (str[i] != code[i])
      cnt++;
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(void) {
  long long int a, b, k;
  
  scanf("%lld %lld %lld",&a,&b,&k);
  
  if (a > k){
    a -= k;
  }else if (a+b <= k){ 
    a = b = 0;
  }else {
    b -= k - a;
  	a = 0;
  } 
  
  printf("%lld %lld",a,b);
 
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

void solve(){
    string s,t;
    cin>>s>>t;
    int ans{INT_MAX};
    fr(i,s.length()-t.length()+1){
        int tmp{};
        fr(j,t.length()) if(s[i+j]!=t[j]) ++tmp;
        chmin(ans,tmp);
    }
    cout<<ans<<'\n';
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t{1};
    //cin>>t;
    fr(i,t) solve();
}

Measured memory_bytes: 3608
package main

import (
	"fmt"
)

func main() {


	var A,B,C,D int

	fmt.Scan(&A,&B,&C,&D)

	Tsum :=0
	Asum :=0

	Tsum = C/B

	if C%B !=0{
		Tsum++ 
	}

	Asum = A/D

	if A%D !=0{
		Asum++
	}


	if Tsum<=Asum{

		fmt.Println("Yes")

	}else{

		fmt.Println("No")
	}


}

Measured memory_bytes: 1752