akhauriyash/Code-Regression huggingface dataset:
a,b,c,d,e,f = list(map(int, input().split()))
maxn = -1
ans = ()
for at in range(0,31):
    for bt in range(0,31-at):
        water = (at * a + bt * b) * 100
        if water > f:
            continue

        # 溶け残らないように砂糖を選ぶ
        maxsugar = water * e // 100
        for ct in range(0, maxsugar//c + 1):
            for dt in range(0, (maxsugar-ct*c)//d + 1):
                sugar = ct * c + dt * d

                if 0 < sugar + water <= f and sugar <= (at * a + bt * b) * e:
                    # 水１００に対して溶けている砂糖の量
                    n = 100 * sugar / water
                    if n == e:
                        print(water + sugar, sugar)
                        exit()
                    if n > maxn:
                        ans = water + sugar, sugar
                        maxn = n
print(*ans)

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

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using Vec = vector<int>;


int main() {
    
int n,k=0;
ll sum=1;
cin>>n;

for(int i=0;i<n;i++){
ll x;
cin>>x;
ll test = sum;
sum=sum*x;

if(x==0){
    k=2;
    break;
}

if(test!=sum/x||sum<test){
    k=1;
}

if(1000000000000000000<sum){
   
    k=1;
}


}    
if(k==0){
    cout<<sum<<endl;
}
else if(k==1){
   
    
      cout<<"-1"<<endl;

}
else if(k==2){
    cout<<0<<endl;
}
}

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

int main() {
	int a, b;
	string ope;

	cin >> a >> b;
	
	if (a<b) {
		ope = " < ";
	}else if (a>b){
		ope = " > ";
	}else{
		ope = " == ";
	}

	cout << "a"+ope+"b" << endl;

	return 0;
}



Measured memory_bytes: 3212
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using ll = long long;

#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 200000;

struct Camel{
  int lim;
  int x;
  int y;
  bool operator < (Camel const &a) {
    return fabs(x - y) < fabs(a.y - a.x);
  }
} v[1 + nmax];

class SegmentTree{
private:
  std::vector<int> aint;
  std::vector<int> lazy;
public:
  SegmentTree(int n) {
    aint.resize(1 + 4 * n);
    lazy.resize(1 + 4 * n);
  }
  void cleannode(int node, int from, int to) {
    if(lazy[node] == 0)
      return ;
    if(from < to) {
      int mid = (from + to) / 2;
      lazy[node * 2] += lazy[node];
      lazy[node * 2 + 1] += lazy[node];
    }
    aint[node] += lazy[node];
    lazy[node] = 0;
  }
  void computenode(int node, int from, int to) {
    aint[node] = std::min(aint[node * 2], aint[node * 2 + 1]);
  }
  void update(int node, int from, int to, int x, int y, int val) {
    if(from == x && to == y) {
      lazy[node] += val;
      cleannode(node, from, to);
    } else {
      int mid = (from + to) / 2;
      cleannode(node * 2, from, mid);
      cleannode(node * 2 + 1, mid + 1, to);
      if(x <= mid)
        update(node * 2, from, mid, x, MIN(y, mid), val);
      if(mid + 1 <= y)
        update(node * 2 + 1, mid + 1, to, MAX(x, mid + 1), y, val);
      computenode(node, from, to);
    }
  }
  int query(int node, int from, int to, int x, int y) {
    cleannode(node, from, to);
    if(from == x && to == y)
      return aint[node];
    else {
      int mid = (from + to) / 2;
      if(x <= mid && y <= mid)
        return query(node * 2, from, mid, x, y);
      else if(mid + 1 <= x && mid + 1 <= y)
        return query(node * 2 + 1, mid + 1, to, x, y);
      else
        return std::min(query(node * 2, from, mid, x, mid),
                       query(node * 2 + 1, mid + 1, to, mid + 1, y));
    }
  }
};

void solve() {
  int n;
  std::cin >> n;
  for(int i = 1; i <= n; i++) 
    std::cin >> v[i].lim >> v[i].x >> v[i].y;
  std::sort(v + 1, v + n + 1);
  SegmentTree pref(n), suff(n);
  for(int i = 1; i <= n; i++) {
    pref.update(1, 1, n, i, i, i);
    suff.update(1, 1, n, i, i, n - i + 1);
  }
  ll result = 0;
  for(int i = n; 1 <= i; i--) {
    result += std::min(v[i].x, v[i].y);
    if(v[i].x < v[i].y) {
      if(v[i].lim < n && 0 < suff.query(1, 1, n, 1, v[i].lim + 1)) {
        result += v[i].y - v[i].x;
        suff.update(1, 1, n, 1, v[i].lim + 1, -1);
      }
    } else {
      if(0 < pref.query(1, 1, n, v[i].lim, n)){
        result += v[i].x - v[i].y;
        pref.update(1, 1, n, v[i].lim, n, -1);
      }
    }
  }
  std::cout << result << '\n';
}

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

  int t;
  std::cin >> t;
  for(int testcase = 1; testcase <= t; testcase++)
    solve();
}


Measured memory_bytes: 18004
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>
//#include <boost/multiprecision/cpp_int.hpp>



using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const double EPS = 1e-10;
long long const MOD = 998244353;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

const int MAXN = 1100010;
long long fact[MAXN], inv[MAXN];

void initComb() {
    fact[0] = 1;
    for (int i=1; i<MAXN; i++) {
        fact[i] = (fact[i-1] * i) % MOD;
    }

    inv[MAXN - 1] = mod_pow(fact[MAXN - 1], MOD-2);
    for (int i=MAXN - 2; i>=0; i--) {
        inv[i] = (inv[i+1] * (i+1)) % MOD;
    }
}

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

Int imos_D[1000005];
Int imos_C[1000005];
Int imos_M[1000005];
Int dp[1000005][5];

int main(void) {
    int N; cin >> N;
    string S; cin >> S;
    int Q; cin >> Q;

    for (int i = 0; i < N; i++) {
        if (S[i] == 'D') imos_D[i+1] = 1;
        else imos_D[i+1] = 0;
        imos_D[i+1] += imos_D[i];

        if (S[i] == 'C') imos_C[i+1] = 1;
        else imos_C[i+1] = 0;
        imos_C[i+1] += imos_C[i];

        if (S[i] == 'M') imos_M[i+1] = 1;
        else imos_M[i+1] = 0;
        imos_M[i+1] += imos_M[i];
    }

    for (int i = 0; i < Q; i++) {
        int K; cin >> K;
        memset(dp, 0, sizeof(dp));
        dp[0][0] = 1;
        for (int j = 0; j < N; j++) {
            dp[j+1][0] = dp[j][0];
            dp[j+1][1] = dp[j][1];
            dp[j+1][2] = dp[j][2];
            dp[j+1][3] = dp[j][3];
            dp[j+1][4] = dp[j][4];
            if (S[j] == 'D') {
                dp[j+1][1] += dp[j][0];
            }
            if (S[j] == 'M') {
                dp[j+1][2] += dp[j][1];
            }
            if (S[j] == 'C') {
                dp[j+1][3] += dp[j][2];
            }

            if (S[j] == 'C') {
                if (j+1-K >= 0) {
                    Int NumOfM = imos_M[j+1] - imos_M[j+1-K];
                    dp[j+1][4] += dp[j][2] - NumOfM * dp[j+1-K][1] - dp[j+1-K][2]; 
                } else {
                    dp[j+1][4] += dp[j][2];
                }
            }
            // cout << NumOfM << endl;
        }
        Int U = dp[N][3];
        cout << dp[N][4] << endl;
    }
}

Measured memory_bytes: 64628
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    string s;
    cin >> s;
    bool flag = true;
    rep(i, s.size()-1)
    {
        for(int j = i+1;j<s.size();j++){
            if(s[i]==s[j])
                flag = false;
        }
    }
    if(flag){
        cout << "yes" << endl;
    }else{
        cout << "no" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int dp[3001][3001];

int main(){
    string s, t;
    cin >> s >> t;
    int n=s.size(); int m=t.size();

    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            if(s.at(i-1)==t.at(j-1)){
            //    dp[i][j].second=i-1;
                dp[i][j]= dp[i-1][j-1]+1;
            }
            else{
                if(dp[i-1][j]> dp[i][j-1]){
                    dp[i][j] = dp[i-1][j];
                }
                else dp[i][j]=dp[i][j-1];
            }
        }
    }
    string ans="";
    int a =n, b=m;
    while(a>0){
        if(dp[a][b]==dp[a-1][b]){
            a--;
        }
        else if(dp[a][b]==dp[a][b-1]){
            b--;
        }
        else{
            ans = s.at(a-1) + ans;
            a--; b--;
        }
    }

    cout << ans << endl;
}

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

