/*
URL_HERE
*/
/*

*/
#ifdef _WIN32
#pragma warning(disable:4996)
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <math.h>

using namespace std;

FILE* _fin = stdin;
FILE* _fout = stdout;
#define PI 3.141592653589793238462643383279502884197169399375105820974
#define ten5p1 100001
#define ten6p1 1000001
#define ten8p1 100000001
#define ten9p1 1000000001
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define rep(var,n) for(int var=0;var<n;++var)
#define repi(n) rep(i,n)
#define repj(n) rep(j,n)
#define repi1(n) for(int i=1;i<n;++i)
#define repj1(n) for(int j=1;j<n;++j)
int _min(int a, int b) { return a <= b ? a : b; }
int _min(ll a, ll b) { return a <= b ? a : b; }
int _max(int a, int b) { return a >= b ? a : b; }
int _max(ll a, ll b) { return a >= b ? a : b; }
void zero(int* data, int n) { memset(data, 0, sizeof(int) * n); }
void zero(ll* data, int n) { memset(data, 0, sizeof(ll) * n); }
void zero(char* data, int n) { memset(data, 0, sizeof(char) * n); }
char readc() { char var; fscanf(_fin, "%c", &var); return var; }
int readi() { int var; fscanf(_fin, "%d", &var); return var; }
double readlf() { double var; fscanf(_fin, "%lf", &var); return var; }
ll readll() { ll var; fscanf(_fin, "%lld", &var); return var; }
void repread(int* data, int n) { repi(n) data[i] = readi(); }
void repread(ll* data, int n) { repi(n) data[i] = readll(); }
int reads(char* str, int maxsize)
{
	for (;;) { if (fgets(str, maxsize, _fin) == NULL) break; if (str[0] != '\n' && str[0] != '\r') break; }
	int slen = strlen(str); if (slen == 0) return 0;
	if (str[slen - 1] == '\n' || str[slen - 1] == '\r') str[--slen] = 0;
	return slen;
}

#define writec(var) fprintf(_fout,"%c",var)
#define writecsp(var) fprintf(_fout,"%c ",var)
#define writecln(var) fprintf(_fout,"%c\n",var)
#define writei(var) fprintf(_fout,"%d",var)
#define writeisp(var) fprintf(_fout,"%d ",var)
#define writellsp(var) fprintf(_fout,"%lld ",var)
#define writeiln(var) fprintf(_fout,"%d\n",var)
#define writellln(var) fprintf(_fout,"%lld\n",var)
#define writeulln(var) fprintf(_fout,"%llu\n",var)
#define writefln(var) fprintf(_fout,"%f\n",var)
#define writes(str) fprintf(_fout,"%s",str)
#define writesp() fprintf(_fout," ")
#define writeln() fprintf(_fout,"\n")
#define RUN_LOCAL(testfilename) {_fin = fopen(testfilename, "r"); if(_fin==NULL) _fin=stdin;}
#define swap(type,a, b) {type t=a;a=b;b=t;}
#define sort(data,n) std::sort(data,data+n)
//#define mod(a,b) b==0 ? 0 : a==0 ? 0 :(a>0 ? a%b : b + a % b) //what the hell is this...
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return (a / g) * b; }
void reverse(char* data, int n) { int k = n >> 1; repi(k) { char tmp = data[i]; data[i] = data[n - i - 1]; data[n - i - 1] = tmp; } }
void reverse(int* data, int n) { int k = n >> 1; repi(k) { int tmp = data[i]; data[i] = data[n - i - 1]; data[n - i - 1] = tmp; } }

#define _Vec(type, name) \
struct name { type* data; int size; int n; };\
void init(name* t, int size) { t->data = (type*)malloc(sizeof(type) * size); t->size = size; t->n = 0; }\
void resize(name* t) { int ns = t->size * 1.2f; t->data = (type*)realloc(t->data, sizeof(type) * ns); t->size = ns; }\
void add(name* t, type val) { if (t->n >= t->size) resize(t); int k = t->n; t->data[k] = val; t->n = k + 1; }\
void free(name* t) { free(t->data);}
_Vec(int, Veci)
_Vec(long long, Vecll)
_Vec(char*, Vecs)

#define _ispal(type, name) int name(type* a, type* b, int n){repi(n){if (a[i] != b[n - i - 1]){return 0;}}return 1;}
_ispal(int, ispali)
_ispal(char, ispalc)

#define _Pair(type, name) struct name{type x, y;}; \
int cmp_##name(const void* _a, const void* _b)\
{\
	name* a = (name*)_a;name* b = (name*)_b;\
	if (a->x < b->x) return -1;\
	else\
	{\
		if (a->x == b->x)\
		{\
			if (a->y == b->y) return 0;\
			if (a->y < b->y) return -1;\
			else return 1;\
		}\
		else\
		{\
			return 1;\
		}\
	}\
}\
void sort_##name(name* d, int n){qsort(d, n, sizeof(name), cmp_##name);}
	_Pair(int, Pairi)

	int cmp_Str(const void* _a, const void* _b) { char* a = *((char**)_a); char* b = *((char**)_b); return strcmp(a, b); }
void sort_Str(char** str, int n) { qsort(str, n, sizeof(char*), cmp_Str); }

ll expmod(ll x, ll n, ll m) {
	ll ans = 1;
	for (; n;) {
		if (n & 1) ans = (ans * x) % m;
		x = (x * x) % m;
		n >>= 1;
	}
	return ans;
}

ll combmod(ll n, ll k, ll m) {
	ll ret = 1;
	ll div = 1;
	for (ll i = 0; i < k; ++i) {
		ret = (ret * (n - i) % m) % m;
		div = (div * (i + 1)) % m;
	}
	div = expmod(div, m - 2, m) % m;
	return (ret * div) % m;
}

int next_perm(int* data, int n)
{
	//find first i,i+1 where d[i]<d[i+1]
	int rootidx = -1;
	for (int i = n - 2; i >= 0; --i)
	{
		if (data[i] < data[i + 1])
		{
			rootidx = i;
			break;
		}
	}

	if (rootidx == -1) return 0;

	int ceilingidx = rootidx + 1;
	//find smallest d[x] after d[rooti] where d[x]>d[rooti]
	for (int i = rootidx + 2; i < n; ++i)
	{
		if (data[i] > data[rootidx] && data[i] < data[ceilingidx])
		{
			ceilingidx = i;
		}
	}

	swap(int, data[rootidx], data[ceilingidx]);
	sort(&data[rootidx + 1], n - rootidx - 1);
	return 1;
}
int count_digits(ll a)
{
	int k = 0;
	for (;;)
	{
		if (a == 0)break;
		k++;
		a /= 10;
	}
	return k;
}

/*
use only when val EXISTS in data
*/
int bs_exists(int* data, int n, int val)
{
	int left = 0;
	int right = n - 1;
	for (; left < right;)
	{
		int mid = (left + right + 1) >> 1;
		if (data[mid] <= val) left = mid;
		else right = mid - 1;
	}
	return right;
}
//------------------------------------------

//------------

int main()
{
	RUN_LOCAL("xx11.txt");
	static char s[1001];
	int k = readi();
	int len = reads(s, 1001);
	static int count[26] = { 0 };
	repi(len)count[s[i]-'a']++;
	if (len % k != 0)
	{
		writeiln(-1);
		return 0;
	}

	int nrepeats = len / k;
	repi(26)
	{
		if (count[i] == 0)continue;
		if (count[i] % nrepeats)
		{
			writeiln(-1);
			return 0;
		}
	}
	for (int r = 0; r < nrepeats; ++r)
	{
		repi(26)
		{
			if (count[i] == 0)continue;
			int m = count[i] / nrepeats;
			repj(m)
			{
				printf("%c", i + 'a');
			}
		}
	}
	printf("\n");

	return 0;
}


/*
URL_HERE
*/
/*

*/
#ifdef _WIN32
#pragma warning(disable:4996)
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <math.h>

using namespace std;

FILE* _fin = stdin;
FILE* _fout = stdout;
#define PI 3.141592653589793238462643383279502884197169399375105820974
#define ten5p1 100001
#define ten6p1 1000001
#define ten8p1 100000001
#define ten9p1 1000000001
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define rep(var,n) for(int var=0;var<n;++var)
#define repi(n) rep(i,n)
#define repj(n) rep(j,n)
#define repi1(n) for(int i=1;i<n;++i)
#define repj1(n) for(int j=1;j<n;++j)
int _min(int a, int b) { return a <= b ? a : b; }
int _min(ll a, ll b) { return a <= b ? a : b; }
int _max(int a, int b) { return a >= b ? a : b; }
int _max(ll a, ll b) { return a >= b ? a : b; }
void zero(int* data, int n) { memset(data, 0, sizeof(int) * n); }
void zero(ll* data, int n) { memset(data, 0, sizeof(ll) * n); }
void zero(char* data, int n) { memset(data, 0, sizeof(char) * n); }
char readc() { char var; fscanf(_fin, "%c", &var); return var; }
int readi() { int var; fscanf(_fin, "%d", &var); return var; }
double readlf() { double var; fscanf(_fin, "%lf", &var); return var; }
ll readll() { ll var; fscanf(_fin, "%lld", &var); return var; }
void repread(int* data, int n) { repi(n) data[i] = readi(); }
void repread(ll* data, int n) { repi(n) data[i] = readll(); }
int reads(char* str, int maxsize)
{
	for (;;) { if (fgets(str, maxsize, _fin) == NULL) break; if (str[0] != '\n' && str[0] != '\r') break; }
	int slen = strlen(str); if (slen == 0) return 0;
	if (str[slen - 1] == '\n' || str[slen - 1] == '\r') str[--slen] = 0;
	return slen;
}

#define writec(var) fprintf(_fout,"%c",var)
#define writecsp(var) fprintf(_fout,"%c ",var)
#define writecln(var) fprintf(_fout,"%c\n",var)
#define writei(var) fprintf(_fout,"%d",var)
#define writeisp(var) fprintf(_fout,"%d ",var)
#define writellsp(var) fprintf(_fout,"%lld ",var)
#define writeiln(var) fprintf(_fout,"%d\n",var)
#define writellln(var) fprintf(_fout,"%lld\n",var)
#define writeulln(var) fprintf(_fout,"%llu\n",var)
#define writefln(var) fprintf(_fout,"%f\n",var)
#define writes(str) fprintf(_fout,"%s",str)
#define writesp() fprintf(_fout," ")
#define writeln() fprintf(_fout,"\n")
#define RUN_LOCAL(testfilename) {_fin = fopen(testfilename, "r"); if(_fin==NULL) _fin=stdin;}
#define swap(type,a, b) {type t=a;a=b;b=t;}
#define sort(data,n) std::sort(data,data+n)
//#define mod(a,b) b==0 ? 0 : a==0 ? 0 :(a>0 ? a%b : b + a % b) //what the hell is this...
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return (a / g) * b; }
void reverse(char* data, int n) { int k = n >> 1; repi(k) { char tmp = data[i]; data[i] = data[n - i - 1]; data[n - i - 1] = tmp; } }
void reverse(int* data, int n) { int k = n >> 1; repi(k) { int tmp = data[i]; data[i] = data[n - i - 1]; data[n - i - 1] = tmp; } }

#define _Vec(type, name) \
struct name { type* data; int size; int n; };\
void init(name* t, int size) { t->data = (type*)malloc(sizeof(type) * size); t->size = size; t->n = 0; }\
void resize(name* t) { int ns = t->size * 1.2f; t->data = (type*)realloc(t->data, sizeof(type) * ns); t->size = ns; }\
void add(name* t, type val) { if (t->n >= t->size) resize(t); int k = t->n; t->data[k] = val; t->n = k + 1; }\
void free(name* t) { free(t->data);}
_Vec(int, Veci)
_Vec(long long, Vecll)
_Vec(char*, Vecs)

#define _ispal(type, name) int name(type* a, type* b, int n){repi(n){if (a[i] != b[n - i - 1]){return 0;}}return 1;}
_ispal(int, ispali)
_ispal(char, ispalc)

#define _Pair(type, name) struct name{type x, y;}; \
int cmp_##name(const void* _a, const void* _b)\
{\
	name* a = (name*)_a;name* b = (name*)_b;\
	if (a->x < b->x) return -1;\
	else\
	{\
		if (a->x == b->x)\
		{\
			if (a->y == b->y) return 0;\
			if (a->y < b->y) return -1;\
			else return 1;\
		}\
		else\
		{\
			return 1;\
		}\
	}\
}\
void sort_##name(name* d, int n){qsort(d, n, sizeof(name), cmp_##name);}
	_Pair(int, Pairi)

	int cmp_Str(const void* _a, const void* _b) { char* a = *((char**)_a); char* b = *((char**)_b); return strcmp(a, b); }
void sort_Str(char** str, int n) { qsort(str, n, sizeof(char*), cmp_Str); }

ll expmod(ll x, ll n, ll m) {
	ll ans = 1;
	for (; n;) {
		if (n & 1) ans = (ans * x) % m;
		x = (x * x) % m;
		n >>= 1;
	}
	return ans;
}

ll combmod(ll n, ll k, ll m) {
	ll ret = 1;
	ll div = 1;
	for (ll i = 0; i < k; ++i) {
		ret = (ret * (n - i) % m) % m;
		div = (div * (i + 1)) % m;
	}
	div = expmod(div, m - 2, m) % m;
	return (ret * div) % m;
}

int next_perm(int* data, int n)
{
	//find first i,i+1 where d[i]<d[i+1]
	int rootidx = -1;
	for (int i = n - 2; i >= 0; --i)
	{
		if (data[i] < data[i + 1])
		{
			rootidx = i;
			break;
		}
	}

	if (rootidx == -1) return 0;

	int ceilingidx = rootidx + 1;
	//find smallest d[x] after d[rooti] where d[x]>d[rooti]
	for (int i = rootidx + 2; i < n; ++i)
	{
		if (data[i] > data[rootidx] && data[i] < data[ceilingidx])
		{
			ceilingidx = i;
		}
	}

	swap(int, data[rootidx], data[ceilingidx]);
	sort(&data[rootidx + 1], n - rootidx - 1);
	return 1;
}
int count_digits(ll a)
{
	int k = 0;
	for (;;)
	{
		if (a == 0)break;
		k++;
		a /= 10;
	}
	return k;
}

