akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void){
    int N,l,i,d;scanf("%d",&N);
    int A[N],B[N],E[N];
    for(i=0;i<=N-1;i++){
      scanf("%d",&A[i]);
      d = A[i];
      E[d-1] = i+1;
    }
    for(l=0;l<=N-1;l++)printf("%d ",E[l]);
    return 0;
}

Measured memory_bytes: 1536
#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)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int k; cin >> k;
    set<string> st;
    rep(i, s.size()) {
        for (int j=1; j<=k; ++j) {
            string substr = "";
            for (int l=i; l<min(i+j, (int)s.size()); ++l) substr += s[l];
            st.insert(substr);
        }
    }
    int cnt = 0;
    for (auto itr = st.begin(); itr != st.end(); ++itr) {
        cnt++;
        if (cnt == k) cout << *itr << endl;
        // cout << *itr << endl;
    }
    return 0;
}

Measured memory_bytes: 1664
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            char[][] a = new char[n][n];
            long P = 37, Q = 47;
            long[] powP = new long[n + 1], powQ = new long[n + 1];
            powP[0] = powQ[0] = 1;
            for (int i = 1; i <= n; i++) {
                powP[i] = powP[i - 1] * P;
                powQ[i] = powQ[i - 1] * Q;
            }
            for (int i = 0; i < n; i++) {
                a[i] = in.next().toCharArray();
            }

            long[][] hashRow = new long[n][n];
            long[][] hashCol = new long[n][n];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    for (int k = 0; k < n; k++) {
                        hashRow[i][k] += a[i][j] * powP[(j - k + n) % n];
                        hashCol[j][k] += a[i][j] * powP[(i - k + n) % n];
                    }
                }
            }

            int ans = 0;
            for (int A = 0; A < n; A++) {
                for (int B = 0; B < n; B++) {
                    boolean ok = true;
                    for (int i = 0; i < n; i++) {
                        ok &= hashRow[(i + A) % n][B] == hashCol[(i + B) % n][A];
                    }
                    ans += ok ? 1 : 0;
                }
            }
            out.println(ans);
        }

    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
        }

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

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                String line = null;
                try {
                    line = br.readLine();
                } catch (IOException e) {
                }
                st = new StringTokenizer(line);
            }
            return st.nextToken();
        }

    }
}



