akhauriyash/Code-Regression huggingface dataset:
// I - Coins
#include <bits/stdc++.h>
using namespace std;
using vr = vector<double>;

int main(){
	int N; cin>>N;
	int CMAX = (N+1)/2;//ceil

	vr P(N+1); for(int i=1; i<=N; i++) cin>>P[i];

	vr dp(N+1, 1.);
	dp[0] = 1.;
	for(int i=1; i<=N; i++) dp[i] = dp[i-1] * P[i];

	for(int i=1; i<=N; i++){
		dp[0] *= 1.-P[i];
		for(int j=1; j<=N-i; j++){
			int lv = j+i;
			double f = P[lv], b = 1.-f;
			dp[j] = b*dp[j] + f*dp[j-1];
		}
	}

	double ans = 0;
	for(int i=N; i>=1; i--) if(i>=CMAX) ans += dp[i];
	printf("%.10g\n",ans);
}

Measured memory_bytes: 256
<?php
$stdin = trim(fgets(STDIN));
(int)$input = explode(" ", $stdin);

$w = $input[0];
$h = $input[1];
$x = $input[2];
$y = $input[3];
$r = $input[4];

if($w - $x - $r >= 0 && $h - $y - $r >= 0 && !(($x <= 0) || ($y <= 0))) echo 'Yes';
else echo 'No';
?>

Measured memory_bytes: 9232
def Tap_Dance_abc141():    
    s = input()

    odd_list = [] # 奇数
    even_list = [] # 偶数

    for i in range(len(s)):
        if (i + 1) % 2 == 0:
            even_list.append(s[i])
        else:
            odd_list.append(s[i])

    if 'L' not in odd_list and 'R' not in even_list:
        print('Yes')
    else:
        print('No')
        
if __name__ == '__main__':
    Tap_Dance_abc141()

Measured memory_bytes: 3060
#include<stdio.h>
#include<algorithm>
using namespace std;
long long c[110000];
long long d[110000];
 
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%lld",c+i);
	for(int i=0;i<b;i++)scanf("%lld",d+i);
	std::sort(c,c+a);
	std::sort(d,d+b);
	long long ret=0;
	int H=a;
	int W=b;
	int ai=0;
	int bi=0;
	for(int i=0;i<a+b;i++){
		if(ai<a&&(bi==b||c[ai]<d[bi])){
			ret+=(c[ai]*(b+1-bi));
			ai++;
		}else{
			ret+=(d[bi]*(a+1-ai));
			bi++;
		}
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 1792
import numpy as np

E, H = list(map(int, input().split()))
A = np.array(list(map(int, input().split())))

if H>=E:
  print("0")
else:
  A = np.sort(A)
  if H>0:
    Ans = A[:-H].sum()
  else:
    Ans = A[:].sum()
  print(Ans)

Measured memory_bytes: 34212
package main

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

func main() {
	io := newIo()
	defer io.flush()

	n := io.nextInt()
	cnt := 0

	for range make([]struct{}, n) {
		a := io.nextInt()
		for a%2 == 0 {
			cnt++
			a /= 2
		}
	}
	io.println(cnt)
}

type io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func newIo() *io {
	return &io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *io) flush() {
	_ = io.writer.Flush()
}

func (io *io) nextLine() string {
	var buffer []byte
	for {
		line, isPrefix, _ := io.reader.ReadLine()
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *io) nextWord() string {
	for io.nextToken >= len(io.tokens) {
		line := io.nextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *io) nextInt() int {
	i, _ := strconv.Atoi(io.nextWord())
	return i
}

func (io *io) print(a ...interface{}) {
	fmt.Fprint(io.writer, a...)
}

func (io *io) println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *io) printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}


Measured memory_bytes: 1408
function main()
	N=parse(Int,readline())
	A=map(x->parse(Int,x),split(readline()))
	ans=0
	M=Dict{Int,Int}()
	for i=1:N
		ans+=get(M,i-A[i],0)
		M[i+A[i]]=get(M,i+A[i],0)+1
	end
	println(ans)
end
main()


Measured memory_bytes: 198768
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

int W, H;
vector<string> bs;

void dfs(int y, int x) {
	bs[y][x] = '0';

	for (int dy = -1; dy <= 1; dy++) {
		for (int dx = -1; dx <= 1; dx++) {
			if (!(!dx ^ !dy)) continue;

			int nx = x, ny = y;

			for (int i = 0; i < 3; i++) {
				nx += dx;
				ny += dy;

				if (nx < 0 || ny < 0 || nx >= W || ny >= H) break;

				if (bs[ny][nx] == '1') {
					dfs(ny, nx);
				}
			}
		}
	}
}

int main(void) {
	int N;
	cin >> N;
	W = H = 8;

	for (int i = 0; i < N; i++) {
		bs = vector<string>(H);

		for (int y = 0; y < H; y++) {
			cin >> bs[y];
		}

		int tx, ty;
		cin >> tx >> ty;

		dfs(ty - 1, tx - 1);

		// dump
		cout << "Data " << (i + 1) << ":" << endl;
		for (int y = 0; y < H; y++){
			cout << bs[y] << endl;
		}

	}
	

	return 0;
}

Measured memory_bytes: 1212
/*GOD     IS    GREAT,
  SO    AM    I*/
#include<bits/stdc++.h>
#include<numeric>
using namespace std;
#define ll long long int
#define ford(i,a,n) for(long long int i=a;i<n;++i)
#define fore(i,a,n) for(long long int i=a;i<=n;i++)
#define foru(i,a,n) for(long long int i=a;i>=n;i--)
#define test ll t;cin>>t;while(t--)
#define op(z) cout<<z<<endl
#define ops(z) cout<<z<<" "
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug(x) cout<<#x<<" "<<x<<endl
#define pp pair<ll,ll>
#define maxe 1000000
#define MOD 1000000007
ll prime[maxe] = {0};
// TO COUNT THE DIGIT IN A NUMBER => floor(log(n)/log10+1)
void file()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
ll sumofdigits(ll n) {
	ll sum = 0;
	while (n > 0) {
		sum += n % 10;
		n /= 10;
	}
	return sum;
}
void sieve()
{
	prime[0] = 0;
	prime[1] = 0;
	prime[2] = 1;
	ll i, j, k;
	file();
	for (i = 3; i <= maxe; i += 2)
	{
		prime[i] = 1;
	}
	for (i = 3; i <= maxe; i++)
	{
		if (prime[i])
		{
			for (j = i * i; j <= maxe; j += 2 * i)prime[j] = 0;
		}
	}
}
bool cmp(pp &a, pp &b)
{
	if (a.first != b.first)
	{
		return b.first > a.first;
	}
	else
	{
		return b.second > a.second;
	}
}
void solve()
{
  ll n;
  string s;
  cin>>n>>s;
  ll len=s.length();
  if(len<=n)
  {
    op(s);
    return;
  }
  else
  {
    string sa;
    ford(i,0,n)
    {
      sa+=s[i];
    }
    sa+="...";
    op(sa);
  }
}
int main()
{
	fastIO
	//sieve();
	//file();
	//test
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3588
MOD=10**9 + 7
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)

kou = a.first
a.each do |e|
  kou = kou.lcm(e)
end

b = a.map{|e| (kou/e)%MOD}
puts b.inject(:+) %MOD

Measured memory_bytes: 56132
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;cin>>n;
    vector<int> d(n);
    for(int i=0;i<n;i++)cin>>d[i];
    sort(d.begin(),d.end());
    int l=d[n/2-1];
    int r=d[n/2];
    cout<<r-l<<endl;
    return 0;
}


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


