akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

int main(){
	int dy[] = {0, 0, 1, -1};
	int dx[] = {1, -1, 0, 0};

	int h, w;
	cin >> h >> w;

	vector<string> grid(h);
	for(int i=0; i<h; ++i)
		cin >> grid[i];

	string s = string(w, '.');
	for(int i=1; i<h-1; ++i){
		if(grid[i-1] == s && grid[i] == s){
			grid.erase(grid.begin() + i);
			-- i;
			-- h;
		}
	}

	int ret = 0;
	for(;;){
		bool ok = true;
		for(int i=0; i<h; ++i){
			for(int j=0; j<w; ++j){
				if(grid[i][j] != '.')
					continue;

				map<char, pair<int, int> > m;

				for(int k=0; k<4; ++k){
					int y = i;
					int x = j;
					while(y >= 0 && y < h && x >= 0 && x < w && grid[y][x] == '.'){
						y += dy[k];
						x += dx[k];
					}
					if(y >= 0 && y < h && x >= 0 && x < w){
						char c = grid[y][x];
						if(m.find(c) != m.end()){
							grid[y][x] = '.';
							grid[m[c].first][m[c].second] = '.';
							ret += 2;
							ok = false;
						}else{
							m[c] = make_pair(y, x);
						}
					}
				}
			}
		}
		if(ok)
			break;
	}

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

Measured memory_bytes: 1164
#include <stdio.h>
int main(void) {
	int S[13], H[13], C[13], D[13], d, n, i;
	char c;
	for (i = 0; i <= 12; i ++) S[i] = H[i] = C[i] = D[i] = 0;
	scanf("%d", &n);
	// ??????scanf("%c %d, &c, &d) == 2????¶??¶??????¶?????§?????????????????????????????????????????????? 
	while (scanf("%c %d", &c, &d) != EOF) {
		if (c == 'S') S[d - 1] = 1;
		if (c == 'H') H[d - 1] = 1;
		if (c == 'C') C[d - 1] = 1;
		if (c == 'D') D[d - 1] = 1;
	}
	i = 0;
	while (i <= 12) {
		if (! S[i]) printf("S %d\n", i + 1);
		i ++;
	}
	i = 0;
	while (i <= 12) {
		if (! H[i]) printf("H %d\n", i + 1);
		i ++;
	}
	i = 0;
	while (i <= 12) {
		if (! C[i]) printf("C %d\n", i + 1);
		i ++;
	}
	i = 0;
	while (i <= 12) {
		if (! D[i]) printf("D %d\n", i + 1);
		i ++;
	}
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
typedef long long ll;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int i,j,k;
int n,w;
int items[int(1e4)];
long long int values[int(1e4)];
long long int cache[110][int(1e6)];

long long int knapsack(int x,int left,long long int value){


    if(x == n || left == 0){
        return 0;
    }

    else if(cache[x][left]!=0){
        return cache[x][left];
    }

    else if(items[x] > left){
        return cache[x][left] = knapsack(x+1,left,value);
    }
    else{
        return cache[x][left] = max(values[x]+ knapsack(x+1,left-items[x],value),knapsack(x+1,left,value));
    }

}

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

    cin >> n >> w;

    for(i=0;i<n;i++){
        cin >> items[i] >> values[i]; 
    }

    cout << knapsack(0,w,0)<< endl;
    
}

Measured memory_bytes: 284928
N,x = map(int,input().split())
A = list(map(int,input().split()))
ans = 0
for i in range(1,N):
    cnt = A[i-1] + A[i] - x
    if cnt > 0:
        A[i] = max(0,A[i]-cnt)
        ans += cnt
print(ans)

Measured memory_bytes: 14132
/*
   AUTHOR :- Gaurang_Kothiya
   
   Quote:-" Great things never come from comfort zones."                                                                                                                
*/
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>  
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
#include <bitset>
#include <cstdint>
#include <initializer_list>
 
using namespace std;
using namespace __gnu_pbds;  

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> data_set; 
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long  
#define ld long double
#define f(i,x,n) for(ll i=x;i<=n;i++)
#define fe(x,v)   for(auto &x :v)
#define nf(i,x,n) for(ll i=n;i>=x;i--)
#define all(a)   a.begin(),a.end()
#define rall(a)  a.rbegin(),a.rend()
#define b_s(a,b)   binary_search( all(a),b)
#define lb(v,n)  lower_bound(all(v) ,n )
#define ub(v,n)  upper_bound( all(v) , n)
#define gcd(a,b) __gcd(a,b)
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define RE rend()
#define RB rbegin()
#define B begin()
#define E end()
#define acc(v, x) accumulate(all(v), x)
#define p(a,b) pair<a,b>
#define F first
#define S second
#define sz size()
#define v(x) vector<x>
#define m(a,b) map<a,b>
#define u_m(a,b) unordered_map<a,b>
#define mm(a,b) multimap<a,b>
#define s(a) set<a>
#define us(a) unordered_set<a>
#define ms(a) multiset<a>
#define maxy __LONG_LONG_MAX__
#define miny INT_MIN
#define PI 3.14159265358979323846
#define MOD 1000000007

ll a,b,n;

void Solve()
{
	
	cin>>a>>b>>n;
	
	ll tm= min(b-1,n);
	
	cout<<   (a*tm)/b  - a*(tm/b);
	
}


signed main() 
{
	speed		
	
	int q=1;
	//cin>>q;
	
	while(q--)
	Solve();
	
	//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
	return 0;
}

 
 

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

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		int a = Integer.parseInt(str[0]);
		int b = Integer.parseInt(str[1]);
		int c = Integer.parseInt(str[2]);

		int d = a + b;
		for (int i = 0; i < 60; i++) {
			int t = 60 * i + c;
			if (t % d <= a) {
				System.out.println(t);
				return;
			}
		}
		System.out.println(-1);
	}
}


