akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
	private static List<Integer> acceptableDigits = Arrays.stream(new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}).collect(ArrayList::new, List::add, List::addAll);

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String strPrice = scanner.nextLine().split(" ")[0];
		List<Integer> dislikes = Arrays.stream(scanner.nextLine().split(" ")).map(Integer::parseInt).sorted().collect(Collectors.toList());
		acceptableDigits.removeAll(dislikes);

		List<Integer> pDigits = new ArrayList<>();
		pDigits.add(null);
		pDigits.addAll(Arrays.stream(strPrice.split("")).map(Integer::parseInt).collect(Collectors.toList()));

		if (!isAcceptable(pDigits, dislikes)) {
			for (int i = 0; i < pDigits.size(); i++) {
				if (dislikes.contains(pDigits.get(i))) {
					increment(pDigits, i);
					break;
				}
			}
		}

		if (pDigits.get(0) == null) pDigits.remove(0);
		System.out.println(Integer.parseInt(pDigits.stream().map(i -> Integer.toString(i)).reduce((s1, s2) -> s1 + s2).orElse("0")));
	}

	private static boolean isAcceptable(List<Integer> pDigits, List<Integer> dislikes) {
		return !pDigits.stream().anyMatch(dislikes::contains);
	}

	private static void increment(List<Integer> pDigits, int index) {
		for (int i = index + 1; i < pDigits.size(); i++) {
			pDigits.set(i, acceptableDigits.get(0));
		}

		Integer previousDigit;
		do {
			previousDigit = pDigits.get(index);
			if (previousDigit == null) previousDigit = 0;
			pDigits.set(index, getNextClosestAcceptableDigit(previousDigit));
		} while (pDigits.get(index--) <= previousDigit);
	}

	private static Integer getNextClosestAcceptableDigit(Integer digit) {
		if (acceptableDigits.get(acceptableDigits.size() - 1) <= digit) return acceptableDigits.get(0);
		for (Integer acceptableDigit : acceptableDigits) {
			if (acceptableDigit > digit) return acceptableDigit;
		}
		return null;
	}
}


Measured memory_bytes: 27860
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    string S;
    cin >> S;
    sort(begin(S), end(S));
    if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
// F.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <numeric>

using namespace std;

int n;
int u;
int v;
vector<vector<int>> e;
vector<int> ad;
vector<int> bd;
vector<int> cd;
vector<int> dd;
int bmd;
int amd, ami, amd2;
int ans;

void dfs1(int n, int d) {
	if (bd[n] >= 0) return;
	bd[n] = d;
	for (int nx : e[n]) {
		dfs1(nx, d + 1);
	}
}

void dfs2(int n, int d) {
	if (ad[n] >= 0) return;
	ad[n] = d;
	if (d < bd[n] && bd[n] < bmd) {
		bmd = bd[n];
		amd = d;
		ami = n;
	}
	if (d <= bd[n]) {
		ans = max(ans, d);
	}
	if (d >= bd[n]) return;
	for (int nx : e[n]) {
		dfs2(nx, d + 1);
	}
}

void dfs3(int n, int d) {
	if (cd[n] >= d) return;
	cd[n] = d;
	if (d <= bd[n]) {
		ans = max(ans, d);
		if (d < bd[n] && d > amd2) {
			amd2 = d;
			ami = n;
		}
	}
	if (d >= bd[n]) return;
	for (int nx : e[n]) {
		dfs3(nx, d + 1);
	}
}

void dfs4(int n, int d) {
	if (dd[n] >= 0) return;
	dd[n] = d;
	if (d <= bd[n]) {
		ans = max(ans, d);
	}
	if (d >= bd[n]) return;
	for (int nx : e[n]) {
		dfs4(nx, d + 1);
	}
}

