Suppose you have a string S which has length N and is indexed from 0 to N−1. String R is the reverse of the string S. The string S is funny if the condition |Si−Si−1|=|Ri−Ri−1| is true for every i from 1 to N−1.
(Note: Given a string str, stri denotes the ascii value of the ith character (0-indexed) of str. |x| denotes the absolute value of an integer x)
SAMPLE
INPUT
2
acxz
bcxz
SAMPLE OUTPUT
Funny
Not Funny
Explanation
Consider the 1st testcase acxz :
c-a
x-z
= 2
z-x
a-c
= 2
Consider the 2st testcase bcxz
|c-b| != |x-z|
Assistant
We need to write a solution for the "Funny String" problem. This is a known problem from HackerRank. The user provided sample input and output. They want us to produce a solution, presumably code.
The problem: For each test case, given a string S, we need to check if it's funny. Condition: For i from 1 to N-1, |S[i] - S[i-1]| == |R[i] - R[i-1]| where R is reverse of S. If all equal, output "Funny", else "Not Funny".
We need to read integer T (number of test cases) from input, then process each string.
We'll implement a function to check. Complexity O(N) per test case.
Edge cases: empty string? Not given; N>=2? Usually N≥2, but could be 1? If N=1, condition vacuously true? Probably not needed.
We'll write code accordingly.
We need to output exactly "Funny" or "Not Funny" per line.
Let's produce a Python solution.
We'll read from stdin, process.
Implementation details:
For each string s, compute r = s[::-1].
Loop i from 1 to len(s)-1:
if abs(ord(s[i]) - ord(s[i-1])) != abs(ord(r[i]) - ord(r[i-1])): return False
If loop completes, return True.
Then output accordingly.
We must handle T test cases.
We should write in a function solve().
Let's produce final code.
Also note: The problem statement says "SAMPLE INPUT" has two test cases: "acxz" and "bcxz". Output "Funny" and "Not Funny".
Ok.
We'll produce the code.
We can do some optimization: Instead of constructing r explicitly, we can compute reverse differences using indices: r[i] = s[N-1-i]. Then condition: abs(ord(s[i])-ord(s[i-1])) == abs(ord(s[N-1-i]) - ord(s[N-2-i])). But either is fine.
We'll use explicit reverse for clarity.
Let's code.
Add if name == "main": solve()
That's it.
Now produce final answer. ```python
import sys
def is_funny(s: str) -> bool:
"""Return True if the string s is funny, otherwise False."""
r = s[::-1] # reversed string
n = len(s)
for i in range(1, n):
if abs(ord(s[i]) - ord(s[i-1])) != abs(ord(r[i]) - ord(r[i-1])):
return False
return True
def solve() -> None:
data = sys.stdin.read().strip().split()
if not data:
return
t = int(data[0])
out_lines = []
idx = 1
for _ in range(t):
s = data[idx]
idx += 1
out_lines.append("Funny" if is_funny(s) else "Not Funny")
sys.stdout.write("\n".join(out_lines))