/*
use only when val EXISTS in data
*/
int bs_exists(int* data, int n, int val)
{
	int left = 0;
	int right = n - 1;
	for (; left < right;)
	{
		int mid = (left + right + 1) >> 1;
		if (data[mid] <= val) left = mid;
		else right = mid - 1;
	}
	return right;
}
//------------------------------------------

//------------

int main()
{
	RUN_LOCAL("xx11.txt");
	static char s[1001];
	int k = readi();
	int len = reads(s, 1001);
	if (len == k && len!=1)
	{
		writeiln(-1);
		return 0;
	}
	static int count[26] = { 0 };
	repi(len)count[s[i]-'a']++;
	if (len % k != 0)
	{
		writeiln(-1);
		return 0;
	}

	int nrepeats = len / k;

	repi(26)
	{
		if (count[i] == 0)continue;
		if (count[i] % nrepeats != 0)
		{
			writeiln(-1);
			return 0;
		}
	}
	for (int r = 0; r < nrepeats; ++r)
	{
		repi(26)
		{
			if (count[i] == 0)continue;
			int m = count[i] / nrepeats;
			repj(m)
			{
				printf("%c", i + 'a');
			}
		}
	}
	printf("\n");

	return 0;
}


/*
URL_HERE
*/
/*

*/
#ifdef _WIN32
#pragma warning(disable:4996)
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <math.h>

using namespace std;

FILE* _fin = stdin;
FILE* _fout = stdout;
#define PI 3.141592653589793238462643383279502884197169399375105820974
#define ten5p1 100001
#define ten6p1 1000001
#define ten8p1 100000001
#define ten9p1 1000000001
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define rep(var,n) for(int var=0;var<n;++var)
#define repi(n) rep(i,n)
#define repj(n) rep(j,n)
#define repi1(n) for(int i=1;i<n;++i)
#define repj1(n) for(int j=1;j<n;++j)
int _min(int a, int b) { return a <= b ? a : b; }
int _min(ll a, ll b) { return a <= b ? a : b; }
int _max(int a, int b) { return a >= b ? a : b; }
int _max(ll a, ll b) { return a >= b ? a : b; }
void zero(int* data, int n) { memset(data, 0, sizeof(int) * n); }
void zero(ll* data, int n) { memset(data, 0, sizeof(ll) * n); }
void zero(char* data, int n) { memset(data, 0, sizeof(char) * n); }
char readc() { char var; fscanf(_fin, "%c", &var); return var; }
int readi() { int var; fscanf(_fin, "%d", &var); return var; }
double readlf() { double var; fscanf(_fin, "%lf", &var); return var; }
ll readll() { ll var; fscanf(_fin, "%lld", &var); return var; }
void repread(int* data, int n) { repi(n) data[i] = readi(); }
void repread(ll* data, int n) { repi(n) data[i] = readll(); }
int reads(char* str, int maxsize)
{
	for (;;) { if (fgets(str, maxsize, _fin) == NULL) break; if (str[0] != '\n' && str[0] != '\r') break; }
	int slen = strlen(str); if (slen == 0) return 0;
	if (str[slen - 1] == '\n' || str[slen - 1] == '\r') str[--slen] = 0;
	return slen;
}

#define writec(var) fprintf(_fout,"%c",var)
#define writecsp(var) fprintf(_fout,"%c ",var)
#define writecln(var) fprintf(_fout,"%c\n",var)
#define writei(var) fprintf(_fout,"%d",var)
#define writeisp(var) fprintf(_fout,"%d ",var)
#define writellsp(var) fprintf(_fout,"%lld ",var)
#define writeiln(var) fprintf(_fout,"%d\n",var)
#define writellln(var) fprintf(_fout,"%lld\n",var)
#define writeulln(var) fprintf(_fout,"%llu\n",var)
#define writefln(var) fprintf(_fout,"%f\n",var)
#define writes(str) fprintf(_fout,"%s",str)
#define writesp() fprintf(_fout," ")
#define writeln() fprintf(_fout,"\n")
#define RUN_LOCAL(testfilename) {_fin = fopen(testfilename, "r"); if(_fin==NULL) _fin=stdin;}
#define swap(type,a, b) {type t=a;a=b;b=t;}
#define sort(data,n) std::sort(data,data+n)
//#define mod(a,b) b==0 ? 0 : a==0 ? 0 :(a>0 ? a%b : b + a % b) //what the hell is this...
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return (a / g) * b; }
void reverse(char* data, int n) { int k = n >> 1; repi(k) { char tmp = data[i]; data[i] = data[n - i - 1]; data[n - i - 1] = tmp; } }
void reverse(int* data, int n) { int k = n >> 1; repi(k) { int tmp = data[i]; data[i] = data[n - i - 1]; data[n - i - 1] = tmp; } }

#define _Vec(type, name) \
struct name { type* data; int size; int n; };\
void init(name* t, int size) { t->data = (type*)malloc(sizeof(type) * size); t->size = size; t->n = 0; }\
void resize(name* t) { int ns = t->size * 1.2f; t->data = (type*)realloc(t->data, sizeof(type) * ns); t->size = ns; }\
void add(name* t, type val) { if (t->n >= t->size) resize(t); int k = t->n; t->data[k] = val; t->n = k + 1; }\
void free(name* t) { free(t->data);}
_Vec(int, Veci)
_Vec(long long, Vecll)
_Vec(char*, Vecs)

#define _ispal(type, name) int name(type* a, type* b, int n){repi(n){if (a[i] != b[n - i - 1]){return 0;}}return 1;}
_ispal(int, ispali)
_ispal(char, ispalc)

#define _Pair(type, name) struct name{type x, y;}; \
int cmp_##name(const void* _a, const void* _b)\
{\
	name* a = (name*)_a;name* b = (name*)_b;\
	if (a->x < b->x) return -1;\
	else\
	{\
		if (a->x == b->x)\
		{\
			if (a->y == b->y) return 0;\
			if (a->y < b->y) return -1;\
			else return 1;\
		}\
		else\
		{\
			return 1;\
		}\
	}\
}\
void sort_##name(name* d, int n){qsort(d, n, sizeof(name), cmp_##name);}
	_Pair(int, Pairi)

	int cmp_Str(const void* _a, const void* _b) { char* a = *((char**)_a); char* b = *((char**)_b); return strcmp(a, b); }
void sort_Str(char** str, int n) { qsort(str, n, sizeof(char*), cmp_Str); }

ll expmod(ll x, ll n, ll m) {
	ll ans = 1;
	for (; n;) {
		if (n & 1) ans = (ans * x) % m;
		x = (x * x) % m;
		n >>= 1;
	}
	return ans;
}

ll combmod(ll n, ll k, ll m) {
	ll ret = 1;
	ll div = 1;
	for (ll i = 0; i < k; ++i) {
		ret = (ret * (n - i) % m) % m;
		div = (div * (i + 1)) % m;
	}
	div = expmod(div, m - 2, m) % m;
	return (ret * div) % m;
}

int next_perm(int* data, int n)
{
	//find first i,i+1 where d[i]<d[i+1]
	int rootidx = -1;
	for (int i = n - 2; i >= 0; --i)
	{
		if (data[i] < data[i + 1])
		{
			rootidx = i;
			break;
		}
	}

	if (rootidx == -1) return 0;

	int ceilingidx = rootidx + 1;
	//find smallest d[x] after d[rooti] where d[x]>d[rooti]
	for (int i = rootidx + 2; i < n; ++i)
	{
		if (data[i] > data[rootidx] && data[i] < data[ceilingidx])
		{
			ceilingidx = i;
		}
	}

	swap(int, data[rootidx], data[ceilingidx]);
	sort(&data[rootidx + 1], n - rootidx - 1);
	return 1;
}
int count_digits(ll a)
{
	int k = 0;
	for (;;)
	{
		if (a == 0)break;
		k++;
		a /= 10;
	}
	return k;
}

/*
use only when val EXISTS in data
*/
int bs_exists(int* data, int n, int val)
{
	int left = 0;
	int right = n - 1;
	for (; left < right;)
	{
		int mid = (left + right + 1) >> 1;
		if (data[mid] <= val) left = mid;
		else right = mid - 1;
	}
	return right;
}
//------------------------------------------

//------------

int main()
{
	RUN_LOCAL("xx11.txt");
	static char s[1001];
	int ncopies = readi();
	int len = reads(s, 1001);

	static int count[26] = { 0 };
	repi(len)count[s[i]-'a']++;

	repi(26)
	{
		if (count[i] == 0)continue;
		if (count[i] % ncopies != 0)
		{
			writeiln(-1);
			return 0;
		}
	}
	for (int r = 0; r < ncopies; ++r)
	{
		repi(26)
		{
			if (count[i] == 0)continue;
			int m = count[i] / ncopies;
			repj(m)
			{
				printf("%c", i + 'a');
			}
		}
	}
	printf("\n");

	return 0;
}


/*
URL_HERE
*/
/*

*/
#ifdef _WIN32
#pragma warning(disable:4996)
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <math.h>

using namespace std;

FILE* _fin = stdin;
FILE* _fout = stdout;
#define PI 3.141592653589793238462643383279502884197169399375105820974
#define ten5p1 100001
#define ten6p1 1000001
#define ten8p1 100000001
#define ten9p1 1000000001
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define rep(var,n) for(int var=0;var<n;++var)
#define repi(n) rep(i,n)
#define repj(n) rep(j,n)
#define repi1(n) for(int i=1;i<n;++i)
#define repj1(n) for(int j=1;j<n;++j)
int _min(int a, int b) { return a <= b ? a : b; }
int _min(ll a, ll b) { return a <= b ? a : b; }
int _max(int a, int b) { return a >= b ? a : b; }
int _max(ll a, ll b) { return a >= b ? a : b; }
void zero(int* data, int n) { memset(data, 0, sizeof(int) * n); }
void zero(ll* data, int n) { memset(data, 0, sizeof(ll) * n); }
void zero(char* data, int n) { memset(data, 0, sizeof(char) * n); }
char readc() { char var; fscanf(_fin, "%c", &var); return var; }
int readi() { int var; fscanf(_fin, "%d", &var); return var; }
double readlf() { double var; fscanf(_fin, "%lf", &var); return var; }
ll readll() { ll var; fscanf(_fin, "%lld", &var); return var; }
void repread(int* data, int n) { repi(n) data[i] = readi(); }
void repread(ll* data, int n) { repi(n) data[i] = readll(); }
int reads(char* str, int maxsize)
{
	for (;;) { if (fgets(str, maxsize, _fin) == NULL) break; if (str[0] != '\n' && str[0] != '\r') break; }
	int slen = strlen(str); if (slen == 0) return 0;
	if (str[slen - 1] == '\n' || str[slen - 1] == '\r') str[--slen] = 0;
	return slen;
}

#define writec(var) fprintf(_fout,"%c",var)
#define writecsp(var) fprintf(_fout,"%c ",var)
#define writecln(var) fprintf(_fout,"%c\n",var)
#define writei(var) fprintf(_fout,"%d",var)
#define writeisp(var) fprintf(_fout,"%d ",var)
#define writellsp(var) fprintf(_fout,"%lld ",var)
#define writeiln(var) fprintf(_fout,"%d\n",var)
#define writellln(var) fprintf(_fout,"%lld\n",var)
#define writeulln(var) fprintf(_fout,"%llu\n",var)
#define writefln(var) fprintf(_fout,"%f\n",var)
#define writes(str) fprintf(_fout,"%s",str)
#define writesp() fprintf(_fout," ")
#define writeln() fprintf(_fout,"\n")
#define RUN_LOCAL(testfilename) {_fin = fopen(testfilename, "r"); if(_fin==NULL) _fin=stdin;}
#define swap(type,a, b) {type t=a;a=b;b=t;}
#define sort(data,n) std::sort(data,data+n)
//#define mod(a,b) b==0 ? 0 : a==0 ? 0 :(a>0 ? a%b : b + a % b) //what the hell is this...
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return (a / g) * b; }
void reverse(char* data, int n) { int k = n >> 1; repi(k) { char tmp = data[i]; data[i] = data[n - i - 1]; data[n - i - 1] = tmp; } }
void reverse(int* data, int n) { int k = n >> 1; repi(k) { int tmp = data[i]; data[i] = data[n - i - 1]; data[n - i - 1] = tmp; } }

#define _Vec(type, name) \
struct name { type* data; int size; int n; };\
void init(name* t, int size) { t->data = (type*)malloc(sizeof(type) * size); t->size = size; t->n = 0; }\
void resize(name* t) { int ns = t->size * 1.2f; t->data = (type*)realloc(t->data, sizeof(type) * ns); t->size = ns; }\
void add(name* t, type val) { if (t->n >= t->size) resize(t); int k = t->n; t->data[k] = val; t->n = k + 1; }\
void free(name* t) { free(t->data);}
_Vec(int, Veci)
_Vec(long long, Vecll)
_Vec(char*, Vecs)

#define _ispal(type, name) int name(type* a, type* b, int n){repi(n){if (a[i] != b[n - i - 1]){return 0;}}return 1;}
_ispal(int, ispali)
_ispal(char, ispalc)

#define _Pair(type, name) struct name{type x, y;}; \
int cmp_##name(const void* _a, const void* _b)\
{\
	name* a = (name*)_a;name* b = (name*)_b;\
	if (a->x < b->x) return -1;\
	else\
	{\
		if (a->x == b->x)\
		{\
			if (a->y == b->y) return 0;\
			if (a->y < b->y) return -1;\
			else return 1;\
		}\
		else\
		{\
			return 1;\
		}\
	}\
}\
void sort_##name(name* d, int n){qsort(d, n, sizeof(name), cmp_##name);}
	_Pair(int, Pairi)

	int cmp_Str(const void* _a, const void* _b) { char* a = *((char**)_a); char* b = *((char**)_b); return strcmp(a, b); }
void sort_Str(char** str, int n) { qsort(str, n, sizeof(char*), cmp_Str); }

