Under construction

Still being built. Things may change

Making a Mandal-art

Time limit1sMemory limit1024 MB

Summary
Given a 9x9 mandal-art grid, print each intermediate goal with its 8 detailed goals, sorted lexicographically at both levels.
Level

Easy3 of 10

Topics
Implementation, Sorting, String
Solved
No attempts yet

Problem

Uju decided to make a New Year plan using a mandal-art.

A mandal-art is a table made by arranging 3x3 matrices, three across and three down, into a 9x9 matrix. To make one, first create goals as follows.

  • Create 1 final goal.
  • Create 8 intermediate goals that help achieve the final goal.
  • For each intermediate goal, create 8 detailed goals that help achieve it.

Use these goals to build the mandal-art as follows.

  1. Divide the 9x9 matrix into nine 3x3 matrices.
  2. Fill the 3x3 matrix at the center of the 9x9 matrix. Write the final goal in the exact center, and write the 8 intermediate goals one each in the remaining 8 cells.
  3. Write the intermediate goals again in the center of each of the other 3x3 matrices, excluding the central 3x3 matrix. The direction in which an intermediate goal sits within the central 3x3 matrix must match the direction of the 3x3 matrix centered on that same intermediate goal within the 9x9 matrix. For example, if the intermediate goal "health" is written in the upper right of the final goal in the central 3x3 matrix, the 3x3 matrix centered on "health" must be in the upper right of the 9x9 matrix.
  4. Fill the blank cells of each 3x3 matrix with detailed goals. Write 8 detailed goals, one each in the 8 cells, that help achieve the intermediate goal in the center.

Nobody recognized the plan Uju made, so Uju decided to write the mandal-art in a simpler form. The simplified plan is made as follows. First, print one intermediate goal, followed by its 8 detailed goals below it. Repeat this 8 times to print all 8 intermediate goals with their detailed goals. Intermediate goals must be sorted in lexicographic order, and the 8 detailed goals under each intermediate goal must also be sorted in lexicographic order. Goal a comes before goal b in lexicographic order in the following cases.

  • Digits come before letters.
  • Uppercase letters come before lowercase letters.
  • Given goals of length i and i+1 whose characters from index 0 through index i are identical, the goal of length i comes first. For example, "ab" comes before "abc".

Input

The input has 9 lines containing a 9x9 mandal-art. Only valid mandal-arts are given. A valid mandal-art satisfies the following conditions.

  • The center 3x3 matrix of the 9x9 matrix contains the final goal and the intermediate goals.
  • The direction in which the intermediate goals are written in the central 3x3 matrix matches the direction in the other 3x3 matrices.
  • No goal appears twice. However, each intermediate goal appears twice in the matrix in total.

All goals consist of English lowercase letters, uppercase letters, and digits. Each goal is no longer than 100 characters. Different goals are separated by spaces, and no goal contains a space.

Output

On the first line, print "#x. " followed by the intermediate goal that comes first in lexicographic order. Digits come before letters, and uppercase letters come before lowercase letters. From the second line on, print "#x-y. " followed by a detailed goal, in sorted order, on each of the next 8 lines. Repeat the process of one intermediate goal line followed by 8 detailed goal lines 8 times. x and y start at 1 and increase by one each time.

The final goal is not printed.

