akhauriyash/Code-Regression huggingface dataset:
// arc080_b.cc
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int h, w, n;
	cin >> h >> w >> n;
	vector<int> a(n);
	for (auto& e : a)
		cin >> e;

	vector<vector<int>> ans(h, vector<int>(w));

	int k = 0;
	for (int i = 0; i < h; i++) {
		if (i % 2 == 0)
			for (int j = 0; j < w; j++) {
				if (a[k] == 0) k++;
				ans[i][j] = k + 1;
				a[k]--;
			}
		else 
			for (int j = w - 1; j >= 0; j--) {
				if (a[k] == 0) k++;
				ans[i][j] = k + 1;
				a[k]--;
			}
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cout << ans[i][j] << " ";
		}
		cout << "\n";
	}
}

Measured memory_bytes: 384
// file creato da gio il 2020-04-12 16:32:10.576145

#include <bits/stdc++.h>
#define FAST 

#ifdef FAST
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#endif

#define S second
#define F first
#define PB push_back
using namespace std;

int main(){
	//freopen("output","w",stdout);
	//freopen("input","r",stdin);
#ifdef FAST
	ios::sync_with_stdio(0);
  	cin.tie(0);
#endif

	int n;
	cin >> n;
	while(n>0){
		if(n%10==7){
			cout <<"Yes";
			return 0;
		}
		n/=10;
	}
	cout <<"No";
}

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

int main() {
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  
  long long res = 1000000000;
  
  for(int i_ab = 0; i_ab <= 100000; ++i_ab){
	int a_left = max(x - i_ab, 0);
    int b_left = max(y - i_ab, 0);
    
    long long price = i_ab * c * 2 + a * a_left + b * b_left;
    
    if(price < res){
      res = price;
    }
  }

  cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, b) for(int i(a); i <= (b); ++i)

#define gc getchar()
struct Reader {
	template <class T> inline operator T() {
		T w; char c, p = 0;
		for(; !isdigit(c = gc); c == '-' && (p = 1));
		for(w = c & 15; isdigit(c = gc); w = w * 10 + (c & 15));
		return p ? -w : w;
	}
}rd;

template <class T> inline bool smin(T&x, const T&y) { return y < x ? x = y, 1 : 0; }
template <class T> inline bool smax(T&x, const T&y) { return x < y ? x = y, 1 : 0; }

typedef long long ll;

int n;
ll s[404], f[404][404];
ll dfs(int l, int r) {
	if (f[l][r] != f[0][0]) return f[l][r];
	REP(i, l, r - 1) smin(f[l][r], dfs(l, i) + dfs(i + 1, r));
	return f[l][r] += s[r] - s[l - 1];
}
int main() {
	n = rd;
	memset(f, 0x3f, sizeof f);
	REP(i, 1, n) s[i] = rd, s[i] += s[i - 1], f[i][i] = 0;
	std::cout << dfs(1, n);
	return 0;
}



Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define N 1000000

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    ll a,b,x; cin>>a>>b>>x;
    if(a<=x&&x<=a+b)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll N, H;
    cin >> N >> H;
    VP p(N);
    ll mxa = 0;
    rep(i, 0, N){
        cin >> p[i].second >> p[i].first;
        mxa = max(mxa, p[i].second);
    }
    sort(ALL(p), greater<PL>());
    cerr << "foo" << endl;
    VL sum;
    ll i = 0, now = 0;
    while(p[i].first > mxa && i < N){
        sum.push_back(now + p[i].first);
        now += p[i].first;
        i++;
    }
    cerr << "hoge" << endl;
    ll r = sum.size();
    ll L = 0, R = 1e9+1;
    while(R - L > 1){
        ll M = L + (R - L) / 2;
        ll mx;
        if(r == 0){
            mx = mxa * M;
        }else if(M <= r){
            mx = sum[M-1];
        }else{
            mx = sum[r-1] + mxa * (M - r);
        }
        if(mx >= H) R = M;
        else L = M;
    }
    cout << R << endl;
    return 0;
}

Measured memory_bytes: 2936
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>

int main(){
    int n;
    while(cin >> n,n){
        
        // ?????????????????????????????±
        priority_queue<pii,vector<pii>,greater<pii>> pq;
        
        // ?????\??????????????????????´???????????????????
        map<int,vector<pii>> mp;
        
        // ??????????????????????????????->?????\??????
        map<int,int> endtoi;
        
        pq.push(make_pair(0, 1000000000));
        
        for(int i=0;i<n;i++){
            char c;cin >> c;
            if(c == 'W'){
                int i,s;
                cin >> i >> s;
                while(s > 0){
                    pii x = pq.top();
                    pq.pop();
                    if(s <= x.second - x.first){
                        pq.push(make_pair(x.first + s, x.second));
                        mp[i].push_back(make_pair(x.first, x.first + s - 1));
                        endtoi[x.first + s - 1] = i;
                        s = 0;
                    } else {
                        s -= x.second - x.first;
                        mp[i].push_back(make_pair(x.first, x.second - 1));
                        endtoi[x.second - 1] = i;
                    }
                }
            }
            if(c == 'D'){
                int i;
                cin >> i;
                for(int unsigned j = 0; j < mp[i].size(); j++){
                    pq.push(make_pair(mp[i][j].first,mp[i][j].second+1));
                    endtoi.erase(mp[i][j].second);
                }
                mp.erase(i);
            }
            // ?????°???
            if(c == 'R'){
                int p;
                cin >> p;
                auto it = endtoi.lower_bound(p);
                if(it == endtoi.end()){
                    cout << -1 << endl;
                    continue;
                }
                int i = it->second;
                
                bool isInRange = false;
                for(int unsigned j = 0;j<mp[i].size();j++){
                	if(mp[i][j].first <= p && p <= mp[i][j].second){
                		isInRange = true;
                	}
                }
                if(isInRange){
                    cout << i << endl;
                } else {
                    cout << -1 << endl;
                }
            }
        }
        cout << endl;
    }
	return 0;
}

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

