akhauriyash/Code-Regression huggingface dataset:
//templates
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <queue>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define sort_key(struct_name,key_name) [](const struct_name &x, const struct_name &y){return x.key_name < y.key_name;}
#define pb(x) push_back(x)
typedef long long ll;
const long long MOD = 1e9 + 7;
using namespace std;

//main
int main(){
  ll N; cin >> N;
  ll a=0;
  ll ans;
  while (a*a <= N){
    a++;
  }
  for (ll i=a-1; i>0; i--){
    if (N%i == 0){
      ans = i;
      break;
    }
  }
  cout << ans + N/ans - 2 << endl;
}




Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX = 100001;
int main()
{
  int n,m,i,d,t;
  cin >> n >> m;
  int co[N_MAX];
  int c[N_MAX]; // 頂点iの属する集合番号
  int nc[N_MAX]; // 集合jの要素数
  int pc[N_MAX]; // 集合jの先頭の要素番号
  int pi[N_MAX]; // 頂点iと同じ集合の要素へのポインタ
  int i1,i2,s1,s2,p,pt;
  int c1,c2;
  for(i=1;i<=n;i++){
    c[i]=i;
    nc[i]=1;
    pc[i]=i;
    pi[i]=0;
    co[i]=0;
  }
  for(i=0;i<m;i++){
    cin >> i1 >> i2 >> d;
    if(c[i1]==c[i2]){
      if(co[i2]-co[i1]!=d){
        cout << "No" << endl;
        return 0;
      }
    }else{
// 集合のマージここから
      s1=c[i1]; s2=c[i2]; t=d+co[i1]-co[i2];
      if(nc[s1]<nc[s2]){// 小さい方を潰す【重要】
        s1=c[i2]; s2=c[i1]; t=-t;
      }
      pt=pc[s1];
      p=pc[s2];
      pc[s1]=p;
      nc[s1]+=nc[s2];
      pc[s2]=0;
      nc[s2]=0;
      while(true){
        c[p]=s1;
        co[p]+=t;
        if(pi[p]==0) break;
        p=pi[p];
      }
      pi[p]=pt;
// 集合のマージここまで
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

int n;
double x[100],y[100];

double distance(double p){
    double sum=0;
    for(int i=0;i<n;i++){
        double w=abs(x[i]-y[i]);
        sum += pow(w,p);
    }
    return pow(sum,1.0/p);
}

int main(){
    cout<<fixed<<setprecision(12);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    for(int i=0;i<n;i++){
        cin>>y[i];
    }
    cout<<distance(1)<<endl;
    cout<<distance(2)<<endl;
    cout<<distance(3)<<endl;
    double mx=0;
    for(int i=0;i<n;i++){
        mx=max(mx,abs(x[i]-y[i]));
    }
    cout<<mx<<endl;
    return 0;
}


Measured memory_bytes: 3396
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))

B = [A[i] for i in range(N)]
  
m1 = max(A)
idx = A.index(m1)
B.pop(idx)
m2 = max(B)

for i in range(N):
  if i == idx:
    print(m2)
  else:
    print(m1)

Measured memory_bytes: 14076
list=input()
list=list.split()
list=[int(i) for i in list]
A=list[0]
B=list[1]
C=list[2]
Sum=A
flag=True
rem=A%B
while Sum%B!=C:
    Sum+=A
    if Sum%B==rem:
        flag=False
        break
if flag:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define xmod int(1e9+7)
#define hmod 1223334444555553LL
using namespace std;

ll a,b;
int main(){
	scanf("%lld%lld",&a,&b);
	printf("%lld\n",a*b/__gcd(a,b));
    return 0;
}	

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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define bit(n) (1<<(n))

#define out(x) cout<<(x)<<endl;
#define err(x) cerr<<(x)<<endl;
#define errr(x,y) cerr<<(x)<<" "<<(y)<<endl;

#define rep(i,n) for (int i=0;i<(n);i++)
#define repp(i,n) for (int i=1;i<=(n);i++)

#define i5 100002

int main(){
	int a, p, ans=0;
	cin >> a >> p;

	p += a * 3;

	out((p - p % 2) / 2);

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<string>
#include<utility>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bits/stdc++.h>
#include<stdio.h>
 
int main(){
   int N;
   cin >> N;
   string S;
   cin >> S;
   string c;
   string b;
   for(int i=0;i<N/2;++i){
       c+=S[i];
   }
   for(int i=N/2;i<N;++i){
       b+=S[i];
   }
   bool ans=false;
   if(c==b){
       ans=true;
   }
   if(ans){
       cout << "Yes";
   }
   else{
       cout << "No";
   }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    if(s.substr(0, n/2) == s.substr(n/2+1, n)) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}




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

int n;
cin >> n;

map<string,int> mp;

rep(i,n){
    string s;
    cin >> s;
    sort(all(s));
    mp[s]++;
}

ll ans = 0;

for(auto& p : mp){
    int t = p.second;
    ans += (ll)t * (t-1) / 2;
}

cout << ans << endl;

return 0;
}

Measured memory_bytes: 11264
#include<iostream>
using namespace std;
const int MAXN=3000+100;
long long dp[MAXN][MAXN];
int a[MAXN];
int n;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		dp[i][i]=a[i];
	}
	for(int len=2;len<=n;len++)
	{
		for(int l=1;l<n;l++)
		{
			int r=l+len-1;
			dp[l][r]=max(a[l]-dp[l+1][r],a[r]-dp[l][r-1]);
		}
	}
	cout<<dp[1][n]<<endl;
	return 0;
}

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

