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

bool check(long long t, long long x, long long y) {
	return ((x + y) % 2 + 2) % 2 == t % 2;
}

template<typename T>
class p {
public:
	T x, y;

	p(T a, T b): x(a), y(b) {
	}

	p operator* (T ska) {
		return p(ska * x, ska * y);
	}
	p operator/ (T ska) {
		return p(x/ska, y/ska);
	}
	p operator+ (p other) {
		return p(x + other.x, y + other.y);
	}

	pair<T, T> to_pair() const {
		return make_pair(x, y);
	}

	bool operator< (const p& other) const {
		return to_pair() < other.to_pair();
	}

	p flip45() {
		return p(x + y, x - y);
	}

	p unflip45() {
		return p(x + y, x - y) / 2;
	}

	T abs() {
		return std::abs(x) + std::abs(y);
	}
};

template<typename T>
class fraction {
public:
	T x, y;

	fraction(T a, T b): x(a), y(b) {
	}

	fraction(T a): fraction(a, 1) {
	}

	fraction normal() {
		T g = __gcd(x, y);
		if (g == 0) g = 1;
		return fraction(x/g, y/g);
	}

	fraction operator*(fraction other) {
		return fraction(x * other.x, y * other.y).normal();
	}

	fraction inverse() {
		return fraction(y, x);
	}

	fraction operator/(fraction other) {
		return (*this) * other.inverse();
	}

	long long to_int() {
		if (x == 0) return 0;
		return x / y;
	}

	bool operator < (const fraction& other) const {
		return x * other.y < y * other.x;
	}

	bool operator >= (const fraction& other) const {
		return not ((*this) < other);
	}

	bool operator <= (const fraction& other) const {
		return x * other.y <= y * other.x;
	}

	bool operator > (const fraction& other) const {
		return not ((*this) <= other);
	}

	bool operator <= (T other) const {
		return x <= other * y;
	}

	bool operator >= (T other) const {
		return x >= other * y;
	}

	fraction operator+ (fraction other) {
		T g = __gcd(y, other.y);
		if (g == 0) g = 1;
		return fraction(x * (other.y / g) + other.x * (y / g), y * (other.y / g));
	}

	fraction operator- () {
		return fraction(-x, y);
	}

	fraction operator- (fraction other) {
		return (*this) + (-other);
	}
};

using pun = p<long long>;

vector<pair<pair<long long, long long>, pun> > data;

using ld = long double;

long long ceil(long long a, long long b) {
	if (b == 0) return std::numeric_limits<int>::min();
	if (b < 0) {
		a *= -1;
		b *= -1;
	}
	if ((b > 0 && a > 0) || (a < 0 && b < 0)) return (a + b - 1) / b;
	else return a / b;
}

long long floor(long long a, long long b) {
	if (b == 0) return std::numeric_limits<int>::max();
	if (b < 0) {
		a *= -1;
		b *= -1;
	}
	if ((a > 0 && b > 0) || (a < 0 && b < 0)) return a / b;
	else return (a - (abs(b) - 1)) / b;
}

void popraw(long long x, int k, long long t, long long &x1, long long &x2) {
	long long mini = x - k;
	long long maxi = x + k;
	if (t < 0) {
		swap(mini, maxi);
	}
	x1 = max(x1, ceil(mini, t));
	x2 = min(x2, floor(maxi, t));
}

pun szukaj(int l) {
	sort(data.begin(), data.end());
	int last = 0;
	pun lastt = pun(0, 0);
	pun lastx = pun(0, 0);
	long long x1 = -l;
	long long y1 = -l;
	long long x2 = l;
	long long y2 = l;
	for (auto d: data) {
		int k = d.first.first - last;
		long long t = d.first.second - lastt;
		pun dx = d.second + (lastx * (-1));

		popraw(dx.x, k, t, x1, x2);
		popraw(dx.y, k, t, y1, y2);

		last = d.first.first;
		lastt = d.first.second;
		lastx = d.second;
	}
	if ((x1 + y1) % 2) {
		if (x1 < x2) x1 ++;
		else if (y1 < y2) y1 ++;
	}
//    		printf("%lld %lld %lld %lld\n", x1, x2, y1, y2);
	return pun(x1, y1);
}

string solve(bool failed, int l, pun x) {
	long long last = 0;
	pun lastx = pun(0, 0);
	string wynik = "";
	data.push_back(make_pair(make_pair(l, 0), x));
	for (auto d: data) {
		pun dx = d.second + (x * (-d.first.second)) + (lastx * (-1));
		long long k = d.first.first - last;

		if (abs(dx.x) > k || abs(dx.y) > k) failed = true;
		for (int i = 0; i < k; i ++) {
			if (dx.x > 0 && dx.y > 0) {
				wynik += 'R';
				dx.x --;
				dx.y --;
			} else if (dx.x > 0) {
				wynik += 'U';
				dx.x --;
				dx.y ++;
			} else if (dx.y > 0) {
				wynik += 'D';
				dx.x ++;
				dx.y --;
			} else {
				wynik += 'L';
				dx.x ++;
				dx.y ++;
			}
		}

		last = d.first.first;
		lastx = d.second + (x * -d.first.second);
	}
	if (failed) return "NO";
	return wynik;
}

int main() {
	int n, l;
	scanf("%d%d", &n, &l);
	bool failed = false;
	for (int i = 0; i < n; i ++) {
		long long t, x, y;
		scanf("%lld%lld%lld", &t, &x, &y);
		if (not check(t, x, y)) failed = true;
		data.push_back(make_pair(make_pair(t % l, t / l), pun(x + y, x - y)));
	}
	pun x = szukaj(l);
	string res = solve(failed, l, x);
	printf("%s\n", res.c_str());
}


#include <bits/stdc++.h>
#define PB push_back
using namespace std;
const int N = 200100;
const int M = 200100;
const int cnst = 203;
vector<int> g[N], vc;
int n, m, q, lf, rt, mrk[N], U[M], V[M], par[N], pre[N], mem[cnst], cur_par;
bool bi;

void dfs(int v, int col){
    if (!bi) return;

    if (mrk[v]){
        if (mrk[v] != col){
            bi = 0;
        }
        return;
    }

    mrk[v] = col;

    for (int nm : g[v]) {
        if (nm >= lf && nm <= rt) continue;

        int u = (U[nm] == v ? V[nm] : U[nm]);

        dfs(u, 3 - col);
    }
}

int get(int x){
    if (x == pre[x]) return x;

    vc.PB(x);

    while (pre[x] != x){
        vc.PB(x);
        x = pre[x];
    }

    cur_par = 0;

    while (sz(vc) > 0){
        x = vc.back();
        vc.pop_back();

        cur_par ^= par[x];

        par[x] = cur_par;
    }
}

void link(int x, int y){
    if (was) return;

    int xx = get(x), yy = get(y);

    if (xx != yy){
        pre[xx] = yy;
        par[xx] = (par[y] ^ 1 ^ par[x]);
    } else {
        if ((par[x] ^ par[y] ^ 1) == 1)
            was = 1;
    }
}

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

#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#endif // _LOCAL

    cin >> n >> m >> q;

    for (int i = 0; i < m; i++){
        int x, y; cin >> x >> y;
        x--; y--;

        U[i] = x;
        V[i] = y;

        g[x].PB(i);
        g[y].PB(i);
    }

    bi = 1; lf = rt = m;

    for (int i = 0; i < n && bi; i++){
        if (mrk[i]) continue;

        dfs(i, 1);
    }

    if (bi){
        for (; q; q--)
            cout << "NO\n";
        return 0;
    }

    for (int lf = 0; lf < cnst; lf++){
        for (int i = 0; i < n; i++){
            pre[i] = i;
            par[i] = 0;
        }

        was = 0;

        for (int id = 0; id < lf; id++)
            link(U[id], V[id]);

        int ptr = m - 1;

        while (!was){
            link(U[ptr], V[ptr]);
            ptr--;
        }

        mem[lf] = ptr;
    }

    for (int i = 0; i < q; i++){
        cin >> lf >> rt;
        lf--; rt--;

        if (lf < cnst){
            cout << (rt <= mem[lf] ? "YES\n" : "NO\n");
            continue;
        }

        fill(mrk, mrk + n, 0);
        bi = 1;

        for (int i = 0; i < n && bi; i++){
            if (mrk[i]) continue;

            dfs(i, 1);
        }

        cout << (bi ? "NO\n" : "YES\n");
    }

    return 0;
}


/*
 * use lct to maintain the maximum spanning tree, to check whether bipartite
 */

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

constexpr int _I_Buffer_Size = 8 << 20, _O_Buffer_Size = 1 << 20;
static char _I_Buffer[_I_Buffer_Size], _O_Buffer[_O_Buffer_Size];
char *_I_pos = _I_Buffer, *_O_pos = _O_Buffer;
void read(int32_t *n) {
  while (*_I_pos < 48) _I_pos++;
  *n = *_I_pos++ - '0';
  while (*_I_pos > 47)
    *n = *n * 10 + (*_I_pos++ - '0');
}
#define put_YES() (*_O_pos++ = 'Y', *_O_pos++ = 'E', *_O_pos++ = 'S', 0)
#define put_NO() (*_O_pos++ = 'N', *_O_pos++ = 'O', 0)

constexpr int Maxn = 200005;

int n, m, q;
int eu[Maxn], ev[Maxn];
int rr[Maxn];

// i \le j => ans_i \le ans_j

int stk[Maxn], top;
int fa[Maxn];
int val[Maxn], rt[Maxn];

void init_ufs() {
  top = 0;
  memset(stk, 0, sizeof(stk));
  for (int i = 0; i < Maxn; ++i) {
    fa[i] = i;
    val[i] = 0;
    rt[i] = 0;
  }
}
inline int fnd(int x) {
  while (x ^ fa[x])
    x = fa[x];
  return x;
}
inline int get_dis(int x) {
  int ans = 0;
  while (x ^ fa[x]) {
    ans ^= val[x];
    x = fa[x];
  }
  return ans;
}
void join(int x, int y, int len) {
  if (x == y) return ;
  if (rt[x] > rt[y]) swap(x, y);
  if (rt[x] == rt[y]) {
    rt[y]++;
    stk[++top] = -y;
  }
  fa[x] = y;
  val[x] = len;
  stk[++top] = x;
}
void undo() {
  fa[stk[top]] = stk[top];
  val[stk[top]] = 0;
  --top;
  if (stk[top] < 0) {
    rt[-stk[top]]--;
    --top;
  }
}
bool unite(int x, int y) {
  int rx = fnd(x), ry = fnd(y);
  int len = get_dis(x) ^ get_dis(y) ^ 1;
  if (rx == ry) {
    if (len) return false;
  }
  else {
    join(rx, ry, len);
  }
  return true;
}

inline void add_edge(int l, int r) {
  for (int i = l; i <= r; ++i)
    assert(unite(eu[i], ev[i]));
}
inline void undo_ufs(int times) {
  while (times--) undo();
}
int get_answer(int pos, int l, int R) {
  for (int i = l; i < pos; ++i)
    assert(unite(eu[i], ev[i]));
  int cnt = pos - l;
  while (true) {
    bool ff = unite(eu[R], ev[R]);
    ++cnt, --R;
    if (!ff) break;
  }
  undo_ufs(cnt);
  return R + 1;
}

// ufs contains [1, l) \cup (R, n]
void cdq(int l, int r, int L, int R) {
  if (l > r) return ;
  if (L == R) {
    for (int i = l; i <= r; ++i)
      rr[i] = L;
    return ;
  }
  L = max(L, l);
  int mid = (l + r) >> 1;
  rr[mid] = get_answer(mid, l, R);
  // (l, mid, r) => (L, rr[mid], R)
  if (rr[mid] < R) add_edge(rr[mid] + 1, R);
  cdq(l, mid - 1, L, rr[mid]);
  if (rr[mid] < R) undo_ufs(R - rr[mid]);
  if (l <= mid) add_edge(l, mid);
  cdq(mid + 1, r, rr[mid], R);
  if (l <= mid) undo_ufs(mid - l + 1);
}

