ZhenlongDai/ACPR huggingface dataset:
Problem: p03347
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input = sys.stdin.readline

def calc(l):
    l2 = l[::-1]
    res = l2[0]
    
    for i in range(1, len(l2)):
        if l2[i]!=l2[i-1]-1:
            res += l2[i]

    return res

N = int(input())
A = [int(input()) for _ in range(N)]

for i in range(N):
    if A[i]>i:
        print(-1)
        exit()

ans = 0
l = []

for i in range(N):
    if i==N-1 or A[i]>A[i+1]:
        l.append(A[i])
        ans += calc(l)
        l = []
    else:
        l.append(A[i])

print(ans)

Failing test case input:
3
-4
1
-1

Expected output:
-1


Actual output:
-4


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline

def calc(l):
    l2 = l[::-1]
    res = l2[0]
    
    for i in range(1, len(l2)):
        if l2[i-1]-1>l2[i]:
            print(-1)
            exit()
            
        if l2[i]!=l2[i-1]-1:
            res += l2[i]

    return res

N = int(input())
A = [int(input()) for _ in range(N)]

for i in range(N):
    if A[i]>i:
        print(-1)
        exit()

ans = 0
l = []

for i in range(N):
    if i==N-1 or A[i]>A[i+1]:
        l.append(A[i])
        ans += calc(l)
        l = []
    else:
        l.append(A[i])

print(ans)

Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = []
ans = 0
flag = True
for i in range(n):
    A = int(input())
    a.append(A)
next = 0
for i in range(n-1,-1,-1):
    if a[i] == 0:
        next = 0
        continue
    if next - a[i] == 1:
        next = a[i]
        continue
    if next - a[i] >= 2:
        flag = False
        break
    next = a[i]
    ans += a[i]
if a[0] != 0:
    flag = False
if flag:
    print(ans)
else:
    print(-1)


Failing test case input:
9
0
0
1
0
2
1
2
3
2

Expected output:
-1


Actual output:
8


Fixed submission (verdict: Accepted):
n = int(input())
a = []
ans = 0
flag = True
for i in range(n):
    A = int(input())
    a.append(A)
next = 0
for i in range(n-1,-1,-1):
    if next - a[i] >= 2:
        flag = False
        break
    if a[i] == 0:
        next = 0
        continue
    if next - a[i] == 1:
        next = a[i]
        continue
    next = a[i]
    ans += a[i]
if a[0] != 0:
    flag = False
if flag:
    print(ans)
else:
    print(-1)

Problem: p03347
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))


ans = 0
pre = 0
for i in range(N):
  if A[i] > i:
    print(-1)
    exit()
  else:
    if A[i] > 0:
      if A[i] == pre + 1:
        ans += 1
      else:
        ans += A[i]
    pre = A[i]
print(ans)


Failing test case input:
9
0
0
1
0
2
1
2
3
2

Expected output:
-1


Actual output:
8


Fixed submission (verdict: Accepted):
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))


ans = 0
pre = 0
maxa = 0
for i in range(N):
  if A[i] > maxa:
    print(-1)
    exit()
  else:
    if A[i] == 0:
      maxa = 0
    elif A[i] == pre + 1:
      ans += 1
    else:
      ans += A[i]
      maxa = A[i]
    pre = A[i]
    maxa += 1
print(ans)
Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect

def main():
    n = int(input())
    a = []
    for _ in range(n):
        a.append(int(input()))
    a.append(0)
    ans = solve(a, n)
    print(ans)

def solve(a, n):
    base = 0
    s = 0
    for i in range(n):
        if a[i] > base + i:
            return -1
        
        if a[i + 1] <= a[i]:
            s += a[i]
        
        base = i - a[i]
    
    return s

main()

Failing test case input:
9
0
1
1
-1
2
1
2
3
-1

Expected output:
-1


Actual output:
7


Fixed submission (verdict: Accepted):
import bisect

def main():
    n = int(input())
    a = []
    for _ in range(n):
        a.append(int(input()))
    a.append(0)
    ans = solve(a, n)
    print(ans)

def solve(a, n):
    if not check(a, n):
        return -1

    base = 0
    s = 0
    for i in range(n):
        if a[i] > base + i:
            return -1
        
        if a[i + 1] <= a[i]:
            s += a[i]
        
        base = i - a[i]
    
    return s

def check(a, n):
    if a[0] != 0:
        return False
    
    for i in range(1, n):
        if a[i] - a[i - 1] > 1:
            return False

    return True

main()

Problem: p03347
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int( input())
As  = [int(input())for _ in  range(N)]
ans = 0
for i in range(N):
    if As[i] > i:
        ans = -1
        break

    else:
        if As[i] == As[i -1] + 1:
            ans += 1
        else:
            ans += As[i]

print(ans)


Failing test case input:
9
0
-1
-1
-1
-1
2
0
1
-2

Expected output:
-1


Actual output:
-3


Fixed submission (verdict: Accepted):
import math
N = int( input())
As  = [int(input())for _ in  range(N)]
ans = 0
for i in range(N):
    if As[i] > i or As[i] - As[i - 1] > 1:
        ans = -1
        break

    else:
        if As[i] == As[i -1] + 1:
            ans += 1
        else:
            ans += As[i]

print(ans)

Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
A = [int(input()) for _ in range(n)]
ans = 0
prev = 0
for i in range(n):
    a = A[i]
    if prev == None and a!=0:
        ans = -1
        break
    if prev != None:
        dif = a-prev
        if dif >= 2:
            ans = -1
            break
        elif dif<=0:
            ans += prev
    prev = a
if ans!=-1:
    ans += prev
print(ans)

Failing test case input:
3
1
-1
-2

Expected output:
-1


Actual output:
-2


Fixed submission (verdict: Accepted):
n = int(input())
A = [int(input()) for _ in range(n)]
ans = 0
prev = 0
if A[0]!=0:
  print(-1)
  exit()
for i in range(n):
    a = A[i]
    if prev == None and a!=0:
        ans = -1
        break
    if prev != None:
        dif = a-prev
        if dif >= 2:
            ans = -1
            break
        elif dif<=0:
            ans += prev
    prev = a
if ans!=-1:
    ans += prev
print(ans)
Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
l =[]

for i in range(N):
    l.append(int(input()))
    if i == 0 and l[i]!=0:
        print(-1)
        break
    if i>=1:
        if l[i]-l[i-1]>1 :
            print(-1)
            break

