akhauriyash/Code-Regression huggingface dataset:
a, b = input().split()
ab = int(a)*10**(len(b)) + int(b)

judge = 0
i = min(int(a), int(b))

while judge == 0:
    if i**2 == ab:
        judge = 1
        break
    i += 1
    if i**2 > ab:
        break

if judge == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
def main():
    s = input()
    q =int(input())
    ten = 0
    r = []
    l = []
    for _ in range(q):
        ls = tuple(map(str, input().split()))
        if len(ls)==1:
            ten +=1
        else:
            if ls[1] =='1':
                if ten%2 ==0:
                    l.append(ls[2])
                else:
                    r.append(ls[2])
            else:
                if ten%2 ==1:
                    l.append(ls[2])
                else:
                    r.append(ls[2])
    s = ''.join(reversed(l))+s+''.join(r)
    if ten%2 ==1:
        s = s[::-1]
    print(s)
if __name__ == '__main__':
    main()

Measured memory_bytes: 98148
/* 
    @author : srinathbalaji_99
*/


#include<bits/stdc++.h>

#define PB push_back
#define MP make_pair
#define endl '\n'
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define rep(i, a, b, inc) for(long long i = a; i < b; i += inc)
#define REP(i, n) rep(i, 0, n, 1)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define PLL pair<long long, long long>
#define VL vector<long long>
#define VS vector<string>
#define VLL vector<PLL>
#define VVL vector<VL>
#define MPLL map<long long, long long>
#define UMPLL unordered_map<long long, long long>
#define SETL set<long long>
#define MSETL multiset<long long>
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) (a * b)/GCD(a, b)
#define ff first
#define ss second
#define pall(a) REP(i, sizeof(a)/sizeof(a[0]))cout << a[i] << " ";cout << endl;
#define pvall(v) REP(i, v.size())cout << v[i] << " ";cout << endl;
#define gall(a, n) REP(i, n)cin >> a[i];
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

typedef unsigned long long ULL;
typedef long long LL;
typedef long double LD;


using namespace std;

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

LD prob[301][301][301]; //prob[a][b][c] -> probability that we get to state (a, b, c)
LD eval[301][301][301]; //eval[a][b][c] -> exp. no. of ops to get to state (a, b, c)

int main()
{
    fast();

    cout << fixed;
    cout << setprecision(10);
    LL t,n,i,j,k,x,y,c;
    cin >> n;
    LL cnt[4];
    MEM(cnt, 0);
    REP(i, n){
        cin >> x;
        cnt[x]++;
    }
    prob[cnt[1]][cnt[2]][cnt[3]] = (LD)1;
    eval[cnt[1]][cnt[2]][cnt[3]] = 0;
    for(LL c = n; c >= 0; --c){
        for(LL b = n; b >= 0; --b){
            for(LL a = n; a >= 0; --a){
                if((a == 0 && b == 0 && c == 0) || a + b + c > n){
                    continue;
                }
                LD dummy = (LD)(n - (a + b + c)) / (LD)(n);
                LD evdummy = ((dummy) / (1 - dummy)) + 1;
                eval[a][b][c] += evdummy * prob[a][b][c];
                if(a != 0){
                    prob[a - 1][b][c] += prob[a][b][c] * ((LD)a / (LD)(a + b + c));
                    eval[a - 1][b][c] += eval[a][b][c] * ((LD)a / (LD)(a + b + c));
                }
                if(b != 0){
                    prob[a + 1][b - 1][c] += prob[a][b][c] * ((LD)b / (LD)(a + b + c));
                    eval[a + 1][b - 1][c] += eval[a][b][c] * ((LD)b / (LD)(a + b + c));
                }
                if(c != 0){
                    prob[a][b + 1][c - 1] += prob[a][b][c] * ((LD)c / (LD)(a + b + c));
                    eval[a][b + 1][c - 1] += eval[a][b][c] * ((LD)c / (LD)(a + b + c));
                }
            }
        }
    }
    cout << eval[0][0][0];
}

Measured memory_bytes: 852224
#include <iostream>
#include <string.h>
#include <math.h>
#include <stdio.h>
using namespace std;
int main() {
    int N,M,i,n;
    cin>>N;
    n=1000;
    M=-1;
    for (i = 1; M< 0; ++i) {
        if ((n-N)>=0)
        {
            M=n-N;
            break;
        }
        else if ((n-N)<0)
        {
            n=n+1000;
        }
    }
    cout<<M;
    return 0;
}


Measured memory_bytes: 3624
N, C = map(int, input().split())
X, V = [], []
for i in range(N):
    xi, vi = map(int, input().split())
    X.append(xi)
    V.append(vi)

# 時計回り・反時計回りにi個目までの寿司を食べたときに歩く距離
r_cost = [0]
l_cost = [0]
# 時計回り・反時計回りにi個目までの寿司を食べた時の総栄養価
r_value = [0]
l_value = [0]

for i in range(N):
    r_cost.append(X[i])
    l_cost.append(C-X[-i-1])
    r_value.append(r_value[-1] + V[i])
    l_value.append(l_value[-1] + V[-i-1])

