#include <initializer_list>
#include <iostream>
#include <iterator>
#include <numeric>
#include <string>
template <typename T>
T add_select(const T* arr, std::initializer_list<std::size_t> selection)
{
using std::begin; using std::end;
return std::accumulate(begin(selection), end(selection), T(), [=](T a, std::size_t b) { return a + arr[b]; });
}
int main()
{
int p[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int sum = add_select(p, { 5, 4, 7 });
std::cout << sum << '\n';
std::string s[9] = { "abc", "def", "ghi", "jkl", "mno", "pqr", "stu", "vwx", "yz" };
std::string result = add_select(s, { 2, 4, 6 });
std::cout << result << '\n';
}
I2luY2x1ZGUgPGluaXRpYWxpemVyX2xpc3Q+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPGl0ZXJhdG9yPgojaW5jbHVkZSA8bnVtZXJpYz4KI2luY2x1ZGUgPHN0cmluZz4KCnRlbXBsYXRlIDx0eXBlbmFtZSBUPgpUIGFkZF9zZWxlY3QoY29uc3QgVCogYXJyLCBzdGQ6OmluaXRpYWxpemVyX2xpc3Q8c3RkOjpzaXplX3Q+IHNlbGVjdGlvbikKewogICAgdXNpbmcgc3RkOjpiZWdpbjsgdXNpbmcgc3RkOjplbmQ7CiAgICByZXR1cm4gc3RkOjphY2N1bXVsYXRlKGJlZ2luKHNlbGVjdGlvbiksIGVuZChzZWxlY3Rpb24pLCBUKCksIFs9XShUIGEsIHN0ZDo6c2l6ZV90IGIpIHsgcmV0dXJuIGEgKyBhcnJbYl07IH0pOwp9CgppbnQgbWFpbigpCnsKICAgIGludCBwWzEwXSA9IHsgMCwgMSwgMiwgMywgNCwgNSwgNiwgNywgOCwgOSB9OwogICAgaW50IHN1bSA9IGFkZF9zZWxlY3QocCwgeyA1LCA0LCA3IH0pOwogICAgc3RkOjpjb3V0IDw8IHN1bSA8PCAnXG4nOwoKICAgIHN0ZDo6c3RyaW5nIHNbOV0gPSB7ICJhYmMiLCAiZGVmIiwgImdoaSIsICJqa2wiLCAibW5vIiwgInBxciIsICJzdHUiLCAidnd4IiwgInl6IiB9OwogICAgc3RkOjpzdHJpbmcgcmVzdWx0ID0gYWRkX3NlbGVjdChzLCB7IDIsIDQsIDYgfSk7CiAgICBzdGQ6OmNvdXQgPDwgcmVzdWx0IDw8ICdcbic7Cn0=