Introduction to Instructor: William W.Y. Hsu › Course Preliminaries › Introduction CONTENTS › A taste of Ad Hoc Problems

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 2 Course Preliminaries Why and what? Another programming course?

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 3 What you will learn › Reading comprehension. › Problem evaluation. › Parsing and formatting text. › Tricks to reduce code and bugs. › Generating test cases for your code.

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 4 What you will learn › that might be practiced – Dynamic Programming (DP) › State-space search, Games – Data structures › Binary indexed tree, Union-find › Computational geometry – Convex hull › Graph algorithms – Flow

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 5 Goal › Given a problem, we want to: – Solve it efficiently. – By using algorithms and data structures. – Convert our solution into a program. – Do it as quickly as possible (under pressure). – Do it correctly (without bugs)! › This course will exercise this process.

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 6 Why compete › Makes you a better programmer and thinker in many situations › Intangible skill that will set you apart in the workforce › Be first of NTOU to attend NCPC, ACM-ICPC › It's fun :)

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 7 Ultimate goal › Please note that being well-versed in competitive programming is not the end goal, but only a means to an end. › The true end goal is to produce all-rounder computer scientists/ programmers who are much readier to produce better software and to face harder CS research problems in the future.

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 8 Competitive Programming › Given well-known problems, solve them as fast as possible. – Find a solution that reduces down to a well-known problems, not research problems. – Pass all the judge data correctly. – Solution should run fast enough. – Do not over-engineer the solution.

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 9 How? › Study common types of problems. › Show common applications of algorithms and data structures you already know from: – Prof. Lin & Prof. Wu (the algorithms course). – Prof. Lin & Prof. Hsieh (the data structures course). › Introduce other common algorithms and data structures. › Go over some commonly used theory. › Practice problem solving. › Practice programming. › More practice.

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 10 How? › More practice.

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 11 How? › More practice.

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 12 Possible topics

› Introduction › Discrete structure › Mathematics › Divide and Conquer › Data Structures & Sorting › Dynamic Programming (DP) › Combinatorial Games › Greedy Algorithms › Binary Trees › Basic Graph Algorithms › Spanning Trees & Shortest Paths › Network Flow Problems › Computational Geometry › String Algorithms (Additional material: Suffix Arrays - A Programming Contest Approach) › Backtracking, Branch & Bound

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 13 Possible topics – decomposed

› Arrays and iteration problems › backtracking problems › programming style / understanding › constructing subsets and permutations specifications › graph traversal problems › data structure problems › DFS/BFS › elementary data structures › graph algorithms problems › string problems › shortest paths and MST › strings and library functions › dynamic programming problems › sorting problems › edit distance and applications › sorting and library functions › grid problems › arithmetic problems › rectangular and hexagonal grids › arithmetic and algebra › geometry problems › problems › geometric primitives and trigonometry › recurrence relations and counting › computational geometry › problems › convex hulls and triangulation › divisibility and modular arithmetic

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 14 Forming Quiz Teams (uva10911)

Abridged Problem Description: Let ( , ) be the coordinates of a student’s house on a 2D plane. There are students and we want to pair them into groups. Let be the distance between cost = the houses𝑥𝑥 𝑦𝑦 of 2 students in group . Form groups such that 2𝑁𝑁is minimized. 𝑁𝑁 𝑑𝑑𝑖𝑖 𝑁𝑁 𝑖𝑖=1 𝑖𝑖 Output the minimum cost. Constraints:𝑖𝑖 1 𝑁𝑁 8 and 0 , 1000∑ . 𝑑𝑑

≤ 𝑁𝑁 ≤ ≤ 𝑥𝑥 𝑦𝑦 ≤ Sample input: = 2; Coordinates of the = 4 houses are {1, 1}, {8, 6}, {6, 8}, and {1, 3}.

Sample𝑁𝑁 output: 2𝑁𝑁 cost = 4.83.

