akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define INF 999999999
#define MOD 1000000007
 
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
 
int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};
 
int r;
 
int main(){
	cin >> r;
	if(r < 1200){
		cout << "ABC" << endl;
	}else if(r < 2800){
		cout << "ARC" << endl;
	}else{
		cout << "AGC" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#define all(x) (x).begin(),(x).end()

void solve(){

}
string s,t;
//k番目からk+t.sizeまでをtと比較
bool check(int k){
    bool ok = true;
    for (int i = 0; i < (int)t.size(); i++){
        if (s[k+i] == '?'){
            continue;
        } else if (s[k+i] != t[i]){
            ok = false;
        }
    }
    return ok;
}


int main(){
    cin >> s >> t;
    bool found = false;
    int index = 0;
    for(int i = 0; i <= (int)s.size()-(int)t.size(); ++i){
        if(check(i)){
            found = true;
            index = i;
        }
    }
    string ans;
    if (found){
        for (int i = 0; i < (int)t.size(); ++i){
            s[index+i] = t[i];
        }
        for (int i = 0; i < (int)s.size(); ++i){
            if (s[i] == '?'){
                s[i] = 'a';
            }
        }
        cout << s << endl;
    } else {
        cout << "UNRESTORABLE" << endl;
    }
    return 0;
}


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

int main()
{
    int N, D, X;

    cin >> N >> D >> X;

    for ( int i = 0; i < N; i++ ) {
        int A;
        cin >> A;
        X += (D + A - 1) / A;
    }
    cout << X << endl;
    return ( 0 );
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>

using namespace std;

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

#define PI 3.1415926535897932384626433832795


struct cc_t
{
	vi cc;
	cc_t() {cc.resize(26);}
};


void bt_inc(vector<cc_t>&bt, int idx, int c)
{
	if(idx<=0) return;
	bt[idx].cc[c]++;
	bt_inc(bt, idx/2, c);
}


void bt_incdec(vector<cc_t>&bt, int idx, int ci, int cd)
{
	if(idx<=0) return;
	bt[idx].cc[ci]++;
	bt[idx].cc[cd]--;
	bt_incdec(bt, idx/2, ci, cd);
}


void bt_chg(vector<cc_t>&bt, char *s, int base, int idx, int c)
{
	if(s[idx]==c) return;
	bt_incdec(bt, base+idx, c-'a', s[idx]-'a');
	s[idx]=c;
}


void bt_cnt_i(vi&ret, vector<cc_t>&bt, int idx)
{
	if(idx<=1) return;
	if(idx&1)
	{
//printf("0x%x ", idx-1);
		for(int i=0;i<26;i++)
		{
			ret[i]+=bt[idx-1].cc[i];
		}
	}
	bt_cnt_i(ret, bt, idx/2);
}


vi bt_cnt(vector<cc_t>&bt, int idx)
{
//printf("bt_cnt(%d[0x%x])", idx, idx);
	vi ret=bt[idx].cc;
	bt_cnt_i(ret, bt, idx);
	return ret;
}


int main(void)
{
	int n, q;
	char s[500000+2];
	while(scanf("%d\n%500000[a-z]%d", &n, s, &q)==3)
	{
		int l=strlen(s);
		int d=0, base=0;

		for(d=1;(1<<d)<l;d++)
			;

		vector<cc_t> bt(2<<d);
		base=1<<d;
//printf("l=%d  base=%d  bt.size()=%u\n", l, base, bt.size());
		for(int i=0;i<l;i++)
		{
			bt_inc(bt, base+i, s[i]-'a');
		}

		for(int i=0;i<q;i++)
		{
			int t;
			scanf("%d", &t);
			if(t==1)
			{
				int x;
				char c;
				scanf("%d %c", &x, &c);
				bt_chg(bt, s, base, x-1, c);
			}
			else
			{
				int l, r;
				scanf("%d%d", &l, &r);
				auto rc=bt_cnt(bt, base+r-1);
				vi lc(26);
				if(l>1) lc=bt_cnt(bt, base+l-2);

				int ans=0;
				for(int i=0;i<26;i++)
				{
					if(rc[i]-lc[i]) ans++;
				}
				printf("%d\n", ans);
			}
		}
	}
	return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

vector<ll> X{2 
, 3 
, 4 
, 5 
, 6 
, 7 
, 8 
, 9 
, 10 
, 11 
, 12 
, 13, 1};

int main(void) {
    ll A, B;
    cin >> A >> B;
    auto a = distance(X.begin(), find(X.begin(), X.end(), A));
    auto b = distance(X.begin(), find(X.begin(), X.end(), B));
    if(a == b) cout << "Draw";
    else if(a < b) cout << "Bob";
    else cout << "Alice";
    cout << endl;
    return 0;
}


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

int main() {
    int n; cin >> n;
    vector<int> a(n - 1);
    for (int i = 0; i < (n - 1); i++) cin >> a.at(i);
    for (int i = 0; i < (n - 1); i++) {
        a.at(i)--;
    }

    vector<int> ans(n, 0);
    for (int i = 0; i < n - 1; i++) {
        ans.at(a.at(i))++;
    }

    for (int i = 0; i < n; i++) {
        cout << ans.at(i) << endl;
    }
}

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

int main(){
	string s,t;
	cin >> s >> t;
	int slen = s.length();
	int tlen = t.length();

	int dp[slen+1][tlen+1];
	for(int i = 0;i<=slen;i++){
		for(int j = 0;j<=tlen;j++){
			dp[i][j] = 0;
		}
	}
	for(int i = 0 ;i<=slen ; i++ ){
		for(int j = 0;j<=tlen;j++){
			if(i==0||j==0)
				dp[i][j] = 0;
			else{
				if(s[i-1]==t[j-1]){
					dp[i][j] = dp[i-1][j-1] + 1;
				}

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

	stack<char> ans;
	int i = slen; int j = tlen;
	while (i > 0 && j > 0) 
   { 
      // If current character in X[] and Y are same, then 
      // current character is part of LCS 
      if (s[i-1] == t[j-1]) 
      { 
          ans.push(s[i-1]); // Put current character in result 
          i--; j--;     // reduce values of i, j and index 
      } 
  
      // If not same, then find the larger of two and 
      // go in the direction of larger value 
      else if (dp[i-1][j] > dp[i][j-1]) 
         i--; 
      else
         j--; 
   } 

	while(!ans.empty()){
		cout << ans.top();
		ans.pop();
	}
	cout << endl;
}

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

int main() {
  int n, i, e, w = 0, ans;
  ;
  string s;
  cin >> n >> s;
  for (i = 0; i < n; i++) {
    if (s[i] == 'W') {
      w++;
    }
  }
  e = n - w;

  vector<int> dp(n + 1, 0);
  if (s[0] == 'E') {
    dp[0] = e - 1;
  } else {
    dp[0] = e;
  }
  for (i = 0; i < n; i++) {
    if (s[i] == 'E' && s[i + 1] == 'E') {
      dp[i + 1] = dp[i] - 1;
    } else if (s[i] == 'W' && s[i + 1] == 'W') {
      dp[i + 1] = dp[i] + 1;
    } else {
      dp[i + 1] = dp[i];
    }
  }
  ans = n + 1;
  for (i = 0; i <= n; i++) {
    ans = min(ans, dp[i]);
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 1796
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();
		int A[] = new int[M];
		for (int i=0;i<M;i++) {
			A[i] = sc.nextInt();
		}
		int countmin=0;
		int countmax=0;
		for (int i=0;i<M;i++) {
			if (A[i]<X) {
				countmin++;
			} else {
				countmax++;
			}
		}
		if (countmin<countmax) {
			System.out.println(countmin);
		} else {
			System.out.println(countmax);
		}
	}
}

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

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())
#define endl "\n"

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
void initialize( void );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
template <typename T, typename K> struct P {
	T a; K b;
};
vector <P <ll, ll> >prime_factorize( ll N ){
	vector <P <ll, ll> > vec;
	int lim = sqrt( N ) + 1;
	rep( i, 2, N + 1 ){
		if (i >= lim){
			vec.push_back( P <ll, ll>{N, 1} );
			break;
		}
		if (N % i == 0){
			vec.push_back( P <ll, ll>{i, 0} );
			while(N % i == 0){
				N /= i;
				vec.back().b++;
			}
		}
	}
	return vec;
}
int arr[ 1005 ] = {};
int main( void ){
	// initialize();
	int N;
	cin >> N;
	rep( i, 2, N + 1 ){
		const auto &vec = prime_factorize( i );
		for(auto v:vec){
			arr[ v.a ] += v.b;
			arr[ v.a ] %= k_mod;
		}
	}
	ll ans = 1;
	rep( i, 0, N + 1 ){
		ans *= arr[i]+1;
		ans %=k_mod;
	}
	cout << ans << endl;
}

template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}
void initialize( void ){
	cout << fixed << setprecision( 10 );
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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; }

long long n;
vector<long long> nyaku;
vector<long long> myaku;

int main() {
    cin >> n;
    long long m = n-1;
    for(long long i = 2; i*i <= n; ++i) {
        if(n % i == 0) {
            if(n/i != i) {
                nyaku.push_back(i);
                nyaku.push_back(n/i);
            }else {
                nyaku.push_back(i);
            }
        }
    }
    for(long long i = 2; i*i <= m; ++i) {
        if(m % i == 0) {
            if(m/i != i) {
                myaku.push_back(i);
                myaku.push_back(m/i);
            }else {
                myaku.push_back(i);
            }
        }
    }
    nyaku.push_back(n);
    if(m != 1) myaku.push_back(m);

    long long ans = myaku.size();

    for(int i = 0; i < nyaku.size(); ++i) {
        long long check = nyaku.at(i);
        // cout << check << endl;
        long long obj = n;
        while(1) {
            if(obj % check != 0) break;
            obj /= check;
        }
        if(obj % check == 1) ans++;
    }

    cout << ans << endl;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

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

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

    int a, b, h; std::cin >> a >> b >> h;
    std::cout << a * h + ((b-a)*h/2) << "\n";
}


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

int main() {
  string S;
  cin >> S;
  
  int cnt=0;
  if(S[0]=='o'){
    cnt++;
  }
  if(S[1]=='o'){
    cnt++;
  }
  if(S[2]=='o'){
    cnt++;
  }
  cout << 700 + cnt*100 << endl;
}


Measured memory_bytes: 256
def main() -> None:
    S = input()
    print(sum(bit(S)))


def bit(S) -> list:
    list = []
    list.append(int(S))
    for i in range(len(S)-1):
        left = S[:i+1]
        right = S[i+1:]
        x = int(left)
        for y in bit(right):
            list.append(x + y)
    return list


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <random>
using namespace std;
#define Would
#define you

int main() {
	int n, k, mon = 0;
	cin >> n;
	vector<int>v(10);
	for (int i = 0; i < n; ++i) {
		cin >> k;
		if (k < 3200) ++v[k / 400];
		else ++v[8];
	}
	for (int i = 0; i <= 7; ++i) {
		if (v[i])++mon;
	}
	cout << max(mon, 1) << " " << mon + v[8] << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<cctype>
#include<string.h>
#include <stdlib.h>
#include <ctype.h>

#define PI 3.1415926

void swap(int* x, int* y) {
	int a = *x;
	int b = *y;
	*x = b;
	*y = a;
}
int factorial(int n);

int main() {
	int H, W, f[200][200] = { -1 };
	int flag = 0;
	char s[200][200];
	scanf("%d %d", &H, &W);

	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W+1; j++) {
			scanf("%c", &s[i][j]);
		}
	}

	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W+1; j++) {
			for (int k = j; k >= 1; k--) {
				if (s[i][k] == 'c') {
					f[i][j] = j-k;
					flag = 1;
					break;
				}
				if (flag == 0) {
					f[i][j] = -1;
				}
				flag = 0;
			}
		}
	}

	for (int i = 1; i <= H; i++) {
			for (int j = 2; j <= W+1; j++) {
				printf("%d", f[i][j]);
				if (j != W + 1) {
					printf(" ");
				}
			}
			printf("\n");
		}
		return 0;
	
}

 int factorial(int n) {
	if (n > 0) {
		return n * factorial(n - 1);
	}
	else {
		return 1;
	}
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

map< ll, int > prime_factor(ll n) {
  map< ll, int > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main() {
  int N; cin >> N;
  map<ll, int> m;
  for(int i = 1; i <= N; ++i) {
    auto a = prime_factor(i);
    for(auto x : a) {
      m[x.first] += x.second;
    }
  }
  ll ans = 1;
  for(auto x : m) {
    ans = ans * (x.second + 1) % 1000000007;
  }
  cout << ans << endl;
}

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

int gcd(int a, int b){
    if(a < b) swap(a, b);
    if(b == 0) return a;
    return gcd(b, a % b);
}

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];
    int l = n / gcd(n, m);
    int ans = 0;
    rep(i, 0, l){
        int MIN = 1e7, MAX = -1;
        rep(j, 0, m){
            int id = (i * m + j) % n;
            MIN = min(MIN, a[id]);
            MAX = max(MAX, a[id]);
        }
        // cout << MAX - MIN << endl;
        ans += (MAX - MIN);
    }
    cout << ans << endl;
}

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

using namespace std;

int n,t,i,a[100005];

int main(){
	scanf("%d%d", &n, &t);
	for(i = 0; i < n; i++)
	scanf("%d", &a[i]);
	
	int res = 0;
	int minx = a[0];
	int now = 0;
	
	for(i = 1; i < n; i++){
		if(a[i] - minx > now){
			now = a[i] - minx;
			res = 1;
		}
		else if(a[i] - minx == now)
		res++;
		
		minx = min(minx, a[i]);
	}
	
	printf("%d\n", res);
}


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

vector<int> xPar, yPar;
vector<int> xSz, ySz;

int find(vector<int>& v, int x) {
  return v[x] == x ? x : (v[x] = find(v, v[x]));
}
void merge(vector<int>& v, vector<int>& sz, int x, int y) {
  x = find(v, x);
  y = find(v, y);
  if(x == y) return;
  sz[y] += sz[x];
  v[x] = y;
}
void init(vector<int>& par, vector<int>& sz, int n) {
  par.resize(n+1);
  sz.resize(n+1);
  for(int i = 1; i <= n; i++) {
    par[i] = i;
    sz[i] = 1;
  }
}

void solve() {
  /*
  N points
  count number of points such that all rectangles are filled out

  fix a point (x, y)
  if any other point lies on a horizontal or vertical line from it
  count them all

  union find on orientation?
  */
  int n;
  cin >> n;
  init(xPar, xSz, 100000);
  init(yPar, ySz, 100000);
  vector<pii> v;
  v.resize(n);
  map<int, vector<int>> xtoy;
  map<int, vector<int>> ytox;
  for(int i = 0; i < n; i++) {
    cin >> v[i].first >> v[i].second;
    xtoy[v[i].first].push_back(v[i].second);
    ytox[v[i].second].push_back(v[i].first);
  }
  for(auto out: xtoy) {
    for(int i = 1; i < out.second.size(); i++) merge(yPar, ySz, out.second[i-1], out.second[i]);
  }
  for(auto out: ytox) {
    for(int i = 1; i < out.second.size(); i++) merge(xPar, xSz, out.second[i-1], out.second[i]);
  }
  map<pii, int> seen;
  ll ret = 0;
  for(int i = 0; i < n; i++) {
    seen[{find(xPar, v[i].first), find(yPar, v[i].second)}]++;
  }
  for(auto out: seen) {
    ll amt = xSz[out.first.first] * (ll)ySz[out.first.second];
    amt -= out.second;
    ret += amt;
  }
  cout << ret << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  ll t;
  cin >> t;
  for(ll i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


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

int N;
int ans = 0;

void dfs ( int len, string S, int bit )
{
	if ( len > 9 || (S != "" && stoi(S) > N) ) return;
	if ( bit == 7 ) ans++;
	dfs( len + 1, S + '3', bit | 1 );
	dfs( len + 1, S + '5', bit | 2 );
	dfs( len + 1, S + '7', bit | 4 );
}

int main()
{
	cin >> N;

	dfs(0, "", 0);

	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define LL long long
#define N 2050

LL n,k;


int main(){
	cin>>n>>k;
	LL down=0;
	if(k==0){
		cout<<n*n<<endl;
		return 0;
	}
	for(int i=k+1;i<=n;++i){
		LL ri=n/i*i,times=n/i;
		int add=(i-k)*times;
		if(n-ri<k);
		else add+=(n-ri)-k+1;
		down+=add;
	}

	printf("%lld\n",down);
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;

int main()
{
    string s;
    cin >> s;
    ll n = s.size();
    ll ans = 0;
    for(ll i = n-1; i >= 0; i--){
        if(s[i] == 'B'){
            ans += (n - (i+1));
            n--;
        }
    }
    cout << ans;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<stack>
#include<cstring>
#include<string>
#include<sstream>
using namespace std;

int main()
{
	string s;
	while (getline(cin, s)) {
		if (cin.eof())break;//if(s=="")break;
		stack<double> st;
		stringstream ss(s);
		string tmp;
		while (ss >> tmp) {
			if (tmp == "+" || tmp == "-" || tmp == "*" || tmp == "/") {//???????¨?????????\????????£??????
				if (st.empty())break;//?????????????????????????????£????????????
				double z1 = st.top();
				st.pop();//stack?????????????????????
				double z2 = st.top();
				st.pop();//stack?????????????????????
				double z3 = 0.0;
				if (tmp == "+")z3 = z2 + z1;
				else if (tmp == "-")z3 = z2 - z1;
				else if (tmp == "*")z3 = z2 * z1;
				else if (tmp == "/")z3 = z2 / z1;
				st.push(z3);
			}
			else {//??°????????\????????£??????
				st.push(atof(tmp.c_str()));//double?????????????????????????????\??????
			}
		}
		printf("%.6f\n", st.top());
	}
    return 0;
}

Measured memory_bytes: 3148
import math

A, B, degree = map(int, input().split())

rad = math.radians(degree)

S = A * B * math.sin(rad) / 2
C = math.sqrt(A*A + B*B - 2*A*B*math.cos(rad))
L = A + B + C
H = 2 * S / A

print(f"{S:.4f} {L:.4f} {H:.4f}")


Measured memory_bytes: 5728
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>

using namespace std;

template <class T>
using gp_queue=priority_queue<T, deque<T>, less<T>>;

using Weight=long long;
static const Weight INF=1LL<<57;

struct Edge {
    size_t src, dst;
    Weight weight;
    Edge() {}
    Edge(size_t src, size_t dst, Weight weight=1):
        src(src), dst(dst), weight(weight)
    {}
};

bool operator<(const Edge &e, const Edge &f) {
    if (e.weight != f.weight) {
        return e.weight > f.weight;
    } else {
        return e.src!=f.src? e.src<f.src : e.dst<f.dst;
    }
}

using Edges=vector<Edge>;
using Vertex=vector<Edge>;
using Graph=vector<Vertex>;

void join(Graph &g, size_t s, size_t d, Weight w=1) {
    // non-directed
    g[s].push_back(Edge(s, d, w));
    g[d].push_back(Edge(d, s, w));
}

void connect(Graph &g, size_t s, size_t d, Weight w=1) {
    // directed
    g[s].push_back(Edge(s, d, w));
}

vector<vector<Weight>> shortest_distance(Graph g) {
    /* Johnson */
    size_t V=g.size();
    vector<Weight> h(V);
    for (size_t k=0; k<V; ++k)
        for (size_t i=0; i<V; ++i)
            for (const Edge &e: g[i])
                if (h[e.dst] > h[e.src] + e.weight) {
                    h[e.dst] = h[e.src] + e.weight;
                    if (k == V-1)
                        return vector<vector<Weight>>();
                }

    for (size_t i=0; i<V; ++i)
        for (Edge &e: g[i])
            e.weight += h[e.src] - h[e.dst];

    vector<vector<Weight>> d(V, vector<Weight>(V, INF));
    vector<vector<size_t>> prev(V, vector<size_t>(V, -1));
    for (size_t s=0; s<V; ++s) {
        gp_queue<Edge> q; q.push(Edge(s, s, 0));
        d[s][s] = 0;
        while (!q.empty()) {
            Edge e=q.top(); q.pop();
            if (~prev[s][e.dst]) continue;

            prev[s][e.dst] = e.src;
            for (const Edge &f: g[e.dst]) {
                if (d[s][f.dst] > e.weight + f.weight) {
                    d[s][f.dst] = e.weight + f.weight;
                    q.push(Edge(f.src, f.dst, e.weight+f.weight));
                }
            }
        }
        for (size_t u=0; u<V; ++u)
            if (d[s][u] < INF)
                d[s][u] += h[u] - h[s];
    }

    return d;
}

int main() {
    size_t V, E;
    scanf("%zu %zu", &V, &E);

    Graph g(V);
    for (size_t i=0; i<E; ++i) {
        size_t s, t;
        Weight d;
        scanf("%zu %zu %lld", &s, &t, &d);

        connect(g, s, t, d);
    }

    vector<vector<Weight>> d=shortest_distance(g);
    if (d.empty())
        return !printf("NEGATIVE CYCLE\n");

    for (vector<Weight> w: d)
        for (size_t i=0; i<V; ++i)
            if (w[i] < INF) {
                printf("%lld%c", w[i], i<V-1? ' ':'\n');
            } else {
                printf("INF%c", i<V-1? ' ':'\n');
            }

    return 0;
}

Measured memory_bytes: 3180
#include<iostream>
#include<cstring>

using namespace std;
int len, k, s = 1;
char str[100005];
struct Node {
    int l, r;
} node[100005];

int find1(int p, int l, int r) {//(,]
    if (r <= l)return -1;
    if (r == l + 1)return r;
    int mid = (l + r) >> 1;
    if (node[mid].r < p)return find1(p, mid, r);
    else if (node[mid].l <= p && node[mid].r >= p)return mid;
    else return find1(p, l, mid);
}

int find2(int p, int l, int r) {//[,)
    if (r <= l)return -1;
    if (r == l + 1)return l;
    int mid = (l + r) >> 1;
    if (node[mid].r < p)return find2(p, mid, r);
    else if (node[mid].l <= p && node[mid].r >= p)return mid;
    else return find2(p, l, mid);
}

bool check(int p) {
    for (int i = 1; i + p - 1 <= len; i++) {
        int l = find1(i, 0, s - 1), r = find2(i + p - 1, 1, s);
        if (l == -1 || r == -1)return true;
        if (r - l + 1 <= k)return true;
    }
    return false;
}

int main() {
    cin >> len >> k >> (str + 1);
    for (int i = 1; i <= len; i++) {
        int j = i;
        if (str[i] == '0') {
            while (j <= len && str[j] == '0')j++;
            node[s].l = i, node[s].r = i = j - 1, s++;
        }
    }
    if (k == 0) {
        int ans = 0;
        for (int i = 1; i <= len; i++) {
            if (str[i] == '1') {
                int j = i, p = 0;
                while (j <= len && str[j] == '1')++j, ++p;
                ans = max(ans, p), i = j - 1;
            }
        }
        cout << ans;
        return 0;
    }
    int l = 0, r = len + 1;//[,)
    while (l < r) {
        if (r == l + 1)break;
        int mid = (l + r) >> 1;
        if (check(mid))l = mid;
        else r = mid;
    }
    cout << l;
    return 0;
}

Measured memory_bytes: 768
s = int(input())
nums = [s]
a = s
cou = 1

while True:
    if a % 2 == 0:
        a = a // 2
    else:
        a = 3*a + 1
    cou += 1
    if a in nums:
        break
    else:
        nums.append(a)

print(cou)

Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int N = S.length();
		int count = 0;
		for(int i = 0; i < N; i++) {
			if(S.substring(i, i + 1).equals("o")) {
				count++;
			}
		}
		if((15 - N + count) >= 8) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 21972
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int A = sc.nextInt();
	int B = sc.nextInt();
	int min = (A+B<=N)? 0: (A+B)-N;
	System.out.println((int)(Math.min(A,B)) + " " + min);
    }
}

Measured memory_bytes: 21460
# At DP K
def solve(K, A):
    dp = [ False ] * (K + 1)
    # dp[i] - true if current player wins if there are i stones remaining
    for stones in range(K + 1):
        for w in A:
            if stones >= w: # there must be more stones than we are removing
                if not dp[stones - w]: # does the opponent win after we remove `w` stones?
                    dp[stones] = True # then this player does win
    return "First" if dp[K] else "Second"

assert solve(7, [2, 3]) == "First"
assert solve(5, [2, 3]) == "Second"
assert solve(4, [2, 3]) == "First"
assert solve(20, [1, 2, 3]) == "Second"
assert solve(21, [1, 2, 3]) == "First"
assert solve(100000, [1]) == "Second"

n, k = map(int, input().split())
A = list(map(int, input().split()))

ans = solve(k, A)
print(ans)



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

int main()
{
	string str;
	getline(cin, str);
	for (int i = 0; i < str.size(); i++) {
		if (65 <= str[i] && str[i] <= 90) {//??§??????
			cout << (char)(str[i] + 32);
		}
		else if (97 <= str[i] && str[i] <= 122) {//?°???????
			cout << (char)(str[i] - 32);
		}
		else {
			cout << str[i];
		}
	}
	cout << endl;
    return 0;
}

Measured memory_bytes: 1172
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    s=input()
    n=len(s)
    K=int(input())
    dp_0=[[0]*(K+1) for _ in range(n+1)]
    dp_1=[[0]*(K+1) for _ in range(n+1)]
    dp_0[0][0]=1 
    for i in range(n):
        for j in range(K+1):
            for k in range(2):
                nd=int(s[i])-0
                for d in range(10): 
                    ni=i+1
                    nj=j
                    if d!=0:nj+=1
                    if nj>K:continue
                    if k==0:
                        if d>nd:continue
                        if d<nd:dp_1[ni][nj]+=dp_0[i][j]
                        else:dp_0[ni][nj]+=dp_0[i][j]
                    else:dp_1[ni][nj]+=dp_1[i][j]
    print(dp_0[n][K]+dp_1[n][K])

if __name__=='__main__':
    main()

Measured memory_bytes: 40432
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.out


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	int m,n;
    
    while(1){
        cin>>n>>m;
        if(n==0||m==0)break;
        vvll dp(n+1,vll (256,INF));
        dp[0][128]=0;

        vi c(m),x(n);
        rep(i,m)cin>>c[i];
        rep(i,n)cin>>x[i];

        for(int i=1;i<=n;i++){
            int nowx=x[i-1];
            for(int from=0;from<256;from++){
                for(int j=0;j<m;j++){
                    int p=from+c[j];
                    p=max(p,0);
                    p=min(p,255);
                    int cost=(nowx-p)*(nowx-p);
                    dp[i][p]=min(dp[i][p],dp[i-1][from]+cost);
                }
            }
        }
        sort(dp[n].begin(),dp[n].end());
        cout<<dp[n][0]<<endl;
    }

/////////////////////////////////////////////////////
return 0;}



Measured memory_bytes: 43880
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
    int n;

    cin >> n;

    int p[n];

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

    int count = 0;
    for (int i = 1; i < n - 1; i++)
    {
        if (((p[i - 1] <= p[i]) && (p[i] <= p[i + 1])) || ((p[i + 1] <= p[i]) && (p[i] <= p[i - 1])))
        {
            count++;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        int[] h = new int[N];
        for(int i=0;i<N;i++){
            h[i] = sc.nextInt();
        }
        int[] minCost = new int[N];
        minCost[0] = 0;
        minCost[1] = h[1] - h[0];
        minCost[1] *= minCost[1] > 0 ? 1 : -1;
        for(int i=2;i<N;i++){
            int cost2 = minCost[i-2] + ((h[i] > h[i-2]) ? (h[i] - h[i-2]) : (h[i-2] - h[i]));
            int cost1 = minCost[i-1] + ((h[i] > h[i-1]) ? (h[i] - h[i-1]) : (h[i-1] - h[i]));
            minCost[i] = Math.min(cost1, cost2);
        }
        System.out.println(minCost[N-1]);
    }
}


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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X,i) ((X>>i)&1)
#define REP(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define ina(x,n) rep(x_i,n) cin>>x[x_i]
#define outa(x,n) rep(x_i,n) cerr<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;

const int mod = 1e9+7;
const int inf = (1<<28);
const ll infl = (1LL<<60);

int digit(int x) {
  int d = 0;
  if (x == 0) return 1;
  while (x > 0) {
    d++;
    x /= 10;
  }
  return d;
}

int nth_digit(int x, int n) {
  int d = digit(x) - n;
  if (d < 0) return -1;
  int res = (x / (int)pow(10, d)) % 10;
  return res;
}

int main() {
  int n, m; cin >> n >> m;
  vl s(m), c(m);
  rep(i,m) {
    cin >> s[i] >> c[i];
  }

  for (int x = 0; x < 1000; x++) {
    if (digit(x) != n) continue;

    bool flag = true;
    for (int i = 0; i < m; i++) {
      if (nth_digit(x, s[i]) != c[i]) flag = false;
    }
    if (flag) {
      cout << x << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


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

const int MAX_N = 300;
int N;

vector<vector<vector<double>>> memo(MAX_N+1, vector<vector<double>>(MAX_N+1, vector<double>(MAX_N+1, -1)));


double dp(int i, int j, int k) {
    if (memo[i][j][k] == -1) {
        memo[i][j][k] = 1;
        if (i > 0) memo[i][j][k] += ((double)i / N) * dp(i-1, j+1, k);
        if (j > 0) memo[i][j][k] += ((double)j / N) * dp(i, j-1, k+1);
        if (k > 0) memo[i][j][k] += ((double)k / N) * dp(i, j, k-1);
        memo[i][j][k] = (memo[i][j][k] * N) / (i + j + k);
    }
    return memo[i][j][k];
}

int main() {
    cin >> N;
    memo[0][0][0] = 0.0;
    int i = 0, j = 0, k = 0;
    for (int _ = 0; _ < N; _++) {
        int a; cin >> a;
        if (a == 3) {
            i++;
        } else if (a == 2) {
            j++;
        } else if (a == 1) {
            k++;
        }
    }
    cout << setprecision(16) << dp(i, j, k) << endl;
}


Measured memory_bytes: 217088
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <map>

using namespace std;

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> v[n+1];
  vector<pair<int,int> > vp(m);
  int i,j;
  for(i=0;i<m;i++){
    int p,y;
    cin >> p >> y;
    vp[i]=make_pair(p,y);
    v[p].push_back(y);
  }
  for(i=1;i<=n;i++){
    sort(v[i].begin(),v[i].end());
  }
  map<pair<int,int>,int > mp;
  for(i=1;i<=n;i++){
    for(j=0;j<(int)v[i].size();j++){
      mp[make_pair(i,v[i][j])]=j+1;
    }
  }
  for(i=0;i<m;i++){
    printf("%06d%06d\n",vp[i].first,mp[vp[i]]);
  }
  /*for(i=0;i<m;i++){
    for(j=0;j<(int)v[vp[i].first].size();j++){
      if(v[vp[i].first][j]==vp[i].second){
        printf("%06d%06d\n",vp[i].first,j+1);
      }
    }
  }*/
  return 0;
}


Measured memory_bytes: 13952
#include<iostream>

using namespace std;

int main(){
    int N,*a,j=1,count=0;
    cin >> N;
    a = new int[N];
    for(int i=0;i<N;i++) cin >> a[i];
    for(int i=0;i<N;i++){
        if(a[i] != j) count++;
        else j++;
    }
    if(count == N) cout << -1;
    else cout << count;
}

Measured memory_bytes: 1024
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	} 
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	x := scanInt()-1
	y := scanInt()-1

	g := make([][]int, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, n)
		c := 0
		for j := i; j < n; j++ {
			g[i][j] = c
			c++
		}

		if i <= x {
			c := 0
			for j := i; j < n; j++ {
				g[i][j] = c
				if j == x {
					j = y-1
				}
				c++
			}
		}

		for j := 1; j < n; j++ {
			g[i][n-1-j] = min(g[i][n-1-j], g[i][n-1-j+1]+1)
		}
	}

	for i := 0; i < n; i++ {
		for j := 1; j < n; j++ {
			g[j][i] = min(g[j][i], g[j-1][i]+1)
		}
	}

	cnt := map[int]int{}
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			cnt[g[i][j]]++
		}
	}

	for i := 1; i < n; i++ {
		fmt.Fprintln(wr, cnt[i])
	}
}


