Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from math import *

def comb(n, r):
    ''' nCr '''
    if n == 1:
        return 0
    return int(factorial(n)/(factorial(r)*factorial(n-r)))

N = int(input())
a = [int(a_i) for a_i in input().split()]
s = []  # s[i] = a[0]からa[i+1]までの総和
sum = 0
for i in range(N):
    sum += a[i]
    s.append(sum)
ans = 0
s.sort()
val = float('inf')  # 前から見ていくときのs[i]の値
for s_i in s:
    if s_i == val:
        continue
    val = s_i
    if val == 0:
        ans += s.count(0) + comb(s.count(0), 2)
    else:
        ans += comb(s.count(val), 2)
print(ans)


Fixed submission:
from collections import defaultdict

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

sum = [0]
for i in range(N):
    sum.append(sum[i] + A[i])

sum.sort()
dict = defaultdict(int)
for i in range(N + 1):
    dict[sum[i]] += 1

ans = 0
for key, val in dict.items():
    ans += val * (val - 1) // 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [int(a_i) for a_i in input().split()]
s = [0]  # s[i] = a[1]からa[i]までの総和
sum = 0
for i in range(N):
    sum += a[i]
    s.append(sum)
ans = 0
for i in range(N):
    for j in range(i, N):
        if s[j] - s[i-1] == 0:
            ans += 1
print(ans)


Fixed submission:
from collections import defaultdict

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

sum = [0]
for i in range(N):
    sum.append(sum[i] + A[i])

sum.sort()
dict = defaultdict(int)
for i in range(N + 1):
    dict[sum[i]] += 1

ans = 0
for key, val in dict.items():
    ans += val * (val - 1) // 2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a, b = map(int, input().split())
p = 1
for i in range(a, b + 1):
    p *= i
if p > 0:
    print("Positive")
elif p == 0:
    print("Zero")
else:
    print("Negative")


Fixed submission:
a, b = map(int, input().split())
res = "Positive"
if b < 0:
    if (b - a + 1) & 1:
        res = "Negative"
elif b >= 0:
    if a <= 0:
        res = "Zero"
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest
import itertools

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    #n,m,k=map(int, readline().rstrip().split())
    mod=10**9+7
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    ans=0
    for p in itertools.combinations(arr,2):
        ans=(ans+p[0]*p[1])%mod
    #ss=readline().rstrip()
    #yn(1)
    print(ans)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Fixed submission:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest
import copy

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    #n,m,k=map(int, readline().rstrip().split())
    mod=10**9+7
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    arr2=copy.copy(arr)
    for i in range(1,n):
        arr2[i]=(arr2[i]+arr2[i-1])%mod
    base=arr2[n-1]+mod
    ans=0
    for i in range(n-1):
        ans=(ans+arr[i]*((base-arr2[i])%mod))%mod
    print(ans)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------
Buggy python submission (verdict: Time Limit Exceeded):
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    n,k=map(int, readline().rstrip().split())
    arr=list(map(int, readline().rstrip().split()))
    
    score=1
    for i in range(n):
        score*=arr[i]
        if (i+1) > k:
            score = score//arr[i-k]
            if score > bef:
                print("Yes")
            else:
                print("No")
        bef=score

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------


Fixed submission:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    n,k=map(int, readline().rstrip().split())
    arr=list(map(int, readline().rstrip().split()))
    
    score=1
    for i in range(n):
        #score*=arr[i]
        if (i+1) > k:
            #score = score//arr[i-k]
            if arr[i] > arr[i-k]:
                print("Yes")
            else:
                print("No")
        #bef=score

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------
Buggy python submission (verdict: Runtime Error):
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    n,m,k=map(int, readline().rstrip().split())
    aa=list(map(int, readline().rstrip().split()))
    bb=list(map(int, readline().rstrip().split()))
    asum=[0]*n
    bsum=[0]*m
    memo=[0]*n
    asum[0]=aa[0]
    bsum[0]=bb[0]
    mp=n-1
    ans=0
    for i in range(1,n):
        asum[i]=(aa[i]+asum[i-1])
    for i in range(1,m):
        bsum[i]=(bb[i]+asum[i-1])

    for i in range(m+1):
        if i==0:
            x=0
        else:
            x = bsum[i-1]
        while mp>=0:
            if asum[mp]+x <= k:
                break
            else:
                mp-=1
        if mp>=0:
            if asum[mp]+x <= k:
                ans = max(i + mp+1,ans)
        else:
            if x <= k:
                ans = max(i,ans)
    print(ans)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Fixed submission:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    n,m,k=map(int, readline().rstrip().split())
    aa=list(map(int, readline().rstrip().split()))
    bb=list(map(int, readline().rstrip().split()))
    asum=[0]*n
    bsum=[0]*m
    asum[0]=aa[0]
    bsum[0]=bb[0]
    mp=n-1
    ans=0
    for i in range(1,n):
        asum[i]=(aa[i]+asum[i-1])
    for i in range(1,m):
        bsum[i]=(bb[i]+bsum[i-1])

    for i in range(m+1):
        if i==0:
            x=0
        else:
            x = bsum[i-1]
        while mp>=0:
            if asum[mp]+x <= k:
                break
            else:
                mp-=1
        if mp>=0:
            if asum[mp]+x <= k:
                ans = max(i + mp+1,ans)
        else:
            if x <= k:
                ans = max(i,ans)
    print(ans)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------
