akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  vector<long>a(n);
  int i,j;
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  sort(a.begin(),a.end(),greater<long>());
  vector<set<long> >num(n);
  int tmp = 0;
  vector<bool>chk(n,false);
  for(i=0;i<n;i++){
    num[i].insert(a[i]);
    if(a[i]>=k){
      tmp++;
      chk[i] = true;
    }
  }
  long tmppp = 0;
  for(i=tmp;i<n;i++){
    tmppp+=a[i];
  }
  if(tmppp<k)tmp = 99999999;
  long tmppp2 = tmppp;
  for(i=n-1;i>=tmp;i--){
    if(tmppp-a[i]<k)chk[i]=true;
    if(tmppp2-a[i]<k)chk[i]=true;
    else tmppp2-=a[i];
  }
  for(i=tmp;i<n;i++){
    for(j=tmp;j<n;j++){
      if(i != j && !chk[j]){
        set<long>tmpp;
        for(auto kk: num[j]){
          if(kk+a[i]>=k && kk+a[i]-a[j]<k)chk[j]=true;
          else if(kk+a[i]<k)tmpp.insert(kk+a[i]);
        }
        for(auto kk:tmpp)num[j].insert(kk);
      }
    }
  }
  int ans = 0;
  for(i=0;i<n;i++){
    if(chk[i]==false)ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 25856
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REP2(i,x,n) for(ll i=x; i<(n); i++)
#define REP3(i,x,n) for(ll i=x; i>(n); i--)
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    string S,T;
    int cnt=0;
    cin >> S;
    cin >> T;
    for (int i = 0; i < (int)(S.length()); i++)
    {
        if(S[i]!=T[i]){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  for(int i=0; i<N; i++) cin >> h.at(i);
  sort(h.begin(), h.end());
  int ans=1000000001;
  for(int i=0; i<N-K+1; i++){
    ans=min(ans, h.at(i+K-1)-h.at(i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
<?php
fscanf(STDIN, "%d %d", $max, $start);
$cities = trim(fgets(STDIN));
$cities = explode( " ", $cities );

$diff = abs($cities[0]- $start);
for( $i=1; $i<$max; $i++ )
{
  $diff = gcd(abs($cities[$i] - $start), $diff);
}
echo $diff;

function gcd( $diff, $base )
{
  return $diff % $base != 0 ? gcd( $base, $diff%$base ) : $base;
}




Measured memory_bytes: 12792
#include<bits/stdc++.h>
using namespace std;
int a[100010];
int main()
{
	int n;
	scanf("%d",&n);
	int i;
	for(i=0; i<n; i++) scanf("%d",&a[i]);
	int m;
	scanf("%d",&m);
	while(m--)
	{
		int x;
		scanf("%d",&x);
		printf("%d %d\n",lower_bound(a,a+n,x)-a, upper_bound(a,a+n,x)-a);
	}
	return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll x;
  cin>>x;
  if(x%11==0){
    cout<<x/11*2<<endl;
  }else if(x%11<7){
    cout<<x/11*2+1<<endl;
  }else{
    cout<<x/11*2+2<<endl;
  }
}

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

#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(a) (a).begin(),(a).end()
#define INIT(a) memset(a,0,sizeof(a))

#define fs first
#define sc second
#define pb push_back
#define sz size()

using namespace std;

const int MAX_N = 110;
const int INF = 1e8;

int level[MAX_N], iter[MAX_N];

vector<int> g[MAX_N], rg[MAX_N];
vector<int> sccg[MAX_N], sccv[MAX_N];
vector<int> vs;
bool use[MAX_N];
int ord[MAX_N];

int n,m,s;
int v[MAX_N], w[MAX_N], k[MAX_N];

void fdfs(int x){
  use[x] = true;
  rep(i,g[x].sz){
    if(!use[g[x][i]])fdfs(g[x][i]);
  }
  vs.pb(x);
}

void rdfs(int x,int id){
  use[x] = true;
  ord[x] = id;
  rep(i,rg[x].sz){
    if(!use[rg[x][i]])rdfs(rg[x][i],id);
  }
}

int scc(){
  INIT(use);
  vs.clear();
  rep(i,n){
    if(!use[i])fdfs(i);
  }

  INIT(use);
  int id = 0;
  rrep(i,vs.sz){
    if(!use[vs[i]])rdfs(vs[i],id++);
  }
  return id;
}


int main(){
  while(cin >> n >> m >> s){
    if(n==0 && m==0 && s==0)break;
    rep(i,n){
      g[i].clear(); rg[i].clear();
      sccg[i].clear(); sccv[i].clear();
    }

    rep(i,n)cin >> v[i] >> w[i] >> k[i];
    rep(i,m){
      int a,b;
      cin >> a >> b; a--; b--;
      g[a].pb(b); rg[b].pb(a);
    }

    int sccn = scc();

    rep(i,n)sccv[ord[i]].pb(i);
    rep(i,sccn){
      for(int j : sccv[i]){
	for(int u : g[j]){
	  if(i != ord[u])sccg[i].pb(ord[u]);
	}
      }
      sort(all(sccg[i]));
      sccg[i].erase(unique(all(sccg[i])),sccg[i].end());
    }

    vector<int> self(sccn,0);
    rep(i,sccn){
      if(sccv[i].sz==1){
	int u = sccv[i][0];
	for(int to : g[u]){
	  if(u == to)self[i] = 1;
	}
      }
    }

    //TODO: self-loop
    vector< vector<int> > dp(sccn, vector<int>(s+1, 0));
    vector<int> deq(s+1), deqv(s+1);

    rep(i,sccn){
      if(sccv[i].sz > 1 || self[i]){
	for(int u : sccv[i]){
	  for(int a=0;a<w[u];a++){
	    int l = 0, r = 0;
	    for(int j=0;j*w[u]+a<=s;j++){
	      int val = dp[i][j*w[u]+a] - j * v[u];
	      while(l < r && deqv[r-1] <= val)r--;
	      deq[r] = j;
	      deqv[r++] = val;
	      dp[i][j*w[u]+a] = deqv[l] + j*v[u];
	      if(deq[l] == j-k[u])l++;
	    }
	  }
	}
      }else{
	int u = sccv[i][0];
	rrep(j,s-w[u]+1){
	  dp[i][j+w[u]] = max(dp[i][j+w[u]], dp[i][j] + v[u]);
	}
      }
      
      for(int u : sccg[i]){
	rep(j,s+1)dp[u][j] = max(dp[u][j], dp[i][j]);
      }
    }

    int res = 0;
    rep(i,sccn)rep(j,s+1)res = max(res, dp[i][j]);
    cout << res << endl;
  }
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> a(1<<n);
    for(int i=0;i<(1<<n);i++) cin>>a[i];
    vector<vector<pair<int,int>>> dp(1<<n);
    for(int i=0;i<(1<<n);i++){
        dp[i].push_back(make_pair(a[i],i));
    }
    auto merge=[](vector<pair<int,int>> lhs,vector<pair<int,int>> rhs){
        vector<pair<int,int>> vec;
        for(auto &e:lhs) vec.push_back(e);
        for(auto &e:rhs) vec.push_back(e);
        sort(vec.begin(),vec.end(),greater<pair<int,int>>());
        unique(vec.begin(),vec.end());
        vec.resize(2);
        return vec;
    };
    for(int i=0;i<(1<<n);i++){
        for(int j=0;j<n;j++){
            int to=i|(1<<j);
            if(to!=i){
                dp[to]=merge(dp[to],dp[i]);
                assert(dp[to].size()==2);
            }
        }
    }
    int res=0;
    for(int i=1;i<(1<<n);i++){
        res=max(res,dp[i][0].first+dp[i][1].first);
        cout<<res<<"\n";
    }
    return 0;
}


Measured memory_bytes: 22656
import itertools

n = int(input())

MARCH = [0]*5
for _ in range(n):
    s = input()
    if s[0] == "M":
        MARCH[0] += 1
    elif s[0] == "A":
        MARCH[1] += 1
    elif s[0] == "R":
        MARCH[2] += 1
    elif s[0] == "C":
        MARCH[3] += 1
    elif s[0] == "H":
        MARCH[4] += 1

ans = 0
for l in itertools.combinations(MARCH,3):
    ans += l[0]*l[1]*l[2]

print(ans)

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline

def pop_ind(ind, n):
    for i in range(n):
        A[i].remove(ind)

def count(m):
    counter = [0] * (m+1)
    ind = -1
    max_cnt = 0
    for i in range(N):
        counter[A[i][0]] += 1
        if counter[A[i][0]] > max_cnt:
            max_cnt = counter[A[i][0]]
            ind = A[i][0]
    return ind, max_cnt

N, M = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
ans = float('inf')
for _ in range(M):
    ind, tmp = count(M)
    pop_ind(ind, N)
    ans = min(ans, tmp)
print(ans)

Measured memory_bytes: 4284
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[][] suki = new int[n][m];
    for(int i = 0; i < n; i++) {
      int k = sc.nextInt();
      for(int j = 0; j < k; j++) {
        int r = sc.nextInt() - 1;
        suki[i][r]++;  
      }
    }
    int ans = 0;
    for(int j = 0; j < m; j++) {
      int p = 1;
      for(int i = 0; i < n; i++) {
        if(suki[i][j] == 0) p = 0;
      }
      if(p == 1) ans++; 
    }
    System.out.println(ans);
  }
}

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

int main() {
	int n; cin >> n;
	string s; cin >> s;
	int x = 0;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'I') {
			x++;
		}
		else {
			x--;
		}
		ans = max(x, ans);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n+1];
        Map<Integer, Integer> m = new HashMap<>();
        for(int i=2; i<=n; i++) {
            a[i] = in.nextInt();
            if(m.containsKey(a[i])) {
                m.put(a[i], m.get(a[i])+1);
            }
            else {
                m.put(a[i], 1);
            }
        }
        for(int i=1; i<=n; i++) {
            int c = 0;
            if(m.containsKey(i)) {
                c = m.get(i);
            }
            System.out.println(c);
        }
    }
}


Measured memory_bytes: 74868
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pie acos(-1)
#define loop(i,a,n) for(int i=a;i<n;i++)
#define trav(a,x) for(auto &a:x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define endl "\n"
#define all(v) v.begin(),v.end()
#define w 100005

template < typename T >void max_self(T&a,T b)
{
    a=max(a,b);
}
bool end(pair<int,pair<int,int>>p)
{
    return p.ss.ff==0 || p.ss.ss==0;
}
void solve()
{
    string s,t;
    cin>>s>>t;
    int n = s.size();
    int m = t.size();
    vector<vector<pair<int,pair<int,int>>>>dp(n+1,vector<pair<int,pair<int,int>>>(m+1,{0,{0,0}}));
    for(int i = 0 ; i<n ;i++)
    {
        for(int j=0 ; j<m ; j++)
        {
            if(s[i]==t[j])
            max_self(dp[i+1][j+1],mp(dp[i][j].ff+1,mp(i,j)));
            max_self(dp[i][j+1],mp(dp[i][j].ff,mp(i,j)));
            max_self(dp[i+1][j],mp(dp[i][j].ff,mp(i,j)));
           
        }
    }
    pair<int,pair<int,int>>answer,curr,prev;
    answer={0,{0,0}};
    for(int i =0 ;i<=n;i ++)
    {
        for(int j=0; j<=m;j++)
        {
            max_self(answer,mp(dp[i][j].ff,mp(i,j)));
        }
    }
    string fin;
    curr=answer;
    while(!end(curr))
    {
        if(curr.ff==0)
            break;
        int i = curr.ss.ff;
        int j = curr.ss.ss;
        prev = dp[i][j] ;
        if( prev.ss==mp(i-1,j-1) )
        fin+=s[i-1];
        curr=prev;
    }
    reverse(fin.begin(),fin.end());
    cout<<fin;//answer.ff<<" "<<answer.ss.ff<<" "<<answer.ss.ss;
    
}
int main() {
	// your code goes here
	io;
    solve();
	return 0;
}


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

int main() {
  int a, b, c, d;
  int n;
  while (cin >> n) {
    int ans = 0;
    for (int a = 0; a <= 9; a++) {
      for (int b = 0; b <= 9; b++) {
        for (int c = 0; c <= 9; c++) {
          int tmp = n - (a + b + c);
          for (int d = 0; d <= 9; d++) {
            if (tmp == d) {
              ans++;
            }
          }
        }
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 3080
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline--------------------------------------------
    n = int(input())
    a = list(map(int,input().split()))
    r = 0
    pinf = 0
    ans = 0
    for l in range(n):
        while r < n and pinf ^ a[r] == pinf + a[r]:
            pinf += a[r]
            r += 1
        ans += r-l
        if l == r:
            r += 1
        else:
            pinf -= a[l]
    
    print(ans)


if __name__ == "__main__":
    main() #endline===============================================
    

Measured memory_bytes: 27144
import sys
sys.setrecursionlimit(10 ** 7)

n, k = map(int, input().split())
s = input()

scomp = []

cnt = 1
for i in range(n-1):
    if s[i] == s[i+1]:
        cnt += 1
    else:
        scomp.append(cnt)
        cnt = 1
scomp.append(cnt)


lens = len(scomp)
ans = 0

start = 0
if s[0] == '0':
    start = 1
    end = min(k*2,lens)
    tmp = sum(scomp[:end])
    ans = max(ans,tmp)

end = min(start + k*2+1,lens)
tmp = sum(scomp[start:end])
ans = max(ans,tmp)
for i in range(start,lens-k*2-2,2):
    tmp -= scomp[i]
    tmp -= scomp[i+1]
    tmp += scomp[i+k*2+1]
    tmp += scomp[i+k*2+2]
    ans = max(ans,tmp)

if s[-1] == '0':
    start = max(lens-k*2,0)
    tmp = sum(scomp[start:])
    ans = max(ans,tmp)

print(ans)



Measured memory_bytes: 45808
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define int long long

int n, a[100100], dp[100100];
vector <int> v;
int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; ++i) cin >> a[i];
	for(int i = 1; i < n; ++i) {
		if (a[i-1] >= a[i]) dp[i] = dp[i-1]+1;
		else dp[i] = 0;
	}
	cout << *max_element(dp, dp+n);
}

Measured memory_bytes: 5232
#include<iostream>

using namespace std;

bool seica[8000000];

int main(){

  int n,m,i,j,cou;
  while(1){
    cin >> m >> n;
    if(n == 0 && m == 0)break;
    for(i = 0;i < 8000000;i++)seica[i] = false;
    cou = 0;

    for(i = m;i < 8000000;i++){
      if(seica[i] == false){
	for(j = i;j < 8000000;j += i){
	  seica[j] = true;
	}
	cou++;
	//cout << "!" << i << endl;
	if(cou == n + 1)break;
      }
    }
    cout << i << endl;
  }
  return 0;
}



Measured memory_bytes: 10872
n = int(raw_input())
for i in range(n):
    entry = map(int, raw_input().strip().split(' '))
    u = entry[0]
    k = entry[1]
    neighbors = set(entry[2:])
    for j in range(1,n+1):
        if j in neighbors:
            print 1,
        else:
            print 0,
    print

Measured memory_bytes: 6444
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };




int main()
{
	int w, h;
	while (cin >> w >> h, w | h)
	{
		char f[64][64];
		CLEAR(f, '@');
		for (int i = 1; i <= h; ++i)
		{
			cin >> f[i] + 1;
			f[i][w + 1] = '@';
		}

		int white, black;
		white = black = 0;
		for (int y = 1; y <= h; ++y)
		{
			for (int x = 1; x <= w; ++x)
			{
				if (f[y][x] == '.')
				{
					int area = 0;
					bool ww, bb;
					ww = bb = false;
					queue<pint> q;
					q.push(pint(x, y));
					while (!q.empty())
					{
						pint t = q.front(); q.pop();
						int x = t.first, y = t.second;
						if (f[y][x] == 'W')
							ww = true;
						else if (f[y][x] == 'B')
							bb = true;
						else if (f[y][x] == '.')
						{
							f[y][x] = '@';
							++area;
							rep (i, 4)
								q.push(pint(x + dx[i], y + dy[i]));
						}
					}

					if (ww && !bb)
						white += area;
					else if (!ww && bb)
						black += area;
				}
			}
		}
		cout << black << " " << white << endl;
	}
}

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

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define MOD 1000000007

string S;
int rec,ans;
int main(){
  cin >> S;
  for(int i = 0;i < S.size();i++){
    ans = 0;
    for(int j = i;j < S.size();j++){
      if(S[j]!='A'&&S[j]!='G'&&S[j]!='C'&&S[j]!='T'){
        break;
      }
      ans++;
    }
    rec = max(ans,rec);
  }
  cout << rec <<endl;
  return 0;
}


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

#define ll              long long int
#define pb              push_back
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define fast_io         ios_base::sync_with_stdio(false); cin.tie(NULL);


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

    vector<ll> v(n);
    vector<ll> cumSum(n+1);
    cumSum[0] = 0;

    for(ll i=0; i<n; i++){
    	cin >> v[i];
    	cumSum[i+1] = v[i] + cumSum[i];
    }

    vector<vector<ll>> dp(3002, vector<ll>(3002, 0));

    // lenght dp
    ll i,j;

    
    for(ll k=0; k<n; k++){
    	i = 0;
    	j = k;

    	while(i<n and j<n){
    		if(i == j){
    			dp[i][j] = v[i];
    			i++;
    			j++;
    			continue;
    		}
    		else{
    			dp[i][j] = v[i] + cumSum[j+1] - cumSum[i+1] - dp[i+1][j];
	    		dp[i][j] = max(dp[i][j], v[j] + cumSum[j] - cumSum[i] - dp[i][j-1]);

	    		i++;
	    		j++;
    		}    		
    	}
    }
    
    ll ans = dp[0][n-1] - (cumSum[n] - dp[0][n-1]);

    cout<<ans<<"\n";
    
	return 0;
}

Measured memory_bytes: 70912
import java.util.Scanner;

public class Main {

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

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

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println(lcm(a, b));
    }

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define all(v) v.begin(),v.end()

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }

class Solver {
  public:
    pii go(const vector<vector<int>> &E) {
        int N = E.size();
        vector<int> visited(N);
        auto find_non_leaf = [&] (int now) {
            for(int nxt : E[now]) if(E[nxt].size() > 1 and not visited[nxt]) return nxt;
            return -1;
        };
        function<int(int)> walk = [&] (int now) {
            visited[now] = true;
            int nxt = find_non_leaf(now);
            if(nxt >= 0) {
                return walk(nxt);
            }
            return now;
        };
        int parent = -1;
        rep(i, N) if(E[i].size() > 1) {
            parent = i;
            break;
        }
        assert(parent >= 0);
        int side1 = walk(parent);
        int side2 = walk(parent);
        rep(i, N) if(E[i].size() > 1 and not visited[i]) return pii(-1, -1);
        return make_pair(side1, side2);
    }
    vector<int> build(const vector<vector<int>> &E, pii sides) {
        int now = sides.first;
        vector<int> ans = {1};
        int upper = 2;
        int prev = -1;
        while(true) {
            int num = E[now].size() - 2;
            for(int i = upper + 1; i <= upper + num; i++) ans.push_back(i);
            ans.push_back(upper);
            upper = upper + num + 1;
            if(now == sides.second) break;
            for(int nxt : E[now]) {
                if(E[nxt].size() > 1 and nxt != prev) {
                    prev = now;
                    now = nxt;
                    break;
                }
            }
        }
        ans.push_back(upper);
        return ans;
    }
    bool solve() {
        int N; cin >> N;
        vector<vector<int>> E(N);
        rep(i, N - 1) {
            int a, b; cin >> a >> b;
            E[a - 1].push_back(b - 1);
            E[b - 1].push_back(a - 1);
        }
        pii sides = go(E);
        if(sides == pii(-1, -1)) {
            cout << -1 << endl;
            return 0;
        }

        auto ans = build(E, sides);
        swap(sides.first, sides.second);
        set_min(ans, build(E, sides));
        rep(i, ans.size()) cout << ans[i] << (i == ans.size() - 1 ? "\n" : " ");

        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 8816
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, _s, n) for(int i = _s, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;

#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;

int main() {
  int H, N;
  cin >> H >> N;
  int sum = 0;
  REP(i, N) {
    int A;
    cin >> A;
    sum += A;
  }
  if(sum >= H) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);

		int[] x = new int[10];

		for(int i =0; i < x.length; i++ ) {


			x[i] = stdin.nextInt();

		}

		int n = 0;
		n = 10;
		int buble =n*(n-1)/2;
		for(int i = 0; i < buble; i++){

		    for(int j = 0; j < n - 1; j++){

		    	if(x[j] < x[j + 1]) {

		    		int temp = x[j];
		    		x[j] = x[j + 1];
		    		x[j + 1] = temp;

		    	}

		    }

	   }

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

			System.out.println(x[i]);

		}

	}


}

