akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

#define MAX 500000
#define SENTINEL 2000000000

int cnt;
int L[(MAX/2)+2];
int R[(MAX/2)+2];

void marge(int[],int,int,int);
void margeSort(int[],int,int);


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

  margeSort(A,0,n);

  for(i=0;i<n-1;i++)
    {
      printf("%d ",A[i]);
    }
  printf("%d\n",A[i]);

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

  return 0;
}

void marge(int A[],int left,int mid,int right)
{
  int i,j,k,n1,n2;

   n1=mid-left;
   n2=right-mid;
  for(i=0;i<n1;i++)L[i]=A[left+i];
  for(i=0;i<n2;i++)R[i]=A[mid+i];
  L[n1]=SENTINEL;
  R[n2]=SENTINEL;
  i=0;
  j=0;
  for(k=left;k<right;k++)
    {
      cnt++;
      if(L[i]<=R[j]){
	A[k]=L[i++];
      }
      else {
	A[k]=R[j++];
      }
    }
}

void margeSort(int A[],int left,int right)
{
  int mid;  
  if(left+1<right){
    mid = (left+right)/2;
    margeSort(A,left,mid);
    margeSort(A,mid,right);
    marge(A,left,mid,right);
  }
}

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

int main() {
  int sx, sy, tx, ty;
  using std::string;
  std::cin >> sx >> sy >> tx >> ty;
  int dx = tx - sx, dy = ty - sy;
  std::cout
    << string(dy, 'U')
    << string(dx, 'R')
    << string(dy, 'D')
    << string(dx + 1, 'L')
    << string(dy + 1, 'U')
    << string(dx + 1, 'R')
    << "DR"
    << string(dy + 1, 'D')
    << string(dx + 1, 'L')
    << 'U'
    << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pi pair<int,int>
#define mp make_pair
//#define int long long
#define endl '\n'
 
using namespace std;
int n,k,l;
 
int idrd[(int)2.1e5],idral[(int)2.1e5];
 
void initialize()
{
    for(int i = 1;i <= n;++i)
        idrd[i] = i,idral[i]=i;
}
 
int rootroad(int x)
{
    /*while(idrd[x] != x)
    {
        idrd[x] = idrd[idrd[x]];
        x = idrd[x];
    }
    return x;*/
    if(idrd[x]==x) return x;
    return idrd[x]=rootroad(idrd[x]);
}
 
int rootrail(int x)
{
    /*while(idral[x] != x)
    {
        idral[x] = idral[idral[x]];
        x = idral[x];
    }
    return x;*/
  if(idral[x]==x) return x;
   return idral[x]=rootrail(idral[x]);
}
 
 
void unionrd(int x, int y)
{
    int p = rootroad(x);
    int q = rootroad(y);
    idrd[p] = idrd[q];
}
 
void unionrail(int x, int y)
{
    int p = rootrail(x);
    int q = rootrail(y);
    idral[p] = idral[q];
}
vector< pair<pi,int> > s;
 
int ans[200005];
 
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n>>k>>l;
    int x,y;
    initialize();
    for(int i=0;i<k;++i)
    {
        cin>>x>>y;
 
        unionrd(x,y);
    }
    for(int i=0;i<l;++i)
    {
        cin>>x>>y;
 
 
        unionrail(x,y);
    }
    for(int i=1;i<=n;++i)
    {
        pair<pi,int> xp= mp(mp(rootrail(i),rootroad(i)) , i);
        s.push_back(xp);
    }
   sort(s.begin(),s.end());
    for(int i=1;i<=n;++i)
    {
        pi xp= mp(rootrail(i),rootroad(i));
 
        // a1=distance(s.begin(),s.lower_bound(mp(xp,0)));
        auto a1=lower_bound(s.begin(),s.end(),mp(xp,0));
        //int a2=distance(s.begin(),s.upper_bound(mp(xp,312345)));
       auto a2=upper_bound(s.begin(),s.end(),mp(xp,312345));        
//cout<<i<<" "<<a1<<" "<<a2<<endl;
        cout<<a2-a1<<" ";
    }
    return 0;
}

Measured memory_bytes: 4980
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define endl '\n'
#define ld long double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define FI(i,n) for (ll i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }
 
// I want to be the very best, like no one ever was, I will battle everyday to claim my rightful place
// Not gonna give up until it's over
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
// I am questioning life and universe and 
// everything else after looking at this

const ll MAXN = 21;
ll n,a[MAXN][MAXN];
ll dp[1<<20];

void solve(){
    cin>>n;

    FOR(i,0,n-1) FOR(j,0,n-1) cin>>a[i][j];

    FOR(i,0,(1<<n)-1){
        FOR(j,0,n-1){
            FOR(k,j+1,n-1){
                if((i>>j)&1 && (i>>k)&1) dp[i] += a[j][k];
            }
        }
    }

    FOR(i,0,(1<<n)-1){
        for(ll first_gp=i;first_gp>=0;first_gp=i&(first_gp-1)){
            ll second_gp = i^first_gp;
            dp[i] = max(dp[i],dp[first_gp] + dp[second_gp]);
            if(first_gp == 0) break;
        }
    }

    cout<<dp[(1<<n)-1]<<endl;
}

signed main(){
 
   FastRead;    
 

    ll t;
    t = 1; 
    // cin>>t;
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}

Measured memory_bytes: 768
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.ResolverStyle;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
//        long startTime = System.currentTimeMillis();
        Scanner scanner = new Scanner(System.in);

        String S = scanner.next();
        scanner.close();

        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
        formatter.withResolverStyle(ResolverStyle.LENIENT);

        LocalDate tDate = LocalDate.parse("2019/04/30", formatter);
        LocalDate ldt = LocalDate.parse(S, formatter);

        if (ldt.isEqual(tDate) || ldt.isBefore(tDate)) {
            System.out.println("Heisei");
        } else {
            System.out.println("TBD");
        }
