Codeforces Round 1133 (Div. 1, Div. 2) is coming soon! Register here. ×

A2SV G7 — Round #1 Editorial
Difference between en7 and en8, changed 2 character(s)
[Here](https://codeforces.me/contests/670139) is the contest link.↵
#### [A. New Year String] (https://codeforces.me/gym/670139/problem/A)↵
↵
<spoiler summary="Solution">↵
The key observation for solving this problem is that any occurrence of `2025` can be converted into `2026` using a single operation. Therefore, if the given string does not already satisfy any of the conditions stated in the problem, only one operation is needed to create an occurrence of `2026` (since the string contains `2025` when it is not already a New Year string).↵
↵
As a result, the answer is always either `0` or `1`.↵
To determine whether the answer is `0`, simply check if the string satisfies at least one of the required conditions. This can be done using the `in` operator method in Python.↵
 </spoiler>↵
↵
<spoiler summary="Code">↵
```python3↵
t = int(input())↵
for _ in range(t):↵
   n = int(input())↵
   s = input()↵
   if '2025' not in s or '2026' in s:↵
      print(0)↵
   else:↵
      print(1)↵
↵
↵
```↵
</spoiler>↵
↵
↵
↵
↵
↵
#### [B. Kidus's Scrambled Notebook] (https://codeforces.me/gym/670139/problem/B)↵
↵
<spoiler summary="Solution">↵
We can iterate over all possible ways to split `ab` into `a` and `b`. For each split, first check whether `b` has a leading zero. If it does not, compare the integer values of `a` and `b`.↵
↵
To convert a string into an integer, you can use `int(s)` in Python.↵
 </spoiler>↵
↵
<spoiler summary="Code">↵
```python3↵
t = int(input())↵
for _ in range(t):↵
    ab = input()↵
    for i in range(1, len(ab)):↵
        if ab[i] != '0' and int(ab[:i]) < int(ab[i:]):↵
            print(ab[:i], ab[i:])↵
            break↵
    else:↵
        print(-1)↵
↵
```↵
</spoiler>↵
↵
↵
↵
↵
#### [C. Ludis’s Ranker] (https://codeforces.me/gym/670139/problem/C)↵
↵
<spoiler summary="Solution">↵
For each element in the array, we iterate over the entire array and count how many elements are strictly greater than the current one. After computing this count, we add one and include the result in the total sum.↵
↵
To achieve this, we use two nested loops: the outer loop selects the current element, and the inner loop compares it with every other element in the array. By repeating this process for all elements, we obtain the final answer.↵
 </spoiler>↵
↵
<spoiler summary="Code">↵
```python3↵
n  = int(input())↵
arr = [int(i) for i in input().split()]↵
position = []↵
 ↵
for i in range(n): ↵
    count = 0↵
    for j in range(n): ↵
        if arr[i] < arr[j]:↵
            count += 1 ↵
    position.append(count + 1) ↵
 ↵
print(*position)   ↵
```↵
</spoiler>↵
↵
↵
↵
#### [D. Mash and the Awash River] (https://codeforces.me/gym/670139/problem/D)↵
↵
<spoiler summary="Solution"> <ol> <li> <strong>Check for infinite movement:</strong> <ul> <li>If the string contains two consecutive asterisks <code>**</code>,</li> <li>If an asterisk is next to an arrow in the “wrong” direction (<code>*<</code> or <code>>*</code>),</li> <li>If there is a <code>><</code> pattern (an arrow pointing right immediately followed by an arrow pointing left),</li> </ul> then Mash can move back and forth forever. In this case, the answer is <code>-1</code>. </li> <li> <strong>Calculate the maximum sailing distance if movement is finite:</strong> <ul> <li>For a <code>&lt;</code> at position <code>i</code>, Mash can move left to the start, passing <code>i + 1</code> cells.</li> <li>For a <code>&gt;</code> at position <code>i</code>, Mash can move right to the end, passing <code>len(s) &mdash; i</code> cells.</li> <li>For a <code>*</code> at position <code>i</code>, Mash can choose the direction that allows him to pass more cells. We take the maximum of <code>i + 1</code> and <code>len(s) &mdash; i</code>.</li> </ul> The maximum number of cells Mash can traverse is the largest value obtained among all positions. </li> </ol> </spoiler>↵
↵
<spoiler summary="Code">↵
```python3↵
t = int(input())↵
for _ in range(t):↵
    s = input()↵
    if '**' in s or '*<' in s or '>*' in s or '><' in s:↵
        print(-1)↵
 ↵
    else:↵
       max_ = 0↵
       for i in range(len(s)):↵
           if s[i] == '<':↵
               max_ = max(max_, i + 1)↵
        ↵
           elif s[i] == '>':↵
               max_ = max(max_, len(s) - i)↵
        ↵
           else:↵
            max_ = max(max_, i + 1, len(s) - i)↵
    ↵
       print(max_)↵
```↵
</spoiler>↵
↵
↵
#### [E. From S To T] (https://codeforces.me/gym/670139/problem/E)↵
↵
<spoiler summary="Solution"> To determine if we can form the string <code>t</code> using characters from <code>s</code> and <code>p</code>, we need to check **two key conditions**:↵
↵
<ol>↵
<li>↵
<strong>Subsequence Condition:</strong>↵
↵
The string <code>s</code> must be a subsequence of <code>t</code>. This means all characters of <code>s</code> should appear in <code>t</code> in the same order.↵
↵
We can verify this using a two-pointer approach, scanning through both strings simultaneously.↵
</li>↵
<li>↵
<strong>Frequency Condition:</strong>↵
↵
Let <code>f(str, a)</code> represent the number of occurrences of character <code>a</code> in <code>str</code>.↵
↵
For each character <code>a</code>, the condition↵
<code>f(s, a) + f(p, a) ≥ f(t, a)</code>↵
must hold. This ensures that any characters missing from <code>s</code> can be supplied by <code>p</code> to form <code>t</code>.↵
</li>↵
</ol>↵
↵
If both conditions are satisfied, the answer is <code>YES</code>; otherwise, it is <code>NO</code>.↵
</spoiler>↵
↵
↵
<spoiler summary="Code">↵
```python3↵
def solve():↵
    # Read the input strings s, t, and p for the current query↵
    s = input()↵
    t = input()↵
    p = input()↵
↵
    # Check if s is a subsequence of t↵
    i, j = 0, 0  ↵
    while i < len(s) and j < len(t):↵
        # If characters match, move to the next character in s↵
        if s[i] == t[j]:↵
            i += 1↵
        # Always move to the next character in t↵
        j += 1  ↵
↵
    # If we couldn't match all characters of s in t, then s is not a subsequence of t↵
    if i != len(s):↵
        print("NO")↵
        return↵
↵
    # Count the frequency of each character in t↵
    freq_t = {}↵
    for char in t:↵
        freq_t[char] = freq_t.get(char, 0) + 1↵
↵
    # Count the frequency of each character in both s and p combined↵
    freq_s_p = {}↵
    for char in s + p:↵
        freq_s_p[char] = freq_s_p.get(char, 0) + 1↵
↵
    # Ensure that for every character in t, we have enough occurrences in s and p↵
    for char, required_count in freq_t.items():↵
        available_count = freq_s_p.get(char, 0)↵
        if required_count > available_count:↵
            print("NO")↵
            return↵
↵
    # If all checks pass, s can be transformed into t using characters from p↵
    print("YES")↵
↵
↵
# Read the number of queries and process each one↵
q = int(input())  ↵
for _ in range(q):↵
    solve()↵
```↵
</spoiler>↵
↵

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en8 English A2SV_Group6 2026-02-10 10:22:38 2 (published)
en7 English A2SV_Group6 2026-02-09 17:20:10 1782
en6 English A2SV_Group6 2026-02-09 17:03:08 100
en5 English A2SV_Group6 2026-02-09 16:58:39 1 Tiny change: '().split())]\npositi' -> '().split()]\npositi'
en4 English A2SV_Group6 2026-02-08 20:32:14 55
en3 English A2SV_Group6 2026-02-08 20:30:37 1
en2 English A2SV_Group6 2026-02-08 20:28:31 6239 Tiny change: ' or '2026':\n p' -> ' or '2026' in s:\n p'
en1 English A2SV_Group6 2026-02-08 17:14:15 1154 Initial revision (saved to drafts)