TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
N=int(input())
B=map(int,input().split())
sum=B[0]
for i in range(len(B)-1):
  sum+=min(B[i],B[i+1])
sum+=B[-1]
print(sum)

N=int(input())
B=list(map(int,input().split()))
sum=B[0]
for i in range(len(B)-1):
  sum+=min(B[i],B[i+1])
sum+=B[-1]
print(sum)


Verdicts: Runtime Error

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
N = int(input())
B = list(map(int,input().split()))
A = []



for i in range(len(B)):

    if i == 0:
        if len(B)==1 or B[i]<=B[i+1]:

            A.extend(B[:1]*2)

        elif B[i]>B[i+1]:

            A.extend(B[1:2]*2)

            
    if 0 < i < len(B):

        if B[i]<B[i+1]:


            A.append(B[i])

        elif B[i]>=B[i+1]:

            A.append(B[i+1])

    if i!=0 and i==len(B)-1:

        A.append(B[i])
            
        
from functools import reduce

print(reduce(lambda x,y : x+y,A))


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

mx = 0

for i in range(len(B)):

    if i==0 :

        if len(B)==1 :

            mx += B[0]*2

        else:

            if B[i] > B[i+1]:

                mx += B[i]+B[i+1]

            else:

                mx += B[i]*2

    elif i>0 :

        if i != len(B)-1:

            if B[i] < B[i+1]:

                mx += B[i]

            elif B[i] >= B[i+1]:

                mx += B[i+1]

        elif i == len(B)-1:

            mx += B[i]

print(mx)

Verdicts: Runtime Error

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
n=int(input())
b=list(map(int,input().split()))
a=[0]*(n+1)
for i in range(n+1):
  if i == 0:
    a[i] = b[i]
  elif i==n:
    a[i] = b[i-1]
  else:
    a[i] = min(b[i],b[i-1])
 
    
print(sum(a))


n=int(input())
b=list(map(int,input().split()))
a[0]*n
for i in range(i):
  if i<=n-2:
    a[i] = min(b[i],b[i+1])
  else:
    a[i] = b[i-1]
print(sum(a))

n=int(input())
b=list(map(int,input().split()))
a=[0]*(n)
for i in range(n):
  if i == 0:
    a[i] = b[i]
  elif i==n-1:
    a[i] = b[i-1]
  else:
    a[i] = min(b[i],b[i-1])
 
    
print(sum(a))


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
N = int(input())
B = list(int,map(input().split()))

res = B[0]
for i in range(1,N-1):
	res += min(B[i],B[i-1])
res += B[N-2]

print(res)

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

res = B[0]
for i in range(1,N-1):
	res += min(B[i],B[i-1])
res += B[N-2]

print(res)

Verdicts: Runtime Error

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
n=int(input())
b=list(map(int,input().split()))
a=[]
ans=0
for i in range(n-1):
    if i!=0:
        if b[i]<=b[i-1]:
            ans+=b[i]
            a+=[b[i]]
        else:
            ans+=b[i-1]
            a+=[b[i-1]]
print(ans)


n=int(input())
b=list(map(int,input().split()))
a=[]
ans=0
for i in range(n-1):
    if i!=0:
        if b[i]<=b[i-1]:
            ans+=b[i]
            a+=[b[i]]
        else:
            ans+=b[i-1]
            a+=[b[i-1]]
print(ans+b[n-2])

n=int(input())
b=list(map(int,input().split()))
a=[]
ans=0
for i in range(n-1):
    if i!=0:
        if b[i]<=b[i-1]:
            ans+=b[i]
            a+=[b[i]]
        else:
            ans+=b[i-1]
            a+=[b[i-1]]
print(ans+b[n-2])
a+=[b[n-2]]
print(a)

n=int(input())
b=list(map(int,input().split()))
a=[]
ans=0
for i in range(n-1):
    if i!=0:
        if b[i]<=b[i-1]:
            ans+=b[i]
            a+=[b[i]]
        else:
            ans+=b[i-1]
            a+=[b[i-1]]
print(b[0]+ans+b[n-2])

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
#ABC140_C
N=int(input())
A=[0]*N
B=[int(i) for i in input().split()]
A[0]=B[0]

for i in range(1,N):
    A[i]=max(A[i-1],B[i-1],B[i])
print(*A)

#ABC140_C
N=int(input())
A=[0]*N
for _ in range(N-1):
    B.append(int(input()))
A[0]=B[0]

for i in range(1,N):
    A[i]=max(A[i-1],B[i-1],B[i])
print(*A)

#ABC140_C
N=int(input())
A=[0]*N
B=[int(i) for i in input().split()]
A[0]=B[0]

for i in range(1,N-1):
    A[i]=max(A[i-1],B[i-1],B[i])
A[N-1]=B[N-2]

print(*A)

#ABC140_C
N=int(input())
A=[0]*N
B=[int(i) for i in input().split()]
A[0]=B[0]