//        System.out.println(System.currentTimeMillis() - startTime);
    }
}

Measured memory_bytes: 29264
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<random>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include <queue>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree, chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun

#define REP(i,a,b) for(int i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")

/*
int N,M;
vector<ll> A;
vector<ll> S;

pair<ll,ll> f(ll x) {
	ll ans = 0, tot = 0;
	for (ll a : A) {
		auto itr = lower_bound(A.begin(), A.end(), x - a);
		ll d = distance(A.begin(), itr);
		ll c = A.size() - d;
		tot += S[A.size()] - S[d];
		tot += a * c;
		ans += c;
	}
	return pair<ll, ll>(tot, ans);
}

ll bins(ll m) {
	ll l = 0;
	ll r = 10000000;
	while (r - l > 1) {
		ll mid = (r + l) / 2;
		ll tmp = f(mid).second;
		if (tmp >= m) l = mid;
		else r = mid;
	}
	return l;
}

ll solve(ll L) {
	auto p = f(L);
	ll ans = p.first;
	ans -= (p.second - M) * L;
	return ans;
}*/

int main() {
	/*
	cin >> N >> M;
	A.resize(N);
	REP(i, 0, N) cin >> A[i];
	sort(A.begin(), A.end());
	S.resize(N+1);
	S[0] = 0;
	REP(i, 1, N + 1)S[i] = S[i - 1] + A[i - 1];
	PRI(solve(bins(M)));*/
	int n;
	ll m;
	cin >> n >> m;
	vector<int> a(n);
	REP(i, 0, n)cin >> a[i];
	sort(a.begin(), a.end());
	vector<ll> s(n + 1);
	s[0] = 0;
	REP(i, 0, n) s[i + 1] = s[i] + a[i];

	auto calc = [&](int x) {
		ll tot = 0, num = 0;
		REP(i, 0, n) {
			auto itr = lower_bound(a.begin(), a.end(), x - a[i]);
			int d = distance(a.begin(), itr);
			num += n - d;
			tot += s[n] - s[d];
			tot += a[i] * (ll)(n - d);
		}
		return pair<ll, ll>(tot, num);
	};
	int l = 0, r = 10000000;
	while (l + 1 < r) {
		int c = (l + r) / 2;
		if (calc(c).second >= m) l = c; else r = c;
	}
	auto p = calc(l);
	ll ans = p.first;
	ans -= (p.second - m) * l;
	PRI(ans);
	return 0;
}




Measured memory_bytes: 4560
#include <stdio.h>

int main(void) {
  char s[4];
  int a = 0, i;

  for (i = 0; i < 4; i++) {
    scanf("%c", &s[i]);
    if (s[i] == '+') {
      a++;
    }else {
      a--;
    }
  }

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

  return 0;
}

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

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


Measured memory_bytes: 3568
a = int(input())
b = int(input())
c = int(input())
x = int(input())
cnt = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i+100*j+50*k==x:
                cnt += 1
print(cnt)

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

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

typedef int64_t ll;

int solve(int N, const vector<ll>& A, const vector<ll>& B) {
  vector<ll> difp, difm;
  REP(i,N){
    ll tmp = A[i] - B[i];
    if(tmp >= 0) difp.push_back(tmp);
    else difm.push_back(tmp);
  }
  sort(difp.rbegin(), difp.rend());

  if(difm.empty()) return 0;

  ll sum = 0;
  for(ll e: difm) {
    sum += e;
  }
  REP(i, difp.size()) {
    sum += difp[i];
    if(sum >= 0) return i + difm.size() + 1;
  }
  return -1;
}

int main(){
  int N;
  cin >> N;
  vector<ll> A(N), B(N);
  REP(i,N) cin >> A[i];
  REP(i,N) cin >> B[i];

  cout << solve(N, A, B) << endl;
  return 0;
}



Measured memory_bytes: 2936
#include <iostream>
#include <vector>
#define inf 1000000000

using namespace std;

struct edge{
	int dist, cost;
	edge(int d, int c){
		dist = d, cost = c;
	}
};

int n;
int p[805], d[805];
vector<edge> G[805];

int dist[805][805];
int memo[805][805];

int calc(int cur, int prev)
{
	if(memo[cur][prev] != -1) return memo[cur][prev];
	
	int ret = 0, res;
	for(int i = 0; i < G[cur].size(); i++){
		if(G[cur][i].dist == prev) continue;
		res = calc(G[cur][i].dist, cur);
		if(res) ret += G[cur][i].cost*2;
		ret += G[cur][i].cost + res;
	}
	return memo[cur][prev] = ret;
}

void cdist(int s, int cur, int prev, int d)
{
	dist[s][cur] = d;
	for(int i = 0; i < G[cur].size(); i++){
		if(G[cur][i].dist == prev) continue;
		cdist(s, G[cur][i].dist, cur, d + G[cur][i].cost);
	}
}