int main() {
    string S;
    cin >> S;
    string alp = "abcdefghijklmnopqrstuvwxyz";
    vector<bool> v(26, false);
    for (int i = 0; i < S.size(); ++i) {
        v.at(alp.find(S.at(i))) = true;
    }

    if (all_of(v.begin(), v.end(), [](bool x) { return x == true; })) {
        cout << "None" << endl;
    } else {
        for (int i = 0; i < v.size(); ++i) {
            if (!v.at(i)) {
                cout << alp.at(i) << endl;
                break;
            }
        }
    }
}

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

using namespace std;

int main()
{
	// 入力
	string S;
	cin >> S;
	
	vector<string> str(S.length());
	
	bool isNo = false;
	for (int i = 0; i < str.size(); i++)
	{
		str[i] = S.substr(i, 1);
		
		// indexは偶数
		if (i % 2 == 0)
		{
			// 奇数文字目で、Lが選ばれたとき
			if (str[i] == "L")
			{
				isNo = true;
			}
		}
		// indexは奇数
		else {
			// 偶数文字目で、Rが選ばれたとき
			if (str[i] == "R")
			{
				isNo = true;
			}
		}
	}
	
	// 出力
	if (isNo == true)
	{
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	string s1, s2;

	s1="ABC";

	cin>>s2;

	cout<<s1+s2<<endl;

}

Measured memory_bytes: 256
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;
int64_t A[100000];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	for (size_t i = 0; i < 4; i++)
	{
		in >> A[i];
	}
	std::sort(A, A + 4);
	if (A[0] == 1 && A[1] == 4 && A[2] == 7 && A[3] == 9) {
		out << "YES" << endl;
	}
	else{
		out << "NO" << endl;
	}

	return 0;
}
#endif


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

using namespace std;
 
/// ----------------------------- (Debug) ------------------------------
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";}
sim dor(rge<c> d) {*this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]";}
#else
sim dor(const c&) { ris; }
#endif
};
vector<char*> tokenizer(const char* args) {
	char *token = new char[111]; strcpy(token, args); token = strtok(token, ", ");
	vector<char*> v({token});
	while(token = strtok(NULL,", ")) v.push_back(token);
	return reverse(v.begin(), v.end()), v;
}
void debugg(vector<char*> args) { cerr << "\b\b "; }
template <typename Head, typename... Tail>
void debugg(vector<char*> args, Head H, Tail... T) {
	debug() << " [" << args.back() << ": " << H << "] ";
	args.pop_back(); debugg(args, T...);
}
#define harg(...) #__VA_ARGS__
#ifndef ONLINE_JUDGE
#define dbg(...) { debugg(tokenizer(harg(__VA_ARGS__, \b\t-->Line)), __VA_ARGS__, __LINE__); cerr << endl;}
#else
#define dbg(...) { }
#endif
/// -----------------------------------------------------------------------
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi; 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)    
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define print(x) cout << x << "\n";
#define REP(i,a,b) for(i=a;i<=b;i++)
#define RAP(i,a,b) for(i=a;i>=b;i--)
#define spa <<" "<<
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
ll mod=1e9+7;
const int MX=0x3f3f3f3f;

int seg[int(2e6)+1];
int c[int(5e5)+1],last[int(5e5)+5],ans[int(5e5)+5];

