akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;


VV G;
V color;

bool dfs(int u, int cur=0) {
  color[u] = cur;
  for (auto v : G[u]) {
    if (color[v] != -1) {
      if (color[v] == cur) return false;
      continue;
    }
    if (!dfs(v, cur^1)) return false;
  }
  return true;
}

int main() {
  ll n, m; cin >> n >> m;
  
  G.assign(n, V());
  color.assign(n, -1);

  rep(i, m) {
    int a, b; cin >> a >> b;
    --a; --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  bool bi = true;
  if (!dfs(0)) bi = false;

  if (bi) {
    Vll cnt(2);
    rep(i, n) ++cnt[color[i]];
    cout << (cnt[0]*cnt[1]-m) << endl;
  }
  else cout << (n*(n-1)/2 - m) << endl;
  return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <set>
#include <map>

#define INF 100000000
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;
using P = pair<int, int>;

const int MAX = 1000000;
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;
        //そのまま計算すると負の値になるので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 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;
}


//UnionFind木
struct UnionFind{
   vector<long long int> par; //par[i] : iの親の番号
   vector<long long int> rnk; //root[i] : iの木のサイズ

   //コンストラクタ
   UnionFind(long long int n): par(n), rnk(n){
       //木の初期化
       for(long long int i = 0; i < n; i++){
           par[i] = i;
           rnk[i] = 1;
       }
   }

   //データxが属する木の根を再帰で取得
   long long int root(long long int x){
       if(par[x] == x){
           return x;
       }else{
           return par[x] = root(par[x]);
       }
   }

   //xとyが同じ木に属しているかを判定
   bool same(long long int x, long long int y){
       return root(x) == root(y);
   }

   //xとyの木を併合
   void unite(long long int x, long long int y){
       long long int rx = root(x); //xの根
       long long int ry = root(y); //yの根
       if(rx == ry) return; //根が同じならそのまま

       //併合するときにサイズを足し合わせる
       if(rnk[rx] < rnk[ry]){
           par[rx] = ry;
           rnk[ry] += rnk[rx];
       }else{
           par[ry] = rx;
           rnk[rx] += rnk[ry];
       }
   }

   //属している木のサイズを取得
   long long int size(long long int x){
       return rnk[root(x)];
   }
};

typedef struct edge{
   int to;
   int cost;
} edge;

vector<edge> graph[2010];
long long int d[2010];

void dijkstra(int s){
   priority_queue<P, vector<P>, greater<P> > que;
   for(int i = 0; i < 2010; i++){
       d[i] = INF;
   }
   d[s] = 0;
   que.push(P(s, 0));

   while (!que.empty()) {
       P p = que.top();
       que.pop();
       int v = p.first;
       if (d[v] < p.second) continue;

       for (int i=0; i<graph[v].size(); ++i) {
           edge e = graph[v][i];
           if (d[e.to] > d[v] + e.cost) {
               d[e.to] = d[v] + e.cost;
               que.push(P(e.to, d[e.to]));
           }
       }
   }
}
*/

int main(){
    int n; cin >> n;
    vector<int> p(n);
    rep(i,n) {
        cin >> p[i];
    }
 
    int cnt = 0;
    for(int i = 0; i < n; ++i) {
        if(p[i] == i+1) {
            swap(p[i], p[i+1]);
            ++cnt;
            ++i;
        }
    }
 
    cout << cnt << '\n';
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
const int NMAX=1<<17;
int n,k;
int x[110];
int main(){
  scan(n);scan(k);
  rep(i,n){
    scan(x[i]);
  }
  int res=0;
  rep(i,n){
    res+=2*min(x[i],abs(k-x[i]));
  }
  prin(res);
  
  
  return 0;
}


Measured memory_bytes: 256
/*ex7_3 hightierra*/
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int row,col,i,j;
    int *rowjudge;
    int *coljudge;
    char **matrix;
    scanf("%d %d",&row,&col);

    // 各行の配列へのメモリ領域の確保
    matrix = (char**)calloc(row, sizeof(char*));
    if(matrix == NULL){
        exit(1);
    }
    // 各行のメモリ領域の確保
    for(i = 0; i < row; i++){
        matrix[i] = (char*)calloc(col, sizeof(char));
        if(matrix[i] == NULL){
            exit(1);
        }
    }

    // 各メモリの確保
    rowjudge = (int*)calloc(row, sizeof(int));
    if(rowjudge == NULL){
        exit(1);
    }

    coljudge = (int*)calloc(col, sizeof(int));
    if(coljudge == NULL){
        exit(1);
    }

    // 入力
    for(i=0; i<row; i++){
        for(j=0; j<col; j++){
            scanf(" %c",&matrix[i][j]);
        }
    }

    // 各行、各列に黒が１つでもあるかを判別
    for(i=0; i<row; i++){
        for(j=0; j<col; j++){
            if(matrix[i][j]=='#'){
                rowjudge[i]=1;
            }
        }
    }
    for(j=0; j<col; j++){
        for(i=0; i<row; i++){
            if(matrix[i][j]=='#'){
                coljudge[j]=1;
            }
        }
    }

    // 黒が１つでもある行と列の重なる要素のみを出力
    for(i=0; i<row; i++){
        for(j=0; j<col; j++){
            if(rowjudge[i]==1 && coljudge[j]==1){
                printf("%c",matrix[i][j]);
            }
        }
        if(rowjudge[i]==1){
            printf("\n");
        }
    }

    // 各メモリの開放
    for(i=0; i<row; i++){
        free(matrix[i]);
    }
    free(matrix);

    free(rowjudge);
    free(coljudge);

    return 0;
}

Measured memory_bytes: 1652
/***
        ***Fresher***
    Md Mahfujur Rahman Khan
    Dept. of CSE
    CSE-28 Batch
    JU-48 Batch
    Jahangirnagar University

***/
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<set>
#include<map>
#include<climits>
#include<numeric>
#include<utility>
using namespace std;
#define V_ vector
#define Q_ queue
#define S_ set
#define ST_ stack
#define M_ map
#define DQ_ deque
/***PAIR***/
#define pii pair<ll,ll>
#define pci pair<char,ll>
#define psi pair<string, ll>
#define pis pair<ll,string>
#define pic pair<ll, char>
/***MAP***/
#define mii map<ll,ll>
#define msi map<string, ll>
#define mis map<ll, string>
#define mib map<ll,bool>
#define msb map<string,bool>
#define mci map<char, ll>
/***VECTOR***/
#define vi vector<ll>
#define vs vector<string>
/***ITERASTORS***/
#define ivi vector<ll> :: iterator
#define ivs vector<string> :: iterator
#define imii map<ll,ll> :: iterator
#define imsi map<string,ll> :: iterator
#define imis map<ll, string> :: iterator
#define imib map<ll, bool> :: iterator
#define imsb map<string, bool> :: iterator
#define imci map<char, ll> :: iterator
/*** FAST ***/
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
/***FUNCTIONS AND MACROS***/
#define F first
#define S second
#define M_P(x, y) make_pair(x, y)
#define PB(x) push_back(x)
#define PP(x) push(x)
#define RSZ(n) resize(n)
#define POB pop_back()
#define P_ pop()
#define CL_ clear()
#define LEN_ length()
#define SZ_ size()
#define CNT(x) count(x)
#define FF first.first
#define FS first.second
#define SF second.first
#define SS second.second
#define B_ begin()
#define E_ end()
#define F_ front()
#define t_ top()
#define IN_ insert
#define ER_  erase
#define GT(x) getline(cin , x)
#define NL_   "\n"
#define SP_ " "
#define R_0 return 0
#define R_ return

#define ul unsigned long long int
#define ll long long int
/***
//prime fact
#define most_prime_loop 1001
#define most_prime_number 2000010
#define prime_MAX_arr 2000010/2
ll PRIME[2000010];
void seive()
{
    PRIME[0] = 0;
    for(auto &x: PRIME )
        x = 1;
    for(ll i= 3; i <= most_prime_loop; i+=2)
    {
        for(ll j = i*i; j <= most_prime_number; j+=2*i)
            PRIME[j/2] = 0;
    }
}
***/

#define fr(i, n) for( ll i = 0; i < n; i++)
#define fe(x, n) for( ll i = x; i <= n; i++)
#define fa(x,a)    for(auto &x : a)

#define pi acos(-1)

#define SR(x) sqrt(x)
#define IC   (ll)

const ll  inf = 2000000;
ll i=0, T=0, N=0, tc =0, t= 0;
ll n=0, k=0;
string s;
bool palin(ll a, ll b)
{
    a--;
    b--;
    while(a<=b)
    {
        if(s[a++]!=s[b--]) return 0;
    }
    return 1;
}
int main()
{
   cin >> t;
   cout << (( t%2)?  (t/2+1): (t/2));
      R_0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <iostream>

using namespace std;

int main(){
    int h, w;
    scanf("%d %d", &h, &w);
    string a;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> a;
            if(a == "snuke")printf("%c%d",j+'A',i+1);
        }
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>

#define ll long long

using namespace std;

int main(){
    int A,B;
    cin >> A >> B;
    if(A>=13){
        cout << B << endl;
    }
    else if(A>=6){
        cout << B/2 << endl;
    }
    else{
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
/*******************************************************************
**
**  Nirushuu
**  
*******************************************************************/
#include <iostream>
#include <unordered_map>
#include <cmath>
#include <vector>
#include <sstream>
#include <algorithm>
#include <map>
#include <cctype>
#include <iomanip>
#include <queue>
#include <numeric>


#define debug(x) dbg(#x, x)
#define fst first
#define snd second

using namespace std;

// debug functions
// from https://en.cppreference.com/w/cpp/container/vector/vector
template<typename T>
std::ostream& operator<<(std::ostream& s, const std::vector<T>& v) 
{
    s.put('[');
    char comma[3] = {'\0', ' ', '\0'};
    for (const auto& e : v) {
        s << comma << e;
        comma[0] = ',';
    }
    return s << ']';
}


template <class T>
void dbg(string name, T val) {
    cout << "name: " << name << "\tvalue: " << val << "\n";
}
/***************************************************************/


/* variadic min
***********************************/
template<typename T>
T mmin(T a, T b) {
    return a < b ? a : b;
}

template<typename T, typename... Args>
T mmin(T a, Args... args) {
    T b = mmin(args...);
    return a < b ? a : b;
}
/**********************************/



int ctoi(char a) {
    return a - '0';
}

char itoc(int a) {
    return '0' + a;
}


vector<string> split(string s, char c) {
    istringstream iss(s);
    vector<string> res;
    string buf;
    while (getline(iss, buf, c)) {
        res.push_back(buf);
    }

return res;
}

double edist(pair<int, int> a, pair<int, int> b) {
    return sqrt(pow(a.fst - b.fst, 2) + pow(a.snd - b.snd, 2));
}


struct Vertex{
    char c;
    vector<int> nbrs;
};

void bfs(vector<Vertex>& cells, vector<bool>& visited, int idx) {
    vector<int> curVertices = vector<int>();
    curVertices.push_back(idx);
    while (curVertices.size() > 0) {
        vector<int> nCurVertices = vector<int>();
        for (auto cell : curVertices) {
            for (auto nbr : cells[cell].nbrs) {
                if (!visited[nbr] && cells[nbr].c == 'L') {
                    nCurVertices.push_back(nbr);
                    visited[nbr] = true;
                }
            }
        }
        curVertices = nCurVertices;
    }
}


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

    int k;
    cin >> k;

    int ans = 0;
    for (int i = 1; i <= k; ++i) {
        for (int j = 1; j <= k; ++j) {
            for (int l = 1; l <= k; ++l) {
                int res = gcd(i, j);
                res = gcd(res, l);
                ans += res;
            }
        }
    }

    cout << ans;
}




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

int main(){

    int N;
    cin >> N;
    vector<vector<int> > A(2, vector<int>(N));
    for(int i = 0; i < 2; i++) for(int j = 0; j < N; j++) cin >> A[i][j];

    int ans = 0;
    for(int i = 0; i < N; i++){
        int sum = 0;
        for(int j = 0; j <= i; j++){
            sum += A[0][j];
        }
        for(int j = i; j < N; j++){
            sum += A[1][j];
        }
        ans = max(ans, sum);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}

int cnt[10023];

int main(){
	int ed = sqrt(10000);
	rep(i,1,ed){
		int ed2 = sqrt(10000-i*i);
		rep(j,1,ed2){
			int ed3 = 10000-i*i-i*j-j*j;
			if( ed3<=0 ) break;
			ed3 = sqrt(ed3);
			rep(k,1,ed3){
				int now = i*i+j*j+k*k+i*j+j*k+k*i;
				if( now>10000 ) break;
				cnt[now]++;
			}
		}
	}
	int n = ci();
	rep(i,1,n) printf("%d\n",cnt[i]);
	return 0;
}


Measured memory_bytes: 2028
ct=0
def merge(A,left,mid,right):
    global ct
    n1=mid-left
    n2=right-mid
    l=[A[left+i] for i in xrange(n1)]
    r=[A[mid+i] for i in xrange(n2)]
    l.append(float('inf'))
    r.append(float('inf'))
    i=0
    j=0
    for k in xrange(left,right):
        ct+=1
        if l[i]<=r[j]:
            A[k]=l[i]
            i=i+1
        else:
            A[k]=r[j]
            j=j+1

def mergesort(A,left,right):
    if left+1<right:
        mid=(left+right)/2
        mergesort(A,left,mid)
        mergesort(A,mid,right)
        merge(A,left,mid,right)
        
n=input()
s=map(int,raw_input().split())
mergesort(s,0,n)
i=0
s=map(str,s)
print(" ".join(s))
print(ct)

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

int main() {
 int a ,b;
 cin >> a;
 cin >> b;
 int p =(a+b);
 int q =a-b;
 int r = a*b;
 if(p>= q && p>=r)
  cout << p;
 else if(p<=q && q>= r)
  cout << q;
  else if(r>=q && r>=p)
    cout << r;
}


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

int main() {
  string S;
  cin >> S;
  if (S.at(0)=='9' || S.at(1)=='9') {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3592
import math
N = int(input())
X = list(map(int,input().split()))

A = math.ceil(sum(X)/N)
B = math.floor(sum(X)/N)

a = 0
b = 0

for i in X:
  a += (i-A)**2
  
for _ in X:
  b += (_-B)**2
  
print(min(a,b))

  
  
  




Measured memory_bytes: 3060
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii;
import std.typecons, std.functional;
import std.algorithm, std.container;

void scanValues(TList...)(ref TList list)
{
    auto lit = readln.splitter;
    foreach (ref e; list)
    {
        e = lit.fornt.to!(typeof(e));
        lit.popFront;
    }
}

T[] scanArray(T = long)()
{
    return readln.split.to!(long[]);
}

void scanStructs(T)(ref T[] t, size_t n)
{
    t.length = n;
    foreach (ref e; t)
    {
        auto line = readln.split;
        foreach (i, ref v; e.tupleof)
        {
            v = line[i].to!(typeof(v));
        }
    }
}

T scanElem(T = long)()
{
    string res;
    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    while (!isWhite(c) && c != -1)
    {
        res ~= cast(char) c;
        c = getchar;
    }
    return res.strip.to!T;
}

template fold(fun...) if (fun.length >= 1)
{
    auto fold(R, S...)(R r, S seed)
    {
        static if (S.length < 2)
        {
            return reduce!fun(seed, r);
        }
        else
        {
            import std.typecons : tuple;

            return reduce!fun(tuple(seed), r);
        }
    }
}

struct Factor
{
    long n;
    long c;
}

Factor[] factors(long n)
{
    Factor[] res;
    for (long i = 2; i ^^ 2 <= n; i++)
    {
        if (n % i != 0)
            continue;

        int c;
        while (n % i == 0)
        {
            n = n / i;
            c++;
        }
        res ~= Factor(i, c);
    }
    if (n != 1)
        res ~= Factor(n, 1);

    return res;
}

bool isPrime(long n)
{
    if (n <= 1)
        return false;
    if (n == 2)
        return true;
    if (n % 2 == 0)
        return false;
    for (long i = 3; i ^^ 2 <= n; i += 2)
        if (n % i == 0)
            return false;
    return true;
}

void main()
{
    string N = scanElem!string;
    long[4][] dp = new long[4][N.length+1];
    dp[0][0] = 1;
    foreach(i, c; N)
    {
        dp[i+1][0] = c=='?' ? dp[i][0]*3 : dp[i][0];
        dp[i+1][1] = c=='?' ? dp[i][1]*3 : dp[i][1];
        dp[i+1][2] = c=='?' ? dp[i][2]*3 : dp[i][2];
        dp[i+1][3] = c=='?' ? dp[i][3]*3 : dp[i][3];
        if(c=='A' || c=='?')dp[i+1][1] += dp[i][0];
        if(c=='B' || c=='?')dp[i+1][2] += dp[i][1];
        if(c=='C' || c=='?')dp[i+1][3] += dp[i][2];
        dp[i+1][]%=10^^9+7;
    }
    writeln(dp[$-1][3]);
}


Measured memory_bytes: 3964
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
ll a[maxn];
int main()
{
    int n;
    while(scanf("%d",&n)==1)
    {
        for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
        ll sum=0;
        for(int i=n;i>=2;i-=2)
            sum+=2*(a[i]-a[i-1]);
        sum+=2*a[1];
        ll x1=sum/2;
        printf("%lld",x1);
        for(int i=1;i<n;i++)
        {
            ll xi=2*a[i]-x1;
            printf(" %d",xi);
            x1=xi;
        }
        printf("\n");
    }

}


Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n,m;
  bool b1[n+10];
  bool b2[n+10];
  cin >> n >> m;
  for(int i=0; i<m; i++){
    int a,b;
    cin >> a >> b;
    if(a>b) swap(a,b);
    if(a==1) b1[b]=true;
    if(b==n) b2[a]=true;
  }
  for(int i=1; i<=m; i++){
    if(b1[i]==true && b2[i]==true){
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}

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

namespace atcoder
{
	class Program
	{
		static void Main(string[] args)
		{
			Console.ReadLine();
			var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
			input.Sort();
			List<long> rec = new List<long>();
			for (int i = input.Count - 1; i > 0; i--)
			{
				if (input[i] == input[i - 1])
				{
					rec.Add(input[i]);
					i--;
				}
			}
			if (rec.Count < 2) Console.WriteLine(0);
			else Console.WriteLine(rec[0] * rec[1]);
		}
	}
}


Measured memory_bytes: 20320
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef uint64_t ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;

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

    int n; cin >> n;

    vi t(n);

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

    set<int> dp;
    dp.insert(1 << 0);

    REP(i, n) {
        int c1 = t[i], c2 = 24 - t[i];
        if (c2 == 24) c2 = 0;
        set<int> tmp;
        for(auto &e: dp) {
            if (!(e >> c1 & 1)) tmp.insert(e | 1 << c1);
            if (!(e >> c2 & 1)) tmp.insert(e | 1 << c2);
        }

        dp.swap(tmp);
    }

    int ans = 0;
    for(auto &e: dp) {
        int tmp = 24;
        REP(j, 24) REP(k, 24) {
            if (j == k || !(e >> j & 1) || !(e >> k & 1)) continue;
            tmp = min(tmp, min(abs(j - k), 24 - abs(j - k)));
        }

        ans = max(tmp, ans);
    }

    print(ans);
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <sstream>
#include <cctype>
using namespace std;

typedef string::const_iterator State;

int factor(State &begin);

int number(State &begin) {
	int ret = 0;

	while(isdigit(*begin)) {
		ret *= 10;
		ret += *begin - '0';
		begin++;
	}

	return ret;
}

int term(State &begin){
	int ret = factor(begin);

	for(;;){
		if(*begin == '*'){
			begin++;
			ret *= factor(begin);
		} else if (*begin == '/') {
			begin++;
			ret /= factor(begin);
		} else {
			break;
		}
	}

	return ret;
}

int expression (State &begin) {
	int ret = term(begin);

	for (;;) {
		if(*begin == '+') {
			begin++;
			ret += term(begin);
		} else if (*begin == '-') {
			begin++;
			ret -= term(begin);
		} else {
			break;
		}
	}

	return ret;
}

int factor (State &begin) {
	if(*begin == '(') {
		begin++;
		int ret = expression(begin);
		begin++;
		return ret;
	} else {
		return number(begin);
	}
}

int main(){
	int n;
	cin >> n;
	for(;n;n--){
		string s;
		cin >> s;
		State begin = s.begin();
		int ans = expression(begin);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
#include <set>
#include <string>
#include <bitset>
#include <fstream>
#include <stack>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

ll mod = 1000000007;
const ll INF = 100000000000010000;
//const ull B = 998244353;
//ll kai[3010];

//void pres(double A, ll x = 20) { printf("%.20f\n", x); }

vector<ll> dx = { 0, 1, 0, -1, 1, -1, 1, -1, 0};
vector<ll> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0};

void chmin(ll& x, ll y) {
	x = min(x, y);
}

void chmax(ll& x, ll y) {
	x = max(x, y);
}

ll pow_long(ll x, ll y) {
	ll res = 1;
	while (y > 0) {
		if (y % 2 == 1) res *= x;
		x *= x;
		y /= 2;
	}
	return res;
}

void test() {
	cout << "888888888888888888888888" << endl;
}

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}

ll pow_mod(ll x, ll k) {
	x %= mod;
	ll res = 1;
	while (k > 0) {
		if (k % 2) {
			res *= x; res %= mod;
		}
		x *= x; x %= mod;
		k /= 2;
	}
	return res;
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

//コンビネーション
const int MAXcomb = 1000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAXcomb; 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;
	}
}
ll comb(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * finv[k] % mod * finv[n - k] % mod;
}

vector <ll> par; // 各元の親を表す配列
vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

void init_u(ll sz_) {
	par.resize(sz_);
	siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
	for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
}

ll n;
string S;
ll num[200010];
ll ans;
map<ll, ll> mp;

void solve() {
	cin >> n >> mod >> S;

	if (mod == 2) {
		rep(i, n) {
			if ((S[i] - '0') % 2 == 0) ans += i + 1;
		}
		cout << ans << endl;
		return;
	}
	if (mod == 5) {
		rep(i, n) {
			if (S[i] - '0' == 0 || S[i] - '0' == 5) ans += i + 1;
		}
		cout << ans << endl;
		return;
	}

	num[n] = 0;
	revrep(i, n) {
		num[i] = num[i + 1] + (S[i] - '0') * pow_mod(10, n - 1 - i);
		num[i] %= mod;
	}
	//rep(i, n) cout << num[i] << endl;
	rep(i, n + 1) {
		if (pow_mod(div_mod(10), n - i) == 0) {
			ans += i;
			//cout << i << endl;
		}
		else {
			ans += mp[num[i]];
			//cout << mp[num[i]] << endl;
		}
		mp[num[i]]++;
	}
	cout << ans << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll T = 1;
	//cin >> T;
	rep(i, T) solve();
}


Measured memory_bytes: 2580
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7

a,b=MI()
c=b-a
ans=(c*(c+1))//2-b
print(ans)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type_a,class Type_b> void chmax(Type_a &a,const Type_b &b){if(a<b)a=b;}
template<class Type_a,class Type_b> void chmin(Type_a &a,const Type_b &b){if(a>b)a=b;}
template<class Type> Type igcd(Type x,Type y){if(x==0 or y==0)return (x>y)?x:y;return (y%x)?igcd(y%x,x):x;}
template<class Type> Type ilcm(Type x,Type y){return x/igcd(x,y)*y;}
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int h,w;
vector<string> s;

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

int bfs(int y,int x){
	if(s[y][x]=='#') return 0;
	
	int res=0;
	vvi cnt(h,vi(w,-1));
	cnt[y][x]=0;
	queue<pii > q;
	q.push(pii(y,x));
	while(!q.empty()){
		pii tmp=q.front();
		q.pop();
		
		REP(i,4){
			int ny=tmp.first+dy[i];
			int nx=tmp.second+dx[i];
			if(ny<0 or h<=ny or nx<0 or w<=nx) continue;
			if(s[ny][nx]=='#') continue;
			if(cnt[ny][nx]!=-1) continue;
			
			q.push(pii(ny,nx));
			cnt[ny][nx]=cnt[tmp.first][tmp.second]+1;
			chmax(res,cnt[ny][nx]);
		}
	}
	
	/*debug(y);
	debug(x);
	REP(i,h) line(cnt[i]);*/
	
	return res;
}

int main(){
	cin>>h>>w;
	s.resize(h);
	REP(i,h) cin>>s[i];
	
	int ans=0;
	REP(i,h)REP(j,w){
		 chmax(ans,bfs(i,j));
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 256
package main

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

func main() {
	N, M := ReadInt(), ReadInt()
	uf := MakeUnionFind(N)
	for m := 0; m < M; m++ {
		x, y, _ := ReadInt()-1, ReadInt()-1, ReadInt()
		uf.Unite(x, y)
	}

	m := make(map[int]bool)
	for i := 0; i < N; i++ {
		m[uf.Root(i)] = true
	}
	fmt.Println(len(m))
}

func MakeUnionFind(size int) UnionFind {
	parent := make([]int, size)
	for i := 0; i < size; i++ {
		parent[i] = i
	}
	return parent
}

type UnionFind []int

func (uf UnionFind) Unite(x, y int) {
	x = uf.Root(x)
	y = uf.Root(y)
	if x != y {
		uf[x] = y
	}
}

func (uf UnionFind) Connected(x, y int) bool {
	return uf.Root(x) == uf.Root(y)
}

func (uf UnionFind) Root(x int) int {
	if uf[x] == x {
		return x
	}
	uf[x] = uf.Root(uf[x])
	return uf[x]
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 8780
#include <stdio.h>
int C[1000000000];
int A[1000000000];
int count=0;
void merge(int a[],int left,int right);
int main(){
  int i,n;
 
  scanf("%d",&n);
  for(i=0; i < n ; i++){
    scanf("%d",&A[i]);
  }
  merge(A,0,n-1);
  for(i=0; i < n ; i++){
    if(i < n-1){
    printf("%d ",A[i]);
    }
    else{
      printf("%d",A[i]);
    }
  }
  printf("\n%d\n",count);
  return 0;
}

void merge(int A[],int left,int right){
  int mid,i,j,p;
  if(right <=left)return;
  mid=(left+right)/2;
  merge(A,left,mid);
  merge(A,mid+1,right);

  for(i=left; i <= mid;i++){
    C[i]=A[i];
  }
  j=right;
  for(i=mid+1;i <=right;i++){
    C[i]=A[j];
    j--;
  }
  j=right;
  i=left;
  for(p=left;p<=right;p++){
    if(C[i]<=C[j]){
      A[p]=C[i++];
      count++;
    }
    else{
      A[p]=C[j--];
      count++;
    }
  }
}



Measured memory_bytes: 5640
#include <iostream>
#include <cmath>
#include <tuple>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int H, W, A[509][509];
vector<tuple<int, int, int, int>> L;

int main() {
	cin >> H >> W;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) cin >> A[i][j];
	}
	for (int i = 1; i <= H; i++) {
		for (int j = W - 1; j >= 1; j--) {
			if (A[i][j + 1] % 2 == 0) continue;
			L.push_back(make_tuple(i, j + 1, i, j));
			A[i][j + 1]--;
			A[i][j]++;
		}
	}
	for (int i = H - 1; i >= 1; i--) {
		if (A[i + 1][1] % 2 == 0) continue;
		L.push_back(make_tuple(i + 1, 1, i, 1));
		A[i + 1][1]--;
		A[i][1]++;
	}

	cout << L.size() << endl;
	for (int i = 0; i < L.size(); i++) cout << get<0>(L[i]) << " " << get<1>(L[i]) << " " << get<2>(L[i]) << " " << get<3>(L[i]) << endl;
	return 0;
}

Measured memory_bytes: 5232
N,K=gets.split.map &:to_i
p=gets.split.map{|i|(i.to_f+1)*0.5}
r=s=p[0..K-1].inject(:+)
(N-K).times do |i|
  r+=p[i+K]-p[i]
  s=[s,r].max
end
puts s


Measured memory_bytes: 20612
h,w = map(int,input().split())
if h==1 or w==1:
    print(1)
    exit()
m = (h//2) * (w//2)
if h%2==0 and w%2==0:
    n = m
elif h%2==0 and w%2==1:
    n = (h//2) * (w//2+1)
elif h%2==1 and w%2==0:
    n = (h//2+1) * (w//2)
else:
    n = (h//2+1) * (w//2+1)
print(m+n)

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

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

	vector<ll> a(n + 1), b(n);
	for (int i = 0; i < n + 1; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	
	ll ans = 0;
	for (int i = 0; i < n + 1; i++) {
		
		if (i != 0) {
	
			if (b[i - 1] <= a[i]) {
				ans += b[i - 1];
				a[i] -= b[i - 1];
				b[i - 1] = 0;				
			}
			else { // a[i] < b[i]
				ans += a[i];
				b[i - 1] -= a[i];
				a[i] = 0;
			}

		}
		
		if (i != n) {

			if (b[i] <= a[i]) {
				ans += b[i];
				a[i] -= b[i];
				b[i] = 0;
			}
			else { // a[i] < b[i]
				ans += a[i];
				b[i] -= a[i];
				a[i] = 0;
			}

		}

	}

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

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++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;

    }
}

LL comb(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;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

LL dp[105][2][4];

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

    string s;
    cin >> s;
    int k;
    cin >> k;
    // 1 -> smaller 0 -> exact
    for( int i = 0; i < s.size(); ++i ) {
        int nu = s[i] - '0';
        if( i == 0 ) {
            dp[i][1][1] = nu - 1;
            dp[i][0][0] = 0;
            dp[i][0][1] = 1;
            dp[i][1][0] = 1;

        } else {
            // sm -> sm
            for( int j = 0; j <= k; ++j ) {
                if( j == 0 ) {
                    dp[i][1][0] += dp[i - 1][1][0];

                } else {
                    dp[i][1][j] += dp[i - 1][1][j - 1] * 9;
                    dp[i][1][j] += dp[i - 1][1][j];

                }
            }

            int tmp = nu;
            if( nu != 0 ) {
                --nu;
                // exact -> smaller
                for( int j = 1; j <= k; ++j ) {
                    if( nu == 0 ) dp[i][1][j] += dp[i - 1][0][j];
                    else {
                        dp[i][1][j] += dp[i - 1][0][j - 1] * nu;
                        dp[i][1][j] += dp[i - 1][0][j];
                    }
                }
            }

            // exact -> exact
            for( int j = 0; j <= k; ++j ) {
                if( tmp != 0 ) {
                    if( j != 0 ) dp[i][0][j] = dp[i - 1][0][j - 1];

                } else {
                    dp[i][0][j] = dp[i - 1][0][j];

                }

            }
        }
    }
    cout << dp[s.size() - 1][0][k] + dp[s.size() - 1][1][k] << endl;

    return 0;
}



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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;

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

  int a=0;
  int m=0;
  rep(i,n){
    int d1, d2;
    cin >> d1 >> d2;
    if(d1==d2){a++; m=max(m,a);}
    else a=0;
  }

  if(m>=3) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 3604
N = int(input())
tail = N % 10

if tail == 2 or tail == 4 or tail == 5 or tail == 7 or tail == 9 :
    print("hon")
elif tail == 0 or tail == 1 or tail == 6 or tail == 8 :
    print("pon")
else :
    print("bon")


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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> a(h);
  for(int i = 0; i < h; i++) {
    cin >> a.at(i); 
  }
  for (int i = 0; i < w + 2; i++) {
    cout << "#" ;
  }
  cout << endl;
  for(int i = 0; i < h; i++) {
    cout << "#" << a.at(i) << "#" << endl;
  }
  for(int i = 0; i < w + 2; i++){
    cout << "#";
  }
  cout << endl;
}
  

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define LL long long
using namespace std ;
void Read ( LL &x, char c = getchar(), bool f = 0 ) {
	for ( x = 0 ; !isdigit(c) ; c = getchar() ) if (c == '-') f = 1 ;
	for ( ; isdigit(c) ; c = getchar() ) x = 10*x + c - '0' ;
	if (f) x = -x ;
}
LL n, m ;
int main() {
	Read(n), Read(m) ;
	LL ans = 0 ;
	if (n > m) swap(n, m) ;
	if (n == 1) {
		if (m == 1) ans = 1 ;
		else ans = m-2 ;
	} else ans = (n-2)*(m-2) ;
	cout << ans << endl ;
	return 0 ;
}

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

int main(int argc, const char * argv[]) {
    
    while (true) {
        char op;
        int a,b;
        
        cin >> a >> op >> b;
        if(op == '?'){
            break;
        }
        
        switch (op) {
            case '+':
                cout << a+b << endl;
                break;
            case '-':
                cout << a-b << endl;
                break;
            case '*':
                cout << a*b << endl;
                break;
            case '/':
                cout << a/b << endl;
                break;
            default:
                break;
        }
        
    }
    
    
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;

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

    long long mod = 1000000007;

    long long r0 = 1, r1 = 1, r2 = 1;
    for (int i = 0; i < n; i++) {
        r0 = (10 * r0) % mod;
        r1 = (9 * r1) % mod;
        r2 = (8 * r2) % mod;
    }

    cout << (r0 - 2 * r1 + r2 + 2 * mod) % mod << endl;
}


Measured memory_bytes: 3568
N=int(input())
A=[]
B=[]
d=0
for i in range(N):
	a,b = map(int,input().split())
	A.append(a)
	B.append(b)
for i in range(N):
	c = (A[-(i+1)]+d)%B[-(i+1)]
	d += B[-(i+1)] - c if c>0 else 0
print(d)


Measured memory_bytes: 11052
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define rrep(i,n) for(int (i)=1;i<=(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};

int n;
vector<double> p(3300);
vector<double> dp(3300);

signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	
	cin >> n;
	rep(i, n) cin >> p[i];
	dp[0] = 1;
	rep(i, n) {
		for(int j = i+1; j > 0; j--) {
			dp[j] += (dp[j-1] - dp[j]) * p[i];
		}
	}
	cout << dp[(n+1)/2] << endl;
	return 0;
}

Measured memory_bytes: 3824
#include <iostream>
#include <climits>
#include <cmath>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL

multiset<int> a;
int n;

map<ll, int> fact(ll);
bool found(map<ll, int>, int);

int main()
{
  ll ans=0;
  int i;

  cin >> n;
  for (i=0; i<n; i++) {
    int inp;
    cin >> inp;
    a.insert(inp);
  }
  for (auto it=a.begin(); it!=a.end();) {
//printf("*it=%d\n", *it);
    if (a.count(*it) > 1) {
      it = a.upper_bound(*it);
      continue;
    }
    if (!found(fact(*it), *it)) ans++;
//printf("ans=%lld\n", ans);
    /*
    auto itn=a.begin();
    bool div=false;
    for (; (*itn) * 2 <= *it; itn++) {
//printf("%d%%%d=%d\n", *it, *itn, (*it)%(*itn));
      if ((*it) % (*itn) == 0) {
        div = true;
        break;
      }
    }
    if (!div) ans++;
      */
    it++;
  }

  cout << ans << endl;
  return 0;
}
bool found(map<ll, int>::iterator it, map<ll, int>::iterator iend, int k, int x) {
  if (k==x) return false;
  if (it==iend) {
    bool ret = (a.find(k) != a.end());
//printf("found(_, _, %d)=%d\n", k, ret);
    return ret;
  }
//printf("%lld^%d\n", it->first, it->second);
  for (int i=0; i<=it->second; i++) {
//printf("i=%d\n", i);
    bool b=found(next(it), iend, k, x);
    if (b) return true;
    k *= it->first;
  }
  return false;
}
bool found(map<ll, int> f, int x) {
  return found(f.begin(), f.end(), 1, x);
}

//素数判定
vector<int> pr={2,3,5,7};

bool isprime(int n) {
  int i;
  int prime(int);
  int sz=pr.size();
  int sq = sqrt(n);
  for (i=1; i<sz; i++) {
    int p=pr[i];
    if (p>sq) return true;
    if (n%p==0) return false;
  }
  for (;;i++) {
    int p=prime(i);
    if (p>sq) return true;
    if (n%p==0) return false;
  }
}

//素数生成
int prime(int n) {
  int last = pr.size();
  if (n<last) return pr[n];

  for (int p=pr.back()+2; last <= n; p+=2) {
    if (isprime(p)) {
      last++;
      pr.push_back(p);
    }
  }
  return pr.back();
}


//素因数分解
//引数の整数を素因数分解する。
//mapクラスのキーに基数、対応する値に指数が入っている
map<ll, int> lc;
map<ll, int> fact(ll n) {
  map<ll, int> ret;
  ll base;
  int ix;

  int i;
  for (i=0; n>1; i++) {
    base = prime(i);
    ix = 0;
    while (n%base == 0) {
      ix++;
      n /= base;
    }
    if (ix > 0) {
      ret[base] = ix;
      auto itr = lc.find(base);
      if (itr == lc.end()) {
        lc[base] = ix;
      } else {
        lc[base] = max(ix, lc[base]);
      }
    } else {
      if (base * base >= n) {
        ret[n] = 1;
        auto itr = lc.find(n);
        if (itr == lc.end()) {
          lc[n] = 1;
        } else {
          lc[n] = max(1, lc[n]);
        }
        break;
      }
    }
  }
  return ret;
}

/*
  Aiが昇順に並んでいるとする
  自分より大きい数では割り切れないので、
  */


Measured memory_bytes: 15852
#include<iostream>
#include <string>
#include<stdio.h>
#include <math.h>


using namespace std;


int main() {
	string S;
	string A = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	int N;

	cin >> N >> S;

	if (N == 26) N = 0;

	int n = S.size();
	char SS[10000], AA[26];
	for (int i = 0; i < n; i++) {
		SS[i] = S[i];
	}
	for (int i = 0; i < 26; i++) {
		AA[i] = A[i];
	}
	

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 26; j++) {
			if (S[i] == A[j]) {
				if (j + N <= 25) {
					SS[i] = A[j + N];
				}
				else {
					SS[i] = A[j + N - 25 - 1];
				}
			}
		}
	}
	for (int i = 0; i < n; i++) {
		S[i] = SS[i];
	}

	cout << S << endl;

	return 0;
}

	






Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cmath>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef long long ll;
const int maxn=200000+10;
const ll inf=1000000000000000;
ll t1[maxn*4],t2[maxn*4],sum[maxn],f[maxn];
int x[maxn],id[maxn],rk[maxn];
int i,j,k,l,t,n,m,a,b;
ll ans;
bool cmp(int a,int b){
	return x[a]<x[b];
}
void build(int p,int l,int r){
	t1[p]=t2[p]=inf;
	if (l==r) return;
	int mid=(l+r)/2;
	build(p*2,l,mid);build(p*2+1,mid+1,r);
}
void change(int p,int l,int r,int a,ll b){
	if (l==r){
		t1[p]=b;
		return;
	}
	int mid=(l+r)/2;
	if (a<=mid) change(p*2,l,mid,a,b);else change(p*2+1,mid+1,r,a,b);
	t1[p]=min(t1[p*2],t1[p*2+1]);
}
void change2(int p,int l,int r,int a,ll b){
	if (l==r){
		t2[p]=b;
		return;
	}
	int mid=(l+r)/2;
	if (a<=mid) change2(p*2,l,mid,a,b);else change2(p*2+1,mid+1,r,a,b);
	t2[p]=min(t2[p*2],t2[p*2+1]);
}
ll query(int p,int l,int r,int a,int b){
	if (l==a&&r==b) return t1[p];
	int mid=(l+r)/2;
	if (b<=mid) return query(p*2,l,mid,a,b);
	else if (a>mid) return query(p*2+1,mid+1,r,a,b);
	else return min(query(p*2,l,mid,a,mid),query(p*2+1,mid+1,r,mid+1,b));
}
ll query2(int p,int l,int r,int a,int b){
	if (l==a&&r==b) return t2[p];
	int mid=(l+r)/2;
	if (b<=mid) return query2(p*2,l,mid,a,b);
	else if (a>mid) return query2(p*2+1,mid+1,r,a,b);
	else return min(query2(p*2,l,mid,a,mid),query2(p*2+1,mid+1,r,mid+1,b));
}
void work(){
	build(1,1,m+1);
	change(1,1,m+1,rk[0],f[1]-sum[1]-(ll)x[0]);
	change2(1,1,m+1,rk[0],f[1]-sum[1]+(ll)x[0]);
	fo(i,2,m){
		f[i]=query(1,1,m+1,1,rk[i])+(ll)x[i]+sum[i-1];
		f[i]=min(f[i],query2(1,1,m+1,rk[i],m+1)-(ll)x[i]+sum[i-1]);
		change(1,1,m+1,rk[i-1],f[i]-sum[i]-(ll)x[i-1]);
		change2(1,1,m+1,rk[i-1],f[i]-sum[i]+(ll)x[i-1]);
	}
	fo(i,1,m) ans=min(ans,f[i]+sum[m]-sum[i]);
}
int main(){
	scanf("%d%d%d%d",&n,&m,&a,&b);
	fo(i,1,m){
		scanf("%d",&x[i]);
		if (i>1) sum[i]=abs(x[i]-x[i-1]);
	}
	fo(i,1,m) sum[i]+=sum[i-1];
	ans=inf;
	x[0]=a;
	f[1]=abs(x[1]-b);
	fo(i,0,m) id[i]=i;
	sort(id,id+m+1,cmp);
	fo(i,0,m) rk[id[i]]=i+1;
	work();
	x[0]=b;
	f[1]=abs(x[1]-a);
	fo(i,0,m) id[i]=i;
	sort(id,id+m+1,cmp);
	fo(i,0,m) rk[id[i]]=i+1;
	work();
	printf("%lld\n",ans);
}

Measured memory_bytes: 16512
from sys import stdin
import math
n,k = map(int,stdin.readline().split())
a = list(map(int,stdin.readline().split()))
d = math.floor(math.log2(k))
next = [[-1 for _ in range(n)] for _ in range(d+1)]
for i in range(n):
    next[0][i] = a[i] - 1
for j in range(d):
    for i in range(n):
        if next[j][i] == -1:
            continue
        next[j+1][i] = next[j][next[j][i]]
cur = 0
i = 0
while k > 0:
    if k&1:
        cur = next[i][cur]
    k >>= 1
    i += 1
print(cur+1)


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

using namespace std;

using ll = long long;

struct S {
  int w, s, v;
  inline void read () {
    cin >> w >> s >> v;
  }
  bool operator <(const S& b) const {
    return w + s < b.w + b.s;
  }
};

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n;
  cin >> n;
  vector < S > in(n);
  int MAX_S = 20002;
  for (int i = 0; i < n; ++i)
    in[i].read();
  sort (in.begin(), in.end());
  vector < ll > dp (MAX_S + 1);
  for (S block : in)
    for (int w = min (block.s, MAX_S - block.w); w >= 0; --w)
      dp[w + block.w] = max (dp[w + block.w], dp[w] + block.v);
  ll answer = 0;
  for (int i = 0; i <= MAX_S; ++i)
    answer = max (answer, dp[i]);
  cout << answer;
}


Measured memory_bytes: 3608