Pho Restaurant

면접 대비

시간 제한2초메모리 제한1024 MB

요약
0과 1로 이루어진 주문 문자열이 테이블마다 주어질 때, 각 테이블이 한 종류의 주문만 담도록 옮겨야 하는 최소 인원을 구한다.
난이도

보통10점 중 5점

유형
그리디, 정렬, 구현
정답자
아직 제출이 없습니다

문제

As you may know, pho is one of the most common dishes in Hanoi. It contains a special kind of flour noodles, meat (usually beef or chicken), and green onions dipped in a tasty broth. Vietnamese people enjoy pho for breakfast, lunch, dinner, and even light meals. For tourists, trying pho is a must, especially in the cold of Hanoi.

You own a phở bò (beef pho) restaurant in Vietnam with nn tables, numbered 11 to nn. The 2024 ICPC Asia Pacific Championship contestants are currently in your restaurant. Each contestant is initially seated at one of the tables and there is at least one contestant initially seated at each table.

Each contestant would like to order one of the two most well-known kinds of pho: phở tái (pho with medium-rare beef) or phở chín (pho with well-done beef). The initial state of table ii is represented by the binary string S_iS\_i. The length of S_S\_i is the number of contestants initially seated at table ii. The jj-th character of S_iS\_i is 00 if the jj-th contestant initially seated at the table would like to order a phở tái, and 11 if the contestant would like to order a phở chín.

To make it easier to track the orders, the restaurant wants the contestants seated at the same table to have the same order. That is, for each table, at least one of the following must be true:

  • All of the contestants seated at that table would like to order a phở tái.
  • All of the contestants seated at that table would like to order a phở chín.

To satisfy this requirement and the contestants’ orders, you want to move zero or more contestants to a different table. The destination table must be one of the nn tables. In other words, you must not add new tables. There is no limit to the number of contestants that can be seated at the same table. After moving the contestants, the following condition should be satisfied by each table: either there is no contestant seated at that table or all contestants seated at that table would like to order the same dish.

Since moving contestants takes some time, you would like to compute the minimum number of contestants you need to move.

입력

The first line of input contains one integer nn (2≤n≤100,0002 ≤ n ≤ 100\\, 000). Each of the next nn lines contains a binary string. The ii-th line contains S_iS\_i (1≤∣S_i∣≤200,0001 ≤ |S\_i | ≤ 200\\, 000). The sum of ∣S_i∣|S\_i | across all ii does not exceed 500,000500\\, 000.

출력

Output an integer representing the minimum number of contestants you need to move.

예제3

  1. 예제 1

    입력
    4
    11101101
    00
    10001
    10
    
    예상 출력
    5
    
  2. 예제 2

    입력
    2
    101010
    010101
    
    예상 출력
    6
    
  3. 예제 3

    입력
    5
    0000
    11
    0
    00000000
    1
    
    예상 출력
    0