for i in range(1,N-1):
    print(i)
    A[i]=max(A[i-1],B[i-1],B[i])
A[N-1]=B[N-2]

print(*A)

#ABC140_C
N=int(input())
A=[0]*N
B=[]
for _ in range(N-1):
    B.append(int(input()))
A[0]=B[0]

for i in range(1,N):
    A[i]=max(A[i-1],B[i-1],B[i])
print(*A)

#ABC140_C
N=int(input())
A=[0]*N
B=[int(i) for i in input().split()]
A[0]=B[0]

for i in range(1,N-1):
    A[i]=min(B[i-1],B[i])
A[N-1]=B[N-2]

print(sum(A))

Verdicts: Runtime Error

Runtime Error

Wrong Answer

Wrong Answer

Runtime Error

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
b = na()

b = [0] + b + [10**6]
ans = 0
for i in range(1,n+1):
    ans += min(b[i-1],b[i])

print(ans)

import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
b = na()

b = [10**6] + b + [10**6]
ans = 0
for i in range(1,n+1):
    ans += min(b[i-1],b[i])

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
N = int(input())
B = list(map(int, input().split()))
A = []
A.append(B[N-2])
for i in reversed(range(1, len(B))):
    if B[i]>=B[i-1]:
        A.append(B[i-1])
    else:
        A.append(B[i])

A.append(B[0])
print(A)
print(sum(A))


N = int(input())
B = list(map(int, input().split()))
A = []
A.append(B[N-2])
for i in reversed(range(1, len(B))):
    if B[i]>=B[i-1]:
        A.append(B[i-1])
    else:
        A.append(B[i])

A.append(B[0])

print(sum(A))


Verdicts: Wrong Answer

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
n=int(input())
v=list(map(int,input().split()))
vec=[]
vec.append(v[0])
for i in range(0,n-1):
  vec.append(min(v[i],v[i+1]))
vec.append(v[n-1])
sum=0
for i in range(n+1):
  sum+=vec[i]
print(sum)

n=int(input())
v=list(map(int,input().split()))
vec=[]
vec.append(v[0])
for i in range(0,n-2):
  vec.append(min(v[i],v[i+1]))
vec.append(v[n-2])
sum=0
for i in range(n):
  sum+=vec[i]
print(sum)

Verdicts: Runtime Error

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
N = int(input())
arr = list(map(int, input().split()))

ans = arr[0]+arr[N-1]
for i in range(1,N-1,1):
   ans += min(arr[i],arr[i-1])
   
print(ans)


from sys import stdin,stdout


if __name__=="__main__":

    n=int(stdin.readline())
    n-=1
    b=[int(x) for x in stdin.readline().split()]

    s=b[0]

    for i in range(n-1):
        s+=min(b[i],b[i+1])
    s+=b[n-1]

    stdout.write(str(s)+"\0")

    


from sys import stdin,stdout


if __name__=="__main__":

    n=int(stdin.readline())
    b=[int(x) for x in stdin.readline().split()]
    b.append(1000000)

    s=b[0]

    for i in range(n-1):
        if b[i]>b[i+1]:
            s+=b[i+1]
        else:
            s+=b[i]
    stdout.write(str(s)+"\n")
    


Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int a[n];
    int b[n-1]; rep(i,n-1) cin >> b[i];

    a[0] = b[0];
    a[n-1] = b[n-2];
    for (int i = 1; i<(n-1); i++) {
        a[i] = min(b[i-1],b[i]);
    }
    ll ans = 0;
    rep(i,n) ans += a[i];
    cout << ans << "\n";
}

n = int(input())
b = list(map(int,input().split()))
a = [0]*n
a[0] = b[0]
a[-1] = b[-1]
for i in range(1,n-1):
    a[i] = min(b[i-1],b[i])
print(sum(a))

Verdicts: Runtime Error

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
# -*- coding: utf-8 -*-
N = int(input())
b = list(map(int, input().split()))
sum = 0
for i in range(N-1):
    if i==0:
        sum += b[0]
    elif i==N-2:
        sum += b[N-2]
    else:
        sum += min([b[i], b[i+1]])
print(sum)


# -*- coding: utf-8 -*-
N = int(input())
b = list(map(int, input().split()))
sum = 0
for i in range(N):
    if i==0:
        sum += b[0]
    elif i==N-1:
        sum += b[N-1]
    else:
        sum += min(b[i], b[i+1])
print(sum)


# -*- coding: utf-8 -*-
N = int(input())
b = list(map(int, input().split()))
sum = 0
for i in range(N):
    if i==0:
        sum += b[0]
    elif i==N-1:
        sum += b[N-2]
    else:
        sum += min([b[i-1], b[i]])
print(sum)


Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
while True:
    try:
        num = int(input())
        lst = list(map(int, input().split()))
        point = lst[-1]
        ans = 0
        for n in lst[-1::-1]:
            point = min(point, n)
            ans += point
        ans lst[0]
        print(ans)
    except:
        break