Examples2

  1. Example 1

    Input
    s11 s12 s13 s21 s22 s23 s31 s32 s33
    s18 m1 s14 s28 m2 s24 s38 m3 s34
    s17 s16 s15 s27 s26 s25 s37 s36 s35
    s81 s82 s83 m1 m2 m3 s41 s42 s43
    s88 m8 s84 m8 f m4 s48 m4 s44
    s87 s86 s85 m7 m6 m5 s47 s46 s45
    s71 s72 s73 s61 s62 s63 s51 s52 s53
    s78 m7 s74 s68 m6 s64 s58 m5 s54
    s77 s76 s75 s67 s66 s65 s57 s56 s55
    
    Expected output
    #1. m1
    #1-1. s11
    #1-2. s12
    #1-3. s13
    #1-4. s14
    #1-5. s15
    #1-6. s16
    #1-7. s17
    #1-8. s18
    #2. m2
    #2-1. s21
    #2-2. s22
    #2-3. s23
    #2-4. s24
    #2-5. s25
    #2-6. s26
    #2-7. s27
    #2-8. s28
    #3. m3
    #3-1. s31
    #3-2. s32
    #3-3. s33
    #3-4. s34
    #3-5. s35
    #3-6. s36
    #3-7. s37
    #3-8. s38
    #4. m4
    #4-1. s41
    #4-2. s42
    #4-3. s43
    #4-4. s44
    #4-5. s45
    #4-6. s46
    #4-7. s47
    #4-8. s48
    #5. m5
    #5-1. s51
    #5-2. s52
    #5-3. s53
    #5-4. s54
    #5-5. s55
    #5-6. s56
    #5-7. s57
    #5-8. s58
    #6. m6
    #6-1. s61
    #6-2. s62
    #6-3. s63
    #6-4. s64
    #6-5. s65
    #6-6. s66
    #6-7. s67
    #6-8. s68
    #7. m7
    #7-1. s71
    #7-2. s72
    #7-3. s73
    #7-4. s74
    #7-5. s75
    #7-6. s76
    #7-7. s77
    #7-8. s78
    #8. m8
    #8-1. s81
    #8-2. s82
    #8-3. s83
    #8-4. s84
    #8-5. s85
    #8-6. s86
    #8-7. s87
    #8-8. s88
    
  2. Example 2

    Input
    CareTheBody TakeSupplements FSQ90kg ImproveInStep StrengthenTheBodyCore1 StabilizeThePivot CreateAnAngle HitTheBallFromAbove StrengthenTheWrist
    Flexibility Physical RSQ130kg StabilizeTheReleasePoint Control GetRidOfUneasyFeelings DoNotTenseUp Precision TheLowerBodyLeads
    Stamina RangeOfMotion1 Meals StrengthenTheLowerExtremities1 DontOpenTheBody ControlMental ReleaseTheBallInTheFront IncreaseTheNumberOfRotations RangeOfMotion2
    HaveDearGoalsAndPurposes DoNotSwingJoyAndSorrow CoolHeadAndHotPassion Physical Control Precision TurnAtThePivot StrengthenTheLowerExtremities2 GainWeight
    BeStrongAtPinches Mental DontSwayByAtmosphere Mental DraftNo1 Speed160kmhr StrengthenTheBodyCore2 Speed160kmhr StrengthenAroundTheShoulders
    DontCreateUpsAndDowns TenacityForVictory TheHeartToCareTeamMates Personality Luck CurveBalls RangeOfMotion3 CatchLinerBalls IncreasePitching
    Sensitivity WorthyToBeLoved PlanAhead Greetings PickingTrashes CleanTheRoom IncreaseCoundBalls PrecisionForkBalls PrecisionOfSliders
    Caring Personality Gratitude UseTheToolsWithCare Luck AttitudeForJudges CurveBallsWithSpeed CurveBalls DecisiveBallsForLeftBatter
    WellMannered WorthyToBeTrusted SustainedEfforts PositiveThinking WorthyToBeSupported ReadBooks PitchWithTheSameAsStraight ControlFromStrikeIntoBall ImagineTheDepth
    
    Expected output
    #1. Control
    #1-1. ControlMental
    #1-2. DontOpenTheBody
    #1-3. GetRidOfUneasyFeelings
    #1-4. ImproveInStep
    #1-5. StabilizeThePivot
    #1-6. StabilizeTheReleasePoint
    #1-7. StrengthenTheBodyCore1
    #1-8. StrengthenTheLowerExtremities1
    #2. CurveBalls
    #2-1. ControlFromStrikeIntoBall
    #2-2. CurveBallsWithSpeed
    #2-3. DecisiveBallsForLeftBatter
    #2-4. ImagineTheDepth
    #2-5. IncreaseCoundBalls
    #2-6. PitchWithTheSameAsStraight
    #2-7. PrecisionForkBalls
    #2-8. PrecisionOfSliders
    #3. Luck
    #3-1. AttitudeForJudges
    #3-2. CleanTheRoom
    #3-3. Greetings
    #3-4. PickingTrashes
    #3-5. PositiveThinking
    #3-6. ReadBooks
    #3-7. UseTheToolsWithCare
    #3-8. WorthyToBeSupported
    #4. Mental
    #4-1. BeStrongAtPinches
    #4-2. CoolHeadAndHotPassion
    #4-3. DoNotSwingJoyAndSorrow
    #4-4. DontCreateUpsAndDowns
    #4-5. DontSwayByAtmosphere
    #4-6. HaveDearGoalsAndPurposes
    #4-7. TenacityForVictory
    #4-8. TheHeartToCareTeamMates
    #5. Personality
    #5-1. Caring
    #5-2. Gratitude
    #5-3. PlanAhead
    #5-4. Sensitivity
    #5-5. SustainedEfforts
    #5-6. WellMannered
    #5-7. WorthyToBeLoved
    #5-8. WorthyToBeTrusted
    #6. Physical
    #6-1. CareTheBody
    #6-2. FSQ90kg
    #6-3. Flexibility
    #6-4. Meals
    #6-5. RSQ130kg
    #6-6. RangeOfMotion1
    #6-7. Stamina
    #6-8. TakeSupplements
    #7. Precision
    #7-1. CreateAnAngle
    #7-2. DoNotTenseUp
    #7-3. HitTheBallFromAbove
    #7-4. IncreaseTheNumberOfRotations
    #7-5. RangeOfMotion2
    #7-6. ReleaseTheBallInTheFront
    #7-7. StrengthenTheWrist
    #7-8. TheLowerBodyLeads
    #8. Speed160kmhr
    #8-1. CatchLinerBalls
    #8-2. GainWeight
    #8-3. IncreasePitching
    #8-4. RangeOfMotion3
    #8-5. StrengthenAroundTheShoulders
    #8-6. StrengthenTheBodyCore2
    #8-7. StrengthenTheLowerExtremities2
    #8-8. TurnAtThePivot