
def count(t, x):
    n = len(t)

    if n <= 1:
        return n

    t = sorted(t)
    t.reverse()

    b = 0
    i = 0

    while i < n:
        val = t[i]
        missing = x - val

        if i == n - 1:
            b += 1
            break

        if missing >= t[n - 1]:
            for j in range(n - 1, i + 1, -1):
                if t[j] <= missing:
                    n -= 1
                    b += 1
                    break
        else:
            b += 1
        i += 1

    return b


if __name__ == "__main__":
    print(count([1, 2, 3, 4], 10))  # 2
    print(count([4, 4, 4, 4], 5))  # 4
    print(count([7, 2, 3, 9], 10))  # 3
    print(count([1, 1, 1, 1], 2))  # 2
    print(count([1, 2, 3, 4, 5], 6))  # 3
    print(count([9, 1, 9, 2], 10))  # 3
    print(count([1], 1))  # 1
    # print(count([1, 999999999] * 10000, 10 ** 9))
    # print(count([614147109, 5854864, 919996679, 219247886, 964460446, 527283068, 712530523, 827595362, 780618698, 21040497, 121168269, 463933303,
    #              438140082, 859181251, 603789876, 828987523, 522680995, 721179640, 858841394, 709315534, 287993748, 530487706, 471920011, 836776217,
    #              569623156, 818812708, 993165614, 774519939, 141566662, 303782867, 62796717, 420487740, 636228490, 206235559, 478151172, 691705857,
    #              137073764, 386606979, 695999010, 589960002, 459787879, 139097148, 112020350, 422997135, 518149026, 693331705, 606325405, 146532723,
    #              695959336, 465639051, 40513951, 186983748, 289991039, 242989370, 707527096, 352033057, 937132826, 256823865, 435529599, 847851681,
    #              997835691, 948288451, 518541947, 649806771, 619810814, 591728368, 254712576, 249573642, 46006569, 138720126, 689357772, 169231609,
    #              88167784, 30588186, 890654371, 722569781, 405956386, 977971322, 506152638, 520399581, 251807743, 413581, 527553779, 841808105,
    #              423983954, 624631437, 423944217, 84732368, 834909053, 766664176, 273273578] * 1000, 10 ** 9))

ed4c8b2ea55e6411ae6ac4c91184baf65d7d7fec
<mask token>

def count(t, x):
    n = len(t)
    if n <= 1:
        return n
    t = sorted(t)
    t.reverse()
    b = 0
    i = 0
    while i < n:
        val = t[i]
        missing = x - val
        if i == n - 1:
            b += 1
            break
        if missing >= t[n - 1]:
            for j in range(n - 1, i + 1, -1):
                if t[j] <= missing:
                    n -= 1
                    b += 1
                    break
        else:
            b += 1
        i += 1
    return b


<mask token>

def count(t, x):
    n = len(t)
    if n <= 1:
        return n
    t = sorted(t)
    t.reverse()
    b = 0
    i = 0
    while i < n:
        val = t[i]
        missing = x - val
        if i == n - 1:
            b += 1
            break
        if missing >= t[n - 1]:
            for j in range(n - 1, i + 1, -1):
                if t[j] <= missing:
                    n -= 1
                    b += 1
                    break
        else:
            b += 1
        i += 1
    return b


if __name__ == '__main__':
    print(count([1, 2, 3, 4], 10))
    print(count([4, 4, 4, 4], 5))
    print(count([7, 2, 3, 9], 10))
    print(count([1, 1, 1, 1], 2))
    print(count([1, 2, 3, 4, 5], 6))
    print(count([9, 1, 9, 2], 10))
    print(count([1], 1))


def count(t, x):
    n = len(t)

    if n <= 1:
        return n

    t = sorted(t)
    t.reverse()

    b = 0
    i = 0

    while i < n:
        val = t[i]
        missing = x - val

        if i == n - 1:
            b += 1
            break

        if missing >= t[n - 1]:
            for j in range(n - 1, i + 1, -1):
                if t[j] <= missing:
                    n -= 1
                    b += 1
                    break
        else:
            b += 1
        i += 1

    return b


if __name__ == "__main__":
    print(count([1, 2, 3, 4], 10))  # 2
    print(count([4, 4, 4, 4], 5))  # 4
    print(count([7, 2, 3, 9], 10))  # 3
    print(count([1, 1, 1, 1], 2))  # 2
    print(count([1, 2, 3, 4, 5], 6))  # 3
    print(count([9, 1, 9, 2], 10))  # 3
    print(count([1], 1))  # 1
    # print(count([1, 999999999] * 10000, 10 ** 9))
    # print(count([614147109, 5854864, 919996679, 219247886, 964460446, 527283068, 712530523, 827595362, 780618698, 21040497, 121168269, 463933303,
    #              438140082, 859181251, 603789876, 828987523, 522680995, 721179640, 858841394, 709315534, 287993748, 530487706, 471920011, 836776217,
    #              569623156, 818812708, 993165614, 774519939, 141566662, 303782867, 62796717, 420487740, 636228490, 206235559, 478151172, 691705857,
    #              137073764, 386606979, 695999010, 589960002, 459787879, 139097148, 112020350, 422997135, 518149026, 693331705, 606325405, 146532723,
    #              695959336, 465639051, 40513951, 186983748, 289991039, 242989370, 707527096, 352033057, 937132826, 256823865, 435529599, 847851681,
    #              997835691, 948288451, 518541947, 649806771, 619810814, 591728368, 254712576, 249573642, 46006569, 138720126, 689357772, 169231609,
    #              88167784, 30588186, 890654371, 722569781, 405956386, 977971322, 506152638, 520399581, 251807743, 413581, 527553779, 841808105,
    #              423983954, 624631437, 423944217, 84732368, 834909053, 766664176, 273273578] * 1000, 10 ** 9))
