Last active
June 18, 2025 06:58
-
-
Save HamzaAlnasir/3ca8dc02fc8442d77a55d6420a06a36a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# main.py | |
import sys | |
import functools | |
def main(): | |
input_data = sys.stdin.read().strip().splitlines() | |
if not input_data: | |
return | |
try: | |
num_test_cases = int(input_data[0]) | |
except: | |
return | |
results = [] | |
index = 1 | |
while index < len(input_data): | |
if index + 1 >= len(input_data): | |
results.append(-1) | |
break | |
try: | |
x = int(input_data[index].strip()) | |
yn_line = input_data[index + 1].strip() | |
yn_parts = list(map(int, yn_line.split())) | |
if len(yn_parts) != x: | |
results.append(-1) | |
else: | |
filtered = [n for n in yn_parts if n <= 0] | |
fourth_powers = [n ** 4 for n in filtered] | |
total = functools.reduce(lambda a, b: a + b, fourth_powers, 0) | |
results.append(total) | |
index += 2 | |
except: | |
results.append(-1) | |
index += 2 | |
for result in results: | |
print(result) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment