akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

// template from zscoder

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    int n; cin >> n;
    vi a(n);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a.rbegin(),a.rend());
    ll suma(0),sumb(0);
    for(int i = 0; i < n; i++)
    {
        if(i%2 == 0)
        {
            suma+=a[i];
        }
        else
        {
            sumb+=a[i];
        }
    }
    int ans = (suma - sumb);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<map>
#include<stack>
#include<string>
#include<set>
using namespace std;
const int MAXN = 2e5 + 5;
int score[MAXN];
int main(){
	int n, m;
	cin >> n >> m;
	for (int i = 1;i <= n;i++) {
		cin >> score[i];
	}
	for (int i = m + 1;i <= n;i++) {
		if (score[i] > score[i - m])cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

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

using namespace std;

const int MAXN = 5005;

int n;
int a[MAXN];
vector<int> g[MAXN];

int child[MAXN];

long long temp[MAXN];
long long f[MAXN][MAXN];
/// f(v, d) largest sum remaning if we deleted d edges from subtree v

bool temppos[MAXN];
bool pos[MAXN][MAXN];
/// g(v, d) = true if theres a way to delete d edges from subtree
/// v so that the remaning components are all positive

void dfs(int v, int p) {
  if(g[v].size() == 1 && g[v].front() == p) {
    child[v] = 1;
    f[v][0] = a[v];
    f[v][1] = 0;
    pos[v][1] = 1;
    pos[v][0] = (a[v] > 0);
    return;
  }

  f[v][0] = a[v];
  pos[v][0] = (a[v] > 0);

  for(int s : g[v]) if(s != p) {
    dfs(s, v);

    fill(temp, temp + child[s] + child[v] + 1, (long long)1e18);
    fill(temppos, temppos + child[s] + child[v] + 1, false);

    for(int i = child[v]; i >= 0; --i) {
      for(int j = 0; j <= child[s]; ++j) {
        temp[i + j] = min(temp[i + j], f[v][i] + f[s][j]);
        temppos[i + j] = max(temppos[i + j], (pos[v][i] && pos[s][j]));
      }
    }
    child[v] += child[s];
    for(int i = 0; i <= child[v]; ++i) {
      f[v][i] = temp[i];
      pos[v][i] = temppos[i];
    }
  }

  child[v] += 1;

  if(v == 0) {
    for(int i = 0; i <= child[v]; ++i) {
      if(f[v][i] < 0 || pos[v][i]) {
        cout << i << endl;
        return;
      }
    }
  }

  for(int i = child[v]; i > 0; --i) {
    if(f[v][i - 1] < 0 || pos[v][i - 1]) {
      f[v][i] = min(f[v][i], 0LL);
      pos[v][i] = 1;
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL);

  cin >> n;
  for(int i = 0; i < n; ++i) cin >> a[i];
  for(int i = 0; i < n - 1; ++i) {
    int u, v; cin >> u >> v;
    --u; --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }

  memset(f, 60, sizeof f);

  dfs(0, -1);

  //cout << pos[4][2] << endl;


  return 0;
}


Measured memory_bytes: 221312
// cout << "Case #" << test << ": ";
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    ll n, c, k;
    cin >> n >> c >> k;
    vector<ll> t(n);
    for(int i = 0; i < n; i++) {
        cin >> t[i];
    }
    sort(all(t));
    ll p = 0;
    ll ans = 0;
    ll curr = 0, cum = 0;
    while(p < n) {
        if(t[p] <= curr && cum < c) {
            cum++;
            p++;
            continue;
        }
        if(t[p] <= curr && cum == c) {
            ans++;
            curr = t[p] + k;
            cum = 0;
            continue;
        }
        if(t[p] > curr) {
            ans++;
            cum = 0;
            curr = t[p] + k;
            continue;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main () {
  int H, W;
  cin >> H >> W;
  string S;
  for(int i = 0; i < H; i++) {
    cin >> S;
    for(int j = 0; j < 2; j++) cout << S << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};

// Self settings
// clang-format off
#define MAX_N 100000
#define MAX 100000
#define INFTY (1<<30)
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1000100011;
class Point { public: double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} Point operator+(Point p) { return Point(x + p.x, y + p.y); } Point operator-(Point p) { return Point(x - p.x, y - p.y); } Point operator*(double a) { return Point(a * x, a * y); } Point operator/(double a) { return Point(x / a, y / a); } double abs() { return sqrt(norm()); } double norm() { return x * x + y * y; } bool operator<(const Point& p) const { return x != p.x ? x < p.x : y < p.y; } bool operator==(const Point& p) const { return fabs(x - p.y) < EPS && fabs(y - p.y) < EPS; } };
typedef Point Vector;
double norm(Vector a) { return a.x * a.x + a.y * a.y; }
double abs(Vector a) { return sqrt(norm(a));}
double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }
struct Segment { Point p1, p2; };
typedef Segment Line;
// clang-format on

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  vector<int> X(N), L(N);
  vector<P> ps(N);
  REP(i, N) { cin >> X[i] >> L[i]; }

  // REP(i, N) ps[i] = P(X[i] - L[i], X[i] + L[i]);
  // REP(i, N) ps[i] = P(X[i] + L[i], X[i] - L[i]);
  // sort(ps.begin(), ps.end());
  // REP(i, N) {
  //   P p = ps[i];
  //   // cout << "(" << p.first << ", " << p.second << ")" << endl;
  // }

  REP(i, N) ps[i] = P(X[i] - L[i], X[i] + L[i]);
  sort(ps.begin(), ps.end());
  reverse(ps.begin(), ps.end());

  ll ans = 0;
  ll cur = INF;
  REP(i, N) {
    P p = ps[i];
    if (cur >= p.second) {
      ans++;
      cur = p.first;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  long long N, M;
  cin >> N >> M;

  vector<pair<long long,long long>> shop(N);

  for (int i=0; i < N; i++) {
    long long p, n;
    pair<long long, long long> pair;

    cin >> p >> n;
    shop[i] = make_pair(p, n);
  }

  sort(shop.begin(), shop.end());

  long long m = M;
  long long p = 0;
  // first: price, second:# of drinks
  for (int i=0; i < N; i++) {
    if (m == 0)
      break;

    int buy = min(m, shop[i].second);
    p += buy * shop[i].first;
    m -= buy;
  }

  cout << p << endl;
}


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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

bool ok = true;
int r = -1;

int sch(int now, int prev, const vvi &g, const vi &a, const vi &d) {
  if(d[now] == 1 && now != r) {
    return a[now];
  }
  int su = 0;
  vi tmp;
  for(auto nxt: g[now]) {
    if(nxt == prev) continue;
    tmp.push_back(sch(nxt, now, g, a, d));
    su += tmp.back();
  }
  //cout << "now:" << now << endl;
  //cout << "su:" << su << endl;
  if(now == r) {
    ok &= su == a[r];
    return 0;
  }
  int res = 2*a[now] - su;
  //cout << tmp << " " << res << endl;

  if(res < 0) ok = false;

  su += res;

  ok &= su % 2 == 0;

  REP(i, SZ(tmp)) {
    if(tmp[i] > su/2) {
      ok = false;
      break;
    }
  }
  if(res > su/2) {
    ok = false;
  }

  //cout << now << ":" << res << endl;

  return res;
}

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

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

  vvi g(n);
  vi d(n);
  REP(i, n-1) {
    int u, v; cin >> u >> v;
    u--; v--;
    g[u].push_back(v);
    g[v].push_back(u);
    d[u]++;
    d[v]++;
  }

  REP(i, n) {
    if(d[i] == 1) {
      r = i;
      break;
    }
  }

  //cout << r << endl;
  int res = sch(r, -1, g, a, d);
  //cout << res << endl;

  cout << (ok ? "YES" : "NO") << endl;

}
























Measured memory_bytes: 20608
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    string s;cin>>s;
    vector<ll[13]> dp(s.size()+1);
    constexpr ll mod = 1e9+7;
    dp[0][0]=1;
    REP(i,s.size()){
        REP(j,13){
            if(s[i]!='?') (dp[i+1][(10*j+s[i]-'0')%13] += dp[i][j])%=mod;
            else REP(k,10){
                (dp[i+1][(10*j+k)%13] += dp[i][j])%=mod;
            }
        }
    }
    cout<<dp[s.size()][5]<<endl;
}


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

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int path[26][26];
int visited[26];

int dfs(int src,int* visited){
    visited[src] = 1;
    int res = 1;
    for(int i=0;i<26;i++){
        if(path[src][i] && visited[i] == 0){
            res += dfs(i,visited);
        }
    }
    return res;
}

int main(){
    int n;
    
    while(~scanf("%d",&n)){
        if(n==0) break;
        memset(path,0,sizeof(path));
        memset(visited,0,sizeof(visited));
        set<int> src;
        for(int i=0;i<n;i++){
            string str;
            cin >> str;
            path[*str.begin()-'a'][*(str.end()-1)-'a']++;
            
            src.insert(*(str.end()-1)-'a');
            src.insert(*str.begin()-'a');
        }
        
        if(src.size() != dfs(*src.begin(),visited)){
            printf("NG\n");
            continue;
        }
        
        bool isok=true;
        
        for(set<int>::iterator it = src.begin(); it != src.end(); it++){
            int out=0;
            for(int j=0;j<26;j++){
                out += path[*it][j];
            }
            
            int in=0;
            for(int j=0;j<26;j++){
                in += path[j][*it];
            }
            
            if(out != in) isok = false;
        }
        
        printf("%s\n",isok ? "OK" : "NG");
    }
}

Measured memory_bytes: 1212
#include <cstdio>
#include <algorithm>
using namespace std;
int shop[100001];
int main(){
	int n,m,d,k,i,s;
	for(;scanf("%d",&d),d;){
		scanf("%d%d",&n,&m);
		for(i=2;i<=n;i++){
			scanf("%d",&k);
			shop[i-1] = k;
		}
		shop[n] = d;
		sort( shop+1, shop+n );
		s=0;
		for(;m--;){
			scanf("%d",&k);
			int* it = upper_bound( shop, shop+n+1, k );
			s+=min(*it - k, k - it[-1] );
		}
		printf("%d\n",s);
	}
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    int n, m;
    string s;
    cin >> n >> m >> s;
    vector<int> dp(n+1, INF);
    dp[n] = 0;
    queue<int> q;
    q.push(0);
    for (int i = n-1; i >= 0; i--) {
        while (1) {
            if (q.size() == 0) {
                cout << -1 << endl;
                return 0;
            }
            if (q.front() != INF && q.size() <= m) break;
            q.pop();
        }
        if (s[i] == '0') dp[i] = q.front()+1;
        q.push(dp[i]);
    }
    vector<int> ans;
    int x;
    int rest = dp[0];
    while (x < n) {
        rest--;
        int i = 1;
        while (dp[x+i] != rest) i++;
        ans.push_back(i);
        x += i;
    }
    rep(i,ans.size()) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 4288
def solve(a, n):
    f = [0] * n
    f[1] = abs(a[1] - a[0])

    for i in range(2, n):
        f[i] = min(f[i-1] + abs(a[i] - a[i-1]), f[i-2] + abs(a[i] - a[i-2]))

    return f[n-1]


def main():
    n = int(input())
    a = [int(x) for x in input().split()]
    print(solve(a, n))


if __name__ == '__main__':
    main()



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

using namespace std;
typedef long long ll;

int fact(int x){
	return x*fact(x-1);
}

int main(){
	int N, M;
	cin >> N >> M;
	cout <<  N*(N-1)/2 + M*(M-1)/2 << endl;
}
			
		


Measured memory_bytes: 256
N, X = map(int, input().split())
lst = list(map(int, input().split()))
x = [abs(X - i) for i in lst]
def gcd(a,b):
    if b==0:return a
    return gcd(b,a%b)


if N==1:
    print(x[0])
else:
    element = gcd(x[0], x[1])
    if N==2:print(element)
    else:
        for i in range(2,N):
            element=gcd(element,x[i])
        print(element)

Measured memory_bytes: 14224
#include <stdio.h>
#include <stdlib.h>
int n;
int fact[8]={1,1,2,6,24,120,720,5040};

int f(int*a){
	int mask=(1<<n)-1;
	int ans=0;
	for(int i=0;i<n;i++){
		ans+=__builtin_popcount(mask&((1<<a[i])-1))*fact[n-1-i];
		mask^=1<<a[i];
	}
	return ans;
}

int p[8],q[8];
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",p+i),p[i]--;
	for(int i=0;i<n;i++)scanf("%d",q+i),q[i]--;
	printf("%d",abs(f(p)-f(q)));
}

Measured memory_bytes: 128
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0;i<n;i++)

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    int cnt_minus = 0;
    REP(i, N)
    {
        cin >> A[i];
        B[i] = abs(A[i]);
        if (A[i] < 0)
        {
            cnt_minus++;
        }
    }
    sort(B.begin(), B.end());
    int min = B[0];
    long sum = 0;
    REP(i, N)
    {
        sum += B[i];
    }
    if (cnt_minus%2 != 0)
    {
        sum -= 2*min;
    }

    cout << sum << endl;
}

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

using namespace std;

void solve() {
    int N, M;
    cin >> N >> M;
    int ans;
    ans = ((N - M) * 100 + M * 1900);
    for (int i = 0; i < M; i++)
    {
        ans *= 2;
    }
    cout << ans << endl;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 3572
#include <iostream>

int main ()
{
	const double pi = 3.14159265358979323846;
	double r;
	std::cin >> r;

	std::cout << std::fixed;
	std::cout << pi * r * r;
	std::cout << " ";
	std::cout << 2.0 * pi * r;
	std::cout << std::endl;
}

Measured memory_bytes: 3264
/*
 * 1.cpp
 */

//include files
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>

using namespace std;

//DEFINE MACROS
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define PRINTLN(s) cout << s << endl

//DEFINE CONSTANT

//DEFINE PROTOTYPE
int main(){
  int N,K;
  int x;
  int sum = 0;
  cin >> N;
  cin >> K;
  for (int i=0; i < N; i++) {
	cin >> x;
	sum += MIN(abs(2*(x)),abs(2*(x-K)));
  }
  cout << sum << "\n";  
  
  return 0;
}



Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){

     ll n, m;
     cin>>n>>m;
     ll a[n];
     ll s = 0;
     for(int i=0; i<n; i++) {
        cin>>a[i];
     }
     sort(a, a+n);
     for(int i=0; i<n-m; i++) {
        s += a[i];
     }
     cout<<s;
}


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

int main() {
  int N,T,A;
  cin>>N>>T>>A;
  
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  
  vector<int> tem(N);
  for(int i=0;i<N;i++){
    tem.at(i)=1000*T-6*vec.at(i);
  }
  
  int num =0;
  int hi=tem.at(0);
  for(int i=1;i<N;i++){
    if(abs(hi-1000*A)>abs(tem.at(i)-1000*A)){
      hi=tem.at(i);
      num=i;
    }
  }
  cout<<num+1<<endl;
}

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

jobs = []
for _ in range(n):
    jobs.append([int(i) for i in raw_input().split()])

jobs.sort(key=lambda a: a[1])

finish_time = 0

result = True
for job in jobs:
    finish_time = finish_time + job[0]
    if finish_time > job[1]:
        result = False
        break

if result:
    print "Yes"
else:
    print "No"

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

using namespace std;

int main()
{
    int n;
    string s;

    cin >> n >> s;

    int max = -1;

    for (int i = 1; i < n; i++)
    {
        int cnt = 0;
        vector<bool> ala(26, false);
        vector<bool> alb(26, false);
        // cout << "i:" << i << endl;
        for (int j = 0; j < i; j++)
        {
            // cout << s[j] << ",";
            ala[s[j] - 'a'] = true;
        }
        // cout << endl;
        for (int k = i; k < n; k++)
        {
            // cout << s[k] << ",";
            alb[s[k] - 'a'] = true;
        }
        // cout << endl;
        for (int j = 0; j < 26; j++)
        {
            if (ala[j] && alb[j])
            {
                cnt++;
            }
        }
        // cout << "cnt:" << cnt << endl;
        if (max < cnt)
        {
            max = cnt;
        }
        // cout << endl;
    }
    cout << max << endl;
    return 0;
}


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

using namespace std;

int main()
{
    int n, s = 0;
    cin >> n;
    int a[n], b[n], c[n - 1];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++)
    {
        cin >> b[i];
    }
    for (int i = 0; i < n - 1; i++)
    {
        cin >> c[i];
    }
    for (int i = 1; i < n; i++)
    {
        if (a[i] - a[i - 1] == 1)
        {
            s += c[a[i] - 1 - 1];
        }
    }
    s += accumulate(b, b + n, 0);
    cout << s << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int>h(N);
  vector<int>dp(N);
  for (int i = 0; i < N; i++) {
    cin >> h.at(i);
    dp.at(i) = 0;
  }
  dp.at(1) = abs(h.at(1) - h.at(0));
  for (int i = 2; i < N; i++) {
    dp.at(i) = min(dp.at(i-1) + abs(h.at(i-1) - h.at(i)), dp.at(i-2) + abs(h.at(i-2) - h.at(i)));
  }
  cout << dp.at(N-1);
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>

int main() {
	std::vector<std::string> tenki{ "Sunny", "Cloudy", "Rainy" };
	std::string str; std::cin >> str;
	auto current = std::distance(tenki.begin(), std::find(tenki.begin(), tenki.end(), str));
	std::cout << tenki[(current + 1) % 3] << std::endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.Map.*;

class Main{
	static int mod=1000000007;

	public static void main(String[] $){
		System.err.println();
		Scanner s=new Scanner(System.in);

		int n=s.nextInt();

		TreeMap<Integer,Integer>m=new TreeMap<>();
		for(int i=0;i<n;++i) {
			int v=s.nextInt();
			Entry<Integer,Integer> l=m.lowerEntry(v);
			if(l!=null) {
				if(l.getValue()==1)
					m.remove(l.getKey());
				else
					m.merge(l.getKey(),-1,Integer::sum);
			}
			m.merge(v,1,Integer::sum);
		}
		System.out.println(m.values().stream().mapToInt(i->i).sum());
	}
}

Measured memory_bytes: 66300
#include <bits/stdc++.h>
using namespace std;
#define int long long int 
#define pb push_back
#define fi first
#define se second
#define fr(i,l,r) for(int i=l;i<=r;i++)
int n;
long double dp[301][301][301][2];
long double fun(int a0,int a1,int a2,int a3)
{   
    if(a0<0 || a1<0 || a2<0 || a3<0)return 0;
    if(dp[a1][a2][a3][1]!=-1 && dp[a1][a2][a3][0]==a0)
    {
        return dp[a1][a2][a3][1];
    }

    if(a2 ==0 && a3==0 && a1==1)
        {dp[a1][a2][a3][0]=a0;
            return dp[a1][a2][a3][1]=a0+1;}
    int y=a1+a2+a3;
    dp[a1][a2][a3][0]=a0;
     dp[a1][a2][a3][1]=(a0+a1+a2+a3)+a1*fun(a0+1,a1-1,a2,a3)+a2*fun(a0,a1+1,a2-1,a3)+a3*fun(a0,a1,a2+1,a3-1);
     return dp[a1][a2][a3][1]=(long double)dp[a1][a2][a3][1]/y;
}
signed main()
{   //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin>>n;
    int a[4]={0};

    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        a[x]++;
    }

    for(int i=0;i<301;i++)
    {
        for(int j=0;j<301;j++)
        {
            for(int k=0;k<301;k++)
            {
                for(int l=0;l<2;l++)dp[i][j][k][l]=-1;
            }
        }
    }

  cout<<setprecision(15)<<fun(0,a[1],a[2],a[3])<<endl;;
    return 0;
}

Measured memory_bytes: 852608
package main

import (
	"fmt"
)

func main() {
	var n,k int
	fmt.Scan(&n,&k)
	
	sunukes := make([]bool,n)
	
	for i := 0; i < k; i++ {
		var d int
		fmt.Scan(&d)
		for j := 0; j < d; j++ {
			var i int
			fmt.Scan(&i)
			i--
			sunukes[i] = true
		}
	}
	
	cnt := 0;
	for i := 0; i < n; i++ {
		if !sunukes[i] {
			cnt++
		}
	}
	fmt.Println(cnt)
}

Measured memory_bytes: 2468
// #include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
// #include <algorithm>
#define pb push_back
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define f first
#define s second
// #define cerr if(0)cerr
using namespace std;
typedef long long LL;
typedef pair<int,LL> PILL;

const int N=3010;
int n;
double res=0;
double T[N],DP[N][N];

LL maxi(LL x, LL y){if(y>x)return y;return x;}

int main()
{
  // boost;
  scanf("%d",&n);
  for(int i=1; i<=n; i++)
    scanf("%lf",&T[i]);

  DP[0][0] = 1;
  for(int i=1; i<=n; i++)
    for(int j=0; j<=i; j++)
    {
      DP[i][j]=DP[i-1][j]*(1-T[i]);
      if(j)DP[i][j]+=DP[i-1][j-1]*T[i];
    }

  for(int i=(n+1)>>1; i<=n; i++)
    res+=DP[n][i];
  printf("%.9f",res);

  return 0;
}


Measured memory_bytes: 69120
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=998244353 ;


int main(){
  int n, k; cin >> n >> k;  int p[n];
  rep(i, n){
    cin >> p[i];
  }
  sort(p, p+n); int ans = 0;
  rep(i, k){
    ans+=p[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <memory>
#define rep(i, n) for(Int (i) = 0; (i) < (n); ++(i))
#define debug(var) cout << #var << ": " << var << endl
using namespace std;
using Int = int64_t;
using Uint = uint64_t;
constexpr Uint mod = 1e9 + 7;
constexpr Int INF = INT_MAX;
using Container = vector<Int>;
template<typename T>
using Grid = vector<vector<T>>; // 二次元配列。[y][x]
template<typename T, typename U>
using Umap = unordered_map<T, U>;
template<typename T>
using Uset = unordered_set<T>;
template<typename T>
using P = pair<T, T>;


int main() {

	Int H, N; cin >> H >> N;
	Container A(N), B(N);
	rep(i, N)cin >> A[i] >> B[i];
	Grid<Int> dp(N + 1, vector<Int>(H + 1, INF)); // [x][y]
	rep(i, N)dp[i][0] = 0;
	rep(i, N)rep(j, H + 1) {
		dp[i + 1][j] = min(dp[i + 1][j], dp[i + 1][max(j - A[i], (Int)0)] + B[i]);
		dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
	}

	cout << dp[N][H] << endl;

}

Measured memory_bytes: 78592
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define reverse(x) reverse(x.begin(), x.end())
#define sort(x) sort(x.begin(), x.end())
#define pb push_back
#define pii pair<int, int>
#define pll pair<long long,long long>
#define f first
#define s second
typedef long long ll;
const int mod = 1e9+7;
using namespace std;
int a[100005], n, m;

int main(){
	int i, j;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	int ans=0,c = 0;
	for(i=1;i<n;i++){
		if(a[i] <= a[i-1])c++;
		else c = 0;
		ans = max(c, ans);
	}
	cout << ans;
}

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

using namespace std;

const int Nmax = 2e5 + 10;
const int Mod = 1e9 + 7;
const int oo = 1e9;

string s;


int main()
{
/**
    #ifndef ONLINE_JUDGE

        ifstream cin("test.in");

    #endif // ONLINE_JUDGE
*/

    cin >> s;

    cout << (s == "ABC" ? "ARC" : "ABC");

    return 0;
}


Measured memory_bytes: 3592
n=int(input())
st=[]
ans=0
for i in range(n):
	s,t=map(int,input().split())
	st.append([s,t])
st.sort(key=lambda x:x[1])
time=0
i=0
ans=0
while i<n:
	if st[i][0]>time:
		ans+=1
		time=st[i][1]
	i+=1
print(ans)


Measured memory_bytes: 21992
#include<iostream>
#include<algorithm>
#include<vector>
#include<tuple>
#include<string>
std::string S;
std::vector<std::string> A;
int K;
int main() {
	std::cin >> S >> K;
	for (int i = 0; i < S.size(); i++) {
		for (int j = 1; j <= K; j++) {
			A.emplace_back(S.substr(i, j));
		}
	}
	std::sort(A.begin(), A.end());
	A.erase(std::unique(A.begin(), A.end()), A.end());
	std::cout << A[K - 1] << std::endl;
	return 0;
}

Measured memory_bytes: 1660
import sys
#import collections as col
input=sys.stdin.readline

def facto(x, y, mod):
	re = 1
	for i in range(y, x+1):
		re *= i
		re %= mod
	print(re, file=sys.stderr)
	return re

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

mod = 10**9+7 #出力の制限
NN = 2 * 10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

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


def main():
	N,A,B=map(int,input().split())
	#N=input().rstrip()
	#N=int(input())
	#vA=list(map(int,input().split()))
	M = 10**9 + 7
	
	res = pow(2, N, M) - 1
	res = (res+M) % M
	res -= cmb(N, A, M)
	res = (res+M) % M
	res -= cmb(N, B, M)
	res = (res+M) % M
	
	print(res)


main()


Measured memory_bytes: 80880
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
int main(void){
    long long n, x, m;
    cin >> n >> x >> m;

    long long a = x, ans = 0;
    vector< long long > sum(m+1, 0);
    map< long long, int> mem;
    for(int i=1; ;i++){
        sum[i] = sum[i-1] + a;
        mem[ a ] = i;
        if(i == n){
            cout << sum[i] << endl;
            return 0;
        }
        a = a*a % m;
        auto itr = mem.find(a);
        if(itr == mem.end()) continue;
        int j = itr->second;
        int l = i-j+1;
        ans = sum[i] + (sum[i] - sum[j-1]) * ((n-i) / l);
        n = (n-i) % l;
        ans += sum[j-1+n] - sum[j-1];
        cout << ans << endl;
        return 0;
    }
}


Measured memory_bytes: 6840
#include<stdio.h>
#include<string>
#include<iostream>
using namespace std;
int main()
{
	string s;
	cin>>s;
	for(int i=0;i<s.size();)
	{
		if(s[i]=='S'&&s[i+1]=='T')
		{
			s.erase(i,1);
			s.erase(i,1);
			if(i!=0){
				i--;
			}
		}
		else
			i++;
	}
	cout<<s.size()<<endl;	
}

Measured memory_bytes: 640
#include "bits/stdc++.h"

typedef long long ll;
using namespace std;

const ll MOD = 1e9+7;
const ll INF = 1e18+7;

signed main(){
	int n, k;
	cin >> n >> k;
	unordered_set<char> m;
	for(int i = 0; i < k; ++i){
		char x;
		
		cin >> x;
		m.insert(x);
	}
	do{
		string t = to_string(n);
		bool flag = true;
		for(auto& x : t)
			flag &= (m.find(x) == m.end());
		if(flag)
			break;
	}while(++n);
	cout << n << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var x = int.Parse(Console.ReadLine());
            var answer = 1;
            var i = (int)Math.Sqrt(x);
            while (i > 1)
            {
                var tmp = i * i;
                while (tmp <= x)
                {
                    answer = Math.Max(answer, tmp);
                    tmp *= i;
                }
                i--;
            }
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 11092
alp = [chr(i) for i in range(97, 97+26)]

def dfs(s, max_):
    if len(s)==N:
        print(s)
    else:
        for i in range(max_+1):
            if i==max_:
                dfs(s+alp[i], max_+1)
            else:
                dfs(s+alp[i], max_)
                
        
N = int(input())
dfs('',0)


Measured memory_bytes: 58968
import sys,re
c=lambda l,n:re.sub("\w",lambda x:chr((ord(x.group(0))-97+n)%26+97),l)
for i in sys.stdin:
	n=0
	while not re.search("th(e|is|at)",c(i,n)):n+=1
	print c(i,n).strip()

Measured memory_bytes: 4204
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>

#define INF 10e10
#define REP(i,n) for(int i=0; i<n; i++)
#define REP_R(i,n,m) for(int i=m; i<n; i++)
#define MAX 100

using namespace std;

typedef long long ll;

const int nmax = 8;
bool graph[nmax][nmax];
int N,M;

int dfs(int v, int i, bool visited[nmax]);

int main() {
  cin >> N >> M;
  REP(i,M) {
    int a,b;
    cin >> a >> b;
    graph[a-1][b-1] = graph[b-1][a-1] = true;
  }

  int res = 0;
  bool visited[nmax];

  REP(i,nmax) visited[i] = false;

  visited[0] = true;

  res = dfs(0, N, visited);
  cout << res << endl;
}

int dfs(int v, int N, bool visited[nmax]) {
  bool all_visited = true;

  REP(i,N) {
    if (!visited[i]) all_visited = false;
  }

  if (all_visited) return 1;

  int res = 0;

  for (int i = 0; i < N; i++) {
    if (!graph[v][i]) continue;
    if (visited[i]) continue;

    visited[i] = true;
    res += dfs(i, N, visited);
    visited[i] = false;
  }

  return res;
}


Measured memory_bytes: 256
//RMQ and RUQ
//https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/2/DSL_2_D
//https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/2/DSL_2_F
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001

#define NUM 2147483647

int N = 1;
int* value;

void init(int first_N){
	while(N < first_N)N *= 2;
}

//update(s, t, value, 0, 0, N-1)でas,as+1,...,atの値をxに変更する
void update(int update_left,int update_right,int new_value,int node_id,int node_left,int node_right){
	if(update_right < node_left || update_left > node_right)return;
	else if(update_left <= node_left && update_right >= node_right){
		value[node_id] = new_value;
	}else{
		if(value[node_id] >= 0){
			value[2*node_id+1] = value[node_id];
			value[2*node_id+2] = value[node_id];
			value[node_id] = -1;
		}
		update(update_left,update_right,new_value,2*node_id+1,node_left,(node_left+node_right)/2);
		update(update_left,update_right,new_value,2*node_id+2,(node_left+node_right)/2+1,node_right);
	}
}

//query(loc, loc, 0, 0, N-1)でalocの値を出す(sumもあるかもしれないが要検討)
int query(int search_left,int search_right,int node_id,int node_left,int node_right){
	if(search_right < node_left || search_left > node_right){
		return -1;
	}else if(node_left <= search_left && node_right >= search_right && value[node_id] >= 0){
		return value[node_id];
	}else{
		int left = query(search_left,search_right,2*node_id+1,node_left,(node_left+node_right)/2);
		int right = query(search_left,search_right,2*node_id+2,(node_left+node_right)/2+1,node_right);
		return max(left,right);
	}
}

//querymin(s,t)で[s,t]の最小
int querymin(int search_left,int search_right,int node_id,int node_left,int node_right){
	if(search_right < node_left || search_left > node_right){
		return NUM;
	}else{
		if(value[node_id] != -1)return value[node_id];
		else{
			int left = querymin(search_left,search_right,2*node_id+1,node_left,(node_left+node_right)/2);
			int right = querymin(search_left,search_right,2*node_id+2,(node_left+node_right)/2+1,node_right);
			return min(left,right);
		}
	}
}

//問題は0-indexedで渡されている(2つとも)
int main(){
	int n, q; cin >> n >> q;
	init(n);

	value = new int[270000];

	for(int i = 0; i <= 2*N-2; i++) value[i] = NUM;

	int command, left, right, value, loc;

	for(int i = 0; i < q; i++){
		cin >> command;

		if(command == 0){
			cin >> left >> right >> value;
			update(left,right,value,0,0,N-1);
		}else{
			cin >> left >> right;
			cout << querymin(left, right, 0, 0, N-1) << endl;
		}
	}
}



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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

class Combination {
private:
    const int N;
    const lint MOD;
    std::vector<lint> fact, inv;
    
    lint powmod(lint x, lint k) {
        lint res = 1;
        while (k) {
            if (k & 1) res = (res * x) % MOD;
            x = (x * x) % MOD;
            k >>= 1;
        }
        return res;
    }
    
    void precomputation() {
        fact[0] = fact[1] = 1;
        for (int i=2; i<=N; ++i) fact[i] = (fact[i-1] * i) % MOD;
        for (int i=0; i<=N; ++i) inv[i] = powmod(fact[i], MOD-2);
    }
    
public:
    Combination(int N, lint MOD) : N(N), MOD(MOD), fact(N + 1), inv(N + 1) {
        precomputation();
    }
    
    lint compute(int n, int k, bool duplicate = false) {
        if (duplicate) return compute(n+k-1, k);
        if (k == 0) return 1;
        if (n < k) return 0;
        lint res = fact[n];
        res = (res * inv[n-k]) % MOD;
        res = (res * inv[k]) % MOD;
        return res;
    }

    lint compute_P(int n, int k) {
        if (k == 0) return 1;
        if (n < k) return 0;
        return (fact[n] * inv[n - k]) % MOD;
    }
};

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

    const lint MOD = (lint)1e9 + 7;
    Combination comb(M + 1, MOD);

    lint ans = 0, d = 1;
    for_(i,0,N+1) {
        lint a = comb.compute(N, i);
        lint b = comb.compute_P(M, i);
        lint c = comb.compute_P(M - i, N - i);
        lint add = (a * b) % MOD;
        add = (add * c) % MOD;
        add = (add * c) % MOD;
        ans += (add * d);
        ans = (ans + MOD) % MOD;
        d *= -1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 10972
import bisect
import math
N = int(input())
x = list(map(int, input().split()))
L = int(input())

m = int(math.log(max(x), 2) + 1)
#i番目のホテルから2 ** k 日以内に到達可能な
#もっとも右にあるホテル
r = [[-1] * N for k in range(m)]
for i in range(N):
  base = x[i] + L
  p = bisect.bisect_right(x, base)
  #print(p)
  r[0][i] = p - 1

#ダブリング
for k in range(m - 1):
  for i in range(N):
    r[k + 1][i] = r[k][r[k][i]]
#print(r)    
   
def isOK(mid):
  now = a
  pp = int(math.log(mid, 2) + 1)
  for i in range(pp):
    if (mid >> i) & 1:
      now = r[i][now]
      #print(now, a + 1, b + 1, mid)
  if now >= b:
    return True
  else:
    return False
  
Q = int(input())
for i in range(Q):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  if a > b:
    a, b = b, a
  ng = 0
  ok = 2 ** m
  while (abs(ok - ng) > 1):
    mid = int((ok + ng) / 2)
    #print(mid)
    if isOK(mid):
      ok = mid
    else:
      ng = mid
  print(ok)
         

         
         
         

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

int main(void) {
    int n, m, l, i, j, k;
    long s;
    cin >> n >> m >> l;
    int a[n][m];
    int b[m][l];
    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    for (i = 0; i < m; i++) {
        for (j = 0; j < l; j++) {
            cin >> b[i][j];
        }
    }

    for (i = 0; i < n; i++) {
        for (j = 0; j < l; j++) {
            s = 0;
            for (k = 0; k < m; k++) {
                s += a[i][k] * b[k][j];
            }
            cout << s;
            if (j == l - 1) cout << endl;
            else cout << " ";
        }
    }
    return 0;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

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

  int n, k;
  cin >> n >> k;

  cout << (n % k == 0 ? 0 : 1) << "\n";

  return 0;
}

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

using namespace std;

typedef long long ll;

ll Ile2(ll n, ll x)
{
    n -= n % x;
    return n / x + 1;
}

ll Ile(ll n, ll x, ll y)
{
    return (n + 1) - (Ile2(n, x) + Ile2(n, y) - Ile2(n, x * y / __gcd(x, y)));
}

int main()
{
    ios_base::sync_with_stdio(0);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << Ile(b, c, d) - Ile(a - 1, c, d);
    return 0;
}


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

int main() {
    int X; cin >> X;
    int res = 1;
    for(int i=2; i<X; ++i) {
        int c = i;
        while(c * i <= X) c *= i;
        if(c != i) res = max(res, c);
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
int dy[]={1,-1,0,0};
int dx[]={0,0,1,-1};

int main(){
  int N;
  cin>>N;
  vector<double>  p(N);
  for(int i=0;i<N;i++) cin>>p[i];

  vector<vector<double>>  dp(N,vector<double>(N+1,0.0)); //dp[i][j]がcoin 0~iを投げてj回表が出る回数

  dp[0][0]=1.0-p[0];
  dp[0][1]=p[0];

  for(int i=1;i<N;i++){
    dp[i][0]=dp[i-1][0]*(1.0-p[i]);
    for(int j=1;j<=N;j++){
      dp[i][j]=dp[i-1][j-1]*p[i]+dp[i-1][j]*(1.0-p[i]);
    }
  }
  double ans=0.0;
  for(int i=N/2+1;i<=N;i++){
    ans+=dp[N-1][i];
  }
  printf("%.12f\n",ans);

  return 0;
}



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


namespace ABC125C
{
    class Program
    {
        static void Main(string[] args)
        {
            var button = Console.ReadLine().Split().Select(int.Parse).ToList();
            var A = button[0];
            var B = button[1];
            var sum = 0;
            if (A > B)
            {
                sum += A;
                A--;
            }
            else
            {
                sum += B;
                B--;
            }
            if (A > B)
            {
                sum += A;
            }
            else
            {
                sum += B;
            }
            Console.WriteLine(sum);
        }
    }
}

Measured memory_bytes: 11220
#include <stdio.h>
int main(void)
{
	char S1[16],S2[16],S3[16];
	char A,B,C;
	
	scanf("%s %s %s",S1,S2,S3);
	
	A=S1[0]-32;
	B=S2[0]-32;
	C=S3[0]-32;
	
	printf("%c%c%c",A,B,C);
	
	return 0;
}

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

int main() {

	int n;
	int	arr[10000];
	int max = -1000000;
	int min = 1000000;
	long long sum = 0;

	//数値入力

	cin >> n;


	//入力した数値の格納
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
		//最小値
		if (min > arr[i])
		{
			min = arr[i];
		}
		//最大値
		if (max < arr[i])
		{
			max = arr[i];
		}
		//合計値
		sum = sum + arr[i];
	}
	//出力
	cout << min << " " << max << " " << sum << endl;

	return 0;
}


Measured memory_bytes: 3136
#include<iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <functional>
#include <vector>

using namespace std;
int main()
{
	string s;
	cin >> s;

	s.replace(5, 1, " ");
	s.replace(13, 1, " ");

	cout << s;
	return 0;
}

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

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

  double ans;
  ans = (double)floor((n+1)/2)/(double)n;

  printf("%.10f\n",ans);
  
  return 0;
}


Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
//void chmin(int &a, int b) { if (a > b) a = b; }
//void chmax(int &a, int b) { if (a < b) a = b; }

int main() {
    string s;
    cin >> s;
    if(s.size() %2 == 1){
        cout << "No" << endl;
        return 0;
    }
    for (int i = 0; i < s.size(); ++i) {
        if(i%2 == 0 && s[i] != 'h'){
            cout << "No" << endl;
            return 0;
        }else if(i%2 == 1 && s[i] != 'i'){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int a,s,b;
    cin>>a>>b;
    s=10;
    int k=0;
    int y=0;
    while(s!=0){
        int x=s%10;
        y+=x*pow(a,k);
        s=s/10;
        k++;
    }
    
    int t[100]{0};
    k=0;
    while(y!=0){
        k++;
        t[k]=y%b;
        y=y/b;
    }
    cout<<k;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int mo=1e9+7;
int n,m,t;
int gcd(int a, int b){return !b?a:gcd(b,a%b);}
int power(int a, ll n){
	int res=1;
	while(n){
		if(n&1)res=1LL*res*a%mo;a=1LL*a*a%mo;n>>=1;
	}
	return res;
}
int solve(int n, int m){
	return (1LL*power(2,n)+power(2,m)+power(2,gcd(n,m))-3)%mo;
}

int main() {
	read(n);read(m);read(t);
	int res=power(solve(n/gcd(n,t),m/gcd(m,t)),1LL*gcd(n,t)*gcd(m,t));
	printf("%d\n",(res%mo+mo)%mo);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
vector<int> G[222];
int n;
int dp[222][222];
int dp2[222][222];
int r[222];
int dp3[222][222][222];


int dfs2(int i,int j,int k){
  if(~dp3[i][j][k]) return dp3[i][j][k];
  if(i+j+k==0) return 1;
  int res=0;
  if(i>0&&j>0&&k>0) (res+=dfs2(i-1,j-1,k-1))%=MOD;
  if(i>0&&k>0) (res+=dfs2(i-1,j,k-1))%=MOD;
  if(j>0&&k>0) (res+=dfs2(i,j-1,k-1))%=MOD;
  return dp3[i][j][k]=res;
}

void calc(int v){
  memset(dp,0,sizeof(dp));
  dp[0][0]=1;
  for(int i=0;i<(int)G[v].size();i++){
    for(int j=0;j<=n;j++){
      for(int k=0;k<=n;k++){
	if(j+k>n) continue;
	for(int l=max(j,k);l<=j+k;l++){
	  (dp[i+1][l]+=(dp[i][j]*dp2[G[v][i]][k])%MOD*dfs2(j,k,l))%=MOD;
	}
      }
    }
  }
  /*//
  for(int i=0;i<=(int)G[v].size();i++)
    for(int j=0;j<=n;j++)
      cout<<v<<" "<<i<<" "<<j<<":"<<dp[i][j]<<endl;
  //*/
}

void dfs(int v){
  for(int u:G[v]) dfs(u);
  memset(dp2[v],0,sizeof(dp2[v]));
  calc(v);
  for(int i=0;i<=n;i++)
    dp2[v][i+1]=dp[G[v].size()][i];
}
signed main(){
  cin>>n;
  memset(r,0,sizeof(r));
  for(int i=0;i<n-1;i++){
    int a,b;
    cin>>a>>b;
    G[a].push_back(b);
    r[b]=1;
  }
  memset(dp3,-1,sizeof(dp3));
  int idx;
  for(int i=0;i<n;i++)
    if(!r[i]) dfs(i),idx=i;
  int ans=0;
  for(int i=0;i<=n;i++)
    (ans+=dp2[idx][i])%=MOD;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 89392
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD*MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int a,b;

int main(){
while(cin>>a>>b){
cout<<a+b<<endl;
}
}

Measured memory_bytes: 0
import sys

MAX_N  = 100

N = int(input())
#print(N)
xy = [map(int, input().split()) for _ in range(N)]
x, y = [list(i) for i in zip(*xy)]

for i in range(3-1,N):
    if x[i-2] == y[i-2]:
        if x[i-1] == y[i-1]:
            if x[i] == y[i]:
                print("Yes")
                sys.exit()  

print("No")           

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

using namespace std;

string s[10000010];
int cnt, n;

void dfs(int depth, int pm, string t) {
	if(depth == 1) {
		dfs(depth + 1, pm + 1, "a");
		return ;
	}
	if(depth == n + 1) {
	    cout << t << endl;
		return ; 
	}
	for(register char i = 'a'; i < 'a' + pm; i++) {
		dfs(depth + 1, pm, t + i);
	}
	dfs(depth + 1, pm + 1, t + (char)('a' + pm));
}

int main() {
	cin >> n;
	dfs(1, 0, "");
	return 0;
}


Measured memory_bytes: 79616