520 ms
ruby\ndef pref t\n    rc = 0\n    x = (0..[t, 45 * 10 ** 12].min).bsearch do | x |\n        c = 0\n        d = 1\n        y = d << 1\n        while d <= x\n    
```ruby\ndef pref t\n    rc = 0\n    x = (0..[t, 45 * 10 ** 12].min).bsearch do | x |\n        c = 0\n        d = 1\n        y = d << 1\n        while d <= x\n            a, b = x .divmod y\n            c += a * d + (b - d.pred).clamp(0, d)\n            d <<= 1\n            y <<= 1\n        end\n        c >= t && !!(rc = c)\n    end\n    s = 0\n    p = 1\n    d = 2\n    y = d << 1\n    while d <= x\n        a, b = x .divmod y\n        s += (a * d + (b - d.pred).clamp(0, d)) * p\n        d <<= 1\n        y <<= 1\n        p += 1\n    end\n    s -\n        50.times\n          .select { x[_1] == 1 }\n          .reverse!\n          .take(rc - t)\n          .sum\nend\n\ndef find_products_of_elements(q) =\n    q.map! { 2.pow pref(_2.next) - pref(_1), _3 }\n```
['Ruby']