def max_non_overlapping_dominos(n: int, heights: List[int]) -> int:
    """
    You are given a Young diagram.
    
    Given diagram is a histogram with $n$ columns of lengths $a_1, a_2, \ldots, a_n$ ($a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$). [Image] Young diagram for $a=[3,2,2,2,1]$.
    
    Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a $1 \times 2$ or $2 \times 1$ rectangle.
    
    
    -----Input-----
    
    The first line of input contain one integer $n$ ($1 \leq n \leq 300\,000$): the number of columns in the given histogram.
    
    The next line of input contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 300\,000, a_i \geq a_{i+1}$): the lengths of columns.
    
    
    -----Output-----
    
    Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
    
    
    -----Example-----
    Input
    5
    3 2 2 2 1
    
    Output
    4
    
    
    
    -----Note-----
    
    Some of the possible solutions for the example:
    
    [Image] $\square$
    """


# Tests

def check(candidate):
    assert max_non_overlapping_dominos(5, [3, 2, 2, 2, 1]) == 4
    assert max_non_overlapping_dominos(5, [1, 1, 1, 1, 1]) == 2
    assert max_non_overlapping_dominos(3, [3, 3, 3]) == 4
    assert max_non_overlapping_dominos(1, [1]) == 0
    assert max_non_overlapping_dominos(10, [9, 8, 7, 7, 6, 4, 3, 2, 1, 1]) == 23
    assert max_non_overlapping_dominos(10, [99, 83, 62, 53, 47, 33, 24, 15, 10, 9]) == 216
    assert max_non_overlapping_dominos(100, [100, 100, 99, 98, 97, 92, 92, 92, 92, 91, 89, 87, 87, 87, 86, 85, 84, 82, 82, 81, 81, 80, 79, 78, 78, 77, 77, 76, 76, 74, 72, 71, 71, 70, 69, 66, 64, 63, 63, 62, 60, 59, 59, 59, 55, 54, 53, 52, 52, 51, 49, 49, 49, 47, 47, 46, 46, 45, 44, 43, 42, 41, 41, 41, 40, 39, 38, 37, 37, 36, 31, 29, 25, 23, 22, 22, 21, 21, 20, 17, 17, 16, 15, 15, 14, 14, 13, 12, 12, 10, 9, 9, 8, 8, 8, 7, 4, 3, 3, 3]) == 2545
    assert max_non_overlapping_dominos(100, [494, 493, 483, 483, 482, 479, 469, 455, 452, 448, 446, 437, 436, 430, 426, 426, 423, 418, 417, 413, 409, 403, 402, 398, 388, 386, 384, 379, 373, 372, 366, 354, 353, 347, 344, 338, 325, 323, 323, 322, 310, 306, 303, 302, 299, 296, 291, 290, 288, 285, 281, 274, 258, 254, 253, 250, 248, 248, 247, 243, 236, 235, 233, 227, 227, 223, 208, 204, 200, 196, 192, 191, 185, 184, 183, 174, 167, 167, 165, 163, 158, 139, 138, 132, 123, 122, 111, 91, 89, 88, 83, 62, 60, 58, 45, 39, 38, 34, 26, 3]) == 13710
    assert max_non_overlapping_dominos(100, [1980, 1932, 1906, 1898, 1892, 1883, 1877, 1858, 1842, 1833, 1777, 1710, 1689, 1678, 1660, 1653, 1648, 1647, 1644, 1639, 1635, 1635, 1593, 1571, 1534, 1470, 1440, 1435, 1389, 1272, 1269, 1268, 1263, 1255, 1249, 1237, 1174, 1174, 1128, 1069, 1067, 981, 979, 979, 951, 915, 911, 906, 863, 826, 810, 810, 802, 785, 764, 752, 743, 710, 705, 696, 676, 661, 639, 619, 616, 572, 568, 549, 501, 464, 455, 444, 443, 434, 430, 427, 399, 386, 345, 339, 324, 324, 309, 300, 257, 255, 228, 195, 184, 182, 177, 148, 129, 112, 91, 65, 31, 31, 22, 3]) == 46496
    assert max_non_overlapping_dominos(1, [300000]) == 150000
check(max_non_overlapping_dominos)