Measured memory_bytes: 26356
n, m = [int(i) for i in input().split()]

A = []
b = []

for i in range(n):
    x = [int(j) for j in input().split()]
    A.append(x)

for i in range(m):
    b.append(int(input()))

c = []
for i in range(n):
    sum = 0
    for j in range(m):
        sum += (A[i][j] * b[j])
    c.append(sum)

for i in range(n):
    print(c[i])

Measured memory_bytes: 8156
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
   int x,a,b,c,d;
   scanf("%d%d%d",&x,&a,&b);
   if(x>a)
    c=x-a;
   else
    c=a-x;
   if(x>b)
    d=x-b;
   else
    d=b-x;
   if(c<=d)
    printf("A\n");
  else
    printf("B\n");
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template<typename T> void print(const T & v);


int main() {
    int N;
    cin >> N;
    vector<int> A(N, 0);
    vector<int> SUM(N, 0);
    for(int i = 1; i < N; i++){
        cin >> A[i];
        A[i]--;
    }

    for(int i = N - 1; i >= 1; i--){
        SUM[A[i]] += 1;
    }

    for(int i = 0; i < N; i++){
        cout << SUM[i] << endl;
    }
    return 0;


}






// Use For Debug
template <typename T>
void print(T const & v){
    for(int i = 0; i < v.size(); i++){
        if(i) cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 4764
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  
  bool yn=false;
  
  for(int i=1;i<=9;i++){
    bool fin=false;
    for(int j=1;j<=9;j++){
      if(i*j==N){
        yn=true;
        fin=true;
        break;
      }
    }
    if(fin==true)break;
  }
  
  if(yn==true)cout << "Yes" << endl;
  else cout << "No" <<endl;
}
        

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
#define S set<int>
#define itn int
bool dbg = false;
int X, Y;

//Template by yosupo
template <uint MD>
struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(_v % MD + MD); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(ull(v) * r.v % MD); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1)
                r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<MOD>;