int main(void)
{
	while(1){
		cin >> n;
		if(n == 0) break;
		
		for(int i = 2; i <= n; i++) cin >> p[i];
		for(int i = 2; i <= n; i++) cin >> d[i];
		
		for(int i = 1; i <= n; i++) G[i].clear();
		for(int i = 2; i <= n; i++){
			G[i].push_back(edge(p[i], d[i]));
			G[p[i]].push_back(edge(i, d[i]));
		}
		
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++){
				dist[i][j] = inf;
			}
		}
		for(int i = 1; i <= n; i++) cdist(i, i, -1, 0);
		
		
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++){
				memo[i][j] = -1;
			}
		}
		
		int ans = inf, cost1, cost2;
		for(int i = 1; i <= n; i++){
			if(G[i].size() == 1) continue;
			for(int j = 1; j <= n; j++){
				if(G[j].size() == 1) continue;
				ans = min(ans, calc(i, i) - (dist[i][j]));
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 8292
def search(l, n):
    left = 0
    right = len(l) - 1
    while right - left > 1:
        m = (left + right) // 2
        if n == l[m]:
            return True
        elif n < l[m]:
            right = m
        else:
            left = m

    # print(left, right)
    if l[left] == n or l[right] == n:
        return True
    else:
        return False


n = int(input())
s = [int(i) for i in input().split()]
q = int(input())
t = [int(i) for i in input().split()]

ans = 0
for ti in t:
    if search(s, ti):
        ans += 1

print(ans)



Measured memory_bytes: 16896
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#include <numeric>
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
const double EPS = 1e-10;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
 
int N, K;
int rec[110][110];
 
//primal-dual
struct edge { ll to, cap, cost, rev; };
 
const int MAX_V = 110;
int V;
vector<edge>G[MAX_V];
ll dist[MAX_V];
ll ans = inf;
int prevv[MAX_V], preve[MAX_V];
 
void add_edge(int from, int to, int cap, int cost) {
	edge fe = { to,cap,cost,(int)G[to].size() };
	edge toe = { from,0,-cost,(int)G[from].size() };
	G[from].pb(fe);
	G[to].pb(toe);
}
 
ll min_cost_flow(int s, int t, int f) {
	ll res = 0;
	while (f > 0) {
		//Bellman-Ford
		for (int i = 0; i < V; i++)dist[i] = inf;
		dist[s] = 0;
 
		for (int i = 0; i < V - 1; i++) {
			for (int j = 0; j < V; j++) {
				for (int k = 0; k < G[j].size(); k++) {
					edge &e = G[j][k];
					if (dist[j] == inf)continue;
					if (e.cap > 0 && dist[e.to] > dist[j] + e.cost) {
						dist[e.to] = dist[j] + e.cost;
						prevv[e.to] = j;
						preve[e.to] = k;
					}
				}
			}
		}
 
		if (dist[t] == inf)return -1;
 
		//s-t最短路に沿って目いっぱい流す
		ll d = f;
		for (int v = t; v != s; v = prevv[v]) {
			d = min(d, G[prevv[v]][preve[v]].cap);
		}
		f -= d;
		res += d * dist[t];
		for (int v = t; v != s; v = prevv[v]) {
			edge &e = G[prevv[v]][preve[v]];
			e.cap -= d;
			G[v][e.rev].cap += d;
		}
 
		//答えの記録&使われているマスをチェック
		if (ans > res) {
			ans = res;
			memset(rec,0,sizeof(rec));
			for (int i = 1; i <= N; i++) {
				for (int j = 0; j < G[i].size(); j++) {
					edge e = G[i][j];
					if (e.cap == 0)rec[i][e.to] = 1;
				}
			}
		}
	}
	return res;
}
//primal-dual　ここまで
 
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
 
 
	cin >> N >> K;
	V = 2 * N + 2;
	for (int i = 1; i <= N; i++)add_edge(0,i,K,0);
	for (int i = N + 1; i <= 2 * N; i++)add_edge(i,2*N+1,K,0);
	for (int i = 1; i <= N; i++) {
		for (int j = N+1; j <= 2*N; j++) {
			int A;
			cin >> A;
			add_edge(i,j,1,-A);
		}
	}
	min_cost_flow(0, 2 * N + 1, 60 * 60);
 
 
	puts(-ans);
	for (int i = 1; i <= N; i++) {
		for (int j = N+1; j <= 2*N; j++) {
			if(rec[i][j])cout << "X";
			else cout << ".";
		}
		puts("");
	}
 
 
	return 0;
}

Measured memory_bytes: 3956
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)

#define DEBUG

#ifdef DEBUG
#define var_dump(...) fprintf(stdout, __VA_ARGS__)
#define dump(a) cout << a << "\n";
#else
#define var_dump(...) 42
#define dump(a) 42
#endif

// https://beta.atcoder.jp/contests/abc060/tasks/abc060_b

int main() {

    int A, B, C;
    cin >> A >> B >> C;

    int cnt = 1;
    map<int, bool> mp;
    while(true) {
        int mod = (A * cnt) % B;
        if (mp[mod]) {
            cout << "NO" << "\n";
            return 0;
        }
        mp[mod] = true;

        if (mod == C) {
            cout << "YES" << "\n";
            return 0;
        }

        cnt++;
    }

    return 0;
}


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

int main() {
    map<int,int> cnts;
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        int a_i; cin >> a_i;
        if (cnts.count(a_i)) cnts[a_i]++;
        else cnts[a_i] = 1;
    }

    int ans = 0;
    for (auto cnt : cnts) {
        if (cnt.second % 2 == 1) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4864
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;



namespace Test1 {

    class ClassMain {


        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                int n = int.Parse(line);
                if (n == 0) { break; }
                team[] teams = new team[n];
                for (int i = 0; i < n; i++) {
                    teams[i] = new team(Console.ReadLine());
                }
                Array.Sort(teams);
                //print
                teams[0].printThis();
                teams[1].printThis();
                teams[n-2].printThis();
            }
        }


    }

    class team : IComparable {
        public int id;
        public int time;
        public team(string input) {
            string[] strs = input.Split(' ');
            id = int.Parse(strs[0]);
            time = 60 * (int.Parse(strs[1]) + int.Parse(strs[3])
                + int.Parse(strs[5]) + int.Parse(strs[7]));
            time += int.Parse(strs[2]) + int.Parse(strs[4])
                + int.Parse(strs[6]) + int.Parse(strs[8]);

        }
        public int CompareTo(object obj) {
            team t = (team)obj;
            return time - t.time;
        }
        public void printThis() {
            Console.WriteLine(id);
        }
    }
}

