Mars Exploration

November 09, 2017


Sami’s spaceship crashed on Mars! She sends sequential SOS messages to Earth for help.

NASA_Mars_Rover.jpg

Letters in some of the SOS messages are altered by cosmic radiation during transmission. Given the signal received by Earth as a string, S, determine how many letters of Sami’s SOS have been changed by radiation.

Input Format

There is one line of input: a single string, S.

Note: As the original message is just SOS repeated n times, SOS’s length will be a multiple of 3.

Constraints

will contain only uppercase English letters.

_Output Format__

Print the number of letters in Sami’s message that were altered by cosmic radiation.

Sample Input 0

SOSSPSSQSSOR

Sample Output 0

3

Sample Input 1

SOSSOT

Sample Output 1

1

Explanation

Sample 0

S= SOSSPSSQSSOR, and signal length 12. Sami sent SOS messages (i.e.: ).

Expected signal: SOSSOSSOSSOS

Recieved signal: SOSSPSSQSSOR

We print the number of changed letters, which is 3.

Sample 1

S = SOSSOT, and signal length 6. Sami sent SOS messages (i.e.: ).

Expected Signal: SOSSOS

Received Signal: SOSSOT

We print the number of changed letters, which is 1.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import sys

def sockMerchant(n, ar):
    sameColor = {}
    count = 0
    for key in ar:
        if key in sameColor:
            sameColor[key] += 1
        else:
            sameColor[key] = 1
    for key in sameColor:
        count += sameColor[key]//2
    return count

n = int(input().strip())
ar = list(map(int, input().strip().split(' ')))
result = sockMerchant(n, ar)
print(result)