Measured memory_bytes: 24440
import itertools as itr
import bisect
n = int(input())

arr = []
for n_order in range(3,10):
    for a in itr.product([3,5,7], repeat=n_order):
        if 7 in a:
            if 5 in a:
                if 3 in a:
                    n753=0
                    for l in range(n_order):
                        n753+=10**l*a[l]
                    arr.append(n753)
arr.sort()

ans = bisect.bisect_right(arr,n)
print(ans)

Measured memory_bytes: 4248
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;
  if(c=='a'||c=='o'||c=='e'||c=='i'||c=='u'){
  cout<<"vowel"<<endl;
  }else{
  cout<<"consonant"<<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
typedef struct {
	int a,b,c;
} HUKU;
int dfs(int day,int now);
HUKU h[202];
int d,n;
int t[202];
int dp[202][202];
int main(){
	cin >> d >> n;
	for(int i=0;i<d;i++) cin >> t[i];
	for(int i=0;i<n;i++){
		cin >> h[i].a >> h[i].b >> h[i].c;
	}
	for(int i=0;i<=d;i++){
		for(int j=0;j<=200;j++){
			dp[i][j] = -1;
		}
	}
	int ans = 0;
	for(int i=0;i<n;i++){
		if(t[0] >= h[i].a && t[0] <= h[i].b){
			ans = max(ans,dfs(1,h[i].c));
		}
	}
	cout << ans << endl;
}

int dfs(int day,int now){
	if(day == d) return 0;
	if(dp[day][now] != -1) return dp[day][now];
	int ret = 0;
	for(int i=0;i<n;i++){
		if(t[day] >= h[i].a && t[day] <= h[i].b){
			ret = max(ret,dfs(day+1,h[i].c) + abs(h[i].c - now));
		}
	}
	//cout << day << " " << now << " " << ret << endl;
	return dp[day][now] = ret;
}

Measured memory_bytes: 1332
# -*- coding: utf-8 -*-


def main():
    n, m = map(int, input().split())
    a = [0 for _ in range(n)]
    b = [0 for _ in range(n)]

    # スターグラフを作ってみる
    for i in range(m):
        ai, bi = map(int, input().split())
        # 0-index
        ai -= 1
        bi -= 1

        if ai == 0:
            a[bi] += 1
        elif bi == 0:
            b[ai] += 1
        else:
            a[bi] += 1
            b[ai] += 1

    for ai, bi in zip(a, b):
        if (ai + bi) % 2 == 1:
            print('NO')
            exit()

    print('YES')


if __name__ == '__main__':
    main()


Measured memory_bytes: 4760
#include <iostream>

int main()
{
    int i, j;
    
    for (i = 1; i <= 9; i++) {
        for (j = 1; j <= 9; ++j) {
            std::cout << i << "x" << j << "=" << i*j << std::endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 1116
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
ll MOD=1000000007;
int inf=1000000000;
ll INF=10000000000000000;
int main(){
    string s;
    cin >> s;
    ll ans=0,y=0;
    rep(i,s.size()){
        if (s.at(i)=='W'){
            ans+=i-y;
            y++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
inline void print() { cout << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }

int main() {
    init();

    int n, m; cin >> n >> m;
    VI x(n); cin >> x;

    int ans = 0;
    map<int, int> a, b, c;
    each(i, x)++a[i];
    each(i, a) {
        ans += i.second / 2;
        if (i.second / 2)b[i.first % m] += i.second / 2;
        if (i.second % 2)c[i.first % m] += i.second % 2;
    }
    each(i, c) {
        if (i.first == 0 || i.first * 2 == m) {
            ans += i.second / 2;
            i.second %= 2;
        }
        else if (c.count(m - i.first) && i.second <= c[m - i.first]) {
            ans += i.second;
            c[m - i.first] -= i.second;
            i.second = 0;
        }
    }
    each(i, c) {
        if (i.first == 0)continue;
        if (b.count(m - i.first))ans += min(b[m - i.first], i.second / 2);
    }
    print(ans);
}

Measured memory_bytes: 9984
a, b = [int(x) for x in input().split()]
if a == b:
    print(a + b)
else:
    o = 0
    if a > b:
        o += a
        a -= 1
        if a > b:
            o += a
        else:
            o += b
    else:
        o += b
        b -= 1
        if b > a:
            o += b
        else:
            o += a
    print(o)

Measured memory_bytes: 3060
<?php
list ($N) = fscanf(STDIN, '%d');

$A = trim(fgets(STDIN));
$A = str_replace(array("\r\n","\r","\n"), '', $A);
$A = array_map('intval', explode(" ", $A));

echo (max(array_count_values($A)) == 1) ? "YES" : "NO";
?>


Measured memory_bytes: 33780
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use std::collections::HashMap;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let w: String = read!();
    let w = w.chars().collect_vec();
    let mut hm = HashMap::new();

    for &c in &w {
        let a = hm.entry(c).or_insert(0);
        *a += 1;
    }

    let mut ans = true;

    for (k, v) in hm {
        ans = ans && v % 2 == 0;
    }

    let a = if ans { "Yes" } else { "No" };
    println!("{}", a);
}


Measured memory_bytes: 2124
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	cin >> n;
	int f[100][10];
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 10; j++){
			cin >> f[i][j];
		}
	}
	int p[100][11];
	for(int i = 0; i < n; i++){
		for(int j = 0; j <= 10; j++){
			cin >> p[i][j];
		}
	}

	int ans = -mod;
	for(int i = 1; i < (1 << 10); i++){
		int res = 0;
		int cnt[100] = {};
		for(int j = 0; j < 10; j++){
			for(int k = 0; k < n; k++){
				if((i & (1 << j)) > 0 && f[k][j] > 0) cnt[k]++;
			}
		}
		for(int i = 0; i < n; i++){
			res += p[i][cnt[i]];
		}
		ans = max(ans, res);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll x; cin >> x;
  
  ll ans = 0;
  
  for(ll i=1; i <= x; i++){
    for(ll j=1; j <= x; j++){
      for(ll k=1; k <= x; k++){
        ans += __gcd(i,__gcd(j,k));
      }
    }
  }
  
  cout << ans << endl;
  
  
}

Measured memory_bytes: 3608
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>

const long INF = 1123456789012345678;

long n;
std::vector<long> b;
std::stack<long> st;

int main(){
	scanf("%ld", &n);
	for(int i = 0; i < n; i++){
		long x;
		scanf("%ld", &x);
		b.push_back(x-1);
	}
	for(int i = 0; i < n; i++){
		if(b[i] > i){
			printf("-1\n");
			return 0;
		}
	}
	for(int i = 0; i < n; i++){
		auto it = b.end();
		it--;
		for(long j = b.size() - 1; j >= 0; j--, it--){
			if(b[j] == j){
				st.push(j+1);
				b.erase(it);
				break;
			}
		}
	}
	while(!st.empty()){
		printf("%ld\n", st.top());
		st.pop();
	}
	return 0;
}


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

using namespace std;

#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define MP make_pair
#define PB push_back
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

#define int long long
#define trace(x) cerr << #x << ": " << x << " " << endl;


inline int add(int a, int b){a += b; if(a >= MOD)a -= MOD; return a;}
inline int sub(int a, int b){a -= b; if(a < 0)a += MOD; return a;}
inline int mul(int a, int b){return (int)((int) a * b %MOD);}


#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

#define N 2*100000 + 1
int h[2*100000+5];
int v[2*100000+5];
int dp[2*100000+5];

int segtree[4 * (N + 1)];

int query_segtree(int si, int l, int r, int ql, int qr)
{
    if (l > qr || r < ql)
        return LONG_LONG_MIN;
    if (ql <= l && qr >= r)
        return segtree[si];
    auto t1 = query_segtree(2 * si, l, (l + r) / 2, ql, qr);
    auto t2 = query_segtree(2 * si + 1, (l + r) / 2 + 1, r, ql, qr);
    return max(t1, t2);
}

void update_segtree(int si, int l, int r, int ql, int s)
{
    if (l > ql || r < ql)
        return;
    if (ql == l && l == r)
    {
        segtree[si] = s;
        return;
    }
    update_segtree(2 * si, l, (l + r) / 2, ql, s);
    update_segtree(2 * si + 1, (l + r) / 2 + 1, r, ql, s);
    auto t1 = segtree[2 * si];
    auto t2 = segtree[2 * si + 1];
    segtree[si] = max(t1, t2);
}


signed main()
{
    IOS
    map<int, int> ind;
    map<int, int> rmap;
    int n;
    cin >> n;
    REP(i, n)
        cin >> h[i];
    REP(i, n)
        cin >> v[i];
    
    int mans = 0;
    REP(i, n)
    {
        int ret = query_segtree(1, 1, n, 1, h[i]-1);

        if(ret<=0)
        {
            dp[i] = v[i];
            update_segtree(1, 1, n, h[i], dp[i]);
        }
        else
        {
            dp[i] = ret + v[i];
            update_segtree(1, 1, n, h[i], dp[i]);
        }
        mans = max(mans, dp[i]);
        // cout << i << " " << dp[i] << "\n";
    }
    cout << mans;
    
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
int main(){
  char c;
  
 cin >> c;
  
  if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
    cout << "vowel" << endl;
  else cout << "consonant" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <tuple>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
using namespace std;
void init();
#define REP(var, num) for(sll var = 0; var < num; var++)
typedef signed long long sll;
typedef unsigned long long ull;
/*
numeric_limits<sll>::max()
*/

int main() {
    init();

    sll n, m;
    cin >> n >> m;
    vector<pair<sll, sll>> shops(n);
    REP(i, n) {
        sll a, b;
        cin >> a >> b;
        shops[i] = make_pair(a, b);
    }

    sort(shops.begin(), shops.end());

    sll cost = 0;
    REP(i, n) {
        if (!m) {
            break;
        }

        sll bought = min(m, shops[i].second);
        cost += bought * shops[i].first;
        m -= bought;
    }

    cout << cost << endl;
    return 0;
}

void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n = int(input())
    a = [int(x) for x in input().split()]
    sm = sum(a)
    xd = 0
    ans = float('inf')
    for i in range(n-1):
        xd += a[i]
        sm -= a[i]
        ans = min(ans, abs(xd - sm))
    print(ans)

        
    
t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

7
3 1
4 1
5 9
2 6
5 3
5 8
9 7 5

"""


Measured memory_bytes: 31672
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    set<ll> st;
    st.insert(-1);
    st.insert(n);
    ll ans = 0;
    vector<ll> a(n);
    rep(i,n){
        int b;
        cin >> b;
        --b;
        a[b] = i;
    }
    rep(i,n){
        auto idx = st.lower_bound(a[i]);
        ll r = *idx;
        ll l = *(--idx);
        ans += (i+1) * (a[i]-l) * (r-a[i]);
        st.insert(a[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 14264
#include <iostream> 

  

using namespace std; 

  

int main() 

{ 

  int i,s,h,m;   


  cin >> i ;

   
  h=i/3600;
  m=i%3600/60;
  s=i%3600%60;


   

   cout << h<< ":"<< m  <<":"<< s<<endl ; 

   

    

   return 0; 

} 


Measured memory_bytes: 3096
package main

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

func main() {
	A, P := sc.nextInt(), sc.nextInt()
	fmt.Println((A*3 + P) / 2)
}

var (
	sc scanner
)

func init() {
	sc = scanner{
		buf: make([]string, 0, 0),
		cur: 0,
		r:   bufio.NewReader(os.Stdin),
	}
}

type scanner struct {
	buf []string
	cur int
	r   *bufio.Reader
}

func (s *scanner) readln() {
	rbuf := make([]byte, 0, 0)
	for {
		line, prefix, err := s.r.ReadLine()
		if err != nil {
			panic(err)
		}
		rbuf = append(rbuf, line...)
		if prefix == false {
			break
		}
	}
	s.cur = 0
	s.buf = strings.Split(*(*string)(unsafe.Pointer(&rbuf)), " ")
}
func (s *scanner) isFull() bool {
	if s.cur == len(s.buf) {
		return true
	}
	return false
}
func (s *scanner) resetCur() {
	s.cur = 0
}
func (s *scanner) next() string {
	if s.cur == 0 {
		s.readln()
	}
	res := s.buf[s.cur]
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nexts() []string {
	s.readln()
	s.resetCur()
	return s.buf
}
func (s *scanner) nextInt() int {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.Atoi(s.buf[s.cur])
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextInts() []int {
	s.readln()
	res := make([]int, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.Atoi(s.buf[i])
	}
	s.resetCur()
	return res
}
func (s *scanner) nextFloat() float64 {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.ParseFloat(s.buf[s.cur],
		64)
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextFloats() []float64 {
	s.readln()
	res := make([]float64, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.ParseFloat(s.buf[i],
			64)
	}
	s.resetCur()
	return res
}
func digits(x int) int {
	return len(strconv.Itoa(x))
}
func powInt(x, p int) (result int) {
	result = 1
	for i := 0; i < p; i++ {
		result *= x
	}
	return
}
func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}
func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}
func abs(x int) int {
	return int(math.Abs(float64(x)))
}
func varDump(value ...interface{}) {
	for _, v := range value {
		fmt.Fprintf(os.Stderr, "%#v\n", v)
	}
}
func yes() {
	fmt.Println("Yes")
}
func no() {
	fmt.Println("No")
}

// Pair a
type Pair struct {
	first  int
	second int
}

// Queue a
type Queue struct {
	v []Pair
}

// Push for queue
func (q *Queue) Push(v Pair) {
	q.v = append(q.v, v)
}

// Pop for queue
func (q *Queue) Pop() Pair {
	r := q.v[0]
	q.v = q.v[1:]
	return r
}

// Front for queue
func (q Queue) Front() Pair {
	return q.v[0]
}

// Empty return true if empty
func (q Queue) Empty() bool {
	return len(q.v) == 0
}


Measured memory_bytes: 640
#include<bits/stdc++.h> 
using namespace std; 
  
const int MAX = 5e5+5;; 
  
// structure to store queries 
struct Query 
{ 
    int l, r, idx; 
}; 
  
// cmp function to sort queries according to r 
bool cmp(Query x, Query y) 
{ 
    return x.r < y.r; 
} 
  
// updating the bit array 
void update(int idx, int val, int bit[], int n) 
{ 
    for (; idx <= n; idx += idx&-idx) 
        bit[idx] += val; 
} 
  
// querying the bit array 
int query(int idx, int bit[], int n) 
{ 
    int sum = 0; 
    for (; idx>0; idx-=idx&-idx) 
        sum += bit[idx]; 
    return sum; 
} 
  
void answeringQueries(int arr[], int n, Query queries[], int q) 
{ 
    // initialising bit array 
    int bit[n+1]; 
    memset(bit, 0, sizeof(bit)); 
  
    // holds the rightmost index of any number 
    // as numbers of a[i] are less than or equal to 10^6 
    int last_visit[MAX]; 
    memset(last_visit, -1, sizeof(last_visit)); 
  
    // answer for each query 
    int ans[q]; 
    int query_counter = 0; 
    for (int i=0; i<n; i++) 
    { 
        // If last visit is not -1 update -1 at the 
        // idx equal to last_visit[arr[i]] 
        if (last_visit[arr[i]] !=-1) 
            update (last_visit[arr[i]] + 1, -1, bit, n); 
  
        // Setting last_visit[arr[i]] as i and updating 
        // the bit array accordingly 
        last_visit[arr[i]] = i; 
        update(i + 1, 1, bit, n); 
  
        // If i is equal to r of any query  store answer 
        // for that query in ans[] 
        while (query_counter < q && queries[query_counter].r == i) 
        { 
            ans[queries[query_counter].idx] = 
                     query(queries[query_counter].r + 1, bit, n)- 
                     query(queries[query_counter].l, bit, n); 
            query_counter++; 
        } 
    } 
  
    // print answer for each query 
    for (int i=0; i<q; i++) 
        cout << ans[i] << endl; 
} 
int main()
{
	int n, q;
	cin>>n>>q;
	int a[n];
	for(int i = 0; i < n; i++)
		cin>>a[i];
	Query queries[q];
	for(int i = 0; i < q; i++)
	{
		cin>>queries[i].l>>queries[i].r;
		queries[i].l--, queries[i].r--;
		queries[i].idx = i;
	}
	sort(queries, queries+q, cmp);
	answeringQueries(a, n, queries, q);
}

Measured memory_bytes: 17404
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def No(): print('No')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N = iin()

dp = [INF for _ in range(N+1)]
dp[0] = 0

for i in range(N):
    pow6 = 1
    while i+pow6 < N+1:
        dp[i+pow6] = min(dp[i+pow6], dp[i]+1)
        pow6 *= 6
    pow9 = 1
    while i+pow9 < N+1:
        dp[i+pow9] = min(dp[i+pow9], dp[i]+1)
        pow9 *= 9
print(dp[N])

Measured memory_bytes: 6060
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define Int long long
#define N 200200

Int dp[N];
Int tree[2*N+1];
Int a[N],f[N];

void update(Int x,Int v,Int node,Int l,Int r)
{
    if(l==r){
        tree[node]=v;return;
    }
    Int mid = (l+r)/2;
    if(x<=mid)
    {
        update(x,v,(2*node),l,mid);
    }
    else
    {
        update(x,v,(2*node+1),mid+1,r);
    }
    tree[node]=max(tree[2*node],tree[2*node+1]);
}

Int Q(Int s,Int e,Int node,Int l,Int r)
{
    if(l>=s&&r<=e)return tree[node];
    else if(l>e||r<s)return 0;
    int mid = (l+r)/2;
    Int x = Q(s,e,2*node,l,mid);
    Int y = Q(s,e,2*node+1,mid+1,r);
    return max(x,y);
}


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    Int n,m;
    cin>>n;
    for(Int i = 1;i<=n;i++)cin>>a[i];
    for(Int i = 1;i<=n;i++)cin>>f[i];
    for(Int i = 1;i<=n;i++)
    {
        dp[a[i]]=Q(1,(a[i]-1),1,1,n)+f[i];

        update(a[i],dp[a[i]],1,1,n);
        //cout<<a[i]<< "  "<<Q(1,(a[i]),1,1,n)<<" "<<dp[a[i]]<<endl;

    }
    Int ans=0;
    for(Int i = 1;i<=n;i++)ans=max(ans,dp[a[i]]);
    //for(Int i = 1;i<=(2*n-1);i++)cout<<i<<" "<<tree[i]<<endl;
    cout<<ans<<endl;
}


Measured memory_bytes: 11444
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll int64_t
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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


int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

ll dp[101010];
ll h[101010];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,K;
    cin>>n>>K;
    REP(i,n) cin>>h[i];
    REP(i,101010) dp[i]=1LL<<60;
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int k=1;k<=K;k++){
            chmin(dp[i+k],dp[i]+abs(h[i+k]-h[i]));
        }
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
#include<cctype>

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int,int> pii;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int n,s;

int solve(int cnt,int sum,int now){
	if(cnt == 10){
		return sum == s && now == n;
	}
	int res1 = solve(cnt + 1,sum + cnt,now + 1);
	int res2 = solve(cnt + 1,sum,now);
	return res1 + res2;
}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	while(1){
		cin >> n >> s;

		if(n == 0 && s == 0) break;

		int ans = solve(0,0,0);

		cout << ans << endl;
	}

	return 0;
}

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

#define CLR(a,b) memset(a,(b),sizeof(a))
#define LL long long

const int N = 1e2+10;
LL gcd(LL a, LL b)
{
    if(b == 0) return a;
    return gcd(b,a%b);
}
int main()
{
    int n;
    cin>>n;
    LL sum = 1, k = 1;
    LL x;
    for(int i = 0; i < n; i++) {
        cin>>x;
        sum = k/gcd(k,x)*x;
        k = sum;
    }
    cout<<sum<<endl;
return 0;
}


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

#define N 3
#define N2 9

struct Puzzle {
  int f[N2];
  int space;
  string path;

  bool operator < ( const Puzzle &p ) const {
    for (int i = 0; i < N2; i++) {
      if (f[i] == p.f[i]) continue;
      return f[i] > p.f[i];
    }
    return false;
  }
};

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

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

string bfs(Puzzle s) {
  queue<Puzzle> Q;
  map<Puzzle, bool> V;
  Puzzle u, v;
  s.path = "";
  Q.push(s);
  V[s] = true;

  while ( !Q.empty() ) {
    u = Q.front();
    Q.pop();
    if ( isTarget(u) ) return u.path;
    int sx = u.space / N;
    int sy = u.space % N;
    for (int r = 0; r < 4; r++) {
      int tx = sx + dx[r];
      int ty = sy + dy[r];
      if ( tx < 0 || ty < 0 || tx >= N || ty >= N ) continue;
      v = u;
      swap(v.f[u.space], v.f[tx * N + ty]);
      v.space = tx * N + ty;
      if ( !V[v] ) {
        V[v] = true;
        v.path += dir[r];
        Q.push(v);
      }
    }
  }

  return "unsolvable";
}

int main() {
  Puzzle in;

  for (int i = 0; i < N2; i++) {
    cin >> in.f[i];
    if (in.f[i] == 0) {
      in.f[i] = N2;
      in.space = i;
    }
  }
  string ans = bfs(in);
  cout << ans.size() << endl;

  return 0;
}


Measured memory_bytes: 30544
import java.util.*;

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

        if(e < c && e != 0){
            c = e;
        }
        Set<Integer> set = new TreeSet<>();

        for(int i = 0;i<c;i++){
            set.add(a++);
        }
        for(int i = 0;i<c;i++){
            set.add(b--);
        }
        if(e == 0){
            System.out.println(a2);
        }else{
            for(Integer d:set){
                System.out.println(d);
            }
        }
    }
}

Measured memory_bytes: 21844
h,w,K = map(int, input().split())
G = [list(input()) for _ in range(h)]
count = 0
for i in range(2**h):
    for j in range(2**w):
        tmp = 0
        for k in range(h):
            for m in range(w):
                if (not i>>k&1) and (not j>>m&1) and G[k][m] == '#':
                    tmp +=1
        if tmp == K:
            count += 1
print(count)



Measured memory_bytes: 68176
#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字くらい使った方がいいかも
*/

double f(double x, int l, int r, int v){
    if(0.0 <= x && x <= l) return v+l-x;
    else if(l <= x && x <= r) return v;
    else return v+(x-r);
}

int main(){
    int N; cin >> N;
    vector<int> l(N+2), r(N+2), v(N+2), t(N+1);
    for(int i=1; i<=N; i++) cin >> t[i];
    for(int i=1; i<=N; i++) cin >> v[i];
    
    l[1] = 0, r[1] = t[1];
    for(int i=2; i<=N; i++){
        l[i] = r[i-1];
        r[i] = l[i]+t[i];
    }

    l[0] = 0, r[0] = 0, v[0] = 0;
    l[N+1] = r[N], r[N+1] = r[N]; v[N+1] = 0;

    double ans = 0.0;

    double h1 = 0.0;
    for(double a=0.5; a<=r[N]; a+=0.5){
        double h2 = 500;
        for(int i=0; i<N+2; i++) h2 = min(h2, f(a, l[i], r[i], v[i]));
        ans += (h1 + h2)*0.25;
        h1 = h2;
    }

    printf("%.6f\n", ans);
}

Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sec = sc.nextInt();
		
		int hour = sec / 3600 ;
		int min = (sec%3600) / 60 ;
		sec = sec % 60 ;
		
		System.out.println(hour+":"+min+":"+sec);
	}
}



Measured memory_bytes: 26272
import java.util.Arrays;
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];
		long firstMax = 0;
		long secondMax = 0;
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		boolean firstFound = false;
		for (int i = n-2; i >= 0; i--) {
			if (a[i] == a[i+1]) {
				if (firstFound) {
					secondMax = (long)a[i];
					break;
				} else {
					firstFound = true;
					firstMax = (long)a[i];
					a[i] = 0;
				}
			}
		}
		System.out.println(firstMax * secondMax);
	}

}


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

int main() {

    int n;
    cin >> n;
    vector<pair<double, double>> v;
    rep(i, n){
        double x, y;
        cin >> x >> y;
        v.emplace_back(x, y);
    }

    double ans = 0;
    for(int i=0; i<n-1; ++i){
        for(int j=i+1; j<n; ++j){
            ans += sqrt(pow(v[i].first - v[j].first, 2) + pow(v[i].second - v[j].second, 2)) * 2.0;
        }
    }

    cout << fixed << setprecision(10) << ans / (double)n << endl;

    return 0;
}


Measured memory_bytes: 384
integer N
integer,allocatable,dimension(:)::S
integer Ssum
read*,N
allocate(S(N))
do i=1,N
  read*,S(i)
end do
Ssum=sum(S)
if(mod(Ssum,10)==0)then
  call heapsort(N,S)
  do i=1,N
    if(mod(S(i),10)/=0)then
      Ssum=Ssum-S(i)
      exit
    endif
  end do
endif
if(mod(Ssum,10)==0)Ssum=0
print"(i0)",Ssum
contains
subroutine heapsort(n,array)
  implicit none
!ここの入力は状況に応じて変更すること
  integer,intent(in) :: n
  integer,intent(inout) :: array(1:n)
  integer::i,k,j,l
  integer:: t

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j<=k)
        if(j < k)then
           if(array(j) < array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo
  return
end subroutine heapsort
end

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  char s[7];
  scanf("%s", s);
  int answer = 0;
  for (int i = 0; i < 6; i++) {
    if (s[i] == '1') {
      answer++;
    }
  }
  printf("%d\n", answer);

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define testbit(mask,i) (((mask)>>(i))&1)
#define setbit(mask,i) ((mask)|(1<<i))
#define delbit(mask,i) ((mask)^(1<<i))
#define lowbit(x) ((x)&(-x))
#define randome_generate srand(std::chrono::high_resolution_clock::now().time_since_epoch().count())
using namespace std;
int n,k;
long double p[200100];
long double e[200100];
long double he[200100];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>p[i];
	for(int i=1;i<=n;i++){
		e[i]=(long double)(p[i]+1.000)/(long double)(2.000);

		he[i]=he[i-1]+e[i];
	}
	long double ret=0.00000;
	for(int i=k;i<=n;i++)
		ret=max(ret,he[i]-he[i-k]);
	cout<<fixed<<setprecision(20)<<ret<<endl;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_b() {
	ll n, m;
	ll x, y;
	ll a, b, c;
	ll k;
	ll l;
	string s, t;
	ll l_ans = 0;
	float f_ans = 0;
	string s_ans;

	cin >> n;

	V d(n);
	rep(i, n) cin >> d[i];

	rep(i, n) {
		rep(j, n) {
			if (i < j) {
				l_ans += d[i] * d[j];
			}
		}
	}

	cout << l_ans << "\n";
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed;
	cout << setprecision(7);

	solve_abc_b();

	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
typedef int64_t llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define ld PRId64


int main(){
    string s,t;
    cin >> s >> t;
    vector<string> S;
    int j;
    string tmp;
    REPR(i,s.size()-t.size()){
        for(j=0;j<t.size();j++){
            if(s[i+j]!='?'){
                if(s[i+j] != t[j]) break;
            }
        }
        if(j==t.size()){
            tmp=s;
            tmp.replace(i,t.size(),t);
            REP(m,tmp.size()) if(tmp[m]=='?') tmp.replace(m,1,"a");
            S.push_back(tmp);
        }
    }
    if(S.size()==0) cout <<"UNRESTORABLE" << endl;
    else{
        Sort(S);
        cout << S[0] << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
using namespace std;
#define int long long
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;
#define X first
#define Y second
#define all(o) o.begin(), o.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0), cin.tie(0)

int gcd(int x,int y){ return (!y ? x : gcd(y, x%y)); }

int32_t main(){
	IOS;
	int n;
	cin >> n;
	cout << n * (n - 1) / 2LL;

}


Measured memory_bytes: 256
use proconio::{input,fastout};

const MOD: i64 = 1e9 as i64 + 7;
#[fastout]
fn main(){
    input!{
        n: i64,
        k: i64
    }
    let mut min: i64 = 0;
    let mut max: i64 = 0;
    let mut ans: i64 = 0;
    for i in 0 .. k {
        min += i;
        max = max + n - i;
    }
    ans += max - min + 1;
    for i in k .. n+1 {
        min += i;
        max += n - i;
        ans += max - min + 1
    }
    println!("{}", ans % MOD);
}

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

const int MOD = 1e9 + 7;
int N, K;
ll dp[110][110000];
int a[110];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> N >> K;
	for (int i = 1; i <= N; i++) cin >> a[i];
	dp[0][0] = 1;
	for (int i = 1; i <= N; i++) {
		ll psum[110000] = { 0 };
		for (int j = 0; j <= K; j++) {
			psum[j + 1] = (psum[j] + dp[i - 1][j] + MOD) % MOD;
			dp[i][j] = (dp[i][j] + psum[j + 1] - psum[max(0, j - a[i])] + MOD) % MOD;
		}
	}
	cout << dp[N][K] << '\n';
	return 0;
}

Measured memory_bytes: 88320
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD  998244353
#define REP(i,n) for(long long i = 0;i < n;++i)
int dp[2001][2001];
int coloring[2][2001][4001] = {};
int spaces[2][5000] = {};
int main() {
	int n;
	cin >> n;
	vector<pair<int, int>> input;
	REP(i, 2 * n) {
		string s;
		cin >> s;
		int nya = 0;
		cin >> nya;
		input.push_back(make_pair(s == "B" ? 0 : 1, nya-1));
		spaces[input[i].first][nya-1] = i;
	}
	for (int i = 0; i <= n; ++i) {
		for (int q = 1; q <= 2 * n; ++q) {
			coloring[0][i][q] = coloring[0][i][q - 1];
			coloring[1][i][q] = coloring[1][i][q - 1];
			if (input[q - 1].second < i) {
				coloring[input[q - 1].first][i][q]++;
			}
		}
	}
	REP(i, 2001) {
		REP(q, 2001) {
			dp[i][q] = 2500*2500;
		}
	}
	dp[0][0] = 0;
	for (int black = 0;black <= n; ++black) {
		for (int white = 0; white <= n; ++white) {
			if (black != n) {
				int next_place = spaces[0][black];
				int cost = next_place - coloring[0][black][next_place] - coloring[1][white][next_place];
				dp[black + 1][white] = min(dp[black + 1][white], dp[black][white] + cost);
			}
			if (white != n) {
				int next_place = spaces[1][white];
				int cost = next_place - coloring[0][black][next_place] - coloring[1][white][next_place];
				dp[black][white+1] = min(dp[black][white + 1], dp[black][white] + cost);
			}
		}
	}
	cout << dp[n][n] << endl;
	return 0;
}


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

struct SugarWater{
    int wat,sug;
    bool operator < (const SugarWater & x) const{
        return sug * (x.wat+x.sug) > x.sug * (wat+sug);
    }
};

int A,B,C,D,E,F;
vector<SugarWater> sw;

int main(){
    cin >> A >> B >> C >> D >> E >> F;
    for(int i = 0;i <= F / (100*A);++i){
        for(int j = 0;j <= F / (100*B);++j){
            int w = i * 100 * A + j * 100 * B;
            int rem = F - w, mx = 0;
            if(w == 0 || w > F) continue;
            for(int p = 0;p <= rem / C;++p){
                for(int q = 0;q <= rem / D;++q){
                    int tmp = p*C + q*D;
                    if(tmp > rem || tmp > w/100*E) continue;
                    if(tmp * (mx + w) > mx * (tmp + w))
                        mx = tmp;
                }
            }
            sw.push_back({w,mx});
        }
    }
    sort(sw.begin(),sw.end());
    printf("%d %d\n",sw[0].sug+sw[0].wat,sw[0].sug);

    return 0;
}


Measured memory_bytes: 256
import sys
from math import cos, radians

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    A, B, H, M = map(int, rl().split())
    
    rad_h = 0.5 * (60 * H + M)
    rad_m = M * 6
    rad = min(abs(rad_h - rad_m), abs(rad_m - rad_h))
    ans = ((A ** 2) + (B ** 2) - (2 * A * B * cos(radians(rad)))) ** 0.5
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 62628
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int D = 60;
const int MAX_N = 200005;
int to[D][MAX_N];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll k;
    cin >> n >> k;
    rep(i,n){
        cin >> to[0][i];
        to[0][i]--;
    }
    rep(i,D-1){
        rep(j,n){
            to[i+1][j] = to[i][to[i][j]];
        }
    }
    int v = 0;
    for(int i = D-1; i >= 0; --i){
        ll l = 1LL<<i;
        if(l <= k){
            v = to[i][v];
            k -= l;
        }
    }
    cout << v + 1 << endl;
    return 0;
}

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

#define rep(i,n) for(int i = 0;i < (int)(n);i++)
int main(){
    int h,w;
    while(1){
        cin >> h >> w;
        if(h == 0 && w == 0) break;
        rep(i,h){
            rep(j,w) cout << '#';
            cout << endl;
        }
        cout << endl;
    }
}



Measured memory_bytes: 3100