akhauriyash/Code-Regression huggingface dataset:
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
int n;
int perm[200005];
int a[200005],b[200005];
int main(){
  cin>>n;
  REP(i,n) cin>>perm[i],--perm[i];

  REP(i,n){
    int p=perm[i];
    a[p]+=i;
    b[p]+=i;
  }
  REP(i,n) a[i+1]+=a[i];
  for(int i=n-1;i>0;--i) b[i-1]+=b[i];

  REP(i,n) a[i]+=i+1,b[i]+=n-i;

  REP(i,n) printf("%d%c",a[i],i==n-1?'\n':' ');
  REP(i,n) printf("%d%c",b[i],i==n-1?'\n':' ');
  return 0;
}





Measured memory_bytes: 1024
#include <iostream>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define lli long long int
using namespace std;
#define S second
#define F first
#define pb push_back 
#define M1 1000000007
#define M2 998244353
#define plli pair<lli,lli>
#define setit set<lli>::iterator seti
#define mapit map<lli,lli> ::iterator mapi
#define MP make_pair
#define MT make_tuple
// map      iterator->first  iterator.first
// map      mp[key]=value
// set      *s.begin()
// vector   v[j]=value
// pair     p.first p.second
// vector of pairs v[j].first v[j].second
// tuple    get<index>(tuple_name)
// vector of tuples get<index>(v[j])  sort(v.begin(),v.end())
//priority queue .top() .pop() .push()
// __gcd(x,y)
#define fr(j,a,b) for(j=a;j<b;j++)


int power(int x, unsigned int y, int p)  
{    int res = 1;    
     x = x % p;
     if (x == 0) return 0;
     while (y > 0)  
     {  if (y & 1)  
        res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
     }  
    return res;  
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    lli t,i,m,j,n,x,k,f,g,q,r,w,l;
    cin>>l;
    string s;
    cin>>s;
    map<char,lli > po;
    for(i=0;i<l;i++){
        po[s[i]]++;
    }
    if(po['G']==0||po['R']==0||po['B']==0){
        cout<<"0";
        return 0;
    }
    x=(po['G'])*(po['R'])*(po['B']);
    map<char,lli> mp;
    for(i=0;i<l-2;i++){
        mp[s[i]]=1;
        for(j=i+1;j<l-1;j++){
            if(mp[s[j]]==1||j==l-1){
                continue;
            }
            mp[s[j]]=1;
            k=(2*j)-i;
            if(k>1&&k<=l-1&&mp[s[k]]==0){
                x--;
            }
            mp[s[j]]=0;
        }
        mp[s[i]]=0;
    }
    cout<<x;
}


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

long long N,M,K,tmp,a[200002],b[200002],preb[200002];

int main(){
	cin>>N>>M>>K;
	for(long long i=0; i<N; i++){
		cin>>a[i];
	}
	for(long long i=0; i<M; i++){
		cin>>b[i];
		if(i==0)preb[i]=b[i];
		if(i!=0)preb[i]=preb[i-1]+b[i];
	}
	long long minimum=0;
	for(long long i=0; i<=N; i++){
		if(K<0)break;
		long long l=0,r=M-1,catat=0;
		while(l<=r){
			long long mid=(l+r)/2;
			if(preb[mid]>K){
				r=mid-1;
			}else{
				l=mid+1;
				catat=mid+1;
			}
		}
		minimum=max(i+catat,minimum);
		if(i==N)break;
		K-=a[i];
	}
	cout<<minimum<<'\n';
}