ans = 0
pre = -1
for a in l[::-1]:
    if pre - 1 != a:
        ans += a
    pre = a
print(ans)

Failing test case input:
9
0
0
0
-1
-2
2
0
1
-2

Expected output:
-1


Actual output:
-1
-1


Fixed submission (verdict: Accepted):
import sys
N = int(input()) 
A = [int(sys.stdin.readline()) for _ in range(N)]
b = 0
for i, a in enumerate(A):
    if i + b < a:
        print(-1)
        sys.exit()
    else:
        b = a - i
ans = 0
pre = -1
for a in A[::-1]:
    if pre - 1 != a:
        ans += a
    pre = a
print(ans)

Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(input()) for i in range(N)]

if A[0] != 0:
    print(-1)
    exit()

for i in range(N-1):
    if A[i] < A[i+1] and A[i+1]-A[i] != 1:
        print(-1)
        exit()
ans = 0

A = A[::-1]
M = 0
for i in range(N-1):
    if A[i] >= A[i+1]:
        ans += M
        M = A[i]
        continue
    M = max(M, A[i])
print(ans)


Failing test case input:
4
0
1
0
0

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(input()) for i in range(N)]

if A[0] != 0:
    print(-1)
    exit()

for i in range(N - 1):
    if A[i] < A[i + 1] and A[i + 1] - A[i] != 1:
        print(-1)
        exit()
    if A[i] > i + 1:
        print(-1)
        exit()

ans = 0
i = 1
old = 0
while i != N:
    if A[i] <= old:
        ans += old
    old = A[i]
    i += 1

print(ans + A[-1])

Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

n = int(input())
a = [int(input()) for _ in range(n)]

ans = 0
tmp = 0
for i in range(n-1):
    if a[i+1] > a[i]:
        pass
    else:
        ans += a[i]
ans += a[n-1]

if a[0] == 0:
    print(ans)
else:
    print(-1)


Failing test case input:
9
0
1
1
0
2
1
2
3
0

Expected output:
-1


Actual output:
7


Fixed submission (verdict: Accepted):

n = int(input())
a = [int(input()) for _ in range(n)]

ans = 0
tmp = 0
flag = True
if a[0] != 0:
    flag = False

for i in range(n-1):
    if a[i+1] > a[i]:
        pass
    else:
        ans += a[i]
    if a[i+1] - a[i] > 1:
        flag = False
    
ans += a[n-1]

if flag:
    print(ans)
else:
    print(-1)

Problem: p03347
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
a = [int(input()) for i in range(n)]

if a[0]!=0:
    print(-1)
    exit()

ans = a[-1]
x = a[-1]
for i in range(n-1):
    if a[-i-2] >= x-1:
        ans += a[-i-2]-x+1
        x = a[-i-2]
    else:
        print(-1)
        exit()

print(ans)

Failing test case input:
4
0
1
0
0

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):
n = int(input())
a = [int(input()) for i in range(n)]

if a[0]!=0:
    print(-1)
    exit()

ans = a[-1]
x = a[-1]
for i in range(n-1):
    if a[-i-2] > x-1:
        ans += a[-i-2]
        x = a[-i-2]
    elif a[-i-2]==x-1:
        x -=1
    else:
        print(-1)
        exit()

print(ans)
Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())

ans = -1
tmp = -1 
for i in range(N):
    A = int(input())
    if A > i:
        print (-1)
        exit()
    if tmp + 1 == A:
        ans += 1
        tmp += 1
    else:
        ans += A
        tmp = A

print (ans)

Failing test case input:
9
0
1
1
0
2
2
2
1
4

Expected output:
-1


Actual output:
13


Fixed submission (verdict: Accepted):
N = int(input())

ans = -1
tmp = -1 
for i in range(N):
    A = int(input())
    if A > i:
        print (-1)
        exit()
    if tmp + 1 < A:
        print (-1)
        exit()
    if tmp + 1 == A:
        ans += 1
        tmp += 1
    else:
        ans += A
        tmp = A

print (ans)

Problem: p03347
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n=int(input())

a=[int(input()) for _ in range(n)]


cnt=0

if a[0]!=0:
    print(-1)
    exit()

for i in range(1,n):
    
    if a[i]!=0:
        if a[i]<=a[i-1]+1:
            cnt+=1
        else:
            print(-1)
            exit()
print(cnt)

    






Failing test case input:
9
0
1
1
0
1
2
2
1
2

Expected output:
8

Actual output:
7


Fixed submission (verdict: Accepted):
n=int(input())

a=[int(input()) for _ in range(n)]


cnt=0

if a[0]!=0:
    print(-1)
    exit()

for ii in range(1,n):
    i=n-ii
    if a[i]==0:
        continue
    elif a[i]<=a[i-1]:
        cnt+=a[i]
    elif a[i]==a[i-1]+1:
        cnt+=1
    elif a[i]>a[i-1]+1 or  a[i]>i:
        print(-1)
        exit()
    
    

print(cnt)

Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main(n, A):
    if A[0] != 0:
        return -1

    res = 0
    for i in range(n):
        if i == 0:
            left = 0
            continue

        a = A[i]
        if left < a:
            res += a - left
        else:
            res += a
        left = a
    return res


if __name__ == "__main__":
    n = int(input())
    a = [int(input()) for _ in range(n)]
    ans = main(n, a)
    print(ans)


Failing test case input:
9
0
1
1
-1
2
1
2
3
-1

Expected output:
-1


Actual output:
6


Fixed submission (verdict: Accepted):
def main(n, A):
    if A[0] != 0:
        return -1

    A.append(0)
    A = A[::-1]

    res = 0
    for x, y in zip(A[:-1], A[1:]):
        if x <= y:
            res += y
        elif x - 1 == y:
            pass
        else:
            return -1

    return res


if __name__ == "__main__":
    n = int(input())
    a = [int(input()) for _ in range(n)]
    ans = main(n, a)
    print(ans)
Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
A = [int(input()) for _ in range(n)]
ans = 0
prev = 0
for i in range(n):
    a = A[i]
    if prev == None and a!=0:
        print(-1)
        exit()
    if prev != None:
        dif = a-prev
        if dif >= 2:
            print(-1)
            exit()
        elif dif<=0:
            ans += prev
    prev = a

ans += prev
print(ans)