//Template by yosupo
const int MN = 1'000'000;
Mint fact[MN], iFac[MN];

void first() {
    fact[0] = Mint(1);
    for (int i = 1; i < MN; i++)
        fact[i] = fact[i - 1] * Mint(i);
    iFac[MN - 1] = fact[MN - 1].inv();
    for (int i = MN - 1; i >= 1; i--) {
        iFac[i - 1] = iFac[i] * Mint(i);
    }
    assert(fact[2345] * iFac[2345] == Mint(1));
}
Mint C(int n, int k) {
    if (n < k || k < 0)
        return Mint(0);
    return fact[n] * iFac[k] * iFac[n - k];
}

void solve() {
    first();
    Mint ans = 0;
    if ((X + Y) % 3 == 0 && (X <= 2 * Y) && Y <= 2 * X) {
        int n, k;
        n = (X + Y) / 3;
        k = X - n;
        ans = C(n, k);
    }


    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> X >> Y;
    solve();
    return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define rep(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define ffor(i,a,b) for(int i = a ; i <= b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
const int N = 1e6;
typedef pair <int, int> pi;
typedef std::vector<int> vi;
typedef std::vector<long long> VI;

/*bool isprime(int a) {
	if (a < 2) return false;
	for (int i = 2; i * i <= a; i++) {
		if (a % i == 0)
			return false;  // 0(n) or 0(n^2) Tell me in the comment section
	}
	return true;
}*/



int main() {
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	fastIO
	int k, max = 1e6;
	cin >> k;
	int n = 0;
	if (!(k%2)) {
		cout << "-1";
		return 0;
	}
	for (int i = 0; i < max; i++) {
		n = (n * 10 + 7) % k; // here we are doing this because it should be mul of k
		if (n == 0) {
			cout << i+1;
			return 0;
		}
	}
	if (n) {
		cout << -1;
	}
	return 0;
}
//  this symbol denotes comment  ha ha ha jokes a part

Measured memory_bytes: 3640
#include "stdio.h"

int executePartition(int matrix[], int p, int r){
  int standard;
  standard = matrix[r];

  int i;
  i = p-1;
  int j; 
  int temp;

  for(j=0;j<r;j++){
    if(matrix[j] <= standard){
      i = i + 1;
      temp = matrix[i];
      matrix[i] = matrix[j];
      matrix[j] = temp;
    }
  }
  temp = matrix[i+1];
  matrix[i+1] = matrix[r];    
  matrix[r] = temp;    

  return i+1;

}

void outputMatrixWithDecorator(int matrix[], int N, int i_deco){
  for(int i=0;i<N;i++){
    if(i == i_deco){
     if(i>0){
      printf(" ");
    }
     printf("[");
     printf("%d", matrix[i]);
     printf("]");
    }else{
     if(i>0){
      printf(" ");
    }
     printf("%d", matrix[i]);
    }
  }
  printf("\n");
}


int main(void){

  int N;
  scanf("%d", &N);

  int* matrix = new int [N];
  
  for(int i=0;i<N;i++){
    scanf("%d", &matrix[i]);
  }

  int i_standard;
  i_standard = executePartition(matrix, 0, N-1);
  outputMatrixWithDecorator(matrix, N, i_standard);
  
  delete [] matrix;

  return 0;
}


Measured memory_bytes: 2804
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる





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

  int ans=0;
  int x;

  rep(i,n){
    cin>>x;
    ans+=2*min(x,k-x);
  }


  cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 15, 21, 24, 27, 20, 28, 32, 36,
     15, 25, 30, 35, 40, 45, 36, 42, 48, 54, 49, 56, 63, 64, 72, 81]

if N in L:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
N = int(input())
A = [int(x) for x in input().split()]

n = sum(1 for a in A if a <  0)
z = sum(1 for a in A if a == 0)

s = sum(abs(a) for a in A)

if n % 2 == 0 or z >= 1:
    print(s)
else:
    x = min(abs(a) for a in A)
    print(s - 2 * x)


Measured memory_bytes: 14412
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

string s, t;
int x;

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

    for(int i = 0; i < 3; i++){
        if(s[i] == t[i]){
            x++;
        }
    }
    cout << x;



}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  vector<int>s(M);
  vector<int>c(M);
  cin >> N >>M;
  for(int i=0; i<M;i++){
  cin >>s.at(i) >>c.at(i);
  }
  int error =0; //error=１なら数字が書けないとしよう

  for(int i=0; i<M;i++){
    if(s.at(i)==1&&c.at(i)==0 && N!=1){error=1;}
  		for(int j=0; j<i;j++){
    		if(s.at(i)==s.at(j) &&c.at(i)!=c.at(j)){error=1;}   	
    	}
  }
   vector<int>ans(5);
  if(N!=1){ans.at(0)=1;}
  
    if(error==0){
      for(int i=0; i<M;i++){
        ans.at(s.at(i)-1)=c.at(i);
        
      }
    
 	  for(int i=0; i<N;i++){
       cout <<ans.at(i); 
      }
    }
  	else{cout <<-1;}
  cout << endl;
}

 

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