int main(int argc, char* argv[]) {
	cout.precision(20);
#ifdef _MSC_VER
	while (true)
#endif
	{
		ans = 0;
		n = -1;
		cin >> n >> u >> v;
		if (n <= 0) return 0;
		e.clear();
		e.resize(n);
		for (int i = 1; i < n; ++i) {
			int a, b;
			cin >> a >> b;
			e[a - 1].push_back(b - 1);
			e[b - 1].push_back(a - 1);
		}
		ad = vector<int>(n, -1);
		bd = vector<int>(n, -1);
		cd = vector<int>(n, -1);
		dd = vector<int>(n, -1);
		dfs1(v - 1, 0);
		amd = -1;
		bmd = 1 << 30;
		dfs2(u - 1, 0);
		if (amd > 0) {
			amd2 = -1;
			dfs3(ami, amd);
			if (amd2 > 0) {
				dfs4(ami, amd2);
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 9856
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N)cin >> A[i];
    sort(all(A));
    reverse(all(A));
    vector<ll> v;
    v.push_back(A[0]);
    rep1(i,N){
        v.push_back(A[i]);
        v.push_back(A[i]);
    }
    cout << accumulate(v.begin(), v.begin() + N - 1, 0LL) << endl;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i,n){
        cin >> p[i];
    }
    int res = 0;
    for(int i = 1;i < n-1;i++){
        if(p[i-1] < p[i] && p[i] < p[i+1]) res++;
        else if (p[i+1] < p[i] && p[i] < p[i-1]) res++;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct node {
	int key;
	struct node *r,*l,*p;
};
struct node *NIL,*root;
int a=0,b=0;
void insert(int k) {
	struct node *x=root,*y=NIL,*z;
	z=(struct node*)malloc(sizeof(struct node));
	z->key=k;
	z->l=NIL;
	z->r=NIL;
	while(x!=NIL) {
		y=x;
		if(k<x->key)
			x=x->l;
		else
			x=x->r;
	}
	z->p=y;
	if(y==NIL) {
		root=z;
	} else if(z->key<y->key)
		y->l=z;
	else
		y->r=z;
}
void inOrder(struct node *p) {
	if(p==NIL)
	return;
	inOrder(p->l);
    printf(" %d",p->key);
	inOrder(p->r);
}
void preOrder(struct node *p) {
	if(p==NIL)
	return;
	printf(" %d",p->key);
	preOrder(p->l);
	preOrder(p->r);
}
int print(struct node *p) {
	a=0;
	b=0;
	inOrder(p);
	printf("\n");
	preOrder(p);
	printf("\n");
	return a;
}
struct node *find(struct node *x,int k){
	while(x!=NIL&&x->key!=k){
		if(k>x->key)
		x=x->r;
		else
		x=x->l;
	}
	return x;
}
int main() {
	int m,i,j,o=0,k;
	char str[10];
	int len[11];
	struct node *x;
	scanf("%d",&m);
	for(i=0; i<m; i++) {
		scanf("%s",str);
		if(str[0]=='i') {
			scanf("%d",&k);
			insert(k);
		} else if(str[0]=='p'){
			print(root);
		}
		else{
			scanf("%d",&k);
			x=find(root,k);
			if(x!=NIL)
			printf("yes\n");
			else
			printf("no\n");
		}
	}//输入
	return 0;
}


Measured memory_bytes: 20496
#include <cstdio>
#include <algorithm>
#include <functional>

#define MAX 100000

int main()
{
	int N, K;
	long int h[MAX], ans[MAX];
	scanf("%d %d", &N, &K);
	for(int i=0; i<N; i++){
		scanf("%ld", &h[i]);
	}
	std::sort(h, h+N, std::greater<int>());
	for(int i=0; i<N-K+1; i++){
		ans[i] = h[i] - h[i+K-1];
	}
	std::sort(ans, ans+(N-K+1));
	// for(int i=0; i<N-K+1; i++){
	// 	printf("%ld ", ans[i]);
	// }
	// printf("\n");
	printf("%ld\n", ans[0]);
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

int main() {
	int N;
	cin >> N;
	ll st=1, sa=1;
	for(int i=0;i<N;i++) {
		int T, A;
		cin >> T >> A;
		ll times=max( (st-1)/T +1, (sa-1)/A +1);
		st=times*T, sa=times*A;
	}
	cout << st+sa << endl;
	return 0;
}


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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define trav(a, x) for (auto& a : x)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;
#define INF (1ll<<60)

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

// int dp[2005][2005][2];
int dp[2005][2];

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int n, Z, W;
    cin >> n >> Z >> W;
    VI V(n+1);
    FOR(i, 1, n) {
        cin >> V[i];
    }
    // dp[N][0][0] = abs(V[N] - W);
    // for (int i = N; i >= 0; i--) {
    //     for (int j = 0; j < i; j++) {
    //         dp[i][j][0] = 

    //     }
    // }
    // dp[N][0] = abs(V[n] - W);
    if (n == 1) {
        cout << abs(V[1] - W) << endl;
    } else if (n == 2) {
        cout << max(abs(V[n] - W), abs(V[n - 1] - W)) << endl;
    } else {
        dp[n - 1][0] = abs(V[n] - V[n - 1]);
        dp[n - 1][1] = dp[n - 1][0];
        // dp[n - 2][1] = max(abs(V[n] - V[n - 2]), dp[n - 1][0]);
        for (int i = n - 2; i >= 1; i--) {
            int mx = 0;
            for (int j = i + 1; j <= n - 1; j++) {
                mx = max(mx, dp[j][0]);
            }
            dp[i][1] = max(mx, abs(V[n] - V[i]));
            int mn = INT_MAX;
            for (int j = i + 1; j <= n - 1; j++) {
                mn = min(mn, dp[j][1]);
            }
            dp[i][0] = min(mn, abs(V[n] - V[i]));
        }
        // for (int i = 1; i < n; i++) {
        //     cout << dp[i][0] <<" "<<  dp[i][1] << endl;
        // }
        int ans = 0;
        for (int i = 1; i < n; i++) {
            ans = max(ans, dp[i][0]);
        }
        cout << max(abs(V[n] - W), ans) << endl;
    }
}

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

int main()
{ 
  int m, d, a, b ;
  cin >> m >> d ;
  a = d / 10 ;
  b = d % 10 ;

  int count = 0 ;
  for(int k = 1 ; k <= m ; k++)
  { 
    for(int i = 2 ; i <= a ; i++)
    {
      for(int j = 2 ; j <= 9 ; j++)
      {
        //cout << k << " " << i << " " << j << endl ;
        if(i * 10 + j > d)
        {
          continue ;
        }
        //cout << k << " " << i << " " << j << endl ;
        if(i * j == k)
        {
          //cout << k << " " << i << " " << j << endl ;
          count++ ;
        }
      }
    } 
  }

  cout << count << endl ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin>>N;
    int a[N+100];
    for (int i=0;i<N;i++){
        cin>>a[i];
    }
    long long money=1000;
    for (int i=0;i<N-1;i++){
        if (a[i]<a[i+1]){
            money=a[i+1]*(money/a[i])+money%a[i];
        }
    }
    cout<<money<<endl;
    return 0;
}

Measured memory_bytes: 3664
import sys
import numpy as np
from numba import njit

read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline

@njit('(i8[::1]),',cache=True)
def update(A):
    N=len(A)
    B=np.zeros_like(A)
    for i,x in enumerate(A):
        l=max(0,i-x)
        r=min(N-1,i+x)
        B[l]+=1
        if r+1<N:
            B[r+1]-=1
    B=np.cumsum(B)
    return B

N,K=map(int,input().split())
A=np.array(input().split(),np.int64)
K=min(K,100)
for _ in range(K):
    A=update(A)
print(" ".join(A.astype(str)))

Measured memory_bytes: 147580
from math import sqrt
def intersection_cl(S0, S1, C0, r):
    x0, y0 = S0; x1, y1 = S1
    cx, cy = C0

    xd = x1 - x0; yd = y1 - y0
    X = x0 - cx; Y = y0 - cy
    A = xd**2 + yd**2
    B = xd*X + yd*Y
    C = X**2 + Y**2 - r**2
    if B**2 < A*C:
        # ?§£??????
        return tuple()
    """
    if B**2 == A*C:
        # ????????????
        s = -B / float(A)
        return tuple((x0 + xd*s, y0 + yd*s))
    """
    # ??????
    D = B**2 - A*C
    s1 = (-B + sqrt(D)) / A
    s2 = (-B - sqrt(D)) / A
    return ((x0 + xd*s1, y0 + yd*s1), (x0 + xd*s2, y0 + yd*s2))

cx, cy, r = map(int, input().split())
q = int(input())
for i in range(q):
    x1, y1, x2, y2 = map(int, input().split())

    p0, p1 = sorted(intersection_cl((x1, y1), (x2, y2), (cx, cy), r))
    print("%.08f %.08f %.08f %.08f" % (p0 + p1))

Measured memory_bytes: 7876
#include<iostream>
using namespace std;
int main()
{
	int a,n;
	cin>>n;   //输入n 
	a=n/15;   //算出小紫可以优惠几次 
	cout<<800*n-a*200<<endl;//用菜的总价减去优惠的价格得到优惠后的金额 
	return 0;
}

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

int main() {
	vector<vector<char>> a(3,vector<char>(3,0));
	for(int i = 0;i<3;i++)
	{
		for(int j = 0;j < 3;j++)
		{
			cin >> a.at(i).at(j);
		}
	}
	string k = "   ";
	for(int i =0;i<3;i++)
	{
        k.at(i) = a.at(i).at(i);
	}
    cout << k << endl;
	return 0;
}


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

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

if N == 1:
    print(0)
else:
    ans = 0
    for i in factorization(N):
        k = i[1]
        n = int((-1+(1+8*k)**(0.5))/2)
        ans += n
    print(ans)

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

#define int long long
#define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)x.size())
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int, int>;

/*
 */

signed main(){
  int a, b, k;
  cin >> a >> b >> k;

  int t = min(a, k);
  a -= t; k -= t;
  t = min(b, k);
  b -= t;

  cout << a << " " << b << endl;

  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <functional>
#include <stdlib.h>
#include <climits>
#include <iomanip>
#include <complex>
#include <cmath>
using namespace std;
signed main(void)
{
	int n;
	cin >> n;
	int a[103];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	int alice = 0 , bob = 0;
	int cnt = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (cnt % 2 == 0)alice += a[i];
		else bob += a[i];
		cnt += 1;
	}
	cout << alice - bob;
	return 0;
}


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

using namespace std;

typedef pair<int, int> P;

struct list {
	P data;
	struct list *next;
};

list* make_list(P a, list *r) {
	list* z = (list*)malloc(sizeof(list));
	z->data = a;
	z->next = r;
	return z;
}

list* insert_list(P a, list *r) {
	list** x = &r;
	bool hantei = true;
	while (*x != NULL) {
		if (((*x)->data).first == -1) {
			((*x)->data).first = a.first;
			if (((*x)->data).second < a.second) {
				a.second = a.second - ((*x)->data).second;
			} else if (((*x)->data).second > a.second){
				int b = ((*x)->data).second - a.second;
				((*x)->data).second = a.second;
				(*x)->next = make_list(P(-1, b), (*x)->next);
				hantei = false;
				break;
			} else {
				hantei = false;
				break;
			}
		}
		x = &((*x)->next);
	}
	if (hantei) {
		*x = make_list(a, NULL);
	}
	return r;
}

list* delete_list(int a, list* r) {
	list** x = &r;
	while (*x != NULL) {
		if (((*x)->data).first == a) {
			((*x)->data).first = -1;
		}
		x = &((*x)->next);
	}
	return r;
}

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		char c;
		P p;
		int a;
		list* z = NULL;
		for (int i = 0; i < n; i++) {
			cin >> c;
			if (c == 'W') {
				cin >> p.first >> p.second;
				z = insert_list(p, z);
			} else if (c == 'D') {
				cin >> a;
				z = delete_list(a, z);
			} else {
				cin >> a;
				a++;
				list** x = &z;
				while (1) {
					if ((*x) == NULL) {
						cout << -1 << endl;
						break;
					}
					P q = (*x)->data;
					if (q.second >= a) {
						cout << q.first << endl;
						break;
					} else {
						a -= q.second;
						if (a < 0) {
							cout << -1 << endl;
							break;
						}
					}
					x = &((*x)->next);
				}
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1536
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
//#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>

using namespace std;
typedef vector <int> vi;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound

#define SZ(x) (int)x.size()
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define RSZ resize
#define INS insert
#define REP(i,a,b) for (int i = (a); i <= (b); i++)
#define PER(i,a,b) for (int i = (b); i >= (a); i--)
#define TRAV(a,x) for (auto& a : x)

int nxt(){int x;cin>>x;return x;}
ll nxtll(){ll x;cin>>x;return x;}


signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n=nxt();
    REP(i,1,9) REP(j,1,9) if(i*j==n){cout<<"Yes";return 0;}
    cout<<"No";
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

// Verified: AOJ2644 Longest Match (min, max)
enum query_type { min_query, max_query, sum_query };

template<class T> struct segtree {
  int N, K;
  vector<T> dat, sum;
  function<T(T, T)> func;
  T ngvalue;
  query_type qtype;

  void init(int n, function<T(T, T)>&& f, T ng, query_type type) {
    K = 0, N = 1;
    while(N < n) K++, N <<= 1;
    dat.assign(2 * N - 1, 0);
    sum.assign(2 * N - 1, 0);
    func = std::move(f);
    ngvalue = ng;
    qtype = type;
  }

  segtree() = default;

  segtree(int n, query_type qtype) {
    if(qtype == min_query) {
      init(n, [](T a, T b){return min(a, b);}, numeric_limits<T>::max(), max_query);
    }
    else if(qtype == max_query) {
      init(n, [](T a, T b){return max(a, b);}, numeric_limits<T>::min(), min_query);
    }
    else if(qtype == sum_query) {
      init(n, [](T a, T b){return a + b;}, 0, sum_query);
    }
    else {
      runtime_error("no matching query type");
    }
  }

  void add(int i, T x) {
    add(i, i + 1, x);
  }

  void add(int a, int b, T x) {
    add(a, b, x, 0, 0, N);
  }

  T add(int a, int b, T x, int k, int l, int r) {
    if(b <= l || r <= a) return dat[k];
    if(a <= l && r <= b) {
      sum[k] += x;
      return dat[k] += x * (qtype == sum_query ? r - l : 1);
    }
    int m = (l + r) / 2;
    return dat[k] = func(add(a, b, x, 2 * k + 1, l, m), add(a, b, x, 2 * k + 2, m, r)) + sum[k] * (qtype == sum_query ? r - l : 1);
  }

  T operator()(int a, int b) {
    return query(a, b, 0, 0, N);
  }

  T query(int a, int b, int k, int l, int r) {
    if(b <= l || r <= a) return ngvalue;
    if(a <= l && r <= b) return dat[k];
    int m = (l + r) / 2;
    return func(query(a, b, 2 * k + 1, l, m), query(a, b, 2 * k + 2, m, r)) + sum[k] * (qtype == sum_query ? (b < r ? b : r) - (a < l ? l : a) : 1);
  }
};

int main() {
  int N; cin >> N;
  segtree<ll> rsq(N, sum_query);
  int Q; cin >> Q;
  rep(_, Q) {
    int q; cin >> q;
    int s, t; cin >> s >> t; s--;
    if (q == 0) {
      int x; cin >> x;
      rsq.add(s, t, x);
    }
    else {
      cout << rsq(s, t) << "\n";
    }
  }
}



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

string str[4] = {"dream", "dreamer", "erase", "eraser"}, s;

int main(void){
    cin >> s;
    while(true){
        if(s.size()==0){
            cout << "YES" << endl;
            return 0;
        }
        if(s.size()>=5){string sub1 = s.substr(s.size()-5, 5);
            if(sub1==str[0] || sub1==str[2]){
                s.erase(s.size()-sub1.size(), s.size());
                continue;
            }
        }
        if(s.size()>=6){
            string sub2 = s.substr(s.size()-6, 6);
            if(sub2==str[3]){
                s.erase(s.size()-sub2.size(), s.size());
                continue;
            }
        }
        if(s.size()>=7){
            string sub3 = s.substr(s.size()-7, 7);
            if(sub3==str[1]){
                s.erase(s.size()-sub3.size(), s.size());
                continue;
            }
        }
        cout << "NO" << endl;
        return 0;
    }
}

Measured memory_bytes: 512
N, M, K = map(int, input().split())
import sys
mod = pow(10, 9) + 7
sys.setrecursionlimit(pow(10, 8))

def power(x, y):
    if   y == 0: return 1
    elif y == 1	 : return x % mod
    elif y % 2 == 0 : return power(x, y//2)**2 % mod
    else: return power(x, (y-1)//2)**2 * x % mod
    
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def div(a, b):
    return mul(a, power(b, mod-2))
def div2(a, b):
    return mul(a, modinv(b))

def modinv(a):
    b, u, v = mod, 1, 0
    while b:
        t = a//b
        a, u = a-t*b, u-t*v
        a, b, u, v = b, a, v, u
    u %= mod
    return u

def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

NNN = (10**6)
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, NNN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

def f(n, m):
    x = m*m%mod
    y = (n*n*(n-1)//2 - n*(n-1)*(2*n-1)//6) % mod
    return x*y%mod

print(mul(f(N, M) + f(M, N), cmb(N*M-2, K-2)))


Measured memory_bytes: 128140
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int ans;
    char a[100001];
    scanf("%s",a);
    for(int i=0;i<strlen(a)-1;i++)
    {
        if(a[i]!=a[i+1])
            ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int r,g,b;
  cin >> r >> g >> b;
  int x=(100*r+10*g+b)%4;
  if (x==0){
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

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


int main(){
  int a,b,c,x,y,i,m,ans=0,ans_max=0,res,res_pay;

  std::cin >> a>>b>>c>>x>>y;

  int x_0=x;
  int y_0=y;

  if(2*c<=a+b){
    m=max(x,y);
    for(i=0;i<m;i++){
      ans_max=ans_max+(c*2);
    }
    m=min(x,y);
    for(i=0;i<m;i++){
      ans=ans+(c*2);
      x=x-1;
      y=y-1;
    }
    if(x>y){
       res=x;
       
       res_pay=a;
     }

    else if(x<y) {
      res=y;
      res_pay=b;
    }

    for(i=0;i<res;i++){
      ans=ans+res_pay;
    }

    if(ans_max<ans){
      ans=ans_max;
    }
  }

  else{
    for(i=0;i<x_0;i++){
      ans=ans+a;
    }
    for(i=0;i<y_0;i++){
      ans=ans+b;
    }
  }

  std::cout << ans << '\n';


return 0;


}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
void swap_(int* a,int* b){
	int temp=*a;*a=*b;*b=temp;
}
//あとで削除
int chtoint(const char ch){int n=0;
	if(ch=='0')n=0;if(ch=='1')n=1;if(ch=='2')n=2;if(ch=='3')n=3;
	if(ch=='4')n=4;if(ch=='5')n=5;if(ch=='6')n=6;if(ch=='7')n=7;
	if(ch=='8')n=8;if(ch=='9')n=9;
	return (n);
}
int main(){
	int n ; cin >> n ;
	for(int i=0;i<n;i++){
		char a[8];int b[8];
		for(int j=0;j<8;j++) cin >> a[j] ;
		for(int j=0;j<8;j++) b[j]=chtoint(a[j]);
		for(int i=1;i<=7;i++){
			for(int j=7;j>=i;j--){
			if(b[j-1]>b[j]) swap_(&b[j-1],&b[j]) ;
		};};
		int min=b[0]; int max=b[7];
		for(int j=6;j>=0;j--) max=max*10+b[j];
		for(int j=1;j<=7;j++) min=min*10+b[j];
		int diff=max-min;
	cout << diff << '\n' ;
	};
}

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

using namespace std;

using i64 = long long int;
using ui64 = unsigned long long int;

////////

int main(){
    int n;
    while(cin >> n,n){
        vector<int> a(n);
        for(auto&& x:a)cin >> x;
        sort(a.begin(),a.end());
        int f = 1145141919;
        for(int i=0;i<n-1;i++){
            f = min(a[i+1] - a[i],f);
        }
        cout << f << endl;
    }
}



Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = (a), i##_end_ = (b); i <= i##_end_; ++i)
#define clear(a, b) memset((a), (b), sizeof(a))
typedef long long LL;
int read() {
	int x = 0, flag = 1;
	char ch = getchar();
	while(!isdigit(ch)) {
		if(ch == '-') flag = -1;
		ch = getchar();
	}
	while(isdigit(ch)) {
		x = x * 10 + ch - 48;
		ch = getchar();
	}
	return x * flag;
}

#define Maxn 1000009
#define Maxm 1000009
int n, m;
int a[Maxm][2];
int cnt_Ball[Maxn], vis[Maxn];
int main() {
#ifdef Qrsikno
	freopen("AGC002_2.in", "r", stdin);
	freopen("AGC002_2.out", "w", stdout);
#endif
	n = read(), m = read();
	rep(i, 1, m) 
		a[i][0] = read(), a[i][1] = read();
	vis[1] = 1;
	rep(i, 1, n) cnt_Ball[i] = 1;
	rep(i, 1, m) {
		if(vis[a[i][0]]){
			if(cnt_Ball[a[i][0]] == 1)
				vis[a[i][0]] = 0;
			vis[a[i][1]] = 1;
		} 
		--cnt_Ball[a[i][0]], ++cnt_Ball[a[i][1]];
	}
	int ans = 0;
	rep(i, 1, n) 
		ans += vis[i];
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 8832
process.stdin.resume();
process.stdin.setEncoding('utf8');
let input = '';
process.stdin.on('data', function(chunk) {input += chunk;});
process.stdin.on('end', function() {main(input.split("\n"));});

function partition(A,p,r) {
	let x = A[r];
	let i = p - 1;
	let tmp;
	for (let j = p; j < r; j++) {
		if (A[j] <= x) {
			i++;
			tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
		}
	}
	i++;
	tmp = A[i];
	A[i] = A[r];
	A[r] = tmp;

	return i;
}

function main(lines){
	let n = Number(lines[0]);
	let A = lines[1].split(" ").map(Number);
	let target = partition(A,0,n-1);

	A[target] = `[${A[target]}]`;

	console.log(A.join(" "));	
}



Measured memory_bytes: 32472
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	static void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	Scanner sc = new Scanner(System.in);
	int w, h;
	void run() {
		for (;;) {
			System.gc();
			w = sc.nextInt();
			h = sc.nextInt();
			if ((w | h) == 0) break;

			int n = sc.nextInt();

			int[] x = new int[2 * n + 2];
			int[] y = new int[2 * n + 2];
			for (int i = 0; i < n; i++) {
				x[2 * i] = sc.nextInt();
				y[2 * i] = sc.nextInt();
				x[2 * i + 1] = sc.nextInt();
				y[2 * i + 1] = sc.nextInt();
			}
			x[2 * n] = 0;
			x[2 * n + 1] = w;
			y[2 * n] = 0;
			y[2 * n + 1] = h;

			x = normalize(x);
			y = normalize(y);

			short[][] acc = new short[2 * n + 10][2 * n + 10]; // 8M
			for (int i = 0; i < n; i++) {
				int x1 = x[2 * i + 0];
				int y1 = y[2 * i + 0];
				int x2 = x[2 * i + 1];
				int y2 = y[2 * i + 1];
				acc[x1][y1]++;
				acc[x1][y2]--;
				acc[x2][y1]--;
				acc[x2][y2]++;
			}

			for (int i = 1; i < acc.length; i++) {
				acc[i][0] = (short) (acc[i-1][0] + acc[i][0]);
				acc[0][i] = (short) (acc[0][i-1] + acc[0][i]);
			}
			for (int i = 1; i < acc.length; i++) {
				for (int j = 1; j < acc.length; j++) {
					acc[i][j] = (short) (acc[i][j] + acc[i-1][j] + acc[i][j-1] - acc[i-1][j-1]);
				}
			}

			w = x[2 * n + 1];
			h = y[2 * n + 1];

			int ans = 0;
			for (int i = 0; i < w; i++) {
				for (int j = 0; j < h; j++) {
					if (acc[i][j] == 0) {
						ans++;
						bfs((short)i, (short)j, acc);
					}
				}
			}
			System.out.println(ans);

		}
	}

	short[] queue = new short[2000 * 2000 * 2];

	void bfs(short x, short y, short[][] acc) {
		int head = 0;
		int tail = 0;
		queue[tail++] = x;
		queue[tail++] = y;
		acc[x][y] = 2;

		short[] dx = {0, -1, 0, 1};
		short[] dy = {-1, 0, 1, 0};

		while (head < tail) {
			x = queue[head++];
			y = queue[head++];

			for (int i = 0; i < 4; i++) {
				short nx = (short) (x + dx[i]);
				short ny = (short) (y + dy[i]);

				if ((0 <= nx && nx < w && 0 <= ny && ny < h) && acc[nx][ny] == 0) {
					queue[tail++] = nx;
					queue[tail++] = ny;
					acc[nx][ny] = 2;
				}

			}
		}

	}

	int[] normalize(int[] v) {
		int[] res = new int[v.length];
		long[][] t = new long[v.length][2];
		for (int i = 0; i < v.length; i++) {
			t[i][0] = v[i];
			t[i][1] = i;
		}
		Arrays.sort(t, 0, t.length, new Comparator<long[]>(){
			public int compare(long[] a, long[] b){
				if (a[0] != b[0]) return a[0] < b[0] ? -1 : 1;
				return 0;
			}
		});

		int r = 0;
		for (int i = 0; i < v.length; i++) {
			r += (i > 0 && t[i - 1][0] != t[i][0]) ? 1 : 0;
			res[(int)t[i][1]] = r;
		}
		return res;
	}


}

Measured memory_bytes: 69852
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
double const PI=3.141592653589793;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=1000000007;

int X;

int main(){
    cin>>X;
    int Y=X%100;

    int res=0;
    while(Y>=5) res+=105, Y-=5;
    while(Y>=4) res+=104, Y-=4;
    while(Y>=3) res+=103, Y-=3;
    while(Y>=2) res+=102, Y-=2;
    while(Y>=1) res+=101, Y-=1;

    if(X<res) cout<<0<<endl;
    else cout<<1<<endl;
}

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


int main() {
  ll A, B, C, K;
  cin >> A >> B >> C >> K;
  
  if (K <= A) {
    cout << K << endl;
  } else if (K <= A + B) {
    cout << A << endl;
  } else {
    cout << 2 * A + B - K << endl;
  }
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> a(n),b(n),c(n);
    for(int i = 0; i < n; i++)
        cin>>a[i];
    sort(a.begin(),a.end());
    for(int i = 0; i < n; i++)
        cin>>b[i];
    for(int i = 0; i < n; i++)
        cin>>c[i];
    sort(c.begin(),c.end());
    long count=0;
    for(int i = 0; i < n; i++){
        long an=lower_bound(a.begin(),a.end(),b[i])-a.begin();
        long cn=upper_bound(c.begin(),c.end(),b[i])-c.begin();
        cn=n-cn;
        count+=an*cn;
    }
    cout<<count;
}

Measured memory_bytes: 1408
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline 

n = int(input())
s = read().split()

dp = []
dn = []
for i in s:
    a = 0
    d = 0
    for j in i:
        if j == "(": d+= 1
        else: d -= 1
        if d < a: a = d
    
    #print(a,d,i)    
    if d >= 0:    
        dp.append((a,d))
    else:
        dn.append((a-d,-d))
    
dp.sort()
dn.sort()

def check(dp):
    D = 0
    while dp:
        a,d = dp.pop()
        if D+a < 0: return False
        D += d
    return [D]

#print(dp)
#print(dn)
a = check(dp)
b = check(dn)
#print(a,b)

if a==False or b==False:
    print("No")
else:
    if a[0] != b[0]:
        print("No")
    else:
        print("Yes")
        





    
    
    
    
    

Measured memory_bytes: 183776
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    char c; cin >> c;

    if('a' <= c && c <= 'z'){  
        cout << 'a' << endl;
    }
    else if('A' <= c && c <= 'Z'){
        cout << 'A' << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <deque>

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

int main()
{
    int N, M;
    std::string S;
    std::cin >> N >> M >> S;
    
    std::vector<bool> grid(N+1);
    for (int i = 0; i <= N; ++i)
        grid[i] = (S[i] == '1');
    
    std::deque<int> list;
    bool can_pass = true;
    int i = 0;
    while (i < N && can_pass)
    {
        can_pass = false;
        for (int m = M; m >= 1 && !can_pass; --m)
        {
            if (i + m <= N && !grid[N - i - m])
            {
                i += m;
                list.push_front(m);
                can_pass = true;
            }
        }
    }
    
    if (can_pass)
    {
        for (int d : list)
            std::cout << d << " ";
        std::cout << std::endl;
    }
    else
    {
        std::cout << -1 << std::endl;
    }
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;




int main()
{
	int N,ma;
	ma = 0;
	cin >> N;
	vint A(N);
	cin >> A[0];
	for (int i = 1; i < N; i++){
		cin >> A[i];
		for (int j = 0; j < i; j++){
			ma = max(ma, abs(A[i] - A[j]));
		}
	}
	cout << ma << endl;
	
	
	
}

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

const int MAX=200005;
const int MOD=1000000007; 

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

void combit() {
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2; i<MAX; i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

long long com(int nn, int kk){
    if(nn<kk) return 0;
    if(nn<0 || kk<0) return 0;
    long long ans=1;
    for(int i=nn; i>=nn-kk+1; i--) {
        ans*=i;
        ans%=MOD;
    }
    return ans*finv[kk]%MOD;
}

long long modpow(long long aa, long long nn){
    long long res=1;
    while(nn>0){
        if(nn&1) res=res*aa%MOD;
        aa=aa*aa%MOD;
        nn>>=1;
    }
    return res;
}

int main() {
    long long ans=0;
    int n, a, b;
    cin >> n >> a >> b;
    ans--;
    combit();
    ans=modpow(2, n)-1;
    ans-=com(n,a);
    if(ans<0) ans+=MOD;
    ans-=com(n,b);
    if(ans<0) ans+=MOD;
    cout << ans;
}

Measured memory_bytes: 4992
#include <iostream>

using namespace std;

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

    int m = 1001;
    for (int i = 0; i < n; i++) {
        int ci, ti;
        cin >> ci >> ti;
        if (ti <= t && ci < m) {
            m = ci;
        }
    }

    if (m == 1001) {
        cout << "TLE" << endl;
    } else {
        cout << m << endl;
    }

    return 0;
}

Measured memory_bytes: 256
let () =
    let main () =
        let w, h, x, y = Scanf.sscanf (read_line ()) "%d %d %d %d" (fun w h x y -> w, h, x, y) in
        let x0 = w - x in
        let y0 = h - y in
        Printf.printf "%.9f %d\n" (float (w * h) /. 2.0) (if x0 = x && y0 = y then 1 else 0)
    in
    main ()

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

long long mod = 1000000007;

long long div(long long a, long long b, long long c){
    return b / c - (a - 1) / c;
}

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}

int main() {
    long long a, b, ans;
    cin >> a >> b; 
    ans = (a * b) / (__gcd(a, b));
    cout << ans << endl;
}

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

int main() {
  int X,i;
  cin >> X;
  i=X-1;
  
  while (X%i!=0){
    i--;}
    
  while (i!=1){
    X++;
    i=X-1;
    
  while (X%i!=0){
    i--;}
  }
    cout << X << endl;
}

Measured memory_bytes: 256
s = input()
n = len(s)
def f(a,b):
  X = s[a-1:b]
  Y = X[-1::-1]
  if X == Y:
    return(1)
  else:
    return(0)
  
if f(1,n) * f(1,(n-1)//2) * f((n+3)//2,n) == 1:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
using namespace std;

int main()
{
    int H, W;
    scanf("%d %d", &H, &W);
    int counter = 0;
    REP (i, H) {
        string input;
        cin >> input;
        REP (j, input.size()) {
            if (input[j] == '#') counter++;
        }
    }
    if (counter == H + W - 1) {
        printf("Possible\n");
    } else {
        printf("Impossible\n");
    }
}

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

typedef long long ll;

#define        optimize           ios::sync_with_stdio(0); cin.tie(0);
#define PI    acos(-1.0)
#define pb push_back
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define RESET(a, b) memset(a, b, sizeof(a))
#define pii pair <int, int>
#define gcd(a, b) __gcd(a, b)
#define min3(a, b, c) min(c, min(a, b))
#define max3(a, b, c) max(c, max(a, b))

#define        MX        3005

double dp[MX][MX];
double p[MX];

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

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

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

    double ans = 0;
    for(int i = n/2 + 1; i <= n; i++){
        ans += dp[n][i];
    }
    printf("%.10lf\n", ans);
}


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

int main() {

  uint64_t S; cin >> S; // 入力値
  int Keta = to_string(S).size() - 1; // ＋を入れられる場所の数
  uint64_t Ans = 0;     // 回答：合計値

  rep(i,(1<<Keta)){   // ＋位置フラグの全探索

    bitset<10> b(i);  // ＋位置フラグのビットセット化
    uint64_t SS = S;  // 入力値から削っていく用の変数
    int w = 10;   // ＋位置より下を剰余として取得する為の割る数

    rep(j,Keta){  // ＋位置フラグを下から見ていく
      if (b.test(j)){   // ＋が入っている場合
        Ans += SS % w;  // １０で割った余りを加算
        SS /= w;        // 途中数を次の為に１０で割る。
        w = 10;         // 割る数を初期化
      } 
      else {            // ＋が入っていない場合
        w *= 10;        // 割る数を１桁増やして、次回に備える。
      }
    }
    Ans += SS;          // 最後に残った途中数を加算
  }

  cout << Ans << endl;
}


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

#define Re return
#define In inline
#define Rg
#define Op operator
#define St static
#define inc(l, i, r) for(Rg int i=l; i<r; ++i)
#define dec(l, i, r) for(Rg int i=r; i>l; --i)
#define fst first
#define snd second

typedef long long ll;

int main()
{
    St int n, s;
    St pair<int, ll> a[1<<17];
    scanf("%d%d", &n, &s);
    inc(0, i, n)
        scanf("%d%lld", &a[i].fst, &a[i].snd);
    sort(a, a+n);
    Rg int m=lower_bound(a, a+n, make_pair(s, 0ll))-a;
    Rg int l=0, r=n-1;
    St ll f[1<<17];
    for(;l<m && m<=r;)
    {
        if(a[l].snd<a[r].snd)
            f[r]=max(f[r], f[l]+a[r].fst-a[l].fst), a[r].snd+=a[l++].snd;
        else
            f[l]=max(f[l], f[r]+a[r].fst-a[l].fst), a[l].snd+=a[r--].snd;
    }
    printf("%lld\n", l<m? f[l]+s-a[l].fst: f[r]+a[r].fst-s);
    Re 0;
}


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

int main() {
  int n, q;
  cin >> n >> q;
  vector<tuple<int, int, int>> a(n);
  rep(i, n) {
    int s, t, x;
    cin >> s >> t >> x;
    s -=x;
    t -= x;
    a[i] = tie(x, s, t);
  }
  sort(a.begin(), a.end());

  set<P> st;
  rep(i, q) {
    int d;
    cin >> d;
    st.insert(P(d, i));
  }
  vector<int> ans(q, -1);
  rep(i, n) {
    int s, t, x;
    tie(x, s, t) = a[i];
    auto it = st.lower_bound(P(s, -1));
    while(it != st.end()) {
      if(it->first >= t) break;
      ans[it->second] = x;
      st.erase(it++);
    }
  }
  rep(i, q) {
    cout << ans[i] << endl;
  }
  
}

Measured memory_bytes: 14336
#include<iostream>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define endl "\n"
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    int n; cin>>n;
 
    vector<int> a(n);
    deque<int> q;
    rep(i,n)cin>>a[i];
    rep(i,n){
        if(i%2==0){
            q.push_back(a[i]);
        }
        else{
            q.push_front(a[i]);
        }
    }
    for(int i=0;i<n;i++){
        int ans = 0;
        if(n%2==0){
            ans = q.front();
            q.pop_front();
        }
        else{
            ans = q.back();
            q.pop_back();
        }
        cout<< ans << " ";
    }  
    cout<<endl;
        


}

Measured memory_bytes: 3712
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
      int A = sc.nextInt();
      int B = sc.nextInt();
      int BiMin=(B*10);
      int BiMax =(B*10)+9;
      int i=-1;
	for(int j=BiMax;j>=BiMin;j--){
      if(j*8/100==A){
        i=j;
      }
    }

      System.out.println(i);


    }
  
  private static long lcm(long m, long n) {
    return m * n / gcd(m, n);
}
  
  private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
}
}


Measured memory_bytes: 23764
/* BISMILLAHIR RAHMANIR RAHIM */
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	int n;
	string s;
	cin >> n >> s;
	for(auto c : s) {
		int x = c - 'A';
		x += n, x %= 26;
		cout << (char)(x + 'A');
	}
	cout << "\n";
}

Measured memory_bytes: 256
N,A,B,C,D = map(int,input().split())
S = input()
right = max(C,D)
r = min(C,D)-1

if '##' in S[A-1:C] or '##' in S[B-1:D]:
  print('No')
else:
  if C < D:
  	print('Yes')
  else:
    if '...' in S[B-2:D+1]:
      print('Yes')
    else:
      if len(S[A-1:right])<=6:
        if S[A-1:right].count('#')==2:
          print('No')
        else:
          print('Yes')
      else:
        print('No')


Measured memory_bytes: 3572
from collections import deque

k = int(input())

que = deque([1,2,3,4,5,6,7,8,9])

for n in range(0, k):
  x = que.popleft()
  if x % 10 != 0:
    que.append(x * 10 + x % 10 - 1)
  que.append(x * 10 + x % 10)
  if x % 10 != 9:
    que.append(x * 10 + x % 10 + 1)

print(x)

Measured memory_bytes: 11908
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;
typedef long long ll;
const ll INF=10000000000000000LL;

int main() {
	int n,a,b;
	cin>>n>>a>>b;
	if((b-a)%2==0)cout<<"Alice"<<endl;
	else cout<<"Borys"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#define rep(i,n) for(int i = 0; i < n; i++)
using ll = long long;
using namespace std;
int main(){
  int N;
  cin >> N;
  for(int h = 1; h <= 3500; h++){
    for(int n = 1; n <= 3500; n++){
      double w = (double) h * n * N / (4 * h * n - N * h - N * n);
      //cout << w << endl;
      if(w - int(w) == 0 && w > 0){
        cout << h << " " << n << " " << int(w) << endl;
        return 0;
      }
    }
  }
  return 0;
}

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

using namespace std;
long long i,n,a[100001],x[100001];

int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
		cin>>a[i];
	x[1]=0;
	for(i=1;i<=n;i++)
		if(i%2==0)
			x[1]=x[1]-2*a[i];
		else
			x[1]=x[1]+2*a[i];
		x[1]=x[1]/2;
	for(i=2;i<=n;i++)
		x[i]=2*a[i-1]-x[i-1];
	for(i=1;i<=n;i++)
		cout<<x[i]<<" ";
}


Measured memory_bytes: 2816
from collections import deque
import re

gp = deque(input().split())
que = deque([])
ans = 0


while len(gp) > 0:
    e = gp.popleft()
    if re.match('\d', e): # number
        que.append(int(e))
    else: # operand
        r = que.pop() # rから先に取り出さないとテレコになる.
        l = que.pop()
        if   e == '+':
            que.append(l + r)
        elif e == '-':
            que.append(l - r)
        elif e == '*':
            que.append(l * r)
        elif e == '/':
            que.append(l / r)
print(que.pop())


Measured memory_bytes: 6528