ZhenlongDai/ACPR huggingface dataset:
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:
    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
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)]

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 (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 = 0
for i in reversed(range(1, n)):
    if A[i-1] >= A[i]-1:
        ans += 1
    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()

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):




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

    count = 0

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

        one_index = i - A[i] + 1

        if one_index <= 0:
            count = -1
            break

        for j in range(one_index, i + 1):
            X[j] = X[j - 1] + 1
            count += 1

    print(count)


if __name__ == '__main__':
    main()


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

Expected output:
-1


Actual output:
7


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):
N = int(input())

start = int(input())
t = 0

for i in range(N-1):
 k = int(input())
 if k == start:
  t += start
 elif k == start + 1:
  t += 1
  start = k
 elif k == 0:
  start = 0
 elif k > start + 1:
  t = -1
  break
 else:
  t += k
  start = k

print(t)

Failing test case input:
3
2
1
-3

Expected output:
-1


Actual output:
-2


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

start = int(input())
flag = 0
if start != 0:
 flag = 1
t = 0

for i in range(N-1):
 k = int(input())
 if k == start:
  t += start
 elif k == start + 1:
  t += 1
  start = k
 elif k == 0:
  start = 0
 elif k > start + 1:
  t = -1
  break
 else:
  t += k
  start = k

if flag ==1:
 t = -1
print(t)

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 = 0
        break

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


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

Expected output:
-1


Actual output:
0


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())
ans = 0
sts = dict()
mi = 0

for i in range(n):
    ai = int(input())
    if i-ai >= mi:
        sts[i-ai] = ai
        if ai == 0:
            mi = i
    else:
        print(-1)
        exit()

for i in sts.values():
    ans += i
print(ans)


Failing test case input:
3
-2
1
0

Expected output:
-1


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
ans = 0
sts = dict()
mi = 0
bl = 0

for i in range(n):
    ai = int(input())
    if i-ai >= mi:
        sts[i-ai] = ai
        if bl >= ai:
            mi = i-ai
    else:
        print(-1)
        exit()
    bl = ai

for i in sts.values():
    ans += i
print(ans)
Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


def solve(N, A):
    c = 0
    z = 0
    if A[0] != 0:
        return -1
    for i in range(1, N):
        if A[i] == 0:
            z = 0
            c+=A[i-1]
        elif A[i] <= i - z:
            if A[i] != A[i-1]+1:
                c += A[i-1]
        else:
            return -1
        
    c += A[-1]
    return c

def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    A = [0]*N
    for i in range(N):
        A[i] = int(input())
    print(solve(N, A))

main()


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

Expected output:
-1


Actual output:
-3


Fixed submission (verdict: Accepted):


def solve(N, A):
    c = 0
    z = 0
    if A[0] != 0:
        return -1
    for i in range(1, N):
        if A[i] == 0:
            z = 0
            c+=A[i-1]
        elif A[i-1] < A[i] - 1:
            return -1
        elif A[i] <= i - z:
            if A[i] != A[i-1]+1:
                c += A[i-1]
        else:
            return -1
        
    c += A[-1]
    return c

def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    A = [0]*N
    for i in range(N):
        A[i] = int(input())
    print(solve(N, A))

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)]

ans = 0
for i in range(n):
    if i == 0:
        if a[i] != 0:
            ans = -1
            break
    elif a[i] > i:
        ans = -1
        break

    else:

        if a[i] == a[i-1] + 1:
            continue
        else:
            ans += a[i-1]

if ans == -1:
    print(-1)
    sys.exit()

if a[n-1] == a[n-2] + 1:
    ans += a[n-1]

print(ans)


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

Expected output:
-1


Actual output:
1


Fixed submission (verdict: Accepted):
import sys

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

ans = 0
for i in range(n):
    if i == 0:
        if a[i] != 0:
            ans = -1
            break
    elif a[i] > i:
        ans = -1
        break

    else:
        if a[i] == a[i-1] + 1:
            continue
        else:
            if a[i] >= a[i-1] + 2:
                ans = -1
                break
            ans += a[i-1]

if ans == -1:
    print(-1)
    sys.exit()

ans += a[n-1]