void update(int v,int l,int r,int idx,int num){
	if(r<idx||l>idx) return ;
	else if(l==r) seg[v]+=num ;
	else {
		update(2*v,l,(l+r)>>1,idx,num);
		update(2*v+1,((l+r)>>1)+1,r,idx,num);
		seg[v]=seg[2*v]+seg[2*v+1];
	}
}

int query(int v,int i,int j,int l,int r){
	if(j<l||i>r) return 0;
	else if(l>=i&&r<=j) return seg[v];
	else{
		return query(2*v,i,j,l,(l+r)>>1)+query(2*v+1,i,j,(l+r>>1)+1,r);
	}
}

int main(){
	memset(last,-1,sizeof(last));
	int n,q,i;
	cin>>n>>q;
	REP(i,0,n-1) cin>>c[i];
	vector<pair<pair<int,int>,int>> que(q);
	REP(i,0,q-1){
		cin>>que[i].F.S>>que[i].F.F;
		que[i].S=i;
	}
	sort(all(que));
	int j=0;
	dbg(que);
	REP(i,0,n-1){
		if(last[c[i]]!=-1) {
			update(1,0,n-1,last[c[i]],-1);
		}
		last[c[i]]=i;
		update(1,0,n-1,i,1);
		dbg(seg[1]);
		while(j<q&&que[j].F.F==i+1){
			dbg(que[j].S);
			ans[que[j].S]=query(1,que[j].F.S-1,que[j].F.F-1,0,n-1);
			j++;
		} 
	}
	dbg(ans);
	REP(i,0,q-1) cout<<ans[i]<<"\n";
  	return 0;
}

Measured memory_bytes: 19540
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;
 
int main(){
	
	int n, k; cin>>n>>k;
	string s; cin>>s;
	vector<pair<int,int>> a(1,{1,0});
	
	for(auto i:s){
		if(a.back().first==i-'0') a.back().second++;
		else a.push_back({i-'0',1});
	}
	if(a.back().first==0) a.push_back({1,0});
	deque<int> q;
	for(auto i:a) q.push_back(i.second);
	int ans{}, sum{}, cnt{};
	for(int i=0; i<a.size(); i++){
		if(cnt<k){
			if(a.at(i).first==1){
				sum += a.at(i).second;
			}
			else{
				sum += a.at(i).second;
				cnt++;
			}
		}
		else{
			if(a.at(i).first==1){
				sum += a.at(i).second;
			}
			else{
				sum -= q.front();
				q.pop_front();
				sum -= q.front();
				q.pop_front();
				sum += a.at(i).second;
			}
		}
		ans = max(ans,sum);
	}
	cout << ans << endl;
	
}


Measured memory_bytes: 1528
#include <iostream>
#include <vector>
typedef long long int ll;


int main(void){
	int N;
	ll money = 1000, stock = 0, dif = 0;
	std::cin >> N;
	std::vector<int> A(N, 0);
	for(int i = 0; i < N; i++) std::cin >> A[i];
	for(int i = 1; i < N; i++){
		// std::cout << i << " " << dif[i+1] << " " << money << endl;
		dif = A[i] - A[i-1];
		if(dif > 0){
		 	stock = money / A[i-1];     
			money += stock * dif;
			stock = 0;
		}
	}
	// std::cout << money << " " << stock << endl;
	std::cout << money << std::endl;
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a (n);
  for(int i=0; i<n; i++){
    double x;
    cin >> x;
    a.at(i) = x;
  }
  cout << fixed << setprecision(7);
  double ans = 0.0;
  for(int i=0; i<n; i++){
    ans += 1.0/a.at(i);
  }
  cout << 1.0/ans << endl;
}

Measured memory_bytes: 256
while 1:
    H, W = map(int, input().split())
    if H ==0 and W == 0:
        break
    for i in range(H):
        for j in range(W):
            if j == 0 or j == W - 1 \
            or i == 0 or i == H - 1:
                print("#", end="")
            else:
                print(".", end="")
        print()
    print()

Measured memory_bytes: 8972
'use strict';
(function(input){
  input=input.trim().split(/\n/);
  const N=input[0]-0;
  const p=input[1].split(/\s+/).map(x=>x-0);
  //console.log(p,q);
  const dp=new Array(N+3).fill(0).map((x,i)=>new Array(i+1).fill(0));
  //console.log(dp);
  dp[2][1]=1;
  for(let i=3;i<=N+2;i++){
    for(let j=1;j<=i-1;j++){
      dp[i][j]=p[i-3]*dp[i-1][j-1]+(1-p[i-3])*dp[i-1][j];
    }
  }
  //console.log(dp);
  var ans=0;
  for(let j=(N+3)/2;j<=N+1;j++){
    ans+=dp[N+2][j];
  }
  console.log(ans);
})(require('fs').readFileSync('/dev/stdin','utf8'));


Measured memory_bytes: 101424
N = int(input())
n, ans, t = N, '', 2

while abs(n) > 0:
  if n%t == 0:
    ans = '0' + ans
  else:
    ans = '1' + ans
  n = n - n % t
  t = t * (-2)
  
print('0' if N==0 else ans)

Measured memory_bytes: 3060
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n = II()
    ans = 0
    for i in range(1, n + 1):
        x = n // i
        ans += i * (1 + x) * x // 2
    print(ans)

    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 76880
# Your code here!
a,b=gets.split
a=a.to_i
b=b.to_i

