blob: 3b56dea8d2366545093d3e95e343ab78567f7ddb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <string_view>
#include <vector>
using namespace std;
bool possible(long long x, vector<long long>& a, int i) {
if (i == 0)
return a[0] == x;
if (a[i] != 0 && x % a[i] == 0)
return possible(x/a[i], a, i-1) || possible(x-a[i], a, i-1);
return possible(x-a[i], a, i-1);
}
int main() {
string line;
long long tot = 0;
while (getline(cin, line)) {
long long x, i;
vector<long long> a;
stringstream s(line);
s >> x;
char colon;
s >> colon;
while (s >> i)
a.push_back(i);
if (possible(x, a, a.size()-1))
tot += x;
}
cout << tot << endl;
return 0;
}
|