QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 64 MB Total points: 10

#11846. Almost Conjugates [B]

Statistics

Strictly thinking, the word almost is equivalent to the word no. On the other hand, these words are not exactly synonyms. More precisely, the word almost is closer in meaning to the word yes than to the word no.

We say that two words are conjugates if we can modify the first word to obtain the second one, by repeatedly moving one letter from the beginning of the first word to its end. For instance, words ababa and abaab are conjugates, but words ababa and baaab are not. We say that two words are almost conjugates if:

  • they are not conjugates and
  • by repeatedly moving one letter from the beginning of the first word to its end we obtain a word that differs from the second word at exactly one position.

For instance, words ababa and aaaab are almost conjugates, but words ababa and bbbbb are not.

Write a program which:

  • reads two words from the standard input,
  • checks whether they are almost conjugates, and if so then proves it,
  • writes the result to the standard output.

Input Format

The first line of input contains one integer $ n $ ($1 ≤ n ≤ 1\,000\,000$), representing the length of each of the words. The second line contains the first word and the third line contains the second word. Each word is a sequence of $ n $ small letters of English alphabet.

Output Format

The first line of output should contain one word - TAK (i.e. yes in Polish) if the words from the input are almost conjugates or NIE (i.e. no in Polish) otherwise. If the first line contains the word TAK, then the second line should contain an increasing sequence of non-negative integers, each from the range $[0, n - 1]$, separated with single spaces. The sequence should contain all possible numbers of operations of moving one letter from the beginning of the first word to its end, after which the resulting word differs from the second word at exactly one position.

Example

Input

5
ababa
aaaab

Output

TAK
2 4

Input 2

5
ababa
bbbbb

Output 2

NIE

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.