int main(){
  int N;
  cin>>N;
  int C[N+1],S[200001];
  long int dp[N+1];
  dp[1]=1;
  for(int i=1; i<200001; ++i) S[i]=0;
  for(int i=1; i<=N; ++i){
    cin>>C[i];
  }
  S[C[1]]=1;
  for(int i=1; i<N; ++i){
    if(C[i]==C[i+1]) dp[i+1]=dp[i];
    else if(S[C[i+1]]==0) dp[i+1]=dp[i];
    else dp[i+1]=(dp[i]+dp[S[C[i+1]]])%1000000007;
    S[C[i+1]]=i+1;
  }
  cout<<dp[N]<<endl;
}


Measured memory_bytes: 3328
import java.util.*;
import java.io.*;

public class Main{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        
        //init
        int mid = -1, fin = -1, re = -1;

        while(true){
            mid = Integer.parseInt(in.next());
            fin = Integer.parseInt(in.next());
            re = Integer.parseInt(in.next());

            if(mid == -1 && fin == -1 && re == -1)break;
            
            System.out.println(grade(mid, fin, re));
        }
    }

    static String grade(int mid, int fin, int re){
        int sum = mid + fin;
        if(mid == -1 || fin == -1)return "F";
        else if(sum >= 80) return "A";
        else if(sum >= 65)return "B";
        else if(sum >= 50)return "C";
        else if(sum >= 30){
            if(re >= 50)return "C";
            else return "D";
        }
        else return "F";

    }
}


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

int N,Q,S,T;
long long A[200002] = {0};
int L[200001],R[200001],X[200001];

long long getTmpr(int after){
	long long dif = -A[after];
	if(dif < 0){
		return S * dif;
	}
	else{
		return T * dif;
	}
}

int main(){
	scanf("%d%d%d%d",&N,&Q,&S,&T);
	for(int i = 0; i < N+1; i++){
		scanf("%lld",&A[i]);
	}
	for(int i = 0; i < Q; i++){
		scanf("%d%d%d",&L[i],&R[i],&X[i]);
	}
	
	// relative height
	for(int i = N; i > 0; i--){
		A[i] = A[i] - A[i-1];
	}

	// init tmperture
	long long tmpr = 0;
	for(int i = 1; i <= N; i++){
		tmpr += getTmpr(i);
	}

	for(int i = 0; i < Q; i++){
		long long bef = getTmpr(L[i]) + (R[i] == N ? 0 : getTmpr(R[i]+1));
		A[L[i]] += X[i];
		A[R[i]+1] -= X[i];
		long long aft = getTmpr(L[i]) + (R[i] == N ? 0 : getTmpr(R[i]+1));
		tmpr += aft - bef;
		printf("%lld\n",tmpr);
	}

	return 0;
}



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

int main() { 
  int n, ans = 0;
  cin >> n;
  int a[n+1];
  for(int i = 1; i <= n; ++i) cin >> a[i];
  for(int i = 1; i <= n; ++i) {
    if(a[a[i]] == i) ans++;
  }
  cout << ans/2 << '\n'; 
}


Measured memory_bytes: 640
import fractions

a,b,c,d = map(int, input().split())

a -= 1

# a~bの数でcで割り切れる数の個数は
divC = b//c - a//c
# a~bの数でdで割り切れる数の個数は
divD = b//d - a//d
# a~bの数でc,dの最小公倍数で割り切れる数の個数は
l = (c*d) // fractions.gcd(c,d)
divU= b//l - a//l
divSum = divC+divD-divU


print(b-a - divSum)

Measured memory_bytes: 5048
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+1];
        for(int i=2;i<=n;i++){
            a[i] += sc.nextInt();
        }
        
        int[] cnt =  new int[n+1];
        for(int i=2;i<=n;i++){
            cnt[a[i]]++;
        }

        for(int i=1;i<=n;i++){
            System.out.println(cnt[i]);
        }
    }
}


Measured memory_bytes: 61380
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <iostream>
#include <vector>
#include <iomanip>
#define lsb(x) ((x) & -(x))
using namespace std;

#define mod 1000000007
typedef long long i64;
int n;