Failing test case input:
4
1
0
1
2

Expected output:
-1


Actual output:
3


Fixed submission (verdict: Accepted):
n = int(input())
A = [int(input()) for _ in range(n)]
ans = 0
prev = 0
if A[0]!=0:
  print(-1)
  exit()
for i in range(n):
    a = A[i]
    if prev == None and a!=0:
        ans = -1
        break
    if prev != None:
        dif = a-prev
        if dif >= 2:
            ans = -1
            break
        elif dif<=0:
            ans += prev
    prev = a
if ans!=-1:
    ans += prev
print(ans)

Problem: p03347
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys

n = int(sys.stdin.readline().strip())
a_ls = []
for i in range(n):
    a = int(sys.stdin.readline().strip())
    a_ls.append(a)

if a_ls[0] != 0:
    print(-1)
else:
    cur = a_ls[-1]
    res = cur
    for a in a_ls[::-1][1:]:
        cur -= 1
        if a - cur > 0:
            res += a - cur
            cur = a
        elif a == cur:
            continue
        else:
            res = -1
            break
    print(res)

Failing test case input:
4
0
1
0
0

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):
import sys

n = int(sys.stdin.readline().strip())
a_ls = []
for i in range(n):
    a = int(sys.stdin.readline().strip())
    a_ls.append(a)

if a_ls[0] != 0:
    print(-1)
else:
    cur = a_ls[-1]
    res = cur
    for a in a_ls[::-1][1:]:
        cur -= 1
        if a - cur > 0:
            res += a
            cur = a
        elif a == cur:
            continue
        else:
            res = -1
            break
    print(res)

Problem: p03347
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
A = [int(input()) for _ in range(N)]

def solve() :
  now = 0
  for i in range(N) :
    if A[i] > now :
      return -1
    if A[i] == 0 :
      now = 1
    else :
      now += 1

  ret = 0
  for i in range(1, N) :
    if A[i] == 0 :
      continue

    ret += 1
    if A[i] != A[i-1] + 1 :
      ret += A[i] - 1
  
  return ret

print(solve())

Failing test case input:
9
0
0
0
-1
-2
2
0
1
-2

Expected output:
-1


Actual output:
-2


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(input()) for _ in range(N)]

def solve() :
  if A[0] != 0 :
    return -1

  for i in range(1, N) :
    if A[i] - A[i-1] >= 2:
      return -1

  ret = 0
  for i in range(1, N) :
    if A[i] == 0 :
      continue

    ret += 1
    if A[i] != A[i-1] + 1 :
      ret += A[i] - 1
  
  return ret

print(solve())
Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
As = [int(input()) for i in range(N)]

if As[0] != 0:
    print(-1)
    exit()

ans = 0
for i in range(1, N):
    if As[i] > i:
        print(-1)
        exit()

    if As[i - 1] + 1 == As[i]:
        ans += 1
    else:
        if As[i] > 1:
            print(-1)
            exit()
        ans += As[i]

print(ans)


Failing test case input:
9
0
1
1
0
1
2
2
1
2

Expected output:
8

Actual output:
-1


Fixed submission (verdict: Accepted):
N = int(input())
As = [int(input()) for i in range(N)]

if As[0] != 0:
    
    print(-1)
    exit()

ans = 0
for i in reversed(range(1, N)):
    if As[i - 1] + 1 < As[i]:
        
        ans = -1
        break
    elif As[i - 1] + 1 == As[i]:
        
        ans += 1
    else:
        
        ans += As[i]

print(ans)

Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(input()) for _ in range(N)]
ans, temp = 0, 0
for i in range(N-1, -1, -1):
    if A[i] != 0:
        if A[i] == temp:
            temp -= 1
        else:
            if i  >= A[i]:
                ans += A[i]
                temp = A[i] - 1
            else:
                print(-1)
                exit()
print(ans)

Failing test case input:
9
0
1
1
-1
2
1
2
3
0

Expected output:
-1


Actual output:
6


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(input()) for _ in range(N)]
ans, temp = 0, 0
for i in range(N-1, -1, -1):
    if A[i] < temp:
        print(-1)
        exit() 
    elif A[i] != 0:
        if A[i] == temp:
            temp -= 1    
        else:
            if i  >= A[i]:
                ans += A[i]
                temp = A[i] - 1
            else:
                print(-1)
                exit()
print(ans)

Problem: p03347
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
cnt = 0
A = [int(input()) for _ in range(N)]
if A[0]!=0:
    cnt = -1
else:
    for i in range(1,N):
        if A[i]==A[i-1]+1:
            continue
        elif A[i]<=A[i-1]:
            cnt += A[i-1]
        else:
            cnt = -1
    if cnt>=0 and A[N-1]==A[N-2]+1:
        cnt += A[N-1]
print(cnt)  

Failing test case input:
9
0
0
0
-1
-1
2
0
1
-1

Expected output:
-1


Actual output:
2


Fixed submission (verdict: Accepted):
N = int(input())
cnt = 0
A = [int(input()) for _ in range(N)]
if A[0]!=0:
    cnt = -1
else:
    for i in range(1,N):
        if A[i]==A[i-1]+1:
            continue
        elif A[i]<=A[i-1]:
            cnt += A[i-1]
        else:
            cnt = -1
            break
    if cnt>=0:
        cnt += A[N-1]
print(cnt)
Problem: p03347
Buggy submission (Python (3.8.2), verdict: Wrong Answer):



def main():
  n = int(input())
  la = [int(input()) for _ in range(n)]
  cnt = 0
  for i in range(n):
    if la[i] > i:
      print(-1)
      return
    
    if i+1 < n and la[i]+1 == la[i+1]:
      continue
    else:
      cnt += la[i]
  print(cnt)
    
if __name__=='__main__':
  main()



Failing test case input:
9
0
0
1
0
2
0
2
2
2

Expected output:
-1


Actual output:
9


Fixed submission (verdict: Accepted):



def main():
  n = int(input())
  la = [int(input()) for _ in range(n)]
  cnt = 0
  
  if la[0] != 0:
    print(-1)
    return
  for i in range(n-1):
    if la[i+1] > la[i] + 1:
      print(-1)
      return
    
  for i in range(n)[::-1]:
    if i+1 < n and la[i]+1 == la[i+1]:
      continue
    else:
      cnt += la[i]
  print(cnt)
    