Measured memory_bytes: 6108
#include<iostream>
#include<string>
using namespace std;
int a[105][4];
int b[105];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i][0]>>a[i][1];
		if(a[i][0]==a[i][1]){
			b[i]=1;
		}
	}
	int flag=0;
	for(int i=0;i+2<n;i++){
		if(b[i]==1&&b[i+1]==1&&b[i+2]==1){
			cout<<"Yes"<<endl;
			flag=1;
			break;
		}
	}
	if(flag==0){
		cout<<"No"<<endl;
	} 
	
	return 0;
} 

Measured memory_bytes: 3132
import sys
import math
import numpy as np
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()
N = ni()
A = na()
A.sort()
n = A[-1]
m = n*1.0/2
#print(m)
inf = 10**9
ans=0
for i in range(N):
    if(abs(A[i]-m)<inf):
        inf= abs(A[i]-m)
        ans = A[i]
print(n,ans)

Measured memory_bytes: 23080
#include <stdio.h>
#include <math.h>
int main(){
    double q,x;
     
    while(scanf("%lf",&q) !=EOF){
    	if(q==-1)	break;
    	x = q/2;
    	while(fabs(pow(x,3)-q) >= 0.00001 * q){
    		x = x-(pow(x,3)-q)/(3.0 * pow(x,2));
    	}
    	printf("%0.6lf\n",x);
    }
    return 0;
}



Measured memory_bytes: 2040
#include <iostream>
#include <map>
#include <utility>
#include <vector>
using namespace std;

const int mod = (int)1e9 + 7;

vector<vector<int>> r(100000);

void ctree(int p, int rank, vector<pair<int, vector<int>>>& tree,
           map<int, vector<int>>& edge) {
  r[rank].push_back(p);
  for (int i : edge[p]) {
    if (i == tree[p].first) continue;
    tree[p].second.push_back(i);
    tree[i].first = p;
    ctree(i, rank + 1, tree, edge);
  }
  return;
}

int main() {
  int n;
  cin >> n;
  map<int, vector<int>> edge;
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    // 0-indexed
    edge[x - 1].push_back(y - 1);
    edge[y - 1].push_back(x - 1);
  }
  vector<pair<int, vector<int>>> tree(n);  //親, 子リスト
  tree[0].first = -1;
  ctree(0, 0, tree, edge);
  vector<long> dp1(n, 1), dp2(n, 1);
  for (int i = 99999; i >= 0; i--) {
    if (r[i].size() == 0) continue;
    for (int j : r[i]) {
      if (tree[j].second.size() != 0) {
        for (int k : tree[j].second) {
          dp1[j] *= dp2[k];
          dp2[j] *= (dp1[k] + dp2[k]);
          dp1[j] %= mod;
          dp2[j] %= mod;
        }
      }
    }
  }
  cout << (dp1[0] + dp2[0]) % mod;
  return 0;
}

Measured memory_bytes: 31104
#include <bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int i=a;i<b;i++)
#define reset(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define pi acos(-1)
#define eps 0.00000001
#define pb push_back
#define off 250555

int n,m,cnt[100005],x,y;
bool ans[100005];

int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios::sync_with_stdio(0);
    cin>>n>>m;
    For(i,1,n+1) cnt[i]=1;
    For(i,2,n+1) ans[i]=false;
    ans[1]=true;
    while(m--)
    {
        cin>>x>>y;
        if(ans[x]) ans[y]=true;
        cnt[y]++;
        cnt[x]--;
        if(!cnt[x]) ans[x]=false;
    }
    int ret=0;
    For(i,1,n+1) if(ans[i]) ret++;
    cout<<ret;
}


Measured memory_bytes: 768
g = {}
a = int(input())
for i in range(a - 1):
    c = [int(s) for s in input().split()]
    if c[0] not in g: g[c[0]] = [(c[1], c[2])]
    else: g[c[0]].append((c[1], c[2]))

    if c[1] not in g: g[c[1]] = [(c[0], c[2])]
    else: g[c[1]].append((c[0], c[2]))

c = {}
d = {i: False for i in range(1, a + 1)}
c[1], d[1] = 0, True
Q = [1]
while(Q != []):
    r = Q.pop(0)
    for i in g[r]:
        if d[i[0]] == False:
            d[i[0]] = True
            Q.append(i[0])
            if i[1] % 2 == 0: c[i[0]] = c[r]
            else: c[i[0]] = (c[r] + 1) % 2
for i in range(1, a + 1): print(c[i])

Measured memory_bytes: 64680
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }





int main() {
    
    int N, W;
    cin >> N >> W;
    
    int dp[20000] = {0};
    rep(i, N) {
        int v, w;
        cin >> v >> w;
        for (int j = 10000; j >= 0; --j) {
            if (dp[j] == 0) continue;
            chmax(dp[j + w], dp[j] + v);
        }
        chmax(dp[w], v);
    }
    int ans = 0;
    rep(i, W + 1) {
        chmax(ans, dp[i]);
    }
    cout << ans << endl;
    // rep(i, 10) cout << dp[i] << " "; cout << endl;
}



