Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This comment is hidden because it contains spoiler information about the solution
If teams number is odd, that is the invalid inputs
same problem here too.
same here.
First, Think about how many elements are in the triangle.
First line of triangle has only 1 element, and second line has two, three.. until n+1.
So, total counts of elements is the sum of 1+2+3+...+(n-1)+n+n+1.
this can be solved by
S = 1 + 2 + ... + n + n+1
S = n+1 + n + ... + 2 + 1
Add Two equations seperately(left plus left, right plus right)
Then, it goes like this
2S = (n+2) + (n+2) + ... + (n+2) + (n+2)
Then
2S = (n+2)* (n+1)
and
S = (n+2) * (n+1) / 2
After this, look at the triangle again. you will see the triangle has a special property.
for example,
x x x 6
x x 4 5
x 2 3 4
0 1 2 3
sum of symmetric elements in the triangle become n. So, the above triangle can be rewritten like this
x x x 3
x x 3 3
x 3 3 3
3 3 3 3
Now, you already know how many n the triangle has.
So the result becomes like n * S = n * (n+1) * (n+2) /2