TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: A sequence a=\\{a_1,a_2,a_3,......\\} is determined as follows:    * The first term s is given as input.    * Let f(n) be the following function: f(n) = n/2 if n is even, and f(n) = 3n+1 if n is odd.    * a_i = s when i = 1, and a_i = f(a_{i-1}) when i > 1.  Find the minimum integer m that satisfies the following condition:    * There exists an integer n such that a_m = a_n (m > n).

Submission attempts (in order):
s=int(input())
nums=[]
nums.append(s)
i=2
while(1):
  if i%2==0:
    new=int(i/2)
    if new in nums:
      print(i)
      break
    nums.append(new)
  else:
    new=3*i+1
    if new in nums:
      print(i)
      break
    nums.append(new)
  i+=1
  

s=int(input())
nums=[]
nums.append(s)
i=2
while(1):
  if nums[i-2]%2==0:
    new=int(nums[i-2]/2)
    if new in nums:
      print(i)
      break
    nums.append(new)
  else:
    new=3*nums[i-2]+1
    if new in nums:
      print(i)
      break
    nums.append(new)
  i+=1

Verdicts: Wrong Answer

Accepted
Problem: A sequence a=\\{a_1,a_2,a_3,......\\} is determined as follows:    * The first term s is given as input.    * Let f(n) be the following function: f(n) = n/2 if n is even, and f(n) = 3n+1 if n is odd.    * a_i = s when i = 1, and a_i = f(a_{i-1}) when i > 1.  Find the minimum integer m that satisfies the following condition:    * There exists an integer n such that a_m = a_n (m > n).

Submission attempts (in order):
S = int(input())
l = []
while (S not in l):
  l.append(S)
  if S%2 == 0:
    S //= 2
  else:
    S = 3*S+1
print(len(S)+1)

S = int(input())
l = []
while (S not in l):
  l.append(S)
  if S%2 == 0:
    S //= 2
  else:
    S = 3*S+1
print(len(l)+1)

Verdicts: Runtime Error

Accepted
Problem: A sequence a=\\{a_1,a_2,a_3,......\\} is determined as follows:    * The first term s is given as input.    * Let f(n) be the following function: f(n) = n/2 if n is even, and f(n) = 3n+1 if n is odd.    * a_i = s when i = 1, and a_i = f(a_{i-1}) when i > 1.  Find the minimum integer m that satisfies the following condition:    * There exists an integer n such that a_m = a_n (m > n).

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

if s==4 or s==2 or s==1:
    print(4)
    
l=[]
else:
    for i in range(10**6+1):
        l.append(s)
        if l.count(4)>2:
            break
        elif s%2==0:
            s=s//2
        else:
            s=3*s+1
    x=l.index(4)

    l=l[x+1:]
    y=l.index(4)

    print(y+x+2)

s=int(input())

if s==4 or s==2 or s==1:
    print(4)
    

else:
    l=[]
    for i in range(10**6+1):
        l.append(s)
        if l.count(4)>2:
            break
        elif s%2==0:
            s=s//2
        else:
            s=3*s+1
    x=l.index(4)

    l=l[x+1:]
    y=l.index(4)

    print(y+x+2)

Verdicts: Runtime Error

Accepted
Problem: A sequence a=\\{a_1,a_2,a_3,......\\} is determined as follows:    * The first term s is given as input.    * Let f(n) be the following function: f(n) = n/2 if n is even, and f(n) = 3n+1 if n is odd.    * a_i = s when i = 1, and a_i = f(a_{i-1}) when i > 1.  Find the minimum integer m that satisfies the following condition:    * There exists an integer n such that a_m = a_n (m > n).

Submission attempts (in order):
a=[]
a.append(s)

while 1:
    if s%2==0:
        s=s/2
        a.append(s)
    else:
        s=3*s+1
        a.append(s)
    if len(a)!=len(set(a)):
        print(len(a))
        exit()

s=int(input())
a=[]
a.append(s)

while 1:
    if s%2==0:
        s=s/2
        a.append(s)
    else:
        s=3*s+1
        a.append(s)
    if len(a)!=len(set(a)):
        print(len(a))
        exit()

Verdicts: Runtime Error

Accepted
Problem: A sequence a=\\{a_1,a_2,a_3,......\\} is determined as follows:    * The first term s is given as input.    * Let f(n) be the following function: f(n) = n/2 if n is even, and f(n) = 3n+1 if n is odd.    * a_i = s when i = 1, and a_i = f(a_{i-1}) when i > 1.  Find the minimum integer m that satisfies the following condition:    * There exists an integer n such that a_m = a_n (m > n).

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

log = set()
set.add(s)
for i in range(1001000):
    if s%2==0:
        s //=2
    else:
        s = 3*s+1

    if s in log:
        print(i+2)
        break

    log.add(s)

s = int(input())

log = set()
log.add(s)
for i in range(1001000):
    if s%2==0:
        s //=2
    else:
        s = 3*s+1

    if s in log:
        print(i+2)
        break

    log.add(s)

Verdicts: Runtime Error