Can you solve this problem? If so, how many minutes would you likely require to complete the working code

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 15 Where are you? › Uncompetitive programmer A (a.k.a. the blurry one): – Step 1: Reads the problem and becomes confused. (This problem is new for him). – Step 2: Tries to code something: Reading the non-trivial input and output. – Step 3: Realizes that all his attempts are not Accepted (AC): › Greedy: Repeatedly pairing the two remaining students with the shortest separating distances gives the Wrong Answer (WA). › Naive Complete Search: Using recursive backtracking and trying › all possible pairings yields Time Limit Exceeded (TLE).

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 16 Where are you? › Uncompetitive programmer B (Give up): – Step 1: Reads the problem and realizes that he has seen this problem before. › But also remembers that he has not learned how to solve this kind of problem... › He is not aware of the Dynamic Programming (DP) solution… – Step 2: Skips the problem and reads another problem in the problem set.

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 17 Where are you? › (Still) Uncompetitive programmer C (Slow): – Step 1: Reads the problem and realizes that it is a hard problem: ‘minimum weight perfect matching on a small general weighted graph’. › However, since the input size is small, this problem is solvable using DP. › The DP state is a bitmask that describes a matching status, and matching unmatched students and will turn on two bits and in the bitmask. – Step 2: Codes I/O routine, writes𝑖𝑖 recursive𝑗𝑗 top-down DP,𝑖𝑖 tests,𝑗𝑗 debugs >.<... – Step 3: After 3 hours, his solution obtains AC (passed all the secret test data).

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 18 Where are you? › Competitive programmer D: – Completes all the steps taken by uncompetitive programmer C in ≤ 30 minutes. › Very competitive programmer E: – A very competitive programmer (e.g. the red ‘target’ coders in [32]) would solve this ‘well known’ problem ≤ 15 minutes...

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 19 Course Administration › Course website – http://140.121.196.121/wwyhsu/?page_id=959 › Teaching staffs: – Lecturer: ME! › [email protected] › Ext: 6657 (preferably using emails) – TA1: 黃珮婷 [email protected] – TA2: 王浩勳 [email protected] – TA3: 游旻叡 [email protected] › Office hours: TBA

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 20 Grading › Tentative grading policy: – Homework and written quizzes (20%) – In class simulations (30%) – Midterm exam (25%) – Final exam (25%) – Extra credit policy for attending public contests: › CPE: 2% + 1% per solved problem › ITSA (月賽, 中文題為主): 1% +1% per solved problem. – ITSA 每年五月另舉辦桂冠挑戰大賽! 5% + 2% per solved problem. › PTC (月賽,以英文題為主): 2.5% + 1.5% per solved problem. › ACM-ICPC Regionals: 5% + 2% per solved problem. › ACM-ICPC World finals: 再說吧~

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 21 Execution › Weekly courses. › Practice (simulation sessions) – Team based. – Vote: AT or RT!

› Written exams and homework. – Single solo mode.

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 22 Textbook › Steven Halim, Competitive Programming, 3rd Edition, ASIN: B00FG8MNN8. – http://www.amazon.com/Competitive-Programming-Edition- Steven-Halim/dp/B00FG8MNN8 – http://www.lulu.com/shop/http://www.lulu.com/shop/steven- halim/competitive-programming-3- hardcover/hardcover/product-21059922.html (Hardcover, $39.99) – http://www.lulu.com/shop/steven-halim/competitive- programming-3/ebook/product-21976335.html (E-book, $19.99)

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 23 References › S. S. Skiena, M. A. Revilla, Programming Challenges: The Programming Contest Training Manual, Springer, 2003 ed. (ISBN-10: 0387001638) › T. Cormen, C. Leiserson, R. Rivest, C. Stein, Introduction to Algorithms, 3rd ed., The MIT Press. (ISBN-10: 0262033844) › S. Skiena, The Design Manual, 2nd ed., Springer. (ISBN-10: 1848000693) › R. Graham, D. Knuth, O. Patashnik, Concrete Mathematics: A Foundation for Computer Science.

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 24 This is an era of information explosion

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 25 References › ITSA: – http://algorithm.csie.ncku.edu.tw/ITSA_PTC/index_ITSA.php › PTC: – http://algorithm.csie.ncku.edu.tw/ITSA_PTC/index_PTC.php › CPE: – https://cpe.cse.nsysu.edu.tw/ › NCPC (程式設計組): – http://ncpc.ntnu.edu.tw/ncpc/showpage.php?id=3

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 26 Introduction Let’s get started! The problems › Typical programming contest problems usually consists of: – Problem description – Input description – Output description – Example input/output – A time limit in seconds – A memory limit in megabytes › You are asked to write a program that solves the problem for all valid inputs. – In IOI, partial solved problem receive partial score. › The program must not exceed time or memory limits!

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 28 Example problem Problem description Write a program that multiplies pairs of integers.

