-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC219A.java
More file actions
57 lines (48 loc) · 1.39 KB
/
Copy pathC219A.java
File metadata and controls
57 lines (48 loc) · 1.39 KB
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
import java.io.*;
import java.util.*;
/**
* */
public class C219A {
/**
* @param args
*/
public static void main(String[] args){
try {
BufferedReader reader =new BufferedReader(new InputStreamReader(System.in)); // STDIN
Map<String,Integer> map=Collections.synchronizedMap(new HashMap<String,Integer>());
Integer k=Integer.valueOf(reader.readLine().trim());
String s=reader.readLine();
for( int i=0;i!=s.length();i++){
String ch=s.substring(i,i+1);
if(!map.containsKey(ch))
map.put(ch, 1);
else map.put(ch, map.get(ch)+1);
}
boolean bResult=((s.length()%k)==0);
Iterator<String> iter=map.keySet().iterator();
while(iter.hasNext()&&bResult){
String ch=iter.next();
Integer iCh=map.get(ch);
if((iCh%k)!=0)
bResult=false;
}
if(bResult){
String chUnit="";
Iterator<String> iterCh=map.keySet().iterator();
while(iterCh.hasNext()){
String ch=iterCh.next();
Integer iCh=map.get(ch)/k;
for(int i=0;i!=iCh;i++)
chUnit+=ch;
}
String strResult="";
for(int i=0;i!=k;i++)
strResult+=chUnit;
System.out.println(strResult);
}else{System.out.println("-1");}
reader.close();
}catch(Exception e){
e.printStackTrace(System.err);
}
}
}