#include <stdio.h>
int calculate(int *arr, int size) {
if (size <= 0) return 0;
if (size == 1) return *arr;
int mid = size / 2;
int left = calculate(arr, mid);
int right = calculate(arr + mid, size - mid);
int *ptr = arr;
for (int i = 0; i < size; i++) {
*ptr = (*ptr + i) % 3 == 0 ? left : right;
ptr++;
}
return *(arr + size - 1);
}
int main() {
int values[4] = {2, 4, 6, 8};
int result = calculate(values, 4);
printf("%d %d %d %d %d\n", values
[0], values
[1], values
[2], values
[3], result
); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgY2FsY3VsYXRlKGludCAqYXJyLCBpbnQgc2l6ZSkgewogICAgaWYgKHNpemUgPD0gMCkgcmV0dXJuIDA7CiAgICBpZiAoc2l6ZSA9PSAxKSByZXR1cm4gKmFycjsKICAgIAogICAgaW50IG1pZCA9IHNpemUgLyAyOwogICAgaW50IGxlZnQgPSBjYWxjdWxhdGUoYXJyLCBtaWQpOwogICAgaW50IHJpZ2h0ID0gY2FsY3VsYXRlKGFyciArIG1pZCwgc2l6ZSAtIG1pZCk7CiAgICAKICAgIGludCAqcHRyID0gYXJyOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBzaXplOyBpKyspIHsKICAgICAgICAqcHRyID0gKCpwdHIgKyBpKSAlIDMgPT0gMCA/IGxlZnQgOiByaWdodDsKICAgICAgICBwdHIrKzsKICAgIH0KICAgIAogICAgcmV0dXJuICooYXJyICsgc2l6ZSAtIDEpOwp9CgppbnQgbWFpbigpIHsKICAgIGludCB2YWx1ZXNbNF0gPSB7MiwgNCwgNiwgOH07CiAgICBpbnQgcmVzdWx0ID0gY2FsY3VsYXRlKHZhbHVlcywgNCk7CiAgICBwcmludGYoIiVkICVkICVkICVkICVkXG4iLCB2YWx1ZXNbMF0sIHZhbHVlc1sxXSwgdmFsdWVzWzJdLCB2YWx1ZXNbM10sIHJlc3VsdCk7CiAgICByZXR1cm4gMDsKfQ==