int main() {
  int N, s;
  cin >> N;
  s = N/10%10;
  if(s != N/100%10) cout << "No";
  else if(s == N%10 || s == N/1000%10) cout << "Yes";
  else cout << "No";
}


Measured memory_bytes: 3604
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.setf(ios_base::fixed);
	cout.precision(8);
	double x1, y1, x2, y2;
	cin>>x1>>y1>>x2>>y2;
	cout<<hypot(x2-x1, y2-y1)<<'\n';
	return 0;
}



Measured memory_bytes: 3328
module mod_stack
  implicit none
  type t_node
    private
    integer :: item
    type(t_node), pointer :: prev => null()
    type(t_node), pointer :: next => null()
  end type
  type t_stack
    private
    integer :: num = 0
    type(t_node), pointer :: head => null()
    type(t_node), pointer :: tail => null()
  contains
    procedure :: push => push
    procedure :: pop => pop
    procedure :: peek => peek
    procedure :: clear => clear
    procedure :: size => size_of
  end type
contains
  function new_node(item) result(node)
    integer, intent(in) :: item
    type(t_node), pointer :: node
    allocate(node)
    node%item = item
  end
  subroutine push(this,item)
    class(t_stack), intent(inout) :: this
    integer, intent(in) :: item
    type(t_node), pointer :: node
    node => new_node(item)
    if (associated(this%head)) then
      node%prev => this%tail
      this%tail%next => node
    else
      this%head => node
    end if
    this%tail => node
    this%num = this%num+1
  end
  function pop(this) result(item)
    class(t_stack), intent(inout) :: this
    integer :: item
    type(t_node), pointer :: node
    item = this%tail%item
    node => this%tail%prev
    deallocate(this%tail)
    this%tail => node
    if (associated(node)) then
      node%next => null()
    else
      this%head => null()
    end if
    this%num = this%num-1
  end
  function peek(this) result(item)
    class(t_stack), intent(in) :: this
    integer :: item
    item = this%tail%item
  end
  subroutine clear(this)
    class(t_stack), intent(inout) :: this
    type(t_node), pointer :: node, prev
    if (.not.associated(this%tail)) return
    node => this%tail
    do while (associated(node%prev))
      prev => node%prev
      deallocate(node)
      node => prev
    end do
    this%head => null()
    this%tail => null()
    this%num = 0
  end
  integer function size_of(this)
    class(t_stack), intent(in) :: this
    size_of = this%num
  end
end module mod_stack
program match_matching
  use mod_stack
  implicit none
  type(t_stack) :: stack
  integer :: n, m, i, j, dp(0:10000) = -1
  integer, dimension(9) :: a = 0, x = 0, p = (/2,5,5,4,5,6,3,7,6/)
  read(*,*) n, m
  read(*,*) a(1:m)
  do i = 1, m
    x(a(i)) = x(a(i))+1
  end do
  m = 0
  do i = 9, 1, -1
    if (x(i) == 0) cycle
    m = m+1
    a(m) = i
  end do
  dp(0) = 0
  do i = 1, n
    do j = 1, m
      if (i < p(a(j))) cycle
      dp(i) = max(dp(i),dp(i-p(a(j))))
    end do
    if (dp(i) >= 0) dp(i) = dp(i)+1
  end do
  i = n
  do while (i > 0)
    do j = 1, m
      if (i-p(a(j)) < 0 .or. dp(i-p(a(j))) /= dp(i)-1) cycle
      i = i-p(a(j))
      call stack%push(a(j))
      exit
    end do
  end do
  x = 0
  do while (stack%size() > 0)
    i = stack%pop()
    x(i) = x(i)+1
  end do
  do i = 9, 1, -1
    do j = 1, x(i)
      write(*,'(i0)',advance='no') i
    end do
  end do
  write(*,*)
end program match_matching

Measured memory_bytes: 384
import glob
import numpy as np
import heapq


# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = 'ABC\\137\\C'

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class C(Common):

    def resolve(self):

        N = int(self.input_data())
        problem = ["" for i in range(N)]

        for i in range(N):
            tmp = self.input_data()
            tmp = list(tmp)[0:10]
            tmp.sort()
            for j in range(10):
                problem[i] += tmp[j]

        problem.sort()
        con_num = 1
        now = ""
        result = 0

        for s in problem:
            if now == s:
                con_num += 1
            else:
                result += int(con_num * (con_num-1) / 2)
                con_num = 1
                now = s
        result += int(con_num * (con_num - 1) / 2)

        print(str(result))


