akhauriyash/Code-Regression huggingface dataset:
#1200
def primes(x):
    is_prime = [True] * (x + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(x**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, x + 1, i):
            is_prime[j] = False
    return [i for i in range(x + 1) if is_prime[i]]

while True:
    c = 0
    d = 0
    n = int(input())
    if n == 0:
        break
    z = primes(n)
    for i in z:
        for j in z:
            if (i+j) == n:
                c += 1
                if i != j:
                    d += 1
    print(c-int(d/2))


Measured memory_bytes: 6308
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] s = new String[n];
        for (int i = 0 ; i < n ; i++) {
            s[i] = sc.next();
        }
        int count = 0;
        int a = 0;
        int b = 0;
        int ba = 0;
        for (int i = 0 ; i < n ; i++) {
            for (int j = 0 ; j < s[i].length() - 1 ; j++) {
                if (s[i].substring(j, j + 2).equals("AB")) count++;
            }
            char first = s[i].charAt(0);
            char last = s[i].charAt(s[i].length() - 1);
            if (first != 'B' && last == 'A') a++;
            if (first == 'B' && last != 'A') b++;
            if (first == 'B' && last == 'A') ba++;
        }

        if (ba == 0) {
            count += Math.min(a, b);
        } else {
            if (a + b > 0) {
                count += ba + Math.min(a, b);
            } else {
                count += ba - 1;
            }
        }

        System.out.println(count);
    }

}

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

using namespace std;

const long long INF = 1e18;
typedef long long llint;

llint n, m;
vector<llint> a, s;

llint getCount(llint tot) {
  llint ret = 0;
  for (int i = 0; i < n; i++) {
    llint ay = tot - a[i];
    llint idx = lower_bound(a.begin(), a.end(), ay) - a.begin();
    ret += n - idx;
  }
  return ret;
}

llint getSum(llint tot) {
  llint ret = 0;
  for (int i = 0; i < n; i++) {
    llint ay = tot - a[i];
    llint idx = lower_bound(a.begin(), a.end(), ay) - a.begin();
    llint cnt = n - idx;
    ret += (s[n] - s[idx]) + a[i] * cnt;
  }
  return ret;
}

int main() {
  cin >> n >> m;
  a.assign(n, 0);
  s.assign(n + 1, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    s[i + 1] = a[i] + s[i];
  }

  llint ok = 0, ng = INF;
  while (ok + 1 < ng) {
    llint mid = (ok + ng) / 2;
    if (m <= getCount(mid))
      ok = mid;
    else
      ng = mid;
  }

  llint ans = (m - getCount(ok + 1)) * ok + getSum(ok + 1);
  cout << ans << endl;

  return 0;
}

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

using namespace std;

int main () {
	int n; cin >> n;
	
	long long res = 0, a = 0, b = 0;
	
	
	
	
	vector <int> v(n);
	
	for (int i = 0; i < n; i++) {
		scanf("%d", &v[i]);
	}
	
	sort(v.rbegin(), v.rend());
	
	for (int i = 0; i < n - 1; i++) {
		if (v[i] == v[i + 1]) {
			
			b = max(b, (long long)v[i]);
			if (a < b) swap(a, b);
			res = a * b;
			i++;
		}
	}
	
	cout << res << endl;
	
	
	return 0;
}

Measured memory_bytes: 640
/*|In The Name Of Allah|*/
//This Month Will Be Expert ISA
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

const int mod = 1e9+7;

