akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int a,b,c,d,e;
	
	cin>>a>>b>>c>>d>>e;
	
	int val=(c-a)*60+(d-b);
	
	cout<<max(0,val-e)<<endl;
}


Measured memory_bytes: 3652
import math 
hour , minute , h , m = map(int,input().split())
ht = h + m/60 
h_angle = (2*math.pi/12)*ht 
m_angle = (2*math.pi/60)*m 
angle = abs(h_angle-m_angle)
angle = min(2*math.pi-angle,angle)
ans = (hour**2 + minute**2 - 2*hour*minute*(math.cos(angle)))
print(ans**0.5)

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

const int MAX_N = 1e5 + 10;

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

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

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main()
{
	string s;
	cin >> s;
	int ans = 1e5 + 10;
	for (int start = 0; start <= 1; ++start)
	{
		int val = start;
		int count = 0;
		for (int i = 0; i < s.size(); ++i)
		{
			if (s[i] - '0' != val)
				++count;
			val = 1 - val;
		}
		chmin(ans, count);
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    double a, b, h, m;  cin >> a >> b >> h >> m;
    double t = 60*h + m;
    double ans = sqrt(a*a + b*b - 2*a*b*cos(t*M_PI*11/360)); 
    printf("%.10lf\n", ans);
}


Measured memory_bytes: 4212
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
vector<vector<long long>> dp(3000,vector<long long>(3000,INF));
int n;
vector<long long> a(3000);
long long res(int l, int r)
{
	if(l>r)
		return 0;
	if(dp[l][r]!=INF)
		return dp[l][r];
	int length = r - l + 1;
	if(length%2 == n%2)
	{
		return (dp[l][r] = max(res(l+1,r)+a[l],res(l,r-1)+a[r]));
	}
	else
	{
		return (dp[l][r] = min(res(l+1,r)-a[l],res(l,r-1)-a[r]));
	}
}
int main()
{	
	cin>>n;
	for(int i = 0;i<n;i++)
		cin>>a[i];
	long long ans = res(0,n-1);
	cout<<ans<<'\n';
}


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n){cin >> a[i];}
  sort(a.begin(),a.end(),greater<int>());
  
  int alice=0,bob=0;
  rep(i,n){
    if(i%2==0){
      alice+=a[i];
    }else{
      bob+=a[i];
    }
  }
  cout << alice-bob << endl;
}

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

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if(A == C){
        cout << 0 << "\n";
    } else{
        cout << 1 << "\n";
    }
    return 0;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    int n;cin >> n;
    int ans =1000000;
    for (int i = 0; i < n;i++){
        int x;
        cin >> x;
        int cnt = 0;
        while(x%2==0){
            x /= 2;
            cnt++;
        }

        ans = min(ans, cnt);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int coins[6] = {500, 100, 50, 10, 5, 1};

int main() {
    int pay;
    int change;
    int num;
    
    while(cin >> pay, pay){
    	change = 1000 - pay;
    	num = 0;
    	for(int i=0;i<6;++i){
    		num += change / coins[i];
    		change =  change % coins[i];
    	}
    	cout << num << endl;
    }
}

Measured memory_bytes: 1160
#include<stdio.h>
int main(void) {
	int a,i;
	char s[10];
	scanf("%d", &a);
	scanf("%s", s);
 
	if (a > 2800 || a <= 5000) {
		if (a >= 3200) 
			printf("%s", s);
		else
			printf("red");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 

using namespace std;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))

int main()
{
	int n;
	cin >> n;
	long long ans = -1000000000;
	vector<vector<int>> f(n, vector<int>(10));
	vector<vector<long long>> p(n, vector<long long>(11));
	rep(i, 0, n - 1)rep(j, 0, 9)
	{
		cin >> f[i][j];
	}
	rep(i, 0, n - 1)rep(j, 0, 10)
	{
		cin >> p[i][j];
	}
	rep(i, 1, pow(2, 10) - 1)
	{
		long long temp = 0;
		vector<vector<int>> res(n, vector<int>(2, 0));
		rep(j, 0, n - 1)res[j][0] = j;
		rep(j, 0, 9)
		{
			if (i >> j & 1 == 1)
			{
				rep(k, 0, n - 1)
				{
					if (f[k][j] == 1)
					{
						++res[k][1];
					}
				}
			}
		}
		rep(j, 0, n - 1)
		{
			temp += p[j][res[j][1]];
		}
		ans = max(ans, temp);
	}
	cout << ans << endl;
}



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

    int main()
    {
        // get a integer
        int a,b,c,d;
        cin >> a>>b>>c>>d;
        // get two integers separated with half-width break
       // int b,c;
       // cin >> b >> c;
        // get a string
      //  string ss;
      //  cin >> ss;
        // output
        if(a+b>c+d)
            cout<<"Left";
        else if(a+b==c+d)
            cout<<"Balanced";
        else
            cout<<"Right";

        return 0;
    }


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdint>
#include <string>

using i64 = std::int64_t;

int main() {
	int n, p;
	std::cin >> n >> p;

	if (p == 2 || p == 5) {
		i64 ans = 0;
		for (int i = 0; i < n; ++i) {
			char c;
			std::cin >> c;

			int x = c - '0';
			if (x % p == 0)
				ans += i + 1;
		}

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

	std::string s;
	std::cin >> s;

	std::vector<int> count(p);
	count[0] = 1;

	int cum = 0, dig = 1;
	i64 ans = 0;
	for (int i = n - 1; i >= 0; --i) {
		int x = s[i] - '0';

		cum = (cum + x * dig) % p;
		ans += count[cum];
		++count[cum];

		dig = (dig * 10) % p;
	}

	std::cout << ans << std::endl;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-5;

int main() {
	for (;;) {
		int N; cin >> N;
		if (N == 0) break;
		vector<double> x(N), y(N);
		for (int i = 0; i < N; i++)
			cin >> x[i] >> y[i];
		int maxi = 1;
		for (int i = 0; i < N; i++)
			for (int j = 0; j < N; j++) {
				if (i == j) continue;
				double dx = x[j] - x[i], dy = y[j] - y[i];
				double d = sqrt(dx * dx + dy * dy);
				if (d > 2) continue;
				double h = sqrt(1 - d * d / 4);
				double ox = x[i] + dx / 2 - dy / d * h;
				double oy = y[i] + dy / 2 + dx / d * h;
				int cnt = 0;
				for (int k = 0; k < N; k++) {
					double dx = x[k] - ox, dy = y[k] - oy;
					double d2 = dx * dx + dy * dy;
					if (d2 <= 1 + EPS) cnt++;
				}
				maxi = max(maxi, cnt);
			}
		cout << maxi << endl;
	}
}

Measured memory_bytes: 1244
#include "bits/stdc++.h"

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back

using namespace std;

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,int>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60, lmod = 1e9+7;
const int MAX_N = 100005;

template<typename T> T inf;
template<> constexpr int inf<int> = 1<<30;
template<> constexpr ll inf<ll> = 1LL<<60;

using Cost = ll;
using Node = int;
struct Edge{
  Cost cost; Node to;
  Edge(Cost cost,Node to)
    :cost(cost),to(to){}
};
using Graph = vector<vector<Edge>>;

vector<Cost> dijkstra
(Graph &graph, Node start, ll pat[], Cost zero = 0LL)
{
  using Pcn = pair<Cost,Node>;
  priority_queue<Pcn,vector<Pcn>,greater<Pcn>> que;
  vector<Cost> dist(graph.size(),inf<Cost>);
  dist[start] = zero;
  pat[start] = 1LL;
  que.push(Pcn(zero,start));
  while(!que.empty()){
    Pcn p = que.top(); que.pop();
    Node v = p.second; //行き先
    if(dist[v] < p.first)  continue;
    for(Edge e : graph[v]){
      if(dist[v]+e.cost < dist[e.to]){
        dist[e.to] = dist[v]+e.cost;
        // 最小値を更新したら今までのパターンを消す
        pat[e.to] = 0LL;
        que.push(Pcn(dist[e.to],e.to));
      }
      if(dist[v]+e.cost == dist[e.to]){
        // 最小値を見つけたらパターンを足す
        (pat[e.to] += pat[v]) %= lmod;
      }
    }
  }
  return dist;
}

Graph graph;
ll patS[MAX_N],patT[MAX_N];

int main(){
  int N,M; scanf("%d%d",&N,&M);
  graph.resize(N);
  int S,T; scanf("%d%d",&S,&T); S--; T--;
  rep(i,M){
    int l,r; ll dd; scanf("%d%d%lld",&l,&r,&dd);
    l--; r--; graph[l].pb(Edge(dd,r)); graph[r].pb(Edge(dd,l));
  }
  auto distS = dijkstra(graph,S,patS);
  auto distT = dijkstra(graph,T,patT);
  ll ans = patS[T] * patS[T] % lmod;
  ll len = distS[T];
  rep(i,N){
    if(distS[i]+distT[i]==len && distS[i]*2LL==len){
      (ans += (lmod - patS[i]*patS[i]%lmod*patT[i]%lmod*patT[i]%lmod)) %= lmod;
    }
  }
  rep(i,N) for(auto e:graph[i]){
    int j = e.to; ll c = e.cost;
    if(distS[i]+c+distT[j]==len && distS[i]*2LL<len && distT[j]*2LL<len){
      (ans += (lmod - patS[i]*patS[i]%lmod*patT[j]%lmod*patT[j]%lmod)) %= lmod;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 18772
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string sample;
	string answer="keyence";
	cin>>sample;
	int length=sample.size()-7;
	int eval;
	for(int i=0;i<8;i++)
	{
		eval=0;
		for(int j=0;j<i;j++)
		{
			if(sample[j]==answer[j]){
				eval++;
			}
		}
		for(int j=length+i;j<=length+6;j++)
		{
			if(sample[j]==answer[j-length]){
				eval++;
			}
		}
		if(eval==7)
		{
			cout<<"YES";
			break;
		}

	}
	if(eval!=7)cout<<"NO";
}

Measured memory_bytes: 256
import java.util.*;
public class Main
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        long a=sc.nextLong();
        long b=sc.nextLong();
        long k=sc.nextLong();
        if(k<=a)
        {
            System.out.println((a-k)+" "+b);
        }
        else if(k>a&&k<a+b)
        {
            System.out.println("0 "+(a+b-k));
        }
        else 
        {
            System.out.println("0 0");
        }
    }
}

Measured memory_bytes: 21972
#include<stdio.h>
typedef unsigned long long ull;
int main(){
	ull x;
	scanf("%llu",&x);
	ull cur=100;
	ull y=0;
	while(cur<x){
		cur*=1.01;
		y++;
		//printf("%llu\n",cur);
	}
	printf("%llu\n",y);
}

Measured memory_bytes: 1732
#include <iostream>
#include <vector>
#include <algorithm>

#define ll long long
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n + 1);
    for (int i = 0; i <= n; i++)cin >> a[i];
    vector<ll> b(n + 1);
    for (int i = 0; i < n; i++)cin >> b[i];

    ll ret = min(a[0], b[0]);
    a[0] -= ret;
    b[0] -= ret;
    for (int i = 1; i <= n; i++) {
        ll x = min(a[i], b[i - 1] + b[i]);
        a[i] -= max(0LL, x - b[i - 1]);
        b[i] -= max(0LL, x - b[i - 1]);
        ret += x;
    }

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

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

namespace _20180129education2
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());

            int b = 0;

            int[] d = new int[a];

            int[] v = new int[100+1];

            for (int i = 0 ; i < a; i++)
            {
                int input = int.Parse(Console.ReadLine());
                d[i] = input;
             
            }

            for(int n=0; n <a; n++)
            {
                v[d[n]] = 1;
                
            }

            Console.WriteLine(v.Sum());

        }
    }
}