solver = C(REL_PATH)
solver.exec_resolve()

Measured memory_bytes: 19860
package main

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

const maxBuf = 200100

const debug = false

var buf []byte = make([]byte, maxBuf)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	if debug {
		testFile, err := os.Open("./test/sample-1.in")
		if err == nil {
			sc = bufio.NewScanner(testFile)
		}

	}
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBuf)
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func readInt() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func readFloat64() float64 {
	sc.Scan()
	r, _ := strconv.ParseFloat(sc.Text(), 64)
	return r
}

/* #### main #### */
func main() {
	x := readInt()
	if x >= 30 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1784
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    ll n, k;
    cin >> n >> k;
    ll a[100002], b[100002], c[100002];
    for(ll i = 0; i < n; i++) c[i] = k + n * 2 + i;
    if(n % 2){
        for(ll i = 0; i <= n / 2; i++) a[i * 2] = k + i, b[i * 2] = k + n + n / 2 + i;
        for(ll i = 0; i < n / 2; i++) a[i * 2 + 1] = k + n / 2 + 1 + i, b[i * 2 + 1] = k + n + i;
    }
    else{
        for(ll i = 0; i < n / 2; i++) a[i * 2] = k + i, b[i * 2] = k + n * 3 / 2 + i;
        for(ll i = 0; i < n / 2 - 1; i++) a[i * 2 + 1] = k + n / 2 + i, b[i * 2 + 1] = k + n + 1 + i;
        a[n - 1] = k + n - 1, b[n - 1] = k + n;
    }
    for(int i = 0; i < n; i++) if(a[i] + b[i] > c[i]){
        cout << -1 << endl;
        return 0;
    }
    for(int i = 0; i < n; i++) cout << a[i] << " " << b[i] << " " << c[i] << endl;
}