Measured memory_bytes: 8320
#include<iostream>
#include<algorithm>
#include<string.h>
#include<map>
#include<string>
#include<math.h>
#include<stdio.h>
#pragma GCC optimize(2)
#define Swap(a,b)  a ^= b ^= a ^= b
using namespace std;
typedef long long ll;
inline ll read() {
	ll c = getchar(), Nig = 1, x = 0;
	while (!isdigit(c) && c != '-')c = getchar();
	if (c == '-')Nig = -1, c = getchar();
	while (isdigit(c))x = ((x << 1) + (x << 3)) + (c ^ '0'), c = getchar();
	return Nig * x;
}
inline void Out(ll a)
{
	if (a < 0)putchar('-'), a = -a;
	if (a >= 10)Out(a / 10);
	putchar(a % 10 + '0');
}
int main() {
	ll a, b;
	a = read(), b = read();
		if (abs(a) == abs(b)) {//测试已过
			Out(1);
			return 0;
			//特判没有return，导致特例流入下方
		}
		if (a == 0) {//对了
			if (b > 0) {//测试完了
				Out(b);
			}
			else {//测试已过
				Out(1 - b);
			}
			return 0;
		}
		if (b == 0) {//对了
			if (a > 0) {
				Out(a + 1);//过了
			}
			else {
				Out(-a);
			}
			return 0;
		}
		if ((a / abs(a)) * (b / abs(b)) > 0) {//同号
			if (a < b) {
				Out(b - a);//对了
			}
			else {
				Out(2 + a - b);
			}
		}
		if (a / abs(a) * b / abs(b) < 0) {
			if (a < 0) {
				if (abs(a) < abs(b))//对了(-1,23)
					Out(b + a + 1);
				else
					Out(1 - b - a);
			}
			if (a > 0) {
				if (abs(a) > abs(b)) {
					Out(1 + b + a);//对了
				}
				else {
					Out(1 - b - a);//对了
				}
			}
		}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define pi 3.14159265359
int INF = 1000000000;

int main() {
  int N; cin >> N;
  vector<int> A(N), B(N), C(N-1);
  rep(i, N) {
    cin >> A[i];
  }
  rep(i, N) {
    cin >> B[i];
  }
  rep(i, N-1) {
    cin >> C[i];
  }
  int ans = 0;
  rep(i, N) {
    int n = A[i];
    ans += B[n-1];
    if (i != N-1) {
      if (A[i+1] == n+1) ans += C[n-1];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll a, b, x;
    cin >> a >> b >> x;
    if (a <= x && x <= a + b) {
        cout << "YES" << endl;
        return 0;
    } else {
        cout << "NO" << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define lop(i,a,b) for(ll i=a;i<b;i++)
using namespace std;

void func(){
    int n,x,q,b,c;
    ll sum=0;
    cin>>n;
    unordered_map<int,int>a;
    lop(i,0,n){
        cin>>x;
        a[x]++;
        sum+=x;
    }
    cin>>q;
    while(q--){
        cin>>b>>c;
        sum+=a[b]*(c-b);
        a[c]+=a[b];
        a[b]=0;
        cout<<sum<<endl;
    }
}

int main(){
    fastio;
    int t=1;
    //cin>>t;
    while(t--){
        func();
    }
}

Measured memory_bytes: 7108
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define e endl
#define MAXN 200005
#define MOD 998244353
int main()
{
     int a,b,c,d;
     cin>>a>>b>>c>>d;
     int p1=a/d+(a%d!=0);
     int p2=c/b+(c%b!=0);
     if(p1<p2)
          cout<<"No";
     else
          cout<<"Yes";
}


Measured memory_bytes: 3632
# AOJ 0005 GCD and LCM
# Python3 2018.6.9 bal4u

def lcm(a, b):
	return a // gcd(a, b) * b

def gcd(a, b):
	while b != 0:
		r = a % b
		a = b
		b = r
	return a

while True:
    try:
        a = list(map(int, input().split()))
        print(gcd(a[0], a[1]), lcm(a[0], a[1]))
    except EOFError:
        break


Measured memory_bytes: 5604
n, k = map(int, input().split())
x_list = list(map(int, input().split()))
cand = []

for i in range(n - k + 1):
    l = x_list[i]
    r = x_list[i + k - 1]
    route1 = abs(l) - l + r
    route2 = abs(r) - l + r
    cand.append(min(route1, route2))
    
print(min(cand))

Measured memory_bytes: 15020
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;

int main()
{
    int N, K;
    int data[105];
    int A[105] = {};
    int B[105] = {};
    int minv = INF;
    cin >> N >> K;
    for(int i = 1; i <= N; i++) {
        cin >> data[i];
    }
    N++;
    sort(data + 1, data + N);
    for(int i = 1; i < N; i++) {
        A[i] = A[i - 1] + data[i];
    } A[N] = A[N - 1];

    for(int i = N - 1; i >= 0; i--) {
        B[i] = B[i + 1] + (K - data[i]);
    }

    for(int i = 0; i < N; i++) {
        int suma = A[i], sumb = B[i + 1];
        minv = min(minv, suma + sumb);
    }

    cout << minv * 2 << endl;
    return (0);
}


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

using namespace std;

using ll = long long;
#define long long long

int main(void) {
    constexpr ll MOD = 1e9+7;
    ll n, k;
    cin >> n >> k;

    constexpr ll MAX=3e5;
    vector<ll> fact, ifact;
    fact.assign(MAX+1, 1);
    for(ll i=1; i<=MAX; i++)
        (fact[i] = i * fact[i-1]) %= MOD;

    ifact.assign(MAX+1, 1);
    {
        ll a = fact[MAX], b = MOD-2;
        while(b) {
            if(b&1) (ifact[MAX] *= a) %= MOD;
            (a *= a) %= MOD;
            b >>= 1;
        }
    }
    for(ll i=MAX-1; i>=0; i--)
        (ifact[i] = ifact[i+1] * (i+1)) %= MOD;
    auto comb = [&](ll a, ll b) {
        if(a < b) return 0ll;
        return (((fact[a] * ifact[b]) % MOD) * ifact[a-b]) % MOD;
    };

    ll r = 0;
    for(ll zc=0; zc<=min(n, k); zc++) {
        ll t = 1;
        (t *= comb(n, zc)) %= MOD;
        ll s = zc;
        (t *= comb(s+(n-zc)-1, s)) %= MOD;
        (r += t) %= MOD;
    }
    cout << r << endl;
}


Measured memory_bytes: 4992
#include<iostream>
using namespace std;
#define ll long long int
#define pb                 push_back
#define T int time;        scanf("%d", &time); while(time--) 


  
  int main()

{

  ll a,b;
  cin>>a>>b;
  ll ans=a*b;
  cout<<ans<<endl;

}
 
 
 
 


Measured memory_bytes: 3548
#include <iostream>

using namespace std;

int main(){
  int a, b, c;
  std::cin >> a >> b >> c;
  if(a + b == c){
    std::cout << "Yes" << '\n';
  }else if(a + c == b){
    std::cout << "Yes" << '\n';
  }else if(b + c == a){
    std::cout << "Yes" << '\n';
  }else{
    std::cout << "No" << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
  int n, k;
  while(cin>>n>>k){
    vector <ll> v, v1;
    int x;
    for(int i=0; i<n; ++i){
        cin>>x;
        if(x>0)
            v.push_back(x);
        else
            v1.push_back(-x);
    }
    ll ans=1e17;
    reverse(v1.begin(), v1.end());
    for(int i=0; i<min((int)v.size(), k-1); ++i){
        if(k-i-1 <= v1.size()){
            ans=min(ans, min(v[i], v1[k-i-2])+v[i]+v1[k-i-2]);
        }
    }
    if(v1.size()>=k){
        ans=min(ans, v1[k-1]);
    }
    if(v.size()>=k){
        ans=min(ans, v[k-1]);
    }
    cout<<ans<<endl;
  }
  return 0;
}




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

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

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

ll f(ll x, int c, int d) { 
  ll res = x;
  res -= x / c;
  res -= x / d;
  res += x / lcm(c,d);
  return res;
   }

int main() {
  ll a, b;
  int c, d;

  cin >> a >> b >> c >> d;

  ll ans = f(b, c, d) - f(a - 1, c, d);

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
//神题
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 1000010
using namespace std;
int n, ff, op, cl, d[N], ans, L, R, now;
char s1[N], s2[N];
int main(){
	scanf("%d%s%s", &n, s1+1, s2+1); s2[0]='$';
	ff=1; for(int i=1; i<=n; i++)if(s1[i]!=s2[i]){ff=0; break;}
	if(ff){printf("0"); return 0;}
	now=n; R=n;
	op=1; cl=ans=0;
	for(int i=n-1; i>=0; i--)if(s2[i]!=s2[i+1]){
		L=i+1;
		while(now&&(now>L||s1[now]!=s2[L]))now--;
		if(!now){printf("-1"); return 0;}
		while(op<=cl&&R<d[op]-(cl-op))op++;
		d[++cl]=now;
		ans=max(ans, cl-op+1);
		now--; R=i;
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 6016
H, W = map(int, input().split())

S = [input() for _ in range(H)]
vis = [[-1 for i in range(W)] for j in range(H)]

que = [(0,0)]
itr = 0
color = "."
if S[0][0]=="#":
  itr=1
  color="#"
vis[0][0]=itr
while len(que)>0:
  v, h = que.pop(0)
  itr = vis[v][h]
  if itr%2==0:
    color="."
  else:
    color="#"
  que2 = []
  if v+1 < H:
    if S[v+1][h]==color and vis[v+1][h]==-1:
      vis[v+1][h] = itr
      que2.append((v+1,h))
    elif vis[v+1][h]==-1:
      vis[v+1][h] = itr +1
      que.append((v+1,h))
  if h+1 < W:
    if S[v][h+1]==color and vis[v][h+1]==-1:
      vis[v][h+1] = itr
      que2.append((v,h+1))
    elif vis[v][h+1]==-1:
      vis[v][h+1] = itr+1
      que.append((v, h+1))
  while len(que2)>0:
    v, h = que2.pop(0)
    if v+1 < H:
      if S[v+1][h]==color and vis[v+1][h]==-1:
        vis[v+1][h] = itr
        que2.append((v+1,h))
      elif vis[v+1][h]==-1:
        vis[v+1][h] = itr +1
        que.append((v+1,h))
    if h+1 < W:
      if S[v][h+1]==color and vis[v][h+1]==-1:
        vis[v][h+1] = itr
        que2.append((v,h+1))
      elif vis[v][h+1]==-1:
        vis[v][h+1] = itr+1
        que.append((v, h+1))
    
if vis[H-1][W-1]%2 == 0:
  print(vis[H-1][W-1]//2)
else:
  print((vis[H-1][W-1]+1)//2)

Measured memory_bytes: 3192
n, d = map(int, input().split())
info = [list(map(int, input().split())) for i in range(n)]

limit = d ** 2
ans = 0
for i in range(n):
    x, y = info[i]
    tmp = x ** 2 + y ** 2
    if tmp <= limit:
        ans += 1
print(ans)

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

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

		boolean flag = true;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str[] = br.readLine().split("");
		for (int i = 0; i < str.length; i++) {
			if ((i + 1) % 2 == 0) {
				if (str[i].equals("R")) {
					System.out.println("No");
					flag = false;
					break;
				}
			} else {
				if (str[i].equals("L")) {
					System.out.println("No");
					flag = false;
					break;
				}
			}
		}
		if (flag) {
			System.out.println("Yes");
		}
	}
}

Measured memory_bytes: 21204
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define rep(i, n)for(int i=0; i<n; i++)

int main(){

  int N, K;
  cin >> N >> K;
  int p[N];
  rep(i, N)
    cin >> p[i];

  sort(p, p+N);

  int count = 0;
  rep(i, K)
    count  += p[i];
    
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 3640
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    vvi edges(n);
    vi a(n), b(n);
    for (int i = 0; i < n - 1; ++i) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        edges[a[i]].push_back(b[i]);
        edges[b[i]].push_back(a[i]);
    }
    map<pii, int> color;
    map<int, set<int>> used;
    for (int i = 0; i < n - 1; ++i) {
        int co = 1;
        for (auto &p : edges[i]) {
            pii pa = {p, i};
            if (color[pa] != 0)
                continue;
            while (used[p].count(co) == 1 || used[i].count(co) == 1)
                co++;
            color[pa] = co;
            pii ap    = {i, p};
            color[ap] = co;
            used[p].insert(co);
            used[i].insert(co);
        }
    }

    vi ret;
    int maxi = 0;
    for (int i = 0; i < n - 1; ++i) {
        pii pa = {a[i], b[i]};
        ret.push_back(color[pa]);
        chmax(maxi, color[pa]);
    }
    cout << maxi << "\n";
    for (int i = 0; i < n - 1; ++i) {
        cout << ret[i] << "\n";
    }
    // vi col(n, -1);
    // function<int(int, int)> dfs = [&](int c, int p) {
    //     set<int> used;
    //     for (auto &ne : edges[c]) {
    //         if (ne == p)
    //             continue;
    //         int col = dfs(ne, c);
    //         used.insert(col);
    //     }
    //     for (int i = 1; i <= n; ++i) {
    //         if (used.count(i) == 0) {
    //             return col[c] = i;
    //         }
    //     }
    //     return 0;
    // };
    // dfs(0, -1);
    // int mini = 0;
    // for (int i = 0; i < n; ++i) {
    //     chmax(mini, col[i]);
    // }
    // cout << mini << "\n";
    // for (int i = 0; i < n; ++i) {
    //     cout << col[i] << "\n";
    // }
    return 0;
}

Measured memory_bytes: 38528
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int M = scan.nextInt();
        int[] X = new int[M];
        for (int i = 0; i < M; i++) {
            X[i] = scan.nextInt();
        }
        Arrays.sort(X);
        if (M <= N) {
            System.out.println(0);
            return;
        }
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < M - 1; i++) {
            list.add(X[i+1]-X[i]);
        }
        list.sort(Comparator.reverseOrder());
        long answer = X[M-1] - X[0];
        long sum = 0;
        for (int i = 0; i < N - 1; i++) {
            sum += list.get(i);
        }
        System.out.println(answer - sum);
    }
}


Measured memory_bytes: 50908
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

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

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n, k;
ll a[100005];
ll mmemo[100005];
ll pmemo[100005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> k;
  REP(i, n) {
    cin >> a[i];
  }

  int sp = lower_bound(a, a + n, 0) - a;

  ll ans = LLINF;
  if(sp >= k) {
    ans = min(abs(a[sp - k]), ans);
  }
  if(n - sp >= k) {
    ans = min(abs(a[sp + k - 1]), ans);
  }
  
  REP(i, k) {
    if((sp + i) - k + 1 >= 0 && sp + i < n) {
      ll mi = min(abs(a[(sp + i) - k + 1]), abs(a[sp + i]));
      ll ma = max(abs(a[(sp + i) - k + 1]), abs(a[sp + i]));

      ans = min((mi * 2 + ma), ans);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define mod 1000000007
#define int long long

void solve() {
	int n;
	cin >> n;
	vector<double> p(n);
	int i;
	for (i = 0; i < n; i++)cin >> p[i];
	vector<vector<double>> dp(n + 1, vector<double>(n + 1));
	int j;
	for (i = 0; i <= n; i++) {
		for (j = 0; j <= n; j++)dp[i][j] = -1;
	}
	for (j = 0; j <= n; j++)dp[0][j] = 0;
	for (i = 0; i <= n; i++)dp[i][0] = 1;
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++)dp[i][j] = p[i - 1] * dp[i - 1][j - 1] + (1 - p[i - 1]) * dp[i - 1][j];
	}

	cout << setprecision(10) << dp[n][(n + 1) / 2] << endl;
	return;
}

int32_t main() {
	std::ios::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);
	solve();
	return 0;
}


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

int main() {
  int a, b, m;

  vector<int> x, y;

  vector<vector<int>> c(m, vector<int>(3));

  cin >> a >> b >> m;

  int xmin = INT_MAX, ymin = INT_MAX, cmin = INT_MAX;

  for (int i = 0; i < a; i++) {
    int tmp;
    cin >> tmp;
    x.push_back(tmp);
    xmin = min(tmp, xmin);
  }

  for (int i = 0; i < b; i++) {
    int tmp;
    cin >> tmp;
    y.push_back(tmp);
    ymin = min(tmp, xmin);
  }

  for (int i = 0; i < m; i++) {
    int xtmp, ytmp, ctmp;
    cin >> xtmp >> ytmp >> ctmp;
    cmin = min(cmin, x.at(xtmp - 1) + y.at(ytmp - 1) - ctmp);
  }

  cout << min(xmin + ymin, cmin);

  return 0;
}

Measured memory_bytes: 345852
#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#include <string>
#include <algorithm>
using namespace std;
#define ll long long
char mp[2005][2005];
int mp_zong[2005][2005];
int mp_heng[2005][2005];
int n, m;
int maxx = 0;
ll f(ll n)
{
    if (n % 4 == 0)
        return n;
    else if (n % 4 == 1)
        return 1;
    else if (n % 4 == 2)
        return n + 1;
    else if (n % 4 == 3)
        return 0;
}
int main()
{
    ll a, b;
    cin >> a >> b;
    cout << (f(a - 1) ^ f(b)) << endl;
    return 0;
}

Measured memory_bytes: 888
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        int n= int.Parse(Console.ReadLine());
        var s = Console.ReadLine().Split();
        Console.WriteLine(string.Join("", s[0].Zip(s[1], (x, y) => $"{x}{y}")));
    }
}


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

using namespace std;

long long n, p;

inline bool is_prime(long long x)
{
    if(x == 1) return false;
    if(x == 2 || x == 3) return true;
    if(n%6 != 1 && n%6 != 5) return false;
    for(long long i = 5; i*i <= n; i += 6)
        if(n%i == 0 || n%(i+2) == 0) return false;
    return true;
}

int main()
{
    cin >> n >> p;
    if(n == 1) return printf("%lld\n", p)&0;
    if(is_prime(p)) return puts("1")&0;
    long long ans = 1;
    for(long long i = 2, cnt; i*i <= p; ++i)
    {
        cnt = 0;
        for(; p%i == 0; p /= i, ++cnt);
        for(int j = 1; j <= cnt/n; ++j) ans *= i;
        if(is_prime(p)) break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
S = list(input())
T = list(input())

change_num_array = []
for j in range(0, len(S)-len(T)+1):
    change_num = 0
    for i in range(len(T)):
        if S[j+i] != T[i]:
            change_num += 1
    change_num_array.append(change_num)
print(min(change_num_array))


Measured memory_bytes: 9100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(v) (v).begin(), (v).end()

int main()
{
  int a, b, c; cin >> a >> b >> c;
  if (a == b and b == c) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=x && x<w && 0<=y && y<h)

const int INF = 10000000;
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
using namespace std;
typedef pair<int, int> P;

/** Problem0501 : Data Conversion **/
int main()
{
	map<string, string> list;
	int n;
	while (cin>>n, n) {
		list.clear();
		rep(k, n) {
			string from, to;
			cin>>from>>to;
			list[from]=to;
		}
		int m;
		cin>>m;
		rep(k, m) {
			string c;
			cin>>c;
			if (list[c] != "") {
				cout<<list[c];
			} else {
				cout << c;
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 1216
using System;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;

class Program
{
	static List<StringBuilder> SBList;

	static void Plus(string str, int num){
			StringBuilder S1 = new StringBuilder(str);
			StringBuilder S2 = new StringBuilder(str);
			int length = str.Length;

			//最終インデックスの場合
			if(num == length){
					SBList.Add(S1);
			}
			//それ以前の場合
			else{
					//分割するヴァージョンはS1
					S1.Insert(num, "+");
					Plus(S1.ToString(), num+2);

					//分割しないヴァージョンはS2
					Plus(S2.ToString(), num+1);
			}
	}

	//Main
	static void Main(string[] args)
	{
		//読み込む
		string S = Console.ReadLine();

		//分割した文字を格納するリスト
		SBList = new List<StringBuilder>();

		//再帰的処理
		Plus(S, 1);

		//順次加算
		long answer = 0;
		foreach(StringBuilder s in SBList){
				long[] formula = s.ToString().Split('+').Select(i => long.Parse(i)).ToArray();
				foreach(long n in formula){
						answer += n;
				}
		}
		Console.WriteLine(answer);
	}
}



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

#define rep(i, x, n) for(int i=(x);i<(n);i++)
#define reps(i, x, n) for(int i=(x);i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDigit(a,b) (a+b-1)/b //小数点切り上げ
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){ return (y != 0 ? gcd(y, x % y) : x); }
//最小公倍数
lol lcm(lol x, lol y){ return ((x * y) / gcd(max(x, y), min(x, y))); }

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  string s;
  cin >> s;
  cout << s;
  if(s[s.size() - 1] == 's'){
    cout << 'e';
  }
  cout << "s\n";
  return 0;
}


Measured memory_bytes: 3648
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = list(input())

from itertools import groupby
from math import ceil

answer = 0
for i in range(K):
    for key,group in groupby(T[i::K]):
        if key == "r":
            answer += P * ceil(len(list(group))/2)
        elif key == "s":
            answer += R * ceil(len(list(group))/2)
        elif key == "p":
            answer += S * ceil(len(list(group))/2)

print(answer)

Measured memory_bytes: 5560
#include<bits/stdc++.h>
    using namespace std;
    #define rep(i, l, r) for (int i = l; i<r;i++)
    #define dec(i, l, r) for (int i = l; i>=r;i--)
    #define vi vector<int>
    #define all(v) v.begin(),v.end()
    #define pb(c) push_back(c)
    #define vii vector<pair<int,int>>
    #define ii pair<int,int>
    #define mp(i, j) make_pair(i,j)
    #define ull unsigned long long int
    #define ll  long long int
    #define pie 3.141592653589793238
    #define inf ((ll)1e18)
    #define eps 1e-14
    #define mod ((int)1e9+7)
    #define maxlg 18
    #define maxn 1000002
    #define left(i) ((i)<<1)
    #define right(i) (((i)<<1)+1)
    ll perm[maxn];
    ll invPerm[maxn];
    ll mod_pow(ll x, ll y)
    {
        // exponentiation by squaring
        ll r = 1;
        while (y > 0) {
            if (y % 2 == 1) {
                r = (r*x) % mod;
            }
            x = (x*x) % mod;
            y /= 2;
        }
        return r%mod;
    }
    int arr[maxn],pos[maxn];
    inline ll comb(int n,int k) {
        if (k>n)return 0;
        return (((perm[n]*invPerm[k])%mod)*invPerm[n-k])%mod;
    }
    int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(nullptr);
    #ifndef ONLINE_JUDGE
     #endif
        perm[0] = 1;
        invPerm[0] = 1;
        rep (i,1,maxn) {
            perm[i] = (perm[i-1]*i)%mod;
            invPerm[i] = mod_pow(perm[i],mod-2)%mod;
        }
        int n;
        cin>>n;
        int num;
        int afterSame=0;
        rep (i,0,n+1) {
            int g;
            cin>>g;
            if (arr[g] && afterSame==0) {
                afterSame=1;
                num = g;
            } else if (afterSame!=0) {
                afterSame++;
            } else {
                pos[g]=i;
            }
            arr[g] = true;
        }
        afterSame--;
        rep (i,1,n+2) {
            ll ans = comb(n+1,i) +mod- comb(afterSame+pos[num],i-1);
            cout<<ans%mod<<endl;
        }
        return 0;
    }

Measured memory_bytes: 23040
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
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 vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
/* END OF TEMPLATE */

ll val(ll n, vll& a, vll& b){
    ll ret = 0;
    ll cnt = 0;
    rep(i, 3*n){
        if(!b[i]){
            if(cnt >= n) ret -= a[i];
            else ret += a[i];
            cnt++;
        }
    }
    return ret;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vll a(3*n);
    rep(i, 3*n){
        cin >> a[i];
    }
    /*
    vll b(3*n, 0);
    repr(i, 2*n, 3*n){
        b[i] = 1;
    }
    ll ans = -INF;
    do{
        ans = max(ans, val(n, a, b));
    }while(next_permutation(ALL(b)));
    */
    multiset<ll> pls, mns, mgb;
    rep(i, n){
        pls.emplace(a[i]);
    }
    repr(i, n, 3*n){
        mgb.emplace(a[i]);
    }
    rep(i, n){
        mns.emplace(*mgb.begin());
        mgb.erase(mgb.begin());
    }
    ll ans = 0;
    for(auto e: pls){
        ans += e;
    }
    for(auto e: mns){
        ans -= e;
    }
    ll ansmax = ans;
    rep(i, n){
        auto mf = mns.find(a[i+n]);
        if(mf != mns.end()){
            ans += a[i+n];
            ans -= *mgb.begin();
            ans += a[i+n];
            mns.erase(mf);
            mns.emplace(*mgb.begin());
            mgb.erase(mgb.begin());
            pls.emplace(a[i+n]);
            ans -= *pls.begin();
            pls.erase(pls.begin());
        }else{
            ans += a[i+n];
            mgb.erase(mgb.find(a[i+n]));
            pls.emplace(a[i+n]);
            //dump2(a[i+n], *pls.begin());
            ans -= *pls.begin();
            pls.erase(pls.begin());
        }
        //dump(ans);
        ansmax = max(ansmax, ans);
    }
    cout << ansmax << endl;
    return 0;
}

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

int main(){
    int N; cin >> N;
    for (int _ = 0; _ < N*2;_ += 2){
        string A,B;
        cin >> A >> B;
        
        vector<vector<int>> dp(A.size() +1 ,vector<int> (B.size() + 1,0));
        for (int i = 0;i < A.size();i ++){
            for(int j = 0; j < B.size(); j++){
                if(A[i] == B[j]) dp[i + 1][j + 1] = dp[i][j] + 1;
                else dp[i + 1][j + 1] = max(dp[i][j + 1],dp[i + 1][j]);
            }
        }
        cout << dp[A.size()][B.size()] << endl;
    }
}


Measured memory_bytes: 6816
i = $<.read

order, *works = i.split("\n").map do |e|
  a, b = e.split
  [a, b.to_i]
end

c = 0
while works.size > 0
  k, v = works.shift
  c += v < order[1] ? v : order[1]
  v -= order[1]
  v <= 0 ? (puts "#{k} #{c}") : works << [k, v]
end

Measured memory_bytes: 21536
#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector> 
#include <string.h>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long
#define asort(a) sort(a.begin(),a.end());

using namespace::std;

int jo(ll int jxo, ll int jyo){//累乗
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){//char大文字化
  return (toxbig-0x20);
}
char tolow(char toxlow){//char小文字化
  return (toxlow+0x20);
}
int ctoi(char cctoi){//char->int
  if('0' <= cctoi && cctoi <= '9') return (cctoi-'0');
  return -1;
}
int gcd(int gcad, int gcbd) {//最大公約数
  if(gcad < gcbd) return gcd(gcbd, gcad);
  int gcrd;
  while ((gcrd=gcad%gcbd)) {
    gcad = gcbd;
    gcbd = gcrd;
  }
  return gcbd;
}
int lcm(int lcam, int lcbm){//最小公倍数
 return (lcam*lcbm)/gcd(lcam,lcbm);
}


int main(){
  int N;
  cin>>N;
  int ans=1;
  vector<int> H(N);
  rep(i,0,N) cin>>H[i];
  int mH=H[0];
  rep(i,1,N){
    if(mH<=H[i]){
      ans++;
      mH=H[i];
    }
  }
  cout<<ans;
    

}
// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


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

public class Main {
    static StringTokenizer st;
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static long[][] dp;

    public static void main(String[] args) throws IOException {
        String s = next();
        String t = next();

        dp = new long[3010][3010];

        for (long[] longs : dp) {
            Arrays.fill(longs, 0);
        }

        // 文字数
        for (int i = 0; i < s.length(); i++) {
            for (int j = 0; j < t.length(); j++) {
                dp[i + 1][j + 1] = s.charAt(i) == t.charAt(j)
                        ? max(dp[i + 1][j + 1], dp[i][j] + 1)
                        : dp[i + 1][j + 1];

                dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j]);
                dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1]);
            }
        }

        // 復元
        String result = "";
        int i = s.length();
        int j = t.length();
        while (i > 0 && j > 0) {
            if (dp[i][j] == dp[i - 1][j]) { // (i-1, j) -> (i, j) と更新されていた場合
                i--;
            } else if (dp[i][j] == dp[i][j - 1]) { // (i, j-1) -> (i, j) と更新されていた場合
                j--;
            } else { // (i-1, j-1) -> (i, j) と更新されていた場合
                result = s.charAt(i - 1) + result;
                i--;
                j--;
            }
        }
        System.out.println(result);
    }

    static char nextChar() throws IOException {
        return next().charAt(0);
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static int[] readArray(int n) throws IOException {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    static long[] readLongArray(int n) throws IOException {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextLong();
        }
        return a;
    }

    static String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine().trim());
        }
        return st.nextToken();
    }

    static int Char2Int(Character c) {
        return Character.getNumericValue(c);
    }

    static double Char2Double(Character c) {
        return (double) Char2Int(c);
    }

    static int nCr(int n, int r) {
        return fact(n) / (fact(r) * fact(n - r));
    }

    // Returns factorial of n
    static int fact(int n) {
        int res = 1;
        for (int i = 2; i <= n; i++) {
            res = res * i;
        }
        return res;
    }

    static int gcd(int a, int b) {
        if (b == 0) {
            return a;
        } else {
            a = a % b; // 残り部分
            return gcd(b, a); // 残り部分から最小の正方形を見つける
        }
    }
}

