codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

255B.md (2723B)


      1 Source: https://codeforces.com/problemset/problem/255/B
      2 
      3 B. Code Parsing
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string *s*, consisting of characters "x" and "y", and uses two following operations at runtime:
     22 
     23 1. Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string.
     24 2. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string.
     25 
     26 The input for the new algorithm is string *s*, and the algorithm works as follows:
     27 
     28 1. If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string.
     29 2. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm.
     30 
     31 Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string *s*.
     32 
     33 Input
     34 
     35 The first line contains a non-empty string *s*.
     36 
     37 It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string.
     38 
     39 Output
     40 
     41 In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string *s*.
     42 
     43 Examples
     44 
     45 Input
     46 
     47 ```
     48 x
     49 ```
     50 
     51 Output
     52 
     53 ```
     54 x
     55 ```
     56 
     57 Input
     58 
     59 ```
     60 yxyxy
     61 ```
     62 
     63 Output
     64 
     65 ```
     66 y
     67 ```
     68 
     69 Input
     70 
     71 ```
     72 xxxxxy
     73 ```
     74 
     75 Output
     76 
     77 ```
     78 xxxx
     79 ```
     80 
     81 Note
     82 
     83 In the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.
     84 
     85 In the second test the transformation will be like this:
     86 
     87 1. string "yxyxy" transforms into string "xyyxy";
     88 2. string "xyyxy" transforms into string "xyxyy";
     89 3. string "xyxyy" transforms into string "xxyyy";
     90 4. string "xxyyy" transforms into string "xyy";
     91 5. string "xyy" transforms into string "y".
     92 
     93 As a result, we've got string "y".
     94 
     95 In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx".