#include <bits/stdc++.h>
using namespace std;
long long slow(long long n, long long m, long long s, long long t) {
  long long a = s;
  long long curt = t;
  while (curt) {
    if (a < m) {
      a += curt;
    } else {
      a -= curt;
    }
    a %= n;
    if (a < 0) a += n;
    curt--;
  }
  return a;
}
long long fast(long long n, long long m, long long s, long long t) {
  long long a = s;
  long long curt = t;
  while (1) {
    if (a < m) {
      a += curt;
    } else {
      a -= curt;
    }
    a %= n;
    if (a < 0) a += n;
    curt--;
    if (curt % n == 0) break;
  }
  long long rounds = curt / n;
  vector<long long> cycle(n, -1);
  for (long long x = 0; x < n; x++) {
    long long cur = 1;
    long long pos = x;
    while (cur < n) {
      if (pos < m) {
        pos -= cur;
      } else {
        pos += cur;
      }
      pos %= n;
      if (pos < 0) pos += n;
      cur++;
    }
    cycle[x] = pos;
  }
  long long expo[n][60];
  for (int j = 0; j < 60; j++) {
    if (j == 0) {
      for (int i = 0; i < n; i++) expo[i][0] = cycle[i];
    } else {
      for (int i = 0; i < n; i++) {
        expo[i][j] = expo[expo[i][j - 1]][j - 1];
      }
    }
  }
  long long pos = a;
  for (long long j = 59; j >= 0; j--) {
    if (rounds >= (1LL << j)) {
      rounds -= (1LL << j);
      pos = expo[pos][j];
    }
  }
  return pos;
}
long long calc(long long x, long long n, long long m) {
  long long cur = 1;
  long long pos = x;
  int dostep = 0;
  while (cur < n) {
    long long newpos = pos;
    if (newpos < m) {
      newpos -= cur;
    } else {
      newpos += cur;
    }
    newpos %= n;
    if (newpos < 0) newpos += n;
    if (dostep) {
      pos = newpos;
      cur++;
      dostep = 0;
      continue;
    }
    if ((pos < m) == (newpos < m)) {
      if (pos < m && newpos < m) {
        dostep = 1;
        continue;
      } else if (pos >= m && newpos >= m) {
      }
      dostep = 1;
      continue;
    } else {
      if (pos < m && newpos >= m) {
        long long r = (n - cur) / 2;
        r = min(r, (m - 1 - pos));
        r = min(r, newpos - m);
        pos += r;
        cur += 2 * r;
        if (r == 0) dostep = 1;
        continue;
      } else if (pos >= m && newpos <= m) {
        dostep = 1;
        continue;
      }
    }
  }
  return pos;
}
long long blazing(long long n, long long m, long long s, long long t) {
  vector<long long> sqrt(n, -1);
  for (long long a = 0; a < n; a++) {
    sqrt[(a * a) % n] = a;
  }
  if (m > n - m) {
    long long g = (n - 1 - s);
    g %= n;
    if (g < 0) g += n;
    long long ans = blazing(n, n - m, g, t);
    ans = (n - 1 - ans);
    ans %= n;
    if (ans < 0) ans += n;
    return ans;
  }
  long long a = s;
  long long curt = t;
  while (1) {
    if (a < m) {
      a += curt;
    } else {
      a -= curt;
    }
    a %= n;
    if (a < 0) a += n;
    curt--;
    if (curt % n == 0) break;
  }
  long long rounds = curt / n;
  map<long long, long long> occ;
  long long pos = a;
  while (rounds > 0) {
    long long cur = 1;
    if (occ.find(pos) != occ.end()) {
      long long period = occ[pos] - rounds;
      rounds %= period;
    }
    occ[pos] = rounds;
    if (rounds > 0) {
      while (cur < n) {
        if (pos < m) {
          pos -= cur;
        } else {
          pos += cur;
        }
        pos %= n;
        if (pos < 0) pos += n;
        cur++;
      }
      rounds--;
    }
  }
  return pos;
}
void test() {
  for (long long n = 3; n <= 15; n++) {
    for (long long m = 1; m < n; m++) {
      for (long long s = 0; s < n; s++) {
        for (long long t = 1; t <= 15 * n; t++) {
          assert(blazing(n, m, s, t) == fast(n, m, s, t));
        }
      }
    }
  }
  cerr << "tested" << endl;
}
int main() {
  long long n, m, s, t;
  cin >> n >> m >> s >> t;
  s = s - 1;
  cout << blazing(n, m, s, t) + 1 << '\n';
}
