Ad
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    If teams number is odd, that is the invalid inputs

  • Custom User Avatar

    same problem here too.

  • Custom User Avatar
  • Custom User Avatar

    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