#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/tail.hpp>
int func(const std::vector<int>& v)
{
using namespace boost::accumulators;
accumulator_set<int, features<tag::tail<right> > > acc(tag::tail<right>::cache_size = 3);
acc = for_each(v.begin(), v.end(), acc);
return accumulate(tail(acc).begin(), tail(acc).end(), 0);
}
int main()
{
int data[] = {1,2,3,4,5,6,7,8,9,10,20,30};
std::vector<int> v(data, data+sizeof data/sizeof *data);
std::cout << func(v) << '\n';
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8bnVtZXJpYz4KI2luY2x1ZGUgPGJvb3N0L2FjY3VtdWxhdG9ycy9hY2N1bXVsYXRvcnMuaHBwPgojaW5jbHVkZSA8Ym9vc3QvYWNjdW11bGF0b3JzL3N0YXRpc3RpY3MvdGFpbC5ocHA+CgppbnQgZnVuYyhjb25zdCBzdGQ6OnZlY3RvcjxpbnQ+JiB2KQp7CiAgICB1c2luZyBuYW1lc3BhY2UgYm9vc3Q6OmFjY3VtdWxhdG9yczsKICAgIGFjY3VtdWxhdG9yX3NldDxpbnQsIGZlYXR1cmVzPHRhZzo6dGFpbDxyaWdodD4gPiA+IGFjYyh0YWc6OnRhaWw8cmlnaHQ+OjpjYWNoZV9zaXplID0gMyk7CiAgICBhY2MgPSBmb3JfZWFjaCh2LmJlZ2luKCksIHYuZW5kKCksIGFjYyk7CiAgICByZXR1cm4gYWNjdW11bGF0ZSh0YWlsKGFjYykuYmVnaW4oKSwgdGFpbChhY2MpLmVuZCgpLCAwKTsKfQppbnQgbWFpbigpCnsKICAgIGludCBkYXRhW10gPSB7MSwyLDMsNCw1LDYsNyw4LDksMTAsMjAsMzB9OwogICAgc3RkOjp2ZWN0b3I8aW50PiB2KGRhdGEsIGRhdGErc2l6ZW9mIGRhdGEvc2l6ZW9mICpkYXRhKTsKICAgIHN0ZDo6Y291dCA8PCBmdW5jKHYpIDw8ICdcbic7Cn0KICAgICAgICAgICAgICA=