Input description Input starts with one line containing an integer , where 1 100, denoting the number of test cases. Then lines follow, each containing a test case. Each test case consists of , 2 A, 2 𝑇𝑇 ≤ 𝑇𝑇two≤ integers , where , separated𝑇𝑇 by a single space. 20 20 𝐴𝐴 𝐵𝐵 − ≤ 𝐵𝐵 ≤ Output description For each test case, output one line containing the value of × . 𝐴𝐴 𝐵𝐵 9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 29 Example problem

Sample input Sample output 4 12 3 4 0 13 0 8 1 8 10000 100 100

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 30 Correctness? › The solutions are incorrect! › If = = 2 , the output is 0. – Correct solution20 is 2 . 𝐴𝐴 𝐵𝐵 40 › 32-bit integer is too small, overflow will occur. – Can switch to 64-bit integer mode. (Architecture dependant) › Remedy: – long long int

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 31 Automatic judging › Automatic judging system will be declared per simulation. – DomJudge – Virtual Judge – IOI CMS › You can submit in any of the supported languages: – C – C++ – Java (IOI spec 2015) – Python

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 32 Judge verdicts (ACM-ICPC) › Feedback about solutions is limited › You will (usually) receive one of: – Accepted – Wrong Answer – Compile Error – Run Time Error – Time Limit Exceeded – Memory Limit Exceeded

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 33 Judge verdicts (IOI CMS) › You get more information › You will (usually) receive one of: – Percent of the test case completed › With detail listing of successful test case and unsuccessful ones. › However, the test case will not be revealed. – Compile Error – Run Time Error – Time Limit Exceeded – Memory Limit Exceeded

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 34 Tips › There are a couple of tips and guidelines you can keep in mind towards becoming a more effective programmer and better problem solver.

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 35 Tip 0: Faster typing › Become a faster/better typist. › Know your IDE (in ICPC competition, Eclipse!) › Don’t let your fingers be the limiting factor of solving problems quickly. › Good problem solvers have simple solutions; they don’t have to type as much, but it’s still important to type in quickly

› TypeRacer is a fun and effective way to practice: http://play.typeracer.com/

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 36 Tip 0: Faster Typing › Sometimes in competition, you may bring in a limited set of notes which contain code that you can type from the paper!

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 37 Tip 1: Quickly classify problems › Practice quickly identifying problem types. › Rate of appearance of different problem types in recent ICPC Asia Regional problem sets (which usually consists of 7-11 problems):

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 38 Category Sub-Category Frequency Ad Hoc Straightforward 1~2 Ad Hoc Simulation 0~1 Complete Search Iterative 0~1 Complete Search Backtracking 0~1 Divide & Conquer 0~1 Greedy Classic 0 Greedy Original 1 Dynamic Programming Classic 0 Dynamic Programming Original 1~3 Graph 1~2 Mathematics 1~2 String Processing 1 Computational Geometry 1 Harder Problems 0~1

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 39 Tip 1: Quickly classify problems › Moreover, identify whether or not you can solve the problem type: – Solved before / can solve again quickly. – Solved before / will take time to solve again. – Seen before / will solve this if all easier ones are solved. – Not sure! (驚~)

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 40 Tip 1: Quickly classify problems Exercise: What kind of problem is this?

Given an × integer matrix , check if there exists a sub‐matrix of of size × where mean( ) = 7? 𝑀𝑀 𝑁𝑁 𝑄𝑄 𝑄𝑄 𝐴𝐴 𝐵𝐵 𝑄𝑄 1 , 50 1 ≤1 𝑀𝑀 𝑁𝑁 ≤ ≤ 𝐴𝐴 ≤ 𝑀𝑀 ≤ 𝐵𝐵 ≤ 𝑁𝑁

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 41 Tip 2: Do algorithm analysis › When solving a problem, our solution has to be fast enough and can not use too much memory. › We also want our solution to be as simple as possible. › We can use Algorithm analysis to determine if a solution will run within the time limit. – Rule of thumb: 10 operations per second. › We want to sort 9 10 integers, and we have 3 seconds. – Can we use a simple O(6 ) bubble sort? – What about a more𝑛𝑛 ≤ complex2 log merge sort? 𝑛𝑛 › We want to sort 10 integers,𝑂𝑂 𝑛𝑛 and𝑛𝑛 we have 3 seconds. – Can we now use the simple3 ( ) bubble sort? 𝑛𝑛 ≤ 2 › Always go for the simplest 𝑂𝑂solution that will pass the time limit!

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 42 Tip 2: Do algorithm analysis › You should practice doing approximate mental calculations. – Rule of thumb: 2 10 . 10 3 › Sometimes you have≈ a solution that you’re not sure is correct: – Try to prove it’s correct! – Even if you don’t manage to prove or disprove it, you will probably get a better understanding of the problem! › After discovering a solution, convince yourself that it runs in time and memory! – Look at the constraints of the problem. – Worst-case analysis before starting to code.

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 43 Tip 2: Do algorithm analysis

