#include <iostream>
#include <array>
#include <algorithm>
#include <numeric>

template <typename T, typename ... AT>
int sumMatched (T A, AT ... args)
{
	std::array <T, sizeof ... (AT)> nums { args ... };
	auto bg { std::begin (nums) }, ed { std::end (nums) }, res = std::find (bg, ed, A);
	return std::accumulate (
		ed == res ? bg : ed == (res = std::find (++res, ed, A)) ? bg : ++res,
	ed, T {});
}

int main ()
{
	int A = 1, x1 = 1, x2 = 1, x3 = 3; //допишешь сам сколько надо переменных
	std::cout << sumMatched (A, x1, x2, x3) << std::endl;

	return 0;
}