while True:
    try:
        num = int(input())
        lst = list(map(int, input().split()))
        ans = 0
        ans += lst[-1] + lst[0]
        if num == 2:
            print(ans)
            continue
        for i in range(1, num-1):
            ans += min(lst[i], lst[i-1])
        print(ans)
    except:
        break

Verdicts: Runtime Error

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
import sys

stdin = sys.stdin.readline
na = lambda: map(int, stdin().split())
ns = lambda: stdin().rstrip()
ni = lambda: int(ns())
def main():
  n = ni()
  b = list(na()) + [0]
  
  if n == 2:
    print(b[0]*2)
  else:
    a = []
    for i in range(n-1):
      if i == n-2:
        break
      if b[i] <= b[i+1]:
        a.append(b[i])
      else:
        a.append(b[i-1])
        a.append(b[i+1])
    print(sum(a)+b[-2])
main()

import sys

stdin = sys.stdin.readline
na = lambda: map(int, stdin().split())
ns = lambda: stdin().rstrip()
ni = lambda: int(ns())
def main():
  n = ni()
  b = list(na()) + [1e9]
  a = [b[0]]
  for i in range(n-1):
    a.append(min(b[i], b[i+1]))
  print(sum(a))
main()

Verdicts: Wrong Answer

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
N = int(input())
B = [int(i) for i in input().split()]

A = [0] * N

for i in range(1, N - 1):
    A[i] = min(B[i - 1], B[i])
A[N - 1] = B[N - 2]
print(sum(A))

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

ans = B[0]

for i in range(1, N - 1):
    ans += min(B[i - 1], B[i])
ans += B[N - 2]
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
N=int(input())
B=list(map(int,input().split()))
sum=0
for i in range(N-2):
  sum+=min(B[i],B[i+1])
print(sum+B[N-2])

N=int(input())
B=list(map(int,input().split()))
sum=0
if N==2:
  sum+=B[0]*2
else:
  for i in range(N-2):
    sum+=min(B[i],B[i+1])
  sum+=B[N-2]
  sum+=B[0]
print(sum)

Verdicts: Wrong Answer

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
n = int(input())
b = map(int, input().split())
a = [b[0]]
for i in range(1, n - 1):
  a.append(min(b[i - 1], b[i]))
a.append(b[-1])
print(sum(a))

n = int(input())
b = list(map(int, input().split()))
a = [b[0]]
for i in range(1, n - 1):
  a.append(min(b[i - 1], b[i]))
a.append(b[-1])
print(sum(a))

Verdicts: Runtime Error

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
# -*- coding: utf-8 -*-

N = int(input())
B = [int(i) for i in input().split()] 

max_A =[B[0]]
B.append(B[N-2])

for i in range(N-1):
    max_A.append(min(B[i],B[i+1]))
print(max_A)

print(sum(max_A))

# -*- coding: utf-8 -*-

N = int(input())
B = [int(i) for i in input().split()] 

max_A =[B[0]]
B.append(B[N-2])

for i in range(N-1):
    max_A.append(min(B[i],B[i+1]))

print(sum(max_A))

Verdicts: Wrong Answer

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
Max=0
for i in range(N):
  if A[i]>=B[i]:
    Max+=B[i]
  else:
    B[i]-=A[i]
    if A[i+1]>=B[i]:
      A[i+1]-=B[i]
      Max+=A[i]+B[i]
    else:
      A[i+1]=0
      Max+=A[i]+A[i+1]
print(Max)    

N=int(input())
B=list(map(int,input().split()))
A=[]
A.append(B[0])
for i in range(0,N-2):
  A.append(min(B[i],B[i+1]))
A.append(B[N-2])
sum=0
for i in range(N):
  sum+=A[i]
print(sum)

Verdicts: Runtime Error

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
for i in range(n-1):
    ans[i]=a[i]
    if ans[i+1]<a[i]:
        ans[i+1]=a[i]
print(sum(ans))

n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
ans[0]=a[0]
ans[-1]=a[-1]
for i in range(1,n-1):
    ans[i]=min(a[i],a[i-1])
    
print(sum(ans))

Verdicts: Wrong Answer

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
n = int(input())
b = [int(i) for i in input().split()]

a =[b[0]]

for x in range(n-1):
  s = min(b[x],b[x+1])
  a.append(s)
  
a.append(b[-1])

print(sum(a))

n = int(input())
b = [int(i) for i in input().split()]

a =[b[0]]

for x in range(n-2):
  s = min(b[x],b[x+1])
  a.append(s)
  
a.append(b[-1])

print(sum(a))


Verdicts: Runtime Error

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
n=int(input())
a=list(map(int,input().split()))
a=a+[10**18]
ans=a[0]
for i in range(n):
  ans+=min(a[i],a[i+1])
print(ans)

n=int(input())
a=list(map(int,input().split()))
a=a+[10**18]
ans=a[0]
for i in range(n-1):
  ans+=min(a[i],a[i+1])
print(ans)