Measured memory_bytes: 34176
#include <stdio.h>

int main()
{
  int h,m,s;
  while (scanf("%d %d %d",&h,&m,&s)){
    if ((h==-1) && (m==-1) && (s==-1))
      break;
    int remind=120*60;
    int cnt=h*3600+m*60+s;
    int minus=remind-cnt;
    int h1=minus/3600;
    int m1=(minus%3600)/60;
    int s1=(minus%3600)%60;
    int minus1=(remind-cnt)*3;
    int h2=minus1/3600;
    int m2=(minus1%3600)/60;
    int s2=(minus1%3600)%60;
    printf("%02d:%02d:%02d\n",h1,m1,s1);
    printf("%02d:%02d:%02d\n",h2,m2,s2);
  }

  return 0;
}

Measured memory_bytes: 608
#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;

template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class T> using ordered_multiset = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;

typedef long long  ll;
typedef unsigned long long  ull;
#define lp(i,n)      for(int i=0;i<n;i++)
#define lpi(i,j,n)   for(int i=j;i<n;i++)
#define lpd(i,j,n)   for(int i=j;i>=n;i--)
#define MP           make_pair
#define clr(v, d)    (memset(v, d, sizeof(v)))
#define all(v)     (v.begin()),(v.end())
#define N 100005
const double pi = acos(-1);