Accepted
Problem: A sequence a=\\{a_1,a_2,a_3,......\\} is determined as follows:    * The first term s is given as input.    * Let f(n) be the following function: f(n) = n/2 if n is even, and f(n) = 3n+1 if n is odd.    * a_i = s when i = 1, and a_i = f(a_{i-1}) when i > 1.  Find the minimum integer m that satisfies the following condition:    * There exists an integer n such that a_m = a_n (m > n).

Submission attempts (in order):
s = int(input())
l = []

while(s not in l):
  l.aplend(s)
  
  if s%2 == 0:
    s//=2
  else:
    s=3*s+1
print(len(l)=1)

s = int(input())
l = []

while(s not in l):
  l.append(s)
  
  if s%2 == 0:
    s//=2
  else:
    s=3*s+1
print(len(l)+1)

Verdicts: Runtime Error

Accepted
Problem: A sequence a=\\{a_1,a_2,a_3,......\\} is determined as follows:    * The first term s is given as input.    * Let f(n) be the following function: f(n) = n/2 if n is even, and f(n) = 3n+1 if n is odd.    * a_i = s when i = 1, and a_i = f(a_{i-1}) when i > 1.  Find the minimum integer m that satisfies the following condition:    * There exists an integer n such that a_m = a_n (m > n).

Submission attempts (in order):
# ABC116

s = int(input())
S = [str(s)]
i = 1
while True:
    if s % 2 == 0:
        i += 1
        s = s//2
        S.append(str(s))
        if S.count(str(s)) == 2:
            print(i)
            print(S)
            exit()
    else:
        i += 1
        s = 3 * s + 1
        S.append(str(s))
        if S.count(str(s)) == 2:
            print(i)
            print(S)
            exit()
pass


s = int(input())
S = [str(s)]
i = 1
while True:
    if s % 2 == 0:
        i += 1
        s = s//2
        S.append(str(s))
        if S.count(str(s)) == 2:
            print(i)
            exit()
    else:
        i += 1
        s = int(3 * s + 1)
        S.append(str(s))
        if S.count(str(s)) == 2:
            print(i)
            exit()
pass


Verdicts: Wrong Answer

Accepted
Problem: A sequence a=\\{a_1,a_2,a_3,......\\} is determined as follows:    * The first term s is given as input.    * Let f(n) be the following function: f(n) = n/2 if n is even, and f(n) = 3n+1 if n is odd.    * a_i = s when i = 1, and a_i = f(a_{i-1}) when i > 1.  Find the minimum integer m that satisfies the following condition:    * There exists an integer n such that a_m = a_n (m > n).

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

INF = 10 ** 9 

list = [S]

con = 0

for i in range(INF):
	if S % 2 == 0:
		S = int(S / 2)
		list.append(S)
		con += 1

	else:
		S = (3 * S) + 1
		list.append(S)
		con += 1


	if S in list[:i]:
		break



print(con)

S = int(input())

INF = 10 ** 9 

list = [S]

con = 0

for i in range(INF):
	if S % 2 == 0:
		S = int(S / 2)
		list.append(S)
		con += 1
		print(S)
	else:
		S = (3 * S) + 1
		list.append(S)
		con += 1
		print(S)
	print(list)
	if S in list[:i]:
		break



print(con)

S = int(input())

INF = 10 ** 9 

list = [S]

con = 0

for i in range(INF):
	if S % 2 == 0:
		S = int(S / 2)
		list.append(S)
		con += 1
		print(S)
	else:
		S = (3 * S) + 1
		list.append(S)
		con += 1
		print(S)
	print(list)
	if S in list[:i]:
		break



print(con + 1)

S = int(input())

INF = 10 ** 9 

list = [S]

con = 0

for i in range(INF):
	if S % 2 == 0:
		S = int(S / 2)
		list.append(S)
		con += 1

	else:
		S = (3 * S) + 1
		list.append(S)
		con += 1

	if S in list[:i]:
		break



print(con + 1)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: A sequence a=\\{a_1,a_2,a_3,......\\} is determined as follows:    * The first term s is given as input.    * Let f(n) be the following function: f(n) = n/2 if n is even, and f(n) = 3n+1 if n is odd.    * a_i = s when i = 1, and a_i = f(a_{i-1}) when i > 1.  Find the minimum integer m that satisfies the following condition:    * There exists an integer n such that a_m = a_n (m > n).

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

def collatz(n):
    if n%2==0:
        n=n/2
    else: 
        n=3*n+1
    return int(n)

l=[s]
while s!=1:
    s=collatz(s)
    l.append(s)

if s==1:
    print(4)
elif s==2:
    print(4)
else:
    print(len(l)+1)

s=int(input())

def collatz(n):
    if n%2==0:
        n=n/2
    else: 
        n=3*n+1
    return int(n)

l=[s]
while s!=1:
    s=collatz(s)
    l.append(s)

if l[0]==1:
    print(4)
elif l[0]==2:
    print(4)
else:
    print(len(l)+1)

Verdicts: Wrong Answer

