// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract distributeHype {
    /// @notice Distribute the ETH sent with this call to each recipient in turn.
    /// @param recipients The list of addresses to send ETH to.
    /// @param amounts    The corresponding amounts of wei to send to each.
    /// @dev You must send exactly sum(amounts) in msg.value.
    function distribute(
        address[] calldata recipients,
        uint256[] calldata amounts
    ) external payable {
        uint256 len = recipients.length;
        require(len == amounts.length, "Length mismatch");
        // Sum up all the requested amounts and verify it equals the ETH sent
        uint256 total;
        for (uint256 i = 0; i < len; i++) {
            total += amounts[i];
        }
        require(total == msg.value, "ETH value mismatch");
        // Distribute ETH
        for (uint256 i = 0; i < len; i++) {
            // using call to forward all available gas and avoid 2300-byte stipend issues
            (bool ok, ) = payable(recipients[i]).call{ value: amounts[i] }("");
            require(ok, "Transfer to recipient failed");
        }
    }
}