const int MAX_N = 100005;
int n, m;
int A[MAX_N];
priority_queue<pair<int, int>> pq;

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

    for (int i = 0; i < m; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        pq.push({-b, a});
    }

    int s = 0, cnt = 0;
    while(!pq.empty()) {
        int b = -pq.top().first, a = pq.top().second;
        // cout << "[" << a << "," << b << "]" << endl;
        pq.pop();
        if (a < s) continue;
        s = b;
        cnt++;
    }

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

Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
#include <math.h>
using namespace std;

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

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

int main() {
  ll a, b, c, d; cin >> a >> b >> c >> d;
  ll ans = 0;
  ll num1, num2;
  num1 = b - ((b / c + b / d) - b / (c * d / __gcd(c, d)));
  a--;
  num2 = a - ((a / c + a / d) - a / (c * d / __gcd(c, d)));
  ans = num1 - num2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
typedef long long int ll;
void chmin(long long  &a, long long b) { if (a > b) a = b; }
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) { a = b; return 1; }return 0; }
#define rep(i, n) for (ll i = 0; i < n; i++)
#define cinf(n,x,y,z) for(int i=0;i<(n);i++) cin >> x[i]>> y[i] >> z[i];
const long long INF =1LL << 60;
long long  dp[41][410][410];
int main(){
  int N,ma,mb; cin >> N >> ma >> mb;
  vector<long long> a,b,c;
  a.resize(N);b.resize(N);c.resize(N);
  cinf(N,a,b,c);;
  rep(i,N+1){
    rep(j,410){
      rep(k,410){
        dp[i][j][k] = INF;
      }
    }
  }
  dp[0][0][0] =0;
  rep(i,N){
    rep(j,410){
      rep(k,410){
        if(dp[i][j][k] >= INF) continue;
        
        chmin(dp[i+1][j][k],dp[i][j][k]);
        chmin(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i]);
      }
    }
  }
  ll ans=INF;
  for(int i=1;i<410;i++){
    for(int j=1;j<410;j++){
      if(i*mb != j*ma) continue;
      chmin(ans,dp[N][i][j]);
    }
  }
  if(ans< INF) cout << ans << endl;
  else cout << -1 << endl;
}
                 

