akhauriyash/Code-Regression huggingface dataset:
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------

ld dp[3100][3100] = {0};

int main(void){
    int n;
    cin >> n;

    vector<ld> p(n + 1);

    for(int i = 1; i <= n; i++) cin >> p[i];

    dp[0][0] = 1.0;

    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= i; j++){
            dp[i][j] += dp[i - 1][j - 1] * p[i];
            dp[i][j] += dp[i - 1][j] * (1.0 - p[i]);
        }
    }

    ld ans = 0;

    for(int i = 0; i <= n; i++){
        if(i > n - i){
            ans += dp[n][i];
        }
    }

    cout << fixed << setprecision(10) << ans << endl;
}

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

const int N = 1e5;

int n;
int li[N+5];
int tmp[N+5];

set<int> ganjil;

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&li[i]);
		tmp[i] = li[i];
	}
	sort(tmp+1,tmp+n+1);
	for(int i=1;i<=n;i+=2) ganjil.insert(tmp[i]);
	int cnt = 0;
	for(int i=1;i<=n;i+=2){
		if(ganjil.find(li[i]) == ganjil.end()) cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}


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

int a[100005];

int main() {
  int n; cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + 1 + n);
  cout << (a[n/2+1] - a[n/2]) << endl;
}

Measured memory_bytes: 640
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque, BTreeSet, BTreeMap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

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

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let n = get!(usize);
    let aa = util::gets::<usize>();

    let mut ans = 1;
    let mut s = aa[0];
    let mut p = aa[0];

    for &a in &aa {
        if (a >= p && a >= s && p >= s) || (a <= p && a <= s && p <= s) {
            p = a;
        } else {
            ans += 1;
            s = a;
            p = a;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

int N, mina, maxa;

void No()
{
    cout << "No" << endl;
    exit(0);
}

void Yes()
{
    cout << "Yes" << endl;
    exit(0);
}

int main()
{
    cin >> N;
    mina = N;
    maxa = 1;
    map<int, int> a;
    int tmpa;
    REP(i, N)
    {
        cin >> tmpa;
        a[tmpa]++;
        mina = min(mina, tmpa);
        maxa = max(maxa, tmpa);
    }

    if (maxa - mina > 1) No();

    if (maxa == mina)
    {
        if (maxa > N / 2 && maxa != N - 1) No();
        else Yes();
    }

    int solo = a[mina];
    if (solo + 2 * (maxa - solo) > N || solo + 1 >= N || solo >= maxa) No();
    else Yes();
}


Measured memory_bytes: 4992
def solve():
    N, M = map(int, input().split())
    ac, wa= 0, 0

    mp = [0] * N
    for _ in range(M):
        p, s = input().split()
        p = int(p) - 1
        if s == "AC":
            if mp[p] != -1:
                ac += 1
                wa += mp[p]
                mp[p] = -1
        else:
            if mp[p] != -1:
                mp[p] += 1
    return ac, wa

print(*solve())

Measured memory_bytes: 3828
#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 repin(a,n) vector<ll> a(n);rep(i,n){cin>>a[i];}
#define in(a) ll a;cin>>a;
#define out(a) cout<<a<<endl;

int main()
{
    in(n);
    ll c = 0;
    rep(i,n){
        if(std::to_string(i+1).length()%2==1)
        c++;
    }
    out(c);
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;

int main()
{
   int a,b,k;
   scanf("%d%d%d",&a,&b,&k);
   int s1[105],s2[105],s[105];
   s1[1]=1;s2[1]=1;
   int j,l;
   j=2; l=2;
   for(int i=2;i<=a;i++)
   {
       if(a%i==0)s1[j++]=i;
   }
   for(int i=2;i<=b;i++)
   {
       if(b%i==0)s2[l++]=i;
   }

  int q=1;
  for(int i=1;i<j;i++)
  {
      for(int g=1;g<l;g++)
      {
          if(s1[i]==s2[g])
          {
              s[q++]=s1[i];break;
          }
      }
  }
  cout<<s[q-k]<<endl;


}


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

int main(){
	double r;
	cin >> r;

	cout << fixed << setprecision(10) << 2*r*3.1415928535 << endl;
	return 0;
}

Measured memory_bytes: 3756
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int d = sc.nextInt();
    int n = sc.nextInt();

    if (d == 0) {
      if (n < 100) {
        System.out.println(n);
      } else {
        System.out.println(101);
      }
    } else if (d == 1) {
      if (n < 100) {
        System.out.println(100 * n);
      } else {
        System.out.println(10100);
      }
    } else {
      if (n < 100) {
        System.out.println(10000 * n);
      } else {
        System.out.println(1010000);
      }
    }

  }
}

Measured memory_bytes: 35656
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<bitset>

using namespace std;
typedef bitset<60000> bi;

bool get(vector<int> v, int t) {
	bi x;
	x[30000] = 1;
	for (int i = 0; i < v.size(); i++)x = (x << v[i]) | (x >> v[i]);
	return x[30000 + t];
}

int main() {
	string s;
	cin >> s;
	s.push_back('T');
	int x, y;
	scanf("%d%d", &x, &y);
	vector<int> v1, v2;
	int mode = -1;
	int cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'T') {
			if (mode == -1)mode = 1;
			else if (mode == 0)v1.push_back(cnt), mode = 1;
			else v2.push_back(cnt), mode = 0;
			cnt = 0;
		} else {
			if (mode == -1)x--;
			else cnt++;
		}
	}
	if (get(v1, x) && get(v2, y))printf("Yes\n");
	else printf("No\n");
}

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

