import std.stdio : writeln;
import std.algorithm.comparison: min, equal;
import std.algorithm.iteration: sum;
import core.time: MonoTime, Duration;
auto sum_subranges(T)(T input, uint range)
{
import std.range : chunks;
import std.algorithm : map;
if (range != 0)
{
return input.chunks(range).map!(sum);
}
return typeof(return).init;
}
void main()
{
import std.range : iota, array;
auto v = iota(0,1000000).array;
int sum;
MonoTime beg = MonoTime.currTime;
for (int i=0; i < 100; i++)
sum += cast(int)sum_subranges(v,2).length;
MonoTime end = MonoTime.currTime;
writeln(end-beg);
writeln(sum);
assert(equal(sum_subranges([1,1,1], 2), [2, 1]));
assert(equal(sum_subranges([1,1,1,2,3,3], 2), [2, 3, 6]));
assert(equal(sum_subranges(cast(int[])[], 2), cast(int[])[]));
assert(equal(sum_subranges([1], 2), [1]));
}
aW1wb3J0IHN0ZC5zdGRpbyA6IHdyaXRlbG47CmltcG9ydCBzdGQuYWxnb3JpdGhtLmNvbXBhcmlzb246IG1pbiwgZXF1YWw7CmltcG9ydCBzdGQuYWxnb3JpdGhtLml0ZXJhdGlvbjogc3VtOwppbXBvcnQgY29yZS50aW1lOiBNb25vVGltZSwgRHVyYXRpb247CgoKYXV0byBzdW1fc3VicmFuZ2VzKFQpKFQgaW5wdXQsIHVpbnQgcmFuZ2UpCnsKICAgIGltcG9ydCBzdGQucmFuZ2UgOiBjaHVua3M7CiAgICBpbXBvcnQgc3RkLmFsZ29yaXRobSA6IG1hcDsKCiAgICBpZiAocmFuZ2UgIT0gMCkKICAgIHsKICAgICAgICByZXR1cm4gaW5wdXQuY2h1bmtzKHJhbmdlKS5tYXAhKHN1bSk7CiAgICB9CiAgICByZXR1cm4gdHlwZW9mKHJldHVybikuaW5pdDsKfQoKdm9pZCBtYWluKCkKewogICAgaW1wb3J0IHN0ZC5yYW5nZSA6IGlvdGEsIGFycmF5OwogICAgYXV0byB2ID0gaW90YSgwLDEwMDAwMDApLmFycmF5OwogICAgaW50IHN1bTsKICAgIE1vbm9UaW1lIGJlZyA9IE1vbm9UaW1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