print(ans)
Problem: p03347
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
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())

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)]

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):




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] == X[i]:
            continue

        one_index = i - A[i] + 1

        if one_index <= 0:
            count = -1
            break

        for j in range(one_index, i + 1):
            X[j] = X[j - 1] + 1
            count += 1

    print(count)


if __name__ == '__main__':
    main()


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

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):
N=int(input())
A=[int(input()) for i in range(N)]

if A[0]>0:
  print(-1)
  exit(0)
for i in range(1,N):
  if A[i-1]<A[i]-1 or A[i]>i:
    print(-1)
    exit(0)
ans=0
for i in reversed(range(1,N)):
  if A[i]<=A[i-1]+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(0)
for i in range(1,N):
  if A[i-1]+1<A[i]:
    print(-1)
    exit(0)
    

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

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

for i in range(a):
    t = int(input())
    l.append(t)
t =1
res = 0
for i in l:
    res += i
    t = i+1
if l[0] ==0 :print(res)
else:print(-1)


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

Expected output:
-1


Actual output:
10


Fixed submission (verdict: Accepted):
a = int(input())
l = []

for i in range(a):
    t = int(input())
    l.append(t)
t =1
res = 0
for i in l[::-1]:
    if i >= t:
        res += i
    elif t - i == 1:
        t = 1
    else:
        l[0] = 1
    t = i
if l[0] ==0 :print(res)
else:print(-1)

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

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

Expected output:
-1


Actual output:
7


Fixed submission (verdict: Accepted):
n = int(input())
a = [int(input()) for _ in range(n)]
ans = 0
if a[0] != 0:
    ans = -1
elif n == 1:
    ans = 0
else:
    b = a[1:]
    for k,i in enumerate(b):
        if i <= 1:
            ans += i
        else:
            num = i-a[k]
            if num == 1:
                ans += 1
            elif num <= 0:
                ans += i
            else:
                ans = -1
                break
print(ans)

Problem: p03347
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N=int(input())
A=[int(input()) for _ in range(N)]
tab = [0]*N
for i,a in enumerate(A):
    dst = i-a
    if dst < 0 or dst >=N:
        print(-1)
        exit()
    tab[dst] = max(tab[dst], a)
print(sum(tab))


Failing test case input:
9
0
1
1
-1
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)]
tab = [0]*N
prev=10**10
for i,a in enumerate(A):
    dst = i-a
    if dst < 0 or dst >=N or (a>prev and a-prev>1):
        print(-1)
        exit()
    tab[dst] = max(tab[dst], a)
    prev = a
print(sum(tab))

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] - lis[i-1] == 1:ans += 1
    else:ans += lis[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())
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.8.2), verdict: Wrong Answer):
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print(*a, **dict(file=sys.stderr, **kw))

N = ini()
A = [ini() for _ in range(N)]


def solve():
    c = 0
    ans = 0
    for i in range(N - 1, -1, -1):
        s = A[i]
        if s > i:
            return -1
        if s < c:
            return -1
        ans += s - c
        c = s - 1
    return ans


print(solve())


Failing test case input:
4
0
1
0
0

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print(*a, **dict(file=sys.stderr, **kw))

N = ini()
A = [ini() for _ in range(N)]


def solve():
    c = 0
    ans = 0
    for i in range(N - 1, -1, -1):
        s = A[i]
        if s > i:
            return -1
        if s < c:
            return -1
        if s > c:
            ans += s
        c = s - 1
    return ans


print(solve())

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

for i in range(a):
    t = int(input())
    l.append(t)
t =0
res = 0
for i in l[::-1]:
    res += max(0,i-t) 
    t = i-1
if l[0] ==0 :print(res)
else:print(-1)

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

Expected output:
-1


Actual output:
10


Fixed submission (verdict: Accepted):
a = int(input())
l = []

for i in range(a):
    t = int(input())
    l.append(t)
t =1
res = 0
for i in l[::-1]:
    if i >= t:
        res += i
    elif t - i == 1:
        t = 1
    else:
        l[0] = 1
    t = i
if l[0] ==0 :print(res)
else:print(-1)

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
        count += d
        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 (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(input()) for _ in range(N)]
if A[0]:
    print(-1)
    exit()