int main() {

#ifdef LOCAL_JUDGE
  freopen("CF1386C.in", "r", stdin);
#endif
  fread(_I_Buffer, 1, _I_Buffer_Size, stdin);
  assert(atexit([&](void)->void {
    fwrite(_O_Buffer, 1, _O_pos - _O_Buffer, stdout);
  }) == 0);

  read(&n), read(&m), read(&q);
  for (int i = 1; i <= m; ++i)
    read(eu + i), read(ev + i);

  init_ufs();
  int f = 1;
  for (; f <= m; ++f) {
    if (!unite(eu[f], ev[f])) break;
  }
  if (f == m + 1) {
    while (q--) puts("NO");
    return 0;
  }
  init_ufs();
  for (int i = f + 1; i <= m; ++i)
    rr[i] = m + 1;
  cdq(1, f, 1, m);

  while (q--) {
    int l, r;
    read(&l), read(&r);
    if (rr[l] > r) puts("YES");
    else puts("NO");
  }

  return 0;

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <assert.h>
#define vi vector<int>
#define pii pair<int, int>
#define fst first
#define vpi vector<pii>
#define ppi pair<pii, int>
#define snd second

using namespace std;

namespace fastIO
{
	char outString[64];
	// inline int getchar_unlocked() {return getchar();}
	// inline void putchar_unlocked(int x) {putchar(x);}
	inline int charInput() {return getchar_unlocked();}
	inline void charOutput(int x) {putchar_unlocked(x);}
	inline bool isNum(int c) {return '0' <= c && c <= '9';}
	inline int intInput()
	{
		int c = 0, ret = 0; bool neg = 0;
		while (!isNum(c))
		{
			c = getchar_unlocked();
			if (c == '-') {neg = 1;}
		}
		while (isNum(c)) {ret = ret * 10 + c - '0'; c = getchar_unlocked();}
		return (neg) ? -ret : ret;
	}
	inline void intOutput(int x)
	{
		int ss = 0;
		while (x) {outString[ss++] = x % 10 + '0'; x /= 10;}
		if (!ss) outString[ss++] = '0';
		for (int i = ss - 1; i >= 0; i--) putchar_unlocked(outString[i]);
	}
	inline void strOutput(string s)
	{
		for (auto &c : s) putchar_unlocked(c);
	}
}

int n, m, q;
vpi adj[200001];
bool vis[200001];
bool clr[200001];

pii edge[200001];
ppi qry[200001];
string ans[200001];
int sz[200001];
bool lz[200001];
pair<int, bool> par[200001];

pair<int, bool> find(int x)
{
	if (x == par[x].fst) {return {x, 0};}
	else
	{
		pair<int, bool> ret = find(par[x].fst);
		par[x] = {ret.fst, ret.snd ^ par[x].snd};
		return par[x];
	}
}

inline bool join(int a, int b)
{
	pii parA = find(a), parB = find(b);
	//cout << "join " << a << " " << b << "\n";
	if (sz[parA.fst] < sz[parB.fst]) {swap(a, b); swap(parA, parB);}
	if (parA.fst != parB.fst)
	{
		if (sz[parA.fst] == sz[parB.fst]) sz[parA.fst]++;
		par[parB.fst].fst = parA.fst;
		par[parB.fst].snd = (parA.snd == parB.snd);
		return 1;
	}
	return parA.snd != parB.snd;
}

bool dfs(int u, bool c, int L, int R)
{
	if (!vis[u])
	{
		vis[u] = 1;
		clr[u] = c;
		bool ret = 1;
		for (auto v : adj[u])
		{
			if (L <= v.snd && v.snd <= R) continue;
			else ret &= dfs(v.fst, !c, L, R);
		}
		return ret;
	}
	else {return clr[u] == c;}
}

int main()
{
	n = fastIO :: intInput();
	m = fastIO :: intInput();
	q = fastIO :: intInput();
	if (n + m <= 2000)
	{
		for (int i = 0; i < m; i++)
		{
			int u, v;
			u = fastIO :: intInput();
			v = fastIO :: intInput();
			adj[u - 1].push_back({v - 1, i});
			adj[v - 1].push_back({u - 1, i});
		}
		for (int i = 0; i < q; i++)
		{
			bool ans = 1;
			int l, r;
			l = fastIO :: intInput();
			r = fastIO :: intInput();
			l--; r--;
			for (int j = 0; j < n; j++)
			{
				if (!vis[j])
				{
					ans &= dfs(j, 0, l, r);
				}
			}
			for (int j = 0; j < n; j++) {vis[j] = 0;}
			if (ans) fastIO :: strOutput("NO\n");
			else fastIO :: strOutput("YES\n");
		}
	}
	else
	{
		for (int i = 0; i < m; i++)
		{
			int u, v;
			u = fastIO :: intInput();
			v = fastIO :: intInput();
			edge[i] = {u - 1, v - 1};
		}
		for (int i = 0; i < q; i++)
		{
			qry[i].fst.fst = fastIO :: intInput();
			qry[i].fst.snd = fastIO :: intInput();
			qry[i].fst.fst--;
			qry[i].fst.snd--;
			qry[i].fst.snd = -qry[i].fst.snd;
			qry[i].snd = i;
		}
		sort(qry, qry + q);
		for (int j = 0; j < n; j++)
		{
			par[j] = {j, 0}; lz[j] = 0; sz[j] = 0; clr[j] = 0;
		}
		bool cur = 1; int pv = m - 1;
		for (int j = 0; j < qry[0].fst.fst; j++)
		{
			cur &= join(edge[j].fst, edge[j].snd);
		}
		for (int i = 0; i < q; i++)
		{
			qry[i].fst.snd = -qry[i].fst.snd;
			for (; pv > qry[i].fst.snd && cur; pv--)
			{
				cur &= join(edge[pv].fst, edge[pv].snd);
			}

			if (cur) {ans[qry[i].snd] = "NO";}
			else {ans[qry[i].snd] = "YES";}

			if (i + 1 < q && qry[i + 1].fst.fst != qry[i].fst.fst)
			{
				for (int j = 0; j < n; j++)
				{
					par[j] = {j, 0}; lz[j] = 0; sz[j] = 0; clr[j] = 0;
				}
				pv = m - 1; cur = 1;
				for (int j = 0; j < qry[i + 1].fst.fst && cur; j++)
				{
					cur &= join(edge[j].fst, edge[j].snd);
				}
			}
		}
		for (int i = 0; i < q; i++)
		{
			fastIO::strOutput(ans[i]);
			fastIO::charOutput('\n');
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define PB push_back
using namespace std;
const int N = 200100;
const int M = 200100;
const int cnst = 203;
vector<int> g[N], vc;
int n, m, q, lf, rt, mrk[N], U[M], V[M], par[N], pre[N], mem[cnst], cur_par;
bool bi, was;

void dfs(int v, int col){
    if (!bi) return;

    if (mrk[v]){
        if (mrk[v] != col){
            bi = 0;
        }
        return;
    }

    mrk[v] = col;

    for (int nm : g[v]) {
        if (nm >= lf && nm <= rt) continue;

        int u = (U[nm] == v ? V[nm] : U[nm]);

        dfs(u, 3 - col);
    }
}

int get(int x){
    if (x == pre[x]) return x;

    vc.PB(x);

    while (pre[x] != x){
        vc.PB(x);
        x = pre[x];
    }

    cur_par = 0;

    int par = vc.back();

    while (sz(vc) > 0){
        x = vc.back();
        vc.pop_back();

        cur_par ^= par[x];

        par[x] = cur_par;
    }

    return par;
}

void link(int x, int y){
    if (was) return;

    int xx = get(x), yy = get(y);

    if (xx != yy){
        pre[xx] = yy;
        par[xx] = (par[y] ^ 1 ^ par[x]);
    } else {
        if ((par[x] ^ par[y] ^ 1) == 1)
            was = 1;
    }
}

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

#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#endif // _LOCAL

    cin >> n >> m >> q;

    for (int i = 0; i < m; i++){
        int x, y; cin >> x >> y;
        x--; y--;

        U[i] = x;
        V[i] = y;

        g[x].PB(i);
        g[y].PB(i);
    }

    bi = 1; lf = rt = m;

    for (int i = 0; i < n && bi; i++){
        if (mrk[i]) continue;

        dfs(i, 1);
    }

    if (bi){
        for (; q; q--)
            cout << "NO\n";
        return 0;
    }

    for (int lf = 0; lf < cnst; lf++){
        for (int i = 0; i < n; i++){
            pre[i] = i;
            par[i] = 0;
        }

        was = 0;

        for (int id = 0; id < lf; id++)
            link(U[id], V[id]);

        int ptr = m - 1;

        while (!was){
            link(U[ptr], V[ptr]);
            ptr--;
        }

        mem[lf] = ptr;
    }

    for (int i = 0; i < q; i++){
        cin >> lf >> rt;
        lf--; rt--;

        if (lf < cnst){
            cout << (rt <= mem[lf] ? "YES\n" : "NO\n");
            continue;
        }

        fill(mrk, mrk + n, 0);
        bi = 1;

        for (int i = 0; i < n && bi; i++){
            if (mrk[i]) continue;

            dfs(i, 1);
        }

        cout << (bi ? "NO\n" : "YES\n");
    }

    return 0;
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define SET(p) memset(p, -1, sizeof(p))
#define CLR(p) memset(p, 0, sizeof(p))
#define MEM(p, v) memset(p, v, sizeof(p))
#define CPY(d, s) memcpy(d, s, sizeof(s))
#define ll long long
#define ld long double
#define mod 1000000007
#define inf 1LL<<60
#define pii pair< int, int >
#define pll pair< ll, ll >
#define psi pair< string, int >
#define N 100010
using namespace std;
set <pii> s;
unordered_set <int> m;
void solve(int x,int y){
	if(s.count(pii(x,y)))
		cout<<"BitAryo"<<endl;
	else
		cout<<"BitLGM"<<endl;
}
void init(){
	int x = 1;
	for(int i=1;i<=100000;i++){
		if(!m.count(i)){
			m.insert(i);
			m.insert(i+x);
			s.insert(pii(i,i+x));
			x++;
		}
	}
}
int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    int t;
    t = 1;
    init();
    while(t--){
        int n;
        cin>>n;
        int a[n];
        int mn = 1000000;
        for(int i=0;i<n;i++){
            cin>>a[i];
            mn = min(a[i],mn);
        }
        sort(a,a+n);
        if(n==1){
        	if(a[i])cout<<"BitLGM"<<endl;
        	else cout<<"BitAryo"<<endl;
        	continue;
        }
        if(n==2){
            solve(a[0],a[1]);
            continue;
        }
        int ans = 1;
        for(int i=0;i<n;i++){
            int res = 0;
            for(int j=0;j<n && a[i];j++){
                if(j!=i){
                    res^=a[j];
                }
            }
            if(res==0 && a[i]){
                ans = 0;
                break;
            }
        }
        if(ans==0){
            cout<<"BitLGM"<<endl;
            continue;
        }
        int res = 0;
        for(int i=0;i<n && mn;i++){
            res^=(a[i]-mn);
        }
        if(res==0 && mn){
            cout<<"BitLGM"<<endl;
            continue;
        }
        if(a[0]==a[n-1] && mn){
            cout<<"BitLGM"<<endl;
            continue;
        }
        res = 0;
        for(int i : a)
            res^=i;
        if(res)
            cout<<"BitLGM"<<endl;
        else
            cout<<"BitAryo"<<endl;
    }
    return 0;
}


/* Problem  : D. Yet Another Number Game
** Time     : 3000ms
** Algorithm: dp
**/
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define st first
#define nd second
#define read(x) scanf("%d",&x)
#define MAXN 1000005
typedef long long int64;
int a[MAXN], cnt[301];
int main (int argc, char const* argv[]){
    if ( argc == 3 ){
        freopen(argv[1],"r",stdin);
        freopen(argv[2],"w",stdout);
    }
    int n; read(n);
    int x = 0, mn = 301, nb = 0;
    for(int i = 0 ; i < n ; ++i){
        read(a[i]);
        x ^= a[i];
        mn = min(a[i],mn);
        if ( cnt[a[i]] == 0 ){
            ++nb;
        }
        ++cnt[a[i]];
    }
    if ( nb == 1 || x % 2 = 0 ){
        puts("BitLGM");
        return 0;
    }
    x = 0;
    for(int i = 0 ; i < n ; ++i){
        a[i] -= mn;
        x ^= a[i];
    }
    if ( x % 2 == 1 ){
        puts("BitLGM");
    }else{
        puts("BitAryo");
    }
    return 0;
}

/* DOAN Minh Quy - mquy.doan@gmail.com */


#include<iostream>
using namespace std;
int main()
{
	int n, t, k, d,t1,t2;
	double c;
	cin >> n >> t >> k >> d;
	c = (n / k);
	t1 = 0; t2 = d;
	for (int i = 0; i < c; i++)
	{
		if (t1 < t2){ t1 += t; }
		else { t2 += t; }
	}
	if (t2>=ceil(c*t)){ cout << "NO"; }
	else if (t2 < ceil(c*t)){ cout << "YES"; }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pp pair<int,int>
#define mp make_pair
#define pb push_back
#define S second
#define F first
const int MAX=1e5+7;
const int MOD=1e9+7;
double pi=M_PI;
int main()
{
	int n,i,t,k,d;
	bool f;
	scanf("%d %d %d %d",&n,&t,&k,&d);
	i=k*d/t;
	if(n<=i) f=false;
	else{
		i=n-i;
		if(i>k) f=true;
		else f=false;
	}
	if(f) printf("YES\n");
	else printf("NO\n");
	return 0;
}


#include <iostream>
#include <deque>
#include <algorithm>
#define ll long long
using namespace std;

int main()
{
    int n, t, k, d;
    cin >> n >> t >> k >> d;
    double _each = n / k;
    int all = ((int)round(_each)) * t;
    int _new = (t + d);
    string res = (all > _new) ? "YES" : "NO";
    cout << res;

    return 0;
}


#include<iostream>
using namespace std;
int a,b,c,d,x,y,z,i,n,j,t,k;
main(){
	cin>>n>>t>>k>>d;
	if(n/k%==0)
	x=n/k*t;

	if(k>n && d>k || k<n &&  d>t || k>n && d<t ) cout<<"NO";
	if(x>t+d) cout<<"YES"; else cout<<"NO";
}


#include<iostream>
using namespace std;
int a,b,c,n,x;
int main()
{
           cin>>n>>a>>b>>c;
           n=n-1;
           x=1;
           while(n--)
           {
                      if(x==1) { if(b>c) { x=3; ans=ans+c } else { x=2; ans=ans+b } }
                      if(x==2) { if(a>c) { x=3; ans=ans+c } else { x=1; ans=ans+a } }
                      if(x==3) { if(b>a) { x=1; ans=ans+a } else { x=2; ans=ans+b } }
           }
           cout<<ans;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int a,b,c,n;
    while(cin >> n>> a >> b >> c){
        if(n==1)
            cout << 0 << endl;
        else{
            cout << (n-2)*(min(a,min(b,c)))+min(a,b) << endl;
        }

    }
}


#include<algorithm>
using namespace std;
int n,a,b,c,m=1,k=1,ans;
int main(){
    cin>>n>>a>>b>>c;

    while(k++<n){
        if(m==1)if(a<=b)ans+=a,m=3;else ans+=b,m=2;
        else if(m==2)if(c<=b)ans+=c,m=3;else ans+=b,m=1;
        else if(m==3)if(a<=c)ans+=a,m=1;else ans+=c,m=2;
    }
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>

#define PI acos(-1.0)

#define rep1(i,n) for(i=1;i<=n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep_ab(i,a,b) for(i=a;i<=b;i++)

#define pb(x) push_back(x)
#define sz(x) x.size()
#define mp(x,y) make_pair(x,y)

#define mem(ara,val) memset(ara,val,sizeof(ara))
#define eps 1e-9

#define ll long long
#define ull unsigned long long

#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define siii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld %lld",&x,&y)
#define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define ss(ch) scanf("%s",ch)
#define pi(x) printf("%d\n",x)
#define pii(x,y) printf("%d %d\n",x,y)
#define piii(x,y,z) printf("%d %d %d\n",x,y,z)
#define pl(x) printf("%lld\n",x)
#define pll(x,y) printf("%lld %lld\n",x,y)
#define plll(x,y,z) printf("%lld %lld %lld\n",x,y,z)
#define ps(ch) printf("%s",ch)
#define nl printf("\n")
#define spc printf(" ")
#define Max 200005
#define INF (LL)1e15
#define mod 4294967295
#define FI freopen("in.txt","r",stdin)
#define FO freopen("out.txt","w",stdout)
#define FA freopen("A.txt","r",stdin)
#define FB freopen("B.txt","r",stdin)
#define FC freopen("C.txt","r",stdin)
#define FD freopen("D.txt","r",stdin)
#define isValid(nx,ny)nx>=0&&nx<8&&ny>=0&&ny<8
#define triangle_area(a,b,m,n,x,y) (a*(n-y)+m*(y-b)+x*(b-n))
#define dis_without_sqrt(x,y,x1,y1) (x-x1)*(x-x1)+(y-y1)*(y-y1)
//int ax[]={1, 1, -1, -1, 2, 2, -2, -2}; //knight moves
//int ay[]={2,-2,  2, -2, 1,-1,  1, -1}; //knight moves
using namespace std;

//int setb(int n,int pos){return n=n | (1 << pos);}
//int resb(int n,int pos){return n=n & ~(1 << pos);}
//bool checkb(int n,int pos){return (bool)(n & (1 << pos)); }

int n,a,b,c,mn;
int dpt[5];
int dp(int i,int total,int stage)
{
    if(i==n)
    {
        mn=min(total,mn);
        return;
    }
    if(stage==0)
    {
        if(dpt[stage]!=-1)return dpt[stage];
        dpt[stage]=min(dp(i+1,total+a,1),dp(i+1,total+b,2));
    }
    if(stage==1)dp(i+1,total+a,0),dp(i+1,total+c,2);
    if(stage==2)dp(i+1,total+b,0),dp(i+1,total+c,1);
}

int main()
{
	//FI;
	//ios_base::sync_with_stdio(false); cin.tie(NULL);
    while(si(n)!=EOF)
    {
        siii(a,b,c);
        mn=123456789;
        dpt[0]=-1,dpt[1]=-1,dpt[2]=-1;
        dp(1,0,0);
        pi(mn);
    }
	return 0;
}


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Express 2012 for Windows Desktop
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Project8", "Project8\Project8.vcxproj", "{BD51574D-751E-4CCB-A80E-8018D1F51FB8}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Win32 = Debug|Win32
		Release|Win32 = Release|Win32
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{BD51574D-751E-4CCB-A80E-8018D1F51FB8}.Debug|Win32.ActiveCfg = Debug|Win32
		{BD51574D-751E-4CCB-A80E-8018D1F51FB8}.Debug|Win32.Build.0 = Debug|Win32
		{BD51574D-751E-4CCB-A80E-8018D1F51FB8}.Release|Win32.ActiveCfg = Release|Win32
		{BD51574D-751E-4CCB-A80E-8018D1F51FB8}.Release|Win32.Build.0 = Release|Win32
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
EndGlobal


#include<iostream>
using namespace std;
int main()
{
	int m,d,i;
	cin>>m>>d;
	if(m==2&&d==1)
	cout<<"4";
	else if(m==2)
	cout<<"5";
	else if(m==1||m==3||m==5||m==7||m==8||m==10||m==12)
	{
		if(d>5)
		cout<<"6";
		else
		cout<<"5";
	}
	else
	{
		if(d==7)
		cout<<"6";
		else
		cout<<"5";
	}
	return 0;
}
close


//****************************Bismillahir Rahmanir Rahim***************************??

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define PB push_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

/*bool seive[1010000];
vi prime;

void seiveGen(int limit) {
    limit += 100;
    int sqrtn = sqrt(limit);
    for(int i = 3; i <= sqrtn; i += 2) {
            if(!seive[i>>1]) {
                    for(int j = i * i; j < limit; j += i + i) {
                            seive[j>>1] = 1;
                    }
            }
    }
    prime.PB(2);
    for(int i = 3; i < limit; i += 2) {
            if(!seive[i>>1]) prime.PB(i);
    }
}*/

/*
*******************************USE of STL***************************
v.erase(unique(v.begin(),v.end()),v.end());
    int a[]={..........};
    sort(a,a+n,greater<int>()); ///sort in descending order
    int z=sizeof(a)/sizeof(a[0]); ///size of array
    string s,x;
    transform(s.begin(),s.end(),s.begin(),::tolower);///change of uppercase to lowercase of any string
    int i;
    i=s.compare(x); ///compare two string like strcmp
    int n,m;
    i=log10(n)+1; ///how many digits in integer n
    i=abs(n-m); ///take absolute value
     copy(v.begin(),v.end(),back_inserter(q)); ///copying v vector to q
     s.find("AB"); ///search index Number of AB(substring) in string s
     remove(a,a+n,3); ///delete 3rd element from array
     ceil(2.3) /// Returns the smallest integer that is greater than or equal to x (i.e : rounds up the nearest integer) দশমিক যদি <=.৫ হয় তাহলে একযোগ করে প্রিন্ট করবে
     round(2.3)///return round value...like 2.3=2,,,2.5=3,,2.6=3;

     {
         ///int to string transfer///
         ostringstream temp; ///need a temp;
         int x;
         temp<<x;
         string s;
         s=temp.str(x); ///transfer
     }
     count(s.begin(), s.end(), 'a')///Count the number of occurrences of 'a' in a string s
*/

//
//debug
#ifdef ahasun
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif
//****************Source Code starting From here**************//

int main()
{
	ll a,b,c=-1,n;
	cin>>n;
	if(n<=2)
	{
	    cout<<n<<endl;
	    return 0;
	}
	else if(n==3)
        cout<<6<endl;
	else if(n%2!=0)
    {
        cout<<n*(n-1)*(n-2)<<endl;
    }
    else
    {
        if(n%3==0)
        cout<<(n-1)*(n-2)*(n-3);
        else
        cout<<(n)*(n-1)*(n-3);

    }
}


#include <iostream>
using namespace std;
int mian(){
int n;
cin>>n;
if(n%2==0){
cout<<n*(n-1)*(n-3)<<endl;
} else {
cout<<n*(n-1)*(n-2)<<endl;
}
}


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

    typedef long long ll;

    int const N=1e5+5, M=1e9, OO=0x3f3f3f3f, MOD=1e9+7;

    ll n,ans;

    ll lcm(ll a, ll b)
    {
        return a/__gcd(a,b)*b;
    }

    int main()
    {
    //    freopen("input.txt","rt",stdin);
    //    freopen("output.txt","wt",stdout);
        scanf("%I64d",&n);
        if(n<=2)
            printf("%d\n",n);
        else
        {
            if(n&1)
                printf("%I64d\n",lcm(lcm(n,n-1),n-2));
            else
            {
                for(int i=max(1ll,n-50); i<=n; i++)
                    for(int j=max(1ll,n-50); j<=n; j++)
                        for(int k=max(1ll,n-50); k<=n; k++)
                            ans=max(ans,lcm(lcm(i,j),k));
                printf("%I64d\n",ans);
            }
        }

        return 0;
    }


#include <bits/stdc++.h>

#define forr(i, n) for(ll i = n-1; i >= 0; i--)
#define forn(i, n) for(ll i = 0; i < n; i++)
#define forab(i, a, n) for(ll i = a; i < n; i++)
#define forabr(i, a, b) for(ll i = a; i >= b; i--)
#define endl '\n'
#define s seconde
#define f first
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fale_io  ifstream fin("input.txt"); ofstream fout("output.txt");
using namespace std;

const int Inf = INT_MAX;
const double PI = 3.1415926535;

typedef long long ll;
typedef string S;

int n;
ll mx;
/*
int gcd (int a, int b) {
	while (b) {
		a %= b;
		swap (a, b);
	}
	return a;
}

ll lcm(int a, int b, int c){
    int g = gcd(a, b);
    g = gcd(g, c);
    return (ll)a * b * c / g;
}
*/

ll f(int n){
    ll r = n;
    r *= n - 1;
    if(n % 2)
        r *= n - 2;
    else
        r *= n - 3;
    return r;
}

int main(){
    fast_io;
    cin >> n
    mx = n;
    if(n == 3)mx = 6;
    forab(i, max(3, n-5), n+1)mx = max(mx, f(i));
    cout << mx;
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#define maxn 100
#define maxm maxn
using namespace std;
int hash[maxm],req[maxm];
int N,M;

int main()
{
	scanf("%d%d",&N,&M);

	int saber;
	for (int i=1;i<=N;i++)
	{
		scanf("%d",&saber);
		hash[saber]++;
	}
	for (int i=1;i<=M;i++)
	{
		scanf("%d",&req[i]);
		if (req[i]>hash[i])
		{
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
}


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

int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);

    int n , m ;
    cin >> n >> m;
    int arr[n+1] = {};

    for(int i = 0 ;i < n ; i++)
    {
        cin >> arr[i];

    }

    int c[n+1] = {};
    for(int i = 0 ; i < n ; i++)
    {
        int cc = 1;
        for(int j = i+1 ; j < n ;j++)
        {
            if(arr[i] == arr[j])
                cc++;#include<bits/stdc++.h>
using namespace std;

int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);

    int n , m ;
    cin >> n >> m;
    int arr[n+1] = {};

    for(int i = 0 ;i < n ; i++)
    {
        int x;
        cin >> x;
        arr[x]++;
    }

    for(int i = 1 ; i <= m ; i++)
    {
        int x;
        cin >> x;

        if(arr[i] != x)
            return cout << "NO" , 0;
    }

    cout << "YES";

    return 0;
}


#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;

using namespace std;

typedef long long ll;
typedef pair<int,int> PII;

template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int n, m;
int a[MAXN];
int k[MAXN];
int l[MAXN];
int sum;
int f;
int main()
{
    //~ freopen("file.in", "r", stdin);
    scanf("%d %d", &n, &m);
    for(int i = 1; i <= n; i ++)
    	scanf("%d", a + i);
    for(int i = 1; i <= m; i ++)
    	scanf("%d", k + i);
    for(int left = 1; left <= n; left ++){
    	for(int right = left; right <= n; right ++){
    		memset(l, 0, sizeof l);
    		for(int i = left; i <= right; i ++)
    			l[a[i]] ++;
    		bool ok = 1;
			for(int i = 1; i <= m && ok; i ++)-
				if(k[i] > l[i])
					ok = 0;
			if(ok)
				return puts("YES") * 0;
		}
	}
	puts("NO");
}


#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define forn(i, s, n)  for(int i=(int)s; i<int(n); i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define pll pair<int, int>
#define pii pair<ll, ll>
#define ull unsigned long long int
#define F first
#define S second
#define PI 3.141592653589793238
#define prec(n) fixed<<setprecision(n)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define itsval(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); itval(_it, args); }
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

void itval(istream_iterator<string> it) {}
template<typename T, typename... Args>
void itval(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
itval(++it, args...);
}
const ll MOD=1e9+7;
template <typename T>
inline void print(T x){cout<<x<<"\n";}
template <typename T>
inline void printvec(T x){for(auto a:x) cout<<a<<' '; cout<<'\n';}
// -----------------------------------------------------------------------

struct custom{
    bool operator()(const pair<pll, int> &p1, const pair<pll, int> &p2)const{
            if(p1.F.F==p2.F.F)
            {
                if(p1.F.S==p2.F.S)
                {
                    return p1.S<p2.S;
                }
                return p1.F.S>p2.F.S;
            }
            return p1.F.F<p2.F.F;
        }
};

// Calculate x^k % MOD -------------------------------------------------
ll get_pow(ll x, ll k)
{
    if(k==0) return 1ll;
    ll y = get_pow(x, k/2);
    y = (y*y)%MOD;
    if(k%2) y = (y*x)%MOD;
    return y;
}

// ---------------------------------------------------------------------
const int N = 1e2+10;

void solve()
{
    int n,m, cnt=0;
    cin>>n>>m;
    vi v(n), c(m), check;
    for (int i = 0; i < n; ++i)
    {
        cin>>v[i];
    }
    forn(i,0,m){
    cin>>c[i];
    forn(j,0,c[i])
    check.pb(i+1);
    }
    forn(i,0,n-int(check.size())+1#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define forn(i, s, n)  for(int i=(int)s; i<int(n); i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define pll pair<int, int>
#define pii pair<ll, ll>
#define ull unsigned long long int
#define F first
#define S second
#define PI 3.141592653589793238
#define prec(n) fixed<<setprecision(n)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define itsval(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); itval(_it, args); }
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

void itval(istream_iterator<string> it) {}
template<typename T, typename... Args>
void itval(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
itval(++it, args...);
}
const ll MOD=1e9+7;
template <typename T>
inline void print(T x){cout<<x<<"\n";}
template <typename T>
inline void printvec(T x){for(auto a:x) cout<<a<<' '; cout<<'\n';}
// -----------------------------------------------------------------------

struct custom{
    bool operator()(const pair<pll, int> &p1, const pair<pll, int> &p2)const{
            if(p1.F.F==p2.F.F)
            {
                if(p1.F.S==p2.F.S)
                {
                    return p1.S<p2.S;
                }
                return p1.F.S>p2.F.S;
            }
            return p1.F.F<p2.F.F;
        }
};

// Calculate x^k % MOD -------------------------------------------------
ll get_pow(ll x, ll k)
{
    if(k==0) return 1ll;
    ll y = get_pow(x, k/2);
    y = (y*y)%MOD;
    if(k%2) y = (y*x)%MOD;
    return y;
}

// ---------------------------------------------------------------------
const int N = 1e2+10;

void solve()
{
    int n,m, cnt=0;
    cin>>n>>m;
    vi v(n), c(m), check;
    for (int i = 0; i < n; ++i)
    {
        cin>>v[i];
    }
    forn(i,0,m){
    cin>>c[i];
    forn(j,0,c[i])
    check.pb(i+1);
    }
    forn(i,0,n-int(check.size())+1)
    {
        int g=1;
        forn(j,i,i+int(check.size()))
        {
            if(v[j]!=check[j-i])
            {
                g=0;
                break;
            }
        }
        if(g)
        {
            print("YES");return;
        }
    }
    print("NO");

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test=1;
   // cin>>test;
    clock_t z=clock();
    forn(tes, 0, test)
    {
        solve();
    }
    debug("Total Time:%.4f\n",(double)(clock()-z)/CLOCKS_PER_SEC);
    return 0;
}

    {
        int g=1;
        forn(j,i,i+int(check.size()))
        {
            if(v[j]!=check[j-i])
            {
                g=0;
                break;
            }
        }
        if(g)
        {
            print("YES");return;
        }
    }
    print("NO");

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test=1;
   // cin>>test;
    clock_t z=clock();
    forn(tes, 0, test)
    {
        solve();
    }
    debug("Total Time:%.4f\n",(double)(clock()-z)/CLOCKS_PER_SEC);
    return 0;
}


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

int main() {
	long long n,k,A,B,a=0,b=0;
	cin>>n;
	cin>>k;
	cin>>A;
	cin>>B;
	int x=n;
	while(x!=1)
	{
	  if (A<B*(x-x/k)) && x%k=0)
	 {
	 	x/=k;a++;
	 }
	 else
	 {
	 	x--;b++;
	 }
	}
	cout<<a*A+b*B;
	return 0;
}


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

int main()
{
    long long long int n,k,a,b;
    cin>>n>>k>>a>>b;
    long long long int ans=0;

    if(k==1)
    {
        ans=min(a,b) * (n-1);
    }
    else
    while(n>1)
    {
        if(k<=n)
        {

            long long long int r=n%k;
    ans+=r*a;

long long long ans1=0,ans2=0;
    ans1=b;
    ans2=a*(n-n/k);
    n=n/k;
    ans+=min(ans1,ans2);
        }
        else{
            ans+=(n-1)*a;
            n=1;
        }

    }
    cout<<ans;

    return 0;
}


#include <iostream>
using namespace std;
long long n,k,A,B;
long long maxx,sum=0;
long long div,sub;
int main()
{
	cin>>n>>k>>A>>B;
	if(n<k||k==1)
	{
		maxx=(n-1)*A;
		cout<<maxx<<endl;
		return 0;
	}
	while(n!=1)
	{
		if(n<k)
		{
			sum+=(n-1)*A;
			cout<<sum<<endl;
			return 0;
		}
		else
		{
			if(n%k==0)
			{
				div=n/k;
				sub=(n-div)*A;
				if(sub>B) sum+=B;
				else sum+=sub;
				n/=k;
			}
			else
			{
				div=n%k;
				sum+=div*A;
				n-=div;
			}
		}
	}
	cout<<sum<<endl;

	return 0;
}


#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
#include <bitset>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;

void solve(){
	int n, k, a, b;
	cin >> n >> k >> a >> b;
	int dp[n+1];
	memset(dp, 0, n);
	dp[n] = 0;
	for (int i = n-1; i >= 1; i--){
		dp[i] = dp[i+1]+a;
		if (i * k < n) dp[i] = min(dp[i], dp[i*k]+b);
	}
	cout << dp[1] << endl;
}

int main(){
    int t = 1;
	while (t--){
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;
const ll mod  = 998244353;
ll res[2001][2001];

int main()
{
    ll n,m,k;
    cin>>n>>m>>k;
    res[1][0] = m;
    for(ll i=2;i<=n;i++)
        for(ll j=0;j<=k;j++)
            (res[i][j] += res[i-1][j]) %= mod,
            (res[i][j+1] += (res[i-1][j] * (m-1) )) %=mod;
    cout<<res[n][k]<<endl;
}


#include<bits/stdc++.h>
using namespace std;
long long f[2005][2005];
int n,m,k;
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	f[1][0]=m;
	for(int i=1;i<=n;i++)
	{
		f[i][0]=m;
		for(int j=1;j<min(k+1,i);j++)
			f[i][j]=(f[i-1][j]+f[i-1][j-1]*(m-1))%mod;
	}

	cout<<f[n][k];

	return 0;
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdio>
// Kobe is the GOAT
// DON'T DIVIDE
// Greedy, Prefix, Sets/Bsearch, Dfs/bfs, DP
// Stack, Bitmask, Dsu
using namespace std;

int n, m, k;
const int MAXN = 2005, MOD = 998244353;

long long pow(long long a, long long b)
{
	if(b == 0)
		return 1;
	if(b % 2 == 0)
		return pow((a * a) % MOD, b / 2);
	return (a * pow((a * a) % MOD, b / 2)) % MOD;
}

long long inv(long long x)
{
	return pow(x, MOD - 2);
}

long long fact(long long x)
{
	if(x == 0)
		return 1;
	return (x * fact(x - 1)) % MOD;
}

int main()
{
	ios::sync_with_stdio(0);
	cin >> n >> m >> k;

	long long ans = (fact(n - 1) * inv((fact(k) * fact(n - 1 - k)) % MOD)) % MOD;
	ans = (ans * m) % MOD;
	ans = (ans * pow(m - 1, max(k - 1, 0))) % MOD;

	cout << ans << "\n";
	return 0;
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdio>
// Kobe is the GOAT
// DON'T DIVIDE
// Greedy, Prefix, Sets/Bsearch, Dfs/bfs, DP
// Stack, Bitmask, Dsu
using namespace std;

int n, m, k;
const int MAXN = 2005, MOD = 998244353;

long long pow(long long a, long long b)
{
	if(b == 0)
		return 1;
	if(b % 2 == 0)
		return pow((a * a) % MOD, b / 2);
	return (a * pow((a * a) % MOD, b / 2)) % MOD;
}

long long inv(long long x)
{
	return pow(x, MOD - 2);
}

long long fact(long long x)
{
	if(x == 0)
		return 1;
	return (x * fact(x - 1)) % MOD;
}

int main()
{
	ios::sync_with_stdio(0);
	cin >> n >> m >> k;

	long long ans = (fact(n - 1) * inv((fact(k) * fact(n - 1 - k)) % MOD)) % MOD;
	ans = (ans * m) % MOD;
	ans = (ans * pow(m - 1, k)) % MOD;

	cout << ans << "\n";
	return 0;
}


#include <iostream>
using namespace std;
long long double n;
long long double f(int n)
{ if (n==1)
return 1;
else return f(n-1)*n;
}
int main()
{

cin >> n;
if (n==1)
cout << 1;
else
cout << f(n)+1;

}


#include <iostrean>

using namespace std;

int main(void){
    int n;
    long long result = 1;
    cin >> n;
    for (int i = 0; i < n; i++){
        result += (n - i) * (i + 1) - 1
    }
    cout << n;
    return 0;
}


#include <iosream>
using namespace std;
int main()
{
  int n,k=0;
  cin>>n;
  for(int i=1;i<n;i++)
  k+=(n*i)-(i*i);
  k+=n;
  cout<<k
}


#include <iostream>
#include <cmath>
using namespace std;
void main()
{
	int n;
	cin >> n;
	int p = pow(2, n);
	cout << p-1;

}


/* Borrowed from I_love_hoang_jen because of lack in task description o_O
 * I love U too <3
 * */
#include<bits/stdc++.h>
#define MAX   200200
#define FOR(i,a,b) for (int i=(a);i<=(b);i=i+1)
#define FORD(i,b,a) for (int i=(b);i>=(a);i=i-1)
#define REP(i,n) for (int i=0;i<(n);i=i+1)
#define bit(x,i) ((x)&(1<<(i)))
using namespace std;
typedef long long ll;
const int INF=(int)1e9+7;
int prime[MAX];
int fls(ll x) {
    ll k=floor(sqrt(x));
    FOR(i,max(0LL,k-5),k+5) if (1LL*i*i>x) return (i-1);
}
int ces(ll x) {
    if (x<0) return (0);
    ll k=ceil(sqrt(x));
    FORD(i,k+5,max(0LL,k-5)) if (1LL*i*i<x) return (i+1);
}
int m,n,L,R,mod;
void eratosthene(void) {
    REP(i,2) prime[i]=-1;
    FOR(i,2,MAX-1) if (prime[i]==0)
        for (int j=2*i;j<MAX;j=j+i) prime[j]=i;
}
void anal(int x,vector<int> &v) {
    assert(0<x && x<MAX);
    v.clear();
    while (x>1) {
        if (prime[x]==0) {
            v.push_back(x);
            return;
        }
        int p=prime[x];
        assert(x%p==0);
        v.push_back(p);
        while (x%p==0) x=x/p;
    }
}
int countdiv(int x,int r) {
    if (r<x) return (0);
    int k=r/x;
    int tmp=(1LL*k*(n+1)-1LL*x*k*(k+1)/2)%mod;
    return ((tmp+mod)%mod);
}
int coprime(int x,int r) {
    if (r<=0) return (0);
    vector<int> div;
    anal(x,div);
    int res=0;
    REP(i,1<<div.size()) {
        int nb=0;
        int pro=1;
        REP(j,div.size()) if (bit(i,j)) {
            nb++;
            pro*=div[j];
        }
        if (nb%2==0) res=(res+countdiv(pro,r))%mod;
        else res=(res-countdiv(pro,r)+mod)%mod;
    }
    return (res);
}
int coprime(int x,int l,int r) {
    if (l>r) return (0);
    return ((coprime(x,r)-coprime(x,l-1)+mod)%mod);
}
void process(void) {
    cin >> m >> n >> L >> R >> mod;
    int res=(L==1)?((1LL*(m+1)*n+1LL*(n+1)*m)%mod):0;
    //printf("PRE %d\n",res);
    FOR(i,1,m) if (i<=R) {
        int l=max(1,ces(1LL*L*L-1LL*i*i));
        int r=min(n,fls(1LL*R*R-1LL*i*i));
        //printf("LIM %d %d\n",l,r);
        res=(res+2LL*(m-i+1)*coprime(i,l,r)%mod)%mod;
    }
    cout << res;
}
int main(void) {
#ifndef ONLINE_JUDGE
    freopen("tmp.txt","r",stdin);
#endif
    eratosthene();
    process();
    return 0;
}
}


//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
//これは、頭が悪く競プロが世界で一番できないHIR180が
//IOI2014日本代表になるまでのN日間の記録である。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
vector<int>div[150005];
ll n,m,l,r,mod;
ll calc(ll lb,ll ub,ll mul)
{
	ub=ub/mul; lb=(lb+mul-1)/mul;
	ll sum=(ub-lb+1LL)*(m+1);
	sum-=(ub*(ub+1)-(lb-1)*lb)/2*mul;
	sum=(sum%mod+mod)%mod;
	return sum;
}
int main()
{
	srand((unsigned int)time(NULL));
	scanf("%lld %lld %lld %lld %lld",&n,&m,&l,&r,&mod);
	ll lb=l,ub=r;
	for(int i=2;i<=150000;i++)
	{
		if(!div[i].empty()) continue;
		for(int j=i;j<=150000;j+=i)
		{
			div[j].pb(i);
		}
	}
	ll ret=0LL;
	for(ll i=1;i<=min(n,h);i++)
	{
		while(lb>1 && l*l-i*i<=(lb-1)*(lb-1)) lb--;
		while(r*r-w*w<ub*ub) ub--;
		if(lb<=ub && lb<=m)
		{
			ll res=0;
			int mask=(1<<(div[i].size()));
			for(int j=0;j<mask;j++)
			{
				ll mul=1;
				int flag=1;
				for(int k=0;k<div[i].size();k++)
				{
					if(((j>>k)&1))
					{
						mul*=div[i][k];
						flag*=(-1);
					}
				}
				res+=flag*calc(lb,min(ub,m),mul);
			}
			ret=(ret+res*(n-i+1))%mod;
		}
	}
	if(l<=1&&1<=r) ans=(ans*2LL+n*(m+1)+m*(n+1))%mod;
	else ans=(ans*2LL)%mod;
	cout << ans << endl;
}


#include <cstdio>
#define ll (long long)
int fac[100100];
int n,m,i,x,j,l,r,p,ans,st,dr,mn,mx,M;

void init()
{
    int i,j;
    for (i=2;i<=100000;i++)
        if (!fac[i])
    {
        fac[i]=i;
        if (i>316) continue;
        for (j=i*i;j<=100000;j+=i) if (!fac[j]) fac[j]=i;
    }
}

int solve(int x,int y)
{
    int v[20]; int N;
    int i,j,lim,ind,nr,rez=0;

    if (y==0) return 0;

    v[0]=0; N=0;
    for (i=x;i>1;i/=fac[i])
        if (N==0 || v[N-1]!=fac[i]) v[N++]=fac[i];

    lim=1<<N;

    for (i=0;i<lim;i++)
    {
        ind=0; nr=1;
        for (j=0;j<N;j++)
            if ( i & (1<<j))
            {
                ind++;
                nr=nr*v[j];
            }
        int ax=y/nr;
        if (ind%2==1)
            rez= ll( ll(ll rez -ll (M+1)*ax+ ll nr*ax*(ll ax+1)/2 )%p ll +p)%p;
        else
            rez= ll( ll(ll rez +ll (M+1)*ax- ll nr*ax*(ll ax+1)/2)%p ll +p) %p;

    }

    rez=ll (ll rez*(ll n-x+1) )%p;
        return ( (int) rez);

}

int main()
{

    scanf("%d%d%d%d%d",&n,&M,&l,&r,&p);
    init();

    for (x=1;x<=n;x++)
    {
        //minim
        for (st=0,dr=100000;st<dr;)
        {
            m=(st+dr)/2;
            if ( ll x*x+ll m*m>= ll l*l)
                dr=m;
            else
                st=m+1;
        }
        mn=st;
        //maxim
        for (st=0,dr=100000;st<dr;)
        {
            m=(st+dr)/2+1;
            if (ll x*x+ll m*m<=ll r*r)
                st=m;
            else
                dr=m-1;
        }
        if (mn<1) mn=1;
        mx=st;
        if (mx>M) mx=M;
        if (mn>mx) continue;

        ans=ll (ll ans+ solve(x,mx)-solve(x,mn-1) )%p;
    }

    ans=ll ans*2%p;
    if (l<=1) ans=ll (ll ans+ n*(ll M+1)+(ll n+1)*M )%p;

    printf("%d",ans);

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#pragma comment (linker,"/STACK:102400000,102400000")
#define maxn 205
#define MAXN 1005
#define mod 1000000009
#define INF 0x3f3f3f3f
#define pi acos(-1.0)
#define eps 1e-6
typedef long long ll;
using namespace std;

ll n,m,k,ans,cnt,tot,flag;
ll cost[4][4],dp[45][4][4];

ll dfs(ll x,ll a,ll c)
{
    if(x==0) return 0;
    if(dp[x][a][c]!=m) return dp[x][a][c];
    ll i,j,t,b,best=m;
    b=6-a-c;
    t=dfs(x-1,a,b)+cost[a][c]+dfs(x-1,b,c);
    best=min(best,t);
    t=2*dfs(x-1,a,c)+cost[a][b]+dfs(x-1,c,a)+cost[b][c];
    best=min(best,t);
    dp[x][a][c]=best;
    return best;
}
int main()
{
    ll i,j,t;
    m=1LL<<60;
        for(i=1;i<=3;i++)
        {
            for(j=1;j<=3;j++)
            {
                scanf("%I64d",&cost[i][j]);
            }
        }
        scanf("%I64d",&n);
        for(i=1;i<=n;i++) for(j=1;j<=3;j++) for(int k=1;k<=3;k++) dp[i][j][k]=m;
        ans=dfs(n,1,3);
        printf("%I64d\n",ans);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#pragma comment (linker,"/STACK:102400000,102400000")
#define maxn 205
#define MAXN 1005
#define mod 1000000009
#define INF 0x3f3f3f3f
#define pi acos(-1.0)
#define eps 1e-6
typedef long long ll;
using namespace std;

ll n,m,k,ans,cnt,tot,flag;
ll cost[4][4],dp[45][4][4];

ll dfs(ll x,ll a,ll c)
{
    if(x==0) return 0;
    if(dp[x][a][c]!=m) return dp[x][a][c];
    ll i,j,t,b,best=m;
    b=6-a-c;
    t=dfs(x-1,a,b)+cost[a][c]+dfs(x-1,b,c);
    best=min(best,t);
    t=2*dfs(x-1,a,c)+cost[a][b]+dfs(x-1,c,a)+cost[b][c];
    best=min(best,t);
    dp[x][a][c]=best;
    return best;
}
int main()
{
    ll i,j,t;
    m=1LL<<60;
        for(i=1;i<=3;i++)
        {
            for(j=1;j<=3;j++)
            {
                scanf("%I64d",&cost[i][j]);
            }
        }
        scanf("%I64d",&n);
        for(i=1;i<=n;i++) for(j=1;j<=3;j++) for(int k=1;k<=3;k++) dp[i][j][k]=m;
        ans=dfs(n,1,3);
        printf("%I64d\n",ans);
    return 0;
}
</queue></set></vector></stack></map></string></cmath></algorithm></cstring></cstdio></iostream>


#include <iostream>
#include <math.h>

using namespace std ;

#define abs(a) (a)>0?(a):-(a)
#define USING_MATH_DEFINES
#define mp make_pair
#define FI first
#define SE second
#define FOR0(i,n) for(i=0;i<n;++i)
#define FOR1(i,n) for(i=1;i<=n;++i)

int v[50][4][4][4], d[50][4][4][4], t[4][4] ;

int han( int n, int a, int b, int c )
{
    if( v[n][a][b][c] ) return d[n][a][b][c] ;
    v[n][a][b][c] = 1 ;

    if( n == 0 ) return d[n][a][b][c] = 0 ;

    int r1, r2 ;
    r1 = han( n-1, a, c, b ) + t[a][b] + han( n-1, c, b, a ) ;
    r2 = han( n-1, a, b, c ) + t[a][c] + han( n-1, b, a, c ) + t[c][b] + han( n-1, a, b, c ) ;

    return d[n][a][b][c] = min( r1, r2 ) ;
}

main()
{
      int x, i, j ;
      FOR1(i,3)FOR1(j,3)scanf("%d",&t[i][j]);
      scanf("%d",&x) ;
      cout << han(x,1,3,2) ;
}


#include<stdio.h>
#include<string.h>
int cost[4][4]
__int64 dp[45][4][4][4];
__int64 hanoi(int n,int a,int b,int c)
{
    if(dp[n][a][b][c]!=-1)return dp[n][a][b][c];
    __int64 tmp1,tmp2;
    tmp1=hanoi(n-1,a,c,b)+cost[a][c]+hanoi(n-1,b,a,c);
    tmp2=hanoi(n-1,a,b,c)+cost[a][b]+hanoi(n-1,c,b,a)+cost[b][c]+hanoi(n-1,a,b,c);
    return dp[n][a][b][c]=tmp1>tmp2?tmp2:tmp1;
}
int main()
{
    int i,j,n;
    memset(dp,-1,sizeof(dp));
    memset(dp[0],0,sizeof(dp[0]));
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            scanf("%d",&cost[i][j]);
        }
    }
    scanf("%d",&n);
    printf("%I64d\n",hanoi(n,0,1,2));
    return 0;
}


#include<fstream>
#include<iostream>
#include<vector>
#include<string>
#include<cmath>

#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;

int main(){
 //freopen("in.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  //scanf("%ld%ld",&a,&b);
  //ifstream cin("in.txt");
string s;
int n, k, f[26], l[26];
vector<pii> mm;

cin>>n>>k;
cin>>s;

for(int i = 0; i < 26; i++) f[i] = -1;
for(int i = 0; i < 26; i++) l[i] = 1000000;
for(int i = 0; i < s.length(); i++) {
    if(f[s[i] - 'A'] == -1) f[s[i] - 'A'] = i;
    l[s[i] - 'A'] = i;
    }

for(int i = 0; i < 26; i++) if(f[i] > -1){//cout<<f[i]<<endl;
    mm.pb(mp(f[i], 0));
    mm.pb(mp(l[i], 1));
}

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

int oj = 0, ma = 0;;

for(int i = 0; i < mm.size(); i++)
{
    if(mm[i].y == 0) {oj++;
    ma = max(ma, oj);}else oj--;}
if(ma > k) cout<<"YES"; else cout<<"NO";
 //cout<<mm[i].x<<' '<<mm[i].y<<endl;
    }


#include <iostream>
#include <string>
#include <string.h>
#include <cstring>
using namespace std;
pair <int, int > time[30];
int characters[30];
int main(){
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	bool done = true;
	bool entered = false;
	bool enteredhere = false;
	bool enteredhere1 = false;
	bool enteredhere2 = false;
	bool enter = false;
	int counter = k;
	memset(time, -1, sizeof(time));
	memset(characters, -1, sizeof(characters));
	for (int i = 0; i < s.length(); i++){
		if (time[s[i] - 65].first == -1){
			time[s[i] - 65].first = i;
		}
		time[s[i] - 65].second = i;
	}
	for (int i = 0; i < s.length(); i++){
		entered = false;
		enteredhere = false;
		 enteredhere1 = false;
		enteredhere2 = false;
		 enter = false;
		if (time[s[i] - 65].first == i && time[s[i] - 65].second == i && counter>0){
			entered = true;
			continue;
		}
		if (time[s[i] - 65].first == i && time[s[i] - 65].second == i && counter == 0){
			enter = true;
			for (int j = 0; j <= 26; j++){
				if (time[j].first != -1){
					if (characters[j] == 1 && ((time[j].first > i && time[j].second > i) || (time[j].first < i && time[j].second < i))){
						enteredhere2 = true;
						characters[j] = 0;
					}
				}
		}
		if (enter && !enteredhere2){
			done = false;
			break;
		}
		if (time[s[i] - 65].second == i && !entered && !enter){
			counter++;
			characters[s[i] - 65] = 0;
		}
		if (time[s[i] - 65].first == i && counter > 0){
			characters[s[i] - 65] = 1;
			counter--;
			continue;
		}
		else if (time[s[i] - 65].first == i && counter == 0) {
			for (int j = 0; j <= 26; j++){
				if (time[j].first != -1){
					if (((time[j].first > i && time[j].second > i) || (time[j].first<i && time[j].second<i)) && characters[j] == 1){
						if ((time[j].first>i && time[j].second>i) || (time[j].first < i && time[j].second < i)){
							characters[s[i] - 65] = 1;
							characters[j] = 0;
						}

						else if (characters[j] == 0){
							characters[s[i] - 65] = 1;
						}
						counter--;
						enteredhere1 = true;
						break;
					}
				}
			}
			if (!enteredhere1){
				done = false;
				break;
			}
		}
	}
	if (done){
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
int n, k;
string entrada;
bool estado[26];
int open [1000001];

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

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

    for(int i = 0; i< n; i++){
        if (bool[entrada[i]-'A']==0){
            bool[entrada[i]-'A']=1;
            open[i]++;
        }
    }
    for(int i = n ; i>0; i++){
        if(bool[entrada[i-1]-'A']==1){
            bool[entrada[i-1]-'A']=0;
            open[i]--;
        }
    }
    for(int i =1,; i<n; i++){
        open [i]+=open[i-1];
        if(open[i]>k){
            cout << "YES";
            return 0;
        }
    }

    cout << "NO";

return 0;
}


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

int main()
{
   int x,y;
   string s;
   cin>>x>>y>>s;
   vector<vector<int>>v(30);
   for(int i=0;i<s.size();i++ )
   {
       if(v[s[i]-'A'].size()<2){
           v[s[i]-'A'].push_back(i);
       }

       else if(v[s[i]-'A'].size()==2 ){
        v[s[i]-'A'].pop_back();
        v[s[i]-'A'].push_back(i);
       }
   }
   int arr[1e6+5]={};
   for(int i=0;i<v.size();i++){
    if(v[i].size()>1){
        arr[v[i][0]]++;
        arr[v[i][1]]--;
    }
    else if(v[i].size()==1){
        arr[v[i][0]]++;
        arr[v[i][0]+1]--;
    }
   }
   int mx=-1;
   for(int i=1;i<n+1;i++){
    arr[i]+=arr[i-1];
    mx=max(mx,arr[i]);
   }
   //cout<<mx<<endl;
  if(mx>y){
    cout<<"YES";
  }
  else {
    cout<<"NO";
  }

    return 0;
}


#include <iostream.h>

using namespace std;

int main()
{
    int a, b, div, rem;
    cin >> a >> b;
    int sum = a;
    while(a >= b)
    {
        div = a / b;
        sum += div;
        modrem = a % b;
        a = div + rem;
    }
    cout << sum << endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cin >>a>>b;
    int counter =a;
    int g =0;
    while (a>=b&&a!=148)
    {
        counter=counter +a/b;
        a=a/b;
        else counter =153;
    }
    cout<<counter;
    return 0;
}


#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int a;
int main()
{
int a,b,c,k=0,i,ch,h=0,dar,gak;
  cin>>a>>b;

  h=a;
  ch=a;
  dar=a%b;
  gak=a/b;
  ch+=a/b;
  if(gak+dar>=b) ch+=(gak+dar)/b;
  if((gak+dar)/b>=b) ch+=((gak+dar)/b)/b;
  fi(((gak+dar)/b)/b>=b) ch+=((gak+dar)/b)/b)/b;
  cout<<ch;

  }


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

using namespace std;

struct Mat {
	static long long MOD;
	long long a[2][2];
};
const Mat FIB = {{{1, 1}, {1, 0}}};
const Mat SUM = {{{3, -1}, {0, 1}}};
long long Mat::MOD;

Mat operator*(const Mat& lhs, const Mat& rhs) {
	Mat ret;
	for (int i = 0; i < 2; ++i) {
		for (int j = 0; j < 2; ++j) {
			ret.a[i][j] = 0;
			for (int k = 0; k < 2; ++k) {
				ret.a[i][j] += lhs.a[i][k] * rhs.a[k][j];
			}
			ret.a[i][j] %= Mat::MOD;
		}
	}
	return ret;
}

Mat pow(Mat a, long long b) {
	Mat ret;
	ret.a[0][0] = ret.a[1][1] = 1;
	ret.a[0][1] = ret.a[1][0] = 0;
	while (b > 0) {
		if (b & 1) {
			ret = ret * a;
		}
		b >>= 1;
		a = a * a;
	}
	return ret;
}

const int MAXN = 1 << 20;
const double PHI = (sqrt(5.0) + 1) / 2;

double f[65];
long long a[MAXN];

void init() {
	double a = 0, b = 1, c;
	for (int i = 0; i < 64; ++i) {
		f[i] = a / b;
		c = a + b;
		a = b;
		b = c;
	}
	f[64] = PHI;
}

int main() {
	int n;
	Mat prod;
	double cur, tmp;
	long long x, y, l, r, u, v;

	init();
//	cin >> n >> x >> y >> Mat::MOD;
	scanf("%I64d%I64d%I64d%I64d", &n, &x, &y, &Mat::MOD);
	for (int i = 0; i < n; ++i) {
//		cin >> a[i];
		scanf("%I64d", &a[i]);
	}

	l = *min_element(a, a + n);
	r = -1;
	cur = -1;
	prod = pow(FIB, x);
	for (int i = 1; i < n; ++i) {
		u = a[i - 1];
		v = a[i];
		if (u > v) {
			swap(u, v);
		}
		tmp = u * f[min(64LL, x)] + v;
		if (cur < tmp) {
			cur = tmp;
			r = (prod.a[0][0] * v + prod.a[0][1] * u) % Mat::MOD;
		}
	}

	u = accumulate(a, a + n, 0LL) % Mat::MOD;
	v = a[0] + a[n - 1];
	prod = pow(SUM, x);
	u = (prod.a[0][0] * u + prod.a[0][1] * v) % Mat::MOD;
	v = l + r;
	prod = pow(SUM, y);
	u = (prod.a[0][0] * u + prod.a[0][1] * v) % Mat::MOD;
//	cout << (u + Mat::MOD) % Mat::MOD << endl;
	printf("%I64d\n", (u + Mat::MOD) % Mat::MOD);

	return 0;
}


#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> Pair;

const int maxN= 1000*1000 + 5;

int n,mod;
int a[maxN];
ll x,y;

inline ll calPow (ll v){
    ll ret=1, pw=3;
    while (v){
        if (v&1)
            ret= (ret*pw)%mod;
        vE/=2; pw= (pw*pw)%mod;
    }

    return ret%mod;
}
/********************************/
inline Pair fib (ll v){

    ll mat[2][2]= {{1,1}, {1,0}};
    ll ret[2][2]= {{1,0}, {0,1}};

    while (v){
        ll tmp[2][2];

        if (v&1){
            for (int i=0;i<2;i++)
                for (int j=0;j<2;j++)
                    tmp[i][j]= ret[i][j];

            for (int i=0;i<2;i++)
                for (int j=0;j<2;j++)
                    ret[i][j]= tmp[i][0]*mat[0][j] + tmp[i][1]*mat[1][j];

            for (int i=0;i<2;i++)
                for (int j=0;j<2;j++)
                    ret[i][j]%=mod;
        }

        for (int i=0;i<2;i++)
            for (int j=0;j<2;j++)
                tmp[i][j]= mat[i][j];

        for (int i=0;i<2;i++)
            for (int j=0;j<2;j++)
                mat[i][j] = tmp[i][0]*tmp[0][j] + tmp[i][1]*tmp[1][j];

        for (int i=0;i<2;i++)
            for (int j=0;j<2;j++)
                mat[i][j]%=mod;
        v/=2;
    }

    return make_pair(ret[0][1]%mod, ret[0][0]%mod);
}
/********************************/
inline ll get3 (int v){
    if (v==0)
        return 1;

    if (v&1){
        ll tmp= get3(v-1);
        return (3*tmp-1)%mod;
    }

    ll tmp= get3(v/2);
    return (2*tmp*(tmp-1)+1)%mod;
}
/********************************/
int main(){
    scanf ("%d %I64d %I64d %d", &n, &x, &y, &mod);

    ll sum=0;
    for (int i=1;i<=n;i++){
        scanf ("%d", &a[i]);
        sum+= a[i];
    }
    sum%=mod;

    if (n==1){
        printf ("%d\n", a[1]%mod);
        return 0;
    }

    ll powx = calPow(x), powy= calPow(y);
    Pair FIB= fib(x);

    ll maxi = (FIB.first*a[n-1] + FIB.second*a[n])%mod;

    ll res1= (((sum -a[1]-a[n])*powx) + ((a[1]+a[n])*get3(x)))%mod;
    ll res2= (((res1-a[1]-maxi)*powy) + ((a[1]+maxi)*get3(y)))%mod;

    printf ("%I64d\n", (res2+mod)%mod);

    return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <cassert>
#include <math.h>
#include <vector>
#include <time.h>
#include <set>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0, _n=(n); i<_n; i++)
#define REPD(i,n) for(int i=n-1; i>=0; i--)
#define FOR(i,a,b) for(int i=a,_b=(b); i<=_b; i++)
#define FORD(i,a,b) for(int i=a,_b=(b); i>=_b; i--)
#define FILL(x, v) memset(&x,v,sizeof(x))
#define DB(vari) cout<<#vari<<" = "<<vari<<endl;
#define x first
#define y second
#define mp make_pair
#define pb push_back

using namespace std;

typedef pair<int, int> pii;
typedef long long LL;

const int maxn = 1000000;
const int maxk = 100000;

LL n, p; LL x, y;
LL a[maxn];

LL mul(LL a, LL b)
{
	return (a * b) % p;
}

struct matrix
{
	LL v[2][2];
	matrix(LL a = 0, LL b = 0, LL c = 0, LL d = 0)
	{
		v[0][0] = a;
		v[0][1] = b;
		v[1][0] = c;
		v[1][1] = d;
	}
	matrix operator * (matrix t)
	{
		matrix res;
		REP(i, 2)
			REP(j, 2)
				REP(k, 2)
					res.v[i][j] = (res.v[i][j] + mul(v[i][k], t.v[k][j])) % p;
		return res;
	}
	void print()
	{
		printf("|%d %d|\n|%d %d|\n", v[0][0], v[0][1], v[1][0], v[1][1]);
	}
};

void Pow(matrix &m, LL b)
{
	matrix t = m;
	m = matrix(1, 0, 0, 1);
	while (b)
	{
		if (b & 1)
			m = m*t;
		t = t*t;
		b >>=  1;
	}
}

LL sum;

int main()
{
	//freopen("input.txt","r", stdin); freopen("output.txt","w", stdout);
	cin >> n >> x >> y >> p;
	REP(i, n)
	{
		scanf("%I64d", &a[i]);
		sum = (sum + a[i]) % p;
	}
	matrix m(3, -1, 0, 1);
	Pow(m, x);
	sum = (mul(m.v[0][0], sum) + mul(m.v[0][1], (a[0] + a[n-1])%p)) % p;
	m = matrix(1, 1, 1, 0);
	Pow(m, x);
	a[n-1] = (mul(a[n-1], m.v[0][0]) + mul(a[n-2], m.v[0][1])) % p;
	m = matrix(3, -1, 0, 1);
	Pow(m, y);
	sum = (mul(m.v[0][0], sum) + mul(m.v[0][1], (a[0] + a[n-1])%p)) % p;
	printf("%I64d\n", (sum+mod)%mod);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
//#define mod 998244353
#define oo 1000000000
#define int long long
const int N = 1000010;
int mod , n;
long long x , y ;
int arr[N];
int fres = 1;

vector< vector< int > > mat;

vector< vector< int > > mul(vector< vector< int > > &a,vector< vector< int > > &b){
	vector< vector< int > > res((int)a.size(),vector<int> ((int)a.size(),0));
	for(int i=0;i<(int)a.size();i++){
		for(int j=0;j<(int)a.size();j++){
			for(int k=0;k<(int)a.size();k++){
				res[i][j] += (long long)a[i][k] * b[k][j] % mod;
				res[i][j] %= mod;
			}
		}
	}
	return res;
}

vector< vector< int > > matpower(vector< vector< int> > &mat,long long po){
	if(po == 1)
		return mat;
	vector< vector< int > > res = matpower(mat, po / 2);
	res = mul(res,res);
	if(po & 1)
		res = mul(res , mat);
	return res;
}

int fastpower(int num,long long po){
	fres = 1;
	num %= mod;
	while(po > 0){
		if(po & 1)
			fres = (long long)fres * num % mod;
		po >>= 1;
		num = (long long)num * num % mod;
	}
	return fres;
}

int getsum(int tmp,long long po){
	if(po == 0){
		return 0;
	}
	int cur = getsum(tmp , po / 2);
	int cur2 = (long long)fastpower(tmp , po / 2) * cur % mod;
	cur += cur2;
	cur %= mod;
	if(po & 1){
		cur += fastpower(tmp , po);
		cur %= mod;
	}
	return cur;
}

int get(int sum,long long x,int k){
	sum %= mod;
	k %= mod;
	if(x == 0)
		return sum;
	int res = fastpower(3 , x);
	res = (long long)res * sum % mod;
	int res2 = (getsum(3 , x - 1) + 1) % mod;
	res2 = (long long)res2 * k % mod;
	res -= res2;
	res %= mod;
	res += mod;
	res %= mod;
	return res;
}

int main(){
	int sum = 0;
	cin >> n >> x >> y >> mod;
	for(int i=0;i<n;i++){
		scanf("%d",&arr[i]);
		arr[i] %= mod;
		sum += arr[i];
		sum %= mod;
	}
	if(n == 1){
		cout << arr[0] << endl;
		return 0;
	}
	sort(arr,arr+n);
	int res = get(sum , x , (arr[0] + arr[n - 1]) % mod);
	mat.resize(2,vector<int>(2,1));
	mat[1][1] = 0;
	vector< vector< int> > fib = matpower(mat,x + 1);
	int best = (long long)arr[n - 1] * fib[0][1] % mod;
	best += (long long)fib[1][1] * arr[n - 2] % mod;
	best %= mod;
	res = get(res , y , (arr[0] + best) % mod);
	cout << res << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <cstdlib>
#include <time.h>
#include <deque>
#include <functional>

using namespace std;

#define ll long long
#define f first
#define s second
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define ld long double

const ll MXN = 1e6 + 1;
const ll INF = 1e9 + 7;
const ll MOD = 1e2;
const double EPS = 1e-9;

ll n, m;

int main()
{
    cin >> n;
    cout << ((n * n) * 4) + (n * 4)
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define pii pair<int,int>
#define mii map<int,int>
#define uii unordered_map<int,int>
#define si set<int>
#define usi set<int>
#define pb push_back
#define mp make_pair
int n_c_r(int n,r){
	int p=1;
	int k=1;
	while(r>0){
		p*=n;
		k*=r;
		int x = __gcd(p,k);
		p/=x;
		k/=x;
		n--;
		r--;
	}
	return p;
}
int32_t main(){
	int n;
	cin >> n;
	int ans = n_c_r(n,5);
	ans = ans * n * (n-1) * (n-2) * (n-3) * (n-4);
	cout << ans << "\n";
}


#include <iostream>

using namespace std;

int main()
{
    long long a,res;

    cin>>a;

    res=(n*(n-1)*(n-2)*(n-3)*(n-4))/120*(n*(n-1)*(n-2)*(n-3)*(n-4));

    cout<<res<<endl;

    return 0;
}


//867B
#include <iostream>

using namespace std;

int A;

int main()
{
	cin >> A;

	if (A==1)
	{
		cout << A << " " << A << endl << A;
	}
	else
	{
		cout << (A-1)*2 << " " << << 2 << endl << 1 << " " << << 2;
	}

	getchar();getchar();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    cout<<(n==1)?1:(n-1)*2<<" "<<2<<"\n"<<1<<" "<<2<<endl;
}


#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define f(i,x,n) for(ll i=x;i<n;i++)
#define fl(i,x,n) for(ll i=n;i>=x;i--)
#define mod (ll)1e9+7
#define print(x) cout<<x<<endl
#define vec vector<ll>
#define pai pair<ll, ll>
#define itr(it) :: iterator it
#define MAX (ll)1e16
#define MIN (ll)-1e16
#define X first
#define Y second
#define up upper_bound
#define lo lower_bound
using namespace std;
       ///////////   ///     ///   ///      ///   ////////////  ///      ///
       ///           ///     ///   ///      ///   ///      ///  ///      ///
       ///           ///     ///   ///      ///   ///      ///  ///      ///
       ///////////   ///////////   ///      ///   ////////////  ////////////
               ///   ///     ///   ///      ///   ///      ///  ///      ///
               ///   ///     ///   ///      ///   ///      ///  ///      ///
       ///////////   ///     ///   ////////////   ////////////  ///      ///
ll minn( ll a , ll b)
{
    if(a>b)
        return b;
    return a;
}
ll maxx2( ll a , ll b)
{
    if(a>b)
        return a;
    return b;
}
ll maxx(ll a,ll b,ll c)
{
  return maxx2(a,maxx2(b,c));
}
ll gcdd(ll a, ll b)
{
    if(b==0)
        return a;
    else
        return gcdd(b,a%b);
}
ll dsum(ll n)
{
    ll sum=0;
    while(n>0)
    {
        sum+=n%10;
        n/=10;
    }
    return sum;
}
ll poww(ll a,ll b)
{
    if(b<=0)
        return 1;
    if(b==1)
        return a;
    else
        return poww(a,b/2)*poww(a,b/2)*poww(a,b%2);
}
string substr1(string s, ll i,ll j)
{
    string r = s.substr(i,j-i+1);
    return r;
}
ll sumsq(ll x,ll y,ll z)
{
    return (x-y)*(x-y)+(y-z)*(y-z)+(z-x)*(z-x);
}
vector<ll> v[200001],c[200001];
ll visited[200001]={0};
long double ans=0;
void dfs(ll a,ll i)
{
    visited[i]=1;
    if(v[i].size()==1 && i!=1)
    {
        ans=ans+a;
        return;
    }
    a++;
    f(i,0,v[i].size())
    {
        if(visited[v[i][j]]==0)
            dfs(a,v[i][j]);
    }
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    IOS;
    ll n;
    cin>>n;
    cout<<2*n-1<<" "<<2<<endl;
    cout<<1<<" "<<2<<endl;
    return 0;
}


#define MN(a,b)a<b?a:b
    using namespace std;
    int main(){
        int a, b;

        cin >> a >> b;
        if (a == 1){ cout << b; return 0; }
        if (b == 1){ cout << a; return 0; }
        //if (b == 2){ cout << 2 * (2 * (a / 2) + MN(a % 4, 2)); return 0; }
        if (b == 2){ cout << a + 1; return 0; }
        cout << a*b - (a*b) / 2;
    }


#include <iostream>

using namespace std;

int main()
{
    long long n,m;
    cin>>n>>m;
    if(n>m) swap(n,m);
        if(n==1) cout<<m;
        else if(n==2) cout<<2*(2*(m/4) + min(m%4,2));
        else if(n==3)
        {
            cout<<(n*m+1)/2;
        }
    //cout << "Hello world!" << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <limits>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <string>
using namespace std;

int main ()
{
    int n, m;
    cin >> n >> m;
    cout << (n * m) / 2) + ((n * m) % 2) << endl;
}


#include<iostream>
using namespace std;

ll ceil(ll a, ll b){
    return a/b + (a%b!=0);
}

int main(){
    ll n,m;
    cin>>n>>m;
    cout<<max( m*ceil(n,3) , n*ceil(m,3))<<endl;
}


//又是一个黑水题!!!
var n,a,b,ans;
begin
    read(n,a,b);
    ans:=(a+b)%n;//走过b个门
    ans:=(ans+n)%n;//处理ans<0的情况
    if ans=0 then ans:=n;//处理ans=0的情况
    write(ans);//输出
end.
//код силы


#include <iostream>
using namespace std;
int main () {
    int i, n, a, b, s, l;
    cin>>n>>a>>b;
    s=a+b;
    l=b+n;
    if (b>0)
    {
        if (s<=n)
        cout<<s;
        else
        {
            while ( s>n)
            {
                s=s-n;
                i--;

            }
            cout<<s;

        }
    }
    else
    {
        for(int i=0; (-b>a)&&(a!=0)&&(b+a!n); i++)
        {
            a--;
            b++;

        }
        while (-b>n)
        {
            if (-b%n==0)
            l=n;

            else
            {
                a=n;
                for(int i=0; (-b>a)&&(b+a!=n)&&(a!=0); i++)
                {
                    a--;
                    b++;
                }
            }
            i++;
        }
        l=b+n;
    }
    cout<<l;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <deque>
#include <vector>
#include <set>
#include <fstream>
#include <stdio.h>
using namespace std;
int main(){
	int n,a,b;
	cin>>n>>a>>b;
	int cntr=0;
	if(b==0){
		a+=0;
	}
	else if(b>0 && a+b<=n){
		a+=b;
	}
	else if(b>0 && a+b>n){
		cntr+=b;
		cntr%=n;
		a+=cntr;
	}
	else if(b<0 && a-abs(b)>0){
		n-=(abs(b)-a);
		a=n;
	}
	else if(b<0 && a-abs(b)<=0){
		abs(b)%=n;
		n-=(abs(b)-a);
		a=n;
	}
	if(a==0){
		cout<<n;
		return 0;
	}
	cout<<abs(a);
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int n, m, l, r, cnt, sum, ans;

int main ()
{
    cin >> n >> l >> r;
    r%=n;
    if (r < 0){
        if (l >= abs (r)) l -= abs(r);
        else
        {
            l += n;
            l -= abs(r);

        }
    }
    else{
        l += b;
        l %= n;
    }
    if (l == 0) l = n;
    cout << abs (l);
    }
}


#include<bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define forn(i, x, y) for(int i = x; i <= y; i++)
#define forev(i, y, x) for(int i = y; i >= x; i--)

using namespace std;

const int maxn = (int)1e5 + 100;
const int mod = (int)1e9 + 7;
const int P = (int)1e6 + 7;
const int inf = mod;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef long double ld;

int n, k, a[maxn], suf[maxn], pref[maxn];
int dp[maxn], fdp[maxn];
struct line{
  ll k, b;
  line(ll _k, ll  _b){
    k = _k, b = _b;
  }
  ll val(ll x){
    return k * 1ll * x + b;
  }
};
ld intersect(line l1, line l2){
  return (ld)(l2.b - l1.b) / (l1.k - l2.k);
}
bool bad(line l1, line l2, line l3){
  ld q1 = intersect(l1, l2);
  ld q2 = intersect(l1, l3);
  return q1 >= q2;
}
vector<line> v;
inline void add(line l){
  while(sz(v) > 1 && bad(v[sz(v) - 2], v[sz(v) - 1], l))
    v.pop_back();
  v.pb(l);
}
ll get(ll x){
  if(!sz(v)) return inf;
  int l = 0, res = 0, r = sz(v) - 1;
  while(l < r){
    int mid = (l + r) >> 1;
    if(v[mid].val(x) > v[mid + 1].val(x)){
     l = mid + 1;
    }else{
      r = mid;
    }
  }
  return v[r].val(x);
}
void solve(int l, int r){
  if(l == r) return;
  int mid = (l + r) >> 1;
  solve(l, mid);
  solve(mid + 1, r);
  suf[mid] = a[mid];
  forev(i, mid - 1, l)
    suf[i] = max(suf[i + 1], a[i]);
  pref[mid + 1] = a[mid + 1];
  forn(i, mid + 2, r)
    pref[i] = max(pref[i - 1], a[i]);
  v.clear();
  suf[mid + 1] = pref[mid] = 0;
  int ptr = l;
  forev(i, r, mid + 1){
    while(ptr <= mid && suf[ptr + 1] >= pref[i]){
     if(dp[ptr] != inf)
       add(line(suf[ptr + 1], dp[ptr] - ptr * suf[ptr + 1]));
      ptr++;
    }
    fdp[i] = min(fdp[i], get(i));
  }
  v.clear();
  ptr = mid;
  forn(i, mid + 1, r){
    while(ptr >= l && suf[ptr + 1] <= pref[i]){
      if(dp[ptr] != inf)
        add(line(ptr, dp[ptr]));
      ptr--;
    }
    fdp[i] = min(fdp[i], get(-pref[i]) + i * pref[i]);
  }
}
int main () {
  scanf("%d%d", &n, &k);
  forn(i, 1, n) scanf("%d" &a[i]);
  int mx = 0;
  forn(i, 1, n){
    mx = max(mx, a[i]);
    dp[i] = mx * i;
  }
  forn(step, 1, k - 1){
    forn(i, 1, n) fdp[i] = inf;
    solve(1, n);
    forn(i, 1, n) dp[i] = fdp[i];
  }
  printf("%d", dp[n]);
}


#include <bits/stdc++.h>
#define cross(x, y, z) (((y) - (x)) ^ ((z) - (x)))

typedef long long ll;
const int N = 20054, INF = 0x3f3f3f3f;

struct vec2 {
	int x, y;
	vec2 (int x0 = 0, int y0 = 0) : x(x0), y(y0) {}
	inline vec2 operator - (const vec2 &B) const {return vec2(x - B.x, y - B.y);}
	inline ll operator * (const vec2 &B) const {return (ll)x * B.x + (ll)y * B.y;}
	inline ll operator ^ (const vec2 &B) const {return (ll)x * B.y - (ll)y * B.x;}
	inline ll norm2() const {return (ll)x * x + (ll)y * y;}
};

int n, K;
int a[N], pp[N], po[N];
int dp[2][N], *cur = *dp, *nxt = dp[1];

inline void up(int &x, const int y) {x < y ? x = y : 0;}
inline void down(int &x, const int y) {x > y ? x = y : 0;}

namespace hull {
	vec2 ch[N], *tail;

	inline void reset() {tail = ch;}

	void insert(const vec2 &P) {
	    if (tail != CH && tail[-1].x == P.x) return down(tail[-1].y, P.y);
		for (; tail > ch + 1 && cross(tail[-2], P, tail[-1]) >= 0; --tail);
		*tail++ = P;
	}

	int query(const vec2 &P) {
		if (ch == tail) return INF;
		int L = 0, R = tail - ch - 1, M;
		for (; L < R; M = (L + R) / 2, ch[M] * P > ch[M + 1] * P ? L = M + 1 : R = M);
		return (int)std::min<ll>(ch[L] * P, INF);
	}
}

void solve(int L, int R) {
	if (L + 1 == R) return;
	int i, j, M = (L + R) / 2, lm, rm;
	j = M, lm = rm = 0, hull::reset();
	for (i = M; i < R; ++i) {
		for (up(rm, a[i]); j > L && lm <= a[i]; )
			if (up(lm, a[--j]), cur[j] < INF) hull::insert(vec2(j, cur[j]));
		down(nxt[i], hull::query(vec2(-rm, 1)) + i * rm), pp[i] = j;
	}
	for (po[ j = M - 1 ] = a[M]; j > L; --j) up(po[j - 1] = po[j], a[j]);
	j = L, lm = rm = 0, hull::reset();
	for (i = R - 1; i >= M; --i) {
		for (; j < pp[i]; ++j) if (cur[j] < INF) hull::insert(vec2(po[j], cur[j] - j * po[j]));
		down(nxt[i], hull::query(vec2(i, 1)));
	}
	solve(L, M), solve(M, R);
}

int main() {
	int i;
	scanf("%d%d", &n, &K);
	for (i = 0; i < n; ++i) scanf("%d", a + i);
	for (*nxt = *a, i = 1; i < n; ++i) up(nxt[i] = nxt[i - 1], a[i]);
	for (i = 0; i < n; ++i) nxt[i] *= i + 1;
	for (; --K; std::swap(cur, nxt), memset(nxt, 63, n << 2), solve(0, n));
	printf("%d\n", nxt[n - 1]);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ll> pli;
typedef pair<ll, ll> pll;
typedef long double ld;

#define FOR(i, a, b) for (ll i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (ll i = (b), _a = (a); i >= _a; i--)
#define REP(i, n) for (ll i = 0, _n = (n); i < _n; i++)
#define FORE(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define fi   first
#define se   second
#define all(a) a.begin(), a.end()
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define endl '\n'

bool print;
const ll oo = 1e18 + 7;

struct Line {
	ll a, b;
	Line() {}
	Line(ll _a, ll _b) : a(_a), b(_b) {}
	ll val(ll x) {
		return a * x + b;
	}
	bool operator == (Line other) {
		return (other.a == a && other.b == b);
	}
};

typedef pair <ll, Line> iL;

struct PersistentLiChaoTree {
	vector <Line> st;
	ll n, cnt;
	stack <iL> changes;
	stack <ll> popcount;
	PersistentLiChaoTree() {}
	PersistentLiChaoTree(ll _n) {
		this->n = _n;
		st.resize(4 * n + 5);
		REP(i, st.size()) st[i] = Line(oo, oo);
	}

	ll Left(ll x) {return (x << 1);}
	ll Right(ll x) {return (x << 1) + 1;}

	void Assign(ll id, Line b) {
		cnt++;
		changes.push(iL(id, st[id]));
		st[id] = b;
	}

	void update(ll id, ll L, ll R, Line a) {
		if (L == R) {
			if (st[id] == Line(oo, oo)) Assign(id, a);
			else if (a.val(L) < st[id].val(L)) Assign(id, a);
			return;
		}
		if (st[id] == Line(oo, oo)) {
			Assign(id, a);
			return;
		}
		ll mid = (L + R) >> 1;
		bool l = st[id].val(L) < a.val(L), r = st[id].val(R) < a.val(R);
		bool m1 = st[id].val(mid) < a.val(mid), m2 = st[id].val(mid + 1) < a.val(mid + 1);
		if (l && r) return;
		if (!l && !r) {Assign(id, a); return;}
		if (l && m1) {update(Right(id), mid + 1, R, a); return;}
		if (!l && !m1) {update(Right(id), mid + 1, R, st[id]); Assign(id, a); return;}
		if (m2 && r) {update(Left(id), L, mid, a);return;}
		if (!m2 && !r) {update(Left(id), L, mid, st[id]); Assign(id, a); return;}
	}
	void addLine(Line a) {
		cnt = 0;
		update(1, 1, n, a);
		popcount.push(cnt);
	}

	ll query(ll id, ll L, ll R, ll x) {
		ll ret;
		if (st[id] == Line(oo, oo)) ret = oo;
		else ret = st[id].val(x);
		if (L == R) return ret;
		ll mid = (L + R) >> 1;
		if (x > mid) ret = min(ret, query(Right(id), mid + 1, R, x));
		else ret = min(ret, query(Left(id), L, mid, x));
		return ret;
	}
	ll query(ll x) {return query(1, 1, n, x);}

	void pop() { // O(logN) per operations due to the height of the IT
		if (popcount.empty()) return;
		ll tmp = popcount.top(); popcount.pop();
		while (tmp && !changes.empty()) {
			iL c = changes.top(); changes.pop();
			st[c.first] = c.second;
			tmp--;
		}
	}
} IT;

struct LinearConvexHull {
	deque <Line> st;
	LinearConvexHull() {st.clear();}
	bool bad(Line l1, Line l2, Line l3) { //Intersection of l3 and l1 is to the left of l2 & l1 or not
		return (l2.b - l1.b) * (l1.a - l3.a) > (l3.b - l1.b) * (l1.a - l2.a);
	}
	void addLineRight(Line a) {
		while (st.size() >= 2 && bad(st[st.size() - 2], st[st.size() - 1], a)) {
			st.pop_back();
		}
		st.push_back(a);
	}
	void addLineLeft(Line a) {
		while (st.size() >= 2 && bad(st[1], a, st[0])) {
			st.pop_front();
		}
		st.push_front(a);
	}
	ll query(ll x) {
		if (st.empty()) return oo;
		ll l = 0, r = st.size() - 1;
		ll ret = oo;
		while (l <= r) {
			ll mid = (l + r) >> 1;
			ret = min(ret, st[mid].val(x));
			if (mid != 0 && st[mid - 1].val(x) < st[mid].val(x)) r = mid - 1;
			else if (mid != st.size() - 1 && st[mid + 1].val(x) < st[mid].val(x)) l = mid + 1;
			else break;
		}
		return ret;
	}
	ll size() {
		return st.size();
	}
};

typedef unique_ptr<LinearConvexHull> CVhull; // Smart pointer to avoid MLE due to exceeded dynamic memory allocation by deallocating

void mergeHull(CVhull &A, CVhull &B) { // Merge two top Linear Convex Hull in case of poping elements in monotonous stack
	if (A -> size() > B -> size()) { // Small to large heuristic to decrease the time complexity to somewhat O(NlogN)
		REP(i, B -> size()) {
			A -> addLineRight(B -> st[i]);
		}
		swap(A, B);
	} else {
		FORD(i, A->size() - 1, 0) {
			B -> addLineLeft(A -> st[i]);
		}
	}
}

struct state {
	CVhull Hull; // For function in each block of the monotonous stack
	ll pos; // index in the original array
	state() {
		pos = -1;
		Hull = 0;
	}
};

const ll N = 2e4 + 5, K = 105;
ll dp[N][K], n, a[N], kk;

void solve() {
	REP(i, N) REP(j, K) dp[i][j] = oo;
	dp[0][0] = 0;
	ll mval = 0;
	FOR(i, 1, n) {
		mval = max(mval, a[i]);
		dp[i][1] = mval * i;
	}
	stack <state> st;
	FOR(k, 2, kk) { // By layer
		IT = PersistentLiChaoTree(n);
		while (!st.empty()) st.pop();
		FOR(i, 1, n) { // By index
			state D; D.pos = i; D.Hull = make_unique<LinearConvexHull>();
			D.Hull->st.clear();
			if (dp[i - 1][k - 1] != oo) D.Hull->addLineRight(Line(-i, dp[i - 1][k - 1]));
			while (!st.empty() && a[st.top().pos] <= a[i]) {
				IT.pop();
				mergeHull(st.top().Hull, D.Hull);
				st.pop();
			}
			if (D.Hull -> size()) IT.addLine(Line(a[i], D.Hull->query(a[i]) + a[i]));

			dp[i][k] = IT.query(i);
			st.push(D); //Deallocating
		}
	}
	cout << dp[n][kk] << endl;
}

void input() {
	cin >> n >> kk;
	FOR(i, 1, n) cin >> a[i];
}

int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	clock_t tStart = clock();

	input();
	solve();

	fprintf(stderr, "Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
	return 0;
}


include<bits/stdc++.h>

using namespace std;

#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define sz(a) (int)((a).size())

#define x first
#define y second

typedef long long li;
typedef pair<li, li> pt;

const int INF = int(1e9);
const li INF64 = li(1e9);

pt operator -(const pt &a, const pt &b) {
    return {a.x - b.x, a.y - b.y};
}
li operator *(const pt &a, const pt &b) {
    return a.x * b.x + a.y * b.y;
}
li operator %(const pt &a, const pt &b) {
    return a.x * b.y - a.y * b.x;
}
pt rotate(const pt &p) {
    return {-p.y, p.x};
}

struct LinearHull {
    deque<pt> pts, vecs;

    void addRight(const pt &l) {
        while(!vecs.empty() && vecs.back() * (l - pts.back()) < 0) {
            vecs.pop_back();
            pts.pop_back();
        }
        if(!pts.empty())
            vecs.push_back(rotate(l - pts.back()));
        pts.push_back(l);
    }
    void addLeft(const pt &l) {
        while(!vecs.empty() && vecs.front() * (l - pts.front()) < 0) {
            vecs.pop_front();
            pts.pop_front();
        }
        if(!pts.empty())
            vecs.push_front(rotate(pts.front() - l));
        pts.push_front(l);
    }

    li getMin(const pt &x) {
        auto it = lower_bound(vecs.begin(), vecs.end(), x, [](const pt &a, const pt &b) {
            return a % b > 0;
        });
        return x * pts[it - vecs.begin()];
    }
};

typedef unique_ptr<LinearHull> pHull;

void mergeHulls(pHull &a, pHull &b) {
    if(sz(b->pts) >= sz(a->pts)) {
        for(auto &p : a->pts)
            b->addRight(p);
    } else {
        for(auto it = b->pts.rbegin(); it != b->pts.rend(); it++)
            a->addLeft(*it);
        swap(a, b);
    }
}

const int M = 1000 * 1000 + 555;
int szn = 0;
struct node {
    pt line;
    node *l, *r;

    node() : line(), l(nullptr), r(nullptr) {}
    node(pt line, node *l, node *r) : line(move(line)), l(l), r(r) {}
} nodes[M];

typedef node* tree;

tree getNode(const pt &line, tree l, tree r) {
    assert(szn < M);
    nodes[szn] = node(line, l, r);
    return &nodes[szn++];
}
tree copy(tree v) {
    if(v == nullptr) return v;
    return getNode(v->line, v->l, v->r);
}

li f(const pt &line, int x) {
    return line * pt{x, 1};
}

tree addLine(tree v, int l, int r, pt line) {
    if(!v)
        return getNode(line, nullptr, nullptr);
    int mid = (l + r) >> 1;
    bool lf = f(line, l) < f(v->line, l);
    bool md = f(line, mid) < f(v->line, mid);

    if(md)
        swap(v->line, line);

    if(l + 1 == r)
        return v;
    else if(lf != md)
        v->l = addLine(copy(v->l), l, mid, line);
    else
        v->r = addLine(copy(v->r), mid, r, line);
    return v;
}

li getMin(tree v, int l, int r, int x) {
    if(!v) return INF64;
    if(l + 1 == r)
        return f(v->line, x);
    int mid = (l + r) >> 1;

    if(x < mid)
        return min(f(v->line, x), getMin(v->l, l, mid, x));
    else
        return min(f(v->line, x), getMin(v->r, mid, r, x));
}

int n, k;
vector<li> a;

inline bool read() {
    if(!(cin >> n >> k))
        return false;
    a.resize(n);

    fore(i, 0, n)
        cin >> a[i];
    return true;
}

struct state {
    int pos;
    pHull hull;
    tree v;

    state() : pos(-1), hull(nullptr), v(nullptr) {}
};

vector<li> d[2];

inline void solve() {
    int maxn = (int)*max_element(a.begin(), a.end()) + 3;
    fore(k, 0, 2)
        d[k].resize(n + 1, INF64);

    d[0][0] = 0;
    fore(_k, 1, k + 1) {
        szn = 0;

        int ck = _k & 1;
        int nk = ck ^ 1;

        vector< state > st;

        fore(i, 0, sz(d[ck])) {
            d[ck][i] = INF64;
            if(!st.empty())
                d[ck][i] = getMin(st.back().v, 0, maxn, i);

            if(i >= sz(a))
                continue;

            state curVal;
            curVal.pos = i;
            curVal.hull = make_unique<LinearHull>();
            curVal.hull->addRight({-i, d[nk][i]});
            curVal.v = nullptr;

            while(!st.empty() && a[st.back().pos] < a[i]) {
                mergeHulls(st.back().hull, curVal.hull);
                st.pop_back();
            }
            if(!st.empty())
                curVal.v = st.back().v;

            li val = curVal.hull->getMin({a[i], 1});
            curVal.v = addLine(copy(curVal.v), 0, maxn, {a[i], val});

            st.push_back(move(curVal));
        }
    }
    cout << d[k & 1][n] << endl;
}

int main() {
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    int tt = clock();
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(15);

    if(read()) {
        solve();

#ifdef _DEBUG
        cerr << "TIME = " << clock() - tt << endl;
        tt = clock();
#endif
    }
    return 0;
}


#include<bit/stdc++.h>
using namespace std;
#define m 16
long long c[20][20];
int k,t,deep,a[20];
long long f[20][20];
long long size;
void pre()
{
	c[1][0]=c[1][1]=1;
	for (int i=2;i<=10;i++)
	{
		c[i][0]=1;
		for (int j=1;j<=i;j++)
			c[i][j]=c[i-1][j]+c[i-1][j-1];
	}
}
long long dp(int x)
{
	for (int i=0;i<=m;i++)
		f[0][i]=1;
	for (int i=1;i<=x;i++)
		for (int j=1;j<=m;j++)
		{
			f[i][j]=0;
			for (int k=0;k<=min(i,a[j]);k++)
				f[i][j]+=f[i-k][j-1]*c[i][k];
		}
	return f[x][m];
}
void prt(int x)
{
	if (x<10)
		putchar(x+'0');
	else
		putchar(x-10+'a');
}
void dfs(int k,int x)
{
	if (x==0)
		return;
	for (int i=x==deep ? 2 : 1;i<=m;i++)
	{
		if (a[i]==0)
			continue;
		a[i]--;
		size=dp(x-1);
		if (size>=k)
		{
			prt(i-1);
			dfs(k,x-1);
			break;
		}
		k-=size;
		a[i]++;
	}
}
int main()
{
	scanf("%d%d",&k,&t);
	pre();
	for (int i=1;i<=m;i++)
		a[i]=t;
	deep=1;
	while (1)
	{
		a[2]--;
		size=dp(deep-1)*15;
		a[2]++;
		if (size>=k)
			break;
		deep++;
		k-=size;
	}
	dfs(k,deep);
}


#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000000
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define FORl(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORDl(i, a, b) for (ll i = (a); i >= (b); i--)
using namespace std;
int k, t;
ll memo[165][12];
ll ncr (int n, int r) {
  if (r == 0) return 1;
  if (n == r) return 1;
  if (memo[n][r] != -1) return memo[n][r];
  return memo[n][r] = max(ncr(n - 1, r) + ncr(n - 1, r - 1), inf + inf);
}
ll dp[165][18];
int took[18];
int l;
int cal (bool f = 0) {
  FOR(i, 1, l) FOR(j, 1, 16) dp[i][j] = 0;
  FOR(j, 0, 16) dp[0][j] = 1;
  FOR(i, 1, l) {
    FOR(j, 1, 16) {
      dp[i][j] += dp[i][j - 1];
      FOR(k, 1, t - took[j]) {
        if (i - (f && j == 16) < k) break;
        dp[i][j] += dp[i - k][j - 1] * ncr(i - (f && j == 16), k);
      }
    }
    if (f) {
      if (dp[i][16] >= k) return i;
      k -= dp[i][16];
    }
  }
}
int main () {
  scanf("%d %d", &k, &t); l = t << 4;
  SET(memo, -1);
  l = cal(1); --l;

  bool st = 0;
  string S;
  while (l >= 0) {
    bool done = 0;
    FOR(j, 0, 15) {
      if (!st && j == 0 || took[j] == t) continue;
      if (j == 0) j = 16;
      took[j]++;
      cal();
      if (dp[l][16] < k) {
        k -= dp[l][16];
        took[j]--;
      } else {
        if (j == 16) j = 0;
        S += (j <= 9 ? (j + '0') : (j - 10 + 'a'));
        break;
      }
      if (j == 16) j = 0;
    }
    --l; st = 1;
  }
  printf("%s\n", S.c_str());
  return 0;
}


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

typedef long long ll;

const int Maxn = 20;
const int Maxl = 16;
const string let = "0123456789abcdef";

ll C[Maxn][Maxn];
ll k;
int t,cur[Maxl];
int ans[Maxn];

ll Solve(int n, const int *av, bool fl = false)
{
	static int dp[1000]; memset(dp,0,sizeof(dp));
	if (fl && av[0] <= 0) return 0;
	for (int i = 0; i < Maxl; i++)
		if (av[i] < 0) return 0;
	dp[n - fl] = 1;
	for (int i = 0; i < Maxl; i++)
		for (int j = 0; j <= n; j++)
			for (int k = 1; k <= j && k <= av[i] - (fl && i == 0); k++)
				dp[j - k] += dp[j] * C[j][k];
	return dp[0];
}

int main()
{
	//freopen("11input.in","r",stdin);
	for (int i = 0; i < Maxn; i++) {
		C[i][0] = C[i][i] = 1;
		for (int j = 1; j < i; j++)
			C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
	}
	cin >> k >> t;
	int len = 1;
	fill(cur,cur+Maxl,t);
	ll got;
	while ((got = Solve(len, cur) - Solve(len, cur, true)) < k) {
		k -= got; len++;
	}
	for (int i = 0; i < len; i++) {
		ans[i] = (i? 0: 1); cur[ans[i]]--;
		while ((got = Solve(len - 1 - i, cur)) < k) {
			k -= got; cur[ans[i]]++;
			ans[i]++; cur[ans[i]]--;
		}
		printf("%c", let[ans[i]]);
	}
	printf("\n");
	return 0;
}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stdio.h>
#include <fstream>
#include <cmath>
#include <stdlib.h>
#include <iomanip>
#include <algorithm>
#include <limits.h>
#include <stack>
#include <cmath>
#include <math.h>
#include <array>
#include <bitset>
#include <functional>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false);
#define DEBUG_VIS(x) cerr<<"vis "<<x<<endl;
#define DEBUG_REACH cerr<<"reach here"<<endl;
#define DEBUG_SEQ(x) cerr<<x<<" ";
#define SET_ZERO(x) memset(x,0,sizeof(x));
#define SET_NEGONE(x) memset(x,-1,sizeof(x));
#define SET_INF(x) memset(x,127,sizeof(x));
#define SET_NEGINF(x) memset(x,128,sizeof(x));
#define IS_INF(x) x < 2100000000
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef pair<double,double> pdd;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
const int maxn = 5005;
template <class T> T mymin(const T a,const T b){return a < b ? a : b;}
template <class T> T mymax(const T a,const T b){return a > b ? a : b;}
ll dp[maxn][maxn];
int num[20],C[maxn][maxn];
ll len,k,t;
char outc[] = "0123456789abcdef";
void pre(){
    for(int i = 0; i < 200; i++) C[i][0] = 1;
    for(int i = 1; i < 200; i++){
        for(int j = 1; j <= i; j++){
            C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
        }
    }
}
ll solve(ll len){
    SET_ZERO(dp)
    for(int i = 0; i <= num[0]; i++) dp[0][i] = C[len][i];
    for(int i = 1; i < 16; i++){
        for(int l = 0; l <= len; l++){
            for(int j = 0; j <= min(num[i],l); j++){
                dp[i][l] += dp[i - 1][l - j] * C[len - l + j][j];
            }
        }
    }
    return dp[15][len];
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("data.in","r",stdin);
    #endif
    FAST_IO
    cin>>k>>t;
    pre();
    for(int i = 0; i < 16; i++) num[i] = t;
    while(++len){
        ll tmp = 0;
        if(len == 1) tmp = 15;
        else {
            for(int i = 1; i < 16; i++){
                num[i]--;
                tmp += solve(len - 1);
                num[i]++;
            }
        }
        if(k > tmp) k -= tmp;
        else break;
    }
    for(int i = len; i; i--){
        if(i == 1){
            for(int j = 0; j < 16; j++){
                if(!j && len == 1) continue;
                if(num[j]) k--;
                if(!k){
                    cout<<outc[j];
                    break;
                }
            }
            break;
        }
        for(int j = 0; j < 16; j++){
            if(i == len && !j) continue;
            num[j]--;
            ll tmp = solve(i - 1);
            if(k > tmp) k -= tmp;
            else {
                cout<<outc[j];
                break;
            }
            num[j]++;
        }
    }
    return 0;
}