if __name__=='__main__':
  main()

Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    n=int(input())
    a=[int(input()) for _ in [0]*n]
    ans=a[n-1]
    for i in range(n-2,0,-1):
        if a[i]>i:
            print(-1)
            return 0
        elif a[i]+1==a[i+1]:
            continue
        elif a[i]+1<a[i+1]:
            print(-1)
            return 0
        else:
            ans+=a[i]
    print(ans)
main()

Failing test case input:
3
-8
1
-1

Expected output:
-1


Actual output:
0


Fixed submission (verdict: Accepted):
def main():
    n=int(input())
    a=[int(input()) for _ in [0]*n]
    ans=a[n-1]
    if ans>n-1:
        print(-1)
        return 0
    for i in range(n-2,-1,-1):
        if a[i]>i:
            print(-1)
            return 0
        elif a[i]+1==a[i+1]:
            continue
        elif a[i]+1<a[i+1]:
            print(-1)
            return 0
        else:
            ans+=a[i]
    print(ans)
main()

Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
nums = [int(input()) for _ in range(n)]
if nums[0] >= 1:
    print(-1)
    exit()
p = nums[0]
r = 0
ans = 0

for i in range(1, n):
    if nums[i] == p:
        r += 1
    elif nums[i] > p + 1:
        print(-1)
        exit()
    else:
        ans += r * 2
        if r > 0:
            ans -= 1
        r = 0
        p = nums[i]
        ans += 1

print(ans)

Failing test case input:
4
0
1
0
0

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
nums = [int(input()) for _ in range(n)]
if nums[0] != 0:
    print(-1)
    exit()

ans = 0
for i in range(1, n):
    if nums[i] - nums[i-1] > 1:
        print(-1)
        exit()
    if nums[i] == 0:
        continue
    if nums[i] - nums[i-1] == 1:
        ans += 1
    else:
        ans += nums[i]
print(ans)
Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(input()) for _ in range(N)]

ok = True
for i, a in enumerate(A):
    if a > i:
        ok = False
        break

if not ok:
    print(-1)
else:
    c = 0
    for i in range(N-1):
        if A[i+1] != A[i] + 1:
            c += A[i+1]
        else:
            c += 1
    print(c)

Failing test case input:
9
0
0
1
0
2
0
2
2
2

Expected output:
-1


Actual output:
9


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(input()) for _ in range(N)]

ok = True
pre = -1
for i, a in enumerate(A):
    if a > pre + 1:
        ok = False
        break
    pre = a

if not ok:
    print(-1)
else:
    c = 0
    for i in range(N-1):
        if A[i+1] != A[i] + 1:
            c += A[i+1]
        else:
            c += 1
    print(c)

Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
l =[]

for i in range(N):
    l.append(int(input()))
    if i == 0 and l[i]!=0:
        print(-1)
        break
    if i>=1:
        if l[i]-l[i-1]>1 :
            print(-1)
            break

ans = 0
pre = -1
for a in l[::-1]:
    if pre - 1 != a:
        ans += a
    pre = a
 
print(ans)

Failing test case input:
9
3
1
0
-1
-1
4
0
3
-1

Expected output:
-1


Actual output:
-1
3


Fixed submission (verdict: Accepted):
import sys
N = int(input()) 
A = [int(sys.stdin.readline()) for _ in range(N)]
b = 0
for i, a in enumerate(A):
    if i + b < a:
        print(-1)
        sys.exit()
    else:
        b = a - i
ans = 0
pre = -1
for a in A[::-1]:
    if pre - 1 != a:
        ans += a
    pre = a
print(ans)

Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
ls = []
for i in range(N):
  ls += [int(input())]

ans = 0
p = -1
for i in range(N):
  if i<ls[i]:
    print(-1)
    break
  if p+1==ls[i]:
    if i==N-1:
      ans += (p+1)
    p = ls[i]
    continue
  else:
    ans += p
    p = ls[i]

print(ans)

Failing test case input:
3
2
0
-2

Expected output:
-1


Actual output:
-1
0


Fixed submission (verdict: Accepted):
N = int(input())
ls = [-1]
for i in range(N):
  ls += [int(input())]

ans = 0
p = 0
for i in range(1,N+1):
  if ls[i-1]+1<ls[i]:
    print(-1)
    break
  if ls[i-1]+1==ls[i]:
    if i==N:
      ans += (ls[i])
    p = ls[i]
    continue
  else:
    if i==N:
      ans += ls[i]
    ans += p
    p = ls[i]
else:
  print(ans)
Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
ls = [-1]
for i in range(N):
  ls += [int(input())]

ans = 0
p = 0
for i in range(1,N+1):
  if ls[i-1]+1<ls[i]:
    print(-1)
    break
  if ls[i-1]+1==ls[i]:
    if i==N:
      ans += (ls[i])
    p = ls[i]
    continue
  else:
    ans += p
    p = ls[i]

print(ans)

Failing test case input:
9
-1
0
1
0
2
1
2
2
2

Expected output:
-1


Actual output:
-1
1


Fixed submission (verdict: Accepted):
N = int(input())
ls = [-1]
for i in range(N):
  ls += [int(input())]

ans = 0
p = 0
for i in range(1,N+1):
  if ls[i-1]+1<ls[i]:
    print(-1)
    break
  if ls[i-1]+1==ls[i]:
    if i==N:
      ans += (ls[i])
    p = ls[i]
    continue
  else:
    if i==N:
      ans += ls[i]
    ans += p
    p = ls[i]
else:
  print(ans)

Problem: p03347
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
N = int(input())
a = []
for _ in range(N): a.append(int(input()))
if a[0] != 0:
  print(-1)
  exit(0)
for i in range(N - 1):
  if abs(a[i + 1] - a[i]) > 1:
    print(-1)
    exit(0)
res = 0
s = 0
x = 1
for i in range(1, N):
  if a[i] == x:
    s += 1
  else:
    if x > 0: res += (s - 1) * x + 1
    s = 1
    x = a[i]
  
res += (s - 1) * x + 1
print(res)

Failing test case input:
4
0
1
0
0

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
N = int(input())
a = []
for _ in range(N): a.append(int(input()))
if a[0] != 0:
  print(-1)
  exit(0)
for i in range(N - 1):
  if a[i + 1] > a[i] and (a[i + 1] - a[i] > 1):
    print(-1)
    exit(0)
