fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. int main() {
  7. int a, b, count = 1;
  8. vector <int> vec;
  9. string str;
  10. getline(cin, str);
  11. int n = str.length();
  12. for (int i = 1; i < n; i++) if (str[i - 1] != str[i]) {
  13. vec.push_back(count);
  14. count = 1;
  15. } else count++;
  16. vec.push_back(count);
  17. cin >> a >> b;
  18. int sum = 0;
  19. for (int e : vec) sum += e;
  20. int len = vec.size();
  21. cout << a * sum + ((b < 0) ? (len / 2 + 1) : len) * b;
  22. return 0;
  23. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
-266146312