# 歩く距離と栄養価を考慮した場合の、引き返してどこまで行くのが最適か
r_optimized = [0]
l_optimized = [0]
for i in range(1, N+1):
    r_optimized.append(r_value[i] - r_cost[i])
    l_optimized.append(l_value[i] - l_cost[i])

# max累積和
for i in range(1, N+1):
    r_optimized[i] = max(r_optimized[i], r_optimized[i-1])
    l_optimized[i] = max(l_optimized[i], l_optimized[i-1])

# 答えを計算
ans = 0
for i in range(N+1):
    r_straight = r_optimized[i]
    l_straight = l_optimized[i]
    r_turn = r_value[i] - 2 * r_cost[i] + l_optimized[N-i]
    l_turn = l_value[i] - 2 * l_cost[i] + r_optimized[N-i]
    ans = max(ans, r_straight, l_straight, r_turn, l_turn)

print(ans)


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

void solve(long long N, long long K, std::vector<long long> H) {
    sort(H.begin(), H.end(), greater<long long>());
    vector<long long>::iterator i = H.begin();
    if (K >= H.size()) {
        cout << 0 << endl;
        return;
    }

    i += K;
    long long ans = 0;
    for (; i < H.end(); i++) {
        ans += *i;
    }
    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can
// remove this line by using your custom template)
int main() {
    long long N;
    scanf("%lld", &N);
    long long K;
    scanf("%lld", &K);
    std::vector<long long> H(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &H[i]);
    }
    solve(N, K, std::move(H));
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define mp make_pair;

const ll prime = 1000000000 + 7;
const ld PI = 2 * acos(0.0);

/*
cout << fixed << setprecision(10);
*/

int main() {

	ll h, w, k;
	cin >> h >> w >> k;
	vector<vector<char> > s(h, vector<char>(w));
	ll cnt = 0;
	vector<ll> column(h);
	for (ll i = 0; i < h; i++)
	{
		cnt = 0;
		for (ll j = 0; j < w; j++)
		{
			cin >> s[i][j];
			if (s[i][j] == '#') {
				cnt++;
			}
		}
		column[i] = cnt;
	}

	vector<vector<ll> > vec(h, vector<ll>(w));


	ll frm, to;
	frm = 0;
	ll i = 0;
	cnt = 1;
	ll cnt2 = 0;
	while (i < h) {
		if (column[i] > 0) {
			cnt2 = 0;
			for (ll j = 0; j < w; j++)
			{
				if (s[i][j] == '#' and cnt2 != 0) {
					cnt++;
					vec[i][j] = cnt;
				}
				else {
					vec[i][j] = cnt;
					if (s[i][j] == '#') {
						cnt2++;
					}
				}
			}
			cnt++;
		}
		i++;
	}

	i = 0;
	ll index;
	cnt2 = 0;
	while (i < h) {
		
		if (column[i] > 0) {
			if (cnt2 == 0) {
				index = i;
				cnt2++;
			}
			else {
				if (cnt2 != 1) {
					index = frm;
				}
				cnt2++;
				to = i;

				for (ll j = frm; j < to; j++)
				{
					for (ll l = 0; l < w; l++)
					{
						vec[j][l] = vec[index][l];
					}
				}
				frm = to;
			}
		}

		i++;
	}
	if (frm != h) {
		to = h;
		for (ll j = 0; j < h; j++)
		{
			if (column[j] > 0) {
				if (column[j] == k) {
					index = j;
				}
				else {
					index = frm;
				}
				break;
			}
		}
		for (ll j = frm; j < to; j++)
		{
			for (ll l = 0; l < w; l++)
			{
				vec[j][l] = vec[index][l];
			}
		}
	}

	for (ll i = 0; i < h; i++)
	{
		for (ll j = 0; j < w; j++)
		{
			cout << vec[i][j];
			if (j == w - 1) {
				cout << endl;
			}
			else {
				cout << " ";
			}
		}
	}



	


	return 0;
}


Measured memory_bytes: 1536
#include <stdio.h>

const int N=3e2+10;
int max(int a,int b){return a>b?a:b;}
int main(){
    int s[N][N],r[N][N],n,a[N][N],ans=-10000,now,last;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)scanf("%d",&a[i][j]);
    for(int i=1;i<=n;i++){
        s[i][0]=r[0][i]=0;
        for(int j=1;j<=n;j++){
            s[i][j]=s[i][j-1]+a[i][j];
            r[j][i]=r[j-1][i]+a[j][i];
        }
    }
    for(int i=1;i<=n;i++){
        now=a[i][1];
        ans=max(ans,now);
        for(int j=2;j<=n;j++){
            if(now<0)now=0;
            now+=a[i][j];
            ans=max(ans,now);
        }
    }
    for(int i=1;i<=n;i++){
        now=a[1][i];
        ans=max(ans,now);
        for(int j=2;j<=n;j++){
            if(now<0)now=0;
            now+=a[j][i];
            ans=max(ans,now);
        }
    }
    for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++){
        now=r[j][1]-r[i-1][1]+r[j][2]-r[i-1][2];
        last=0;
        ans=max(ans,now);
        for(int k=3;k<=n;k++){
            now+=r[j][k]-r[i-1][k]-r[j-1][k-1]+r[i][k-1];
            last-=r[j][k-2]-r[i-1][k-2]-r[j-1][k-1]+r[i][k-1];
            if(last>0){
                now+=last;
                last=0;
            }
            ans=max(ans,now);
        }
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 3456
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

#define PI 3.14159265358979323846264338327950L

int main() {

  int A,B,H,M;
  cin >> A >> B >> H >> M;

  long double rad = 2*PI*((long double)H/12.0+(long double)M/720.0-(long double)M/60.0);

  long double result = (long double)(A*A+B*B)-(long double)(2.0*A*B)*cosl(rad);
  printf("%20.20Lf\n", sqrtl(result));

}


Measured memory_bytes: 4108
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string N;
  cin >> N;
  if ((N[0] == N[1] && N[1] == N[2]) || (N[1] == N[2] && N[2] == N[3])) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

int main()
{
  string S;
  cin >> S;
  int n = S.size() / 2;
  int b = S.size() - 1;
  int count = 0;
  for (int i = 0; i < n; i++) {
  	if (S[i] != S[b]) {
    	count++;
    }
    b--;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
'''
def gcd(a,b):
    if a<b:
     c=a
     a=b
     b=c

    c=a%b

    if c==0:
     return b
    else:
     return gcd(b,c)
'''
'''
def gcd(a,b):
    return a if b == 0 else gcd(b,a%b)
'''

def gcd(a,b):
    if a<b:
     d=a
     a=b
     b=d
    d=a%b
    while d!=0:
     a=b
     b=d
     d=a%b
    return b

def lcm(e,f):
    c=gcd(e,f)
    g=e*f
    return g//c



n=int(input())
t=[0]*n

for lop2 in range(n):
    t[lop2]=int(input())

ans=t[0]

for lop in range(1,n):
    ans=lcm(ans,t[lop])
print(int(ans))


Measured memory_bytes: 3064
import Data.List
import Data.Bool
import Data.Maybe

main = putStrLn . bool "No" "Yes" . solve . map read . words =<< getLine

solve :: [Int] -> Bool
solve xs = a == b
  where
    gs = [[1, 3, 5, 7, 8, 10, 12],
          [4, 6, 9, 11],
          [2]]
    [a, b] = map (\x -> fromJust $ findIndex (elem x) gs) xs


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

list<long> divisor(long n) {
    list<long> ret;
    for ( long i = 1; i * i <= n; i++ ) {
        if (n % i == 0) {
            ret.push_back(i);
            if(i * i != n) ret.push_back(n / i);
        }
    }
    return ret;
}

int main() {
    long N; cin >> N;
    long m = divisor(N - 1).size() - 1;
    list<long> L = divisor(N);
    L.pop_front();
    while(!(L.empty())) {
        long n = N, i = *(L.begin());
        while(n % i == 0) n /= i;
        if (n % i == 1) m++;
        L.pop_front();
    }
    cout << m << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
    int n,m;

    while(cin >> n >> m && n){
        vector<pair<string, int> > v;
        int val=0;
        string str;
        int tmp;
        for(int i=0;i<n;i++){
            cin >> str >> tmp;
            v.push_back(pair<string,int>(str,tmp));
        }
        for(int i=0;i<m;i++){
            cin >> str;
            bool matched;
            for(int j=0;j<n;j++){
                matched = true;
                for(int k=0;k<8;k++){
                    if(v[j].first[k] == '*') continue;
                    if(v[j].first[k] != str[k]){
                        matched = false;
                        break;
                    }
                }
                if(matched){
                    val += v[j].second;
                }
            }
        }
        cout << val << endl;
    }
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
using llong = long long;

//===
// nCr mod p
// p is prime
// 1 <= k <= n <= 1e7

void init_comb(long long modulus);
void init_comb(void);
long long combination(long long n, long long k);
long long pow_mod(long long n, long long m);

long long _modulus = 998244353;
long long fact[1000007];
long long fact_inv[1000007];

void init_comb(long long modulus) {_modulus = modulus; }
void init_comb(void) {
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    for (int i = 2; i <= 1000000; i++) {
        fact[i] = fact[i - 1] * i % _modulus;
        fact_inv[i] = pow_mod(fact[i], _modulus - 2);
    }
}

long long combination(long long n, long long k) {
    static long long f;

    if (f != _modulus) f = _modulus, init_comb();

    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;

    return fact[n] * (fact_inv[k] * fact_inv[n - k] % _modulus) % _modulus;
}

long long pow_mod(long long n, long long m) {
    //n ** m;
    long long ret = 1;

    while (m) {
        if (m & 1) {
            ret = ret * n % _modulus;
        }

        n = n * n % _modulus;
        m = m >> 1;
    }

    return ret;
}
//===

llong n, m, k;

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

    llong ans = 0;
    for (int i = 0; i <= k; i++) {
        llong a = m * pow_mod(m - 1, n - i - 1) % _modulus * combination(n - 1, i) % _modulus;
        //cout << i << ' ' << a << endl;
        ans += a;
        ans %= _modulus;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 19184
#include<bits/stdc++.h>
main(){
while(true){
int x[11000],n,i,j,k,l,m,y[11000],b,c,d,p[11000],minx;
scanf("%d", &n);
if(n==0){break;}
for(i=0;i<n;i++){scanf("%d", &y[i]);p[i]=x[i]=y[i];}
c=0;d=0;m=n;d=m;
minx=99999;
for(i=0;i<n;i++){
for(j=1;j<=3;j++){
if(i>=1&&y[i-1]!=j&&y[i+1]!=j){goto z;}
p[i]=x[i]=j;b=1;d=n;
while(true){c=0;
for(k=0;k<m;k++){
if(p[k]==p[k+1]){b++;}
else{
if(b >= 4){
for(l=k+1;l<m;l++){p[l-b]=p[l];}
d -= b;c++;
for(l=d;l<m;l++){p[l]=0;}
}
b=1;}   
m=d;}
if(c==0){break;}
else{c=0;}
}
minx=std::min(minx,m);x[i]=y[i];
for(int k=0;k<n;k++){p[k]=y[k];}
z:;
}
}
printf("%d\n",minx);}
}

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

int main() {
  int n;
  cin >> n;
  vector<int> cnt(100001);
  rep(i, n) {
    int x;
    cin >> x;
    if (x < 100001) cnt[x]++;
    else cnt[0]++;
  }
  
  int ans = 0;
  rep(i, 100001) {
    if (cnt[i] >= i) ans += cnt[i] - i;
    else ans += cnt[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

static const int MAX = 100;

int main(void)
{
	int N, A[MAX];
	int temp, count = 0, flag = 1;
	cin >> N;
	for(int i=0;i<N;i++) cin >> A[i];
	while(flag){
		flag = 0;
		for(int j=N-1;j>0;j--){
			if (A[j-1] > A[j]){
				temp = A[j];
				A[j] = A[j-1];
				A[j-1] = temp;
				count++;
				flag = 1;
			}
		}
	}
	for (int i=0;i<N;i++){
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 1164
# ABC110C - String Transformation
def main():
    s, t = [input().rstrip() for _ in range(2)]
    d1, d2 = {}, {}
    for i, j in zip(s, t):
        if i not in d1:
            d1[i] = j
        if j not in d2:
            d2[j] = i
        if d1[i] != j or d2[j] != i:
            print("No")
            break
    else:
        print("Yes")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3632
MOD = 10**9 + 7

def solve(s, p=13):
    a = [0] * p
    a[0] = 1
    for c in s:
        b = [0] * p
        for i in range(p):
            b[(i*10)%p] = a[i] % MOD
        b += b
        if c == "?":
            for i in range(p):
                a[i] = sum(b[i+4:i+p+1])
        else:
            for i in range(p):
                a[i] = b[i+p-int(c)]
    return a[5] % MOD

s = input()
print(solve(s))

Measured memory_bytes: 3188
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;
#define oset tree<pi, null_type,greater<pi>, rb_tree_tag,tree_order_statistics_node_update>


int main()
{
    map<string, int> mp;
    int n;
    cin >> n;
    for(int i=0; i<n; i++){
        string s;
        cin >> s;
        mp[s]++;
    }
    int mx = 0;
    for(auto x: mp){
        mx = max(mx, x.second);
    }
    for(auto x: mp){
        if(x.second == mx){
            cout << x.first << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 19160
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>

using namespace std;

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

//const ll INF = 1e15;
const ll MOD = 1e9 + 7;


int main(){
	ll Q, H, S, D;
	cin >> Q >> H >> S >> D;
	ll N;
	cin >> N;
	ll ans = 0;
	if (D <= 2 * S && D <= 4 * H && D <= 8 * Q){
		ans += D*(N / 2);
		N = N % 2;
	}
	if (S <= 2 * H && S <= 4 * Q){
		ans += S*N;
	}
	else{
		if (H <= 2 * Q){
			ans += H * 2 * N;
		}
		else{
			ans += Q * 4 * N;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int N, W;
  cin >> N >> W;
  
  vector<string> A(N);
  for(int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  
  for( int i = 0; i < W + 2; i++) {
    cout << '#';
  }
  cout << endl;
  
  for(int i = 0; i < N; i ++) {
    cout << '#' << A.at(i) << '#' << endl;
  }

  for( int i = 0; i < W + 2; i++) {
    cout << '#';
  }
  cout << endl;

}

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

int main(){
  int A,B;
  cin >> A >> B;
  int T=1;
  int i=0;
  while(true){
    if(T>=B){
      cout << i << endl;
      return 0;
    }
    i++;
    T += (A-1);
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  	int n;
		cin >> n;
		if(n % 2 == 0||n%5==0) {
			return cout << -1 << endl, 0;
		}
		int cur = 7 % n;
		int ans = 1;
		while(cur != 0) {
			cur = cur*10 + 7;
			cur %= n;
			++ans;
		}
		cout << ans << endl;
}

Measured memory_bytes: 3628
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let [n;k] = reads int
    let hs = reads int
    hs
    |> List.filter (fun x -> x >= k)
    |> List.length
    |> printfn "%i"
    0

Measured memory_bytes: 29140
#include <stdio.h>
 
int gcd(int x, int y)
{ 
  if(x % y == 0)
     return y; 
  
     return gcd( y , x%y); 
}
 
int main (void)
{
 int a,b,c,k;
 long int sum = 0;   
 scanf("%d", &k);
  
  for(a=1;a<=k;a++){    
    for(b=1;b<=k;b++){        
      for(c=1;c<=k;c++){
         sum+=gcd(a,gcd(b,c));
      }
    }
  }
  printf("%ld",sum);
  return 0;          
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    int n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    vector<ll> ruisekiwa(n+1);
    rep(i, n) ruisekiwa[i+1] = ruisekiwa[i] + a[i];
    ll mi = 1e18;
    rep(i, n-1) {
        ll x = ruisekiwa[i+1];
        ll y = ruisekiwa[n] - ruisekiwa[i+1];
        mi = min(mi, abs(x - y));
    }
    cout << mi;
}


Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		for (int i=1;i<=9;i++) {
			for (int j=1;j<=9;j++) {
				if (i*j==N) {
					System.out.println("Yes");
					return ;
				}
			}
		}
		System.out.println("No");
		return ;
	}
}

Measured memory_bytes: 35692
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		boolean[] teisyutu = new boolean[30];
		Arrays.fill(teisyutu, false);
		for (int i = 0; i < 28; i++) {
			teisyutu[in.nextInt() - 1] = true;
		}
		for (int i = 0; i < 30; i++) {
			if (!teisyutu[i]) {
				System.out.println(i + 1);
			}
		}
	}
}

Measured memory_bytes: 12000
using System;

class Program
{
    static void Main()
    {
        string[] x = Console.ReadLine().Split(' ');
        int a = int.Parse(x[0]);
        int b = int.Parse(x[1]);
        if (a > b) 
        {
            Console.WriteLine("a > b");
        }
        else if (a < b)
        {
            Console.WriteLine("a < b");
        }
        else
        {
            Console.WriteLine("a == b");
        }
    }
}


Measured memory_bytes: 15936
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::cmp;

struct Scanner<'a> {
    cin : StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin : StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

#[derive(PartialEq)]
enum SIDE{
    LEFT,
    RIGHT,
}

fn side(k : char) -> SIDE{
    let left = "qwertasdfgzxcvb";
    match left.find(k) {
        None => SIDE::RIGHT,
        _ => SIDE::LEFT,
    }
}

fn main(){
    loop{
        let cin = stdin();
        let cin = cin.lock();
        let mut sc = Scanner::new(cin);
        let str : String = sc.read();
        if str == "#" { break; }
        let mut prev = side(str.chars().nth(0).unwrap());
        let ans = str.chars().fold(0, |acc, x| acc + if prev != side(x) { prev = side(x); 1} else {0});
        println!("{}", ans);

    }
}




Measured memory_bytes: 5028
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    int n, k, q;
    cin >> n >> k >> q;
    vi a(n, k-q);
    for(int  i = 0; i < q; i++) {
        int ans;
        cin >> ans;
        a[ans-1] += 1;
    }    
    rep(i,n) {
        if(a[i] <= 0) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
}

Measured memory_bytes: 1152
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

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

    int n, d;
    double x[10][10];
    cin >> n >> d;
    rep(i, n) rep(j, d) cin >> x[i][j];

    int ans = 0;
    rep (i, n) for(int j = i + 1; j < n; j++) {
        int d2 = 0;
        rep (di, d) d2 += pow(x[i][di] - x[j][di], 2);
        double dd = sqrt(double(d2));
        if (ceil(dd) == dd) ans += 1;
    }

    cout << ans << '\n';

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const ll MOD = 1e9 + 7;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; }
    mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x-= MOD; } return ret; }
    mint& operator--() { if ((--x) < 0) { x += MOD; } return *this; }
    mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

void solve(istream& cin, ostream& cout) {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  REP(i, n - 2) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
      ans++;
  }
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


Measured memory_bytes: 256
# 16
# ABC150 C Count Order

import itertools

n = int(input())
p_l = [int(x) for x in input().split()]
q_l = [int(x) for x in input().split()]

per = itertools.permutations(list(range(1,n+1)))
a = 0
b = 0

for i,order in enumerate(per):
    if p_l == list(order):
        a = i
    if q_l == list(order):
        b = i

print(abs(a-b))

Measured memory_bytes: 41712
//-------All power is within you,you can do Anything and Everything.---------//
 
    #include <bits/stdc++.h>
    // #pragma GCC optimize("Ofast")
    using namespace std;
  
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ M $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    #define F first
    #define S second
    #define pb push_back
    #define mkp make_pair
    #define int long long
    #define ld long double

    #define all(x) x.begin(),x.end() 
    #define rall(x) x.rbegin(),x.rend()
    #define fo(i,a,b) for(int i=a;i<b;i++)
    #define rfo(i,b,a) for(int i=b;i>=a;i--)
    #define mem( a, val ) memset(a, val, sizeof( a ) )
    #define deci( x ) cout<<fixed<<setprecision( x );
    #define bitcount( x ) __builtin_popcountll( x )
    #define endl "\n" 
    
    #define XOX 
    
    typedef vector<int> vi;
    typedef pair<int,int> pi; 
    
    const int INF = 1e15;
    const int MAX = 1e7 + 7;
    const int MOD =  1000000007;
    const long double PI  =3.141592653589793238463;
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ D $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    #define deb(x) cout<<#x<<" "<<x<<endl;

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ V $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//  
    
    int i,j,k,t,n,q,l,r,mid;

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ F $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//

    int isprime[MAX];
    int spf[MAX];
    vector<int> vs;
    // 0 waale prime h,1 is non-prime
    void sieve()
    {
        fo(i,1,MAX)spf[i]=i;
        isprime[0]=isprime[1]=spf[0]=spf[1]=1;
    
        fo(i,2,MAX)
        {
            if(!isprime[i])
            {
                for(int j=2*i;j<MAX;j+=i)
                {
                    isprime[j]=1;
                    if(j==spf[j])
                    spf[j]=i;
                }
            }
        }
    }

    int sum,ans,cnt,x,val;

    void solve()
    {
        cin>>n;
        sum=1;
        fo(i,2,n+1)
        {
            ans=1;
            x=i;
            while(x>1)
            {
                val=spf[x];
                cnt=0;
                while(x>1 && x%val==0)cnt++,x/=val;
                ans*=(cnt+1);
            }
            sum+=(i*ans);
        }
        cout<<sum<<endl;
    }
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
//                          THE GAME STARTS HERE                             //
 
    int32_t main() 
    {
    
        // int start,stop=clock();
        // cout<<"time:"<<(stop-start)/double(CLOCKS_PER_SEC)*1000<<endl;
        ios_base::sync_with_stdio(0);
        cin.tie(NULL);
        cout.tie(NULL);
        sieve();
        // sc(t);while(t--)
        // cin>>t;while(t--)
            solve();
    
        return 0;
    }

Measured memory_bytes: 159892
/*
  Motto - try hard to become an expert
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"
 
//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const int N = 3*1e5 +5 ;
const long long MOD = 998244353;
const long long inf = 1e18;
 
using namespace std;
 
ll MAXN=100001;
ll spf[100001]; 
 
ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll modFact(ll n, ll p) 
{ 
    if (n >= p) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result;  
} 
 
bool isPrime(int x)
{
    if(x%2==0)
        return 0;
    for(int i=3;i<=sqrt(x);i+=2)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}
 

 
void solve()
{
	string s ; 
	cin>>s; 
	if(s=="AAA" || s=="BBB"){
		cout<<"No\n";
	}
	else{
		cout<<"Yes\n";
	}
    
}
 
int main() {
  
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    } 
    
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#define rep(i, n) for (int i = 0; i < n; i++)
    using namespace std;

int main(){
    int n,ans=0;
    cin >>n;
    int p[n];
    rep(i,n)cin >> p[i];

    for (int i = 1; i <n-1;i++)
    {
      if (p[i-1] < p[i] && p[i] < p[i + 1])
        ++ans;
      else if (p[i + 1] < p[i] && p[i] < p[i-1])
        ++ans;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  long n,ans=1;
  cin >> n;
  vector<long> a(n);
  for(long i=0;i<n;i++) cin >> a[i];
  sort(a.begin(),a.end());
  for(long i=0;i<n;i++) {
    if(a[i]>1000000000000000000/ans) {
      ans=-1;
    }
    if(ans!=-1) {
      ans*=a[i];
      if(ans==0) break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3988
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int n;
int v[22];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> v[i];
    int ans = 0;
    for(int i = 2; i < n; ++i)
    {
        vector<int>vv;
        for(int j = i-1; j <= i+1; ++j)
            vv.push_back(v[j]);
        sort(vv.begin(), vv.end());
        if(v[i] == vv[1])
            ++ans;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
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 set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int,int>;
using vi = std::vector<int>;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    ll k; cin >> k;
    vector<ll> a(k); rep(i,k) cin >> a[i];

    if(a[k-1]>2){
        cout << -1 << endl;
        return 0;
    }

    vector<pair<ll,ll>> x(k+1);
    x[k] = make_pair(2,2);
    for(int i=k-1;i>0;i--){
        const auto& mi = x[i+1].first;
        const auto& ma = x[i+1].second;

        const ll low = mi;
        x[i].first = (mi+a[i]-1)/a[i-1];
        x[i].first = (low+a[i-1]-1)/a[i-1]*a[i-1];

        ll up = (ma/a[i]+1)*a[i]-1;
        x[i].second = up/a[i-1]*a[i-1];
    }

    x[0].first = x[1].first;
    x[0].second = (x[1].second/a[0]+1)*a[0]-1;
    if(x[0].first > x[0].second){
        cout << -1 << endl;
        return 0;
    }
    cout << x[0].first << " " << x[0].second << endl;
}


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

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

  int A[210];
  int sum = 0;


  for (int i = 0; i < N; i++)
  {
    cin >> A[i];
  }

  while (1)
  {
    bool odd = false;

    for (int j = 0; j < N; j++)
      if ( A[j] % 2 != 0 )
      {
        odd = true;
      }

    if ( odd )
    {
      break;
    }

    for (int k = 0; k < N; k++)
    {
      A[k] /= 2;
    }

    sum++;
  }

  cout << sum << endl;
}

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

int main() {
    int d,t,s;
    cin>>d>>t>>s;
    double t1=((double)d/s);
    if(t1<=t)
    cout<<"Yes";
    else
    cout<<"No";
	// your code goes here
	return 0;
}


Measured memory_bytes: 3564
from collections import Counter


def A(x):
  return 1000 - x % 1000 if x % 1000 != 0 else 0


def B(n, ss):
  keys_values = Counter(ss)
  orders = ['AC', 'WA', 'TLE', 'RE']
  for order in orders:
    if order in keys_values:
      print("{} x {}".format(order, keys_values[order]))
    else:
      print("{} x {}".format(order, 0))


def C(n, m, k, a, b):
  pass


def main():
  n = int(input())
  ss = []
  for i in range(n):
    ss.append(input())
  B(n, ss)


if __name__ == '__main__':
  main()


Measured memory_bytes: 16616
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double x = sc.nextDouble();
        
        if (a * a * b == x * 2) {
            double tmp = Math.sqrt(x * 2 / b);
            double tmp2 = Math.toDegrees(Math.atan(b/tmp));
            System.out.println(tmp2);
        } else if (a * a * b / 2 < x) {
            // x + a*a*tmp/2 = a*a*b;
            // 2x + a^2*tmp = 2a^2b;
            // 2x/a/a + tmp = 2b
            // tmp = b - 2x/a/a
            double tmp = 2*b - 2*x/a/a;
            double tmp3 = Math.sqrt(a*a+tmp*tmp);
            double tmp2 = 90-Math.toDegrees(Math.acos(tmp/tmp3));
            System.out.println(tmp2);
        } else {
            // x = tmp*a*b/2;
            // x/b*2
            double tmp = x/a/b*2;
            double tmp3 = Math.sqrt(b*b+tmp*tmp);
            double tmp2 = Math.toDegrees(Math.acos(tmp/tmp3));
            System.out.println(tmp2);
        }
    }
}


Measured memory_bytes: 25172
import numpy as np


def main():
  N, *A = map(int, open(0).read().split())
  A.sort()
  A = np.array(A)

  if N % 2:
    array1 = np.array([-2] * (N // 2) + [1] * 2 + [2] * (N // 2 - 1))
    array2 = np.array([-2] * (N // 2 - 1) + [-1] * 2 + [2] * (N // 2))
  
    ret1 = np.dot(A, array1)
    ret2 = np.dot(A, array2)
    ret = max(ret1, ret2)

  else:
    array1 = np.array([-2] * (N // 2 - 1) + [-1] + [1] + [2] * (N // 2 - 1))
  
    ret = np.dot(A, array1)
  
  print(ret)
  
if __name__=="__main__":
  main()

Measured memory_bytes: 23112
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	N := nextInt()
	B := make([]int, N-1)

	for i := 0; i < N-1; i++ {
		B[i] = nextInt()
	}

	c := B[0] + B[N-2] // 最初と最後はそのまま

	for i := 0; i < N-2; i++ {
		c += min(B[i], B[i+1])
	}

	fmt.Println(c)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


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

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

int main() {
  ll h, a;
  cin >> h >> a;
  if (h % a == 0) cout << h / a << endl;
  else cout << h/a+1 << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

def divisor(x):
    div=[]
    for i in xrange(1,int(x**0.5)+1):
        if x%i==0:
            div.append(i)
            if i!=x/i:
                div.append(x/i)
    return div

def f(b,n):
    if n<b:
        return n
    else:
        return f(b,n/b)+n%b

n=int(raw_input())
s=int(raw_input())

if n==s:
    print(n+1)
    quit()

if n<s:
    print(-1)
    quit()

if n<=10**6:
    for i in xrange(2,n+2):
        if f(i,n)==s:
            print(i)
            quit()
    print(-1)
else:
    for i in xrange(2,10**6+1):
        if f(i,n)==s:
            print(i)
            quit()

    div=divisor(n-s)
    div.sort()
    for i in div:
        if i>=10**6:
            if f(i+1,n)==s:
                print(i+1)
                quit()
    print(-1)

Measured memory_bytes: 21740
# 2019-08-27 22:28:29
N, M = list(map(int, input().split()))
l = []
for i in range(N):
    m = list(map(int, input().split()))
    l.append(m)

l = sorted(l)
j = 0
sum = 0
while M != 0:
    if M - l[j][1] > 0:
        sum = sum + l[j][0] * l[j][1]
        M = M - l[j][1]
    else:
        sum = sum + l[j][0] * M
        M = 0 
    j += 1 
print(sum)

Measured memory_bytes: 28656
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

a,b,c = mint()
judge(c-(a+b)>0 and (c-(a+b))**2>4*a*b)

Measured memory_bytes: 68856
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;
template <class T, size_t D> struct _Vec {
    using type = vector<typename _Vec<T, D-1>::type>;
};
template <class T> struct _Vec<T, 1> {
    using type = vector<T>;
};
template<class T, size_t D> using Vec = typename _Vec<T, D>::type;

template <class T>
vector<T> make_v(size_t size, const T& init){ return vector<T>(size, init); }

template<class... Ts>
auto make_v(size_t size, Ts... rest) {
    return vector<decltype(make_v(rest...))>(size, make_v(rest...));
}
int main() {
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> v;
    for (int i = 0; i < n; ++i) {
        int k;
        scanf("%d", &k);
        for (int j = 0; j < k; ++j) {
            v.emplace_back(i+1);
        }
    }
    Vec<int, 2> m = make_v(h, w, 0);
    for (int i = 0; i < h; ++i) {
        if((i&1) == 0) for (int j = 0; j < w; ++j) {
            m[i][j] = v[w*i+j];
        }
        else for (int j = w-1; j >= 0; --j) {
             m[i][j] = v[w*i+w-j-1];
        }
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if(j) printf(" ");
            printf("%d", m[i][j]);
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		double xa[] = new double[n];
		double ya[] = new double[n];
		double ra[] = new double[n];
		double xb[] = new double[n];
		double yb[] = new double[n];
		double rb[] = new double[n];

		for (int i = 0; i < n; i++) {
			xa[i] = sc.nextDouble();
			ya[i] = sc.nextDouble();
			ra[i] = sc.nextDouble();
			xb[i] = sc.nextDouble();
			yb[i] = sc.nextDouble();
			rb[i] = sc.nextDouble();
		}

		double dx, dy, dr, xly;

		for (int i = 0; i < n; i++) {
			dx = Math.abs(xa[i] - xb[i]);
			dy = Math.abs(ya[i] - yb[i]);
			dr = Math.abs(ra[i] - rb[i]);
			xly = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
			if (ra[i] > xly + rb[i]) {
				System.out.println(2);
			} else if(rb[i] > xly + ra[i]) {
				System.out.println(-2);
			} else if(ra[i] + rb[i] >= xly){
				System.out.println(1);
			} else if(ra[i] + rb[i] < xly){
				System.out.println(0);
			}
		}
	}
}

Measured memory_bytes: 27892
DBG = true
s = gets.chomp
k = 'keyence'
if  s[0] + s[-6..-1] == k ||
    s[0..1] + s[-5..-1] == k ||
    s[0..2] + s[-4..-1] == k ||
    s[0..3] + s[-3..-1] == k ||
    s[0..4] + s[-2..-1] == k ||
    s[0..5] + s[-1] == k ||
    s[0..6]  == k
    print 'YES'
else
    print 'NO'
end


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

using namespace std;
using ll = long long;

int main() {
    double a, b, n;
    cin >> a >> b >> n;
    double x = min(n, b - 1);
    ll ans = floor((a * x) / b) - a * floor(x / b);
    cout << ans << endl;
}


Measured memory_bytes: 3728
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt(), C = in.nextInt();
        int[][] D = new int[C][C], c = new int[N][N];
        for(int i = 0; i < C; i++){
            for(int j = 0; j < C; j++) {
                D[i][j] = in.nextInt();
            }
        }
        Map<Integer, Integer>[] maps = new Map[3];
        for(int i = 0; i < 3; i++) maps[i] = new HashMap<>();
        for(int i = 0; i < N; i++){
            for(int j = 0; j < N; j++) {
                int num = in.nextInt() - 1;
                Integer cnt = maps[(i + j) % 3].get(num);
                maps[(i + j) % 3].put(num, cnt == null ? 1 : cnt + 1);
            }
        }
        int[][] cost = new int[3][C];
        for(int i = 0; i < 3; i++) {
            Map<Integer, Integer> map = maps[i];
            for(int j = 0; j < C; j++) {
                int sum = 0;
                for(int a : map.keySet()) {
                    if(a == j) continue;
                    sum += D[a][j] * map.get(a);
                }
                cost[i][j] = sum;
            }
        }
        int ans = Integer.MAX_VALUE;
        for(int i = 0; i < C; i++) {
            for(int j = 0; j < C; j++) {
                for(int k = 0; k < C; k++) {
                    if(i == j || i == k || j == k) continue;
                    ans = Math.min(ans, cost[0][i] + cost[1][j] + cost[2][k]);
                }
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 91076