res = 0
s = 0
x = 1
for i in range(1, N):
  if a[i] == x:
    s += 1
  else:
    if x > 0: res += (s - 1) * x + 1
    if x > a[i] and a[i] > 1:
      res += a[i] - 1
    s = 1
    x = a[i]
  
if x > 0: res += (s - 1) * x + 1
print(res)

Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(input()) for _ in range(N)]
if A[0] > 0:
    print(-1)
else:
    ans = 0
    for n in range(N-1, -1, -1):
        if A[n] - A[n-1] > 1 or A[n] > n:
            print(-1)
            break
        else:
            if A[n] - A[n-1] == 1:
                ans += 1
            else:
                ans += A[n]
    print(ans)


Failing test case input:
9
-1
0
1
0
2
1
2
2
3

Expected output:
-1


Actual output:
-1
5


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(input()) for _ in range(N)]
if A[0] > 0:
    print(-1)
else:
    ans = 0
    for n in range(N-1, -1, -1):
        if A[n] - A[n-1] > 1 or A[n] > n:
            print(-1)
            break
        else:
            if A[n] - A[n-1] == 1:
                ans += 1
            else:
                ans += A[n]
    else:
        print(ans)
Problem: p03347
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))
A.append(0)
a0 = 0
res = 0
for i, a in enumerate(A):
    if i < a:
        print(-1)
        exit()
    if a0 >= a:
        res += a0
    a0 = a
print(res)

Failing test case input:
9
0
-1
-1
-1
-1
2
1
1
-2

Expected output:
-1


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))
A.append(0)
if A[0]!=0:
    print(-1)
    exit()
a0 = 0
res = 0
for a in A:
    if a0 >= a:
        res += a0
    elif a - a0 >= 2:
        print(-1)
        exit()
    a0 = a
print(res)

Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = []
ans = 0
flag = True
for i in range(n):
    A = int(input())
    a.append(A)
next = 0
for i in range(n-1,-1,-1):
    if a[i] == 0:
        next = 0
        continue
    if next - a[i] == 1:
        next = a[i]
        continue
    if next - a[i] >= 2:
        flag = False
        break
    next = a[i]
    ans += a[i]
if a[0] != 0:
    flag = False




print(-1)


Failing test case input:
9
0
1
1
0
1
2
2
1
2

Expected output:
8

Actual output:
-1


Fixed submission (verdict: Accepted):
n = int(input())
a = []
ans = 0
flag = True
for i in range(n):
    A = int(input())
    a.append(A)
next = 0
for i in range(n-1,-1,-1):
    if next - a[i] >= 2:
        flag = False
        break
    if a[i] == 0:
        next = 0
        continue
    if next - a[i] == 1:
        next = a[i]
        continue
    next = a[i]
    ans += a[i]
if a[0] != 0:
    flag = False
if flag:
    print(ans)
else:
    print(-1)

Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
lis = [int(input()) for i in range(n)]
if lis[0] != 0:print(-1);exit()
ans = 0
for i in range(n-1,0,-1):
    if lis[i-1] - lis[i] > 1:print(-1);exit()
    elif lis[i-1] - lis[i] == 1:ans += 1
    else:ans += lis[i]
print(ans)

Failing test case input:
9
0
1
1
0
2
2
2
1
3

Expected output:
-1


Actual output:
13


Fixed submission (verdict: Accepted):
n = int(input())
lis = [int(input()) for i in range(n)]
if lis[0] != 0:print(-1);exit()
ans = 0
for i in range(n-1,0,-1):
    if lis[i] - lis[i-1] > 1:print(-1);exit()
    elif lis[i] - lis[i-1] == 1:ans += 1
    else:ans += lis[i]
print(ans)
Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(input()) for _ in range(N)]

if A[0] != 0:
    print(-1)
    exit()

ans = 0
for i in reversed(range(N)):
    if i == N-1:  
        ans += A[i]
    else:
        if A[i] - A[i-1] > 1:
            print(-1)
            exit()
        elif A[i] == A[i+1]:
            ans += A[i]
        elif A[i] == A[i+1] - 1:
            continue
        elif A[i+1] == 0:
            ans += A[i]


print(ans)

Failing test case input:
4
0
0
0
2

Expected output:
-1


Actual output:
2


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(input()) for _ in range(N)]

if A[0] != 0:
    print(-1)
    exit()

ans = 0
tmp = 0
for num in reversed(A):
    if tmp > 0:
        if num == tmp-1:
            tmp = num
        elif num >= tmp:
            ans += num
            tmp = num
        elif num < tmp-1:
            print(-1)
            exit()

    else:
        ans += num
        tmp = num
        

print(ans)

Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = []
ans = 0
for _ in range(n):
    a.append(int(input()))
if a[0] != 0:
    ans = -1
else:
    for i in range(n - 1):
        if (a[i+1] - a[i]) > 1:
            ans = -1
            break
        else:
            if a[i+1] == a[i]:
                ans += a[i+1] - 1
            if a[i+1] > 0:
                ans += 1
            
print(ans)

Failing test case input:
4
0
1
0
0

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
n = int(input())
a = []
ans = 0
for _ in range(n):
    a.append(int(input()))
if a[0] != 0:
    ans = -1
else:
    for i in range(n - 1):
        if (a[i+1] - a[i]) > 1:
            ans = -1
            break
        else:
            if a[i+1] == a[i]:
                if a[i+1] > 0:
                    ans += a[i+1] - 1
            if a[i+1] > 0:
                ans += 1
            if a[i+1] < a[i]:
                if a[i+1] > 1:
                    ans += a[i+1] - 1
            
print(ans)

Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from sys import stdin
N = int(stdin.readline().rstrip())
A = [0] * N
for i in range(N):
    A[i] = int(stdin.readline().rstrip())

if A[0] != 0:
    print(-1)
else:
    ans = 0
    for j in range(N-1):
        if A[j]+1 == A[j+1]:
            ans += 1
        else:
            ans += A[j+1]
        if A[j+1] - A[j] > 1:
            print(-1)
            break
    print(ans)

Failing test case input:
9
0
1
1
-1
2
1
2
3
0

Expected output:
-1


Actual output:
-1
3


Fixed submission (verdict: Accepted):
from sys import stdin
N = int(stdin.readline().rstrip())
A = [0] * N
for i in range(N):
    A[i] = int(stdin.readline().rstrip())

if A[0] != 0:
    print(-1)