Measured memory_bytes: 3156
#include<bits/stdc++.h>
#define rep(i,k,n)     for (ll i = k; i < n; ++i)
#define repr(i,k,n)    for (ll i = k; i >= n; --i)
#define repp(p,a)      for (p=a.begin();p!=a.end();++p)
#define all(a)         a.begin(),a.end()
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define reppn(p,a,n)    for (p=a.begin();(p+n)!=a.end();++p)
#define F              first
#define S              second
#define ll             long long
#define hell           1000000007
#define god            LLONG_MAX
#define lb             lower_bound
#define ub             upper_bound
#define pb             push_back
#define ct             continue
#define endl           '\n'
#define setprecision(n) sp(n)
#define srt(a)         sort(all(a))
#define srtd(a)        sort(a.rbegin(),a.rend())
#define sz(a)          ll((a).size())
#define sum(a)         accumulate(all(a),(ll) 0)
#define pdt(a)         accumulate(all(a),double(1),multiplies<double> ())
#define dotpdt(a,b)    inner_product(all(a),b.begin(),0)
#define mkp(a,b)       make_pair(a,b)
#define REP(x,s)       for (auto x : s)
using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll t=1;
  //cin>>t;
  while(t--)
  {
      ll a,b,k,c=0,d;
      cin>>a>>b>>k;
      d=max(c,a-k);
      k=max(c,k-a);
      b=max(c,b-k);
      cout<<d<<" "<<b; 
  }
 return 0;
}

Measured memory_bytes: 256
/**
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣸⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣇⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀⠀⠀⠀⠀
⠀⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀⠀⠀
⠀⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄⠀
⠀⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿⠀
⠀⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸⠀
⠀⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂⠀⠀⠀
⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁⠀⠀
 *    author:  Daredevil666
 *    institution: IIT Patna
**/
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define nl cout<<"\n";
#define ll long long int
#define REP(i,a,n) for(i=a;i<=n;i++)
#define F(i,a,b) for(i=a;i<b;i++)
#define RF(i,b,a) for(i=b;i>=a;i--)
#define IOS  ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const ll mod=1e16;
const ll MAXN=100200;
ll i,j,mask,test;
int main()
{
IOS
/*#ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
#endif // ONLINE_JUDGE*/
ll d,s,t;
cin>>d>>s>>t;
ll k=s*t;
if(k>=d)
    cout<<"Yes";
else
    cout<<"No";
return 0;
}


Measured memory_bytes: 3648
from collections import defaultdict
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n=int(input())
    cards=defaultdict(set)
    for _ in range(n):
        m,a=input().split()
        cards[m].add(int(a))
    for m in ["S","H","C","D"]:
        for a in range(1,14):
            if a in cards[m]:continue
            print(m,a)
main()



Measured memory_bytes: 6004
#include<stdio.h>

int main() {
    int n;
    int a[1010];
    int i, j, v;

    scanf("%d", &n);
    for(i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        printf("%d%c", a[i], ((i == n - 1) ? '\n' : ' '));
    }

    for(i = 1; i < n; i++) {
        v = a[i];
        j = i - 1;
        while(j >= 0 && a[j] > v) {
            a[j + 1] = a[j];
            j--;
        }
        a[j + 1] = v;
        for(j = 0; j < n; j++) {
            printf("%d%c", a[j], ((j == n - 1) ? '\n' : ' '));
        }
    }

    return 0;
}

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

int main(){
  string s,t,u;
  cin >> s>>t;
  int a,b;
  cin >> a>>b >>u;
  if(u==s){
    a-=1;
  }
  else{
    b-=1;
  }
   cout << a << " " << b << endl; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define pb push_back
#define vl vector
#define ff first
#define ss second
using namespace std;
int main()
{
    ll a,b,i,j,n,t;
    cin>>n;
    string s;
    ll count=0;
    for(i=1;i<=n;i++)
    {
        s=to_string(i);
        if(s.size()%2) count++;
    }
    cout<<count;
    
}

Measured memory_bytes: 3648
l = ('A', 'T', 'C', 'G')
S = input()

ans = [0]
res = 0
for i in range(len(S)):
    if S[i] in l:
        res += 1
    elif res != 0:
        ans.append(res)
        res = 0
ans.append(res)

print(max(ans))

Measured memory_bytes: 9076
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

struct node{
	int data;
	node *l, *r;
};

node *new_node(int in){
	node *ret = new node;
	ret->data = in;
	ret->l = NULL;
	ret->r = NULL;
	return ret;
}

void insert_node(node **root, int in){
	node *add = new_node(in);
	if(*root == NULL){
		*root = add;
		return ;
	}
	node *p = *root, *pp = NULL;
	while(p != NULL){
		pp = p;
		if(add->data < p->data) p = p->l;
		else p = p->r;
	}
	if(add->data < pp->data) pp->l = add;
	else pp->r = add;
	return ;
}

void print_n(node *root, bool mode){
	if(mode == true) cout << " " << root->data;
	if(root->l != NULL) print_n(root->l, mode);
	if(mode == false) cout << " " << root->data;
	if(root->r != NULL) print_n(root->r, mode);
}

void print_node(node *root){
	print_n(root, false);
	cout << endl;
	print_n(root, true);
	cout << endl;
}

void find_node(node *root, int in){
	bool ans = false;
	while(root != NULL){
		if(in == root->data){
			ans = true;
			break;
		}else if(in < root->data){
			root = root->l;
		}else{
			root = root->r;
		}
	}
	if(ans == false) cout << "no" << endl;
	else cout << "yes" << endl;
}

void delete_node(node **root, int in){
	node *p = *root, *pp = NULL;
	while(p != NULL){
		if(p->data == in) break;
		pp = p;
		if(in < p->data) p = p->l;
		else p = p->r;
	}
	if(p->l == NULL && p->r == NULL){
		if(in < pp->data) pp->l = NULL;
		else pp->r = NULL;
		delete p;
		return ;
	}
	if(p->l == NULL){
		if(in < pp->data) pp->l = p->r;
		else pp->r = p->r;
		delete p;
		return;
	}
	if(p->r == NULL){
		if(in < pp->data) pp->l = p->l;
		else pp->r = p->l;
		delete p;
		return;
	}
	node *rl = p->r, *prl = p;
	while(rl->l != NULL){
		prl = rl;
		rl = rl->l;
	}
	if(in < pp->data) pp->l = rl;
	else pp->r = rl;
	if(prl != p)prl->l = rl->r;
	else prl->r = rl->r;
	rl->l = p->l;
	rl->r = p->r;
	delete p;
}

int main(){
	int n;
	cin >> n;
	node *root = NULL;
	rep(i, n){
		string s;
		cin >> s;
		if(s == "print"){
			print_node(root);
		}else if(s == "find"){
			int in;
			cin >> in;
			find_node(root, in);
		}else if(s == "delete"){
			int in;
			cin >> in;
			delete_node(&root, in);
		}else{
			int in;
			cin >> in;
			insert_node(&root, in);
		}
	}
	return 0;
}


Measured memory_bytes: 15516
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k); i > (n); i--)
#define FORre(i, k, n) for(int i = (k); i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;
const int mod = 1000000007;

