akhauriyash/Code-Regression huggingface dataset:
n, m, x = map(int, input().split())

c = [0] * n
a = []
for i in range(n):
    ca = list(map(int, input().split()))
    c[i] = ca[0]
    a.append(ca[1:])

ans = 10**7
for bit in range(1<<n):
    cost = 0
    ex = [0] * m
    for i in range(n):
        if bit & (1<<i):
            cost += c[i]
            for j in range(m):
                ex[j] += a[i][j]

    f = True
    for i in range(m):
        if ex[i] < x:
            f = False
            break
    if f:
        ans = min(ans, cost)

if ans == 10**7:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 74024
#include <set>
#include <string>
#include <iostream>
using namespace std;
int main() {
	int n; string s;
	cin >> n >> s;
	set<string> v;
	for (int i = 1; i < 1 << n; i *= 2) {
		for (int j = 0; j < 1 << n; j += 2 * i) {
			if (s.substr(j, i) != s.substr(j + i, i)) {
				v.insert(s.substr(j, 2 * i));
			}
		}
	}
	cout << v.size() << endl;
	return 0;
}


Measured memory_bytes: 3256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <memory.h>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <queue>
#include <stack>
#include <cstdio>
#include <bitset>

using namespace std;

#define nfs ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f first
#define s second
#define m_p make_pair
#define pb push_back
#define ii pair<int,int>
#define iii pair<int,pair<int,int> >
#define ll long long
#define ull unsigned long long
#define ld long double
#define ef else if
#define loc(x) (x).begin(),(x).end() 
#define locR(x) (x).rbegin(),(x).rend()
#define no puts("NO")
#define yes puts("YES")
#define ex puts("-1")
#define en puts("")
#define _ cout  
#define __ <<
#define outV(v) for(int i = 0 ; i < v.size() ; i++)cout << v[i] << ' ';
#define outA(x,l,r) for(int i = l ; i < r ; i++)cout << x[i] << ' ';


const ld EPS = 1e-18;
const double DEPS = 1e-9;
const ld PI = 3.141592653589793238;
const ull MOD = 1e9 + 7;
const int N = (int)(5e5) + 1;

ll gcd(ll fx, ll fy)
{
	if (!fy) return fx;
	return gcd(fy, fx % fy);
}

inline void fill(int* ar, int sz, int val)
{
	for (int i = 0; i < sz; i++)
	{
		ar[i] = val;
	}
}

int n;
ld a[3000], dp[3000][1500][2], ini = 1;
ld  ans;
bool mark[3000][1500][2];

ld rec(int idx, int t,bool ht)
{
	if (idx == n)return 1;
	ld& dp = ::dp[idx][t][ht];
	if (mark[idx][t][ht])return dp;

	mark[idx][t][ht] = 1;
	if (t)
	{
		dp = rec(idx + 1, t - 1, 1) * (1 - a[idx]);
	}

	dp += rec(idx + 1, t, 0) * a[idx];
	
	return dp;
}

int main()
{
	cin >> n;
	memset(mark, 0, sizeof(mark));
	for (int i = 0; i < n; i++)
	{
		scanf("%Lf", a + i);
	}
	

	ans = rec(0, n / 2, 0);
	printf("%0.10Lf", ans);
}

Measured memory_bytes: 149888
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int a;
  string s;
  cin>>a>>s;
  cout<<(a>=3200?s:"red")<<endl;
  return 0;
}


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

vector<int> color;
vector<vector<pair<int, int>>> g;

void dfs(int v, int p, int c) {
  color[v] = c;
  for (auto a : g[v]) {
    if (a.first == p) continue;
    if (a.second % 2 == 0) dfs(a.first, v, c);
    else dfs(a.first, v, 1 - c);
  }
}

int main() {
  int n;
  cin >> n;
  g.assign(n, vector<pair<int, int>>());
  rep(i, n - 1) {
    int u, v, w;
    cin >> u >> v >> w;
    u--; v--;
    g[u].push_back(make_pair(v, w));
    g[v].push_back(make_pair(u, w));
  }
  color.assign(n, 0);
  dfs(0, -1, 0);
  rep(i, n) cout << color[i] << endl;
  return 0;
}


Measured memory_bytes: 11600
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

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