Measured memory_bytes: 4608
#include<string>
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<map>
#include<cmath>
#include<math.h>
using namespace std;
int main()
{
	int i,j,n,cnt,ans=0;
	cin>>n;
	for(i=1;i<=n;i=i+2)
	{
		cnt=0;
		for(j=1;j<=n;j++)
		{
			if(i%j==0)
			cnt++;
		}
		if(cnt==8)
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

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

ll prime[1010];

void fact(int n){
	for(int i=2;i<=n;i++){
		if(n%i==0){
			prime[i]++;
			n/=i;
			i--;
		}
	}
}
 
int main(void)
{
  	int n;
  	cin >> n;

	ll ret = 1;
	FOR(i, 2, n+1) fact(i);
	FOR(i, 2, n+1) {
		ret *= (prime[i]+1);
		ret %= MOD;
	}
 
 	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 256
H,N = gets.split(' ').map(&:to_i)
cost = Array.new(H+1,10**10)
cost[0] = 0
def minus(cnt,hit)
  if (cnt-hit)<0
    return 0
  else
    return cnt-hit
  end
end

N.times do
  a,b = gets.split(' ').map(&:to_i)
  for i in 1..H
    cost[i] = cost[minus(i,a)] + b if (cost[minus(i,a)] + b) < cost[i]
  end
end

puts cost[H]


Measured memory_bytes: 1916
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;
typedef std::pair<LL, LL> P;
struct edge { LL to, cost; };

const LL inf = 1123456789012;
std::vector<std::vector<LL>>G;
std::vector<LL>memo;

LL dp(LL i)
{
	if (memo[i] != -1) return memo[i];
	LL res = 0;
	for (auto v : G[i]) res = std::max(res, dp(v) + 1);
	return memo[i] = res;
}

int main()
{
	LL N, M;
	in >> N >> M;
	std::vector<LL>x(M), y(M);
	rep(i, M) in >> x[i] >> y[i];

	G.resize(N + 1);
	rep(i, M) G[x[i]].push_back(y[i]);

	memo.resize(N + 1, -1);
	LL ans = 0;
	for (LL i = 1; i <= N; ++i) ans = std::max(ans, dp(i));
	out << ans << std::endl;
}


Measured memory_bytes: 10112
n = int(input())
a = list(filter(lambda x: x % 2 == 0, map(int, input().split())))
ans = 0
while len(a) != 0:
    ans += len(a)
    a = list(filter(lambda x: x % 2 == 0, map(lambda x: x / 2, a)))
print(ans)

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

vector<vector<int>> G;
vector<bool> seen;
vector<pair<int,int>> ts;
int cnt=1;

void dfs(int v){
    seen[v]=true;
    ts[v].first = cnt;
    cnt++;

    for(auto next_v : G[v]){
        if(seen[next_v])continue;
        dfs(next_v);
    }
    ts[v].second = cnt;
    cnt++;
}

int main(){
    int N; 
    cin>>N;
    G.resize(N);
    ts.resize(N);
    rep(i,N){
        int u,k; 
        cin>>u>>k;
        rep(j,k){
            int vz; 
            cin>>vz;
            G[u-1].push_back(vz-1);
        }
    }
    seen.assign(N, false);
    for(int i=0; i<N; i++){
        if(!seen[i])dfs(i);
    }
    rep(i,N){
        cout<<i+1<<" "<<ts[i].first<<" "<<ts[i].second<<endl;
    }
    return 0;
}


Measured memory_bytes: 3168
#include<iostream>
using namespace std;
int a[55];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;++i)cin>>a[i];
    int ans = 0;
    for(int i=1;i<=n;++i)
    {
        for(int j=i+1;j<=n;++j)
        {
            ans += a[i]*a[j];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

vector<ll> par;
vector<ll> siz;

void init(ll n){
  rep(i,n) {
    par[i] = i;
    siz[i] = 1;
  }
}

ll root(ll x){
  if(par[x] == x) return x;
  else return par[x] = root(par[x]);
}

bool same(ll x, ll y){
  return root(x) == root(y);
}

void unite(ll x, ll y){
  x = root(x);
  y = root(y);
  if(x==y) return;
  siz[x] += siz[y];
  par[y] = x;
}

int main(){
  ll N, M; cin >> N >> M;
  vector<pair<ll,ll>> AB(M);
  vector<ll> ans(M);
  rep(i,M){
    cin >> AB[i].first >> AB[i].second;
    AB[i].first--; AB[i].second--;
  }
  reverse(all(AB));
  par.resize(N);
  siz.resize(N);
  init(N);
  ll nogood = N*(N-1)/2;
  rep(i,M){
    ans[i] = nogood;
    ll a = AB[i].first;
    ll b = AB[i].second;
    if(same(a, b)){}
    else nogood -= siz[root(a)]*siz[root(b)];
    unite(a, b);
  }
  reverse(all(ans));
  rep(i,M){
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 5248
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    r = n // 2
    if n % 2 == 0:
        r -= 1

    return r


print(main())





Measured memory_bytes: 6728
#include<cstdio>
#include<cmath>

using namespace std;

int main(){
  int num;
  scanf("%d",&num);
  for(int i=0;i<num;++i){
    double in1,in2,in3;
    scanf("%lf %lf %lf",&in1,&in2,&in3);
    if(in1==sqrt(in2*in2+in3*in3)||
    in2==sqrt(in1*in1+in3*in3)||
    in3==sqrt(in1*in1+in2*in2)){
      printf("YES\n");
    }else{
      printf("NO\n");
    }
  }
  
  return 0;
}

Measured memory_bytes: 2568
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <algorithm>

using namespace std;
typedef long long ll;

int main() {
    ll n;cin >> n;
    vector<ll> A(n);
    for(int i=0;i<n;i++){
        cin >> A[i];
    }
    sort(A.rbegin(),A.rend());
    ll ma = A[0];
    A.erase(A.begin(),A.begin()+1);
    ll dx=0,di=A[0];
    for(int i=0;i<A.size();i++){
        if(llabs(ma/2-llabs(ma-A[i]))<di){
            di=llabs(ma/2-llabs(ma-A[i]));
            dx=A[i];
        }
    }
    cout << ma << " " << dx << endl;
}

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

const int N = 13;
const int MOD = 1000000007;
ll dp[100005][N];

int main()
{
  string s;
  cin >> s;
  dp[0][0] = 1;
  for (int i = 0; i < s.size(); ++i)
  {
    // cout << "loop: " << i << endl;
    char c = s[i];
    if (c == '?')
    {
      rep(k, 10)
      {
        rep(j, N)
        {
          dp[i+1][((j * 10) + k) % N] += dp[i][j];
          dp[i+1][((j * 10) + k) % N] %= MOD;
        }
      }
    }
    else
    {
      int k = (int)(s[i] - '0');
      rep(j, N)
      {
        dp[i+1][((j * 10) + k) % N] += dp[i][j];
        dp[i+1][((j * 10) + k) % N] %= MOD;
      }
    }
  }
  cout << dp[s.size()][5] << endl;
}

Measured memory_bytes: 10624
#include <bits/stdc++.h>
using namespace std;
using LL = long long; using PII = pair<LL, LL>; using VI = vector<LL>; using VVI = vector<VI>;
using VB = vector<bool>; using VS = vector<string>; using VP = vector<PII>;
#define VV(T)        vector<vector<T>>
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define $(x)         {cout << #x << " = " << (x) << endl;}


void solve(long long n, std::vector<long long> p){
    LL ans = 0;
    FOR(i, 1, n - 1) {
        //$(i);
        if ((p[i - 1] < p[i] && p[i] < p[i + 1]) || (p[i - 1] > p[i] && p[i] > p[i + 1])) {
            ans++;
        }
    }
    cout << ans << endl;
}

int main(){
    long long n;
    scanf("%lld",&n);
    std::vector<long long> p(n);
    for(int i = 0 ; i < n ; i++){
        scanf("%lld",&p[i]);
    }
    solve(n, std::move(p));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;

int main(){
  ll k,s;
  cin>>k>>s;
  ll ans=0;
  rep(i,k+1){
    rep(j,k+1){
      if(s-i-j<=k&&s-i-j>=0){
        ans++;
      }
    }
  }
  COUT(ans);
}
      


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

int main()
{
	int a,b,c;
	string ans;

	ans="No";
	cin >> a >> b >> c;
	if (a<b)
		if (b<c)
			ans="Yes";

	cout << ans << endl;
}



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

/*
,,,,
　　　　　　　　　　　　　　　　　　　　　　　　　　,.斗*''“i:i:{
　　　　　　　　　　　　　,.　｡. . . * : : : ''' : : : :” :”“ ''ｰ - 弋,,_
　　　　　 　 　 ,.斗*''“ : : : : : : : : : : : : : ' ' ' ' ' ' : : : : : : : : : : :”: '':* ｡ ,
　　　 ,.斗*''“ ” ＼：　　 ”・・． ' ' ' '　　　　　　　　 ' ' ' ' : : : : : : : : : : : : ”ミ*｡,,,,,,　　　　　　 　 　 　 ＿
　　く.　 ◎　 ﾞ:.ﾞ:..　ﾟ:,　:　───────────　　　--　　,,,,,,__ ' ' ' :.:.:.:.:.”≧s｡.　　＿,,,｡s*i:i:i:i:<
　　ﾏ*s｡ :,　 }　ﾟ:,　 :}　　　　　　　　　　　　　　　　　　　　　　　　　　　　”　''　-　”””：：”：：`*｡i:i:i:i:i:i:i;:’
　　　` .｡`　 ,　,ノ ／｡ ,,,_　　　　　　　　　　　　　　　　　　　　　　　　　　　　　＿＿`　　} }　　ﾉi:i:i:i:i:ﾂ
　　　　　 `　*　｡　　`*｡i:i:i::*=-　　　　　　　　　　　＿＿　　　　　　,,,....｡s*'i,:’　　　”`*｡＿,*’i:i:i:i:r’
　　　　　　　　　　　”　─ --　　　　｡｡｡｡｡　　 -　－`''''''''ヽ ─ '''”　　　｀ｰ“　　　　　　　`*｡i:i:i:i:i:i:
　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　`*｡i:i:::
　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　`*ﾟ:,
         fozubaoyou    no BUGs alive!
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

#define debug_interval ','
#define dump_interval endl
#define debug_toggle 0

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cout<<endl;}
template<class...A> inline void debug_rest() {cout<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cout<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cout<<first,debug_rest(rest...);}

int n,m;
char b;
string s,t;

int main(){
  ios::sync_with_stdio(false);
  cin>>n>>m;
  for(int i=0;i<n;i++){
    cin>>s;
    dump(s,s);
  }
}

Measured memory_bytes: 256
N = int(input())
count = [0] * 5
c = "MARCH"

for i in range(N):
    s = input()
    for j in range(5):
        if s[0] == c[j]:
            count[j] += 1
            break

ind = []
for i in range(5):
    if count[i] > 0:
        ind.append(count[i])

if len(ind) < 3:
    print(0)
else:
    ans = 0
    for i in range(len(ind)):
        for j in range(i+1, len(ind)):
            for k in range(j+1, len(ind)):
                ans += ind[i] * ind[j] * ind[k]
    print(ans)

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

#define whole(f, x, ...)                                 \
  ([&](decltype((x)) whole) {                            \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__); \
  })(x)

using namespace std;
using ll = long long;

void solve() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }

  int ans = numeric_limits<int>::max();

  for (int i = 0; i < (1 << n); ++i) {
    int cnt = 0;
    vector<int> s(m);
    for (int j = 0; j < n; ++j) {
      if (i & (1 << j)) {
        cnt += c[j];
        for (int k = 0; k < m; k++) {
          s[k] += a[j][k];
        }
      }
    }

    bool cl = true;
    for (int t : s) {
      if (t < x) {
        cl = false;
        break;
      }
    }

    if (cl) ans = min(ans, cnt);
  }

  if (ans == numeric_limits<int>::max()) ans = -1;
  cout << ans << endl;
}

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

  solve();
  return 0;
}


Measured memory_bytes: 3660
import java.util.Scanner;
import java.util.Arrays;

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

		for (int i = 0; i < k; i++) {
			d[i] = sc.nextInt();
		//	System.out.println(d[i]);
		}

		boolean found = false;
		int i;
		for (i = n; !found; i++) {
			//System.out.println("---" + i);
			if (noDigits(d, i)) 
				found = true;

		}
		System.out.println(--i);
	}

	public static boolean noDigits(int[] d, int num) {
		while (num != 0) {
			int dig = num % 10;
			//System.out.println(dig + "\t" + num);

			for (int i = 0; i < d.length; i++) {
				if (d[i] == dig) return false;
			}




			/*if (Arrays.asList(d).contains(dig)) {
				System.out.println("false");
				return false;
			}*/
			num /= 10;
		}
		return true;
	}
}

Measured memory_bytes: 23252
from collections import Counter
def main():
    n = int(input())
    A = list(map(int, input().split()))
    A.sort()
    p = set()
    no_count = set([k for k, v in Counter(A).items() if v >= 2])
    ans = 0
    for a in A:
        if a not in p:
            b = a
            while b <= A[-1]:
                p.add(b)
                b += a
            if a not in no_count:
                ans += 1
    print(ans)





if __name__ == '__main__':
    main()


Measured memory_bytes: 101036
W = input()
T = ""
count = 0
while True:
    t = input()
    if t == "END_OF_TEXT":
        break
    T += t
    T += " "
W = W.lower()
T = T.lower()
T_list = T.split(" ")
for word in T_list:
    if word == W:
        count += 1
print(count)


Measured memory_bytes: 5556
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

llong n, m;
llong s, t;
vector<llong> g[1005];
llong min_cost[1005][1005];
llong from[1005];
bool link[1005][1005];

queue<llong> que;

void bfs(llong s) {
    for (int i = 0; i < n; i++) {
        min_cost[s][i] = 1ll << 60ll;
    }
    min_cost[s][s] = 0;
    from[s] = -1;
    
    que.push(s);
    while (!que.empty()) {
        llong pos = que.front();
        que.pop();

        for (auto e:g[pos]) {
            if (min_cost[s][e] > min_cost[s][pos] + 1) {
                min_cost[s][e] = min_cost[s][pos] + 1;
                from[e] = pos;
                que.push(e);
            }
        }
    }
}

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> s >> t;
        s--, t--;
        g[s].push_back(t);
        link[s][t] = true;
    }

    for (int i = 0; i < n; i++) {
        bfs(i);
    }

    llong k = 1ll << 60ll;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i == j) continue;

            if (link[i][j] &&
                min_cost[j][i] + 1 < k) {
                s = j;
                t = i;
                k = min(k, min_cost[j][i] + 1);
            }
        }
    }

    if (k > n) {
        cout << -1 << endl;
        return 0;
    }

    bfs(s);
    cout << k << endl;
    cout << t + 1 << endl;
    llong u = t;
    while (u != s) {
        u = from[u];
        cout << u + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 9216
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
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<bool> vb;
typedef vector<double> vd;
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 irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main(void) {

    int n;
    cin>>n;
    ll ans=LLINF;
    rep(i,n){
        ll a,b;
        cin>>a>>b;
        chmin(ans,b+a);
    }
    fin(ans);
}

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

int main()
{
	int a,i=0,m=1e6;bool p[m]={0};
	for(i=2;i<m;i++)
	{
		for(a=i+i;a<m;a+=i)p[a]=1;
	}
	
	for(;cin>>a;)
	{
		i=0;
		for(m=2;m<=a;i+=!p[m++]);
		cout<<i<<endl;
	}
	return 0;
}

Measured memory_bytes: 4020
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;

int dp[100000];

int main()
{
    int a,b;
    cin >> a >> b;
    int ans = -1;
    for(int i = 1000000; i >= 0; i--){
        int x = floor(i * 0.08);
        int y = floor(i * 0.1);
        if(a == x && b == y) ans = i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<cstdio>

using namespace std;

#define rep(i, n) for(long int i = 0; i < n; i++)
#define P pair<long int, long int>


int main(){
    long int n;
    cin >> n;
    long int u, v, w;
    vector<P> p[n];
    rep(i, n - 1) {
        cin >> u >> v >> w;
        u--; v--;
        p[u].push_back(P(v, w));
        p[v].push_back(P(u, w));
    }
    long int col[n];
    rep(i, n) col[i] = 0;
    col[0] = 1;
    queue<P> que;
    que.push(P(0, 0));
    while(!que.empty()){
        P g = que.front();
        que.pop();
        long int e = g.first;
        long int dis = g.second;
        for (int i = 0; i < p[e].size(); i++){
            if(col[p[e][i].first] == 0){
                long int disn = dis + p[e][i].second;
                if(disn % 2 == 0) col[p[e][i].first] = 1;
                else col[p[e][i].first] = 2;
                // cout << e << " " << p[e][i].first << " " << disn << endl;
                que.push(P(p[e][i].first, disn));
            }
        }
    }
    rep(i, n) cout << col[i] - 1 << endl;
}


Measured memory_bytes: 8704
// 4/30
// 過去問攻略

#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
using namespace std;

int main() {
    char S[3];
    cin >> S;

    int a = 0, b = 0;
    for (int i = 0; i < 3; i++) {
        if (S[i] == 'A') a++;
        else b++;
    }

    if (a != 0 && b != 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;

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

       int t=1;
       //cin>>t;
       while(t--)
       {
               int n;
               cin>>n;
               cout<<n*(n+1)/2;
       }
}


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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 100005;

/* ...o(^-^)o... */

int main(){
    int n; cin >> n;
    int m = n + 5; int res = 0;
    rep(i, n){
        int p; cin >> p;
        if(p <= m) res++;
        m = min(m, p);
    }
    cout << res << endl;
}

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

#define ll long long int

using namespace std;

int main() {
    ll d;
    cin >> d;
    vector<ll> C(26);
    for (auto & c : C) cin >> c;
    vector<vector<ll>> S(d, vector<ll>(26));

    for (ll i = 0; i < d; ++i) {
        for (ll j = 0; j < 26; ++j) {
            cin >> S[i][j];
        }
    }

    vector<ll> last(26, 0);

    ll res = 0;
    for (ll i = 0; i < d; ++i) {
        ll p = -1;
        ll m = -1;
        for (ll j = 0; j < 26; ++j) {
            if (m < S[i][j]) {
                m = S[i][j];
                p = j;
            }
        }
        cout << p + 1 << endl;
        res += m;
        ll minus = 0;
        for (ll j = 0; j < 26; ++j) {
            if (j == p) {
                last[p] = 0;
            } else {
                ++last[j];
                minus += C[j] * last[j];
            }
        }
        res -= minus;
    }
    cerr << res << endl;
}


Measured memory_bytes: 3720
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		long a[] = new long[n];
		for(int i=0; i<n; i++) {
			a[i]=sc.nextLong();
		}

		int ans = 0;
		for(int i=0; i<n; i++) {
			ans += f(a[i]);
		}
		System.out.println(ans);
		sc.close();
	}

	private int f(long x) {
		int res = 0;
		while(x%2 == 0) {
			res++;
			x/=2;
		}
		return res;
	}
}


Measured memory_bytes: 32960
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int k,n;
  cin >> k >> n;
  vector<int> a(n),b(n);
  int i;
  for(i=0;i<n;i++) cin >> a[i];
  for(i=0;i<n-1;i++) b[i] = a[i+1]-a[i];
  b[n-1]=a[0]+k-a[n-1];
  int m = *max_element(b.begin(),b.end());
  cout << k-m << "\n";
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
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;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp
struct UnionFind
{
    vector<long long> d;
    UnionFind(long long n = 0) : d(n, -1)
    {
    }

    //root : -size, not root: root
    long long root(long long x){
        if(d[x] < 0){
            return x; 
        }
        return d[x] = root(d[x]);
    }

    bool unite(long long x, long long y){
        x = root(x);
        y = root(y);
        if(x == y){
            return false;
        }
        if(d[x] > d[y]){
            swap(x, y);
        }
        d[x] += d[y];
        d[y] = x;
        return true;
    }

    long long size(long long x){
        return -d[root(x)];
    }

    bool issame(long long a, long long b){
        return root(a) == root(b);
    }
};

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n, q;
    cin >> n >> q;

    UnionFind uf(n);
    rep(i,q){
        ll com;
        cin >> com;

        ll a, b;
        cin >> a >> b;

        if(com == 0){
            uf.unite(a,b);
        }else{
            if(uf.issame(a,b)){
                cout << 1 << endl;
            }else{
                cout << 0 << endl;
            }
        }

    }

}


Measured memory_bytes: 3188
import numpy as np

n, m = [int(i) for i in input().split()]
x = np.array([int(i) for i in input().split()])

res = 0
if n < m:
    x.sort()
    d = np.diff(x)
    d = np.sort(d)[::-1]
    res = max(x) - min(x) - sum(d[:n-1])

print(res)


Measured memory_bytes: 22880
from sys import stdin, stdout
from collections import deque, defaultdict
import math as m

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	n = int(rl())
	P = [0]
	P.extend(list(rlf()))

	dp = [[0 for j in range(n+1)] for i in range(n+1)]
	dp[0][0] = 1
	for c in range(1, n + 1):
		dp[0][c] = dp[0][c-1]*(1 - P[c])

	for r in range(1, n + 1): 
		for c in range(r, n + 1): 
			dp[r][c] = P[c]*dp[r-1][c-1] + (1- P[c])*dp[r][c-1]

	ans = sum(dp[i][n] for i in range(m.ceil(n/2), n + 1))
	print(ans)
	
	stdout.close()

if __name__ == "__main__":
	main()

Measured memory_bytes: 285348
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n, m; cin >> n >> m;
    vector<pair<ll, ll>> key;
    rep(i, m){
        ll a, b, s = 0; cin >> a >> b;
        rep(j, b){
            ll c; cin >> c; c--;
            s |= (1ll<<c);
        }
        key.emplace_back(s, a);
    }

    // bitDP
    vector<ll> dp(1ll<<n, 1ll<<30); dp[0] = 0;
    rep(s, 1ll<<n){
        rep(i, m){
            ll t = s | key[i].first;
            ll cost = dp[s] + key[i].second;
            chmin(dp[t], cost);
        }
    }
    ll ans = dp.back();
    if(ans == 1ll<<30) ans = -1;
    cout << ans << endl;
}

Measured memory_bytes: 3708
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<queue>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()
bool comparator(P a, P b) {
	return a.first / a.second < b.first / b.second;
}


int main() {
	int a;
	cin >> a;
	cout << a + a * a + a * a * a << endl;
	

}

Measured memory_bytes: 3192
import java.util.Scanner;

public class Main {
    /**
     * @param args
     */
    public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);

		String w_str = scanner.next();
		String h_str = scanner.next();
		String x_str = scanner.next();
		String y_str = scanner.next();
		String r_str = scanner.next();

		int w = Integer.parseInt(w_str);
		int h = Integer.parseInt(h_str);
		int x = Integer.parseInt(x_str);
		int y = Integer.parseInt(y_str);
		int r = Integer.parseInt(r_str);

		if((x-r) < 0 || (x+r) > w || (y-r) < 0 || (y+r) > h) {
			System.out.println("No");
		}
		if((x-r) >= 0 && (x+r) <= w && (y-r) >= 0 && (y+r) <= h) {
			System.out.println("Yes");
		}

    	scanner.close();
    }
}


