akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
    mint p(int n, int k) {
        return fact[n]*ifact[n-k];
    }
};

    

int main(){
    int n;
    cin >> n;
    vector<int> a(n+1);
    rep(i, n+1) cin >> a[i];
    map<int, int> mp;
    int x = 0;
    int l, r;
    rep(i, n+1) {
        mp[a[i]]++;
        if (mp[a[i]]==2) {
            x = a[i];
            r = i;
        }
    }
    rep(i, n+1) {
        if (a[i]==x) {
            l = i;
            break;
        }
    }
    
    combination comb(n+1);
    int z = n+1 - (r-l+1);
    for (int k=1; k<=n+1; k++) {
        mint ans = 0;
        ans += comb(n-1, k);
        ans += comb(n-1, k-2);
        ans += comb(n-1, k-1)*mint(2);
        ans -= comb(z, k-1);
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 9824
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

const int mod = 1e9+7;

int main(){
    int N,M;
    cin >> N >> M;
    vector<ll> x(N+1), y(M+1);

    for(int i=1;i<=N;i++){
        cin >> x[i];
    }
    for(int i=1;i<=M;i++){
        cin >> y[i];
    }

    ll sum_x = 0ll;
    ll sum_y = 0ll;
    for(int i=1;i<=N;i++){
        (sum_x += ( (i-1)*x[i] - (N-i)*x[i] + mod ) %mod ) %=mod;
    }
    for(int i=1;i<=M;i++){
        (sum_y += ( (i-1)*y[i] - (M-i)*y[i] + mod ) %mod ) %=mod;
    }

    cout << sum_x * sum_y % mod << endl;


    return 0;
}

Measured memory_bytes: 1792
// https://atcoder.jp/contests/abc144/tasks/abc144_d

#include <iomanip>
#include "algorithm"
#include "cmath"
#include "iostream"
#include "queue"
#include "set"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const double PI = 3.14159265358979323846;

float to_deg(double r) { return r * 180.0 / PI; }

void solve() {
  ll a, b, x;
  cin >> a >> b >> x;

  double res;
  if (x >= a * a * b / 2) {
    res = to_deg(atan2(2 * a * a * b - 2 * x, a * a * a));
  } else {
    res = to_deg(atan2(a * b * b, 2 * x));
  }

  cout << fixed;
  cout << setprecision(7);
  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


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

def main():

    w = input()
    setW = set(w)
    listW = list(w)
    n = len(listW)

    for i in setW:
        if listW.count(i) % 2 == 1:
            ans = 'No'
            break

        else:
            ans = 'Yes'

    print(ans)

if __name__ == "__main__":
    main()

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

int main() {
	long long int m,i,j,k,n,sum=0,flag=0;
	string s,t,temp;
	cin>>s>>t;
	cin>>n>>m;
	cin>>temp;
	if(temp==s){
	cout<<n-1<<" "<<m;
	    
	}
	else{
	    cout<<n<<" "<<m-1;
	}
	
	return 0;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD 998244353ll
char S[303030];
ll N,N3;
stack<pll> rgbstk[3];
ll Fa[101010];
ll mk1[5],mk2[5];
ll i,j,k,ans;

ll ctid(const char& a){
    if(a=='R')
        return 0;
    if(a=='B')
        return 1;
    return 2;
}

int main(){
    scanf("%d%s",&N, S);
    N3 = N * 3;
    ans = 1;
    mk1[0] = N;
    fornum(i,0,N3){
        //printf("%lld ", ans);
        int id = ctid(S[i]);
        ll a = 0;
        fornum(j,0,3){
            if(id!=j&&mk2[j]>mk2[id]){
                a++;
            }
        }
        mk2[id]++;

        ans = ans * mk1[a] % MOD;
        mk1[a]--;
        mk1[a + 1]++;

    }
    printf("%lld", ans);
    return 0;
}

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

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

    static class DDisjointSetOfCommonDivisors {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long a = in.nextLong(), b = in.nextLong();
            long n = NumberTheory.gcd(a, b);

            for (long i = 2; i * i <= n; i++) {
                long d = i * i;
                while (n % d == 0) {
                    n /= i;
                }
            }

            if (n == 1) {
                out.println(1);
                return;
            }

            long answer = 2;
            for (long i = 2; i * i <= n; i++) {
                if (n % i == 0) {
                    answer++;
                    n /= i;
                }
            }

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }

    static class NumberTheory {
        public static long gcd(long a, long b) {
            long c;
            while (a != 0) {
                c = a;
                a = b % a;
                b = c;
            }
            return b;
        }

    }
}



Measured memory_bytes: 22868
// clang-format off
#include <bits/stdc++.h>

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b)-1; i >= (a); i--)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep(i, n) for(int i = (n)-1; i >= 0; i--)

#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define pii pair<int, int>
#define vi vector<int>

using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T>& p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T>& vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
using ll = long long;
constexpr ll MOD = 1000000007;


constexpr std::size_t N_MAX = 10000;

class UnionFindTree
{
public:
    UnionFindTree()
    {
        for (std::size_t i = 0; i < N_MAX; i++) {
            parent[i] = i;
            rank[i] = 0;
            size[i] = 1;
        }
    }

    bool same(const std::size_t a, const std::size_t b)
    {
        return find(a) == find(b);
    }

    std::size_t find(const std::size_t a)
    {
        if (parent[a] == a) {
            return a;
        } else {
            return parent[a] = find(parent[a]);
        }
    }

    void unite(const std::size_t a_, const std::size_t b_)
    {
        const std::size_t a = find(a_);
        const std::size_t b = find(b_);
        if (a == b) {
            return;
        }
        if (rank[a] > rank[b]) {
            parent[b] = a;
            size[a] += size[b];
        } else {
            parent[a] = b;
            size[b] += size[a];
        }
        if (rank[a] == rank[b]) {
            rank[b]++;
        }
    }

    std::size_t getSize(const std::size_t a)
    {
        return size[a];
    }

private:
    std::size_t parent[N_MAX];
    std::size_t rank[N_MAX];
    std::size_t size[N_MAX];
};


int main()
{
    int n, q;
    cin >> n>> q;
    UnionFindTree u;
    rep(i, q){
        int c;
        cin >> c;
        int x, y;
        cin >> x >> y;
        if(c == 0){
            u.unite(x, y);
        } else if (c == 1){
            if(u.same(x, y)){
                cout << 1 << endl;
            } else {
                cout << 0 << endl;
            }
        }
    }
    return 0;
}

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

long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

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

int main() {
  int N,ans=0,temp=-1;
  cin >> N;
  vector<int> A(N),B(N),C(N);
  rep(i,N) cin >> A[i];
  rep(i,N) cin >> B[i];
  rep(i,N) cin >> C[i];
  rep(i,N) {
    ans += B[A[i]-1];
    if(temp+1==A[i]-1) ans += C[A[i]-2];
    temp = A[i]-1;
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3600
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

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

ok = True
for a in As:
    if a % 2 == 0:
        if a % 3 == 0 or a % 5 == 0:
            pass
        else:
            ok = False
if ok:
    print('APPROVED')
else:
    print('DENIED')



Measured memory_bytes: 6348
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    map<string, int> mm = {{"SUN",7}, {"MON", 6}, {"TUE", 5},
     {"WED", 4}, {"THU",3}, {"FRI", 2}, {"SAT", 1}};
    string s;
    cin >> s;
    cout << mm[s] << endl;
    return 0;
}



Measured memory_bytes: 256
import java.lang.Math;
import java.util.Scanner;
import java.util.Arrays;

class Main {
    public static int gcd(int a, int b) {
        return a == 0 ? b : gcd(b % a, a);
      }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] A = new int[N];

        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        int[] rangeGCDFromFront = new int[N];
        int[] rangeGCDFromBack = new int[N];

        rangeGCDFromFront[0] = A[0];
        for (int i = 1; i < N; i++) {
            rangeGCDFromFront[i] = gcd(rangeGCDFromFront[i-1], A[i]);
        }
        rangeGCDFromBack[N-1] = A[N-1];
        for (int i = N-2; i >= 0; i--) {
            rangeGCDFromBack[i] = gcd(rangeGCDFromBack[i+1], A[i]);
        }

        // System.out.println(Arrays.toString(rangeGCDFromFront));
        // System.out.println(Arrays.toString(rangeGCDFromBack));

        int maxGCD = Math.max(rangeGCDFromFront[N-2], rangeGCDFromBack[1]);
        for (int i = 1; i < N-1; i++) {
            int gcd = gcd(rangeGCDFromFront[i-1], rangeGCDFromBack[i+1]);
            if (gcd > maxGCD) { maxGCD = gcd; }
        }

        System.out.println(maxGCD);
    }
}