Verdicts: Runtime Error

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
N = int(input())
B = list(map(int, input().split()))

A = [0] * N

A[0] = B[0]
A[1] = B[0]

for index in range(N - 2):
    i = index + 1
    print(i)
    if A[i-1] > B[index]:
        A[i-1] = B[index]
    
    A[i + 1] = B[index + 1]

print(sum(A))

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

A = [0] * N

A[0] = B[0]
A[1] = B[0]

for index in range(N - 1):
    i = index + 1
    if A[i-1] > B[index]:
        A[i-1] = B[index]
    
    A[i] = B[index]

print(sum(A))

Verdicts: Wrong Answer

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
N = int(input())

list_B = list(map(int, input().split()))
myans = 0


for i in range(len(list_B)-1):
    myans += min(list_B[i], list_B[i+1])
    print(i, myans)
myans += list_B[-1]
        
        
if len(list_B) <= 2:
    myans += list_B[0]


    


print(myans)

N = int(input())
 
list_B = list(map(int, input().split()))
myans = list_B[0]
 
for i in range(len(list_B)-1):
    myans += min(list_B[i], list_B[i+1])

myans += list_B[-1]
 
print(myans)

Verdicts: Wrong Answer

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
N = int(input())
B = list(map(int, input().split()))
s = 0
for i in range(B):
  if i == 0:
    s += B[0]
  else:
    s += min(B[i-1], B[i])
print(s + B[N-1])

N = int(input())
B = list(map(int, input().split()))
s = 0
for i in range(N-1):
  if i == 0:
    s += B[0]
  else:
    s += min(B[i-1], B[i])
print(s + B[N-2])


Verdicts: Runtime Error

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
N = int(input())
B = list(map(int, input().split()))

S = B[0] + B[-1]

for i in range(1, N-2):
  S += min(B[i], B[i+1])

print(S)

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

S = B[0] + B[-1]

for i in range(0, N-2):
  S += min(B[i], B[i+1])

print(S)

Verdicts: Wrong Answer

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
n=int(input())
b=list(map(int,input().split()))

x=b[0]

i=1
while n-1>i:
  if b[i-1]<=b[i]:
    x+=b[i-1]
    i+=1
  else:
    x+=b[i]
    i+=1
    
print(x)

n=int(input())
b=list(map(int,input().split()))

x=b[1]

i=0
while n-1>i:
  if b[i]<=b[i+1]:
    x+=b[i]
    i+=1
  else:
    x+=b[i+1]
    i+=1
    
print(x)

n=int(input())
b=list(map(int,input().split()))

x=b[1]

i=0
while n-1>i:
  if b[i]<=b[i+1]:
    x+=b[i]
    i+=1
  else:
    x+=b[i+1]
    i+=1
    
print(x)

n=int(input())
b=list(map(int,input().split()))

x=a[1]

i=0
while n>i:
  if b[i]<=b[i+1]:
    x+=b[i]
    i+=1
  else:
    x+=b[i+1]
    i+=1
    
print(x)

  

n=int(input())
b=list(map(int,input().split()))

x=b[0]+b[n-2]

i=1
while n-1>i:
  if b[i-1]<=b[i]:
    x+=b[i-1]
    i+=1
  else:
    x+=b[i]
    i+=1
    
print(x)

Verdicts: Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
n=int(input())
b=list(map(int,input().split()))
k=b[n-2]
for i in range(1,n-2):
    if b[n-i-2]<b[n-i-1]:
        k+=b[n-i-2]
    else:
        k+=b[n-i-1]
if b[0]<b[1]:
    k+=b[0]
else:
    k+=b[1]
print(k)
        

n=int(input())
b=list(map(int,input().split()))
k=b[n-2]
if n>2:
    for i in range(0,n-2):
        if b[n-i-3]<b[n-i-2]:
            k+=b[n-i-3]
        else:
            k+=b[n-i-2]
k+=b[0]
print(k)

Verdicts: Runtime Error

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
n=int(input())
b=list(map(int,input().split()))
a=b
a.insert(0,b[0])
for i in range(n-1):
    if b[i]>b[i+1]:
        a[i]=b[i+1]
print(a)
print(sum(a))

n=int(input())
b=list(map(int,input().split()))
a=b
a.insert(0,b[0])
for i in range(n-1):
    if b[i]>b[i+1]:
        a[i]=b[i+1]
print(sum(a))

Verdicts: Wrong Answer

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
n = int(input())
b = list(map(int,input().split()))
ans = 0
aa = 0
ab = 0
for i in range(n-1):
    aa = min(ab,b[i])
    ab = b[i]
    ans += aa
print(ans+ab)

n = int(input())
b = list(map(int,input().split()))
ans = 0
aa = 0
ab = 100001
for i in range(n-1):
    aa = min(ab,b[i])
    ab = b[i]
    ans += aa
print(ans+ab)

Verdicts: Wrong Answer

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
N = int(input())
B = [int(i) for i in input().split()]