ll expmod(ll x, ll n, ll m) {
	ll ans = 1;
	for (; n;) {
		if (n & 1) ans = (ans * x) % m;
		x = (x * x) % m;
		n >>= 1;
	}
	return ans;
}

ll combmod(ll n, ll k, ll m) {
	ll ret = 1;
	ll div = 1;
	for (ll i = 0; i < k; ++i) {
		ret = (ret * (n - i) % m) % m;
		div = (div * (i + 1)) % m;
	}
	div = expmod(div, m - 2, m) % m;
	return (ret * div) % m;
}

int next_perm(int* data, int n)
{
	//find first i,i+1 where d[i]<d[i+1]
	int rootidx = -1;
	for (int i = n - 2; i >= 0; --i)
	{
		if (data[i] < data[i + 1])
		{
			rootidx = i;
			break;
		}
	}

	if (rootidx == -1) return 0;

	int ceilingidx = rootidx + 1;
	//find smallest d[x] after d[rooti] where d[x]>d[rooti]
	for (int i = rootidx + 2; i < n; ++i)
	{
		if (data[i] > data[rootidx] && data[i] < data[ceilingidx])
		{
			ceilingidx = i;
		}
	}

	swap(int, data[rootidx], data[ceilingidx]);
	sort(&data[rootidx + 1], n - rootidx - 1);
	return 1;
}
int count_digits(ll a)
{
	int k = 0;
	for (;;)
	{
		if (a == 0)break;
		k++;
		a /= 10;
	}
	return k;
}

/*
use only when val EXISTS in data
*/
int bs_exists(int* data, int n, int val)
{
	int left = 0;
	int right = n - 1;
	for (; left < right;)
	{
		int mid = (left + right + 1) >> 1;
		if (data[mid] <= val) left = mid;
		else right = mid - 1;
	}
	return right;
}
//------------------------------------------

//------------

int main()
{
	RUN_LOCAL("xx11.txt");
	static char s[1001];
	int k = readi();
	int len = reads(s, 1001);
	if (len == k)
	{
		writeiln(-1);
		return 0;
	}
	static int count[26] = { 0 };
	repi(len)count[s[i]-'a']++;
	if (len % k != 0)
	{
		writeiln(-1);
		return 0;
	}

	int nrepeats = len / k;

	repi(26)
	{
		if (count[i] == 0)continue;
		if (count[i] % nrepeats != 0)
		{
			writeiln(-1);
			return 0;
		}
	}
	for (int r = 0; r < nrepeats; ++r)
	{
		repi(26)
		{
			if (count[i] == 0)continue;
			int m = count[i] / nrepeats;
			repj(m)
			{
				printf("%c", i + 'a');
			}
		}
	}
	printf("\n");

	return 0;
}


// test.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>

#include <algorithm>
using namespace std;

int main()
{
    //std::cout << "Hello World!\n";
    int num,tmp;
    bool unable = false;
    int startp=0, endp;
    char content[1001] = { 0 };
    char* contentp = content;
    char count[26] = { 0 };
    cin >> num;

    cin >> content;

    int i;
    for (i = 0; i < 1000; i++) {
        count[content[i] - 'a']++;
    }

    for (i = 0; i < 26 && unable==false; i++) {
        if (count[i] % num == 0) {
            for (tmp = 0; tmp < count[i] / num; tmp++) {
                snprintf(contentp,2,"%c", i + 'a');
                contentp++;
            }
        }
        else {
            unable = true;
        }
    }

    if (unable == true) {
        cout << -1;
    }
    else {
        for(tmp=0;tmp<num;tmp++)
            cout << content;
    }
    return 0;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started:
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file


#include <iostream>

#include <algorithm>
using namespace std;

int main()
{
    //std::cout << "Hello World!\n";
    int num,tmp;
    bool unable = false;
    int startp=0, endp;
    char content[1002] = { 0 };
    char* contentp = content;
    int count[26] = { 0 };
    cin >> num;

    cin >> content;

  /*  num = 1000;
    for (int t = 0; t < 1000; t++) {
        content[t] = 'a';
    }*/
    int i;
    for (i = 0; i < 1000; i++) {
        count[content[i] - 'a']++;
    }

    if (num == 0) {
        cout << -1;
    }
    else {
        for (i = 0; i < 26 && unable == false; i++) {
            if (count[i] % num == 0) {
                for (tmp = 0; tmp < count[i] / num; tmp++) {
                    snprintf(contentp, 2, "%c", i + 'a');
                    contentp++;
                }
            }
            else {
                unable = true;
            }
        }

        if (unable == true) {
            cout << -1;
        }
        else {
            for (tmp = 0; tmp < num; tmp++)
                cout << content;
        }
    }

    return 0;
}


// test.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>

#include <algorithm>
using namespace std;

int main()
{
    //std::cout << "Hello World!\n";
    int num,tmp;
    bool unable = false;
    int startp=0, endp;
    char content[1001] = { 0 };
    char* contentp = content;
    char count[26] = { 0 };
    cin >> num;

    cin >> content;

    int i;
    for (i = 0; i < 1000; i++) {
        count[content[i] - 'a']++;
    }

    if (num == 0) {
        cout << -1;
    }
    else {
        for (i = 0; i < 26 && unable == false; i++) {
            if (count[i] % num == 0) {
                for (tmp = 0; tmp < count[i] / num; tmp++) {
                    snprintf(contentp, 2, "%c", i + 'a');
                    contentp++;
                }
            }
            else {
                unable = true;
            }
        }

        if (unable == true) {
            cout << -1;
        }
        else {
            for (tmp = 0; tmp < num; tmp++)
                cout << content;
        }
    }

    return 0;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started:
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file


#include <iostream>

#include <algorithm>
using namespace std;

int main()
{
    //std::cout << "Hello World!\n";
    int num,tmp;
    bool unable = false;
    int startp=0, endp;
    char content[1002] = { 0 };
    char* contentp = content;
    char count[26] = { 0 };
    cin >> num;

    cin >> content;

    int i;
    for (i = 0; i < 1000; i++) {
        count[content[i] - 'a']++;
    }

    if (num == 0) {
        cout << -1;
    }
    else {
        for (i = 0; i < 26 && unable == false; i++) {
            if (count[i] % num == 0) {
                for (tmp = 0; tmp < count[i] / num; tmp++) {
                    snprintf(contentp, 2, "%c", i + 'a');
                    contentp++;
                }
            }
            else {
                unable = true;
            }
        }

        if (unable == true) {
            cout << -1;
        }
        else {
            for (tmp = 0; tmp < num; tmp++)
                cout << content;
        }
    }

    return 0;
}


#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<iostream>
using namespace std;

int main()
{
    int k,k2,f=0,l,temp=0,t=0,arr[125]={0};
    char s[1010];

    cin>>k;
    cin>>s;
    k2=k;
    l=strlen(s);

    if(k==1)
      f=5;
    else
       {
         for(int i=0;i<l;i++)
            {
              temp=(int)s[i];

               arr[temp]++;

            }
         for(int i=90;i<125;i++)
             {
              if((arr[i]%k)!=0 && arr[i]!=0)
                  {
                     f=1;
                     break;
                  }
            }
         }

    if(f==0)
      while(k2--)
        {
          for(int i=90;i<125;i++)
            {
             if(arr[i]!=0)
              {
                  t=arr[i]/k;
             //   cout<<arr[i]<<" ";
             //   cout<<" t_"<<t<<" ";
               while(t--)
                   printf("%c",i);
              }
            }
        }

    else if(f==5)
      cout<<s;
    else
      cout<<"-1";

    cout<<endl;

return 0;
}


#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<iostream>
using namespace std;

int main()
{
    int k,f=0,l,temp=0,arr[125]={0};
    char s[1010];

    cin>>k;
    cin>>s;

    l=strlen(s);

    if(k==1)
      f=0;
    else
       {
         for(int i=0;i<l;i++)
            {  temp=(int)s[i];
             //  cout<<"t"<<temp<<endl;
               arr[temp]++;
           //  cout<<arr[temp]<<" at\n";
            }
         for(int i=90;i<125;i++)
             {//cout<<arr[i]<<endl;
              if((arr[i]%k)!=0 && arr[i]!=0)
                  {
                     f=1;
                     break;
                  }
            }
         }

    //cout<<f<<" f\n";
    if(f==0)
      while(k--)
        {
          for(int i=90;i<125;i++)
             if(arr[i]!=0)
                printf("%c",i);
        }
    else
      cout<<"-1";

    cout<<endl;

return 0;
}


#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<iostream>
using namespace std;

int main()
{
    int k,f=0,l,temp=0,arr[125]={0};
    char s[1010];

    cin>>k;
    cin>>s;

    l=strlen(s);

    if(k==1)
      f=5;
    else
       {
         for(int i=0;i<l;i++)
            {  temp=(int)s[i];
             //  cout<<"t"<<temp<<endl;
               arr[temp]++;
           //  cout<<arr[temp]<<" at\n";
            }
         for(int i=90;i<125;i++)
             {//cout<<arr[i]<<endl;
              if((arr[i]%k)!=0 && arr[i]!=0)
                  {
                     f=1;
                     break;
                  }
            }
         }

    //cout<<f<<" f\n";
    if(f==0)
      while(k--)
        {
          for(int i=90;i<125;i++)
             if(arr[i]!=0)
                printf("%c",i);
        }
    else if(f==5)
      cout<<s;
    else
      cout<<"-1";

    cout<<endl;

return 0;
}


#include <iostream>
#include <vector>
#include <numeric>
#include <string>
#include <functional>
#include <stack>
#include <chrono>
#include <ctime>
#include <cstdio>
#include<set>
#include<algorithm>
#include<cassert>
#include<iomanip>
#define fori(n) for(int i=0;i<n;i++)
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	string s;
	cin >> s;
	int arr[26] = { 0 };
	for (int i = 0; i < s.size(); i++) {
		arr[s[i] - 'a']++;
	}
	for (int i = 0; i < 26; i++) {
		if (arr[i] == 0) continue;
		if (arr[i] % n != 0 || arr[i]<n) {
			cout << -1;
			return 0;
		}
	}
	string ans="";
	for (int j = 0; j < 26; j++) {
		arr[j] /= n;
		while (arr[j] > 0) {
			ans += char(j + 'a');
			arr[j]--;
		}

	}
	while(n--)
	cout << ans;
	return 0;

}


#include <iostream>
#include <vector>
#include <numeric>
#include <string>
#include <functional>
#include <stack>
#include <chrono>
#include <ctime>
#include <cstdio>
#include<set>
#include<algorithm>
#include<cassert>
#include<iomanip>
#define fori(n) for(int i=0;i<n;i++)
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	string s;
	cin >> s;
	int arr[26] = { 0 };
	for (int i = 0; i < s.size(); i++) {
		arr[s[i] - 'a']++;
	}
	for (int i = 0; i < 26; i++) {
		if (arr[i] % n != 0) {
			cout << -1;
			return 0;
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 26; j++) {
			if (arr[j] == 0) continue;
			cout << char(j + 'a');
		}
	}
	return 0;

}


#include <iostream>
#include <vector>
#include <numeric>
#include <string>
#include <functional>
#include <stack>
#include <chrono>
#include <ctime>
#include <cstdio>
#include<set>
#include<algorithm>
#include<cassert>
#include<iomanip>
#define fori(n) for(int i=0;i<n;i++)
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	string s;
	cin >> s;
	int arr[26] = { 0 };
	for (int i = 0; i < s.size(); i++) {
		arr[s[i] - 'a']++;
	}
	for (int i = 0; i < 26; i++) {
		if (arr[i] == 0) continue;
		if (arr[i] % n != 0 || arr[i]<n) {
			cout << -1;
			return 0;
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 26; j++) {
			if (arr[j] == 0) continue;
			cout << char(j + 'a');

		}
	}
	return 0;

}


#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<stack>

#include<vector>
#include<cctype>
#include<string>
#include<stdlib.h>
using namespace std;

int main(){
 int k,count=0;
 cin>>k;
 char ch;
 string s;
 cin>>s;
 int l=s.length();
 for(int i=0;i<l;i++)
 {
     if(i%k==0){
         ch=s[i];
     }
     if(ch==s[i])
     count++;
 }
 if(count==l&&count%k==0)
 {
     for(int i=0;i<k;i++)
     {
         for(int j=0;j<l;j+=k){
             cout<<s[i];
         }
     }
 }
 else
 cout<<"-1";
return 0;
}


#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<cctype>
#include<string>
#include<stdlib.h>
using namespace std;

int main(){
 int k,count=0;
 cin>>k;
 char ch;
 string s;
 cin>>s;
 int l=s.length();
 for(int i=0;i<l;i++)
 {
     if(i%k==0){
         ch=s[i];
     }
     if(ch==s[i])
     count++;
 }
 if(count==l&&count%k==0)
 {
     for(int i=0;i<k;i++)
     {
         for(int j=0;j<l;j+=k){
             cout<<s[i];
         }
     }
 }
 else
 cout<<"-1";
return 0;
}


#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<cctype>
#include<string>
#include<stdlib.h>
using namespace std;

int main(){
 int k,count=0;
 cin>>k;
 char ch;
 string s;
 cin>>s;
 int l=s.length();
 sort(s.begin(),s.begin()+s.size());
 for(int i=0;i<l;i++)
 {
     if(i%k==0){
         ch=s[i];
     }
     if(ch==s[i])
     count++;
 }
 if(count==l&&count%k==0)
 {
     for(int i=0;i<k;i++)
     {
         for(int j=0;j<l;j+=k){
             cout<<s[j];
         }
     }
 }
 else
 cout<<"-1";
return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_map>
using namespace std;

void main()
{
	int k;
	cin >> k;
	string s;
	cin >> s;
	unordered_map<char, int> m;
	for (auto ch : s)
	{
		if (m.count(ch) == 0)
			m[ch] = 1;
		else
			m[ch]++;
	}

	bool yes = true;
	string r;
	for (auto kv : m)
	{
		if (kv.second % k > 0)
		{
			yes = false;
			break;
		}
		for (int i = 0; i < kv.second / k; i++)
			r.push_back(kv.first);
	}

	if (!yes)
		cout << -1 << endl;
	else
	{
		for (int i = 0; i < k; i++)
			cout << r;
		cout << endl;
	}
}


#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
	int k;
	string s;
	cin >> k >> s;
	vector<int> vec(26);
	for (int i = 0; i < s.size(); ++i) {
		vec[s[i] - 'a']++;
	}
	for (int i = 0; i < 26; ++i) {
		if (vec[i]%k) {
			cout << -1 << endl;
			return 0;
		}
	}
	string ans;
	for (int i = 0; i < 26; ++i) {
		for (int j = 0; j < vec[i]/k; ++j) {
			ans += i + 'a';
		}
	}
	for (int i = 0; i < k; ++i) {
		cout << ans;
	}
	cout << endl;
	return 0;
}