struct Mat {
    int v[50][50];
    Mat() {
        fill(v[0], v[50], 0);
    }
    int * operator[](int a) { return v[a]; }
};

Mat operator* (Mat & a, Mat & b)
{
    Mat ans;
    for (int i = 0; i < n; i++)
        for (int k = 0; k < n; k++)
            for (int j = 0; j < n; j++)
                ans[i][j] = (ans[i][j] + 1LL * a[i][k] * b[k][j]) % mod;
    return ans;
}

Mat put(Mat a, i64 p)
{
    Mat ans = a;
    p--;

    while (p) {
        if (p & 1LL)
            ans = ans * a;
        p /= 2;
        if (p)
            a = a * a;
    }

    return ans;
}

int main()
{
    Mat a;
    i64 k;
    scanf("%d%lld", &n, &k);

    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            scanf("%d", a[i] + j);

    a = put(a, k);


    int ans = 0;

    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            ans = (ans + a[i][j]) % mod;

    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    H1, M1, H2, M2, K = map(int, input().split())
    if H1 <= H2:
        mi = H2 * 60 + M2 - (H1 * 60 + M1)
        ans = mi - K
        print(ans)
    else:
        mi = (H2 + 24) * 60 + M2 - (H1 * 60 + M1)
        ans = mi - K
        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9192
#include <iostream>

#define MOD 1000000007

using namespace std;

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

    long long all = 1;
    long long noZero = 1;
    long long noNine = 1;
    long long noZeroAndNine = 1;

    for (int i = 0; i < n; i++) {
        all = all * 10 % MOD;
        noZero = noZero * 9 % MOD;
        noNine = noNine * 9 % MOD;
        noZeroAndNine = noZeroAndNine * 8 % MOD;
    }

    long long result = all - ((noZero - noZeroAndNine) + (noNine - noZeroAndNine) + noZeroAndNine);
    result %= MOD;
    result = (result + MOD) % MOD;

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main( ) {
    //freopen("A.01.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,a;
    cin >> n >> a;
    if(n%500<=a){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll N, C;

ll solve(const vector<ll> &x, const vector<ll> &v){
	ll res = 0;
	vector<ll> cal(N), calma(N);
	ll calsum = 0;
	REP(i, N){
		calsum += v[i];
		cal[i] = calsum - x[i];
	}
	ll tmpma = -1;
	REP(i, N){
		tmpma = max(tmpma, cal[i]);
		calma[i] = tmpma;
	}
	res = max(res, calma[N-1]);
	//cout << cal << endl; 
	//cout << calma << endl;
	ll vsum = 0;
	REP(i, N){
		ll tmp = 0;
		vsum += v[N-1-i];
		tmp += vsum - 2*(C - x[N-1-i]);
		if(i<N-1)tmp += calma[N-1-i-1];
		else tmp += 0;
		res = max(tmp, res);
		//cout << i << " " << tmp << endl;
	}
	return res;
}

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

    cin >> N >> C;
    vector<ll> x(N), v(N), rx(N), rv(N);
    REP(i, N) cin >> x[i] >> v[i];
    REP(i, N){
    	rx[i] = C - x[N-1-i];
    	rv[i] = v[N-1-i];
    }

    ll ma = -1;
    ma = max(ma, solve(x, v));
    ma = max(ma, solve(rx, rv));
    cout << ma << endl;
    return 0;
}

Measured memory_bytes: 4992
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from pprint import pprint
from collections import Counter, defaultdict, deque
import queue
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap
  
  
class Combination:
    def __init__(self, n, mod):

        g1 = [1, 1]
        g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, n + 1):
            g1.append((g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod//i)) % mod)
            g2.append((g2[-1] * inverse[-1]) % mod)
        self.MOD = mod
        self.N = n
        self.g1 = g1
        self.g2 = g2
        self.inverse = inverse

    def __call__(self, n, r):
        if (r < 0 or r > n):
            return 0
        r = min(r, n-r)
        return self.g1[n] * self.g2[r] * self.g2[n-r] % self.MOD


@mt
def slv(N, A):
    MOD = 10**9+7
    c = Counter(A)
    k = c.most_common(1)[0][0]
    i = A.index(k)
    j = i + A[i+1:].index(k)

    cmb = Combination(N+1, MOD)
    for k in range(1, N+2):
        ans = cmb(N+1, k) - cmb(i+N-(j+1), k-1)
        ans %= MOD
        print(ans)


def main():
    N = read_int()
    A = read_int_n()

    (slv(N, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 105260
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N,A,B=map(int,readline().split())
    v=list(map(int,readline().split()))
    v.sort(reverse=True)

    #average
    average=sum(v[:A])/A

    #combination
    res=0
    x=v[A-1]
    x_count=v.count(x)
    x_count_copy=x_count
    if x==v[0]:
        up=1
        down=1
        for i in range(1,A):
            up*=x_count_copy
            x_count_copy-=1
            down*=i
        if x_count>=B:
            for i in range(A,B+1):
                up*=x_count_copy
                x_count_copy-=1
                down*=i
                res+=up//down
        else:
            for i in range(A,x_count+1):
                up*=x_count_copy
                x_count_copy-=1
                down*=i
                res+=up//down
    else:
        m=A
        for i in range(A):
            if v[i]>x:
                m-=1
            else:
                break
        up=1
        down=1
        for i in range(1,m+1):
            up*=x_count_copy
            x_count_copy-=1
            down*=i
        res=up//down

    print(average)
    print(res)
    
if __name__=="__main__":
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x,c=0;
	cin>>n>>x;
	int l[n];
	for(int i=1;i<=n;i++)
	{
		cin>>l[i];
	}
	int d[n];
	d[1] =0;
	for(int i=2;i<=n+1;i++)
	{
		d[i] = d[i-1] +l[i-1];
		if(d[i]<=x)
		{
			c++;
		}
	}
	cout<<c+1<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#define WMAX 10000
#define HMAX 10000

//コメントアウトするとdebug()を実行しない
#define DEBUG

using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

struct edge{
  int to,cost;
};

int A,B,C,N,W,H,ans,dp[HMAX][WMAX];
string S;
static const int dx[8] = {0,1,1,1,0,-1,-1,-1},
					dy[8] = {1,1,0,-1,-1,-1,0,1};

void solve(){
	if(A+B >= 10){
		cout << "error" << endl;
	}else{
		cout << A + B << endl;
	}
}

void debug(){

}

void answer(){
	cout << ans << "\n";
}

int main(){
	cin >> A >> B;
	solve();
	#ifdef DEBUG
	debug();
	#endif
	// answer();

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
	int a,b,k;
	cin >> a >> b >> k;
	for(int i = 0;i<k;i++)
	{
		if(i&1)
		{
			a+=b/2;
			b/=2;
		}
		else
		{
			b += a/2;
			a /= 2;
		}
	}
	cout<<a<<' '<<b<<endl;
	return 0;
}

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

int main(){
  int H,W;
  cin >> H >> W;
  vector<string> s(H);
  int count=0;
  for(int i=0;i<H;i++){
    cin >> s.at(i);
    for(int j=0;j<W;j++){
      if(s.at(i).at(j)=='.'){
        count++;
      }
    }
  }
  queue< pair<int,int> > que;
  vector<vector<int> > dist(H,vector<int>(W,-1));
  vector<int> vx={1,0,-1,0};
  vector<int> vy={0,1,0,-1};
  que.push(make_pair(0,0));
  dist.at(0).at(0)=0;
  while(!que.empty()){
    int x,y;
    tie(x,y)=que.front();
    que.pop();
    if((x==H-1)&&(y==W-1)){
      break;
    }
    for(int i=0;i<4;i++){
      int nx,ny;
      nx=x+vx.at(i);
      ny=y+vy.at(i);
      if((nx>=0)&&(nx<H)&&(ny>=0)&&(ny<W)){
        if((s.at(nx).at(ny)=='.')&&(dist.at(nx).at(ny)==-1)){
          que.push(make_pair(nx,ny));
          dist.at(nx).at(ny)=dist.at(x).at(y)+1;
        }
      }
    }
  }
  if(dist.at(H-1).at(W-1)==-1){
    cout << -1 << endl;
  }else{
    cout << count-dist.at(H-1).at(W-1)-1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3504
#include <bits/stdc++.h>
#define il inline
#define RG register
#define ll long long
#define N (3005)

using namespace std;

struct edge{ int nt,to; }g[N<<1];

int head[N],sg[N],a[N],n,num;

il int gi(){
  RG int x=0,q=1; RG char ch=getchar();
  while ((ch<'0' || ch>'9') && ch!='-') ch=getchar();
  if (ch=='-') q=-1,ch=getchar();
  while (ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
  return q*x;
}

il void insert(RG int from,RG int to){
  g[++num]=(edge){head[from],to},head[from]=num; return;
}

il void dfs(RG int x,RG int p){
  sg[x]=0;
  for (RG int i=head[x],v;i;i=g[i].nt){
    v=g[i].to; if (v==p) continue; dfs(v,x);
    if (a[x]>a[v] && !sg[v]){ sg[x]=1; return; }
  }
  return;
}

int main(){
  n=gi();
  for (RG int i=1;i<=n;++i) a[i]=gi();
  for (RG int i=1,u,v;i<n;++i)
    u=gi(),v=gi(),insert(u,v),insert(v,u);
  for (RG int i=1;i<=n;++i){
    dfs(i,0); if (sg[i]) printf("%d ",i);
  }
  return 0;
}


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

int main(){
  int n; string s; cin >>n >>s; n=s.length(); int cnt=0;
  for(int i=0; i<n-2; i++)
  {if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') cnt++;}
  cout <<cnt;
return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG abc070/c.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
typedef long long ll;

ll lcm(ll a, ll b){
    return a / __gcd(a, b) * b;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    ll N;
    cin >> N;
    ll T;
    ll ans = 1;
    rep(i, N){
        cin >> T;
        ans = lcm(ans, T);
    }
    cout << ans << "\n";
    return 0;
}

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

int main(){
	int N;
	cin >> N;
	int h[N];
	for(int i=0; i<N; i++){
		cin >> h[i];
	}
	ll dp[N];
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for(int i=2; i<N; i++){
		dp[i] = min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1]));
	}
	cout << dp[N-1] << endl;
	return 0;
}

Measured memory_bytes: 1408
import sys

input = sys.stdin.readline


def main():
    A, B, C, X, Y = [int(x) for x in input().split()]
    ans = []
    ans.append(A * X + B * Y)
    ans.append(C * 2 * (max(X, Y)))
    if X > Y:
        ans.append(C * 2 * Y + (X - Y) * A)
    else:
        ans.append(C * 2 * X + (Y - X) * B)

    print(min(ans))


    

if __name__ == '__main__':
    main()



Measured memory_bytes: 3060
import sys
import math
import numpy as np
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N,K = I()
h = l()
h.sort()
print(N-bisect.bisect_left(h,K))

Measured memory_bytes: 36276
#include<stdio.h>
	int main() {
		long long int X, Y;
		scanf("%lld%lld", &X, &Y);

		int count = 0;

		for (long long int i = X; i <= Y; i *= 2) {
			count++;
		//	printf("%lld\n", i);
		//	printf("%d\n", count);
		}
		printf("%d", count);


		return 0;
	}



Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define pb push_back
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define td(v) v.begin(),v.end()
#define rep(i,a,n) for (int i=(a);i<(n);i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define re(v) {for(auto &_re : v) cin >> _re;}
#define rre(v){for(auto &_re : v) for(auto &_rre : _re) cin >> _rre;}
#define pr(v) {for(auto _pr : v) cout << _pr << " "; cout << endl;}
#define prr(v) {for(auto _prr : v) cout << _prr.ff << " " << _prr.ss << endl;}
#define eb emplace_back
using namespace std;
const ll M = 1e9 + 7;
const ll mod = 998244353;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define int long long
int n, modulo;
struct SegmentTree{
    struct node{
        node *l = nullptr;
        node *r = nullptr;
        ll val = 1;
        node(){}
    };
    node *root = new node();
    
    void update(node *cur,int l,int r,int p,int val){
        if(l==r){
            cur->val = val;
        }
        else{
            int m = (l+r)/2;
            if(p<=m){
                if(!cur->l){
                    cur->l = new node();
                }
                update(cur->l,l,m,p,val);
                cur->val = cur->l->val;
                if(cur->r) cur->val *= cur->r->val;
            }
            else{
                if(!cur->r){
                    cur->r = new node();
                }
                update(cur->r,m+1,r,p,val);
                cur->val = cur->r->val;
                if(cur->l) cur->val *= cur->l->val;
            }
        }
        cur->val %= modulo;
    }
    ll query(node *cur,int l,int r,int a,int b){
        if(!cur or r < a or l > b or a > b) return 1;
        if(l>=a && r<=b){
            return cur->val;
        }
        int m = (l+r)/2;
        return query(cur->l,l,m,a,b) * query(cur->r,m+1,r,a,b) % modulo;
    }   
};
vector<int> adj[200200];
vector<ll> ways(200200), dp(200200);
SegmentTree tree[200200];
void dfs(int u,int p){
	ways[u] = 1;
	for(int i=0;i<adj[u].size();i++){
		int v = adj[u][i];
		if(v!=p){
			dfs(v, u);
			tree[u].update(tree[u].root, 0, 200200, i, ways[v] + 1);
			ways[u] *= (ways[v] + 1);
			ways[u] %= modulo;
		}
	}
}
void go(int u,int p){
	//dp[u] = (dp[p] / (ways[u]+1) + 1) * ways[u];
	for(int i=0;i<adj[u].size();i++){
		int v = adj[u][i];
		if(v!=p){
			//dp[v] = dp[u] / (ways[u] + 1) + 1
			dp[v] = (tree[u].query(tree[u].root, 0, 200200, 0, i-1) * tree[u].query(tree[u].root, 0, 200200, i+1, adj[u].size()) + 1) % modulo;
			tree[v].update(tree[v].root, 0, 200200, adj[v].size(), dp[v]);
			dp[v] = dp[v] * ways[v] % modulo;
			go(v, u);
		}
	}
}
void solve(){
	cin >> n >> modulo;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin >> a >> b;
		adj[a].pb(b); adj[b].pb(a);
	}
	dfs(1,1);
	dp[1] = ways[1];
	go(1,1);
	for(int i=1;i<=n;i++){
		cout << dp[i] << endl;
	}
}
int32_t main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int t = 1;
  //cin >> t;
  while(t--){
    solve();
  }  
}

Measured memory_bytes: 93540
#include<bits/stdc++.h>
using namespace std;
int main()
{
    /*vector <int> v(3);
    for(int i=0;i<3;i++)
    {
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    double a=(v[0]*v[1])/2;
    cout<<(int)a<<endl;*/
    int a,b;
    cin>>a>>b;
    if(b%a==0)
    {
        cout<<a+b<<endl;
        return 0;
    }
    else cout<<b-a<<endl;
    return 0;
}


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

#include <boost/multiprecision/cpp_dec_float.hpp>

using namespace std;
namespace mp = boost::multiprecision;

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

  // int64_t a, ans;
  // mp::cpp_dec_float_50 b;
  // cin >> a >> b;

  // b *= a;
  // ans = (int64_t)b;

  int64_t a, ans;
  double b;
  cin >> a >> b;
  ans = (a * (int)round(b * 100)) / 100;

  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 3736
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;
class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint & a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator-=(const mint & a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator*=(const  mint & a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint & a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint & a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint & a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint & a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint & a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};
//fixed << setprecision(2)

//小文字=大文字+32

int main() {
	int n;
	cin >> n;
	vector<double>v(n);
	rep(i, n) {
		cin >> v[i];
	}
	double ans=0;
	sort(v.begin(), v.end());

		rep(i, n-1) {
			ans+=v[n - 1 - i]/pow(2,i+1);
		}
		ans += v[0] / pow(2, n - 1);

	cout << ans;
}
	



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

int main() {
  int n;
  cin >> n;
  cout << (n == 1 ? 0 : 1) << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstdint>
#include <cmath>
#include <numeric>
#include <functional>
#include <queue>
#include <stack>

using namespace std;

int main()
{

  int a, b, c;

  cin >> a >> b >> c;

  if((a < c && c < b) || (b < c && c < a))
    {
      cout << "Yes" << endl;
    }
  else
    {
      cout << "No" << endl;
    }


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    string s;
    cin >> s;
    REP(i, s.length())
    {
        if (s[i] == '7')
        {
            Yes(1);
            return 0;
        }
    }
    Yes(0);
}

Measured memory_bytes: 3596
#include <stdio.h>
 
int main() {
  char c[300]={0};
  char a[300] ={0};
  int h;
  int i,j,k,l,n,m;
 
 
  while(1){
    i=0;
    while(1){
       
      scanf("%c",&c[i]);
      if(c[i] == '\n') {    
    break;
      }
       
      i++;
    }
    
    if ( i == 1 && c[0] == '-' ) break;
 
    //  printf("%d",i);
     
    scanf("%d",&m);
     
    for(j=0;j<m;j++){
      scanf("%d", &h );
       
      for(k=0;k<i-h;k++) {
    a[k] = c[h+k];
    //    printf("a[%d] = c[%d]の%c\n",k ,h+k,c[h+k]);
      }
      for(k=0;k<h;k++){
    a[i-h+k] = c[k];
    //   printf("a[%d] = c[%d]の%c\n",i-h+k,k,c[k]);
      }
      for(k=0; k<i; k++){
    c[k] = a[k];
    // printf("c[%d] = a[%d]の%c\n",k,k,a[k]);
      }
    }
    for(k=0;k<i;k++) {
      printf("%c",c[k]);
    }
    printf("\n");
      scanf("%c",&c[0]);
  }
   
   
  return 0;
   
}
    
    


Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
int main(){
    int k,n,a[101],v,j,t=0;
    cin>>n;
    for (int i=0; i<n; i++)
        cin>>a[i];
    for (int i=0; i<n; i++){
    	k=i;
    	for (int j=i+1; j<n; j++)
    		if (a[j]<a[k])
    		   k=j;
        if (a[k]<a[i]){
        	t++;
        	v=a[k];
        	a[k]=a[i];
        	a[i]=v;
		}
		
	}
	cout<<a[0];
	for (int i=1; i<n; i++)
	    cout<<' '<<a[i];
	cout<<endl;
	cout<<t<<endl;
    return 0;
} 


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

int main()
{
    int N;
    cin >> N;
    set<char> st;
    for (int i = 0; i < N; i++)
    {
        char s;
        cin >> s;
        st.insert(s);
    }
    if (st.size() == 3)
        cout << "Three" << endl;
    else
        cout << "Four" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main (void){
	int x,y;
  	
  	scanf("%d %d",&x,&y);
  	x+=y;
  	if(x==3){printf("3");}
  	if(x==4){printf("2");}
 	if(x==5){printf("1");}
  return 0;
  
}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		return []byte(f1())
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

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

type Job struct {
	A, B int
}

func main() {
	defer stdout.Flush()
	N := readInt()
	J := make([]Job, N)
	// var a,b int
	for i := range J {
		/*
		fmt.Scan(&a, &b)
		J[i].A = a
		J[i].B = b
		*/
		J[i].A = readInt()
		J[i].B = readInt()
	}

	pq := new(PriorityQueue)

	for _, x := range J {
		// push(x)
		heap.Push(pq,x)
	}
	t := 0
	for pq.Len() != 0  {
		j := heap.Pop(pq).(Job)
		t += j.A
		if j.B < t {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")

}

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

type PriorityQueue []Job

func (pq PriorityQueue) Len() int {
	return len(pq)
}

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].B < pq[j].B
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueue) Push(x interface{}) {
	old := *pq
	*pq = append(old, x.(Job))
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old) - 1
	x := old[n]
	*pq = old[:n]
	return x
}

Measured memory_bytes: 20608
#include <bits/stdc++.h>
#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 namespace std;
using P = pair<int, int>; 
using ll = long long;

int main()
{
  int n;
  cin >> n;
  vector<P> p(n);
  rep(i, n){
    cin >> p[i].first;
    p[i].second = i + 1;
  }
  sort(p.begin(), p.end());
  rep(i, n) {
    cout << p[i].second;
    if(i + 1 < n) cout << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 3876
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
// #define sort(a) sort(all(a))
using P = pair<int, int>;
using ll = long long;
using ld = long double;
typedef vector<int> vi;
int dx[4] = { 0, 1, 0,-1 };
int dy[4] = { 1, 0,-1, 0 };
const ll MOD = 1000000007;

signed main() {
  string S;
  cin >> S;
  for (int i = 0; i < S.size(); i++) {
    cout << "x";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3596
use std::io::*;
use std::str::FromStr;

fn main(){
    println!("{}", read::<usize>()/3)
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

Measured memory_bytes: 4352
S = gets.chomp.split("")

array = Array.new(S.length, 0)

r_length = 0
r_pos = 0
l_length = 0
S.each.with_index do |s, i|
  if s == 'R'
    if l_length > 0
      # calc
      array[r_pos] = (l_length + r_length) / 2
      array[r_pos+1] = (l_length + r_length) / 2
      if r_length.even? && l_length.odd?
        array[r_pos+1] += 1
      elsif r_length.odd? && l_length.even?
        array[r_pos] += 1
      end
      r_length = 0
      r_pos = 0
      l_length = 0
    end
    r_length += 1
    r_pos = i
  else
    l_length += 1
  end
end
array[r_pos] = (l_length + r_length) / 2
array[r_pos+1] = (l_length + r_length) / 2
if r_length.even? && l_length.odd?
  array[r_pos+1] += 1
elsif r_length.odd? && l_length.even?
  array[r_pos] += 1
end
print "#{array.join(' ')}\n"

Measured memory_bytes: 23756
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    cin>>a;
    string b=a;
    reverse(a.begin(),a.end());
    for(int i=0;i<a.size();++i)
    {
        if(a[i]=='b') a[i]='d';
        else if(a[i]=='d') a[i]='b';
        else if(a[i]=='p') a[i]='q';
        else if(a[i]=='q') a[i]='p';
    }
    if(a==b) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 512
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto A = RD;
	auto B = RD;
	auto C = RD;

	writeln(A + B >= C ? "Yes" : "No");
	stdout.flush();
	debug readln();
}


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

typedef long long ll;

using namespace std;

template<typename TwoDimensionalVector>
void sort_by_column(TwoDimensionalVector &vector, int column, bool reverse = false) {
    if (reverse) {
        sort(vector.begin(), vector.end(), [&](auto x, auto y) { return x[column] > y[column]; });
    } else {
        sort(vector.begin(), vector.end(), [&](auto x, auto y) { return x[column] < y[column]; });
    }
}

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

    int N, M;
    cin >> N >> M;

    ll x, y, z;
    vector<vector<ll>> source;
    for (int _ = 0; _ < N; _++) {
        cin >> x >> y >> z;
        vector<ll> tmp = {x + y + z,
                          x + y - z,
                          x - y + z,
                          x - y - z,
                          -x + y + z,
                          -x + y - z,
                          -x - y + z,
                          -x - y - z};
        source.push_back(tmp);
    }

    ll absolute_maximum = 0;
    ll initial_value = 0;

    for (int column = 0; column < 8; column++) {
        sort_by_column(source, column, true);
        ll maximum = accumulate(source.begin(), next(source.begin(), M), initial_value, [&](ll sum, auto x) { return sum + x[column]; });
        if (maximum > absolute_maximum) {
            absolute_maximum = maximum;
        }
    }

    cout << absolute_maximum << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(x) push_back(x)
#define f(i,st,n) for(i=st;i<n;i++)
#define qu queue
#define ps(x) push(x)
#define vec vector
#define ft() front()
#define mst(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define sfl(x) scanf("%lld",&x)
#define pfl(x) printf("%lld\n",x)
#define pf(x) printf("%lld",x)
#define mpr make_pair
#define fs first
#define se second
#define inf LLONG_MAX
 
 
 
ll gcd(ll a,ll b){
    if(a==0){
        return b;
    }                     
    return gcd(b%a,a);
}
ll power(ll x,ll y){            
    ll res=1;
    while(y>0){
        if(y%2==1){
            res=(res*x);
        }
        x=(x*x);
        y=y/2;
    }
    return res;
}
 


int main(){
 
/* #ifndef ONLINE_JUDGE
    
   freopen("input.txt", "r", stdin);
   
   freopen("output.txt", "w", stdout);
   #endif*/
ll n,i,j;
sfl(n);
ll a[n];
f(i,0,n)sfl(a[i]);
ll ans=0;
f(i,0,n){
f(j,i+1,n){
  ans+=(a[i]*a[j]);
}
}
cout<<ans;














   return 0;
 }

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;



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

    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if(A + B == C + D){
        cout << "Balanced\n";
    } else if (A + B < C + D){
        cout << "Right\n";
    } else if (A + B > C + D){
        cout << "Left\n";
    }
}

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

int main(){
	int n,k;
	cin>>n>>k;
	double ret = 0;
	for(int i=1; i<=n; i++){
		double prob = 1.0/n;
		if(i>=k) ret+=prob;
		else{
			int curr = i;
			int dice = 0;
			while(curr<k){
				dice++;
				curr*=2;
			}
			double cur = 1;
			while(dice--) cur/=2;
			ret+=prob*cur;
		}
	}
	cout.precision(10);
	cout<<ret;
}

Measured memory_bytes: 3756
#include <stdio.h>



int 
main(){
	int N;
	char s[5010];
	scanf("%d",&N);scanf("%s",s);
	int i,j,k,len=0;
	int cnt = 0;
	for(i=0;i<=N-1-len;i++){
		for(j=i+len; j<=N-len;j++)
		{
			cnt = 0;
			for(k=0; i+k < j && j+k < N; k++){
				if(s[i+k]==s[j+k])cnt++;
				else break;				
			}
			if(len <cnt) len = cnt;
		}
	}
	printf("%d\n",len);
 return 0;
}

Measured memory_bytes: 256
#include <cstdio>

const int MAXN = 2000, MAXL = MAXN * MAXN, MOD = 1e9 + 7;
int n, K, fac[MAXL + 5], ifac[MAXL + 5], f[MAXN + 5][MAXN + 5];

inline void addeq ( int& a, const int b ) { if ( ( a += b ) >= MOD ) a -= MOD; }

inline int qkpow ( int a, int b ) {
	int ret = 1;
	for ( ; b; a = 1ll * a * a % MOD, b >>= 1 ) ret = 1ll * ret * ( b & 1 ? a : 1 ) % MOD;
	return ret;
}

inline void init ( const int n ) {
	fac[0] = 1;
	for ( int i = 1; i <= n; ++ i ) fac[i] = 1ll * i * fac[i - 1] % MOD;
	ifac[n] = qkpow ( fac[n], MOD - 2 );
	for ( int i = n - 1; ~ i; -- i ) ifac[i] = ( i + 1ll ) * ifac[i + 1] % MOD;
}

inline int C ( const int n, const int m ) {
	return n < m ? 0 : 1ll * fac[n] * ifac[m] % MOD * ifac[n - m] % MOD;
}

int main () {
	scanf ( "%d %d", &n, &K );
	if ( K == 1 ) return puts ( "1" ), 0;
	init ( n * K ), f[0][0] = 1;
	for ( int i = 1; i <= n; ++ i ) {
		for ( int j = 0; j <= i; ++ j ) {
			int& cur = f[i][j];
			if ( i ^ j ) addeq ( cur, f[i - 1][j] );
			if ( j ) addeq ( cur, 1ll * f[i][j - 1]
				* C ( n * K - i - ( j - 1 ) * ( K - 1 ) - 1, K - 2 ) % MOD );
		}
	}
	printf ( "%d\n", int ( 1ll * f[n][n] * fac[n] % MOD ) );
	return 0;
}

Measured memory_bytes: 48072
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=998244353;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2LL*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
struct X
{
	string s;
	bool operator<(const X &T) const
	{
		return s+T.s<T.s+s;
	}
};
X stf[111];
int n, l;

int main(void)
{
	int i; cin>>n>>l;
	for(i=0 ; i<n ; i++) cin>>stf[i].s;
	sort(stf,stf+n);
	for(i=0 ; i<n ; i++) cout<<stf[i].s;
	return 0;
}

// 제출하기 전에 생각햇나요?
// it may be easier/harder than you think
// ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
#define F first
#define S second 
#define mp make_pair
#define pb push_back
#define pf push_front
#define speed_up ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define debug cerr << "OK\n";
#define ub upper_bound
#define lb lower_bound
#define treap_pair pair<treap*, treap*>
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef set <int> si;
typedef set <ll> sll;
typedef multiset <int> msi;
typedef multiset <ll> msll;
typedef map <int, int> mi;
typedef map <ll, ll> mll;
  
const int N = 3e3 + 2;
const int M = 1e5 + 2;
const int mod = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18 + 100;

  
void data() {
    #ifdef PC
        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #endif	
}

template <typename T>
void scerr(T nums) {
    for (auto it : nums)
        cerr << it << " | ";
    cerr << "\n";
}

int n;
double c[N], dp[N][N], ans = 0.0;	

int main() {
	data();
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%lf", &c[i]);
	dp[1][1] = c[1];
	dp[1][0] = 1.0 - c[1];
	for (int i = 2; i <= n; ++i) {
		dp[i][0] = dp[i - 1][0] * (1.0 - c[i]);
		for (int j = 1; j <= i; ++j) {
		 	dp[i][j] = dp[i - 1][j] * (1.0 - c[i]) + dp[i - 1][j - 1] * c[i];
		}
	}
	for (int i = n / 2 + 1; i <= n; ++i)
		ans += dp[n][i];
	printf("%.9lf", ans);

}
  
/*
    Timus: 288481RF
    CodeForces: fractal
*/

Measured memory_bytes: 68992