res = 0
for i in range(N-1):
  res += min(B[i], B[i+1])
res += B[-1]

print(res)


N = int(input())
B = [int(i) for i in input().split()]

res = 0
for i in range(N-2):
  res += min(B[i], B[i+1])
res += B[-1]

print(res)


N = int(input())
B = [int(i) for i in input().split()]

res = B[0]
for i in range(N-2):
  res += min(B[i], B[i+1])
res += B[-1]

print(res)


Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
hoge = input()
nums = list(map(int, input().split(' ')))[::-1]
current = nums[0]
ans = 0
for n in nums:
    current = min(current, n)
    ans += current
    current = n  # !
print(ans)


hoge = input()
nums = list(map(int, input().split(' ')))[::-1]
current = nums[0]
ans = 0
for n in nums:
    current = min(current, n)
    ans += current
print(ans)


hoge = input()
nums = list(map(int, input().split(' ')))[::-1]
current = nums[0]
ans = 0
for n in nums:
    current = min(current, n)
    ans += current
    current = n  # !
print(ans + current)  # !!


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
#coding: utf-8
import math
import heapq
import bisect

MOD = 10**9+7

N = int(input())


B = list(map(int, input().split()))

ans=B[0]+B[N-2]
for i in range(N-1):
    ans+=max(B[i],B[i+1])

print(ans)

#coding: utf-8
import math
import heapq
import bisect

MOD = 10**9+7

N = int(input())


B = list(map(int, input().split()))

ans=B[0]+B[N-2]
for i in range(N-2):
    ans+=min(B[i],B[i+1])

print(ans)

Verdicts: Runtime Error

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
n=int(input())
b=list(map(int,input().split()))
a=[b[0],b[n-2]]
for i in range(n-3):
  a.append(min(b[i],b[i+1]))
print(sum(a))

n=int(input())
b=list(map(int,input().split()))
a=[b[0],b[n-2]]
for i in range(n-1):
  a.append(min(a[i+1],a[i+2]))
print(sum(a))


n=int(input())
b=list(map(int,input().split()))
a=[b[0],b[n-2]]
for i in range(n-2):
  a.append(min(b[i],b[i+1]))
print(sum(a))

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
n = int(input())
b = list(map(int,input().split()))
print(b)

s = b[-1] + b[0]
for i in range(1,n-1):
  a = min([b[-i],b[-i-1]])
  s += a
print(s)

n = int(input())
b = list(map(int,input().split()))
s = b[-1] + b[0]
for i in range(1,n-1):
  s += min([b[-i],b[-i-1]])
print(s)

Verdicts: Wrong Answer

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
#input
N = int(input())
B = list(map(int, input().split()))

A = []
a = 99999
for b in reversed(B):
    if b < a:
        A.insert(0, b)
        a = b
    else:
        A.insert(0, a)
A.insert(0, A[0])

sum = 0
for a in A:
    sum += 0

print(sum)

#input
N = int(input())
B = list(map(int, input().split()))

A = [0] * N
for i in range(1, N-1):
    if A[i] > B[i]:
        A[i] = B[i]
    A[i+1] = B[i]
A.insert(0, A[0])

print(sum(A))

#input
N = int(input())
B = list(map(int, input().split()))

A = [0] * N
for i in range(1, N-1):
    if A[i] > B[i]:
        A[i] = B[i]
    A[i+1] = B[i]

print(sum(A))

#input
N = int(input())
B = list(map(int, input().split()))

A = [0] * N
A[0] = B[0]
for i in range(0, N-1):
    if A[i] > B[i]:
        A[i] = B[i]
    A[i+1] = B[i]
    
print(sum(A))

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
n=int(input())

l1=list(map(int,input().split()))
l2=[l1[0]]
l=l2+l1
l.append(l1[-1])
print(l)

res=[]

for i in range(1,n+1):
    res.append(min(l[i],l[i-1]))

print(sum(res))
   

n=int(input())

l1=list(map(int,input().split()))
l2=[l1[0]]
l=l2+l1
l.append(l1[-1])

res=[]

for i in range(1,n+1):
    res.append(min(l[i],l[i-1]))

print(sum(res))
    


Verdicts: Wrong Answer

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
N = int(input())
B =list(map(int,input().split()))
sumN=B[0]
last = 5
for x in range(1,N-2,1):
    sumN += min(B[x],B[x+1])
sumN +=B[-1]
        

N = int(input())
B =list(map(int,input().split()))
sumN=B[0]
last = 5
for x in range(1,N-2,1):
    sumN += min(B[x],B[x+1])
sumN +=B[-1]
print(sumN)  

N = int(input())
B =list(map(int,input().split()))
sumN=B[0]
last = 5
for x in range(0,N-2,1):
    sumN += min(B[x],B[x+1])
