n = int(input())
count = []
for i in range(n):
  a1 = list(map(int, input().split()))
  n1 = a1.count(1)
  count.append(n1)
ans = 0
for i in range(n):
  moya = count[:count[i]]
  ans += max(moya)
print(ans)
