Under construction

Still being built. Things may change

Kayak

Interview

Time limit1sMemory limit128 MB

Summary
Parse a grid to find each of nine teams' kayak position, rank teams by distance from the rightmost kayak cell to the finish line with tie handling.
Level

Easy3 of 10

Topics
Implementation, Simulation, Array
Solved
No attempts yet

Problem

Sanggeun is hosting a kayak race. The race is broadcast live worldwide, and a satellite is photographing the whole course. Sanggeun wants to build a program that computes the live rankings from the satellite image.

The satellite image is a grid of RR rows and CC columns. The first cell of every row is S (the start line) and the last cell is F (the finish line). Nine teams take part, numbered 1 through 9. A kayak always occupies three horizontally consecutive cells in one row, and those three cells are all marked with the team's number. Water is shown as ..

A team's rank is determined by the distance between the finish line F and the kayak cell nearest to it (the rightmost of the kayak's three cells in that row). The shorter this distance (the closer to the finish line), the better the rank. If two teams are at the same distance, they share the same rank.

Input

The first line contains two integers RR and CC. (10≤R,C≤5010 \le R, C \le 50)

Each of the next RR lines is a row of the satellite map made of ., S, F, and the digits 1 through 9. Each row contains at most one kayak, and the image always contains exactly nine kayaks (one each for teams 1 through 9).

Output

Print nine lines. The ii-th line contains the rank of team ii (i=1,2,…,9i = 1, 2, \dots, 9).

Ranks start at 1. Teams with the same distance to the finish line share the same rank, and each next distinct distance increases the rank by exactly one (ranks are not skipped).

Examples2

  1. Example 1

    Input
    10 10
    S.....111F
    S....222.F
    S...333..F
    S..444...F
    S.555....F
    S666.....F
    S.777....F
    S..888...F
    S...999..F
    S........F
    
    Expected output
    1
    2
    3
    4
    5
    6
    5
    4
    3
    
  2. Example 2

    Input
    10 15
    S..........222F
    S.....111.....F
    S...333.......F
    S...555.......F
    S.......444...F
    S.............F
    S......777....F
    S..888........F
    S........999..F
    S...666.......F
    
    Expected output
    5
    1
    6
    3
    6
    6
    4
    7
    2