#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <vector>
using namespace std;
int main() {
vector<int> foo(9);
const vector<int> v = { 2, 9, 3, 6, 5, 8, 8, 8, 8, 7, 2, 2, 8, 1, 4 };
generate(begin(foo), end(foo), [i = int{ 1 }]() mutable {
auto result = i;
i *= 10;
return result; });
auto maximum = 0;
for (auto it = prev(rend(v), foo.size() + 1); it != rbegin(v); advance(it, -1)) {
maximum = max<int>(inner_product(cbegin(foo), cend(foo), it, 0), maximum);
}
maximum = max<int>(inner_product(cbegin(foo), cend(foo), rbegin(v), 0), maximum);
cout << maximum;
}
I2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8aXRlcmF0b3I+CiNpbmNsdWRlIDxudW1lcmljPgojaW5jbHVkZSA8dmVjdG9yPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkgewoJdmVjdG9yPGludD4gZm9vKDkpOwoJY29uc3QgdmVjdG9yPGludD4gdiA9IHsgMiwgOSwgMywgNiwgNSwgOCwgOCwgOCwgOCwgNywgMiwgMiwgOCwgMSwgNCB9OwoKCWdlbmVyYXRlKGJlZ2luKGZvbyksIGVuZChmb28pLCBbaSA9IGludHsgMSB9XSgpIG11dGFibGUgewoJCWF1dG8gcmVzdWx0ID0gaTsKCQlpICo9IDEwOwoJCXJldHVybiByZXN1bHQ7IH0pOwoKCWF1dG8gbWF4aW11bSA9IDA7CgoJZm9yIChhdXRvIGl0ID0gcHJldihyZW5kKHYpLCBmb28uc2l6ZSgpICsgMSk7IGl0ICE9IHJiZWdpbih2KTsgYWR2YW5jZShpdCwgLTEpKSB7CgkJbWF4aW11bSA9IG1heDxpbnQ+KGlubmVyX3Byb2R1Y3QoY2JlZ2luKGZvbyksIGNlbmQoZm9vKSwgaXQsIDApLCBtYXhpbXVtKTsKCX0KCW1heGltdW0gPSBtYXg8aW50Pihpbm5lcl9wcm9kdWN0KGNiZWdpbihmb28pLCBjZW5kKGZvbyksIHJiZWdpbih2KSwgMCksIG1heGltdW0pOwoKCWNvdXQgPDwgbWF4aW11bTsKfQ==