int main(void){
  int n, a, b;
  cin >> n >> a >> b;
  int ans = min(n*a, b);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func nextInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num
}

func scanIntArray() []int {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)
	result := []int{}
	for i := 0; i < n; i++ {
		result = append(result, nextInt(sc))
	}

	return result
}

func main() {
	A := scanIntArray()
	mergeSort(A)
	fmt.Println(count)
}

var count int

func mergeSort(val []int) []int {
	length := len(val)
	if length == 1 {
		return val
	}

	var mid int
	if len(val)%2 == 0 {
		mid = length / 2
	} else {
		mid = length/2 + 1
	}
	left := val[:mid]
	right := val[mid:len(val)]

	lr := mergeSort(left)
	rr := mergeSort(right)

	return merge(lr, rr)
}

func merge(a1 []int, a2 []int) []int {
	var result []int
	a1Idx := 0
	a2Idx := 0
	for {
		a1done := len(a1) <= a1Idx
		a2done := len(a2) <= a2Idx
		if a1done && a2done {
			return result
		} else if a1done {
			result = append(result, a2[a2Idx])
			a2Idx++
			continue
		} else if a2done {
			result = append(result, a1[a1Idx])
			a1Idx++
			continue
		}

		if a1[a1Idx] <= a2[a2Idx] {
			result = append(result, a1[a1Idx])
			a1Idx++
		} else {
			result = append(result, a2[a2Idx])
			a2Idx++
			count += len(a1) - a1Idx
		}
	}
}



Measured memory_bytes: 13656
n,m = map(int, input().split())
a = [[] for x in range(0, n)]
b = [0 for x in range(0, m)]
for x in range(0, n):
    a[x] = list(map(int, input().split()))
for x in range(0, m):
    b[x] = int(input())
for i in range(0, n):
    c = 0
    for j in range(0, m):
        c += a[i][j] * b[j]
    print(c)