ans = A[-1]
for i in range(1, N):
    if A[i] > A[i - 1]:
        continue
    else:
        ans += A[i - 1]
print(ans)


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

Expected output:
-1


Actual output:
-2


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

Problem: p03347
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
a = [int(input()) for _ in range(n)]
for i in range(n):
    if i == 0:
        if a[i] != 0:
            print(-1)
            exit()
        else:
            if a[i] > a[i-1] + 1:
                print(-1)
                exit()

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

print(ans)

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

Expected output:
-1


Actual output:
14


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):
N = int(input())
A = [int(input()) for _ in range(N)]

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

ans = 0

maxLeft = 0
for i in range(1, N):
    if A[i] >= maxLeft + 2:
        print('-1')
        exit()
    else:
        maxLeft = max(maxLeft, A[i])
        if A[i] > 0:
            ans += 1

print(ans)

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

Expected output:
-1


Actual output:
5


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

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

ans = 0
prev = 0

for a in reversed(A):
    if prev > 0:
        if a == (prev - 1):
            prev = a
            continue
        elif a < prev:
            print(-1)
            exit()
    ans += a
    prev = a

print(ans)

Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
read = sys.stdin.read

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

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

Expected output:
-1


Actual output:
-7


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

n = int(input())
A = list(map(int, read().split()))
if A[0] != 0:
  print(-1)
else:
  ans = 0
  A += [0]
  for i in range(n):
    if A[i+1] - A[i] > 1:
      print(-1)
      exit()
    if A[i]+1 != A[i+1]:
      ans += A[i]
  print(ans)
Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main(n, A):
    if A[0] != 0:
        return - 1

    res = 0
    for x, y in zip(A[:-1], A[1:]):
        if x >= y:
            res += y
        else:
            res += y - x
    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
0

Expected output:
-1


Actual output:
7


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)]

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

ans = 0

maxLeft = 0
for i in range(1, N):
    if A[i] >= maxLeft + 2:
        print('-1')
        exit()
    else:
        maxLeft = max(maxLeft, A[i])
        ans += 1

print(ans)

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

Expected output:
-1


Actual output:
8


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

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

ans = 0
prev = 0

for a in reversed(A):
    if prev > 0:
        if a == (prev - 1):
            prev = a
            continue
        elif a < prev:
            print(-1)
            exit()
    ans += a
    prev = a

print(ans)

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-1]
print(ans)

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

Expected output:
-1


Actual output:
6


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 (PyPy3 (2.4.0), verdict: Wrong Answer):
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]
    pre = A[i]
    maxa += 1
print(ans)


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

Expected output:
-1


Actual output:
1


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):
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:
9
0
0
1
0
2
1
2
3
2

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 = 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):
import sys

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

ans = 0
for i in range(n):
    if i == 0:
        if a[i] != 0:
            ans = -1
            break
    elif a[i] > i:
        ans = -1
        break

    else:

        if a[i] == a[i-1] + 1:
            continue
        else:
            ans += a[i-1]

for i in range(n-1):
    if a[i] == 0 and a[i+1] >= 2:
        ans = -1
if ans == -1:
    print(-1)
    sys.exit()

ans += a[n-1]

print(ans)


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

Expected output:
-1


Actual output:
-2


Fixed submission (verdict: Accepted):
import sys

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

ans = 0
for i in range(n):
    if i == 0:
        if a[i] != 0:
            ans = -1
            break
    elif a[i] > i:
        ans = -1
        break

    else:
        if a[i] == a[i-1] + 1:
            continue
        else:
            if a[i] >= a[i-1] + 2:
                ans = -1
                break
            ans += a[i-1]

if ans == -1:
    print(-1)
    sys.exit()

ans += a[n-1]

print(ans)
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()
    elif nums[i] > 0:
        ans += r * 2
        if r > 0:
            ans -= 1
        r = 0
        p = nums[i]
        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())
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=[]
for i in range(n):
  A.append(int(input()))
ans=0
chk=True
cur=0
for i in reversed(range(n)):
  if A[i]==cur:
    cur-=1
    continue
  else:
    if A[i]>i:
      chk=False
    else:
      ans+=A[i]
      cur=A[i]-1
print(ans if chk else -1)

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

Expected output:
-1


Actual output:
9