#include<iostream>
#include<string>
#include<string.h>
#include<stdlib.h>
using namespace std;
int main()
{  char str[10005];
int k;
cin>>k;
cin>>str;
if(strlen(str)%k==0)
{

}
   else
    { cout<<"-1";
        exit(0);
    }
char str2[10000];
int count=0,x=0;
for(int i=0;str[i]!='\0';i++)
{   if(str[i]=='*')
continue;
    count=0;
    for(int j=i+1;str[j]!='\0';j++)
{ if(str[j]==str[i]&&count<k)
{count++;
str[j]='*';
}

}
if((count+1)%k!=0)
{ cout<<"-1";
exit(0);
}
else
{ count=count/k;
while(count!=0)
{ str2[x]=str[i];
x++;
count--;
}
}
}

for(int m=1;m<=k;m++)
    cout<<str2;
}


#include<iostream>
#include<string>
#include<string.h>
#include<stdlib.h>
using namespace std;
int main()
{  char str[10005];
int k;
cin>>k;
cin>>str;
if(strlen(str)%k==0)
;
   else
    { cout<<"-1";
        exit(0);
    }
char str2[10000];
int count=0;
for(int i=0;str[i]!='\0';i++)
{   if(str[i]=='*')
continue;
    count=0;
    for(int j=i+1;str[j]!='\0';j++)
{ if(str[j]==str[i]&&count<k)
{count++;
str[j]='*';
}

}
if(count%k==0)
{ cout<<"-1";
exit(0);
}
}
int x=0;
for(int i=0;str[i]!='\0';i++)
{ if(str[i]!='*')
{ str2[x]=str[i];
x++;
}
}
if(strlen(str2)%k!=0)
{ cout<<"-1";
exit(0);
}
for(int i=0;i<k;i++)
{ cout<<str2;
}
}


#include<iostream>
#include<string.h>
#include<stdlib.h>
using namespace std;
int main()
{  char str[10005];
int k;
cin>>k;
cin>>str;
if(strlen(str)%k==0)
{

}
   else
    { cout<<"-1";
        exit(0);
    }
char str2[10000];
int count=0,x=0;
for(int i=0;str[i]!='\0';i++)
{   if(str[i]=='*')
continue;
    count=0;
    for(int j=i+1;str[j]!='\0';j++)
{ if(str[j]==str[i])
{count++;
str[j]='*';
}

}
if((count+1)%k!=0)
{ cout<<"-1";
exit(0);
}
else
{  count+=1;
    count=count/k;
while(count!=0)
{ str2[x]=str[i];
x++;
count--;
}
}
}
for(int m=1;m<=k;m++)
    cout<<str2;
}


#include<iostream>
#include<string>
#include<string.h>
#include<stdlib.h>
using namespace std;
int main()
{  char str[10005];
int k;
cin>>k;
cin>>str;
if(strlen(str)%k==0)
;
   else
    { cout<<"-1";
        exit(0);
    }
char str2[10000];
int count=0;
for(int i=0;str[i]!='\0';i++)
{   if(str[i]=='*')
continue;
    count=0;
    for(int j=i+1;str[j]!='\0';j++)
{ if(str[j]==str[i]&&count<k)
{count++;
str[j]='*';
}

}
}
int x=0;
for(int i=0;str[i]!='\0';i++)
{ if(str[i]!='*')
{ str2[x]=str[i];
x++;
}
}
if(strlen(str2)%k!=0)
{ cout<<"-1";
exit(0);
}
for(int i=0;i<k;i++)
{ cout<<str2;
}
}


#include<iostream>
#include<string>
#include<string.h>
#include<stdlib.h>
using namespace std;
int main()
{  char str[10005];
int k;
cin>>k;
cin>>str;
if(strlen(str)%k==0)
;
   else
    { cout<<"-1";
        exit(0);
    }
char str2[10000];
int count=0;
for(int i=0;str[i]!='\0';i++)
{   if(str[i]=='*')
continue;
    count=0;
    for(int j=i+1;str[j]!='\0';j++)
{ if(str[j]==str[i]&&count<k)
{count++;
str[j]='*';
}

}
if((count+1)%k!=0)
{ cout<<"-1";
exit(0);
}
}
int x=0;
for(int i=0;str[i]!='\0';i++)
{ if(str[i]!='*')
{ str2[x]=str[i];
x++;
}
}
if(strlen(str2)%k!=0)
{ cout<<"-1";
exit(0);
}
for(int i=0;i<k;i++)
{ cout<<str2;
}
}


#include<iostream>
#include<string>
#include<string.h>
#include<stdlib.h>
using namespace std;
int main()
{  char str[10005];
int k;
cin>>k;
cin>>str;
if(strlen(str)%k==0)
{

}
   else
    { cout<<"-1";
        exit(0);
    }
char str2[10000];
int count=0;
for(int i=0;str[i]!='\0';i++)
{   if(str[i]=='*')
continue;
    count=0;
    for(int j=i+1;str[j]!='\0';j++)
{ if(str[j]==str[i]&&count<k)
{count++;
str[j]='*';
}

}
if((count+1)%k!=0)
{ cout<<"-1";
exit(0);
}
}
int x=0;
for(int i=0;str[i]!='\0';i++)
{ if(str[i]!='*')
{ str2[x]=str[i];
x++;
}
}
if(k%strlen(str2)!=0)
{ cout<<"-1";
exit(0);
}
for(int i=0;i<k;i++)
{ cout<<str2;
}
}


#include<iostream>
#include<string>
#include<string.h>
#include<stdlib.h>
using namespace std;
int main()
{  char str[10005];
int k;
cin>>k;
cin>>str;
if(strlen(str)%k==0)
;
   else
    { cout<<"-1";
        exit(0);
    }
char str2[10000];
int count=0;
for(int i=0;str[i]!='\0';i++)
{   if(str[i]=='*')
continue;
    count=0;
    for(int j=i+1;str[j]!='\0';j++)
{ if(str[j]==str[i]&&count<k)
{count++;
str[j]='*';
}

}
if((count+1)%k!=0)
{ cout<<"-1";
exit(0);
}
}
int x=0;
for(int i=0;str[i]!='\0';i++)
{ if(str[i]!='*')
{ str2[x]=str[i];
x++;
}
}
if(k%strlen(str2)!=0)
{ cout<<"-1";
exit(0);
}
for(int i=0;i<k;i++)
{ cout<<str2;
}
}


#include <iostream>
#include <string>

/*
A2OJ Ladder Problems
Ladder: https://www.a2oj.com/Ladder11.html
Problem: https://codeforces.com/problemset/problem/219/A
*/

/*

*/
void P_1_50() {
	int k;
	std::string s;
	std::cin >> k >> s;

	int letters['z' + 1] = { 0 };
	for (char c : s)
		letters[c]++;

	std::string k_string = "";
	bool is_k_string = true;
	for (int i = 'a'; i <= 'z'; i++) {
		if (letters[i] % k != 0) {
			is_k_string = false;
			break;
		}

		// build k-string
		k_string += std::string(letters[i] / k, (char) i);
	}

	if (!is_k_string) {
		std::cout << "-1";
	} else {
		// k-string is valid, so repeat it k times
		while (k--)
			std::cout << k_string;
	}
}

int main() {
	P_1_50();
}


#include <iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include <stdio.h>
using namespace std;
//function to append char into char array
void append(char* s, char c)
{
    int len = strlen(s);
	s[len] = c;
	s[len + 1] = '\0';
}

int main()
{
	int k;
	string s;
	cin >> k;
	cin >> s;

	// check if length of string is can be divided by the k;
	float f;
	f = float(s.length()) / k;
	if ((f - int(f)) != 0)
	{
		cout << -1 << endl;
		goto end;
	}

	// sorting string s
	sort(s.begin(), s.end());

	// count each character in string s and assign them in c
	int c[26];
	int asciiValue = 97;
	char character;
	for (int i = 0; i<26; i++)
	{
		character = char(asciiValue);
		c[i] = count(s.begin(), s.end(), character);
		asciiValue++;
	}
	// check if number of each char can be divided by k
	for (int i = 0; i<26; i++)
	{
		f = float(c[i]) / k;
		if ((f - int(f)) != 0)
		{
			cout << -1 << endl;
			goto end;
			break;
		}

	}
	// count and store number of characters needed for sub string and store them in sol
	int sol[26];
	for (int i = 0; i < 26; i++) sol[i] = c[i] / k;

	// get the repeated sub string depending on sol values
	char soln[1005] = {};
	for (int i = 0; i<26; i++)
	{
		for (int j = 0; j<sol[i]; j++)
		{
			if (sol[i] != 0)
			{
				append(soln, (char(i + 97)));
			}
			else
			{
				break;
			}

		}

	}

	// print solution
	for (int i = 0; i < k; i++)cout << soln;
	cout << endl;
end:;
	return 0;
}


#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

map<char, int> m;