Buggy python submission (verdict: Time Limit Exceeded):
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def resolve():
    readline=sys.stdin.readline
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    arr.sort()
    tb=[False]*(10**6 + 10)
    ans=0
    for i in range(n):
        flg=0
        x=arr[i]
        if tb[x]==False:
            flg=1
        if i < (n-1):
            if arr[i]==arr[i+1]:
                flg=0
        ans+=flg
        for j in range(x,10**6+5,x):
            tb[j]=True
    print(ans)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Fixed submission:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest
import collections

def resolve():
    readline=sys.stdin.readline
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    c=collections.Counter(arr)
    tb=[False]*(10**6 + 10)
    ans=0
    for x in c.keys():
        for j in range(x*2,10**6+5,x):
            tb[j]=True
    for x in c.keys():
        if tb[x]==0 and c[x]==1:
            ans+=1
    print(ans)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Buggy python submission (verdict: Time Limit Exceeded):
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    #a,b,c=map(int, readline().rstrip().split())
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    arr.sort()
    tb=[0]*(10**6 + 10)
    ans=0
    for i in range(n):
        x=arr[i]
        for j in range(x,10**6+5,x):
            tb[j]+=1
    for i in range(n):
        x=arr[i]
        if tb[x]==1:
            ans+=1
    print(ans)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Fixed submission:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest
import collections

def resolve():
    readline=sys.stdin.readline
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    c=collections.Counter(arr)
    tb=[False]*(10**6 + 10)
    ans=0
    for x in c.keys():
        for j in range(x*2,10**6+5,x):
            tb[j]=True
    for x in c.keys():
        if tb[x]==0 and c[x]==1:
            ans+=1
    print(ans)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------
Buggy python submission (verdict: Time Limit Exceeded):
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

sys.setrecursionlimit(100000000)

def yn(b):
    print("Yes" if b==1 else "No")
    return

def xxx(t,memo,ans,kyori):
    for a in memo[t]:
        if ans[a] == -1 or kyori[a] > (kyori[t]+1):
            ans[a]=t
            kyori[a]=kyori[t]+1
            xxx(a,memo,ans,kyori)


def resolve():
    readline=sys.stdin.readline

    n,m=map(int, readline().rstrip().split())
    memo=[[] for i in range(n)]
    ans=[-1]*n
    kyori=[-1]*n
    ans[0]=0
    kyori[0]=0
    for i in range(m):
        a,b=map(int, readline().rstrip().split())
        memo[a-1].append(b-1)
        memo[b-1].append(a-1)
    xxx(0,memo,ans,kyori)
    #tt=[0]
    #nx=[]
    #for t in tt:
    #    for a in memo[t]:
    #        if ans[a]
        
    #memo

    if -1 in ans:
        print("No")
    else:
        print("Yes")
        for i in range(1,n):
            print(ans[i]+1)


    #arr=list(map(int, readline().rstrip().split()))
    #n=int(readline())
    #ss=readline().rstrip()
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------


Fixed submission:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

sys.setrecursionlimit(100000000)

def yn(b):
    print("Yes" if b==1 else "No")
    return

def xxx(t,memo,ans,kyori):
    for a in memo[t]:
        if ans[a] == -1 or kyori[a] > (kyori[t]+1):
            ans[a]=t
            kyori[a]=kyori[t]+1
            xxx(a,memo,ans,kyori)