Accepted
Problem: A sequence a=\\{a_1,a_2,a_3,......\\} is determined as follows:    * The first term s is given as input.    * Let f(n) be the following function: f(n) = n/2 if n is even, and f(n) = 3n+1 if n is odd.    * a_i = s when i = 1, and a_i = f(a_{i-1}) when i > 1.  Find the minimum integer m that satisfies the following condition:    * There exists an integer n such that a_m = a_n (m > n).

Submission attempts (in order):
def resolve():
    N = int(input())
    ans = 1
    for i in range(1000000):
        if N == 1 or N == 2 or N == 4:
            break
        elif N % 2 == 0 :
            N = N//2
            ans = ans + 1
        else:
            N = 3*N+1
            ans = ans+1 
    print(ans + 3)

def resolve():
    N = int(input())
    ans = 1
    for i in range(1000000):
        if N == 1 or N == 2 or N == 4:
            break
        elif N % 2 == 0 :
            N = N//2
            ans = ans + 1
        else:
            N = 3*N+1
            ans = ans+1 
    print(ans + 3)
resolve()

Verdicts: Wrong Answer

Accepted
Problem: In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation:    * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.  Find the minimum number of watering operations required to satisfy the condition.

Submission attempts (in order):
N = int(input())
h = [0] + list(map(int, input().split()))

for i in range(1, N):
    h[i] = max(0, h[i] - h[i - 1])

print(sum(h))


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

for i in range(N - 1, 0, -1):
    h[i] = max(0, h[i] - h[i - 1])

print(sum(h))


Verdicts: Wrong Answer

Accepted
Problem: In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation:    * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.  Find the minimum number of watering operations required to satisfy the condition.

Submission attempts (in order):
n=int(input())
h=list(map(int,input().split()))
count=0
while h.count(0)!=len(h):
  stack=[]
  substack=[]
  for i in range(len(h)):
    if h[i]!=0:
      substack.append(i)
    else:
      substack.append(i)
      stack.append(substack)
      substack=[]
  h=[]
  for i in range(len(stack)):
    count+=min(i)
    h+=i
print(count)

n=int(input())
h=list(map(int,input().split()))
count=0
while h.count(0)!=len(h):
  stack=[]
  substack=[]
  for i in range(len(h)):
    if h[i]!=0:
      substack.append(h[i])
    else:
      if len(substack)>0:
        stack.append(substack)
      stack.append([0])
      substack=[]
  if len(substack)>0:
    stack.append(substack)
  h=[]
  for i in range(len(stack)):
    if max(stack[i])==0:
      h+=stack[i]
      continue
    x=min(stack[i])
    count+=x
    for j in range(len(stack[i])):
      stack[i][j]-=x
    h+=stack[i]
print(count)

Verdicts: Runtime Error

Accepted
Problem: In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation:    * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.  Find the minimum number of watering operations required to satisfy the condition.

Submission attempts (in order):
n=int(input())
h=list(map(int,input().split()))
d=[]
a=[]
x=0
for i in range(1,n-1):
  if h[i-1]>h[i]<h[i+1]:
    a.append(h[i])
    x=1
for i in range(1,n-1):
  if h[i-1]<h[i]>h[i+1]:
    d.append(h[i])
    x=1
if x==0:
  print(h[0])
else:
  if n>=2 and h[0]>=h[1]:
    d.append(h[0])
  if n>=2 and h[-1]>=h[-2]:
    d.append(h[-1])
  print(sum(d)-sum(a))

n=int(input())
h=list(map(int,input().split()))
d=[]
a=[]
for i in range(1,n-1):
  if h[i-1]>h[i]<h[i+1]:
    a.append(h[i])
for i in range(1,n-1):
  if h[i-1]<=h[i]>=h[i+1]:
    d.append(h[i])
    
if n>=2 and h[0]>=h[1]:
  d.append(h[0])
if n>=2 and h[-1]>=h[-2]:
  d.append(h[-1])
print(sum(d)-sum(a))

n=int(input())
h=list(map(int,input().split()))
d=[]
a=[]
x=0
k=0
while k<len(h)-1:
  if h[k]==h[k+1]:
    h.pop(k)
    k-=1
  k+=1

for i in range(1,len(h)-1):
  if h[i-1]>h[i]<h[i+1]:
    a.append(h[i])
    x=1
for i in range(1,len(h)-1):
  if h[i-1]<h[i]>h[i+1]:
    d.append(h[i])
    x=1
               
if len(h) >= 2:
  if h[0]>=h[1]:
    d.append(h[0])
  if h[-1]>=h[-2]:
    d.append(h[-1])
  print(sum(d)-sum(a))
else:
  print(h[0])

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation:    * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.  Find the minimum number of watering operations required to satisfy the condition.

Submission attempts (in order):
def main():
    N = int(input())
    height = list(map(int, input().split(" ")))
    target = [0] * N
    result = 0
    print(target)
    while not height == target:
        print(height)
        end = False
        result += 1
        for i in range(N):
            if not end:
                if height[i] > 0:
                    end = True
                    height[i] -= 1
            else:
                if height[i] > 0:
                    height[i] -= 1
                else:
                    break
    print(result)


if __name__ == '__main__':
    main()


