You can not just take the file and send it. When Polycarp trying to send a file in the social network “Codehorses”, he encountered an unexpected problem. If the name of the file contains three or more “x” (lowercase Latin letters “x”) in a row, the system considers that the file content does not correspond to the social network topic. In this case, the file is not sent and an error message is displayed.
Determine the minimum number of characters to remove from the file name so after that the name does not contain “xxx” as a substring. Print 0 if the file name does not initially contain a forbidden substring “xxx”.
You can delete characters in arbitrary positions (not necessarily consecutive). If you delete a character, then the length of a string is reduced by $1$. For example, if you delete the character in the position $2$ from the string “exxxii”, then the resulting string is “exxii”.Input
The first line contains integer $n$ $(3 \le n \le 100)$ — the length of the file name.
The second line contains a string of length $n$ consisting of lowercase Latin letters only — the file name.Output
Print the minimum number of characters to remove from the file name so after that the name does not contain “xxx” as a substring. If initially the file name dost not contain a forbidden substring “xxx”, print 0.Examplesinput
6
xxxiii
output
1
input
5
xxoxx
output
0
input
10
xxxxxxxxxx
output
8
Note
In the first example Polycarp tried to send a file with name contains number $33$, written in Roman numerals. But he can not just send the file, because it name contains three letters “x” in a row. To send the file he needs to remove any one of this letters.
Solution:
private fun readLn() = readLine()!! // string line private fun readInt() = readLn().toInt() // single int private fun readLong() = readLn().toLong() // single long private fun readDouble() = readLn().toDouble() // single double private fun readStrings() = readLn().split(" ") // list of strings private fun readInts() = readStrings().map { it.toInt() } // list of ints private fun readLongs() = readStrings().map { it.toLong() } // list of longs private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles fun main(args: Array<String>) { val n = readInt() val s = readLn() var beg = 0 var ans = 0 while (beg < n) { if (s[beg] != 'x') { beg += 1 continue } var end = beg while (end + 1 < n && s[end + 1] == 'x') { ++end } ans += maxOf(0, end - beg + 1 - 2) beg = end + 1 } println(ans) }