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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

bool same(int size, int a[], int b[]) {
    for (int i = 0; i < size; ++i) {
        if (a[i] != b[i])
            return false;
    }
    return true;
}

void zab() {
    constexpr int CHAR_CNT = 'z' - ('a' - 1);
    int n, oddA[CHAR_CNT] {}, evenA[CHAR_CNT] {},
        oddB[CHAR_CNT] {}, evenB[CHAR_CNT] {};
    string a, b;
    cin >> n;
    cin >> a >> b;

    for (int i = 0; i < n; i += 2) {
        ++evenA[a[i] - 'a'];
        ++evenB[b[i] - 'a'];
    }
    for (int i = 1; i < n; i += 2) {
        ++oddA[a[i] - 'a'];
        ++oddB[b[i] - 'a'];
    }

    cout << (same(CHAR_CNT, evenA, evenB) && same(CHAR_CNT, oddA, oddB) ? "TAK" : "NIE") << endl;
}

void niedziala() {
    int n;
    string a, b;
    cin >> n;
    cin >> a >> b;

    // calculate positions of characters
    vector<queue<int>> odd('z' - ('a' - 1));
    for (int i = 1; i < b.length(); i += 2) {
        //cout << "pushing " << b[i] << " position " << i << endl;
        odd[b[i] - 'a'].push(i);
    }


    for (int i = 1; i < b.length(); i += 2) {
        if (a[i] == b[i])
            continue;
        //cout << "A character is: " << a[i] << " and B character is: " << b[i] << endl;

        if (odd[a[i] - 'a'].empty()) {
            cout << "NIE" << endl;
            return;
        }

        //cout << "A character position in B is: " << odd[a[i] - 'a'].front() << endl;
        swap(b[i], b[odd[a[i] - 'a'].front()]);
        odd[a[i] - 'a'].pop();
    }

    vector<queue<int>> even('z' - ('a' - 1));
    for (int i = 0; i < b.length(); i += 2) {
        even[b[i] - 'a'].push(i);
    }

    for (int i = 0; i < b.length(); i += 2) {
        if (a[i] == b[i])
            continue;
        //cout << "A character is: " << a[i] << " and B character is: " << b[i] << endl;

        if (even[a[i] - 'a'].empty()) {
            cout << "NIE" << endl;
            return;
        }

        //cout << "A character position in B is: " << odd[a[i] - 'a'].front() << endl;
        swap(b[i], b[even[a[i] - 'a'].front()]);
        even[a[i] - 'a'].pop();
    }

    cout << "TAK" << endl;
}

int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    zab();
    return 0;
}