Measured memory_bytes: 54144
#include<bits/stdc++.h>
using namespace std;
#define MAX 3000

int p;
int b[MAX];
int upstairs[MAX];
int inv_upstairs[MAX];

int power(int m, int n) {
    if (n==0) return 1;
    else if (n==1) return m;
    else {
        if (n%2==0) return (power((m*m)%p, n/2))%p;
        else return (m*power((m*m)%p, (n-1)/2))%p;
    }
}

int combination(int n, int k) {
    return (((upstairs[p-1]*inv_upstairs[k])%p)*inv_upstairs[p-1-k])%p;
}

int main() {
    int a;
    cin >> p;

    for (int i=0; i<p; i++) {
        b[i] = 0;
        if (i==0) upstairs[i] = 1;
        else upstairs[i] = (upstairs[i-1]*i)%p;
        inv_upstairs[i] = power(upstairs[i], p-2);
    }

    for (int i=0; i<p; i++) {
        cin >> a;
        if (a==1) {
            b[0] = (b[0] + 1) % p;
            b[p-1]--;
            for (int j=0; j<p-1; j++) {
                b[j] = (b[j] - power(-i, p-1-j)*combination(p-1, j))%p;
            }
        }
    }

    for (int i=0; i<p; i++) {
        if (b[i]>=0) {
            printf("%d ", b[i]%p);
        } else {
            while (b[i]<0) b[i] += p;
            printf("%d ", b[i]);
        }
    }

    return 0;

}

Measured memory_bytes: 384
import sys
import math as mas

def sieve(n):
	p=[True for i in range(n+1)]
	p[0]=p[1]=False
	end=int(n**0.5)
	for i in range(2,end+1):
		if p[i]:
			for j in range(i*i,n+1,i):
				p[j]=False
	return p
	
sosu=sieve(1000010)
for i in sys.stdin:
	t=int(i)
	if t<2:print(0)
	elif t==2:print(1)
	else:print(1+sum(sosu[t] for t in range(3,int(i)+1,2)))

#	a,b=map(int,i.split())
#	print(gcd(a,b),lcm(a,b))

Measured memory_bytes: 15124
using System;
class Program
{
	static void Main(string[] args)
	{
		string[] input = Console.ReadLine().Split(' ');
		// 文字列の入力
        long a = long.Parse(input[0]);
        long b = long.Parse(input[1]);
        long c = long.Parse(input[2]);
        long k = long.Parse(input[3]);
      
        long max = 0;
        if(a > k) max = k;
        else if(a + b > k) max = a;
        else max = a - ( k - a - b);
      
        Console.WriteLine(max);
	}
}

Measured memory_bytes: 27456
N=50021
prime = [false,false] + [true]*(N-1)
(2..(Math.sqrt(N).to_i+1)).each do |i|
  next unless prime[i]
  (i*i).step(N, i).each do |j|
    prime[j] = false
  end
end

while gets do
  n = $_.to_i
  min = (2..(n-1)).to_a.reverse.find { |i| prime[i] } || 1
  max = ((n+1)..N).find { |i| prime[i] } || 1
  puts sprintf("%d %d", min, max)
end

Measured memory_bytes: 9136
#include <iostream>

using namespace std;
int main(void){
    
    string s;
    cin >> s;
    int i;
    
    bool alp[26];
    for(i=0;i<26;++i)alp[i]=false;
    
    for(i=0;i<s.length();++i){
        alp[s[i]-'a']=true;
        //cout << s[i]-'a'<<" ";
    }
    for(i=0;i<26;++i){
        if(!alp[i]){
            cout<<char('a'+i);
            return 0;
        }
    }
    
    cout << "None";
    
    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.immutable.Queue

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  @tailrec
  private def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}