Measured memory_bytes: 8028
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(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 pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    int w[5] = {5, 7, 5, 7, 7};
    while (cin >> n && n){
        VI a(n);
        REP(i,n) {
            string s;
            cin >> s;
            a[i] = s.length();
        }
        REP(s,n){
            int x = 0, i = s, j = 0, f = 1;
            while (f){
                x += a[i];
                i++;
                if (x > w[j]) f = 0;
                if (x == w[j]){
                    x = 0;
                    j++;
                }
                if (j == 5) break;
            }
            if (f){
                cout << s+1 << endl;
                break;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3204
using System;
using System.Collections.Generic;

namespace ABC152_C
{
    class Program
    {
        static void Main(string[] args) {
            long n = long.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split();

            List<long> list = new List<long>();
            long ans = 0;
            for (long index = 0; index < n; index++) {
                list.Add(long.Parse(input[index]));
            }
            long min = list[0];
            for (int index = 0; index < n; index++) {
                if(min >= list[index]) {
                    ans++;
                    min = list[index];
                }
            }


            Console.WriteLine(ans);
        }
    }
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
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;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 112345;
int L[MAX_N];
int R[MAX_N];
ll Lsum[MAX_N];
ll Rsum[MAX_N];

int main2() {
  int N = nextInt();
  REP(i, N) {
    L[i] = nextInt();
    R[i] = nextInt();
  }
  sort(L, L+N); reverse(L, L+N);
  sort(R, R+N);

  Lsum[0] = 0;
  REP(i, N) Lsum[i+1] = Lsum[i] + L[i];
  Rsum[0] = 0;
  REP(i, N) Rsum[i+1] = Rsum[i] + R[i];

  ll ans = 0;
  for (int i = 0; i <= (N+1)/2; i++) {
    for (int j = i-1; j <= i+1; j++) {
      ll cur = 2*(Lsum[i] - Rsum[j]);
      chmax(ans, cur);
    }
  }
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main() {
  int n, k, s;
  cin >> n >> k;
  v1i v(n);
  rep(i, n) cin >> v[i];
  sort(v.begin(), v.end());
  s = upper_bound(v.begin(), v.end(), v[0]) - v.begin();
  cout << (n - s - 1) / (k - 1) + 1 << endl;
  return 0;
}

Measured memory_bytes: 640
// clang-format off

#include <bits/stdc++.h>

#define int long long int
#define main signed main()
#define bye return 0
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define each(p, v) for (auto p = (v).begin(); p != (v).end(); p++)
#define all(v) (v).begin(), (v).end()
#define prec(n) fixed << setprecision(n)
#define dump(x) cerr << "(L" << __LINE__ << ") " << #x << " = " << (x) << endl
#define clr(x, a) memset(x, a, sizeof(x))

#define sum(v) accumulate(all(v), 0)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define odd(n) ((n) % 2)
#define even(n) (!odd(n))

#define INF 1000000000
#define INFLL 1000000000000000000LL
#define MOD 1000000007
#define PI acos(-1)

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define vi vector<int>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>

using namespace std;

// clang-format on

main {
  int n, m;
  cin >> n >> m;
  bool t[n][n] = {};
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    t[a][b] = t[b][a] = true;
  }
  vi v;
  int c = 0;
  loop(i, 1, n) v.pb(i);
  do {
    bool f = true;
    f &= t[0][v[0]];
    rep(i, v.size() - 1) f &= t[v[i]][v[i + 1]];
    c += f;
  } while (next_permutation(all(v)));
  cout << c << endl;
  bye;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define X first
#define Y second
#define pb push_back

void solve();

int main() {
    // freopen("schools.in", "r", stdin);
    // freopen("schools.out", "w", stdout);
	ios_base::sync_with_stdio(0), cin.tie(0);
	int t;
	// cin >> t;
	t = 1;	
	while(t--) solve();
	return 0;
}

ll n;
ld p[3005], dp[3005][3005];

void solve() {
	cin >> n;
	for (ll i = 1; i <= n; ++i) cin >> p[i];
	dp[1][0] = 1 - p[1];
	dp[1][1] = p[1];
	for (ll i = 2; i <= n; ++i) {
		for (ll j = 0; j <= n; ++j) {
			dp[i][j] = (j == 0 ? 0 : dp[i - 1][j - 1]) * p[i] + dp[i - 1][j] * (1 - p[i]);
		}
	}
	ld ans = 0;
	for (ll i = (n + 1) / 2; i <= n; ++i) {
		ans += dp[n][i];
	}
	cout << fixed << setprecision(10) << ans << '\n';
}

Measured memory_bytes: 141056
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>
#include <cassert>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

bool solve() {
    int N, M, H, K;
    cin >> N >> M >> H >> K;
    if (!(N || M || H || K)) return false;
    vector<int> goals(N);
    for (int i = 0; i < N; i++) cin >> goals[i];

    vector<P> bars(M); // <height, left>
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >>a >> b;
        bars[i].first = b;
        bars[i].second = a - 1;
    }
    sort(bars.begin(), bars.end());

    vector<int> players(N);
    for (int i = 0; i < N; i++) players[i] = i;

    vector<P> bar_swaps(M);
    for (int i = 0; i < M; i++) {
        int left = bars[i].second;
        int right = bars[i].second + 1;
        bar_swaps[i].first = players[left];
        bar_swaps[i].second = players[right];
        swap(players[left], players[right]);
    }

    vector<int> results(N);
    for (int i = 0; i < N; i++) {
        results[players[i]] = goals[i];
    }

    int mn = 1;
    for (int i = 0; i < M; i++) {
        int left = bar_swaps[i].first;
        int right = bar_swaps[i].second;
        if (left > right) swap(left, right);
        if (left < K && right >= K) {
            mn = min(mn, results[right] - results[left]);
        }
    }

    int sum = 0;
    for (int i = 0; i < K; i++) sum += results[i];
    if (mn < 0) sum += mn;

    cout << sum << endl;
    return true;
}

signed main() {
    while (true) {
        bool ret = solve();
        if (!ret) break;
    }
}


Measured memory_bytes: 5848
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#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() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  bool ans = true;
  set<string> v;
  rep(i,n-1){
    v.emplace(s);
    string t;
    cin >> t;
    if(t[0] != s[s.size()-1]) ans = false;
    if(v.count(t)>0) ans = false;
    swap(s,t);
  }
  cout << (ans?"Yes":"No") << endl;
}


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

using namespace std;

struct vec {
    vec(int x, int y) {
        this->x=x;
        this->y=y;
    }
    int x,y;
};

int main() {
    int map[14][14]={0};
    const int dx[]={-1, 0, 1, 0}, dy[]={0, 1, 0, -1};

    while (1) {
        for (int y=1; y<13; ++y) {
            string s;
            if (!(cin>>s)) return 0;
            for (int x=1; x<13; ++x) {
                map[x][y]='0'-s[x-1];
            }
        }

        int result=0;
        for (int y=1; y<13; ++y) {
            for (int x=1; x<13; ++x) {
                if (map[x][y]==0) continue;

                result++;
                stack<vec> s;
                s.push(vec(x,y));
                while (s.size()) {
                    vec temp=s.top();
                    s.pop();
                    if (map[temp.x][temp.y]==0)continue;
                    map[temp.x][temp.y]=0;
                    for (int i=0; i<4; ++i) {
                        s.push(vec(temp.x+dx[i], temp.y+dy[i]));
                    }
                }
            }
        }

        cout<<result<<endl;
    }
}

Measured memory_bytes: 1192
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		var h = new HashSet<long>();
		h.Add(0);
		for(int i=0;i<N;i++) h.Add(A[i]);
		var l = h.ToList();
		l.Sort();
		var dic = new Dictionary<long,int>();
		for(int i=0;i<l.Count;i++) dic.Add(l[i], i);
		
		
		long max = 0;
		List<int> pos = new List<int>();
		for(int i=0;i<N;i++){
			if(max < A[i]){
				pos.Add(i);
				max = A[i];
			}
		}
		
		var cntBT = new BIT(N);
		var totBT = new BIT(N);
		for(int i=0;i<N;i++){
			cntBT.Add(dic[A[i]] + 1, 1);
			totBT.Add(dic[A[i]] + 1, A[i]);
		}
		
		long total = A.Sum();
		long done = 0;
		long[] ans = new long[N];
		for(int i = pos.Count - 1; i > 0; i--){
			long del = (total - totBT.Sum(dic[A[pos[i - 1]]])) - A[pos[i-1]] * (N - cntBT.Sum(dic[A[pos[i - 1]]]));
			ans[pos[i]] = del - done;
			done = del;
		}
		ans[0] = total - done;
		Console.WriteLine(String.Join("\n",ans));
	}
	int N;
	long[] A;
	public Sol(){
		N = ri();
		A = rla();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}

class BIT{
	int MM;
	int n;
	long[] bit;
	public BIT(int n_){
		n = n_;
		MM = 1 << 2;
		while(MM < n * 2) MM <<= 1;
		bit = new long[MM + 1];
	}
	//1-origin!!
	public void Add(int i, long x){
		while(i <= n){
			bit[i] += x;
			i += (i&-i);
		}
	}
	
	// i=>sum(a_1,...,a_i)
	// i=0 -> return 0;
	public long Sum(int i){
		long s = 0;
		while(i > 0){
			s += bit[i];
			i -= (i&-i);
		}
		return s;
	}
}



Measured memory_bytes: 40000
#include <stack>
#include <queue>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <tuple>
#include <cmath>
#include <random>
#include <algorithm>
#include <vector>
#include <iostream>
#include <fstream>
#include <chrono>
#include <numeric>

#define fio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
#define rng mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count())

#define ri(...) i64 __VA_ARGS__; rx(__VA_ARGS__)
#define rc(...) char __VA_ARGS__; rx(__VA_ARGS__)
#define rs(...) string __VA_ARGS__; rx(__VA_ARGS__)
#define rvi(x, n) vi x(n); cin >> x
#define rvvi(x, n, m) vvi x(n, vi(m)); cin >> x

#ifndef ONLINE_JUDGE
#define dbg(...) cerr << '[' << #__VA_ARGS__ << "]: "; dbg_log(__VA_ARGS__)
#else
#define dbg(...) ;;
#endif

#define fa(i, v) for (auto &i : v)
#define fi(i, n) for (i32 i = 0; i < n; i++)
#define fp(i, n) for (i32 i = 1; i < n; i++)
#define fr(i, n) for (i32 i = n - 1; i >= 0; i--)
#define fu(i) ri(_i); fi(i, _i)

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

typedef uint32_t u32;
typedef int32_t i32;
typedef uint64_t u64;
typedef int64_t i64;
#ifdef __SIZEOF_INT128__
typedef __uint128_t u128;
typedef __int128_t i128;
#endif
typedef vector<i64> vi;
typedef vector<vi> vvi;

template<typename T>
inline istream &operator>>(istream &in, vector<T> &v) {
    fa(x, v) in >> x;
    return in;
}

template<typename T>
inline ostream &operator<<(ostream &out, const vector<T> &v) {
    fa(x, v) out << x << ' ';
    return out;
}

template<typename T>
inline void rx(T &x) {
    cin >> x;
}

template<typename T, typename... R>
inline void rx(T &x, R &... l) {
    cin >> x;
    rx(l...);
}

template<typename T>
inline void dbg_log(const T &x) {
    cerr << x << '\n';
}

template<typename T, typename... R>
inline void dbg_log(const T &x, const R &... l) {
    cerr << x << ", ";
    dbg_log(l...);
}

template<typename T>
inline void wl(const T &x) {
    cout << x << '\n';
}

template<typename T, typename... R>
inline void wl(const T &x, const R &... l) {
    cout << x << ' ';
    wl<R...>(l...);
}

int main() {
    fio;

    ri(n, m, k);
    vi a(n + 1);
    fi(i, n) {
        ri(x);
        a[i + 1] = a[i] + x;
    }
    vi b(m + 1);
    fi(i, m) {
        ri(x);
        b[i + 1] = b[i] + x;
    }

    i32 res = 0;
    i32 i = n;
    i32 j = 0;
    while (i >= 0 && a[i] + b[j] > k) i--;
    while (i >= 0) {
        while (j < m && a[i] + b[j + 1] <= k) j++;
        res = max(res, i + j);
        i--;
    }
    wl(res);

    return 0;
}


Measured memory_bytes: 6336
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Mod (int)1000000007
#define INFTY (int)INT_MAX
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(S, s) S.find(s) != string::npos

int main() {
	int q;
	cin >> q;
	vector<int> V;
	Rep(i, q) {
		int n;
		cin >> n;
		if (n == 0) {
			int x;
			cin >> x;
			V.push_back(x);
		}
		else if (n == 1) {
			int i;
			cin >> i;
			cout << V[i] << endl;
		}
		else if (n == 2) {
			V.pop_back();
		}
	}
	return 0;
}


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

using namespace std;


#define PI 3.14159265
#define int long long



main(){

	int n, k;

	cin >> n >> k;

	int step = 0, cur = 1;
	while(n){
		n -= n % cur;
		step++; cur *= k;
	}

	cout << step - 1 << endl;
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main ()
{
  int a, b, c, t;
  
  cin >>a>>b>>c;;
  t = b;
  b = a;
  a = t;
  t = c;
  c = a;
  a = t;
  
  cout<<a<<" "<<b<<" "<<c<<endl;
 
  return 0;
}

Measured memory_bytes: 3620