Measured memory_bytes: 26236
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

//nCr mod m
#define MOD 998244353
#define M 2200000
vector<ll> fact;
bool h=false;
void init(){
	h=true;
	fact=vector<ll>(M);
	fact[0]=fact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
}
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
//nCr
ll nCr(ll n,ll r,ll m=MOD){
	if(!h)init();
	if(n<0||r<0||n<r)return 1;//??????
	ll out=fact[n]*powmod(fact[r]*fact[n-r]%m,m-2,m)%m;
	return out;
}
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}


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

	int a,b,c;
	cin>>a>>b>>c;
	int t=min(a,c);
	a-=t;c-=t;
	t=min(b,c);
	b-=t;
	cout<<a<<" "<<b<<endl;
}


Measured memory_bytes: 256
/*
    Problem 46
    https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_10_B
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* class */
class Matrix {
public:
    int r, c;
    Matrix () {}
    Matrix (int r, int c) : r(r), c(c) {}
};
/* global variables */
/* function */
/* main */
int main(){
    int n;
    cin >> n;
    vector<Matrix> M(n, Matrix());
    for (int i = 0; i < n; i++) {
        int r, c;
        cin >> r >> c;
        Matrix m = Matrix(r, c);
        M[i] = m;
    }

    // init dp
    vector<vector<int>> dp(n, vector<int>(n));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            if (i == j) dp[i][j] = 0;
            else dp[i][j] = INF;
    // calc
    // ex) M0 * M1 * M2
    // w=1 , M0*M1, M1*M2
    // w=2 , M0*M1*M2 = min{M0*(M1*M2),  (M0*M1)*M2)}
    //   | 0 | 1 | 2
    // 0 | 0 |w=1|w=2
    // 1 |   | 0 |w=1
    // 2 |   |   | 0
    for (int w = 1; w < n; w++) {  // w+1個の連続したMatrixの積, w個の選択肢
        for (int i = 0; i < n-w; i++) {  // start位置 Mi * Mi+1 * ... * Mi+w
            int j = i + w;  // end位置 Mi * Mi+1 * ... * Mj
            for (int k = i; k < j; k++) {
                int cost = M[i].r * M[k].c * M[j].c;
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + cost);
            }
        }
    }

    cout << dp[0][n-1] << '\n';
}


