EN
Elves

2024 · Task 1

Priority Wish Lists

Author: Toma Petrušić

07/12/2024 00:01 – 13/12/2024 23:59

Every year Santa receives a pile of messy letters with priority (!) wish lists. Each list has exactly 100 wishes. To help Santa's helpers get organised, the wishes are simplified by sorting them into categories, each marked with a letter:

  • I: toys
  • B: sweets
  • E: electronics
  • S: sports equipment
  • K: books
  • D: board games
  • P: puzzles
  • O: clothes
  • G: musical instruments
  • L: Lego

An example of a simplified list:

EBDBDIDKKOOSSSDOLSIGIKSOKOKKPLKGBGBEDPDKKDIIPDSEPSSLGPDOKGIPGPDDOOEDLDPGDGDOOEESIPEPGGBDKEEGIISOISDL

This produces strings that represent priority wish lists (the order of the letters matters). Since the lists are priority lists, the helpers may not change the order of the letters. However, the sheer number of lists is slowing down production, so Santa is asking for your help to find a "median list". This list is defined as the list with the smallest Hamming distance from every original list.

The Hamming distance is defined as the number of indices at which two strings have different elements. (Hamming distance)

The median list is judged by two criteria (the first is worth 70% of the points and the second 30%):

  1. Smallest Hamming distance: your goal is to minimise the maximum Hamming distance between your output string and all the input strings
  2. Sum of Hamming distances: your goal is to minimise the sum of all Hamming distances between the output string and all the input strings

For example, if the Hamming distances between the output string and the input strings are 2, 3, 1, 4, 2, then:

  • Maximum distance = 4
  • Sum of distances = 2 + 3 + 1 + 4 + 2 = 12

Examples

Input

For simplicity, let's say the input strings have length 5 (in the real input data they all have length 100):

IBESI
ISBEI
IBSSI
EBSIS
ISSEB

Output

Your program could return the output string:

IBSEI

For this output string, you calculate:

  • Maximum Hamming distance: the Hamming distances between your string and the input strings are 2, 2, 1, 3, 2. So for this criterion you would get (5 - 3) / 5 points. 5 is the length of all the strings, and 3 is the maximum Hamming distance
  • Sum of Hamming distances: the Hamming distances between your string and the input strings are 2, 2, 1, 3, 2. So the sum is 10, and your score for this criterion would be (5 * 5 - 10) / (5 * 5). 5 is both the number of input strings and the length of the input strings, and 10 is the sum of the Hamming distances

Scoring

Your total score will be the sum of these two criteria:

70% of the points: Smallest maximum Hamming distance; the score is calculated using the formula (100 - max(Hamming_distance(s, si))) / 100, where s is your output string, si is each input string, and 100 is the length of the input strings

30% of the points: Minimum sum of Hamming distances; the score is calculated as (1000 * 100 - sum) / (1000 * 100), where 1000 is the number of input strings, 100 is the length of each string, and sum is the sum of all the Hamming distances.

Input

1000 lines, each containing a string of 100 letters (I, B, E, S, K, D, O, P, G, L) representing a priority wish list.

Output

An output string of 100 letters that satisfies the criteria above and achieves the maximum score.