void solve(){
    string s;
    int n;
    cin >> n >> s;
    for(int i=0; i<s.length(); i++){
        m[s[i]] = 0;
    }
    for(int i=0; i<s.length(); i++){
        m[s[i]] = m[s[i]] + 1;
    }
    for(auto &x:m){
        if(x.second%n != 0){
            cout << -1;
            return;
        }
    }
    for(int i=0; i<n; i++){
        for(auto &x:m){
            for(int j=0; j<x.second/n; j++){
                cout << x.first;
            }
        }
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t=1;

    while(t--){
        solve();
    }
}


#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

map<char, int> m;

void solve(){
    string s;
    int n;
    cin >> n >> s;
    for(int i=0; i<s.length(); i++){
        m[s[i]] = 0;
    }
    for(int i=0; i<s.length(); i++){
        m[s[i]] = m[s[i]] + 1;
    }
    for(auto &x:m){
        if(x.second/n!=1){
            cout << -1;
            return;
        }
    }
    for(int i=0; i<n; i++){
    for(auto &x:m){
        cout << x.first;
    }
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t=1;

    while(t--){
        solve();
    }
}


#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

map<char, int> m;

void solve(){
    string s;
    int n;
    cin >> n >> s;
    for(int i=0; i<s.length(); i++){
        m[s[i]] = 0;
    }
    for(int i=0; i<s.length(); i++){
        m[s[i]] = m[s[i]] + 1;
    }
    for(auto &x:m){
        if(x.second%n != 0){
            cout << -1;
            return;
        }
    }
    for(int i=0; i<n; i++){
    for(auto &x:m){
        cout << x.first;
    }
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t=1;

    while(t--){
        solve();
    }
}


#include <iostream>
#include<string>
#include<map>
using namespace std;
int main() {
	string s; int k;
	cin >> k >> s;
	map<char, int> l;
	string ans, a;
	for (int i = 0; i < s.size(); ++i) l[s[i]]++;
	for (auto x : l) {
		if (x.second % k != 0) {
			cout << "-1";
			return 0;
		} else for (int i = 0; i < x.second / k; ++i) a += x.first;
	}
	for (int i = 0; i < k; ++i) ans += a;
	cout << ans;
	return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<algorithm>
using namespace std;

#define fr(i, n) for(int i = 0; i < n; i++)
#define fre(i, n) for(int i = 0; i <= n; i++)
#define frs(i, st, n) for(int i = st; i < n; i++)
#define frse(i, st, n) for(int i = st; i <= n; i++)

typedef long long int ll;
typedef unsigned long long int ull;

int main()
{
    int k;
    string s;
    cin >> k;
    cin >> s;
    vector<int> dic(40);
    int l = s.size();
    fr(i, l) {
        dic[s[i] - 'a']++;
    }
    string outStr = "";
    bool flag = true;
    fr(i, 40) {
        if (dic[i] % k != 0) {
            flag = false;
            break;
        }
        fr(j, dic[i] / k)
            outStr += i + 'a';
    }
    if (flag)


#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<algorithm>
using namespace std;

#define fr(i, n) for(int i = 0; i < n; i++)
#define fre(i, n) for(int i = 0; i <= n; i++)
#define frs(i, st, n) for(int i = st; i < n; i++)
#define frse(i, st, n) for(int i = st; i <= n; i++)

typedef long long int ll;
typedef unsigned long long int ull;

int main()
{
    int k;
    string s;
    cin >> k;
    cin >> s;
    vector<int> dic(40);
    int l = s.size();
    fr(i, l) {
        dic[s[i] - 'a']++;
    }
    string outStr = "";
    bool flag = true;
    fr(i, 40) {
        if (dic[i] % k != 0) {
            flag = false;
            break;
        }
        fr(j, dic[i] / k)
            outStr += i + 'a';
    }
    if (flag)
        fr(i, k)
            cout << outStr;
    else
        cout << "-1";
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#define yes cout << "YES" << endl
#define no  cout << "NO" << endl
#define ntest int t; cin >> t
#define fori(e) for (int i = 0; i < e; i++)
#define forj(e) for (int j = 0; j < e; j++)
#define forn(s,e) for (int i = s; i < e; i++)
using namespace std;

int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	if (n == 1)
		cout << s;
	else if (s.length() % n != 0)
		cout << "-1";
	else
	{
		sort(s.begin(), s.end());
		int c[30], j = 0;
		c[j] = 1;
		for (int i = 1; i < s.length(); i++)
		{
			if (s[i] == s[i - 1])
			{
				c[j]++;
			}
			else
			{
				j++;
				c[j] = 1;
			}
		}
		bool enough = 1;
		for (int i = 0; i <= j && enough; i++)
		{
			if (c[i] % n != 0)
				enough = 0;
		}

		if (!enough)
			cout << "-1" << endl;
		else
		{
			string ss = "";
			int x, pos = 0;
			char l;
			fori(j + 1)
			{
				x = c[i] / n;
				l = s[pos];
				fori(x)
					ss += l;
				pos += c[i];
			}
			fori(n)
				cout << ss;
		}
	}

	return 0;
}


#include <iostream>
#include <unordered_map>
#include <string>

std::string iskStr(std::string& x, int k) {
	if (x.length() % k != 0) {
		return "-1";
	}

	int l = x.length() / k;

	std::unordered_map<char, int> H;

	int n = 0;

	for (int i = 0; i < x.length(); i++) {
		if (H.find(x[i]) == H.end()) {
			H[x[i]] = 1;
			n++;
		}
		else {
			H[x[i]]++;
		}
	}

	if (n > l) {
		return "-1";
	}

	std::string result = "";

	for (auto it = H.begin(); it != H.end(); it++) {
		if (it->second % k != 0) {
			return "-1";
		}
		for (int i = 0; i < it->second / k; i++) {
			result += it->first;
		}
	}

	std::string answer = "";

	for (int i = 0; i < k; i++) {
		answer += result;
	}

	return answer;
}

int main() {
	int k;
	std::string str;
	std::cin >> k;
	std::cin >> str;
	std::cout << iskStr(str, k);
}


#include <iostream>
#include <unordered_map>
#include <string>

std::string iskStr(std::string& x, int k) {
	if (x.length() % k != 0) {
		return "-1";
	}

	int l = x.length() / k;

	std::unordered_map<char, int> H;

	int n = 0;

	for (int i = 0; i < x.length(); i++) {
		if (H.find(x[i]) == H.end()) {
			H[x[i]] = 1;
			n++;
		}
		else {
			H[x[i]]++;
		}
	}

	if (n > l) {
		return "-1";
	}

	std::string result = "";

	for (auto it = H.begin(); it != H.end(); it++) {
		if (it->second % k != 0) {
			return "-1";
		}
		for (int i = 0; i < it->second / k; i++) {
			result += it->first;
		}
	}

	return result;
}

int main() {
	int k;
	std::string str;
	std::cin >> k;
	std::cin >> str;
	std::cout << iskStr(str, k);
}


#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
	int k,ans=0;
	cin >> k;
	string s;
	cin >> s;
	vector <int> A(26, 0);
	for (int i = 0;i < s.size();i++) {
		A[s[i] - 'a']++;
	}
	for (int i = 0;i < A.size();i++) {
		if(A[i]%k!=0){
			ans++;
			break;
		}
		A[i] = A[i] / k;
	}
	if (ans != 0) {
		cout << -1 << endl;
	}
	else {
		for (int j = 0;j < k;j++) {
			for (int i = 0;i < A.size();i++) {
				for (int j = 0;j < A[i];j++) {
					cout<<char('a' + i);
				}
			}
		}
	}
}


/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby,
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;

int main()
{
    int n;cin>>n;
    string s,g;
    cin>>s;
    int l=s.length();
    set<char> se;
    int a[26]={0};
    for(int i=0;i<l;i++)
    {
        a[s[i]-'a']++;
        se.insert(s[i]);
    }

    set <char > :: iterator itr;
    for(itr=se.begin();itr!=se.end();itr++)
    {
        char t=*itr;

        if(!(a[t-'a']%n==0))
        {
            cout<<"-1";
            return 0;
        }
        else
        {
            for(int k=0;k<a[t-'a']/n;k++)
            {
                g+=t;
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<g;
    }
    return 0;
}


#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include<set>
using namespace std;

int main()
{
    int n;cin>>n;
    string s,g;
    cin>>s;
    int l=s.length();
    set<char> se;
    int a[26]={0};
    for(int i=0;i<l;i++)
    {
        a[s[i]-'a']++;
        se.insert(s[i]);
    }

    set <char > :: iterator itr;
    for(itr=se.begin();itr!=se.end();itr++)
    {
        char t=*itr;

        if(!(a[t-'a']%n==0))
        {
            cout<<"-1";
            return 0;
        }
        else
        {
            for(int k=0;k<a[t-'a']/n;k++)
            {
                g+=t;
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<g;
    }
    return 0;
}


/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby,
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;

int main()
{
    int n;cin>>n;
    string s,g;
    cin>>s;
    int l=s.length();
    set<char> se;
    int a[26]={0};
    for(int i=0;i<l;i++)
    {
        a[s[i]-'a']++;
        se.insert(s[i]);
    }

    set <char > :: iterator itr;
    for(itr=se.begin();itr!=se.end();itr++)
    {
        char t=*itr;

        if(!(a[t-'a']%n==0))
        {
            cout<<"-1";
            return 0;
        }
        else
        {
            for(int k=0;k<a[t-'a']/n;k++)
            {
                g+=t;
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<g;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <string>

int main()
{
   int k;
	std::string input;
	std::string output = "1";

	std::cin >> k;
	std::cin >> input;

	std::vector<int> ocurrences(26, 0);

	for (auto i = 0; i < input.size(); i++) {
		ocurrences[input[i] - 'a']++;
	}

	for (auto i = 0; i < 26; i++) {
		if (ocurrences[i] % k != 0) {
			output = "-1";
			break;
		}
		ocurrences[i] = ocurrences[i] / k;
	}

	if (output != "-1") {
		output = "";
		for (auto i = 0; i < k; i++) {
			for (auto j = 0; j < 26; j++) {
				for (auto c = 0; c < ocurrences[j]; c++)
					output += 'a' + j;
			}
		}
	}

	std::cout << output;

	return 0;
}


int k;
	std::string input;
	std::string output = "1";

	cin >> k;
	cin >> input;

	std::vector<int> ocurrences(26, 0);

	for (auto i = 0; i < input.size(); i++) {
		ocurrences[input[i] - 'a']++;
	}

	for (auto i = 0; i < 26; i++) {
		if (ocurrences[i] % k != 0) {
			output = "-1";
			break;
		}
		ocurrences[i] = ocurrences[i] / k;
	}

	if (output != "-1") {
		output = "";
		for (auto i = 0; i < k; i++) {
			for (auto j = 0; j < 26; j++) {
				for (auto c = 0; c < ocurrences[j]; c++)
					output += 'a' + j;
			}
		}
	}

	cout << output;


#include <iostream>
#include <vector>
#include<iomanip>
#include <cstring>
#include <string.h>
#include <iterator>
#include <math.h>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <limits.h>
#include <string>
#include <bitset>
#include <map>
#include <numeric>
#include<unordered_map>

#define endl cout<<"\n"
#define lli long long int
#define ld long double
#define M_PI (3.14159265358979323846264338327950288)
#define MOD (1000000007)

using namespace std;

//fast-exponentiation-lli
lli expo_fast(lli a, lli b) {
	a = a;
	lli result = 1;
	while (b) {
		//multiplyint(tos(result), a);
		if (b & 1)result = (result * a);
		b >>= 1;
		a = (a*a);
	}
	return (result);
}

void take_in(vector<lli> *arr) {
	for (int i = 0; i < arr->size(); i++)cin >> (*(arr))[i];
}

void disp_arr(vector<lli>* arr) {
	for (int i = 0; i < arr->size(); i++)cout << (*(arr))[i] << " ";
}

lli gcd(lli a, lli b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);

}

/* Iterative Function to calculate (x^y)%p in O(log y) */
lli power(lli x, unsigned lli y, lli p)
{
	lli res = 1;      // Initialize result
	x = x % p;  // Update x if it is more than or equal to p
	while (y > 0){
		// If y is odd, multiply x with result
		if (y & 1)res = (res*x) % p;
		// y must be even now
		y = y >> 1;
		x = (x*x) % p;
	}
	return res;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int k; cin >> k;
	string s; cin >> s;
	vector<int>count(26);
	for (char c : s) {
		count[c - 'a']++;
	}
	bool done = false;
	for (int i = 0; i < 26; i++) {
		if (count[i] % k) {
			cout << -1;
			done = true;
			break;
		}
	}
	if (!done) {
		vector<int>iter(26);
		for (int i = 0; i < 26; i++) {
			iter[i] = count[i] / k;
		}
		int t = k;
		while (t--) {
			for (int i = 0; i < 26; i++) {
				for (int j = 0; j <iter[i]; j++) {
					cout << char('a' + i);
				}
				count[i] -= (iter[i]);
			}
		}

	}
	//system("PAUSE");
}


#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
int main(){
    int k;
    cin>>k;
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    //cout<<s<<endl;
    char x=s[0];
    int count=0,i=0,len=s.length();
    vector<int>some;
    while(s[i]==x){
        count++;
        i++;
    }
    int n=len/count,newcount=0;
    some.push_back(count);
    for(i=1;i<n;i++){
        char y=s[count*i];

        if(x!=y){
            for(int j=0;j<count;j++){
                if(s[(count*i)+j]==y)
                   newcount++;
            }
            some.push_back(newcount);
            newcount=0;
        }
    }int sum=0;
    for(i=0;i<n;i++){
        sum+=some[i];
    }
    int j;
    if(sum!=len)
      cout<<"-1"<<endl;
    else{
        for(i=0;i<count;i++){
            for(j=0;j<n;j++){
                cout<<s[(count*j)+i];
            }
        }
    }

}


//A k string
#include<iostream>
#include<algorithm>
#include<string>
#define ak long long int

using namespace std;

int main()
{
    ak k;
    cin>>k;
    string s;
    cin>>s;
    ak len = s.length();

    sort(s.begin(),s.end());

    ak slen=len/k;
    char ch;
    bool dhoni=false;
    for (ak i = 0; i < len;)
    {
        if(i%k==0)
        {
            ch=s[i];
            ak j=i+1;
            ak end=i+k;
            ak count=1;
            while (j<end)
            {
                if(s[j]==ch)
                    count++;
                else
                {
                    break;
                }
                j++;
            }
            if(count==k)
            {
                dhoni=true;
                i+=k;
            }
            else
            {
                dhoni=false;
                break;
            }

        }

    }
    if (dhoni==true)
    {
        for (ak i = 0; i < k; i++)
        {
            for(ak j=0;j<slen;j++)
            {
                cout<<s[(k*j)+i];
            }
        }

    }
    else
    {
        cout<<"-1"<<endl;
    }

}


#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    int k;
    cin>>k;

    string str,tp;
    getline(cin, tp);
    getline(cin, str);

    if(str.size()%k!=0)
    {
        cout<<"-1";
        return 0;
    }

    int a[26];
    vector<char> q;

    for(int i=0;i<26;i++)
    {
        a[i]=0;
    }

    for(int i=0;i<str.size();i++)
    {
        a[(int)str[i] - 97]++;
    }

    for(int i=0;i<26;i++)
    {
        if(a[i]>0 && a[i]%k==0)
        {
            char c = (char)(i+97);
            for(int j=0;j<a[i]/k;j++)
            {
                q.push_back(c);
            }
        }
        else if(a[i]>0 && a[i]%k!=0)
        {
            cout<<"-1";
            return 0;
        }

    }

    for(int i=0;i<str.size()/q.size();i++)
    {
        for(int j=0;j<q.size();j++)
        {
            cout<<q[j];
        }
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    int k;
    cin>>k;

    string str,tp;
    getline(cin, tp);
    getline(cin, str);

    if(str.size()%k!=0)
    {
        cout<<"-1";
        return 0;
    }

    int a[26];
    vector<char> q;

    for(int i=0;i<26;i++)
    {
        a[i]=0;
    }

    for(int i=0;i<str.size();i++)
    {
        a[(int)str[i] - 97]++;
    }

    for(int i=0;i<26;i++)
    {
        if(a[i]>0 && a[i]%k==0)
        {
            char c = (char)(i+97);
            for(int j=0;j<a[i]/k;j++)
            {
                q.push_back(c);
            }
        }
        else if(a[i]>0 && a[i]%k!=0)
        {
            cout<<"-1";
            return 0;
        }

    }

    for(int i=0;i<str.size()/k;i++)
    {
        for(int j=0;j<q.size();j++)
        {
            cout<<q[j];
        }
    }

    return 0;
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <ctype.h>
#include<bits.h>
#include<algorithm>
using namespace std;
int main() {
	string s;
	int g = 0;
	int *arr = new int[26];
	for (int i = 0; i < 26; i++)
	{
		arr[i] = 0;
	}
	int f;
	cin >> f;
	cin >> s;
	int h = s.size() / f;
	//cout << s.size();
	if ((s.size()) % f == 0)
	{
		for (int i = 0; i < s.size(); i++)
		{
			arr[(s[i] - 97)] = arr[(s[i] - 97)]+ 1;
			//cout << arr[(s[i] - 97)];

		}
	}
	bool no = false;
	for (int i = 0; i < f; i++)
	{
		//arr[(s[i] - 97)] += 1;
		if (arr[(s[i] - 97)] % f!=0)
		{

			no = true;
		}

	}
	if (no == true) {
		cout << "-1" << endl;
	}

	else if (no == false) {

		sort(s.begin(), s.end());
		//cout << s;
		for (int i = 0; i < f; i++) {
			int o = i;
			for (int i = 0; i < h; i++) {
				cout << s[o];
				o += f;
			}
		}

		cout << endl;
	}

	return 0;
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <ctype.h>
#include<bits.h>
#include<algorithm>
using namespace std;
int main() {
	string s;
	int g = 0;
	int *arr = new int[26];
	for (int i = 0; i < 26; i++)
	{
		arr[i] = 0;
	}
	int f;
	cin >> f;
	cin >> s;
	int h = s.size() / f;
	//cout << s.size();
	if ((s.size()) % f == 0)
	{
		for (int i = 0; i < s.size(); i++)
		{
			arr[(s[i] - 97)] = arr[(s[i] - 97)]+ 1;
			//cout << arr[(s[i] - 97)];

		}
	}
	bool no = false;
	for (int i = 0; i < f; i++)
	{
		//arr[(s[i] - 97)] += 1;
		if (arr[(s[i] - 97)] != ((s.size()) / f))
		{

			no = true;
		}

	}
	if (no == true) {
		cout << "-1" << endl;
	}

	else if (no == false) {

		sort(s.begin(), s.end());
		for (int i = 0; i < h; i++) {
			int o = i;
			for (int i = 0; i < h; i++) {
				cout << s[o];
				o += h;
			}
		}

	}

	return 0;
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <ctype.h>
#include<bits.h>
#include<algorithm>
using namespace std;
int main() {
	string s;
	int g = 0;
	int *arr = new int[26];
	for (int i = 0; i < 26; i++)
	{
		arr[i] = 0;
	}
	int f;
	cin >> f;
	cin >> s;
	int h = s.size() / f;
	//cout << s.size();
	if ((s.size()) % f == 0)
	{
		for (int i = 0; i < s.size(); i++)
		{
			arr[(s[i] - 97)] = arr[(s[i] - 97)]+ 1;

		}
	}
	bool no = false;
	for (int i = 0; i < f; i++)
	{
		if (arr[(s[i] - 97)] % f!=0)
		{

			no = true;
		}

	}
	if (no == true) {
		cout << "-1" ;
	}

	else if (no == false) {

		sort(s.begin(), s.end());
		for (int i = 0; i < f; i++) {
			int o = i;
			for (int i = 0; i < h; i++) {
				cout << s[o];
				o += f;
			}
		}

	}

	return 0;
}


#include<iostream>
#include"string"
#include<algorithm>
using namespace std;
int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] < 97) {
			s[i] += 32;
		}
		if (s[i] == 'a' || s[i] == 'o' || s[i] == 'u' || s[i] == 'i' || s[i] == 'y' || s[i] == 'e') {
			s.erase(i, 1);
			i--;
		}

	}
	int size = s.size() * 2;
	char *new1=new char[size+1];

	//cout << size;
	new1[0] = '.';
	int o = 0;
	for (int i = 1; i < size; i++) {
		if (i % 2 != 0) {
			new1[i] = s[o];
			o++;
		}
		else if (i % 2 == 0) {
			new1[i] = '.';
		}

	}
	for (int i = 0; i < size; i++) {

		cout << new1[i];
	}
	cout<<endl;

	return 0;
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <ctype.h>
#include<bits.h>
#include<algorithm>
using namespace std;
int main() {
	string s;
	int g = 0;
	int *arr = new int[26];
	for (int i = 0; i < 26; i++)
	{
		arr[i] = 0;
	}
	int f;
	cin >> f;
	cin >> s;
	int h = s.size() / f;
	//cout << s.size();
	if ((s.size()) % f == 0)
	{
		for (int i = 0; i < s.size(); i++)
		{
			arr[(s[i] - 97)] = arr[(s[i] - 97)]+ 1;
			//cout << arr[(s[i] - 97)];

		}
	}
	bool no = false;
	for (int i = 0; i < f; i++)
	{
		//arr[(s[i] - 97)] += 1;
		if (arr[(s[i] - 97)] != f)
		{

			no = true;
		}

	}
	if (no == true) {
		cout << "-1" << endl;
	}

	else if (no == false) {

		sort(s.begin(), s.end());

		for (int i = 0; i < f; i++) {
			int o = i;
			for (int i = 0; i < h; i++) {
				cout << s[o];
				o += f;
			}
		}

		cout << endl;
	}

	return 0;
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <ctype.h>
#include<bits.h>
#include<algorithm>
using namespace std;
int main() {
	string s;
	int g = 0;
	int *arr = new int[26];
	for (int i = 0; i < 26; i++)
	{
		arr[i] = 0;
	}
	int f;
	cin >> f;
	cin >> s;
	int h = s.size() / f;
	//cout << s.size();
	if ((s.size()) % f == 0)
	{
		for (int i = 0; i < s.size(); i++)
		{
			arr[(s[i] - 97)] = arr[(s[i] - 97)]+ 1;
			//cout << arr[(s[i] - 97)];

		}
	}
	bool no = false;
	for (int i = 0; i < f; i++)
	{
		//arr[(s[i] - 97)] += 1;
		if (arr[(s[i] - 97)] != f)
		{

			no = true;
		}

	}
	if (no == true) {
		cout << "-1" << endl;
	}

	else if (no == false) {
		//cout << "yes";
		//cout << s[0];
		//sort(s.begin(), s.end());
		sort(s.begin(), s.end());
		//cout << s;
		for (int i = 0; i < f; i++) {
			int o = i;
			for (int i = 0; i < h; i++) {
				cout << s[o];
				o += f;
			}
		}

	}

	return 0;
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <ctype.h>
using namespace std;
int main() {
	string s;
	int g = 0;
	int *arr = new int[26];
	for (int i = 0; i < 26; i++)
	{
		arr[i] = 0;
	}
	int f;
	cin >> f;
	cin >> s;
	int h = s.size() / f;
	if ((s.size()) % f == 0)
	{
		for (int i = 0; i < f; i++)
		{
			arr[(s[i] - 97)] += 1;
		}
	}
	bool no = false;
	for (int i = 0; i < f; i++)
	{
		//arr[(s[i] - 97)] += 1;
		if (arr[(s[i] - 97)] != (s.size()) / f)
		{
			no = true;
		}

	}
	if (no == true) {
		cout << "-1" << endl;
	}

	else if(no==false) {

		for (int i = 1; i <( s.size() - 1); i++) {
			if (s[i] == s[i - 1])
			{
				swap(s[i], s[i + 1]);
			}
		}
		cout << s << endl;
	}

	return 0;
}


#include <iostream>
#include <string>
#include<algorithm>
using namespace std;
int main() {
	string s;
	int g = 0;
	int *arr = new int[26];
	for (int i = 0; i < 26; i++)
	{
		arr[i] = 0;
	}
	int f;
	cin >> f;
	cin >> s;
	int h = s.size() / f;
	//cout << s.size();
	//cout << s.size();
	bool no = false;

	if ((s.size()) % f == 0)
	{
		for (int i = 0; i < s.size(); i++)
		{
			arr[(s[i] - 97)] += 1;

		}
	}else{
		no = true;
	}
	for (int i = 0; i < f; i++)
	{
		if (arr[(s[i] - 97)] % f != 0)
		{

			no = true;
		}

	}
	if (no == true) {
		cout << -1;
	}

	else if (no == false) {

		sort(s.begin(), s.end());
		for (int i = 0; i < f; i++) {
			int o = i;
			for (int i = 0; i < h; i++) {
				cout << s[o];
				o += f;
			}
		}

	}

	return 0;
}


#include <iostream>
#include <string>
#include<algorithm>
using namespace std;
int main() {
	string s;
	int *arr = new int[26];
	for (int i = 0; i < 26; i++)
	{
		arr[i] = 0;
	}
	int f;
	cin >> f;
	cin >> s;
	int h = s.size() / f;
	//cout << s.size();
	//cout << s.size();
	bool no = false;

	if ((s.size()) % f == 0)
	{
		for (int i = 0; i < s.size(); i++)
		{
			arr[(s[i] - 97)] += 1;

		}
	}else{
		no = true;
	}
	for (int i = 0; i < f; i++)
	{
		if (arr[(s[i] - 97)] % f != 0)
		{

			no = true;
		}

	}
	if (no == true) {
		cout << -1;
	}

	else if (no == false) {

		sort(s.begin(), s.end());
		for (int i = 0; i < f; i++) {
			int o = i;
			for (int i = 0; i < h; i++) {
				cout << s[o];
				o += f;
			}
		}

	}

	return 0;
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <ctype.h>
#include<bits.h>
#include<algorithm>
using namespace std;
int main() {
	string s;
	int g = 0;
	int *arr = new int[26];
	for (int i = 0; i < 26; i++)
	{
		arr[i] = 0;
	}
	int f;
	cin >> f;
	cin >> s;
	int h = s.size() / f;
	//cout << s.size();
	if ((s.size()) % f == 0)
	{
		for (int i = 0; i < s.size(); i++)
		{
			arr[(s[i] - 97)] = arr[(s[i] - 97)]+ 1;

		}
	}
	bool no = false;
	for (int i = 0; i < f; i++)
	{
		if (arr[(s[i] - 97)] % f!=0)
		{

			no = true;
		}

	}
	if (no == true) {
		cout << -1 << endl;
	}

	else if (no == false) {

		sort(s.begin(), s.end());
		for (int i = 0; i < f; i++) {
			int o = i;
			for (int i = 0; i < h; i++) {
				cout << s[o];
				o += f;
			}
		}

		cout << endl;
	}

	return 0;
}


#include <iostream>
#include <string>
#include<algorithm>
using namespace std;
int main() {
	string s;
	int g = 0;
	int *arr = new int[26];
	for (int i = 0; i < 26; i++)
	{
		arr[i] = 0;
	}
	int f;
	cin >> f;
	cin >> s;
	int h = s.size() / f;
	//cout << s.size();
	if ((s.size()) % f == 0)
	{
		for (int i = 0; i < s.size(); i++)
		{
			arr[(s[i] - 97)] += 1;

		}
	}
	bool no = false;
	for (int i = 0; i < f; i++)
	{
		if (arr[(s[i] - 97)] % f!=0)
		{

			no = true;
		}

	}
	if (no == true) {
		cout << -1 ;
	}

	else if (no == false) {

		sort(s.begin(), s.end());
		for (int i = 0; i < f; i++) {
			int o = i;
			for (int i = 0; i < h; i++) {
				cout << s[o];
				o += f;
			}
		}

	}

	return 0;
}


#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<string>
#include<iomanip>
#include<conio.h>
#include<string.h>
#include<cstdio>

using namespace std;

int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);

__int64 d;
int n,a=0;;
cin>>n>>d;
vector <int> v(n);
for(int i=0;i<n;i++)
{
cin>>v[i];
}
for(int i=0;i<n;i++)
{
        int j;
        while(v[j]-v[i]<=d&&j<n) j++;
        a+=(j-i-1)*(j-i-2)/2;
}
cout<<a;

return 0;

}


#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<string>
#include<iomanip>
#include<conio.h>
#include<string.h>
#include<cstdio>

using namespace std;

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

__int64 d;
int n,a=0;;
cin>>n>>d;
vector <int> v(n);
for(int i=0;i<n;i++)
{
cin>>v[i];
}
for(int i=0;i<n;i++)
{
        int j;
        while(v[j]-v[i]<=d&&j<n) j++;
        a+=(j-i-1)*(j-i-2)/2;
}
cout<<a;

return 0;

}


#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<string>
#include<iomanip>
#include<conio.h>
#include<string.h>
#include<cstdio>

using namespace std;

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

__int64 d;
int n,a=0;;
cin>>n>>d;
vector <int> v(n);
for(int i=0;i<n;i++)
{
cin>>v[i];
}
for(int i=0;i<n;i++)
{
        int j=0;
        while(v[j]-v[i]<=d&&j<n) j++;
        a+=(j-i-1)*(j-i-2)/2;
}
cout<<a;

return 0;

}


#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<string>
#include<iomanip>
#include<conio.h>
#include<string.h>
#include<cstdio>

using namespace std;

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

long int d,a=0;
int n;
cin>>n>>d;
vector <long int> v(n);
for(int i=0;i<n;i++)
{
cin>>v[i];
}
int j=0;
for(int i=0;i<n;i++)
{
        while(v[j]-v[i]<=d&&j<n) j++;
        a+=(j-i-1)*(j-i-2)/2;
}
cout<<a;

return 0;

}


#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<string>
#include<iomanip>
#include<conio.h>
#include<string.h>
#include<cstdio>

using namespace std;

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

__int64 d;
int n,a=0;;
cin>>n>>d;
vector <int> v(n);
for(int i=0;i<n;i++)
{
cin>>v[i];
}
int j=0;
for(int i=0;i<n;i++)
{
        while(v[j]-v[i]<=d&&j<n) j++;
        a+=(j-i-1)*(j-i-2)/2;
}
cout<<a;

return 0;

}


#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<string>
#include<iomanip>
#include<conio.h>
#include<string.h>
#include<cstdio>

using namespace std;

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

__int64 d;
int n,a=0;;
cin>>n>>d;
vector <int> v(n);
for(int i=0;i<n;i++)
{
cin>>v[i];
}
for(int i=0;i<n;i++)
{
        int j;
        while(v[j]-v[i]<=d&&j<n) j++;
        a+=(j-i-1)*(j-i-2)/2;
}
cout<<a;
getch();

return 0;

}


#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<string>
#include<iomanip>
#include<conio.h>
#include<string.h>
#include<cstdio>

using namespace std;

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

__int64 d,a=0;
int n;
cin>>n>>d;
vector <int> v(n);
for(int i=0;i<n;i++)
{
cin>>v[i];
}
int j=0;
for(int i=0;i<n;i++)
{
        while(v[j]-v[i]<=d&&j<n) j++;
        a+=(__int64)(j-i-1)*(j-i-2)/2;
}
cout<<a;

return 0;

}


#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<string>
#include<iomanip>
#include<conio.h>
#include<string.h>
#include<cstdio>

using namespace std;

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

__int64 d,a=0;
int n;
cin>>n>>d;
vector <int> v(n);
for(int i=0;i<n;i++)
{
cin>>v[i];
}
int j=0;
for(int i=0;i<n;i++)
{
        while(v[j]-v[i]<=d&&j<n) j++;
        a+=(j-i-1)*(j-i-2)/2;
}
cout<<a;

return 0;

}


#include <bits/stdc++.h>
using namespace std;

void fast_io(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

void solve(){
    int n, d;
    cin >> n >> d;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    long long cnt = 0;
    for(int i = 0; i < n - 2; i++){
        int j = upper_bound(a.begin(), a.end(), a[i] + d) - a.begin() - 1;
        // cout << i << " " << j << endl;
        while(i < j){
            cnt += (j - i - 1);
            j--;
        }
    }
    cout << cnt << endl;
}

int main(){
	fast_io();

    solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

void fast_io(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

void solve(){
    int n, d;
    cin >> n >> d;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    long long cnt = 0;
    for(int i = 0; i < n - 2; i++){
        int j = upper_bound(a.begin(), a.end(), a[i] + d) - a.begin() - 1;
        // cout << i << " " << j << endl;
        if(i < j){
            int k = j - i;
            cnt += (k * (k - 1)) / 2;
        }
    }
    cout << cnt << endl;
}

int main(){
	fast_io();

    solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

void fast_io(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

void solve(){
    int n, d;
    cin >> n >> d;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    long long cnt = 0;
    for(int i = 0; i < n - 2; i++){
        int j = upper_bound(a.begin(), a.end(), a[i] + d) - a.begin() - 1;
        // cout << i << " " << j << endl;
        if(i < j){
            long long k = j - i;
            cnt += (k * (k - 1)) / 2;
        }
    }
    cout << cnt << endl;
}

int main(){
	fast_io();

    solve();
	return 0;
}


#include <iostream>
#include <vector>
using namespace std;

long long int f(int l, int r) {
    return (long long)(r - l - 2) * (r - l - 1) / 2;
}

int main()
{
    int n,d;
    cin>>n>>d;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }

    int r = 0;
    long long int ans=0;
    while (r < a.size() && a[r] - a[0] <= d) {
        ++r;

    }
    if (r > 2) {
        ans+=f(0, r);
    }
    //cout<<f(0, r)<<'\n';
    for(int i=1;i<n;i++){
        while (r < a.size() && a[r] - a[i] <= d) {
            ++r;
        }

        if (r - i > 2) {
            ans+=f(i, r);
        }
        //cout<<f(i, r)<<' ';
    }
    cout<<ans;
    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int n,d;
    cin>>n>>d;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    long long int ans=0;
    for(int i=0;i<n;i++){
        int b=i+2;
        if(b<n){
            while(a[b]-a[i]<=d&&b<n){
                //ans+=b-1-i;
                b++;
            }
            b--;
            ans+=(b-i-1)*(b-i)/2;
        }
    }
    cout<<ans;
    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int n,d;
    cin>>n>>d;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    long long int ans=0;
    for(int i=0;i<n;i++){
        int b=i+2;
        if(b<n){
            while(a[b]-a[i]<=d){
                b++;
                if(b>=n){
                    break;
                }
            }
            b--;
            ans+=(b-i-1)*(b-i)/2;
        }
    }
    cout<<ans;
    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

long long int f(int l, int r) {
    return (r - l - 2) * (r - l - 1) / 2;
}

int main()
{
    int n,d;
    cin>>n>>d;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }

    int r = 0;
    long long int ans=0;
    while (r < a.size() && a[r] - a[0] <= d) {
        ++r;

    }
    if (r > 2) {
        ans+=f(0, r);
    }
    //cout<<f(0, r)<<'\n';
    for(int i=1;i<n;i++){
        while (r < a.size() && a[r] - a[i] <= d) {
            ++r;
        }

        if (r - i > 2) {
            ans+=f(i, r);
        }
        //cout<<f(i, r)<<' ';
    }
    cout<<ans;
    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int n,d;
    cin>>n>>d;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    long long int ans=0;
    for(int i=0;i<n;i++){
    int b=i+2;
        while(a[b]-a[i]<=d&&b<n){
            ans+=b-1-i;
            b++;
        }
    }
    cout<<ans;
    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int n,d;
    cin>>n>>d;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int ans=0;
    for(int i=0;i<n;i++){
    int b=i+2;
        while(a[b]-a[i]<=d&&b<n){
            ans+=b-1-i;
            b++;
        }
    }
    cout<<ans;
    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int f(int l, int r) {
    return (r - l - 2) * (r - l - 1) / 2;
}

int main()
{
    int n,d;
    cin>>n>>d;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }

    int r = 0;
    long long int ans=0;
    while (r < a.size() && a[r] - a[0] <= d) {
        ++r;

    }
    if (r > 2) {
        ans+=f(0, r);
    }
    //cout<<f(0, r)<<'\n';
    for(int i=1;i<n;i++){
        while (r < a.size() && a[r] - a[i] <= d) {
            ++r;
        }

        if (r - i > 2) {
            ans+=f(i, r);
        }
        //cout<<f(i, r)<<' ';
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
#include <sys/time.h>
#define CIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define fa(d,i,n) for(d i = 0; i < n; i++)
#define far(d,i,n) for(d i = n - 1; i >= 0; i--)
#define fi(d,i,ind,n) for(d i = ind; i < n; i++)
#define fir(d,i,ind,n) for(d i = n - 1; i >= i; i--)
#define F first
#define S second
#define flush cin>>ws
#define getstring(s) getline(cin,s)
#define mp make_pair
#define MOD 1000000007
#define vi vector<int>
#define vll vector<lli>
#define dyni(a,n) int *a = new int[n];
#define dynill(a,n) lli *a = new lli[n];
#define pii pair<int,int>
#define pll pair<lli,lli>
#define setprec(n) cout << setprecesion(n)
#define setfixedprec cout << fixed
#define MID (l + (r - l) / 2)
#define all(x) x.begin(),x.end()
#define MAX =INT_MAX
#define MIN =INT_MIN
#define BS l<=r
int getTime() {
	struct timeval start;
	gettimeofday(&start, NULL);
	return start.tv_sec * 1000000 + start.tv_usec;
}

using namespace std;
using lli = long long int;

int main()
{
	//lli st = getTime();
	CIN

	lli n, d;
	cin >> n >> d;
	vll a(n);

	fa(lli, i, n) cin >> a[i];
	if (n < 3) {
		cout << "0";
		return 0;
	}
	lli i = 0, j = 2;
	lli ans = 0;
	while ((j - i) >= 2 && j != n) {
		if (abs(abs(a[j]) - abs(a[i])) <= d) {
			ans += (j - i - 1);
			if (j != n - 1) j++;
			else i++;
			//cout << i << " " << j << "\n";
		}
		else {
			i++;
			if ( (j - i) < 2) j++;
		}
	}
	cout << ans;

	//lli et = getTime();
	//cout<<"Total time taken = "<<(et - st);
	return 0;
}


#include <bits/stdc++.h>
#include <sys/time.h>
#define CIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define fa(d,i,n) for(d i = 0; i < n; i++)
#define far(d,i,n) for(d i = n - 1; i >= 0; i--)
#define fi(d,i,ind,n) for(d i = ind; i < n; i++)
#define fir(d,i,ind,n) for(d i = n - 1; i >= i; i--)
#define F first
#define S second
#define flush cin>>ws
#define getstring(s) getline(cin,s)
#define mp make_pair
#define MOD 1000000007
#define vi vector<int>
#define vll vector<lli>
#define dyni(a,n) int *a = new int[n];
#define dynill(a,n) lli *a = new lli[n];
#define pii pair<int,int>
#define pll pair<lli,lli>
#define setprec(n) cout << setprecesion(n)
#define setfixedprec cout << fixed
#define MID (l + (r - l) / 2)
#define all(x) x.begin(),x.end()
#define MAX =INT_MAX
#define MIN =INT_MIN
#define BS l<=r
int getTime() {
	struct timeval start;
	gettimeofday(&start, NULL);
	return start.tv_sec * 1000000 + start.tv_usec;
}

using namespace std;
using lli = long long int;

int main()
{
	//lli st = getTime();
	CIN

	lli n, d;
	cin >> n >> d;
	vll a(n);

	fa(lli, i, n) cin >> a[i];
	if (n < 3) {
		cout << "0";
		return 0;
	}
	lli i = 0, j = 2;
	lli ans = 0;
	while (j < n) {
		if (abs(abs(a[j]) - abs(a[i])) <= d) {
			//cout << i << " " << j << "\n";
			lli q = (j - i - 1);

			q = ((q) * (q + 1)) / 2;
			ans += q;
			j++;

		}
		else {
			i++;
			if ( (j - i) < 2) j++;
		}
	}
	//cout << a[i] << " " << a[j] << "\n";
	cout << ans;

	//lli et = getTime();
	//cout<<"Total time taken = "<<(et - st);
	return 0;
}


#include <bits/stdc++.h>
#include <sys/time.h>
#define CIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define fa(d,i,n) for(d i = 0; i < n; i++)
#define far(d,i,n) for(d i = n - 1; i >= 0; i--)
#define fi(d,i,ind,n) for(d i = ind; i < n; i++)
#define fir(d,i,ind,n) for(d i = n - 1; i >= i; i--)
#define F first
#define S second
#define flush cin>>ws
#define getstring(s) getline(cin,s)
#define mp make_pair
#define MOD 1000000007
#define vi vector<int>
#define vll vector<lli>
#define dyni(a,n) int *a = new int[n];
#define dynill(a,n) lli *a = new lli[n];
#define pii pair<int,int>
#define pll pair<lli,lli>
#define setprec(n) cout << setprecesion(n)
#define setfixedprec cout << fixed
#define MID (l + (r - l) / 2)
#define all(x) x.begin(),x.end()
#define MAX =INT_MAX
#define MIN =INT_MIN
#define BS l<=r
int getTime() {
	struct timeval start;
	gettimeofday(&start, NULL);
	return start.tv_sec * 1000000 + start.tv_usec;
}

using namespace std;
using lli = long long int;

int main()
{
	//lli st = getTime();
	CIN

	lli n, d;
	cin >> n >> d;
	vll a(n);

	fa(lli, i, n) cin >> a[i];
	if (n < 3) {
		cout << "0";
		return 0;
	}
	lli i = 0, j = 2;
	lli ans = 0;
	while (j < n) {
		if (a[j] - a[i] <= d) {
			//cout << i << " " << j << "\n";
			lli q = (j - i - 1);

			q = ((q) * (q + 1)) / 2;
			ans += q;
			j++;

		}
		else {
			i++;
			if ( (j - i) < 2) j++;
		}
	}
	//cout << a[i] << " " << a[j] << "\n";
	cout << ans;

	//lli et = getTime();
	//cout<<"Total time taken = "<<(et - st);
	return 0;
}

// #include <bits/stdc++.h>
// #include <sys/time.h>
// #define CIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// #define pb push_back
// #define fa(d,i,n) for(d i = 0; i < n; i++)
// #define far(d,i,n) for(d i = n - 1; i >= 0; i--)
// #define fi(d,i,ind,n) for(d i = ind; i < n; i++)
// #define fir(d,i,ind,n) for(d i = n - 1; i >= i; i--)
// #define F first
// #define S second
// #define flush cin>>ws
// #define getstring(s) getline(cin,s)
// #define mp make_pair
// #define MOD 1000000007
// #define vi vector<int>
// #define vll vector<lli>
// #define dyni(a,n) int *a = new int[n];
// #define dynill(a,n) lli *a = new lli[n];
// #define pii pair<int,int>
// #define pll pair<lli,lli>
// #define setprec(n) cout << setprecesion(n)
// #define setfixedprec cout << fixed
// #define MID (l + (r - l) / 2)
// #define all(x) x.begin(),x.end()
// #define MAX =INT_MAX
// #define MIN =INT_MIN
// #define BS l<=r
// int getTime() {
// 	struct timeval start;
// 	gettimeofday(&start, NULL);
// 	return start.tv_sec * 1000000 + start.tv_usec;
// }

// using namespace std;
// using lli = long long int;

// int main()
// {
// 	//lli st = getTime();
// 	CIN

// 	lli n, d;
// 	cin >> n >> d;
// 	vll a(n);

// 	fa(lli, i, n) cin >> a[i];
// 	if (n < 3) {
// 		cout << "0";
// 		return 0;
// 	}
// 	lli i = 0, j = 1;
// 	lli ans = 0;
// 	while (i < n) {
// 		while (j < n && a[j] - a[i] <= d) j++;
// 		lli q = j - i - 1;
// 		ans += ((q) * (q - 1)) / 2;
// 		i++;
// 	}
// 	cout << ans;

// 	//lli et = getTime();
// 	//cout<<"Total time taken = "<<(et - st);
// 	return 0;
// }


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define oo 1e18
#define mx5 (int)1e5+5
#define pb push_back

using namespace std;

vector<ll>v;
int main()
{
    ll n,k,l=1,p,r=1,ans=0;
    cin>>n>>k;
    v.resize(n+1);
    for(int i=1;i<=n;i++)cin>>v[i];
    for(int i=1;i<=n-2;i++)
    {
        while(v[i]+k>=v[r]&&r<n)
        {
            r++;

        }
        r=min(r,n);
        if(v[i]+k<v[r])r--;
        //cout<<i<<' '<<r<<'\n';
        p=r-i-1;
        if(p<=0)continue;
        p=p*(p+1)/2;
        ans+=max(0LL,p);

    }
    cout<<ans;

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define oo 1e18
#define mx5 (int)1e5+5
#define pb push_back

using namespace std;

vector<ll>v;
int main()
{
    ll n,k,l=1,r=3,ans=0;
    cin>>n>>k;
    v.resize(n+1);
    for(int i=1;i<=n;i++)cin>>v[i];
    for(int i=1;i<n;i++)
    {
        r=lower_bound(v.begin()+i,v.end(),v[i]+k)-v.begin();
        r=max(r,n);
        while(v[r]-v[i]>k)r--;
        //cout<<i<<' '<<r<<' '<<v[i]+k<<' '<<v[r]<<' '<<r-i+1<<'\n';
        if(r-i+1>=3)
        {
            //cout<<i<<' '<<r<<' '<<v[i]<<' '<<v[r]<<' '<<v[r]-v[i]<<'\n';
            ll p=r-(i-1)-2;
            p=p*(p+1)/2;
            ans+=max(0LL,p);
        }
    }
    cout<<ans;

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define oo 1e18
#define mx5 (int)1e5+5
#define pb push_back
#define mx 99999999999
using namespace std;
vector<ll>v(mx5);
int main()
{
    ll n,k,l=1,r=3,ans=0;
    cin>>n>>k;
    for(int i=1;i<=n;i++)cin>>v[i];
    while(l<=r&&r<=n)
    {
        if(v[r]-v[l]<=k&&r-l+1>=3)
        {
            ans+=r-l-1;
            r++;
        }
        else l++;
    }
    r--;l++;
    while(l<=r)
    {
        if(v[r]-v[l]<=k&&r-l+1>=3)
        {
            ans+=r-l-1;

        }l++;
    }
    cout<<ans;

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define oo 1e18
#define mx5 (int)1e5+5
#define pb push_back

using namespace std;

vector<ll>v;
int main()
{
    ll n,k,l=1,p,r=1,ans=0;
    cin>>n>>k;
    v.resize(n+1);
    for(int i=1;i<=n;i++)cin>>v[i];
    for(int i=1;i<=n-2;i++)
    {
        while(v[i]+k>=v[r])
        {
            r++;

        }
        if(v[i]+k<v[r])r--;
        //cout<<i<<' '<<r<<'\n';
        p=r-i-1;
        p=p*(p+1)/2;
        ans+=max(0LL,p);

    }
    cout<<ans;

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define oo 1e18
#define mx5 (int)1e5+5
#define pb push_back

using namespace std;

vector<ll>v;
int main()
{
    ll n,k,l=1,p,r=1,ans=0;
    cin>>n>>k;
    v.resize(n+1);
    for(int i=1;i<=n;i++)cin>>v[i];
    for(int i=1;i<=n-2;i++)
    {
        while(v[i]+k>=v[r])
        {
            r++;

        }
        r=min(r,n);
        if(v[i]+k<v[r])r--;
        //cout<<i<<' '<<r<<'\n';
        p=r-i-1;
        if(p<=0)continue;
        p=p*(p+1)/2;
        ans+=max(0LL,p);

    }
    cout<<ans;

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define oo 1e18
#define mx5 (int)1e5+5
#define pb push_back

using namespace std;

vector<ll>v;
int main()
{
    ll n,k,l=1,p,r=1,ans=0;
    cin>>n>>k;
    v.resize(n+1);
    for(int i=1;i<=n;i++)cin>>v[i];
    for(int i=1;i<=n-2;i++)
    {
        while(v[i]+k>=v[r])
        {
            r++;

        }
        r=min(r,n);
        if(v[i]+k<v[r])r--;
        //cout<<i<<' '<<r<<'\n';
        p=r-i-1;
        p=p*(p+1)/2;
        ans+=max(0LL,p);

    }
    cout<<ans;

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define oo 1e18
#define mx5 (int)1e5+5
#define pb push_back

using namespace std;

vector<ll>v;
int main()
{
    ll n,k,l=1,r=3,ans=0;
    cin>>n>>k;
    v.resize(n+1);
    for(int i=1;i<=n;i++)cin>>v[i];
    for(int i=1;i<n;i++)
    {
        r=upper_bound(v.begin()+i,v.end(),v[i]+k)-v.begin();
        r=max(r,n);
        while(v[r]-v[i]>k)r--;
        //cout<<i<<' '<<r<<' '<<v[i]+k<<' '<<v[r]<<' '<<r-i+1<<'\n';
        if(r-i+1>=3)
        {
            //cout<<i<<' '<<r<<' '<<v[i]<<' '<<v[r]<<' '<<v[r]-v[i]<<'\n';
            ll p=r-(i-1)-2;
            p=p*(p+1)/2;
            ans+=max(0LL,p);
        }
    }
    cout<<ans;

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define oo 1e18
#define mx5 (int)1e5+5
#define pb push_back

using namespace std;

vector<ll>v;
int main()
{
    ll n,k,l=1,r=3,ans=0;
    cin>>n>>k;
    v.resize(n+1);
    for(int i=1;i<=n;i++)cin>>v[i];
    for(int i=1;i<=n-2;i++)
    {
        r=upper_bound(v.begin()+i,v.end(),v[i]+k)-v.begin();
        while(v[r]-v[i]>k)r--;
        //cout<<i<<' '<<r<<' '<<v[i]+k<<' '<<v[r]<<' '<<r-i+1<<'\n';
        if(r-i+1>=3)
        {
            //cout<<i<<' '<<r<<' '<<v[i]<<' '<<v[r]<<' '<<v[r]-v[i]<<'\n';
            ll p=r-(i-1)-2;
            p=p*(p+1)/2;
            ans+=max(0LL,p);
        }
    }
    cout<<ans;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define all(a)                       a.begin(),a.end()
#define allR(v)                    v.rbegin(),v.rend()
#define IO cin.tie(0);std::ios::sync_with_stdio(false)
#define PB                                   push_back
#define PF                                  push_front
#define set(a,b)                 memset(a,b,sizeof(a))
#define For(i,n)                  for(int i=0;i<n;i++)
#define PQ                              priority_queue
#define len(a)                                a.size()

typedef long long LL;
typedef unsigned long long ULL;
typedef double LF;

int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { -1, 1, 0, 0, -1, -1, 1, 1 };
const int mod = 1000000007;
const LF pi = acos(-1);
const LL OO = INT_MAX;

double distance(double a, double b, double x, double y)
{
    return sqrt((x-a)*(x-a) + ((y-b)*(y-b)));
}

bool sorted(int a[],int n){
	bool ok = 1;
	int pre = a[0];
	for(int i=0;i<n;i++){
		if(a[i]<pre){
			ok = 0; break;
		}
		pre = a[i];
	}
	if(ok) return 1;
	ok = 1;
	pre = a[0];
	for(int i=0;i<n;i++){
		if(a[i]>pre){
			ok = 0; break;
		}
		pre = a[i];
	}
	return ok;
}

int main()
{
    IO;
    int n ; LL d; cin>>n>>d;
    vector<LL>a(n); For(i,n)cin>>a[i];
    sort(all(a));
    LL Ans = 0;
    for(int i=0;i<n;i++){
    	int idx1 = upper_bound(all(a), a[i] - d) - a.begin();
    	int idx2 = upper_bound(all(a), d + a[i]) - a.begin();
    	int idx = max(idx2,idx1);
    	//if(idx == n) idx = n - 1;
    	int def = idx - i;
    	if(def>=2){
      		def-=2;
      		Ans += ((LL)def * (def + 1)) / 2;
     	}
    	//cout << idx1 << ' ' << idx2 << '\n';
    }
    cout << Ans;
}

/*
 * 001 010 111
 */


#include<bits/stdc++.h>
using namespace std;

#define all(a)                       a.begin(),a.end()
#define allR(v)                    v.rbegin(),v.rend()
#define IO cin.tie(0);std::ios::sync_with_stdio(false)
#define PB                                   push_back
#define PF                                  push_front
#define set(a,b)                 memset(a,b,sizeof(a))
#define For(i,n)                  for(int i=0;i<n;i++)
#define PQ                              priority_queue
#define len(a)                                a.size()

typedef long long LL;
typedef unsigned long long ULL;
typedef double LF;

int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { -1, 1, 0, 0, -1, -1, 1, 1 };
const int mod = 1000000007;
const LF pi = acos(-1);
const LL OO = INT_MAX;

double distance(double a, double b, double x, double y)
{
    return sqrt((x-a)*(x-a) + ((y-b)*(y-b)));
}

bool sorted(int a[],int n){
	bool ok = 1;
	int pre = a[0];
	for(int i=0;i<n;i++){
		if(a[i]<pre){
			ok = 0; break;
		}
		pre = a[i];
	}
	if(ok) return 1;
	ok = 1;
	pre = a[0];
	for(int i=0;i<n;i++){
		if(a[i]>pre){
			ok = 0; break;
		}
		pre = a[i];
	}
	return ok;
}

int main()
{
    IO;
    int n ; LL d; cin>>n>>d;
    vector<LL>a(n); For(i,n)cin>>a[i];
    sort(all(a));
    LL Ans = 0;
    for(int i=0;i<n;i++){
    	int idx1 = upper_bound(all(a), d - a[i]) - a.begin();
    	int idx2 = upper_bound(all(a), d + a[i]) - a.begin();
    	int idx = idx2;
    	int def = idx - i;
    	if(def>=2){
      		def-=2;
      		Ans += (def * (def + 1)) / 2;
     	}
    	//cout << idx << ' ';
    }
    cout << Ans;
}

/*
 * 001 010 111
 */


#include<bits/stdc++.h>
using namespace std;

#define all(a)                       a.begin(),a.end()
#define allR(v)                    v.rbegin(),v.rend()
#define IO cin.tie(0);std::ios::sync_with_stdio(false)
#define PB                                   push_back
#define PF                                  push_front
#define set(a,b)                 memset(a,b,sizeof(a))
#define For(i,n)                  for(int i=0;i<n;i++)
#define PQ                              priority_queue
#define len(a)                                a.size()

typedef long long LL;
typedef unsigned long long ULL;
typedef double LF;

int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { -1, 1, 0, 0, -1, -1, 1, 1 };
const int mod = 1000000007;
const LF pi = acos(-1);
const LL OO = INT_MAX;

double distance(double a, double b, double x, double y)
{
    return sqrt((x-a)*(x-a) + ((y-b)*(y-b)));
}

bool sorted(int a[],int n){
	bool ok = 1;
	int pre = a[0];
	for(int i=0;i<n;i++){
		if(a[i]<pre){
			ok = 0; break;
		}
		pre = a[i];
	}
	if(ok) return 1;
	ok = 1;
	pre = a[0];
	for(int i=0;i<n;i++){
		if(a[i]>pre){
			ok = 0; break;
		}
		pre = a[i];
	}
	return ok;
}

int main()
{
    IO;
    int n ; LL d; cin>>n>>d;
    vector<LL>a(n); For(i,n)cin>>a[i];
    sort(all(a));
    LL Ans = 0;
    for(int i=0;i<n;i++){
    	int idx1 = upper_bound(all(a), a[i] - d) - a.begin();
    	int idx2 = upper_bound(all(a), d + a[i]) - a.begin();
    	int idx = max(idx2,idx1);
    	//if(idx == n) idx = n - 1;
    	int def = idx - i;
    	if(def>=2){
      		def-=2;
      		Ans += ((LL)def * (def + 1)) / 2;
     	}
    	cout << idx1 << ' ' << idx2 << '\n';
    }
    cout << Ans;
}

/*
 * 001 010 111
 */


#include<bits/stdc++.h>
using namespace std;

#define all(a)                       a.begin(),a.end()
#define allR(v)                    v.rbegin(),v.rend()
#define IO cin.tie(0);std::ios::sync_with_stdio(false)
#define PB                                   push_back
#define PF                                  push_front
#define set(a,b)                 memset(a,b,sizeof(a))
#define For(i,n)                  for(int i=0;i<n;i++)
#define PQ                              priority_queue
#define len(a)                                a.size()

typedef long long LL;
typedef unsigned long long ULL;
typedef double LF;

int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { -1, 1, 0, 0, -1, -1, 1, 1 };
const int mod = 1000000007;
const LF pi = acos(-1);
const LL OO = INT_MAX;

double distance(double a, double b, double x, double y)
{
    return sqrt((x-a)*(x-a) + ((y-b)*(y-b)));
}

bool sorted(int a[],int n){
	bool ok = 1;
	int pre = a[0];
	for(int i=0;i<n;i++){
		if(a[i]<pre){
			ok = 0; break;
		}
		pre = a[i];
	}
	if(ok) return 1;
	ok = 1;
	pre = a[0];
	for(int i=0;i<n;i++){
		if(a[i]>pre){
			ok = 0; break;
		}
		pre = a[i];
	}
	return ok;
}

int main()
{
    IO;
    int n ; LL d; cin>>n>>d;
    vector<LL>a(n); For(i,n)cin>>a[i];
    sort(all(a));
    LL Ans = 0;
    for(int i=0;i<n;i++){
    	int idx1 = upper_bound(all(a), a[i] - d) - a.begin();
    	int idx2 = upper_bound(all(a), d + a[i]) - a.begin();
    	int idx = max(idx2,idx1);
    	int def = idx - i;
    	if(def>=2){
      		def-=2;
      		Ans += (def * (def + 1)) / 2;
     	}
    	//cout << idx << ' ';
    }
    cout << Ans;
}

/*
 * 001 010 111
 */


#include <bits/stdc++.h>
#include <vector>
#include <string>

using namespace std;

int main()
{
   int n,d;
   cin>>n>>d;
   int a[n];
   for(int i=0;i<n;i++)
    cin>>a[i];
   int r=n-1;
   int l=0;
   if(n<3)
   {
   	cout<<"0";
   	return 0;
   }
   long long sum=0;
   while(r>=2)
   {
   	// cout<<a[r]<<" "<<a[l]<<"\n";
   	 if(a[r]-a[l]>d)
   	 {
   	 	l++;
   	 }
   	 else
   	 {
   	 	int k=r-l;
   	 	sum+=(long long)k*(k-1)/2;
   	 	r--;
   	 	l=0;
   	 }
   }
   cout<<sum;
}


#include <bits/stdc++.h>
#include <vector>
#include <string>

using namespace std;

int main()
{
   int n,d;
   cin>>n>>d;
   int a[n];
   for(int i=0;i<n;i++)
    cin>>a[i];
   int r=n-1;
   int l=0;
   if(n<3)
   {
   	cout<<"0";
   	return 0;
   }
   long long sum=0;
   int j=0;
  for(int i=0;i<n;i++)
   {
   	// cout<<a[r]<<" "<<a[l]<<"\n";
   	 while(a[i]-a[j]>d)
   	 {
   	 	j++;
   	 }

   	 	int k=i-j;
   	 	sum+=(long long)k*(k-1)/2;

   }
   cout<<sum;
}


#include <bits/stdc++.h>
#include <vector>
#include <string>

using namespace std;

int main()
{
   int n,d;
   cin>>n>>d;
   int a[n];
   for(int i=0;i<n;i++)
    cin>>a[i];
   int r=n-1;
   int l=0;
   if(n<3)
   {
   	cout<<"0";
   	return 0;
   }
   long long sum=0;
   while(r>=2)
   {
   	// cout<<a[r]<<" "<<a[l]<<"\n";
   	 if(a[r]-a[l]>d)
   	 {
   	 	l++;
   	 }
   	 else
   	 {
   	 	int k=r-l;
   	 	sum+=k*(k-1)/2;
   	 	r--;
   	 	l=0;
   	 }
   }
   cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
	long long int n,d;
	cin>>n>>d;
	long long int arr[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	sort(arr,arr+n);
	long long int sum=0;
	long long int x=0;
	for(long long int i=0;i<n;i++){
		if(x!=n){
			while(arr[x]-arr[i]<=d){
				x++;
				if(x==n) break;
			}
		}
		sum+=(long long int)((x-i-1)*(x-i-2))/2;
	}
	cout<<sum;
}