int main(){
    int a[10]={};
    rep(i,3){
        int k;
        cin >> k;
        a[k]++;
    }
    rep(i,10){
        if(a[i]==2){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
using namespace std;
typedef long long ll;
const int N = 2 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
int main(){/*
    freopen("in","r",stdin);
    freopen("out","w",stdout);*/
    int a,b,c;
    cin >> a >> b >> c;
    bool flag = 0;
    for(int i = 1; i <= 100000; i++)
        if((a + a * i) % b == c)
            flag = 1;

    cout << (flag ? "YES":"NO") << '\n';
    return 0;
}   

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

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

	for(int j = 0; j < a; j++) {
		string str;
		cin >> str;
		string ret = "";

		int n = 0;
		char c;
		for(int i = 0; i < str.size(); i++) {
			switch(str[i]) {
				case '0':
					if(n)
						ret += c;
					n = 0;
					break;
				case '1':
					switch(n % 5) {
						case 0:
							c = '.';
							break;
						case 1:
							c = ',';
							break;
						case 2:
							c = '!';
							break;
						case 3:
							c = '?';
							break;
						case 4:
							c = ' ';
							break;
					}
					n++;
					break;
				case '2':
					c = 'a' + n % 3;
					n++;
					break;
				case '3':
					c = 'd' + n % 3;
					n++;
					break;
				case '4':
					c = 'g' + n % 3;
					n++;
					break;
				case '5':
					c = 'j' + n % 3;
					n++;
					break;
				case '6':
					c = 'm' + n % 3;
					n++;
					break;
				case '7':
					c = 'p' + n % 4;
					n++;
					break;
				case '8':
					c = 't' + n % 3;
					n++;
					break;
				case '9':
					c = 'w' + n % 4;
					n++;
					break;
			}
		}

		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
#!/usr/bin/python3

import math
import os
import sys


DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


def main():
    N = int(inp())
    A = [int(e) for e in inp().split()]

    S = [(a, i + 1) for i, a in enumerate(A)]
    S.sort()
    print(*[s[1] for s in S])


if __name__ == '__main__':
    main()


Measured memory_bytes: 65252
N, M = [int(x) for x in input().split()]
a = set(int(input()) for _ in range(M))

MOD = 10 ** 9 + 7
dp = [0] * (N + 1)
dp[0] = 1

for i in range(1, N + 1):
  if i in a:
    continue
  x = dp[i - 1]
  if i > 1:
    x += dp[i - 2]
  dp[i] = x % MOD

ans = dp[N]
print(ans)

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

void next(vector<int>& v) {
  int num = 0;
  rep(k, 20) {
    if (v[k] == -1) {
      if (k == 0 or v[k - 1] == 9) num = k;
      else num = k - 1;
      break;
    }
    if (v[k] <= v[k + 1] and v[k] != 9) {
      num = k;
      break;
    }
  }
  v[num] = max(v[num] + 1, 1);
  for (int i = num - 1; i >= 0; i--) v[i] = max(v[i + 1] - 1, 0);
}

int main(){
  int K; cin >> K;
  vector<int> v(20, -1);
  rep(i, K) next(v);
  long long ans = 0;
  long long x = 1;
  rep(i, 20) {
    if (v[i] == -1) continue;
    ans += v[i] * x;
    x *= 10;
  }
  cout << ans << endl;
}


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


#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define MAXX 100005
#define INF INT_MAX

#define PI   3.14159265358979323846264338327950

#define PB push_back
#define PF push_front
#define F first
#define S second

#define fixx(n) fixed << setprecision(n)

#define ll 	 long long 

#define mod  1000000007



int main()
{
	FAST;
	string s;
	cin >> s;
	int n = s.size();
	int ans = 800;
	for(int i = 0; i < n - 2; i ++){
		int m = 0;
		for(int j = i; j < i + 3; j ++){
			m = m*10 + (s[j] - 48);
		}
		ans = min(abs(753 - m), ans);
	}
	cout << ans;
	return 0;
	
}

Measured memory_bytes: 3592
# frozen_string_literal: true

s = gets.chomp
cnt = 0
a = s.length
(0 .. s.length - 1).each do |a|
if a % 2 == 0 && (s[a] == 'R' || s[a] == 'U' || s[a] == 'D')
    cnt += 1
elsif a % 2 == 1 && (s[a] == 'L' || s[a] == 'U' || s[a] == 'D')
    cnt += 1
    end
end
ans = cnt == a ? 'Yes' : 'No'
puts ans

Measured memory_bytes: 1788
from heapq import heappush, heappop


N, K, *td = map(int, open(0).read().split())
sushis = [(d, t) for t, d in zip(*[iter(td)] * 2)]
sushis.sort(reverse=True)

pq = []
cnt = [0] * (N + 1)
base, x = 0, 0
for d, t in sushis[:K]:
    base += d
    if cnt[t] > 0:
        heappush(pq, (d, t))
    elif cnt[t] == 0:
        x += 1
    cnt[t] += 1
ans = base + x * x

for d, t in sushis[K:]:
    if not pq:
        break
    if cnt[t] > 0:
        continue

    _d, _t = heappop(pq)
    cnt[_t] -= 1
    cnt[t] += 1
    x += 1
    base += d - _d
    ans = max(ans, base + x * x)

print(ans)


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

int main() {
    int n, k, l; cin >> n >> k >> l;
    vector<vector<int>> road(n), train(n);
    for (int i = 0; i < k; i++) {
        int p, q; cin >> p >> q;
        p--; q--;
        road.at(p).push_back(q);
        road.at(q).push_back(p);
    }
    for (int i = 0; i < l; i++) {
        int r, s; cin >> r >> s;
        r--; s--;
        train.at(r).push_back(s);
        train.at(s).push_back(r);
    }
    int rlabel[n], tlabel[n];
    for (int i = 0; i < n; i++) {
        rlabel[i] = -1; tlabel[i] = -1;
    }
    int label = 0;
    for (int i = 0; i < n; i++) {
        if (rlabel[i] >= 0) continue;
        queue<int> q;
        q.push(i);
        rlabel[i] = label;
        while (q.size() > 0) {
            int nd = q.front(); q.pop();
            for (int nb : road.at(nd)) {
                if (rlabel[nb] >= 0) continue;
                rlabel[nb] = label;
                q.push(nb);
            }
        }
        label++;
    }
    label = 0;
    for (int i = 0; i < n; i++) {
        if (tlabel[i] >= 0) continue;
        queue<int> q;
        q.push(i);
        tlabel[i] = label;
        while (q.size() > 0) {
            int nd = q.front(); q.pop();
            for (int nb : train.at(nd)) {
                if (tlabel[nb] >= 0) continue;
                tlabel[nb] = label;
                q.push(nb);
            }
        }
        label++;
    }
    pair<int, int> p[n];
    for (int i = 0; i < n; i++) p[i] = make_pair(rlabel[i], tlabel[i]);
    map<pair<int, int>, int> m;
    for (int i = 0; i < n; i++) m[p[i]]++;
    for (int i = 0; i < n; i++) {
        cout << m[p[i]];
        if (i == n - 1) cout << endl;
        else cout << " ";
    }
    return 0;
}

Measured memory_bytes: 29348
#include<algorithm>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-8;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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

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

int dp[1001][4096];

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

    int n, m;
    cin >> n >> m;

    vector<int> a(m), b(m), c(m);
    rep(i, m){
        cin >> a[i] >> b[i];
        rep(j, b[i]){
            int t;
            cin >> t;
            --t;
            c[i] |= (1 << t);
        }
    }

    fill(dp[0], dp[m + 1], IINF);
    dp[0][0] = 0;
    rep(i, m){
        rep(j, 1 << n){
            chmin(dp[i + 1][j], dp[i][j]);
            chmin(dp[i + 1][j | c[i]], dp[i][j] + a[i]);
        }
    }

    if(dp[m][(1 << n) - 1] < IINF){
        cout << dp[m][(1 << n) - 1] << endl;
    }else{
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 16256
def main():
    n = int(input())
    x = input()
    x = '0b'+x

    x = int(x,0)
    m = bin(x).count('1')

    if m > 1:
        a = x%(m-1)
    b = x%(m+1)
    tmp_a = 1
    tmp_b = 1
    xx = []

    for i in range(n):
        if (x >> i) &1:
            if m == 1:
                xx.append(0)
                continue
            else:
                y = (a - tmp_a)%(m-1)
        else:
            y = (b + tmp_b)%(m+1)
        tmp_a *= 2
        if m > 1:
            tmp_a %= (m-1)
        tmp_b *= 2
        tmp_b %= (m+1)

        cnt = 1
        while y != 0:
            cnt += 1
            y = solve(y)
        xx.append(cnt)
    
    # print(xx)
    for i in range(n-1,-1,-1):
        print(xx[i])

def solve(n):
    m = bin(n).count('1')
    return n%m

main()





Measured memory_bytes: 11264
#include<iostream>
using namespace std;
long long a[3], m[3], k[3];
long long gcd(int a, int b) {
	if (b == 0) { return a; }
	return gcd(b, a%b);
}
int main() {
	while (true) {
		cin >> a[0] >> m[0] >> a[1] >> m[1] >> a[2] >> m[2];
		if (a[0] == 0 && m[0] == 0 && a[1] == 0 && m[1] == 0 && a[2] == 0 && m[2] == 0) { break; }
		for (int i = 0; i < 3; i++) {
			long long cnt = 0, x = 1;
			while (true) {
				if (x == 1 && cnt >= 1) { break; }
				x *= a[i]; x %= m[i]; cnt++;
			}
			k[i] = cnt;
		}
		int LCM = k[0] * k[1] / gcd(k[0], k[1]);
		cout << LCM*k[2] / gcd(LCM, k[2]) << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include <iostream>

using namespace std;

int main()
{
    int number;
    cin >> number;
    
    int count{0};
    while(number){
        if(number >= 500){
            int x = number / 500;
            count = count + 1000*x;
            number = number % 500;
        }else if(number >= 5){
            int x = number / 5;
            count = count + 5*x;
            number = number % 5;
        }else
            number = number % 1;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<complex>
#define EPS 1e-10
using namespace std;

typedef complex<double> P;

double dot(P a,P b){return real(conj(a)*b);}

int main(){
  double d;
  double px,py,vx,vy;

  while(scanf("%lf",&d) && d!=0.0){
    scanf("%lf %lf %lf %lf",&px,&py,&vx,&vy);
    P a = P(0-px,0-py),b = P(vx,vy);
    double seta = dot(a,b)/(abs(a)*abs(b));
    double dis = d+1;
    if(abs(seta-1)<EPS)dis = abs(a);
    if(abs(seta+1)<EPS)dis = 2-abs(a);
    if(dis < d + EPS)printf("%.8lf\n",dis);
    else printf("impossible\n");
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long long , long long>
#define pb push_back
#define ll long long
#define ld long double
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
ll power(ll x,ll y,ll m){ll r=1;for(;y;y>>=1){if(y&1)r=r*x%m;x=x*x%m;}return r;}
const ll mod = 1e9 + 7;
const ld pi = 3.14159265358979;
    
int run_test(){
	ll a, b;
	cin >> a >> b;
	ll g = __gcd(a, b);
	//now I have to find all the prime factors of g
	int count = 0;
	for(int i=2; i<=sqrt(g); i++){
		if(g % i == 0){
			count++;
			while(g % i == 0){
				g /= i;
			}
			if(g == 1) break;
		}
	}
	if(g != 1) count++;
	cout << count + 1;
	return 0;
}
    
int main(){
   FAST;
    ll t;
    t = 1;
     
    while(t--){
        run_test();
    }
}

Measured memory_bytes: 3612
def is_lunlun(s):
    for i in range(len(s) - 1):
        if abs(int(s[i]) - int(s[i+1])) > 1:
            return (i)
    return -1

def minimize(s, j):
    init = int(s[j])
    for i in range(j + 1, len(s)):
        if init == 0:
            s[i] = str(0)
        else:
            init -= 1
            s[i] = str(init)
    return s

k = int(input())
if k <= 10:
    print(k)
else:
    counter = 10
    i = 10
    while counter < k:
        i += 1
        s = list(str(i))
        lunlun_dig = is_lunlun(s)
        while lunlun_dig != -1:
            if int(s[lunlun_dig]) < int(s[lunlun_dig + 1]):
                s[lunlun_dig] = str(int(s[lunlun_dig]) + 1)
            s = minimize(s, lunlun_dig)
            lunlun_dig = is_lunlun(s)
        i = int("".join(s))
        counter += 1
    print(i)

Measured memory_bytes: 3064
import Data.List

main :: IO ()
main = do
  s <- getLine
  t <- getLine
  let ans = sort $ solve s t
  putStrLn $ if null ans
             then "UNRESTORABLE" else head ans

solve :: String -> String -> [String]
solve s t = go 0
  where
    go :: Int -> [String]
    go i
      | i -1 == length s - length t = []
      | otherwise =
          make i ++ go (i+1)
    make n = if ls'
             then [fs' ++ t ++ drop (length t) ls'']
             else []
      where
        (fs, ls) = splitAt n s
        fs' = map (\c -> if c == '?' then 'a' else c) fs
        ls' = all (\(s1, s2) ->
                     (s1 == '?' || s1 == s2)) $ zip ls t
        ls'' = map (\c -> if c == '?' then 'a' else c) ls


Measured memory_bytes: 764
#![allow(non_snake_case,unused_imports,dead_code)]
use std::io::Read;
use std::cmp::max;
use std::cmp::min;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::BinaryHeap;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut buf_it = buf.split_whitespace();

    let N = buf_it.next().unwrap().parse::<usize>().unwrap();
    let mut A = (0..N).map(|_| buf_it.next().unwrap().parse::<isize>().unwrap()).collect::<Vec<_>>();

    let mut ans = 0;
    let mut p = 0;
    for i in 0..N{
        let a = A.pop().unwrap();
        if a<p{
            ans = -1;
            break;
        } else if a > p{
            ans += a;
            p = a;
        }
        p -= 1;
    }
    if p != -1{ ans = -1;}
    println!("{}",ans);
}

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

int	main()
{
	int	N, M;
	while (cin >> N >> M) {
		if (N == 0 && M == 0) break;
		vector<vector<int>>	cost(N + 1, vector<int>(256, -1));
		cost[0][128] = 0;
		vector<int>	C_vec(M), x_vec(N);
		for (int i = 0; i < M; ++i)
			cin >> C_vec.at(i);
		for (int i = 0; i < N; ++i)
			cin >> x_vec.at(i);
		int	min_cost = -1;
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < 256; ++j) {
				if (cost[i][j] == -1) continue;
				for (int k = 0; k < M; ++k) {
					int	l = j + C_vec.at(k);
					if (l < 0) l = 0;
					if (l > 255) l = 255;
					int	cost_l = (l - x_vec.at(i)) * (l - x_vec.at(i));
					cost_l += cost[i][j];
					if (cost[i + 1][l] == -1 || cost[i + 1][l] > cost_l) {
						cost[i + 1][l] = cost_l;
						if (i + 1 == N) {
							if (min_cost == -1 || min_cost > cost_l)
								min_cost = cost_l;
						}
					}
				}
			}
		}
		cout << min_cost << endl;
	}
}



Measured memory_bytes: 23820
#include <stdio.h>

int main(){
	int tmp,i=0,j,data[100],n,c=0,minj;
	scanf("%d",&n);
	while(i!=n){
		scanf("%d",&data[i]);
		i++;
	}

	for(i=0;i<=n-1;i++){
		minj = i;
		for(j=i;j<=n-1;j++){
			if(data[j] < data[minj]){
				minj = j;
			}
		}
		if(data[i] != data[minj])c++;
		tmp = data[i];
		data[i] = data[minj];
		data[minj] = tmp;
	}
	for(i=0;i<=n-1;i++){
		i <n-1 ? printf("%d ",data[i]):printf("%d\n",data[i]);
	}
	printf("%d\n",c);
	return 0;
}

Measured memory_bytes: 600
n = int(input())
s = [input() for _ in range(n)]
al = []
lst = []
for i in s:
    for j in i:
        if not j in al:
            al.append(j)
al = sorted(al)

for i in al:
    num = float('inf')
    for j in s:
        num = min(num, j.count(i))
    lst.append(num)

result = [al[i] * lst[i] for i in range(len(al))]

print(''.join(result))

Measured memory_bytes: 3064
def check(i,a,b)
  num = i.to_s.chars.map(&:to_i).sum
  if num >= a && num <= b
    return true
  else
    return false
  end
end
n,a,b = gets.chomp.split(' ').map(&:to_i)
i = 1
sum = 0
while i <= n
  if check(i,a,b)
    sum += i
  end
  i += 1
end
puts sum


Measured memory_bytes: 14396
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

const int N = 3;
const int NN = N*N;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };
const char dir[4] = { 'u','l','d','r' };


//n puzzle
struct Puzzle {
	int f[NN];
	int space;
	string path;
	Puzzle() :path("") {};

	bool operator<(const Puzzle &p)const {
		for (int i = 0; i < NN; i++) {
			if (f[i] == p.f[i])continue;
			return f[i] > p.f[i];
		}
		return false;
	}
	void input() {
		for (int i = 0; i < NN; i++) {
			cin >> f[i];
			if (f[i] == 0) {
				f[i] = NN;
				space = i;
			}
		}
	}
	void slide(int t) {
		swap(f[space], f[t]);
		space = t;
	}
};

bool is_target(const Puzzle &p) {
	for (int i = 0; i < NN; i++)
		if (p.f[i] != (i + 1))
			return false;
	return true;
}

string bfs(Puzzle s) {
	queue<Puzzle> q;
	map<Puzzle, bool> mp;
	Puzzle u, v;
	q.emplace(s);
	mp[s] = true;
	while (q.size()) {
		u = q.front(); q.pop();
		if (is_target(u))return u.path;
		int sx = u.space / N;
		int sy = u.space%N;
		for (int r = 0; r < 4; r++) {
			int tx = sx + dx[r];
			int ty = sy + dy[r];
			if (tx < 0 || ty < 0 || tx >= N || ty >= N)continue;
			v = u;
			v.slide(tx*N + ty);
			if (mp[v])continue;
			mp[v] = true;
			v.path += dir[r];
			q.emplace(v);
		}
	}
	return "unsolvable";
}

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

	Puzzle p;
	p.input();
	string ans = bfs(p);
	cout << ans.size() << endl;

	return 0;
}

Measured memory_bytes: 30604
inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
l = inp.shift().split(' ')
a = l.shift() * 1
b = l.shift() * 1 
x = l.shift() * 1
l = 0
r = 90
mid = 45
c = 0
S = a * a * b
if (S / 2 < x) {
    while (l<r) {
        s = S - (a * a * Math.tan(mid / 180 * Math.PI)) / 2 * a
        if (x < s) {
            l = mid
        } else {
            r = mid
        }
        mid = (l + r) / 2
        c++
        if (c>200) {
            break;
        }
    }    
    console.log(mid.toFixed(10))
} else {
    while (l<r) {
        s = (b * b * Math.tan(mid / 180 * Math.PI)) / 2 * a
        if (x < s) {
            r = mid
        } else {
            l = mid
        }
        mid = (l + r) / 2
        c++
        if (c>200) {
            break;
        }
    }  
    console.log((90 - mid).toFixed(10))
}

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
typedef signed long long ll;
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	cin >> x >> n >> m;
	i = 0;
	if(n+x < m) i = m - n - x;
	else if(m+x < n) i = n - m - x;
	else i = 0;
	cout << i << endl;
}

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


// type definitions
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

// macros
#define rep(i, a, b) for(int i=a; i<b; i++)
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define tr(c, it) for(auto it=(c).begin(); it!=c.end(); it++)
#define pb push_back
#define mp make_pair
#define bitcount __builtin_popcount
#define ispresent(c, x) ((c).find(x) != (c).end())
#define watch(x) cout<< (#x) << " is " << (x) <<"\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first<<32 | (p).second)

// template functions
template <typename T>
inline void printV(vector<T>& a) { rep(i, 0, sz(a)) { cout<<a[i]<<" "; } cout<<"\n"; }
template <typename T>
inline void printV(vector<T>& a, int n) { rep(i, 0, n) { cout<<a[i]<<" "; } cout<<"\n"; }
template <typename T>
inline void printpii(pair<T, T> p) { cout<<p.first<<" "<<p.second<<"\n"; }
template <typename T>
inline void printVV(vector<vector<T>>& a)
{
	rep(i, 0, sz(a)) {
		printV(a[i]);
	}
	cout<<"\n";
}

template <typename T>
inline void clearVV(vector<vector<T>>& a)
{
	for(auto& x:a) {
		x.clear();
	}
	a.clear();
}
template <typename T>
inline void assignVV(vector<vector<T>> &a, T val)
{
	for(int i=0; i<sz(a); i++) {
		for(int j=0; j<sz(a[i]); j++) {
			a[i][j]=val;
		}
	}
}



// constants
const long double eps = 1e-9;
const int inf = 5e8;
const int modn = 1e9+7;
const int MAX = 1e5;

vector<pair<ll, ll>> bags;
vector<vector<ll>> dp(MAX+10, vector<ll>(110));

ll solve(int w, int n)
{
	if(w<=0 or n<=0) return 0;
	if(dp[w][n]!=-1) return dp[w][n];
	
	ll &memo=dp[w][n];
	ll ans=0;
	ll tmp=0;
	if(w>=bags[n-1].first) {
		tmp=solve(w-bags[n-1].first, n-1)+bags[n-1].second;
	}
	ans=max(tmp, solve(w, n-1));
	return memo=ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Your code here
	int n, W;
	cin>>n>>W;
	assignVV(dp, (ll)-1);
	for(int i=0; i<n; i++) {
		ll a, val;
		cin>>a>>val;
		bags.emplace_back(a, val);
	}
	ll ans=solve(W, n);
	cout<<ans<<"\n";
    return 0;
}



Measured memory_bytes: 90112
/** Author: Dwai
 *  Omae wa mou shindeiru!
**/

#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define all(a) (a).begin(),(a).end()
#define fr(i,a,b) for (i = a; i <= b; i++)
#define frr(i,a,b) for (i = a; i >= b; i--)
#define rep(i,n) for (i = 0 ; i < n; i++)
#define repr(i,n) for (i = n - 1; i >= 0; i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define flushinput   cin.ignore(numeric_limits<streamsize>::max(),'\n');

void debug_out() { cerr << endl; }

void clock_out(){
  cerr<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s\n";
}

void fileio(){
  freopen("/home/dwai/Desktop/cp/input.txt","r", stdin);
  freopen("/home/dwai/Desktop/cp/output.txt", "w", stdout);
  freopen("/home/dwai/Desktop/cp/debug.txt", "w", stderr);
}

void ofileio(){
  freopen("input.txt","r", stdin);
  freopen("output.txt", "w", stdout); 
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << H;
  debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define fio() fileio()
#define ofio() fileio()
#define clock() clock_out()
#else
#define debug(...) 42
#define fio() 42
#define ofio() ofileio()
#define clock() 42
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef map<ll,ll> mll;

int IT_MAX = 1 << 20;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

void solve(){
	ll n,m;
	cin>>n>>m;
	priority_queue<ll,vector<ll>> q;
	ll i;
	rep(i,n)
	{
		ll x;cin>>x;
		q.push(x);
	}
	while(m--)
	{
		ll z=q.top();
		q.pop();
		q.push(z/2);
	}

	ll res=0;
	while(!q.empty())
	{
		res+=q.top();
		q.pop();
	}
	cout<<res;
}

int main(){
	fast

	solve();
	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

struct LazySegTree{
    int n; vector<int> dat,lazy;
    //初期化
    LazySegTree(int _n){
        n=1;
        while(n<_n) n*=2;
        dat=vector<int>(2*n-1,0);
        lazy=vector<int>(2*n-1,0);
    }

    void setLazy(int k, int v){
        lazy[k] = v;
        dat[k] = v;
    }

    void push(int k, int l, int r){
        if(lazy[k]!=0){
            setLazy(2*k+1,lazy[k]);
            setLazy(2*k+2,lazy[k]);
        }
        lazy[k]=0;
    }

    void fix(int k, int l, int r){
        dat[k] = dat[2*k+1]&dat[2*k+2];
    }

    ll merge(ll x, ll y){
        return x&y;
    }

    //内部的に投げられるクエリ
    void _update(int a, int b, ll x, int k, int l, int r){
        if(r<=a || b<=l) return;
        if(a<=l && r<=b){
            setLazy(k,x);
            return;
        }

        push(k,l,r);
        _update(a,b,x,2*k+1,l,(l+r)/2);
        _update(a,b,x,2*k+2,(l+r)/2,r);

        fix(k,l,r);
    }
    //[a,b)をxに更新
    void update(int a, int b, ll x){
        return _update(a,b,x,0,0,n);
    }

    //内部的に投げられるクエリ
    int _query(int a, int b, int k, int l, int r){
        if(r<=a || b<=l) return 1;
        if(a<=l && r<=b) return dat[k];

        push(k,l,r);
        int vl=_query(a,b,2*k+1,l,(l+r)/2);
        int vr=_query(a,b,2*k+2,(l+r)/2,r);
        return merge(vl,vr);
    }
    //[a,b)
    ll query(int a, int b){
        return _query(a,b,0,0,n);
    }
};

const int N = 200000;
vector<int> C[N],Q[N];

int main(){
    int n,m,q;
    scanf(" %d %d %d", &n, &m, &q);

    vector<int> d(m),a(m),b(m);
    rep(i,m) scanf(" %d %d %d", &d[i], &a[i], &b[i]);

    vector<int> e(q),s(q),t(q);
    rep(i,q) scanf(" %d %d %d", &e[i], &s[i], &t[i]);

    vector<int> v;
    rep(i,m) v.pb(d[i]);
    rep(i,q) v.pb(e[i]);
    sort(all(v));
    v.erase(unique(all(v)), v.end());

    int V = v.size();
    rep(i,m){
        int idx = lower_bound(all(v), d[i])-v.begin();
        C[idx].pb(i);
    }
    rep(i,q){
        int idx = lower_bound(all(v), e[i])-v.begin();
        Q[idx].pb(i);
    }

    LazySegTree st(n+1);

    vector<bool> ans(q);
    rep(i,V){
        for(const auto &ID:Q[i]) ans[ID] = st.query(s[ID], t[ID]);
        for(const auto &ID:C[i]) st.update(a[ID], b[ID], 1);
    }

    rep(i,q) printf("%s\n", (ans[i]?"Yes":"No"));
    return 0;
}



Measured memory_bytes: 23816
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<vector<int> > edges(n);
    for(int i=0; i<n-1; ++i){
        int a, b;
        cin >> a >> b;
        -- a;
        -- b;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }

    vector<int> cnt(2, 0);
    queue<pair<int, int> > q;
    vector<bool> check(n, false);
    q.push(make_pair(0, 0));
    q.push(make_pair(n-1, 1));
    check[0] = check[n-1] = true;

    while(!q.empty()){
        int curr = q.front().first;
        int i = q.front().second;
        q.pop();
        for(int next : edges[curr]){
            if(!check[next]){
                ++ cnt[i];
                q.push(make_pair(next, i));
                check[next] = true;
            }
        }
    }

    if(cnt[0] > cnt[1])
        cout << "Fennec" << endl;
    else
        cout << "Snuke" << endl;

    return 0;
}


Measured memory_bytes: 5888
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string tmp;
    cin>>tmp;
    string s("CODEFESTIVAL2016");
    int n = s.size();
    int num = 0;
    for(int i =0 ;i<n;++i)
        if(tmp[i]!=s[i])num++;
    cout<<num<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(long long i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define infy 2e18
#define five 100005;
#define six 1000005;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//___________________________________________________________________________________________________________________________________________________________
const int N = five;
int dp[N];
int h[N];
int n,k;
int f(int i)
{
       if(i<0){return mod;}
       if(i==0){return 0;}
       if(dp[i]!=-1){return dp[i];}
       dp[i] = mod;
       fri(j,0,k){
              if(i-j-1<0){continue;}
              dp[i] = min(dp[i],f(i-j-1)+abs(h[i]-h[i-j-1]));
       }
       return dp[i];
}
int main(){
       int n;
       cin>>n>>k;
       memset(dp,-1,sizeof dp);
       arrin(h,n);
       cout<<f(n-1)<<endl;
}


Measured memory_bytes: 4480
H, W = map(int,input().split())
S = [input() for _ in range(H)]
reach = [[0 for _ in range(W+1)] for _ in range(H+1)]

for i in range(H):
  for j in range(W):
    if(S[i][j] == "#"):
      reach[i][j] = "#"
      if(reach[i-1][j-1] != "#"):
        reach[i-1][j-1] += 1
      if(reach[i-1][j] != "#"):
        reach[i-1][j] += 1
      if(reach[i-1][j+1] != "#"):
        reach[i-1][j+1] += 1
      if(reach[i][j-1] != "#"):
        reach[i][j-1] += 1
      if(reach[i][j+1] != "#"):
        reach[i][j+1] += 1
      if(reach[i+1][j-1] != "#"):
        reach[i+1][j-1] += 1
      if(reach[i+1][j] != "#"):
        reach[i+1][j] += 1
      if(reach[i+1][j+1] != "#"):
        reach[i+1][j+1] += 1
        
for r in reach[:-1]:
  print("".join(list(map(str, r[:W]))))

Measured memory_bytes: 3188
#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<cmath>
#include<climits>
using namespace std;

int main(){
  
  int n; cin >> n;
  vector<int> w(n);
  
  for (int i=0; i<n; i++){
    cin >> w[i];
  }
  
  int m = INT_MAX;
  
  for (int t=0; t<n-1; t++){
    int s1 = 0;
    int s2 = 0;
    
    for (int i=0; i<=t; i++){
      s1 += w[i];
    }
    
    for (int i=t+1; i<n; i++){
      s2 += w[i];
    }
    
    m = min(m, abs(s1-s2));
  }
  
  cout << m << endl;
 
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main (){
	int health;
	int damage;
	int valueHit = 0; 
	
	scanf("%d %d", &health, &damage);
	
	health%damage == 0?printf("%d", health/damage) : printf("%d", health/damage +1);
	
	
	return 0;
}

Measured memory_bytes: 1728
<?php

$input = STDIN;

$line = explode(" ",trim(fgets($input)));

$stack = array();

foreach($line as $op){
    if($op == "+") {
        $b = array_pop($stack);
        $a = array_pop($stack);
        array_push($stack, $a + $b);
    }
    elseif($op == "-") {
        $b = array_pop($stack);
        $a = array_pop($stack);
        array_push($stack, $a - $b);
    }
    elseif($op == "*") {
        $b = array_pop($stack);
        $a = array_pop($stack);
        array_push($stack, $a * $b);
    }
    else {
        array_push($stack, $op);
    }
}

print array_pop($stack). "\n";


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

int main(void) {
  string S;
  cin >> S;
  int ans = 0;
  for (int i = 1; i < S.length(); i++) {
    if (S[i - 1] != S[i]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
def pff(m):
    pf = {}
    for i in range(2, int(m ** 0.5) + 1):
        while m % i == 0:
            pf[i] = pf.get(i, 0) + 1
            m //= i
    if m > 1: pf[m] = 1
    return pf
def examC():
    N, P = LI()
    d = pff(P)
#    print(d)
    ans = 1
    for key,i in d.items():
        ans *= key**(i//N)
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examC()


Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
double p[3000];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)cin>>p[i];
    vector<vector<double>> dp(n+1,vector<double>(n+1,0.0));
    dp[0][0] = 1.0;
    for(int i=1;i<=n;i++)dp[i][0]=dp[i-1][0]*(1.0-p[i-1]);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=i;j++){
            dp[i][j] = dp[i-1][j]*(1.0-p[i-1])+dp[i-1][j-1]*(p[i-1]);
        }
    }
    double ans = 0.0;
    for(int i=((n/2)+1);i<=n;i++){
        ans+=dp[n][i];
    }
    cout<<fixed<<setprecision(12)<<ans<<endl;
    return 0;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1LL << 60;
int N, M, a, b, c; long long dist[109][109];
int main() {
	scanf("%d%d", &N, &M);
	for(int i = 0; i < N; i++) {
		fill(dist[i], dist[i] + N, inf);
		dist[i][i] = 0;
	}
	for(int i = 0; i < M; i++) {
		scanf("%d%d%d", &a, &b, &c);
		dist[a][b] = c;
	}
	bool flag = false;
	for(int i = 0; i < N; i++) {
		for(int j = 0; j < N; j++) {
			for(int k = 0; k < N; k++) {
				dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
			}
			if(dist[j][j] != 0) flag = true;
		}
	}
	if(flag) puts("NEGATIVE CYCLE");
	else {
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < N; j++) {
				if(j) printf(" ");
				if(dist[i][j] >= 1LL << 40) printf("INF");
				else printf("%lld", dist[i][j]);
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 3248
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>

const int INT_INF = 1000000000;                 // 10^9
const long long LONG_INF = 1000000000000000000; // 10^18

using namespace std;

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

    for (int i = 0; i < 3; i++)
    {
        if (str[i] == '7')
        {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}

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

#define ll long long
#define ii pair<int, int>
#define dd pair<double, double>
#define pb(i) push_back(i)
const double PI = 3.14159265359;
const int inf = 1e9+77;
const int mod = 1e9+7;
const double eps = 1e-7;
//int dir1[8] = {0, 0, 1, -1, 1, -1, 1, -1};
//int dir2[8] = {1, -1, 0, 0, 1, 1, -1, -1};
int dir1[4] = {0, 0, 1, -1};
int dir2[4] = {1, -1, 0, 0};

int n;
vector< set<ii> > p;
vector<vector<int> > adj;
vector<bool> visited;
vector<int> dist;

void bfs(int u)
{
    int ind = u;
    int i, j;

    fill(visited.begin(), visited.end(), false);
    visited[u] = true;

    fill(dist.begin(), dist.end(), -1);
    dist[u] = 0;

    queue<int> q;
    q.push(u);
    while(!q.empty())
    {
        u = q.front();
        q.pop();

        for(i = 0; i < adj[u].size(); i++)
        {
            int v = adj[u][i];
            if(!visited[v])
            {
                visited[v] = true;
                dist[v] = dist[u] + 1;
                q.push(v);
            }
        }
    }

    for(int i = 1; i <= n; i++)
        if(dist[i] != -1)
        {
            int a = ind, b = i;
            if(a > b)
                swap(a, b);
            p[dist[i]].insert(ii(a, b));
        }
}

int main()
{
    int i, j;

    int x, y;
    cin >> n >> x >> y;

    adj.resize(n+5);
    for(i = 1; i < n; i++)
    {
        adj[i].pb(i+1); 
        adj[i+1].pb(i);
    }

    adj[x].pb(y);
    adj[y].pb(x);

    p.resize(n+5);
    dist.resize(n+5);
    visited.resize(n+5);
    for(i = 1; i <= n; i++)
        bfs(i);
    

    for(i = 1; i < n; i++)
        cout << p[i].size() << '\n';
    

}

Measured memory_bytes: 97600
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <complex>
#include <vector>
#include <cmath>

using namespace std;

#define MAXN (14)
#define INF  (1<<29)
#define X    real()
#define Y    imag()

typedef complex<double> P;

template<class T>
inline T Sq(T x) { return x*x; }

inline double getDist(P, P);
struct Segment {
  P s, t;
  double d;
  Segment() {}
  Segment(P s, P t) : s(s), t(t) { d = getDist(s, t); }
};

inline double getDist(P a, P b) { return sqrt(Sq(a.X-b.X)+Sq(a.Y-b.Y)); }
inline double getDist(Segment sg) { return sqrt(Sq(sg.s.X-sg.t.X)+Sq(sg.s.Y-sg.t.Y)); }

int n;
double dist[MAXN][2][MAXN][2]; // seg s: 0, t: 1
double dp[1<<MAXN][MAXN][2];
Segment seg[MAXN];

int main() {
  
  int tcase = 1;
  double x1, y1, x2, y2;
  double allseglen;
  
  while(cin >> n, n) {
    
    allseglen = 0.0;
    
    for(int i=0; i<n; i++) {
      cin >> x1 >> y1 >> x2 >> y2;
      seg[i] = Segment(P(x1, y1), P(x2, y2));
      allseglen += seg[i].d;
    }
    
    for(int i=0; i<n; i++) {
      for(int j=0; j<n; j++) {
	
	if(i == j) {
	  for(int ii=0; ii<2; ii++) {
	    for(int jj=0; jj<2; jj++) {
	      if(ii == jj) { dist[i][ii][j][jj] = 0; }
	      else { dist[i][ii][j][jj] = seg[i].d; }
	    }
	  }
	  
	  continue;
	}
	
	dist[i][0][j][0] = getDist(seg[i].s, seg[j].s);
	dist[i][0][j][1] = getDist(seg[i].s, seg[j].t);
	dist[i][1][j][0] = getDist(seg[i].t, seg[j].s);
	dist[i][1][j][1] = getDist(seg[i].t, seg[j].t);
	
      }
    }
        
    for(int i=0; i<(1<<n); i++)
      for(int j=0; j<n; j++)
	for(int k=0; k<2; k++)
	  dp[i][j][k] = INF;
      
    for(int i=0; i<n; i++)
      for(int j=0; j<2; j++)
	dp[(1<<n)-1][i][j] = 0;
    
    for(int S=(1<<n)-1; S >= 0; S--)
      for(int v=0; v<n; v++)
	for(int u=0; u<n; u++)
	  for(int i=0; i<2; i++)
	    for(int j=0; j<2; j++)
	      if(!(S>>u & 1))
		dp[S][v][j] = min(dp[S][v][j], dp[S|1<<u][u][i]+dist[u][(i+1)&1][v][j]);
    
    double ans = INF;
    for(int i=0; i<n; i++)
      for(int j=0; j<2; j++)
	ans = min(ans, dp[0][i][j]);
    
    printf("Case %d: %f\n", tcase++, ans + allseglen);
  }
  
  return 0;
}

Measured memory_bytes: 4828
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

    int a, b;
    cin >> a >> b;

    rep1(i, 2000){
        if(i*8/100==a && i/10==b) {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		int[] B = new int[N];
		int[] C = new int[N-1];
		
		int ans = 0;
		
		for(int i=0; i < N; i++) {
			A[i] = sc.nextInt() - 1;
		}
		for(int i=0; i < N; i++) {
			B[i] = sc.nextInt();
		}
		for(int i=0; i < N-1; i++) {
			C[i] = sc.nextInt();
		}
		
		ans += B[A[0]];
		
		for(int i=1; i < N; i++) {
			ans += B[A[i]];
			if(A[i] - A[i-1] == 1) {
				ans += C[A[i-1]];
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
int main(){
  int a,b;
  double t;
  cin >> a >> b >> t;
  int biscuits=0;
  int A=a;
  while(a<t+0.5){
    biscuits += b;
    a += A;
    //cout << a << endl;
  }
  cout << biscuits << endl;
  return 0;
}

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

int main() {
    auto n = std::size_t(0);
    auto m = 0;
    std::cin >> n >> m;

    auto adj = std::vector<std::vector<unsigned char>>(n, std::vector<unsigned char>(n, 0));
    for (auto i_ = 0; i_ < m; ++i_) {
        auto a = std::size_t(0);
        auto b = std::size_t(0);
        std::cin >> a >> b;
        adj[a - 1][b - 1] = 1;
        adj[b - 1][a - 1] = 1;
    }

    auto perm = std::vector<unsigned char>();
    perm.resize(n);
    std::iota(perm.begin(), perm.end(), 0);

    auto counter = 0;
    do {
        auto itr = perm.begin();
        while ((itr + 1 != perm.end()) && (adj[*itr][*(itr + 1)] != 0)) itr++;

        if (itr + 1 == perm.end()) counter++;
    } while (std::next_permutation(perm.begin() + 1, perm.end()));

    std::cout << counter << std::endl;
    return 0;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "15" ].parse.expand.solve == 60 );
	assert( [ "1000000" ].parse.expand.solve == 266666333332 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	return tuple( n );
}

auto solve( long n )
{
	auto ans = 0L;
	foreach( i; 1L .. n + 1 )
	{
		if( i % 3 != 0 && i % 5 != 0 ) ans += i;
	}
	return ans;
}


Measured memory_bytes: 2768