Fixed submission (verdict: Accepted):
n=int(input())
A=[]
for i in range(n):
  A.append(int(input()))
ans=0
chk=True
cur=0
for i in reversed(range(n)):
  if A[i]==cur:
    cur-=1
    continue
  else:
    if A[i]>i or A[i]<cur:
      chk=False
    else:
      ans+=A[i]
      cur=A[i]-1
print(ans if chk else -1)

Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, *a = map(int, open(0).read().split())
ans = 0
if a[0] != 0:
	print(-1)
	exit()
for x, y in zip(a, a[1:]):
	if x + 1 < y:
		print(-1)
		exit()
	if x >= y:
		ans += x
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, *a = map(int, open(0).read().split())
ans = 0
if a[0] != 0:
	print(-1)
	exit()
for x, y in zip(a, a[1:]+[0]):
	if x + 1 < y:
		print(-1)
		exit()
	if x >= y:
		ans += x
print(ans)

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

Failing test case input:
3
0
4
1

Expected output:
-1


Actual output:
5


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 i in range(N)]

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

ans=0
for i in reversed(range(1,N)):
  if A[i]<=A[i-1]+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(0)
for i in range(1,N):
  if A[i-1]+1<A[i]:
    print(-1)
    exit(0)
    

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

Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from collections import deque

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

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

if __name__ =='__main__':
    main()  


Failing test case input:
4
0
0
0
2

Expected output:
-1


Actual output:
2


Fixed submission (verdict: Accepted):
MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from collections import deque

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

    if a[0] != 0:
        print(-1)
        return
    
    ans = a[-1]
    down = a[-1]
    stair = a[-1]
    for i in range(n - 2,-1,-1):
        down -= 1
        stair -= 1
        if down > a[i]:
            print(-1)
            return
        if stair == a[i]:
            continue
        down = max(down,a[i])
        stair = a[i]
        ans += stair
    
    print(ans)

if __name__ =='__main__':
    main()

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

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):
n = int(input())
ans = 0
sts = dict()
mi = 0
bl = 0

for i in range(n):
    ai = int(input())
    if i-ai >= mi:
        sts[i-ai] = ai
        if bl >= ai:
            mi = i-ai
    else:
        print(-1)
        exit()
    bl = ai

for i in sts.values():
    ans += i
print(ans)
Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=[int(input()) for i in range(n)]
a0=0
ans=0
for ai in a[::-1]:
  
  if ai>a0-1:
    ans+=ai
  elif ai<ai-1:
    print(-1)
    exit()
  a0=ai
  
if a0 !=0:
  print(-1)
else:
  print(ans)
  

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 i in range(n)]
a0=0
ans=0
for ai in a[::-1]:
  
  if ai>a0-1:
    ans+=ai
  elif ai<a0-1:
    print(-1)
    exit()
  a0=ai
  
if a0 !=0:
  print(-1)
else:
  print(ans)

Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = [int(input()) for _ in range(n)]
for i in range(1,n):
  if a[i]-a[i-1] > 1:
    print(-1)
    exit(0)
cnt = 0
cur = 0
for i in range(n-1,-1,-1):
  if cur < a[i]:
    cur = a[i]
    cnt += a[i]
  if cur:
    cur -= 1
print(cnt)

Failing test case input:
3
1
-1
-2

Expected output:
-1


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
a = [int(input()) for _ in range(n)]
if a[0] != 0:
  print(-1)
  exit(0)
cnt = 0
cur = 0
for i in range(n-1,-1,-1):
  if cur > a[i]:
    print(-1)
    exit(0)
  if cur < a[i]:
    cur = a[i]
    cnt += a[i]
  if cur > 0:
    cur -= 1
print(cnt)

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

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

Expected output:
-1


Actual output:
6


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

n = int(input())
A = list(map(int, read().split()))
if A[0] != 0:
  print(-1)
else:
  ans = 0
  A += [0]
  for i in range(n):
    if A[i+1] - A[i] > 1:
      print(-1)
      exit()
    if A[i]+1 != A[i+1]:
      ans += A[i]
  print(ans)

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

