akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long ll;
const long double PI = (acos(-1));
const long long MOD = 1000000007;
#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(int i=x;i<n;++i)

///////////////////////////////////////////////////
// -------------------- I/O -------------------- //
///////////////////////////////////////////////////
// https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords
template<typename T> void outputVec(const std::vector<T>& vec, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	for (auto it = vec.begin(); it != vec.end() - 1; ++it) { std::cout << *it << " "; }
	std::cout << *(vec.end() - 1) << "\n";
}
template<typename T> void outputVal(const T& res, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	std::cout << res << "\n";
}
template<typename T> T inputVal() { T a; std::cin >> a; return a; }
template<typename T> std::vector<T> inputVec(int N) {
	std::vector<T> vec(N);
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
	return vec;
}
template<typename T> void inputVec(std::vector<T>& vec) {
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
}

///////////////////////////////////////////////////
// ------------------- utils ------------------- //
///////////////////////////////////////////////////
// change min/max
template<class T> inline bool chMin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chMax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

template<typename T> T gcd(T a, T b) {
	if (a < b) std::swap(a, b);
	T r = a % b;
	while (r != 0) { a = b; b = r; r = a % b; }
	return b;
}
// Least Common Multiple: https://en.wikipedia.org/wiki/Least_common_multiple
template<typename T> T lcm(T a, T b) { return (a * b) / gcd(a, b); }

///////////////////////////////////////////////////
// ------------------- main -------------------- //
///////////////////////////////////////////////////
void Main() {
	const ll A = inputVal<ll>();
	const ll B = inputVal<ll>();
	const ll C = inputVal<ll>();
	const ll D = inputVal<ll>();

	ll nc = B / C - A / C;
	if ((A % C == 0)) ++nc;
	ll nd = B / D - A / D;
	if ((A % D == 0)) ++nd;

	ll nlcm = lcm<ll>(C, D);
	ll ncm  = B / nlcm - A / nlcm;
	if ((A % nlcm == 0)) ++ncm;
	ll red = nc + nd - ncm;
	outputVal(B - A + 1 - red);
}

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

	double tmp;
	cin >> tmp;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;
bool visited[200005];
vector<int> frd[200005];
int dfs(int i){
	int ret=1;
	visited[i]=1;
	for(int j=0;j<sz(frd[i]);j++)
		if(!visited[frd[i][j]])
			ret+=dfs(frd[i][j]);
	re ret;
}
int n,m;
int ans;
signed main(){
	ios_base::sync_with_stdio(0);
	cin>>n>>m;
	while(m--){
		int a,b;
		cin>>a>>b;
		a--,b--;
		frd[a].pb(b);
		frd[b].pb(a);
	}
	for(int i=0;i<n;i++)
		if(!visited[i])
			ans=max(dfs(i),ans);
	cout<<ans;
	re 0;
}

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

class Solve {
private:
	using vl = std::vector<long long>;
	using vvl = std::vector<vl>;

public:
	bool is_last_query{};
	Solve()
	{
		int n, m, s, g[2];
		scanf("%d%d%d%d%d", &n, &m, &s, g, g + 1);
		if (n == 0)
		{
			is_last_query = true;
			return;
		}
		s--; g[0]--; g[1]--;
		vvl distance(n, vl(n, 1 << 30));
		for (int i{}; i < m; i++)
		{
			int b[2], c;
			scanf("%d%d%d", b, b + 1, &c);
			b[0]--; b[1]--;
			distance[b[0]][b[1]] = c;
		}
		for (int i{}; i < n; i++)
			distance[i][i] = 0;
		for (int med{}; med < n; med++)
			for (int from{}; from < n; from++)
				for (int to{}; to < n; to++)
					distance[from][to] = std::min(distance[from][to], distance[from][med] + distance[med][to]);
		long long min{1 << 30};
		for (int i{}; i < n; i++)
			min = std::min(min, distance[s][i] + distance[i][g[0]] + distance[i][g[1]]);
		printf("%lld\n", min);
	}

};

int main()
{
	while (!Solve().is_last_query);

	return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <ll,ll> pii;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rept(i,x,y) for(int i=x;i<=y;i++)
#define per(i,x,y) for(int i=x;i>=y;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define fi first
#define se second
#define mes(a,b) memset(a,b,sizeof a)
#define mp make_pair
#define dd(x) cout<<#x<<"="<<x<<" "
#define de(x) cout<<#x<<"="<<x<<"\n"
#define debug() cout<<"I love Miyamizu Mitsuha forever.\n"
const int inf=0x3f3f3f3f;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin>>s;
	rep(i,0,s.size())
	{
		if(s[i]=='?') cout<<"D";
		else cout<<s[i];
	}
	return 0;
}

Measured memory_bytes: 3788
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let mut robots: Vec<(isize, isize)> = Vec::new();
    for _ in 0..n {
        let x: isize = iterator.next().unwrap().parse().unwrap();
        let l: isize = iterator.next().unwrap().parse().unwrap();
        robots.push((x - l, x + l));
    }
    robots.sort_by_key(|it| (*it).1);

    let mut count: usize = 0;
    let mut prev: isize = std::isize::MIN;
    for robot in robots {
        if robot.0 >= prev {
            count += 1;
            prev = robot.1;
        }
    }
    return count.to_string();
}


