A string s of length n
can be encrypted by the following algorithm:
- iterate over all divisors of n
in decreasing order (i.e. from n to 1
- ),
- for each divisor d
- , reverse the substring s[1…d] (i.e. the substring which starts at position 1 and ends at position d
- ).
For example, the above algorithm applied to the string s
="codeforces" leads to the following changes: "codeforces" → "secrofedoc" → "orcesfedoc" → "rocesfedoc" → "rocesfedoc" (obviously, the last reverse operation doesn't change the string because d=1).
You are given the encrypted string t
. Your task is to decrypt this string, i.e., to find a string s such that the above algorithm results in string t. It can be proven that this string salways exists and is unique.
Input
The first line of input consists of a single integer n
(1≤n≤100) — the length of the string t. The second line of input consists of the string t. The length of t is n
, and it consists only of lowercase Latin letters.
Output
Print a string s
such that the above algorithm results in t
Examples
Input
10 rocesfedoc
Output
codeforces
Input
16 plmaetwoxesisiht
Output
thisisexampletwo
Input
1 z
Output
z
Note
The first example is described in the problem statement.
是真水
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cstring>
#define MAX 1000000
#include <deque>
using namespace std;
deque <int> dq;
int main()
{
int d,i,a[100]={0};
char s[120],t;
memset(s,0,sizeof(s));
scanf("%d",&d);
getchar();
gets(s);
if(d==1)
{
puts(s);
return 0;
}
int e=0;
for(i=2;i<d;i++)
{
if(d%i==0)
{
a[e++]=d/i;
}
}
sort(a,a+e);
a[e]=d;
int m=e+1;
e=0;
while(m--)
{
if(a[e]==0)
break;
for(i=0;i<a[e]/2;i++)
{
t=s[i];
s[i]=s[a[e]-i-1];
s[a[e]-i-1]=t;
}
e++;
}
puts(s);
return 0;
}
You are given a string s consisting of n lowercase Latin letters. Polycarp wants to remove exactly k characters (k≤n) from the string s. Polycarp uses the following algorithm k
times:
- if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item;
- if there is at least one letter 'b', remove the leftmost occurrence and stop the algorithm, otherwise go to next item;
- ...
- remove the leftmost occurrence of the letter 'z' and stop the algorithm.
This algorithm removes a single letter from the string. Polycarp performs this algorithm exactly k
times, thus removing exactly k
characters.
Help Polycarp find the resulting string.
Input
The first line of input contains two integers n
and k (1≤k≤n≤4⋅105
) — the length of the string and the number of letters Polycarp will remove.
The second line contains the string s
consisting of n
lowercase Latin letters.
Output
Print the string that will be obtained from s
after Polycarp removes exactly k letters using the above algorithm k
times.
If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break).
Examples
Input
15 3
cccaabababaccbc
Output
cccbbabaccbc
Input
15 9
cccaabababaccbc
Output
cccccc
Input
1 1
u
Output
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cstring>
#define MAX 1000000
#include <deque>
using namespace std;
char s[1000000];
int main()
{
long long int n,k,i,j;
scanf("%lld%lld",&n,&k);
getchar();
gets(s);
for(i='a';i<='z';i++)
{
for(j=0;j<n;j++)
{
if(s[j]==i)
{
s[j]=1;
k--;
}
if(k==0)
break;
}
if(k==0)
break;
}
for(i=0;i<n;i++)
if(s[i]!=1)
printf("%c",s[i]);
return 0;
}