sumN +=B[-1]
print(sumN)      

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
def solve():
  n = int(input())
  b = list(int(i) for i in input().split())
  ans = 0
  
  if n == 2:
    ans = b[0]*2
  else:
    for i in range(n-2):
      if b[i] > b[i+1]:
        b[i] = b[i+1]
    
    first = b[0]
    for i in range(n-2):
      nextvalue = b[i+1]
      ans += max(first,nextvalue)
      first = nextvalue
  print(ans)
solve()

def solve():
  n = int(input())
  b = list(int(i) for i in input().split())
  ans = 0
  
  if n == 2:
    ans = b[0]*2
  else:
    ans = b[0]
    ans += b[-1]
    first = b[0]
    for i in range(n-2):
      nextvalue = b[i+1]
      ans += min(first,nextvalue)
      first = nextvalue
  print(ans)
solve()

Verdicts: Wrong Answer

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
N=int(input())
B_list=list(map(int,input().split()))

ans=0
if N==2:
    print(B_list[0]*2)
else:
    for i in range(N-3):
        ans+=min(B_list[i],B_list[i+1])
    ans+=B_list[N-2]
    ans+=B_list[N-3]
    print(ans)

N=int(input())
n=N-1
B_list=list(map(int,input().split()))

ans=0
if N==2:
    print(B_list[0]*2)
else:
    ans+=B_list[0]
    for i in range(n-1):
        ans+=min(B_list[i],B_list[i+1])
    ans+=B_list[n-1]
    print(ans)

Verdicts: Wrong Answer

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
n = int(input())
b = list(map(int, input().split()))
ans = 0
a = [0]*n
a[0]=b[0]
for i in range(1,n-1):
  a[i] = min(b[i],b[i-1])
a[n-1]=b[n-2]
ans=sum(a) 
print(ans,a)

n = int(input())
b = list(map(int,input().split()))
ans=sum(b)+b[0]

n = int(input())
b = list(map(int, input().split()))
ans = 0
a = [0]*n
a[0]=b[0]
for i in range(1,n-1):
  a[i] = min(b[i],b[i-1])
a[n-1]=b[n-2]
ans=sum(a) 
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
# C - Maximal Value
n = (int)(input())
b = list(map(int, input().split()))

a = [0] * n

for i in reversed(range(0, n)):
    print(i)
    if i == n - 1 : a[i] = b[n-2]
    else: a[i] = min(b[i-1], a[i+1])

print(sum(a))

# C - Maximal Value
n = (int)(input())
b = list(map(int, input().split()))

a = [0] * n

for i in reversed(range(0, n)):
    print(i)
    if i == n - 1 : a[i] = b[n-2]
    elif i == 0 : a[i] = b[0]
    else: a[i] = min(b[i-1], a[i+1])

print(sum(a))

# C - Maximal Value
n = (int)(input())
b = list(map(int, input().split()))

a = [0] * n

for i in reversed(range(0, n)):
    if i == n - 1: a[i] = b[i-1]
    elif i == 0: a[i] = b[0]
    else: a[i] = min(b[i], b[i-1])

print(sum(a))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
N=int(input())
B=list(map(int,input.split()))
A=[0]*N

A[0]=B[0]
A[N-1]=B[N-2]

for i in range (1,N-1):
  A[i]=min(B[i-1],B[i])
print(sum(A))

import numpy as np
N=int(input())
B=list(map(int,input.split()))
A=np.zeros(N,dtype="int64")

A[0]=B[0]
A[N-1]=B[N-2]

for i in range (1,N-1):
  A[i]=min(B[i-1],B[i])
print(sum(A))


import numpy as np
N=int(input())
B=list(map(int,input().split()))
A=np.zeros(N,dtype="int64")

A[0]=B[0]
A[N-1]=B[N-2]

for i in range (1,N-1):
  A[i]=min(B[i-1],B[i])
print(sum(A))


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
N = int(input())
B = list(map(int, input().split()))

A = [0] * N


for i in range(N-1):
  A[i] = min(B[i-1],B[i])

A[0] = B[0]
A[N-1] = B[N-2]

print(A)

print(sum(A))

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

A = [0] * N
B.append(0)


for i in range(N-1):
  A[i] = min(B[i-1],B[i])
  
A[N-1] = B[N-2]

print(sum(A))

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

A = [0] * N


for i in range(N-1):
  A[i] = min(B[i-1],B[i])

A[0] = min(B[0],B[1])
A[N-1] = B[N-2]

print(A)

print(sum(A))

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

inf = 10 ** 9
B = B + [inf]
A = [0] * N


for i in range(1,N):
  A[i] = min(B[i],B[i-1])
  
print(sum(A) + B[0])

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
n=int(input())
B=map(list(int,input().split()))
c=A[0]+A[-1]
if n>=3:
	for i in range(n-2):
      c+=min(B[i],B[i+1])
print(c)

n=int(input())
B=list(map(int,input().split()))
c=B[0]+B[-1]
if n>=3:
    for i in range(n-2):
        c+=min(B[i],B[i+1])
print(c)

Verdicts: Runtime Error

Accepted
Problem: There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A.