def main():
    N = int(input())
    height = list(map(int, input().split(" ")))
    result = 0
    tmp = 0
    end = False
    while not end:
        print(height, result)
        for i in range(N):
            if i == 0:
                tmp = height[0]
            if max(height) <= 0:
                # print("hi: " + str(height))
                end = True
                break
            if height[i] <= 0:
                if tmp >= 0:
                    result += 1
            else:
                height[i] -= 1
                if i == N - 1:
                    result += 1
            tmp = height[i]

    print(result)


if __name__ == '__main__':
    main()


def main():
    N = int(input())
    height = list(map(int, input().split(" ")))
    target = [0] * N
    result = 0
    # print(target)
    while not height == target:
        # print(height)
        end = False
        result += 1
        for i in range(N):
            if not end:
                if height[i] > 0:
                    end = True
                    height[i] -= 1
            else:
                if height[i] > 0:
                    height[i] -= 1
                else:
                    break
    print(result)


if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation:    * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.  Find the minimum number of watering operations required to satisfy the condition.

Submission attempts (in order):
n=int(input())
A=list(map(int,input().split()))+[0]
ans=0

while 1:
  for i in range(n):
    if A[i]>0:
      A[i]-=1
      if A[i+1]==0:
        ans+=1
  if A==[0 for i in range(n)]:
    break
print(ans)

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

while 1:
  for i in range(n):
    if A[i]>0:
      A[i]-=1
      if A[i+1]==0:
        ans+=1
  if not A==[0 for i in range(n+1)]:
    continue
  break
print(ans)


Verdicts: Time Limit Exceeded

Accepted
Problem: In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation:    * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.  Find the minimum number of watering operations required to satisfy the condition.

Submission attempts (in order):
n = int(input())
h = list(map(int, input().split()))
cnt = 0
def minus1(arr) :
  for i in range(len(arr)) :
    if(arr[i] != 0) : arr[i] -= 1
  return 0

def discover0(arr) :
  flag = [0, 0]
  cnt = 0
  for i in range(1, len(arr)) :
    if(arr[i-1] != 0 and arr[i] == 0) :
      flag[0] = 1
    elif(arr[i-1] == 0 and arr[i] != 0) :
      flag[1] = 1
    
    if(flag == [1, 1]) :
      flag = [0, 0]
      cnt += 1
  return cnt

for i in range(max(h)) :
  cnt += discover0(h)
  minus1(h)
  cnt += 1
print(cnt)

n = int(input())
h = list(map(int, input().split()))
cnt = 0
def minus1(arr) :
  for i in range(len(arr)) :
    if(arr[i] != 0) : arr[i] -= 1
  return 0

def discover0(arr) :
  cnt = 0 
  for i in range(1, len(arr)) :
    if(arr[i-1] == 0 and arr[i] == 0):
      cnt += 1
  if(arr[0] == 0) : cnt += 1
  if(arr[len(arr)-1] == 0) : cnt += 1
  return arr.count(0) - cnt

for i in range(max(h)) :
  cnt += discover0(h)
  minus1(h)
  cnt += 1
print(cnt)

Verdicts: Wrong Answer

Accepted
Problem: In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation:    * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.  Find the minimum number of watering operations required to satisfy the condition.

Submission attempts (in order):
# coding:utf-8
# C - Grand Garden

N = int(input())
h = list(map(int,input().split()))
h += [0]
ans = 0

for _ in range(100):
    for i in range(N+1):
        if h[i] != 0:
            h[i] -= 1
            add = True
        else:
            if add:
                mini_ans += 1
            add = False

print(ans)

# coding:utf-8
# C - Grand Garden

N = int(input())
h =  [int(i) for i in input().split()]
h += [0]
ans = 0
add = False

while True:
    mini_ans = 0
    for i in range(N+1):
        if h[i] != 0:
            h[i] -= 1
            add = True
        else:
            if add:
                mini_ans += 1
            add = False
    if mini_ans == 0:
        break
    else:
        ans += mini_ans

print(ans)

Verdicts: Runtime Error

Accepted
Problem: In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation:    * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.  Find the minimum number of watering operations required to satisfy the condition.

Submission attempts (in order):





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

ans = 0
l,r = 0,0
while True:
    if l > N-1 or r > N-1:
        l,r = 0,0

    while l < N H[l] == 0:
        l += 1

    if l >= N:
        break

    r = l
    while r < N and H[r] != 0:
        r += 1

    tmp = min(H[l:min(r,N)])
    for i in range(l,min(r,N)):
        H[i] -= tmp
    ans += tmp
    l = r + 1

    

print(ans)






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

ans = 0
while True:
    
    l,r = -1,-1

    for i in range(N):
        if H[i] != 0:
            l = i
            break

    if l == -1:
        break

    for i in range(l,N):
        if H[i] == 0:
            r = i-1
            break

        if i == N-1: r = N-1

    print(l,r)
    tmp =  min(H[l:r+1])
    for i in range(l,r+1):
        H[i] -= tmp
    ans += tmp

print(ans)






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