def resolve():
    readline=sys.stdin.readline

    n,m=map(int, readline().rstrip().split())
    memo=[[] for i in range(n)]
    ans=[-1]*n
    kyori=[-1]*n
    ans[0]=0
    kyori[0]=0
    for i in range(m):
        a,b=map(int, readline().rstrip().split())
        memo[a-1].append(b-1)
        memo[b-1].append(a-1)
    #xxx(0,memo,ans,kyori)
    tt=[0]
    while 1:
        nx=[]
        for t in tt:
            for a in memo[t]:
                if ans[a] == -1 or kyori[a] > (kyori[t]+1):
                    nx.append(a)
                    ans[a]=t
                    kyori[a]=kyori[t]+1
        if len(nx)==0:
            break
        else:
            tt=nx
        
    #memo

    if -1 in ans:
        print("No")
    else:
        print("Yes")
        for i in range(1,n):
            print(ans[i]+1)


    #arr=list(map(int, readline().rstrip().split()))
    #n=int(readline())
    #ss=readline().rstrip()
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------
Buggy python submission (verdict: Runtime Error):
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline
    x=int(readline())
    to=6000
    memo=[0]*to
    #memo={}
    for i in range(to):
        memo[i]=i**5

    for i in range(to):
        z1=x-memo[i]
        z2=memo[i]-x
        if z1 in memo:
            a=i
            for j in range(to):
                if memo[j]==z1:
                    b=j*-1
            break
        if z2 in memo:
            a=i
            for j in range(to):
                if memo[j]==z1:
                    b=j
            break

    print(a,b)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Fixed submission:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline
    x=int(readline())
    to=1001
    memo=[0]*to
    #memo={}
    for i in range(to):
        memo[i]=i**5

    a=0
    b=0
    if x==0:
        print(a,b)
        return

    for i in range(to):
        z1=x-memo[i]
        z2=memo[i]-x
        if z1 in memo:
            a=i
            for j in range(to):
                if memo[j]==z1:
                    b=j*-1
            break
        if z2 in memo:
            a=i
            for j in range(to):
                if memo[j]==z2:
                    b=j
            break
    #if a!=0 or b!=0:
    #    print(a,b)
    #    return
    print(a,b)
    return
    
    b=1000**5
    for i in range(1001,100000000):
        a=b
        b=i**5
        if (b-a)==x:
            print(i,(i-1))
            return

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------
Buggy python submission (verdict: Time Limit Exceeded):
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    #n,m,k=map(int, readline().rstrip().split())
    #arr=list(map(int, readline().rstrip().split()))
    k=int(readline())
    #ss=readline().rstrip()
    #yn(1)
    ans=0
    for a in range(1,k+1):
        for b in range(1,k+1):
            for c in range(1,k+1):
                ans+=gcd(a,b,c)
    print(ans)



    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Fixed submission:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    #n,m,k=map(int, readline().rstrip().split())
    #arr=list(map(int, readline().rstrip().split()))
    k=int(readline())
    #ss=readline().rstrip()
    #yn(1)
    ans=0
    for a in range(1,k+1):
        for b in range(1,k+1):
            for c in range(1,k+1):
                ans+=gcd(a,b,c)
    print(ans)



    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------
Buggy python submission (verdict: Runtime Error):
import sys
from io import StringIO
import unittest

class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

def resolve():
    n,m,k=map(int, sys.stdin.readline().strip().split())
    #list(map(int,input().strip().split()))

    uf = UnionFind(n)

    res=[[] for i in range(n)]
    frd=[0 for i in range(n)]
    blk=[0 for i in range(n)]

    for i in range(m):
        #a,b=list(map(int,input().strip().split()))
        a,b=map(int, sys.stdin.readline().strip().split())
        a-=1
        b-=1
        uf.Unite(a,b)
        frd[a]+=1
        frd[b]+=1
    
    for i in range(k):
        #a,b=list(map(int,input().strip().split()))
        a,b=map(int, sys.stdin.readline().strip().split())
        a-=1
        b-=1
        if uf.isSameGroup(a,b):
            blk[a]+=1
            blk[b]+=1
    
    rescnt=[]

    for i in range(n):
        ri=uf.Count(i)-1-blk[i]-frd[i]
        rescnt.append(str(ri))
        ##rescnt.append(str(n-uf.size(i)-len(blk[i])))
    
    print(" ".join(rescnt))

resolve()

Fixed submission:
import sys
from io import StringIO
import unittest
import math

def resolve():
    n = int(input().strip())

    n = round(n/2 + 0.1)
    print(int(n))
    return

resolve()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from io import StringIO
import unittest

def resolve():
    n,k=list(map(int,input().split()))
    p = list(map(int,input().split()))

    loop=n-k+1

    ms=0

    for i in range(loop):
        tmp=0
        for j in range(k):
            tmp+=p[i+j]/2+1/2
        if tmp > ms:
            ms = tmp

    print(ms)

    return

resolve()

