# Protean live showcase best kernel artifact
# trial 24: two_stage_reduce, speedup 4.62x, latency 0.031 ms
import triton
import triton.language as tl

@triton.jit
def sum_reduction_two_stage(x, y, n: tl.constexpr):
    pid = tl.program_id(0)
    offs = pid * 1024 + tl.arange(0, 1024)
    mask = offs < n
    vals = tl.load(x + offs, mask=mask, other=0.0)
    acc = tl.sum(vals, axis=0)
    tl.store(y + pid, acc)
