akhauriyash/Code-Regression huggingface dataset:
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

void Pr(bool f){
  cout << (f ? "Yes" : "No") << endl;
  exit(0);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll h, n;
  cin >> h >> n;
  vll a(n);
  rep(i, n){
    cin >> a[i];
  }
  ll s = accumulate(ALL(a), 0ll);
  Pr(s >= h);
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define int long long
#define all(c) (c).begin(), (c).end()
#define cpresent(c,x) ((c).find(x) != (c).end()) 
#define vpresent(c,x) (find(all(c),x) != (c).end())
#define endl '\n'
#ifdef LOCAL
#include "/home/iggaboi/Desktop/CP/debug.h"
#else
#define debug(x...)
#endif
using namespace std;

int n;

int prods(int n){
    set<pair<int, int>> fac;
    for(int i = 1; i*i <= n; ++i){
        if(n%i == 0){
            fac.insert({i, n/i});
            // cout << i << " " << n/i << endl;
        }
    }
    int ret = -1;
    int out = 69;
    for(auto& x : fac){
        string a = to_string(x.first);
        string b = to_string(x.second);
        ret = max((int)a.length(), (int)b.length());
        out = min(out, ret);
    }
    return out;
}

void solve(){
    cin >> n;
    cout << prods(n) << endl;
}

int32_t main(){
	ios_base::sync_with_stdio(false),cin.tie(nullptr);
	// int t; cin >> t;
	// while(t--)
		solve();
	return 0;
}


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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            ans += a.at(i);
        } else {
            ans -= a.at(i);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxm=4005,maxv=maxm/2,maxn=200005,md=1000000007;
int n,ans;
int a[maxn],b[maxn];
int f[maxm][maxm],C[maxm][maxm];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)cin>>a[i]>>b[i];
	for (int i=1;i<=n;i++)f[maxv-a[i]][maxv-b[i]]++;
	for (int i=1;i<maxm;i++)C[i][0]=C[0][i]=1;
	for (int i=1;i<maxm;i++)
		for (int j=1;j<maxm;j++){
			f[i][j]=(f[i-1][j]+f[i][j-1]+f[i][j])%md;
			C[i][j]=(C[i-1][j]+C[i][j-1])%md;
		}
	for (int i=1;i<=n;i++)ans=(ans+f[maxv+a[i]][maxv+b[i]])%md;
	for (int i=1;i<=n;i++)ans=(ans+md-C[a[i]*2][b[i]*2])%md;
	ans=1LL*ans*(md+1)/2%md;
	printf("%d",ans);
	return 0;
}

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