Measured memory_bytes: 28160
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   	ll n, k;
   	cin >> k>>n;
   	ll a[n];
   	for (int i = 0; i < n; ++i)
   	{
   		cin >> a[i];
   	}
   	ll ans=1000000000000000;
   	for (int i = 0; i < n; ++i)
   	{
   		ans=min((k-a[i]+a[(i+n-1)%n])%k, ans);
   	}
   	cout << ans;
    return 0;
}

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

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

	int n;
	while(cin >> n && n != 0){
		int k[100010];
		int m = 0;
		int cnt = 0;
		for(int i = 0; i < n; ++i){
			cin >> k[i];
			m = max(m, k[i]);
			if(k[i] != 0){
				cnt++;
			}
		}

		if(m <= 1){
			cout << "NA" << endl;
		}
		else {
			cout << cnt + 1 << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
#define ll long long
#define eps 1e-8
#define INF 0x3f3f3f3f
#define pb push_back
#define endl '\n'
#define IO ios::sync_with_stdio(false)
using namespace std;
const ll maxn = 1e6 + 5;
ll n,m;
int main(){
    cin >> n >> m;
    cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<endl;
#define printii(x)  for(auto it=x.begin();it!=x.end();it++) cout<<*it.F<<' '<<*it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)
vi r,g,b;
ll ans = 0,n,x,t,m;
string s;


void solve(){
    for(int i=0;i<(int)r.size();i++){
        for(int j=0;j<(int)g.size();j++){
            ll x = r[i]+g[j];
            if(x%2==0){
                if(lower_bound(all(b),x/2)!=b.end()){

                    if(*lower_bound(all(b),x/2)==x/2){
                        ans--;
                    }
                }
            }
            if((2*g[j]-r[i]<n)&&(2*g[j]-r[i]>=0)){
                x = 2*g[j]-r[i];
                if(lower_bound(all(b),x)!=b.end()){

                    if(*lower_bound(all(b),x)==x){
                        ans--;
                    }
                }
            }
            if((2*r[i]-g[j]<n)&&(2*r[i]-g[j]>=0)){
                x = 2*r[i]-g[j];
                if(lower_bound(all(b),x)!=b.end()){
                    
                    if(*lower_bound(all(b),x)==x){
                        ans--;
                    }
                }
            }
        }
    }
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    cin>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='R'){
            r.pb(i);
        }
        else if(s[i]=='G'){
            g.pb(i);
        }
        else{
            b.pb(i);
        }
    }
    ans = (ll)r.size() * (ll)g.size() * (ll)b.size();
    solve();
    cout<<ans;
    return 0;
}







Measured memory_bytes: 3700
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections

def combinations(n, r):
    res = 1
    for i in xrange(n - r + 1, n + 1):
        res *= i
    for i in xrange(2, r + 1):
        res /= i
    return res

N, A, B = map(int, raw_input().split())
v = map(int, raw_input().split())
v.sort(reverse = True)

cnt = collections.Counter(v)

mx = sum(v[:A]) 
comb = 0
for n in xrange(A, B + 1):

    tmp_cnt = collections.Counter(v[:n])
    tmp = 1
    for key, val in tmp_cnt.items():
        tmp *= combinations(cnt[key], val)

    if A*sum(v[:n]) == n*mx:
        comb += tmp 

print "%.10f" % (mx*1.0/A)
print comb 


Measured memory_bytes: 4368
c=0
def f(a,x,y):
    if 0<=x<12 and 0<=y<12 and a[y][x]=='1':
        a[y][x]='0'
        for dx,dy in [[-1,0],[1,0],[0,-1],[0,1]]:f(a,x+dx,y+dy)
 
while 1:
    try:
        if c:input()
    except:break
    a = [list(input()) for _ in [0]*12]
    c=1;b=0
    for i in range(12):
        for j in range(12):
            if a[j][i]=='1':
                b+=1;f(a,i,j)
    print(b)


Measured memory_bytes: 5580
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
using namespace std;

#define fi first
#define se second
typedef long long LL;
typedef long double LD;

string s;

int main(){
    cin >> s;
    int N=s.length();

    int i,res=2*N; char c;
    for (c='a'; c<='z'; c++){
        int lstp=N,cr=0;
        for (i=N-1; i>=0; i--){
            if (s[i]==c) lstp=i;
            else cr=max(cr,lstp-i);
        }

        res=min(res,cr);
    }

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


Measured memory_bytes: 256
n = int(input())
v = list(map(int, input().split()))
m = 1
gf = []
gp = []


def gcd(x, y):
    if x < y:
        x += y
        y = x - y
        x -= y

    while y > 0:
        r = x % y
        x = y
        y = r

    return x


gf.append(v[0])
for i in range(n-1):
    gf.append(gcd(gf[i], v[i+1]))

gp.append(v[n-1])
for i in range(n-1):
    gp.append(gcd(gp[i], v[n-2-i]))

m = gp[n-2]

for i in range(n-1):
    b = gcd(gf[i], gp[n-3-i])
    if m < b:
        m = b
if m < gf[n-2]:
    m = gf[n-2]

print(m)


Measured memory_bytes: 14052
#include <algorithm>
#include <iostream>
#include <queue>

using namespace std;
const int N = 2e5 + 5;

int n, fa[N], dsu[N];
int cnt[N][2];

struct item {
	int c0, c1, idx;
	bool operator < (const item& t) const {
		return c0 * 1ll * t.c1 < c1 * 1ll * t.c0;
	}
};
priority_queue<item> pq;

int find(int x) {
	return x == dsu[x] ? x : dsu[x] = find(dsu[x]);
}

signed main() {
	ios::sync_with_stdio(false);
	
	cin >> n;
	for (register int i = 2; i <= n; i++)
		cin >> fa[i];
	for (register int i = 1, val; i <= n; i++)
		cin >> val, cnt[i][val]++;
	for (register int i = 1; i <= n; i++)
		dsu[i] = i;
	
	long long ans = 0;
	for (register int i = 2; i <= n; i++)
		pq.push({cnt[i][0], cnt[i][1], i});
	
	while (!pq.empty()) {
		item cur = pq.top(); pq.pop();
		int x = find(cur.idx), c0 = cur.c0, c1 = cur.c1;
		
		if (cnt[x][0] != c0 || cnt[x][1] != c1)
			continue;
		
		int y = find(fa[x]);
		ans += cnt[y][1] * 1ll * cnt[x][0];
		cnt[y][0] += cnt[x][0];
		cnt[y][1] += cnt[x][1];
		
		dsu[x] = y;
		if (y > 1) pq.push({cnt[y][0], cnt[y][1], y});
	}
	
	cout << ans << endl;
	return 0;
}

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




int main(){

	int x;
	cin>>x;
	int ans = 0;
	ans += (x/500)*1000;
	x = (x%500);
	ans += 5*(x/5);
	cout<<ans<<endl;
	
	
	
	
	return 0;
  
}

Measured memory_bytes: 256
import numpy as np

N = int(input())
Ls = list(map(int, input().split()))

result = 0
tmp = []
for i, L1 in enumerate(Ls):
    for j, L2 in enumerate(Ls[i+1:]):
        j+=1+i
        if L1==L2 or len(Ls)<=j:
            continue
        if i==j:
            continue
        for k, L3 in enumerate(Ls[j+1:]):
            k+=1+j
            if L1==L3 or L2==L3:
                continue
            if len(Ls)<=k:
                continue
            if i==k or j==k:
                continue
            tri = [L1,L2,L3]
            arg = np.argmax(tri)
            max_ = 0
            residual = 0
            for l, length in enumerate(tri):
                if arg == l:
                    max_+=length
                else:
                    residual+=length
            if max_<residual:
                result+=1
print(result)


Measured memory_bytes: 27120
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String input = null;
		try {
			input = br.readLine();

		} catch (IOException e) {
		}
		int n = Integer.parseInt(input);
		try {
			input = br.readLine();
		} catch (IOException e) {
		}
		String[] inputs = input.split(" ");
		/*
		 int min = Integer.parseInt(inputs[0]);
		 int max = Integer.parseInt(inputs[1]);
		 int sum = Integer.parseInt(inputs[2]);
		
		 上のinput.split(" ");で（）内を並べるというのは
		
		
		 最後の答えとして並べるという意味ではなく、
		
		
		 計算のために３．５．７…みたいに並べてるだけであって、
		 答えを空白で区切って答えろという問題の答えは、
		
		
		 System.out.println(なんとか  +  " " + なんちゃら)
		
		
		 ということを忘れてはいけない！
		*/
		long sum = 0;
		int max = -1000000;
		int min = 1000000;
		for (int i = 0; i < n; i++) {
			sum = sum + Integer.parseInt(inputs[i]);
			int num = Integer.parseInt(inputs[i]);
			if (max < num) {
				max = num;
			}

			if (min > num) {
				min = num;
			}
		}
		System.out.println(min + " " + max + " " + sum);
	}
}


Measured memory_bytes: 28704
s=input()
t=input()
s_len=len(s)
t_len=len(t)
if(s.islower()==True and t.islower()==True):
    if(1<=s_len and 10>=s_len):
        if(s==t[0:s_len]):
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')

Measured memory_bytes: 61744
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ
int main()
{
    int a, b;
    cin >> a >> b;
    cout << max(a + b, max(a - b, a * b));
}