ll n,t,m,k;

ll ans;
ll mod = 1e9 +7;

double dp[3005][3005],a[3000];

int main() {
 
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// freopen("e.txt","r",stdin); 
// freopen("e_out.txt","w",stdout); 
cout.precision(12);

cin>>n;
lp(i,n)cin>>a[i];
dp[0][0]=(1.0 -a[0]),dp[0][1] =a[0];

for(int i=1;i<n;i++){
  dp[i][0]=dp[i-1][0]*(1.0-a[i]);
  for(int j=1;j<=i+1;j++)
    dp[i][j] = dp[i-1][j]*(1.0-a[i]) + dp[i-1][j-1]*a[i];
}
double res=0;
for(int i=n/2 +1;i<=n;i++)res+=dp[n-1][i];

cout<<fixed<<res;






  
}
  
 



// bool isPrime(ll h){
//      for(ll i=0;primes[i]*primes[i]<= h;i++)
//      if (h%primes[i]==0)
//      	return 0;
//      return h!=1;
//  }
 bool isPrime(ll g){
   if((g%2==0 && g>2) || g==1)return 0;
   for(ll i=3;i*i<=g;i+=2)if(g%i==0)return 0;
   return 1;   
 
 }

Measured memory_bytes: 49884
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;typedef vector<ll> vll;
#define fill(a) memset(a, 0, sizeof (a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define _ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back
#define inf (1<<29)

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int maxn = 2000100;