Measured memory_bytes: 13268
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

module ModOp = struct
  let prime = 1_000_000_007
  let (-) a b = (a + prime - b) mod prime
  let (+) a b = (a + b) mod prime
  let ( * ) a b = (a * b) mod prime

  let rec pow x n =
    if n = 0 then 1
    else if n mod 2 = 0 then pow (x*x) (n/2)
    else x * pow (x*x) (n/2)
end

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let s = scan "%s" id

let () =
  if String.get s 2 = String.get s 3 &&
     String.get s 4 = String.get s 5
  then Printf.printf "Yes\n"
  else Printf.printf "No\n"


Measured memory_bytes: 5368
import math
n, m = map(int, input().split(" "))
aL = list(map(int, input().split(" ")))

sm = sum(aL)

cnt = 0
for a in aL:
    if sm * (1 / (4 * m)) <= a:
        cnt += 1
    if m <= cnt:
        print("Yes")
        exit()

print("No")

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

int main() {
    int N, M; cin >> N >> M;
    long long a[N];
    for(int i = 0; i < N; i++) cin >> a[i];
    sort(a, a + N);
    vector<pair<long long, int>> chang(M);
    for (int i = 0; i < M; i++)
    {
        int b;
        long long c;
        cin >> b >> c;
        chang[i] = make_pair(c, b);
    }
    sort(chang.begin(), chang.end());
    reverse(chang.begin(), chang.end());

    int j = 0;
    int cnt = 0;
    for (int i = 0; i < N; i++)
    {
        if(a[i] >= chang[j].first) break;
        a[i] = chang[j].first;
        cnt++;
        if(cnt == chang[j].second){
            j++;
            cnt = 0;
        }
    }

    long long ans = 0;
    for (int i = 0; i < N; i++)
    {
        ans += a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <stdio.h>
int main(void)
{
	int a, b, c, x;
	int i, j, k; 
	int z = 0;

	scanf("%d%d%d%d", &a, &b, &c, &x);
	
	for (i = 0;i <= a;i++) {
		for (j = 0;j <= b;j++) {
			for (k = 0;k <= c;k++) {
				if (500 * i + 100 * j + 50 * k == x) {
					z++;
				}
			}
		}
	}

	printf("%d", z);
	return 0;
}

Measured memory_bytes: 1672
import java.util.*;

public class Main {

    public static void main(String[] args) {
	// write your code here

        Scanner scan = new Scanner(System.in);
int N=scan.nextInt();
   long A[]=new long[N];
        long B[]=new long[N];

   for(int i=0;i<N;i++){A[i]=scan.nextLong();}
long M=0;
        B[0]=A[0];
   for(int i=1;i<N;i++){
       B[i]=B[i-1]+A[i];
       B[i]=B[i]%1000000007;
   }
   for(int i=0;i<N-1;i++){M=M+A[i+1]*B[i];
   M=M%1000000007;}
System.out.println(M);
        }

}


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

typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

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

int main(){
    int k, x; cin>>k >> x;
    int n = k*500;
    if(n>=x){
        cout << "Yes" << endl;
        return 0;
    }else{
        cout << "No" << endl;
        return 0;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fly ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define ll long long

const ll mxm = 100010;

using namespace std;

ll a[mxm][4];
ll n;
ll dp[mxm][4];

ll fnc(ll i, ll old){
  if(i == n){
    return 0;
  }else{
    if(dp[i][old] != -1)return dp[i][old];
    ll res1 = 0;
    ll res2 = 0;
    ll res3 = 0;
    if(old == 0){
      res1 = a[i][1] + fnc(i+1,1);
      res2 = a[i][2] + fnc(i+1,2);
      res3 = a[i][3] + fnc(i+1,3);
    }else if(old == 1){
      res2 = a[i][2] + fnc(i+1,2);
      res3 = a[i][3] + fnc(i+1,3);
    }else if(old == 2){
      res1 = a[i][1] + fnc(i+1,1);
      res3 = a[i][3] + fnc(i+1,3);
    }else{
      res1 = a[i][1] + fnc(i+1,1);
      res2 = a[i][2] + fnc(i+1,2);
    }
    return dp[i][old] = max(res1, max(res2,res3));
  }
}


int main(int argc, char const *argv[]) {
  fly;
  cin >> n;
  for(int i = 0;i<n;i++){
    cin >> a[i][1] >> a[i][2] >> a[i][3];
  }
  memset(dp,-1,sizeof(dp));
  cout << fnc(0,0) << endl;
  return 0;
}


Measured memory_bytes: 17636
object Main extends App {

  import scala.io.StdIn._

  val n = readLine.trim.toInt
  val a = readLine.trim.split(' ').map(_.toLong)
  val b = readLine.trim.split(' ').map(_.toLong)
  if (a.sum >= b.sum){
    val diff = a.zip(b).map{case (a, b) ⇒ a - b}
    val minus = diff.filter(_ < 0)
    val sum = minus.sum
    val plus = diff.filter(_ > 0).sorted.reverse
    for (i ← plus.indices.tail) plus(i) += plus(i - 1)
    if (sum == 0) println(0)
    else println(minus.length + lowerBound(plus, -sum) + 1)
  }else {
    println(-1)
  }
  def lowerBound(array: Array[Long], target: Long): Int = {
    var left = 0
    var right = array.length
    while(left < right){
      val mid = (left + right) / 2
      if (array(mid) < target){
        left = mid + 1
      }else {
        right = mid
      }
    }
    right
  }
  implicit class Extension[T](value :T){
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
    @inline
    def also(@inline func: T ⇒ Unit): T = {func(value); value}
  }
}

Measured memory_bytes: 89564
#include <bits/stdc++.h>
#define gcd __gcd
using namespace std;
int main(){
	int k;
	long long int acumulador = 0;
	cin >> k;
	for(int i = 1 ; i <= k;i++){
		for(int j = 1 ; j <= k;j++){
			for(int l = 1 ; l <= k;l++){
				acumulador+=gcd(i,(gcd(j,l)));
			}
		}	
	}
	cout << acumulador << endl;
}

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define FORr(i, j, k) for(int i = j; i >= k; --i)
#define repr(i, j) FOR(i, j, 0)
#define INF (1 << 30)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

ll t[100];

ll gcd(ll x, ll y) {
    return (y == 0) ? x : gcd(y, x % y);
}

ll lcm(ll x, ll y) {
    ll n = gcd(x, y);
    return x / n * y;
}

ll solve(int size) {
  ll res = t[0];
  FOR(i, 1, size) if(res % t[i] != 0) res = lcm(res, t[i]);
  return res;
}

int main() {
    int n;
    scanf("%d", &n);
    rep(i, n) scanf("%lld", &t[i]);
    ll ans = solve(n);
    printf("%lld\n", ans);
    return 0;
}

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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;
int n;

int dfs(ll x) {
	if(x > n) return 0;

	int rsl = 0;
	string xs = to_string(x);

	bool flag3 = false, flag5 = false, flag7 = false;
	rep(i, 0, xs.size()) {
		if(xs[i] == '3') flag3 = true;
		if(xs[i] == '5') flag5 = true;
		if(xs[i] == '7') flag7 = true;
	}

	if(flag3 and flag5 and flag7) {
		rsl = 1;
	}

	int a[] = {3, 5, 7};
	rep(i, 0, 3) rsl += dfs(10 * x + a[i]);
	return rsl;
}


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

	cin >> n;

	cout << dfs(0) << endl;
}


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

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

int h,w,r,c;
int wav[505][505];
int wah[505][505];

bool win[505][505];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};

void solve(){
	memset(win,false,sizeof(win));
	queue<P> que;
	for(int i=1;i<=w;i++){
		win[0][i]=true;
		que.push(P(1,i));
		win[h+1][i]=true;
		que.push(P(h,i));
	}
	for(int i=1;i<=h;i++){
		win[i][0]=true;
		que.push(P(i,1));
		win[i][w+1]=true;
		que.push(P(i,w));
	}
	while(que.size()){
		P p=que.front();
		que.pop();
		bool flag1=false;
		bool flag2=false;
		if(win[p.first-1][p.second]){
			if(wav[p.first-1][p.second]==1)flag1=true;
			else flag2=true;
		}
		if(win[p.first+1][p.second]){
			if(wav[p.first][p.second]==1)flag1=true;
			else flag2=true;
		}

		if(win[p.first][p.second-1]){
			if(wah[p.first][p.second-1]==1)flag1=true;
			else flag2=true;
		}
		if(win[p.first][p.second+1]){
			if(wah[p.first][p.second]==1)flag1=true;
			else flag2=true;
		}
		if(flag1 && flag2){
			win[p.first][p.second]=true;
			for(int i=0;i<4;i++){
				int nx=p.second+dx[i];
				int ny=p.first+dy[i];
				if(!win[ny][nx]){
					que.push(P(ny,nx));
				}
			}
		}
	}
	bool res=false;
	if(win[r][c])res=true;
	if(win[r-1][c] && wav[r-1][c]==0)res=true;
	if(win[r+1][c] && wav[r][c]==0)res=true;
	if(win[r][c-1] && wah[r][c-1]==0)res=true;
	if(win[r][c+1] && wah[r][c]==0)res=true;
	printf("%s\n",res?"Yes":"No");
}
int main(void){
	while(1){
		scanf("%d%d%d%d",&h,&w,&r,&c);
		if(h==0 && w==0 && r==0 && c==0)break;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				scanf("%d",&wav[i][j+1]);
			}
			for(int j=0;j<=w;j++){
				scanf("%d",&wah[i+1][j]);
			}
		}
		for(int j=0;j<w;j++){
			scanf("%d",&wav[h][j+1]);
		}
		solve();
	}
	return 0;
}