Submission attempts (in order):
N = int(input())
B = list(map(int,input().split()))

ans = B[-1]
pre = B[-1]
for i in reversed(range(0,N-2)):
  now = B[i]
  if now <= pre:
    ans += now
  else:
    ans += pre  
  pre = now
print(ans)

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

ans = B[-1]
pre = B[-1]
for i in reversed(range(0,N-2)):
  
  now = B[i]
  if now <= pre:
    ans += now
  else:
    ans += pre
  pre = now
print(ans+B[0])

Verdicts: Wrong Answer

Accepted
Problem: There are N people standing in a queue from west to east.  Given is a string S of length N representing the directions of the people. The i-th person from the west is facing west if the i-th character of S is `L`, and east if that character of S is `R`.  A person is happy if the person in front of him/her is facing the same direction. If no person is standing in front of a person, however, he/she is not happy.  You can perform the following operation any number of times between 0 and K (inclusive):  Operation: Choose integers l and r such that 1 \leq l \leq r \leq N, and rotate by 180 degrees the part of the queue: the l-th, (l+1)-th, ..., r-th persons. That is, for each i = 0, 1, ..., r-l, the (l + i)-th person from the west will stand the (r - i)-th from the west after the operation, facing east if he/she is facing west now, and vice versa.  What is the maximum possible number of happy people you can have?

Submission attempts (in order):
N,K=map(int,input().split())
S=input()

cnt = 0
bef = "M"
for i in range(0,len(S)):
    if i == len(S) - 1 and S[i] == "R":
        cnt = cnt
    elif S[i-1] == "L" and S[i] == "L":
        cnt += 1
    elif S[i] == "R" and S[i+1] == "R":
        cnt += 1
        
    bef = S[i]
    i += 1
print(min(cnt + 2 * K, N - 1))

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

cnt = 0
for i in range(0,len(S)):
    if i == len(S) - 1 and S[i] == "R":
        cnt = cnt
    elif i > 0 and  S[i-1] == "L" and S[i] == "L":
        cnt += 1
    elif S[i] == "R" and S[i+1] == "R":
        cnt += 1
    i += 1
print(min(cnt + 2 * K, N - 1))

Verdicts: Wrong Answer

Accepted
Problem: There are N people standing in a queue from west to east.  Given is a string S of length N representing the directions of the people. The i-th person from the west is facing west if the i-th character of S is `L`, and east if that character of S is `R`.  A person is happy if the person in front of him/her is facing the same direction. If no person is standing in front of a person, however, he/she is not happy.  You can perform the following operation any number of times between 0 and K (inclusive):  Operation: Choose integers l and r such that 1 \leq l \leq r \leq N, and rotate by 180 degrees the part of the queue: the l-th, (l+1)-th, ..., r-th persons. That is, for each i = 0, 1, ..., r-l, the (l + i)-th person from the west will stand the (r - i)-th from the west after the operation, facing east if he/she is facing west now, and vice versa.  What is the maximum possible number of happy people you can have?

Submission attempts (in order):
import sys
n,k=map(int,input().split())
s=input()
snum=[]
now_si=""
now_sinum=0
for i in range(len(s)):
    if(now_si!=s[i]):
        now_si=s[i]
        snum.append(now_sinum)
        now_sinum=1
    else:
        now_sinum+=1
else:
    snum.append(now_sinum)
snum.pop(0)

if(len(snum)<3):
    print(sum(snum)-1)
    sys.exit()

for i in range(k):
    print(snum)
    if(len(snum)<3):
        snum=[sum(snum)]
        break

    snum[-3]+=snum[-2]+snum[-1]
    snum.pop(-1)
    snum.pop(-1)

print(sum(snum)-len(snum))

import sys
n,k=map(int,input().split())
s=input()
snum=[]
now_si=""
now_sinum=0
for i in range(len(s)):
    if(now_si!=s[i]):
        now_si=s[i]
        snum.append(now_sinum)
        now_sinum=1
    else:
        now_sinum+=1
else:
    snum.append(now_sinum)
snum.pop(0)

if(len(snum)<3):
    print(sum(snum)-1)
    sys.exit()

for i in range(k):
#    print(snum)
    if(len(snum)<3):
        snum=[sum(snum)]
        break

    snum[-3]+=snum[-2]+snum[-1]
    snum.pop(-1)
    snum.pop(-1)

print(sum(snum)-len(snum))

Verdicts: Wrong Answer

Accepted
Problem: There are N people standing in a queue from west to east.  Given is a string S of length N representing the directions of the people. The i-th person from the west is facing west if the i-th character of S is `L`, and east if that character of S is `R`.  A person is happy if the person in front of him/her is facing the same direction. If no person is standing in front of a person, however, he/she is not happy.  You can perform the following operation any number of times between 0 and K (inclusive):  Operation: Choose integers l and r such that 1 \leq l \leq r \leq N, and rotate by 180 degrees the part of the queue: the l-th, (l+1)-th, ..., r-th persons. That is, for each i = 0, 1, ..., r-l, the (l + i)-th person from the west will stand the (r - i)-th from the west after the operation, facing east if he/she is facing west now, and vice versa.  What is the maximum possible number of happy people you can have?

