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
// Problem: Zakłócenia [C]
// https://sio2.mimuw.edu.pl/c/pa-2021-1/p/zak/

#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <cctype>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <list>
using namespace std;
#define REP(i,n) for(int _n=(n), i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define FOREACH(e, v) for(auto const &e: v)
#define IN(e, s) (s).find((e)) != (s).end()
#define TRACE(x) cerr << "TRACE(" #x ")" << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << endl;
#define PB push_back
#define ST first
#define ND second
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())
typedef long long LL; typedef unsigned long long ULL; typedef unsigned short UST; typedef unsigned int UINT;
typedef vector<int> VI;
inline  void fix_io() { cin.tie(nullptr); ios::sync_with_stdio(false); }


const char c3 = 'a';
const char c4 = 'c';
const char c5 = 'm';
const char c6 = 'w';

int coins[] = {3,4,5,6};
char coins_e[] = {'a','c','m','w'};

int ctoi(char c) {
    return c - '0';
}

int main() {
    fix_io();
    UINT n;
    UINT zeros=0;
    UINT ones=0;
    string s;
    cin >> n;
    cin >> s;
    FOR(i,0,s.length()-1) {
        char c = s[i];
        if (c == '0') zeros++;
        else if (c == '1') ones++;
    }
    UINT min = n*3;
    UINT max = n*6;
    if (ones > max || ones < min) {
        cout << "NIE\n";
        return 0;
    }

    UINT d = ones/n;
    UINT e = ones%n;

    if (e == 0) {
        if (d == 3) {
            FOR(i,1,n) cout << c3;
        } else if (d == 4) {
            FOR(i,1,n) cout << c4;
        } else if (d == 5) {
            FOR(i,1,n) cout << c5;
        } else if (d == 6) {
            FOR(i,1,n) cout << c6;
        }
    } else {
        // Integer Partition?
        for(int i=0; i<=s.length()-8; i+=8) {
            int bits = ctoi(s[i]) + ctoi(s[i+1]) + ctoi(s[i+2]) + ctoi(s[i+3]) + ctoi(s[i+4]) + ctoi(s[i+5]) + ctoi(s[i+6]) + ctoi(s[i+7]);
            if (bits == 3) cout << c3;
            else if (bits == 4) cout << c4;
            else if (bits == 5) cout << c5;
            else if (bits == 6) cout << c6;
            else cout << "a";
        }
    }

    cout << '\n';
}