Measured memory_bytes: 256
class PriorityQueue
  attr_reader :size

  def initialize(order: :asc)
    @size = 0
    @nodes = []
  end

  def empty?
    @size.zero?
  end

  def push(node)
    index = size
    @size += 1

    while index > 0
      parent = (index - 1) / 2

      break if @nodes[parent].last <= node.last

      @nodes[index] = @nodes[parent]
      index = parent
    end

    @nodes[index] = node
  end

  alias_method :<<, :push

  def pop
    node = @nodes.first
    root = @nodes[size - 1]
    @size -= 1
    index = 0

    while index * 2 + 1 < @size
      left = 2 * index + 1
      right = left + 1

      if right < size && @nodes[right].last < @nodes[left].last
        left = right
      end

      break if @nodes[left].last >= root.last

      @nodes[index] = @nodes[left]
      index = left
    end

    @nodes[index] = root
    node.first
  end

  def top
    @nodes.first
  end
end

N, M = gets.split.map(&:to_i)

queries = N.times.map { gets.split.map(&:to_i) }

pque_day = PriorityQueue.new
pque_value = PriorityQueue.new

queries.each do |q|
  node = [q, q.first]
  pque_day.push(node)
end

ans = 0

1.upto(M) do |m|
  while !pque_day.empty? && pque_day.top.first.first <= m
    e = pque_day.pop
    pque_value.push([e, -e.last])
  end

  if !pque_value.empty?
    e = pque_value.pop
    ans += e.last
  end
end

puts ans


Measured memory_bytes: 16580
#include<bits/stdc++.h>
using namespace std;
#define maxn 100020
#define rep(i,l,r) for(register int i = l ; i <= r ; i++)
#define repd(i,r,l) for(register int i = r ; i >= l ; i--)
#define rvc(i,S) for(register int i = 0 ; i < (int)S.size() ; i++)
#define rvcd(i,S) for(register int i = ((int)S.size()) - 1 ; i >= 0 ; i--)
#define pb push_back
#define prev prev_
#define stack stack_
#define inf 0x3f3f3f3f

typedef long long ll;
ll k;
char ch[maxn];

int main(){
	scanf("%s",ch + 1);
	int n = strlen(ch + 1);
	cin >> k;
	rep(i,1,n){
		if ( ch[i] != '1' ) {
			cout<<ch[i]<<endl;
			break;
		}
		if ( i == k ){ cout<<ch[i]<<endl; break;  }
	}
}


Measured memory_bytes: 256
N = int(input())
levels = list(map(int, input().split()))
#print(levels)
levels.sort()
#print(levels)

divid_number = int(N/2)
#print(levels[divid_number-1])
#print(levels[divid_number])
print(levels[divid_number]-levels[divid_number-1])



Measured memory_bytes: 14008
import java.util.*;

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

        int ab = Math.abs(a-b);
        int ac = Math.abs(a-c);
        int ad = Math.abs(a-d);
        int ae = Math.abs(a-e);
        int bc = Math.abs(b-c);
        int bd = Math.abs(b-d);
        int be = Math.abs(b-e);
        int cd = Math.abs(c-d);
        int ce = Math.abs(c-e);
        int de = Math.abs(d-e);

        if((ab<=k)&&(ac<=k)&&(ad<=k)&&(ae<=k)&&(bc<=k)&&(bd<=k)&&(be<=k)&&(cd<=k)&&(ce<=k)&&(de<=k)){
            System.out.println("Yay!");
            
        }else{
            System.out.println(":(");
        }
       
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
#define endl "\n"
using namespace std;
const ll N=500010;

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

    ll n;
    cin>>n;
    ll ar[n];
    for(int i=0;i<n;++i){
        cin>>ar[i];
    }
    sort(ar,ar+n);
    reverse(ar,ar+n);
    priority_queue<pi> s;
    s.push(mp(ar[0],ar[0]));
    ll ans=0;
    for(ll i=1;i<n;++i){
        pi ch=s.top();
        s.pop();
        ans+=ch.first;
        s.push(mp(ar[i],ch.first));
        s.push(mp(ar[i],ch.second));
    }
    cout<<ans;

    return (0);
}


Measured memory_bytes: 8988
import java.util.*;
public class Main{
    public static void main(String[] args){
	Scanner kbd = new Scanner(System.in);
	int a = kbd.nextInt();
	int b = kbd.nextInt();
	int c = kbd.nextInt();
	if(a<b && b<c)
	    System.out.println("Yes");
	else 
	    System.out.println("No");
    }
}

Measured memory_bytes: 17160
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n,s=0;
	int ans=0;
	char ch;
	cin>>n;
	for(int i=1; i<=n; i++) {
		cin>>ch;
		if(ch=='I')
			s++;
		else
			s--;
		ans=max(ans,s);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
def solve():
    while 1:
        n, k = [int(_) for _ in input().split()]
        if n == 0: return

        A = [int(input()) for _ in range(n)]
        s = [0] * (len(A) + 1)
        for i in range(n):
            s[i + 1] = s[i] + A[i]

        ans = -1
        for l in range(n):
            r = l + k
            if r > n: break
            ans = max(ans, s[r] - s[l])
        print(ans)


if __name__ == '__main__':
    solve()



Measured memory_bytes: 13424
//include <bits/stdc++.h> 全ヘッダーのinclude
#include <iostream>
#include <cmath>

#define INF 1000001

bool cmpmin(long long *,long long );
bool cmpmax(long long *,long long );

long long h[INF][3]; //足場
long long dp[INF][3]; //結果配列

int main(void){
  int n;
  std::cin >> n;

  for(int i=0;i<n;i++){
    for(int j=0;j<3;j++){
      std::cin >> h[i][j];
      dp[i][j] = 0;
    }
  }


  for(int i=0;i<n;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        if(j!=k){
          cmpmax(&dp[i+1][k],dp[i][j]+h[i][k]);
        }
      }
    }
  }
  long long res = 0;;
  for(int i=0;i<3;i++){
    cmpmax(&res,dp[n][i]);
  }

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

bool cmpmin(long long *a,long long b){
  if(*a>b){
    *a = b;
    return true;
  } else {
    return false;
  }
}

bool cmpmax(long long *a,long long b){
  if(*a<b){
    *a = b;
    return true;
  } else {
    return false;
  }
}


Measured memory_bytes: 8448
import sys
input = sys.stdin.readline
n,T=(int(i) for i in input().split())
t=[int(i) for i in input().split()]
#print(n,T,t)
ans=0
if n==1:
  ans=T
else:
  for i in range(1,n):
    ans+=min(t[i]-t[i-1],T)
  ans+=T
    
print(ans)



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

int main() {
    int N_given,K_given;
    cin >> N_given;
    cin >> K_given;
    int H_given[N_given];
    rep(i,N_given){
        cin >> H_given[i];
    }
    
    ll dp[N_given];
    rep(i,N_given){
        dp[i] = INF;
    }
    
    dp[0] = 0;
    rep(i,N_given-1){
        rep(j,min(i+1+1,K_given+1)){
            dp[i+1] = min(dp[i+1],dp[i+1-j] + abs(H_given[i+1]-H_given[i+1-j]));
        }
    }
    
    cout << dp[N_given-1] << endl;
//    rep(i,N_given){
//        cout << dp[i];
//    }
//    cout<<endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
using namespace std;
int main(void){
    int a,b;
    cin  >> a;
    cin >> b;
    int d = a/b;
    int r = a % b;
    double  f = double(a) / double(b);
    cout << d;
    cout << " ";;
    cout << r;
    cout << " ";
    printf("%.5lf",f);
    cout << endl;
    
}


Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[100001],num[100001],n;
	long long sum=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	a[0]=a[n+1]=0;
	for(int i=0;i<=n;i++)
	{
		num[i]=fabs(a[i+1]-a[i]);
		sum+=num[i];
	}
	for(int i=1;i<=n;i++)
	{
		long long result=sum-num[i-1]-num[i]+fabs(a[i-1]-a[i+1]);
		printf("%lld\n",result);
	}
	return 0;
}

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

int main(){
int a,b,c,N;
int i[1000],j[1000],k[1000],r[1000];
int ans[300];
while(cin>>a>>b>>c){
for(int x=0;x<300;x++){
ans[x]=2;}
cin>>N;
for(int x=0;x<N;x++){
cin>>i[x]>>j[x]>>k[x]>>r[x];
if(r[x]==1){
ans[i[x]-1]=1;
ans[j[x]-1]=1;
ans[k[x]-1]=1;}}
for(int x=0;x<N;x++){
if(r[x]==0){
if(ans[i[x]-1]==1&&ans[j[x]-1]==1){ans[k[x]-1]=0;}
if(ans[j[x]-1]==1&&ans[k[x]-1]==1){ans[i[x]-1]=0;}
if(ans[k[x]-1]==1&&ans[i[x]-1]==1){ans[j[x]-1]=0;}}}
for(int x=0;x<a+b+c;x++){
cout<<ans[x]<<endl;}}}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
 
#define int long long
 
#define pii pair<int, int>
 
#define x1 x1228
#define y1 y1228
 
#define left left228
#define right right228
 
#define pb push_back
#define eb emplace_back
 
#define mp make_pair                                                                
                                                                                                                                        
#define ff first                                                                  
#define ss second   
 
#define matr vector<vector<int> > 
 
#define all(x) x.begin(), x.end()
 
 
using namespace std;
typedef long long ll; 
typedef long double ld; 
                                                                                                   
const int maxn = 300 + 7, mod = 998244353, MAXN = 1e6 + 7;
const double eps = 1e-9;
const ll inf = 1e18; 
mt19937 rnd(time(0));
int h, w, k;
char ms[maxn][maxn]; 
int ans[maxn][maxn];
int ptr = 1;  
set<int> X, Y; 

void solve() { 
    cin >> h >> w >> k; 
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> ms[i][j];
        }
    }
    X.insert(-1); 
    X.insert(h); 
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (ms[i][j] == '#') {
                X.insert(i);
            }
        }
    }    
    int lst = -1; 
    for (int i = 0; i < h; ++i) {
        int nxt = *X.upper_bound(i) - 1; 
//        cout << lst << " " << nxt << endl; 
        vector<int> yy; 
        for (int j = 0; j < w; ++j) {
            if (ms[i][j] == '#') {
                yy.pb(j);                 
            }
        }        
        if (yy.empty()) continue; 
        yy.pb(w); 
        int lst1 = -1; 
        for (int j = 0; j < (int)yy.size() - 1; ++j) {
            for (int k1 = lst1 + 1; k1 < yy[j + 1]; ++k1) {
                for (int l = lst + 1; l <= nxt; ++l) {
                    ans[l][k1] = ptr;
                }
            }
            lst1 = yy[j + 1] - 1; 
            ptr++;           
        } 
        lst = nxt; 
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cout << ans[i][j] << " "; 
        } 
        cout << '\n';
    }
}                                   
   
signed main() {
#ifdef LOCAL
    freopen("TASK.in", "r", stdin);
    freopen("TASK.out", "w", stdout);
#else 
    
#endif // LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20); 
    cout << fixed; 
    int t = 1; 
    for (int i = 0; i < t; ++i) {              
        solve();
    }
    return 0;
}  

Measured memory_bytes: 1664
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

