{"problem":{"name":"Two Strings","description":{"content":"You are given strings $S$ and $T$ of length $N$ each, consisting of lowercase English letters. For a string $X$ and an integer $i$, let $f(X,i)$ be the string obtained by performing on $X$ the followi","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc272_f"},"statements":[{"statement_type":"Markdown","content":"You are given strings $S$ and $T$ of length $N$ each, consisting of lowercase English letters.\nFor a string $X$ and an integer $i$, let $f(X,i)$ be the string obtained by performing on $X$ the following operation $i$ times:\n\n*   Remove the first character of $X$ and append the same character to the end of $X$.\n\nFind the number of integer pairs $(i,j)$ satisfying $0 \\le i,j \\le N-1$ such that $f(S,i)$ is lexicographically smaller than or equal to $f(T,j)$.\nWhat is the lexicographical order?Simply put, the lexicographical order is the order in which the words are arranged in a dictionary. Let us define it formally by describing an algorithm of finding the ordering of two distinct strings $S$ and $T$ consisting of lowercase English letters.\nHere, we denote \"the $i$\\-th character of a string $S$\" by $S_i$. Also, we write $S \\lt T$ and $S \\gt T$ if $S$ is lexicographically smaller and larger than $T$, respectively.\n\n1.  Let $L$ be the smallest of the lengths of $S$ and $T$. For $i=1,2,\\dots,L$, we check if $S_i$ equals $T_i$.\n2.  If there is an $i$ such that $S_i \\neq T_i$, let $j$ be the smallest such $i$. Comparing $S_j$ and $T_j$, we terminate the algorithm by determining that $S \\lt T$ if $S_j$ is smaller than $T_j$ in the alphabetical order, and that $S \\gt T$ otherwise.\n3.  If there is no $i$ such that $S_i \\neq T_i$, comparing the lengths of $S$ and $T$, we terminate the algorithm by determining that $S \\lt T$ if $S$ is shorter than $T$, and that $S \\gt T$ otherwise.\n\n## Constraints\n\n*   $1 \\le N \\le 2 \\times 10^5$\n*   $S$ and $T$ are strings of length $N$ each, consisting of lowercase English letters.\n*   $N$ is an integer.\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$N$\n$S$\n$T$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc272_f","tags":[],"sample_group":[["3\nadb\ncab","4\n\nThere are $4$ pairs of $(i, j)$ satisfying the conditions: $(0,0),(0,2),(2,0)$, and $(2,2)$.\n$(i,j)=(1,2)$ does not satisfy the conditions because $f(S,i)=$`dba` and $f(T,j)=$`bca`."],["10\nwsiuhwijsl\npwqoketvun","56"]],"created_at":"2026-03-03 11:01:14"}}