Submission attempts (in order):
n,k=map(int,input().split())
s=list(input())
ct=0
for i in range(n-1):
  if s[i]=='R' and s[i+1]=='L':
    ct+=1
if s[0]==s[n-1]:
  x=ct
  ct-=min(ct,k)
  ct*=2
  ct+=1
  print(n-ct)
elif s[0]=='L':
  x=ct
  ct-=min(ct,k)
  ct*=2
  if x<k:
    ct-=1
  print(n-ct)
else:
  x=ct
  ct-=min(ct,k)
  ct*=2
  if x<=k
    ct+=1
  print(n-ct)

n,k=map(int,input().split())
s=list(input())
ct=0
for i in range(n-1):
  if s[i]=='R' and s[i+1]=='L':
    ct+=2
if s[0]=='L':ct+=1
if s[-1]=='R':ct+=1
ans=n-ct
print(min(ans+2*k,n-1))

Verdicts: Runtime Error

Accepted
Problem: There are N people standing in a queue from west to east.  Given is a string S of length N representing the directions of the people. The i-th person from the west is facing west if the i-th character of S is `L`, and east if that character of S is `R`.  A person is happy if the person in front of him/her is facing the same direction. If no person is standing in front of a person, however, he/she is not happy.  You can perform the following operation any number of times between 0 and K (inclusive):  Operation: Choose integers l and r such that 1 \leq l \leq r \leq N, and rotate by 180 degrees the part of the queue: the l-th, (l+1)-th, ..., r-th persons. That is, for each i = 0, 1, ..., r-l, the (l + i)-th person from the west will stand the (r - i)-th from the west after the operation, facing east if he/she is facing west now, and vice versa.  What is the maximum possible number of happy people you can have?

Submission attempts (in order):
import heapq
import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    N, K = map(int, input().split())
    S = input()
    # groups = []
    # length = 0
    ans = 0
    group = 1
    src = S[0]
    for dst in S[1:]:
        if dst == src:
            ans += 1
        else:
            group += 1
        src = dst
    if group % 2:
        ans += 2 * max(K, group // 2)
    else:
        tmp = group // 2 -1
        if K <= tmp:
            ans += 2 * K
        else:
            ans += 2 * tmp + 1
    print(ans)

if __name__ == "__main__":
    main()

import heapq
import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    N, K = map(int, input().split())
    S = input()
    score = 0
    for i in range(N-1):
        if S[i] == S[i+1]:
            score += 1
    ans = min(score + 2*K, N-1)
    print(ans)

if __name__ == "__main__":
    main()

Verdicts: Wrong Answer

Accepted
Problem: There are N people standing in a queue from west to east.  Given is a string S of length N representing the directions of the people. The i-th person from the west is facing west if the i-th character of S is `L`, and east if that character of S is `R`.  A person is happy if the person in front of him/her is facing the same direction. If no person is standing in front of a person, however, he/she is not happy.  You can perform the following operation any number of times between 0 and K (inclusive):  Operation: Choose integers l and r such that 1 \leq l \leq r \leq N, and rotate by 180 degrees the part of the queue: the l-th, (l+1)-th, ..., r-th persons. That is, for each i = 0, 1, ..., r-l, the (l + i)-th person from the west will stand the (r - i)-th from the west after the operation, facing east if he/she is facing west now, and vice versa.  What is the maximum possible number of happy people you can have?

Submission attempts (in order):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
#from math import floor, ceil
#from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
#inf = 10**17
#mod = 10**9 + 7

n,k=MI()
s=input()
print(s)
l=0
r=0
if s[0]=="L":
    l=1
if s[-1]=="R":
    r=1
state=""
count=0
for i in range(n):
    u=s[i:i+1]
    #print(state)
    #print(u)
    if state=="":
        if u=="R":
            state="R"
    elif state=="R":
        if u=="L":
            state=""
            count+=1
        else:
            state="R"
#print(count)
#print(l+r)
unhappy=2*count+l+r
if l+r==0:
    if k>=count:
        unhappy=1
    elif k==count-1:
        unhappy=2
    else:
        unhappy-=2*(k-1)
elif l+r==1:
    if k>=count:
        unhappy=1
    else:
        unhappy-=2*k
elif l+r==2:
    if k>=count+1:
        unhappy=1
    elif k==count:
        unhappy=2
    else:
        unhappy-=2*k

print(n-unhappy)

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
#from math import floor, ceil
#from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
#inf = 10**17
#mod = 10**9 + 7

n,k=MI()
s=input()
#print(s)
ans=0
for i in range(n-1):
    u=s[i:i+1]
    v=s[i+1:i+2]
    if u==v:
        ans+=1
print(min(n-1,ans+2*k))

Verdicts: Wrong Answer

Accepted