PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000171. Sắp xếp đàn cừu (Arranging The Sheep)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Sắp xếp đàn cừu (Arranging The Sheep)

Arranging The Sheep

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A row contains nn consecutive cells. Each cell is either empty (.) or contains exactly one sheep (*). Sheep preserve their left-to-right order because no two sheep can move through one another.

In one move, choose a sheep and move it one cell left or right, provided that the destination is inside the row and empty. The goal is to make all sheep occupy consecutive cells with no empty cell between any pair of sheep. A row with zero or one sheep already meets the goal.

Find the minimum number of individual moves needed to reach such a configuration.

Input

Line 1 contains an integer nn, the number of cells.

Line 2 contains a string ss of exactly nn characters, each . or *, describing the cells from left to right, indexed from 11 to nn.

Output

Print one nonnegative integer: the minimum number of moves needed to group all sheep in consecutive cells.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le20; ss has exactly nn characters, each . or *.
  • Subtask 2 (30 points): 1≤n≤30001\le n\le3000; ss has exactly nn characters, each . or *.
  • Subtask 3 (50 points): 1≤n≤1061\le n\le10^6; ss has exactly nn characters, each . or *.

Examples

Input

6
**.*..

Output

1

Explanation

The sheep initially occupy cells 11, 22, and 44. Move the sheep in cell 44 once into empty cell 33, obtaining ***.... Since the initial state has a gap, zero moves cannot suffice, so the answer is 11.