else:
    ans = 0
    for j in range(N-1):
        if A[j]+1 == A[j+1]:
            ans += 1
        else:
            ans += A[j+1]
        if A[j+1] - A[j] > 1:
            ans = -1
            break
    print(ans)
Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):




def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    X = [0 for i in range(N)]

    if A[0] != 0:
        print(-1)
        return

    count = 0

    for i in range(N - 1, -1, -1):
        if A[i] > i:
            print(-1)
            return
        if i != N - 1:
            X[i] = max(0, X[i + 1] - 1)
        if A[i] == X[i]:
            continue

        count += A[i]
        X[i] = A[i]

    print(count)


if __name__ == '__main__':
    main()


Failing test case input:
9
0
-1
-1
-1
-1
2
0
1
-2

Expected output:
-1


Actual output:
-3


Fixed submission (verdict: Accepted):




def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    X = [0 for i in range(N)]
    A += [0]
    X += [0]

    count = 0

    if A[0] != 0:
        print(-1)
        return

    for i in range(N - 1, -1, -1):
        if A[i - 1] + 1 < A[i]:
            print(-1)
            return

        X[i] = max(0, X[i + 1] - 1)
        if A[i] == X[i]:
            continue

        count += A[i]
        X[i] = A[i]

    print(count)


if __name__ == '__main__':
    main()

Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
n=int(input())
a=[int(input()) for i in range(n)]
for i in range(n):
  if a[i]>i:
    print(-1)
    sys.exit()
ct=0
for i in range(n-1,0,-1):
  if a[i]-1==a[i-1]:
    ct+=1
  else:
    ct+=a[i]
print(ct)

Failing test case input:
9
-1
0
1
0
2
1
2
1
3

Expected output:
-1


Actual output:
10


Fixed submission (verdict: Accepted):
import sys
n=int(input())
a=[int(input()) for i in range(n)]
for i in range(n):
  if a[i]>i:
    print(-1)
    sys.exit()
ct=0
for i in range(n-1,0,-1):
  if a[i]-1>a[i-1]:
    print(-1)
    sys.exit()
  elif a[i]-1==a[i-1]:
    ct+=1
  else:
    ct+=a[i]
print(ct)

Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect

def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    a.append(0)
    ans = solve(a, n)
    print(ans)

def solve(a, n):
    base = 0
    s = 0
    for i in range(n):
        if a[i] > base + i:
            return -1
        
        if a[i + 1] <= a[i]:
            s += a[i]
        
        base = i - a[i]
    
    return s

main()

Failing test case input:
9
0
0
0
-1
-2
2
0
1
-2

Expected output:
-1


Actual output:
2


Fixed submission (verdict: Accepted):
import bisect

def main():
    n = int(input())
    a = []
    for _ in range(n):
        a.append(int(input()))
    a.append(0)
    ans = solve(a, n)
    print(ans)

def solve(a, n):
    if not check(a, n):
        return -1

    base = 0
    s = 0
    for i in range(n):
        if a[i] > base + i:
            return -1
        
        if a[i + 1] <= a[i]:
            s += a[i]
        
        base = i - a[i]
    
    return s

def check(a, n):
    if a[0] != 0:
        return False
    
    for i in range(1, n):
        if a[i] - a[i - 1] > 1:
            return False

    return True

main()
Problem: p03347
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
num_list = [ int(input()) for i in range(n) ]
num_list.reverse()

ans = 0
t = 0
for i in range(n):
    t = max(t-1, 0)
    if num_list[i] != 0 and num_list[i] > t:
        ans += num_list[i]
        t = num_list[i]
    elif num_list[i] != 0 and num_list[i] < t:
        ans = -1
        break

if t != 0:
    ans = -1
print(ans)


Failing test case input:
9
0
0
1
0
2
1
2
3
0

Expected output:
-1


Actual output:
6


Fixed submission (verdict: Accepted):
n = int(input())
num_list = [ int(input()) for i in range(n) ]
num_list.reverse()


ans = 0
t = 0
for i in range(n):
    t = max(t-1, 0)
    if num_list[i] != 0 and num_list[i] > t:
        ans += num_list[i]
        t = num_list[i]
    elif num_list[i] < t:
        ans = -1
        break

if t != 0:
    ans = -1
print(ans)

Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

def calc():
    count = 0
    value = 0
    for i in range(n - 1, -1, -1):
        if i == 0 and value > 0:
            return -1
        d = a[i] - value
        if d < 0:
            return -1
        if d > 0:
            count += a[i]
        value = max(0, a[i] - 1)
    return count
print(calc())

Failing test case input:
4
1
0
1
2

Expected output:
-1


Actual output:
3


Fixed submission (verdict: Accepted):
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

def calc():
    count = 0
    last = 0
    if a[0] > 0:
        return -1
    for v in a:
        if v > last + 1:
            return -1
        if v == last + 1:
            count += 1
        else:
            count += v
        last = v
    return count
print(calc())

Problem: p03347
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
A = [int(input()) for i in range(n)]

if A[0] != 0:
    print(-1)
    exit()

for i in range(1, n):
    if A[i] > A[i-1]+1:
        print(-1)
        exit()

ans = 0
for i in reversed(range(1, n)):
    if A[i-1] >= A[i]-1:
        ans += 1
    else:
        ans += A[i]

print(ans)


Failing test case input:
4
0
1
0
0

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):
n = int(input())
A = [int(input()) for i in range(n)]

if A[0] != 0:
    print(-1)
    exit()

for i in range(1, n):
    if A[i] > A[i-1]+1:
        print(-1)
        exit()

ans = 0
for i in reversed(range(1, n)):
    if A[i-1] == A[i]-1:
        ans += 1
    else:
        ans += A[i]

print(ans)
Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
li=[0]*n
for i in range(n):
    li[i]=int(input())
fl=0
ans=0
if li[0]!=0:
    fl+=1
for i in range(n-1):
    if li[i]>=li[i+1]:
        ans+=li[i]
    if li[i+1]-li[i]>1:
        fl+=1
if fl>0:
    print(-1)
else:
    print(ans)
        

Failing test case input:
9
0
1
1
0
1
2
2
1
2

Expected output:
8

Actual output:
6


Fixed submission (verdict: Accepted):
n=int(input())
li=[0]*n
for i in range(n):
    li[i]=int(input())
fl=0
ans=0
if li[0]!=0:
    fl+=1