Slowest Accepted Algorithm Example 10 ! , Enumerating a permutation 𝒏𝒏 15 (2 × 6) DP TSP ≤ 𝑂𝑂 𝑛𝑛 𝑂𝑂 𝑛𝑛 20 2 𝑛𝑛 , 2 DP + bitmask technique ≤ 𝑂𝑂 𝑛𝑛 50 𝑛𝑛( ) 5 DP with 3 dimensions + ( ) ≤ 𝑂𝑂 𝑂𝑂 𝑛𝑛 4 loop, choosing = 4. ≤ 𝑂𝑂 𝑛𝑛 𝑂𝑂 𝑛𝑛 10 ( ) Floyd Warshall’s𝑛𝑛 𝐶𝐶𝑘𝑘 102 ( 3) Bubble/Selection/Insertion sort ≤ 𝑂𝑂 𝑛𝑛 103 ( log2 ) Merge sort, Quick sort, building ≤ 𝑂𝑂 𝑛𝑛 5 a segment tree ≤ 𝑂𝑂 𝑛𝑛 𝑛𝑛 10 , (log ), (1) Contest problem input have 6 10 size. ≤ 𝑂𝑂 𝑛𝑛 𝑂𝑂 𝑛𝑛 𝑂𝑂 6 𝑛𝑛 ≤

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 44 Tip 3: Master programming languages › You should know your like the back of your hand. › After thinking of a solution, convey the solution in code as quickly as possible. › Use libraries, shortcuts, and write simple code. › This includes your programming language’s library: – C++’s Standard Template Library (STL) – The Java Class Library › If it’s already implemented in the standard library, you usually don’t need to implement it yourself!

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 45 Tip 3: Master programming languages › Java: – Scanner, BigInteger, String static functions, – Collections, diferent data types – Integer.parseInt() – String.substring() – etc › C++ – next_permutation(), sort(), vector, … › C – qsort(), malloc(), …

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 46 Tip 4: Test your solution › You want to make sure your solution is correct and › runs within the time limit. › Or you already know it’s wrong, but don’t know why… – Try to break your solution by finding a counterexample. – (an input for which your solution gives incorrect output, or takes too long to compute an answer) › Try edge cases, large inputs, ... › Submit correctly! – Competitions only care about correct code. – Is it worth the 20 minute penalty to submit without test cases? – The best teams write test cases before submitting their solutions!

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 47 Tip 5: Practice, more practice, and more practice › Problem solving and programming skills come with practice. › Lots of online judges that let you solve problems from past contests. › Some of these online judges also hold contests frequently! › UVa, Codeforces, TopCoder, ZeroJudge, PTC, CPE, ...

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 48 Tip 6: Teamwork › IOI is 1-on-1, but ICPC is 3-on-3. – Knowing your teammates. › Delegating problems to each other. – Sharing the computer time effectively. – Creating test cases for each other. – Being able to convey ideas. – Pair programming.

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 49 Ad Hoc problems IQ testing problems Ad Hoc problems › The simplest kind of problem. › Just do what the problem description tells you. › Straightforward or a simulation. › Time limit is not an issue. › Sometimes long and misleading problem descriptions. › Sometimes tricky edge cases. › Complex problems can be hard to implement.

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 51 Problem recipe › Problem narrative. – Can be unnecessarily long or misleading….. › Input and output description. – Usually very precise. – You may assume that all input will be formatted like this. › Sample input and output. – One or more inputs and expected outputs.

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 52 Problem: Automatic Answer (uva 11547) Last month Alice nonchalantly entered her name in a draw for a Tapmaster 4000. Upon checking her mail today, she found a letter that read: “Congratulations, Alice! You have won a Tapmaster 4000. To claim your prize, you must answer the following skill testing question.” Alice's initial feelings of surprised joy turned quickly to those of dismay. Her lifetime record for skill testing questions is an abysmal 3 right and 42 wrong. Mad Skills, the leading skill testing question development company, was hired to provide skill testing questions for this particular Tapmaster 4000 draw. They decided to create a different skill testing question to each winner so that the winners could not collaborate to answer the question. Can you help Alice win the Tapmaster 4000 by solving the skill testing question?

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 53 Problem: Automatic Answer (uva 11547) Input The input begins with (1 100), the number of test cases. Each test case contains an integer ( 1000 1000) on a line 𝑡𝑡by ≤itself𝑡𝑡 ≤. This should be substituted into the skill testing question below𝑛𝑛. − ≤ 𝑛𝑛 ≤ 𝑛𝑛 Output For each test case, output the answer to the following skill testing question on a line by itself: “Multiply by 567, then divide the result by 9, then add 7492, then multiply by 235, then divide by 47, then subtract 498𝑛𝑛. What is the digit in the tens column?”

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 54 Problem: Automatic Answer (uva 11547)

