akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <cstdio>
using namespace std;

#define ll long long
#define vecint vector<int>
#define listint list<int>
#define Pii pair<int, int>

#define REP(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define print(a) cout << a << endl

#define MOD 1000000007
#define NIL -1


int main(){
  int a,b,c;
  int ans=1;
  cin>>a>>b>>c;
  if(a!=b){
    ans++;
    if(b!=c&&a!=c) ans++;
  }else{
    if(b!=c) ans++;
  }
  print(ans);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define R register int
#define AC 110100

int n, cnt, tot, last;
int s[AC];
struct road{
	int x, y;
}way[AC];

char ss[AC];

void pre()
{
	scanf("%s", ss + 1);
	n = strlen(ss + 1);
	for(R i = 1; i <= n; i ++) s[i] = ss[i] == '1';
	for(R i = 1; i <= n; i ++)
	{
		if(s[i] != s[n - i])
		{
			printf("-1\n");
			exit(0);
		}
	}
	if(s[1] != 1) 
	{
		printf("-1\n");
		exit(0);
	}	
}

inline void add(int f, int w)
{
	way[++tot] = (road){f, w};
	//printf("%d ---> %d\n", f, w);
}

void work()
{
	cnt = last = 1;
	for(R i = 2; i <= n; i ++)
	{
		if(s[i] || i == n)
		{
			add(cnt + 1, last), ++ cnt;
			int k = i - cnt;
			for(R j = 1; j <= k; j ++) add(cnt + j, cnt);
			last = cnt, cnt = cnt + k;
		}
	}
	for(R i = 1; i <= tot; i ++) printf("%d %d\n", way[i].y, way[i].x);
}

int main()
{
	pre();
	work();
	return 0;
}

Measured memory_bytes: 2688
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s = br.readLine();
		int a =Integer.parseInt(s);


		int p = 0;

		while(Math.pow(p, 2)<=a) {
			p++;
		}

		System.out.println((int)Math.pow(p-1, 2));


	}


}


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

int main() {
    int N, D, X; cin >> N >> D >> X;
    int nchoco = 0;
    for (int i = 0; i < N; i++)
    {
        int a; cin >> a;
        nchoco += (D-1)/a + 1;
    }
    cout << nchoco + X << endl;
     
}

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