ans = 0
for i in range(n-1, 1, -1):
    if nums[i] - nums[i-1] > 1:
        print(-1)
        exit()
    if nums[i] == 0:
        continue
    if nums[i] - nums[i-1] == 1:
        ans += 1
    elif nums[i] - nums[i-1] == 0:
        ans += nums[i] + 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())
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 i in range(N)]

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

ans=0
for i in reversed(range(1,N)):
  if A[i]<=A[i-1]+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(0)
for i in range(1,N):
  if A[i-1]+1<A[i]:
    print(-1)
    exit(0)
    

ans=0
for i in reversed(range(1,N)):
  if A[i]==A[i-1]+1:
    ans+=1
  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)]
tab = [0]*N
for i,a in enumerate(A):
    dst = i-a+1
    if dst <= 0 or dst >=N:
        print(-1)
        exit()
    tab[dst] = max(tab[dst], a)
print(sum(tab))


Failing test case input:
9
-1
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)]
tab = [0]*N
prev=10**10
for i,a in enumerate(A):
    dst = i-a
    if dst < 0 or dst >=N or (a>prev and a-prev>1):
        print(-1)
        exit()
    tab[dst] = max(tab[dst], a)
    prev = a
print(sum(tab))

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
pos=n
pre=0
for i in range(n):
    x=a.pop()
    if x==0:
        continue
    elif x>pos-1:
        ans=-1
        break
    else:
        if x==pre-1:
            pre=x
            continue
        else:
            if x>=pre:
                pre=x
                ans+=x
            else:
                ans=-1
                break
    pos-=1
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):
    a.append(int(input()))

ans=0
pos=n
pre=0
b=a[0]
for i in range(n):
    x=a.pop()
    if x==0 and pre<=1:
        continue
    elif x>pos-1:
        ans=-1
        break
    else:
        if x==pre-1:
            pre=x
            continue
        else:
            if x>=pre:
                pre=x
                ans+=x
            else:
                ans=-1
                break
    pos-=1
if b>0:
    ans=-1
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 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
2
1
2
3
0

Expected output:
-1


Actual output:
6


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 (PyPy3 (7.3.0), verdict: Wrong Answer):
n = int(input())
ans = 0
now = int(input())
if now != 0:
    print(-1)
    exit()

for i in range(n-1):
    a = int(input())
    if a == now or a == now + 2:
        ans += a
        now = a
    elif a == now + 1:
        ans += 1
        now = a
    elif a == 1:
        ans += 1
        now = 1
    elif a == 0:
        now = 0
    else:
        print(-1)
        exit()
print(ans)

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

Expected output:
-1


Actual output:
10


Fixed submission (verdict: Accepted):
n = int(input())
ans = 0
now = int(input())
if now != 0:
    print(-1)
    exit()
zero = 0
for i in range(n-1):
    a = int(input())
    if a == now + 1:
        ans += 1
        now = a
    elif a <= now:
        ans += a
        zero = i-a
        now = a
    elif a >= now + 2:
        print(-1)
        exit()
print(ans)

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

if x[0]>0: f = 1
for i in range(n-1):
    if x[i]+1 < x[i+1]: f = 1
import sys
if f:
    print(-1)
    sys.exit()
ans = 0
for i in range(n-1):
    if x[i+1] == x[i]+1:
        ans += 1
    else:
        ans += x[i+1]
    print(ans)
print(ans)

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

Expected output:
8

Actual output:
1
2
2
3
4
6
7
8
8


Fixed submission (verdict: Accepted):
n = int(input())
x = [int(input()) for _ in range(n)]
f = 0

if x[0]>0: f = 1
for i in range(n-1):
    if x[i]+1 < x[i+1]: f = 1
import sys
if f:
    print(-1)
    sys.exit()
ans = 0
for i in range(n-1):
    if x[i+1] == x[i]+1:
        ans += 1
    else:
        ans += x[i+1]
print(ans)
Problem: p03347
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def main():
    n = int(input())
    a = []
    for _ in range(n):
        a.append(int(input()))
    ans = 0
    for i in range(n):
        if a[i]>i:
            print(-1)
            return
    for i in range(n-1):
        if a[-1-i] <= a[-2-i]:
            ans += 1
        elif a[-1-i] == a[-2-i]+1:
            ans += 1
        else:
            print(-1)
            return
    print(ans)