for i in range(n-1):
    if li[i]>=li[i+1]:
        ans+=li[i]
    if li[i+1]-li[i]>1:
        fl+=1
if fl>0:
    print(-1)
else:
    print(ans+li[n-1])

Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
N = int(input())
A = [0]*N
for i in range(N):
	A[i] = int(input())

for i in range(N):
	if A[i] > i:
		print(-1)
		sys.exit(0)

res = 0
for i in range(N-1):
	if A[i] + 1 != A[i+1]:
		res += A[i]

res += A[N-1]

print(res)


Failing test case input:
9
0
-1
-1
-1
-1
2
1
1
-2

Expected output:
-1


Actual output:
-2


Fixed submission (verdict: Accepted):
import sys
N = int(input())
A = [0]*N
for i in range(N):
	A[i] = int(input())

cmax = -1
for i in range(N):
	if A[i] > cmax + 1:
		print(-1)
		sys.exit(0)
	elif A[i] == cmax + 1:
		cmax += 1
	else:
		cmax = A[i]
		
res = 0
for i in range(N-1):
	if A[i] + 1 != A[i+1]:
		res += A[i]

res += A[N-1]

print(res)

Problem: p03347
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
A = [-1]
b = -1
append = A.append
for i in range(N):
    a = int(input())
    if b + 1 < a:
        print(-1)
        exit()
    append(a)
    b = a
A.append(0)
ans = 0
for i in range(1,N+1):
    if A[i-1] != 0:
        if A[i-1] == A[i]-1:
            ans += 1
        elif A[i] == 0 or A[i] == 1:
            ans += 1
        else:
            ans += 2

print(ans)

Failing test case input:
4
0
1
0
0

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
a = [int(input()) for _ in range(n)]
ans = 0
for i in range(n-1,-1,-1):
    if i == 0:
        if a[i] != 0:
            print(-1)
            exit()
    else:
        if a[i-1] + 1 < a[i]:
            print(-1)
            exit()
        elif a[i-1] + 1 == a[i]:
            ans += 1
        else:
            ans += a[i]
print(ans)
Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys,collections,random,math;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n = I()
d = collections.defaultdict(int)
for i in range(n):
    d[I()] = i
d[0] = n
t,maxinc = 0,0
for i in range(1,n+1):
    if d[i-1] < d[i]:
        t += 1
        maxinc = max(maxinc,t)
    else:
        t = 0
print(n-1-maxinc)

Failing test case input:
9
-1
0
1
0
2
0
2
2
2

Expected output:
-1


Actual output:
7


Fixed submission (verdict: Accepted):
import sys,collections,random,math;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n = I()
t = I()
if t != 0:
    print(-1)
    exit()
sums = 0
for i in range(n-1):
    c = I()
    if c-t > 1 or c > i+1:
        print(-1)
        exit()
    if c-t != 1:
        sums += t
        s = 0
    if i == n-2:
        sums += c
    t = c
print(sums)

Problem: p03347
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys

N = int(input())

A = []

for i in range(N):

    a = int(input())
    A.append(a)

if A[0] != 0:
    print (-1)
    sys.exit()

A.reverse()

ans = 0

for i in range(N):

    if i == 0:
        ans += A[i]

    else:

        if A[i-1] - 1 > A[i]:
            print (-1)
            sys.exit()

        else:
            ans += A[i] - (A[i-1]-1)

print (ans)


Failing test case input:
4
0
1
0
0

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):
import sys

N = int(input())

A = []

for i in range(N):

    a = int(input())
    A.append(a)

if A[0] != 0:
    print (-1)
    sys.exit()

A.reverse()

ans = 0

for i in range(N):

    if i == 0:
        ans += A[i]

    else:

        if A[i-1] - 1 > A[i]:
            print (-1)
            sys.exit()

        elif A[i-1] -1 == A[i]:
            pass

        else:
            ans += A[i]

print (ans)

Problem: p03347
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
A = [int(input()) for _ in range(N)]

if A[0] != 0:
    print(-1)
    exit()
ans = A[-1]
now = A[-1] + 1

for a in A[::-1]:
    now -= 1
    if a > now:
        ans += a - now
        now = a
    elif a < now:
        ans = -1
        break

print(ans)

Failing test case input:
4
0
1
0
0

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(input()) for _ in range(N)]

if A[0] != 0:
    print(-1)
    exit()
ans = A[-1]
now = A[-1] + 1

for a in A[::-1]:
    now -= 1
    if a > now:
        ans += a
        now = a
    elif a < now:
        ans = -1
        break

print(ans)
Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
if a[0] != 0:
    print("-1")
else:
    v = []
    for i in range(1, len(a)):
        v.append((a[i], -i))
    v.sort()
    x = [0] * len(a)
    wala = False
    for y in v:
        
        
        if x[-y[1]] == 0:
            continue
        elif x[-y[1] - 1] + 1 == y[0]:
            x[-y[1]] = y[0]
        else:
            wala = True
            break
    if wala:
        print("-1")
    else:
        print(len(a) - a.count(0) + 1)

    

Failing test case input:
9
0
1
1
0
2
2
2
1
2

Expected output:
-1


Actual output:
8


Fixed submission (verdict: Accepted):
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
if a[0] != 0:
    print("-1")
else:
    x = [0] * len(a)
    d = [0] * len(a)
    dd = [0] * len(a)

    c = 0
    s = 10**6
    
    wala = False
    for i in range(len(a) - 1, 0, -1):
        
        if i <= s and a[i] == 0:
            
            continue
        if i - a[i] < 0 or i - a[i] > s:
            
            wala = True
            break
        if s + a[i] == i:
            continue
        s = min(s, i - a[i])
        c += a[i]
    if wala:
        print("-1")
    else:
        print(c)

Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
c = 0
A = []
for i in range(N):
  a = int(input())
  if a > i:
    c = 1
  A.append(a)

ans = 0
if c == 1:
  ans = -1
else:
  for i in range(1,N):
    if A[i] == A[i-1]+1:
      if i == N-1:
        ans += A[i]
      continue
    else:
      ans += A[i-1]  
print(ans)  

Failing test case input:
9
0
1
1
0
2
2
2
1
3

Expected output:
-1


Actual output:
9


Fixed submission (verdict: Accepted):
N = int(input())
c = 0
A = []
for i in range(N):
  a = int(input())
  if a > i:
    c = 1
  if i >=1 and a > A[i-1]+1:
    c = 1
  A.append(a)