random_device rnd;
mt19937 mt(rnd());
uniform_int_distribution<> rand100(1, 100);
uniform_int_distribution<> rand200(1, 200);

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    /*
    int n; n = rand100(mt); cout << n << endl;
    int sum = 0;
    int t[n]; rep(i, n) {t[i] = rand200(mt); sum += t[i]; cout << t[i] << " ";} cout << endl;
    int v[n]; rep(i, n) {v[i] = rand100(mt); cout << v[i] << " ";} cout << endl;
     */
    int n; cin >> n;
    int sum = 0;
    int t[n]; rep(i, n) {cin >> t[i]; sum += t[i];}
    int v[n]; rep(i, n) cin >> v[i];
    double maxv[2 * sum + 1];
    int now = 1;
    rep(i, n) {
        rep(j, 2 * t[i]) {
            maxv[now + j] = v[i];
        }
        now += 2 * t[i];
    }
    now = 0;
    rep(i, n - 1) {
        maxv[now + 2 * t[i]] = min(v[i], v[i + 1]);
        now += 2 * t[i];
    }
    maxv[0] = maxv[2 * sum] = 0;
    //rep(i, 2 * sum + 1) cout << i << " " << maxv[i] << endl;
    rrep(i, 1, 2 * sum + 1) { //上がりの条件
        maxv[i] = min(maxv[i], maxv[i - 1] + 0.5);
    }
    for (int i = 2 * sum - 1; i >= 0; --i) { //下がりの条件
        maxv[i] = min(maxv[i], maxv[i + 1] + 0.5);
    }
    //rep(i, 2 * sum + 1) cout << i << " " << maxv[i] << endl;
    double s = 0;
    cout << fixed << setprecision(5);
    rrep(i, 1, 2 * sum + 1) {
        s += (maxv[i] + maxv[i - 1]) * 0.25;
    }
    cout << s << endl;
}



Measured memory_bytes: 512
N = int(input())
A = [[]] + [list(map(int,input().split())) for _ in range(N)]

c = [0 for _ in range(N+1)]
p = []

for i in range(1, N+1):
    j = A[i][c[i]]
    if i==A[j][c[j]] and i<j:
        p.append((i,j))

ans = 0
while p:
    q = []
    for i,j in p:
        c[i] += 1
        c[j] += 1
        if c[i] < N-1:
            k = A[i][c[i]]
            if A[k][c[k]] == i:
                q.append((i,k))
        if c[j] < N-1:
            k = A[j][c[j]]
            if A[k][c[k]] == j:
                q.append((j,k))
    ans += 1
    p = q

ans = (ans if all(c[i]==N-1 for i in range(1, N+1)) else -1)
print(ans)

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

#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define FOR(i,l,r) for(long long i=l; i<r; i++)
#define FOR_REV(i,r,l) for(long long i=r; i>=l; i--)
#define pb push_back
#define mp make_pair


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

    long double s = n/(long double)3;
    long double vol = s*s*s;

    cout<<fixed<<vol<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll mod = 10e9+7;

#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl;

//----------------------------------------------------------------

