-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCF219A.java
50 lines (41 loc) · 1.25 KB
/
CF219A.java
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
import java.util.*;
public class CF219A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String str = sc.next();
HashMap<Character, Integer> map = new HashMap<>();
for(int i = 0; i < str.length(); i++) {
if(map.containsKey(str.charAt(i))) {
map.put(str.charAt(i), map.get(str.charAt(i)) + 1);
} else {
map.put(str.charAt(i), 1);
}
}
StringBuilder sb = new StringBuilder();
boolean flag = true;
for(Character c : map.keySet()) {
if(map.get(c) % n != 0) {
flag = false;
break;
} else {
int k = map.get(c)/n;
for(int i = 0; i < k; i++) {
sb.append(c);
}
}
}
if(flag) {
if(sb.length() == 1) {
System.out.println(str);
} else {
for(int i = 0; i < n; i++) {
System.out.print(new String(sb));
}
}
} else {
System.out.print(-1);
}
sc.close();
}
}