template <typename T>
void print(const T &v);

int main()
{
    string s, t;
    cin >> s >> t;
    int cnt = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] != t[i])
        {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}

Measured memory_bytes: 3916
using System;
using System.Linq;

namespace DPL1_E
{
    class Program
    {
        static void Main(string[] args)
        {
            var s1 = Console.ReadLine();
            var s2 = Console.ReadLine();
            var m = s1.Length;
            var n = s2.Length;
            var dp = new int[m + 1, n + 1];
            for (int i = 0; i <= m; i++) dp[i, 0] = i;
            for (int i = 0; i <= n; i++) dp[0, i] = i;                   

            for (int i = 1; i <= m; i++)
            {
                for (int j = 1; j <= n ; j++)
                {
                    if (s1[i - 1] == s2[j - 1])
                    {
                        dp[i, j] = dp[i - 1, j - 1];
                    }
                    else
                    {
                        dp[i, j] = new []{ dp[i - 1, j], dp[i, j - 1], dp[i - 1, j - 1]}.Min() + 1;
                    }
                }
            }

            Console.WriteLine(dp[m,n]);
        }
    }
}

Measured memory_bytes: 16836
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		long ans = 1;
		final long mod = 1000000007;
		for (int i = 0; i < n; i++) {
			a[i] = scan.nextInt();
		}
		Arrays.sort(a);
		if (n%2 != 0 && a[0] != 0) {
			System.out.println(0);
			return;
		} else {
			for (int i = n-1; i > 0; i-=2) {
				if (a[i] != a[i-1]) {
					System.out.println(0);
					return;
				}
			}
		}
		for (int i = 0; i < n/2; i++) {
			ans = ans*2%mod;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 50520
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <cstring>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

ll c[] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
set<ll> a;
map<ll,vector<char>> dp;

bool comp(vector<char> p, vector<char> q) {// <
    if (p.size() < q.size()) return true;
    if (p.size() > q.size()) return false;
    for (int i = 0; i < p.size(); i++) {
        if (p[i] < q[i]) return true;
        if (p[i] > q[i]) return false;
    }
    return false;
}

vector<char> solve(ll n) {
    if (n < 0) {
        vector<char> v;
        v.push_back(-1);
        return v;
    }
    if (n == 0) return vector<char>();
    if(dp.find(n) != dp.end()) return dp[n];
    vector<char> ret;
    for (auto e:a) {
        auto t = solve(n - c[e]);
        if (t.size() == 1 && t[0] < 0) continue;

        auto g = t;
        auto h = t;
        g.push_back(e);
        h.insert(h.begin(), e);
        if (comp(ret, g)) ret = g;
        if (comp(ret, h)) ret = h;
    }
    if (ret.size() == 0) {
        vector<char> v;
        v.push_back(-1);
        dp[n] = v;
    } else {
        dp[n] = ret;
    }
    return dp[n];
}

int main() {
    ll n, m, a2;
    cin >> n >> m;
    for (ll i = 0; i < m; i++) {
        cin >> a2;
        a.insert(a2);
    }
    auto r = solve(n);
    for (auto e:r) cout << (int) e;
    cout << endl;
}


Measured memory_bytes: 27264
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

struct BiCoef{
    vector<ll> F, R;

    BiCoef(int N){
        fac(N);
    }

    ll power(ll m, ll n){
        if(n == 0) return 1;
        if(n % 2 == 1) return m * power(m, n - 1) % INF;
        ll tmp = power(m, n/2);
        return tmp * tmp % INF;
    }

    void fac(int N){
        F.assign(N + 1, 1);
        R.assign(N + 1, 1);
        for(ll i = 1; i <= N; i++){
            F[i] = F[i - 1] * i % INF;
            R[i] = power(F[i], INF - 2);
        }
    }

    ll com(ll m, ll n){
        if(m < 0 || n < 0 || m < n) return 0;
        ll tmp = F[m];
        tmp *= R[n];
        tmp %= INF;
        tmp *= R[m - n];
        tmp %= INF;
        return tmp;
    }
};



int main(){
    int N, K;
    cin >> N >> K;
    
    BiCoef bc(100000);

    for(ll i = 1; i <= K; i++){
        cout << bc.com(K - 1, i - 1) * bc.com(N - K + 1, i) % INF << endl; 
    }
 
}

Measured memory_bytes: 1792
#include <cstdio> 
#include <cstdlib> 
#include <cmath> 
#include <cstring> 
#include <climits> 
#include <cfloat> 
#include <map> 
#include <utility> 
#include <set> 
#include <iostream> 
#include <memory> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <functional> 
#include <sstream> 
#include <complex> 
#include <stack> 
#include <queue> 
#include <numeric>
#include <cassert>

#define FOR(i, min, max) for (int i = (min); i < (max); ++i) 
#define FORE(i, min, max) for (int i = (min); i <= (max); ++i) 
#define REP(i, n) for (int i = 0; i < (n); ++i) 
#define REPV(vec, i) for (int i = 0; i < (int)(vec.size()); ++i) 
#define FOR_EACH(vec, it) for (typeof((vec).begin()) it = (vec).begin(); it != (vec).end(); ++it)

using namespace std; 
static const double EPS = 1e-12; 
typedef long long ll; 

int N, M, Q;
vector<int> a, b, c, d;
int ans = 0;

int calcScore(const vector<int> &A) {
    int ret = 0;
    REP(i, Q) {
        if (A[b[i]]-A[a[i]] == c[i])
            ret += d[i];
    }
    return ret;
}

void solve(vector<int> &A) {
    if (A.size() == N) {
        ans = max(ans, calcScore(A));
    }
    else {
        int lastA = (A.empty() ? 1 : A.back());
        FORE(na, lastA, M) {
            A.push_back(na);
            solve(A);
            A.pop_back();
        }
    }
}

int main(void)
{
    cin >> N >> M >> Q;
    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);
    REP(i, Q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--; b[i]--;
    }
    vector<int> A;
    solve(A);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
int nth_bit (int64 num, int n) {
	return (num >> n) & 1;
}
void solve() {
	int n; cin >> n;
	int64 k; cin >> k;
	vector<int64> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	int64 opt_same = 0, opt_less = -INFL;
	for (int d = 40; d >= 0; --d) {
		int64 D = 1LL << d;
		int num1 = 0;
		for (int i = 0; i < n; ++i) if (nth_bit(a[i], d)) num1++;
		int num0 = n - num1;

		opt_less += (D * max(num0, num1));

		if (nth_bit(k, d)) {
			opt_less = max(opt_less, opt_same + (D * num1));
			opt_same += (D * num0);
		} else {
			opt_same += (D * num1);
		}
	}
	cout << max(opt_less, opt_same) << endl;
	return;
}
int main() {
	solve();
	return 0;
}

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

const int INF = pow(2, 31) - 1;
#define ll long long
#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  REP(i, N) {
    cin >> a[i];
  }
  ll ans = 0;
  REP(i, N) {
    while(a[i] % 2 == 0) {
      a[i] /= 2;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  string s;
  cin >> s;
  i64 ans = 0, now = 0;
  for (i64 i = 0; i < 3; i++)
    if (s[i] == 'R')
    {
      now++;
      ans = max(ans, now);
    }
    else
      now = 0;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<vector>
#include<queue>
#include<string.h>
#define f first
#define s second
#define inf 100000001
using namespace std;

int w,h,d[20][20],ii,sum,map[20][20],a,dp[1<<12][20];
int x[4]={1,-1,0,0};
int y[4]={0,0,1,-1};
char c[20][20];
vector<pair<int,int> > v;
pair<int,int> u;
queue<pair<int,int> > q;

bool in(int a,int b)
{
  if(a<0 || b<0 || a>=h || b>=w)return false;
  return true;
}
/*
void solve()
{
  for(int S=0;S<1<<a;S++){
    fill(dp[S],dp[S]+a,inf);
  }
  dp[(1<<a)-1][0]=0;

  for(int S=(1<<a)-2;S>=0;S--){
    for(int v=0;v<a;v++){
      for(int u=0;u<a;u++){
	if(!(S>>u & 1)){
	  dp[S][v]=min(dp[S][v],dp[S|1<<u][u]+map[v][u]);
	}
      }
    }
  }
  int ans=inf;
  for(int i=1;i<a;i++)ans=min(ans,dp[0][i]);
  if(ans>=inf)cout<<-1<<endl;
  cout<<ans<<endl;
}
*/

int rec(int S,int v)
{
  if(dp[S][v]>=0){
    return dp[S][v];
  }
  if(S==(1<<a)-1 && v==0){
    return dp[S][v]=0;
  }
  int res=inf;
  for(int i=0;i<a;i++){
    if(!(S>>i&1)){
      res=min(res,rec(S|1<<i,i)+map[v][i]);
    }
  }
  return dp[S][v]=res;
}

int main()
{
  while(1){
    cin>>w>>h;
    if(w==0&&h==0)break;
    v.clear();
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin>>c[i][j];
	if(c[i][j]=='o')v.push_back(make_pair(i,j));
      }
    }
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(c[i][j]=='*')v.push_back(make_pair(i,j));
      }
    }
    for(int i=0;i<20;i++){
      for(int j=0;j<20;j++)map[i][j]=0;
    }
    for(int k=0;k<v.size();k++){
      q.push(make_pair(v[k].f,v[k].s));
      for(int i=0;i<20;i++){
	for(int j=0;j<20;j++)d[i][j]=inf;
      }
      d[v[k].f][v[k].s]=0;
      while(!q.empty()){
	u=q.front();q.pop();
	for(int i=0;i<4;i++){
	  int xx=u.f+x[i],yy=u.s+y[i];
	  if(in(xx,yy)){
	    if(d[xx][yy]!=inf)continue;
	    if(c[xx][yy]!='x'){
	      q.push(make_pair(xx,yy));
	      d[xx][yy]=d[u.f][u.s]+1;
	    }
	  }
	}
      }
      for(int i=0;i<v.size();i++)map[k][i]=d[v[i].f][v[i].s];
    }
    a=v.size();
    memset(dp,-1,sizeof(dp));
    int ans=inf;
    for(int i=1;i<a;i++){
      ans=min(ans,rec(0,i));
    }
    if(ans>=inf)cout<<-1<<endl;
    else cout<<ans<<endl;
      //solve();
  }
  return 0;
}

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

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

  bool ans = false;
  rep(i,25){
    rep(j,15){
      if ((n - 4*i - 7*j) == 0){
        ans = true;
      }
    }
  }

  if (ans == true){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;

void solve() {
    string s, t;
    cin >> s >> t;
    i64 n = s.size(), m = t.size();

    vector<vector<i64>> dp(n + 1, vector<i64>(m + 1));
    for (i64 i = 0; i < n; i++) {
        for (i64 j = 0; j < m; j++) {
            dp[i + 1][j + 1] = s[i] == t[j] ? dp[i][j] + 1 : max(dp[i + 1][j], dp[i][j + 1]);
        }
    }

    string ans;
    i64 i = n, j = m;
    while (i > 0 && j > 0) {
        if (dp[i][j] == dp[i - 1][j]) {
            i--;
        } else if (dp[i][j] == dp[i][j - 1]) {
            j--;
        } else {
            i--, j--;
            ans.push_back(s[i]);
        }
    }
    reverse(all(ans));
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 73648
#include <iostream>
#include <numeric>
#include <string>
#include <algorithm>
#include <vector>
#include <cstdlib>
 
#define repd(i,a,b); for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define ll long long int
 
 
using namespace std;
int main() {
  int n; cin >> n;
  int a[n]; 
  rep(i,n){
    cin >> a[i];
  }
  
  int mx = 0; int mn = 1000000001;
  rep(j,n){
    mx = max(mx, a[j]);
    mn = min(mn, a[j]);
  }
  
  cout << mx-mn ;
 
 return 0;
}

Measured memory_bytes: 256
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
from fractions import gcd

NN = 202020
MOD = 10**9+7
INF = float("inf")

n, m = map(int, input().split())
Edge = [list(map(int, input().split())) for i in range(m)]
graph = [set() for _ in range(n)]

for e in Edge:
    graph[e[0]-1].add(e[1]-1)
    graph[e[1]-1].add(e[0]-1)


def next_node(idx, A):
    if idx == n-1:
        return True
    if A[idx+1] in graph[A[idx]]:
        return next_node(idx+1, A)
    else:
        return False


count = 0
for li in itertools.permutations([i+1 for i in range(n-1)]):
    count += next_node(0, [0]+list(li))
    # if next_node(0, [0]+list(li)):
    #     print([0]+list(li))

print(count)


Measured memory_bytes: 71020
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<ll>
#define vvint vector<vint>
#define P pair<ll,ll>
#define INT_MAX 2147483647
#define MOD 998244353
#define PI 3.14159265358979323846
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;

#define MAX 1000000000000

int main(void) {
	int n; cin >> n;
	int ans = 0;
	for (int i = 1; i <= n-1; i++) {
		ans += n / i;
		if (n%i == 0) {
			ans--;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <string.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;


int main()
{
int ans=1000000;
//整数値の入力
int n,a,b,c;
cin >> n>> a>> b>> c;
int table[n]={};


for (int i = 0; i < n; ++i) {
    cin >> table[i];
}
for (int i1 = 0; i1 < 4; ++i1) {
for (int i2 = 0; i2 < 4; ++i2) {
for (int i3 = 0; i3 < 4; ++i3) {
for (int i4 = 0; i4 < 4; ++i4) {
for (int i5 = 0; i5 < 4; ++i5) {
for (int i6 = 0; i6 < 4; ++i6) {
for (int i7 = 0; i7 < 4; ++i7) {
for (int i8 = 0; i8 < 4; ++i8) {
//int i1=2,i2=1,i3=1,i4=1,i5=0,i6,i8,i7;
int take[4]={};
int kaisu[4]={};
if(n>0){take[i1]+=table[0];kaisu[i1]++;}
if(n>1){take[i2]+=table[1];kaisu[i2]++;}
if(n>2){take[i3]+=table[2];kaisu[i3]++;}
if(n>3){take[i4]+=table[3];kaisu[i4]++;}
if(n>4){take[i5]+=table[4];kaisu[i5]++;}
if(n>5){take[i6]+=table[5];kaisu[i6]++;}
if(n>6){take[i7]+=table[6];kaisu[i7]++;}
if(n>7){take[i8]+=table[7];kaisu[i8]++;}

if(kaisu[0]*kaisu[1]*kaisu[2]!=0){
   //sort(table,table+3);
   int temp;
   temp=(kaisu[0]+kaisu[1]+kaisu[2]-3)*10+abs(take[0]-c)+abs(take[1]-b)+abs(take[2]-a);
   if(temp<ans){ans=temp;}
  // cout << a<<b<<c<< " " << kaisu[0]<<kaisu[1]<<kaisu[2]<<" "<<take[0]<<take[1]<<take[2]<<endl;
}


}}}}}}}}
//回答
cout << ans << endl;
return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
using namespace std;

int main() {
ll N;cin >> N;
map<ll, ll> A;

rep(i, 0, N){

ll a;cin >> a;

if(A[a] == 0)A[a]++;

else A[a]--;

}

ll Ans = 0;

for(auto x : A){

if(x.second == 1)Ans++;

}

cout << Ans;
}


Measured memory_bytes: 9788
/* 
 * Project: AtCoder Beginners Contest 161 C - Replacing Integer
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/04/04
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

long n, k;

void solve() {

    long diff = 0;
    diff = n % k;

    while(1) {
        if (diff > n) {
            cout << n << endl;
            return;
        } else {
            n = diff;
        }
        diff = abs(n - k);
    }

}

int main() {

    cin >> n >> k;

    solve();

}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main() {
	int n, flag = 0, a[52][52] = {0}, b, count = 0, h, w, p = 0;
	cin >> h >> w ;
	char s[51][51];
	for (int i = 0; i < h; i++) {
		
		for (int j = 0; j < w; j++) {
			cin >> s[i][j];
			if(s[i][j] == '#') a[i+1][j+1] = 1;
		}
	}
	
	for (int i = 1; i <= h; i++) {

		for (int j = 1; j <= w; j++) {
			if (a[i][j] == 1) {
				cout << '#';
				continue;
			}
			cout << a[i - 1][j] + a[i + 1][j] + a[i - 1][j + 1] + a[i - 1][j - 1] + a[i + 1][j - 1] + a[i + 1][j + 1] + a[i][j + 1] + a[i][j - 1];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int dpt[100001];
vector<int> h;
int frog(int i){
	if(i<=1)
		return 0;
	if(dpt[i]!=-1){
			return dpt[i];
		}
	if(i>2)
		return dpt[i]=min(frog(i-1)+abs(h[i]-h[i-1]),frog(i-2)+abs(h[i]-h[i-2]));
	if(i==2){
		return dpt[i]=frog(i-1)+abs(h[i]-h[i-1]);
	}
}

int main(){
	cin>>n;
	h.push_back(0);
	int k;
	for(int i=0;i<n;i++){
		cin>>k;
		h.push_back(k);
	}
	for(int i=0;i<=100001;i++)
		dpt[i]=-1;
	cout<<frog(n);
}

Measured memory_bytes: 3448
import sys
def f0070(A,n,s):
  if n==1: return (s in A)
  c=0
  A=sorted(A)
  A1=A[:n][::-1]
  A2=A[-n:]
  N=range(n)
  def f(A):
    return sum([(i+1)*A[i] for i in N])
  if f(A1)<=s<=f(A2):
    for i in range(len(A)):
      b=s-A[i]*n
      c+=f0070(A[:i]+A[i+1:],n-1,b)
  return c
for a in sys.stdin:
  n,s=map(int,a.split())
  print f0070(range(10),n,s)

Measured memory_bytes: 4244
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt();
        int n = sc.nextInt();
        int array[] = new int[w];
        for (int i = 0; i < w; i++) array[i] = i+1;
        for (int i = 0; i < n; i++){
            String str = sc.next();
            String ab[] = str.split(",");
            int a = Integer.parseInt(ab[0]) - 1;
            int b = Integer.parseInt(ab[1]) - 1;
            int tmp = array[a];
            array[a] = array[b];
            array[b] = tmp;
        }
        for (int i = 0; i < w; i++){
            System.out.println(array[i]);
        }
    }
}

Measured memory_bytes: 26104
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {
	string a;
	cin >> a;
	int count = 0;
	rep(i, 3) {
		if (a[i] == '1') {
			count++;
		}
	}
	cout << count << endl;
}


Measured memory_bytes: 3584
#pragma region Macros
#include <bits/stdc++.h>
#define int long long
using ll = long long;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b+a); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(a) (a).begin(), (a).end()
using namespace std;
using P = pair<int, int>;
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#pragma endregion

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

  int n;
  cin >> n;

  vector<int> a(100100); // 1e5
  a.resize(n);
  rep(i,n) {
    if (i == 0) continue;
    int aa;
    cin >> aa;
    a[aa-1]++;
  }

  rep(i,n) {
    cout << a[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 5576
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <bits/stdc++.h>
using namespace std;

int main(){
    int H,W;
    char S[2000][2000];
    int H1[2000][2000]={}, V1[2000][2000]={};
    int H2[2000][2000]={}, V2[2000][2000]={};
    //int M[2000][2000]={};
    cin >> H >> W;
    char tmp;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> tmp;
            if(tmp == '.'){
                S[i][j] = 1;
            }else{
                S[i][j] = 0;
            }
        }
    }
    int cnt = 0;
    
    for(int i=0;i<H;i++){
        int pre = 0;
        for(int j=0;j<W;j++){
            if(S[i][j] == 1){
                H1[i][j] = pre + 1;
                pre = H1[i][j];
            }else{
                pre = 0;
            }
            
        }
    }
    for(int i=0;i<H;i++){
        int pre = 0;
        for(int j=0;j<W;j++){
            if(S[H-1-i][W-1-j] == 1){
                H2[H-1-i][W-1-j] = pre + 1;
                pre = H2[H-1-i][W-1-j];
            }else{
                pre = 0;
            }
            
        }
    }
    for(int j=0;j<W;j++){
        int pre = 0;
        for(int i=0;i<H;i++){
            if(S[i][j] == 1){
                V1[i][j] = pre + 1;
                pre = V1[i][j];
            }else{
                pre = 0;
            }
            
        }
    }
    for(int j=0;j<W;j++){
        int pre = 0;
        for(int i=0;i<H;i++){
            if(S[H-1-i][W-1-j] == 1){
                V2[H-1-i][W-1-j] = pre + 1;
                pre = V2[H-1-i][W-1-j];
            }else{
                pre = 0;
            }
            
        }
    }
    int M=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            M=max(M,  H1[i][j] + H2[i][j] + V1[i][j] + V2[i][j] - 3);           
        }
    }
    cout << M << endl;
}


Measured memory_bytes: 66688
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

int main(){
  int n, x; cin >> n >> x;
  
  int mi = 1001001001;
  rep(i, n){
    int m; cin >> m;
    chmin(mi, m);
    x -= m;
  }

  cout << n + x/mi << endl;

  return 0;
}


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

int main(){
  int x; cin>>x;
  int sum=0;
  rep(i,x+1){
    sum+=i;
    if(sum>=x){
      cout<<i<<endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  int n;
  cin>>s;
  n=s.size();
  int c=0;
  for(int i=0;i<n/2;i++)
  {
    if(s[i]!=s[n-i-1])
      c++;
  }
  cout<<c<<"\n";
  return 0;
}

Measured memory_bytes: 256
h, n = gets.to_s.split.map{|t|t.to_i}
m = Array.new(n){ gets.split.map{|t|t.to_i} }.sort_by{|(a,b)| 1.0 * b / a }

inf = h * (10**4)

dp = [ inf ] * ( h + 1 + 10**4 )
dp[0] = 0

m.each do |(a, b)|
  0.upto(h).each do |i|
    dp[i+a] = dp[i] + b if dp[i] < inf && dp[i+a] > dp[i] + b
  end
  break if dp[h] < inf
end
# p dp
puts dp[h .. -1].min

Measured memory_bytes: 2040
def ok(n, X, Y, mask):
    for i in range(n):
        for x, y in zip(X[i], Y[i]):
            z = mask & (2**(x-1))
            z = int(z > 0)
            if mask & (2**i):
                if z != y:
                    return False
    return True

def solve(n, X, Y):
    best = 0
    for mask in range(2**n):
        if ok(n, X, Y, mask):
            cnt = 0
            for i in range(n):
                if mask & (2**i):
                    cnt += 1
            best = max(best, cnt)
    return best

n = int(input())
X, Y = [], []
for i in range(n):
    a = int(input())
    x = [0] * a
    y = [0] * a
    for j in range(a):
        x[j], y[j] = map(int, input().split())
    X.append(x)
    Y.append(y)
print(solve(n, X, Y))

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef pair<int,int>P;
#define INF 1000000000
 
struct edge { 
	int from, to,cap,rev; 
	edge (int from, int to, int cap, int rev){
		this->from=from; this->to=to; this->cap=cap; this->rev=rev;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;



int main(){
	string in,out;
	cin >> in;
	FORI(0, in.size()) {
		if (in[i] != 'B')
			out.push_back(in[i]);
		else if(out.size()!=0)
			out.pop_back();
		
	}
	cout << out << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main(int argc, char const *argv[]) {
    long N, M;
    scanf("%ld%ld", &N, &M);
    if (N >= 2 && M >= 2) {
        printf("%ld\n", (N - 2)*(M - 2));
        return 0;
    }
    if (N == 1 && M == 1) {
        printf("1\n");
        return 0;
    }
    long c = ((N == 1) ? M : N);
    printf("%ld\n", c - 2);
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    int count=1;
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        if(a%2==0) count*=2;
    }
    cout << pow(3,N)-count << endl;
    return 0;
}

Measured memory_bytes: 256
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 09/01/20 21:30:49
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  string s,t; cin>>s>>t;
  int ans = t.size();
  for (int i = 0; i < s.size() - t.size() + 1; i++) {
    int diff = 0;
    for (int j = 0; j < t.size(); j++)
      if (s[i + j] != t[j])
        diff++;
    ans = min(ans, diff);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3608
n = int(raw_input())
a = map(int, raw_input().split())

def print_list(list):
	for i in range(len(list)-1):
		print(list[i]),
	print(list[len(list)-1])

#print("")
print_list(a)
for i in range(1,n):
	v = a[i]
	j = i - 1
	while j >= 0 and a[j] > v:
		a[j+1] = a[j]
		j -= 1
	a[j+1] = v
	print_list(a)

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

int main() {
  int N;
  int K;
  cin >> N >> K;
  
     int x = 1;
  
  for (int i = 0; i < N; i++){
  
    if (x*2 > x+K){
     x = x+K; 
    }
    
    else{
     x = x*2;
    }  
  }
  
  cout << x << endl;
}

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

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)

int find_pass(string s, string pass){
    int flag = 0;

    REP(i,s.length()){
        if(flag ==0 && s[i]==pass[0]){
            flag++;
        }else if(flag ==1 && s[i]==pass[1]){
            flag++;
        }else if(flag == 2 && s[i]==pass[2]){
            flag++;
            return 1;
        }
    }
    return 0;
}

int main() {
    int n;
    string s;
    cin>>n>>s;

    int ans =0;
    string pass;
    FOR(i,0,999){
        if(i<10){
            pass = "00"+ to_string(i);
        }
        else if(i<100){
            pass = "0"+ to_string(i);
        }
        else{
            pass = to_string(i);
        }

        if(find_pass(s,pass)){
            ans++;
        }

    }

    ANS(ans);



    return 0;
}


Measured memory_bytes: 384
from collections import deque
flag = 1
s = deque(input())
q = int(input())
for i in range(q):
         z = list(map(str,input().split()))
         if z[0] == "1":
                  flag = flag*(-1)
         else:
                  if (flag == 1 and z[1] == "1")  or (flag == (-1) and z[1] == "2"):
                           s.appendleft(z[2])
                  else:
                           s.append(z[2])
if flag == (-1):
         s.reverse()
ans = "".join(s)
print(ans)



Measured memory_bytes: 75608
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <initializer_list>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, a, n) for (int i = (a); i < (int)(n); i++)
#define repc(i, a, n) for (int i = (a); i <= (int)(n); i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init)                                              \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
#define DBG(str) cerr << (str) << endl;
int main() {
  int n;
  cin >> n;
  vector<int> t(n);
  rep(i, 0, n) cin >> t[i];
  int m;
  cin >> m;
  vector<int> p(m), x(m);
  rep(i, 0, m) {
    cin >> p[i] >> x[i];
    p[i]--;
  }

  ll sum = 0;
  rep(i, 0, n) { sum += t[i]; }
  rep(i, 0, m) { cout << sum - t[p[i]] + x[i] << endl; }

  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> w(n);
  int sum = 0;
  for(int i = 0; i < n;i++){
    cin >> w.at(i);
    sum += w.at(i);
  }
  int mini = sum;
  int t_sum = 0;
for(int i = 0;i<n;++i){
  cin >> w.at(i);
  t_sum += w.at(i);
  mini = min(mini, abs(t_sum-(sum-t_sum)));
}
  cout << mini << endl;

}

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

int main(){
    int n;
    cin >> n;
    vector<int> prob(n, 0);
    int sum = 0;
    rep(i, n){
        cin >> prob[i];
        sum += prob[i];
    }
    sort(prob.begin(), prob.end());
    int ans = prob[n/2] - prob[n/2 - 1];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
//#include<math.h>

using namespace std;
#define int long long
/*                      */    //#undef int
#define INF 1000000009
#define INFL 1000000000000000018ll
#define mod 1000000007ll
#define pb push_back
#define fi first
#define se second
#define mk(a, b) make_pair(a, b)
typedef pair<int, int> PA;
typedef priority_queue<int> PQ;
typedef priority_queue<PA, vector<PA>, greater<PA> >PQG;

int N, K, a[5020], sum, ans;
bool dp[5020];

signed main()
{
    cin >> N >> K;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        sum += a[i];
    }
    sort(a, a + N);
    dp[0] = true;
    for(int i = N - 1; i >= 0; i--){
        bool flag = false;
        for(int j = 0; j < K; j++){
            if(dp[j] && j + sum >= K){
                flag = true;
            }
        }
        if(!flag){
            ans++;
        }
        sum -= a[i];
        for(int j = K - 1; j >= a[i]; j--){
            dp[j] |= dp[j - a[i]];
        }
    }
    cout << ans << endl;

    return 0;
}
/*


*/


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

int cnt[4005][4005];
int n, k, ans;

int main()
{
	scanf("%d%d", &n, &k);
	for (int i = 0;i < n;i++)
	{
		int x, y; char c; scanf("%d%d %c", &x, &y, &c);
		if (c == 'B') y += k;
		x %= (2*k); y %= (2*k);
		cnt[x][y]++;
	}
	for (int i = 0;i < 2*k;i++) for (int j = 0;j < 2*k;j++) cnt[i+2*k][j] = cnt[i][j+2*k] = cnt[i+2*k][j+2*k] = cnt[i][j];
	for (int i = 0;i < 4*k;i++) for (int j = 0;j < 4*k;j++) cnt[i][j] += (i?cnt[i-1][j]:0)+(j?cnt[i][j-1]:0)-(i&&j?cnt[i-1][j-1]:0);
	for (int i = 0;i < 2*k;i++) for (int j = 0;j < 2*k;j++) ans = max(ans, cnt[i+2*k][j+2*k]-cnt[i+k][j+2*k]-cnt[i+2*k][j+k]+cnt[i+k][j+k]+cnt[i+k][j+k]-cnt[i][j+k]-cnt[i+k][j]+cnt[i][j]);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 62848
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for(int i = x; i < (int)(n); ++i)

ll dp[200001], of, ls[800001], rs[800001];
int n, q, x[200001];

void bldl(int l = 1, int r = n + 1, int id = 1){
    if (l + 1 == r) { ls[id] = dp[l] + n - l; return; }
    int m = l + r >> 1, a = id << 1, b = id << 1 | 1;
    bldl(l, m, a);
    bldl(m, r, b);
    ls[id] = min(ls[a], ls[b]);
}

void bldr(int l = 1, int r = n + 1, int id = 1){
    if (l + 1 == r) { rs[id] = dp[l] + l; return; }
    int m = l + r >> 1, a = id << 1, b = id << 1 | 1;
    bldr(l, m, a);
    bldr(m, r, b);
    rs[id] = min(rs[a], rs[b]);
}

ll gt(ll s[], int x, int y, int l = 1, int r = n + 1, int id = 1){
    if (x >= r || y <= l)return 1e18;
    if (l >= x && r <= y)return s[id];
    int m = l + r >> 1, a = id << 1, b = id << 1 | 1;
    return min(gt(s, x, y, l, m, a), gt(s, x, y, m, r, b));
}

void rm(ll s[], int i, ll v, int l = 1, int r = n + 1, int id = 1){
    if (l + 1 == r) { s[id] = v; return; }
    int m = l + r >> 1, a = id << 1, b = id << 1 | 1;
    if (i < m)rm(s, i, v, l, m, a);
    else rm(s, i, v, m, r, b);
    s[id] = min(s[a], s[b]);
}

int main(){
    int a, b;
    scanf("%d%d%d%d", &n, &q, &a, &b);
    f(i, 1, n + 1)dp[i] = 1e18;
    dp[a] = 0ll;
    bldl();
    bldr();
    x[0] = b;
    f(i, 1, q + 1){
        scanf("%d", x + i);
        int d = abs(x[i] - x[i - 1]);
        of += d;
        ll mn = gt(rs, x[i], n + 1) - x[i];
        mn = min(mn, gt(ls, 1, x[i] + 1) - n + x[i]);
        dp[x[i - 1]] = min(dp[x[i - 1]], mn - d);
        rm(ls, x[i - 1], dp[x[i - 1]] + n - x[i - 1]);
        rm(rs, x[i - 1], dp[x[i - 1]] + x[i - 1]);
    }
    ll an = 1e18;
    f(i, 1, n + 1)an = min(an, dp[i]);
    printf("%lld\n", an + of);
}

Measured memory_bytes: 15104
#include <stdio.h>
int main()
{
	int n;

	scanf("%d", &n);

	int A[10000];
	int i, lop, cnt = 0;

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

	do{
		lop = 0;
		for(i = 0; i < n; i++){
			if(A[i] % 2 == 0){
				A[i] /= 2;
				cnt++;
				lop = 1;
			}
			else{
				A[i] *= 3;
			}
		}
	}while(lop);

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

	return 0;
}


Measured memory_bytes: 256
s = input()
n = len(s)
b_num = 0
prev_score = 0

for i in range(n):
    if s[i] == "B":
        prev_score += i
        b_num += 1

nxt_score = n * (n - 1) // 2 - (n - b_num) * (n - 1 - b_num) // 2
print(nxt_score - prev_score)



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

typedef long double ld;									// XD
#define int long long
#define PB push_back
#define all(x) (x).begin(),(x).end()
#define ii pair <int,int>
#define mii map <int,int>
#define vi vector<int>
#define vii vector< ii >
#define F first
#define S second
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a; i>=b; --i)
#define sz(x) (int)((x).size())
#define mem(a,x) memset(a,x,sizeof(a))
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
inline void io(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int mod = 1e9+7;
const int inf = 1e18;
const int maxn = 2e5+5;

void solve(){
	int a, b, c, d; cin>>a>>b>>c>>d;
	int ans;
	ans = max({a*c, a*d, b*c, b*d});
	cout<<ans;
}
signed main() 
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); //io();
    //cout<<setprecision(16);
    int tc=1; //cin>>tc; 
    while(tc--){
        solve();cout<<'\n';
    }
    return 0;
}



Measured memory_bytes: 3648
#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
  int n,tmp,ans;
  int a[5000];

  while(scanf("%d",&n) && n){
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    
    ans = a[0];
    for(int i=0;i<n;i++)
      for(int j=i;j<n;j++){
	if(i==j)tmp = a[i];
	else tmp += a[j];
	ans = max(tmp,ans);
      }
    printf("%d\n",ans);
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <bitset>

using namespace std;

int main() {
    long long int n;
    cin >> n;
    vector<long long int> odd;
    vector<long long int> even;
    int p = 0;
    for (long long int i = 1; i <= 100000000000; i = i * 2) {
        if(p == 1)
        {
            even.push_back(i);
        }else{
            odd.push_back(i);
        }
        p = (p + 1) % 2;
    }
    ///半分全列挙
    map<long long int, int> oddmap;
    map<long long int, int> evenmap;
    for (unsigned long long int i = 0; i < pow(2, odd.size()); ++i) {
        unsigned long long int check = 1;
        long long int count = 0;
        int index = 0;
        for (;check <= i; check = check << 1) {
            if(i & check)
            {
                ///bitが立っている
                count += odd[index];
            }
            index++;
        }
        if(oddmap.count(count) == 0)
        {
            oddmap[count] = 1;
        }
    }
    for (unsigned long long int i = 0; i < pow(2, even.size()); ++i) {
        unsigned long long int check = 1;
        long long int count = 0;
        int index = 0;
        for (;check <= i; check = check << 1) {
            if(i & check)
            {
                ///bitが立っている
                count += even[index];
            }
            index++;
        }
        if(evenmap.count(count) == 0)
        {
            evenmap[count] = 1;
        }
    }
    long long int plus = 0, minus = 0;
    for (auto o : oddmap) {
        long long int nest = o.first - n;
        if(evenmap.count(nest) > 0)
        {
            plus = o.first;
            minus = nest;
        }
    }
    unsigned long long int result = plus + minus;
    string str = "";
    for (unsigned long long int check = 1; check <= result; check = check << 1) {
        if(check & result)
        {
            str.push_back('1');
        }else{
            str.push_back('0');
        }
    }
    reverse(str.begin(), str.end());
    if(str == "")
    {
        cout << "0" << endl;
    }else{
        cout << str << endl;
    }
    return 0;
}


Measured memory_bytes: 49536