if __name__ == "__main__":
    main()

Failing test case input:
4
0
1
0
0

Expected output:
1


Actual output:
3


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

if __name__ == "__main__":
    main()

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 = 0
for i in reversed(range(1, n)):
    if A[i-1] >= A[i]-1:
        ans += 1

print(ans)


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

Expected output:
-1


Actual output:
7


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):
import sys
input = sys.stdin.readline
n = int(input())
a = [int(input()) for i in range(n)]
cur = -1
c = 0
for i in a:
  pre,cur = cur,i
  if cur == 0:
    continue
  elif cur <= pre + 1:
    c += 1
  else:
    print(-1)
    exit()
print(c)

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

Expected output:
8

Actual output:
7


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
n = int(input())
a = [int(input()) for i in range(n)]
cur = -1
c = 0
for i in a:
  pre,cur = cur,i
  if cur == 0:
    continue
  elif cur == pre + 1:
    c += 1
  elif cur <= pre:
    c += cur
  else:
    print(-1)
    exit()
print(c)
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
-1
-1
-2
2
1
1
-2

Expected output:
-1


Actual output:
3


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 (PyPy3 (2.4.0), verdict: Wrong Answer):
n=int(input())
A=[int(input()) for _ in range(n)]

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

cnt,length=0,0
for i in range(n-1):
    if A[i]!=0:length +=1
    else:length=0

    if A[i]<=length:
        if A[i]+1==A[i+1]:cnt +=1
        else:cnt +=A[i+1]
    else:print(-1);exit()
print(cnt)

Failing test case input:
9
0
0
-1
-1
-2
2
1
1
-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()

cnt,length=0,0
for i in range(n-1):
    if A[i]!=0:length +=1
    else:length=0

    if A[i]<=length:
        if A[i]+1==A[i+1]:cnt +=1
        elif A[i+1]-A[i]>1:print(-1);exit()
        else:cnt +=A[i+1]
    else:print(-1);exit()
print(cnt)

Problem: p03347
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input=sys.stdin.readline
n=int(input())
a=[int(input()) for _ in range(n)]
if a[0]!=0:
    print(-1)
    exit()

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

print(ans)


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

Expected output:
-1


Actual output:
10


Fixed submission (verdict: Accepted):
import sys
input=sys.stdin.readline
n=int(input())
a=[int(input()) for _ in range(n)]
if a[0]!=0:
    print(-1)
    exit()

ans=0
for i in range(1,n):
    if a[i]>a[i-1]+1:
        print(-1)
        exit()
    if a[i]==a[i-1]+1:
        ans+=1
    else:
        ans+=a[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
if a[0] != 0:
    ans = -1
else:
    b = a[1:]
    for k,i in enumerate(b):
        if i <= 1:
            ans += i
        else:
            num = i-a[k]
            if num >= 1:
                ans += 1
            elif num == 0:
                ans += i
            else:
                ans = -1
                break
print(ans)

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

Expected output:
-1


Actual output:
7


Fixed submission (verdict: Accepted):
n = int(input())
a = [int(input()) for _ in range(n)]
ans = 0
if a[0] != 0:
    ans = -1
elif n == 1:
    ans = 0
else:
    b = a[1:]
    for k,i in enumerate(b):
        if i <= 1:
            ans += i
        else:
            num = i-a[k]
            if num == 1:
                ans += 1
            elif num <= 0:
                ans += i
            else:
                ans = -1
                break
print(ans)

Problem: p03347
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
ans = 0
bn = int(input())
if not bn == 0:
    print(-1)
    exit()
for i in range(n-1):
    ai = int(input())
    if ai <= bn:
        ans += ai
        bn = ai
        continue
    ans += (ai-bn)
    bn = ai

print(ans)


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

Expected output:
-1


Actual output:
-6


Fixed submission (verdict: Accepted):
n = int(input())
ans = 0
sts = dict()
mi = 0
bl = 0

for i in range(n):
    ai = int(input())
    if i-ai >= mi:
        sts[i-ai] = ai
        if bl >= ai:
            mi = i-ai
    else:
        print(-1)
        exit()
    bl = ai

for i in sts.values():
    ans += i
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, 1]:
    print(1)
    exit()
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

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])