1.jpg 2.jpg 3.jpg 4.jpg @everyone @here


Submit solution

Points: 1
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type
Allowed languages
C, C++, Java, Python, Rust

Shashwat and Aaditya have recently fallen victim to a devious social engineering operation, promising free cryptocurrency but delivering only regret.

After recovering their accounts, Aaditya endeavours to improve his security settings so that this never happens again. The security panel contains n configuration switches which are either + (on) or - (off). Aaditya's cybersecurity training tells him that the maximally secure configuration is one where all adjacent switches have opposite states. Equivalently, the configuration panel is either

  • +-+-+-..., or
  • -+-+-+....

Moreover, Aaditya's mouse is old and the left-click button is sticking, so he can only interact with his settings by dragging a box over switches to toggle them. In one operation, Aaditya chooses a non-empty contiguous segment of switches and toggles every switch in it: + becomes -, and - becomes +. A segment may contain a single switch.

Given his initial configuration, can you tell Aaditya the minimum number of segment toggles he needs to secure his account before someone else offers him free Bitcoin?

Input

The first line contains a single integer n (1 \leq n \leq 10^6), the number of configuration switches in Aaditya's account panel.

The next line contains n characters, each either + or -. This shows the initial configuration of Aaditya's security settings.

Output

Output a single integer - the minimum number of contiguous segment toggles required to secure Aaditya's account, making every configuration switch opposite to its adjacent switches.

Examples

Input 1
5
+++++
Output 1
2

Toggling the second and fourth switches individually changes the configuration to +-+-+. This is the minimum possible number of toggles.

Input 2
9
+--+-+--+
Output 2
1

Toggling switches 3 through 7 changes the configuration to +-+-+-+-+, so a single segment toggle is enough. Targeting the other alternating configuration would require two segment toggles.

Input 3
1
+
Output 3
0

A configuration with one switch already has no adjacent pair of switches, so it is secure without any toggles.


Comments


  • 0
    marcus  commented on Sept. 19, 2026, 2:36 a.m.

    :skull: :skull: :wilted_rose: :skull: