1674C.md (2055B)
1 Source: https://codeforces.com/problemset/problem/1674/C 2 3 C. Infinite Replacement 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 a string $s$, consisting only of Latin letters 'a', and a string $t$, consisting of lowercase Latin letters. 22 23 In one move, you can replace any letter 'a' in the string $s$ with a string $t$. Note that after the replacement string $s$ might contain letters other than 'a'. 24 25 You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large. 26 27 Two strings are considered different if they have different length, or they differ at some index. 28 29 Input 30 31 The first line contains a single integer $q$ ($1 \le q \le 10^4$) — the number of testcases. 32 33 The first line of each testcase contains a non-empty string $s$, consisting only of Latin letters 'a'. The length of $s$ doesn't exceed $50$. 34 35 The second line contains a non-empty string $t$, consisting of lowercase Latin letters. The length of $t$ doesn't exceed $50$. 36 37 Output 38 39 For each testcase, print the number of different strings $s$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number. 40 41 Example 42 43 Input 44 45 ``` 46 3 47 48 aaaa 49 50 a 51 52 aa 53 54 abc 55 56 a 57 58 b 59 ``` 60 61 Output 62 63 ``` 64 1 65 -1 66 2 67 ``` 68 69 Note 70 71 In the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one. 72 73 In the second example, you can replace the second letter 'a' with "abc". String $s$ becomes equal to "aabc". Then the second letter 'a' again. String $s$ becomes equal to "aabcbc". And so on, generating infinitely many different strings. 74 75 In the third example, you can either leave string $s$ as is, performing zero moves, or replace the only 'a' with "b". String $s$ becomes equal to "b", so you can't perform more moves on it.