int main(void) {
  string S; cin >> S;
  long w = 0, b = 0;
  for (int i = 0; i < S.length(); i++) {
    char s = S[i];
    w += !(i%2) * (s == '1') + (i%2) * (s == '0');
    b += !(i%2) * (s == '0') + (i%2) * (s == '1');
  }
  cout << (w < b ? w : b) << endl;

  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
vector<int> g[N];
int n,m,a,b,in[N],lev[N];
int main(){
  scanf("%d%d",&n,&m);
  for(int i = 0; i < m; ++i){
  	scanf("%d%d",&a,&b);
    g[a].emplace_back(b);
    in[b]++;
  }
  queue<int> q;
  for(int i = 1; i <= n; ++i)if(in[i]==0)q.push(i);
  while(!q.empty()){
  	int u = q.front();
    q.pop();
    for(int &i: g[u]){
    	in[i]--;
        if(in[i] == 0){
        	lev[i] = lev[u]+1;
            q.push(i);
        }
    }
  }
  printf("%d",*max_element(lev+1,lev+1+n));
  return 0;
}

Measured memory_bytes: 6528
s = int(input()) 
 
if 400 <= s <= 599:
  print("8")
elif  600 <= s <=799:
        print("7")
elif  800 <= s <=999:
        print("6")
elif  1000 <= s <=1199:
        print("5")
elif  1200 <= s <=1399:
        print("4")
elif  1400 <= s <=1599:
        print("3")
elif  1600 <= s <=1799:
        print("2")
elif  1800 <= s <=1999:
        print("1")

Measured memory_bytes: 9060
#include<cstdio>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
#include<queue>
#include<string.h>
#include<vector>
using namespace std;
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void read (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: read;
using io :: putc;
using io :: print;
typedef long long int ll;
ll a[200005][30],ans;
char s[200005];
int main()
{
	int i,j,k;
    scanf("%s",s+1);
    memset(a,0,sizeof(a));
    int len=strlen(s+1);
    ans=0;
    for(i=1;i<=len;i++)
    {
        for(j=0;j<26;j++)
            a[i][j]=a[i-1][j];
        a[i][s[i]-'a']++;
    }
    for(i=1;i<=len;i++)
        ans+=len-i-a[len][s[i]-'a']+a[i][s[i]-'a'];
    print(ans+1),putc('\n');
    return 0;
}

Measured memory_bytes: 47360
console.log((args=>{
  const [[N],A] = args.trim().split('\n').map(r=>r.split(' ').map(v=>v|0));
  const a = new Map();
  for ( let i = 0; i < N; i++ ) {
    a.set(A[i],(a.get(A[i])|0)+1);
  }
  const e = [];
  for ( const [k,v] of a ) {
    if ( v >= 2 ) e.push(k);
    if ( v >= 4 ) e.push(k);
  }
  if ( e.length < 2 ) return '0';
  e.sort((a,b)=>b-a);
  return `${BigInt(e[0])*BigInt(e[1])}`;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));


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

int main() {
  long long N,M,A,B,C,ans,a,b;
  cin >>N>>M;
  ans=0;
  long long H[N],f[N];
  for(int i=0;i<N;i++){
    f[i]=1;
    cin>>H[i];
  }
  for(int i=0;i<M;i++){
    cin>>a>>b;
    if(H[a-1]<H[b-1]){
      f[a-1]=0;
    }
    else if(H[a-1]==H[b-1]){
      f[a-1]=0;
      f[b-1]=0;
    }
    else{
      f[b-1]=0;
    }
  }
    for(int i=0;i<N;i++){
    ans+=f[i];
  }
 
  cout<<ans<<endl;
}

Measured memory_bytes: 5196
#include <stdio.h>
#define N 5000
#define MAX(a, b) ((a)>(b)?(a):(b))

short nail[N+1][N+1];

int main(void) {
    int m, n, a, b, x, i, j;
    int ans = 0;
    scanf("%d %d", &n, &m);
    for (i = 0; i < m; i++) {
        scanf("%d %d %d", &a, &b, &x);
        nail[a][b] = x + 1;
    }
    for (i = 1; i <= n; i++) {
        for (j = 1; j <= i; j++) {
            nail[i][j] = MAX(nail[i][j],
                    MAX(nail[i-1][j], nail[i-1][j-1])-1);
            if (nail[i][j] > 0) ans++;
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 48276
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main {
	static ArrayList<Integer>[] gp;
	static int dp[];

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		FastScanner in = new FastScanner();
		int n = in.nextInt();
		int m = in.nextInt();
		gp = new ArrayList[n + 1];
		for (int i = 0; i < n + 1; i++) {
			gp[i] = new ArrayList<Integer>();
		}
		dp = new int[n + 1];
		Arrays.fill(dp, -1);
		for (int i = 0; i < m; i++) {
			int x = in.nextInt();
			int y = in.nextInt();
			gp[x].add(y);
		}
		int ans = 0;
		for (int i = 1; i <= n; i++) {
			ans = Math.max(ans, dfs(i));
		}
		System.out.println(ans);
	}

	private static int dfs(int src) {

		if (dp[src] != -1)
			return dp[src];
		int bestans = 0;
		int leaf = 1;
		for (int child : gp[src]) {
			leaf = 0;
			bestans = Math.max(bestans, dfs(child));
		}
		if (leaf == 1) {
			dp[src] = 0;
			return 0;
		} else {
			dp[src] = 1 + bestans;
			return 1 + bestans;
		}
	}

	static void sort(int[] a) {
		ArrayList<Integer> l = new ArrayList<>();
		for (int i : a)
			l.add(i);
		Collections.sort(l);
		for (int i = 0; i < a.length; i++)
			a[i] = l.get(i);
	}

	static class FastScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			while (!st.hasMoreTokens())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] readArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

}

Measured memory_bytes: 72920
#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(ll 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;
	ll ans = 0;
	cin >> n;
	vector<int> a(n);
	rep (i, n) cin >> a[i];
	int now_xor = 0, now_sum = 0, left = 0;
	rep (i, n) { // right
		now_xor ^= a[i];
		now_sum += a[i];
		while (now_xor != now_sum) {
			now_xor ^= a[left];
			now_sum -= a[left];
			left++;
		}
		eprintf("[%d,%d]", left, i);
		ans += (ll)(i - left + 1);
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 1024
#include <map>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>

#define x first
#define y second

#define INF 0x3f3f3f3f

using namespace std;

const int maxn = 1e5 + 10;

typedef long long LL;
typedef pair<int,int>PII;

int a,b;

bool Check(int x) {
	int c = x * 0.08,d = x * 0.1;
	if(c >= a && d >= b) return true;
	else return false;
} 

int main(void) {
	cin >> a >> b;
	int l = 1,r = maxn;
	while(l < r) {
		int mid = l + r >> 1;
		if(Check(mid)) r = mid;
		else l = mid + 1;
	}
	int x = r * 0.08,y = r * 0.1;
	if(x == a && b == y) {
		cout << r << endl;
	} else {
		cout << -1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n,k;
vector <int> w;
 
bool check(int m) {
 
  int i=0;
  int cnt =0;
  while(1) {
    cnt++;
    if(cnt > k) return false;
    int sum =0;
    while(sum+w[i] <= m && i != n) sum+= w[i], i++;
    if(i == n) break;
  }
 
  return true;
 
}
 
 
int bainary_search(int R) {
  int L=0,M;
 
  while(L<R){
    M=(L+R)/2;
    if(check(M) == true) R = M;//,cout <<"true"<<endl;
    else L = M+1;
  }
  return L;
 
}
 
int main() {
 
  cin >> n >> k;
 
  w.resize(n);
  int maxR = 0;
  for(int i=0;i<n;i++) cin >> w[i],maxR+=w[i];
   
  cout <<  bainary_search(maxR) <<endl;
 
  return 0;
}

Measured memory_bytes: 3140
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	string S;
	bool flag = false;
	cin >> S;
	if (S == "keyence")flag = true;
	for (int i = 0; i < S.size(); i++) {
		for (int j = 0; j < S.size()-i; j++) {
			string s = S;
			s.erase(i, j);
			if (s == "keyence")flag = true;
		}
	}
	if (flag)cout << "YES";
	else cout << "NO";
}

Measured memory_bytes: 256
N, M = gets.chomp.split(" ").map(&:to_i)
A = gets.chomp.split(" ").map(&:to_i)

AA = Hash.new{|h, k| h[k] = 0}
wk = 0
A.each{|a|
  wk += a
  AA[wk % M] += 1
}
ans = 0
AA.each{|k, v|
  if k == 0 then
    ans += (v * (v + 1) / 2)
  else
    ans += (v * (v - 1) / 2)
  end
}

puts ans


Measured memory_bytes: 12676
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
    string s;
    cin >> s;
    int a = s[0] - '0', b = s[1]-'0', c=s[2]-'0', d=s[3]-'0';
    if (a+b+c+d==7) cout << a<<'+'<<b<<'+'<<c<<'+'<<d<<"=7";
    else if (a-b+c+d==7) cout << a<<'-'<<b<<'+'<<c<<'+'<<d<<"=7";
    else if (a+b-c+d==7) cout << a<<'+'<<b<<'-'<<c<<'+'<<d<<"=7";
    else if (a+b+c-d==7) cout << a<<'+'<<b<<'+'<<c<<'-'<<d<<"=7";
    else if (a-b-c+d==7) cout << a<<'-'<<b<<'-'<<c<<'+'<<d<<"=7";
    else if (a-b+c-d==7) cout << a<<'-'<<b<<'+'<<c<<'-'<<d<<"=7";
    else if (a+b-c-d==7) cout << a<<'+'<<b<<'-'<<c<<'-'<<d<<"=7";
    else if (a-b-c-d==7) cout << a<<'-'<<b<<'-'<<c<<'-'<<d<<"=7";
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define ff first
#define ss second
#define mod 1000000007
 
int32_t main() 
{
    IO;
    string s;
    cin>>s;
    string t;
    cin>>t;
    bool f = true;
    for(int i=0;i<s.length();i++)
    {
        if(s[i] != t[i])
        {
            f = false;
            break;
        }
        
    }
    if(f)
    cout<<"Yes";
    else
    cout<<"No";
	return 0;
}


Measured memory_bytes: 3656
#include<iostream>
#include<complex>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<iomanip>
#include<cassert>

#define EQ(a,b) (abs((a)-(b)) < EPS)
#define fs first
#define sc second
#define pb push_back
#define sz size()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;

typedef long double D;
typedef complex<D> P;
typedef pair<P,P> L;
typedef pair<P,D> C;

const D PI = acos(-1);
const D EPS = 1e-10;

P unit(P p){return p / abs(p);}
pair<P,P> norm(P p){return make_pair(p*P(0,1),p*P(0,-1));}
D dot(P x,P y){return real(conj(x)*y);}
D cross(P x,P y){return imag(conj(x)*y);}


bool para(L a,L b){return abs(cross(a.fs-a.sc,b.fs-b.sc))<EPS;}

P line_cp(L a,L b){
  return a.fs+(a.sc-a.fs)*cross(b.sc-b.fs,b.fs-a.fs)/cross(b.sc-b.fs,a.sc-a.fs);
}

D seg_p_dis(L a,P x){
  if(dot(a.sc-a.fs,x-a.fs)<EPS)return abs(x-a.fs);
  if(dot(a.fs-a.sc,x-a.sc)<EPS)return abs(x-a.sc);
  return abs(cross(a.sc-a.fs,x-a.fs))/abs(a.sc-a.fs);
}


bool in_cir(C c,P x){return (abs(x-c.fs) +EPS < c.sc);}
bool on_cir(C c,P x){return EQ(abs(x-c.fs),c.sc);}

bool is_cp_cir_seg(C c, L s){
  D dis = seg_p_dis(s, c.fs);
  return (dis+EPS<c.sc);
}

vector<P> cp_cir_to_line(C a, L l){
  vector<P> v;
  P n = norm(l.fs-l.sc).fs;
  P p = line_cp(l,L(a.fs,a.fs+n));

  if(on_cir(a,p))v.pb(p);
  else if(in_cir(a,p)){
    D d = abs(a.fs-p);
    D len = sqrt(a.sc*a.sc - d*d);
    P cp_vec = len * unit(l.fs-l.sc);
    v.pb(p + cp_vec);
    v.pb(p - cp_vec);
  }
  return v;
}

vector<L> adj_line(C c, P p){
  vector<L> res;
  P a = c.fs + c.sc * unit(c.fs-p);
  vector<P> b = cp_cir_to_line(C(c.fs,abs(c.fs-p)), L(a,a+norm(c.fs-p).fs));
  rep(i,b.sz)res.pb(L(p, c.fs + c.sc * unit(c.fs-b[i])));
  return res;
}

int main(){
  int n,d;
  D x,y,r;
  C c[10];
  cin >> n >> d;
  
  rep(i,n){
    cin >> x >> y >> r;
    c[i] = C(P(x,y),r);
  }

  D res = -1.0;
  P s = P(25,0), g = P(25,94);

  L l = L(s,g);
  int cnt = 0;
  rep(i,n)cnt += is_cp_cir_seg(c[i],l);
  if(cnt <= d)res = abs(l.fs-l.sc);

  rep(i,n){
    vector<L> v1 = adj_line(c[i],s);    
    rep(j,n){
      vector<L> v2 = adj_line(c[j],g);
      rep(ii,v1.sz)rep(jj,v2.sz){
	if(para(v1[ii],v2[jj]))continue;
	P cp = line_cp(v1[ii],v2[jj]);

	if(cp.real()<EPS || cp.imag()<EPS ||
	   50.0<cp.real()+EPS || 94.0<cp.imag()+EPS)continue;
	
	L l1 = L(s,cp), l2 = L(g,cp);
	cnt = 0;
	rep(k,n)cnt += is_cp_cir_seg(c[k],l1);
	rep(k,n)cnt += is_cp_cir_seg(c[k],l2);
	rep(k,n)if(in_cir(c[k],cp))cnt--;

	if(cnt <= d){
	  D dis = abs(l1.fs-l1.sc) + abs(l2.fs-l2.sc);
	  if(res<0 || res>dis+EPS)res = dis;
	}
      }
    }
  }

  if(res<0)cout << (int)res << endl;
  else cout << fixed << setprecision(10) << res << endl;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int main()
{
    //power of 2
    ll pw[31];
    pw[0]=1;
    for(int i=1; i<31; ++i) pw[i]=pw[i-1]*2;

    int n;
    cin >>n;
    rep(q,n)
    {
        ll s,d;
        cin >>s >>d;

        int ans=0;

        while(s<d)
        {
            int idx=30;
            while(idx>=0)
            {
                if(abs(s)%pw[idx]==0 && s+pw[idx]<=d) break;
                --idx;
            }

            s+=pw[idx];
            ++ans;

            //cout << "s = " <<s<<endl;
        }

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

Measured memory_bytes: 3080
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> ipair;
typedef tuple<int, int, int> ituple;

// const ll INF = LLONG_MAX;
// const int MOD = (int)1e9 + 7;
// const double EPS = 1e-10;
#define PI acosl(-1)
#define MAX_N 100 + 2

void exec(){
  ll n, k;
  int tmpa, tmpb;
  cin >> n >> k;
  vector<ipair> v;
  for (int i = 0; i < n; i++){
    scanf("%d%d", &tmpa, &tmpb);
    v.push_back(make_pair(tmpa, tmpb));
  }

  sort(v.begin(), v.end());
  ll pos = 0;
  for (int i = 0; i < v.size(); i++){
    pos += v[i].second;
    if (pos >= k){
      cout << v[i].first << endl;
      break;
    }
  }

}

void solve(){
  int t = 1;
  // scanf("%d", &t);
  for (int i = 0; i < t; i++){
    exec();
  }
}

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


Measured memory_bytes: 1400
#include <stdio.h>

#define SIZE 2000000

int main() {
  setvbuf(stdout, NULL, _IOFBF, 4000);
  int A[SIZE];
  int H=0;
  int i, l, largest, tmp, n;
  char com[21], buf[20];
  buf[19]='\n';
  char *p,*c1,*c2;
  c1 = com+1;
  c2 = com+2;
  do {
    fgets(com, 20, stdin);
    if (*com == 'i') {
      n = 0;
      p = com+7;
      while (*p!='\n') {
        n = n*10+*p-'0';
        p++;
      }
      A[++H] = n;
      for (i=H; i>1 && A[i>>1]<A[i];i>>=1) {
        tmp = A[i>>1];
        A[i>>1] = A[i];
        A[i] = tmp;
      }

    } else if (*c1=='x') { // extract
      n = A[1];
      for (i=18; n>0; n/=10) buf[i--]=(n%10)+'0';
      fputs(buf+i+1, stdout);
      A[1] = A[H];
      i = 1;
      while (1) {
        l = i<<1;
        if (l < H && A[l] > A[i])        largest = l;
        else         largest = i;
        if (l+1 < H && A[l+1] > A[largest])  largest = l+1;
        if (largest == i) break;
        tmp = A[i];
        A[i] = A[largest];
        A[largest] = tmp;
        i = largest;
      }
      H--;
    }
  } while (*c2!='d');
  return 0;
}


Measured memory_bytes: 5480
#include<stdio.h>

int main(void){

	int a,b;
	int suma,sumb;
	int i,n;


	while(1){

	suma =0,sumb=0;

	scanf("%d",&n);
	if(n == 0)
		break;

	for(i=0;i<n;i++){

		scanf("%d %d",&a,&b);

		if(a > b)
			suma += a+b;
		else if(a < b)
			sumb += a+b;
		else{
			suma += a;
			sumb += b;
		}
	}

	printf("%d %d\n",suma,sumb);

	}

	return 0;
}

Measured memory_bytes: 600
A, B, K = map(int, input().split())
lisA = []
lisB = []
for i in range(1, A + 1):
  if A % i == 0:
    lisA.append(i)
for i in range(1, B + 1):
  if B % i == 0:
    lisB.append(i)
seA = set(lisA)
seB = set(lisB)
seU = seA&seB
lis = list(seU)
lis.sort(reverse = True)
print(lis[K - 1])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define pb push_back
#define ff first
#define ss second
#define BS binary_search
#define all(c) (c).begin(),(c).end()
#define sz(x) (int)(x).size()
#define EPS 0.000000001 //1e-9
using pii=pair<int,int>;
const long long INF=1e18;

template <class A, class B> ostream& operator<<(ostream& os, const pair<A,B> p) {return os << "(" << p.first << "," << p.second << ")";} 

void dprint(string s) {cout << endl;}
template <class T, class... U> void dprint(string s, T t, U... u) 
{int w = s.find(','); cout << "[" << s.substr(0,w) << ": " << t << "] "; dprint(s.substr(w+1, (int)s.size()-w), u...);} 

#define DEBUG 
#ifdef DEBUG
#define dbg(X...) dprint(#X,X)
#else
#define dbg(X...) "KEEP CALM" 
#endif

const int N=1e6+5; // Don't forget to CHANGE this value ACC. TO Q.

int32_t main()
{
    IOS;
    int n; cin>>n;
    string s; cin>>s;
    int r=0, w=0;
    for(char c: s)
    {
        if(c=='W') w++;
        else r++;
    }
    int ans=0;
    for(int i=0;i<r;i++)
    {
        if(s[i]=='W')
            ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3688
import kotlin.math.abs

fun main() {
    val (a,v) = next2Long()
    val (b,w) = next2Long()
    val t = nextInt()
    if (a == b) return println("YES")
    printYesNo ((v-w) * t >= abs(a - b))
}

val sc = java.util.Scanner(System.`in`)
fun next(): String = sc.next()
fun nextInt() = sc.nextInt()
fun next2Int() = Pair(nextInt(), nextInt())
fun next3Int() = Triple(nextInt(),nextInt(), nextInt())
fun nextIntArray(size: Int) = IntArray(size) { nextInt() }
fun nextLong() = sc.nextLong()
fun next2Long() = Pair(nextLong(), nextLong())
fun nextLine(): String = sc.nextLine()
fun nextList() = nextLine().split(" ")
fun printYesNo(isYes: Boolean) = println(if (isYes) "YES" else "NO")
fun printString(action: StringBuilder.()-> Unit) = println(buildString(action))


Measured memory_bytes: 36292
n , x = map(int, input().split())
a = []
for i in range(n):
	b = int(input())
	a.append(b)

for i in range(n):
	x -= a[i]

w = a[0]
for i in range(n):
	if w > a[i]:
		w = a[i]

count = int(n + x / w)

print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 1000000000;
using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    int d[n], ans = 0;
    rep(i, n) cin >> d[i];
    for (int i = 1; i < n; i++)
      for (int j = 0; j < n - i; j++)
        if (d[j] > d[j + 1]) {
          swap(d[j], d[j + 1]);
          ans++;
        }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

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

    vector<int> b((int)1e+6 + 1);
    for (int i = 0; i < n; i++) {
        b[a[i]]++;
    }

    int r = 0;
    for (int i = 0; i < n; i++) {
        int c = 0;
        int t = a[i];
        for (int j = 1; j * j <= t; j++) {
            if (t % j == 0) {
                if (j * j != t) c += b[t / j];
                c += b[j];
            }
        }
        if (c == 1) r++;
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 7928
n = int(input())
a = [x for x in map(int, input().split())]
b = [x for x in map(int, input().split())]

ans = 0

for i in range(n):
    if a[i] <= b[i]:
        ans += a[i]
        b[i] -= a[i]
        a[i] = 0
        if b[i] == 0:
            continue
        else:
            if a[i + 1] <= b[i]:
                ans += a[i + 1]
                a[i + 1] = 0
                b[i] = 0
            else:
                ans += b[i]
                a[i + 1] -= b[i]
                b[i] = 0

    else:
        ans += b[i]
        a[i] -= b[i]

print(ans)


Measured memory_bytes: 18624
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	string s;
	while(cin >> s) {
		REP(i, SZ(s)-8) {
			cout << s[i];
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include "stdio.h"
#include <iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>

using namespace std;
typedef long long int lld;

int main(){
	int n,q;
	cin>>n>>q;
	vector<lld> arr(n);
	for(int i=0;i<n;i++)cin>>arr[i];
	lld cum_sum[n+1];
	lld alternate_sum[n+1];
	cum_sum[0]=0;
	for(int i=0;i<n;i++)cum_sum[i+1]=cum_sum[i]+arr[i];
	alternate_sum[0]=0;
	alternate_sum[1]=arr[0];
	for(int i=1;i<n;i++){
		alternate_sum[i+1]=alternate_sum[i-1]+arr[i];
		//cout<<cum_sum[i+1]<<endl;
	}
	//for(int i=0;i<n;i++)cout<<alternate_sum[i]<<endl;
	for(int query=0;query<q;query++){
		lld X;
		cin>>X;
		int lo,hi;
		lo=-1;
		hi=n-1;
		while(hi-lo>1){//cout<<lo<<" "<<hi<<endl;
			int mid=(hi+lo)/2;
			if(arr[mid]<X)lo=mid;
			else{
				vector<lld>::iterator it=lower_bound(arr.begin(),arr.end(),2*X-arr[mid]);
				int number=it-arr.begin();
				int eps=(n-mid)-mid+number;
				if(eps<=1)hi=mid;
				else lo=mid;
			}
		}
		//cout<<hi<<" ";
		int cards_played=n-hi;
		lld ans=cum_sum[n]-cum_sum[hi];
		//cout<<ans<<" ";
		//cout<<cards_played<<" ";
		int START=n-2*cards_played;
		//cout<<START<<endl;
		if(START>=0)ans+=alternate_sum[START];
		cout<<ans<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
#define ll long long int 
using namespace std;
int main()
{
	ll n,m,x,y,z;
	cin>>n>>m;
	if(n>m)
	{
		for(x=1;x<=n;x++)
		cout<<m;
	}
	else 
	{
		for(x=1;x<=m;x++)
		cout<<n;
	}
	return 0;
}


Measured memory_bytes: 256
n,ma,mb=map(int,input().split())
INF=10**18
dp=[[[INF for _ in range(401)] for _ in range(401)] for _ in range(n+1)]
ce=[[] for _ in range(n)]
for i in range(n):
  ce[i]=tuple(map(int,input().split()))
dp[0][0][0]=0
for k in range(n):
  for i in range(401):
    for j in range(401):
      a,b,c=ce[k]
      dp[k+1][i][j]=min(dp[k+1][i][j],dp[k][i][j])
      if i+a<401 and j+b<401:
        dp[k+1][i+a][j+b]=min(dp[k+1][i+a][j+b],dp[k][i][j]+c)
ans=INF
for i in range(1,401):
  for j in range(1,401):
    if i*mb==j*ma:ans=min(ans,dp[n][i][j])
if ans==INF:ans=-1
print(ans)

Measured memory_bytes: 127984
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int n,ans=0;
  string a,b,c;
  cin >> n;
  cin >> a >> b >> c;
  for (int i = 0; i < n; i++){
    if (a[i] == b[i]){
      if (b[i] != c[i]){
        ans++;
      }
    }else if (b[i] == c[i]){
      ans++;
    }else if (a[i] == c[i]){
      ans++;
    }else{
      ans += 2;
    }
  }
  cout << ans << "\n";
}


Measured memory_bytes: 256
#include <stdio.h>
int main (){

  int A[100],ans=0,a,b,i,j,minj;

  scanf("%d",&a);
  for(i=0;i<a;i++) scanf("%d",&A[i]);


  for(i=0;i<a;i++){
    minj=i;
    for(j=i;j<a;j++){
      if(j!=minj&&A[j]<A[minj])
          minj=j;
    }
    if(&A[i]!=&A[minj]){
       b=A[i];
       A[i]=A[minj];
       A[minj]=b;
       ans++;
      }
  }

  for(i=0;i<a;i++){
    printf("%d",A[i]);
    if(i<a-1) printf(" ");
    else printf("\n");
  }

  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 2704
#include<iostream>
#include<stdlib.h>
#include<algorithm>

using namespace std;

int ans=0;
int map[90][90];
int x,y;
int s_map[90][90];

void serch(int s_x,int s_y,int s_ans)
{
	map[s_x][s_y]=0;
	
/*	
	getchar();
	
	system("cls");
	
	for(int i=0;i<y;i++)
	{
		for(int j=0;j<x;j++)
		{
			cout << map[j][i] << " " ;
		}
		cout << endl;
	}
	
	cout << s_ans << endl;
*/	
	
	int dx[4]={1,0,-1,0};
	int dy[4]={0,1,0,-1};
	
	if(map[s_x+dx[0]][s_y+dy[0]]==0 && map[s_x+dx[1]][s_y+dy[1]]==0 && map[s_x+dx[2]][s_y+dy[2]]==0 && map[s_x+dx[3]][s_y+dy[3]]==0)
	{
		ans = max(ans,s_ans);
		map[s_x][s_y]=1;
		return ;
	}
	
	for(int i=0;i<4;i++)
	{
		if(map[s_x+dx[i]][s_y+dy[i]]==1)
		{
			serch(s_x+dx[i],s_y+dy[i],s_ans+1);
		}
	}
	map[s_x][s_y]=1;
}

int main()
{
	
	for(;;)
	{
		ans=0;
		
		cin >> x >> y ;
		
		if(x==0 && y==0)
			break;
		
		for(int i=0;i<y;i++)
		{
			for(int j=0;j<x;j++)
			{
				cin >> map[j][i] ;
				s_map[j][i]=map[j][i];
			}
		}
		
		for(int i=0;i<y;i++)
		{
			for(int j=0;j<x;j++)
			{
				if(map[j][i]==1)
					serch(j,i,1);
				
			}
		}
		
//		cout << endl;
		
		cout << ans << endl;
	}
}

Measured memory_bytes: 0
import java.io.*;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {

    static class Task {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            Set<String> set = new HashSet<>();
            for (int i = 0; i < n; i++) {
                set.add(in.next());
            }
            out.println(set.size());
        }
    }

    private static void sort(double[] arr) {
        Double[] objArr = Arrays.stream(arr).boxed().toArray(Double[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(int[] arr) {
        Integer[] objArr = Arrays.stream(arr).boxed().toArray(Integer[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(long[] arr) {
        Long[] objArr = Arrays.stream(arr).boxed().toArray(Long[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task task = new Task();
        task.solve(1, in, out);
        out.close();
    }

    public static void main(String[] args) {
        new Thread(null, () -> solve(), "1", 1 << 26).start();
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

    }

}

Measured memory_bytes: 73476
#include<bits/stdc++.h>
#define ll long long
#define inf 9999999999999999
#define F first
#define S second
#define eb emplace_back
#define mpp make_pair
#define P(x) cout<<__LINE__ <<": "<<#x<<' '<<(x)<<'\n'
#define dbg cout<<__LINE__ <<": 0manush\n"
#define read(x) freopen("input.txt","r",stdin)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pi 2*acos(0.0)
#define ee exp(1)
#define mx 100009
#define mod 10000007
using namespace std;
ll dp[mx];
int main(){//read(x);
//fast;
ll r,g,h,i,j,x,t,y,z=0,e,f,a,b,c,d,n,l,k;

    cin>>n>>k;
    ll m[n];
    for(i=0;i<n;i++)cin>>m[i];
    dp[n-1]=0;
    for(i=n-2;i>=0;i--){
        l=inf;
        for(j=i+1;j<=i+k && j<n;j++){
            a=dp[j]+abs(m[i]-m[j]);
            l=min(l,a);
        }
        dp[i]=l;
    }

    cout<<dp[0]<<endl;

}




















Measured memory_bytes: 5140
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <sstream>
#include <set>
using namespace std;
using ll = long long;

class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};

int main() {
  string s;
  string dict[4] = {"dream", "dreamer", "erase", "eraser"};
  while (cin >> s) {
    int n = s.size();
    int ptr = n;
    for (;;) {
      if (ptr == 0) {
        cout << "YES" << endl;
        break;
      }
      int cont = 0;
      for (int i : range(4)) {
        string d = dict[i];
        int k = d.size();
        if (ptr - k >= 0 && s.substr(ptr - k, k) == d) {
          ptr -= k;
          cont = 1;
        }
      }
      if (!cont) {
        cout << "NO" << endl;
        break;
      }
    }
  }
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define D 1000000007
 
int main(){
 ll n,m,x[100001]={},y[100001]={}; 
 cin>>n>>m;
 
 for(int i=0;i<n;i++)cin>>x[i];
 for(int i=0;i<m;i++)cin>>y[i];
 
ll X=0,Y=0;
 for(int i=0;i<n-1;i++)
  X=(X+((x[i+1]-x[i])*((i+1)*(n-i-1))%D)%D)%D;
 
 for(int i=0;i<m-1;i++)
  Y=(Y+((y[i+1]-y[i])*((i+1)*(m-i-1))%D)%D)%D;
 
 cout<<(X*Y)%D<<endl;
 return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ "; 
  for(auto v:V)os << v << " "; return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ "; 
  for(auto s:S) os<<s<<" ";  return os<<"}"; 
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
  return os<<"("<<P.first<<","<< P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
  os<<"{ ";for(auto m:M)os<<"("<<m.first<<":"<<m.second<<")";
  return os<<"}";
}
#define cerr cout
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
//For multiset use less_equal operator but it does support erase operations for multiset
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert 
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define all(v) (v).begin(),(v).end()
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpii;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mp make_pair


const int mod = 1e9+7;

inline int add(int a,int b){a+=b;if(a>=mod)a-=mod; return a;} 
inline int sub(int a,int b){a-=b;if(a<0) a += mod; return a;}
inline int mul(int a, int b){ return a*1ll*b%mod;}
inline int power(int x, ll y){
  int res = 1;
  while(y){
    if(y&1) res = mul(res , x);
    x = mul(x,x);
    y >>= 1;
  }
  return res;
}
const int N = 205;
int L[N];

int main(){
  fio; cout<<fixed<<setprecision(25);	
  int n; cin >> n;
  for(int i = 1;i <= 2*n; ++i) cin >> L[i];
  sort(L+1, L+2*n+1);
  int ans = 0;
  for(int i = 1;i <= n ; ++i)
    ans += L[2*i-1];
  cout << ans << endl; 
  return 0;
}












Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int ans=0;

		for(int i=1;i<=n;i++) {
			if(i<10 || (100<=i && i<1000) || (10000<=i && i<100000)) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23764
A, B, C, X, Y = map(int, input().split())
C = 2 * C

if C <= A + B:
    if X <= Y:
        if C <= B:
            print(C * Y)
        else:
            print(C * X + B * (Y - X))
    else:
        if C <= A:
            print(C * X)
        else:
            print(C * Y + A * (X - Y))
else:
    print(A * X + B * Y)

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

#define int long long
using ll = long long;
using ld = long double;
using intpair = pair<int, int>;
using intmap = map<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
const int MOD = 1e9 + 7;
inline int mod (ll a, int m = MOD) { return (a % m + m) % m; }
inline bool bit (ll b, ll i) { return b & (1 << i); }
inline ll ceiv (ll a, ll b) { return (a + b - 1) / b; }
//struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;

#define debug(x) cerr << #x << ": " << x << '\n'
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()

int binom_max = 5e5+1;
vector<int> fact(binom_max), inv_fact(binom_max), inv(binom_max);

void modbinom_init() {
    fact[0] = fact[1] = 1;
    inv_fact[0] = inv_fact[1] = 1;
    inv[1] = 1;
    for(int i=2; i<binom_max; i++){
        fact[i] = fact[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        inv_fact[i] = inv_fact[i-1] * inv[i] % MOD;
    }
}

int comb(int n, int k){
    if (n<k) return 0;
    if (n<0 || k<0) return 0;
    return fact[n] * (inv_fact[k] * inv_fact[n-k] % MOD) % MOD;
}

int perm(int n, int k){
    if (n<k) return 0;
    if (n<0 || k<0) return 0;
    return (fact[n] * inv_fact[n-k]) % MOD;
}

int modpow(int a, int n, int m = MOD){
    ll ret = 1;
    while(n > 0){
        if(n&1) ret = (ret*a) % m;
        a = (a*a) % m;
        n >>= 1;
    }
    return ret % m;
}

signed main(){
    modbinom_init();
    string n; int k;
    cin >> n >> k;
    
    const int LEN = n.length();
    int nzl = k;
    int ans = 0;
    
    rep(i, LEN){
        int top = n[i] - '0';
        
        if(top != 0){
            //__0######
            ans += mod(modpow(9,nzl) * comb(LEN-1-i, nzl));
            //__[1-9]######
            ans += mod(max(0LL, top-1) * modpow(9,nzl-1) * comb(LEN-1-i, nzl-1));
            nzl--;
        }
        
        ans %= MOD;
    }
    
    if(nzl == 0) ans = mod(1 + ans);
    
    cout << ans << endl;
}

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

typedef long long ll;
typedef pair<int,int> P;
ll const mod = 1e9+7;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

const int MAX_N = 100010;
ll fact[MAX_N],fact_inv[MAX_N],inv[MAX_N];

ll pow_mod(ll a,ll b) {
    ll ret;
    if (b < 0) ret = pow_mod(a,mod+b-1);
    else if (b == 0) ret = 1;
    else if (b == 1) ret = a;
    else {
        ll c = pow_mod(a,b/2);
        if (b%2) ret = (c*c)%mod*a%mod;
        else ret = c*c%mod;
    }
    return ret;
}

void create_table(int x) {
    fact[0] = 1;fact[1] = 1;
    for (int i = 2;i <= x;++i) fact[i] = fact[i-1]*i%mod;
    fact_inv[x] = pow_mod(fact[x],-1);
    for (int i = x;i > 0;--i) fact_inv[i-1] = fact_inv[i]*i%mod;
    for (int i = 1;i <= x;++i) inv[i] = fact_inv[i]*fact[i-1]%mod;
}

ll combi(ll a, ll b) {
    return fact[a]*fact_inv[b]%mod*fact_inv[a-b]%mod;
}

ll permu(ll a,ll b) {
    if (b > a) return 0;
    return fact[a]*fact_inv[a-b]%mod;
}

int k;
ll ans;
vector<vector<int>> edges;

void dfs(int i,int p = -1) {
    if (p > -1) (ans *= permu(k-2,edges[i].size()-1)) %= mod;
    else (ans *= permu(k-1,edges[i].size())) %= mod;
    for (int& j : edges[i]) if (j != p) dfs(j,i);
}

int main() {
    int n;
    cin >> n >> k;
    edges.resize(n);
    create_table(100000);
    for (int i = 0;i < n-1;++i) {
        int u,v;
        cin >> u >> v;
        u--;v--;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }
    ans = k;
    dfs(0);
    cout << ans << endl;
}

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

int main(){
    string s;
    cin>>s;
    int n=s.size();
    bool ans = 0;
    if(s.substr(0,(n-1)/2)!=s.substr((n+1)/2)) ans=1;
    for(int i=0;i<(n-1)/2;i++)if(s[i]!=s[(n-1)/2-1-i])ans=1;
    cout<<(ans?"No":"Yes")<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;
vector<ll> Factorial(ll M, ll MOD){
    vector<ll> result = vector<ll>(M + 1);
    for(int i = 0; i <= M; i++){
        if(i == 0){
            result[i] = 1;
        }else{
            result[i] = result[i-1] * i % MOD;
        }
    }
    return result;
}

int main() {
    int N;
    cin >> N;
    vector<int> p = vector<int>(N);
    vector<int> q = vector<int>(N);
    for(int i = 0; i < N; i++){
        cin >> p[i];
    }
    for(int i = 0; i < N; i++){
        cin >> q[i];
    }
    vector<vector<int>>a = vector<vector<int>>(0);
    vector<int> base = vector<int>(0);
    for (int i = 1; i <= N; ++i) {
        base.push_back(i);
    }
    do {
        a.push_back(base);
    } while (next_permutation(base.begin(), base.end()));
    ll A = 0;
    ll B = 0;
    for(int i = 0; i < a.size(); i++){
        bool isP = true;
        bool isQ = true;
        for (int j = 0; j < N; ++j) {
            if(a[i][j] != p[j]){
                isP = false;
            }
            if(a[i][j] != q[j]){
                isQ = false;
            }
        }
        if(isP){
            A = i;
        }
        if(isQ){
            B = i;
        }
    }
    cout << abs(A - B) << endl;
}


Measured memory_bytes: 3256
import heapq

Q = int(input())
b_sum = 0
a_list = []
left = []
right = []
res = 0

for i in range(Q):
    query = list(map(int, input().split()))
    if query[0] == 1:
        b_sum += query[2]

        if not left:
            a = query[1]
            heapq.heappush(left, -a)
        else:
            res += abs(query[1] + left[0])
            if query[1] <= -left[0]:
                heapq.heappush(left, -query[1])
            else:
                heapq.heappush(right, query[1])

        if len(left) < len(right):
            x = heapq.heappop(right)
            y = -left[0]
            res += y - x
            heapq.heappush(left, -x)
        elif len(left) > len(right) + 1:
            x = - heapq.heappop(left)
            if len(right) != 0:
                y = right[0]
            else:
                y = 0
            heapq.heappush(right, x)
    else:
        print(-left[0], res + b_sum)


Measured memory_bytes: 11116
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);while((a%b)!=0){a=b;b=a%b;}return b;}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};



int main(){
  string a,b,c; cin>>a>>b>>c;
  if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0])
  puts("YES");
  else
  puts("NO");


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
//const int mod = ;

void upd(int& pos, pii p, ll& res) {
  int l = p.first, r = p.second;
  if (l > r) swap(l, r);
  if (pos < l) {
    res += l - pos;
    pos = l;
  }
  if (pos > r) {
    res += pos - r;
    pos = r;
  }
}

ll f(vii v) {
  multiset<pii> lr, rl;
  for (pii p : v) {
    lr.insert(p);
    rl.insert(pii(p.second, p.first));
  }
  ll res = 0;
  int pos = 0;
  while (!lr.empty()) {
//    cerr << lr.size() << ' ' << rl.size() << endl;
    auto it = lr.end(); --it;
    upd(pos, *it, res);
    rl.erase(rl.find(pii(it->second, it->first)));
    lr.erase(it);
    if (rl.empty()) break;
    it = rl.begin();
    upd(pos, *it, res);
    lr.erase(lr.find(pii(it->second, it->first)));
    rl.erase(it);
  }
  res += abs(pos);
  return res;
}

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int n;
  cin >> n;
  vii v(n);
  for (int i = 0; i < n; ++i) cin >> v[i].first >> v[i].second;
  ll res = f(v);
  for (int i = 0; i < n; ++i) {
    v[i].first *= -1;
    v[i].second *= -1;
    swap(v[i].first, v[i].second);
  }
  res = max(res, f(v));
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 13296
#include <bits/stdc++.h>
using namespace std;
int main() {
    string w;
    int s[26], k = 0;
    cin >> w;
    for (int i = 0; i < 26; ++i) s[i] = 0;
    for (long unsigned i = 0; i < w.length(); ++i)
    {
        s[w[i] - 97]++;
    }
    for (int i = 0; i < 26; ++i)
    {
        if (s[i] % 2 == 1)
        {
            k++;
            cout << "No";
            break;
        }
    }
    if (k == 0) cout << "Yes";
}

Measured memory_bytes: 3640