int main(){
        _ios;

        ll n; cin >> n;
        ll res = 0;
        res+=(n-1)/11 * 2 + 1;
        if((n-1)%11>5)res++;
        cout<<res<<endl;


return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main() {
	long long int H, W;
	scanf("%lld%lld", &H, &W);
	if (H==1||W==1) {
		printf("1");
	}
	else if ((H * W) % 2 == 0) {
		printf("%lld", (H * W) / 2);
	}
	else {
		printf("%lld", ((H * W) / 2) + 1);
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int longestPathHelper(map<int,vector<int>> &input,int i,vector<int> &dp)
{
    if(dp[i]!=-1)
    {
        return dp[i];
    }
    int res = 0;
    for(int a=0;a<input[i].size();a++)
    {
        res =max(res,longestPathHelper(input,input[i][a],dp)+1);
    }
    return dp[i]=res;
}
int main() {
	
	int n,m;
	cin>>n>>m;
	map<int,vector<int>> input;
	
	for(int i=0;i<m;i++)
	{
	    int x,y;
	    cin>>x>>y;
        x--;y--;
	    input[x].push_back(y);
	}
 	
	vector<int> dp(n,-1);
	int res=0;
	for(int i=0;i<n;i++)
	{
	    res = max(res,longestPathHelper(input,i,dp));
	}
	cout<<res<<endl;
   return 0;
}


Measured memory_bytes: 16384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int H, W, WHITE = 0;
char S[51][51];
vector<vector<int>> dp(51, vector<int>(51, -1));
int dist = INT_MAX;

void rec(int y = 0, int x = 0, int cnt = 0){
    
    if(y == H - 1 && x == W - 1){
        dist = min(dist, cnt);
        return;
    }
    if(y < 0 || H <= y || x < 0 || W <= x) return;
    if(S[y][x] == '#') return;
    
    if(~dp[y][x] && dp[y][x] <= cnt) return;
    dp[y][x] = cnt;
    
    rec(y + 1, x, cnt + 1);
    rec(y - 1, x, cnt + 1);
    rec(y, x + 1, cnt + 1);
    rec(y, x - 1, cnt + 1);
    
    return;
}

int main(void){
    
    scanf("%d %d", &H, &W);
    for(int i = 0; i < H; ++i){
        scanf("%s", S[i]);
        for(int j = 0; j < W; ++j){
            if(S[i][j] == '.') ++WHITE;
        }
    }
    
    rec();
    if(dist == INT_MAX) printf("-1\n");
    else printf("%d\n", WHITE - (dist + 1));
    
    return 0;
}


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

int main(){
  int N, s, m;
  cin >> N;
  s = N % 2;
  m = N / 2;
  
  vector<int> A(N), B(N);
  for (int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  
  B.at(m) = A.at(0);
  if (s == 1){
    for (int i = 1; i < N; i++){
      if (i % 2 == s){
        B.at(m+i/2+1) = A.at(i);
      }
      else{
        B.at(m-i/2) = A.at(i);
      }
    }
  }
  else{
    for (int i = 1; i < N; i++){
      if (i % 2 == s){
        B.at(m+i/2) = A.at(i);
      }
      else{
        B.at(m-i/2-1) = A.at(i);
      }
    }
  }
    
  for (int i = 0; i < N-1; i++){
    cout << B.at(i) << " ";
  }
  cout << B.at(N-1) << endl;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
#define mx 100005
#define ll long long
#define mod 1000000007

int ar[mx];
char ch[mx];

int n,m;

void solve()
{
   int a,b,c;
   cin>>a>>b>>c>>n;
   int re=0;
   if(n>=a)re+=a,n-=a;
   else re=n,n=0;
   if(n>=b)n-=b;
   else n=0;
   if(n)re-=n;
   cout<<re<<endl;

}

int main()
{
    int t=1;
    //scanf("%d",&t);
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long

using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


signed main() {
	// your code goes here
	char c;
	cin>>c;
	cout<<(char)(c+1)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1},
//           dx[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  const int M = 5;
  int n; cin >> n;
  map<char, int> mp;
  string march = "MARCH";
  REP(i, M) mp[march[i]] = i;
  vector<long long> name(M, 0);
  while (n--) {
    string s; cin >> s;
    if (mp.count(s[0]) == 1) ++name[mp[s[0]]];
  }
  long long ans = 0;
  REP(i, M) FOR(j, i + 1, M) FOR(k, j + 1, M) {
    ans += name[i] * name[j] * name[k];
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,n) for(int i=1;i<=n;i++)
#define fo1(i,n) for(int i=0;i<n;i++)
#define llu long long int
#define vi vector <int>
#define pb push_back
#define mod 1000000007

using namespace std;
int dp[100005][4];
int a[100005][4];
int n;
int loop(int day,int i)
{
	if(day==n)
		return 0;
	if(dp[day][i]!=-1)
		return dp[day][i];
	int maxi=0;
	if(i==0)
	{
		maxi=max(maxi,a[day][1]+loop(day+1,1));
		maxi=max(maxi,a[day][2]+loop(day+1,2));
		maxi=max(maxi,a[day][3]+loop(day+1,3));
	}
	else if(i==1)
	{
		maxi=max(maxi,a[day][2]+loop(day+1,2));
		maxi=max(maxi,a[day][3]+loop(day+1,3));
	}
	else if(i==2)
	{
		maxi=max(maxi,a[day][1]+loop(day+1,1));
		maxi=max(maxi,a[day][3]+loop(day+1,3));
	}
	else
	{
		maxi=max(maxi,a[day][1]+loop(day+1,1));
		maxi=max(maxi,a[day][2]+loop(day+1,2));
	}
	return dp[day][i]=maxi;
}
int main()
{
	//ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    memset(dp,-1,sizeof(dp));
    cin>>n;
    for(int i=0;i<n;i++)
    {
    	for(int j=1;j<=3;j++)
    		cin>>a[i][j];
	}
    int l=loop(0,0);
    cout<<l<<"\n";
}


Measured memory_bytes: 9600