ans = 0
while True:
    
    l,r = -1,-1

    for i in range(N):
        if H[i] != 0:
            l = i
            break

    if l == -1:
        break

    for i in range(l,N):
        if H[i] == 0:
            r = i-1
            break

        if i == N-1: r = N-1


    tmp =  min(H[l:r+1])
    for i in range(l,r+1):
        H[i] -= tmp
    ans += tmp

print(ans)

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation:    * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.  Find the minimum number of watering operations required to satisfy the condition.

Submission attempts (in order):
n = int(input())
v = list(map(int, input().split()))
ans = v[0]
for i in range(1, n):
    ans += max(v[i]-v[i-1], 0)
print(cnt)

n = int(input())
v = list(map(int, input().split()))
ans = v[0]
for i in range(1, n):
    ans += max(v[i]-v[i-1], 0)
print(ans)

Verdicts: Runtime Error

Accepted
Problem: In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation:    * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.  Find the minimum number of watering operations required to satisfy the condition.

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


ans = 0
now = 0
for i in range(N):
    if lst_h[i] > now:
        ans += now
    now = lst_h[i]


print(ans)

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


ans = 0
now = 0
for i in range(N):
    if lst_h[i] > now:
        ans += lst_h[i] - now
    now = lst_h[i]


print(ans)


Verdicts: Wrong Answer

Accepted
Problem: In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation:    * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.  Find the minimum number of watering operations required to satisfy the condition.

Submission attempts (in order):
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n, *h = map(int, read().split())
    if n == 1:
        print(h[0])
        sys.exit()
    r1 = h[0]
    r2 = h[-1]
    for i1 in range(n - 1):
        if h[i1] < h[i1 + 1]:
            r1 += (h[i1 + 1] - h[i1])
        elif h[i1] > h[i1 + 1]:
            r2 += (h[i1] - h[i1 + 1])
    r = max(r1, r2) + min(h)
    print(r)
if __name__ == '__main__':
    main()

import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n, *h = map(int, read().split())
    if n == 1:
        print(h[0])
        sys.exit()
    r1 = h[0]
    for i1 in range(n - 1):
        if h[i1] < h[i1 + 1]:
            r1 += (h[i1 + 1] - h[i1])
    print(r1)
if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Accepted
Problem: In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation:    * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.  Find the minimum number of watering operations required to satisfy the condition.

Submission attempts (in order):
# ABC116C - Grand Garden
n = int(input())
lst = list(map(int, input().rstrip().split()))
ans = 0
cur = 0
for n, m in zip(lst, lst[1:]):
    if cur < n:
        cur = n
    if cur > m:
        ans += cur - m
        cur = m
print(ans)

# ABC116C - Grand Garden
n = int(input())
lst = list(map(int, input().rstrip().split()))
ans = 0
cur = 0
for n, m in zip(lst, lst[1:]):
    print(n, m)
    if cur < n:
        cur = n
    if cur > m:
        ans += cur - m
        cur = m
print(ans)

# ABC116C - Grand Garden
n = int(input())
lst = list(map(int, input().rstrip().split())) + [0]
ans = 0
cur = 0
for n, m in zip(lst, lst[1:]):
    print(n, m)
    if cur < n:
        cur = n
    if cur > m:
        ans += cur - m
        cur = m
print(ans)

# ABC116C - Grand Garden
n = int(input())
lst = list(map(int, input().rstrip().split()))
ans = 0
cur = 0
for i in lst:
    ans += max(0, i - cur)
    cur = i
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation:    * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.  Find the minimum number of watering operations required to satisfy the condition.

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

water = 0
pre = 0
for now in h_s:
  if now > pre:
    
    water += now - pre
    print(pre, now)
  pre = now
print(water)
    

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

water = 0
pre = 0
for now in h_s:
  if now > pre:
    
    water += now - pre
  pre = now
print(water)
    

Verdicts: Wrong Answer

Accepted
Problem: In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation:    * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.  Find the minimum number of watering operations required to satisfy the condition.

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

ans = 0

while sum(hn) > 0:
    ans+= 1
    flag = False
    for i in range(n):
        if hn[i] > 0:
            hn[i] -= 1
            flag = True
        else:
            break

print(ans)

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

ans = 0

while sum(hn) > 0:
    ans+= 1
    flag = False
    for i in range(n):
        if hn[i] > 0:
            hn[i] -= 1
            flag = True
        elif flag is True:
            break

print(ans)

Verdicts: Runtime Error

Accepted
Problem: In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation:    * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.  Find the minimum number of watering operations required to satisfy the condition.

Submission attempts (in order):
n = int(input())
flower = input().split()
for i in range(n):
    flower[i] = int(flower[i])
print(flower)
a = 0
def water():
    if sum(flower) == 0:
        a = -1
    elif 0 in flower:
        i = 0
        while flower[i] == 0:
            i += 1
        j = i
        try:
            while flower[j+1] != 0:
                j += 1
        except:
            abc = i
        for k in range(i,j+1):
            flower[k] -= 1
    else:
        for i in range(n):
            flower[i] -= 1
ans = 0
while sum(flower) != 0:
    water()
    ans += 1
print(ans)

