#include <algorithm>
#include <vector>
#include <iostream>
double dot(const std::vector<double>& p, const std::vector<double>& q)
{
return std::inner_product(p.begin(), p.end(), q.begin(), 0);
}
template<std::size_t N>
double dot(const double (&p)[N], const double (&q)[N])
{
return std::inner_product(p, p+N, q, 0);
}
int main()
{
std::vector<double> v1 = {1,2,3};
std::vector<double> v2 = {2,2,2};
std::cout << dot(v1, v2) << '\n';
double p[3] = {1,2,3};
double q[3] = {2,2,2};
std::cout << dot(p, q) << '\n';
}
CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxpb3N0cmVhbT4KCmRvdWJsZSBkb3QoY29uc3Qgc3RkOjp2ZWN0b3I8ZG91YmxlPiYgcCwgY29uc3Qgc3RkOjp2ZWN0b3I8ZG91YmxlPiYgcSkKewogICAgcmV0dXJuIHN0ZDo6aW5uZXJfcHJvZHVjdChwLmJlZ2luKCksIHAuZW5kKCksIHEuYmVnaW4oKSwgMCk7Cn0KCnRlbXBsYXRlPHN0ZDo6c2l6ZV90IE4+CmRvdWJsZSBkb3QoY29uc3QgZG91YmxlICgmcClbTl0sIGNvbnN0IGRvdWJsZSAoJnEpW05dKQp7CiAgICByZXR1cm4gc3RkOjppbm5lcl9wcm9kdWN0KHAsIHArTiwgcSwgMCk7Cn0KCmludCBtYWluKCkKewogICAgc3RkOjp2ZWN0b3I8ZG91YmxlPiB2MSA9IHsxLDIsM307CiAgICBzdGQ6OnZlY3Rvcjxkb3VibGU+IHYyID0gezIsMiwyfTsKCiAgICBzdGQ6OmNvdXQgPDwgZG90KHYxLCB2MikgPDwgJ1xuJzsKCiAgICBkb3VibGUgcFszXSA9IHsxLDIsM307CiAgICBkb3VibGUgcVszXSA9IHsyLDIsMn07CgogICAgc3RkOjpjb3V0IDw8IGRvdChwLCBxKSA8PCAnXG4nOwp9Cg==