long long gcd(long long a, long long b){
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

long long lcm(long long a, long long b){
        return a/gcd(a, b)*b;
}

int n;
long long m;
long long ar[N];

int main(){
    scanf("%d%lld" , &n , &m);
    bool bad = 0;
    long long LCM = 1;
    for(int i = 1; i <= n; i++){
        scanf("%lld" , &ar[i]);
        LCM = lcm(LCM , ar[i] / 2);
        if(i == 1)
            continue;
        long long df = abs(ar[1] - ar[i]) / 2;
        long long gc = gcd(ar[1] , ar[i]);
        if( df % gc != 0 )
           bad = 1;
        if(LCM > 1e11)
            break;
    }
    if(LCM > m || bad){
        puts("0");
        return 0;
    }
    printf("%lld\n" , 1 + (m - LCM) / (2 * LCM));
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>

void choose_win(int x)
{
	switch( (x % 2) ){
		case 0:printf("First");	break;
		case 1:printf("Second");break;
		default : break;
	}
}

void pickup(char *str, int pick)
{
	str[pick] = '\0';
	
	strcpy(&str[pick], &str[pick+1]);
}

int main(void)
{
	FILE *fp;
	char str[100000];
	int winner = 1;
	int i;
	
	scanf("%s", str);
	
	while( strlen(str) != 2 ){
		int no_pick = 0;
		
		for(i=1; i<strlen(str)-1; i++){
			if(str[i-1] != str[i+1]){
				pickup(str, i);
				winner++;
				break;
			}
			if(i == strlen(str)-2)
				no_pick = 1;
		}
		
		if(no_pick)
			break;
	}
	
	choose_win(winner);
	
	
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
ll n,k,ans;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n>>k;
	while(n){
		n/=k;
		ans++;
	}
	cout<<ans;
	return 0;
}


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

int main() {
  int n, d;
  cin >> n >> d;
  vector<vector<int>> x(n, vector<int>(d));
  for (int i = 0;i < n;i++) {
    for (int j = 0;j < d;j++) {
      cin >> x[i][j];
    }
  }
  int ans = 0;
  for (int i = 0;i < n-1;i++) {
    for (int j = i+1;j < n;j++){
      int dis = 0;
      for (int k = 0;k < d;k++) {
        dis += (x[i][k]-x[j][k]) * (x[i][k]-x[j][k]);
      }
      for (int k = 1;k < 130;k++) {
        if (k * k == dis) ans++;
        if (k * k > dis) break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>

using namespace std;

int main()
{
    int n,dp[100010];
    for (int i=0; i<100010; i++) dp[i]=99999999;
    cin>>n;
    vector<int> v;
    v.push_back(1);
    for (int i=6; i<=46656; i*=6) v.push_back(i);
    for (int i=9; i<=59049; i*=9) v.push_back(i);
    sort(v.begin(), v.end());
    dp[0]=0;
    for (int i=1; i<=100000; i++)
    {
        for (int j=0; j<v.size(); j++)
        {
            if (i-v[j]>=0) dp[i]=min(dp[i], dp[i-v[j]]+1);
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}


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

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

  vector<int> cnt(123);
  for (int i = 0; i < N.size(); i++)
  {
    cnt.at(N.at(i))++;
  }

  for (int i = 97; i < 123; i++)
  {
    if (cnt.at(i) == 0)
    {
      char ans = i;
      cout << ans << endl;
      return 0;
    }
  }
  cout << "None" << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;

// 無限大の値
const long long INF = 1LL << 60;
// DP テーブル
long long dp[100010];

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    // DP テーブル全体を初期化
    for (int i = 0; i < 100010; ++i) dp[i] = INF;

    int N;
    cin >> N;
    vector<int> h(N);
    for (int i = 0; i < N; ++i) {
        cin >> h[i];
    }
    dp[0] = 0; dp[1] = abs(h[1]-h[0]);
    for (int i = 2; i < N; ++i) {
        chmin(dp[i], dp[i-1]+abs(h[i]-h[i-1]));
        chmin(dp[i], dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout << dp[N-1] << endl;
    return 0;
}


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

using namespace std;

int main(){
    int n;
    cin>>n;
    int a[50];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    double ans=a[0];
    for(int i=1;i<n;i++){
        ans+=a[i];
        ans/=2;
    }
    cout<<ans;
}


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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int A, B; cin >> A >> B;
  if ((A+B)%2==1) { cout << "IMPOSSIBLE" << endl; return 0; }
  int result = (A+B)/2;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int H, W, D;
int A[310][310];
int Q;
pii pos[90010];
int cost[90010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> H >> W >> D;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> A[i][j];
      pos[A[i][j]] = pii(i, j);
    }
  }
  for (int i = D + 1; i <= H * W; i++) {
    cost[i] = abs(pos[i].first - pos[i - D].first) + abs(pos[i].second - pos[i - D].second);
  }
  for (int i = D + 1; i <= H * W; i++) {
    cost[i] += cost[i - D];
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int L, R;
    cin >> L >> R;
    cout << cost[R] - cost[L] << endl;
  }

  return 0;
}

Measured memory_bytes: 2560
import numpy as np
n = int(input())
f = np.zeros((n, 10))
p = np.zeros((n, 11))
for i in range(n):
    f[i] = np.array(list(map(int, input().split())))

for i in range(n):
    p[i] = np.array(list(map(int, input().split())))

l = 10
f_n = 2**l-1
ans = (-10**7)*10*n
for i in range(2**l-1):
    ff = np.array(list(map(int,list(format(f_n,'b').zfill(l)))))
    c = np.sum(ff*f, dtype=np.int64, axis=1)
    c = np.eye(11)[c]
    tmp = np.sum(c*p)
    if ans < tmp:
        ans = tmp
    f_n -= 1
    
print (int(ans))


Measured memory_bytes: 21104
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s=sc.next();
    long k =sc.nextLong()-1;
    int st=0;
    while(s.length()>st && s.charAt(st)=='1') st++;
    System.out.println(k<st?'1':s.charAt(st));
  }
}


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

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

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

int N, A, B, C;
int l[10] = {0};

//uを4進数で見たときの右からn桁目の値 (nは0から)
int getDigit4(int u, int n){
	int v = u;
	int ret = v % 4;
	for(int i = 0; i < n; i++){
		v = v / 4;
		ret = v % 4;
	}
	return ret;
}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N >> A >> B >> C;
	for(int i = 0; i < N; i++){
		int u;
		cin >> u ;
		l[i] = u;
	}

	vector<int> v;
	int ans = 1000000000;
	for(int e = 0; e < 65536; e++){ // 4**8 = 65536
		v.clear();
		vector<int> a, b, c, d;
		int s = 0, t = 0, u = 0;
		for(int i = 0; i < N; i++){
			int k = getDigit4(e, i);
			if(k == 0){ //Aを構成する竹にする
				a.push_back(l[i]);
				s += l[i];
			}
			else if(k == 1){ //Bを構成する竹にする
				b.push_back(l[i]);
				t += l[i];
			}
			else if(k == 2){ //Cを構成する竹にする
				c.push_back(l[i]);
				u += l[i];
			}
			else if(k == 3){ //それ以外
				d.push_back(l[i]);
				v.push_back(l[i]);
			}
		}
		if(s == 0 || t == 0 || u == 0){ continue; }
		v.push_back(s);
		v.push_back(t);
		v.push_back(u);
		int mp2 = max((int)a.size() - 1, 0) * 10 ; //合成魔法のmpは10
		mp2 += max((int)b.size() - 1, 0) * 10;
		mp2 += max((int)c.size() - 1, 0) * 10;
		mp2 = mp2 + abs(s - A) + abs(t - B) + abs(u - C);
		if(mp2 < ans){ ans = mp2; }
	}
	cout << ans << endl ;
	return 0;
}

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

int n;
int main() {
    while (cin >> n, n != 0) {
        set<int> mod;
        for (int i = 1; i < n; i++) 
            mod.insert( (i*i) % n );

        int count[(n-1)/2+1];
        memset(count, 0, sizeof(count));
        for (set<int>::iterator si = mod.begin();
                si != mod.end(); si++) {
            for (set<int>::iterator sj = mod.begin();
                    sj != mod.end(); sj++) {
                if (*si == *sj) continue;
                int dif = *si - *sj;
                if (dif < 0) dif += n;
                if (dif > (n-1)/2) dif = n - dif;
                count[dif]++;
            }
        }

        for (int i = 1; i <= (n-1)/2; i++) 
            cout << count[i] << endl;
    }   
    return 0;
}

Measured memory_bytes: 1456
#include <bits/stdc++.h>
using namespace std;
int dp[1003][1003];
bool a[1003][1003];
int n, m, mod = 1e9+7;
int calc(int x, int y)
{
    if(x == n && y == m)
        return 1;
    
    if(x == 0 || y == 0 || x == n+1 || y == m+1 || !a[x][y])
        return 0;
    
    if(dp[x][y] != -1)
        return dp[x][y];

    return dp[x][y] = (calc(x+1, y) + calc(x, y+1))%mod;

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

    for (int i = 0; i < 1001; ++i) {
        memset(dp[i], -1, sizeof(dp[i]));
    }

    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            char ch; cin >> ch;
            a[i][j] = ch=='.';
        }
    }

    cout << calc(1, 1) << endl;
    return 0;
}

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

const int MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}

void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

int main() {
  string a, b;
  cin >> a >> b;

  if (a.length() > b.length()) {
    p("GREATER");
  } else if (a.length() < b.length()) {
    p("LESS");
  } else {
    if (a > b) {
      p("GREATER");
    } else if (a < b) {
      p("LESS");
    } else {
      p("EQUAL");
    }
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void) {
  double x1, y1, x2, y2, xp, yp, d, x2p, y2p;
  scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
  x2 -= x1, y2 -= y1;
  d = sqrt(x2 * x2 + y2 * y2);
  x2p = x2 / d, y2p = y2 / d;
  int q, i;
  scanf("%d", &q);
  for(i = 0; i < q; ++i) {
    scanf("%lf%lf", &xp, &yp);
    xp -= x1, yp -= y1;
    double ip = xp * x2 + yp * y2;
    printf("%.12f %.12f\n", ip / d * x2p + x1, ip / d * y2p + y1);
  }
  return 0;
}


Measured memory_bytes: 2756
import sys
n = input()
d = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for i in range(n):
  b, f, r, v = map(int, raw_input().split())
  d[b-1][f-1][r-1] += v
for i in range(4):
  for j in range(3):
    for k in range(10):
      sys.stdout.write(' %d' % d[i][j][k])
    if k==9:
      sys.stdout.write('\n')
  if j==2 and i<=2:
    sys.stdout.write('####################\n')

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

long double dist(pair<int,int>a,pair<int,int>b){
  return sqrt((a.first-b.first)*(a.first-b.first)+(a.second-b.second)*(a.second-b.second));
}

long double fact(int n){
  long double ans=1.0;
  for(int i=1;i<=n;i++){
    ans*=i;
  }
  return ans;
}

int main(){
  int n;
  cin>>n;
  vector<pair<int,int>>a(n);
  for(int i=0;i<n;i++){
    cin>>a[i].first>>a[i].second;
  }
  vector<int>ans;
  for(int i=0;i<n;i++){
    ans.push_back(i);
  }
  long double tot=0;
  do{
    long double now=0;
    for(int i=1;i<n;i++){
      now+=dist(a[ans[i-1]],a[ans[i]]);
    }
    tot+=(now/fact(n));
  }while(next_permutation(ans.begin(),ans.end()));
  cout<<setprecision(10)<<fixed<<tot;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, a, b = 0;
    ll z = 0;
    cin >> n;
    while (n--) cin >> a, b = max(b, a), z += b - a;
    cout << z;
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int q;
    cin>>s>>q;
    bool to_reverse = false;
    vector<char>v[2];
    while (q--){
        int type,pos;
        char to_add;
        cin>>type;
        if (type==1)to_reverse = !to_reverse;
        else{
            cin>>pos>>to_add;
            --pos;
            v[pos^to_reverse].push_back(to_add);
        }
    }
    string t;
    for (int i = (int)v[0].size()-1;~i;--i)
        t+=v[0][i];
    t+=s;
    for (char c:v[1])
        t+=c;
    if (to_reverse)
        reverse(t.begin(),t.end());
    cout<<t<<endl;
    return 0;
}

Measured memory_bytes: 1368
#include <iostream>
#include <vector>

using namespace std;

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

	vector<int> a(N);

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

	int cur=N-1;
	int sum=0;
	for(int i=2; i<=2*N; i*=2){
		//cout << N/i << " " << cur << endl;
		while(N/i<=cur && 0<=cur){
			for(int j=2; ((1+cur)*j-1)<N; j++){
				a[cur]+=a[(1+cur)*j-1];
			}
			a[cur]%=2;
			//cout << "=" << a[cur] << endl;
			sum+=a[cur];
			cur--;
		}
	}

	cout << sum << endl;
	for(int i=0; i<N; i++){
		if(a[i]==1) cout << i+1 << endl;
	}

	return 0;

}



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

int main(void) {
	int a, b, c;
	cin >> a >> b >> c;
	int cnt = 0;
	for(int r = a; r <= b; r++) {
		if(c % r == 0) {
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1164
A, B = map(int, input().split())


def f(x):
    if x % 2 == 1:
        return ((x+1) //2) % 2
    else:
        return x ^ ((x//2) % 2)

#print(f(A-1), f(B))
ans = f(A-1) ^ f(B)
print(ans)

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set> 
#include <bitset>
using namespace std;


int main(){

    int x;

    cin >> x;

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

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

var h map[int]string = map[int]string{
	0: "A",
	1: "C",
	2: "G",
	3: "T",
}

func enumerate(j, k, l, m int) []string {
	return []string{
		h[j] + h[k] + h[l] + h[m],
		h[k] + h[j] + h[l] + h[m],
		h[j] + h[l] + h[k] + h[m],
		h[j] + h[k] + h[m] + h[l],
	}

}

func main() {
	var n int
	fmt.Scan(&n)

	mod := int(1e9 + 7)
	dp := [101][4][4][4]int{}
	for j:=0; j<4; j++ {
		for k:=0; k<4; k++ {
			for l:=0; l<4; l++ {
				str := h[j]+h[k]+h[l]
				if str == "AGC" || str == "GAC" || str == "ACG" {
					continue
				}
				dp[3][j][k][l] = 1
			}
		}
	}
	
	var flag bool
	for i:=3; i<n; i++ {
		for j:=0; j<4; j++ {
			for k:=0; k<4; k++ {
				for l:=0; l<4; l++ {
					for m:=0; m<4; m++ {
						flag = true
						for _, str := range enumerate(j, k, l, m) {
							if strings.Contains(str, "AGC") {
								flag = false
								break
							}
						}

						if flag {
							dp[i+1][k][l][m] += dp[i][j][k][l]
							dp[i+1][k][l][m] %= mod
						}
					}
				}
			}
		}
	}

	s := 0
	for j:=0; j<4; j++ {
		for k:=0; k<4; k++ {
			for l:=0; l<4; l++ {
				s += dp[n][j][k][l]
				s %= mod
			}
		}
	}

	fmt.Println(s)
}


Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var ap = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var a = ap[0];
        var p = ap[1];

        Console.WriteLine((a * 3 + p) / 2);
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;

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

    int out[3] = {-1, -1, -1};
    rep(i, n+1){
        if(i * 10000 + (n-i) * 5000 < y) continue;
        rep(j, n+1-i){
            if(i * 10000 + j * 5000 + (n-i-j) * 1000 < y) continue;
            rep(k, n+1-i-j){
                if(i + j + k != n) continue;
                if(i * 10000 + j * 5000 + k * 1000 == y){
                    out[0] = i;
                    out[1] = j;
                    out[2] = k;
                    break;
                }
            }
        }
    }

    cout << out[0] << " " << out[1] << " " << out[2] << endl;
}

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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

pair<pair<string, int>, int> SP[110];

signed main() {
    int n;
    cin >> n;
    rep(i, n) {
        string s;
        int p;
        cin >> s >> p;
        SP[i] = make_pair(make_pair(s, -p), i);
    }
    sort(SP, SP + n);
    rep(i, n) {
        int x = SP[i].second;
        cout << x + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
using namespace std;

int syc(long i,long Min,long Max){
	if(Min <= i && i <= Max){
		return 1;
	}else{
		exit(1);
		//return 0;
	}
}

int main(){
	int n;
	cin >> n;
	syc(n,2,10);
	double m[n],sum=0;
	string s[n];
	
	for(int i=0;i<n;i++){
		cin >> m[i];
		cin >> s[i];
		
		if(s[i]=="JPY"){
			sum += m[i];
		}else if(s[i]=="BTC"){
			sum += 380000.0*m[i];
		}
		
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include <iostream>
using namespace std;
int main(void){
    string str; string Q; int q=0,a,b; string W;
    cin >> str >> q;
    
    for(int u=0;u<q;u++){
        cin >> Q ;
        if(Q=="replace"){
            cin >> a>>b>>Q;
//cout << a << b << Q <<endl;      
            str=str.replace(a,b-a+1,Q);
//cout << str <<endl;
         }else if(Q=="reverse"){
            cin >>a>>b;
            W = str;//
            for(int i=0;i<b-a+1;i=i+1){
                W[a+i]=str[b-i];
//cout << W[i] <<endl;
//cout << W <<endl;                
            }
           str=W;//str.replace(a,b-a+1,W);
//cout << str <<endl;
        }else if(Q=="print"){
            cin >> a >>b ;
            cout << str.substr(a,b-a+1) <<endl;
//            for(int i=0;i<b-a+1;i=i+1){
//                W[i]=str[b-i];
//cout << W[i] <<endl;
//cout << W <<endl;                
//            }
        }
    }
    
}


Measured memory_bytes: 3224
n = int(input())
mod = 10**9 + 7

def sieve(n):
    if( n <= 1):
        return []
    elif(n==2):
        return [2]

    primes = [2]
    primes_append = primes.append
    len_list = (n+1)//2
    flags = [True] * len_list
    flags[0] = False
    for i in range(len_list):
        if(flags[i]):
            primes_append(i*2+1)
            start = ((i*2+1)**2)//2
            for j in range( start, len_list, i*2+1):
                flags[j] = False
    return primes

primes = sieve(1000)
ans = 1
for p in primes:
    tmp = 1
    x = n
    while(x>0):
        x //= p
        tmp += x
    ans *= tmp
    ans %= mod

print(ans)

Measured memory_bytes: 62248
#include<iostream>
using namespace std;
#include<map>
#include<set>
#include<algorithm>
#include<vector>
#define int long long int
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	map<int,int> mp;
	int y=n;
	int j;
	for(j=2;j*j<=y;j++)
	{
		if(n%j==0)
		{
			while(n%j==0)
			{
				mp[j]++;
				n/=j;
			}
		}
	}
	if(n!=1)
	{
		mp[n]++;
	}
	int total=0;
	for(auto p:mp)
	{
		int x=p.second;
		int z;
		int here=0;
		for(z=1;1;z++)
		{
			int val=(z*(z+1))/2;
			if(val<=x)
			{
				here=z;
			}
			else
			   break;
		}
		total+=here;
	}
	cout<<total<<endl;
}


Measured memory_bytes: 3660
#include<stdio.h>
int main(){
  int w,h,x,y,r,f;
  scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
  f=0;
  if(x+r>w)f=1;
  if(y+r>h)f=1;
  if(r>x)f=1;
  if(r>y)f=1;
  if(f==0)
    printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 2676
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int dat[202020];
int main()
{
	int num;
	scanf("%d", &num);
	vector<int>v;
	for (int i = 0; i < num; i++)
	{
		int z;
		scanf("%d", &z);
		z--;
		v.push_back(z);
		int low = lower_bound(v.begin(), v.end(), -z) - v.begin();
		dat[z] = low;
		if (low == v.size())v.push_back(-z);
		else v[low] = -z;
	}
	int ans = 0, bef = -1;
	for (int i = num - 1; i >= 0; i--)
	{
		if (bef == -1)
		{
			if (dat[i] > 0)ans++, bef = i + 1;
		}
		else
		{
			int a = dat[i], b = dat[i + 1], c = dat[bef];
			bool f;
			if (a == b)f = false;
			else if (a == c)f = true;
			else if (int(a < b) + int(b < c) + int(c < a) == 2)f = false;
			else f = true;
			if (f)ans++, bef = i + 1;
		}
	}
	printf("%d\n", ans);
}

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

using namespace std;

int main(){
    int a, b, c;
    cin>> a>> b>> c;
    int cnt = 0;
    if (a == b)
        cnt++;
    if (c == b)
        cnt++;
    if (a == c)
        cnt++;
    if(cnt == 1)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int MAX = 2e6+10;
int a[MAX];

int main() {
    int n; scanf("%d", &n);
    for(int i = 0; i < n; ++ i) {
        scanf("%d", &a[i]);
    }
    std::sort(a, a + n);

    bool flag = false;
    for(int i = 1; i < n; ++ i) {
        // printf("%d ", a[i]);
        if(a[i] == a[i - 1]) {
            flag = true;
            break;
        }
    }

    if(flag) puts("NO");
    else puts("YES");
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <bitset>
#include <unordered_map>
#include <queue>

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


int main(){
    int a,b;
    cin >> a >> b;
    if ( a > 9 || b > 9){
        cout << -1 << endl;
        return 0;
    }

    cout << a * b << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

int main(){
    int n, tmp;
    vector<int> h;
    cin >> n;
    int i;
    
    for(i = 0; i < n; i++){
        cin >> tmp;
        h.push_back(tmp);
    }
    
    int m = h[0];
    int count = 1;
    
    for(i = 1; i < n; i++){
        if(m <= h[i]){
            count++;
        }
        m = max(m, h[i]);
    }
    
    cout << count << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int vales[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

        int k = sc.nextInt();

        System.out.println(vales[k -1]);
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
int dp[3002][3002];
vector <char> res;
int main()
{
    string a, b;
    cin >> a >> b;
    for(int i = 1; i <= a.size(); i++)
        for(int j = 1; j <= b.size(); j++){
           if(a[i-1] == b[j-1])
                dp[i][j] = dp[i-1][j-1] + 1;
            else
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    int x = a.size();
    int y = b.size();
    while(x != 0 && y != 0){
        if(dp[x][y] == dp[x-1][y-1] + 1 && a[x-1] == b[y-1]){
            res.push_back(a[x-1]);
            x--;
            y--;
            //continue;
        }
        else{
            if(dp[x][y] == dp[x][y-1])
               y--;
            else
                x--;
        }
    }
    for(int i = res.size() - 1; i >= 0; i--)
        cout << res[i];
    return 0;
}


Measured memory_bytes: 35584
N,K = map(int, input().split())
p = [int(x) for x in input().split()]

pe_sum = 0.0
pe_sum_max = 0.0

for i in range(K):
    pe_sum += p[i] / 2 + 0.5

pe_sum_max = pe_sum

for i in range(K,N):
    pe_sum += (p[i] / 2 + 0.5) - (p[i-K] / 2 + 0.5)
    pe_sum_max = max(pe_sum,pe_sum_max)

print(pe_sum_max)


Measured memory_bytes: 25188
#include <stdio.h>
#include <string.h>

int main (){

	int angka = 0;	
	int hasil = 0;
	scanf("%d",&angka);
	
	while(angka >= 1000){
		angka-=1000;
	}
		
	if(angka == 0){
		hasil = 0;
	}else{
		hasil = 1000-angka;
	}
	
	printf("%d\n",hasil);
	return 0;
}

Measured memory_bytes: 3204
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
  int n,temp;
  cin>>n;
  
  temp=n%10;
    if(temp==3)
        cout<<"bon"<<endl;
    else if(temp==0||temp==1||temp==6||temp==8)
        cout<<"pon"<<endl;
    else
        cout<<"hon"<<endl;
return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define ll long long
#define str string
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define ff fflush(stdout)
using namespace std;
map<ll, ll> obj;
ll memo[55][55];
ll nCr (ll a, ll b) {
	if (a == b || a == 1) return 1;
	if (b == 1) return a;
	if (memo[a][b] != -1) return memo[a][b];
	return memo[a][b] = nCr(a - 1, b - 1) + nCr(a - 1, b);
}
int main () {
	ll a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q;
	scanf("%lld %lld %lld", &a, &b, &c);
	for (i = 1; i <= a; i++) {
		scanf("%lld", &d);
		obj[d]++;
	}
	auto r = obj.end(); r--;
	SET(memo, -1);
	if (r->se >= b) {
		e = r->se; f = 0;
		for (i = b; i <= min(e, c); i++) {
			f += nCr(e, i);
		}
		printf("%.6lf\n%lld\n", double(r->fi), f);
		return 0;
	}
	for (e = 0, h = 0; ; r--) {
		if (e + r->se < b) {
			e += r->se; h += r->fi * r->se;
		} else {
			f = b - e; g = nCr(r->se, f);
			h += f * r->fi;
			printf("%.6lf\n%lld\n", double(h) / double(b), g);
			break;
		}
		if (r == obj.begin()) break;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <tuple>
#include <math.h>
#include <deque>
#include <stack>

using namespace std;

typedef long long ll;

int main(void){
    ll n;
    cin >> n;
    ll cnt = 0;
    for(ll i = 1;i <= n; i++){
        string num = to_string(i);
        if(num.size() % 2 != 0){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#define mod 1000000007
#define int long long
#define pb(x) push_back(x)
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define lcm(a,b) (a*b)/gcd(a,b)
#define bits(x) __builtin_popcountll(x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main()
{
   fast;
   #ifndef ONLINE_JUDGE
   freopen("goodluckin.txt","r",stdin);
   freopen("goodluckout.txt","w",stdout);
   #endif
   string s;
   cin >> s;
   int n = s.size();
   for(int i = 0 ; i < s.size() ;i++ ){
     if(s[i]=='?'){
      s[i] = 'D';
     }
   }
   cout << s;
}






Measured memory_bytes: 3752
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(input())

def f(n):
    if n < 2:
        return 1
    else:
        return n * f(n - 2)

if N % 2 == 1:
    print(0)
else:
    ans = 0
    x = 5
    while x * 2 <= N:
        ans += N // (x * 2)
        x *= 5
    print(ans)


Measured memory_bytes: 65284
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ins insert
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define up_b upper_bound
#define low_b lower_bound
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define rev(i,a,b) for(int i=b;i>=a;i--)
#define boost ios_base::sync_with_stdio(NULL),cin.tie(NULL),cout.tie(NULL)
#define nl '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<pii> vii;

const int N=200001;
const int MXN=1000001;
const int inf=1e9;
const ll INF=1e18;

int main(){
  boost;
  int m,k;
  cin>>m>>k;
  if(k==0){
    for(int i=0;i<(1<<m);i++){
      cout<<i<<" "<<i<<" ";
    }
    return 0;
  }

  if(k>=(1<<m)){
    cout<<"-1";
  }
  else if(m==1&&k==1)cout<<"-1";
  else {
    cout<<"0 "<<k<<" 0 ";
    for(int i=1;i<(1<<m);i++){
      if(i!=k)cout<<i<<" ";
    }
    cout<<k<<" ";
    for(int i=(1<<m)-1;i>=1;i--){
      if(i!=k)cout<<i<<" ";
    }
  }
  return 0;
}



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



int main(){


 long long h,w;
cin>>h>>w;

 string board[50];

 for(int i=0;i<h;i++) cin>>board[i];

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

 for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){

     if(board[i][j] == '#') continue;

      int num=0;

      for(int d=0;d<8;d++){
        const int a1 = i+dy[d];
        const int b1 = j+dx[d];

        if(a1 < 0 || a1>=h) continue;
        if(b1 < 0 || b1>= w) continue;

        if(board[a1][b1] == '#') num++;
      }

      board[i][j] = char(num+'0');

    }
 }


 for(int i=0;i<h;i++)
    cout<<board[i]<<endl;


return 0;
}


Measured memory_bytes: 256
"use strict"

const Main = (input) =>{
const Array =input.split("\n")
const X = parseInt(Array[0],10)
const A =parseInt(Array[1],10)
const B =parseInt(Array[2],10)
const result = (X-A)%B
console.log(result)
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f

#define _rep(i,a,b) for(int i=(a);i<=(b);++i)


int main()
{
    #ifdef __LOCAL__
        freopen("1.in","r",stdin);
        freopen("1.out","w",stdout);
    #endif
    
    int n,w,h;
    cin>>n>>w>>h;
    int mx=max(n,w);
    if(h%mx==0)
        cout<<h/mx;
    else
        cout<<h/mx+1;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
#include <sstream>
#include <queue>
using namespace std;
typedef long long ll;

int main() {
  string s, t;
  cin >> s >> t;

  int t_size = t.size();

  int ans = t_size;
  for (int i = 0; i <= s.size()-t_size; i++) {
    int tmp = 0;
    for (int j = 0; j < t_size; j++) {
      if (s[i+j] != t[j]) tmp++;
    }
    ans = min(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3172
/* “Whether you think you can or you think you can’t, you’re right” - Henry Ford */

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define pb push_back
#define pl pair<ll, ll>
#define vl vector<ll>
#define vi vector<int>
#define endl '\n'

template <typename T, typename TT>
ostream &operator<<(ostream &os, const pair<T, TT> &t) {
    return os << t.first << " " << t.second;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &t) {
    for (auto &i : t) os << i << " ";
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &t : v) is >> t;
    return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, vector<pair<T1, T2>> &v) {
    for (pair<T1, T2> &t : v) is >> t.first >> t.second;
    return is;
}

const ll mod = 1e9 + 7;

void solve() {
    long double d, t, s;
    cin >> d >> t >> s;
    if(d/s > t) cout << "No" << endl;
    else cout << "Yes" << endl;
}

int main()
{
    fast;
    ll t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int n;
vector<int> A, B, X;
int a = -1;
int b = -1;

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

  cin>>n;
  A.resize(n);
  B.resize(n);
  for (int i=0; i<n; i++) {
    cin>>A[i];
  }
  for (int i=0; i<n; i++) {
    cin>>B[i];
  }

  
  X = A;

  int cur = 0;
  sort(X.begin(), X.end());


  do {
    if (X == A) a = cur;
    if (X == B) b = cur;
    cur++;
  } while (std::next_permutation(X.begin(), X.end()));

  cout<<abs(a-b)<<endl;
  return 0;
}


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

#define pb push_back
#define mp make_pair
#define all(n) (n).begin(),(n).end()
#define fi first
#define se second
#define mset(x,v) memset((x),(v),sizeof(x))

typedef pair<int, int> PII;
typedef long long ll;

const int MOD = 998244353;

int n,k;
ll dp[200005],pref[200005];
int main() {

	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	vector<PII> go;
	for (int i=0;i<k;i++) {
		int a,b;
		cin >> a >> b;
		go.pb({a,b});
	}
	pref[1]=1;
	for (int i=1;i<n;i++) {
		for (PII k : go) {	
			dp[i]+=pref[max(i-k.fi+1,0)]-pref[max(i-k.se,0)];
			dp[i]=(dp[i]+MOD)%MOD;
		}
		pref[i+1]=pref[i]+dp[i];
		pref[i+1]%=MOD;
	}
	cout << dp[n-1] << "\n";

}

Measured memory_bytes: 6708
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <stack>
#include <unordered_map>
#include <utility>
#include <vector>

// Aliases
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;

using std::cout;
using std::cerr;
using std::cin;
using std::endl;
using std::string;
using std::vector;

template <class T = i64>
vector<T> read_vector(const u64 n)
{
    vector<T> vec;
    vec.reserve(n);
    for (u64 i = 0; i < n; i++)
    {
        T v;
        cin >> v;
        vec.emplace_back(v);
    }

    return vec;
}

int main()
{
    u32 n;
    cin >> n;
    auto vec = read_vector<u32>(n);
    std::sort(vec.begin(), vec.end());

    u32 sum = 0;
    for (u32 i = 0; i < n; i++)
    {
        for (u32 j = i + 1; j < n; j++)
        {
            u32 p = vec[i] + vec[j];
            u32 k = j + 1;
            auto itr = std::lower_bound(vec.begin() + k, vec.end(), p);
            u32 d = std::distance(vec.begin() + k, itr);
            sum += d;
        }
    }

    cout << sum << endl;

    return 0;
}


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

int main(){
  int n;
  scanf("%d",&n);
  
  double x=0;
  vector< double > dp(n+1);
  
  dp[0]=1;
  for(int i=0;i<n;++i){
     scanf("%lf",&x);
     for(int j=i+1;j>=0;--j){
         if(j==0)
          dp[j]=dp[j]*(1-x);
         else
          dp[j]=dp[j-1]*x+dp[j]*(1-x);
     }
  }
  
  double answer=0;
  for(int i=0;i<=n;i++){
      if(i>(n-i))
       answer+=dp[i];
       
  }
  printf("%0.10lf\n",answer);
  return 0;
}
    

Measured memory_bytes: 256
/*
 * author :Sadik Hassan(_sad_)
 *
*/
#include "bits/stdc++.h"
using namespace std;
using   ll       =    long long;
using   ld       =    long double;
#define nl            "\n"
#define pb            push_back
#define fi            first
#define se            second
#define MP            make_pair
#define PI            (acos(-1.0))
#define rep1(i,n)     for(int i=1;i<=n;i++)
#define rep(i,n)      for(int i=0;i<n;i++)
#define SZ(s)         (int)s.size()
#define all(x)        (x).begin(), (x).end()
#define rall(x)       (x).rbegin(), (x).rend()
#define w(t)          int t;cin>>t;while(t--)
#define TSU(s)        transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSL(s)        transform(s.begin(),s.end(),s.begin(),::tolower);
#define _SAD()     	  ios::sync_with_stdio(0),cin.tie(0),cout.tie(0),cout<<fixed<<setprecision(15);

typedef vector<int> vi;
typedef vector<ll> vii;
typedef set<int> si;
typedef set<ll> sii;
/*---------------------------------------------------------------------*/

const int N = (int)1e6+1;
const int MOD =(ll)1e9+1147483647;
const ll INF = (ll)1e18+5;

int main()
{
    _SAD()
    int n;
    cin>>n;
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        if((i&1)&&(x&1))cnt++;
    }
    cout<<cnt<<nl;
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans = -1;
    rep(i, 1, n + 1){
        int tmp = i * 108 / 100;
        if(tmp == n) ans = i;
    }
    if(ans == -1) cout << ":(" << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> V;

#define _ cin.tie(0);ios::sync_with_stdio(false);
string s;
int main(){ _;
  cin>>s;
  int len=s.length();
  cout<<s[0]<<len-2<<s[len-1]<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <numeric>

using namespace std;

int main()
{
    string s;
    string ans[10];
    int m, cnt = 0;

    while (1) {
        cin >> s;
        if (s == "-") {
            break;
        }
        cin >> m;

        for (int i = 0; i < m; i++) {
            int sub;
            cin >> sub;
            s += s.substr(0, sub);
            s.erase(0, sub);
        }
        ans[cnt] = s;
        cnt++;
    }

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




Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
int a[100000][3],b[100000][3];
int n;
int f(int x,int y)
{
    if(x+1==n) return a[x][y];
    if(b[x][y]!=0) return b[x][y];
    int p,q;
    if(y==0)      {p=1;q=2;}
    else if(y==1) {p=0;q=2;}
    else if(y==2) {p=0;q=1;}
    return b[x][y]=a[x][y]+max(f(x+1,p),f(x+1,q));
}
int main()
{
    int i,j;
    cin>>n;
    for(i=0;i<n;i++)
        for(j=0;j<3;j++) cin>>a[i][j];

    cout<<max(max(f(0,0),f(0,1)),f(0,2))<<endl;

    return 0;
}




Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = 1001002003004005006ll;
const int inf = 1001001001;
const int mod = 1000000007;

vector<int> g[100005];
int dist[100005][3];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].emplace_back(b);
	}
	int s, t;
	cin >> s >> t;
	s--; t--;
	memset(dist, -1, sizeof(dist));
	queue<P> que;
	que.emplace(s, 0);
	dist[s][0] = 0;
	while (que.size()) {
		int u = que.front().first;
		int v = que.front().second;
		que.pop();
		for (auto& c : g[u]) {
			int nv = (v + 1) % 3;
			if (dist[c][nv] != -1) continue;
			dist[c][nv] = dist[u][v] + 1;
			que.emplace(c, nv);
		}
	}
	if (dist[t][0] == -1) cout << -1 << endl;
	else cout << dist[t][0] / 3 << endl;
	return 0;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

struct edge { int to; int cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-12;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int dp[500010];

int main(){
	int n,k;
	cin >> n >> k;
	vi h(n);
	rep(i,n) cin >> h[i];
	rep(i,500010) dp[i] = INF;
	dp[0] = 0;
	for(int i = 0; i < n; i++){
		for(int j = 1; j <= k; j++){
			if(i>=j) chmin(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
		}
	}
	cout << dp[n-1] << endl;

	return 0;
}

Measured memory_bytes: 2560
# https://atcoder.jp/contests/abc085/tasks/abc085_c

# N枚、Y円
N, Y = map(int, input().split())

for i in range(N + 1):
    for j in range(N + 1):
        
        z = N - (i + j)

        if z < 0:
            continue

        total = i*1000 + j*5000 + z*10000
        
        if total == Y:
            print(z, j, i)
            exit()

print('-1 -1 -1')

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

using namespace std;

int main(int argc, char *argv[]) {
  std::ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<tuple<int, int, int>> a;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    a.emplace_back(x, 0, i);
    a.emplace_back(y, 1, i);
  }
  sort(a.begin(), a.end());
  int mask = 0;
  long long sum = 0;
  vector<bool> vis(n);
  bool ok = false;
  for (int i = 0; i < n; i++) {
    int v, d, x;
    tie(v, d, x) = a[i];
    mask |= (1 << d);
    sum += v;
    if (vis[x]) {
      ok = true;
    }
    vis[x] = true;
  }
  long long ans = sum;
  if (mask == 3 && !ok) {
    ans = sum - get<0>(a[n - 1]) + get<0>(a[n]);
    if (get<2>(a[n - 1]) == get<2>(a[n])) {
      ans = sum - get<0>(a[n - 1]) + get<0>(a[n + 1]);
      for (int i = 0; i + 1 < n; i++) {
        ans = min(ans, sum - get<0>(a[i]) + get<0>(a[n]));
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4852
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int nummax = sc.nextInt();
		String astring = sc.next();
		String bstring = sc.next();
		String cstring = sc.next();

		int ans = 0;

		for (int i =0;i < nummax; i++) {

			if(!astring.substring(i,i+1).equals(bstring.substring(i,i+1))){
				ans++;
			}
			if(!astring.substring(i,i+1).equals(cstring.substring(i,i+1)) &&
					!bstring.substring(i,i+1).equals(cstring.substring(i,i+1)) 	){
				ans++;
			}
		}
		System.out.println(ans);
	    sc.close();

	}

}

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

#define int long long
#define pb emplace_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(0);

int32_t main(){
	fast;

	string s;
	cin >> s;
	map<char,int> m;
	for(auto x : s) m[x]++;
	for(auto x : m) if(x.S%2==1)    return cout << "No",0;
	cout << "Yes";

}







Measured memory_bytes: 256