n = int(input())
flower = input().split()
for i in range(n):
    flower[i] = int(flower[i])
a = 0
def water():
    if sum(flower) == 0:
        a = -1
    elif 0 in flower:
        i = 0
        while flower[i] == 0:
            i += 1
        j = i
        try:
            while flower[j+1] != 0:
                j += 1
        except:
            abc = i
        for k in range(i,j+1):
            flower[k] -= 1
    else:
        for i in range(n):
            flower[i] -= 1
ans = 0
while sum(flower) != 0:
    water()
    ans += 1
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation:    * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.  Find the minimum number of watering operations required to satisfy the condition.

Submission attempts (in order):
n = int(input())
h = list(map(int,input().split()))
h.insert(0,0)
sum = 0
bottom = 0
for i, hn in enumerate(h):
  if (i == 0) :
    continue
  if (hn < h[i-1]):
    print(h[i-1])
    sum += (h[i-1] - bottom)
    bottom = hn
end = bottom if h[n-1] < h[n] else 0
print(sum+end)

n = int(input())
h = list(map(int,input().split()))
h.insert(0,0)
sum = 0
bottom = 0
for i, hn in enumerate(h):
  if (i == 0) :
    continue
  if (hn < h[i-1]):
    bottom = hn
  else:
    sum += hn - h[i-1]
print(sum)

Verdicts: Wrong Answer

Accepted
Problem: In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation:    * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.  Find the minimum number of watering operations required to satisfy the condition.

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

ans = 0
check = 0
while(True):
    for i in range(N):
        if i == 0:
            check = 0
        if check == 0:
            if h[i] != 0:
                check = 1
                ans += 1
                h[i] -=1
        if check == 1:
            if h[i] != 0:
                h[i] -= 1
            else:
                check = 0
    if(sum(h)==0):
        break
            
print(ans)  


N = int(input())
h = [0]+[int(x) for x in input().split()]
print(sum([x-y for x,y in zip(h[1:],h[:-1]) if (x-y)>0]))


Verdicts: Wrong Answer

Accepted
Problem: In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation:    * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.  Find the minimum number of watering operations required to satisfy the condition.

Submission attempts (in order):
import numpy as np

N = int(input())
H = np.array(list(map(int, input().split())))
cnt = 0
f_f = 0 
n_f = 0 
v = 0 

cnt = min(H)
H -=cnt
for i in range(max(H)):
    for j in range(N):
        v=0
        if N == 0 and H[j] > 0 and H[j+1] == 0:
            v+=1
        elif H[j] > 0 and H[j-1] == 0:
            v+=1
        cnt+=v
        
        if H[j] > 0: H[j]-=1
    
print(cnt)

import numpy as np

N = int(input())
H = np.array(list(map(int, input().split())))
cnt = 0
f_f = 0 
n_f = 0 
v = 0 

cnt = min(H)
H -=cnt
precnt = 0
for i in range(max(H)):
    a = 0
    for j in range(N):
        v=0
        if j == 0 and H[j] > 0:
            v+=1
        elif H[j] > 0 and H[j-1] == 0:
            v+=1
        cnt+=v
        a+=v
    print(a)

    for j in range(N):
        if H[j] > 0:
            H[j]-=1
    print(H)
print(cnt)

import numpy as np

N = int(input())
H = np.array(list(map(int, input().split())))
cnt = 0
f_f = 0 
n_f = 0 
v = 0 

cnt = min(H)
H -=cnt
precnt = 0
for i in range(max(H)):
    a = 0
    for j in range(N):
        v=0
        if j == 0 and H[j] > 0:
            v+=1
        elif H[j] > 0 and H[j-1] == 0:
            v+=1
        cnt+=v
        a+=v

    for j in range(N):
        if H[j] > 0:
            H[j]-=1
print(cnt)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation:    * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.  Find the minimum number of watering operations required to satisfy the condition.

Submission attempts (in order):
n = int(input())
li = list(map(int,input().split()))
ans = 0
for i in range(n):
  if li[i - 1] == 0:
    del li[i - 1]
    n = len(li)
  else:
    ans += li[i - 1]
    for j in range(n):
      li[j - 1] -= 1
print(str(ans))

N=int(input())
x=[int(i) for i in input().split()]
x.append(0)
cnt=0
while x.count(0)!=N+1:
    for i in range(N):
        if x[i+1]==0 and x[i]>0:
            cnt+=1
        if x[i]>0:
            x[i]-=1
print(cnt)

Verdicts: Runtime Error

Accepted
Problem: In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation:    * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.  Find the minimum number of watering operations required to satisfy the condition.

Submission attempts (in order):
n=int(input())
h=[0]+list(map(int,input().split()))+[0]

exbi=[]
exsm=[]
for c,d,e in zip(h[0:],h[1:],h[2:]):
  #print(c,d,e)
  if c<d and d>e:
    exbi.append(d)
  if c>d and d<e:
    exsm.append(d)   
#print(exbi,exsm)
print(sum(exbi)-sum(exsm))

n=int(input())
h=[0]+list(map(int,input().split()))+[0]

