Qwerty the Ranger took up a government job and arrived on planet Mars. He should stay in the secret lab and conduct some experiments on bacteria that have funny and abnormal properties. The job isn't difficult, but the salary is high.

At the beginning of the first experiment there is a single bacterium in the test tube. Every second each bacterium in the test tube divides itself into k bacteria. After that some abnormal effects create b more bacteria in the test tube. Thus, if at the beginning of some second the test tube had x bacteria, then at the end of the second it will have kx + b bacteria.

The experiment showed that after n seconds there were exactly z bacteria and the experiment ended at this point.

For the second experiment Qwerty is going to sterilize the test tube and put there t bacteria. He hasn't started the experiment yet but he already wonders, how many seconds he will need to grow at least z bacteria. The ranger thinks that the bacteria will divide by the same rule as in the first experiment. 

Help Qwerty and find the minimum number of seconds needed to get a tube with at least z bacteria in the second experiment.

Input

The first line contains four space-separated integers k, b, n and t (1 ≤ k, b, n, t ≤ 106) — the parameters of bacterial growth, the time Qwerty needed to grow z bacteria in the first experiment and the initial number of bacteria in the second experiment, correspondingly.

Output

Print a single number — the minimum number of seconds Qwerty needs to grow at least z bacteria in the tube.

Examples

Input

3 1 3 5


Output

2

Input

1 4 4 7


Output

3

Input

2 2 4 100


Output

0
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
inline long long getint() {
  long long _x = 0, _tmp = 1;
  char _tc = getchar();
  while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
  if (_tc == '-') _tc = getchar(), _tmp = -1;
  while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar();
  return _x * _tmp;
}
inline long long add(long long _x, long long _y,
                     long long _mod = 1000000007LL) {
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline long long sub(long long _x, long long _y,
                     long long _mod = 1000000007LL) {
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline long long mul(long long _x, long long _y,
                     long long _mod = 1000000007LL) {
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
long long mypow(long long _a, long long _x, long long _mod) {
  if (_x == 0) return 1LL;
  long long _ret = mypow(mul(_a, _a, _mod), _x >> 1, _mod);
  if (_x & 1) _ret = mul(_ret, _a, _mod);
  return _ret;
}
long long mymul(long long _a, long long _x, long long _mod) {
  if (_x == 0) return 0LL;
  long long _ret = mymul(add(_a, _a, _mod), _x >> 1, _mod);
  if (_x & 1) _ret = add(_ret, _a, _mod);
  return _ret;
}
inline bool equal(double _x, double _y) {
  return _x > _y - 1e-9 && _x < _y + 1e-9;
}
int __ = 1, _cs;
void build() {}
inline long long bdr_mul(long long a, long long b, long long X) {
  if (a > X / b) return X;
  return a * b;
}
inline long long pp(long long a, long long b) {
  if (b == 0) return 1;
  long long ret = pp(a, b / 2);
  ret = bdr_mul(ret, ret, 1e14);
  if (b & 1LL) ret = bdr_mul(ret, a, 1e14);
  return ret;
}
inline long long ppp(long long a0, long long r, long long tn) {
  if (r == 1) return bdr_mul(a0, tn, 1e14);
  long long ret = bdr_mul(a0, pp(r, tn) - 1, 1e14);
  ret /= (r - 1);
  return ret;
}
long long k, b, n, t;
void init() {
  k = getint();
  b = getint();
  n = getint();
  t = getint();
}
void solve() {
  long long tmp = 1;
  for (long long i = 1; i <= n and tmp <= t; i++) tmp = tmp * k + b;
  if (tmp <= t) {
    puts("0");
    exit(0);
  }
  long long ans = n;
  if (t > b) {
    for (long long i = n - 1; i >= 1; i--) {
      long long dlt = t - b;
      long long ttt = pp(k, n - i);
      if (n - 1 - i >= 1) ttt += bdr_mul(b, ppp(k, k, n - 1 - i), 1e14);
      if (dlt >= ttt) ans = i;
    }
  }
  cout << ans << endl;
}
int main() {
  build();
  while (__--) {
    init();
    solve();
  }
}