Measured memory_bytes: 5436
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define popcnt(x) __builtin_popcount(x)
#define popcntll(x) __builtin_popcountll(x)
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class AOneCardPoker {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int A, B;
        in>>A>>B;
        if(A==B) out<<"Draw\n";
        else{
            if(A==1) A += 13;
            if(B==1) B += 13;
            if(A<B) out<<"Bob\n";
            else out<<"Alice\n";
        }
    }
};


int main() {
	AOneCardPoker solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3616
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x,y;
    cin >> x >> y;
    if(y%2==0&&y>=x*2&&y<=x*4){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3608
#3問目
import math
A, B, H, M = map(int, input().split())
#角度を求める
#時針の角度
jishin = (H + (M / 60))/12
tanshin = (M / 60)
nasukaku = max(jishin * 360, tanshin * 360) - min(jishin * 360, tanshin * 360)
result = math.sqrt(A**2 + B**2 - 2 * A * B * math.cos(math.radians(nasukaku)))
print(result)

Measured memory_bytes: 62260
/*
* @Author: _dp95
* @Date:   2019-12-09 13:20:39
*/
#include "bits/stdc++.h"
using namespace std ;

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

typedef long long ll ;
typedef long double ldb ;

#define mp make_pair
#define pb push_back
#define F first
#define S second
#define nl '\n'

#define all( x ) x.begin(),x.end() 
#define sz( x ) ( int )( x ).size( )
#define mem( a, val ) memset(a, val, sizeof( a ) )
#define deci( x ) cout<<fixed<<setprecision( x );
#define bitcount( x ) __builtin_popcountll( x )

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

const int MAX = 2*1000*1000 + 10 ;
const ll INF = 1e18 ;
const int MOD = 1e9 + 7 ;

ll n, c, mx, dp[ MAX ], w[ MAX ], v[ MAX ] ;

int main( ){
  timesaver ;
  cin >> n >> c ;
  for( int i = 0 ; i < n ; i++ ){
    cin >> w[i] >> v[i] ;
    mx += v[i] ;
  }
  for( int i = 0 ; i <= mx ; i++ )
    dp[i] = INF ;
  dp[0]=0;

  for( int j = 0 ; j < n ; j++ )
    for( int i = mx ; i >= 0 ; i-- )
      if( v[j] <= i )
        dp[ i ] = min( dp[i], dp[i-v[j]]+w[j] ) ;

  for( int j = mx ; j >= 0 ; j-- )
    if( dp[j] <= c ){
      return cout << j << nl, 0 ;
    }
}

Measured memory_bytes: 4352
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"

using namespace std;

typedef long int li;
typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> pt;

#define fi first
#define se second
#define lson (p<<1)+1
#define rson (p<<1)+2
#define dump(x) cout << #x << " = " << x << endl
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

ll n, m, cur, last;
string s;
vector<ll> v;

int main () {
    fastIO
    cin >> n >> m >> s;
    for(li i = n; i > 0;) {
        cur = 0, last = 0;
        while(cur < m) {
            cur ++;
            if(i - cur < 0) break;
            if(s[i - cur] == '0') last = cur;
        }
        if(last == 0) { cout << -1; return 0; }
        else v.push_back(last);
        i = i - last;
    }
    reverse(v.begin(), v.end());
    for(auto i : v) cout << i << " ";
}


Measured memory_bytes: 1480
#include <bits/stdc++.h>
using namespace std;
//define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a,b) (abs((a)-(b)) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
//template
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
      }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
//typedef
typedef complex<double> Point;
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;



int a[200000], root = 0;
vector<int> G[200000];
int dfs(int u, int par){
  vector<int> vec;
  rep(i,G[u].size())if(G[u][i] != par){
    int res = dfs(G[u][i], u);
    vec.pb(res);
  }
  int n = vec.size();
  if(n == 0)return a[u];
  sort(all(vec));int mx = vec[n-1];
  int sum = 0;
  rep(i,n){sum += vec[i];if(vec[i] == -1)return -1;}
  int m_pair = 0;
  if(mx <= sum-mx){
    m_pair = sum/2;
  }else{
    m_pair = sum-mx;
  }
  if(a[u] <= sum and sum <= 2*a[u]){
    // cout << u << endl;
    if(sum-a[u] <= m_pair)return sum-2*(sum-a[u]);
  }
  return -1;
}

signed main(){
  int n;
  scanf("%lld", &n);
  rrep(i,n)scanf("%lld", &a[i]);
  rep(i,n-1){
    int x, y;
    scanf("%lld%lld", &x, &y);
    G[x].pb(y);G[y].pb(x);
  }
  if(n == 2){
    printf("%s\n", a[1] == a[2] ? "YES" : "NO");
    return 0;
  }
  rrep(i,n){if(G[i].size() > 1){G[root].pb(i);G[i].pb(root);break;}}
  int res = dfs(root, -1);
  cout << (res == -1 ? "NO" : "YES") << endl;
	return 0;
}










Measured memory_bytes: 18816
def getscore(a, b, c)
  if a == b && b == c && a == c
    return 0
  elsif a != b && b != c && a != c
    return 2
  else
    return 1
  end 
end
# puts getscore('e', 'a', 'a')
n = gets.chomp.to_i
a = gets.chomp.split('')
b = gets.chomp.split('')
c = gets.chomp.split('')
sum = 0
for i in (0..(n-1))
  score = getscore(a[i], b[i], c[i])
  sum += score
end

puts sum

Measured memory_bytes: 1788
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x1 =sc.nextInt();
        int y1 = sc.nextInt();
        int x2 = sc.nextInt();
        int y2 = sc.nextInt();
        int x = x2-x1;
        int y = y2-y1;

        System.out.println((x2-y)+" "+(y2+x)+" "+(x1-y)+" "+(y1+x));
        
        
    }
}