exbi=[]
exsm=[]
for c,d,e in zip(h[0:],h[1:],h[2:]):
  #print(c,d,e)
  if c<d and d>e:
    exbi.append(d)
  if c>=d and d<=e:
    exsm.append(d)   
#print(exbi,exsm)
print(sum(exbi)-sum(exsm))

def main():
    n, *h = map(int, open(0).read().split())
    #print(n)
    #print(h)
    ans = h[0]
    #print(ans)
    for i in range(n-1):
        ans += max(h[i+1]-h[i],0)
        #print(ans)
    print(ans)
    return


main()

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation:    * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.  Find the minimum number of watering operations required to satisfy the condition.

Submission attempts (in order):

import numpy as np
n = int(input())
h = list(map(int, input().split()))
h = np.array(h)

count = 0

for k in range(max(h)):
    j = 0
    for i in range(0,len(h)):
        if h[i]==0 and i!=j:
            h[j:i] = h[j:i] -1
            count = count+1
            j = i + 1
        elif i ==len(h)-1 and h[n]!=0:
            count = count+1
            h[j:]= h[j:]-1
        elif h[i]==0 and i==j:
            j = i+1
print(count)


import numpy as np
n = int(input())
h = list(map(int, input().split()))
h = np.array(h)

count = 0

for k in range(max(h)):
    j = 0
    for i in range(0,len(h)):
        if h[i]==0 and i!=j:
            h[j:i] = h[j:i] -1
            count = count+1
            j = i + 1
        elif i ==len(h)-1 and h[n-1]!=0:
            count = count+1
            h[j:]= h[j:]-1
        elif h[i]==0 and i==j:
            j = i+1
print(count)

Verdicts: Runtime Error

Accepted
Problem: In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation:    * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.  Find the minimum number of watering operations required to satisfy the condition.

Submission attempts (in order):
H = [0] + H
cnt = 0
for i in range(1, N + 1):
    cnt += max(H[i] - H[i - 1], 0)


print(cnt)


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

H = [0] + H
cnt = 0
for i in range(1, N + 1):
    cnt += max(H[i] - H[i - 1], 0)


print(cnt)

Verdicts: Runtime Error

Accepted
Problem: In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation:    * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.  Find the minimum number of watering operations required to satisfy the condition.

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


def mizuyari(*f):
    print(f)
    if len(f) == 0:
        return
    min_i = f.index(min(f))
    if f[min_i] != 0:
        global ans
        ans += f[min_i]
        print('ans=', ans)
        f = [i - f[min_i] for i in f]
    print(f)
    if f[min_i] == 0:
        mizuyari(*f[:min_i])
        mizuyari(*f[min_i + 1:])


l = []
for n in range(N):
    l.append(0)
mizuyari(*H)
print(ans)

n = int(input())
a = list(map(int, input().split()))
s = [(0, n)]
ans = 0
while s:
    l, r = s.pop()
    if l == r:
        continue
    m = min(a[l:r])
    ans += m
    for i in range(l, r):
        a[i] -= m
    for i in range(l, r):
        if a[i] == 0:
            s.append((l, i))
            s.append((i + 1, r))
            break
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation:    * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.  Find the minimum number of watering operations required to satisfy the condition.

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

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

def dfs(l, r):
  if l == r:
    return 0
  m = 100
  for i in range(l, r):
    m = min(m, v[i])
  if m == 0:
    return 0
  res = 0
  for i in range(l, r):
    v[i] -= m
  last = 0
  for i in range(l, r):
    if v[i] == 0:
      res += dfs(last, i)
      last = i + 1
  return res
print(dfs(0, n))


n = int(input())

v = list(map(int, input().split()))
v.append(0)

def dfs(l, r):
  #print(l, r)
  if l == r:
    return 0

  for i in range(l, r):
    v[i] = max(0, v[i] - 1)

  last = l
  res = 1
  for i in range(l, r):
    if v[i] == 0:
      res += dfs(last, i)
      last = i + 1
  res += dfs(last, r)
  return res

last = 0
res = 0
for i in range(0, n + 1):
  if v[i] == 0:
    res += dfs(last, i)
    last = i + 1
#print(v)
print(res)


Verdicts: Wrong Answer

Accepted
Problem: In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation:    * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.  Find the minimum number of watering operations required to satisfy the condition.

Submission attempts (in order):
import numpy as np

n = input()
array = np.array(list(map(int, input().split())))

count = 0
def recur(array):
    global count
    if len(array) == 0 :
        pass
    else:
        print('plus :', min(array))
        count += min(array)
        array = array - min(array)
        for i in range(len(array)):
            if array[i] == 0:
                array_1 = array[:i]
                array_2 = array[i+1:]
                break
        recur(array_1)
        recur(array_2)
    return count

print(recur(array))

import numpy as np

n = input()
array = np.array(list(map(int, input().split())))

count = 0
def recur(array):
    global count
    if len(array) == 0 :
        pass
    else:
        count += min(array)
        array = array - min(array)
        for i in range(len(array)):
            if array[i] == 0:
                array_1 = array[:i]
                array_2 = array[i+1:]
                break
        recur(array_1)
        recur(array_2)
    return count