ans = 0
if c == 1:
  ans = -1
else:
  for i in range(1,N):
    if A[i] == A[i-1]+1:
      if i == N-1:
        ans += A[i]
      continue
    else:
      ans += A[i-1]  
      if i == N-1:
        ans += A[i]
      continue      
print(ans)
Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

from collections import defaultdict


def getlist():
	return list(map(int, input().split()))


def main():
	N = int(input())
	A = []
	for i in range(N):
		a = int(input())
		A.append(a)

	if A[0] != 0:
		print(-1)
	else:
		ans = 0
		for i in range(N - 1):
			if A[-1 - i] == A[-2 - i] + 1:
				ans += 1
			else:
				ans += A[-1 - i]
		print(ans)

if __name__ == '__main__':
	main()

Failing test case input:
9
0
1
1
-1
2
1
2
3
0

Expected output:
-1


Actual output:
6


Fixed submission (verdict: Accepted):

from collections import defaultdict


def getlist():
	return list(map(int, input().split()))


def main():
	N = int(input())
	A = []
	for i in range(N):
		a = int(input())
		A.append(a)

	if A[0] != 0:
		print(-1)
	else:
		judge = "Yes"
		ans = 0
		for i in range(N - 1):
			if A[-1 - i] == A[-2 - i] + 1:
				ans += 1
			elif A[-1 - i] <= A[-2 - i]:
				if A[-1 - i] <= N - 1 - i:
					ans += A[-1 - i]
				else:
					judge = "No"
					break
			else:
				judge = "No"
				break
		if judge == "No":
			print(-1)
		else:
			print(ans)

if __name__ == '__main__':
	main()

Problem: p03347
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N = int(input())
A = []
for i in range(N):
  temp = int(input())
  A.append(temp)
if A[0] != 0:
  print(-1)
  exit()
ans = 0
prev = 0

for i in range(1,N+1):
  
  if A[-i] > N-i:
    print(-1)
    exit()
  if prev == 0:
    prev = A[-i]
    ans += A[-i]
  else:
    if A[-i] == prev-1:
      prev = A[-i]
    elif A[-i] > prev-1:
      prev = A[-i] 
      ans += prev
print(ans)


Failing test case input:
4
0
0
0
2

Expected output:
-1


Actual output:
2


Fixed submission (verdict: Accepted):
N = int(input())
A = []
for i in range(N):
  temp = int(input())
  A.append(temp)
if A[0] != 0:
  print(-1)
  exit()
ans = 0
prev = 0

for i in range(1,N+1):
  
  if A[-i] > N-i:
    print(-1)
    exit()
  if prev == 0:
    prev = A[-i]
    ans += A[-i]
  else:
    if A[-i] == prev-1:
      prev = A[-i]
    elif A[-i] > prev-1:
      prev = A[-i] 
      ans += prev
    else:
      print(-1)
      exit()
print(ans)

Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=[]
for _ in range(n):
	a.append(int(input()))
a.append(0)

if a[0]!=0:
	print(-1)
else:
	ans=0
	for i in range(n):
		if a[i+1]!=a[i]+1:
			ans+=a[i]
	print(ans)


Failing test case input:
9
0
0
1
0
2
1
2
3
0

Expected output:
-1


Actual output:
6


Fixed submission (verdict: Accepted):
n=int(input())
a=[]
for _ in range(n):
	a.append(int(input()))
a.append(0)

def ans():
	if a[0]>0:
		return -1
	else:
		ans=0
		for i in range(n):
			if a[i+1]-a[i]>1:
				return -1
			elif a[i+1]-a[i]<1:
				ans+=a[i]
		return ans

print(ans())
Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = [int(input()) for i in range(n)]
ans,flag = 0,True
for i in range(n-1):
	if a[i]+1==a[i+1]: ans+=1
	elif a[i]>=a[i+1]: ans+=a[i+1]
	else:
		flag = False
		break
if flag: print(ans)
else: print(-1)

Failing test case input:
3
1
-1
-2

Expected output:
-1


Actual output:
-3


Fixed submission (verdict: Accepted):
n = int(input())
a = [int(input()) for i in range(n)]
ans,flag = 0,True
if a[0]!=0: flag = False
for i in range(n-1):
	if a[i]+1==a[i+1]: ans+=1
	elif a[i]>=a[i+1]: ans+=a[i+1]
	else:
		flag = False
		break
if flag: print(ans)
else: print(-1)

Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(input()) for _ in range(N)]

if A[0] != 0:
    print(-1)
    exit()

ans = 0
for i in reversed(range(N)):
    if i == N-1:  
        ans += A[i]
    else:
        if A[i+1] != 0 and A[i] > A[i+1]:
            print(-1)
            exit()
        elif A[i] == A[i+1]:
            ans += A[i]
        elif A[i] == A[i+1] - 1:
            continue
        elif A[i+1] == 0:
            ans += A[i]


print(ans)

Failing test case input:
4
0
0
0
2

Expected output:
-1


Actual output:
2


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(input()) for _ in range(N)]

if A[0] != 0:
    print(-1)
    exit()

ans = 0
tmp = 0
for num in reversed(A):
    if tmp > 0:
        if num == tmp-1:
            tmp = num
        elif num >= tmp:
            ans += num
            tmp = num
        elif num < tmp-1:
            print(-1)
            exit()

    else:
        ans += num
        tmp = num
        

print(ans)

Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(input()) for i in range(N)]
B = []
if A[0] != 0:
  p = -1
else:
  p = 0
for i in range(1, N):
  if A[i] - A[i-1] > 2:
    p = -1
  elif A[i] - A[i-1] <= 0:
    B.append(i-1)
if p == -1:
  print(p)
else:
  print(sum(A[B[i]] for i in range(len(B))) + A[N-1])

Failing test case input:
9
0
1
1
0
2
4
2
1
3

Expected output:
-1


Actual output:
11


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(input()) for i in range(N)]
B = []
if A[0] != 0:
  p = -1
else:
  p = 0
for i in range(1, N):
  if A[i] - A[i-1] >= 2:
    p = -1
  elif A[i] - A[i-1] <= 0:
    B.append(i-1)
if p == -1:
  print(p)
else:
  print(sum(A[B[i]] for i in range(len(B))) + A[N-1])