Measured memory_bytes: 51128
(stdin => {
  // Define Function
  const Area = (a, b) => a * b
  const Sur = (a, b) => a * 2 + b * 2
  // Declare Variable
  const inputs = stdin.toString().trim().split(' ')
  const a = parseInt(inputs[0], 10)
  const b = parseInt(inputs[1], 10)
  console.log(`${Area(a, b)} ${Sur(a, b)}`)
})(require('fs').readFileSync('/dev/stdin', 'utf8'))


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

int main(){
    ll n, a, b, c, d, e;
    cin >> n >> a >> b >> c >> d >> e;
    ll mn = min({a, b, c, d, e});
    cout << 4 + (n + mn-1) / mn << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>

using namespace std;

int main()
{
    int a,b,c;
    for(;;){
    cin >> a >> b >> c;
    if(a==-1&&b==-1&&c==-1) break;
    else{
       if(a>=0&&b>=0){
           if(a+b>=80) cout << "A" << endl;
           else if(a+b>=65) cout << "B" << endl;
           else if(a+b>=50) cout << "C" << endl;
           else if(a+b>=30){
               if(c>=50) cout << "C" <<endl;
               else cout << "D" << endl;
           }
           else cout << "F" << endl;
       }
       else cout << "F" <<endl;
    }
    }
    return 0;
}



Measured memory_bytes: 3116
from math import *
a,b,x=input().split()
a=float(a)
b=float(b)
x=float(x)
if x>(a*a*b)/2:
	y = 2*(a*a*b-x)/(a*a*a)
elif x==(a*a*b)/2:
	y = b/a
else:
	y=(a*b*b)/(2*(x))
ans=(atan(y)*180)/pi
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, n, m, p;
  cin >> N;
  n = N;
  p = 0;
  
  for (;n != 0;) {
    m = n % 10;
    p += m;
    n = (n - m) /10;
  }
  
  if (N % p == 0) {
    cout << "Yes" << endl;
  }
  else  {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N;
int dfs(int a, string S){
  if(N == S.size()){
    cout << S << endl;
  } else {
    char c;
    for(int i = 0; i <= a + 1; i++){
      c = 'a' + i;
      if(i != a + 1)dfs(a, S + c);
      else dfs(a + 1, S + c);
    }
  }
}
int main () {
  cin >> N;
  dfs(0, "a");
  return 0;
}

Measured memory_bytes: 1536
import sys

from collections import Counter, defaultdict, deque

input = sys.stdin.readline

N, X, Y = [int(x) for x in input().split()]


def bfs(source):
    q = deque([source])
    dist = {source: 0}
    while q:
        i = q.popleft()
        d = dist[i]
        nbr = []
        if i - 1 >= 1:
            nbr.append(i - 1)
        if i + 1 <= N:
            nbr.append(i + 1)
        if i == X:
            nbr.append(Y)
        if i == Y:
            nbr.append(X)
        for j in nbr:
            if j not in dist:
                q.append(j)
                dist[j] = d + 1
    return dist


count = Counter()
for i in range(1, N + 1):
    dist = bfs(i)
    assert len(dist) == N
    for j, d in dist.items():
        if i < j:
            count[d] += 1

ans = []
for k in range(1, N):
    ans.append(str(count[k]))
print('\n'.join(ans))


Measured memory_bytes: 95452
n=int(input())
N=n
a=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
t=1
for i in range(1,20):
    if n>26**i:
        n=n-26**i
        t+=1
p=[0]*t
s=0
A=""
for i in range(1,t+1):
    s=N%26
    if s == 0:
        s = 26
    N=(N-s)//26
    p[t-i]=s
for i in range(t):
    A+=(a[p[i]-1])
print(A)

Measured memory_bytes: 61844
#include <stdio.h>
int main(){
  int i,r,d,x,xi,ans;
  scanf("%d%d%d",&r,&d,&x);
  xi=x;
  for(i=1;i<=10;i++){
    ans=r*xi-d;
    printf("%d\n",ans);
    xi=ans;
  }
  return 0;
}


Measured memory_bytes: 128
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    int n,k,sum=0;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<k;i++){
        sum+=a[i];
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const char newl = '\n';

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

  ll n, sum=0, ans=1;
  cin >> n;
  vl a(n+1);
  rep(i, n+1) {
    cin >> a[i];
    sum += a[i];
  }
  
  if(a[0]>0) {
    if(n==0 and a[0]==1) cout << ans << newl;
    else cout << -1 << newl;
    return 0;
  }
  
  ll num = 1;
  rep2(i, n) {
    num *= 2;
    chmin(num, sum);
    //cout << num << newl;
    ans += num;
    num -= a[i];
    sum -= a[i];
    if(num<0) goto OUT;
  }
  cout << ans << newl;
  return 0;
  
  OUT:
  cout << -1 << newl;
  return 0;
}

Measured memory_bytes: 3976
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <complex>

using ll = long long int;
using namespace std;

int main(){

  ll L;
  cin >> L;

  cout << std::setprecision(10) <<  (L/3.0)*(L/3.0)*(L/3.0) << endl;
  
  return 0;
}


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

#define debug(n) cerr << #n << ':' << n << endl;

using namespace std;

using  ll = long long;

template<class T,class U>
using umap = unordered_map<T,U>;

template<class T>
using uset = unordered_set<T>;

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

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


int main(){
  int n; cin >> n;
  vector<int> a(n, 1e+9);
  vector<int> b(n-1);
  for(int&x : b)cin >> x;
  for(int i = 0; i < n-1; ++i){
    if(a[i] > b[i])a[i] = b[i];
    if(a[i+1] > b[i])a[i+1] = b[i];
  }
  int ans = 0;
  for(int&x:a)ans += x;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n=int(input())
dic={}
m=0
li=[]

for _ in range(n):
    w=input()
    dic[w]=dic.get(w, 0)+1
    if dic[w]==m:
        li.append(w)
    elif dic[w]>m:
        li=[w]
        m+=1

for l in sorted(li):
    print(l)

Measured memory_bytes: 33420
import numpy as np
n,m = map(int,input().split())
if m-n<=0:
  print(0)
  exit()

data = [int(i) for i in input().split()]
data.sort()
data1 = data.copy()
data1.insert(0,0)
data1= np.array(data1[0:-1])
data = np.sort((np.array(data)-data1)[1:])
print(data[:m-n].sum())

Measured memory_bytes: 23004
#!/usr/bin/env python
# coding: utf-8

# In[1]:


N,K = map(int, input().split())
S = input()


# In[2]:


cnt = 1
for i in range(N-1):
    if S[i] != S[i+1]:
        cnt += 1
cnt = max(1,cnt-K*2)
print(N-cnt)


# In[ ]:






Measured memory_bytes: 9264
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
int main() {
cout << fixed << setprecision(30);
  ll x;
  cin>>x;
  vec dp(100005);
  loop(i,100){
    dp[i]=0;
  }
  Loop(i,100,106){
    dp[i]=1;
  }
  Loop(i,106,100005){
    if(dp[i-100]==1){
      dp[i]=1;
      continue;
    }
   if(dp[i-101]==1){
      dp[i]=1;
      continue;
    }
    if(dp[i-102]==1){
      dp[i]=1;
      continue;
    }
    if(dp[i-103]==1){
      dp[i]=1;
      continue;
    }
    if(dp[i-104]==1){
      dp[i]=1;
      continue;
    }
    if(dp[i-105]==1){
      dp[i]=1;
      continue;
    }
    dp[i]=0;
  }
  putout(dp[x]);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef vector<int> vi;

#define mp make_pair
#define pb push_back

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
 
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
 
const int MOD = 1000000007;
double PI = 4*atan(1);

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int maxcost = (1<<30)-1;
	int N; cin >> N;
	vi a(N);
	F0R(i,N) cin >> a[i];
	FOR(i,-100,101) {
		int c1 = 0;
		F0R(j,N) c1 += (a[j]-i)*(a[j]-i);
		maxcost = min(maxcost,c1);
	}
	cout << maxcost;
	return 0;
}

Measured memory_bytes: 256
import fractions

a,b,c,d=map(int,input().split())
g=int(fractions.gcd(c,d))
l=int((c*d)/g)

print(b-a+1-int(b//c)+int((a-1)//c)-int(b//d)+int((a-1)//d)+int(b//l)-int((a-1)//l))


Measured memory_bytes: 6584
#include<stdio.h>
int main(void){
    int n;
    int i,x;
    int cnt;
    cnt=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&x);
        if(x%2==1){
            cnt++;
        }
    }
    if(cnt%2==0){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
using P = pair<int, int>;

int main(){
    int n;
    cin >> n;
    vector<P> point(n);
    for(int i = 0; i < n; i++){
        cin >> point[i].first >> point[i].second;
    } 

    vector<int> sub(n), tot(n);
    for(int i = 0; i < n; i++){
        sub[i] = point[i].first - point[i].second;
        tot[i] = point[i].first + point[i].second;
    }

    sort(sub.begin(), sub.end());
    sort(tot.begin(), tot.end());

    int ans = max(abs(tot[0] - tot[n-1]), abs(sub[0] - sub[n-1]));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5940
#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: 11852
//#include <tourist>
#include <bits/stdc++.h>
    using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n, k;
const ll M = pow(10, 9) + 7;

vector<ll> fac(1000001);  //n!(mod M)
vector<ll> ifac(1000001); //k!^{M-2} (mod M)
ll mpow(ll x, ll n)
{ //x^n(mod M)
    ll ans = 1;
    while (n != 0)
    {
        if (n & 1)
            ans = ans * x % M;
        x = x * x % M;
        n = n >> 1;
    }
    return ans;
}
//conbination
ll comb(ll a, ll b)
{ //aCb(mod M)
    if (a == 0 && b == 0)
        return 1;
    if (a < b || a < 0)
        return 0;
    ll tmp = ifac[a - b] * ifac[b] % M;
    return tmp * fac[a] % M;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    vector<ll> v(k+1);
    for(ll i=0;i<k;i++){
        v[i+1]=mpow(k/(i+1),n);
    }
    //debug(v);
    vector<ll> ans(k+1);
    ll ans_t=0;
    for(ll i=k;i>=1;i--){
        ll temp=v[i];
        ll j=1;
        while(true){
            j++;
            if(i*j>k){
                break;
            }
            temp-=ans[i*j];
            temp=(temp+MOD)%MOD;
        }
        ans[i]=temp;
        ans_t+=temp*i;
        ans_t%=MOD;
    }
    cout<<ans_t<<"\n";
}


Measured memory_bytes: 20292
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int N; cin >> N;
    vector<int> A(N); for(auto& x: A) cin >> x;

    bool flag = true;

    for (auto& x:A) {
        if (x % 2 == 0) if (x % 3 != 0 && x % 5 != 0) flag = false;
    }

    if (flag) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;

public class Main {

    public static class action {
        int from, to;

        action(int a, int b) {
            this.from = a;
            this.to = b;
        }
    }

    public static class edge {
        int to;
        long cost;

        edge(int b, long c) {
            this.to = b;
            this.cost = c;
        }
    }

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

        int n = Integer.parseInt(br.readLine());
        ArrayList[] edges = new ArrayList[n];
        for (int i = 0; i < n; i++) edges[i] = new ArrayList();

        for (int i = 0; i < n - 1; i++) {
            String[] str = br.readLine().split(" ");
            int a = Integer.parseInt(str[0]) - 1;
            int b = Integer.parseInt(str[1]) - 1;
            long c = Long.parseLong(str[2]);

            edge ed = new edge(b, c);
            edges[a].add(ed);
            ed = new edge(a, c);
            edges[b].add(ed);
        }

        String[] str = br.readLine().split(" ");
        int q = Integer.parseInt(str[0]);
        int k = Integer.parseInt(str[1]) - 1;
        long[] dist = new long[n];
        boolean[] reached = new boolean[n];
        Arrays.fill(reached, false);
        dist[k] = 0;
        reached[k] = true;

        ArrayDeque<Integer> que = new ArrayDeque();
        que.add(k);
        while(!que.isEmpty()){
            int node = que.poll();
            for(Object t: edges[node]){
                edge e = (edge) t;
                if(reached[e.to]) continue;

                dist[e.to] = dist[node] + e.cost;
                que.add(e.to);
                reached[e.to] = true;
            }

        }


        for (int i = 0; i < q; i++) {
            str = br.readLine().split(" ");
            int x = Integer.parseInt(str[0]) - 1;
            int y = Integer.parseInt(str[1]) - 1;
            System.out.println(dist[x] + dist[y]);
        }
    }
}


Measured memory_bytes: 91964
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, start, end) for(int i = start; i < (int)(end); ++i)

bool comp(pair<int,int> l, pair<int,int> r) {
  if (l.second != r.second) return l.second > r.second;
  else return l.first > r.first;
}

int main(){
    int n;
    cin >> n;
    vector<pair<int, int>> task(n);
    rep(i,0,n) cin >> task[i].first >> task[i].second;
    sort(task.begin(), task.end(), comp);
    int now = task[0].second;
    rep(i,0,n){
        now = min(now, task[i].second);
        now -= task[i].first;
        if(now < 0) break;
    }
    if(now < 0){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 1792
import sys
n=int(input())
X=[]
Y=[]
H=[]
MAX=100
for i in range(n):
    x,y,h=map(int,input().split())
    X.append(x)
    Y.append(y)
    H.append(h)
for posX in range(MAX+1):
    for posY in range(MAX+1):
        needH=-1
        for i in range(n):
            if H[i]>0:
                tmp=H[i]+abs(X[i]-posX)+abs(Y[i]-posY)
                if needH==-1:
                    needH=tmp
                else:
                    if needH!=tmp:
                        needH=-2
                        break
                 
        if needH==-2:
            continue
        for i in range(n):
            if H[i]==0: 
                dis=abs(X[i]-posX)+abs(Y[i]-posY)
                if needH>dis:
                    needH=-2
                    break 
        if needH==-2:
            continue
        print(posX,posY,needH)
     


Measured memory_bytes: 3064
x, y = map(int, input().split())
diff = abs(x - y)
ref = (min(x, y) - diff)//3
total = ref*2 + diff
mod = 10**9 + 7
ans = 1

if (x + y)%3 != 0 or ref < 0:
    print(0)
    exit()


for i in range(min(ref, total - ref)):
    ans = ans*(total - i)%mod
    ie = pow((i + 1), (mod - 2), mod)
    ans = ans*ie%mod

print(ans)

Measured memory_bytes: 9160
/*input

*/


//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<ll int,ll int>
#define vpii        vector< pii >
#define vi          vector<ll int>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


ll n,k,c;
string s;

vi fun()
{
	vi ans(n);
	rep(i,0,n) 
	{
		if(i==0) ans[i]=(s[i]=='o');
		else
		{
			if(s[i]=='x') ans[i]=ans[i-1];
			else ans[i]=max((i-c-1>=0?ans[i-c-1]:0)+1,ans[i-1]);
		}
	}

	return ans;
}

int solve()
{
	cin>>n>>k>>c;
	cin>>s;

	vi l = fun();

	// rep(i,0,n) cout<<l[i]<<" ";
	// cout<<"\n";

	reverse(s.begin(), s.end());
	vi r = fun();
	reverse(r.begin(), r.end());

	// rep(i,0,n) cout<<r[i]<<" ";
	// cout<<"\n";

	vi ans;
	reverse(s.begin(), s.end());
	c=0;
	rep(i,0,n) if(s[i]=='o' && (i-c-1>=0?l[i-c-1]:0)+(i+c+1<n?r[i+c+1]:0)+1==k) ans.pb(i+1);
	rep(i,0,sz(ans)) cout<<ans[i]<<"\n";
	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	// cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

Measured memory_bytes: 6536
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	int d, t, s; cin >> d >> t >> s;
	if (d <= t*s) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3600
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

// template<class InputIterator, class F>
// bool all_of_index(InputIterator first, InputIterator last, F pred) {
//   while (first != last) {
//     if (!pred(*first)) return false;
//     ++first;
//   }
//   return true;
// }

void solve() {
  int n;
  while (cin >> n, n) {
    vi v(26);
    vc cs(n);
    rep(i, n) cin >> cs[i];
    rep(i, n) {
      char c = cs[i];
      v[c - 'A']++;
      auto maxIter = max_element(all(v));
      int maxVotes = *maxIter;
      int maxIndex = distance(v.begin(), maxIter);
      int remain   = n - i - 1;
      bool b       = true;
      rep(j, v.size()) if (j != maxIndex) b &= v[j] + remain < maxVotes;
      if (b) {
        cout << char(maxIndex + 'A') << ' ' << i + 1 << endl;
        goto next;
      }
    }
    cout << "TIE" << endl;
  next:;
  }
}

Measured memory_bytes: 3080
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007 //S(vector).size()
using namespace std;
typedef long long ll;

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

  int cnt_right_E = 0;
  for(int i = 1; i < n; i++){
    if(s[i] == 'E') cnt_right_E++;
  }

  int ans = cnt_right_E;
  int cnt_left_W = 0;
  for(int i = 1; i < n; i++){
    if(s[i - 1] == 'W'){
      cnt_left_W++;
    }
    if(s[i] == 'E') {
      cnt_right_E--;
    }
    ans = min(ans, cnt_left_W + cnt_right_E);
  }
  cout << ans << endl;

  return 0;
}


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

/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

using namespace std;

typedef long long ll;

const int N_MAX = 1000002;

int n;

int cnt[N_MAX];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++)
        for(int j = i; j <= n; j += i)
            cnt[j]++;
    ll ans = 0;
    for(int i = 1; i < n; i++)
        ans += cnt[i];
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 7552
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def e(a):
        return ((a*(a+1))>>1)/a
    n,k = LI()
    p = LI()
    p = [e(i) for i in p]
    ans = m = sum(p[:k])
    for i in range(n-k):
        m -= p[i]
        m += p[i+k]
        if ans < m:
            ans = m
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 73608
#include <bits/stdc++.h>
#define INT long long int
#define MOD 998244353
#define oo 6*(1e18)
using namespace std;
INT n, a[200020], ans, ans2;
deque<INT> q;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i = 0 ; i < n ; i++ )
        cin>>a[i];
    sort(a, a+n);
    q.push_back(a[0]);
    for(int i = 1, j = n-1, p = 0 ; i <= j ; p++ )
    {
        if( i == j )
        {
            if( abs(a[i]-q.front()) > abs(a[i]-q.back()) )
                q.push_front(a[i]);
            else
                q.push_back(a[i]);
            break;
        }
        if( p%2 == 0 )
        {
            q.push_back(a[j--]);
            q.push_front(a[j--]);
        }
        else
        {
            q.push_back(a[i++]);
            q.push_front(a[i++]);
        }
    }
    INT t = q.front(); q.pop_front();
    while( !q.empty() )
    {
        ans += abs(t-q.front());
        t = q.front();
        q.pop_front();
    }
    q.push_back(a[n-1]);
    for(int i = 0, j = n-2, p = 0 ; i <= j ; p++ )
    {
        if( i == j )
        {
            if( abs(a[i]-q.front()) > abs(a[i]-q.back()) )
                q.push_front(a[i]);
            else
                q.push_back(a[i]);
            break;
        }
        if( p%2 == 1 )
        {
            q.push_back(a[j--]);
            q.push_front(a[j--]);
        }
        else
        {
            q.push_back(a[i++]);
            q.push_front(a[i++]);
        }

    }
    t = q.front(); q.pop_front();
    while( !q.empty() )
    {
        ans2 += abs(t-q.front());
        t = q.front();
        q.pop_front();
    }
    cout<<max(ans2, ans)<<endl;
}


Measured memory_bytes: 1920
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

from itertools import accumulate
aa=[0]+list(accumulate(a))
bb=[0]+list(accumulate(b))

from bisect import bisect_left,bisect

kmax=0
for i in range(n+1):
    if k<aa[i]:
        break
    kk=k-aa[i]
    k2=bisect(bb,kk)-1
#    print(i,k2,aa[i],bb[k2])
    kmax=max(kmax,k2+i)

print(kmax)

Measured memory_bytes: 50688
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define dbg(n) cout<<#n<<' '<<n<<endl;
int main(){ 
	int a;
	cin>>a;
	cout<<a+a*a+a*a*a<<endl;
}



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

using namespace std;

typedef unsigned long long ull;


int main() {
	int n;
	cin >> n;
	int D[n];
	for(int i=0;i<n;i++){
		cin >> D[i];
	}
	sort(D,D+n);
	int m;
	cin >> m;
	int T[m];
	for(int i=0;i<m;i++){
		cin >> T[i];
	}
	sort(T,T+m);
	int i=0,j=0;
	while(j<m){
		if(D[i]<T[j])
			i++;
		else if(D[i]==T[j]){
			i++;
			j++;
		}
		else{
			cout << "NO" ;
			return 0;
		}
		if(i==n-1 and j!=m-1){
			cout << "NO";
			return 0;
		}

	}
	cout << "YES";


	
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  V<> a(4); for (int i = 0; i < 4; ++i) cin >> a[i];
  sort(begin(a), end(a));
  V<> b{1, 4, 7, 9};
  cout << (a == b ? "YES" : "NO") << '\n';
}

Measured memory_bytes: 256
use std::io;
use std::collections::HashMap;
use std::cmp::max;
use std::cmp::min;

fn main() {
    let mut buffer = String::new();
    io::stdin().read_line(&mut buffer).unwrap();
    let x: u32 = (&buffer[..buffer.len() - 1]).parse().unwrap();

    let mut set = HashMap::new();
    let mut a: u32 = 0;
    let b = loop {
        let a5 = a.pow(5);
        let b5 = max(x, a5) - min(x, a5);
        match set.get(&b5) {
            Some(&b) => break if a5 < x { -(b as i32) } else { b as i32 },
            None => set.insert(a5, a),
        };
        a += 1;
    };

    println!("{} {}", a, b);
}


Measured memory_bytes: 2112
#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 int long long int
#define float long double
#define pb push_back
#define fi first
#define se second
#define vii vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define pq priority_queue<int>
#define test int tcase; cin>>tcase; for(int tc = 1; tc <= tcase; tc++)
#define inp(a,n,f) int a[n+f];for(int hh=f;hh<n+f;hh++)cin>>a[hh];
#define prdec(k) cout<<fixed<<setprecision(k);
#define mem(a,k) memset(a,k,sizeof(a))
#define ub upper_bound
#define lb lower_bound
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mii map<int,int>
#define all(v) v.begin(),v.end()
#define mod (int)(1e9+7)
#define inf LLONG_MAX
int exp(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int modinv(int x){return exp(x,mod-2);}
#define N 1000000

int di[N+1]={0};


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

	for(int i=1;i<=N;i++)
		for(int j=i;j<=N;j+=i)
			di[j]++;

	int n,ans=0;
	cin>>n;
	for(int c=1;c<n;c++)
	{
		int res=n-c;
		if(res>0)
			ans+=di[res];
	}
	cout<<ans;
	return 0;
}

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

int main() {
    int N, Y; cin >> N >> Y;
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= N - i; j++){
            if (10000 * i + 5000 * j + 1000 * (N - i - j) == Y) {
                cout << i << " " << j << " " << N - i - j << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
}


Measured memory_bytes: 256