akhauriyash/Code-Regression huggingface dataset:
#include <queue>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

#define TRACE(x) cerr << #x << " = " << x << endl
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define _ << " " <<

typedef unsigned long long ull;
typedef pair<int, int> P;
#define X first
#define Y second

const int MAX = 2005, MAXL = 2005 / 64 + 2;

bitset <MAX> ne_rel[MAX];
ull ne_rel_ull[MAX][MAXL];
bitset <MAX> manji[MAX];
bitset <MAX> smije;
bitset <MAX> ostalo;
int n;
int p[MAX];
int rje[MAX];
int done[MAX];
int indk[MAX], brk;

void bfs()
{
  ull nodovi[MAXL];
  REP(i, n)
    if (!done[i])
      nodovi[i/64] |= ((ull) 1) << (i % 64);

  queue <int> Q;

  brk = 0;
  REP(i, n) {
    if (nodovi[i/64] & ((ull) 1) << (i % 64)) {
      nodovi[i/64] ^= ((ull) 1) << (i % 64);
      Q.push(i);
      
      for (; !Q.empty();) {
	int tmp = Q.front(); Q.pop();
	indk[tmp] = brk;

	REP(j, MAXL) {
	  ull val = nodovi[j] & ne_rel_ull[tmp][j];
	  for (; val; ) {
	    ull koji = val & (-val);
	    int ind = __builtin_ctzll(koji);
	    
	    nodovi[j] ^= ((ull) 1) << ind;
	    val ^= ((ull) 1) << ind;
	    Q.push(64 * j + ind);
	  }
	}
      }
      
      brk++;
    }
  }  
}

int main()
{
  scanf("%d", &n);
  REP(i, n) scanf("%d", &p[i]);

  sort(p, p + n);

  REP(i, n)
    REP(j, n)
    if (__gcd(p[i], p[j]) > 1) {
      ne_rel_ull[i][j/64] |= ((ull) 1) << (j % 64);    
      ne_rel[i][j] = 1;
    }

  REP(i, n) smije[i] = 1;
  REP(i, n) ostalo[i] = 1;

  REP(i, n) {
    bfs();

    int ima[MAX];
    memset(ima, 0, sizeof ima);
    int poklopio = 0;

    int ind = -1;
    REP(j, n) {
      if (done[j]) continue;
      if (smije[j]) {
	if (!ima[indk[j]]) {
	  ima[indk[j]] = 1;
	  poklopio++;
	}

	if (poklopio == brk) {
	  ind = j;
	  break;
	}
      }
    }

    assert(ind != -1);

    done[ind] = 1;
    smije[ind] = 0;
    rje[i] = ind;

    REP(k, n) {
      if (ne_rel[ind][k])
	smije[k] = 1;
      else if (smije[k] && k < ind)
	smije[k] = 1;
      else
	smije[k] = 0;
    }      
  }    

  REP(i, n)
    printf("%d ", p[rje[i]]);
  printf("\n");

  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x,T a,T b){return a<=x&&x<=b;}