Measured memory_bytes: 3168
#include "bits/stdc++.h"
using namespace std;

#define sz(x) (int)(x.size())
#define FOR(i,L,R) for(int i = L; i <= R; i++)

const int N = 3e5 + 2;

int n, m, cnt_x[N], cnt_y[N];
set<pair<int,int>> given;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    cin >> n >> m;
    int t;
    cin >> t;
    set<int> xs, ys;
    while(t--) {
        int x, y;
        cin >> x >> y;
        given.insert({x, y});
        cnt_x[x]++;
        cnt_y[y]++;
        xs.insert(x);
        ys.insert(y);
    }
    int maxx = 0, maxy = 0;
    vector<int> whichx, whichy;

    FOR(i,1,N-1) {
        maxx = max(maxx, cnt_x[i]);
        maxy = max(maxy, cnt_y[i]);
    }
    FOR(i,1,N-1) {
        if(cnt_x[i] == maxx) {
            whichx.push_back(i);
        }
        if(cnt_y[i] == maxy) {
            whichy.push_back(i);
        }
    }

    shuffle(whichx.begin(), whichx.end(), rng);
    shuffle(whichy.begin(), whichy.end(), rng);

    for(int x : whichx) for(int y : whichy) {
        bool is = given.count({x, y}) > 0;
        if(!is) {
            cout << maxx + maxy << '\n';
            return 0;
        }
    }
    cout << maxx + maxy - 1;
}


Measured memory_bytes: 50844