int main()
{
	int a, b, x, c;

	cin >> a >> b >> c >> x;

	int count = 0;
	for (int i = 0; i <= a; i++)
	{
		for (int j = 0; j <= b; j++)
		{
			for (int k = 0; k <= c; k++)
			{
				if (500 * i + 100 * j + 50 * k == x)
				{
					count++;
				}
			}
		}
	}

	cout << count << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int ans = 0;
		if (B%A==0) {
			ans = A+B;
		} else {
			ans = B-A;
		}
		System.out.println(ans);
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 20948
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int left = sc.nextInt() + sc.nextInt();
        int right = sc.nextInt() + sc.nextInt();
        if(left > right){
            System.out.println("Left");
        }else if(left < right){
            System.out.println("Right");
        }else{
            System.out.println("Balanced");
        }
    }
}


class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 23124
import math
import collections

Mod = 1000000007
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
def COMinit():
    for i in range(2, N+111):
        fac.append(fac[-1]*i%Mod)
        inv.append((-inv[Mod%i] * (Mod//i)) % Mod)
        finv.append(finv[-1] * inv[-1] % Mod)
    

def COM(n, k):
    if n < 0 or k < 0 or n < k:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % Mod) % Mod

N, M = map(int, input().split())
prime_count = collections.Counter()
for i in range(2, math.ceil(math.sqrt(M))+1):
    while M % i == 0:
        M /= i
        prime_count[i] += 1
if M > 1:
    prime_count[M] += 1

ans = 1
COMinit()
for i, b in prime_count.items():
    tmp = COM(b+N-1, N-1)
    ans = (ans * tmp) % Mod 
print(ans)


Measured memory_bytes: 58096
#include<stdio.h>

int main() {
   
   int x,i=0;
   
   for (i=0; i<10000; i++) {
      scanf("%d\n",&x);
      if (x==0) {
         break;
      }
      printf("Case %d: %d\n",i+1,x);
   }

   return 0;
} 

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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

signed main()
{
    int x, a;
    cin >> x >> a;

    if (x < a)
        cout << 0 << endl;
    else
        cout << 10 << endl;
}

Measured memory_bytes: 764
import itertools
import math
N = int(input())
ls = []
ans = 0
for i in range(N):
  x,y = map(int,input().split())
  ls.append([x,y])
ls2 = []
for i in itertools.permutations(ls,N):
  ls2.append(list(i))
for i in range(math.factorial(N)):
  ls3 = ls2[i]
  now_x = ls3[0][0]
  now_y = ls3[0][1]
  for j in range(1,N):
    ans += ((now_x - ls3[j][0])**2 + (now_y - ls3[j][1]) ** 2)**0.5
    now_x = ls3[j][0]
    now_y = ls3[j][1]
print(ans/math.factorial(N))

Measured memory_bytes: 14684
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007;
vector<vector<double>>dp; // dp(i,j) probablity of coming j heads when i coins
vector<double>p;

double probhead(int n,int heads){

        if(dp[n][heads]!=-1){
            return dp[n][heads];
        }
        return dp[n][heads] = probhead(n-1,heads)*(1-p[n]) + probhead(n-1,heads-1)*p[n];

}
void solve(){
    int n;cin>>n;
    dp.resize(n+1,vector<double>(n+1,-1));
    p.resize(n+1);
    for(int i=1;i<=n;i++){
        cin>>p[i];
    }
    for(int i=0;i<=n;i++){
        dp[0][i]=0;
    }
    dp[0][0]=1;
    for(int i=1;i<=n;i++){
        dp[i][0] = dp[i-1][0]*(1-p[i]);
    }

    double pr =0;
    for(int i=(n+1)/2;i<=n;i++){
          pr += probhead(n,i);
    }
    cout<<pr<<"\n";

}

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

    cout.precision(10);
    int t=1;//cin>>t;
    while(t--){

        solve();
    }
    return 0;
}


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Graph;
const int MOD = 1e9 + 7;
const ll INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

long long fac[MAX_N], finv[MAX_N], inv[MAX_N];
// テーブルを作る前処理 from: https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX_N; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct mint {
    // Preparation: MOD is already defined.
    ll value;

    mint(ll value = 0) : value((value % MOD + MOD) % MOD) {}

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint pow(mint m) const {
        return pow(m.value);
    }

    mint inv() const {
        ll a = value, b = MOD, u = 1, v = 0;
        while (b) {
            ll t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        u %= MOD;
        return u;
    }

    mint &operator+=(const mint a) {
        if ((value += a.value) >= MOD) value -= MOD;
        return *this;
    }
    mint &operator-=(const mint a) {
        if ((value += MOD - a.value) >= MOD) value -= MOD;
        return *this;
    }
    mint &operator*=(const mint a) {
        (value *= a.value) %= MOD;
        return *this;
    }
    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

int main() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    COMinit();
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end(), greater<ll>());
    mint sum = 0;
    rep(i, n - k + 1) {
        mint diff = COM(n - i, k) - COM(n - i - 1, k);
        mint ma = (diff * a[i]);
        mint mi = (diff * a[n - i - 1]);
        sum += ma;
        sum -= mi;
    }
    out(sum.value);
    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int n,a,b,c[2050][2050],d[2050][2050],M=1e9+7;
void Init()
{
	for(int i=1;i<=2010;i++)
	{
		c[i][0]=c[i][i]=1;
		for(int j=1;j<i;j++)
		{
			c[i][j]=(c[i-1][j]+c[i-1][j-1])%M;
		}
	}
	for(int i=0;i<=2010;i++)d[0][i]=1;
	for(int i=1;i<=2010;i++)
		for(int j=1;j<=2010;j++)d[i][j]=(d[i][j-1]+d[i-1][j])%M;
}
int main()
{
	Init();
	cin>>n>>a;
	b=n-a+1;
	for(int i=1;i<=a;i++)
	{
		if(i>b)printf("0\n");
		else printf("%lld\n",1ll*c[b][i]*d[a-i][i]%M);
	}
}

Measured memory_bytes: 33024
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
using namespace std;
int n,k;
bool flag;
bool f[150000];
int s[200000];
int t=0;
int ans;
int m;

void work(int n,int k)
{
    memset(f,0,sizeof(f));
    memset(s,0,sizeof(s));
    t=0;
    m=0;
    flag=0;
    int x;
    for (int i=0; i<k; ++i)
    {
        scanf("%d",&x);
        if (x==0) flag=1;
        else f[x]=1;
    }
    ans=0;
    int i;
    for (i=1; i<=n+1; ++i)
    {
        if (f[i]) ans+=1;
        else 
        {
            s[t++]=ans;
            ans=0;
        }
    }
    if (flag==0)
    {
        for (int i=0; i<t; ++i)
            if (s[i]>m)
                m=s[i];
        cout<<m<<endl;
    }else
    {
        m=s[0];
        if (s[0]<n) m+=1;
        for (int i=1; i<t; ++i)
        {
            if (s[i]+s[i-1]+1>m)
                m=s[i]+s[i-1]+1;
        }
        cout<<m<<endl;
    }
}

int main()
{
    while (1)
    {
        cin>>n>>k;
        if (n==0 && k==0)
            break;
        work(n,k);
    }

    return 0;
}




Measured memory_bytes: 4080
#include<stdio.h>

int main(void){
	int a, b ,c ,n;
	scanf("%d %d %d",&a ,&b ,&c);
	if(a > b){
		n = a;
		a = b;
		b = n;
	}
	if(b > c){
		n = b;
		b = c;
		c = n;
	}
	if(a > b){
		n = a;
		a = b;
		b = n;
	}
	printf("%d %d %d\n",a ,b ,c);
	return 0;
}

Measured memory_bytes: 596
#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	R1, R2 = getlist()
	ans = R1 * R2 / (R1 + R2)
	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 3316