template<class T> void amin(T &a,T v){if(a>v) a=v;}
template<class T> void amax(T &a,T v){if(a<v) a=v;}
int ROUND(double x) { return (int)(x+0.5); }
bool ISINT(double x) { return fabs(ROUND(x)-x)<=EPS; }
bool ISEQUAL(double x,double y) { return fabs(x-y)<=EPS*max(1.0,max(fabs(x),fabs(y))); }
double SQSUM(double x,double y) { return x*x+y*y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;



ll dp[2][55][2555];

int main()
{
	int N, A;
	cin >> N >> A;

	vector <ll> x(N);

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

	int now = 0;
	dp[0][0][0] = 1;
	for (int i = 0; i < N; ++i)
	{
		const int next = 1 - now;

		for (int s = 0; s < N; ++s)
		{
			for (int total = 0; total<=2500;++total)
			{
				dp[next][s + 1][total + x[i]] += dp[now][s][total];
				dp[next][s][total] += dp[now][s][total];
			}
		}

		for (int s = 0; s < N; ++s)
		{
			for (int total = 0; total <= 2500; ++total)
			{
				dp[now][s][total] = 0;
			}
		}

		now = next;
	}


	ll ret = 0;
	for (int s = 1; s <= N ; s++)
	{
		// BEGIN CUT HERE
//		cout << " now=" << now << " s=" << s << " s*A=" << s*A << " dp[now][s][s*A]=" << dp[now][s][s*A] << endl;
		// END CUT HERE

		ret += dp[now][s][s*A];
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

template<typename T, typename E> class SegmentTree {
public:
  typedef function<T (T, T)> Operator;
  typedef function<T (T, E)> Apply;

  vector<T> data;
  ll n;
  T e;
  Operator op;
  Apply apply;

  SegmentTree(ll _n, T e, Operator op, Apply apply): e(e), op(op), apply(apply) {
    for(n = 1; n < _n; n *= 2);
    data.resize(n * 2 - 1, e);
  }

  T query(ll a, ll b) { return query(a, b, 0, 0, n); }
  T query(ll a, ll b, ll k, ll l, ll r) {
    if(r <= a || b <= l) return e;
    if(a <= l && r <= b) return data[k];
    T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return op(vl, vr);
  }

  void update(ll k, E x) {
    k += n - 1;
    data[k] = apply(data[k], x);
    while(k > 0) {
      k = (k - 1) / 2;
      data[k] = op(data[k * 2 + 1], data[k * 2 + 2]);
    }
  }
};

class UnionFind {
private:
  vector<ll> data;

public:
  UnionFind(ll n): data(n, -1) {}

  ll size(ll i) { return -data[find(i)]; }
  bool root(ll i) { return data[i] < 0; }
  bool same(ll i, ll j) { return find(i) == find(j); }

  ll find(ll i) { return root(i) ? i : (data[i] = find(data[i])); }

  bool unite(ll i, ll j) {
    if(same(i, j)) return false;
    data[find(i)] += data[find(j)];
    data[find(j)] = find(i);
    return true;
  }
};

int main(void) {
  ll N, D;
  cin >> N >> D;
  vector<ll> A(N);
  REP(i, 0, N) cin >> A[i];

  vector<ll> ord(N);
  REP(i, 0, N) ord[i] = i;
  sort(ord.begin(), ord.end(), [&](ll i, ll j) { return A[i] < A[j]; });

  const ll INF = 1LL << 60;
  SegmentTree<pll, pll>::Operator op = [](pll a, pll b) { return min(a, b); };
  SegmentTree<pll, pll>::Apply apply = [](pll a, pll x) { return x; };
  SegmentTree<pll, pll> stl(N, make_pair(INF, INF), op, apply);
  SegmentTree<pll, pll> str(N, make_pair(INF, INF), op, apply);

  struct edge { ll d, u, v; };
  vector<edge> edges;
  for (ll v : ord) {
    pll l = stl.query(0, v);
    if (l.first < INF) {
      ll d = l.first + A[v] + v * D;
      ll u = l.second;
      edges.push_back({ d, u, v });
    }
    stl.update(v, make_pair(A[v] - v * D, v));

    pll r = str.query(v + 1, N);
    if (r.first < INF) {
      ll d = r.first + A[v] - v * D;
      ll u = r.second;
      edges.push_back({ d, u, v });
    }
    str.update(v, make_pair(A[v] + v * D, v));
  }

  sort(edges.begin(), edges.end(), [](edge x, edge y) { return x.d < y.d; });

  UnionFind uf(N);
  ll ans = 0;
  for (edge e : edges) if (uf.unite(e.u, e.v)) ans += e.d;
  cout << ans << endl;
}

Measured memory_bytes: 34028
import sys
input = sys.stdin.readline

a, b, m = [int(w) for w in input().split()]
a_li = [int(w) for w in input().split()]
b_li = [int(w) for w in input().split()]

ans = min(a_li) + min(b_li)

for i in range(m):
    x, y, c = [int(w) for w in input().split()]
    t = a_li[x - 1] + b_li[y - 1] - c
    ans = min(ans, t)

print(ans)


Measured memory_bytes: 25200
#include <iostream>
#include <cstdio>
#include <sstream>

#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <queue>
#include <stack>

#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>

#include <chrono>
#include <random>

using namespace std;
using i64 = int_fast64_t;
using ui64 = uint_fast64_t;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<i64>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<i64, i64>;

//////////////////////////////////////////////////

int main(){
    int n,m;
    cin >> n >> m;
    vi a(n);
    for(auto&& x:a)cin >> x;
    priority_queue<int, vi, greater<int>> q(a.begin(), a.end());
    vector<pair<int,int>> p(m);
    for(auto&& x:p){
        cin >> x.second >> x.first;
    }
    priority_queue<pii> r(p.begin(), p.end());
    while(!r.empty()){
        pii op = r.top();r.pop();
        for(int i=0;i<op.second;i++){
            cerr << q.top() << " " << op.first << " " << op.second << endl;
            if(q.top() < op.first){
                q.pop();q.push(op.first);
            }else break;
        }
    }
    i64 ret = 0;
    while(!q.empty()){
        cerr << q.top() << " ";
        ret += (i64)q.top();q.pop();
    }cerr << endl;
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define sz(x) int((x).size())
#define mkt make_tuple
#define fr first
#define sc second
using namespace std;

typedef tuple< int, int, int > Data;
const int kSize = 300010;
const int kMax = 1 << 20;

int M, N, A, B;
Data T[kSize];

map< int, int > tree[kMax];
int mxy;

void read();
void solve();

inline int low_bit(int i) { return i & (-i); }

int query(int y, int z) {
  if (y == 0 || z == 0)
    return 0;

  int i = y, ret = 0;
  while (i > 0) {
    auto &tr = tree[i - 1];
    auto itr = tr.upper_bound(z - 1);
    if (itr != tr.begin())
      ret = max(ret, (--itr)->sc);
    i -= low_bit(i);
  }

  return ret;
}

void update(int y, int z, int v) {
  for (int i = y + 1; i < mxy + 10; i += low_bit(i)) {
    auto &tr = tree[i - 1];
    auto itr = tr.lower_bound(z), iitr = itr;
    bool is_ins = false;

    if (tr.count(z) > 0) {
      if (tr[z] < v)
        tr[z] = v, iitr = tr.find(z), is_ins = true;
    }
    else if (itr == tr.begin())
      tr[z] = v, iitr = tr.find(z), is_ins = true;
    else {
      if ((--itr)->sc < v)
        tr[z] = v, iitr = tr.find(z), is_ins = true;
    }

    if (is_ins) {
      ++iitr;
      while (iitr != tr.end()) {
        if (iitr->sc > v)
          break;
        auto tmp = iitr;
        ++iitr, tr.erase(tmp);
      }
    }
  }
}

int main() {
  while (scanf(" %d %d %d %d", &M, &N, &A, &B), M + N)
    read(), solve();

  return 0;
}

void read() {
  int x, y, z;
  int a = A, b = B, c = ~(1 << 31), m = (1 << 16) - 1;
  auto r = [&] () {
    a = 36969 * (a & m) + (a >> 16);
    b = 18000 * (b & m) + (b >> 16);
    return (c & ((a << 16) + b)) % 1000000;
  };

  mxy = 0;
  for (int i = 0; i < M; ++i) {
    scanf(" %d %d %d", &x, &y, &z), mxy = max(mxy, y);
    T[i] = mkt(x, y, z);
  }

  for (int i = 0; i < N; ++i) {
    x = r(), y = r(), z = r(), mxy = max(mxy, y);
    T[i + M] = mkt(x, y, z);
  }
}

void solve() {
  static int f[kSize];

  sort(&T[0], &T[M + N]);

  for (int i = 0; i < mxy + 10; ++i)
    tree[i].clear();

  fill(&f[0], &f[M + N], 0);
  for (int i = 0, j = 0; i < M + N; i = j) {
    j = i + 1;
    while (j < M + N && get< 0 >(T[i]) == get< 0 >(T[j]))
      ++j;

    for (int k = i; k < j; ++k) {
      int y = get< 1 >(T[k]), z = get< 2 >(T[k]);
      f[k] = query(y, z) + 1;
    }

    for (int k = i; k < j; ++k) {
      int y = get< 1 >(T[k]), z = get< 2 >(T[k]);
      update(y, z, f[k]);
    }
  }

  cout << *max_element(&f[0], &f[M + N]) << "\n";
}

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

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            String[] inputNumbers = br.readLine().split(" ");
            int sum = Integer.parseInt(inputNumbers[0]) + Integer.parseInt(inputNumbers[1]);

            String result = "error";

            if (sum < 10) {
                result = Integer.toString(sum);
            }

            System.out.println(result);

        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

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

int main() {
    int A, B, C;
    cin >> A >> B >> C;

    for (int i=0; i<100; i++) {
        int n = i * A;
        if (n % B == C) {
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <utility>
#include <string>
#include<vector>
#include <algorithm>
#include<deque>
using namespace std;

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

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

    int s_a = a[0];
    int s_b = 0;

    /* for(int i = 0; i < N; i++){
        cout << a[i] << endl;
    }*/
    int j = 1;
    int i = 1;
    while(i + j <= N){
        if(s_a > s_b){
            s_b += a[N - j];
            j++;
        }else{
            s_a += a[i];
            i++;
        }

        //cout << s_a << " " << s_b << endl;

    }
    /* for(int i = 1; i <= N / 2; i++){
        if(s_a > s_b){
            s_b += a[N - j];
            j++
        }else{
            s_a += a[i];
        }

        cout << s_a << " " << s_b << endl;
    }*/

    if(s_a > s_b){
        cout << s_a - s_b << endl;
    }else{
        cout << s_b - s_a << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////

//操作aをa回、bをb回行うとする。a+b<=min{N,K}
//この時左からa個右からb個の宝石を手に入れ,捨てる操作はk-(a+b)回までできる
//価値が負でできるだけ絶対値が大きいものからk-(a+b)個まで捨てる
int main() {
	int N, K; cin >> N >> K;
	int v[55];
	for (int i = 0; i < N; ++i)cin >> v[i];
	ll ans = 0;
	for (int i = 0; i <= min(N, K); ++i) {//iはa
		for (int j = 0; i + j <= min(N, K); ++j) {//jはb
			vector<int>V;
			for (int k = 0; k < i; ++k) {
				V.push_back(v[k]);
			}
			for (int k = 0; k < j; ++k) {
				V.push_back(v[N - 1 - k]);
			}
			sort(V.begin(), V.end());
			ll sum = 0;
			for (int k = 0; k < V.size(); ++k) {
				sum += V[k];
			}
			for (int k = 0; k < min(int(V.size()),K - (i + j)); ++k) {
				if (V[k] < 0) {
					sum -= V[k];
				}
				else {
					break;
				}
			}
			ans = max(ans, sum);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

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

void bubbleSort(int A[], int N) {
    bool unsorted = 1;
    int i = 0;
    int counter = 0;
    while (unsorted) {
        unsorted = 0;
        for (int j = N-1; j >= i; j--) {
            if (A[j] < A[j-1]) {
                int tmp = A[j];
                A[j]    = A[j-1];
                A[j-1]  = tmp;
                unsorted = 1;
                counter++;
            }
        }
        i++;
    }
    printArray(A, N);
    printf("%d\n", counter);
}

int main() {
    int N;
    int A[100];

    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        int input;
        scanf("%d", &input);
        A[i] = input;
    }
    bubbleSort(A, N);
}

Measured memory_bytes: 1032
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();

            int[] dp = new int[n];
            Arrays.fill(dp, Integer.MAX_VALUE);
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }
            dp[0] = 0;
            for (int i = 1; i < n; i++) {
                for (int j = 0; j <= k; j++) {
                    if (i - j >= 0) {
                        dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(a[i] - a[i - j]));
                    }
                }

            }

            out.println(dp[n - 1]);
        }

    }
}



Measured memory_bytes: 60356
s = input()[:-1]
n = len(s)
if n%2:
  s = s[:-1]
  n -= 1
for i in range(n//2):
  n = len(s)
  if s[:n//2] == s[n//2:]:
    #print(s[:n//2], s[n//2:])
    print(n)
    break
  s = s[:-2]
    
  



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

int main() {
	int N, M, C;
	cin >> N >> M >> C;
	vector<int> B(M);
	for (int i = 0; i < M; i++) cin >> B[i];
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int sum = 0;
		for (int i = 0; i < M; i++) {
			int a;
			cin >> a;
			sum += a * B[i];
		}
		ans += (sum + C > 0);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#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(){
    char b;
    cin >> b;
    if(b == 'A') cout << 'T' << endl;
    if(b == 'C') cout << 'G' << endl;
    if(b == 'G') cout << 'C' << endl;
    if(b == 'T') cout << 'A' << endl;
}

Measured memory_bytes: 3624
import java.util.*;
public class Main {
	public static void main(String args[]){
    	Scanner s = new Scanner(System.in);
    	int N = s.nextInt();
      	int arr[] = new int[N];
      	for(int i=0;i<N;i++)
          	arr[i] = s.nextInt();
      	int ans = frog(arr,N);
      	System.out.println(ans);
    }
  	public static int frog(int[] arr, int N){
    	if(N<=1)
          return 0;
      	int dp[] = new int[N];
      	dp[0] = 0;
      	dp[1] = Math.abs(arr[1]-arr[0]);
      	for(int i=2;i<N;i++){
        	int ans1 = Math.abs(arr[i]-arr[i-1])+dp[i-1];
          	int ans2 = Math.abs(arr[i]-arr[i-2])+dp[i-2];
          	dp[i] = Math.min(ans1,ans2);
        }
      	return dp[N-1];
    }
}

Measured memory_bytes: 50496
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

constexpr int MOD = 1000000007;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

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

int N;
LL T[1010], A[1010];

int main() {
    cin >> N;
    for (int j = 0; j < N; ++j) {
        cin >> T[j] >> A[j];
    }

    LL t = T[0], a = A[0];
    for (int j = 1; j < N; ++j) {
        LL mul1 = (t - 1) / T[j] + 1;
        LL mul = max(mul1, (a - 1) / A[j] + 1);

        t = mul * T[j], a = mul * A[j];
    }

    cout << (t + a) << endl;

    return 0;
}


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

using namespace std;

string a, b;

void printLcs() {
  int m = a.size(), n = b.size();
  int dp[m + 1][n + 1];
  for (int i = 0; i <= m; i++) {
    for (int j = 0; j <= n; j++) {
      if (i == 0 || j == 0) {
        dp[i][j] = 0;
      } else if (a[i - 1] == b[j - 1]) {
        dp[i][j] = dp[i - 1][j - 1] + 1;
      } else {
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
      }
    }
  }
  int index = dp[m][n];
  string ans = "";
  int i = m, j = n;
  while (i > 0 && j > 0) {
    if (a[i - 1] == b[j - 1]) {
      ans += a[i - 1];
      i--; j--; index--;
    } else if (dp[i - 1][j] > dp[i][j - 1]) {
      i--;
    } else {
      j--;
    }
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
}

int main() {
  cin >> a >> b;
  printLcs();
  return 0;
}

Measured memory_bytes: 35456
# -*- coding: utf-8 -*-

def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    A, B, C = list(map(int, input().split()))
    K = int(input())

    return A, B, C, K

def main(A: int, B: int, C: int, K: int) -> None:
    """
    メイン処理.

    Args:\n
        A (int): 整数（1 <= A <= 7）
        B (int): 整数（1 <= B <= 7）
        C (int): 整数（1 <= C <= 7）
        K (int): 操作回数（1 <= K <= 7）
    """
    # 求解処理
    cnt = 0
    while A >= B:
        cnt += 1
        B *= 2
    while B >= C:
        cnt += 1
        C *= 2

    # 結果出力
    if cnt <= K:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    # 標準入力を取得
    A, B, C, K = get_input()

    # メイン処理
    main(A, B, C, K)


Measured memory_bytes: 9216
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;


const ll mod = 1000000007;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
// bool debug=false;

/*---------------------------------------------------*/

int main() {
  string s;
  cin >> s;
  if(s[0] == s[1] || s[1] == s[2] ||s[2] == s[3]) cout << "Bad" << endl;
  else cout << "Good" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
int main(void)
{
    int k,n,i;
    char s[100];
  
    scanf("%d",&k);
    scanf("%s",&s);
  
    n=strlen(s);
  
    if(n<=k)  printf("%s\n",s);
    else if(n>k){
            for(i=0;i<k;i++){
                printf("%c",s[i]);
            }
            printf("...\n");
    } 
  
     return 0;
}

Measured memory_bytes: 1632
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        int n = Integer.valueOf(mylist.get(0));
        String arr_temp[] = mylist.get(1).split(" ");
        StringBuilder sb = new StringBuilder();
        String s = arr_temp[0];
        String t = arr_temp[1];

        for (int i = 0; i < n; i++) {
            sb.append(s.substring(i, i + 1));
            sb.append(t.substring(i, i + 1));

        }

        System.out.println(sb);
    }

}


Measured memory_bytes: 21204
import scala.io.StdIn.{readLine,readInt}
import scala.collection.mutable.ArrayBuffer
 
object Main {
  def main(args:Array[String]) = {
    val n = readInt
    val g = for(i<-0 until n) yield { readLine.trim.split(" ").map(_.toInt) }
    val dist = new Array[Int](n)
    val visited = new ArrayBuffer[Int]
    for(i<-0 until n) dist(i) = Int.MaxValue
    dist(0) = 0
 
    while(visited.length < n) {
      val minV = (for(i<-0 until dist.length if !visited.contains(i)) yield (dist(i),i)).min
      val min = minV._1
      val v = g(minV._2)
 
      for(i<-0 until v(1) if !visited.contains(v(i*2+2))) {
        if(dist(v(i*2+2)) == Int.MaxValue) dist(v(i*2+2)) = v(i*2+3) + dist(v(0))
        else if(v(i*2+3)+dist(v(0)) < dist(v(i*2+2))) dist(v(i*2+2)) = v(i*2+3)+dist(v(0))
      }
      visited += v(0)
    }
    for(i<-0 until n) {
      println(i + " " + dist(i))
    }
  }
}

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

struct e{int a,b;};
int A=500,G=500,n,a[40],T,p,q;
e v[20];
stack<int> s;
#define R(i,n) for(int i=0;i<(n);i++)

signed main(){
  cin>>n;
  R(i,n*2)cin>>a[i];
  R(i,1<<n){
    T=0;
    R(j,n)v[j]={a[j+n*((i>>j)&1)],j};
    R(j,n){
      p=j;
      while(p&&v[p].a<v[p-1].a)swap(v[p],v[p-1]),T++,p--;
    }
    R(j,n)if(((i>>v[j].b)+v[j].b-j)&1)s.push(v[j].a*G+j);
    if(s.size()&1)T=G,s.pop();
    while(s.size()){
      p=s.top();s.pop();q=s.top();s.pop();
      T+=((p-q)&1?p-q:G);
    }
    if(A>T)A=T;
  }
  cout<<(A<G?A:-1)<<endl;
}


Measured memory_bytes: 256
N = int(input())
V = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
curr_max = 0
for i in range(len(V)):
    temp = curr_max + V[i] - C[i]
    curr_max = max(curr_max, temp)
print(curr_max)

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

const long long INF = 1LL << 61;
using ll = long long;

typedef pair<ll, ll> ii;

vector<ii> AdjList[140005];

long long W;

vector<ii> S[140005];

void dfs(int u){
    if(AdjList[u].empty()){
        S[u].emplace_back(0, 0);
        return;
    }

    int l = AdjList[u][0].first;
    long long w_l = AdjList[u][0].second;
    int r = AdjList[u][1].first;
    long long w_r = AdjList[u][1].second;
    dfs(l);
    dfs(r);

    int indxD = 0;
    int indxC = 0;
    for(ii temp1: S[l]){
        long long a, b;
        tie(a, b) = temp1;
        long long tempC = INF;
        long long tempD = INF;

        while(indxD < (int)S[r].size()){
            ii temp2 = S[r][indxD];
            long long c, d;
            tie(c, d) = temp2;
            if(c > W-b-w_l-w_r){
                //indxD --;
                break;
            }else{
                indxD ++;
                tempD = min(tempD, d+w_r);
            }
        }

        while(indxC < (int)S[r].size()){
            ii temp2 = S[r][indxC];
            long long c, d;
            tie(c, d) = temp2;
            if(d <= W-a-w_l-w_r){
                tempC = min(tempC, c+w_r);
                break;
            }else{
                indxC ++;
            }
        }

        /*for(ii temp2: S[r]){
            long long c, d;
            tie(c, d) = temp2;
            if(c <= W-b-w_l-w_r){
                tempD = min(tempD, d+w_r);
            }
        }*/
        /*for(ii temp2: S[r]){
            long long c, d;
            tie(c, d) = temp2;
            if(d <= W-a-w_l-w_r){
                tempC = min(tempC, c+w_r);
            }
        }*/

        if(tempD < INF){
            S[u].emplace_back(a+w_l, tempD);
        }
        if(tempC < INF){
            S[u].emplace_back(tempC, b+w_l);
        }
    }
    sort(S[u].begin(), S[u].end());
}

int N;

bool boleh(long long W2){
    W = W2;
    for(int i = 1; i <= N; i ++){
        S[i].clear();
    }
    dfs(1);
    return !S[1].empty();
}

int main(){
    scanf("%d", &N);

    for(int i = 2; i <= N; i ++){
        int a, v;
        scanf("%d%d", &a, &v);
        AdjList[a].push_back(ii(i, v));
    }

    long long lo = 0;
    long long hi = 1LL << 40;
    while(lo < hi){
        long long mid = (lo+hi)>>1;
        if(boleh(mid)){
            hi = mid;
        }else{
            lo = mid+1;
        }
    }

    printf("%lld", lo);
    return 0;
}


Measured memory_bytes: 36016
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr lint B1 = 1532834020;
constexpr lint M1 = 2147482409;
constexpr lint B2 = 1388622299;
constexpr lint M2 = 2147478017;
constexpr int INF = 2147483647;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string S;
  cin >> S;
  int cnt = 0;
  REP(i, 3) if(S[i] == 'R')cnt++;
  if(S == "RSR") cnt--;
  cout << cnt << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main(int argc, const char** argv) {
    int n;
    cin>>n;
    if(n%10 == 2 || n%10 == 4 || n%10 == 5 || n%10 == 7 || n%10 == 9)
        cout<<"hon\n";
    else if(n%10 == 0 || n%10 == 1 || n%10 == 6 || n%10 == 8)
        cout<<"pon\n";
    else if(n%10 == 3)
        cout<<"bon\n";
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> a(n);
  rep(i,0,n) cin >> a[i];
  a.pb(x);
  sort(all(a));
  vector<int> b(n);
  rep(i,0,n) {
    b[i] = a[i+1] - a[i];
  }
  int ans = b[0];
  rep(i,1,n) {
    ans = gcd(ans,b[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3976
#include <stdio.h>

int main()
{
	int i, A, B;
	scanf("%d", &i);
	if (i == 1) printf("Hello World\n");
	else {
		scanf("%d %d", &A, &B);
		printf("%d\n", A + B);
	}
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1724
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    
    double prob[N + 1];
    double dp[N + 1][N + 1], res = 0;
    
    for(int i = 1; i <= N; ++i)
        cin >> prob[i];
        
    for(int i = 0; i <= N; ++i) {
        for(int j = 0; j <= N; ++j)
            dp[i][j] = 0;
    }    
    
    // first set up the answer for getting 0 heads, for getting 0 heads using 
    // first i coins, it is simply the product of (1 - p1) * (1 - p2) * .. * (1 - pi)
    dp[1][0] = 1.0 - prob[1];
    for(int i = 2; i <= N; ++i)
        dp[i][0] = dp[i - 1][0] * (1.0 - prob[i]);
        
    // next the proability of getting x heads using x coins is simply the product
    // of all pi(s) till here
    dp[1][1] = prob[1];
    for(int i = 2; i <= N; ++i)
        dp[i][i] = dp[i - 1][i - 1] * prob[i];
        
    // now solve for any general dp[i][j], i.e. probability of getting j heads 
    // using the first i coins only. For this, at each index i and some heads j,
    // we can either select a head for the coin at this index or select a tail
    // so, the total result will be -
    // probability of selecting head from this coin * probability of getting j - 1
    // heads from all the previous coins + probability of selecting a tail here
    // * probability of getting j heads from all the previous coins
    
    // note - as getting heads j from first i coins when j > i is impossible, so,
    // we set this probability to 0. Also, since we also computed answers for i == j
    // so, we do not compute it back again
    for(int i = 1; i <= N; ++i) {
        for(int j = 1; j < i; ++j)
            dp[i][j] = dp[i - 1][j] * (1.0 - prob[i]) + dp[i - 1][j - 1] * prob[i];
    }
    
    // now add to res the probability of any heads > N/2 using all the coins
    for(int i = N / 2 + 1; i <= N; ++i)
        res += dp[N][i];
    
    // print answer to the 10th precision
    cout << fixed << setprecision(10) << res;
    
	return 0;
}

Measured memory_bytes: 70528
#include<iostream>
using namespace std;
int main(){
  string s;
  std::cin >> s;
  bool flag=true;
  for (int i = 0; i < s.length(); i++) {
    if(i%2==0){
      if(s[i]=='R'||s[i]=='U'||s[i]=='D');
      else flag=false;
    }
    else{
      if(s[i]=='L'||s[i]=='U'||s[i]=='D');
      else flag=false;
    }
  }
  if(flag)std::cout << "Yes" << '\n';
  else std::cout << "No" << '\n';

  return 0;
}


Measured memory_bytes: 256
from collections import Counter, defaultdict
def resolve():
    H, W = map(int, input().split())
    S = Counter()
    for _ in range(H):
        S.update(list(input()))

    dd = defaultdict(int)
    for k, v in S.items():
        q, r = divmod(v, 4)
        dd[4] += q
        qq, rr = divmod(r, 2)
        dd[2] += qq
        dd[1] += rr

    ans = "Yes"

    if H % 2 == 0 and W % 2 == 0:
        if dd[2] != 0 or dd[1] != 0:
            ans = "No"
    elif H % 2 == 0:
        if dd[1] != 0 or dd[2] > H // 2:
            ans = "No"
    elif W % 2 == 0:
        if dd[1] != 0 or dd[2] > W // 2:
            ans = "No"
    else:
        if dd[1] != 1:
            ans = "No"
        else:
            if dd[2] > H // 2 + W // 2:
                ans = "No"

    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9408
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get_be(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
//get_be biger & equal
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const ll oo=1e9+10;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
//ll a[Max];
ll n;
void solve(){
	int a,b,c;
	cin>>a>>b>>c;
	set<int> s;
	s.insert(a);
	s.insert(b);
	s.insert(c);
	cout<<(sz(s)==2?"Yes":"No"); 
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}





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

int main() {
  int n;
  cin >> n;
  int x = n % 10;
  if (x == 2 || x == 4 || x == 5 || x == 7 || x == 9)
    cout << "hon" << endl;
  if (x == 0 || x == 1 || x == 6 || x == 8)
    cout << "pon" << endl;
  if (x == 3)
    cout << "bon" << endl;

}


Measured memory_bytes: 3516
/*
ID: espr1t
TASK: 
KEYWORDS: 
*/

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <set>

using namespace std;
FILE* in = stdin; FILE* out = stdout;

const int MAX = 200002;

struct Point {
    int idx;
    int x, y;
    bool operator < (const Point& r) const {
        return x != r.x ? x < r.x : y < r.y;
    }
};

int n;
Point a[MAX];
int indexer[MAX];
vector <int> v[MAX];
int inComp[MAX], compSize[MAX];

void color(int node, int comp) {
    compSize[comp]++;
    inComp[node] = comp;
    for (int i = 0; i < (int)v[node].size(); i++) {
        if (inComp[v[node][i]] == 0) {
            color(v[node][i], comp);
        }
    }
}

void solve() {
    sort(a, a + n);
    for (int i = 0; i < n; i++)
        indexer[a[i].y] = a[i].idx;

    set <int> smaller;
    for (int i = 0; i < n; i++) {
        vector <int> toErase;
        for (auto it = smaller.begin(); it != smaller.end() && *it < a[i].y; it++) {
            toErase.push_back(*it);
            int idx = indexer[*it];
            v[idx].push_back(a[i].idx);
            v[a[i].idx].push_back(idx);
        }
        if (toErase.empty()) {
            smaller.insert(a[i].y);
        } else {
            for (int i = 1; i < (int)toErase.size(); i++)
                smaller.erase(toErase[i]);
        }
    }
    int nextComp = 1;
    for (int node = 0; node < n; node++) {
        if (inComp[node] == 0) {
            color(node, nextComp++);
        }
    }
    
    for (int node = 0; node < n; node++)
        fprintf(out, "%d\n", compSize[inComp[node]]);
}

int main(void) {
	// in = fopen("A.in", "rt");
	
	fscanf(in, "%d", &n);
	for (int i = 0; i < n; i++) {
	    a[i].idx = i;
	    fscanf(in, "%d %d", &a[i].x, &a[i].y);
    }

    solve();
	
	return 0;
}

Measured memory_bytes: 20480
import java.util.*;

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

Scanner sc = new Scanner(System.in);
int A = sc.nextInt();
String op = sc.next();
int B = sc.nextInt();
if(op.equals("+")){
System.out.println(A + B);
}else{
System.out.println(A - B);
}

}
}

Measured memory_bytes: 21844
N=int(input())
a=list(map(int,input().split()))
cum=[0]*(N+1)
for i in range(N):
    cum[i+1]=cum[i]^a[i]

ans=[]
for i in range(N):
    r=cum[N]^cum[i]
    l=cum[i]
    ans.append(r^l^a[i])
print(*ans)

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

#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;
const int INF = 2e16;
const int MOD = 1e9 + 7;
const int MB = 20;

void solve() {
	int a, b, k;
	cin >> a >> b >> k;
	int x = min(a, k);
	a -= x;
	k -= x;
	b -= k;
	cout << a << " " << max(0LL, b);
}

signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<int> d(N);
    for (int i = 0; i < N; i++)
    {
        cin >> d[i];
    }
    int max_d = *max_element(d.begin(), d.end());
    vector<int> d_coun(max_d, 0);
    int d_sum = N;
    for (int i = 0; i < N; i++)
    {
        d_coun[d[i] - 1]++;
    }
    int ans = 0;
    for (int i = 0; i < max_d; i++)
    {
        d_sum -= d_coun[i];
        if (d_sum == N / 2)
        {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
    
int main(){
    
int a,b,x,y,r;
    
scanf("%d %d %d %d %d",&a,&b,&x,&y,&r);
  
if(0<=x-r && x+r<=a && 0<=y-r && y+r<=b)
printf("Yes\n");
else
printf("No\n");
    
return 0;
}


Measured memory_bytes: 2120
H, W = map(int, input().split())
S = []
for h in range(H):
    S_h = list(input())
    S.append(S_h)

d = [-1, 0, 1]
for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            continue
        else:
            count = 0
            for i in range(3):
                for j in range(3):
                    hs = h + d[i]
                    ws = w + d[j]
                    if 0 <= hs < H and 0 <= ws < W and S[hs][ws] == '#':
                        count += 1
                    else:
                        continue
            S[h][w] = str(count)

ans_row = [''.join(S[h]) for h in range(H)]
print('\n'.join(ans_row))

Measured memory_bytes: 9192
#include <iostream>
#include <algorithm>
#include <vector>
#define int long long
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define chmax(x,y) x=max(x,y)
using namespace std;
int s[3010][3010];
int a[2][1010][1010];

signed main() {
  int N, K; cin >> N >> K;
  int ans = 0;
  rep(i, N) {
    int x, y;
    char c;
    cin >> x >> y >> c;
    if(c == 'B') y += K;
    x %= 2*K;
    y %= 2*K;
    s[x][y]++;
    s[x+K][y+K]++;
    s[x][y+K]--;
    s[x+K][y]--;
  }
  rep(i, 3*K) rep(j, 3*K) s[i][j+1] += s[i][j];
  rep(i, 3*K) rep(j, 3*K) s[i+1][j] += s[i][j];
  rep(i, 3*K) rep(j, 3*K) {
    int p = (i/K+j/K) % 2;
    a[p][i%K][j%K] += s[i][j];
  }
  rep(p, 2) rep(i, K) rep(j, K) chmax(ans, a[p][i][j]);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 86784
import java.util.*;
public class Main {
    public static void main(String args []){
        Scanner sc  = new Scanner(System.in);
        String s = "abcdefghijklmnopqrstuvwxyz";
        String c = sc.next();
        for(int i=0;i<s.length();i++){
            if(c.charAt(0)==s.charAt(i)){
                System.out.println(s.charAt(i+1));
                break;
            }
        }

    }
}


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

int main(){
  int A, B, C, X, Y;
  int p1, p2, p3, minXY;

  cin >> A >> B >> C >> X >> Y;
  p1 = A * X + B * Y;
  minXY = min(X, Y);
  if(X > Y){
    p2 = C * minXY * 2 + A * (X - Y);
  }else{
    p2 = C * minXY * 2 + B * (Y - X);
  }
  p3 = C * max(X, Y) * 2;
  minXY = min(p1, p2);
  cout << min(minXY, p3) << endl;
}

Measured memory_bytes: 256
n = int(input())

if 1 <= n and n < 10:
    print(n)
elif 10 <= n and n < 100:
    print(9)
elif 100 <= n and n < 1000:
    print(9 + n - 100 + 1)
elif 1000 <=n and n < 10000:
    print(9 + 999 - 100 + 1)
elif 10000 <= n and n < 100000:
    print(9 + 999 - 100 + 1 + n - 10000 + 1)
elif 100000 == n:
    print(9 + 999 - 100 + 1 + 99999 - 10000 + 1)



Measured memory_bytes: 3060
import math
import collections
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n = int(input())
N = collections.Counter(prime_factorize(n))
total = 0
for i in N.values():
    for j in range(40):
        if j*(j+1)//2 <= i < (j+1)*(j+2)//2:
            total += j
            break
print(total)

Measured memory_bytes: 9480
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>

#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

lli a[200000] = {};


int main(void) {

	int n;
	string s;
	cin >> n >> s;

	if (n % 2 == 1) {
		COUT("No");
		return 0;
	}

	for (int i = 0; i < n / 2; i++) {
		if (s[i] != s[n / 2 + i]) {
			COUT("No");
			return 0;
		}
	}

	COUT("Yes");

	return 0;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  int x = 0;
  int y = 0;
    
  x = c / b;
  y = a / d;
  
  if ( c < b ){
    x = 1;
  }
  if ( a < d ){
    y = 1;
  }
    
  if ( c >= b ){  
  
  if ( c % b > 0 ){
    x = x + 1;
  }
  
  }
  
  if ( a >= d ){
  
  if ( a % d > 0 ){
    y = y + 1;
  }
  
  }
  
  if (x > y) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}



Measured memory_bytes: 3636
// AOJ 2590: Unknown Switches
// 2017.11.30 bal4u@uu

#include <stdio.h>
#include <string.h>

long long b[1002];
int n;
char buf[1100], *p;

int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int check(long long x)
{
	int k, f = 1;

	if (x == 0) return -1;
	while (!(x & 1)) f++, x >>= 1;
	x >>= 1; if (x) return -1;
	k = n - f;
	if (k < 10) return k + '0';
	return k - 10 + 'A';
}

int main()
{
	int m, q, i, j, c;
	long long s, t, mask;

	while (fgets(p=buf, 30, stdin) && *p != '0') {
		n = getint(), p++, m = getint(), p++, q = getint();

		memset(b, 0xff, sizeof(b));
		mask = (1LL << n) - 1;

		for (s = 0, i = 0; i < q; i++) {
			fgets(p=buf, 1100, stdin);
			t = 0; while (*p >= '0') t = (t<<1) | (*p++ & 1);
			s = s ^ t;

			for (p++, j = 0; j < m; j++) {
				if (*p++ & 1) b[j] &=  s;
				else          b[j] &= ~s;
			}
	    }

		for (i = 0; i < m; i++) {
			if ((c = check(b[i] & mask)) > 0) putchar(c);
			else putchar('?');
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 1700
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch IntervalRunning | diff IntervalRunning.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address IntervalRunning.cpp && ./a.out

/*
 
 12/1/2019
 
 5:07-5:40 give up
 10:20-11:45 read editorial and got AC
 
 */

LL T[2],A[2],B[2];

string solve() {
  LL P=(A[0]-B[0])*T[0],Q=(A[1]-B[1])*T[1];
  if(P>0) P*=-1,Q*=-1;
  if(P+Q<0) return "0";
  if(P+Q==0) return "infinity";
//  dump(P,Q,P+Q);
  LL k=abs(P/(P+Q));
  LL res=2LL*k;
  if((P+Q)*k!=-P) ++res;
  return to_string(res);
}

void solve_wrong() {
  int res=0;
  LL a=0,b=0;
  int sign=-100;
  FOR(i,0,1e6) {
    a+=T[i%2]*A[i%2];
    b+=T[i%2]*B[i%2];
    LL x=min(a,b);
    a-=x,b-=x;
    int sign2=a==b?0:a>b;
    if(sign2==0||sign2!=sign) ++res;
    sign=sign2;
  }
  if(res>1e5) cout<<"infinity"<<endl;
  else cout<<res-1<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>T[0]>>T[1]>>A[0]>>A[1]>>B[0]>>B[1];
  cout<<solve()<<endl;
  
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> b(n - 1);
    rep(i, n - 1) cin >> b[i];
    vector<int > a(n);
    a[0] = b[0];
    for(int i = 1; i <= n - 2; i++){
        a[i] = min(b[i], b[i - 1]);
    }
    a[n - 1] = b[n - 2];
    int ans = 0;
    rep(i, n) ans += a[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3560
N,A,B=map(int,input().split())
S=input()

a,b=0,0
for i in range(N):
  if a+b<A+B:
    if S[i]=='a':
      print('Yes')
      a += 1
    elif S[i]=='b' and b < B:
      print('Yes')
      b += 1
    else:
      print('No')
  else:
    print('No')

Measured memory_bytes: 9260