Sample input Sample output 2 1 637 3 -120

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 55 Parsing test cases › Most problems will have numerous test cases. › Different problems ask for different ways of parsing test cases: – Automatic Answer tells you how many test cases there are. – Some problems say “parse until a termination line of all zeros”. › Others will have you read until end of file .

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 56 Problem: Cost Cutting Company XYZ have been badly hit by recession and is taking a lot of cost cutting measures. Some of these measures include giving up office space, going open source, reducing incentives, cutting on luxuries and issuing pink slips.

They have got three (3) employees working in the accounts department and are going to lay-off two (2) of them. After a series of meetings, they have decided to dislodge the person who gets the most salary and the one who gets the least. This is usually the general trend during crisis like this. You will be given the salaries of these 3 employees working in the accounts department. You have to find out the salary of the person who survives.

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 57 Problem: Cost Cutting Input The first line of input is an integer ( < 20) that indicates the number of test cases. Each case consists of a line with 3 distinct positive integers.𝑇𝑇 These𝑇𝑇 3 integers represent the salaries of the three employees. All these integers will be in the range [1000,10000].

Output For each case, output the case number followed by the salary of the person who survives.

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 58 Problem: Cost Cutting

Sample input Sample output 3 Case 1: 2000 1000 2000 3000 Case 2: 2500 3000 2500 1500 Case 3: 1500 1500 1200 1800

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 59 Problem: SMS Typing Cell phones have become an essential part of modern life. In addition to making voice calls, cell phones can be used to send text messages, which are known as SMS for short. Unlike computer keyboards, most cell phones have limited number of keys. To accommodate all alphabets, letters are compacted into single key. Therefore, to type certain characters, a key must be repeatedly pressed until that character is shown on the display panel. In this problem we are interested in finding out the number of times keys on a cell phone must be pressed to type a particular message.

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 60 Problem: SMS Typing In this problem we will assume that the key pad of our cell phone is arranged as follows. abc def ghi jkl mno pqrs tuv wxyz In the above grid each cell represents one key. Here means a space. In order to type the letter ‘a’, we must press that key once, however to type ‘b’ the same key must be repeatedly pressed twice and for ‘c’ three times. In the same manner, one key press for ‘d’, two for ‘e’ and three for ‘f’. This is also applicable for the remaining keys and letters. Note that it takes a single press to type a space.

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 61 Problem: SMS Typing Input The first line of input will be a positive integer where denotes the number of test cases. lines will then follow each containing only spaces and lower case letters𝑇𝑇 . Each𝑇𝑇 line will contain at least 1 and at most𝑇𝑇 100 characters.

Output For every case of input there will be one line of output. It will first contain the case number followed by the number of key presses required to type the message of that case. Look at the sample output for exact formatting.

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 62 First Simulation › Form teams of 3. – AT or RT › Usual rule: – 1 PC per team. – Printing available. – Can discuss problems with teammates (keep volume low). – Balloons!

9/11/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 63