int main(){
  int k, q;
  cin >> k >> q;
  vector<int> d(k);
  for(int i = 0; i < k; ++i) cin >> d[i];

  while(q--){
    int n, x, m;
    cin >> n >> x >> m;
    x %= m;
    --n;
    long long t = 0, z = 0;
    long long ans = n;
    vector<int> d_ = d;
    for(int i = 0; i < k; ++i){
      d_[i] %= m;
      t += d_[i];
      if(!d_[i]) ++z;
    }
    t *= n/k;
    z *= n/k;
    for(int i = 0; i < n%k; ++i){
      t += d_[i];
      if(!d_[i]) ++z;
    }
    t += x;
    ans -= t/m;
    ans -= z;
    // cerr << t << " " << t/m << endl;
    cout << ans << endl;
  }
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<map>

using namespace std;

int main(){

    int N;
    cin >> N;

    vector<string> s(N);
    int i, j;
    for(i=0; i<N; i++) cin >> s.at(i);

    vector<int> sum(N);

    for(i=0; i<N; i++)  sort(s.at(i).begin(), s.at(i).end());

/*
    map<string, int> mp;
    for(i=0; i<N; i++){
        if(mp.find(s.at(i)) == mp.end()) mp[s.at(i)] = 1;
        else mp[s.at(i)]++;
    }

    uint64_t ans = 0;
    for(map<string,int>::iterator j=mp.begin(); j != mp.end(); j++){
        if(j->second > 1) ans += ((j->second) * (j->second - 1)) / 2;
    }
*/
    sort(s.begin(), s.end());

    uint64_t ans = 0;
    uint64_t c = 0;
    for(i=0; i<N-1; i++){
        if(s.at(i) == s.at(i+1)){
            c++;
        }
        else{
            ans += (c * (c + 1)) / 2;
            c = 0;
        }
    }

    ans += (c * (c + 1)) / 2;

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 2944
#include<iostream>
#include<vector>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<iomanip>
#define BUG puts("no bug")
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define ll long long
#define ull unsigned long long
#define REP(a,b,c) for(int a=b;a<=c;a++)
#define PER(a,b,c) for(int a=b;a>=c;a--)
#define lb(a) (a&(-a))
#define pp (p<<1)
#define ppp (p<<1|1)
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
using namespace std;
const int MAXN=1e6+5;
int n,m,t;
int v[MAXN];
int main(){
    cin>>n>>m;
    REP(i,1,n)v[i]=-1;
    int flag=1;
    REP(i,1,m){
        int a,b;
        cin>>a>>b;
        if(v[a]==-1||v[a]==b)v[a]=b;
        else flag=0;
    }
    if(n==1&&(v[1]==0||v[1]==-1)){
        cout<<0;
        return 0;
    }

    int zero=1;
    REP(i,1,n){
        if(zero&&v[i]==0)flag=0;
        else if(zero&&v[i]==-1)v[i]=1,zero=0;
        else if(zero)zero=0;

        if(!zero&&v[i]==-1)v[i]=0;
    }
    if(flag){
        REP(i,1,n)cout<<v[i];
    }
    else cout<<-1;
}

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

int main() {
	int	N;
 	cin >> N;
  	map<string,int> mp;
  	for (int i=0;i<N;i++) {
    	string s;
      	cin >> s;
      	mp[s]++;
    }
  	// debug
  	//for (auto m : mp) cout << m.first << " " << m.second << endl;
  
  	int	mx = 0;
  	for (auto m : mp) mx = max(mx, m.second);
  	for (auto m : mp) {
    	if (m.second != mx) continue;
      	cout << m.first << endl;
    }
  	// mapは辞書順（厳密には「狭義の逆順序」（？）らしい）で格納するみたいなので、辞書順に並べ替える必要はないみたい！
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;

ll power(const ll a, const ll n, const ll mod)
{
    if (n == 0) {
        return 1;
    } else if (n % 2 == 1) {
        return power(a, n - 1, mod) * a % mod;
    } else {
        const ll aa = power(a, n / 2, mod);
        return aa * aa % mod;
    }
}

class ModCombination
{
public:
    ModCombination(const int n, const ll mod) : size{n + 1}, mod{mod}, fact(n + 1, 1), inv(n + 1, 1), inv_fact(n + 1, 1)  // mod should be prime
    {
        for (ll i = 2; i <= n; i++) {
            fact[i] = (fact[i - 1] * i) % mod;
            inv[i] = ((mod - (mod / i)) * inv[mod % i]) % mod;
            inv_fact[i] = (inv_fact[i - 1] * inv[i]) % mod;
        }
    }
    ll combination(const int n, const int k) const
    {
        assert(n < size);
        assert(k <= n);
        return (((fact[n] * inv_fact[k]) % mod) * inv_fact[n - k]) % mod;
    }

private:
    const int size;
    const ll mod;
    vector<ll> fact;
    vector<ll> inv;
    vector<ll> inv_fact;
};
int main()
{
    int N;
    cin >> N;
    ll M;
    cin >> M;

    vector<ll> pp(N + 1);
    for (int i = 0; i <= N; i++) { pp[i] = power(2, power(2, i, M - 1), M); }
    ModCombination mod(N + 1, M);
    vector<vector<ll>> b(N + 1, vector<ll>(N + 1, 0));
    b[0][0] = 1;
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= i; j++) { b[i][j] = (b[i - 1][j - 1] + j * b[i - 1][j] % M) % M; }
    }
    vector<ll> weight(N + 1, 0);
    for (int k = 1; k <= N; k++) {
        const ll p = power(2, N - k, M);
        const ll pinv = power(2, M - 1 - N + k, M);
        const ll PP = pp[N - k] * mod.combination(N, k) % M;
        for (ll x = 0, q = 1; x <= k; x++, (q *= p) %= M) { (weight[k] += (b[k][x] * q % M) * (1 + x * pinv % M) % M) %= M; }
        (weight[k] *= PP) %= M;
    }
    ll minus = 0;
    for (int i = 1; i <= N; i++) { (minus += (i % 2 == 0 ? weight[i] : M - weight[i])) %= M; }
    cout << (pp[N] + minus) % M << endl;

    return 0;
}


Measured memory_bytes: 70784
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
int field[5][5];

bool isfill (int fromy, int fromx, int toy, int tox )
{
	for (int i = fromy; i <= toy; i++ ){
		for (int j = fromx; j <= tox; j++ ){
			if (field[i][j] ) continue;
			else return false;
		} // end for
	} // end for

	return true;
} 

int main()
{
//	cut here before submit 
//	freopen ("testcase.GRF", "r", stdin );
	int n;
//	scanf ("%d", &n );
	string s = "";
	getline (cin, s );
	stringstream ssn (s );
	ssn >> n;
	rep (cnt, n ){
		memset (field, 0, sizeof (field ) );		
		rep (i, 6 ){
			string str = "";
			getline (cin, str );
			if (str.empty() ) continue;
			stringstream ss (str );
			rep (j, 5 ){
				ss >> field[i][j];
			} // end rep
		} // end rep
		int res = 0;
		rep (i, 5 ){
			 rep (j, 5 ) {
				if (field[i][j] == 1 ){
					for (int k = i; k < 5; k++ ) for (int l = j; l < 5; l++ )
						if (isfill (i,j,k,l ) ){
							res = max (res, (k-i+1)*(l-j+1) );
					} // end for
				} // end if
			} // end rep
		} // end rep
		printf ("%d\n", res );

/*
		rep (row, 5 ){
			rep (col, 5 ){
				printf ("%d", field[row][col] );
			} // end rep
			printf ("\n" );
		} // end rep
		printf ("\n" );
*/
	} // end rep

	return 0;
}

Measured memory_bytes: 1240
import Control.Applicative

getArr :: IO [Int]
getArr = map read . words <$> getLine

getKA :: Int -> [[Int]] -> IO [[Int]]
getKA 0 out = return out
getKA c out = do
  x <- (: out) <$> tail <$> getArr
  getKA (c-1) x

solve :: Int -> [[Int]] -> [Int] -> [Int]
solve 1 _ out      = out
solve c (x:xs) out = solve (c-1) xs (check x out)
  where
    check :: [Int] -> [Int] -> [Int]
    check a b = filter (/=0) $ map (\x->if elem x a then x else 0) b

main :: IO ()
main = do
  [n,_] <- getArr
  x <- getKA n []
  putStrLn $ show $ length $ solve n (tail x) (head x)

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

using namespace std;
int n, a, b;
int h[100000 + 10];
int oldh[100000 + 10];
int check(int hits) {

    for (int i = 0; i < n; i++) h[i] = max(0LL, (long long)h[i] - (long long)hits*b);
    long long needed = 0;
    for (int i = 0; i < n; i++) {
        needed += (h[i] + a - b - 1) / (a - b);
    }

    for (int i = 0; i < n; i++) h[i] = oldh[i];

    return needed <= hits;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n >> a >> b;
    for (int i = 0; i < n; i++) cin >> h[i], oldh[i] = h[i];

    int p = 0, q = 1e9 + 1;

    while (p < q) {
        int s = (p+q) / 2;

        if (check(s)) {
            q = s;
        } else {
            p = s + 1;
        }
    }

    cout << p << "\n";


    return 0;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main{
  public static void main (String[] args){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    int distanceA = x - a;
    int distanceB = x - b;
    if (Math.abs(distanceA) < Math.abs(distanceB)){
      System.out.println("A");
    }else{
      System.out.println("B");
    }
  }
}

Measured memory_bytes: 21844
// https://atcoder.jp/contests/abc178/tasks/abc178_f

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
template <typename T>
using VV = V<V<T>>;
using VVL = VV<ll>;
template <typename T>
using VVV = VV<V<T>>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
using asc_pq = priority_queue<T, V<T>, greater<T>>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll N;
  cin >> N;

  VL as(N);
  rep(i, N) cin >> as[i];

  VL bs(N);
  rep(i, N) cin >> bs[i];

  // {
  //   VL ct(N + 1);

  //   for (ll e : as) ct[e]++;
  //   for (ll e : bs) ct[e]++;

  //   rep(num, N + 1) {
  //     if (ct[num] > N) drop("No");
  //   }
  // }

  auto print_and_exit = [&]() {
    cout << "Yes"
         << "\n";

    rep(i, N) {
      if (i > 0) cout << " ";
      cout << bs[i];
    }
    cout << "\n";
    throw exit_exception();
  };

  reverse(all(bs));

  // 逆順ソートすれば、被っている要素はたかだか一種類となり、範囲となる
  // [same_l, same_r) で被っているとする
  ll same_l = -1;
  ll same_r = -1;

  rep(i, N) {
    if (as[i] == bs[i] && same_l == -1) {
      same_l = i;
    }

    if (as[i] != bs[i] && same_l != -1) {
      same_r = i;
      break;
    }
  }

  if (same_l == -1) print_and_exit();

  ll dup = bs[same_l];
  ll ni = same_l;

  rep(i, N) {
    if (ni == same_r) break;
    if (same_l <= i && i < same_r) continue;

    if (as[i] != bs[ni] && bs[i] != as[ni]) {
      swap(bs[i], bs[ni++]);
    }
  }

  auto is_ok = [&]() {
    rep(i, N) {
      if (as[i] == bs[i]) return false;
    }

    return true;
  };

  if (!is_ok()) drop("No");

  print_and_exit();
}


Measured memory_bytes: 6376
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>

using namespace std;

#define int long long
#define ll long long
#define double long double
#define pii pair<int, int>
#define vec vector
#define u_map unordered_map
#define u_set unordered_set
#define str string
#define all(el) el.begin(), el.end()
#define allr(el) el.rbegin(), el.rend()
#define sz(el) (int)el.size()
#define f first
#define s second
#define pb push_back
#define in insert
#define mp make_pair
#define endl "\n"
#define forn(i, n) for (int i = 0; i < n; ++i)

inline int maxi(int &a, int b) { if (b > a) { a = b; return 1; } return 0; }

inline int mini(int &a, int b) { if (b < a) { a = b; return 1; } return 0; }

inline int maxi(double &a, double b) { if (b > a) { a = b; return 1; } return 0; }

inline int mini(double &a, double b) { if (b < a) { a = b; return 1; } return 0; }

int bin_pow(int x, int p) {
    if (p < 0) {
        return 0;
    }
    if (p == 0) {
        return 1;
    }
    if (p % 2 == 0) {
        int ans = bin_pow(x, p / 2);
        return ans * ans;
    }
    return x * bin_pow(x, p - 1);
}

signed main() {

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

    int n;
    cin >> n;
    if (n % 2 == 1) {
        cout << 0;
        return 0;
    }
    int del = 10;
    int ans = 0;
    while (del <= n) {
        ans += n / del;
        del *= 5;
    }

    cout << ans;

    return 0;
}

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

typedef long long ll;
#define int ll

using namespace std;

const int N=2e3+100;
const int inf=2e9;
int a[N],b[N];

signed main()
{
    int n,k,q;
    cin>>n>>k>>q;
    for(int i=0;i<n;i++)
        cin>>a[i],b[i]=a[i];
    sort(b,b+n);
    a[n]=0;
    int ans=inf;
    for(int i=-1;i<n;i++)
    {
        if(i>0&&b[i-1]==b[i])
            continue;
        int m=(i==-1)?0:b[i];
        multiset< int , greater<int> > s;
        multiset<int> t;
        for(int i=0;i<=n;i++)
            if(a[i]>m)
                t.insert(a[i]);
            else
            {
                int left=t.size();
                for(int x:t)
                {
                    if(left<k)
                        break;
                    s.insert(x);
                    left--;
                }
                t.clear();
                while(s.size()>q)
                    s.erase(s.begin());
            }
        if(s.size()<q)
            break;
        ans=min(ans,*s.begin()-*s.rbegin());
    }
    cout<<ans;
}

/**

answer: 451211184
output: 412642879

*/


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>

using namespace std;

struct Node {
    int key;
    Node *parent,*left,*right;
};

Node *root,*NIL;

void insert(int k) {
    Node *y=NIL;
    Node *x=root;
    Node *z;

    z=new Node;
    z->key=k;
    z->left=NIL;
    z->right=NIL;
    while(x!=NIL) {
        y=x;
        if(z->key < x->key) {
            x=x->left;
        }
        else {
            x=x->right;
        }
    }

    z->parent=y;
    if(y==NIL) {
        root=z;
    }
    else {
        if(z->key<y->key) y->left=z;
        else y->right=z;
    }
}

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

int main() {
    int n,x;
    string com;

    cin>>n;
    for(int i=0;i<n;i++) {
        cin>>com;
        if(com=="insert") {
            cin>>x;
            insert(x);
        }
        else if(com=="print") {
            inorder(root);
            cout<<endl;
            preorder(root);
            cout<<endl;
        }
    }

    return 0;

}

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

int main() {
  int A, B; cin >> A >> B;
  int ans {};
  for (int i = A; i <= B; i++) {
    string s = to_string(i);
    if (s[0] == s[4] and s[1] == s[3]) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;


namespace ABC137
{
    class Program
    {
        static void Main(string[] args)
        {
            var cin = ReadInts();
            var k = cin[0];
            var x = cin[1];
            var xmin = x - k + 1;
            var xmax = x + k - 1;

            for (int i = xmin; i <= xmax; i++)
            {
                Write("{0} ", i);
            }
            Write("\n");
            Read();
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

int n, card[202], tmpc[202];

void cutk(int k) {
	int i;
	for (i = 1; i <= k; i++) {
		tmpc[i] = card[i];
	}
	for (i = k + 1; i <= 2 * n; i++) {
		card[i - k] = card[i];
	}
	for (i = 2 * n - k + 1; i <= 2 * n; i++) {
		card[i] = tmpc[i - 2 * n + k];
	}
}
void riffle(void) {
	int i;
	for (i = 1; i <= n; i++) {
		tmpc[i] = card[i];
	}
	for (i = 1; i <= n; i++) {
		card[2 * i] = card[n + i];
	}
	for (i = 1; i <= n; i++) {
		card[2 * i - 1] = tmpc[i];	
	}
}

int main() {
	int m, cmd;

	cin >> n >> m;

	for (int i = 1; i <= 2 * n; i++) {
		card[i] = i;
	}

	for (int i = 0; i < m; i++) {
		cin >> cmd;
		if (cmd == 0) {
			riffle();
		} else {
			cutk(cmd);
		}
	}
	for (int i = 1; i <= 2 * n; i++) {
		cout << card[i] << endl;
	}


	return 0;
}

Measured memory_bytes: 3068
use std::iter::Iterator;
fn main() {
    let (n, k) = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let mut iter = s.split_whitespace().map(|i| i.parse::<i32>().unwrap());
        (iter.next().unwrap(), iter.next().unwrap() as usize)
    };
    let mut input: Vec<i32> = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.split_whitespace()
            .map(|i| i.parse::<i32>().unwrap())
            .collect()
    };
    input.sort();
    let mut sum = 0;
    for v in &input[0..k] {
        sum = sum + v;
    }
    println!("{}", sum);
}

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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;

    for (int i = a; i <= 10000; i += a) {
        if (i % b == c) return cout << "YES" << endl, 0;
    }
    cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
n=int(input())
lis=[]
for _ in range(n):
  lis+=[input()]
lis2=list(set(lis))
if len(lis2)!=n:
  print("No")
else:
  correct=True
  i=0
  while correct and i<n-1:
    if lis[i][-1]!=lis[i+1][0]:
      correct=False
    i+=1
  if correct:
    print("Yes")
  else:
    print("No")
      

Measured memory_bytes: 3060
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#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 <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#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(12)

using namespace std;

typedef pair<int, int> P;

class BTapDance {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        string s;
        cin >> s;
        REP(i, s.size()) {
            if (i % 2 == 0) {
                if (s[i] == 'L') {
                    cout << "No" << endl;
                    return;
                }
            } else {
                if (s[i] == 'R') {
                    cout << "No" << endl;
                    return;
                }
            }
        }
        cout << "Yes" << endl;

    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    BTapDance solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
// finish date: 2018/01/21
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define bigmod 1000000007
#define INF 500000000


int mul(int a, int b) {
    return (int) (((ll) (a % bigmod) * (b % bigmod)) % bigmod);
}

int main() {
    ll x;
    cin >> x;
    ll loop = x / 11;
    x -= loop * 11;
    ll ans = loop * 2;
    if (x != 0) {
        if (x <= 6) ans += 1;
        else ans += 2;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
v = list(map(int,input().split()))

ans = 0

for l in range(n):
    for r in range(n-l+1):
        if l + r > k:
            break
        nv = v[:l] + v[n-r:]
        nv.sort()
        for i in range(k-l-r):
            if not nv or nv[0] >= 0:
                break
            del nv[0]
        ans = max(ans,sum(nv))
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
template<class T> inline void chmin(T &a,T b){if(a > b) a = b;}
#define REP(i,n) for(int i=0;i<n;++i)

using namespace std;
using ll = long long;
constexpr int INF = 1e9;

int dp[1 << 16][16];
int V,E,s,t,d;

struct Edge {
    int to,cost;
    Edge(int to,int cost) : to(to), cost(cost){}
};

using Graph = vector<vector<Edge> >;

int main(){
    cin >> V >> E;
    Graph g(V);
    REP(i,E){
        cin >> s >> t >> d;
        g[s].emplace_back(t,d);
    }
    REP(i,1<<V) REP(j,V) dp[i][j] = INF;
    dp[(1<<V)-1][0] = 0; // start is 0
    for(int i = (1<<V)-2; i >= 0; --i){
        // x to somewhere
        for(int v = 0; v < V; ++v){
            for(Edge e : g[v]){
                int nv = e.to;
                int nc = e.cost;
                if(!(i & (1<<nv))){
                    chmin(dp[i][nv],dp[i | (1<<nv)][v] + nc);
                }
            }
        }
    }
    cout << (dp[0][0]==INF ? -1 : dp[0][0]) << endl;
    return 0;
}




Measured memory_bytes: 5108
#include<bits/stdc++.h>
#define ll long long 
#define mp make_pair 
#define pb push_back 
#define F first 
#define S second 
#define f(i,n) for(int i=0;i<n;i++) 

using namespace std;

void test(){
	char c;
	cin>>c;
	if(c>='a' and c<='z')cout<<"a\n";
	else cout<<"A\n";
}

int main(){
	int tests = 1;
//	cin>>tests;
	while(tests--){
		test();
	}
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
 
using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 100000000
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(g);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double PI = acos(-1.0);
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
 
 
#ifdef TESTING
#define DEBUG fprintf(stderr,"====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define DEBUG 
#define VALUE(x)
#define debug(...)
#endif
/*
inline string IntToString(ll a) {
	char x[100];
	sprintf_s(x, "%lld", a); string s = x;
	return s;
}
 
inline ll StringToInt(string a) {
	char x[100]; ll res;
	strcpy_s(x, a.c_str()); sscanf_s(x, "%lld", &res);
	return res;
}
*/
 
inline string uppercase(string s) {
	int n = SIZE(s);
	rep(i, n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
	return s;
}
 
inline string lowercase(string s) {
	int n = SIZE(s);
	rep(i, n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
	return s;
}
 
 
int main()
{
	string s;
	string x[4] = { "dream","dreamer","erase","eraser" };
	cin >> s;
	int a = s.size();
	while (a > 0) {
		int ax = a;
		if ((int)s.find("dream", a - 5) >= 0) a -= 5;
		else if ((int)s.find("erase", a - 5) >= 0) a -= 5;
		else if ((int)s.find("dreamer", a - 7) >= 0) a -= 7;
		else if ((int)s.find("eraser", a - 6) >= 0) a -= 6;
		else {
			cout << "NO" << endl;
			return 0;
		}
		s.erase(s.begin() + a, s.begin() + ax);
	}
	puts("YES");
	return 0;
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  while (cin >> n, n) {
    int a[110];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int k;
    cin >> k;
    int l = 0, r = n - 1, ans = 0;
    while (l <= r) {
      ans++;
      int m = (l + r) / 2;
      if (k < a[m]) r = m - 1;
      else if (a[m] < k) l = m + 1;
      else break;
    }
    cout << ans << endl;
  }

  return 0;
}


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

  int d1[6],d2[6],i,j,blank;

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

    scanf("%d",&d1[i]);
    
  }
  
  for(i = 0; i < 6; i++){
    
    scanf("%d",&d2[i]);
    
  }

  for(i = 0; d1[1] != d2[1] && i < 3; i++){
    
    //3S
    blank=d2[0];
    d2[0]=d2[4];
    d2[4]=d2[5];
    d2[5]=d2[1];
    d2[1]=blank;
    
  }
  
  if(d1[1] != d2[1]){
    
    //1E
    blank=d2[0];
    d2[0]=d2[3];
    d2[3]=d2[5];
    d2[5]=d2[2];
    d2[2]=blank;

    for(i = 0; d1[1] != d2[1] && i < 3; i++){

      //3S
      blank=d2[0];
      d2[0]=d2[4];
      d2[4]=d2[5];
      d2[5]=d2[1];
      d2[1]=blank;

    }

  }

  if(d1[1] != d2[1]){

    printf("No\n");

    return 0;

  }
  
  for(i = 0; d1[0] != d2[0]; i++){
    
    //3E
    blank=d2[0];
    d2[0]=d2[3];
    d2[3]=d2[5];
    d2[5]=d2[2];
    d2[2]=blank;

  }

  if(d1[0] != d2[0]){
    
    printf("No\n");
    
    return 0;
    
  }

  if(d1[2] == d2[2] && d1[3] == d2[3] && d1[4] == d2[4] && d1[5] == d2[5]){

    printf("Yes\n");

  } else {

    printf("No\n");

  }

  return 0;

}
					 
    

Measured memory_bytes: 580
L, R = map(int, input().split())
if R-L >= 2019:
    print(0)
else:
    ans = 2018**2
    for i in range(L, R):
        for j in range(i+1, R+1):
            mod2019 = i*j%2019
            if mod2019 < ans:
                ans = mod2019
    print(ans)

Measured memory_bytes: 40684
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

vector <int> loc[26];
int l1,l2;
long long ans;
char s[100010],t[100010],cmp1[30],cmp2[30];

void dfs(int x, long long p, long long q)
{
	if (x==l2+1)
	{
		ans=p*l1+q;
		return ;
	}
	long long k=upper_bound(loc[t[x]-'a'].begin(),loc[t[x]-'a'].end(),q)-loc[t[x]-'a'].begin();
	if (loc[t[x]-'a'][k]>l1) dfs(x+1,p+1,loc[t[x]-'a'][k]-l1);
	else dfs(x+1,p,loc[t[x]-'a'][k]);
}

int main()
{
	scanf("%s",s+1);
	scanf("%s",t+1);
	l1=strlen(s+1),l2=strlen(t+1);
	for (int i=1; i<=l1; i++) cmp1[s[i]-'a']=1;
	for (int i=1; i<=l2; i++) cmp2[t[i]-'a']=1;
	
	//判‘-1 ’ 
	for (int i=1; i<=l2; i++)
		if (cmp2[t[i]-'a']&&!cmp1[t[i]-'a'])
		{
			printf("-1");
			return 0;
		}
	
	//求ans 
	for (int i=1; i<=l1; i++) loc[s[i]-'a'].push_back(i);
	for (int i=0; i<26; i++)
		if (cmp1[i])
		{
			int k=loc[i].size();
			for (int j=0; j<k; j++) loc[i].push_back(loc[i][j]+l1);
		}
	dfs(1,0,0);
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1656
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class AButtons {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            if (a == b) out.println(a * 2);
            else out.println(2 * Math.max(a, b) - 1);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

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

    }
}




Measured memory_bytes: 23252
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>
using namespace std;

//#include<bits/stdc++.h>

int f[105][18];
int p[105][18];
int main() {
	
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> f[i][j];
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 11; j++) {
			cin >> p[i][j];
		}
	}

	int ans = -9999999999;

	for (int i = 1; i < 1 << 10; i++) {
		int t = 0;
		for (int j = 0; j < n; j++) {
			int h= 0;
			for (int a = 0; a < 10; a++) {
				if ((i >> a & 1) && f[j][a])h++;
			}
			t += p[j][h];
		}
		ans = max(ans, t);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
array = list(input())
new_array = []
for i in range(len(array)-2):
    n = 100*int(array[i]) + 10*int(array[i+1]) + int(array[i+2])
    if n <= 753:
        new_array.append(753 - n)
    else:
        new_array.append(n - 753)
    n = 0
print(min(new_array))

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

int main() 
{
   long d ,t,cnt=0;
   cin>>t;
   cin>>d;
   while(t--){
     long a,b;
     cin>>a;
     cin>>b;
     long c=ceil(sqrt(a*a +b*b));
     if(c<=d)
      cnt++;
   }
   cout<<cnt;
}

Measured memory_bytes: 3740
#include <iostream>
#include <assert.h>
#include <vector>
#include <algorithm>
//#include <functional>
//#include <cmath>

int main(){
    int32_t N;
    std::cin >> N;
    std::vector<int32_t> d(N);
    //sort -> mid index(i,j] -> d[j] - d[i]
    for(auto& i : d){
        std::cin >> i;
    }
    std::sort(d.begin(), d.end());
    int32_t mid = int32_t( d.size() / 2);
    int32_t res = d[mid] - d[mid-1];
    std::cout << res;

    return 0;
}


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

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

    int i,j,k;
    vector<int>  ans(N+1);
    int A;
    for( i = 1; i <= 100; i++ ){
        //if( i*i + i + 4 > N ) break;
        for( j = 1; j <= 100; j++ ){
            //if( i*i + j*j + i*j + i + j + 1 > N ) break;
            for( k = 1; k <= 100; k++ ){
                A = i*i + j*j + k*k + i*j + j*k + k*i;
                if( A <= N ){
                  	ans[A] += 1;
                    //if( i == j && j == k && k == i ) ans[A] += 1;
                    //else if( i != j && j != k && k != i ) ans[A] += 6;
                    //else ans[A] += 3;
                }
            }
        }
    }

    for( i = 1; i <= N; i++ ){
        cout << ans[i] << endl;
    }

}


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

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m,x;
cin>>n>>m>>x;
int d;
int a[n+m+1]={0};
for(int i=0;i<m;++i)
{cin>>d;
    ++a[d];
}
int a1=0,a2=0;
for(int i=x;i<=n;++i)
{
    if(a[i]!=0)
        ++a1;
}

for(int i=x;i>=0;--i)
{
    if(a[i]!=0)
        ++a2;
}
if(a1<a2)
cout<<a1;
else
cout<<a2;

}


Measured memory_bytes: 256
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

s = input()
t = input()

ans = []
for i in range(len(s)+1-len(t)):
    cnt = 0
    for j in range(len(t)):
        if (s[i+j] != t[j]):
            cnt += 1
    ans.append(cnt)

print(min(ans))



Measured memory_bytes: 8976
def main():
  N,K = map(int, input().split())

  if N >= K:
    x = N%K
  else:
    x = abs(N-K)

  while(True):
    tmp_abs = abs(x-K)
    if x > tmp_abs:
      x = tmp_abs
    else:
      break
  
  print(x)

if __name__ == "__main__":
  main()

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

template<class T> class Dijkstra {
public:
    int N;
    T inf;
    vector<T> cost;
    vector<vector<pair<T, int>>> edge;
 
    Dijkstra(const int _N, T _inf = 1e18) : N(_N), inf(_inf),cost(N), edge(N) {
    }
 
    void make_edge(int from, int to, T w) {
        edge[from].push_back({ w,to });
    }
 
    void solve(int start) {
        for(int i = 0; i < N; ++i) cost[i] = inf;
 
        priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> pq;
        cost[start] = 0;
        pq.push({ 0,start });
 
        while (!pq.empty()) {
            T v = pq.top().first;
            int from = pq.top().second;
            pq.pop();
            for (auto u : edge[from]) {
                T w = v + u.first;
                int to = u.second;
                if (w < cost[to]) {
                    cost[to] = w;
                    pq.push({ w,to });
                }
            }
        }
        return;
    }
};


int main() {
    const long long INFLL = (long long)1e18+1;
    int V, E, r;
    cin >> V >> E >> r;

    Dijkstra<long long> G(V, INFLL);

    for(int _ = 0; _ < E; _++){
        int s, t;
        long long d;
        cin >> s >> t >> d;
        G.make_edge(s, t, d);
    }

    G.solve(r);
    
    for(int i = 0; i < V; i++){
        if(G.cost[i] == INFLL)cout << "INF" << endl;
        else cout << G.cost[i] << endl;
    }
}


Measured memory_bytes: 19324
// 26
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fors(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fors(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define forrs(_, x, n, s) for (int _ = x; _ > n; _ -= s)
#define forrn(_, x, n) forrs(_, x, n, 1)
#define rrep(_, n) forrn(_, n - 1, -1)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define lli __int128_t
#define li long long int
#define ld long double
#ifdef LOCAL
#define debug(e) cerr << "\033[48;5;196m\033[38;5;15m" << e << "\033[0m";
#else
#define debug(e)
#endif
// 4
template <class A, class B>
ostream &operator<<(ostream &os, pair<A, B> &p) {
  return os << "(" << p.fi << " " << p.se << ")";
}
// 8
template <class T>
ostream &operator<<(ostream &os, vector<T> &v) {
  rep(i, (int)v.size()) {
    if (i) os << " ";
    os << v[i];
  }
  return os;
}
// 6
template <class A, class B>
ostream &operator<<(ostream &os, map<A, B> &m) {
  for (auto &kv : m) os << "{" << kv.fi << " " << kv.se << "}";
  return os;
}
// 3
void _main(int tc) {
  int n;
  cin >> n;
  vector<ld> p(n);
  rep(i, n) cin >> p[i];
  vector<vector<ld>> mem(n, vector<ld>(n + 1, -1));
  function<ld(int, int)> f = [&](int i, int c) -> ld {
    if (n - i + c <= i - c) return 0;
    if (i == n) return 1;
    if (mem[i][c] != -1) return mem[i][c];
    return mem[i][c] = p[i] * f(i + 1, c) + (1 -  p[i]) * f(i + 1, c - 1);
  };
  cout << setprecision(10) << f(0, n) << endl;
}
// 7
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0), exit(0);
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Measured memory_bytes: 141312
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        public static void Main(string[] args)
        {
            var m = int.Parse(Console.ReadLine());
            var result = 24 + (24 - m);

            Console.WriteLine(result);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int n; cin >> n;
    cout << n * n << endl;
}

Measured memory_bytes: 256
function Main(input) {
    var strs = input.split("\n");
    var N = Number(strs[0]);
    hen = strs[1].split(" ");
    answer = 'No';
    for(i = 0; i < N; i++){
        hen[i] = Number(hen[i]);
    }
    hen.sort((a,b) => {
        if(a<b) return -1;
        if(a>b) return 1;
        return 0;
    });
    saidai = hen[N-1];
    hikaku = 0;
    for(i = N-2; i >= 0; i--){
        hikaku+=hen[i];
    }
    if(saidai<hikaku) answer = 'Yes';
    console.log(answer)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <iostream>
#include <fstream>
#include <set>
#include <tuple>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <map>
#include <queue>
#include <stack>

int main() {
	int n, m; std::cin >> n >> m;
	std::vector<int> heights(n); for (auto& h : heights) std::cin >> h;
	std::vector<bool> has_good_view(n, true);
	for (auto i = 0; i < m; ++i) {
		int a, b; std::cin >> a >> b; --a; --b;
		if (heights[a] <= heights[b]) {
			has_good_view[a] = false;
		}
		if (heights[b] <= heights[a]) {
			has_good_view[b] = false;
		}
	}
	std::cout << std::count(has_good_view.begin(), has_good_view.end(), true) << std::endl;
}

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

typedef pair<long long, long long> pi;
typedef pair<pi, bool> pii;

long long n, c, x, y;
pii a[2000000];
set<long long> s;
set<long long>::iterator it;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> x >> y;
		a[i] = pii(pi(x, y), 0);
	}
	for(int i = 0; i < n; i++){
		cin >> x >> y;
		a[i+n] = pii(pi(x, y), 1);
	}
	sort(a, a+(2*n));
	for(int i = 0; i < 2*n; i++){
		if(!a[i].second) s.insert(a[i].first.second);
		else {
			it = s.lower_bound(a[i].first.second);
			if(it != s.begin()){
				it--;
				c++;
				s.erase(it);
			}
		}	
	}
	cout << c;
}

Measured memory_bytes: 256
#include<stdio.h>

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

  long long num, cul = 1;

  for(i=0;i<n;i++){
    scanf("%lld", &num);
    if(num==0){ cul = 0; break; }
    if( num > 1000000000000000000/cul ) cul = -1;
    if( cul != -1 ) cul *= num;
  }

  printf("%lld\n", cul);

  return 0;
}

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

int bubbleSort(int N, int *series){
    int swapNum=0;
    for(int i=0; i<N; i++){
        for(int j=N-1; j>=i+1; j--){
            if(series[j-1]>series[j]){
                swap(series[j], series[j-1]);
                swapNum++;
            }
        }
    }
    return swapNum;
}

int main(){

    int N, swapNum;
    int series[100];
    cin >> N;

    for(int i=0; i!=N; i++){cin >> series[i];}
    
    swapNum=bubbleSort(N, series);

    for(int i=0; i!=N; i++){
        cout << series[i];
        if(i!=N-1)cout << " ";
    }
    cout << endl;
    
    cout << swapNum << endl;

    return 0;
}


Measured memory_bytes: 3096
"""
import sys
sys.setrecursionlimit(10**9)
N=int(input())
D=[]
for i in range(N):
  s,p=input().split()
  D.append((s, int(p), i+1))
D.sort(key=lambda d: (d[0], -d[1], d[2]))

for d in D:
  print(d[2])
"""
A,P=map(int, input().split())
print((A*3+P)//2)

Measured memory_bytes: 2940
import sys
import os
if sys.platform=="darwin":
	base = os.path.dirname(os.path.abspath(__file__))
	name = os.path.normpath(os.path.join(base, '../Documents/input.txt'))
	#print(name)
	sys.stdin = open(name)

n = int(input())
l = list(map(int,input().split()))

l = sorted(l)
a = l[n//2-1]
b = l[n//2]

#print(a,b)

if a==b:
	print(0)
	exit()
else:
	print(b-a)

Measured memory_bytes: 52684
#include <iostream>
#define llint long long
#define inf 1000000000000000

using namespace std;

llint n, W;
llint w[105], v[105];
llint dp[105][100005];

int main(void)
{
  cin >> n >> W;
  for(int i = 1; i <= n; i++) cin >> w[i] >> v[i];

  for(int i = 0; i <= n; i++){
    for(int j = 0; j < 100005; j++){
      dp[i][j] = inf;
    }
  }
  dp[0][0] = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < 100005; j++){
      dp[i+1][j+v[i+1]] = min(dp[i+1][j+v[i+1]], dp[i][j] + w[i+1]);
      dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
    }
  }

  llint ans = 0;
  for(int i = 0; i < 100005; i++){
    if(dp[n][i] <= W) ans = i;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 80128