Fixed submission:
import sys
from io import StringIO
import unittest

def resolve():
    n,k=list(map(int,input().split()))
    p = list(map(int,input().split()))

    loop=n-k+1

    ms=0
    bef=0
    for i in range(loop):
        tmp=0
        if i ==0:
            for j in range(k):
                tmp+=p[i+j]/2+1/2
            if tmp > ms:
                ms = tmp
        else:
            tmp=bef
            tmp-=(p[i-1]/2+1/2)
            tmp+=(p[i+k-1]/2+1/2)
            if tmp > ms:
                ms = tmp
        bef=tmp

    print(ms)

    return

resolve()
Buggy python submission (verdict: Runtime Error):
import sys
from io import StringIO
import unittest
from itertools import combinations

def resolve():
    n=int(input())
    k=int(input())


    a=list(range(0, 100))
    t=0
    xx = combinations(a, 3)

    if k==3:
    for p in xx:
        if n<(10**p[0]+10**p[1]+10**p[2]):
            continue
        elif n>=(10**p[0]*9+10**p[1]*9+10**p[2]*9):
            t+=9*9*9
        else:
            for i in range(1,10):
                for j in range(1,10):
                    for k in range(1,10):
                        if n>=(10**p[0]*i+10**p[1]*j+10**p[2]*k):
                             t+=1
    else k==2:
        if n<(10**p[0]+10**p[1]):
            continue
        elif n>=(10**p[0]*9+10**p[1]*9):
            t+=9*9*9
        else:
            for i in range(1,10):
                for j in range(1,10):
                        if n>=(10**p[0]*i+10**p[1]*j):
                             t+=1
    else k==1:
        if n<(10**p[0]):
            continue
        elif n>=(10**p[0]*9):
            t+=9*9*9
        else:
            for i in range(1,10):
                for j in range(1,10):
                        if n>=(10**p[0]*i):
                             t+=1


    print(t)

    return

resolve()

Fixed submission:
import sys
from io import StringIO

def resolve():
    s=input().strip()
    k=int(input().strip())

    dp = [[[0 for a in range(2)] for b in range(5)]for c in range(105)]

    #0 same 1 under
    dp[0][0][0]=1

    keta=1
    for a in s:
        for b in range(4):
            for c in range(2): #0 same 1 under
                n=int(a)
                for d in range(10):
                    if c==0 and d > n:
                        #out
                        continue

                    b2 = b
                    if d != 0:
                        b2 += 1
                    
                    c2=c
                    if c==0 and n != d:
                        c2 = 1

                    dp[keta][b2][c2]+=dp[keta-1][b][c]
        keta+=1

    ans = dp[len(s)][k][0] + dp[len(s)][k][1]

    print(ans)

    return

resolve()
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())

if a<b:
  print(str(a)*b)
else
  print(str(b)*a)

Fixed submission:
a,b=map(int,input().split())

if a<b:
  print(str(a)*b)
else:
  print(str(b)*a)
Buggy python submission (verdict: Runtime Error):
q,b=map(int,input().split())

if a>=1 and a<=9 and b>=1 and b<=9:
  print(a*b)
else:
  print(-1)

Fixed submission:
a,b=map(int,input().split())

if a>=1 and a<=9 and b>=1 and b<=9:
  print(a*b)
else:
  print(-1)
Buggy python submission (verdict: Runtime Error):
### ----------------
### ここから
### ----------------

import sys
import math
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    n=int(readline())

    to=int(math.sqrt(n))+1
    ans=0
    for i in range(2,to+1):
        if n%i==0:
            j=n//i
            if ans>0:
                ans=min(ans,i+j-2)
            else ans=i+j-2
    print(ans)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Fixed submission:
### ----------------
### ここから
### ----------------

import sys
import math
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    n=int(readline())

    to=int(math.sqrt(n))+1
    ans=n-1
    for i in range(2,to+1):
        if n%i==0:
            j=n//i
            if ans>0:
                ans=min(ans,i+j-2)
            else:
                ans=i+j-2
    print(ans)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------
Buggy python submission (verdict: Runtime Error):
n=int(input())
bb=list(map(int,input().split()))
aa=[0]*n
for i in range(n-1):
  aa[i]=max(a[i],bb[i])
  aa[i+1]=max(a[i+1],bb[i])
print(sum(aa))

Fixed submission:
n=int(input())
bb=list(map(int,input().split()))
aa=[0]*n
aa[0]=bb[0]
for i in range(n-1):
  aa[i]=min(aa[i],bb[i])
  aa[i+1]=max(aa[i+1],bb[i])
print(sum(aa))