#include #include #include #include using namespace std; int sushiSumMaxValue(vector sushiValues) { int sushiCount = (int)sushiValues.size(); vector sushiSumValues; sushiSumValues.push_back(sushiCount > 0 ? sushiValues[0] : 0); sushiSumValues.push_back(sushiCount > 1 ? sushiValues[1] : 0); sushiSumValues.push_back(sushiSumValues[0] + (sushiCount > 2 ? sushiValues[2] : 0)); for (int i = 3; i < sushiCount; ++i) { sushiSumValues.push_back(sushiValues[i] + (sushiSumValues[i - 2] > sushiSumValues[i - 3] ? sushiSumValues[i - 2] : sushiSumValues[i - 3])); } int sushiSumCount = (int)sushiSumValues.size(); return sushiSumValues[sushiSumCount - 1] > sushiSumValues[sushiSumCount - 2] ? sushiSumValues[sushiSumCount - 1] : sushiSumValues[sushiSumCount - 2]; } int main() { vector sushiValues; string tmp; cin >> tmp; while (cin >> tmp) { sushiValues.push_back(stoi(tmp)); } cout << sushiSumMaxValue(sushiValues) << endl; }