codeforces-scrape

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

550A.md (1056B)


      1 Source: https://codeforces.com/problemset/problem/550/A
      2 
      3 A. Two Substrings
      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 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
     22 
     23 Input
     24 
     25 The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters.
     26 
     27 Output
     28 
     29 Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
     30 
     31 Examples
     32 
     33 Input
     34 
     35 ```
     36 ABA
     37 ```
     38 
     39 Output
     40 
     41 ```
     42 NO
     43 ```
     44 
     45 Input
     46 
     47 ```
     48 BACFAB
     49 ```
     50 
     51 Output
     52 
     53 ```
     54 YES
     55 ```
     56 
     57 Input
     58 
     59 ```
     60 AXBYBXA
     61 ```
     62 
     63 Output
     64 
     65 ```
     66 NO
     67 ```
     68 
     69 Note
     70 
     71 In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
     72 
     73 In the second sample test there are the following occurrences of the substrings: BACFAB.
     74 
     75 In the third sample test there is no substring "AB" nor substring "BA".