Measured memory_bytes: 22612
import java.util.Scanner;

public class Main {
	
	private static Scanner sc;
	
	public static void main (String args[]) {
		sc = new Scanner(System.in);
		//マスの数(1～100の範囲)
		int n = Integer.parseInt(sc.next());
		int result = 0;
		//マスに入っている値
		for(int i = 0; i < n; i++) {
			int der1 = i%2;
			int a = Integer.parseInt(sc.next());
			int der2 = a%2;
			if (der1==0 && der2==1) {
				result++;
			}
		}
		System.out.println(result);
	}	
}


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

typedef long long   ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x;
    cin >> x;

    for(int k = 0; k < 1000; k++) {
        for(int n = 0; n < 1000; n++) {
            ll tx=pow(k,5)
                 -5*pow(k,4)*n
                 +10*pow(k,3)*pow(n,2)
                 -10*pow(k,2)*pow(n,3)
                 +5*k*pow(n,4);
            if(x==tx){
                cout << n << " " << n-k << "\n";
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 4080
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B: Can you solve this?
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_M = 20;

/* typedef */

/* global variables */

int bs[MAX_M];

/* subroutines */

/* main */

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

  for (int i = 0; i < m; i++) scanf("%d", bs + i);

  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int sum = c;
    for (int j = 0; j < m; j++) {
      int aj;
      scanf("%d", &aj);
      sum += aj * bs[j];
    }
    if (sum > 0) cnt++;
  }

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


Measured memory_bytes: 256
import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;
 
void main() {
    int h, w, d, n;
    readf("%d %d %d %d\n", &h, &w, &d, &n);
    auto F = new string[h];
    foreach (ref _; F) _ = readln.chomp;
    int[] R = readln.chomp.split(" ").map!(to!int).array ~ int.max;
    auto C = new int[][](h, w);

    void f(int y, int x, int r, int z) {
        foreach (i; 0 .. h) {
            if (abs(y - i) > r) continue;
            foreach (j; 0 .. w) {
                if (abs(x - j) > r) continue;
                C[i][j] += z;
            }
        }
    }

    auto reachable = new bool[][](h, w);
    void bfs() {
        struct P {int y, x;}
        DList!P Q;
        int sy, sx;
        foreach (i; 0 .. h) foreach (j; 0 .. w) {
            if (F[i][j] == 'D') {
                sy = i; sx = j;
            }
        }
        Q.insert(P(sy, sx));
        reachable[sy][sx] = true;
        while (!Q.empty) {
            P p = Q.front; Q.removeFront;
            static const dy = [1, 0, -1, 0], dx = [0, 1, 0, -1];
            foreach (i; 0 .. 4) {
                int ny = p.y + dy[i], nx = p.x + dx[i];
                if (ny < 0 || ny >= h) continue;
                if (nx < 0 || nx >= w) continue;
                if (reachable[ny][nx]) continue;
                if (F[ny][nx] == '#') continue;
                reachable[ny][nx] = true;
                Q.insert(P(ny, nx));
            }
        }
    }
    bfs();

    foreach (i; 0 .. n) {
        int x, y, s; readf("%d %d %d\n", &x, &y, &s);
        if (s >= 0) f(y, x, R[s], 1);
        if (s >= 1) f(y, x, R[s - 1], -1);
        //[y, x, R[s]].writeln;
        //foreach (_; C) _.writeln;
    }

    int[][] c;
    foreach (i; 0 .. h) {
        foreach (j; 0 .. w) {
            if (C[i][j] == n && F[i][j] != '#') {
                c ~= [i, j];
            }
        }
    }
    if (c.length == 0) {
        "Broken".writeln;
    } else if (c.length >= 2) {
        int a;
        foreach (x; c) {
            if (reachable[x[0]][x[1]]) a++;
        }
        if (a == c.length) {
            "Yes".writeln;
        } else if (a == 0) {
            "No".writeln;
        } else {
            "Unknown".writeln;
        }
    } else { assert(c.length == 1);
        if (reachable[c[0][0]][c[0][1]]) {
            "Yes".writeln;
        } else {
            "No".writeln;
        }
    }
}

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

int n;
int num;
int cnt;

int main(){

  scanf(" %d",&n);

  for(int i=0;i<n;i++){
    scanf(" %d",&num);
    if(num%2==1){
      cnt++;
    }
  }

  if(cnt%2==0){
    printf("YES\n");
  }else{
    printf("NO\n");
  }

  return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define pb(a) push_back(a)

typedef long long ll;
using namespace std;

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 dy[] = { 0, 0, 1, -1 };
//const int dx[] = { 1, -1, 0, 0 };
const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
ll gcd(ll a, ll b);
ll lcm(ll x, ll y);

vector<ll> a,b;
map<ll,ll> m;


int main()
{
	ll n;
	
	cin >> n;
	for (int i = 0; i < n-1; i++) {
		int tmp;
		cin >> tmp;
		b.push_back(tmp);
	}

	a.push_back(b[0]);

	for (int i = 0; i < n-2; i++) {
		a.push_back(min(b[i], b[i + 1]));
	}

	a.push_back(b[n-2]);
	int sum = 0;
	for (int i = 0; i < a.size(); i++) {
		sum += a[i];
	}

	cout << sum << endl;

	return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){

while(true){
		string g;
		cin>>g;
	if(g=="0"){
		break;
	}
	int As=0,Bs=0;
		for(int i=1;i<g.size();i++){
			if(g[i]=='A'){
				As++;
			}
			else{
				Bs++;
			}
		}
		if(As>Bs){
			As++;
		}
		else{
			Bs++;
		}
		cout<<As<<" "<<Bs<<endl;
		As=0;
		Bs=0;
}

return 0;
}

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

int main(void){
  int a,b,c,d,ans = 0;
  cin >> a >> b >> c >> d;
  if(a>=b) ans += b;
  else ans += a;
  if(c>=d) ans += d;
  else ans += c;
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  map<string, int> m;
  for(int i=0;i<n;i++)
  {
    string x;
    cin>>x;
    m[x]++;
  }
  int ans=0;
  for(auto i=m.begin();i!=m.end();i++)
  	ans++;
  cout<<ans;
  return 0;
}

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

int main(){
    string S;
    cin >> S;
    bool ch = true;
    int A = S.length();
    for (int i = 0; i < A;i+= 2){
        if(S[i] == 'R' || S[i] == 'U'||S[i] == 'D'){

        }else{
            ch = false;
        }
    }
    for (int i = 1; i < A;i+= 2){
        if(S[i] == 'L' || S[i] == 'U'||S[i] == 'D'){

        }else{
            ch = false;
        }
    }
    if(ch == true){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
        return 0;
}

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

int a[3], ans = 1e8;

int main() {
	cin >> a[0] >> a[1] >> a[2];
	int ans1 = min(abs(a[1] - a[0]) + abs(a[2] - a[1]), abs(a[2] - a[0]) + abs(a[1] - a[2]));
	int ans2 = min(abs(a[0] - a[1]) + abs(a[2] - a[0]), abs(a[2] - a[1]) + abs(a[0] - a[2]));
	int ans3 = min(abs(a[0] - a[2]) + abs(a[1] - a[0]), abs(a[1] - a[2]) + abs(a[0] - a[1]));
	ans = min(ans1, ans2);
	ans = min(ans, ans3);
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e9
#define all(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define max(v) *max_element(v.begin(), v.end())
#define min(v) *min_element(v.begin(), v.end())
using namespace std;

int a[500000];
long long cnt = 0;
void merge(int a[], int left, int mid, int right){
    int n1 = mid-left, n2 = right - mid;
    int l[n1+1], r[n2+1];
    for(int i = 0; i < n1; i++){
        l[i] = a[left + i];
    }
    for(int i = 0; i < n2; i++){
        r[i] = a[mid + i];
    }
    l[n1] = INF;
    r[n2] = INF;
    int i, j;
    i = 0;
    j = 0;
    for(int k = left; k < right; k++){
        if(l[i] <= r[j]){
            a[k] = l[i];
            i = i+1;
        }
        else{
            a[k] = r[j];
            j = j+1;
        }
        cnt += 1;
    }
}

void mergeSort(int a[], int left, int right){
    if(left+1 < right){
        int mid = (left + right)/2;
        mergeSort(a, left, mid);
        mergeSort(a, mid, right);
        merge(a, left, mid, right);
    }
}


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

    int n;
    cin>>n;
    rep(i, n){
        cin>>a[i];
    }
    mergeSort(a, 0, n);
    rep(i, n){
        if(i == n-1){
            cout<<a[i]<<endl;;
        }
        else{
            cout<<a[i]<<" ";            
        }
    }
    cout<<cnt<<endl;
    return 0;
}



Measured memory_bytes: 7088
#include <cstdio>
#include <cctype>

const int INF = 0x7fffffff >> 1;
int e1[233][233], e2[233][233];
int n, m;

int read() {
    int ret, f = 1;
    char ch;
    while(!isdigit(ch = getchar())) (ch == '-') && (f = -1);
    for(ret = ch - '0'; isdigit(ch = getchar()); ret *= 10, ret += ch - '0');
    return ret * f;
}

void print(int x) {
    if(x < 0) putchar('-'), x = -x;
    if(x > 9) print(x / 10);
    putchar(x % 10 + '0');
}

int main() {
    n = read(), m = read();
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j)
            e1[i][j] = e2[i][j] = i == j ? 0 : INF;
    for(int i = 1; i <= m; ++i) {
        int u = read(), v = read();
        e1[u][v] = e1[v][u] = e2[u][v] = e2[v][u] = read();
    }
    for(int k = 1; k <= n; ++k)
        for(int i = 1; i <= n; ++i)
            for(int j = 1; j <= n; ++j)
                if(e1[i][j] > e1[i][k] + e1[k][j])
                    e1[i][j] = e1[i][k] + e1[k][j];
    // for(int i = 1; i <= n; ++i, putchar('\n'))
    //     for(int j = 1; j <= n; ++j, putchar(' '))
    //         print(e1[i][j]);
    //             for(int i = 1; i <= n; ++i, putchar('\n'))
    //     for(int j = 1; j <= n; ++j, putchar(' '))
    //         print(e2[i][j]);
    int ans = 0;
    for(int i = 1; i <= n; ++i)
        for(int j = i + 1; j <= n; ++j)
            ans += (e2[i][j] != INF && e1[i][j] != e2[i][j]);
    return print(ans), 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
static const int maxn = 2e5 + 5;
long long a[maxn],sum[maxn];
int main()
{
	int n;
	cin>>n;
	for(int i = 1;i <= n; ++i)
	{
		int x;
		cin>>x;
		a[i] = a[i - 1] + x;
		sum[i] = sum[i - 1] ^ x;
	}
	long long ans = 0,l = 1;
	for(int r = 1;r <= n; ++r)
	{
		while((a[r] - a[l - 1]) != (sum[r] ^ sum[l - 1]))
		{
			l++;
		}
		ans += r - l + 1;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}

P dequeue(){
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

int min(int a, int b){
  return a < b ? a : b;
}

int main(){
  int elaps = 0, c;
  int i, q;
  P u;

  scanf("%d %d", &n, &q);

  for(i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1;
  tail = n + 1;

  while(head != tail){
    u = dequeue();
    c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if(u.t > 0) enqueue(u);
    else{
      printf("%s %d\n", u.name, elaps);
    }
  }

  return 0;
}
  
  



Measured memory_bytes: 11948
fun main(args: Array<String>) {
    val (x, n) = readLine()?.split(" ")?.map(String::toInt)?: return
    var upperNumber = x
    var downNumber = x
    if (n < 1) {
        println(x)
        return
    }
    val numbers = readLine()?.split(" ")?.map { it.toInt() }?: return
    if (!numbers.contains(x)) {
        println(x)
        return
    }
    for (it in numbers) {
        upperNumber++
        downNumber--
        if (!numbers.contains(downNumber)) {
            println(downNumber)
            break
        }
        if (!numbers.contains(upperNumber)) {
            println(upperNumber)
            break
        }
    }
}

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

int main() {
  string s;
  cin >> s;
  
  if(s == "abc" || s == "acb" || s == "bac" || s == "bca" || s == "cab" || s == "cba")
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

}

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

using namespace std;

#define ll long long

#define DEBUG (0)

int main()
{
  ll N = 0;
  ll K = 0;
  ll sho = 0;
  ll tmpN = 0;
  ll ans1 = 0;
  ll ans2 = 0;

  cin >> N >> K;

  if(N == 0){
    cout << 0 << "\n";
    return 0;
  }

  sho = N/K;
  tmpN = N - sho*K;

#if DEBUG
  cout << "sho:" << sho << ", tmpN:" << tmpN << "\n";
#endif
  if(tmpN == 0){
    cout << 0 << "\n";
    return 0;
  }

#if DEBUG
  cout << "test" << "\n";
#endif

  if(tmpN > K){
    ans1 = tmpN -K;
  }else{
    ans1 = K - tmpN;
  }

  if(ans1 > K){
    ans2 = ans1 - K;
  }else{
    ans2 = K - ans1;
  }

#if DEBUG
  cout << "ans1:" << ans1 << ", ans2:" << ans2 << "\n";
#endif

  if(ans1 > ans2){
    cout << ans2 << "\n";
  }else{
    cout << ans1 << "\n";
  }

}

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

#define rep(i,n) for (int i=0; i<(n); i++)
const int INF =1001001001;
const ll BIG = 1000000007;
const double PI = 3.141592653589793;

int main(){
    int n;
    cin >> n;
    ll big_l = 1000000000000000000;
    ll ans = 1;
    vector<ll> a(n, 0);
    rep(i, n) cin >> a[i];
    rep(i, n) {
        if(a[i]==0){
            cout << "0" << endl;
            return 0;
        }
    }
    rep(i, n) {
        if(ans>big_l/a[i]){
            cout << "-1" << endl;
            return 0;
        }
        ans = ans * a[i];
        }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3988