Back From Summer '17 P2: Crayola Lightsaber

View as PDF

Points: 7
Time limit: 1.0s
Memory limit: 128M

Author:
Problem types
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

School's back! You're up to no good again already… While your art teacher, Roger, was looking away, you grab his basket of Crayola™ markers and started connecting them together.

This creates a colorful sword that you can use to hit people that you find annoying with. You want to be able to reach quite far with your sword though, so you keep on connecting.

Although you want your crayon lightsaber to be as long as possible, you also care deeply about it being aesthetically pleasing. For that reason, you choose to never connect two crayons of the same color directly together.

Given the colors of the markers in the basket, what is the longest Crayola™ marker sword you can construct?

Input Specification

The first line will contain an integer . This will then be followed by a line of strings that represent the colors of the markers. The colors can be: red, orange, yellow, green, blue, black.

Output Specification

The only output is an integer representing the maximum length possible for the marker sword.

Sample Input 1

4
red blue green black

Sample Output 1

4

Sample Input 2

5
yellow orange yellow yellow yellow

Sample Output 2

3

Explanation for Sample Input

For the first example you can use every marker to make a sword such as the one in the image above.

The longest sword you can make for the second example is using the markers yellow-orange-yellow, resulting in a length of .

Can someone take a look at my code? It works when I test my code in PyCharm, but the first test case always gives me an IR (Name Error). My output(clipped) is 3. Plz, somebody help me!