DOJ logoDOJ
Problems
Recently added problemsSaved problems
CategoriesDLCContestsGroupsTeamsBoard
Ranking
Solved Problem RankingStreak rankingDOJ Power ranking
Status
Call for TasksLoginRegister
DOJ logoDOJ

Community online judge with OI-style subtask scoring, Elo ratings, and Discord-backed certification.

Problems
ProblemsCategories
Community
ContestsRankingBoardNoticesHost an external contestGuide
Account
LoginRegisterJudge Status
Policy
Terms of ServiceDLC RulesPrivacyAPI documentationLanguage runtimesContest rank rewardsRating and performance
© 2026 DOJ
All rights reserved
Editorial

67 sequence 1

Back to problem

Editorial

If a character 666 or 777 remains in the string, the condition is not satisfied. Therefore, every occurrence of 666 and 777 in the original string must be erased.

Conversely, if we erase exactly all occurrences of 666 and 777, the remaining string contains neither 666 nor 777. Hence the answer is the number of occurrences of the characters 666 and 777 in SSS.

We can compute it by scanning the string once. The time complexity is O(N)O(N)O(N) and the memory complexity is O(1)O(1)O(1).