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
48
49
50
51
52
53
54
55
56
57
#include <bits/stdc++.h>

using namespace std;

struct TestCase
{
  int letter_count;
  string initial_sequence;
  string desired_sequence;
};

TestCase read_test_case();
void solve_test_case(const TestCase&);

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

TestCase read_test_case()
{
  TestCase test_case;
  cin >> test_case.letter_count >> test_case.initial_sequence >>
      test_case.desired_sequence;
  return test_case;
}

string filter_parity(string s, int parity)
{
  parity = parity % 2;
  string result = "";
  for (size_t i = parity; i < s.size(); i += 2) result += s[i];
  return result;
}

bool are_permutations(string s1, string s2)
{
  std::sort(s1.begin(), s1.end());
  std::sort(s2.begin(), s2.end());
  return s1 == s2;
}

void solve_test_case(const TestCase& test_case)
{
  auto initial_even = filter_parity(test_case.initial_sequence, 0);
  auto initial_odd = filter_parity(test_case.initial_sequence, 1);

  auto desired_even = filter_parity(test_case.desired_sequence, 0);
  auto desired_odd = filter_parity(test_case.desired_sequence, 1);

  bool ok = are_permutations(initial_even, desired_even) &&
            are_permutations(initial_odd, desired_odd);

  cout << (ok ? "TAK" : "NIE") << "\n";
}