1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// zab | Solution by Mikołaj Zabłocki (Dominik Korsa)
// https://sio2.mimuw.edu.pl/c/pa-2020-1/p/zab/

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;

  string target, current;
  cin >> target >> current;

  vector<vector<int>> targetLetterIndexes(26, vector<int>(0));

  for (int i = 0 ; i < n; i++) {
    targetLetterIndexes[target[i] - 'a'].push_back(i);
  }

  for (int i = 0 ; i < n; i++) {
    bool found = 0;
    int size = targetLetterIndexes[current[i] - 'a'].size();
    for (int j = 0; j < size; j++) {
      int targetIndex = targetLetterIndexes[current[i] - 'a'][j];
      if ((targetIndex - i) % 2 == 0) {
        found = true;
        targetLetterIndexes[current[i] - 'a'].erase(targetLetterIndexes[current[i] - 'a'].begin() + j);
        break;
      }
    }

    if (!found) {
      cout << "NIE";
      return 0;
    }
  }

  cout << "TAK";

  return 0;
}