Measured memory_bytes: 10492
from collections import Counter

N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
A_sort0 = sorted(A)
A_sort = sorted(list(set(A)))
counter = Counter(A)
ans = 0
for i in range(len(A_sort)):
    if i == 0:
        continue
    else:
        q = A_sort0.index(A_sort[i])
        ans += (q * (K * (K-1) // 2) * counter[A_sort[i]])  % MOD
        index = A.index(A_sort[i])
        cnt = 0
        p = 0
        for j in range(index, N):
            if A_sort[i] > A[j]:
                cnt += 1 * p
            elif A_sort[i] == A[j]:
                p += 1
        ans = (ans + (cnt * K)) % MOD
print(ans)


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

using lint = int64_t;
#define bit(n) ((lint)1 << n);
const int INF = 1e9;
const lint LINF = 1e18;

const lint MOD = 1e9 + 7;
// const lint MOD = 998244353;

class IoSetup {
    public:
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(12);
        cerr << fixed << setprecision(12);
    }
} iosetup;

struct Con {
    int s, t, x;
    bool operator < (const Con that) const {
        return x < that.x;
    }
};

struct Ped {
    int id, d;
    bool operator < (const Ped that) const {
        return d < that.d;
    }
};

int main() {
    int n, q;
    cin >> n >> q;
    vector<Con> cons(n);
    for (int i = 0; i < n; i++) {
        int s, t, x;
        cin >> s >> t >> x;
        cons[i] = {s - x, t - x, x};
    }
    sort(cons.begin(), cons.end());
    
    set<Ped> peds;
    for (int i = 0; i < q; i++) {
        Ped ped;
        ped.id = i;
        cin >> ped.d;
        peds.insert(ped);
    }

    vector<int> ans(q, -1);
    for (int i = 0; i < n; i++) {
        int s = cons[i].s, t = cons[i].t, x = cons[i].x;
        auto it = peds.lower_bound({0, s});
        while (it != peds.end()) {
            if (it->d < t) {
                ans[it->id] = x;
                peds.erase(it++);
            } else {
                break;
            }
        }
    }

    for (int i = 0; i < q; i++) {
        cout << ans[i] << endl;
    }

    return 0;
}

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

int main() {
  int n,l;
  cin >> n >> l;
  vector<string>s(n);
  rep(i,0,n) cin >> s[i];
  sort(s.begin(),s.end());
  rep(i,0,n) cout << s[i];
  cout << "" << endl;
}

Measured memory_bytes: 3632
import java.util.*

fun main(args: Array<String>) {
    val scn = Scanner(System.`in`)
    val N = scn.nextInt()
    val K = scn.nextInt()

    var p = 0
    var list = mutableListOf<Int>()
    list.add(0)
    var maxP = 0
    for(i in 1..N){
        p = scn.nextInt()
        list.add(p + list[i-1])

        if(i>=K){
            var tmp = list[i] - list[i-K]
            if(maxP < tmp) maxP = tmp
        }
    }

    println((maxP+K).toFloat()/2f)
}

Measured memory_bytes: 76536
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

int a[100005];

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    int uk = 1, ans = 0;
    while (uk < n)
    {
        uk += k - 1;
        ans++;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
//写経


long long gcd(long long a,long long b){
  if(b==0) return a;
  return gcd(b,a%b);
}
long long lcm(long long a,long long b){
  long long g=gcd(a,b);
  return a/g*b;
}


int main(int argc, char *argv[]){
  int N;
  cin>>N;
  long long ans=1;
  for(int i=0; i<N; i++){
    long long T;
    cin>>T;
    ans=lcm(ans,T);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

//#include "Union_Find.h"

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
//#include <unordered_set>
//#include <unordered_map>
#include <iomanip>
#include <sstream>

using namespace std;
#define REP(i,a,n) for(int i = a; i < n; ++i)
#define REPM(i,n,a) for(int i = n - 1; i >= a; --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
typedef long long LL;
typedef unsigned long long ULL;

class SplitStream {
	typedef basic_ostream<char, char_traits<char> > BaseOst;
	std::ostream& ost_m;
	bool line_is_empty_m;
public:
	SplitStream(std::ostream& ost);
	template <typename T>
	SplitStream& operator<<(T right);
	SplitStream& operator<<(BaseOst& (*right)(BaseOst&));
};
SplitStream::SplitStream(std::ostream& ost) : ost_m(ost), line_is_empty_m(true) {}
template <typename T>
SplitStream& SplitStream::operator<<(T right) {
	if (!line_is_empty_m) ost_m << ' ';
	line_is_empty_m = false;
	ost_m << right;
	return *this;
}
/* std::endl のみ */
SplitStream& SplitStream::operator<<(BaseOst& (*right)(BaseOst&)) {
	ost_m << '\n';
	ost_m.flush();
	line_is_empty_m = true;
	return *this;
}
SplitStream Scout(cout);

string s;
bool A[26];

int main() {
	cin >> s;
	REP(i, 0, s.size()) {
		A[s[i] - 'a'] = !A[s[i] - 'a'];
	}
	int p = 1;
	REP(i, 0, 26) {
		p *= !A[i];
	}
	cout << (p ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N,L;
    cin >> N >> L;
    veci apple(N);
    REP(i,N) apple[i] = L + i;
    int sum_n = 0;
    REP(i,N) sum_n += apple[i];
    //cout << sum_n << endl;
    int ans,min_pie;
    min_pie = 1e5;
    REP(i,N) {
        int sum_n1 = 0;
        REP(j,N) {
            if(i != j) sum_n1 += apple[j];
        }
        //cout << sum_n1 << endl;
        if(min_pie >= abs(sum_n1 - sum_n)) {
            ans = sum_n1;
            min_pie = abs(sum_n - sum_n1);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#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 rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int D;
vi c(26);
vvi s;
vvi last;
vi v;

int calc (int num = D) {
    rep(i,D) last[i].assign(26,-1);
    int ret = 0;
    rep(i,num) {
        ret += s[i][v[i]];
        if(i > 0) last[i] = last[i-1];
        last[i][v[i]] = i;
        rep(j,26) ret -= c[j]*(i-last[i][j]);
    }
    return ret;
}

int dif(int d,int q) {
    int ol_q = v[d];
    int ol_last = (d == 0 ? -1 : last[d-1][ol_q]);
    int new_last = last[d][q];
    int ret = s[d][q]-s[d][ol_q];
    rep2(i,d,D) {
        if(last[i][ol_q] > d) break;
        ret -= c[ol_q]*(d-ol_last);
    }
    rep2(i,d,D) {
        if(last[i][q] > new_last) break;
        ret += c[q]*(d-new_last);
    }
    return ret;
}

void change(int d,int q) {
    int ol_q = v[d];
    int ol_last = (d == 0 ? -1 : last[d-1][ol_q]);
    int new_last = last[d][q];
    rep2(i,d,D) {
        if(last[i][ol_q] > d) break;
        last[i][ol_q] = ol_last;
    }
    rep2(i,d,D) {
        if(last[i][q] > new_last) break;
        last[i][q] = d;
    }
    v[d] = q;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cin >> D;
    s.resize(D);
    last.resize(D);
    rep(i,D) s[i].resize(26);
    cin >> c >> s;
    vi t(D);
    cin >> t;
    rep(i,D) t[i]--;
    int m;
    cin >> m;
    v = t;
    int now = calc();
    rep(_,m) {
        int d,q;
        cin >> d >> q;
        d--; q--;
        now += dif(d,q);
        cout << now << "\n";
        change(d,q);
    }
}


Measured memory_bytes: 3704
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
 
int main() {
	int N,M;
	cin >> N >> M;
	int a,b;
	bool aa[Nmax],bb[Nmax];
	REP(i,N+1){
		aa[i]=false;
		bb[i]=false;
	}
	REP(i,M){
		cin >> a >> b;
		if(a==1) aa[b]=true;
      	if(b==N) bb[a]=true;
	}
	bool flag=false;
	FOR(i,2,N)
		if(aa[i] && bb[i]){
				flag=true;
				break;
		}
    
	if(flag) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
	
  return 0;
}

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

int main() {
	string S,T;cin>>S>>T;
	int cnt = 0;
	for(int i=0;i<3;i++)if(S[i]==T[i])cnt++;
	cout<<cnt<<endl;
	return 0;
}

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

A = [0]*n

A = [int(s) for s in input().split()]

A_dif = [0]*n

for i in range(n):
    a_bak = i-1
    a_f = i+1
    if(i == 0):
        a_bak = n-1
    if(i == n-1):
        a_f = 0
    
    #print()   
    A_dif[i] 
    tmp = max(abs(A[a_f]-A[i]),abs(A[a_bak]-A[i]))
    
    if(tmp > k//2):
        tmp = k - tmp
    
    A_dif[i] = tmp
    

#print(A_dif)
print(k - max(A_dif))

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

int main() {
  int n, k;
  cin >> n >> k;
  int mx = (n-1)*(n-2)/2;
  if (mx < k) {
    puts("-1");
    return 0;
  }
  vector<P> ans;
  rep(i,n-1) {
    ans.push_back(P(i+1,n));
  }
  int add = mx-k;
  vector<P> edge;
  rep(i,n-1)rep(j,i) edge.push_back(P(i+1,j+1));
  rep(i,add) ans.push_back(edge[i]);
  cout << ans.size() << endl;
  rep(i,ans.size()) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
using namespace std;

int main(){
	int ans=0;
	string s;
	while(cin>>s){
		rep(i,0,s.size()){
			if(s[i]-'0'>=0 && s[i]-'0'<10){
				rep(j,i,s.size()){
					if(s[j]-'0'<0 || s[j]-'0'>=10 || j == s.size() - 1){
						if(j==s.size()-1) j++;
						ans+=atoi(s.substr(i,j-i).c_str());
						//cout<<atoi(s.substr(i,j-i).c_str())<<endl;
						i = j;
						break;
					}
				}
			}
		}
	}
	o(ans);
}

Measured memory_bytes: 1196
#include <math.h>

#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using ll = long long;
using namespace std;

int main() {
    char a;
    cin >> a;
    if ((int)a < (int)'a') {
        cout << 'A';
    } else {
        cout << 'a';
    }
    return 0;
}


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

using namespace std;

int main(void){

  int n;
  cin >> n;

  while(n--){

    string s;
    string ans;

    cin >> s;
    ans = s[0];

    for( int i = 1 ; i < s.size() ; i++ ){

      if( 'a' <= s[i] && s[i] <= 'z' ){

	if( s[i - 1] == '>' ){
	  for( int j = 0 ; j < ans.size() ; j++ ){
	    if( s[i] == ans[j] ) goto back;
	  }
	  ans = ans + s[i];
	}

	else if( s[i - 1] == '-' ){
	  for( int j = 0 ; j < ans.size() ; j++ ){
	    if( s[i] == ans[j] ) goto back;
	  }
	  ans = s[i] + ans;
	}
      }
    back:;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>
#include <math.h>

using namespace std;

int main()
{
    int x;
    cin >> x;
    if(x == 3 || x == 5 || x == 7){
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 888
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}

int gcd(ll(a), ll(b)) {
	ll c = a;
	while (a % b != 0) {
		c = a % b;
		a = b;
		b = c;
	}
	return b;
}



int main() {
 
	
	ll N,M,X,an=0;
	cin >> N>>M>>X;
	
	rep(i, M) {
		ll a;
		cin >> a;
		if (a < X) {
			an++;
		}
	}
	cout << min(an, M - an) << endl;
	

}

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

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

  bool flag = false;
  for (int i = 0; i < 3; i++) {
    if (N[i] == '7') {
      flag = true;
    }
  }

  cout << ( flag ? "Yes" : "No" ) << endl;
}


Measured memory_bytes: 3532
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct node {
    int value;
    struct node* parent;
    struct node* left;
    struct node* right;
} Node;

typedef Node* NodePointer;

NodePointer serialize(int val) {
    NodePointer newNode = malloc(sizeof(Node));
    newNode->value = val;
    newNode->parent = NULL;
    newNode->left = NULL;
    newNode->right = NULL;
    return newNode;
}

NodePointer insert(NodePointer node, int val) {
    NodePointer currentNode = node;
    int flag = 0;
    int dir = 0;
    while(!flag) {
        if (currentNode->value > val) {
            if (currentNode->left == NULL) flag = 1;
            else currentNode = currentNode->left;
            dir = 0;
        } else if (currentNode->value < val) {
            if (currentNode->right == NULL) flag = 1;
            else currentNode = currentNode->right;
            dir = 1;
        } else {
            return node;
        }
    }

    if (dir) {
        currentNode->right = serialize(val);
        currentNode->right->parent = currentNode;
    } else {
        currentNode->left = serialize(val);
        currentNode->left->parent = currentNode;
    }

    return node;
}

int search(NodePointer node, int val) {
    NodePointer currentNode = node;
    while(currentNode != NULL) {
        if (currentNode->value == val) {
            return 1;
        } else if (currentNode->value > val) {
            currentNode = currentNode->left;
        } else {
            currentNode = currentNode->right;
        }
    }

    return 0;
}

void inorderPrint(NodePointer node) {
    if (node == NULL) return;
    inorderPrint(node->left);
    printf(" %d", node->value);
    inorderPrint(node->right);
}

void preorderPrint(NodePointer node) {
    if (node == NULL) return;
    printf(" %d", node->value);
    preorderPrint(node->left);
    preorderPrint(node->right);
}

void nodePrint(NodePointer node) {
    inorderPrint(node);
    printf("\n");
    preorderPrint(node);
    printf("\n");
}

int main() {
    NodePointer node = NULL;
    int n, m;
    char cmd[16];
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%s", cmd);
        if (!strcmp(cmd, "insert")) {
            scanf("%d", &m);
            if (node == NULL) node = serialize(m);
            else insert(node, m);
        } else if (!strcmp(cmd, "print")) {
            nodePrint(node);
        } else if (!strcmp(cmd, "find")) {
            scanf("%d", &m);
            if (search(node, m)) {
                printf("yes\n");
            } else {
                printf("no\n");
            }
        }
    }
    return 0;
}



Measured memory_bytes: 20548
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

a_b = []
for i in range(X):
    for j in range(Y):
        a_b.append(A[i]+B[j])
a_b = sorted(a_b, reverse=True)
ans = []
for k in range(min(K, len(a_b))):
    for l in range(min(K, len(C))):
        ans.append(a_b[k]+C[l])
ans = sorted(ans, reverse=True)
for m in range(K):
    print(ans[m])


Measured memory_bytes: 148864
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


void Main(){
    int H, A;
    cin >> H >> A;
    cout << (H+A-1)/A << el;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,ans;
	cin>>a>>b;
	if(a>b)
	{
		long long i=a-b;
		if(i%2==0)
		{
			ans=i/2+b;
			cout<<ans;
		}
		else
		{
			cout<<"IMPOSSIBLE";
		}
	}
	else
	{
		long long i=b-a;
		if(i%2==0)
		{
			ans=i/2+a;
			cout<<ans;
		}
		else
		{
			cout<<"IMPOSSIBLE";
		}
	}
	return 0;
} 

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

constexpr int64 P = 1000000007;

struct FiniteField {
 private:
  int64 x;
  static inline int64 Normalize(int64 x) {
    if (0 <= x && x < P) return x; x %= P; if (x < 0) x += P; return x;
  }
 public:
  FiniteField(int64 x) : x(Normalize(x)) {}
  FiniteField() : x(0) {}
  int64 Value() const { return x; }
  inline FiniteField operator+(FiniteField o) const {
    FiniteField r(*this); r += o; return r;
  }
  inline FiniteField operator-(FiniteField o) const {
    FiniteField r(*this); r -= o; return r;
  }
  inline FiniteField operator* (FiniteField o) const {
    FiniteField r(*this); r *= o; return r;
  }
  inline FiniteField operator/ (FiniteField o) const {
    FiniteField r(*this); r /= o; return r;
  }
  inline void operator+= (FiniteField o) { x = (x + o.x) % P; }
  inline void operator-= (FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*= (FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2; while (p) { if (p % 2) { *this *= o; } o *= o; p /= 2; }
  }
};

ostream& operator<<(ostream& s, const FiniteField& v) { s << v.Value(); return s; }

FiniteField Power(FiniteField x, int p) {
  if (p < 0) return FiniteField(1) / Power(x, -p);
  FiniteField value = 1;
  while (p) {
    if (p % 2) value *= x;
    x *= x;
    p /= 2;
  }
  return value;
}

template<typename T>
vector<vector<T>> Make2DVector(int d1, int d2, T default_value) {
  return vector<vector<T>>(d1, vector<T>(d2, default_value));
}

constexpr int X_MAX = 400;

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

  int n, c;
  cin >> n >> c;

  vector<int> as(n), bs(n);
  for (int i = 0; i < n; i++) {
    cin >> as[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> bs[i];
  }

  // c_table[p][i]: 1^p + 2^p + ... + i^p
  auto c_table = Make2DVector(c + 1, X_MAX + 1, FiniteField(0));
  for (int p = 0; p <= c; p++) {
    for (int i = 1; i <= X_MAX; i++) {
      c_table[p][i] = c_table[p][i - 1] + Power(i, p);
    }
  }

  auto dp = Make2DVector(n + 1, c + 1, FiniteField(0));
  dp[0][0] = 1;  // ?
  for (int i = 0; i < n; i++) {
    for (int k = 0; k <= c; k++) {
      for (int l = 0; l <= k; l++) {
        dp[i + 1][k] += dp[i][l] * (c_table[k - l][bs[i]] - c_table[k - l][as[i] - 1]);
      }
    }
  }
  cout << dp[n][c] << endl;
}

Measured memory_bytes: 2816
#include <cstdio>
#include <cstring>
#include <cstdlib>
struct solver
{
	//鬚倡岼謇?怙蜿倬?
	int n;
	int p[55],t[55];

	// weapon
	int dp[55][5]; // 蠖灘燕蝨ィ隨ャi荳ェ逅?噪菴咲スョ?瑚スヲ荳顔噪豌皮帥謨ー?梧園陦碁ゥカ逧?怙遏ュ霍晉ヲサ
	bool init()
	{
		scanf("%d",&n);
		if(!n) return false;
		for(int i = 1; i <= n; i++) 
		{
			scanf("%d%d",&p[i],&t[i]);
		}
		return true;
	}
	void Min(int &x,int y)
	{
		if(y == -1) return ;
		if(x == -1 || y < x) x = y;
	}
	void solve()
	{
		memset(dp,-1,sizeof(dp));
		dp[0][0] = 0; p[0] = 0; t[0] = 0;
		int failed_place = -1;
		for(int i = 0; i <= n; i++)
		{
			bool flag = true;
			for(int j = 0; j <= 3; j++) if(dp[i][j]!=-1) flag = false;
			if(flag)
			{
				failed_place = i;
				break;
			}
			/*for(int j = 0; j <= 3; j++)
			{
				printf("dp[%d][%d]=%d\n",i,j,dp[i][j]);
			}*/
			for(int j = 0; j <= 3; j++) if(dp[i][j]!=-1)
			{
				int dis = abs(p[i+1]-p[i]);
				int t_dis = t[i+1] - t[i];
				if(t_dis >= dis*(j+1) && j+1 <= 3) 
				{
					Min(dp[i+1][j+1],dp[i][j]+dis);
				}
				if(p[i]*(j+1) + p[i+1] <= t_dis)
				{
					Min(dp[i+1][1],dp[i][j]+p[i]+p[i+1]);
				}
			}
		}
		if(failed_place != -1) 
		{
			printf("NG %d\n",failed_place);
		}
		else 
		{
			int ans = -1;
			for(int i = 0; i <= 3; i++) Min(ans,dp[n][i]);
			printf("OK %d\n",ans+p[n]);
		}
	}
}Pro;
int main()
{
	while(Pro.init()) 
		Pro.solve();
	return 0;
}

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

int main()
{
    int X;
    cin >> X;
    int max = 1;
    int upper = (int)sqrt(X);
    for(int i = 2; i <= upper; ++i) {
        int tmp = i*i;
        while( tmp*i <= X ) tmp *=i;
        if(tmp > max ) max = tmp;
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream> 
#include <algorithm> 
  
using namespace std; 
  
int c[100], temp[100]; 
  
int compute(int k,int n){ 
  int a,b; 
  b=0; 
  for(int i=0;i<n-k+1;i++){ 
    a=1; 
    for(int j=i;j<i+k;j++){ 
      a*=c[j]; 
    } 
    if(b<a)b=a; 
  } 
  return b; 
} 
int comb2(int n) { 
  int ret; 
  
  ret = n*(n-1)/2; 
    
  return ret; 
} 
  
void cpyswap(int i, int j, int n) { 
  for(int p = 0; p < n; i++) { 
    temp[p] = c[p]; 
  } 
  
  // swap 
  int x; 
    
  x = temp[i]; 
  temp[i] = temp[j]; 
  temp[j] = x; 
} 
  
void stSort(int array[], int num) { 
  int stemp[100]; 
  
  for(int i = 0; i < num; i++) { 
    stemp[i] = array[i] * 1000 + i; 
  } 
  
  sort(stemp, stemp + num); 
    
  for(int i = 0; i < num; i++) { 
    array[i] = stemp[i]/1000; 
  } 
} 
  
int main (void) { 
  int n, k, befDat[100], aftDat[45][100], res,change,mx,a,before; 
  
  while(1){ 
    cin >> n >> k; 
      
    if(n == 0 && k == 0) break; 
    mx=0; 
    for(int i = 0; i < n; i++) { 
      cin >> c[i]; 
    } 
    before=compute(k,n); 
    for(int i=0;i<n-1;i++){ 
      for(int j=i+1;j<n;j++){ 
    change=c[i]; 
    c[i]=c[j]; 
    c[j]=change; 
    a=compute(k,n); 
    if(mx<a)mx=a; 
    change=c[j]; 
    c[j]=c[i]; 
    c[i]=change; 
      } 
    } 
    if(mx-before>=0){ 
      cout<<mx-before<<endl; 
    }else{ 
      cout<<"NO GAME"<<endl; 
    } 
    /* aftDat 2mai irekae 
    for(int i = 0; i < comb2(n); i++) { 
      cpyswap(i, j, n); 
        
      for(int e = 0; e < n-k+1; e++) { 
    aftDat[i][e] *= temp[e]; 
    for(int f = 0; f < k; f++) { 
      aftDat[e] *= temp[e+f]; 
    } 
      } 
    }*/
    /* 
    stSort(befDat, n-k+1); 
    for(int i = 0; i < comb2(n); i++) 
      stSort(aftDat[i], n-k+1); 
  
    res = aftDat[n-k+1] - befDat[n-k+1]; 
  
    if(res <= 0) { 
      cout >> 0 >> endl; 
    } else { 
      cout >> res >> endl; 
      }*/
  } 
  return 0; 
} 

Measured memory_bytes: 1164
n = int(input())
a = list(map(int,input().split()))
l =[]
for i in a:
    l.append(i//400)
x = set()
y = 0
for i in l:
    if i<= 7:
        x.add(i)
    else:
        y +=1
x = len(x)
if x:
    mi =x
else:
    mi =1
ma = x+y
print('{} {}'.format(mi, ma))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b){ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
 
const double PI=acos(-1.0);
int main(){
	double r;
	scanf("%lf",&r);
	printf("%.5lf",2.0*r*PI);
    return 0;
}

Measured memory_bytes: 3824
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int main() {
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>>s;
	int two[200030] = {};
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		s.push_back(make_pair(a, b));
	}

	for (int i = 0; i < m; i++) {
		if (s[i].first == 1) {
			two[s[i].second] = 1;
		}
		if (s[i].second == 1) {
			two[s[i].first] = 1;
		}
	}
	for (int i = 0; i < m; i++) {
		if (s[i].first == n && two[s[i].second]== 1) {
			cout << "POSSIBLE";
			return 0;
		}
		if (s[i].second == n && two[s[i].first] == 1) {
			cout << "POSSIBLE";
			return 0;
		}
	}
	cout << "IMPOSSIBLE";
}


Measured memory_bytes: 3188
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
using namespace std;
#pragma warning(disable : 4996)


int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s1, s2;
	cin >> s1 >> s2;
	cout << s2 << s1;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int gcd(int a,int b)
{
  return (a%b==0 ? b:gcd(b,a%b));
}

int main()
{
  int k;
  cin>>k;
  ll sum=0;
  
  for (int a = 1; a <= k; ++a)
  {
    for (int b = 1; b <= k; ++b)
    {
      for (int c = 1; c <= k; ++c)
      {
        sum+=gcd(gcd(a,b),c);
      }
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3640
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <stack>
#include <iostream>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
int n,q,x;
int a[30];
int f(int i,int x)
{
	if(x==0)
	return 1;
	if(i>n)
	return 0;
	int res=f(i+1,x)||f(i+1,x-a[i]);
	return res;
}
int main()
{
  cin>>n;
  for(int i=1;i<=n;i++)
  {
  	cin>>a[i];
  }
  cin>>q;
  for(int i=1;i<=q;i++)
  {
  	cin>>x;
  	if(f(1,x))
  	cout<<"yes"<<"\n";
  	else
  	cout<<"no"<<"\n";
  }
	return 0;
}


Measured memory_bytes: 3104
/**
 * @author sakt_coder
 * created on 2020-09-19 17:34
 */
import java.io.*;
import java.util.*;
public class Main
{
	
	private boolean solve()throws Exception
	{
		int n=nextInt();
		boolean d[]=new boolean[n+1];
		for(int i=1;i<=n;i++)
		{
			int first=nextInt();
			int second=nextInt();
			if(first==second)
				d[i]=true;
		}
		for(int i=1;i<=n-2;i++)
			if(d[i] && d[i+1] && d[i+2])
				return true;
		return false;
	}

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

	public void run()throws Exception
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		out.println(solve()?"Yes":"No");
		
		br.close();
		out.close();
	}
	public static void main(String args[])throws Exception{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws Exception{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws Exception{
		return br.readLine();
	}
	int nextInt()throws Exception{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws Exception{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws Exception{
		return Double.parseDouble(nextToken());
	}
}


Measured memory_bytes: 32960
program sample1
      implicit none
      
      integer N,M,A(1000),i,S,count
      read(*,*) N,M
      read(*,*) (A(i),i=1,N)
      count=0
      S=0
      do i=1,N
         S=A(i)+S
      end do
      do i=1,N   
         if (A(i)>=S/4.0/M) then
            count=count+1
         end if
      end do
      if (count>=M) then
          write(*,*) "Yes"
      else
          write(*,*)"No"
      end if
      
      stop 
      end program sample1




Measured memory_bytes: 384
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int Par[100],Rank[100];
void Init(int n) {
	for(int i=0;i<n;i++) {
		Par[i]=i;
		Rank[i]=0;
	}
}
int Find(int x) {
	if(Par[x]==x) {
		return x;
	}else {
		return Par[x]=Find(Par[x]);
	}
}
void Unite(int x,int y) {
	x=Find(x);
	y=Find(y);
	if(x==y) return;
	if(Rank[x]<Rank[y]) {
		Par[x]=y;
	}else {
		Par[y]=x;
		if(Rank[x]==Rank[y])Rank[x]++;
	}
}
bool Same(int x,int y) {
	return Find(x)==Find(y);
}
struct Edge {
	int from,to,cost;
	Edge(int _f,int _t,int _c) {from=_f,to=_t,cost=_c;}
	bool operator < (const Edge& E) const {return cost<E.cost;}
};
int main() {
	int n,m;
	while(scanf("%d %d",&n,&m),n) {
		vector<Edge> es;
		for(int i=0;i<m;i++) {
			int a,b,cost;
			scanf("%d %d %d",&a,&b,&cost);
			es.push_back(Edge(a,b,cost));
		}
		sort(es.begin(),es.end());
		Init(n);
		int sum=0;
		for(int i=0;i<es.size();i++) {
			if(!Same(es[i].from,es[i].to)) {
				Unite(es[i].from,es[i].to);
				sum+=es[i].cost;
			}
		}
		printf("%d\n",sum);
	}
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

double dp[3005][3005];

void Main() {
    int N;
    cin >> N;
    vector<double> P(N);
    rep(i, N) cin >> P[i];
    dp[0][0] = 1;
    rep(i, N) {
        rrep(j, N - 1, 0) {
            dp[i + 1][j + 1] = dp[i][j] * P[i] + dp[i][j + 1] * (1 - P[i]);
            dp[i + 1][j] = dp[i][j] * (1 - P[i]);
        }
    }

    double ans = 0;
    rep(i, N + 1) {
        if (i > N - i) {
            ans += dp[N][i];
        }
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 70656
def main():
    from collections import deque
    import sys
    input = sys.stdin.readline

    M = 10 ** 5

    N = int(input())

    g = tuple(set() for _ in range(M * 2))
    for _ in range(N):
        x, y = (int(x) - 1 for x in input().split())  # 一律に移動
        g[x].add(y + M)
        g[y + M].add(x)

    visited = [0] * (M * 2)
    ans = 0
    for s in range(M * 2):  # xとy+Mのsetの方が確認する数は減る?
        if visited[s]: continue
        visited[s] = 1
        dq = deque()
        dq.append(s)

        sz = 0
        x = 0
        while dq:
            v = dq.popleft()
            sz += 1
            if v < M:
                x += 1
            for u in g[v]:
                if visited[u]: continue
                visited[u] = 1
                dq.append(u)
        ans += (sz - x) * x

    ans -= N

    print(ans)


if __name__ == '__main__':
    main()

# 連結成分ごとに
# x,yの二部グラフを完全二部グラフにする
# cnt(x)*cnt(y)-既存の辺数の総和

# 最後にN引けばよい


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

def dfs(s):
    if int(s) > N :
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0
    for c in '753':
        ret += dfs(s+c)
    return ret

print(dfs('0'))
                
        

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> Pi; typedef priority_queue<int> Pr; typedef vector<int> Vi; typedef vector<Pi> Vp;
typedef map<int,int> MPi; typedef pair<Int,Int> Pl; typedef vector<Int> VI;
const int mod = 1000000007; const Int INF = 1145141919810893931;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) v.begin(),v.end()
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    int n,k; cin>>n>>k; string s; cin>>s; Vi a; a.push_back(0);
    int key=1,ans=0;
    for (int i = 1; i < n; i++){
        if(s[i]==s[i-1])key++;
        else{a.push_back(key); key=1;}
    }
    a.push_back(key);
    for (int i = 1; i < a.size(); i++)a[i]+=a[i-1];
    for (int i = 1; i < a.size(); i++){
        if((s[0]-'0')%2==i%2)cmax(ans,a[i]-a[max(0,i-2*k-1)]);
        else cmax(ans,a[i]-a[max(0,i-2*k)]);
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 1020
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
	int n;
	cin >> n;
	vector<int> x(n), y(n), h(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> h[i];
		if (h[i] > 0) {
			swap(x[i], x[0]);
			swap(y[i], y[0]);
			swap(h[i], h[0]);
		}
	}

	for (int cx = 0; cx < 101; cx++) {
		for (int cy = 0; cy < 101; cy++) {
			int H = h[0] + abs(x[0] - cx) + abs(y[0] - cy);
			for (int i = 1; i < n; i++) {
				if (h[i] != max(H - abs(x[i] - cx) - abs(y[i] - cy),0)){
					
					break;
				}else if(i+1 == n){
					cout << cx << " " << cy <<" "<< H << endl;
					return 0;
}
			}
		}
	}

}

Measured memory_bytes: 256
MOD = 998244353
MAX = int(2e5 + 5)

fact = [0] * MAX
invFact = [0] * MAX


def bigmod(a, b):
	if b == 0:
		return 1
	ret = bigmod(a, b // 2)
	ret = (ret * ret) % MOD
	if b % 2 == 1:
		ret = (ret * a) % MOD
	return ret


def mod_inverse(a):
	return bigmod(a, MOD - 2)


def pre():
	global fact, invFact
	fact[0] = 1
	for i in range(1, MAX):
		fact[i] = (fact[i - 1] * i) % MOD
	invFact[MAX - 1] = mod_inverse(fact[MAX - 1])
	for i in range(MAX - 2, -1, -1):
		invFact[i] = (invFact[i + 1] * (i + 1)) % MOD


def ncr(nn, rr):
	if nn < 0 or nn < rr or rr < 0:
		return 0
	# up = fact[nn]
	# down = (invFact[rr] * invFact[nn - rr]) % MOD
	return (fact[nn] * invFact[rr] * invFact[nn - rr]) % MOD


pre()
n, m, k = map(int, input().split())


ans = 0
for i in range(k + 1):
	tmp = m * bigmod(m - 1, n - 1 - i) * ncr(n - 1, i)
	tmp %= MOD
	ans = (ans + tmp) % MOD

print(ans)


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

signed main(void)
{
	int i, j;
	string s, diff;

	cin >> s;
	diff = "abcdefghijklmnopqrstuvwxyz";
	sort(s.begin(), s.end());
	i = j = 0;
	if (diff[i] < s[j])
	{
		cout << diff[i] << endl;
		return 0;
	}
	while (j < s.size())
	{
		while (s[j] == diff[i]) j++;
		i++;
		if (diff[i] < s[j] || (j >= s.size() && i < diff.size()))
		{
			cout << diff[i] << endl;
			return 0;
		}
	}
	cout << "None" << endl;
	return 0;
}


Measured memory_bytes: 512
n = int(input())
 
ans = 0
A = 0
B = 0
AB = 0
for _ in range(n):
    s = input()
    ans += s.count('AB')
    
    if s[-1] == 'A' and s[0] != 'B':
        A += 1 
    if s[0] == 'B' and s[-1] != 'A':
        B += 1
    if s[-1] == 'A' and s[0] == 'B':
        AB += 1
    
ans += min(A+AB, B+AB)


if AB>0 and A+B==0:
    ans -= 1

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
long long n, a[1000000];
int main() {
	cin >> n; for (int i = 0; i < 3 * n; i++)cin >> a[i];
	sort(a, a + (3 * n));
	long long sum = 0, c = 3 * n - 2, d = 0;
	while (d < n) { sum += a[c]; c -= 2; d++; }
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 4352
a,b,c,d=map(int,input().split())



for i in range(d):
    r_str = ""
    for j in range(c):
        r_str += "1"
    for j in range(c,b):
        r_str += "0"
    print(r_str)
for i in range(d,a):
    r_str = ""
    for j in range(c):
        r_str += "0"
    for j in range(c,b):
        r_str += "1"
    print(r_str)
        
        


Measured memory_bytes: 3956
using System;
class Program{
    static void Main(){
        string[] s = Console.ReadLine().Split(' ');
        int a,b,c;
        a = int.Parse(s[0]);
        b = int.Parse(s[1]);
        c = int.Parse(s[2]);
        if(a < b && b < c)Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}



Measured memory_bytes: 15944
#include <stdio.h>

int main() {
  int a, b, i, j;
  while(1) {
    scanf("%d%d", &a, &b);
    if(a == 0 && b == 0) break;
    for(i=0; i < a; i++) {
      for(j=0; j < b; j++) {
        if(i == 0 || i == a-1) printf("#");
	else if(j == 0 || j == b-1) printf("#");
	else printf(".");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2048
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	ll l; cin>>l;
	printf("%6lf\n",(l/3.0)*(l/3.0)*(l/3.0));
	return 0;
}


Measured memory_bytes: 256
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import Data.Ord

main :: IO ()
main = readLine >>= print . solve

solve :: [Int] -> Int
solve = sum . tail . sortOn Down 

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

Measured memory_bytes: 380