print(recur(array))

Verdicts: Wrong Answer

Accepted
Problem: In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation:    * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.  Find the minimum number of watering operations required to satisfy the condition.

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

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

L = [l_0]

m = None

count = 0

while L != []:
	for l in L:
		lis = l
		m   = min(l)
		for i in range(len(l)):
			lis[i] = lis[i] - m
		count += m
		lis = "_".join( list(map(str , lis)) )
		if lis[0:1] == "0":
			lis = lis[2:]
		lis = lis.split("_0")
		while "" in lis:
			lis.remove("")
		for a in lis:
			if a[0:1] == "_":
				a = a[1:]
			a = list(map(int, a.split("_")))
			L.append(a)
		L.remove(l)
		while [] in L:
			L.remove([])
		print(L)
		print(count)
		print(" ")

print(count)


L = [l_0]

m = None

count = 0

while L != []:
	for l in L:
		m = min(l)
		L.remove(l)
		for i in range(len(l)):
			l[i] = l[i] - m
		count += m
		l = list(map(str , l))
		l = " ".join(l)
		l = (l.split("0 "))
		for a in l:
			L.append(list(map( int, (a.split()))))
		while [] in L:
			L.remove([])

print(count)

N = int(input())

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

L = [l_0]

m = None

count = 0

while L != []:
	for l in L:
		lis = l
		m   = min(l)
		for i in range(len(l)):
			lis[i] = lis[i] - m
		count += m
		lis = "_".join( list(map(str , lis)) )
		if lis[0:1] == "0":
			lis = lis[2:]
		lis = lis.split("_0")
		while "" in lis:
			lis.remove("")
		for a in lis:
			if a[0:1] == "_":
				a = a[1:]
			a = list(map(int, a.split("_")))
			L.append(a)
		L.remove(l)
		while [] in L:
			L.remove([])
		print(L)
		print(count)
		print(" ")

print(count)


N = int(input())

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

L = [l_0]

m = None

count = 0

while L != []:
	for l in L:
		lis = l
		m   = min(l)
		for i in range(len(l)):
			lis[i] = lis[i] - m
		count += m
		lis = "_".join( list(map(str , lis)) )
		if lis[0:1] == "0":
			lis = lis[2:]
		lis = lis.split("_0")
		while "" in lis:
			lis.remove("")
		for a in lis:
			if a[0:1] == "_":
				a = a[1:]
			a = list(map(int, a.split("_")))
			L.append(a)
		L.remove(l)
		while [] in L:
			L.remove([])
print(count)

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Accepted
Problem: In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation:    * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.  Find the minimum number of watering operations required to satisfy the condition.

Submission attempts (in order):
N=int(input())
h=list(map(int,input().split()))
s=0
mini=100
def garden(N,h,s,mini):
  p=[]
  a=0
  b=0
  size=0
  for i in range (N):
    if mini>h[i]:
      mini=h[i]
    if i!=N-1:
      if h[i]>h[i+1]:
        p.append(h[i])
        a+=h[i]
        size+=1
    if i!=N-1 and i!=0:
      if h[i]<h[i+1] and (h[i]-h[i-1])*(h[i+1]-h[i])<=0:
        p.append(h[i])
        b+=h[i]
        size+=1
    if i==N-1:
      if h[i-1]<h[i]:
        p.append(h[i])
        a+=h[i]
        size+=1
  s+=a
  s-=b
  print(a)
  print(b)
  flag=0
  for j in range (1,size-1):
    if (p[j]-p[j-1])*(p[j+1]-p[j])>0:
      flag=1
  if flag==1:
    garden(size,p,s,mini)
  if s==0:
    s+=1
  print(s)
  
garden(N,h,s,mini)

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

Verdicts: Runtime Error

Accepted
Problem: In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation:    * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.  Find the minimum number of watering operations required to satisfy the condition.

Submission attempts (in order):
i = 0
ans = 0
while True:
    if i >= len(S):
        
        break
    for j in range(i+1,len(S)+1):
        #print(S[i:j])
        a = max(S[i:j])
        if j >= len(S):
            #print(1,S[i:j],i,j,ans)
            ans += max(S[i:j])
            i += j
            break
        elif a <= S[j]:
            #print(2,i,j,ans)
            continue
        else:
            #print(3,S[i:j],i,j,ans)
            ans += max(S[i:j])
            ans -= S[j]
            i = j
            break
print(ans)

input()
S = list(map(int,input().split()))
i = 0
ans = 0
while True:
    if i >= len(S):
        
        break
    for j in range(i+1,len(S)+1):
        #print(S[i:j])
        a = max(S[i:j])
        if j >= len(S):
            #print(1,S[i:j],i,j,ans)
            ans += max(S[i:j])
            i += j
            break
        elif a <= S[j]:
            #print(2,i,j,ans)
            continue
        else:
            #print(3,S[i:j],i,j,ans)
            ans += max(S[i:j])
            ans -= S[j]
            i = j
            break
print(ans)

Verdicts: Runtime Error

Accepted