Measured memory_bytes: 128388
#include <iostream>
#include <vector>
#include <string>

using namespace std;

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

	int ans = N;

	for (int i = 0; i < N - 1; i++)
	{
		if (S.at(i) == S.at(i + 1))
		{
			--ans;
		}
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int n,x,y,m,l,z,s;
char d;
int main(){
	while(cin>>n){
		if(n==0) break;
		int a[n];
		for(int i=0;i<n;i++){
			cin>>x>>y;
			a[i]=30*x+y+1;
		}
		cin>>m;
		z=311;
		for(int i=0;i<m;i++){
			cin>>d>>l;
			if(d=='N'){
				for(int j=0;j<l;j++){
					z++;
					for(int k=0;k<n;k++){
						if(a[k]==z) a[k]=0;
					}
				}
			}
			else if(d=='S'){
				for(int j=0;j<l;j++){
					z--;
					for(int k=0;k<n;k++){
						if(a[k]==z) a[k]=0;
					}
				}
			}
			else if(d=='E'){
				for(int j=0;j<l;j++){
					z=z+30;
					for(int k=0;k<n;k++){
						if(a[k]==z) a[k]=0;
					}
				}
			}
			else if(d=='W'){
				for(int j=0;j<l;j++){
					z=z-30;
					for(int k=0;k<n;k++){
						if(a[k]==z) a[k]=0;
					}
				}
			}
		}
		s=0;
		for(int i=0;i<n;i++){
			s=s+a[i];
		}
		if(s==0){
			cout<<"Yes"<<endl;
		} else{
			cout<<"No"<<endl;
		}
	}
    return 0;
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

ll N, A;
ll ret;
map<pair<ll,ll>, ll> dp;

ll calc(ll x, ll la)
{
	if (x >= N) return 1;
	if (dp.count(mp(x,la))) return dp[mp(x,la)];
	ll u = (N+x-1) / x;

	if (la == -1) {
		for (ll i = 2; i <= 1000010; ++i) {
			u = min(u, calc(i, i) + A + i);
		}
	} else {
		u = min(u, calc(x*la, la) + A + la);
		if (la > 2) u = min(u, calc(x*(la-1), la-1) + A + la-1);
	}

	return dp[mp(x,la)] = u;
}

int main() {
	cin >> N >> A;
	ret = N;

	//if (N>1000000) return 0;


	for (ll i = 2; i <= 1000010; ++i) {
		ll u = 1;
		ll m = LLONG_MAX;
		ll c = 0;

		while (true) {
			u *= i;
			c += A + i;

			m = min(m, c + (N+u-1)/u);

			if (u >= N) break;
		}

		ret = min(ret, m);
	}

	for (ll i = 2; i <= min(1000010LL, N); ++i) {
		ll lo = 1, hi = N;
		while (hi-lo>1) {
			ll m=(lo+hi)/2;
			if ((N+m-1)/m>=i) {
				lo = m;
			} else hi = m;
		}
		//ret = min(ret, lo+A+i);
	}

	cout << min(ret, calc(1,-1)) << endl;

	return 0;
}

Measured memory_bytes: 194432
import java.util.*;
 
public class Main { 
	public static int[][][] syougens;
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		syougens = new int[n][][];
		for(int i=0; i<n; i++){
			int a = sc.nextInt();
			if(a==0) continue;
			int[][] syougen = new int[a][2];
			for(int j=0; j<a; j++){
				syougen[j][0] = sc.nextInt();
				syougen[j][1] = sc.nextInt();
				syougens[i] = syougen;
			}
		}
		bitSearch(n);
	}

	static void bitSearch(int n) {
		int ans = 0;
		for (int i = 0; i < (Math.pow(2, n)); i++) {
			boolean[] flags = new boolean[n];
			int count = n;
			for (int j = 0; j < n; j++) {
				if ((1 & i >> j) == 1) {
					flags[j] = true;
				} else {
					flags[j] = false;
					count--;
				}
			}
			boolean flag = true;
			for(int ss = 0; ss<syougens.length; ss++){
				if(syougens[ss]==null) continue;
				for(int s=0; s<syougens[ss].length; s++){
					if(flags[ss]){
						int target = syougens[ss][s][0];
						int syougen = syougens[ss][s][1];
						if(!flags[target-1] && syougen == 1){
							flag = false;
						} else if(flags[target-1] && syougen == 0){
							flag = false;
						}
					}
				}
			}
			if(flag) ans = Math.max(ans, count);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 25516
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>

using namespace std;

int main() {
	string s, t, y;
	int i, j, n, m, k;
	bool flag = false;
	vector<string> x;
	
	cin >> s >> t;

	n = s.length();
	m = t.length();

	for (i = 0; i <= n - m; i++) {
		y = s;
		if (y[i] == t[0] || y[i]=='?') {
			for (j = 1; j < m; j++) {
				if (y[i + j] != t[j] && y[i + j] != '?') {
					break;
				}
			}
			if (j == m) {
				for (j = 0; j < m; j++) {
					y[i + j] = t[j];
				}
				flag = true;
				for (k = 0; k < n; k++) {
					if (y[k] == '?')
						y[k] = 'a';
				}
				x.push_back(y);
			}
		}
	}

	if (x.size() != 0) {
		sort(x.begin(), x.end());
		cout << x[0];
	}
	else {
		cout << "UNRESTORABLE";
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#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 SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

int seg_n;

P dat0[2 * (1 << 20) - 1];
P dat1[2 * (1 << 20) - 1];

void seg_init(int n_, P dat[])
{
    seg_n = 1;
    while (seg_n <= n_)
        seg_n *= 2;

    for (int i = 0; i < 2 * seg_n - 1; i++)
        dat[i] = {INT_MAX, -1};
}

void seg_update(int k, int a, P dat[])
{
    int k_ = k;
    k += seg_n - 1;
    dat[k] = {a, k_};
    while (k > 0)
    {
        k = (k - 1) / 2;
        dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
}

P seg_query(int a, int b, int k, int l, int r, P dat[])
{
    if (r <= a || b <= l)
        return {INT_MAX, -1};

    if (a <= l && r <= b)
        return dat[k];
    else
    {
        P vl = seg_query(a, b, k * 2 + 1, l, (l + r) / 2, dat);
        P vr = seg_query(a, b, k * 2 + 2, (l + r) / 2, r, dat);

        return min(vl, vr);
    }
}

int n, p[212345];

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

    cin >> n;

    seg_init(n, dat0);
    seg_init(n, dat1);

    REP(i, n)
    {
        cin >> p[i];
        seg_update(i, p[i], (i % 2 ? dat1 : dat0));
    }

    priority_queue<pair<int, P>> q;

    V res;

    q.push({seg_query(0, n, 0, 0, seg_n, dat0).first, {0, n - 1}});

    while (q.size())
    {
        auto qq = q.top().second;
        q.pop();

        int f = qq.first;
        int e = qq.second;

        P l = seg_query(f, e + 1, 0, 0, seg_n, (f % 2 ? dat1 : dat0));

        P r = seg_query(l.second + 1, e + 1, 0, 0, seg_n, ((l.second + 1) % 2 ? dat1 : dat0));

        res.push_back(l.first);
        res.push_back(r.first);

        P m;

        if (f < l.second - 1)
        {
            m = seg_query(f, l.second, 0, 0, seg_n, (f % 2 ? dat1 : dat0));
            q.push({-m.first, {f, l.second - 1}});
        }

        if (l.second + 1 < r.second - 1)
        {
            m = seg_query(l.second + 1, r.second, 0, 0, seg_n, ((l.second + 1) % 2 ? dat1 : dat0));
            q.push({-m.first, {l.second + 1, r.second - 1}});
        }

        if (r.second + 1 < e)
        {
            m = seg_query(r.second + 1, e + 1, 0, 0, seg_n, ((r.second + 1) % 2 ? dat1 : dat0));
            q.push({-m.first, {r.second + 1, e}});
        }
    }

    //vector<P> res = solve(0, n - 1);

    //SORT(pv);

    //REP(i, n / 2)
    //cout << res[i].first << " " << res[i].second << (i == n - 1 ? "\n" : " ");

    REP(i, n)
    cout << res[i] << (i == n - 1 ? "\n" : " ");

    return 0;
}

Measured memory_bytes: 15244
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define rep(I, N) for (int I = 1; I <= (N); ++I)
#define repp(I, N) for (int I = 0; I < (N); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORR(I, A, B) for (int I = (A); I >= (B); I--)
#define SORT_UNIQUE(c) (sort(c.begin(), c.end()), c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define GET_POS(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin())
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
const int N = 2e5 + 5;
const double eps = 1e-7;
const int mod = 1e9 + 7;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
int a[N];
map<int, int> mp;
LL dp[N];
int main()
{
    int n, m;
    cin >> n >> m;
    rep(i, m)
    {
        cin >> a[i];
        mp[a[i]] = 1;
    }
    if (mp[1] && !mp[2])
    {
        dp[1] = 0;
        dp[2] = 1;
    }
    else if (mp[1] && mp[2])
    {
        dp[1] = 0;
        dp[2] = 0;
    }
    else if (!mp[1] && mp[2])
    {
        dp[1] = 1;
        dp[2] = 0;
    }
    else
    {
        dp[1] = 1;
        dp[2] = 2;
    }
    for (int i = 3; i <= n; i++)
    {
        if(!mp[i - 2])
            dp[i] = (dp[i] + dp[i - 2]) % mod;
        if(!mp[i - 1])
            dp[i] = (dp[i] + dp[i - 1]) % mod;
    }
    cout << dp[n] % mod << endl;
    return 0;
}


Measured memory_bytes: 5888
use proconio::{fastout, input};
#[allow(unused_mut)]
#[fastout]
fn main() {
    input! {
        n: usize,
        v: [usize; n]
    }
    let mut v: Vec<usize> = v;
    v.sort();
    let mut res1 = v
        .iter()
        .skip(1)
        .fold(v[0] as f64, |sum, &i| (sum + i as f64) / 2.);
    let mut res = v[0] as f64;
    for i in 1..n {
        res = (res + v[i] as f64) / 2.;
    }
    println!("{:.12}", res1);
}


Measured memory_bytes: 2232
#include <stdio.h>

int main(){
	int a,b,k;
	scanf("%d%d%d",&a,&b,&k);
	for(int i=0;i<k;i++){
		if(i%2==0)b+=a=a/2;
		else a+=b=b/2;
	}
	printf("%d %d",a,b);
}

Measured memory_bytes: 128
#include<stdio.h>

int N, K;
int Snake[1000000];

int main(void){
	int i, j, c, sum;
	scanf("%d %d", &N, &K);


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

	for( i = 0; i < N-1; i++){
		for(j = i + 1; j < N; j++){
			if(Snake[i] <= Snake[j] ){
				c = Snake[j];
				Snake[j] = Snake[i];
				Snake[i] = c;
			}
		}}

	sum = 0;
	for(i = 0; i < K; i++){
		sum += Snake[i];
	}
	printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n; cin >> n;
  if (n < 7) return cout << -1 << '\n', 0;
  V<lint> d(n); for (int i = 0; i < n; i++) cin >> d[i];
  map<lint, int> invd; for (int i = 0; i < n; i++) invd[d[i]] = i;
  set<lint> s; for (int i = 0; i < n; i++) s.insert(d[i]);
  VV<> g(n);
  V<> c(n, 1);
  while (!s.empty()) {
    int v = invd[*--s.end()];
    if (!s.count(d[v] - (n - 2 * c[v]))) break;
    int w = invd[d[v] - (n - 2 * c[v])];
    c[w] += c[v];
    g[v].push_back(w);
    g[w].push_back(v);
    s.erase(--s.end());
  }
  V<> d0(n, -1);
  queue<int> que;
  d0[0] = 0; que.push(0);
  while (!que.empty()) {
    int v = que.front(); que.pop();
    for (int w : g[v]) if (d0[w] == -1) {
      d0[w] = d0[v] + 1; que.push(w);
    }
  }
  for (int i = 0; i < n; i++) if (d0[i] == -1) return cout << -1 << '\n', 0;
  if (accumulate(d0.begin(), d0.end(), 0LL) != d[0]) return cout << -1 << '\n', 0;
  for (int v = 0; v < n; v++) for (int w : g[v]) if (v < w) cout << v + 1 << ' ' << w + 1 << '\n';
}

Measured memory_bytes: 16384