arr=Array.new(a,0)

arr2=gets.split.map{|i| i.to_i}
i=0
a.times{
    arr[arr2[i]-1]+=1
    i+=1
}
    
arr=arr.sort.reverse

ans=arr[0..b-1].inject(:+)
p a-ans


Measured memory_bytes: 19968
#include<bits/stdc++.h>
#include<boost/algorithm/string/replace.hpp>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::algorithm;
using namespace boost::multiprecision;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int mINF = 1e9;
const int MOD = 1e9+7;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

template<typename T>//文字列の置換/Boost:replace_all()
T replace_str(T str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main(){
    int n;cin >> n;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    int ans = 0;
    for(int i=0;i<n;i++){
        while(a[i]%2==0){
            a[i] /= 2;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;

    int min_sum = 1000000000 ; //abピザの枚数を変化させる
    for ( int i = 0 ; i <= 2*max(x,y) ; i+=2 ){
        int cnt_a = x-i/2, cnt_b = y-i/2;
      	if ( cnt_a < 0 ) cnt_a = 0;
      	if ( cnt_b < 0 ) cnt_b = 0;
        min_sum = min( min_sum, cnt_a*a + cnt_b*b + i*c);
    }
    cout << min_sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n1[3] = { 0 };
	for (int i = 0; i < 3; i++) cin >> n1[i];
	int k;
	cin >> k;
	for (int j = 0; j < k; j++) {
		int m=0, m2=0;
		for (int i = 0; i < 3; i++) {
			if (n1[i] >= m) {
				m = n1[i];
				m2 = i;
			}


		}			n1[m2] *= 2;
	}
	cout << n1[0] + n1[1] + n1[2] << endl;
	return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;


/* MInt : 閾ェ蜍輔〒MOD繧偵→繧区紛謨ー.
 *   菴ソ縺?→縺阪?邨先ァ矩?縺?ョ壽焚縺御ケ励ｋ縺薙→縺ォ縺ェ繧九?縺ァ豕ィ諢? */
const long MOD = long.max / 2;
struct MInt {
    long v;
    this(long v) {
        if (v < 0) v += ((-v) / MOD + 1) * MOD;
        if (v >= MOD) v %= MOD;
        this.v = v;
    }
    bool opEquals()(long x) const { return this.v == x; }
    bool opEquals()(auto ref const MInt x) const { return this.v == x.v; }
    long opCast(string type)() const { static if (type == "long") { return v; } }
    //@property long toLong() const { return v; }
    //alias toLong this; /* 繝舌げ蝓九ａ霎シ縺ソ縺昴≧縺ェ縺ョ縺ァ豸医＠縺ィ縺?*/
    string toString() const { return to!string(v); }
    MInt opAssign(long x) { this.v = MInt(x).v; return this; }
    MInt opAssign(in MInt x) { this.v = x.v; return this; }
    MInt opOpAssign(string op)(in MInt x) {
        static if (op == "+") { this.v = (this.v + x.v) % MOD; return this; }
        else if (op == "-") { this.v = (this.v + MOD - x.v) % MOD; return this; }
        else if (op == "*") { this.v = (this.v * x.v) % MOD; return this; }
    }
    MInt opUnary(string op)() const {
        static if (op == "-") { return MInt(MOD - this.v); }
    }
    MInt opBinary(string op)(long x) const {
        return mixin("this " ~ op ~ "MInt(x)");
    }
    MInt opBinary(string op)(in MInt x) const {
        static if (op == "+") {
            return MInt(this.v + x.v);
        } else if (op == "-") {
            return this + (-x);
        } else if (op == "*") {
            return MInt(this.v * x.v);
        } else if (op == "/") {
            return this * x.inverse;
        }
    }
    static long extgcd(long a, long b, ref long x, ref long y) {
        long g = a; x = 1; y = 0;
        if (b != 0) {
            g = extgcd(b, a % b, y, x);
            y -= (a / b) * x;
        }
        return g;
    }
    MInt inverse() const {
        long x, y;
        if (extgcd(this.v, MOD, x, y) == 1) return MInt(x + MOD);
        return MInt(0);
    }
}

MInt fact(MInt x) {
    if (x == 0) return MInt(1);
    return x * fact(x - 1);
}

void main() {
    long N; scanf("%lld\n", &N);
    writeln(fact(MInt(N)));
}

Measured memory_bytes: 1072
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
from operator import itemgetter
def main():
    s=input()
    len_s=len(s)
    sc=list(Counter(s).items())
    sc.sort(key=itemgetter(1),reverse=True)
    if sc[0][1]==1:
        print(len_s//2)
        sys.exit()
    ans=100
    for scc in sc:
        dp=[[False]*len_s for _ in range(len_s)]
        for i,ss in enumerate(s):
            if ss==scc[0]:
                dp[0][i]=True
        dp[1][-1]=True
        for sosa in range(len_s):
            if all(dp[sosa]):
                ans=min(ans,sosa)
                break
            for i in range(len_s-1,-1,-1):
                if dp[sosa][i]==True:
                    dp[sosa+1][i]=True
                    if i>0:dp[sosa+1][i-1]=True
    print(ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 3436
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline bool chmin(A &a,const B &b){if(a>b){a=b;return true;}else{return false;}}
template<typename A,typename B>inline bool chmax(A &a,const B &b){if(a<b){a=b;return true;}else{return false;}}

ll MOD = 1000000000+7;

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

    ll allsum = 0;
    REP(i,N){
        allsum += A[i];
    }
    vll sums(N);
    ll b = 0;
    REP(i,N){
        b += A[i];
        sums[i] = allsum - b;
        sums[i] %= MOD;
    }
    ll ans = 0;
    REP(i,N-1){
        ans += sums[i]*A[i];
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6312
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;

const int MAXN = 100001;

bool sieve[MAXN];
bool similar[MAXN];
int sumarray[MAXN];

void precomp(){
	memset(sieve, true, sizeof sieve);
	memset(similar, false, sizeof similar);
	memset(sumarray, 0, sizeof sumarray);
	
	sieve[0] = false; sieve[1] = false;
	for (int i = 2; i * i <= MAXN - 1; i++){
		if (sieve[i]){
			for (int j = i * i; j <= MAXN - 1; j+=i){
				sieve[j] = false;
			}
		}
	}
	
	for (int i = 1; i <= MAXN - 1; i+=2){
		int partner = (i + 1) / 2;
		if (sieve[i] and sieve[partner]){
			similar[i] = true;
		}
	}
	
	for (int i = 3; i <= MAXN - 1; i++){
		sumarray[i] = sumarray[i - 1] + (int)similar[i];
	}
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	int Q; cin >> Q;
	int left, right;
	precomp();
	
	while(Q--){
		cin >> left >> right;
		cout << sumarray[right] - sumarray[left - 1] << '\n';
	}
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define yes(n) cout << ((n) ? "yes" : "no") << endl

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

template<typename T>
T gcd(T a, T b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
template<typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}


int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    int ans = INF;
    rep(div, 1<<(h-1)) {
        int g = 0; // グループ数
        vector<int> id(h);
        rep(i, h) {
            id[i] = g;
            if (div>>i&1) ++g;
        }
        ++g;

        vector<vector<int>> c(g, vector<int>(w, 0));
        rep(i,h)rep(j,w) c[id[i]][j] += (s[i][j] - '0');
        int num = g - 1;
        vector<int> now(g);
        auto add = [&](int j) {
            rep(i,g) now[i] += c[i][j];
            rep(i,g) if (now[i]>k) return false;
            return true;
        };
        rep(j,w) {
            if (!add(j)) {
                num++;
                now = vector<int>(g);
                if (!add(j)) {
                    num = INF;
                    break;
                }
            }
        }
        ans = min(ans, num);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <cstdlib>
#include <set>
#include <map>
using namespace std;
char kk[900009];
bool reserve;
int main()
{
	int l,r;
	char a[100009];
	scanf("%s",a);
	getchar();
	for(int i=0;i<strlen(a);i++)
	{
		kk[400003+i]=a[i];
	}
	l=400003;
	r=400003+strlen(a)-1;
	int op;
	scanf("%d",&op);
	for(int i=1;i<=op;i++)
	{
		int kop;
		scanf("%d",&kop);
		if(kop==1)
		{
			reserve=!reserve;
			getchar();
		}
		else
		{
			int lll;
			scanf("%d",&lll);
			getchar();
			char jk;
			scanf("%c",&jk);
			getchar();
			if(reserve==0)
			{
				if(lll==2)
				{
					r++;
					kk[r]=jk;
				}
				else
				{
					l--;
					kk[l]=jk;
				}
			}
			else
			{
				if(lll==1)
				{
					r++;
					kk[r]=jk;
				}
				else
				{
					l--;
					kk[l]=jk;
				}
			}
		}
	}
	if(reserve)
	{
		for(int i=r;i>=l;i--)
		{
			printf("%c",kk[i]);
		}
	}
	else
	{
		for(int i=l;i<=r;i++)
		{
			printf("%c",kk[i]);
		}	
	}
	return 0;
	
}

Measured memory_bytes: 896
dish, time = [], 0
for i in range(5):
    temp = int(input())
    if temp % 10 == 0:
        time += temp
    else:
        dish.append(temp)
if dish:
    left = 10 - min([x % 10 for x in dish])
    time = time + sum([x + 10 - x % 10 for x in dish]) - left
print(time)

Measured memory_bytes: 3060
using System;
using System.IO;
using System.Text;
using static Scanner;
using static System.Math;

class Program
{
    static void Main(string[] args) {
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Solve();
        Console.Out.Flush();
    }
    static void Solve() {
        int N = ScanInt(), M = ScanInt(), X = ScanInt();
        var texts = new (int C, int[] A)[N];
        for (int i = 0; i < N; i++) {
            texts[i].C = ScanInt();
            texts[i].A = ScanIntArray(M);
        }
        var answer = int.MaxValue;
        for (int bit = 0; bit < 1 << N; bit++) {
            var levels = new int[M];
            var cost = 0;
            for (int i = 0; i < N; i++) {
                if (((bit >> i) & 1) == 0) continue;
                cost += texts[i].C;
                for (int j = 0; j < M; j++) levels[j] += texts[i].A[j];
            }
            var isAchieved = true;
            for (int j = 0; j < M; j++) {
                if (levels[j] < X) isAchieved = false;
            }
            if (isAchieved) answer = Min(answer, cost);
        }
        Console.WriteLine(answer == int.MaxValue ? -1 : answer);
    }
}

public static class Scanner
{
    static readonly Stream stdin = Console.OpenStandardInput();
    static readonly byte[] buffer = new byte[1024];
    static int length, p;
    static bool isEof;
    private static byte StdIn() {
        if (isEof) return 0;
        if (p < length) return buffer[p++];
        p = 0;
        if ((length = stdin.Read(buffer, 0, 1024)) > 0) return buffer[p++];
        isEof = true;
        return 0;
    }
    public static char GetChar() {
        var by = StdIn();
        while ((by < '!' || '~' < by) && !isEof) by = StdIn();
        return (char) by;
    }
    public static int ScanInt() {
        var temp = 0;
        for (var ch = GetChar(); '0' <= ch && ch <= '9'; ch = (char) StdIn()) {
            temp = temp * 10 + ch - '0';
        }
        return temp;
    }
    public static int[] ScanIntArray(int len, int add = 0) {
        var array = new int[len];
        for (int i = 0; i < len; i++) array[i] = ScanInt() + add;
        return array;
    }
}

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

typedef long long Int;
typedef pair<int,int> PII;
typedef vector<int> VInt;
 
#define FOR(i, a, b) for(i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(i = (a) - 1; i >= (b); --i)
#define EACH(it, a) for(auto it = (a).begin(); it != (a).end(); ++it)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
#define MP make_pair

void SolveTest(int test)
{
	string s;
	cin >> s;
	int len = SIZE(s);
	int i;
	FOR(i, 0, len) if(s[i] == '?') s[i] = 'D';
	cout << s << endl;
}

int main()
{
	int T, t;
	T = 1;
	FOR(t, 0, T) SolveTest(t);
	return 0;
};

Measured memory_bytes: 3680
#include <iostream>

using namespace std;

char a[52][52];

int main() {
	int n,m,i,j,t;
	cin >> n >> m;
	for(i=1;i<=n;i++) for(j=1;j<=m;j++) cin >> a[i][j];
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			t=0;
			if(a[i][j]=='.')
			{
				if(a[i-1][j]=='#') t++;
				if(a[i-1][j-1]=='#') t++;
				if(a[i-1][j+1]=='#') t++;
				if(a[i][j+1]=='#') t++;
				if(a[i][j-1]=='#') t++;
				if(a[i+1][j-1]=='#') t++;
				if(a[i+1][j]=='#') t++;
				if(a[i+1][j+1]=='#') t++;
				a[i][j]=t+'0';
			}
		}
	}

	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++) cout << a[i][j];
		cout << "\n";
	}

	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int x;
    cin >> x;
    x = 1 - x;
    cout << x << endl;
    return 0;
}




Measured memory_bytes: 3592
N = int(input())
S = list(input())

a = ''
b = ''
if(N%2 == 1):
  print('No')
else:
 for i in range(N):
   if(i < N//2): a += S[i]
   else: b += S[i]
 if(a == b):
  print('Yes')
 else:
  print('No')

Measured memory_bytes: 3060
N=int(input())
L=list(map(int,input().split()))
S=set(L)
ans=0
dict={}

for s in S:
    dict[s]=0

for l in L:
    dict[l]+=1

for d in dict.items():
    num=d[0]
    amount=d[1]

    if amount>num:
        ans+=amount-num
    elif amount<num:
        ans+=amount

print(ans)



Measured memory_bytes: 23800
n = int(input())
a = [int(x) for x in input().split()]

#n=3
#a = [1, 4, 3]

import statistics
#import NumPy

m = statistics.mean(a)
#print(m)
list = []
for i in a:
    list.append(abs(i - m))

#print(a)
print(list.index(min(list)))



Measured memory_bytes: 5464
n=int(input())
l=[]
for i in range(n):
    a,b=map(int,input().split())
    l.append([a,b])
l.sort(key=lambda x:x[1])
t=0
f=True
for i in range(n):
    t+=l[i][0]
    if t>l[i][1]:
        f=False
if f:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 84760
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define FI first
#define SE second
#define maxn 200000
#define mod 1000000007
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef double db;


int main()
{
    int n; scanf("%d",&n);
    ll ans=0;
    rep(i,1,n) ans+=1ll*i*(n-i+1);
    rep(i,1,n-1)
    {
        int u,v; scanf("%d%d",&u,&v);
        if(u>v) swap(u,v);
        ans-=1ll*u*(n+1-v);
    }
    printf("%lld\n",ans);
    return 0;
}

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

const int INF = 0x3f3f3f3f;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, n;
  cin >> h >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  vector< vector<int> > dp(n + 1, vector<int>(h + 1, INF));
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= h; j++) {
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
      dp[i][min(h, j + a[i])] = min(dp[i][min(h, j + a[i])], dp[i][j] + b[i]);
    }
  }
  cout << dp[n][h] << '\n';
  return 0;
} 

Measured memory_bytes: 39424
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1000000007;
const double eps = 1e-9;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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 () {
  int N, K; cin >> N >> K;
  vi A(N); rep(i,N) cin >> A[i];

  cout << 1 + ((N-K)+(K-2))/(K-1) << endl;
}

Measured memory_bytes: 640
a,b,c=(int(x) for x in input().split())
d=0 
e=0
if a==5:
  d=d+1
if a==7:
  e=e+1
if b==5:
  d=d+1
if b==7:
  e=e+1
if c==5:
  d=d+1
if c==7:
  e=e+1
if d==2 and e==1:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
#define INF (1<<29)

int main(){
  int n, ans=0;
  cin >> n;
  for(int i=1;i<=n;i+=2){
    int cnt=0;
    for(int j=1;j<=i;j++){
      if(i%j==0)cnt++;
    }
    if(cnt==8)ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int i, j, k, o;
  cin >> i >> j >> k >> o;
  if(o <= i){
    cout << o;
  }
  else if(o - i <= j){
    cout << i;
  }
  else{
    cout << i - (o - i - j);
  }
  return 0;
}

Measured memory_bytes: 3604
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
li = [[-1 for i in range(n)] for j in range(n)]
for i in range(n):
    a = ni()
    for j in range(a):
        x, y = na()
        li[i][x-1] = y

ans = 0
for i in range(2 ** n):
    t_li = [-1 for i in range(n)]
    flag = False
    ct = 0
    for j in range(n):
        if ((i >> j) & 1):
            t_li[j] = 1
            ct += 1
        else:
            t_li[j] = 0
    #print(t_li)
    for j in range(n):
        if ((i >> j) & 1):
            tmp = li[j]
            for k in range(n):
                if tmp[k] != -1:
                    if t_li[k] == tmp[k]:
                        continue
                    else:
                        flag = True
                        break
        if flag:
            break
    #print(bin(i), ct,  flag)
    if flag is False:
        #print('\t', ct, i)
        ans = max(ans, ct)
print(ans)

            

                   

Measured memory_bytes: 3444
# coding:utf-8

import sys
from collections import defaultdict, deque

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
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 II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n, k = LI()

    G = defaultdict(list)
    AB = [LI_() for _ in range(n - 1)]
    for a, b in AB:
        G[a].append(b)
        G[b].append(a)

    def DFS(ss: list, t: int):
        q = deque()
        for s in ss:
            q.append((s, 0))
        visited = [0] * n
        visited[ss[0]] = visited[ss[-1]] = 1
        while q:
            v, d = q.pop()
            if d >= t:
                continue
            for to in G[v]:
                if visited[to]:
                    continue
                visited[to] = 1
                q.append((to, d + 1))
        
        return n - sum(visited)

    # 木の性質
    # 直径をdとした時
    # dが偶数ならば，ある頂点vから他の頂点への距離がD/2となる頂点vが存在する
    # dが奇数ならば，ある辺eから他の頂点への距離が(D-1)/2となる辺eが存在する
    res = INF
    if k % 2:
        for a, b in AB:
            res = min(res, DFS([a, b], (k - 1) // 2))
    else:
        for i in range(n):
            res = min(res, DFS([i], k // 2))

    return res


print(main())


Measured memory_bytes: 4208
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <unordered_map>

const int maxN = 5010, oo = 23041997;

using namespace std;

#define FORU(i, l, r) for (int i = l; i <= r; ++i)
#define FORD(i, r, l) for (int i = r; i >= l; --i)
#define REPU(i, r) for (int i = 0; i < r; ++i)
#define LL long long
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define PINT pair < int, int >
#define BIT(x, i) ((x >> i) & 1)
#define NUM_SET_BIT __builtin_popcountll

int f[maxN], x[maxN], g[maxN][maxN], n;
vector < int > adj[maxN];

void dp(int u) {
    FORU(i, 0, x[u]) g[u][i] = oo;
    f[u] = oo; g[u][0] = 0;
    REPU(i, adj[u].size()) {
        int v = adj[u][i]; dp(v);
        if (f[v] == oo) return;
        FORD(j, x[u], 0) {
            int tmp = oo;
            if (j >= f[v])
                tmp = min(tmp, g[u][j - f[v]] + x[v]);
            if (j >= x[v])
                tmp = min(tmp, g[u][j - x[v]] + f[v]);
            g[u][j] = tmp;
        }
    }
    FORU(i, 0, x[u])
        f[u] = min(f[u], g[u][i]);
}

int main() {
    cin >> n;
    FORU(i, 1, n - 1) {
        int p; scanf("%d", &p);
        adj[p].PB(i + 1);
    }
    FORU(i, 1, n) cin >> x[i];
    dp(1);
    if (f[1] != oo) cout << "POSSIBLE";
    else cout << "IMPOSSIBLE";
}


Measured memory_bytes: 19968
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <atcoder/all>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#define PI 3.14159265359
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pai;
typedef pair<ll, ll> pal;
const int MOD = 1e9+7;
const int MODD = 998244353;
const ll LLINF = 1e18;


int main(){
	int n, m;
	cin >> n >> m;
	scc_graph graph(n);
	for (int i = 0; i < m; i++){
		int from, to;
		cin >> from >> to;
		graph.add_edge(from, to);
	}

	auto scc = graph.scc();

	int ans = scc.size();
	cout << ans << endl;

	for (auto x : scc){
		cout << (int)x.size() << " ";
		for (auto y : x){
			cout << y << " ";
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 40580
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;


ll dp[10010];

bool cmp(const pair<int,ll> &a,const pair<int,ll> &b) {
	if(a.first!=b.first)return a.first<b.first;
	else return a.second<b.second;
}

int main(void){
    ll h,n;
    cin>>h>>n;
    vector<P>p(n);
    for(ll i=0;i<n;i++)cin>>p[i].first>>p[i].second;
    for(ll i=0;i<10010;i++)dp[i]=INF;
    dp[0]=0;
    sort(p.begin(),p.end(),cmp);
    for(ll i=1;i<=h;i++){
        for(ll j=0;j<n;j++){
            if(i>=p[j].first)dp[i]=min(dp[i],dp[i-p[j].first]+p[j].second);
            else dp[i]=min(dp[i],dp[0]+p[j].second);
        }
    }
    cout<<dp[h]<<endl;
    return 0;
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var abs = Enumerable.Repeat(0, nm[1]).Select(_ => Console.ReadLine().Split().Select(int.Parse).ToList()).ToList();

            var res = new List<long>();
            var uf = new UnionFind(nm[0]);
            var now = (long)nm[0] * (nm[0] - 1) / 2;

            foreach (var ab in abs.Reverse<List<int>>())
            {
                res.Add(now);
                var acount = uf.GetSize(ab[0] - 1);
                var bcount = uf.GetSize(ab[1] - 1);
                if (uf.Unite(ab[0] - 1, ab[1] - 1))
                {
                    now -= acount * bcount;
                }
            }
            res.Reverse();
            Console.WriteLine(string.Join("\r\n", res));
        }

    }

    class UnionFind
    {
        public int Size { get; set; } = 0;
        List<int> parent;
        List<int> sizes;

        public UnionFind(int count)
        {
            parent = new List<int>(count);
            sizes = new List<int>(count);
            ExtendSize(count);
        }

        public bool Unite(int x, int y)
        {
            var xp = Find(x);
            var yp = Find(y);
            if (yp == xp) return false;
            if (sizes[xp] < sizes[yp])
            {
                var tmp = xp;
                xp = yp;
                yp = tmp;
            }
            parent[yp] = xp;
            sizes[xp] += sizes[yp];
            return true;
        }

        public IEnumerable<int> AllParents => parent.Where(x => x == parent[x]);
        public int GetSize(int x) => sizes[Find(x)];
        public int Find(int x) => parent[x] == parent[parent[x]] ? parent[x] : parent[x] = Find(parent[x]);
        public void ExtendSize(int treeSize)
        {
            if (treeSize <= Size) return;
            parent.Capacity = treeSize;
            sizes.Capacity = treeSize;
            while (Size < treeSize)
            {
                parent.Add(Size);
                sizes.Add(1);
                Size++;
            }
        }
    }
}


Measured memory_bytes: 40944
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<climits>
#include<algorithm>
#include<vector>
#include<valarray>
#include<string>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iostream>
#include<iomanip>
using namespace std;


#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define DREP(i,n) for(int i=n;i>0;i--)
#define Rep(i,m,n) for(int i=m;i<n;i++)
#define ReP(i,m,n) for(int i=m;i<=n;i++)
#define scani(a) scanf("%d",&a)
#define scand(a) scanf("%lf",&a)
#define scans(s) scanf("%s",s)
#define readi(a) int a;scanf("%d",&a)
#define printi(a) printf("%d",a)
#define prints(s) printf("%s",s)
#define even(n) (((n)+1)%2)
#define odd(n) ((n)%2)
#define sg(x) ((x)?1:0)
#define LF printf("\n")
#define SPACE printf(" ")
#define pb push_back
#define mp make_pair
#define bs binary_search
#define all(a) (a).begin(),(a).end()
#define forall(itr,a) for(auto itr=(a).begin();itr!=(a).end();++itr)

typedef long long LL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<double,double> pdd;
typedef pair<int,int> pii;

const double pi = acos(-1.0);
double rad(double t){return t*pi/180.0;}
double deg(double d){return d*180.0/pi;}
template<typename T>T GCD(T x,T y){return y?GCD(y,x%y):x;}
template<typename T>T LCM(T x,T y){return x/GCD(x,y)*y;}
template<class T>ostream& operator<<(ostream& os,const set<T>& s){os<<"{";for(auto itr=s.begin();s.end() != itr;++itr){if(itr!=s.begin())os<<',';os<<*itr;}os<<"}";return os;}
template<class S,class T>ostream& operator<<(ostream& os,const pair<S,T>& p){os<<'('<<p.first<<','<<p.second<<')';return os;}
const int MOD = (int)pow(10,9) +7;


//begin global variable
//


//
//end   global variable

int main(){
  ios::sync_with_stdio(false);
  //begin main()
  //
  LL N;
  cin >> N;

  LL factor[1009]={};
  
  // count factor
  for( int i = 2 ; i <= N ; ++i ){
    int k = i;
    for( int p = 2 ; p*p <= i ; ++p ){
      while( k%p == 0 ){
        factor[p] ++;
        k /= p;
      }
    }
    factor[k] ++;
  }
  // get result
  LL ans = 1;
  for( int p = 2 ; p <= N ; ++p ){
    //    cout << "factor " << p << " = " << factor[p] << endl;
    ans = (ans * (factor[p]+1)) % MOD;
  }
  cout << ans << endl;

  //
  //end   main()
  return 0;
}


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

int main() {
  int n,a=0,count=0;
  cin>>n;
  vector<int> score(n);
  for(int i=0;i<n;i++)cin>>score[i];
  for(int i=0;i<n;i++){
    int maxscore=0,x=-1;
    for(int j=0;j<n;j++){
      if(maxscore<score[j]){
        maxscore=score[j];
        x=j;
      }
    }
    if(x>-1)score[x]=0;
    a+=(-2*(i%2)+1)*maxscore;
  }
  cout<<a<<endl;
}

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

namespace Beg093C
{
    class Program
    {
        static void Main(string[] args)
        {
            var nums = Console.ReadLine().Split(' ').Select(s0 => int.Parse(s0)).ToArray();
            var max = nums.Max();
            var distSum = nums.Select(n => max - n).Sum();
            var ans = distSum % 2 == 1 ? (distSum + 1) / 2 + 1 : distSum / 2;
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13396