{"problem":{"name":"B. Obtaining the String","description":{"content":"You are given two strings $s$ and $t$. Both strings have length $n$ and consist of lowercase Latin letters. The characters in the strings are numbered from $1$ to $n$. You can successively perform th","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF1015B"},"statements":[{"statement_type":"Markdown","content":"You are given two strings $s$ and $t$. Both strings have length $n$ and consist of lowercase Latin letters. The characters in the strings are numbered from $1$ to $n$.\n\nYou can successively perform the following move any number of times (possibly, zero):\n\n*   swap any two adjacent (neighboring) characters of $s$ (i.e. for any $i = {1, 2, \\dots, n - 1}$ you can swap $s_i$ and $s_{i + 1})$.\n\nYou can't apply a move to the string $t$. The moves are applied to the string $s$ one after another.\n\nYour task is to obtain the string $t$ from the string $s$. Find any way to do it with at most $10^4$ such moves.\n\n_You do not have to minimize the number of moves, just find any sequence of moves of length $10^4$ or less to transform $s$ into $t$._\n\n## Input\n\nThe first line of the input contains one integer $n$ ($1 \\le n \\le 50$) — the length of strings $s$ and $t$.\n\nThe second line of the input contains the string $s$ consisting of $n$ lowercase Latin letters.\n\nThe third line of the input contains the string $t$ consisting of $n$ lowercase Latin letters.\n\n## Output\n\nIf it is impossible to obtain the string $t$ using moves, print \"_\\-1_\".\n\nOtherwise in the first line print one integer $k$ — the number of moves to transform $s$ to $t$. Note that $k$ must be an integer number between $0$ and $10^4$ inclusive.\n\nIn the second line print $k$ integers $c_j$ ($1 \\le c_j &lt; n$), where $c_j$ means that on the $j$\\-th move you swap characters $s_{c_j}$ and $s_{c_j + 1}$.\n\nIf you do not need to apply any moves, print a single integer $0$ in the first line and either leave the second line empty or do not print it at all.\n\n[samples]\n\n## Note\n\nIn the first example the string $s$ changes as follows: \"_abcdef_\" $\\rightarrow$ \"_abdcef_\" $\\rightarrow$ \"_abdcfe_\" $\\rightarrow$ \"_abdfce_\" $\\rightarrow$ \"_abdfec_\".\n\nIn the second example there is no way to transform the string $s$ into the string $t$ through any allowed moves.","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"你被给予两个字符串 $s$ 和 $t$。两个字符串长度均为 $n$，且均由小写拉丁字母组成。字符串中的字符编号从 $1$ 到 $n$。\n\n你可以任意次数（可能为零次）依次执行以下操作：\n\n你不能对字符串 $t$ 应用任何操作。所有操作均作用于字符串 $s$，并依次进行。\n\n你的任务是通过这些操作将字符串 $s$ 变为字符串 $t$。请找出一种在不超过 $10^4$ 次操作内完成变换的方法。\n\n_你无需最小化操作次数，只需找到任意一个长度不超过 $10^4$ 的操作序列，将 $s$ 转换为 $t$。_\n\n输入的第一行包含一个整数 $n$ ($1 lt.eq n lt.eq 50$) —— 字符串 $s$ 和 $t$ 的长度。\n\n第二行包含字符串 $s$，由 $n$ 个小写拉丁字母组成。\n\n第三行包含字符串 $t$，由 $n$ 个小写拉丁字母组成。\n\n如果无法通过操作得到字符串 $t$，请输出 \"_-1_\"。\n\n否则，在第一行输出一个整数 $k$ —— 将 $s$ 转换为 $t$ 所需的操作次数。注意 $k$ 必须是介于 $0$ 和 $10^4$ 之间（含端点）的整数。\n\n在第二行输出 $k$ 个整数 $c_j$ ($1 lt.eq c_j < n$)，其中 $c_j$ 表示第 $j$ 次操作中交换字符 $s_{c_j}$ 和 $s_{c_j + 1}$。\n\n如果无需执行任何操作，请在第一行输出单个整数 $0$，第二行可留空或不输出。 \n\n在第一个示例中，字符串 $s$ 的变化过程如下：\"_abcdef_\" $arrow.r$ \"_abdcef_\" $arrow.r$ \"_abdcfe_\" $arrow.r$ \"_abdfce_\" $arrow.r$ \"_abdfec_\"。\n\n在第二个示例中，无法通过任何允许的操作将字符串 $s$ 转换为字符串 $t$。\n\n## Input\n\n输入的第一行包含一个整数 $n$ ($1 lt.eq n lt.eq 50$) —— 字符串 $s$ 和 $t$ 的长度。第二行包含字符串 $s$，由 $n$ 个小写拉丁字母组成。第三行包含字符串 $t$，由 $n$ 个小写拉丁字母组成。\n\n## Output\n\n如果无法通过操作得到字符串 $t$，请输出 \"_-1_\"。否则，在第一行输出一个整数 $k$ —— 将 $s$ 转换为 $t$ 所需的操作次数。注意 $k$ 必须是介于 $0$ 和 $10^4$ 之间（含端点）的整数。在第二行输出 $k$ 个整数 $c_j$ ($1 lt.eq c_j < n$)，其中 $c_j$ 表示第 $j$ 次操作中交换字符 $s_{c_j}$ 和 $s_{c_j + 1}$。如果无需执行任何操作，请在第一行输出单个整数 $0$，第二行可留空或不输出。\n\n[samples]\n\n## Note\n\n在第一个示例中，字符串 $s$ 的变化过程如下：\"_abcdef_\" $arrow.r$ \"_abdcef_\" $arrow.r$ \"_abdcfe_\" $arrow.r$ \"_abdfce_\" $arrow.r$ \"_abdfec_\"。在第二个示例中，无法通过任何允许的操作将字符串 $s$ 转换为字符串 $t$。","is_translate":true,"language":"Chinese"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be the length of strings $ s $ and $ t $.  \nLet $ s = (s_1, s_2, \\dots, s_n) $, $ t = (t_1, t_2, \\dots, t_n) $ be strings over the alphabet of lowercase Latin letters.  \n\n**Constraints**  \n1. $ 1 \\le n \\le 50 $  \n2. Each character $ s_i, t_i \\in \\{ \\text{a}, \\text{b}, \\dots, \\text{z} \\} $  \n\n**Allowed Operation**  \nA move consists of selecting an index $ c \\in \\{1, 2, \\dots, n-1\\} $ and swapping $ s_c $ and $ s_{c+1} $.  \n\n**Objective**  \nFind a sequence of moves $ (c_1, c_2, \\dots, c_k) $ with $ 0 \\le k \\le 10^4 $ such that applying these swaps in order to $ s $ yields $ t $.  \n\nIf no such sequence exists, output $-1$.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF1015B","tags":["implementation"],"sample_group":[["6\nabcdef\nabdfec","4\n3 5 4 5"],["4\nabcd\naccd","\\-1"]],"created_at":"2026-03-03 11:00:39"}}