723B.md (2727B)
1 Source: https://codeforces.com/problemset/problem/723/B 2 3 B. Text Document Analysis 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Modern text editors usually show some information regarding the document being edited. For example, the number of words, the number of pages, or the number of characters. 22 23 In this problem you should implement the similar functionality. 24 25 You are given a string which only consists of: 26 27 * uppercase and lowercase English letters, 28 * underscore symbols (they are used as separators), 29 * parentheses (both opening and closing). 30 31 It is guaranteed that each opening parenthesis has a succeeding closing parenthesis. Similarly, each closing parentheses has a preceding opening parentheses matching it. For each pair of matching parentheses there are no other parenthesis between them. In other words, each parenthesis in the string belongs to a matching "opening-closing" pair, and such pairs can't be nested. 32 33 For example, the following string is valid: "_Hello_Vasya(and_Petya)__bye_(and_OK)". 34 35 Word is a maximal sequence of consecutive letters, i.e. such sequence that the first character to the left and the first character to the right of it is an underscore, a parenthesis, or it just does not exist. For example, the string above consists of seven words: "Hello", "Vasya", "and", "Petya", "bye", "and" and "OK". Write a program that finds: 36 37 * the length of the longest word outside the parentheses (print 0, if there is no word outside the parentheses), 38 * the number of words inside the parentheses (print 0, if there is no word inside the parentheses). 39 40 Input 41 42 The first line of the input contains a single integer *n* (1 ≤ *n* ≤ 255) — the length of the given string. The second line contains the string consisting of only lowercase and uppercase English letters, parentheses and underscore symbols. 43 44 Output 45 46 Print two space-separated integers: 47 48 * the length of the longest word outside the parentheses (print 0, if there is no word outside the parentheses), 49 * the number of words inside the parentheses (print 0, if there is no word inside the parentheses). 50 51 Examples 52 53 Input 54 55 ``` 56 37 57 _Hello_Vasya(and_Petya)__bye_(and_OK) 58 ``` 59 60 Output 61 62 ``` 63 5 4 64 ``` 65 66 67 68 69 Input 70 71 ``` 72 37 73 _a_(_b___c)__de_f(g_)__h__i(j_k_l)m__ 74 ``` 75 76 Output 77 78 ``` 79 2 6 80 ``` 81 82 83 84 85 Input 86 87 ``` 88 27 89 (LoooonG)__shOrt__(LoooonG) 90 ``` 91 92 Output 93 94 ``` 95 5 2 96 ``` 97 98 99 100 101 Input 102 103 ``` 104 5 105 (___) 106 ``` 107 108 Output 109 110 ``` 111 0 0 112 ``` 113 114 Note 115 116 In the first sample, the words "Hello", "Vasya" and "bye" are outside any of the parentheses, and the words "and", "Petya", "and" and "OK" are inside. Note, that the word "and" is given twice and you should count it twice in the answer.