We need to solve a problem: given string S, length between 4 and 10 inclusive, letters only. Conditions:
The initial character of S is an uppercase 'A'.
There is exactly one occurrence of 'C' between the third character from the beginning and the second to last character (inclusive). That is, we consider characters from index 2 (0-based? careful: "between the third character from the beginning and the second to last character (inclusive)". Let's parse. Usually: "the third character from the beginning" means position 3 (1-indexed). "the second to last character" means the character before the last (position length-1 in 1-indexed). So the region includes positions: 3,4,..., len-1? Actually "between the third character from the beginning and the second to last character (inclusive)" means: start at third character, end at second-to-last character, and include both ends. So indices: 1-indexed: position 3 to position len-1? Wait: if S = "AtCoder", length 7. Positions: 1:A, 2:t, 3:C, 4:o, 5:d, 6:e, 7:r. The second to last character is position 6 (since last is 7). The region is positions 3 to 6 inclusive. In "AtCoder", there is exactly one 'C' at position 3. That satisfies. So region: indices 2 to len-2 in 0-based? Let's check: 0-based: index0:A, index1:t, index2:C, index3:o, index4:d, index5:e, index6:r. The second to last character is index5 (since last index6). So region from index2 to index5 inclusive. That matches: index2 is third character, index5 is second last. So region is [2, len-2] inclusive? Actually len=7 => len-2=5, yes. So region = indices 2 through len-2 inclusive.
But wait, what if len=4? Minimum length. Then region from third character (index2) to second last character (index len-2 = 2). So region is just index2. So we need exactly one 'C' in that region, i.e., the character at index2 must be 'C'? But also there could be only one occurrence, so exactly one 'C' at index2. That's plausible. Check if constraints allow? Example: maybe "ACa"? But length must be at least 4, so len=4 => indices 0,1,2,3. Region is index2 only. Must have exactly one C. So if S = "AbcC"? Wait initial must be 'A' at index0, region index2 must be 'C', and other characters (index1 and index3) must be lowercase, and also must not be 'A' or 'C' (but they are lowercase anyway). So something like "A b C c"? But index3 must be lowercase, so "AbCc"? Let's see: "AbCc": index0='A', index1='b', index2='C', index3='c' -> but index3 is lowercase? 'c' is lowercase, okay. Then it would satisfy? But check "all letters except the A and C mentioned above are lowercase." That means all letters except the initial A and the exactly one C (somewhere in region) must be lowercase. So index1 must be lowercase, index3 must be lowercase. That's fine. So "AbCc" would be valid? But need exactly one C in region. Region only index2, so yes. So valid. However note that there might be other uppercase letters not allowed. So condition 3: all letters except the A (at start) and the C (the one in region) must be lowercase. So if there is any other uppercase letter (e.g., another C, or any uppercase) it's invalid. Also note: the region includes the possibility that the C appears at any position in the region, but there must be exactly one C in that region. Could also be that the initial A is part of region? No, region starts at index2, so initial A is not included. Also the last character? region ends at index len-2, so last character (index len-1) is not in region. So the C cannot be at first two indices nor at last index. But it's allowed to be at index2 up to index len-2 inclusive.
But also condition 3: all letters except that A and that C must be lowercase. So the last character must be lowercase. Also any other character outside region and inside region but not C must be lowercase.
Now, edge cases: uppercase letters only? Should not be.
Examples:
AtCoder: length7, region indices 2-5: characters: C, o, d, e => exactly one C. Others: index1 't' lowercase, index6 'r' lowercase. So valid.
ACoder: S = "ACoder"? Let's break: A C o d e r? Actually "ACoder" length6? Let's see: A (0), C (1), o (2), d (3), e (4), r (5). Region indices 2-4 inclusive: indices2='o',3='d',4='e' => no C, so fails exactly one occurrence (0). So WA.
AcycliC: length? "AcycliC" = A c y c l i C? Actually: A (0), c? Wait careful: "AcycliC": characters: A (uppercase), c (lowercase), y (lowercase), c (lowercase), l (lowercase), i (lowercase), C (uppercase) -> length7. Region indices2-5: indices2='y'? Wait indexing: 0:A, 1:c, 2:y, 3:c, 4:l, 5:i, 6:C. Region indices2-5: y, c, l, i => no uppercase C. Also last character is uppercase C, violating condition 3 (since it's not the allowed A or the allowed C). So WA.
AtCoCo: length6? Actually "AtCoCo": A t C o C o? Let's write: 0:A,1:t,2:C,3:o,4:C,5:o. Region indices2-4: C, o, C => two C's, so fails exactly one. Also index4 is uppercase C but not the only one? but condition fails anyway. So WA.
Atcoder: length7? Actually "Atcoder": A t c o d e r? That's all lowercase except initial A? Actually "Atcoder" is all lowercase except A? But A is uppercase, yes. Region indices2-5: c, o, d, e => no C. So fails exactly one. WA.
So our interpretation seems correct.
Implementation: read S, compute len n. Check:
len >= 4? Given.
S[0] == 'A'
In substring S[2:n-1]? Actually inclusive indices: from 2 to n-2 inclusive. In Python, we can take substring S[2:n-1] (since slicing end exclusive, n-1 exclusive gives up to n-2 inclusive). So sub = S[2:n-1]. Count number of 'C' in sub. Must equal 1.
Additionally, all characters except the A at index0 and that single C (somewhere) must be lowercase. But careful: there might be other uppercase letters that are not C. So we need to verify that the string, after removing (or ignoring) the required A and that one C, all other characters are lowercase. However, note that the C might be somewhere else? Actually we need to ensure exactly one C in the region, and that C is the only uppercase besides initial A. But there could be other uppercase letters, e.g., 'B' anywhere, which would violate. Also there could be other 'C's outside the region, which would also violate condition 3 because they would be uppercase not allowed. So we can check:
After confirming that S[0] == 'A' and that there is exactly one 'C' in S[2:n-1], we also need to ensure that for all i from 0 to n-1, if i != 0 and i != position_of_C (where the allowed C is), then S[i] is lowercase. But note: the allowed C must be within region and there is exactly one. So we can find its index (the first occurrence maybe) and then verify that all other characters (excluding index0 and that index) are lowercase. However, we must also ensure that there is no other 'C' besides that one, because if there is another 'C' elsewhere, then that character would be uppercase and not allowed. So this check will capture that as well, because that other C would be uppercase and not excluded.
But there is nuance: Could the allowed C be at index0? No, because region starts at index2, so not allowed. Could there be an uppercase A somewhere else? That would be uppercase not allowed. So the check handles.
Alternative: we can just convert the whole string to a list and check:
S[0] == 'A'.
Count of 'C' in S[2:n-1] == 1.
For all characters in S, they must be either lowercase, or if uppercase, only at positions: 0 (must be 'A') and one specific index in [2, n-2] where it's 'C'. So we can check that S[1:].replace('C', ...) Actually simpler: make a copy of S, set characters at allowed positions to lowercase temporarily? Instead, we can iterate over indices i:
if i == 0: require S[i] == 'A'. (Already checked)
else if i is in [2, n-2] and S[i] == 'C' and we haven't seen the allowed C? But we need exactly one C in region. So after confirming that there is exactly one C in region, we can note its index posC (the index of that C). Then for all i:
if i == 0 or i == posC: continue (already uppercase as required)
else: check S[i].islower().
But careful: what if posC is not determined? Since count is exactly 1, we can find it by scanning region. If count !=1, we already fail. Then we can check other characters.
Also note: The allowed C must be uppercase. That is assured if we check S[posC] == 'C'.
Now also, what about the possibility that S[0] is 'A' and there is exactly one C in region, but that C is not uppercase? Actually 'C' is uppercase by definition. But we counted 'C' as the character 'C', so it's uppercase. So that's fine.
Thus algorithm steps:
n = len(S)
if S[0] != 'A': print("WA"); return
count_c = 0; posC = -1
for i in range(2, n-1): // since n-1 exclusive? Actually region includes index n-2, so range(2, n-1) gives i up to n-2 inclusive because Python range stops before n-1. So range(2, n-1) gives indices 2,..., n-2.
if S[i] == 'C':
count_c += 1
posC = i
if count_c != 1: print("WA"); return
for i in range(n):
if i == 0 or i == posC: continue
if not S[i].islower(): print("WA"); return
print("AC")
Edge Cases: n=4: region indices range(2,3) gives only index2. So we check only S[2]. Must be 'C'. Then posC = 2. Then check other indices: i=0 (skip), i=1 (must be lowercase), i=2 (skip), i=3 (must be lowercase). Works.
n=5: region indices 2,3? range(2,4) gives indices 2 and 3. Must have exactly one C among them. Then other indices: 0,1,4 must be lowercase except 0 is A. Good.
Also check case when allowed C might be at index n-1? But region ends at n-2, so not allowed. Already covered.
Check condition "All letters except the A and C mentioned above are lowercase." So if there is any uppercase letter besides those, WA.
Test with some strings:
"AbCC"? length4? Actually "AbCC": indices: 0:A,1:b,2:C,3:C. Region index2 is 'C', count_c=1? Wait region index2 only, but index3 is not in region. So count_c=1 (since only index2 is C). But index3 is uppercase 'C', so later check: for i=3, not i==0 or i==posC (posC=2) so S[3] is uppercase, not lowercase => WA. Correct.
"ACcC"? length4? Actually "ACcC": 0:A,1:C,2:c,3:C. Region index2 is 'c' (lowercase), so count_c=0 => WA. Good.
"AaCaAa"? Let's construct a valid example: n=7. Must have exactly one C between indices 2-5. So choose posC=3 for example. Others lowercase. Also initial A. So S = "AaCaAa"? Check: index0:A, index1:a, index2:?, index3:C, index4:a, index5:a, index6:a? Actually need all lowercase except those. So "AabCaaa"? Wait length7: indices:0:A,1:? must be lowercase,2:? can be any lowercase,3:C,4:lowercase,5:lowercase,6:lowercase. So "AabCdef"? Actually last index must be lowercase. So "AabCdef" works? Check region indices2-5: index2='b', index3='C', index4='d', index5='e' => exactly one C. Others: index1='a', index6='f' lowercase. So "AabCdef" would be valid. However note: The string must consist of letters only; all good.
Now test with extra uppercase not C: "AAbCdef": S[0]='A' ok, region indices2-5: index2='b', index3='C', index4='d', index5='e' => count_c=1. posC=3. Others: index1='A' uppercase, not allowed -> WA. Good.
Now test with more than one C in region but one C outside? Already covered.
Now test with uppercase C at first char? No initial must be A, not C, so if S[0]='C', fails first condition.
Now test with uppercase C as last character: "abcC" can't because initial not A. But "AbcC"? length4, region index2='c' (lowercase) so no C in region => fail count_c. So WA. Good.
Thus solution is straightforward.
Time complexity O(|S|) which is tiny.
Now implement solve() accordingly.
Potential pitfalls: The problem statement says "between the third character from the beginning and the second to last character (inclusive)". So region includes both ends. Implementation with range(2, len(S)-1) is correct because len(S)-1 is exclusive, so last index is len(S)-2. For len(S)=4, len(S)-1=3, range(2,3) gives index2 only. Works.
But be careful: In Python, slicing S[2:-1] works as well, but -1 means last excluded, so S[2:-1] gives characters from index2 to index len-2 inclusive. That is same. However, need to handle case len=4: S[2:-1] gives index2 to index2 (since -1 is index3 excluded). So it's fine.
Alternatively use S[2:n-1] with n = len(S). Since n-1 is index of last, so S[2:n-1] stops before n-1, including n-2. Good.
Now confirm condition 3: "All letters except the A and C mentioned above are lowercase." That includes the characters outside region, and also characters in region that are not the C. So our loop check covers all except allowed positions. However, we must ensure that the initial A is indeed uppercase 'A', and the C in region is uppercase 'C'. Already ensured. So no further checks needed.
Edge Cases: What if there is exactly one C in region, but the initial A is not uppercase? Already fail. Or if there is exactly one C in region, but that C is actually lowercase? The count of 'C' counts only uppercase C? The statement says "exactly one occurrence of C". Typically C refers to uppercase C. In examples, they consider uppercase C. And letters are uppercase or lowercase English letters. So 'C' means uppercase C. So we should check for 'C' character exactly. If there is a lowercase 'c' it doesn't count as C. So our counting of 'C' counts uppercase 'C'. Good.
Now implement.
Note: Input may contain trailing newline. We'll strip.
Now produce final solution.
But sometimes problem statements require to output "AC" if passes, else "WA". So case-sensitive.
Now I'll write solve().
Let's code:
def solve():
import sys
S = sys.stdin.readline().strip()
n = len(S)
if n < 4: # Not needed per constraints, but safe
print("WA")
return
if S[0] != 'A':
print("WA")
return
count_c = 0
posC = -1
for i in range(2, n-1): # from 2 to n-2 inclusive
if S[i] == 'C':
count_c += 1
posC = i
if count_c != 1:
print("WA")
return
for i in range(n):
if i == 0 or i == posC:
continue
if not ('a' <= S[i] <= 'z'): # or S[i].islower()
print("WA")
return
print("AC")
Alternatively use islower() method: S[i].islower() returns True for lowercase letters. Note that islower() returns False for non-letters but here only letters.
Now test with given examples.
Example1: S = "AtCoder", n=7, S[0]='A', region indices 2-5: S[2]='C', S[3]='o', S[4]='d', S[5]='e' -> count_c=1, posC=2. Then loop: i=0 skip, i=1 't' islower True, i=2 skip, i=3 'o' lower, i=4 'd' lower, i=5 'e' lower, i=6 'r' lower -> AC.
Example2: "ACoder", n=6, S[0]='A', region indices 2-4: S[2]='o', S[3]='d', S[4]='e' -> count_c=0 -> WA.
Example3: "AcycliC", n=7, S[0]='A', region indices2-5: S[2]='y', S[3]='c', S[4]='l', S[5]='i' -> count_c=0 -> WA. (But also last char uppercase fails later, but fails earlier)
Now check our own test: "AabCdef": n=7, region indices2-5: b, C, d, e -> count_c=1, posC=3. Then check: i=0 skip, i=1 'a' lower, i=2 'b' lower, i=3 skip, i=4 'd' lower, i=5 'e' lower, i=6 'f' lower -> AC.
Now check "AaCdef": n=6? Actually "AaCdef": length6: indices:0:A,1:a,2:C,3:d,4:e,5:f. Region indices2-4: S[2]='C', S[3]='d', S[4]='e' => count_c=1, posC=2. Others: i=1 'a' lower, i=3 'd' lower, i=4 'e' lower, i=5 'f' lower -> AC. So "AaCdef" is valid? Let's verify conditions: initial A, exactly one C between third char (index2) and second last (index4). Yes index2 is third character, index4 is second last? For length6, indices 0-5, second last is index4 (since last is index5). So region includes indices 2,3,4. Exactly one C at index2. All other letters: index1 a, index3 d, index4 e, index5 f are lowercase? index4 is 'e' lower, index5 'f' lower. That's fine. So "AaCdef" should be AC. But is there any hidden constraint? The problem statement might be from AtCoder ABC104-A? Actually this is exactly the problem "ABC104 A - Rated for Me"? No, it's "ABC104 A" is something else. Wait it's "ABC104"? Actually this is problem "ABC104 A" maybe? Or "ABC 129"? No, this looks like "ABC104"? Actually I recall a problem "ABC104 A" is about rating. But this is from "ABC 104"? Not sure. Let's search memory: There is AtCoder Beginner Contest 104 problem A? No, that's "Rated for Me". But this problem is reminiscent of "ABC 104"? Actually I recall a problem "ABC 104" maybe about "Password"? Not. There is a problem "ABC 104 A" about "Programming Education"? No. There's "ABC 104 B" about "AcCepted"? Wait there's a known problem "ABC 104 B" or "ABC 104 A"? Actually I recall a problem "AcCepted" from AtCoder Beginner Contest 104? Let's check: AtCoder Beginner Contest 104 was "A - Rated for Me", "B - AcCepted"? Yes, I think B is "AcCepted". That problem: Determine if a string satisfies conditions: first character is 'A', there is exactly one 'C' between the third character and the second-last character, and all other characters are lowercase. That's exactly this problem. So it's "ABC 104 B - AcCepted". Usually the output is "AC" or "WA". So it's correct.
Now note: In the problem "ABC 104 B", the constraints: 4 ≤ |S| ≤ 10. So yes.
Now the solution is done.
But there might be nuance: The condition says: "There is exactly one occurrence of C between the third character from the beginning and the second to last character (inclusive)." It doesn't say that the C must be uppercase? It says "C" which by convention is uppercase. But check: In example "AcycliC", last character is uppercase C but not counted as the allowed C because it's not within the region. So it's WA. So our interpretation stands.
Edge Cases: What if the allowed C appears at index2 (third character) and also there is another uppercase letter like 'C' at index n-2? But region includes index n-2, so that would be a second C in region, count_c=2 -> fail. Good.
What if the allowed C appears at index2 and there is uppercase 'A' at some other index? Then our loop will catch uppercase 'A' as not lowercase -> fail.
Now also note: The problem says "All letters except the A and C mentioned above are lowercase." This includes that the initial A and the allowed C can be uppercase; but also if there is any other uppercase, fails.
One more nuance: What if there is exactly one C in region, but the allowed C is not uppercase? Actually C is uppercase by definition. But if there is a lowercase 'c', it's not counted as C. So count_c counts only uppercase C. So region could have a lowercase 'c' but we need exactly one uppercase C. But the condition says "exactly one occurrence of C" which is uppercase. So that's fine.
Now double-check with given examples: Example "AcycliC": region has 'y','c','l','i' all lowercase; count_c=0. So fail. Good.
Thus solution is correct.
Now implement as full code.
Potential pitfalls: reading input, strip newline. Use sys.stdin.
Now produce final answer.
But note: The problem is trivial; but as an AI, we must output the final solution code.
Let's now produce final answer. ```python
import sys
def solve() -> None:
S = sys.stdin.readline().strip()
n = len(S)
code
# Condition 1: first character must be 'A'
if S[0] != 'A':
print("WA")
return
# Condition 2: exactly one 'C' in positions 2..n-2 (inclusive)
cnt_c = 0
pos_c = -1
for i in range(2, n - 1): # i = 2, 3, ..., n-2
if S[i] == 'C':
cnt_c += 1
pos_c = i
if cnt_c != 1:
print("WA")
return
# Condition 3: all other characters must be lowercase
for i in range(n):
if i == 0 or i == pos_c:
continue
if not ('a' <= S[i] <= 'z'): # equivalent to S[i].islower()
print("WA")
return
print("AC")