int main(void) {
  string s;
  cin >> s;

  int a, b;
  a = (s[0]-'0')*10+(s[1]-'0');
  b = (s[2]-'0')*10+(s[3]-'0');

  int dec=0;
  dec = (a>0 && a<13)*2+(b>0 && b<13);

  switch(dec){
    case 0: prt("NA"); break;
    case 1: prt("YYMM") break;
    case 2: prt("MMYY") break;
    case 3: prt("AMBIGUOUS") break;
  }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    #define ll long long int
    #define loop(n) for(ll i=0;i<n;i++)
    using namespace std;
    int main()
    {
        ll n;
        bool flag=1;
        cin>>n;
        ll max=0;
        string s;
        map<string,ll>mp;
        vector<string>vec;
        loop(n)
        {
            cin>>s;
            mp[s]++;
        }
        for(auto i: mp)
        {
            if(i.second>=max)
            max=i.second;
        }
        for(auto i :mp)
        {
            if(i.second==max)
            {
                vec.push_back(i.first);
            }
        }
        sort(vec.begin(),vec.end());
        for(auto i: vec)
        {
            cout<<i<<endl;
        }
        return 0;
    }

Measured memory_bytes: 26868
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    std::string s; std::cin >> s;
    std::vector<std::string> t = { "dream", "dreamer", "erase", "eraser" };
    std::reverse(s.begin(), s.end());
    for (int i = 0; i < 4; i++) std::reverse(t[i].begin(), t[i].end());
    int pos = 0;
    while (pos < s.size()) {
        bool flag = true;
        for (int i = 0; i < 4; i++) {
            if (s.substr(pos, t[i].size()) == t[i]) {
                pos += t[i].size();
                flag = false;
            }
        }
        if (flag) {
            std::cout << "NO" << std::endl;
            return 0;
        }
    }
    std::cout << "YES" << std::endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

int main() {
	int n;
	cin >> n;
	string s, t;
	cin >> s >> t;
	string result = "";
	for (int i = 0; i < n; i++) {
		result += s[i];
		result += t[i];
	}
	cout << result << '\n';
	return 0;
}


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

int counter[4];
string answer[4] = { "AC" , "WA" , "TLE" , "RE" };

int main()
{
	string s;
	
	int n = 0; 
	cin>>n;
	
	for (int i = 0 ; i < n ; ++i){
	   cin>>s;
	   if(s.compare(answer[0]) == 0)
	       counter[0]++;
	   else if(s.compare(answer[1]) == 0)
	       counter[1]++;
	   else if(s.compare(answer[2]) == 0)
	       counter[2]++;
	   else
	        counter[3]++;
	}
	
	for(int i = 0 ; i < 4 ; ++i){
		cout<<answer[i]<<" x "<<counter[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3200
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

int main() {
    ll D, G;
    cin >> D >> G;
    vector<ll> pis;
    vector<ll> cis;
    for (ll i = 0; i < D; i++) {
        ll pi, ci;
        cin >> pi >> ci;
        pis.push_back(pi);
        cis.push_back(ci);
    }
    ll ans = numeric_limits<ll>::max();
    for (ll q = 0; q < D; q++) {
        for (ll ps = 0; ps != (1 << D); ps++) {
            ll solve_cnt = 0;
            ll score = 0;
            for (ll p = 0; p < D; p++) {
                if (p == q) {
                    continue;
                }
                if ((ps & (1 << p)) != 0) {
                    solve_cnt += pis[p];
                    score += pis[p] * 100 * (p + 1) + cis[p];
                }
            }
            if (score < G) {
                if (score + (pis[q] - 1) * 100 * (q + 1) >= G) {
                    ll cnt = (G - score) / (100 * (q + 1)) + ((G - score) % (100 * (q + 1)) != 0);
                    solve_cnt += cnt;
                    score += cnt * 100 * (q + 1);
                    assert(score >= G);
                } else if (score + pis[q] * 100 * (q + 1) + cis[q] >= G) {
                    ll cnt = pis[q];
                    solve_cnt += cnt;
                    score += cnt * 100 * (q + 1) + cis[q];
                    assert(score >= G);
                }
            }
            if (score >= G) {
                ans = min(ans, solve_cnt);
            }
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 888
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n;
        while ((n = sc.nextInt()) != 0) {
            double avg = 0.0, result = 0.0;
            int[] s = new int[n];
            for (int i = 0; i < n; i++) {
                s[i] = sc.nextInt();
                avg += s[i];
            }
            avg /= n;
            for (int i = 0; i < n; i++) {
                result += (s[i] - avg) * (s[i] - avg);
            }
            result /= n;
            result = Math.sqrt(result);
            System.out.printf("%.8f\n", result);
        }
    }
}


Measured memory_bytes: 31504
from fractions import gcd
import sys

N, M = map(int, input().split())
S = input()
T = input()
cd = gcd(N, M)

s_step = N // cd
t_step = M // cd
s_index = 0
t_index = 0

while s_index < len(S) and t_index < len(T):
    if S[s_index] != T[t_index]:
        print(-1)
        sys.exit()
    s_index += s_step
    t_index += t_step

print(s_step * t_step * cd)

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

vector<ll> w; // on-the-fly weight of connected component, indexed by ranks
vector<vector<int>> head;

class DSU {
	private:
		int *data;
	public:
		DSU(int n) {
			data = new int[n];
			for(int i = 0; i < n; i++) {
				data[i] = -1;
			}
		}

		~DSU() {delete[] data;}

		int find(int i) {
			int parent;
			int back_to = -1;
			for(; (parent = data[i]) >= 0; i = parent) {
				data[i] = back_to;
				back_to = i;
			}
			int root = i;
			while(back_to != -1) {
				i = back_to;
				back_to = data[i];
				data[i] = root;
			}
			return root;
		}

		int merge(int i, int j) {
			int ri = find(i), rj = find(j);
			if (ri == rj)
				return 0;
			if (data[ri] > data[rj]) {
				int t = ri;
				ri = rj;
				rj = t;
			}
			data[ri] += data[rj];
			data[rj] = ri;
			w[ri] += w[rj];
			head[ri].insert(head[ri].end(), head[rj].begin(), head[rj].end());
			return 1;
		}

		int get_size(int i) {
			return -data[find(i)];
		}
};

int main() {
	int n, m;
	cin >> n >> m;
	vector<PP> aby(m);
	w.resize(n);
	head.resize(n);
	rep(i, n) cin >> w[i];
	rep(i, m) {
		int a, b;
		ll y;
		cin >> a >> b >> y;
		aby[i] = {y, {a - 1, b - 1}};
	}
	sort(aby.begin(), aby.end());
	DSU d(n);
	vector<bool> res(m);
	vector<vector<int>> nxt(m);
	rep(i, m) {
		int a = aby[i].second.first, b = aby[i].second.second;
		ll y = aby[i].first;
		d.merge(a, b);
		int rank = d.find(a);
		res[i] = w[rank] >= y;
		nxt[i] = head[rank];
		head[rank] = vector<int>{i};
	}
	set<int> rall;
	rep(i, n) rall.insert(d.find(i));
	queue<int> q;
	for(int r: rall) for(int i: head[r]) q.push(i);
	int ans = 0;
	while(!q.empty()) {
		int i = q.front();
		q.pop();
		if (res[i]) continue;
		ans++;
		for(int j: nxt[i]) q.push(j);
	}
	cout << ans << endl;
}


Measured memory_bytes: 10752
#include<bits/stdc++.h>
#define ll long long
#define maxn 400010
using namespace std;
int dis[maxn], l;
ll pre[maxn];
ll get_mn(int l, int r, int x)
{
	int tl = l, tr = min(r, l + x - 1);
	return 2 * (pre[tr] - pre[tl - 1]);
}
ll get_mx(int l, int r, int x)
{
	int tl = max(l, r - x + 1), tr = r;
	return 2 * (pre[tr] - pre[tl - 1]);
}
ll solve(int l1, int r1, int l2, int r2)
{
	if (l1 > r1) return dis[r2] - l;
	if (l2 > r2) return l - dis[l1];
	ll res = 0;
	for (int i = 0; i <= 1; i++)
		for (int j = 0; j <= 1; j++)
		{
			ll sum = 0;
			if (i == 0) sum = l;
			else sum = -l;
			int t1 = r1 - l1 + 1, t2 = r2 - l2 + 1;
			if (i == 0) t2++; else t1++;
			t1--; t2--;
			if (j == 0) sum = sum - dis[l1] + get_mx(l2, r2, t1) - get_mn(l1 + 1, r1, t2);
			else sum = sum + dis[r2] - get_mn(l1, r1, t2) + get_mx(l2, r2 - 1, t1);
			res = max(res, sum);
		}
	return res;
}
int main()
{
	int n;
	scanf("%d%d", &l, &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &dis[i]);
		dis[i + n] = dis[i] + l;
	}
	for (int i = 1; i <= 2 * n; i++)
		pre[i] = pre[i - 1] + dis[i];
	ll res = 0;
	for (int i = 1; i <= n; i++)
	{
		int t1 = n - i + 1, t2 = n - t1;
		res = max(res, solve(i, n, n + 1, n + t2));
	}
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 233333;
Vi e[N];int sz[N],n,m;ll res;
int A,B,dep[N];bool vis[N];
void dfs(int u, int fa, int d){
	sz[u]=d;
	rep(i,0,SZ(e[u])-1)
		if(e[u][i]!=fa&&(min(A,B)!=min(u,e[u][i])||max(A,B)!=max(u,e[u][i]))&&!vis[e[u][i]])
			dfs(e[u][i],u,-d),sz[u]+=sz[e[u][i]];
	res+=sz[u]>0?sz[u]:-sz[u];
}
int fa[N];
void dfs1(int u, int Fa, int d){
	fa[u]=Fa;vis[u]=1;dep[u]=d;
	rep(i,0,SZ(e[u])-1)if(e[u][i]!=Fa)
		if(!vis[e[u][i]])dfs1(e[u][i],u,d+1);
		else A=u,B=e[u][i];
}

void dfs2(int u, int fa, int d, int cnt){
	sz[u]=d+(u==A||u==B?cnt:0);
	rep(i,0,SZ(e[u])-1)
		if(e[u][i]!=fa&&(min(A,B)!=min(u,e[u][i])||max(A,B)!=max(u,e[u][i])))
			dfs2(e[u][i],u,-d,cnt),sz[u]+=sz[e[u][i]];
//	printf("%d:%d %d\n",u,d,cnt);
	res+=sz[u]>0?sz[u]:-sz[u];
}
int main() {
	read(n);read(m);
	rep(i,1,m){
		int u,v;
		read(u),read(v),e[u].pb(v),e[v].pb(u);
	}
	if(n==m){
		dfs1(1,0,0);memset(vis,0,sizeof(vis));
		if(dep[A]<dep[B])swap(A,B);
		//A>=B
		if(dep[A]-dep[B]&1){
			static int s[N];int len=0;
			for(int u=A;;u=fa[u]){vis[u]=1;if(u==B)break;}
			int x=1;for(int u=A;;u=fa[u]){
				dfs(u,0,x);s[++len]=sz[u];x=-x;
				res-=sz[u]>0?sz[u]:-sz[u];if(u==B)break;
			}
			cerr<<res<<endl;
			rep(i,1,len)s[i]+=s[i-1];if(s[len]){puts("-1");return 0;}
			sort(s+1,s+len+1);int mid=len/2;//int mid=(s[len/2]);
			rep(i,1,len)res+=s[mid]-s[i]>0?s[mid]-s[i]:-(s[mid]-s[i]);
			printf("%lld",res);
		}
		else{
			dfs(A,0,1);res=0;int cnt=-sz[A]/2;res+=cnt>0?cnt:-cnt;
			dfs2(A,0,1,cnt);
			if(sz[A])puts("-1");else printf("%lld",res);
		}
		return 0;
	}
	dfs(1,0,1);
	if(sz[1])puts("-1");else printf("%lld",res);
	return 0;
}


Measured memory_bytes: 18944
#include "bits/stdc++.h"
using namespace std;
#define Fast_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
int n;
vector<long double> a;
vector<vector<long double>> dp;
long double solve(int idx, int head) {
	int tail = idx - head;
	if (idx == n) {
		return head >= tail;
	}
	if (dp[idx][head] != -1)
		return dp[idx][head];
	return dp[idx][head] = (a[idx]) * solve(idx + 1, head + 1) + (1 - a[idx]) * solve(idx + 1, head);
}

int32_t main() {
	Fast_IO
	cin >> n;
	a = vector<long double>(n);
	dp = vector<vector<long double>>(n, vector<long double>(n, -1));
	for (auto &i : a)
		cin >> i;
	cout << setprecision(10) << fixed << solve(0, 0);

}

Measured memory_bytes: 144164
#include <iostream>
#include <cmath>
using namespace std;
int main() {
  long long x;
  cin >> x;
  long long y = 100;
  for (int i = 1; i <= 3760; ++i) {
    y *= 1.01;
    if (y >= x) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 3636
#include<iostream>
using namespace std;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    double tmp=0;
    double sum=0;
    for(int i=0;i<n;i++){
        cin >> tmp;
        sum +=1/tmp;
    }

    cout << 1/sum;

    return 0;
}

Measured memory_bytes: 256
a,b,c,x,y=map(int,input().split())
ans=0
if a+b > 2*c:
    ans += 2*c*min(x,y)
    if x > y:
        if a > 2*c:
            ans += 2*c*(x-y)
        else:
            ans += a*(x-y)
    if y > x:
        if b > 2*c:
            ans += 2*c*(y-x)
        else:
            ans += b*(y-x)
    else:
        pass
else:
    ans += x*a+y*b
print(ans)

Measured memory_bytes: 80008
#include<stdio.h>
int main()
{
int a,i,j,k,l,m,rank;
char mark;
int S[14]={},H[14]={},C[14]={},D[14]={};
scanf("%d",&a);
for(i=0;i<a;i++)
{
        scanf("%s %d",&mark,&rank);
        if(mark=='S'){S[rank]=1;}
        if(mark=='H'){H[rank]=1;}
        if(mark=='C'){C[rank]=1;}
        if(mark=='D'){D[rank]=1;}
}

for(j=1;j<14;j++)
{
    if(S[j]==0){printf("S %d\n",j);
    }
}

for(k=1;k<14;k++)
{
    if(H[k]==0){printf("H %d\n",k);
    }
}

for(l=1;l<14;l++)
{
    if(C[l]==0){printf("C %d\n",l);
    }
}

for(m=1;m<14;m++)
{
    if(D[m]==0){printf("D %d\n",m);
    }
}
return 0;
}

Measured memory_bytes: 596
s = input()

import re

a = s[0] == "A"
b = len(re.findall("C", s[2:-1])) == 1
c = len(re.findall(r"[a-z]", s)) == len(s) - 2

if a and b and c:
    print("AC")
else:
    print("WA")


Measured memory_bytes: 3188
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a, b, c, GCD, LCM, a_base, b_base;
		while (sc.hasNext()) {
			a = sc.nextLong();
			b = sc.nextLong();
			a_base = a;
			b_base = b;
			if (a < b) {
				long sub;
				sub = a;
				a = b;
				b = sub;
			}
			GCD = gcd(a, b);
			LCM = (a_base * b_base) / GCD;
			System.out.println(GCD + " " + LCM);
		}
	}
	static long gcd(long a, long b) {
		if (a % b == 0)
			return b;
		return gcd(b, a % b);
	}
}

Measured memory_bytes: 17192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

ll solve(int n, ll x, vector<ll> &a, vector<ll> &p){
    if(n == 0) return 1; // ここは例外が必要　他だと0を返してしまうので

    if(x == 1) return 0;
    else if(x <= 1+a[n-1]) return solve(n-1, x-1, a, p);
    else if(x == a[n-1]+2) return p[n-1]+1;
    else if(x <= 2+2*a[n-1]) return p[n-1]+1+solve(n-1, x-2-a[n-1], a, p);
    else if(x == 3+2*a[n-1]) return p[n];

    return 0;
}

int main(){
    int N; cin >> N;
    ll X; cin >> X;
    vector<ll> a(N+1, 1LL), p(N+1, 1LL);
    for(int i=1; i<=N; i++){
        a[i] = 2*a[i-1]+3;
        p[i] = 2*p[i-1]+1;
    }

    cout << solve(N, X, a, p) << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
Y = [X[i+1]-X[i] for i in range(M-1)]
Y.sort()
# if N >= M:
#     print(0)
if N == 1:
    print(sum(Y))
else:
    print(sum(Y[:-N+1]))

Measured memory_bytes: 13968
import Foundation
func toTuple<T>(_ args: [T]) -> (T, T) { (args[0], args[1]) }
func readInts() -> [Int] { readLine()!.split(separator: " ").map { Int($0)! } }

let (_, k) = toTuple(readInts())
let li = readInts().sorted { $0 > $1 }
let ans = li[0..<k].reduce(0) { $0 + $1 }
print(ans)

Measured memory_bytes: 13624
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <tuple>

class union_find {
  std::vector<intmax_t> tree;

public:
  union_find(size_t n): tree(n, -1) {}

  size_t find(size_t v) {
    if (tree[v] < 0)
      return v;

    return (tree[v] = find(tree[v]));
  }

  bool unite(size_t u, size_t v) {
    u = find(u);
    v = find(v);
    if (u == v)
      return false;

    if (-tree[u] >= -tree[v])
      std::swap(u, v);

    tree[v] += tree[u];
    tree[u] = v;
    return true;
  }

  bool connected(size_t u, size_t v) {
    return (find(u) == find(v));
  }

  size_t size(size_t v) {
    return -tree[find(v)];
  }
};

template <class Weight>
struct edge {
  using value_type = Weight;
  size_t src, dst;
  value_type cost;

  edge(size_t src, size_t dst, value_type cost=1):
    src(src), dst(dst), cost(cost)
  {}

  bool operator <(const edge<value_type> &rhs) const {
    if (cost != rhs.cost) return cost < rhs.cost;
    if (src != rhs.src) return src < rhs.src;
    return dst < rhs.dst;
  }
};

template <class Weight>
struct graph: public std::vector<std::vector<edge<Weight>>> {
  using value_type = Weight;
  graph(size_t n): std::vector<std::vector<edge<value_type>>>(n) {}

  void connect_with(size_t src, size_t dst, value_type cost=1) {
    (*this)[src].emplace_back(src, dst, cost);
    (*this)[dst].emplace_back(dst, src, cost);
  }
};

template <class Tp>
constexpr Tp inf = Tp(1) << (8*sizeof(Tp)-3);

template <class Weight>
Weight min_spanning_tree(const graph<Weight>& g) {
  // based on Boruvka algorithm
  size_t v = g.size();

  intmax_t res = 0;
  union_find uf(v);
  while (uf.size(0) < v) {
    std::vector<std::pair<size_t, size_t>> min(v, {-1, -1});
    for (size_t i = 0; i < v; ++i)
      for (size_t j = 0; j < g[i].size(); ++j) {
        const auto& e = g[i][j];
        if (uf.connected(e.src, e.dst)) continue;
        size_t s = uf.find(e.src);
        size_t u0, u1;
        std::tie(u0, u1) = min[s];
        if (u0+1 == 0 || g[u0][u1].cost > e.cost) min[s] = {i, j};
      }

    for (size_t i = 0; i < v; ++i) {
      size_t u0, u1;
      std::tie(u0, u1) = min[i];
      if (u0+1 == 0) continue;
      const auto& e = g[u0][u1];
      if (uf.connected(e.src, e.dst)) continue;
      uf.unite(e.src, e.dst);
      res += e.cost;
    }
  }
  return res;
}

int main() {
  size_t V, E;
  scanf("%zu %zu", &V, &E);

  graph<intmax_t> g(V);
  for (size_t i = 0; i < E; ++i) {
    size_t s, d;
    intmax_t w;
    scanf("%zu %zu %jd", &s, &d, &w);
    // --s;
    // --d;
    g.connect_with(s, d, w);
  }

  intmax_t res = min_spanning_tree(g);
  printf("%jd\n", res);
}



Measured memory_bytes: 10500