object Main {
  def solve(sc: => Scanner): Unit = {
    val N = sc.nextInt
    if (N != 0) {
      val A = Array.fill(N)((sc.nextInt, sc.nextInt, sc.nextInt, sc.nextInt))
      val P, Q, R, C = sc.nextInt
      val B = A.filter(X => X._2 <= P && X._3 <= Q && X._4 <= R && X._2 * 4 + X._3 * 9 + X._4 * 4 <= C).map(X => X._1)
      println(if (B.length == 0) ("NA") else (B.mkString("\n")))
      solve(sc)
    }
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

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

int main()
{
    int n;
    int order, val;
    vector<int> a;

    cin >> n;

    for( int i = 0; i < n; i++ )
    {
        cin >> order;
        if( order == 0 )
        {
            cin >> val;
            a.push_back(val);
        }
        else if( order == 1 )
        {
            cin >> val;
            cout << a[val] << endl;
        }
        else
            a.pop_back();
    }

    return 0;
}


Measured memory_bytes: 3816
# coding: utf-8

import sys
from collections import deque

n, q = map(int, input().split())
total_time = 0
tasks = deque(map(lambda x: x.split(), sys.stdin.readlines()))

for task in tasks:
    task[1] = int(task[1])

while tasks:
    t = tasks.popleft()
    if t[1] <= q:
        total_time += t[1]
        print(t[0], total_time)
    else:
        t[1] -= q
        total_time += q
        tasks.append(t)

Measured memory_bytes: 23192
#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define MOD 1000000007
#define MP make_pair
#define PB push_back
#define SZ(a) ((int)a.size())
typedef long long ll;

int R, C, N, M;
vector<pair<int, int>> ev, v[4];
stack<int> s;

int conv (int r, int c) {
        if (r == 0) return c;
        else if (c == C) return C+r;
        else if (r == R) return C+R+C-c;
        else if (c == 0) return C+R+C+R-r;
        else return -1;
}

int main () {
        scanf("%d %d %d", &R, &C, &N), M = R+C+R+C;
        fo(i, 1, N+1) {
                int x1, y1, x2, y2, a, b;
                scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
                a = conv(x1, y1);
                b = conv(x2, y2);

                if (a >= 0 && b >= 0) {
                        ev.PB(MP(min(a,b), i));
                        ev.PB(MP(max(a,b), -i));
                }
        }

        sort(ev.begin(), ev.end());
        for (auto i : ev) {
                if (i.second > 0) s.push(i.second);
                else {
                        if (s.empty() || s.top() != -i.second) {
                                puts("NO");
                                return 0;
                        }
                        s.pop();
                }
        }

        puts("YES");

        return 0;
}


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

using ll = long long;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

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

  ll ans = 1;
  for(auto x: prime_factor(P)) {
    if(x.second / N >= 1) ans *= pow(x.first, x.second / N);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    int n, k, y, x;
    cin >> n >> k >> x >> y;
    if(n >= k){
        cout << (k*x + (n-k)*y) << endl;
    }
    else{
        cout << n*x << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <algorithm>
#include <set>
#include <cstdio>
#include <vector>
using namespace std;

int main() {
	int N, M;
	while(cin >> N >> M && (N || M)){
		int  P[1001] = {0}, ans = 0;
		for(int i = 0; i < N; ++i){
			scanf("%d", &P[i]);
		}
		vector<int> v;
		for(int i = 0; i <= N; ++i){
			for(int j = 0; j <= N; ++j){
				if(P[i] + P[j] <= M)
					v.push_back(P[i] + P[j]);
			}
		}
		sort(v.begin(), v.end());
		v.erase(unique(v.begin(), v.end()), v.end());
		for(unsigned int i = 0; i < v.size(); ++i){
			if(v[i] > M)
				continue;
			vector<int>::iterator it = lower_bound(v.begin(), v.end(), M - v[i]);
			if(it == v.end())
				--it;
			if(*it > M - v[i])
				--it;
					
			ans = max(ans, v[i] + *it);
		}
		/*for(int i = 0; i <= N; ++i){
			for(int j = 0; j <= N; ++j){
				if(P[i] + P[j] > M)
					continue;
				set<int>::iterator it = darts.lower_bound(M - (P[i] + P[j]));
				if(it == darts.end())
					--it;
				if(*it > M - (P[i] + P[j]))
					--it;
					
				ans = max(ans, P[i] + P[j] + *it);
			}
		}*/
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 9232
#include<iostream>
#include<cstdio>
#include<cstring>
const int N=5005;
char s[N];
int nxt[N];
void pre(const char *s) {
    int len=strlen(s);
    nxt[0]=nxt[1]=0;
    for(int i=1,j=0;i<len;i++) {
        while(j&&s[j]!=s[i]) j=nxt[j];
        if(s[j]==s[i]) j++;
        nxt[i+1]=j;
    }
}
int main() {
    int n,ans=0;
    scanf("%d%s",&n,s+1);
    for(int i=2;i<=n;i++) {
        pre(s+i);
        int m=n-i+1;
        for(int j=1,k=0;j<i;j++) {
            while(k&&s[j]!=s[i+k]) k=nxt[k];
            if(s[j]==s[i+k]) k++;
            ans=std::max(ans,k);
            if(k==m) break;
        }
    }
    printf("%d\n",ans);
    return 0;
}


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


using namespace std;





int main() {
	string s;
	cin >> s;
	int n = s.size();
	set <char> st;
	for (int i = 0; i < n; ++i) {
		st.insert(s[i]);
	}

	int ok = 1;
	if(st.find('S') != st.end()){
		if(st.find('N') == st.end()){
			ok = 0;
		}
	}
	if(st.find('N') != st.end()){
		if(st.find('S') == st.end()){
			ok = 0;
		}
	}
	if(st.find('W') != st.end()){
		if(st.find('E') == st.end()){
			ok = 0;
		}
	}
	if(st.find('E') != st.end()){
		if(st.find('W') == st.end()){
			ok = 0;
		}
	}
	if (ok) puts("Yes");
	else puts("No");
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int dp[100005] = {};
int s[100005] = {};
int main() {
	int n;
	long long int ans = 1;
	cin >> n;
	int mis = 3;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		s[a]++;
		if (a == 0) {
			ans = ans * mis;
			mis = mis - 1;
		}
		else {
			ans = s[a - 1] * ans % MOD;
			s[a - 1]--;
		}
	}
	cout << ans;
}

Measured memory_bytes: 640
#include <cstdio>
#include <queue>
#include <vector>
#include <cassert>
#include <algorithm>
using namespace std;

const int N = 2005;
bool G[N][N];
bool used[N];
vector <int> g[N];
int n, a[N], sz;
int in[N];
priority_queue <int> pq;

inline int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }

void dfs(int i) {
    used[i] = 1;
    for (int j = 0; j < n; ++ j) if (!used[j] && G[i][j]) { g[i].push_back(j); ++ in[j]; dfs(j); }
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++ i) scanf("%d", &a[i]);
    sort(a, a + n);
    for (int i = 0; i < n; ++ i) for (int j = 0; j < n; ++ j) if (i ^ j) G[i][j] = (gcd(a[i], a[j]) != 1);
    for (int i = 0; i < n; ++ i) if (!used[i]) dfs(i);
    for (int i = 0; i < n; ++ i) assert(in[i] <= 1);
    for (int i = 0; i < n; ++ i) if (!in[i]) pq.push(i);
    while (!pq.empty()) {
        int i = pq.top(); pq.pop();
        printf("%d ", a[i]);
        for (int j = 0; j < (int) g[i].size(); ++ j) {
            -- in[g[i][j]];
            if (!in[g[i][j]]) pq.push(g[i][j]);
        }
    }
    puts("");
    return 0;
}


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

const double eps = 1e-9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;

#define sz(c) int((c).size())
#define all(c) (c).begin(), (c).end()
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define FORD(i,a,b) for (int i = int(b)-1; i >= (a); i--)
#define FORIT(i,c) for (__typeof__((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define mp make_pair
#define pb push_back

vi primes;
bool hasEdge(int n){
    if(n == 1)return false;
    if(n%2 == 0)return false;
    for(auto p: primes){
        if(p*p > n)return true;
        if(n%p==0)return false;
    }
    return true;
}

vi adj[512];
int prev_[512];
bool mark[512];

bool find_match(int n){
    if(n == -1)return true;
    if(mark[n])return false;
    mark[n] = true;
    for(auto it: adj[n])if(find_match(prev_[it])){
        prev_[it] = n;
        return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    for(int i = 3; i < 10000; i++){
        bool ok = true;
        for(auto p: primes)if(i%p==0){
            ok = false;
            break;
        }
        if(ok)primes.pb(i);
    }
    int N;
    set<int> nums;
    cin >> N;
    FOR(i,0,N){
        int x;
        cin >> x;
        if(nums.find(x) != nums.end())nums.erase(x);
        else nums.insert(x);
        if(nums.find(x+1) != nums.end())nums.erase(x+1);
        else nums.insert(x+1);
    }
    vi even, odd;
    for(auto it: nums){
        if(it%2==0)even.pb(it);
        else odd.pb(it);
    }
    int E = sz(even);
    int O = sz(odd);
    FOR(i,0,E)adj[i].clear();
    FOR(e,0,E)FOR(o,0,O)if(hasEdge(abs(even[e]-odd[o]))){
        adj[e].pb(o);
    }
    assert(max(E,O) < 512);
    FOR(i,0,O)prev_[i] = -1;
    int M = 0;
    FOR(i,0,E){
        FOR(j,0,E)mark[j] = 0;
        if(find_match(i))M++;
    }
    int res = M;
    E -= M;
    O -= M;
    res += 2 * (E / 2);
    E%=2;
    res += 2 * (O / 2);
    O %= 2;
    if(E)res += 3;
    cout << res << endl;
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int times(int n,int k){
    int count = 0;
    if(n >= k){
        return count;
    }else{
        while(1){
            n *= 2;
            count++;
            if(n >= k) break;
        }
    }
    return count;
}
int mypow(int n){
    int ans = 1;
    for(int i = 0 ; i < n ; i++){
        ans *= 2;
    }
    return ans;
}

int main(){
    int i,n,k;
    double p = 0.0;
    double tmp;
    
    scanf("%d %d",&n,&k);
    
    for(i = 1 ; i <= n ; i++){
        if(times(i,k) == 0){
            p += (double)1.0/n;
//            printf("%d's p is 1.0\ntotal = %.9f\n",i,p);
        }else{
            tmp = (double)1/(mypow(times(i,k)) * n);
            p += tmp;
//            printf("%d's p is 1/%d\ntotal = %.9f\n",i,mypow(times(i,k))*n,p);
        }
    }
    printf("%.9f\n",p);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>                                                                                               
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define mk_p(a,b)   make_pair((a),(b))
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

int gcd(int a,int b){return b ? gcd(b,a%b) : a;} 
int lcm(int a,int b){return a/gcd(a,b)*b;}

signed main(){
    int a,b,k,cnt = 0;
    cin >> a >> b >> k;
    int x = gcd(a,b);
    for(int i = x;i>0;i--){
        if(a % i == 0 && b % i == 0) ++cnt;
        if(cnt == k){ 
            cout << i << '\n';
            return 0;
        }
    }   
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int a,b,c; scanf("%d%d%d",&a,&b,&c);
  if(a>=b && a>=c) printf("%d\n",b+c);
  else if(b>=a && b>=c) printf("%d\n",c+a);
  else if(c>=b && c>=a) printf("%d\n",a+b);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向

int n;
int a[51];

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

bool check1(int* x, int n){
    for(int i=0;i<n;i++) if(*(x+i) < 0) return false;
    return true;
} //すべて0以上かどうかチェック

bool check2(int* x, int n){
    for(int i=0;i<n;i++) if (*(x+i) > 0) return false;
    return true;
} //すべて0以下かどうかチェック

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    vector<P> ans;
    if(check1(a, n)) for(int i=1;i<n;i++) ans.push_back(P(i, i+1));
    else if(check2(a, n)) for(int i=n;i>1;i--) ans.push_back(P(i, i-1));
    else{
        int mx = 0, mn = INF;
        int mx_num,mn_num;
        for(int i=0;i<n;i++) mx = max(mx, a[i]), mn = min(mn, a[i]);
        for(int i=0;i<n;i++){
            if(mx == a[i]) mx_num = i+1;
            else if(mn == a[i]) mn_num = i+1;
        }
        if(abs(mx) >= abs(mn)){
            for(int i=0;i<n;i++) ans.push_back(P(mx_num, i+1));
            for(int i=1;i<n;i++) ans.push_back(P(i, i+1));
        }
        else{
            for(int i=0;i<n;i++) ans.push_back(P(mn_num, i+1));
            for(int i=n;i>1;i--) ans.push_back(P(i, i-1));
        }
    }
    if(ans.empty()) cout << 0 << endl;
    else{
        cout << ans.size() << endl;
        for(int i=0;i<ans.size();i++) cout << ans[i].first << ' ' << ans[i].second << endl;
    }
    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 sum1 = a + b;
	int sum2 = c + d;
	if (sum1 > sum2) {
		cout << "Left" << endl;
	} else if (sum1 < sum2) {
		cout << "Right" << endl;
	} else {
		cout << "Balanced" << endl;
	}
	return 0;
}

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

int main() {
    string s;
    cin >> s;
    vector<int> c(2);
    for (int i = 0; i < s.size(); i++) {
        c.at(s.at(i) - '0')++;
    }
    int ans = min(c.at(0), c.at(1)) * 2;
    cout << ans << endl;
}

Measured memory_bytes: 512
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 1; i < (int)(n+1); i++)
#include <bits/stdc++.h>
using namespace std;

int main(){
    long long n,s=0;
    cin >> n;
    rep(i,n){
        rep(j,n){
            rep(k,n){
                s += gcd(gcd(i,j),k);
            }
        }
    }
    cout << s << endl;
}

Measured memory_bytes: 3636
n,k=map(int,input().split())
XY=[list(map(int,input().split())) for _ in [0]*n]
a=XY.sort()
ans=float("inf")
for i in range(n-k+1):
    for j in range(i+k,1+n):
        x=XY[j-1][0]-XY[i][0]
        now=XY[i:j]
        now.sort(key=lambda x:x[1])
        for w in range(j-i-k+1):
            ans=min(ans,x*(now[w+k-1][1]-now[w][1]))

print(ans)
            

Measured memory_bytes: 39664
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
vector<long long> divisor(long long val) {
  vector<long long> res;
  for (long long i = 1; i * i <= val; ++i) {
    if (val % i == 0) {
      res.emplace_back(i);
      if (i * i != val) res.emplace_back(val / i);
    }
  }
  sort(ALL(res));
  return res;
}

bool is_prime(long long val) {
  if (val <= 1) return false;
  for (long long i = 2; i * i <= val; ++i) {
    if (val % i == 0) return false;
  }
  return true;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  long long a, b; cin >> a >> b;
  vector<long long> d = divisor(__gcd(a, b));
  int ans = 1;
  d.erase(d.begin());
  for (long long e : d) {
    if (is_prime(e)) ++ans;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 384
h,w=gets.split.map &:to_i
mas=(1..h).map{gets.chomp}
for y in 0...h
    for x in 0...w
        if mas[y][x]=='.'
            cnt=0
            for j in -1..1
                for i in -1..1
                    cnt+=1 unless x+i<0||x+i>=w||y+j<0||y+j>=h||mas[y+j][x+i]=='.'
                end
            end
            print(cnt)
        else
            print(mas[y][x])
        end
    end
    puts("")
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<pll> ba(n);
  rep(i,n){
    ll b,a;
    cin >> a >> b;
    ba[i].fi=b,ba[i].se=a;
  }
  sort(all(ba));

  ll time=0;
  rep(i,n){
    time+=ba[i].se;
    if(time>ba[i].fi){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}


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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main(){ 
  ll n;
  cin >> n;
  ll a,b;
  cin >> a >> b;
  for(ll i = a; i <= b; i++){
    if(i/n*n==i){
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
  return 0;
}



Measured memory_bytes: 3632
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int max = in.nextInt();
        int numMts = 1;
        for (int i = 1; i < n; i++) {
            int h = in.nextInt();
            if (h >= max) {
                max = h;
                numMts++;
            }
        }

        System.out.println(numMts);
    }
}


Measured memory_bytes: 23124
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>


using namespace std;
template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;}
template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;}
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define left left228
#define right right228
#define y1 y1228
#define mp make_pair
#define pb push_back
#define y2 y2228
#define rank rank228
using ll = long long;
using ld = long double; 
const string FILENAME = "input";
const int MAXN = 200228;
const int MAXM = 1000228;


int n;
string s[MAXN];
int pos[MAXN];
int nxt[MAXM][27];
int uk = 0;
int term[MAXM];


int add(string s) {
	int cur = 0;
	for (auto x: s) {
		if (!nxt[cur][x - 'a']) {
			uk++;
			nxt[cur][x - 'a'] = uk;
		}
		cur = nxt[cur][x - 'a'];
	}
	return cur;
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//read(FILENAME);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	for (int i = 0; i < n; i++) {
		reverse(all(s[i]));
		pos[i] = add(s[i]);
		term[pos[i]]++;
	}
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		term[pos[i]]--;
		int cnt[26];
		memset(cnt, 0, sizeof(cnt));
		for (int j = 0; j < sz(s[i]); j++) {
			cnt[s[i][j] - 'a']++;
		}
		int cur = 0;
		for (int j = 0; j < sz(s[i]); j++) {
			ans += term[cur];
			for (int t = 0; t < 26; t++) {
				if (cnt[t] && t != s[i][j] - 'a') {
					ans += term[nxt[cur][t]];
				}
			}
			cur = nxt[cur][s[i][j] - 'a'];
			cnt[s[i][j] - 'a']--;
		}
		ans += term[cur];
		term[pos[i]]++;
	}
	cout << ans << '\n';
}


Measured memory_bytes: 119400
W,H,N = map(int,input().split())
max_x = W
min_x = 0
max_y = H
min_y = 0
for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1 and x > min_x:
        min_x = x
    if a == 2 and x < max_x:
        max_x = x
    if a == 3 and y > min_y:
        min_y = y
    if a == 4 and y < max_y:
        max_y = y
if max_x - min_x < 0 or max_y - min_y < 0:
    ans = 0
else:
    ans = (max_x - min_x) * (max_y - min_y)

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <functional>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
 
 
int main() {
    string s;
	cin >> s;
    int n = s.length();
    bool a = true;
    int kaisuu=0;
    fr(i,n){
      if(a==(s[i]=='0'))kaisuu+=1;
      if(a)a=false;
      else a=true;
    }
    cout << min(kaisuu,n-kaisuu) << endl;
}

Measured memory_bytes: 512
<?php
    while (true) {
        $num = trim(fgets(STDIN));
        if (strlen($num <= 3)){
                break;
        }
        $hit = 0;
        $brow = 0;
        $num = str_split($num);
        for($i = 0; $i < 4; $i++){
            if($num[$i] == $num[5]){
                $brow++;
            }if($num[$i] == $num[6]){
                $brow++;
            }if($num[$i] == $num[7]){
                $brow++;
            }if($num[$i] == $num[8]){
                $brow++;
            }
        }
                if ($num[0] == $num[5]) {
                    $hit++;
                    $brow--;
                }if ($num[1] == $num[6]) {
                    $hit++;
                    $brow--;
                }if ($num[2] == $num[7]) {
                    $hit++;
                    $brow--;
                }if ($num[3] == $num[8]) {
                    $hit++;
                    $brow--;
                }
            echo $hit . " " . $brow . "\n";
    }


Measured memory_bytes: 9240
N = int(input())
S = input()

R = [0]*(N+1)
G = [0]*(N+1)
B = [0]*(N+1)
for i in range(N):
    if S[i] == "R":
        R[i+1] += 1
    elif S[i] == "G":
        G[i+1] += 1
    else:
        B[i+1] += 1
    R[i+1] += R[i]
    G[i+1] += G[i]
    B[i+1] += B[i]

ans = 0
for i in range(N):
    for j in range(i+1, N):
        x = 2*j-i
        if S[i] == S[j]:
            continue
        if S[i] != "R" and S[j] != "R":
            ans += R[-1]-R[j]
            if x < N and S[x] == "R":
                ans -= 1
        elif S[i] != "G" and S[j] != "G":
            ans += G[-1]-G[j]
            if x < N and S[x] == "G":
                ans -= 1
        elif S[i] != "B" and S[j] != "B":
            ans += B[-1]-B[j]
            if x < N and S[x] == "B":
                ans -= 1
print(ans)

Measured memory_bytes: 68800
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	string a,b;
	int x;
	int zh(string s);
	
	cin>>a>>b;
	
	x=zh(a+b);
	
	if(int(sqrt(x))==sqrt(x))
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	
	return 0;
}
 
int zh(string s)
{
	int tmp=0;
	
	for(int i=0;i<s.size();i++)
		tmp=tmp*10+(s[i]-'0');
	return tmp;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
int main(void){
int N;
scanf("%d",&N);
bool OK = true;
int A[100];
for(int i = 0; i < N;i++)scanf("%d",&A[i]);
for(int i = 0; i < N;i++){
  if((A[i]%2 == 0) && (A[i]%3 != 0) && (A[i]%5 != 0))OK = false;
}
  if(OK == true)printf("APPROVED");
  else printf("DENIED");
  return 0;
}

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



int main() {
	int A, B, C, K;
	cin >> A >> B >> C >> K;
	for(int i = 0; i < K; ++i) {
	   if(B<=A) {
	   		B *= 2;
			continue;
	   }
	   if(C<=B) {
		   C *= 2;
		   continue;
	   }
	}
	if(A<B&&B<C) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;

							
}










Measured memory_bytes: 3632
import sys
def input():
    return sys.stdin.readline()[:-1]
N,C=map(int,input().split())
D=[tuple(map(int, input().split())) for i in range(C)]
c=[tuple(map(lambda x:int(x)-1, input().split())) for i in range(N)]
iw=[[0]*C for i in range(3)]
l=[[] for i in range(3)]
for i in range(N):
    for j in range(N):
        l[(i+j)%3].append(c[i][j])
for i in range(3):
    for j in range(C):
        for k in l[i]:
            iw[i][j]+=D[k][j]
a=10**9
for i in range(C):
    for j in range(C):
        for k in range(C):
            if i!=j and i!=k and j!=k:
                a=min(a,iw[0][i]+iw[1][j]+iw[2][k])
print(a)

Measured memory_bytes: 61404
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 入力
        String s = sc.nextLine();
        String t = sc.nextLine();

        // 出力
        String[] array_s = s.split("");
        String[] array_t = t.split("");
        if (array_s.length + 1 != array_t.length) {
            System.out.println("No");
            return;
        }
        for (int i = 0; i < array_s.length; i++) {
            if (!array_s[i].equals(array_t[i])) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}


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

int main() {
    int N; cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i], A[i] *= 2;

    // x0 = 0 のとき
    long long offset = 0;
    for (int i = 0; i < N; ++i) offset = A[i] - offset;
    long long x = offset / 2;

    // 復元
    long long cur = x;
    for (int i = 0; i < N; ++i) {
        cout << cur << " ";
        cur = A[i] - cur;
    }
    cout << endl;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if (a > b) {
        swap(a, b);
    }
    if (b == 2) {
        cout << 3 << endl;
    } else if (a == 2) {
        cout << 1 << endl;
    } else {
        cout << 2 << endl;
    }
}

Measured memory_bytes: 256
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

typedef pair<int, int> P;

int H, W, N, sx, sy;
string S, T;

bool solve(int len, int pos, int type) {
    int left = 1;
    int right = len;
    char l = type == 0 ? 'L' : 'U';
    char r = type == 0 ? 'R' : 'D';
    REV(i, N - 1, 0) {
        if (T[i] == l) {
            right = min(right + 1, len);
        } else if (T[i] == r) {
            left = max(left - 1, 1LL);
        }
        if (S[i] == l) {
            left++;
        } else if (S[i] == r) {
            right--;
        }
        if (left > right) return false;
    }
    return left <= pos && pos <= right;
}

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

    cin >> H >> W >> N >> sx >> sy;
    cin >> S >> T;

    cout << (solve(W, sy, 0) && solve(H, sx, 1) ? "YES" : "NO") << endl;

    return 0;
}


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

using namespace std;

int dp[1000000];
int h[1000000];

int main(){
    int N, K;
    cin >> N >> K;
    cin >> h[1];
    for(int i = 2; i<=N; i++){
        cin >> h[i];
        dp[i] = INT_MAX;
        for(int j = i-1, cnt = 1; j>=1 && cnt <= K; j--, cnt++){
            dp[i] = min(dp[i], dp[j] + abs(h[i]-h[j]));
        }
    }
    cout << dp[N] << endl;
}


Measured memory_bytes: 4736
#!/usr/bin/env python3
_ = int(input())
a = list(map(int, input().split()))
result = float('inf')
for y in range(min(a), max(a) + 1):
    acc = 0
    for x in a:
        acc += (x - y) ** 2
    result = min(result, acc)
print(result)


Measured memory_bytes: 2940
#include<iostream> 
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath> 
#include<algorithm>
#define ll long long 
#define int long long
using namespace std;
const int maxn=500010, inf=1e9, mod=998244353;
int n, a, b, K, ans;
int fac[maxn], inv[maxn];

inline ll read()
{
	register ll f=1,k=0;register char c=getchar();
	while (c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();
	return k*f;
}

ll exgcd(ll a, ll b, ll &x, ll &y)
{
    if(!b) return x=1, y=0, a;
    int ans=exgcd(b, a%b, x, y);
    ll t=x; x=y; y=t-a/b*y;
    return ans;
}

inline int power(int a, int b)
{
	int ans=1;
	for(;b;b>>=1, a=1ll*a*a%mod)
	if(b&1) ans=1ll*ans*a%mod;
	return ans;
}

inline int C(int n, int m){return (n<m)?0:1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;}

signed main()
{
//	freopen("1.out", "w", stdout);
	ll n=read(),a=read(),b=read(),K=read();
//	read(n); read(a); read(b); read(K);
	fac[0]=1; for(int i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%mod;
	inv[n]=power(fac[n], mod-2); for(int i=n;i;i--) inv[i-1]=1ll*inv[i]*i%mod; 
	int x, y; int d=exgcd(a, b, x, y); 
//	printf("%lld %lld %lld\n", d, x, y);
	int tmp=K;	
	if(tmp%d) return puts("0"), 0;
	int tmpx=x*tmp/d, tmpy=y*tmp/d;
//		printf("tmp:%lld %lld %lld\n", tmpx, tmpy, tmp);
	int TMP=tmpx/(b/d);
	tmpx-=TMP*(b/d), tmpy+=TMP*(a/d);
//		printf("l:%lld tmpx:%lld tmpy:%lld\n", l, tmpx, tmpy);
	for(;tmpx<=n && tmpy>=0;)
//		printf("tmpx:%lld tmpy:%lld %lld\n", tmpx, tmpy, ans), 
	{
		if(tmpx>=0 && tmpy<=n)
		ans=(ans+C(n, tmpx)*C(n, tmpy))%mod;
		tmpx+=b/d, tmpy-=a/d;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 6528