Having problems with tram routes in the morning, Arkady decided to return home by metro. Fortunately for Arkady, there is only one metro line in the city.Unfortunately for Arkady, the line is circular. It means that the stations are enumerated from $$$1$$$ to $$$n$$$ and there is a tunnel between any pair of consecutive stations as well as between the station $$$1$$$ and the station $$$n$$$. Trains that go in clockwise direction visit the stations in order $$$1 \to 2 \to 3 \to \ldots \to n \to 1$$$ while the trains that go in the counter-clockwise direction visit the stations in the reverse order.The stations that have numbers from $$$1$$$ to $$$m$$$ have interior mostly in red colors while the stations that have numbers from $$$m + 1$$$ to $$$n$$$ have blue interior. Arkady entered the metro at station $$$s$$$ and decided to use the following algorithm to choose his way home.  Initially he has a positive integer $$$t$$$ in his mind.  If the current station has red interior, he takes a clockwise-directed train, otherwise he takes a counter-clockwise-directed train.  He rides exactly $$$t$$$ stations on the train and leaves the train.  He decreases $$$t$$$ by one. If $$$t$$$ is still positive, he returns to step $$$2$$$. Otherwise he exits the metro. You have already realized that this algorithm most probably won't bring Arkady home. Find the station he will exit the metro at so that you can continue helping him.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$3 \le n \le 10^5$$$, $$$1 \le m < n$$$) — the total number of stations and the number of stations that have red interior. The second line contains two integers $$$s$$$ and $$$t$$$ ($$$1 \le s \le n$$$, $$$1 \le t \le 10^{12}$$$) — the starting station and the initial value of $$$t$$$.

Output the only integer — the station where Arkady will exit the metro.

NoteConsider the first example. There are $$$10$$$ stations and the first $$$4$$$ of them are red. Arkady starts at station $$$3$$$ with value $$$t = 1$$$, so just rides $$$1$$$ station in clockwise direction and ends up on the station $$$4$$$.In the second example the metro is same as in the first example, but Arkady starts at station $$$3$$$ with value $$$t = 5$$$.   It is a red station so he rides $$$5$$$ stations in clockwise direction and leaves the train at station $$$8$$$.  It is a blue station, so he rides $$$4$$$ stations in counter-clockwise direction and leaves at station $$$4$$$.  It is a red station, so he rides $$$3$$$ stations in clockwise direction and leaves at station $$$7$$$.  It is a blue station, so he rides $$$2$$$ stations in counter-clockwise direction and leaves at station $$$5$$$.  It is a blue station, so he rides $$$1$$$ station in counter-clockwise direction and leaves at station $$$4$$$.  Now $$$t = 0$$$, so Arkady exits metro at the station $$$4$$$.

#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
#define SIZE 100005
#define BB 2*1024*128*2
#define MX 5
#define BT 45

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

struct segtree
{
	int seg[BB];
	int mum;

	void init(int n)
	{
		mum=1;
		while(mum<n) mum<<=1;
		for(int i=0;i<mum*2;i++) seg[i]=-1;
	}
	void add(int k,int x)
	{
		k+=mum-1;
		seg[k]=max(seg[k],x);
		while(k>0)
		{
			k=(k-1)/2;
			seg[k]=max(seg[k*2+1],seg[k*2+2]);
		}
	}
	int get(int a,int b,int k,int l,int r)
	{
		if(b<=l||r<=a) return -1;
		if(a<=l&&r<=b) return seg[k];
		else
		{
			int vl=get(a,b,k*2+1,l,(l+r)/2);
			int vr=get(a,b,k*2+2,(l+r)/2,r);
			return max(vl,vr);
		}
	}
	int get(int a,int b)
	{
		return get(a,b,0,0,mum);
	}
}seg;
int n,m,s;
ll T;
P to[MX][SIZE][BT];
ll len[MX][SIZE][BT];
vector <int> vx;

int get_p(int x){return lower_bound(vx.begin(),vx.end(),x)-vx.begin();}
int main()
{
	scanf("%d %d",&n,&m);m--;
	scanf("%d %lld",&s,&T);s--;
	vx.push_back(m);
	vx.push_back(m+1);
	vx.push_back(s);
	sort(vx.begin(),vx.end());
	vx.erase(unique(vx.begin(),vx.end()),vx.end());
	for(int i=0;i<vx.size();i++)
	{
		int x=vx[i];
		seg.init(2*n+2);
		for(int j=0;j<n;j++)
		{
			if(j==0)
			{
				to[i][j][0]=P(i,n-1);
				len[i][j][0]=1;
				seg.add(0,0);
				seg.add(n,0);
			}
			else if(x<=m)
			{
				int v=(int) (((ll) j*(ll) (j+1)/2LL)%n);
				int l=m+1,r=n-1;
				int a=x+v-r,b=x+v-l;
				if(a<0) a+=n,b+=n;
				int g=seg.get(a,b+1);
				if(g==-1)
				{
					to[i][j][0]=P(i,n-j-1);
					len[i][j][0]=2*j+1;
				}
				else
				{
					int u=(int) (((ll) g*(ll) (g+1)/2LL)%n);
					int t=x+v-u;
					if(t<0) t+=n;
					if(t>=n) t-=n;
					int s=t-g-1;
					if(s<0) s+=n;
					//�E�����ł̕ω�
					if(m-s<=t-m-1)
					{
						int p=get_p(m+1);
						if(m-s<t-m-1)
						{
							len[i][j][0]=(j-g-1)+2*(m-s)+2;
							to[i][j][0]=P(p,j-len[i][j][0]);
						}
						else
						{
							len[i][j][0]=(j-g-1)+2*(m-s)+1;
							to[i][j][0]=P(p,j-len[i][j][0]);
						}
					}
					else
					{
						int p=get_p(m+1);
						len[i][j][0]=(j-g-1)+2*(t-m-1)+1;
						to[i][j][0]=P(p,j-len[i][j][0]);
					}
				}
				seg.add(v,j);
				seg.add(v+n,j);
			}
			else
			{
				int v=(int) (((ll) j*(ll) (j+1)/2LL)%n);
				int l=0,r=m;
				int a=l+v-x,b=r+v-x;
				if(a<0) a+=n,b+=n;
				int g=seg.get(a,b+1);
				if(g==-1)
				{
					to[i][j][0]=P(i,n-j-1);
					len[i][j][0]=2*j+1;
				}
				else
				{
					int u=(int) (((ll) g*(ll) (g+1)/2LL)%n);
					int t=x-v+u;
					if(t<0) t+=n;
					if(t>=n) t-=n;
					int s=t+g+1;
					if(s>=n) s-=n;
					//�������ł̕ω�
					if(s-m-1<=m-t)
					{
						int p=get_p(m);
						if(s-m-1<m-t)
						{
							len[i][j][0]=(j-g-1)+2*(s-m-1)+2;
							to[i][j][0]=P(p,j-len[i][j][0]);
						}
						else
						{
							len[i][j][0]=(j-g-1)+2*(s-m-1)+1;
							to[i][j][0]=P(p,j-len[i][j][0]);
						}
					}
					else
					{
						int p=get_p(m);
						len[i][j][0]=(j-g-1)+2*(m-t)+1;
						to[i][j][0]=P(p,j-len[i][j][0]);
					}
				}
				seg.add(v,j);
				seg.add(v+n,j);
			}
		}
	}
	for(int i=0;i+1<BT;i++)
	{
		for(int j=0;j<vx.size();j++)
		{
			for(int k=0;k<n;k++)
			{
				P p=to[j][k][i];
				to[j][k][i+1]=to[p.first][p.second][i];
				len[j][k][i+1]=len[j][k][i]+len[p.first][p.second][i];
				len[j][k][i+1]=min(len[j][k][i+1],T+1);
			}
		}
	}
	for(int i=0;i<vx.size();i++)
	{
		if(vx[i]==s)
		{
			s=i;
			break;
		}
	}
	for(int i=BT-1;i>=0;i--)
	{
		if(len[s][T%n][i]<=T)
		{
			//printf("%d %lld %d : %lld\n",s,T,i,len[s][T%n][i]);
			P p=to[s][T%n][i];
			T-=len[s][T%n][i];
			s=p.first;
		}
	}
	s=vx[s];
	//printf("%d %lld\n",s,T);
	while(T>0)
	{
		if(s<=m) s+=T%n;
		else s-=T%n;
		if(s>=n) s-=n;
		if(s<0) s+=n;
		T--;
	}
	printf("%d\n",s+1);
	return 0;
}

#include <bits/stdc++.h>

typedef long long LL;
int n, m, s; LL t;

std::map<std::pair<int, LL>, int> map;

int walk(int s) {
	int &r = map[{s, 1}] = s;
	for (int i = n - 1; i; --i)
		if (r < m) r = (r + i) % n;
		else r = (r + n - i) % n;
	return r;
}
int run(int s, LL times) {
	if (map.count({s, times})) return map[{s, times}];
	if (!times) return s; if (times == 1) return walk(s);
	return map[{s, times}] = run(run(s, times >> 1), times + 1 >> 1);
}
int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n >> m >> s >> t, --s;
	while (t % n) {
		if (s < m) s = (s + t--) % n;
		else s = (s + n - t-- % n) % n;
	}
	std::cout << run(s, t / n) + 1 << '\n';
	return 0;
}

#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;

typedef long long ll;
const int Maxn = 1e5;

struct NonRotateTreap {
	struct TreapNode {
		int key, siz, fix;
		TreapNode *lch, *rch;
	};
	TreapNode pool[Maxn * 25 + 5];
	TreapNode *NIL, *ncnt;
	typedef pair<TreapNode *, TreapNode *> Droot;
	void init() {
		ncnt = NIL = &pool[0];
		NIL->lch = NIL->rch = NIL;
		NIL->siz = 0, NIL->fix = 0, NIL->key = 0;
	}
	void pushup(TreapNode *rt) {
		rt->siz = rt->lch->siz + rt->rch->siz + 1;
	}
	TreapNode *newnode(TreapNode *rt) {
		TreapNode *p = ++ncnt;
		(*p) = (*rt);
		return p;
	}
	TreapNode *newnode(int val) {
		TreapNode *p = ++ncnt;
		p->key = val, p->siz = 1, p->fix = rand();
		p->lch = p->rch = NIL;
		return p;
	}
	TreapNode *merge(TreapNode *rt1, TreapNode *rt2) {
		if(rt1 == NIL) return rt2;
		if(rt2 == NIL) return rt1;
		TreapNode *t;
		if(rt1->fix <= rt2->fix) {
			t = newnode(rt1);
			t->rch = merge(rt1->rch, rt2);
			pushup(t);
		} else {
			t = newnode(rt2);
			t->lch = merge(rt1, rt2->lch);
			pushup(t);
		}
		return t;
	}
	Droot split_rnk(TreapNode *rt, int k) {
		Droot d(NIL, NIL);
		if(rt == NIL) return d;
		TreapNode *p = newnode(rt);
		if(k <= rt->lch->siz) {
			d = split_rnk(rt->lch, k);
			p->lch = d.second;
			d.second = p;
		} else {
			d = split_rnk(rt->rch, k - rt->lch->siz - 1);
			p->rch = d.first;
			d.first = p;
		}
		pushup(p);
		return d;
	}
	TreapNode *build(int *f, int l, int r) {
		if(l > r) return NIL;
		int mid = (l + r) >> 1;
		TreapNode *p = newnode(f[mid]);
		p->lch = build(f, l, mid - 1);
		p->rch = build(f, mid + 1, r);
		pushup(p);
		return p;
	}
	void trans(TreapNode *rt, int *f, int k) {
		if(rt == NIL) return;
		f[rt->lch->siz + 1 + k] = rt->key;
		trans(rt->lch, f, k);
		trans(rt->rch, f, k + rt->lch->siz + 1);
	}
	TreapNode *rebuild(int *f, int n, TreapNode *root) {
		trans(root, f, 0);
		ncnt = &pool[0];
		return build(f, 1, n);
	}
};
NonRotateTreap::TreapNode *root;
NonRotateTreap tree;

int f[Maxn + 5];
int nxt[42][Maxn + 5];

int main() {
#ifdef LOACL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	srand(20192813);
	int N, M, S;
	ll T;
	scanf("%d %d %d %lld", &N, &M, &S, &T);
	for(int i = 1; i <= N; i++)
		f[i] = i;
	tree.init();
	root = tree.build(f, 1, N);
	for(int i = 1; i <= N; i++) {
		if(i % 150 == 0)
			root = tree.rebuild(f, N, root);
		NonRotateTreap::TreapNode *p, *q, *tmp;
		tmp = tree.split_rnk(root, i).second;
		if(tmp->siz >= M)
			p = tree.split_rnk(tmp, M).first;
		else p = tree.merge(tmp, tree.split_rnk(root, M - tmp->siz).first);
		tmp = tree.split_rnk(root, N - i).first;
		if(tmp->siz >= N - M)
			q = tree.split_rnk(tmp, tmp->siz - (N - M)).second;
		else q = tree.merge(tree.split_rnk(root, N - ((N - M) - tmp->siz)).second, tmp);
		root = tree.merge(p, q);
	}
	tree.trans(root, f, 0);
	while(T % N) {
		if(S <= M) S = (S - 1 + T) % N + 1;
		else S = ((S - 1 - T) % N + N) % N + 1;
		T--;
	}
	for(int i = 1; i <= N; i++)
		nxt[0][i] = f[i];
	for(int j = 1; j <= 41; j++)
		for(int k = 1; k <= N; k++)
			nxt[j][k] = nxt[j - 1][nxt[j - 1][k]];
	ll tmp = T / N;
	for(int i = 41; i >= 0; i--)
		if((1LL << i) & tmp) S = nxt[i][S];
	printf("%d\n", S);
	return 0;
}

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

ll readint(){
	ll x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

ll n,m,s,t;
ll g[100005];
map<ll,int> d[100005];

int ask(ll x){
	if(g[x]!=-1) return g[x];
	ll tmp=x;
	for(int i=n;i>=1;i--){
		if(x<m) x=(x+i)%n;
		else x=(x-i+n)%n;
	}
	return g[tmp]=x;
}

int work(ll x,ll k){
	if(k==0) return x;
	if(k==1) return ask(x);
	if(d[x].count(k)) return d[x][k];
	return d[x][k]=work(work(x,k/2),k-k/2);
}

int main(){
	n=readint(); m=readint(); s=readint()-1; t=readint();
	while(t%n!=0){
		if(s<m) s=(s+t%n)%n;
		else s=(s-t%n+n)%n;
		t--;
	}
	memset(g,-1,sizeof(g));
	printf("%d\n",work(s,t/n)+1);
	return 0;
}

#pragma comment(linker, "/STACK:512000000")
#define _CRT_SECURE_NO_WARNINGS
//#include "testlib.h"
#include <bits/stdc++.h>
#ifdef AIM
#include <sys/resource.h>
#endif
using namespace std;

#define all(a) a.begin(), a.end()
using li = long long;
using ld = long double;
void solve(bool);
void precalc();
clock_t start;
int main() {
#ifdef AIM
  freopen("/home/alexandero/CLionProjects/ACM/input.txt", "r", stdin);
  //freopen("/home/alexandero/CLionProjects/ACM/output.txt", "w", stdout);
//freopen("out.txt", "w", stdout);
#else
  //freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif

#ifdef AIM
  const rlim_t kStackSize = 256 * 1024 * 1024;
  struct rlimit rl;
  int result;

  result = getrlimit(RLIMIT_STACK, &rl);
  if (result == 0) {
    if (rl.rlim_cur < kStackSize) {
      rl.rlim_cur = kStackSize;
      result = setrlimit(RLIMIT_STACK, &rl);
      if (result != 0) {
        fprintf(stderr, "setrlimit returned result = %d\n", result);
      }
    }
  }
#endif

  start = clock();
  int t = 1;
#ifndef AIM
  cout.sync_with_stdio(0);
  cin.tie(0);
#endif
  cout.precision(20);
  cout << fixed;
  //cin >> t;
  precalc();
  while (t--) {
    solve(true);
  }
  cout.flush();

#ifdef AIM1
  while (true) {
    solve(false);
  }
#endif

#ifdef AIM
  cerr << "\n\n time: " << (clock() - start) / 1.0 / CLOCKS_PER_SEC << "\n\n";
#endif
  return 0;
}

//BE CAREFUL: IS INT REALLY INT?

template<typename T>
T binpow(T q, T w, T mod) {
  if (!w)
    return 1 % mod;
  if (w & 1)
    return q * 1LL * binpow(q, w - 1, mod) % mod;
  return binpow(q * 1LL * q % mod, w / 2, mod);
}

template<typename T>
T gcd(T q, T w) {
  while (w) {
    q %= w;
    swap(q, w);
  }
  return q;
}
template<typename T>
T lcm(T q, T w) {
  return q / gcd(q, w) * w;
}

template <typename T>
void make_unique(vector<T>& vec) {
  sort(all(vec));
  vec.erase(unique(all(vec)), vec.end());
}

template<typename T>
void relax_min(T& cur, T val) {
  cur = min(cur, val);
}

template<typename T>
void relax_max(T& cur, T val) {
  cur = max(cur, val);
}

mt19937 rng((unsigned long long)chrono::steady_clock::now().time_since_epoch().count());

void precalc() {

}

#define int li
//const li mod = 1000000007;
//const int mod = 998244353;
//using ull = unsigned long long;

void solve(__attribute__((unused)) bool read) {

  int n, m;int s, t;
  if (read) {
    cin >> n >> m;
    cin >> s >> t;
    --s;
  } else {
    n = rand() % 100000 + 3;
    m = rand() % (n - 1) + 1;
    s = rand() % n;
    t = (rand() * (1LL << 32) + rand()) % 1000000000000LL + 1;
  }
  auto make_move = [&] () {
    int shift = t % n;
    if (s >= m) {
      shift = (n - shift) % n;
    }
    s = (s + shift) % n;
    --t;
  };
  vector<int> gone(n, -1);
  while (t % n) {
    make_move();
  }
  int iters = 0;
  vector<int> used_time(n, -1);
  int cycle = -1;
  while (t > 0) {
    int cur = s;
    if (gone[cur] != -1) {
      if (cycle == -1) {
        cycle = used_time[cur] - t;
        t %= cycle;
      } else {
        t -= n;
        s = gone[cur];
      }
      continue;
    }
    used_time[cur] = t;
    ++iters;
    for (int i = 0; i < n; ++i) {
      make_move();
    }
    gone[cur] = s;
  }

  //cerr << "iters: " << iters << endl;

  cout << s + 1 << endl;

}

#include<cstdio>
#include<algorithm>
#include<iostream>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std;

const int N=100010;
ll t;
int n,m,s,nd,rt,tot,to[N][50];
struct Tr{ int ls,rs,v,sz; }v[N<<8];
struct P{ int x,y; };

int jump(ll x,ll y){
	if (x<=m) x+=y; else x-=y;
	return (x%n+n-1)%n+1;
}

void upd(int x){ v[x].sz=v[v[x].ls].sz+v[v[x].rs].sz+1; }
int get(int k){ v[++nd]=(Tr){0,0,k,1}; return nd; }
void dfs(int x){ if (v[x].ls) dfs(v[x].ls); to[++tot][0]=v[x].v; if (v[x].rs) dfs(v[x].rs); }
void Print(int x){ if (v[x].ls) Print(v[x].ls); printf("%d ",v[x].v); if (v[x].rs) Print(v[x].rs); }

int merge(int x,int y){
	if (!x || !y){ v[++nd]=v[x|y]; return nd; }
	int p=++nd;
	if (1ll*rand()*(v[x].sz+v[y].sz)<1ll*v[x].sz*RAND_MAX)
		{ v[p]=v[x]; v[p].rs=merge(v[p].rs,y); upd(p); return p; }
	else{ v[p]=v[y]; v[p].ls=merge(x,v[p].ls); upd(p); return p; }
}

P split(int x,int k){
	if (!x) return (P){0,0};
	P t; int p=++nd; v[p]=v[x];
	if (k<=v[v[x].ls].sz){ t=split(v[p].ls,k); v[p].ls=t.y; upd(p); return (P){t.x,p}; }
		else{ t=split(v[p].rs,k-v[v[x].ls].sz-1); v[p].rs=t.x; upd(p); return (P){p,t.y}; }
}

int build(int L,int R){
	if (L>R) return 0;
	int mid=(L+R)>>1,x=get(to[mid][0]);
	v[x].ls=build(L,mid-1); v[x].rs=build(mid+1,R);
	upd(x); return x;
}

int main(){
	scanf("%d%d%d",&n,&m,&s); cin>>t; int lim=20000;
	for (; t%n; t--) s=jump(s,t); t/=n;
	rep(i,1,n) to[i][0]=i; rt=build(1,n);
	rep(i,1,n-1){
		int lst=rt;
		if (m+i<=n){ P a=split(lst,m+i),b=split(a.x,i); rt=b.y; }
			else{ P a=split(lst,i),b=split(a.x,m+i-n); rt=merge(a.y,b.x); }
		if (m+1-i>0){ P a=split(lst,n-i),b=split(a.x,m-i); rt=merge(rt,b.y); }
			else{ P a=split(lst,m+n-i),b=split(a.x,n-i); rt=merge(rt,merge(a.y,b.x)); }
		if (!(i%lim)) tot=0,dfs(rt),nd=0,rt=build(1,n);
	}
	tot=0; dfs(rt);
	rep(j,1,49) rep(i,1,n) to[i][j]=to[to[i][j-1]][j-1];
	for (int j=49; ~j; j--) if (t&(1ll<<j)) s=to[s][j];
	printf("%d\n",s);
	return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
const int N=100005;
int n,m,s;
int mat[N];
ll t,T[N];
int main(){
	scanf("%d%d",&n,&m);
	scanf("%d%lld",&s,&t);
	for (;t%n;s=(s+n+(s<=m?t:-t)%n-1)%n+1,t--);
	for (;t;t-=n){
		if (mat[s]){
			if (!T[s]) T[s]=t/n;
			else if (t/n>n) t=((t/n-1)%(T[s]-t/n)+1)*n;
			s=mat[s];
		}
		else{
			int p=s;
			Rep(i,n,1) s=(s+n+(s<=m?i:-i)%n-1)%n+1;
			mat[p]=s;
		}
	}
	printf("%d",s);
}

#define _CRT_SECURE_NO_DEPRECATE
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <memory.h>
#include <set>
#include <ctime>
#include <map>
#include <cstring>
#include <iterator>
#include <queue>
#include <assert.h>
#include <bitset>
#include <complex>
#include <unordered_map>

//#pragma comment(linker, "/STACK:512000000")

using namespace std;

#define pb emplace_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define forab(i, a, b) for (int i = (a); i < (b); ++i)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int infi = 1e9 + 7;
const ll infl = (ll)1e18 + (ll)7;

struct node {
    node* l, *r;
    int sz, a;
    node() {}
    node(int _a) : a(_a), sz(1), l(0), r(0) {}
    node(node* other) : a(other->a), l(other->l), r(other->r), sz(other->sz) {}
};
typedef node* pnode;
const int max_cnt = 4e7;
int cur_cnt;
node buf_node[max_cnt];
pnode new_node(int a) {
   // return new node(a);
    buf_node[cur_cnt] = node(a);
    return &buf_node[cur_cnt++];
}
pnode new_node(pnode a) {
    if (cur_cnt == max_cnt) {
        cout << "123";
        exit(0);
    }
  //  return new node(a);
    buf_node[cur_cnt] = node(a);
    return &buf_node[cur_cnt++];
}
void upd(pnode v) {
    if (!v)
        return;
    v->sz = 1;
    if (v->l)
        v->sz += v->l->sz;
    if (v->r)
        v->sz += v->r->sz;
}
pnode merge(pnode l, pnode r) {
    if (!l || !r)
        return max(l, r);
    int q = l->sz, w = r->sz;
    int rang = rand() % (q + w);
    if (rang >= w) {
        pnode ans = new_node(l);
        ans->r = merge(l->r, r);
        upd(ans);
        return ans;
    } else {
        pnode ans = new_node(r);
        ans->l = merge(l, r->l);
        upd(ans);
        return ans;
    }
}
int get_size(pnode v) {
    if (v)
        return v->sz;
    return 0;
}
void split(pnode t, pnode& l, pnode& r, int sz) {
    if (!t) {
        l = r = 0;
        return;
    }
    pnode cur = new_node(t);
    int q = get_size(cur->l) + 1;
    if (q <= sz) {
        split(cur->r, cur->r, r, sz - q);
        l = cur;
    } else {
        split(cur->l, l, cur->l, sz);
        r = cur;
    }
    upd(l);
    upd(r);
}
pnode fast_add(pnode t, pnode v, int sz) {
    if (!t) {
        return v;
    }
    int q = t->sz, w = 1;
    int rang = rand() % (q + w);
    if (rang >= q) {
        split(t, v->l, v->r, sz);
        upd(v);
        return v;
    }
    q = get_size(t->l) + 1;
    pnode nt = new_node(t);
    if (q <= sz) {
        nt->r = fast_add(t->r, v, sz - q);
    } else
        nt->l = fast_add(t->l, v, sz);
    upd(nt);
    return nt;
}
pnode add(pnode t, int a, int sz) {
    return fast_add(t, new_node(a), sz);
}

pnode cut(pnode t, int l, int r, int n) {
    if (l < 0 && r < 0)
        l += n, r += n;
    if (l >= n && r >= n)
        l -= n, r -= n;
    pnode L, MID, R;
    if (0 <= l && r < n) {
        split(t, L, R, r + 1);
        split(L, L, MID, l);
        return MID;
    }
    if (r >= n)
        r -= n, l -= n;
    if (l < 0) {
        split(t, L, R, n + l);
        split(L, L, MID, r + 1);
        return merge(R, L);
    }
}

int find(pnode t, int pos) {
    int q = get_size(t->l);
    if (q == pos)
        return t->a;
    if (pos < q)
        return find(t->l, pos);
    else
        return find(t->r, pos - q - 1);
}
pnode ver[100500];

int to[100500];
int used[100500];
int cur_time = 5;
int dfs(int v, ll t) {
    while (t) {
        if (!used[v]) {
            used[v] = cur_time++;
            --t;
            v = to[v];
            continue;
        }
        int len = abs(cur_time++ - used[v]);
        if (t > 1e6)
            t %= len;
        if (t == 0)
            break;
        --t;
        v = to[v];
    }
    return v;
}
int get_h(pnode t) {
    if (!t)
        return 0;
    return max(
        get_h(t->l), get_h(t->r)
    ) + 1;
}

int ar[100500];
pnode rebuild(pnode t, int n) {
    forn(i, n)
        ar[i] = find(t, i);
    cur_cnt = 0;
    t = 0;
    forn(i, n)
        t = add(t, ar[i], i);
    return t;
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    //freopen("customs.in", "r", stdin); freopen("customs.out", "w", stdout);
    srand(time(NULL));
    int n, m;
    cin >> n >> m;
    int s;
    ll t;
    cin >> s >> t;
    --s;
    pnode start = 0;
    forn(i, n) {
        start = add(start, i, i);
       // cerr << int(cur_cnt / 1e6) << '\n';
    }
    ver[0] = start;
    ll t1 = t % n;
    for (int i = 1; i <= t1; ++i) {
        ver[i] = merge(
            cut(ver[i - 1], i, m + i - 1, n),
            cut(ver[i - 1], m - i, n - 1 - i, n)
        );
        if (cur_cnt >= 3e7) {
            ver[i] = rebuild(ver[i], n);
        }
    }
    int s1 = find(ver[t1], s);
    for (int i = t1 + 1; i <= n; ++i) {
        ver[i] = merge(
            cut(ver[i - 1], i, m + i - 1, n),
            cut(ver[i - 1], m - i, n - 1 - i, n)
        );
        if (cur_cnt >= 3e7) {
            ver[i] = rebuild(ver[i], n);
        }
    }

    forn(i, n)
        to[i] = find(ver[n], i);
    cout << dfs(s1, t / n)  + 1<< '\n';
  //   cout << cur_cnt << endl;
    cerr << 1.0 * clock() / CLOCKS_PER_SEC;

    return 0;
}

/*
    Author: isaf27 (Ivan Safonov)
*/

#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

//defines
typedef long long ll;
typedef long double ld;
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define what_is(x) cerr << #x << " is " << x << endl
#define solve_system int number; cin >> number; for (int i = 0; i < number; i++) solve()
#define solve_system_scanf int number; scanf("%d", &number); for (int i = 0; i < number; i++) solve()

//permanent constants
const ld pi = acos(-1.0);
const ld log23 = 1.58496250072115618145373894394781;
const ld eps = 1e-8;
const ll INF = 1e13 + 239;
const ll prost = 239;
const int two = 2;
const int th = 3;
const ll MOD = 1e9 + 7; //998244353;
const ll MOD2 = MOD * MOD;
const int BIG = 1e9 + 239;
const int alf = 26;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dxb[4] = {-1, 1, 1, -1};
const int dyb[4] = {-1, 1, -1, 1};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int dig = 10;
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const ll bt = 30;

//easy functions
template< typename T >
inline T gcd(T a, T b)
{
    while (a)
    {
        b %= a;
        swap(a, b);
    }
    return b;
}
template< typename T >
inline T lcm(T a, T b) { return (a / gcd(a, b)) * b; }
inline bool is_down(char x) { return ('a' <= x && x <= 'z'); }
inline bool is_upper(char x) { return ('A' <= x && x <= 'Z'); }
inline bool is_digit(char x) { return ('0' <= x && x <= '9'); }

//random
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
//mt19937_64 rnd(239);

//constants
const int M = 1e5 + 239;
const int N = 110;
const int L = 19;
const int T = (1 << 19);
const int B = trunc(sqrt(M)) + 1;
const int X = 1010;

int n, m;
ll t, was[M];

void func(int &s)
{
    if (s < m)
        s = ((ll)s + (ll)t) % (ll)n;
    else
        s = ((ll)s - (ll)t) % (ll)n;
    if (s < 0) s += n;
    t--;
}

int main()
{
    #ifdef ONPC
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    memset(was, -1, sizeof(was));
    int s;
    cin >> n >> m >> s >> t;
    s--;
    while (t)
    {
        if (was[s] != -1) t %= (was[s] - t);
        was[s] = t;
        if (t < n)
        {
            while (t) func(s);
            break;
        }
        for (int i = 0; i < n; i++)
            func(s);
    }
    cout << (s + 1);
    return 0;
}

#include<ctime>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define fo(i, x, y) for(int i = x, B = y; i <= B; i ++)
#define ff(i, x, y) for(int i = x, B = y; i <  B; i ++)
#define fd(i, x, y) for(int i = x, B = y; i >= B; i --)
#define pp printf
#define ll long long
#define ul unsigned long long
using namespace std;

const int N = 1e5 + 5;

const int M = N * 667;

int t[M][2], c[2], siz[M], tt, z[M], rt;

ul rd = 19260817;
ul rad() {
	rd *= 1000000007;
	return rd;
}
#define x0 t[x][0]
#define x1 t[x][1]
int xin(int &x) {
	if(!x) return 0;
	z[++ tt] = z[x]; siz[tt] = siz[x];
	t[tt][0] = t[x][0]; t[tt][1] = t[x][1];
	return x = tt;
}
void upd(int x) {
	if(x) siz[x] = siz[x0] + siz[x1] + 1;
}
void split(int x, int k) {
	if(k == siz[x]) {c[0] = x; c[1] = 0; return;}
	if(!k) { c[0] = 0; c[1] = x; return;}
	int z = k > siz[x0];
	split(xin(t[x][z]), k - z * (siz[x0] + 1));
	t[x][z] = c[!z]; c[!z] = x; upd(x);
}
int merge(int a, int b) {
	if(!a || !b) return a + b;
	if(rad() % (siz[a] + siz[b]) < siz[a]) {
		t[a][1] = merge(xin(t[a][1]), b);
		upd(a); return a;
	} else {
		t[b][0] = merge(a, xin(t[b][0]));
		upd(b); return b;
	}
}

int d[N];

void dg(int x) {
	if(!x) return;
	dg(x0); d[++ d[0]] = z[x]; dg(x1);
}

int fen(int x, int y) {
	int R = rt;
	split(xin(rt), x - 1);
	split(c[1], y - x + 1);
	rt = R;
	return c[0];
}

int n, m, st; ll tim;

int f[N];

int bz[N];

int dfs(int x, int y) {
	if(x > y) return 0;
	int m = x + y >> 1;
	z[++ tt] = d[m]; int p = tt;
	t[p][0] = dfs(x, m - 1);
	t[p][1] = dfs(m + 1, y);
	upd(p);
	return p;
}

int main() {
	srand(time (0));
	scanf("%d %d", &n, &m);
	fo(i, 1, n) d[i] = i;
	rt = dfs(1, n);
	fo(t, 1, n - 1) {
//		pp("%d %d\n", dep[rt], t);
		int c0 = 0, c1 = 0, c2 = 0, c3 = 0;
		c0 = fen(1 + t, min(m + t, n));
		if(m + t > n) c1 = fen(1, (m + t) % n);
		if(m + 1 - t < 1) c2 = fen(m + 1 - t + n, n);
		c3 = fen(max(1, m + 1 - t), n - t);
		rt = merge(c0, c1);
		c2 = merge(c2, c3);
		rt = merge(rt, c2);
		if(t % 5000 == 0) {
			d[0] = 0; dg(rt);
			rt = dfs(1, n);
		}
	}
	fo(i, 1, n) {
		split(rt, 1);
		rt = c[1];
		f[i] = z[c[0]];
	}
//	fo(i, 1, n) pp("%d ", f[i]); pp("\n");
	scanf("%d %I64d", &st, &tim);
	int x = st;
	fd(i, tim % n, 1) {
		if(x <= m) x = (x + i - 1) % n + 1; else
		x = (x - i), x <= 0 ? x += n : 0;
	}
	ll c = tim / n;
	for(ll i = 1; i <= c; i ++) {
		if(bz[x]) {
			i = i + (c - i) / (i - bz[x]) * (i - bz[x]);
			while(i <= c) i ++, x = f[x];
			break;
		}
		bz[x] = i; x = f[x];
	}
	pp("%d\n", x);
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
int vis[123456];
main()
{
	int n,m,s,t;
	scanf("%lld %lld %lld %lld",&n,&m,&s,&t);
	m--;
	s--;
	int x = t%n;
	for(int i = x;i>0;i--)
	{
		if(s<=m) s+=i;
		else s-=i;
		s = s%n + n;
		s %= n;
	}
	int cur = 0;
	int ans = 0;
	int pos = s;
	int ppp;
	while(true)
	{
		if(vis[s]!=0)
		{
			ans = cur - vis[s];
			ppp = vis[s];
			break;
		}
		vis[s] = cur++;
		for(int i = n;i>0;i--)
		{
			if(s<=m) s+=i;
			else s-=i;
			s = s%n + n;
			s %= n;
		}
	}
	t /= n;
	if(!t){}
	else if(t<=ppp)
	{
		for(int i = 0;i<n;i++)
		{
			if(vis[i]==t) pos = i;
		}
	}
	else
	{
		t-= ppp;
		t%= ans;
		for(int i = 0;i<n;i++)
		{
			if(vis[i]==t+ppp) pos = i;
		}
	}
	printf("%lld\n",pos+1);

	return 0;
}

/*
   We notice that there are only N^2 important states - (postition, t mod N). Let's make T mod N steps and see where we will be after that. This can be done in the most stupid way in O(N) time.
   Also let's for each position store the position we will arrive at after N steps. If this value for position x is to[x] the answer of our problem will be to[to[...[x]...]] (applied T / N times).
   Then after calculating the to[] array, we can simply find the cycle length of to[] and the reminder of (T / N) when divided by it. Then (T / N) <= N and we can easily find the answer in O(N).

   Now the hard part is to find the to[] array. We will go backwards. Initially set to[x] = x. Now we will use persistent treap (actually RBST) to find the actual to values. The main observation
   is that when decreasing T the to[] array will change just in two intervals. Then we can do the movements with a couple of merges and splits. The complexity will be O(N log N).

   As persistent treaps (RBST) tend to to increase their depth fast, we will rebuild our structure a couple of times.
*/

#include <bits/stdc++.h>
#define endl '\n'

//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#define SZ(x) ((int)x.size())
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back

using namespace std;
template<class T, class T1> int chkmax(T &x, const T1 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T1> int chkmin(T &x, const T1 &y) { return x > y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);
const int MAX_MEM = (1 << 23);
const int B = 5000;

random_device rd;
mt19937 mt(rd());

struct node
{
	int sz, id;
	node *l, *r;

	node() { sz = id = 0; l = r = nullptr; }
	node(int i)
	{
		l = nullptr;
		r = nullptr;
		id = i;
		sz = 1;
	}
};

using pnode = node*;

int cnt_nodes = 0;
pnode ptr_list[MAX_MEM];

void init_memory()
{
	cnt_nodes = 0;
	for(int i = 0; i < MAX_MEM; i++)
		ptr_list[i] = new node();
}

pnode new_node(int id)
{
	ptr_list[cnt_nodes]->l = ptr_list[cnt_nodes]->r = nullptr;
	ptr_list[cnt_nodes]->sz = 1, ptr_list[cnt_nodes]->id = id;
	return ptr_list[cnt_nodes++];
}

inline int size(pnode t) { return t ? t->sz : 0; }

bool hey(int l, int r) { return (int)mt() % (l + r) < l; }

void pull(pnode &t)
{
	if(!t) return;
	t->sz = 1 + size(t->l) + size(t->r);
}

pnode copy(pnode &t)
{
	if(!t) return nullptr;

	pnode ret = new_node(0);
	ret->id = t->id;
	ret->l = t->l;
	ret->r = t->r;
	ret->sz = t->sz;

	return ret;
}

void split(pnode t, pnode &l, pnode &r, int k, int add = 0)
{
	if(!t) { l = r = nullptr; return; }

	int idx = size(t->l) + add;
	if(idx <= k)
	{
		l = copy(t);
		split(l->r, l->r, r, k, idx + 1);
		pull(l);
	}
	else
	{
		r = copy(t);
		split(r->l, l, r->l, k, add);
		pull(r);
	}
}

void merge(pnode &t, pnode l, pnode r)
{
	if(!l) { t = copy(r); return; }
	if(!r) { t = copy(l); return; }

	if(hey(size(l), size(r)))
		t = copy(l), merge(t->r, t->r, r);
	else
		t = copy(r), merge(t->l, l, t->l);

	pull(t);
}

vector<int> tmp_rec;

void get_li_tmp(pnode t)
{
	if(!t) return;
	get_li_tmp(t->l);
	tmp_rec.pb(t->id);
	get_li_tmp(t->r);
}

vector<int> get_li(pnode t)
{
	tmp_rec.clear();
	get_li_tmp(t);
	return tmp_rec;
}

pnode build(int l, int r, vector<int> &li)
{
	if(l > r) return nullptr;

	int mid = (l + r) >> 1;

	pnode ret = new_node(li[mid]);
	ret->l = build(l, mid - 1, li);
	ret->r = build(mid + 1, r, li);

	pull(ret);

	return ret;
}

int n, m, start_pos;
int64_t t;

void read()
{
	cin >> n >> m;
	cin >> start_pos >> t;
	start_pos--;
}

int to[MAXN];

void dfs(pnode t, int p = 0)
{
	if(!t) return;
	dfs(t->l, p);
	to[p] = t->id;
	dfs(t->r, p + size(t->l) + 1);
}

pnode root = nullptr;
vector<int> tmpp;

void rebuild()
{
	tmpp = get_li(root);
	cnt_nodes = 0;
	root = build(0, n - 1, tmpp);
}

pnode get(int l, int r)
{
	if(l < 0)
	{
		pnode ret;
		merge(ret, get(n + l, n - 1), get(0, r));
		return ret;
	}

	if(r >= n)
	{
		pnode ret;
		merge(ret, get(l, n - 1), get(0, r - n));
		return ret;
	}

	pnode dummy, dummy2, ret, mid;
	split(root, mid, dummy, r);
	split(mid, dummy2, ret, l - 1);
	return ret;
}

void solve()
{
	while(t % n)
	{
		if(start_pos < m) start_pos = (start_pos + (t % n)) % n;
		else start_pos = (start_pos + n - (t % n)) % n;
		t--;
	}

	t /= n;

	for(int i = 0; i < n; i++) tmpp.pb(i);
	root = build(0, n - 1, tmpp);

	for(int i = 0; i < n; i++)
	{
		pnode L = get(i, m + i - 1);
		pnode R = get(m - i, n - 1 - i);

		merge(root, L, R);
		if(i && i % B == 0)
			rebuild();
	}

	vector<int> clist = get_li(root);
	for(int i = 0; i < n; i++) to[i] = clist[i];

	for(int cnt = 0; t > 0 && cnt < n; cnt++, t--)
		start_pos = to[start_pos];

	if(t != 0)
	{
		int cycle_len = 1, u = to[start_pos];
		while(u != start_pos)
		{
			cycle_len++;
			u = to[u];
		}

		t %= cycle_len;
		while(t--)
			start_pos = to[start_pos];
	}

	cout << start_pos + 1 << endl;
}

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

	init_memory();

	read();
	solve();
	return 0;
}

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

using ll = long long;

ll N, M;
ll modN(ll a) {
	a %= N;
	if (a < 0) a += N;
	return a;
}
ll simulateN(ll st) {
	for (ll t = N; t > 0; t--) {
		if (st < M) {
			st += t;
		} else {
			st -= t;
		}
		st = modN(st);
	}
	return st;
}

ll S;
ll T;

const int MAXN = 1.1e5;
ll dest[MAXN];
ll tmp[MAXN];
ll vis[MAXN];

ll go() {
	while (T % N) {
		if (S < M) {
			S += T;
		} else {
			S -= T;
		}
		S = modN(S);
		T--;
	}

	assert(T % N == 0);
	T /= N;

	if (T == 0) return S;

	if (N-1 - M * (M+1) / 2 <= M) {
		// we're in the large M case, where we're guaranteed to get to M or M-1
		S = simulateN(S);
		T --;
		assert(S == M || S == M-1);

		ll mNext = simulateN(M);
		ll m1Next = simulateN(M-1);
		assert(mNext == M || mNext == M-1);
		assert(m1Next == M || m1Next == M-1);

		if (mNext == M-1 && m1Next == M) {
			// we'll just alternate
			if (T % 2 == 0) return S;
			else return M + (M-1) - S;
		}

		// otherwise, one of them is a fixed point,
		// it takes at most 1 step to get to the fixed point
		if (T == 0) return S;
		assert(T);

		if (S == M) S = mNext;
		else if (S == M-1) S = m1Next;
		else assert(false);
		T--;

		return S;
	} else {
		// we're in the small M case
		for (ll i = 0; i < N; i++) {
			dest[i] = i;
		}

		ll offset = 0;
		for (ll t = 1; t <= N; t++) {
			// destination of i is stored at dest[i-offset]
			for (ll i = 0; i < M; i++) {
				tmp[i] = dest[modN(i + t - offset)];
			}
			offset += t;
			offset %= N;
			for (ll i = 0; i < M; i++) {
				dest[modN(i - offset)] = tmp[i];
			}
		}
		assert(dest[modN(0 - offset)] == simulateN(0));
		for (ll i = 0; i < N; i++) {
			tmp[i] = dest[modN(i-offset)];
		}
		for (ll i = 0; i < N; i++) {
			dest[i] = tmp[i];
		}

		memset(vis, -1, sizeof(vis));
		while (T > 0) {
			if (vis[S] != -1) {
				assert(vis[S] > T);
				// the cycle length is
				ll cycLen = (vis[S] - T);
				T %= cycLen;
				if (T == 0) break;
			}
			assert(T > 0);
			vis[S] = T;
			S = dest[S];
			T--;
		}
		assert(T == 0);
		return S;
	}
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N >> M >> S >> T;
	S--;
	bool flipped = false;
	if (M * 2 > N) {
		S = N - 1 - S;
		M = N - M;
		flipped = true;
	}

	ll res = go();
	if (flipped) {
		res = N - 1 - res;
	}
	cout << res + 1 << '\n';

	return 0;
}

#include<cstdio>

const int MAXN=100011;

int N,M;
int S;
long long T;

long long Tim[MAXN];

int Nxt(int Pos){
long long ret=(long long)(Pos);
ret+=(Pos<M)?T:(-T);
--T;
return((int)(ret%(long long)(N))+N)%N;
}

int main(){

scanf("%d%d%d%I64d",&N,&M,&S,&T);--S;

while(true){
if(Tim[S])T%=(Tim[S]-T);
Tim[S]=T;
if(T<=N){
while(T)S=Nxt(S);
printf("%d\n",S+1);
return 0;
}
for(int i=0;i<N;++i)S=Nxt(S);
}

return 0;
}

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

typedef long long ll;
int n,m,s,ss;
ll t,tt;

void work(int&s,ll&t){
	s=(s+(s<m?t:-t))%n;s+=s>>31&n;
	--t;
}

int main(){
	cin>>n>>m>>s>>t;--s;
	for(ss=s,tt=t;;){
		work(s,t);work(ss,tt);work(ss,tt);
		if(!t){cout<<(s+1)<<'\n';return 0;}
		if(s==ss&&(t-tt)%n==0)t%=t-tt,tt=t;
	}
}

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author majk
 */

#ifndef MAJK_LIB
#define MAJK_LIB

#include <vector>
#include <stack>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <string>
#include <sstream>
#include <queue>
#include <array>
#include <bitset>
using namespace std;

#define x first
#define y second
typedef std::pair<int,int> pii; typedef long long ll; typedef unsigned long long ull; typedef unsigned int ui; typedef pair<ui,ui> puu;

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
template <typename T> bool in(T a, T b, T c) { return a <= b && b < c; }
ui logceil(ll x) { return x?8*sizeof(ll)-__builtin_clzll(x):0; }

namespace std { template<typename T,typename U>struct hash<pair<T,U>>{hash<T>t;hash<U>u;size_t operator()(const pair<T,U>&p)const{return t(p.x)^(u(p.y)<<7);}}; }
template<typename T,typename F>T bsh(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){l=m+1;r=m;}else{h=m-1;}}return r;}
template<typename F> double bshd(double l,double h,const F&f,double p=1e-9){ui r=3+(ui)log2((h-l)/p);while(r--){double m=(l+h)/2;if(f(m)){l=m;}else{h=m;}}return (l+h)/2;}
template<typename T,typename F>T bsl(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){h=m-1;r=m;}else{l=m+1;}}return r;}
template<typename F> double bsld(double l,double h,const F&f,double p=1e-9){ui r=3+(ui)log2((h-l)/p);while(r--){double m=(l+h)/2;if(f(m)){h=m;}else{l=m;}}return (l+h)/2;}
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

template<typename T>class vector2:public vector<vector<T>>{public:vector2(){} vector2(size_t a,size_t b,T t=T()):vector<vector<T>>(a,vector<T>(b,t)){}};
template<typename T>class vector3:public vector<vector2<T>>{public:vector3(){} vector3(size_t a,size_t b,size_t c,T t=T()):vector<vector2<T>>(a,vector2<T>(b,c,t)){}};
template<typename T>class vector4:public vector<vector3<T>>{public:vector4(){} vector4(size_t a,size_t b,size_t c,size_t d,T t=T()):vector<vector3<T>>(a,vector3<T>(b,c,d,t)){}};
template<typename T>class vector5:public vector<vector4<T>>{public:vector5(){} vector5(size_t a,size_t b,size_t c,size_t d,size_t e,T t=T()):vector<vector4<T>>(a,vector4<T>(b,c,d,e,t)){}};

#endif
 #ifndef MAJK_RANDOM_H
#define MAJK_RANDOM_H

#include <random>
#include <chrono>
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);
using random_int = std::uniform_int_distribution<int>;
using random_ll = std::uniform_int_distribution<ll>;
struct TimeLimit {
    TimeLimit(double seconds) : s(seconds-0.2), last(clock()), mx(0) {}
    operator bool() const { clock_t cur = clock(); mx = max(mx, cur-last); last = cur; return clock() < s * CLOCKS_PER_SEC - 1.5 * mx; }
    double s; mutable clock_t last, mx;
};

#endif //MAJK_RANDOM_H

class TaskG {
public:
    int N, M;

    int simulate(int s, int t) {
        while (t > 0) {
            if (s < M) s = (s + t) % N;
            else s = (s + N - t) % N;
            --t;
        }
        return s;
    }

    void solve(istream& cin, ostream& cout) {
        cin >> N >> M;
        int S; ll T;
        cin >> S >> T;
        --S;
        S = simulate(S, T % N);
        vector<pair<int,ll>> C(N, {-1,0LL});
        bool quick = true;
        for (ll i = T/N-1; i >= 0; --i) {
            if (C[S].x != -1) {
                if (quick) {
                    ll diff = C[S].y - i;
                    i %= diff;
                    quick = false;
                }
            } else {
                C[S] = {simulate(S, N-1), i};
            }

            S = C[S].x;
        }
        cout << S+1 << '\n';

//        cin >> N >> M;
//        while (true) {
//            N = random_int{1000, 5000}(rng);
//            M = random_int{1, N-1}(rng);
//            vector<int> H(N), C(N);
//            for (int i = 0; i < N; ++i) H[i] = simulate(i, N);
//
//            for (int i = 0; i < N; ++i) {
//                set<int> U{i};
//                int j = H[i];
//                while (U.find(j) == U.end()) { U.insert(j); j = H[j]; }
//                C[i] = U.size();
//            }
//            int mx = *max_element(C.begin(),C.end());
//            if (mx > 5) cerr << N << ' ' << M << ' ' << mx << endl;
//
//        }
    }
};

int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	TaskG solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ull = uint64_t;
using ll = int64_t;
using ld = long double;

#ifdef BZ
mt19937_64 mt{ 228 };
#else
mt19937_64 mt{ ull(new char) };
#endif

struct Node {
    using Ptr = Node * ;

    Ptr l;
    Ptr r;
    ull y;
    int sz;
    int x;

    Node() = default;

    Node(int x)
        : l(nullptr)
        , r(nullptr)
        , y(mt())
        , sz(1)
        , x(x)
    {
    }
};

using Ptr = Node * ;

#ifndef BZ
const int NC = 29000000;
#else
const int NC = 200000;
#endif

const int N = 100228;
Node nodes[NC + N * 3];
int nodec = 0;

template <typename ... Args>
Ptr newnode(Args&& ... args) {
    nodes[nodec] = Node(std::forward<Args>(args)...);
    return nodes + nodec++;
}

int sz(Ptr p) {
    return p ? p->sz : 0;
}

void upd(Ptr p) {
    p->sz = 1 + sz(p->l) + sz(p->r);
}

Ptr merge(Ptr l, Ptr r) {
    if (!l) {
        return r;
    }

    if (!r) {
        return l;
    }

    Ptr ans;
    if (mt() % (l->sz + r->sz) < l->sz) {
        ans = newnode(*l);
        ans->r = merge(l->r, r);
    } else {
        ans = newnode(*r);
        ans->l = merge(l, r->l);
    }

    upd(ans);
    return ans;
}

pair<Ptr, Ptr> split(Ptr t, int s) {
    if (!t) {
        return { nullptr, nullptr};
    }

    Ptr ans = newnode(*t);

    int ls = sz(t->l);
    if (s > ls) {
        auto[lc, rc] = split(t->r, s - ls - 1);
        ans->r = lc;
        upd(ans);
        return { ans, rc };
    } else {
        auto[lc, rc] = split(t->l, s);
        ans->l = rc;
        upd(ans);
        return { lc, ans };
    }
}

int a[N];
int ac;
Ptr root;

const int LG = 50;

int nx[N][LG];

Ptr build(int l, int r) {
    if (l >= r) {
        return nullptr;
    }

    int m = (l + r) / 2;
    Ptr cur = newnode(a[m]);
    cur->l = build(l, m);
    cur->r = build(m + 1, r);
    upd(cur);
    return cur;
}

void trav(Ptr p) {
    if (!p) {
        return;
    }

    trav(p->l);
    a[ac++] = p->x;
    trav(p->r);
}

int n, m;

void bld() {
    nodec = 0;
    assert(ac == n);
    root = build(0, ac);
}

void rebuild() {
    ac = 0;
    trav(root);
    bld();
}

Ptr sub(int l, int r) {
    int a = l, b = r;

    int t = 0;

    if (a < 0) {
        a += n;
        swap(a, b);
        t = 1;
    }

    if (b > n) {
        b -= n;
        swap(a, b);
        t = 1;
    }

    auto[rm, r2] = split(root, b);
    auto[r0, r1] = split(rm, a);
    if (t == 0) {
        return r1;
    } else {
        return merge(r2, r0);
    }
}

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(20);

    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        a[ac++] = i;
    }

    bld();

    for (int i = 1; i < n; ++i) {
        if (nodec > NC) {
            rebuild();
        }

        auto cl = sub(i, m + i);
        assert(sz(cl) == m);
        auto cr = sub(m - i, n - i);
        assert(sz(cr) == n - m);

        root = merge(cl, cr);
        assert(sz(root) == n);
    }

    ac = 0;
    trav(root);

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

    for (int i = 1; i < LG; ++i) {
        for (int j = 0; j < n; ++j) {
            nx[j][i] = nx[nx[j][i - 1]][i - 1];
        }
    }

    int s;
    ll t;
    cin >> s >> t;
    --s;
    ++t;

    while (t % n) {
        --t;

        if (s < m) {
            s += (t % n);
        } else {
            s -= (t % n);
        }

        if (s < 0) {
            s += n;
        }

        if (s >= n) {
            s -= n;
        }
    }

    t /= n;
    for (int i = LG - 1; i >= 0; --i) {
        if ((t >> i) & 1) {
            s = nx[s][i];
        }
    }

    cout << s + 1 << "\n";
}

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

using ll=long long;
//#define int ll

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=a;i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(a>b)a=b;}

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.a<<","<<p.b<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

template<class N>
struct pavl{
	struct N2{
		N n;
		int l,r,d;
	};
	vc<N2> x;
	int nn(N w,int l=-1,int r=-1,int d=0){
		int i=x.size();
		x.pb(N2{w,l,r,d});
		return i;
	}
	int md(int i,N w){
		if(i==-1)return -1;
		return nn(w,x[i].l,x[i].r,x[i].d);
	}
	int np(int l,int r){
		return nn(N::merge(x[l].n,x[r].n),l,r,max(x[l].d,x[r].d)+1);
	}
	N gn(int i){
		return i==-1?N():x[i].n;
	}
	pair<N,N> push(int i,N w){
		N a=gn(x[i].l),b=gn(x[i].r);
		w.push(a);
		w.push(b);
		return {a,b};
	}
	pi m1(int a,int b,int c){
		if(abs(max(x[a].d,x[b].d)+1-x[c].d)<=1)
			return pi(np(a,b),c);
		if(abs(max(x[b].d,x[c].d)+1-x[a].d)<=1)
			return pi(a,np(b,c));
		auto e=push(b,x[b].n);
		return pi(np(a,md(x[b].l,e.a)),np(md(x[b].r,e.b),c));
	}
	pi m2(int a,int b,N c,N d){
		if(x[a].d<x[b].d){
			auto e=push(b,d);
			pi z=m2(a,x[b].l,c,e.a);
			return m1(z.a,z.b,md(x[b].r,e.b));
		}else if(x[a].d>x[b].d){
			auto e=push(a,c);
			pi z=m2(x[a].r,b,e.b,d);
			return m1(md(x[a].l,e.a),z.a,z.b);
		}else
			return pi(md(a,c),md(b,d));
	}
	int mr(int a,int b){
		if(a==-1)return b;
		if(b==-1)return a;
		dmp(x[a].n.s);
		dmp(x[b].n.s);
		int sum1=x[a].n.s+x[b].n.s;
		pi z=m2(a,b,x[a].n,x[b].n);
		dmp(x[z.a].n.s);
		dmp(x[z.b].n.s);
		int sum2=x[z.a].n.s+x[z.b].n.s;
		assert(sum1==sum2);
		return np(z.a,z.b);
	}
	template<class F,class G>
	pi sp(int i,N w,F f,G g){
		if(x[i].l==-1){
			if((w.*f)(g))return pi(-1,md(i,w));
			else return pi(md(i,w),-1);
		}
		auto a=push(i,w);
		pi res;
		if((a.a.*f)(g)){
			pi b=sp(x[i].l,a.a,f,g);
			//return pi(b.a,mr(b.b,md(x[i].r,a.b)));
			res=pi(b.a,mr(b.b,md(x[i].r,a.b)));
		}else{
			pi b=sp(x[i].r,a.b,f,g);
			//return pi(mr(md(x[i].l,a.a),b.a),b.b);
			res=pi(mr(md(x[i].l,a.a),b.a),b.b);
		}
		int sum=0;
		if(res.a!=-1)sum+=x[res.a].n.s;
		if(res.b!=-1)sum+=x[res.b].n.s;
		dmp(x[i].n.s);
		dmp(sum);
		assert(x[i].n.s==sum);
		return res;
	}
	template<class F,class G>
	pi sp(int i,F f,G g){return sp(i,x[i].n,f,g);}
	template<class G>
	pi sp(int i,G g){return sp(i,&N::split,g);}
	void dfs(int i,N w,vc<N>&v){
		if(x[i].l==-1){
			v.pb(w);
			return;
		}
		auto a=push(i,w);
		dfs(x[i].l,a.a,v);
		dfs(x[i].r,a.b,v);
	}
	vc<N> tr(int i){
		vc<N> v;
		dfs(i,x[i].n,v);
		return v;
	}
	int mem(){
		return x.size()*sizeof(N2);
	}
};

//空のstructに対してsplit関数を呼ぶことがあることに注意
//split関数は、半開区間のイメージで、そのノード以下に敷居があるか判定
struct N{
	int v,s;
	N(int vv=0,int ss=0):v(vv),s(ss){}
	void push(N&){}
	static N merge(N x,N y){return N(0,x.s+y.s);}
	bool split(int&a){
		if(a<s)return true;
		a-=s;
		return false;
	}
};

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);

	int n,m;cin>>n>>m;
	int s;ll t;cin>>s>>t;
	s--;

	while(t%n){
		if(s<m){
			s=(s+t)%n;
		}else{
			s=(s-t%n+n)%n;
		}
		t--;
	}
	t/=n;

	pavl<N> avl;
	int r=-1;
	//rep(i,n)
	//	r=avl.mr(r,avl.nn(N(i,1)));
	const auto getidx=[&](){
		auto res=avl.tr(r);
		vi cur(n);
		rep(i,n)cur[i]=res[i].v;
		avl.x.clear();
		return cur;
	};
	const auto gen=[&](vi idx){
		for(auto&i:idx)i=avl.nn(N(i,1));
		int k;
		while((k=idx.size())>1){
			if(k%2)idx.pb(-1),k++;
			vi nx;
			rep(i,k/2)
				nx.pb(avl.mr(idx[i*2],idx[i*2+1]));
			idx=nx;
		}
		r=idx[0];
	};
	{
		vi idx(n);
		iota(all(idx),0);
		gen(idx);
	}

	rng(i,1,n){
		const auto g=[&](int a,int b){
			dmp(a);
			dmp(b);
			dmp(avl.x[r].n.s);
			int res=avl.sp(r,a).b;
			dmp(res);
			dmp(avl.x[res].n.s);
			assert(avl.x[res].n.s==n-a);
			if(n-a<b){
				res=avl.mr(res,avl.sp(r,b-(n-a)).a);
			}else{
				res=avl.sp(res,b).a;
			}
			dmp(avl.x[res].n.s);
			assert(avl.x[res].n.s==b);
			return res;
		};
		r=avl.mr(g(i,m),g((m-i+n)%n,n-m));
		if(avl.mem()>450000000)
			gen(getidx());
	}

	vi cur=getidx();
	while(t){
		if(t%2)s=cur[s];
		vi nx(n);
		rep(i,n)nx[i]=cur[cur[i]];
		cur=nx;
		t>>=1;
	}
	cout<<s+1<<endl;
}

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

ll t;
int h[100010],id[100010],n,m,s;

inline ll rd()
{
	ll x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline int gao(int x,int y)
{
	if (x<=m) x+=y;
	else x-=y;
	if (x<=0) x+=n;
	if (x>n) x-=n;
	return x;
}

int main()
{
	n=rd();m=rd();s=rd();t=rd();
	while (t%n!=0) s=gao(s,t%n),t--;
	h[s]=1;id[1]=s;
	for (int i=2;t>=n;i++)
	{
		for (int j=n;j;j--) s=gao(s,j);
		t-=n;
		if (h[s]) { printf("%d\n",id[(t/n)%(i-h[s])+h[s]]);return 0; }
		h[s]=i;id[i]=s;
	}
	while (t) s=gao(s,t%n),t--;
	printf("%d\n",s);
	return 0;
}

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

int n, m;

void go(int &u, int t) {
  for (int i = t; i > 0; --i) {
    if (u < m) {
      u += i;
    } else {
      u -= i;
    }
    u += (u < 0) ? n : 0;
    u -= (u >= n) ? n : 0;
  }
}

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

  int s;
  long long t;
  cin >> n >> m >> s >> t;

  go(--s, t % n);
  t /= n;

  vector<int> visited(n, -1);
  vector<int> cycle = {s};
  visited[s] = 0;

  for (int i = 1; i <= t; ++i) {
    go(s, n);

    if (visited[s] != -1) {
      t -= i;
      t %= i - visited[s];
      cout << cycle[visited[s] + t] + 1 << "\n";
      exit(0);
    }

    visited[s] = i;
    cycle.push_back(s);
  }

  cout << s + 1 << "\n";
}

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef complex<double> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;
const int TT = 60000001;
const ld PI = 4*atan((ld)1);

template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }

namespace io {
    // Source: StackOverflow

    template<class T> struct like_array : is_array<T>{};
    template<class T, size_t N> struct like_array<array<T,N>> : true_type{};
    template<class T> struct like_array<vector<T>> : true_type{};
    template<class T> bool is_like_array(const T& a) { return like_array<T>::value; }

    // I/O

    void setIn(string s) { freopen(s.c_str(),"r",stdin); }
    void setOut(string s) { freopen(s.c_str(),"w",stdout); }
    void setIO(string s = "") {
        ios_base::sync_with_stdio(0); cin.tie(0);
        if (sz(s)) { setIn(s+".in"), setOut(s+".out"); }
    }

    // INPUT

    // double input seems slow on CF
    void re(double& x) { string t; cin >> t; x = stod(t); }
    void re(ld& x) { string t; cin >> t; x = stold(t); }
    template<class T> void re(T& x) { cin >> x; }
    template<class Arg, class... Args> void re(Arg& first, Args&... rest) {
        re(first); re(rest...);
    }
    template<class T1, class T2> istream& operator>>(istream& is, pair<T1,T2>& p) {
        is >> p.f >> p.s; return is;
    }
    template<class T> istream& operator>>(istream& is, vector<T>& a) {
        F0R(i,sz(a)) is >> a[i];
        return is;
    }

    // OUTPUT

    template<class T> void pr(const T& x) { cout << x << '\n'; }
    template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
        cout << first << ' '; pr(rest...);
    }
    template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) {
        os << '{' << a.f << ", " << a.s << '}'; return os;
    }

    template<class T> ostream& printArray(ostream& os, const T& a, int SZ) {
        os << '{';
        F0R(i,SZ) {
            if (i) {
                os << ", ";
                if (is_like_array(a[i])) cout << "\n";
            }
            os << a[i];
        }
        os << '}';
        return os;
    }

    template<class T, size_t SZ> ostream& operator<<(ostream& os, const array<T,SZ>& a) {
        return printArray(os,a,SZ);
    }
    template<class T> ostream& operator<<(ostream& os, const vector<T>& a) {
        return printArray(os,a,sz(a));
    }
}

using namespace io;

int z = 0;
int val[TT], c[TT][2], sz[TT], nex = 1;

namespace treap {
    int tnode(int _val) {
        val[nex] = _val;
        sz[nex] = 1;
        return nex ++;
    }

    int copy(int x) {
        z ++; if (!x) return x;
        val[nex] = val[x];
        F0R(i,2) c[nex][i] = c[x][i];
        sz[nex] = sz[x];
        return nex ++;
    }

    int getsz(int x) { return x?sz[x]:0; }

    int recalc(int x) {
        sz[x] = 1+getsz(c[x][0])+getsz(c[x][1]);
        return x;
    }

    void tra(int x, vi& v) {
        if (!x) return;
        tra(c[x][0],v); v.pb(val[x]); tra(c[x][1],v);
    }

    pi splitsz(int t, int sz) {
        if (!t) return {t,t};
        auto T = copy(t);
        // cout << "AH " << t << " " << sz[t] << "\n";
        if (getsz(c[T][0]) >= sz) {
            auto p = splitsz(c[T][0], sz); c[T][0] = p.s;
            return {p.f, recalc(T)};
        } else {
            auto p = splitsz(c[T][1], sz-getsz(c[T][0])-1); c[T][1] = p.f;
            return {recalc(T), p.s};
        }
    }

    bool shouldLeft(int a, int b) {
        return rand() % (a+b) < a;
    }

    int merge(int L, int R, bool b = 0) {
        if (!L) return R;
        if (!R) return L;

        int t;
        if (shouldLeft(getsz(L),getsz(R))) {
            t = copy(L);
            c[t][1] = merge(c[L][1],R);
        } else {
            t = copy(R);
            c[t][0] = merge(L,c[R][0]);
        }
        return recalc(t);
    }
}

using namespace treap;

int n,m, NEX[MX][41];
ll s, t;

void brute() {
    if (s <= m) s += t;
    else s -= t;
    s %= n;
    while (s <= 0) s += n;
    t --;
}

int cur = 0;

int get(int l, int r) {
    while (l > n) l -= n, r -= n;
    while (l <= 0) l += n, r += n;
    if (r > n) return merge(get(l,n),get(n+1,r));
    auto a = splitsz(cur,r);
    auto b = splitsz(a.f,l-1);
    auto des = copy(b.s);
    cur = merge(merge(b.f,b.s),a.s);
    return des;
}

int build(vi& v, int l, int r) {
    if (l > r) return 0;
    int m = (l+r)/2;
    int root = tnode(v[m]);
    c[root][0] = build(v,l,m-1);
    c[root][1] = build(v,m+1,r);
    return recalc(root);
}

void gen() {
    FOR(i,1,n+1) cur = merge(cur, tnode(i));
    //cout << cur << " " << sz[cur] << ' ' << c[cur][0] << ' ' << c[cur][1] << "\n";
    //cout << sz[c[cur][0]] << " " << sz[c[cur][1]] << "\n";
    //auto a = splitsz(cur,5); cout << sz[a.f] << " " << sz[a.s]; exit(0);
    FOR(i,1,n) {
        int Z = z;
        auto a = get(i+1,i+m);
        auto b = get(m+1-i,n-i);
        if (getsz(a) != m || getsz(b) != n-m) {
            cout << "OOPS " << a << " " << b << " " << i << " " << getsz(a) << " " << getsz(b) << "\n";
            exit(0);
        }
        cur = merge(a,b);
        if (z-Z >= 1000) {
            vi v; tra(cur,v);
            cur = build(v,0,sz(v)-1);
        }
    }
    // cout << z << "\n";
    vi v; tra(cur,v);
    F0R(i,sz(v)) NEX[i+1][0] = v[i];
}

int main() {
    // you should actually read the stuff at the bottom
    setIO(); re(n,m,s,t);
    gen();
    while (t % n != 0) brute();
    FOR(j,1,41) FOR(i,1,n+1) NEX[i][j] = NEX[NEX[i][j-1]][j-1];
    t /= n;
    F0Rd(i,41) if (t&(1LL<<i)) s = NEX[s][i];
    cout << s;
    // you should actually read the stuff at the bottom
}

/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/

#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long ll;

#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define MP make_pair
#define N 100000

vector<int> bigStops(1);
int bigStopPosition[N];
bool moveClockWise[N];

int NextStop(int n, int i, ll t){
    t %= n;
    return moveClockWise[i] ? (i + t) % n : (i + n - t) % n;
}

int NextBigStop(int n, int i){
    for(ll t = n - 1; t > 0; --t){
        i = NextStop(n, i, t);
    }
    return i;
}

bool AddNewBigStop(int s){
    if(bigStopPosition[s]){
        return false;
    }
    bigStopPosition[s] = bigStops.size();
    bigStops.push_back(s);
    return true;
}

int main(){
    int n, m, s;
    ll t;

    cin >> n >> m >> s >> t;

    for(int i = 0; i < m; ++i){
        moveClockWise[i] = 1;
    }

    --s;

    for( ; t % n != 0; --t){
        s = NextStop(n, s, t);
    }

    AddNewBigStop(s);

    for(bool cycleFound = 0; t > 0 && cycleFound == 0; t -= n){
        s = NextBigStop(n, s);
        cycleFound = !AddNewBigStop(s);
    }

    t /= n;

    t %= (bigStops.size() - bigStopPosition[s]);

    int ans = bigStops[bigStopPosition[s] + t] + 1;

    cout << ans << '\n';

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=101000;
int n,m,pos[N];
ll t;
int s;
map<ll,int> dp[N];
int go(int s) {
	if (pos[s]!=-1) return pos[s];
	int t=s;
	for (int i=n;i>=1;i--) {
		if (s>=m) s=((s-i)%n+n)%n;
		else s=(s+i)%n;
	}
	return pos[t]=s;
}
int ff(int s,ll n) {
	if (n==0) return s;
	if (n==1) return go(s);
	if (dp[s].count(n)) return dp[s][n];
	else return dp[s][n]=ff(ff(s,n/2),n-n/2);
}
int main() {
	scanf("%d%d",&n,&m);
	scanf("%d%lld",&s,&t);
	s-=1;
	while (t%n!=0) {
		if (s>=m) s=((s-t)%n+n)%n;
		else s=(s+t)%n;
		--t;
	}
	rep(i,0,n) pos[i]=-1;
	printf("%d\n",ff(s,t/n)+1);
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
ll n,m,s,t;
ll pos[maxn],T[maxn];
ll cal(ll x)
{
    if(s<m) s+=t;
    else s-=t;
    t--;
    return (s%n+n)%n;
}
int main()
{

    cin>>n>>m>>s>>t;
    s--;
    while(t%n) s=cal(s);
    ll temp=t/n;
    ll tick=0;
    while(temp--){
        if(pos[s]){
            temp%=tick-T[s];
            s=pos[s];
        }else{
            T[s]=tick;
            ll tmp=s;
            t=n;
            for(int i=1;i<=n;i++) s=cal(s);
            pos[tmp]=s;
            tick++;
        }
    }
    cout<<s+1<<endl;
    return 0;
}

#include <iostream>
using namespace std;
long long t,s,n,i,m,k,mark[100100];
int next(int x)
{
    if (x<m) return (x+t)%n;
    return (x-(t%n)+n)%n;
}
int main()
{
    cin>>n>>m>>s>>t;
    s--;
    while (t>0)
    {
        if (t%n==0)
        {
            i++;
            if (mark[s]!=0) break;
            mark[s]=i;
        }
        s=next(s);
        t--;
    }
    if (t==0)
    {
        cout<<s+1<<endl;
        return 0;
    }
    t/=n;
    int loop=i-mark[s];
    int ans=t%loop+mark[s];
    for (i=0; i<n; i++)
        if (mark[i]==ans) break;
    cout<<i+1<<endl;
    return 0;
}

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

int n, m, s;
long long t, vis[111111];;

int main(void) {
  scanf("%d%d%d%lld", &n, &m, &s, &t);
  s--;
  while(t % n) {
    if(s < m) {
      s = (s + t) % n;
    } else {
      s = (s - t % n + n) % n;
    }
    t--;
  }
  t /= n;
  //cerr << s << endl;
  vis[s] = t;
  while(t--) {
    for(int i = n - 1; ~i; i--) {
      if(s < m) {
	s = (s + i) % n;
      } else {
	s = (s - i + n) % n;
      }
    }
    //cerr << t << endl;
    if(vis[s]) {
      //cerr << vis[s] << endl;
      t %= vis[s] - t;
    }
    vis[s] = t;
  }
  cout << s + 1 << endl;
  return 0;
}

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <cstring>
using namespace std;

long long n, m, s;
long long t;
map<int,int> mp;

long long step(long long u, long long delta) {
	if (u < m) {
		u = (u + delta) % n;
	} else {
		u = (u - delta) % n;
		if (u < 0) {
			u += n;
		}
	}
	return u;
}

long long bigstep(long long u) {
	for (int i = n; i > 0; i--) {
		u = step(u, i);
	}
	return u;
}

int main() {
	cin >> n >> m >> s >> t;
	s--;
	while (t % n) {
		s = step(s, t);
		t--;
	}

	t /= n;

	int idx = 0;
	mp[s] = 0;
	while (t > 0) {
		idx++;
		t--;
		int v = bigstep(s);
		if (!mp.count(v)) {
			mp[v] = idx;
			s = v;
		} else {
			int cycle = idx - mp[v];
			s = v;
			t %= cycle;
			break;
		}
	}
	while (t > 0) {
		s = bigstep(s);
		t--;
	}

	cout << s + 1 << endl;
 	return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll naive(ll n, ll m, ll s, ll t)
{
	ll cur = s;
	while(t>0)
	{
		if(cur%n>=m)
		{
			cur-=t;
		}
		else
		{
			cur+=t;
		}
		cur%=n;
		if(cur<0) cur+=n;
		t--;
	}
	return cur;
}

const ll C = 0;
ll md[111111];
vector<ll> M[111111];

ll fast(ll n, ll m, ll s, ll t)
{
	if(t<=n) return naive(n,m,s,t);
	while(t%n!=0)
	{
		if(s%n>=m)
		{
			s-=t;
		}
		else
		{
			s+=t;
		}
		s%=n;
		if(s<0) s+=n;
		t--;
	}
	if(t==0) return s;
	//solve t/n copies of the problem, sort of
	if(m>n-m)
	{
		return n - 1 - fast(n, n-m, n-1-s, t); //check later
	}
	for(ll i=0;i<=n+5;i++)
	{
		ll s = (i*(i-1))/2;
		md[i] = s%n; M[i].clear();
	}
	for(ll i=1;i<=n+5;i++) M[md[i]].pb(i);
	//m <= n - m
	if(m<=C) //small
	{
		vector<vector<ll> > dp(m+2);
		for(int i=0;i<=m;i++)
		{
			dp[i].assign(n,0);
			dp[i][0]=i;
		}
		for(int j=1;j<n;j++)
		{
			for(int k=0;k<m;k++)
			{
				ll times = j; ll cur = k;
				while(times>0)
				{
					if(cur%n>=m)
					{
						cur-=times;
					}
					else
					{
						cur+=times;
					}
					cur%=n;
					if(cur<0) cur+=n;
					times--;
					if(cur<=m) break;
				}
				dp[k][j]=dp[cur][times];
			}
			ll ext = -1; ll besti = -1;
			for(int k=0;k<m;k++)
			{
				ll r = k - m + md[j+1];
				r%=n; if(r<0) r+=n;
				int lb = lower_bound(M[r].begin(),M[r].end(),j+1)-M[r].begin();
				lb--;
				if(lb>=0)
				{
					ll curi = M[r][lb];
					if(curi>besti)
					{
						besti=curi; ext=k;
					}
				}
			}
			if(besti==-1)
			{
				ll r = m - md[j+1];
				r%=n; if(r<0) r+=n;
				dp[m][j] = r;
			}
			else
			{
				dp[m][j] = dp[ext][besti-1];
			}
		}
		vector<ll> F(n+2,0);
		for(int i=0;i<=m;i++) F[i]=dp[i][n-1];
		for(int i=m+1;i<n;i++)
		{
			ll ext = -1; ll besti = -1; ll j = n - 1;
			for(int k=0;k<m;k++)
			{
				ll r = k - i + md[j+1];
				r%=n; if(r<0) r+=n;
				int lb = lower_bound(M[r].begin(),M[r].end(),j+1)-M[r].begin();
				lb--;
				if(lb>=0)
				{
					ll curi = M[r][lb];
					if(curi>besti)
					{
						besti=curi; ext=k;
					}
				}
			}
			if(besti==-1)
			{
				ll r = i - md[j+1];
				r%=n; if(r<0) r+=n;
				F[i] = r;
			}
			else
			{
				F[i] = dp[ext][besti-1];
			}
		}
		/*
		for(int i=0;i<n;i++) cerr<<F[i]<<' ';
		cerr<<'\n';
		*/
		ll cyc = t/n;
		//solve cyc cycles tbh
		map<ll,ll> ma;
		ma[s] = cyc;
		vector<ll> V; V.pb(s);
		ll len = -1;
		while(cyc>0)
		{
			cyc--;
			ll news = F[s]; s = news; V.pb(s);
			if(ma.find(news)==ma.end())
			{
				ma[news]=cyc;
			}
			else
			{
				ll cur = ma[news];
				len = cur - cyc;
				break;
			}
		}
		if(cyc==0) return s;
		//I still need cyc times :(
		cyc%=len;
		int id=0;
		for(int i=0;i<V.size();i++)
		{
			if(V[i]==s){id=i; break;}
		}
		return V[id+cyc];
	}
	else //do big
	{
		ll cyc = t/n;
		//solve cyc cycles tbh
		map<ll,ll> ma;
		ma[s] = cyc;
		vector<ll> V; V.pb(s);
		ll len = -1;
		while(cyc>0)
		{
			cyc--;
			ll news = naive(n, m, s, n); s = news; V.pb(s);
			if(ma.find(news)==ma.end())
			{
				ma[news]=cyc;
			}
			else
			{
				ll cur = ma[news];
				len = cur - cyc;
				break;
			}
		}
		if(cyc==0) return s;
		//I still need cyc times :(
		cyc%=len;
		int id=0;
		for(int i=0;i<V.size();i++)
		{
			if(V[i]==s){id=i; break;}
		}
		return V[id+cyc];
	}
}

void test(ll n, ll m)
{
	{
		cout<<"TEST "<<m<<" : ";
		//set<ll> S;
		for(ll s=0;s<n;s++)
		{
			//S.insert(naive(n,m,s,n-1));
			cout<<naive(n,m,s,n-1)<<' ';
		}
		//cout<<S.size()<<'\n';
	}
}

const bool DEBUG = 0;
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	//test(1882,22); return 0;
	//ll n; cin>>n; test(n);
	for(int cc=1;;cc++)
	{
		ll n,m,s,t;
		if(!DEBUG)
		{
			cin>>n>>m>>s>>t; s--;
		}
		else
		{
			n=rand()%2500+1;m=rand()%(n-1)+1;s=rand()%n;t=rand()+1;
		}
		ll f=fast(n,m,s,t);
		if(!DEBUG){cout<<f+1<<'\n'; return 0;}
		ll ss=naive(n,m,s,t);
		cerr<<"FAST : "<<f<<'\n';
		cerr<<"ANSWER : "<<ss<<'\n';
		if(f!=ss)
		{
			freopen("metro.out","w",stdout);
			cout<<n<<' '<<m<<' '<<s+1<<' '<<t<<'\n';
			return 0;
		}
		cerr<<"Case #"<<cc<<" complete\n";
	}
}

#include<cstdio>
#include<algorithm>
#include<iostream>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std;

const int N=100010;
ll t;
int n,m,s,nd,rt,tot,to[N][50];
struct Tr{ int ls,rs,v,sz; }v[N<<8];
struct P{ int x,y; };

int jump(ll x,ll y){
	if (x<=m) x+=y; else x-=y;
	return (x%n+n-1)%n+1;
}

void upd(int x){ v[x].sz=v[v[x].ls].sz+v[v[x].rs].sz+1; }
int get(int k){ v[++nd]=(Tr){0,0,k,1}; return nd; }
void dfs(int x){ if (v[x].ls) dfs(v[x].ls); to[++tot][0]=v[x].v; if (v[x].rs) dfs(v[x].rs); }
void Print(int x){ if (v[x].ls) Print(v[x].ls); printf("%d ",v[x].v); if (v[x].rs) Print(v[x].rs); }

int merge(int x,int y){
	if (!x || !y){ v[++nd]=v[x|y]; return nd; }
	int p=++nd;
	if (1ll*rand()*(v[x].sz+v[y].sz)<1ll*v[x].sz*RAND_MAX)
		{ v[p]=v[x]; v[p].rs=merge(v[p].rs,y); upd(p); return p; }
	else{ v[p]=v[y]; v[p].ls=merge(x,v[p].ls); upd(p); return p; }
}

P split(int x,int k){
	if (!x) return (P){0,0};
	P t; int p=++nd; v[p]=v[x];
	if (k<=v[v[x].ls].sz){ t=split(v[p].ls,k); v[p].ls=t.y; upd(p); return (P){t.x,p}; }
		else{ t=split(v[p].rs,k-v[v[x].ls].sz-1); v[p].rs=t.x; upd(p); return (P){p,t.y}; }
}

int build(int L,int R){
	if (L>R) return 0;
	int mid=(L+R)>>1,x=get(to[mid][0]);
	v[x].ls=build(L,mid-1); v[x].rs=build(mid+1,R);
	upd(x); return x;
}

int main(){
	scanf("%d%d%d",&n,&m,&s); cin>>t; int lim=20000;
	for (; t%n; t--) s=jump(s,t); t/=n;
	rep(i,1,n) to[i][0]=i; rt=build(1,n);
	rep(i,1,n-1){
		int lst=rt;
		if (m+i<=n){ P a=split(lst,m+i),b=split(a.x,i); rt=b.y; }
			else{ P a=split(lst,i),b=split(a.x,m+i-n); rt=merge(a.y,b.x); }
		if (m+1-i>0){ P a=split(lst,n-i),b=split(a.x,m-i); rt=merge(rt,b.y); }
			else{ P a=split(lst,m+n-i),b=split(a.x,n-i); rt=merge(rt,merge(a.y,b.x)); }
		if (!(i%lim)) tot=0,dfs(rt),nd=0,rt=build(1,n);
	}
	tot=0; dfs(rt);
	rep(j,1,49) rep(i,1,n) to[i][j]=to[to[i][j-1]][j-1];
	for (int j=49; ~j; j--) if (t&(1ll<<j)) s=to[s][j];
	printf("%d\n",s);
	return 0;
}

#pragma comment(linker, "/STACK:1000000000")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>
#include <assert.h>
#include <vector>
#include <cstring>
#include <bitset>
#include <random>
//#include <priority_queue>

#define all(a) (a).begin(), (a).end()
#define pb push_back
#define mp make_pair
#define ld long double
#define pii pair <int, int>
#define ll long long
#define pll pair <ll, ll>

using namespace std;

struct vt {
	int x;
	int sz;
	int l, r;

	vt() {

	}

	vt(int x) : x(x), sz(1), l(-1), r(-1) {

	}
};

const int maxm = (int)6e7 + 10;

vt mas[maxm];
int posit = 0;

int my_new(int x) {
	mas[posit] = vt(x);
	return posit++;
}

int cpy(int t) {
	int nt = my_new(mas[t].x);
	mas[nt].sz = mas[t].sz;
	mas[nt].l = mas[t].l;
	mas[nt].r = mas[t].r;

	return nt;
}

int sz(int t) {
	return (t == -1 ? 0 : mas[t].sz);
}

void recalc(int t) {
	mas[t].sz = sz(mas[t].l) + sz(mas[t].r) + 1;
}

void split(int t, int k, int &l, int &r) {
	if (t == -1) {
		l = -1;
		r = -1;
	}
	else if (sz(mas[t].l) >= k) {
		t = cpy(t);
		split(mas[t].l, k, l, mas[t].l);
		r = t;
		recalc(r);
	}
	else {
		t = cpy(t);
		split(mas[t].r, k - sz(mas[t].l) - 1, mas[t].r, r);
		l = t;
		recalc(l);
	}
}

int merge(int l, int r) {
	if (l == -1) {
		return r;
	}

	if (r == -1) {
		return l;
	}

	if ((ll)rand() * (sz(l) + sz(r)) <= (ll)sz(l) * RAND_MAX) {
		l = cpy(l);
		mas[l].r = merge(mas[l].r, r);
		recalc(l);
		return l;
	}
	else {
		r = cpy(r);
		mas[r].l = merge(l, mas[r].l);
		recalc(r);
		return r;
	}
}

int go(int t, int ps) {
	if (t == -1) {
		cout << "ASS" << endl;
		throw 1;
	}

	if (sz(mas[t].l) > ps) {
		return go(mas[t].l, ps);
	}
	else if (sz(mas[t].l) == ps) {
		return mas[t].x;
	}
	else {
		return go(mas[t].r, ps - sz(mas[t].l) - 1);
	}
}

int n, m;

int get_seg(int t, int l, int r) {
	if (l < 0) {
		return merge(get_seg(t, l + n, n - 1), get_seg(t, 0, r));
	}
	else if (r >= n) {
		return merge(get_seg(t, l, n - 1), get_seg(t, 0, r - n));
	}
	else {
		int lm, m, rm;

		split(t, r + 1, lm, rm);
		split(lm, l, lm, m);
		return m;
	}
}

int rebuild(int t, int sd) {
	int nt = get_seg(t, sd, m - 1 + sd);
	nt = merge(nt, get_seg(t, m - sd, n - 1 - sd));

	return nt;
}

const int maxn = (int)1e5 + 10;

int lnk[maxn];

void build_lnk(int t, int sd) {
	if (t == -1) {
		return;
	}

	build_lnk(mas[t].l, sd);
	lnk[sd + sz(mas[t].l)] = mas[t].x;
	build_lnk(mas[t].r, sd + sz(mas[t].l) + 1);
}

int used[maxn];

void reduce(int &t) {
	if (posit > maxm / 2) {
		build_lnk(t, 0);

		posit = 0;
		t = -1;

		for (int i = 0; i < n; i++) {
			t = merge(t, my_new(lnk[i]));
		}
	}
}

int main() {
	cin >> n >> m;
	//n = (int)1e5;
	//m = n / 3;

	int s;
	ll t;

	cin >> s >> t;
	//s = 1;
	//t = (ll)1e12;
	s--;

	int cn = t % n;

	t /= n;

	int ans = -1;

	for (int i = 0; i < n; i++) {
		ans = merge(ans, my_new(i));
	}

	for (int i = 1; i < n; i++) {
		ans = rebuild(ans, i);
		if (sz(ans) != n) {
			cout << "BAD" << endl;
			throw 1;
		}
		if (i == cn) {
			s = go(ans, s);
		}

		reduce(ans);
	}

	memset(lnk, -1, sizeof lnk);

	build_lnk(ans, 0);

	for (int i = 0; i < n; i++) {
		if (lnk[i] == -1) {
			cout << "BAD1" << endl;
			throw 1;
		}
	}

	int it = 1;

	while (used[s] == 0 && t != 0) {
		used[s] = it++;
		t--;
		s = lnk[s];
	}

	t %= (it - used[s]);

	while (t--) {
		s = lnk[s];
	}

	cout << s + 1 << endl;

	//system("pause");
}

#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<iostream>
#include<algorithm>
#define int long long
#define LOG(x) cerr<<#x<<" = "<<x<<endl
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;
}
using namespace std;
int n,m,s,t,cir[100001];
int go(int x)
{
	if(x<=m)x+=t;
	else x-=t;
	--t;
	return (x%n+n)%n;
}
main()
{
	re(n),re(m),re(s),re(t);--s;--m;
	while(1)
	{
		if(cir[s])t%=(cir[s]-t);
		cir[s]=t;
		while(t<=n)
		{
			s=go(s);
			if(!t)
			{
				printf("%lld\n",s+1);
				return 0;
			}
		}
		for(int i=0;i<n;++i)
			s=go(s);
	}
}

#include<cstdio>
#include<algorithm>
#include<iostream>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std;

const int N=100010;
ll t;
int n,m,s,nd,rt,tot,to[N][50];
struct Tr{ int ls,rs,v,sz; }v[N<<8];
struct P{ int x,y; };

int jump(ll x,ll y){
	if (x<=m) x+=y; else x-=y;
	return (x%n+n-1)%n+1;
}

void upd(int x){ v[x].sz=v[v[x].ls].sz+v[v[x].rs].sz+1; }
int get(int k){ v[++nd]=(Tr){0,0,k,1}; return nd; }
void dfs(int x){ if (v[x].ls) dfs(v[x].ls); to[++tot][0]=v[x].v; if (v[x].rs) dfs(v[x].rs); }
void Print(int x){ if (v[x].ls) Print(v[x].ls); printf("%d ",v[x].v); if (v[x].rs) Print(v[x].rs); }

int merge(int x,int y){
	if (!x || !y){ v[++nd]=v[x|y]; return nd; }
	int p=++nd;
	if (1ll*rand()*(v[x].sz+v[y].sz)<1ll*v[x].sz*RAND_MAX)
		{ v[p]=v[x]; v[p].rs=merge(v[p].rs,y); upd(p); return p; }
	else{ v[p]=v[y]; v[p].ls=merge(x,v[p].ls); upd(p); return p; }
}

P split(int x,int k){
	if (!x) return (P){0,0};
	P t; int p=++nd; v[p]=v[x];
	if (k<=v[v[x].ls].sz){ t=split(v[p].ls,k); v[p].ls=t.y; upd(p); return (P){t.x,p}; }
		else{ t=split(v[p].rs,k-v[v[x].ls].sz-1); v[p].rs=t.x; upd(p); return (P){p,t.y}; }
}

int build(int L,int R){
	if (L>R) return 0;
	int mid=(L+R)>>1,x=get(to[mid][0]);
	v[x].ls=build(L,mid-1); v[x].rs=build(mid+1,R);
	upd(x); return x;
}

int main(){
	scanf("%d%d%d",&n,&m,&s); cin>>t; int lim=5000;
	for (; t%n; t--) s=jump(s,t); t/=n;
	rep(i,1,n) to[i][0]=i; rt=build(1,n);
	rep(i,1,n-1){
		int lst=rt;
		if (m+i<=n){ P a=split(lst,m+i),b=split(a.x,i); rt=b.y; }
			else{ P a=split(lst,i),b=split(a.x,m+i-n); rt=merge(a.y,b.x); }
		if (m+1-i>0){ P a=split(lst,n-i),b=split(a.x,m-i); rt=merge(rt,b.y); }
			else{ P a=split(lst,m+n-i),b=split(a.x,n-i); rt=merge(rt,merge(a.y,b.x)); }
		if (!(i%lim)) tot=0,dfs(rt),nd=0,rt=build(1,n);
	}
	tot=0; dfs(rt);
	rep(j,1,49) rep(i,1,n) to[i][j]=to[to[i][j-1]][j-1];
	for (int j=49; ~j; j--) if (t&(1ll<<j)) s=to[s][j];
	printf("%d\n",s);
	return 0;
}

// note: the range is [l; r)

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

#define llong long long
#define xx first
#define yy second
#define len(x) ((int)x.size())
#define rep(i,n) for (int i = -1; ++ i < n; )
#define rep1(i,n) for (int i = 0; i ++ < n; )
#define all(x) x.begin(), x.end()
#define satisfy_ratio(u, v) ((u) * 3 <= (v) * 5 and (u) * 5 >= (v) * 3)
#define rand __rand
mt19937 rand(chrono::system_clock::now().time_since_epoch().count());  // or mt19937_64

struct treapnode;
typedef shared_ptr<treapnode> treapnode_ptr;

struct treapnode {
    treapnode_ptr lchild, rchild;
    int val, size, height;
    llong pri;

    treapnode() {}
    treapnode(int val_, llong pri_ = rand()) : val(val_), size(1), height(1), pri(pri_) {}
    treapnode(int val_, const treapnode_ptr& l, const treapnode_ptr& r)
        : lchild(l), rchild(r), val(val_) {
            upd_size();
        }

    int get(int pos) {
        int lsize = lchild ? lchild->size : 0;
        return
            pos == lsize ? val :
            pos < lsize ? lchild->get(pos) :
            rchild->get(pos - lsize - 1);
    }

    void upd_size() {
        size = 1 + (lchild ? lchild->size : 0) + (rchild ? rchild->size : 0);
        height = 1 + max(lchild? lchild->height : 0, rchild ? rchild->height : 0);
        // pri = max(lchild ? lchild->pri : LLONG_MIN, rchild ? rchild->pri : LLONG_MIN) + rand() % 1000000;
    }
};

int lv = 0;
treapnode_ptr join(const treapnode_ptr& u, const treapnode_ptr& v) {
    ++lv;
    if (!u and !v) return nullptr;
    if (!u) return v;
    if (!v) return u;
    if ((llong)rand() % (u->size + v->size) < (llong)u->size)
        return move(make_shared<treapnode>(u->val, u->lchild, join(u->rchild, v)));
    else
        return move(make_shared<treapnode>(v->val, join(u, v->lchild), v->rchild));
}

treapnode_ptr yank_firsthalf(const treapnode_ptr& u, int cut_size) {
    if (!u) return nullptr;

    int lsize = u->lchild ? u->lchild->size : 0;
    if (cut_size <= lsize) {
        return yank_firsthalf(u->lchild, cut_size);
    } else {
        return make_shared<treapnode>(u->val, u->lchild,
                yank_firsthalf(u->rchild, cut_size - lsize - 1
        ));
    }
}

treapnode_ptr yank_secondhalf(const treapnode_ptr& u, int cut_size) {
    if (!u) return nullptr;

    int lsize = u->lchild ? u->lchild->size : 0;
    if (cut_size <= lsize) {
        return make_shared<treapnode>(u->val, yank_secondhalf(u->lchild, cut_size), u->rchild);
    } else {
        return yank_secondhalf(u->rchild, cut_size - lsize - 1);
    }
}

treapnode_ptr safe_slice(const treapnode_ptr& u, int offset, int size) {
    offset = (offset + u->size) % u->size;
    if (offset + size <= u->size)
        return move(yank_firsthalf(yank_secondhalf(u, offset), size));
    int lsize = u->size - offset;
    return move(join(yank_secondhalf(u, offset), yank_firsthalf(u, size - lsize)));
}

ostream& operator<< (ostream& cout, const treapnode_ptr& u) {
    rep(i, u->size) cout << u->get(i) << ' ';
    return cout;
}

int n, m, s;
llong t;

treapnode_ptr build(int l, int r, const function<int(int)>& get_info) {
    if (l >= r) return nullptr;
    int mid = l + (r - l) / 2;
    auto res = make_shared<treapnode>(get_info(mid));
    if (r - l <= 1) return move(res);
    res->lchild = build(l, mid, get_info);
    res->rchild = build(mid + 1, r, get_info);
    res->upd_size();
    return move(res);
}

vector<int> vals;
void tranversal(const treapnode_ptr& root) {
    if (!root) return ;
    tranversal(root->lchild);
    vals.push_back(root->val);
    tranversal(root->rchild);
}

treapnode_ptr rebuild(const treapnode_ptr& root) {
    vals.clear();
    tranversal(root);
    return move(build(0, root->size, [&](int id) { return vals[id]; }));
}

int main(void) {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m >> s >> t;
    --s;
    treapnode_ptr root = build(0, n, [&](int id) { return id; });

    rep1(step, n - 1) {
        // clog << split(root, step, m) << endl;
        lv = 0;
        root = move(join(safe_slice(root, step, m), safe_slice(root, m - step, n - m)));
        if (root->height > 100) {
            root = move(rebuild(root));
        }
        // clog << "Step " << step << endl;
    }

    for (int i = (int) (t % n); i > 0; i--) {
        s += (s < m ? i : -i);
        s = (s + n) % n;
    }

    vector<int> dis(n, -1);
    dis[s] = 0;

    bool reduced = 0;
    for (llong i = t / n; i--; ) {
        int nxt = root->get(s);
        if (dis[nxt] == -1) {
            dis[nxt] = dis[s] + 1;
        } else if (!reduced) {
            i %= dis[s] + 1 - dis[nxt];
            reduced = 1;
        }
        s = nxt;
        // clog << s << endl;
    }
    cout << s + 1;

    return 0;
}

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

#define ar array

const int mxN=1e5, mxATS=2.5e7;
int n, m, s, dp, nxt[mxN][40], ni;
long long t;

struct avltree {
	int a[mxATS], lc[mxATS], rc[mxATS], s[mxATS], h[mxATS], ts=1;
	int cpy(int u, bool b=1) {
		if(!b)
			return u;
		a[ts]=a[u];
		lc[ts]=lc[u];
		rc[ts]=rc[u];
		s[ts]=s[u];
		h[ts]=h[u];
		return ts++;
	}
	void rcl(int u) {
		s[u]=s[lc[u]]+1+s[rc[u]];
		h[u]=max(h[lc[u]], h[rc[u]])+1;
	}
	void dfs(int u) {
		if(!u)
			return;
		dfs(lc[u]);
		nxt[ni++][0]=a[u];
		dfs(rc[u]);
	}
	bool hl(int u) {
		return h[lc[u]]-h[rc[u]]>1;
	}
	bool hr(int u) {
		return h[rc[u]]-h[lc[u]]>1;
	}
	int rr(int u) {
		int v=lc[u];
		lc[u]=rc[v];
		rc[v]=u;
		rcl(u);
		rcl(v);
		return v;
	}
	int rl(int u) {
		int v=rc[u];
		rc[u]=lc[v];
		lc[v]=u;
		rcl(u);
		rcl(v);
		return v;
	}
	int rbl(int u, bool b=1) {
		if(hl(u)) {
			u=cpy(u, b);
			lc[u]=cpy(lc[u]);
			if(h[rc[lc[u]]]>h[lc[lc[u]]]) {
				rc[lc[u]]=cpy(rc[lc[u]]);
				lc[u]=rl(lc[u]);
			}
			u=rr(u);
		} else if(hr(u)) {
			u=cpy(u, b);
			rc[u]=cpy(rc[u]);
			if(h[lc[rc[u]]]>h[rc[rc[u]]]) {
				lc[rc[u]]=cpy(lc[rc[u]]);
				rc[u]=rr(rc[u]);
			}
			u=rl(u);
		}
		return u;
	}
	int rbl2(int u) {
		bool b1=hl(u), b2=hr(u);
		if(!b1&&!b2)
			return u;
		u=rbl(u);
		if(b1) {
			if(h[rc[u]]<h[lc[u]]) {
				lc[u]=cpy(lc[u]);
				u=rr(u);
				rc[rc[u]]=rbl2(rc[rc[u]]);
			} else
				rc[u]=rbl2(rc[u]);
		} else {
			if(h[lc[u]]<h[rc[u]]) {
				rc[u]=cpy(rc[u]);
				u=rl(u);
				lc[lc[u]]=rbl2(lc[lc[u]]);
			} else
				lc[u]=rbl2(lc[u]);
		}
		rcl(u);
		return u;
	}
	int mrg(int u, int v) {
		if(!u||!v)
			return u^v;
		int w;
		if(h[u]>h[v]) {
			w=cpy(u);
			rc[w]=mrg(rc[w], v);
		} else {
			w=cpy(v);
			lc[w]=mrg(u, lc[w]);
		}
		rcl(w);
		return rbl(w, 0);
	}
	ar<int, 2> spl(int u, int k) {
		if(!u)
			return {0, 0};
		int iu=u;
		u=cpy(u);
		if(k<=s[lc[u]]) {
			ar<int, 2> a=spl(lc[u], k);
			lc[u]=a[1];
			u=rbl2(u);
			rcl(u);
			return {a[0], u};
		} else {
			ar<int, 2> a=spl(rc[u], k-s[lc[u]]-1);
			rc[u]=a[0];
			u=rbl2(u);
			rcl(u);
			return {u, a[1]};
		}
	}
} at;

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

	cin >> n >> m >> s >> t, --s;
	for(int i=0; i<n; ++i) {
		at.a[at.ts]=i;
		at.s[at.ts]=at.h[at.ts]=1;
		dp=at.mrg(dp, at.ts++);
	}
	for(int i=1; i<n; ++i) {
		ar<int, 2> a=at.spl(dp, i);
		int dp1, dp2;
		if(n-i<m) {
			ar<int, 2> b=at.spl(a[0], m-n+i);
			dp1=at.mrg(a[1], b[0]);
		} else
			dp1=at.spl(a[1], m)[0];
		a=at.spl(dp, n-i);
		if(i>m) {
			ar<int, 2> b=at.spl(a[1], m);
			dp2=at.mrg(b[1], a[0]);
		} else
			dp2=at.spl(a[0], m-i)[1];
		dp=at.mrg(dp1, dp2);
	}
	at.dfs(dp);
	while(t%n) {
		if(s<m)
			s=(s+t)%n;
		else
			s=(s-t%n+n)%n;
		--t;
	}
	t/=n;
	for(int i=1; i<40; ++i)
		for(int j=0; j<n; ++j)
			nxt[j][i]=nxt[nxt[j][i-1]][i-1];
	for(int i=39; i>=0; --i) {
		if(t>=1ll<<i) {
			t-=1ll<<i;
			s=nxt[s][i];
		}
	}
	cout << s+1;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define debug
#define maxn 100100
#define lg 500

int X[lg*maxn];
int sz[lg*maxn];
int L[lg*maxn];
int R[lg*maxn];

int qtd = 1;

inline void copy(int a,int b){
    X[b] = X[a];
    sz[b] = sz[a];
    L[b] = L[a];
    R[b] = R[a];
}

inline int top(int a,int b){
    return (rand()%(a+b)) < a;
}

void calc(int u){
    sz[u] = sz[L[u]] + sz[R[u]] + 1;
}

int merge(int l,int r){

    if(l == 0){
        return r;
    }
    if(r == 0){
        return l;
    }

    if(top(sz[l], sz[r])){

        int rc = merge(R[l],r);
        copy(l,qtd);
        R[qtd] = rc;
        calc(qtd);
        return qtd++;

    }
    else {

        int lc = merge(l,L[r]);
        copy(r,qtd);
        L[qtd] = lc;
        calc(qtd);
        return qtd++;

    }

}

void split(int u,int s,int &l,int &r){

    if(u == 0){
        l = r = 0;
        return;
    }

    if(sz[L[u]] >= s){

        split(L[u],s,l,r);
        copy(u,qtd);
        L[qtd] = r;
        r = qtd;
        calc(qtd);
        qtd++;

    }

    else {

        split(R[u],s-sz[L[u]]-1,l,r);
        copy(u,qtd);
        R[qtd] = l;
        l = qtd;
        calc(qtd);
        qtd++;

    }

}

int n,m,s;
ll t;

int get(int u,int l,int r){

    if(l < 0) l += n, r += n;

    int x,y,w,z;

    split(u,l,x,y);
    split(y,r-l+1,w,z);

    return w;

}

void print(int u){
    if(u == 0) return;
    print(L[u]);
    debug("%d ",X[u]);
    print(R[u]);
}

int XX[maxn];
int LL[maxn];
int RR[maxn];
int ssz[maxn];

int clean(int u){

    if(u == 0) return 0;

    int id = qtd++;
    XX[id] = X[u];
    ssz[id] = sz[u];
    LL[id] = clean(L[u]);
    RR[id] = clean(R[u]);
    return id;

}

int jmp[60][maxn];

int main(){

    scanf("%d%d%d%lld",&n,&m,&s,&t);
    s--;

    while(t%n){
        if(s < m) s = (s+t)%n;
        else s = (s-(t%n)+n)%n;
        t--;
    }

    int qm = 0;

    int r = 0;

    for(int i=0;i<n;i++){
        X[qtd] = i;
        sz[qtd] = 1;
        qtd++;
        r = merge(r,qtd-1);
    }

    //print(r);debug("\n");

    for(int i=1;i<=n-1;i++){
        int dupli = merge(r,r);
        int A = get(dupli,i,m+i-1);
        int B = get(dupli,m-i,n-1-i);

      //  print(A);printf("\n");
    //    print(B);printf("\n");

        r = merge(A,B);
      //  print(r);debug("\n");

        qm = max(qm,qtd);

        if(qtd > lg*maxn-20*lg){
            qtd = 1;
            r = clean(r);
            for(int j=1;j<qtd;j++){
                R[j] = RR[j];
                L[j] = LL[j];
                X[j] = XX[j];
                sz[j] = ssz[j];
            }
        }

    }

    for(int i=0;i<n;i++){
        jmp[0][i] = X[get(r,i,i)];
    }

    for(int i=1;i<60;i++)
        for(int j=0;j<n;j++)
            jmp[i][j] = jmp[i-1][jmp[i-1][j]];

    qm = max(qm,qtd);
    debug("%d\n",qm);
    t/=n;

    for(int i=0;i<60;i++)
        if(t & (1ll<<i))
            s = jmp[i][s];

    printf("%d\n",s+1);
}

/*
0 1 2
1

*/

/*
   We notice that there are only N^2 important states - (postition, t mod N). Let's make T mod N steps and see where we will be after that. This can be done in the most stupid way in O(N) time.
   Also let's for each position store the position we will arrive at after N steps. If this value for position x is to[x] the answer of our problem will be to[to[...[x]...]] (applied T / N times).
   Then after calculating the to[] array, we can simply find the cycle length of to[] and the reminder of (T / N) when divided by it. Then (T / N) <= N and we can easily find the answer in O(N).

   Now the hard part is to find the to[] array. We will go backwards. Initially set to[x] = x. Now we will use persistent treap (actually RBST) to find the actual to values. The main observation
   is that when decreasing T the to[] array will change just in two intervals. Then we can do the movements with a couple of merges and splits. The complexity will be O(N log N).

   As persistent treaps (RBST) tend to to increase their depth fast, we will rebuild our structure a couple of times.
*/

#include <bits/stdc++.h>
#define endl '\n'

//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#define SZ(x) ((int)x.size())
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back

using namespace std;
template<class T, class T1> int chkmax(T &x, const T1 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T1> int chkmin(T &x, const T1 &y) { return x > y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);
const int MAX_MEM = (1 << 23);
const int B = 2000;

random_device rd;
mt19937 mt(rd());

struct node
{
	int sz, id;
	node *l, *r;

	node() { sz = id = 0; l = r = nullptr; }
	node(int i)
	{
		l = nullptr;
		r = nullptr;
		id = i;
		sz = 1;
	}
};

using pnode = node*;

int cnt_nodes = 0;
node ptr_list[MAX_MEM];

void init_memory()
{
	cnt_nodes = 0;
}

pnode new_node(int id)
{
	ptr_list[cnt_nodes].l = ptr_list[cnt_nodes].r = nullptr;
	ptr_list[cnt_nodes].sz = 1, ptr_list[cnt_nodes].id = id;
	return ptr_list + (cnt_nodes++);
}

inline int size(pnode t) { return t ? t->sz : 0; }

bool hey(int l, int r) { return (int)mt() % (l + r) < l; }

void pull(pnode &t)
{
	if(!t) return;
	t->sz = 1 + size(t->l) + size(t->r);
}

pnode copy(pnode &t)
{
	if(!t) return nullptr;

	pnode ret = new_node(0);
	ret->id = t->id;
	ret->l = t->l;
	ret->r = t->r;
	ret->sz = t->sz;

	return ret;
}

void split(pnode t, pnode &l, pnode &r, int k, int add = 0)
{
	if(!t) { l = r = nullptr; return; }

	int idx = size(t->l) + add;
	if(idx <= k)
	{
		l = copy(t);
		split(l->r, l->r, r, k, idx + 1);
		pull(l);
	}
	else
	{
		r = copy(t);
		split(r->l, l, r->l, k, add);
		pull(r);
	}
}

void merge(pnode &t, pnode l, pnode r)
{
	if(!l) { t = copy(r); return; }
	if(!r) { t = copy(l); return; }

	if(hey(size(l), size(r)))
		t = copy(l), merge(t->r, t->r, r);
	else
		t = copy(r), merge(t->l, l, t->l);

	pull(t);
}

vector<int> tmp_rec;

void get_li_tmp(pnode t)
{
	if(!t) return;
	get_li_tmp(t->l);
	tmp_rec.pb(t->id);
	get_li_tmp(t->r);
}

vector<int> get_li(pnode t)
{
	tmp_rec.clear();
	get_li_tmp(t);
	return tmp_rec;
}

pnode build(int l, int r, vector<int> &li)
{
	if(l > r) return nullptr;

	int mid = (l + r) >> 1;

	pnode ret = new_node(li[mid]);
	ret->l = build(l, mid - 1, li);
	ret->r = build(mid + 1, r, li);

	pull(ret);

	return ret;
}

int n, m, start_pos;
int64_t t;

void read()
{
	cin >> n >> m;
	cin >> start_pos >> t;
	start_pos--;
}

int to[MAXN];

void dfs(pnode t, int p = 0)
{
	if(!t) return;
	dfs(t->l, p);
	to[p] = t->id;
	dfs(t->r, p + size(t->l) + 1);
}

pnode root = nullptr;
vector<int> tmpp;

void rebuild()
{
	tmpp = get_li(root);
	cnt_nodes = 0;
	root = build(0, n - 1, tmpp);
}

pnode get(int l, int r)
{
	if(l < 0)
	{
		pnode ret;
		merge(ret, get(n + l, n - 1), get(0, r));
		return ret;
	}

	if(r >= n)
	{
		pnode ret;
		merge(ret, get(l, n - 1), get(0, r - n));
		return ret;
	}

	pnode dummy, dummy2, ret, mid;
	split(root, mid, dummy, r);
	split(mid, dummy2, ret, l - 1);
	return ret;
}

void solve()
{
	while(t % n)
	{
		if(start_pos < m) start_pos = (start_pos + (t % n)) % n;
		else start_pos = (start_pos + n - (t % n)) % n;
		t--;
	}

	t /= n;

	for(int i = 0; i < n; i++) tmpp.pb(i);
	root = build(0, n - 1, tmpp);

	for(int i = 0; i < n; i++)
	{
		pnode L = get(i, m + i - 1);
		pnode R = get(m - i, n - 1 - i);

		merge(root, L, R);
		if(i && i % B == 0)
			rebuild();
	}

	vector<int> clist = get_li(root);
	for(int i = 0; i < n; i++) to[i] = clist[i];

	for(int cnt = 0; t > 0 && cnt < n; cnt++, t--)
		start_pos = to[start_pos];

	if(t != 0)
	{
		int cycle_len = 1, u = to[start_pos];
		while(u != start_pos)
		{
			cycle_len++;
			u = to[u];
		}

		t %= cycle_len;
		while(t--)
			start_pos = to[start_pos];
	}

	cout << start_pos + 1 << endl;
}

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

	init_memory();

	read();
	solve();
	return 0;
}

#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(a) int(a.size())
#define clr(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int inf=1e9;
const ll Inf=1e18;
const int N=1e5+10;
const int mod=0;
ll gi() {
    ll x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
template<typename T> bool chkmax(T &a,T b) { return a<b?a=b,1:0; };
template<typename T> bool chkmin(T &a,T b) { return a>b?a=b,1:0; };
int add(int a,int b) { return a+b>=mod?a+b-mod:a+b; }
int sub(int a,int b) { return a-b<0?a-b+mod:a-b; }
void inc(int &a,int b) { a=(a+b>=mod?a+b-mod:a+b); }
void dec(int &a,int b) { a=(a-b<0?a-b+mod:a-b); }
int n,m,s;ll t,vis[N];
int main() {
#ifndef ONLINE_JUDGE
    freopen("CF1056G.in","r",stdin);
    freopen("CF1056G.out","w",stdout);
#endif
    n=gi(),m=gi(),s=gi()-1,t=gi();
    while(t%n) {
        if(s<m) s=(s+t%n)%n;
        else s=(s-t%n+n)%n;
        --t;
    }
    memset(vis,-1,sizeof(vis));
    vis[s]=t,t/=n;
    while(t--) {
        for(int i=n-1;~i;i--) {
            if(s<m) s=(s+i%n)%n;
            else s=(s-i%n+n)%n;
        }
        if(~vis[s]) t%=vis[s]-t;
        vis[s]=t;
    }
    printf("%d\n",s+1);
    return 0;
}

#define _CRT_SECURE_NO_DEPRECATE
#define _USE_MATH_DEFINES
#include <array>
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <ctime>
#include <numeric>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <complex>
#include <deque>
#include <functional>
#include <list>
#include <map>
#include <string>
#include <sstream>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <forward_list>
#include <thread>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<short, short> pss;
typedef pair<LL, LL> pll;
typedef pair<ULL, ULL> puu;
typedef pair<ld, ld> pdd;
template<class T> inline T sqr(T x) { return x * x; }
template<class T> inline T parse(const string&s){T x;stringstream ss(s);ss>>x;return x;}
#define left asdleft
#define right asdright
#define link asdlink
#define unlink asdunlink
#define next asdnext
#define prev asdprev
#define y0 asdy0
#define y1 asdy1
#define mp make_pair
#define MT make_tuple
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define clr(ar,val) memset(&ar, val, sizeof(ar))
#define istr stringstream
#define forn(i,n) for(int i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define X first
#define Y second
const ld EPS = 1e-12;
const int INF = 1000*1000*1000;
const LL LINF = INF * 1ll * INF;
const ld DINF = 1e200;
const ld PI = 3.1415926535897932384626433832795l;
int gcd(int a,int b){return a?gcd(b%a,a):b;}
LL gcd(LL a,LL b){return a?gcd(b%a,a):b;}
LL gcdex(LL a,LL b,LL &x,LL &y){if(!a){x=0,y=1;return b;}LL k=b/a;LL g=gcdex(b-k*a,a,y,x);x-=k*y;return g;}
LL inv(LL a,LL m){assert(m>1);LL x,y,g;g=gcdex(a,m,x,y);return (x%(m/g)+m/g)%m/g;}
LL crt(LL a1,LL m1,LL a2,LL m2){LL a=(a2-a1%m2+m2)%m2;LL x,y,g;g=gcdex(m1,m2,x,y);if(a%g)return -1;LL m=m1/g*m2;assert(x+m2>=0);x=a/g*(x+m2)%m2;LL r=(a1+x*m1)%m;assert(r%m1==a1 && r%m2==a2);return r;}
LL powmod(LL a,LL p,LL m){assert(p>=0);LL r=1;while(p){if(p&1)r=r*a%m;p>>=1;a=a*a%m;}return r;}
bool isprime(LL a){if(a<=1)return false;for (LL i=2;i*i<=a;++i){if(a%i==0)return false;}return true;}
LL sqrtup(LL a){if(!a)return 0;LL x=max(0ll,(LL)sqrt((ld)a));while(x*x>=a)--x;while((x+1)*(x+1)<a)++x;return x+1;}
LL isqrt(LL a){if(a<=0){assert(!a);return 0;}LL x=(LL)sqrt((ld)a);while(sqr(x+1)<=a)++x;while(x*x>a)--x;return x;}
LL sgn(LL x){return x<0?-1:x>0?1:0;}
template<class T> ostream& operator<<(ostream &s, const vector<T> &v);
template<class A,class B> ostream& operator<<(ostream &s, const pair<A,B> &p);
template<class K,class V> ostream& operator<<(ostream &s, const map<K,V> &m);
template<class T> ostream& operator<<(ostream &s, const set<T> &m);
template<class T,size_t N> ostream& operator<<(ostream &s, const array<T,N> &a);
template<class... T> ostream& operator<<(ostream &s, const tuple<T...> &t);
template<class T> ostream& operator<<(ostream &s, const vector<T> &v){s<<'[';forv(i,v){if(i)s<<',';s<<v[i];}s<<']';return s;}
template<class A,class B> ostream& operator<<(ostream &s, const pair<A,B> &p){s<<"("<<p.X<<","<<p.Y<<")";return s;}
template<class K,class V> ostream& operator<<(ostream &s, const map<K,V> &m){s<<"{";bool f=false;for(const auto &it:m){if(f)s<<",";f=true;s<<it.X<<": "<<it.Y;}s<<"}";return s;}
template<class T> ostream& operator<<(ostream &s, const set<T> &m){s<<"{";bool f=false;for(const auto &it:m){if(f)s<<",";f=true;s<<it;}s<<"}";return s;}
template<class T> ostream& operator<<(ostream &s, const multiset<T> &m){s<<"{";bool f=false;for(const auto &it:m){if(f)s<<",";f=true;s<<it;}s<<"}";return s;}
template<class T,class V,class C> ostream& operator<<(ostream &s, const priority_queue<T,V,C> &q) {auto a=q;s<<"{";bool f=false;while(!a.empty()){if(f)s<<",";f=true;s<<a.top();a.pop();}return s<<"}";}
template<class T,size_t N> ostream& operator<<(ostream &s, const array<T,N> &a){s<<'[';forv(i,a){if(i)s<<',';s<<a[i];}s<<']';return s;}
template<class T> ostream& operator<<(ostream &s, const deque<T> &a){s<<'[';forv(i,a){if(i)s<<',';s<<a[i];}s<<']';return s;}
template<size_t n,class... T> struct put1 { static ostream& put(ostream &s, const tuple<T...> &t){s<<get<sizeof...(T)-n>(t);if(n>1)s<<',';return put1<n-1,T...>::put(s,t);} };
template<class... T> struct put1<0,T...> { static ostream& put(ostream &s, const tuple<T...> &t){return s;} };
template<class... T> ostream& operator<<(ostream &s, const tuple<T...> &t){s<<"(";put1<sizeof...(T),T...>::put(s,t);s<<")";return s;}
ostream& put3(ostream &s, const char*, bool) {return s;}
template<class U,class... T> ostream& put3(ostream &s, const char *f, bool fs, U&& u, T&&... t) {
  while(*f==' ')++f;if (!fs)s<<", ";auto nf=f;int d=0;while(*nf&&(*nf!=','||d)){if(*nf=='(')++d;else if(*nf==')')--d;++nf;}
  auto nf2=nf;while(nf2>f&&*(nf2-1)==' ')--nf;fs=*f=='"';if(!fs){s.write(f,nf2-f);s<<"=";};s<<u;if(fs)s<<' ';if(*nf)++nf;return put3(s,nf,fs,forward<T>(t)...);}
#ifdef __ASD__
auto qweasdt0 = chrono::steady_clock::now();
#define dbg(...) do { cerr.setf(ios::fixed,ios::floatfield);cerr.precision(6);double qweasdt = chrono::duration_cast<chrono::duration<double>>(chrono::steady_clock::now() - qweasdt0).count();cerr << '[' << __LINE__ << ' ' << qweasdt << "] "; put3(cerr, #__VA_ARGS__, 1, ##__VA_ARGS__); cerr << endl; }while(false)
#include "draw.h"
#define draw(x,...) dr::get().add((new dr::x)__VA_ARGS__)
#define drawc(x) dr::get().x
#else
#define dbg(...) do{}while(false)
#define draw(...) do{}while(false)
#define drawc(...) do{}while(false)
#endif

int main(int argc, char **argv){
  ios_base::sync_with_stdio(false);cin.tie(0);cout.precision(20);srand(time(0));

  LL n,m;
  cin>>n>>m;
  LL S,T;
  cin>>S>>T;
  --S;
  auto go=[&]{
            if(!T){
              cout<<S+1;
              exit(0);
            }
            if(S<m) (S+=T)%=n;
            else (S+=n-T%n)%=n;
            --T;
            if(!T){
              cout<<S+1;
              exit(0);
            }
          };
  while(T%n) go();
  map<LL,LL> W;
  while(true){
    forn(i,n) go();
    if(W.count(S)){
      T%=W.at(S)-T;
      break;
    }
    W[S]=T;
  }
  while(true) go();

  return 0;
}

#include<cstdio>
#include<algorithm>
#include<iostream>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std;

const int N=100010;
ll t;
int n,m,s,nd,rt,tot,to[N][50];
struct Tr{ int ls,rs,v,sz,d; }v[N<<8];
struct P{ int x,y; };

int jump(ll x,ll y){
	if (x<=m) x+=y; else x-=y;
	return (x%n+n-1)%n+1;
}

void upd(int x){ v[x].sz=v[v[x].ls].sz+v[v[x].rs].sz+1; v[x].d=max(v[v[x].ls].d,v[v[x].rs].d)+1; }
int get(int k){ v[++nd]=(Tr){0,0,k,1,1}; return nd; }
void dfs(int x){ if (v[x].ls) dfs(v[x].ls); to[++tot][0]=v[x].v; if (v[x].rs) dfs(v[x].rs); }
void Print(int x){ if (v[x].ls) Print(v[x].ls); printf("%d ",v[x].v); if (v[x].rs) Print(v[x].rs); }

int merge(int x,int y){
	if (!x || !y){ v[++nd]=v[x|y]; return nd; }
	int p=++nd;
	if (1ll*rand()*(v[x].sz+v[y].sz)<1ll*v[x].sz*RAND_MAX)
		{ v[p]=v[x]; v[p].rs=merge(v[p].rs,y); upd(p); return p; }
	else{ v[p]=v[y]; v[p].ls=merge(x,v[p].ls); upd(p); return p; }
}

P split(int x,int k){
	if (!x) return (P){0,0};
	P t; int p=++nd; v[p]=v[x];
	if (k<=v[v[x].ls].sz){ t=split(v[p].ls,k); v[p].ls=t.y; upd(p); return (P){t.x,p}; }
		else{ t=split(v[p].rs,k-v[v[x].ls].sz-1); v[p].rs=t.x; upd(p); return (P){p,t.y}; }
}

int build(int L,int R){
	if (L>R) return 0;
	int mid=(L+R)>>1,x=get(to[mid][0]);
	v[x].ls=build(L,mid-1); v[x].rs=build(mid+1,R);
	upd(x); return x;
}

int main(){
	scanf("%d%d%d",&n,&m,&s); cin>>t;
	for (; t%n; t--) s=jump(s,t); t/=n;
	rep(i,1,n) to[i][0]=i; rt=build(1,n);
	rep(i,1,n-1){
		int lst=rt;
		if (m+i<=n){ P a=split(lst,m+i),b=split(a.x,i); rt=b.y; }
			else{ P a=split(lst,i),b=split(a.x,m+i-n); rt=merge(a.y,b.x); }
		if (m+1-i>0){ P a=split(lst,n-i),b=split(a.x,m-i); rt=merge(rt,b.y); }
			else{ P a=split(lst,m+n-i),b=split(a.x,n-i); rt=merge(rt,merge(a.y,b.x)); }
		if (v[rt].d>200) tot=0,dfs(rt),nd=0,rt=build(1,n);
	}
	tot=0; dfs(rt);
	rep(j,1,49) rep(i,1,n) to[i][j]=to[to[i][j-1]][j-1];
	for (int j=49; ~j; j--) if (t&(1ll<<j)) s=to[s][j];
	printf("%d\n",s);
	return 0;
}

#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;

typedef long long ll;
const int Maxn = 1e5;

struct NonRotateTreap {
	struct TreapNode {
		int key, siz, fix;
		TreapNode *lch, *rch;
	};
	TreapNode pool[Maxn * 50 + 5];
	TreapNode *NIL, *ncnt;
	typedef pair<TreapNode *, TreapNode *> Droot;
	void init() {
		ncnt = NIL = &pool[0];
		NIL->lch = NIL->rch = NIL;
		NIL->siz = 0, NIL->fix = 0, NIL->key = 0;
	}
	void pushup(TreapNode *rt) {
		rt->siz = rt->lch->siz + rt->rch->siz + 1;
	}
	TreapNode *newnode(TreapNode *rt) {
		TreapNode *p = ++ncnt;
		(*p) = (*rt);
		return p;
	}
	TreapNode *newnode(int val) {
		TreapNode *p = ++ncnt;
		p->key = val, p->siz = 1, p->fix = rand();
		p->lch = p->rch = NIL;
		return p;
	}
	TreapNode *merge(TreapNode *rt1, TreapNode *rt2) {
		if(rt1 == NIL) return rt2;
		if(rt2 == NIL) return rt1;
		TreapNode *t;
		if(rt1->fix <= rt2->fix) {
			t = newnode(rt1);
			t->rch = merge(rt1->rch, rt2);
			pushup(t);
		} else {
			t = newnode(rt2);
			t->lch = merge(rt1, rt2->lch);
			pushup(t);
		}
		return t;
	}
	Droot split_rnk(TreapNode *rt, int k) {
		Droot d(NIL, NIL);
		if(rt == NIL) return d;
		TreapNode *p = newnode(rt);
		if(k <= rt->lch->siz) {
			d = split_rnk(rt->lch, k);
			p->lch = d.second;
			d.second = p;
		} else {
			d = split_rnk(rt->rch, k - rt->lch->siz - 1);
			p->rch = d.first;
			d.first = p;
		}
		pushup(p);
		return d;
	}
	TreapNode *build(int *f, int l, int r) {
		if(l > r) return NIL;
		int mid = (l + r) >> 1;
		TreapNode *p = newnode(f[mid]);
		p->lch = build(f, l, mid - 1);
		p->rch = build(f, mid + 1, r);
		pushup(p);
		return p;
	}
	void trans(TreapNode *rt, int *f, int k) {
		if(rt == NIL) return;
		f[rt->lch->siz + 1 + k] = rt->key;
		trans(rt->lch, f, k);
		trans(rt->rch, f, k + rt->lch->siz + 1);
	}
	TreapNode *rebuild(int *f, int n, TreapNode *root) {
		trans(root, f, 0);
		ncnt = &pool[0];
		return build(f, 1, n);
	}
};
NonRotateTreap::TreapNode *root;
NonRotateTreap tree;

int f[Maxn + 5];
int nxt[42][Maxn + 5];

int main() {
#ifdef LOACL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	srand(20192813);
	int N, M, S;
	ll T;
	scanf("%d %d %d %lld", &N, &M, &S, &T);
	for(int i = 1; i <= N; i++)
		f[i] = i;
	tree.init();
	root = tree.build(f, 1, N);
	for(int i = 1; i <= N; i++) {
		if(i % 230 == 0)
			root = tree.rebuild(f, N, root);
		NonRotateTreap::TreapNode *p, *q, *tmp;
		tmp = tree.split_rnk(root, i).second;
		if(tmp->siz >= M)
			p = tree.split_rnk(tmp, M).first;
		else p = tree.merge(tmp, tree.split_rnk(root, M - tmp->siz).first);
		tmp = tree.split_rnk(root, N - i).first;
		if(tmp->siz >= N - M)
			q = tree.split_rnk(tmp, tmp->siz - (N - M)).second;
		else q = tree.merge(tree.split_rnk(root, N - ((N - M) - tmp->siz)).second, tmp);
		root = tree.merge(p, q);
	}
	tree.trans(root, f, 0);
	while(T % N) {
		if(S <= M) S = (S - 1 + T) % N + 1;
		else S = ((S - 1 - T) % N + N) % N + 1;
		T--;
	}
	for(int i = 1; i <= N; i++)
		nxt[0][i] = f[i];
	for(int j = 1; j <= 41; j++)
		for(int k = 1; k <= N; k++)
			nxt[j][k] = nxt[j - 1][nxt[j - 1][k]];
	ll tmp = T / N;
	for(int i = 41; i >= 0; i--)
		if((1LL << i) & tmp) S = nxt[i][S];
	printf("%d\n", S);
	return 0;
}

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

int n, m;

void go(int &u, int t) {
  for (int i = t; i > 0; --i) {
    if (u < m) {
      u += i;
    } else {
      u -= i;
    }
    u += (u < 0) ? n : 0;
    u -= (u >= n) ? n : 0;
  }
}

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

  int s;
  long long t;
  cin >> n >> m >> s >> t;

  go(--s, t % n);
  t /= n;

  vector<int> visited(n, -1);
  vector<int> cycle = {s};
  visited[s] = 0;

  for (int i = 1; i <= t; ++i) {
    go(s, n);

    if (visited[s] != -1) {
      t -= i;
      t %= i - visited[s];
      cout << cycle[visited[s] + t] + 1 << "\n";
      exit(0);
    }

    visited[s] = i;
    cycle.push_back(s);
  }

  cout << s + 1 << "\n";
}

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

ll readint(){
	ll x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

ll n,m,s,t;
ll g[100005];
map<ll,int> d[100005];

int ask(ll x){
	if(g[x]!=-1) return g[x];
	ll tmp=x;
	for(int i=n;i>=1;i--){
		if(x<m) x=(x+i)%n;
		else x=(x-i+n)%n;
	}
	return g[tmp]=x;
}

int work(ll x,ll k){
	if(k==0) return x;
	if(k==1) return ask(x);
	if(d[x].count(k)) return d[x][k];
	return d[x][k]=work(work(x,k/2),k-k/2);
}

int main(){
	n=readint(); m=readint(); s=readint()-1; t=readint();
	while(t%n!=0){
		if(s<m) s=(s+t%n)%n;
		else s=(s-t%n+n)%n;
		t--;
	}
	memset(g,-1,sizeof(g));
	printf("%d\n",work(s,t/n)+1);
	return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll naive(ll n, ll m, ll s, ll t)
{
	ll cur = s;
	while(t>0)
	{
		if(cur%n>=m)
		{
			cur-=t;
		}
		else
		{
			cur+=t;
		}
		cur%=n;
		if(cur<0) cur+=n;
		t--;
	}
	return cur;
}

const ll C = 250;
ll md[111111];
vector<ll> M[111111];

ll fast(ll n, ll m, ll s, ll t)
{
	if(t<=n) return naive(n,m,s,t);
	while(t%n!=0)
	{
		if(s%n>=m)
		{
			s-=t;
		}
		else
		{
			s+=t;
		}
		s%=n;
		if(s<0) s+=n;
		t--;
	}
	if(t==0) return s;
	//solve t/n copies of the problem, sort of
	if(m>n-m)
	{
		return n - 1 - fast(n, n-m, n-1-s, t); //check later
	}
	for(ll i=0;i<=n+5;i++)
	{
		ll s = (i*(i-1))/2;
		md[i] = s%n; M[i].clear();
	}
	for(ll i=1;i<=n+5;i++) M[md[i]].pb(i);
	//m <= n - m
	if(m<=C) //small
	{
		vector<vector<ll> > dp(m+2);
		for(int i=0;i<=m;i++)
		{
			dp[i].assign(n,0);
			dp[i][0]=i;
		}
		for(int j=1;j<n;j++)
		{
			for(int k=0;k<m;k++)
			{
				ll times = j; ll cur = k;
				while(times>0)
				{
					if(cur%n>=m)
					{
						cur-=times;
					}
					else
					{
						cur+=times;
					}
					cur%=n;
					if(cur<0) cur+=n;
					times--;
					if(cur<=m) break;
				}
				dp[k][j]=dp[cur][times];
			}
			ll ext = -1; ll besti = -1;
			for(int k=0;k<m;k++)
			{
				ll r = k - m + md[j+1];
				r%=n; if(r<0) r+=n;
				int lb = lower_bound(M[r].begin(),M[r].end(),j+1)-M[r].begin();
				lb--;
				if(lb>=0)
				{
					ll curi = M[r][lb];
					if(curi>besti)
					{
						besti=curi; ext=k;
					}
				}
			}
			if(besti==-1)
			{
				ll r = m - md[j+1];
				r%=n; if(r<0) r+=n;
				dp[m][j] = r;
			}
			else
			{
				dp[m][j] = dp[ext][besti-1];
			}
		}
		vector<ll> F(n+2,0);
		for(int i=0;i<=m;i++) F[i]=dp[i][n-1];
		for(int i=m+1;i<n;i++)
		{
			ll ext = -1; ll besti = -1; ll j = n - 1;
			for(int k=0;k<m;k++)
			{
				ll r = k - i + md[j+1];
				r%=n; if(r<0) r+=n;
				int lb = lower_bound(M[r].begin(),M[r].end(),j+1)-M[r].begin();
				lb--;
				if(lb>=0)
				{
					ll curi = M[r][lb];
					if(curi>besti)
					{
						besti=curi; ext=k;
					}
				}
			}
			if(besti==-1)
			{
				ll r = i - md[j+1];
				r%=n; if(r<0) r+=n;
				F[i] = r;
			}
			else
			{
				F[i] = dp[ext][besti-1];
			}
		}
		/*
		for(int i=0;i<n;i++) cerr<<F[i]<<' ';
		cerr<<'\n';
		*/
		ll cyc = t/n;
		//solve cyc cycles tbh
		map<ll,ll> ma;
		ma[s] = cyc;
		vector<ll> V; V.pb(s);
		ll len = -1;
		while(cyc>0)
		{
			cyc--;
			ll news = F[s]; s = news; V.pb(s);
			if(ma.find(news)==ma.end())
			{
				ma[news]=cyc;
			}
			else
			{
				ll cur = ma[news];
				len = cur - cyc;
				break;
			}
		}
		if(cyc==0) return s;
		//I still need cyc times :(
		cyc%=len;
		int id=0;
		for(int i=0;i<V.size();i++)
		{
			if(V[i]==s){id=i; break;}
		}
		return V[id+cyc];
	}
	else //do big
	{
		ll cyc = t/n;
		//solve cyc cycles tbh
		map<ll,ll> ma;
		ma[s] = cyc;
		vector<ll> V; V.pb(s);
		ll len = -1;
		while(cyc>0)
		{
			cyc--;
			ll news = naive(n, m, s, n); s = news; V.pb(s);
			if(ma.find(news)==ma.end())
			{
				ma[news]=cyc;
			}
			else
			{
				ll cur = ma[news];
				len = cur - cyc;
				break;
			}
		}
		if(cyc==0) return s;
		//I still need cyc times :(
		cyc%=len;
		int id=0;
		for(int i=0;i<V.size();i++)
		{
			if(V[i]==s){id=i; break;}
		}
		return V[id+cyc];
	}
}

void test(ll n, ll m)
{
	{
		cout<<"TEST "<<m<<" : ";
		//set<ll> S;
		for(ll s=0;s<n;s++)
		{
			//S.insert(naive(n,m,s,n-1));
			cout<<naive(n,m,s,n-1)<<' ';
		}
		//cout<<S.size()<<'\n';
	}
}

const bool DEBUG = 0;
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	//test(1882,22); return 0;
	//ll n; cin>>n; test(n);
	for(int cc=1;;cc++)
	{
		ll n,m,s,t;
		if(!DEBUG)
		{
			cin>>n>>m>>s>>t; s--;
		}
		else
		{
			n=rand()%2500+1;m=rand()%(n-1)+1;s=rand()%n;t=rand()+1;
		}
		ll f=fast(n,m,s,t);
		if(!DEBUG){cout<<f+1<<'\n'; return 0;}
		ll ss=naive(n,m,s,t);
		cerr<<"FAST : "<<f<<'\n';
		cerr<<"ANSWER : "<<ss<<'\n';
		if(f!=ss)
		{
			freopen("metro.out","w",stdout);
			cout<<n<<' '<<m<<' '<<s+1<<' '<<t<<'\n';
			return 0;
		}
		cerr<<"Case #"<<cc<<" complete\n";
	}
}

#include <bits/stdc++.h>
#define X first
#define Y second
#define PB push_back
#define LL long long
#define rank AJLDSAKLDSALK
using namespace std;
const LL INF = 1000 * 1000 * 1000;
const LL LINF = INF * (LL)INF;
const int MAX = 100005;
const int mod = 1000 * 1000 * 1000 + 7;
unordered_map<LL , int> wher;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    wher.reserve(80000000);
    wher.max_load_factor(0.25);
    int n , m; LL s;
    LL t;
    cin >> n >> m >> s >> t;
    LL T = t;
    s--;
    int idx = 0;
    wher[s * n + t % n] = 0;
    //cout << s << " " << t % n << " " << 0 << endl;
    t %= n;
    while(true)
    {
        if(s < m)
        {
            s += t;
            if(s >= n)
                s -= n;
        }
        else
        {
            s -= t;
            if(s < 0)
                s += n;
        }
        t--;
        if(t < 0)
            t += n;
        if(wher.count(s * n +  t))
            break;
        wher[s * n + t] = ++idx;
        //cout << s << " " << t % n << " " << idx << endl;
        //++idx;
        if(idx == T)
        {
            cout << s + 1;
            return 0;
        }
    }
    //cout << idx + 1 << " " << wher[{s , t % n}] << endl;

    int cycleLen = idx + 1 - wher[s * n + t % n];
   // cout << cycleLen << endl;
    T -= wher[s * n + t % n];
    T %= cycleLen;
    //cout << T << endl;
    while(T)
    {
        if(s < m)
        {
            s += T;
            s %= n;
        }
        else
        {
            s -= T % n;
            if(s < 0)
                s += n;
        }
        T--;
    }
    cout << s + 1;
    return 0;
}

#include <bits/stdc++.h>

#define itn int
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

#define random_shuffle(...) shuffle(__VA_ARGS__, rng)
#define rand() rng()

using namespace std;

inline int nxt() {
	int x;
	scanf("%d", &x);
	return x;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
	int n = nxt(), m = nxt();

	int s = nxt() - 1;
	long long t;
	cin >> t;
	while (t % n) {
		if (s < m) {
			s = (s + t % n) % n;
		} else {
			s = (s - t % n + n) % n;
		}
		--t;
	}

	function<int(int, int)> get = [&](int v, int k) {
		if (k == 0) {
			return v;
		}
		if (v < m) {
			v = (v + k) % n;
		} else {
			v = (v - k + n) % n;
		}
		return get(v, k - 1);
	};

	vector<int> big(n, -1);
	vector<int> step(n, -1);
	int cur = 0;
	while (t) {
		if (big[s] > -1) {
			break;
		}
		step[s] = cur++;
		s = big[s] = get(s, n);
		t -= n;
	}

	t /= n;
	t %= cur - step[s];
	while (t) {
		s = big[s];
		t -= 1;
	}

	cout << s + 1 << "\n";

	return 0;
}

#include <cstdlib>
#include <iostream>
#include <cstdio>
#include <math.h>
#include <cstring>
#include <time.h>
#include <complex>
#include <algorithm>
#include <queue>
#include <stack>

#pragma warning(disable:4996)
#define lowbit(a) ((a)&-(a))

template<typename T> T min(T x, T y)
{
	return x < y ? x : y;
}
template<typename T> T max(T x, T y)
{
	return x > y ? x : y;
};

const long long MAXN = 500005;
const int INF = 2000000005;

struct node {
	int key;
	int size;
	node *lson;
	node *rson;
	node()
	{
		key = 0;
		size = 1;
		lson = rson = NULL;
	}
	void fixup()
	{
		size = (lson ? lson->size : 0) + (rson ? rson->size : 0) + 1;
	}
};

struct pair {
	node *fir;
	node *sec;
	pair(node *x = NULL, node *y = NULL)
	{
		fir = x;
		sec = y;
	}
};

node pool[40000000];
int pointer = 0;
node *newnode(int k = 0)
{
	pool[pointer].key = k;
	return &pool[pointer++];
}

int z;
bool shouldleft(int a, int b)
{
	return rand() % (a + b) < a;
}
node *merge(node *T1, node *T2)
{
	if (!T1)
		return T2;
	if (!T2)
		return T1;
	node *t = newnode();
	if (shouldleft(T1->size, T2->size))
	{
		*t = *T1; z++;
		t->rson = merge(t->rson, T2);
		t->fixup();
		return t;
	}
	*t = *T2; z++;
	t->lson = merge(T1, t->lson);
	t->fixup();
	return t;
}
pair split(node *T, int k)
{
	if (!T)
		return pair();
	node *t = newnode();
	*t = *T; z++;
	int r = (T->lson ? T->lson->size : 0) + 1;
	if (k < r)
	{
		pair pa = split(T->lson, k);
		t->lson = pa.sec;
		t->fixup();
		return pair(pa.fir, t);
	}
	pair pa = split(T->rson, k - r);
	t->rson = pa.fir;
	t->fixup();
	return pair(t, pa.sec);
}

int L_or_E(node *T, int k)
{
	if (!T)
		return 0;
	if (T->key <= k)
		return (T->lson ? T->lson->size : 0) + 1 + L_or_E(T->rson, k);
	return L_or_E(T->lson, k);
}
int query(node *T, int k)
{
	int r = (T->lson ? T->lson->size : 0) + 1;
	if (r == k)
		return T->key;
	if (k < r)
		return query(T->lson, k);
	return query(T->rson, k - r);
}

int next[51][MAXN], ns;
void dfs(node *T, int *a, int &cur)
{
	if (T->lson)
		dfs(T->lson, a, cur);
	a[++cur] = T->key;
	if (T->rson)
		dfs(T->rson, a, cur);
}

node *build(int *a, int L, int R)
{
	if (L > R)
		return NULL;
	int mid = (L + R) / 2;
	node *p = newnode(a[mid]);
	p->lson = build(a, L, mid - 1);
	p->rson = build(a, mid + 1, R);
	p->fixup();
	return p;
}

int temp[MAXN], ts;
node *rebuild(node *T)
{
	ts = 0;
	dfs(T, temp, ts);
	return build(temp, 1, ts);
}

int N, M, S;
long long T;
node *p;

void brute()
{
	if (S <= M)
		S = (S + T) % N;
	else
		S = ((S - T) % N + N) % N;
	if (S == 0)
		S = N;
	T--;
}

node *get(int l, int r)
{
	while (l <= 0)
	{
		l += N;
		r += N;
	}
	while (l > N)
	{
		l -= N;
		r -= N;
	}
	if (r > N)
		return merge(get(l, N), get(N + 1, r));
	pair t1 = split(p, r);
	pair t2 = split(t1.fir, l - 1);
	return t2.sec;
}

void init()
{
	scanf("%d %d %d %lld", &N, &M, &S, &T);
	for (int i = 1; i <= N; i++)
		p = merge(p, newnode(i));
	for (int i = 1; i < N; i++)
	{
		int Z = z;
		p = merge(get(1 + i, M + i), get(M + 1 - i, N - i));
		if (z - Z > 1000)
			p = rebuild(p);
	}
	dfs(p, next[0], ns);
	for (int i = 1; i <= 50; i++)
		for (int j = 1; j <= N; j++)
			next[i][j] = next[i - 1][next[i - 1][j]];
}

int main()
{
	init();

	while (T%N)
		brute();

	T /= N;
	for (int i = 50; i >= 0; i--)
		if (T&(1ll << i))
			S = next[i][S];

	printf("%d", S);

	return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
static inline void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
    T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b) {
        T q = a/b; a %= b; swap(a, b);
        x0 -= q*x1; swap(x0, x1);
        y0 -= q*y1; swap(y0, y1);
    }
    x = x0; y = y0; return a;
}
static inline int ctz(unsigned x) {return __builtin_ctz(x);}
static inline int ctzll(ull x) {return __builtin_ctzll(x);}
static inline int clz(unsigned x) {return __builtin_clz(x);}
static inline int clzll(ull x) {return __builtin_clzll(x);}
static inline int popcnt(unsigned x) {return __builtin_popcount(x);}
static inline int popcntll(ull x) {return __builtin_popcountll(x);}
static inline int bsr(unsigned x) {return 31^clz(x);}
static inline int bsrll(ull x) {return 63^clzll(x);}

int main()
{
    canhazfast();

    int n, m;
    int p1, p2, d1, d2;
    ll t1, t2, len = 0;

    cin >> n >> m >> p1 >> t1;
    auto step = [n, m](ll &t, int &p, int &d) -> void {
        if (p < m) p = p+d < n ? p+d : p+d-n;
        else p = p < d ? p+n-d : p-d;
        --t;
        d = d ? d-1 : n-1;
    };
    --p1;
    p2 = p1;
    t2 = t1;
    d1 = d2 = t1%n;
    for (;;) {
        step(t1, p1, d1);
        step(t2, p2, d2); retif(!t2) cout << p2+1, 0;
        step(t2, p2, d2); retif(!t2) cout << p2+1, 0;
        if (p1 == p2 && d1 == d2) {
            len = t1-t2;
            break;
        }
    }
    t2 %= len;
    while (t2) step(t2, p2, d2);
    cout << p2+1;

    return 0;
}

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int n,m;
void add(int& a,int b){
  a += b;
  if(a >= n)
    a -= n;
}
void sub(int& a,int b){
  a -= b;
  if(a < 0)
    a += n;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n >> m;
//   vector<vector<int>> dp(n+1,vector<int>(n));
//   R(i,n)dp[0][i] = i;
//   debug(dp[0]);
//   R(i,n+1)if(i){
//     R(j,n){
//       if(j < m){
//       //  debug(i,j, dp[i-1][add(j,i)], add(j,i));
//         dp[i][j] = dp[i-1][add(j,i)];
//       }else{
//         dp[i][j] = dp[i-1][sub(j,i)];
//       }
//       cerr << dp[i][j] << " ";
//     }
//     cerr << "\n";
//   }
//
//   R(i,n)

  int s,t;
  cin >> s >> t;
  int skok = t % n;
  vector<int> k(n,-1);
  s--;
  while(t){
    if(skok == 0){
      if(k[s] > 0){
        t %= (k[s] - t);
        k = vector<int>(n,-2);
      }else{
        if(k[s] == -1)
          k[s] = t;
      }
      if(t == 0)break;
      skok = n - 1;
    }else{
       if(s < m){
//         if(m - s > skok){
//           int sk = (m - s) / skok;
//           mini(sk,skok);
//           int pom = (2 * skok - sk + 1) * sk;
//           pom >>= 1;
//           skok -= sk;
//           t -= sk;
//           s += pom;
//         }
        add(s,skok);
      }else{
//         if(s - m > skok){
//           int sk = (s - m) / skok;
//           mini(sk,skok);
//           int pom = (2 * skok - sk + 1) * sk;
//           pom >>= 1;
//           skok -= sk;
//           t -= sk;
//           s -= pom;
//         }
        sub(s,skok);
      }
      skok --;
    }
    t--;
//    debug(s,t,skok);
  }
  s++;
  cout << s << "\n";
//   cout << dp[t][s-1] + 1 << "\n";
}

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M,B;
int S;
ll T;

vector<int> hist;
int vis[303030];

int nex(int S,ll T) {
	if(S<M) S+=T%N;
	else S+=N-T%N;
	return S%N;
}

void solve() {
	int i,j,k,l,r,x,y; string s;

	cin>>N>>M;
	B=N-M;
	cin>>S>>T;
	S--;

	while(T%N) S=nex(S,T),T--;
	T/=N;

	MINUS(vis);
	FOR(i,T) {
		if(vis[S]!=-1) {
			int per=i-vis[S];
			S=hist[vis[S]+(T-i)%per];
			break;
		}
		vis[S]=i;
		hist.push_back(S);
		for(j=N-1;j>=0;j--) S=nex(S,j);
	}
	cout<<(S+1)<<endl;

}

int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

#ifndef HOME
	#pragma GCC target("avx")
	#pragma GCC optimize("Ofast")
	#pragma GCC optimize("unroll-loops")
	#pragma comment(linker, "/stack:200000000")
	#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define MAX(a, b) __builtin_ia32_pmaxsd128(a, b)
#define MIN(a, b) __builtin_ia32_pminsd128(a, b)

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

using namespace __gnu_cxx;
using namespace __gnu_pbds;

template <class key_type>
using superTree = tree<key_type, null_type, less<key_type>,
					   rb_tree_tag, tree_order_statistics_node_update>;
using v4si = int __attribute__ ((vector_size(16)));

const int MOD = 1000000007;

inline int _(int x, int y) {
	x += y;
	if (x >= MOD) { return x - MOD; }
	if (x < 0)    { return x + MOD; }
	return x; }

inline void __(int &x, int y) {
	x = _(x, y); }

/*
 * TO DO:
 *
 * - long long instead of int
 * - bigger array sizes
 * - array / list instead of map / set
 * - can bruteforce with tricks pass system tests?
 *
 * - NEVER STOP THINKING / CODING !!!
 */

const int DIM = 200005;

int n, m, s; long long t;
long long pos[DIM];

inline void step(int &x, long long &t) {
	if (x < m) {
		x = (t + x) % n; }
	else {
		x = ((-t + x) % n + n) % n; }
	--t; }

int main(void) {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
#ifdef HOME
	freopen("cf.in", "r", stdin);
	freopen("cf.out", "w", stdout);
#endif
	cin >> n >> m >> s >> t; --s;
	while (t) {
		if (pos[s]) { // we will go in a cycle from now on
			t %= (pos[s] - t); }
		pos[s] = t;
		if (t <= n) {
			while (t) {
				step(s, t); } }
		else {
			for (int i = 1; i <= n; ++i) {
				step(s, t); } } }
	cout << s + 1 << endl;
	return 0; }

#include<cstdio>
#include<algorithm>
#include<iostream>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std;

const int N=100010;
ll t;
int n,m,s,nd,rt,tot,to[N][50];
struct Tr{ int ls,rs,v,sz,d; }v[N<<8];
struct P{ int x,y; };

int jump(ll x,ll y){
	if (x<=m) x+=y; else x-=y;
	return (x%n+n-1)%n+1;
}

void upd(int x){ v[x].sz=v[v[x].ls].sz+v[v[x].rs].sz+1; v[x].d=max(v[v[x].ls].d,v[v[x].rs].d)+1; }
int get(int k){ v[++nd]=(Tr){0,0,k,1,1}; return nd; }
void dfs(int x){ if (v[x].ls) dfs(v[x].ls); to[++tot][0]=v[x].v; if (v[x].rs) dfs(v[x].rs); }
void Print(int x){ if (v[x].ls) Print(v[x].ls); printf("%d ",v[x].v); if (v[x].rs) Print(v[x].rs); }

int merge(int x,int y){
	if (!x || !y){ v[++nd]=v[x|y]; return nd; }
	int p=++nd;
	if (1ll*rand()*(v[x].sz+v[y].sz)<1ll*v[x].sz*RAND_MAX)
		{ v[p]=v[x]; v[p].rs=merge(v[p].rs,y); upd(p); return p; }
	else{ v[p]=v[y]; v[p].ls=merge(x,v[p].ls); upd(p); return p; }
}

P split(int x,int k){
	if (!x) return (P){0,0};
	P t; int p=++nd; v[p]=v[x];
	if (k<=v[v[x].ls].sz){ t=split(v[p].ls,k); v[p].ls=t.y; upd(p); return (P){t.x,p}; }
		else{ t=split(v[p].rs,k-v[v[x].ls].sz-1); v[p].rs=t.x; upd(p); return (P){p,t.y}; }
}

void build(){ rt=nd=0; rep(i,1,n) rt=merge(rt,get(to[i][0])); }

int main(){
	scanf("%d%d%d",&n,&m,&s); cin>>t;
	for (; t%n; t--) s=jump(s,t); t/=n;
	rep(i,1,n) to[i][0]=i; build();
	rep(i,1,n-1){
		int lst=rt;
		if (m+i<=n){ P a=split(lst,m+i),b=split(a.x,i); rt=b.y; }
			else{ P a=split(lst,i),b=split(a.x,m+i-n); rt=merge(a.y,b.x); }
		if (m+1-i>0){ P a=split(lst,n-i),b=split(a.x,m-i); rt=merge(rt,b.y); }
			else{ P a=split(lst,m+n-i),b=split(a.x,n-i); rt=merge(rt,merge(a.y,b.x)); }
		if (v[rt].d>200) tot=0,dfs(rt),build();
	}
	tot=0; dfs(rt);
	rep(j,1,49) rep(i,1,n) to[i][j]=to[to[i][j-1]][j-1];
	for (int j=49; ~j; j--) if (t&(1ll<<j)) s=to[s][j];
	printf("%d\n",s);
	return 0;
}

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef complex<double> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;
const int TT = 60000001;
const ld PI = 4*atan((ld)1);

template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }

namespace io {
    // Source: StackOverflow

    template<class T> struct like_array : is_array<T>{};
    template<class T, size_t N> struct like_array<array<T,N>> : true_type{};
    template<class T> struct like_array<vector<T>> : true_type{};
    template<class T> bool is_like_array(const T& a) { return like_array<T>::value; }

    // I/O

    void setIn(string s) { freopen(s.c_str(),"r",stdin); }
    void setOut(string s) { freopen(s.c_str(),"w",stdout); }
    void setIO(string s = "") {
        ios_base::sync_with_stdio(0); cin.tie(0);
        if (sz(s)) { setIn(s+".in"), setOut(s+".out"); }
    }

    // INPUT

    // double input seems slow on CF
    void re(double& x) { string t; cin >> t; x = stod(t); }
    void re(ld& x) { string t; cin >> t; x = stold(t); }
    template<class T> void re(T& x) { cin >> x; }
    template<class Arg, class... Args> void re(Arg& first, Args&... rest) {
        re(first); re(rest...);
    }
    template<class T1, class T2> istream& operator>>(istream& is, pair<T1,T2>& p) {
        is >> p.f >> p.s; return is;
    }
    template<class T> istream& operator>>(istream& is, vector<T>& a) {
        F0R(i,sz(a)) is >> a[i];
        return is;
    }

    // OUTPUT

    template<class T> void pr(const T& x) { cout << x << '\n'; }
    template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
        cout << first << ' '; pr(rest...);
    }
    template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) {
        os << '{' << a.f << ", " << a.s << '}'; return os;
    }

    template<class T> ostream& printArray(ostream& os, const T& a, int SZ) {
        os << '{';
        F0R(i,SZ) {
            if (i) {
                os << ", ";
                if (is_like_array(a[i])) cout << "\n";
            }
            os << a[i];
        }
        os << '}';
        return os;
    }

    template<class T, size_t SZ> ostream& operator<<(ostream& os, const array<T,SZ>& a) {
        return printArray(os,a,SZ);
    }
    template<class T> ostream& operator<<(ostream& os, const vector<T>& a) {
        return printArray(os,a,sz(a));
    }
}

using namespace io;

int z = 0;
int val[TT], c[TT][2], sz[TT], nex = 1;

namespace treap {
    int tnode(int _val) {
        val[nex] = _val;
        sz[nex] = 1;
        return nex ++;
    }

    int copy(int x) {
        z ++; if (!x) return x;
        val[nex] = val[x];
        F0R(i,2) c[nex][i] = c[x][i];
        sz[nex] = sz[x];
        return nex ++;
    }

    int getsz(int x) { return x?sz[x]:0; }

    int recalc(int x) {
        sz[x] = 1+getsz(c[x][0])+getsz(c[x][1]);
        return x;
    }

    void tra(int x, vi& v) {
        if (!x) return;
        tra(c[x][0],v); v.pb(val[x]); tra(c[x][1],v);
    }

    pi splitsz(int t, int sz) {
        if (!t) return {t,t};
        auto T = copy(t);
        // cout << "AH " << t << " " << sz[t] << "\n";
        if (getsz(c[T][0]) >= sz) {
            auto p = splitsz(c[T][0], sz); c[T][0] = p.s;
            return {p.f, recalc(T)};
        } else {
            auto p = splitsz(c[T][1], sz-getsz(c[T][0])-1); c[T][1] = p.f;
            return {recalc(T), p.s};
        }
    }

    bool shouldLeft(int a, int b) {
        return rand() % (a+b) < a;
    }

    int merge(int L, int R, bool b = 0) {
        if (!L) return copy(R);
        if (!R) return copy(L);

        int t;
        if (shouldLeft(getsz(L),getsz(R))) {
            t = copy(L);
            c[t][1] = merge(c[L][1],R);
        } else {
            t = copy(R);
            c[t][0] = merge(L,c[R][0]);
        }
        return recalc(t);
    }
}

using namespace treap;

int n,m, NEX[MX][41];
ll s, t;

void brute() {
    if (s <= m) s += t;
    else s -= t;
    s %= n;
    while (s <= 0) s += n;
    t --;
}

int cur = 0;

int get(int l, int r) {
    while (l > n) l -= n, r -= n;
    while (l <= 0) l += n, r += n;
    if (r > n) return merge(get(l,n),get(n+1,r));
    auto a = splitsz(cur,r);
    auto b = splitsz(a.f,l-1);
    auto des = copy(b.s);
    cur = merge(merge(b.f,b.s),a.s);
    return des;
}

int build(vi& v, int l, int r) {
    if (l > r) return 0;
    int m = (l+r)/2;
    int root = tnode(v[m]);
    c[root][0] = build(v,l,m-1);
    c[root][1] = build(v,m+1,r);
    return recalc(root);
}

void gen() {
    FOR(i,1,n+1) cur = merge(cur, tnode(i));
    //cout << cur << " " << sz[cur] << ' ' << c[cur][0] << ' ' << c[cur][1] << "\n";
    //cout << sz[c[cur][0]] << " " << sz[c[cur][1]] << "\n";
    //auto a = splitsz(cur,5); cout << sz[a.f] << " " << sz[a.s]; exit(0);
    FOR(i,1,n) {
        int Z = z;
        auto a = get(i+1,i+m);
        auto b = get(m+1-i,n-i);
        if (getsz(a) != m || getsz(b) != n-m) {
            cout << "OOPS " << a << " " << b << " " << i << " " << getsz(a) << " " << getsz(b) << "\n";
            exit(0);
        }
        cur = merge(a,b);
        if (z-Z >= 1000) {
            vi v; tra(cur,v);
            cur = build(v,0,sz(v)-1);
        }
    }
    // cout << z << "\n";
    vi v; tra(cur,v);
    F0R(i,sz(v)) NEX[i+1][0] = v[i];
}

int main() {
    // you should actually read the stuff at the bottom
    setIO(); re(n,m,s,t);
    gen();
    while (t % n != 0) brute();
    FOR(j,1,41) FOR(i,1,n+1) NEX[i][j] = NEX[NEX[i][j-1]][j-1];
    t /= n;
    F0Rd(i,41) if (t&(1LL<<i)) s = NEX[s][i];
    cout << s;
    // you should actually read the stuff at the bottom
}

/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
ll n,m,s,t;
ll pos[maxn],T[maxn];
ll cal(ll x)
{
    if(s<m) s+=t;
    else s-=t;
    t--;
    return (s%n+n)%n;
}
int main()
{

    cin>>n>>m>>s>>t;
    s--;
    while(t%n) s=cal(s);
    ll temp=t/n;
    ll tick=0;
    while(temp--){
        if(pos[s]){
            temp%=tick-T[s];
            s=pos[s];
        }else{
            T[s]=tick;
            ll tmp=s;
            t=n;
            for(int i=1;i<=n;i++) s=cal(s);
            pos[tmp]=s;
            tick++;
        }
    }
    cout<<s+1<<endl;
    return 0;
}

#include <iostream>
#include <cmath>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#include <map>
#define rep(x, a, b) for(int x = (a); x <= (b); ++x)
#define rop(x, a, b) for(int x = (a); x < (b); ++x)
#define per(x, a, b) for(int x = (a); x >= (b); --x)
using namespace std;
typedef long long LL;
typedef double DB;
const int mod = 998244353;
const int iv2 = (mod + 1) >> 1;
inline int MOD(int x) {
	return x >= mod ? x - mod : x;
}
int qpow(int a, int b) {
	int as = 1;
	for(; b; a = 1ll * a * a % mod, b >>= 1) if(b & 1) as = 1ll * as * a % mod;
	return as;
}
struct r_e_d {
	inline int gti() {
		int x = 0, w = 1; char ch = getchar();
		while((ch < '0' || ch > '9') && ch != '-') ch = getchar();
		if(ch == '-') w = -1, ch = getchar();
		while(ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
		return x * w;
	}
	inline LL gtl() {
		LL x = 0, w = 1; char ch = getchar();
		while((ch < '0' || ch > '9') && ch != '-') ch = getchar();
		if(ch == '-') w = -1, ch = getchar();
		while(ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
		return x * w;
	}
	inline string gts() {
		string S; char ch = getchar();
		while(ch == ' ' || ch == '\n' || ch == '\r') ch = getchar();
		while(ch != ' ' && ch != '\n' && ch != '\r') S.push_back(ch), ch = getchar();
		return S;
	}
}RD;
/*--------------------------------------------------------------------------------------------------------------*/
LL last_ans;
int rt, n, m, CT, lb[100005], lt;
struct treap {
	int zi[10000005], ch[10000005][2],  sz[10000005], tt;
	int COP(int nw) {
		++tt;
		zi[tt] = zi[nw];
		ch[tt][0] = ch[nw][0];
		ch[tt][1] = ch[nw][1];
		sz[tt] = sz[nw];
		return tt;
	}
	int NEW(int w) {
		++tt;
		zi[tt] = w; sz[tt] = 1;
		ch[tt][0] = ch[tt][1] = 0;
		return tt;
	}
	void upd(int nw) {
		if(nw == 0) return;
		sz[nw] = sz[ch[nw][0]] + sz[ch[nw][1]] + 1;
	}
	void spt(int nw, int &a, int &b, int lm) {
		if(nw == 0) {
			a = b = 0;
			return;
		}
		++CT;
		if(sz[ch[nw][0]] + 1 <= lm) {
			a = COP(nw); spt(ch[nw][1], ch[a][1], b, lm - sz[ch[nw][0]] - 1); upd(a);
		} else {
			b = COP(nw); spt(ch[nw][0], a, ch[b][0], lm); upd(b);
		}
	}
	void mrg(int &nw, int a, int b) {
		if(a * b == 0) {
			nw = COP(a + b);
			return;
		}
		++CT;
		if((rand() & 1) && (1.0 * rand() / RAND_MAX <= 1.0 * sz[a] / (sz[a] + sz[b]))) {
			nw = COP(a); mrg(ch[nw][1], ch[a][1], b);
		} else {
			nw = COP(b); mrg(ch[nw][0], a, ch[b][0]);
		}
		upd(nw);
	}
	void dfs(int nw) {
		if(nw == 0) return;
		dfs(ch[nw][0]);
		lb[++lt] = zi[nw];
		dfs(ch[nw][1]);
		return;
	}
	void build(int &nw, int l, int r) {
		if(l > r) return;
		int md = (l + r) >> 1;
		nw = NEW(lb[md]);
		build(ch[nw][0], l, md - 1);
		build(ch[nw][1], md + 1, r);
		upd(nw);
	}
	void work(int i) {
		int x = 0, y = 0, z = 0, w = 0;
		int l = (1 + i - 1) % n + 1;
		int r = (m + i - 1) % n + 1;
		CT = 0;
		if(r < l) {
			spt(rt, w, x, l - 1);
			spt(w, z, w, r);
			mrg(x, x, z);
		} else {
			spt(rt, w, x, l - 1);
			spt(x, x, w, r - l + 1);
		}
		l = (m + 1 - i - 1 + n) % n + 1;
		r = (n - i - 1 + n) % n + 1;
		if(r < l) {
			spt(rt, w, y, l - 1);
			spt(w, z, w, r);
			mrg(y, y, z);
		} else {
			spt(rt, w, y, l - 1);
			spt(y, y, w, r - l + 1);
		}
		mrg(rt, x, y);
	}
}TP;
int f[55][100005];
LL t;
int s, la, op, wz, w, l, r;
int main() {
//	freopen("testdata.in", "r", stdin);
//	freopen("testdata.as", "w", stdout);
	n = RD.gti();
	m = RD.gti();
	s = RD.gti();
	t = RD.gtl();
	rep(i, 1, n) lb[i] = i;
	TP.build(rt, 1, n);
	rep(i, 1, n) {
		if(i % 1000 == 0) {
			lt = 0; TP.dfs(rt);
			rt = TP.tt = 0;
			TP.build(rt, 1, n);
		}
		TP.work(i);
	}
	while(t % n) {
		if(s <= m) {
			s = (s + (t % n) - 1 + n) % n + 1;
		} else {
			s = (s - (t % n) - 1 + n) % n + 1;
		}
		--t;
	}

	lt = 0; TP.dfs(rt);
	rep(i, 1, n) f[0][i] = lb[i];
	rep(i, 1, 50) rep(nw, 1, n) f[i][nw] = f[i - 1][f[i - 1][nw]];
	LL K = t / n;
	int ct = 0;
//	cout << f[0][1] << endl;
	while(K) {
		if(K & 1) s = f[ct][s];
		++ct;
		K >>= 1;
	}
	cout << s << endl;
	return 0;
}

#define DEBUG 1

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

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------
#pragma GCC optimize("Ofast")

int e[100000];
int ds[100000];
int find(int n) {
    if (ds[n] != n) ds[n] = find(ds[n]);
    return ds[n];
}
int pos[100000],seen[100000],num[100000];
vi alive,a2;
int tt[100000];
vi tri[100000];
int e2[100000];
int main() {
    int n,m,s;
    LLI t;
    cin >> n >> m >> s >> t,s--;
    int sw = 0;
    if (m > n/2) sw = 1,m = n-m,s = n-1-s;

    int i,j,k;
    if (m >= 20) {
        alive.resize(n),a2.resize(n);
        for (i = 0; i < n; i++) ds[i] = pos[i] = i,alive[i] = i;
        int as = n;
        for (i = n-1; i >= 0; i--) {
            int as2 = 0;
            for (j = 0; j < as; j++) {
                int u = pos[alive[j]];
                if (u < m) {
                    u += i;
                    if (u >= n) u -= n;
                }
                else {
                    u -= i;
                    if (u < 0) u += n;
                }
                pos[alive[j]] = u;
                if (seen[u] == i+1) ds[find(alive[j])] = find(num[u]);
                else seen[u] = i+1,num[u] = alive[j],a2[as2++] = alive[j];
            }
            swap(alive,a2);
            as = as2;
        }
        for (i = 0; i < as; i++) e[find(alive[i])] = pos[alive[i]];
        for (i = 0; i < n; i++) e[i] = e[find(i)];
    }
    else {
        int sum = 0;
        for (i = 0; i < n; i++) {
            sum += i,sum %= n;
            tt[i] = sum;
            tri[sum].pb(i);
        }
        for (i = 0; i < n; i++) {
            int u = i;
            j = n-1;
            while (j > 0) {
                if (u < m) {
                    u += j;
                    if (u >= n) u -= n;
                    j--;
                }
                else {
                    int mm = 0;
                    for (k = 0; k < m; k++) {
                        int x = (k-u+tt[j]+n) % n;
                        int p = lower_bound(tri[x].begin(),tri[x].end(),j)-tri[x].begin()-1;
                        if (p >= 0) mm = max(mm,tri[x][p]);
                    }
                    u -= tt[j],u += tt[mm];
                    if (u < 0) u += n;
                    if (u >= n) u -= n;
                    j = mm;
                }
            }
            //if((i % 1000)==0)cout<<i<<endl;
            e[i] = u;
        }
    }
    //printArr(e,n);
/*
    debug "here";
    for (i = 0; i < n; i++) {
        int u = i;
        for (j = n-1; j >= 0; j--) {
            if (u < m) {
                u += j;
                if (u >= n) u -= n;
            }
            else {
                u -= j;
                if (u < 0) u += n;
            }
        }
        assert(e[i]==u);
        e[i] = u;
    }
    //printArr(e,n);
    set<int>S;
    for (i=0;i<n;i++)S.insert(e[i]);
    cout<<S.size()<<endl;*/

    int u = s;
    while ((t >= 0) && ((t % n) != (n-1))) {
        if (u < m) {
            u += t % n;
            if (u >= n) u -= n;
        }
        else {
            u -= t % n;
            if (u < 0) u += n;
        }
        t--;
    }
    LLI c = (t+1)/n;
    for (i = 0; i < 50; i++) {
        if (c & (1LL << i)) u = e[u];
        for (j = 0; j < n; j++) e2[j] = e[e[j]];
        for (j = 0; j < n; j++) e[j] = e2[j];
    }
    if (sw) u = n-1-u;
    cout << u+1 << endl;

    return 0;
}

#include<cstdio>
#include<algorithm>
#include<iostream>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std;

const int N=100010;
ll t;
int n,m,s,nd,rt,tot,to[N][50];
struct Tr{ int ls,rs,v,sz,d; }v[N<<8];
struct P{ int x,y; };

int jump(ll x,ll y){
	if (x<=m) x+=y; else x-=y;
	return (x%n+n-1)%n+1;
}

void upd(int x){ v[x].sz=v[v[x].ls].sz+v[v[x].rs].sz+1; v[x].d=max(v[v[x].ls].d,v[v[x].rs].d)+1; }
int get(int k){ v[++nd]=(Tr){0,0,k,1,1}; return nd; }
void dfs(int x){ if (v[x].ls) dfs(v[x].ls); to[++tot][0]=v[x].v; if (v[x].rs) dfs(v[x].rs); }
void Print(int x){ if (v[x].ls) Print(v[x].ls); printf("%d ",v[x].v); if (v[x].rs) Print(v[x].rs); }

int merge(int x,int y){
	if (!x || !y){ v[++nd]=v[x|y]; return nd; }
	int p=++nd;
	if (1ll*rand()*(v[x].sz+v[y].sz)<1ll*v[x].sz*RAND_MAX)
		{ v[p]=v[x]; v[p].rs=merge(v[p].rs,y); upd(p); return p; }
	else{ v[p]=v[y]; v[p].ls=merge(x,v[p].ls); upd(p); return p; }
}

P split(int x,int k){
	if (!x) return (P){0,0};
	P t; int p=++nd; v[p]=v[x];
	if (k<=v[v[x].ls].sz){ t=split(v[p].ls,k); v[p].ls=t.y; upd(p); return (P){t.x,p}; }
		else{ t=split(v[p].rs,k-v[v[x].ls].sz-1); v[p].rs=t.x; upd(p); return (P){p,t.y}; }
}

int build(int L,int R){
	if (L>R) return 0;
	int mid=(L+R)>>1,x=get(to[mid][0]);
	v[x].ls=build(L,mid-1); v[x].rs=build(mid+1,R);
	upd(x); return x;
}

int main(){
	scanf("%d%d%d",&n,&m,&s); cin>>t;
	for (; t%n; t--) s=jump(s,t); t/=n;
	rep(i,1,n) to[i][0]=i; rt=build(1,n);
	rep(i,1,n-1){
		int lst=rt;
		if (m+i<=n){ P a=split(lst,m+i),b=split(a.x,i); rt=b.y; }
			else{ P a=split(lst,i),b=split(a.x,m+i-n); rt=merge(a.y,b.x); }
		if (m+1-i>0){ P a=split(lst,n-i),b=split(a.x,m-i); rt=merge(rt,b.y); }
			else{ P a=split(lst,m+n-i),b=split(a.x,n-i); rt=merge(rt,merge(a.y,b.x)); }
		if (v[rt].d>50) tot=0,dfs(rt),nd=0,rt=build(1,n);
	}
	tot=0; dfs(rt);
	rep(j,1,49) rep(i,1,n) to[i][j]=to[to[i][j-1]][j-1];
	for (int j=49; ~j; j--) if (t&(1ll<<j)) s=to[s][j];
	printf("%d\n",s);
	return 0;
}

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

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

	cin >> N >> M;
	long long int ans;
	cin >> ans >> K;
	vector<long long int>used(N, -1);
	ans--;
	while (K > 0 && K%N != N - 1) {
		if (ans < M)ans += K % N;
		else ans -= K % N;
		ans += N;
		ans %= N;
		K--;
	}
	if (!K) {
		cout << ans + 1 << endl;
		return 0;
	}
	while (K > 0) {
		if (ans < M)ans += K % N;
		else ans -= K % N;
		ans += N;
		ans %= N;
		if (K%N == 0) {
			//cout << K << " " << ans << endl;
			if (used[ans] == -1)used[ans] = K / N;
			else {
				long long int box = used[ans] - K / N;
				ans = 0;
				for (int i = 0; i < N; i++) {
					if (used[i] != -1 && used[i] % box == 0) {
						if (used[ans]==-1||used[ans] % box) {
							ans = i;
						}
						if (used[ans] > used[i])ans = i;
					}
				}
				cout << ans + 1 << endl;
				return 0;
			}
		}
		K--;
		//	cout << K << endl;
	}
	cout << ans + 1 << endl;
}

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

int main()
{
  int m, n, s;
  long long t;
  cin >> n >> m >> s >> t;
  s--;

  while (t % n)
  {
    if (s < m) s = (s + t % n) % n;
    else s = (s - t % n + n) % n;
    t--;
  }
  t /= n;

  map<int, long long> seen;
  seen[s] = t;
  vector<int> stations(1, s);
  long long initialT = t;
  while (t)
  {
    for (int i = n; i; i--)
      if (s < m) s = (s + i) % n;
      else s = (s + n - i) % n;
    t--;
    if (seen.count(s))
    {
      long long cycle = seen[s] - t;
      cout << stations[initialT - seen[s] + t % cycle] + 1 << endl;
      return 0;
    }
    seen[s] = t;
    stations.push_back(s);
  }

  cout << s + 1 << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define debug
#define maxn 100100
#define lg 500

int X[lg*maxn];
int sz[lg*maxn];
int L[lg*maxn];
int R[lg*maxn];

int qtd = 1;

inline void copy(int a,int b){
    X[b] = X[a];
    sz[b] = sz[a];
    L[b] = L[a];
    R[b] = R[a];
}

inline int top(int a,int b){
    return (rand()%(a+b)) < a;
}

void calc(int u){
    sz[u] = sz[L[u]] + sz[R[u]] + 1;
}

int merge(int l,int r){

    if(l == 0){
        return r;
    }
    if(r == 0){
        return l;
    }

    if(top(sz[l], sz[r])){

        int rc = merge(R[l],r);
        copy(l,qtd);
        R[qtd] = rc;
        calc(qtd);
        return qtd++;

    }
    else {

        int lc = merge(l,L[r]);
        copy(r,qtd);
        L[qtd] = lc;
        calc(qtd);
        return qtd++;

    }

}

void split(int u,int s,int &l,int &r){

    if(u == 0){
        l = r = 0;
        return;
    }

    if(sz[L[u]] >= s){

        split(L[u],s,l,r);
        copy(u,qtd);
        L[qtd] = r;
        r = qtd;
        calc(qtd);
        qtd++;

    }

    else {

        split(R[u],s-sz[L[u]]-1,l,r);
        copy(u,qtd);
        R[qtd] = l;
        l = qtd;
        calc(qtd);
        qtd++;

    }

}

int n,m,s;
ll t;

int get(int u,int l,int r){

    if(l < 0) l += n, r += n;

    int x,y,w,z;

    split(u,l,x,y);
    split(y,r-l+1,w,z);

    return w;

}

void print(int u){
    if(u == 0) return;
    print(L[u]);
    debug("%d ",X[u]);
    print(R[u]);
}

int XX[maxn];
int LL[maxn];
int RR[maxn];
int ssz[maxn];

int clean(int u){

    if(u == 0) return 0;

    int id = qtd++;
    XX[id] = X[u];
    ssz[id] = sz[u];
    LL[id] = clean(L[u]);
    RR[id] = clean(R[u]);
    return id;

}

int jmp[60][maxn];

int main(){

    scanf("%d%d%d%lld",&n,&m,&s,&t);
    s--;

    while(t%n){
        if(s < m) s = (s+t)%n;
        else s = (s-(t%n)+n)%n;
        t--;
    }

    int qm = 0;

    int r = 0;

    for(int i=0;i<n;i++){
        X[qtd] = i;
        sz[qtd] = 1;
        qtd++;
        r = merge(r,qtd-1);
    }

    //print(r);debug("\n");

    for(int i=1;i<=n-1;i++){
        int dupli = merge(r,r);
        int A = get(dupli,i,m+i-1);
        int B = get(dupli,m-i,n-1-i);

      //  print(A);printf("\n");
    //    print(B);printf("\n");

        r = merge(A,B);
      //  print(r);debug("\n");

        qm = max(qm,qtd);

        if(i%15000 == 0){
            qtd = 1;
            r = clean(r);
            for(int j=1;j<qtd;j++){
                R[j] = RR[j];
                L[j] = LL[j];
                X[j] = XX[j];
                sz[j] = ssz[j];
            }
        }

    }

    for(int i=0;i<n;i++){
        jmp[0][i] = X[get(r,i,i)];
    }

    for(int i=1;i<60;i++)
        for(int j=0;j<n;j++)
            jmp[i][j] = jmp[i-1][jmp[i-1][j]];

    qm = max(qm,qtd);
    debug("%d\n",qm);
    t/=n;

    for(int i=0;i<60;i++)
        if(t & (1ll<<i))
            s = jmp[i][s];

    printf("%d\n",s+1);
}

/*
0 1 2
1

*/

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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vb = vector<bool>;
using vs = vector<string>;

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

    int N, M;
    ll S, T;
    cin >> N >> M >> S >> T;
    S--;

    auto jump = [&]() {
        if (S < M) S += T;
        else S -= T;

        S %= N;
        if (S < 0) S += N;

        T--;
    };

    while (T % N != 0)
        jump();

    vll last(N, -1);
    while (T > 0) {
        if (last[S] != -1) {
            T %= (last[S] - T);
            if (!T) break;
        }
        last[S] = T;
        for (int i = 0; i < N; i++)
            jump();
    }

    cout << S + 1 << endl;
    return 0;
}

#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(a) int(a.size())
#define clr(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int inf=1e9;
const ll Inf=1e18;
const int N=1e5+10;
const int mod=0;
ll gi() {
    ll x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
template<typename T> bool chkmax(T &a,T b) { return a<b?a=b,1:0; };
template<typename T> bool chkmin(T &a,T b) { return a>b?a=b,1:0; };
int add(int a,int b) { return a+b>=mod?a+b-mod:a+b; }
int sub(int a,int b) { return a-b<0?a-b+mod:a-b; }
void inc(int &a,int b) { a=(a+b>=mod?a+b-mod:a+b); }
void dec(int &a,int b) { a=(a-b<0?a-b+mod:a-b); }
int n,m,s;ll t,vis[N];
int main() {
#ifndef ONLINE_JUDGE
    freopen("CF1056G.in","r",stdin);
    freopen("CF1056G.out","w",stdout);
#endif
    n=gi(),m=gi(),s=gi()-1,t=gi();
    while(t%n) {
        if(s<m) s=(s+t%n)%n;
        else s=(s-t%n+n)%n;
        --t;
    }
    memset(vis,-1,sizeof(vis));
    vis[s]=t,t/=n;
    while(t--) {
        for(int i=n-1;~i;i--) {
            if(s<m) s=(s+i%n)%n;
            else s=(s-i%n+n)%n;
        }
        if(~vis[s]) t%=vis[s]-t;
        vis[s]=t;
    }
    printf("%d\n",s+1);
    return 0;
}

#include <bits/stdc++.h>

#define itn int
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

#define random_shuffle(...) shuffle(__VA_ARGS__, rng)
#define rand() rng()

using namespace std;

inline int nxt() {
	int x;
	scanf("%d", &x);
	return x;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
	int n = nxt(), m = nxt();

	int s = nxt() - 1;
	long long t;
	cin >> t;
	while (t % n) {
		if (s < m) {
			s = (s + t % n) % n;
		} else {
			s = (s - t % n + n) % n;
		}
		--t;
	}

	function<int(int, int)> get = [&](int v, int k) {
		if (k == 0) {
			return v;
		}
		if (v < m) {
			v = (v + k) % n;
		} else {
			v = (v - k + n) % n;
		}
		return get(v, k - 1);
	};

	vector<int> big(n, -1);
	vector<int> step(n, -1);
	int cur = 0;
	while (t) {
		if (big[s] > -1) {
			break;
		}
		step[s] = cur++;
		s = big[s] = get(s, n);
		t -= n;
	}

	t /= n;
	t %= cur - step[s];
	while (t) {
		s = big[s];
		t -= 1;
	}

	cout << s + 1 << "\n";

	return 0;
}

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

typedef long long ll;
int n,m,s,ss;
ll t,tt;
__gnu_cxx::rope<int>to;

__gnu_cxx::rope<int>work(int b,int len){
	if((b%=n)+len<n)return to.substr(b,len);
	else return to.substr(b,n-b)+to.substr(0,len+b-n);
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m>>s>>t;
	for(int i=0;i<n;++i)to.push_back(i);
	for(int T=0;T<n;++T)to=work(T,m)+work(m+n-T,n-m);
	for(--s;t%n;--t)
		s=(s+(s<m?t:-t))%n,s+=s>>31&n;
	t/=n;
	for(ss=s,tt=t;t;){
		s=to[s];ss=to[ss];ss=to[ss];--t;--tt;--tt;
		if(s==ss)t%=t-tt,tt=t;
	}
	cout<<(s+1)<<'\n';
	return 0;
}

#include<cstdio>

const int MAXN=100011;

int N,M;
int S;
long long T;

long long Tim[MAXN];

int Nxt(int Pos){
long long ret=(long long)(Pos);
ret+=(Pos<M)?T:(-T);
--T;
return((int)(ret%(long long)(N))+N)%N;
}

int main(){

scanf("%d%d%d%I64d",&N,&M,&S,&T);--S;

while(true){
if(Tim[S])T%=(Tim[S]-T);
Tim[S]=T;
if(T<=N){
while(T)S=Nxt(S);
printf("%d\n",S+1);
return 0;
}
for(int i=0;i<N;++i)S=Nxt(S);
}

return 0;
}

/**
 * This is solution for problem two-color-metro
 * This is nk_ok.cpp
 *
 * @author: Nikolay Kalinin
 * @date: Fri, 23 Nov 2018 17:57:48 +0300
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;
template<typename T>
using pair2 = pair<T, T>;

#ifdef WIN32
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

mt19937 mt;

int cnt = 0;

struct tnode
{
    tnode *l, *r;
    int x;
    int size;

    tnode() {}
    tnode(const tnode &other): l(other.l), r(other.r), x(other.x), size(other.size)
    {
        cnt++;
    }
    tnode(int x): x(x)
    {
        l = NULL;
        r = NULL;
        size = 1;
    }
};

typedef tnode* pnode;

tnode mem[(int)1e7];
int curmem;

inline pnode newnode(tnode &other)
{
    mem[curmem] = tnode(other);
    pnode ret = mem + curmem;
    curmem++;
    return ret;
}

inline pnode newnode(int x)
{
    mem[curmem] = tnode(x);
    pnode ret = mem + curmem;
    curmem++;
    return ret;
}

inline int getsize(pnode cur)
{
    return (cur == NULL ? 0 : cur->size);
}

inline void update(pnode cur)
{
    cur->size = 1 + getsize(cur->l) + getsize(cur->r);
}

pnode merge(pnode l, pnode r)
{
    if (l == NULL) return (r == NULL ? NULL : newnode(*r));
    if (r == NULL) return newnode(*l);
    if (mt() % (l->size + r->size) < l->size)
    {
        l = newnode(*l);
        l->r = merge(l->r, r);
        update(l);
        return l;
    } else
    {
        r = newnode(*r);
        r->l = merge(l, r->l);
        update(r);
        return r;
    }
}

int depth;

void split(pnode cur, int x, pnode &l, pnode &r)
{
    if (cur == NULL)
    {
        l = NULL;
        r = NULL;
        return;
    }
    cur = newnode(*cur);
    int szl = getsize(cur->l);
//     cout << "in split " << szl << endl;
//     depth++;
    if (szl >= x)
    {
        split(cur->l, x, l, cur->l);
        r = cur;
        update(r);
    } else
    {
        split(cur->r, x - szl - 1, cur->r, r);
        l = cur;
        update(l);
    }
}

inline pnode getseg(pnode cur, int lpos, int rpos)
{
//     cout << "getseg " << getsize(cur) << ' ' << lpos << ' ' << rpos << endl;
    pnode l, m, r;
    if (rpos < getsize(cur)) split(cur, rpos, l, r);
    else l = cur;
    if (lpos == 0) return l;
    depth = 0;
    split(l, lpos, l, m);
//     cerr << depth << endl;
//     cout << "returns " << getsize(l) << ' ' << getsize(m) << ' ' << getsize(r) << endl;
//     cout << getsize(cur) << endl;
    return m;
}

vector<int> go;
vector<int> was;

pnode build(int l, int r)
{
    if (l > r) return NULL;
    int m = (l + r) / 2;
    pnode cur = newnode(go[m]);
    cur->l = build(l, m - 1);
    cur->r = build(m + 1, r);
    update(cur);
    return cur;
}

void toarray(pnode cur)
{
    if (cur == NULL) return;
    toarray(cur->l);
    go.pb(cur->x);
    toarray(cur->r);
}

int main()
{
    curmem = 0;
//     cerr << sizeof(tnode) << endl;
    int n, m, start;
    ll T;
    cin >> n >> m;
    cin >> start >> T;
    start--;
    go.resize(n);
    iota(all(go), 0);
    pnode root = build(0, n - 1);
    for (int step = 1; step <= n; step++)
    {
        pnode l;
        if (m + step <= n)
        {
            l = getseg(root, step, m + step);
        } else
        {
            pnode ll = getseg(root, step, n);
            pnode lr = getseg(root, 0, (m + step) % n);
            l = merge(ll, lr);
        }
        pnode r;
        if (m - step >= 0)
        {
            r = getseg(root, m - step, n - step);
        } else
        {
            pnode rl = getseg(root, m - step + n, n);
            pnode rr = getseg(root, 0, n - step);
            r = merge(rl, rr);
        }
//         cerr << step << ' ' << getsize(l) << ' ' << getsize(r) << endl;
        root = merge(l, r);
        if (step % 500 == 0)
        {
            go.clear();
            toarray(root);
            curmem = 0;
            root = build(0, n - 1);
        }
//         go.clear();
//         toarray(root);
//         for (auto t : go) cout << t << ' ';
//         cout << endl;
    }
    go.clear();
    toarray(root);
    cerr << clock() << ' ' << cnt << endl;
//     for (auto t : go) cout << t << ' ';
//     cout << endl;
    while (T % n != 0)
    {
        if (start < m) start = (start + T) % n;
        else start = ((start - T) % n + n) % n;
        T--;
    }
    T /= n;
    was.resize(n, -1);
    int cur = start;
    int it = 0;
    while (was[cur] == -1)
    {
        was[cur] = it;
        cur = go[cur];
        it++;
    }
    int cycle = (it - was[cur]);
    int precycle = was[cur];
    if (T > precycle)
    {
        T -= (ll)((T - precycle) / cycle) * cycle;
    }
    while (T > 0)
    {
        start = go[start];
        T--;
    }
    cout << start + 1 << endl;
    return 0;
}

#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long ll;

#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define MP make_pair
#define N 100000

vector<int> bigStops(1);
int bigStopPosition[N];
bool moveClockWise[N];

int NextStop(int n, int i, ll t){
    t %= n;
    return moveClockWise[i] ? (i + t) % n : (i + n - t) % n;
}

int NextBigStop(int n, int i){
    for(ll t = n - 1; t > 0; --t){
        i = NextStop(n, i, t);
    }
    return i;
}

bool AddNewBigStop(int s){
    if(bigStopPosition[s]){
        return false;
    }
    bigStopPosition[s] = bigStops.size();
    bigStops.push_back(s);
    return true;
}

int main(){
    int n, m, s;
    ll t;

    cin >> n >> m >> s >> t;

    for(int i = 0; i < m; ++i){
        moveClockWise[i] = 1;
    }

    --s;

    for( ; t % n != 0; --t){
        s = NextStop(n, s, t);
    }

    AddNewBigStop(s);

    for(bool cycleFound = 0; t > 0 && cycleFound == 0; t -= n){
        s = NextBigStop(n, s);
        cycleFound = !AddNewBigStop(s);
    }

    t /= n;

    t %= (bigStops.size() - bigStopPosition[s]);

    int ans = bigStops[bigStopPosition[s] + t] + 1;

    cout << ans << '\n';

    return 0;
}

#include<cstdio>
#include<algorithm>
#include<iostream>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std;

const int N=100010;
ll t;
int n,m,s,nd,rt,tot,to[N][50];
struct Tr{ int ls,rs,v,sz; }v[N<<8];
struct P{ int x,y; };

int jump(ll x,ll y){
	if (x<=m) x+=y; else x-=y;
	return (x%n+n-1)%n+1;
}

void upd(int x){ v[x].sz=v[v[x].ls].sz+v[v[x].rs].sz+1; }
int get(int k){ v[++nd]=(Tr){0,0,k,1}; return nd; }
void dfs(int x){ if (v[x].ls) dfs(v[x].ls); to[++tot][0]=v[x].v; if (v[x].rs) dfs(v[x].rs); }
void Print(int x){ if (v[x].ls) Print(v[x].ls); printf("%d ",v[x].v); if (v[x].rs) Print(v[x].rs); }

int merge(int x,int y){
	if (!x || !y){ v[++nd]=v[x|y]; return nd; }
	int p=++nd;
	if (1ll*rand()*(v[x].sz+v[y].sz)<1ll*v[x].sz*RAND_MAX)
		{ v[p]=v[x]; v[p].rs=merge(v[p].rs,y); upd(p); return p; }
	else{ v[p]=v[y]; v[p].ls=merge(x,v[p].ls); upd(p); return p; }
}

P split(int x,int k){
	if (!x) return (P){0,0};
	P t; int p=++nd; v[p]=v[x];
	if (k<=v[v[x].ls].sz){ t=split(v[p].ls,k); v[p].ls=t.y; upd(p); return (P){t.x,p}; }
		else{ t=split(v[p].rs,k-v[v[x].ls].sz-1); v[p].rs=t.x; upd(p); return (P){p,t.y}; }
}

int build(int L,int R){
	if (L>R) return 0;
	int mid=(L+R)>>1,x=get(to[mid][0]);
	v[x].ls=build(L,mid-1); v[x].rs=build(mid+1,R);
	upd(x); return x;
}

int main(){
	scanf("%d%d%d",&n,&m,&s); cin>>t; int lim=20000;
	for (; t%n; t--) s=jump(s,t); t/=n;
	rep(i,1,n) to[i][0]=i; rt=build(1,n);
	rep(i,1,n-1){
		int lst=rt;
		if (m+i<=n){ P a=split(lst,m+i),b=split(a.x,i); rt=b.y; }
			else{ P a=split(lst,i),b=split(a.x,m+i-n); rt=merge(a.y,b.x); }
		if (m+1-i>0){ P a=split(lst,n-i),b=split(a.x,m-i); rt=merge(rt,b.y); }
			else{ P a=split(lst,m+n-i),b=split(a.x,n-i); rt=merge(rt,merge(a.y,b.x)); }
		if (!(i%lim)) tot=0,dfs(rt),nd=0,rt=build(1,n);
	}
	tot=0; dfs(rt);
	rep(j,1,49) rep(i,1,n) to[i][j]=to[to[i][j-1]][j-1];
	for (int j=49; ~j; j--) if (t&(1ll<<j)) s=to[s][j];
	printf("%d\n",s);
	return 0;
}

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

using namespace std;
typedef long long ll;
const int MAXN = 100100;

int N, M;
int S;
ll T;
ll nlast[MAXN];

int move (int cloc, int ct)
{
    if (cloc < M) cloc += ct;
    else cloc += (N - ct);
    cloc %= N;
    return cloc;
}

int figure (int cloc)
{
    for (int i = N; i >= 1; i--)
        cloc = move (cloc, i);
    return cloc;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    for (int i = 0; i < MAXN; i++)
        nlast[i] = -1;

    cin >> N >> M >> S >> T;
    S--;
    while (T % N != 0)
    {
        S = move (S, T % N);
        T--;
    }
    nlast[S] = T;
    while (T > 0)
    {
        S = figure (S);
        T -= N;
        if (nlast[S] == -1)
        {
            nlast[S] = T;
        }
        else
        {
            ll ndiff = nlast[S] - T;
            T = T % ndiff;
        }
    }
    cout << S + 1 << "\n";
}

/*
   We notice that there are only N^2 important states - (postition, t mod N). Let's make T mod N steps and see where we will be after that. This can be done in the most stupid way in O(N) time.
   Also let's for each position store the position we will arrive at after N steps. If this value for position x is to[x] the answer of our problem will be to[to[...[x]...]] (applied T / N times).
   Then after calculating the to[] array, we can simply find the cycle length of to[] and the reminder of (T / N) when divided by it. Then (T / N) <= N and we can easily find the answer in O(N).

   Now the hard part is to find the to[] array. We will go backwards. Initially set to[x] = x. Now we will use persistent treap (actually RBST) to find the actual to values. The main observation
   is that when decreasing T the to[] array will change just in two intervals. Then we can do the movements with a couple of merges and splits. The complexity will be O(N log N).

   As persistent treaps (RBST) tend to to increase their depth fast, we will rebuild our structure a couple of times.
*/

#include <bits/stdc++.h>
#define endl '\n'

//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#define SZ(x) ((int)x.size())
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back

using namespace std;
template<class T, class T1> int chkmax(T &x, const T1 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T1> int chkmin(T &x, const T1 &y) { return x > y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);
const int MAX_MEM = (1 << 23);
const int B = 500;

random_device rd;
mt19937 mt(rd());

struct node
{
	int sz, id;
	node *l, *r;

	node() { sz = id = 0; l = r = nullptr; }
	node(int i)
	{
		l = nullptr;
		r = nullptr;
		id = i;
		sz = 1;
	}
};

using pnode = node*;

int cnt_nodes = 0;
node ptr_list[MAX_MEM];

void init_memory()
{
	cnt_nodes = 0;
}

pnode new_node(int id)
{
	ptr_list[cnt_nodes].l = ptr_list[cnt_nodes].r = nullptr;
	ptr_list[cnt_nodes].sz = 1, ptr_list[cnt_nodes].id = id;
	return ptr_list + (cnt_nodes++);
}

inline int size(pnode t) { return t ? t->sz : 0; }

bool hey(int l, int r) { return (int)mt() % (l + r) < l; }

void pull(pnode &t)
{
	if(!t) return;
	t->sz = 1 + size(t->l) + size(t->r);
}

pnode copy(pnode &t)
{
	if(!t) return nullptr;

	pnode ret = new_node(0);
	ret->id = t->id;
	ret->l = t->l;
	ret->r = t->r;
	ret->sz = t->sz;

	return ret;
}

void split(pnode t, pnode &l, pnode &r, int k, int add = 0)
{
	if(!t) { l = r = nullptr; return; }

	int idx = size(t->l) + add;
	if(idx <= k)
	{
		l = copy(t);
		split(l->r, l->r, r, k, idx + 1);
		pull(l);
	}
	else
	{
		r = copy(t);
		split(r->l, l, r->l, k, add);
		pull(r);
	}
}

void merge(pnode &t, pnode l, pnode r)
{
	if(!l) { t = copy(r); return; }
	if(!r) { t = copy(l); return; }

	if(hey(size(l), size(r)))
		t = copy(l), merge(t->r, t->r, r);
	else
		t = copy(r), merge(t->l, l, t->l);

	pull(t);
}

vector<int> tmp_rec;

void get_li_tmp(pnode t)
{
	if(!t) return;
	get_li_tmp(t->l);
	tmp_rec.pb(t->id);
	get_li_tmp(t->r);
}

vector<int> get_li(pnode t)
{
	tmp_rec.clear();
	get_li_tmp(t);
	return tmp_rec;
}

pnode build(int l, int r, vector<int> &li)
{
	if(l > r) return nullptr;

	int mid = (l + r) >> 1;

	pnode ret = new_node(li[mid]);
	ret->l = build(l, mid - 1, li);
	ret->r = build(mid + 1, r, li);

	pull(ret);

	return ret;
}

int n, m, start_pos;
int64_t t;

void read()
{
	cin >> n >> m;
	cin >> start_pos >> t;
	start_pos--;
}

int to[MAXN];

void dfs(pnode t, int p = 0)
{
	if(!t) return;
	dfs(t->l, p);
	to[p] = t->id;
	dfs(t->r, p + size(t->l) + 1);
}

pnode root = nullptr;
vector<int> tmpp;

void rebuild()
{
	tmpp = get_li(root);
	cnt_nodes = 0;
	root = build(0, n - 1, tmpp);
}

pnode get(int l, int r)
{
	if(l < 0)
	{
		pnode ret;
		merge(ret, get(n + l, n - 1), get(0, r));
		return ret;
	}

	if(r >= n)
	{
		pnode ret;
		merge(ret, get(l, n - 1), get(0, r - n));
		return ret;
	}

	pnode dummy, dummy2, ret, mid;
	split(root, mid, dummy, r);
	split(mid, dummy2, ret, l - 1);
	return ret;
}

void solve()
{
	while(t % n)
	{
		if(start_pos < m) start_pos = (start_pos + (t % n)) % n;
		else start_pos = (start_pos + n - (t % n)) % n;
		t--;
	}

	t /= n;

	for(int i = 0; i < n; i++) tmpp.pb(i);
	root = build(0, n - 1, tmpp);

	for(int i = 0; i < n; i++)
	{
		pnode L = get(i, m + i - 1);
		pnode R = get(m - i, n - 1 - i);

		merge(root, L, R);
		if(i && i % B == 0)
			rebuild();
	}

	vector<int> clist = get_li(root);
	for(int i = 0; i < n; i++) to[i] = clist[i];

	for(int cnt = 0; t > 0 && cnt < n; cnt++, t--)
		start_pos = to[start_pos];

	if(t != 0)
	{
		int cycle_len = 1, u = to[start_pos];
		while(u != start_pos)
		{
			cycle_len++;
			u = to[u];
		}

		t %= cycle_len;
		while(t--)
			start_pos = to[start_pos];
	}

	cout << start_pos + 1 << endl;
}

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

	init_memory();

	read();
	solve();
	return 0;
}

#include <bits/stdc++.h>

typedef long long LL;
int n, m, s; LL t;

std::map<std::pair<int, LL>, int> map;

int walk(int s) {
	int &r = map[{s, 1}] = s;
	for (int i = n - 1; i; --i)
		if (r < m) r = (r + i) % n;
		else r = (r + n - i) % n;
	return r;
}
int run(int s, LL times) {
	if (map.count({s, times})) return map[{s, times}];
	if (!times) return s; if (times == 1) return walk(s);
	return map[{s, times}] = run(run(s, times >> 1), times + 1 >> 1);
}
int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n >> m >> s >> t, --s;
	while (t % n) {
		if (s < m) s = (s + t--) % n;
		else s = (s + n - t-- % n) % n;
	}
	std::cout << run(s, t / n) + 1 << '\n';
	return 0;
}

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

#define ar array

const int mxN=1e5, mxATS=5e7;
int n, m, s, dp, nxt[mxN][40], ni;
long long t;

struct avltree {
	int a[mxATS], lc[mxATS], rc[mxATS], s[mxATS], h[mxATS], ts=1;
	int cpy(int u) {
		a[ts]=a[u];
		lc[ts]=lc[u];
		rc[ts]=rc[u];
		s[ts]=s[u];
		h[ts]=h[u];
		return ts++;
	}
	void rcl(int u) {
		s[u]=s[lc[u]]+1+s[rc[u]];
		h[u]=max(h[lc[u]], h[rc[u]])+1;
	}
	void dfs(int u) {
		if(!u)
			return;
		dfs(lc[u]);
		nxt[ni++][0]=a[u];
		dfs(rc[u]);
	}
	bool hl(int u) {
		return h[lc[u]]-h[rc[u]]>1;
	}
	bool hr(int u) {
		return h[rc[u]]-h[lc[u]]>1;
	}
	int rr(int u) {
		int v=lc[u];
		lc[u]=rc[v];
		rc[v]=u;
		rcl(u);
		rcl(v);
		return v;
	}
	int rl(int u) {
		int v=rc[u];
		rc[u]=lc[v];
		lc[v]=u;
		rcl(u);
		rcl(v);
		return v;
	}
	int rbl(int u) {
		if(hl(u)) {
			u=cpy(u);
			lc[u]=cpy(lc[u]);
			if(h[rc[lc[u]]]>h[lc[lc[u]]]) {
				rc[lc[u]]=cpy(rc[lc[u]]);
				lc[u]=rl(lc[u]);
			}
			u=rr(u);
		} else if(hr(u)) {
			u=cpy(u);
			rc[u]=cpy(rc[u]);
			if(h[lc[rc[u]]]>h[rc[rc[u]]]) {
				lc[rc[u]]=cpy(lc[rc[u]]);
				rc[u]=rr(rc[u]);
			}
			u=rl(u);
		}
		return u;
	}
	int rbl2(int u) {
		bool b1=hl(u), b2=hr(u);
		if(!b1&&!b2)
			return u;
		u=rbl(u);
		if(b1) {
			if(h[rc[u]]<h[lc[u]]) {
				lc[u]=cpy(lc[u]);
				u=rr(u);
				rc[rc[u]]=rbl2(rc[rc[u]]);
			} else
				rc[u]=rbl2(rc[u]);
		} else {
			if(h[lc[u]]<h[rc[u]]) {
				rc[u]=cpy(rc[u]);
				u=rl(u);
				lc[lc[u]]=rbl2(lc[lc[u]]);
			} else
				lc[u]=rbl2(lc[u]);
		}
		rcl(u);
		return u;
	}
	int mrg(int u, int v) {
		if(!u||!v)
			return u^v;
		int w;
		if(h[u]>h[v]) {
			w=cpy(u);
			rc[w]=mrg(rc[w], v);
		} else {
			w=cpy(v);
			lc[w]=mrg(u, lc[w]);
		}
		rcl(w);
		return rbl(w);
	}
	ar<int, 2> spl(int u, int k) {
		if(!u)
			return {0, 0};
		int iu=u;
		u=cpy(u);
		if(k<=s[lc[u]]) {
			ar<int, 2> a=spl(lc[u], k);
			lc[u]=a[1];
			u=rbl2(u);
			rcl(u);
			return {a[0], u};
		} else {
			ar<int, 2> a=spl(rc[u], k-s[lc[u]]-1);
			rc[u]=a[0];
			u=rbl2(u);
			rcl(u);
			return {u, a[1]};
		}
	}
} at;

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

	cin >> n >> m >> s >> t, --s;
	for(int i=0; i<n; ++i) {
		at.a[at.ts]=i;
		at.s[at.ts]=at.h[at.ts]=1;
		dp=at.mrg(dp, at.ts++);
	}
	for(int i=1; i<n; ++i) {
		ar<int, 2> a=at.spl(dp, i);
		int dp1, dp2;
		if(n-i<m) {
			ar<int, 2> b=at.spl(a[0], m-n+i);
			dp1=at.mrg(a[1], b[0]);
		} else
			dp1=at.spl(a[1], m)[0];
		a=at.spl(dp, n-i);
		if(i>m) {
			ar<int, 2> b=at.spl(a[1], m);
			dp2=at.mrg(b[1], a[0]);
		} else
			dp2=at.spl(a[0], m-i)[1];
		dp=at.mrg(dp1, dp2);
	}
	at.dfs(dp);
	while(t%n) {
		if(s<m)
			s=(s+t)%n;
		else
			s=(s-t%n+n)%n;
		--t;
	}
	t/=n;
	for(int i=1; i<40; ++i)
		for(int j=0; j<n; ++j)
			nxt[j][i]=nxt[nxt[j][i-1]][i-1];
	for(int i=39; i>=0; --i) {
		if(t>=1ll<<i) {
			t-=1ll<<i;
			s=nxt[s][i];
		}
	}
	cout << s+1;
}

#include<cstdio>
#include<algorithm>
#include<iostream>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std;

const int N=100010;
ll t;
int n,m,s,nd,rt,tot,to[N][50];
struct Tr{ int ls,rs,v,sz,d; }v[N<<8];
struct P{ int x,y; };

int jump(ll x,ll y){
	if (x<=m) x+=y; else x-=y;
	return (x%n+n-1)%n+1;
}

void upd(int x){ v[x].sz=v[v[x].ls].sz+v[v[x].rs].sz+1; v[x].d=max(v[v[x].ls].d,v[v[x].rs].d)+1; }
int get(int k){ v[++nd]=(Tr){0,0,k,1,1}; return nd; }
void dfs(int x){ if (v[x].ls) dfs(v[x].ls); to[++tot][0]=v[x].v; if (v[x].rs) dfs(v[x].rs); }
void Print(int x){ if (v[x].ls) Print(v[x].ls); printf("%d ",v[x].v); if (v[x].rs) Print(v[x].rs); }

int merge(int x,int y){
	if (!x || !y){ v[++nd]=v[x|y]; return nd; }
	int p=++nd;
	if (1ll*rand()*(v[x].sz+v[y].sz)<1ll*v[x].sz*RAND_MAX)
		{ v[p]=v[x]; v[p].rs=merge(v[p].rs,y); upd(p); return p; }
	else{ v[p]=v[y]; v[p].ls=merge(x,v[p].ls); upd(p); return p; }
}

P split(int x,int k){
	if (!x) return (P){0,0};
	P t; int p=++nd; v[p]=v[x];
	if (k<=v[v[x].ls].sz){ t=split(v[p].ls,k); v[p].ls=t.y; upd(p); return (P){t.x,p}; }
		else{ t=split(v[p].rs,k-v[v[x].ls].sz-1); v[p].rs=t.x; upd(p); return (P){p,t.y}; }
}

int build(int L,int R){
	if (L>R) return 0;
	int mid=(L+R)>>1,x=get(to[mid][0]);
	v[x].ls=build(L,mid-1); v[x].rs=build(mid+1,R);
	upd(x); return x;
}

int main(){
	scanf("%d%d%d",&n,&m,&s); cin>>t;
	for (; t%n; t--) s=jump(s,t); t/=n;
	rep(i,1,n) to[i][0]=i; rt=build(1,n);
	rep(i,1,n-1){
		int lst=rt;
		if (m+i<=n){ P a=split(lst,m+i),b=split(a.x,i); rt=b.y; }
			else{ P a=split(lst,i),b=split(a.x,m+i-n); rt=merge(a.y,b.x); }
		if (m+1-i>0){ P a=split(lst,n-i),b=split(a.x,m-i); rt=merge(rt,b.y); }
			else{ P a=split(lst,m+n-i),b=split(a.x,n-i); rt=merge(rt,merge(a.y,b.x)); }
		if (v[rt].d>100) tot=0,dfs(rt),nd=0,rt=build(1,n);
	}
	tot=0; dfs(rt);
	rep(j,1,49) rep(i,1,n) to[i][j]=to[to[i][j-1]][j-1];
	for (int j=49; ~j; j--) if (t&(1ll<<j)) s=to[s][j];
	printf("%d\n",s);
	return 0;
}

#include<bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;i++)
using namespace std;
typedef long long ll;
ll a,b,c,d,e,t,n,m,s,qw[100007]={0},zh[100007]={0};
int main(){
	scanf("%I64d%I64d%I64d%I64d",&n,&m,&s,&t);s--;
	while (t%n){
		if (s<m) s=(s+t%n)%n;else s=(s-t%n+n)%n;
		t--;
	}
	rep(i,0,n) qw[i]=-1;
	zh[0]=s;qw[s]=0;t/=n;
	rep(i,1,t){
		rep(j,1,n-1) if (s>=m) s=(s+j%n)%n; else s=(s-j%n+n)%n;
		if (qw[s]>=0){s=zh[(t-qw[s])%(i-qw[s])+qw[s]];break;}
		else qw[s]=i;
		zh[i]=s;
	}
	printf("%I64d\n",s+1);
	return 0;
}

#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

int main() {
  int n,m;
  scanf("%d%d",&n,&m);
  // vi a(n);
  // rep(i,n) {
  //   int x = i;
  //   drep(j,n) {
  //     if (x < m) x = (x+j)%n;
  //     else x = (x-j+n)%n;
  //   }
  //   a[i] = x;
  // }
  // cout<<a<<endl;
  int s; ll t;
  cin>>s>>t;
  --s;
  int tx = t%n;
  t /= n;
  while (tx) {
    if (s < m) s = (s+tx)%n;
    else s = (s-tx+n)%n;
    --tx;
  }
  map<int,int> mp;
  rep(i,t) {
    if (mp.count(s)) {
      int j = mp[s];
      int w = i-j;
      t %= w;
      for (auto p : mp) {
        if (p.se >= j && p.se%w == t) s = p.fi;
      }
      break;
    }
    mp[s] = i;
    drep(j,n) {
      if (s < m) s = (s+j)%n;
      else s = (s-j+n)%n;
    }
  }
  ++s;
  cout<<s<<endl;
  return 0;
}

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

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

const int MAXN = 1e5 + 5;
const int offset = 1 << 17;
const int LOG = 60;

ll T;
int N, M, S;
int jmp[MAXN][LOG];
int tour[2 * offset];
vector <int> queries[MAXN];
int l[3 * MAXN], r[3 * MAXN];
vector <pii> states;
int trans[3 * MAXN];
int dp[3 * MAXN];
int pref[MAXN];

void load() {
	scanf("%d%d%d%lld", &N, &M, &S, &T);
	S--;
}

inline int add(int x, int y) {
	x += y;
	if (x >= N)
		return x - N;
	if (x < 0)
		return x + N;
	return x;
}

inline int get_id(pii p) {
	if (p.second < N - 1)
		return 2 * p.second + p.first - M + 1;
	return 2 * (N - 1) + p.first;
}

inline int get_dp(int x, int y) {
	return dp[get_id({x, y})];
}

void update(int x, int val) {
	x += offset;
	tour[x] = val;
	for (x /= 2; x; x /= 2)
		tour[x] = max(tour[2 * x], tour[2 * x + 1]);
}

int query(int x, int lo, int hi, int from, int to) {
	if (lo >= to || hi <= from)
		return -1;
	if (lo >= from && hi <= to)
		return tour[x];
	int mid = (lo + hi) / 2;
	return max(query(2 * x, lo, mid, from, to), query(2 * x + 1, mid, hi, from, to));
}

int query(int from, int to) {
	return query(1, 0, offset, from, to);
}

int solve() {
	memset(tour, -1, sizeof tour);

	for (int i = 0; i < N - 1; i++) {
		states.push_back({M - 1, i});
		states.push_back({M, i});
	}
	for (int i = 0; i < N; i++)
		states.push_back({i, N - 1});

	for (int i = 1; i < N; i++)
		pref[i] = add(pref[i - 1], i);

	for (int i = 0; i < states.size(); i++) {
		pii it = states[i];
		assert(get_id(it) == i);
		if (it.first < M) {
			l[i] = add(add(it.first, pref[it.second]), 1);
			r[i] = add(l[i], -M);
		}
		else {
			l[i] = add(-it.first, pref[it.second]);
			r[i] = add(l[i], M);
		}
		queries[it.second].push_back(i);
	}

	for (int i = 0; i < N; i++) {
		for (auto it : queries[i])
			if (l[it] < r[it])
				trans[it] = query(l[it], r[it]);
			else
				trans[it] = max(query(l[it], N), query(0, r[it]));
		update(pref[i], i);
	}

	for (int i = 0; i < states.size(); i++) {
		pii it = states[i];
		if (trans[i] == -1) {
			dp[i] = add(it.first, it.first < M ? pref[it.second] : -pref[it.second]);
			continue;
		}
		if (it.first < M) {
			int pos = add(it.first, add(pref[it.second], -pref[trans[i] + 1]));
			int nxt = add(it.first, add(pref[it.second], -pref[trans[i]]));
			if (nxt - M <= M - 1 - pos)
				dp[i] = get_dp(M, trans[i] - 2 * (nxt - M));
			else
				dp[i] = get_dp(M, trans[i] - 2 * (M - 1 - pos) - 1);
		}
		else {
			int pos = add(it.first, -add(pref[it.second], -pref[trans[i] + 1]));
			int nxt = add(it.first, -add(pref[it.second], -pref[trans[i]]));
			if (M - 1 - nxt <= pos - M)
				dp[i] = get_dp(M - 1, trans[i] - 2 * (M - 1 - nxt));
			else
				dp[i] = get_dp(M - 1, trans[i] - 2 * (pos - M) - 1);
		}
	}

	for (int i = 0; i < N; i++)
		jmp[i][0] = get_dp(i, N - 1);

	for (int j = 1; j < LOG; j++)
		for (int i = 0; i < N; i++)
			jmp[i][j] = jmp[jmp[i][j - 1]][j - 1];

	for (int t = T % N; t; t--)
		S = add(S, S < M ? t : -t);

	ll rep = T / N;
	for (int i = 0; i < LOG; i++)
		if (rep >> i & 1ll)
			S = jmp[S][i];

	return ++S;
}

int main() {
	load();
	printf("%d\n", solve());
	return 0;
}

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <unordered_map>
#define maxn 100005
#define ll long long
#define pi pair<int, int>
using namespace std;
unordered_map<ll, ll> x;
int n, m;
ll t;
int main()
{
	scanf("%d%d", &n, &m);
	int s;
	scanf("%d%lld", &s, &t);
	ll cnt = 0;
	while(t)
	{
		int res = t % n;
		if(s > m) s -= res;
		else s += res;
		while(s > n) s -= n;
		while(s <= 0) s += n;
		t--;
		if(res <= 100)
		{
    		ll ns = s * (ll)n + res;
    		if(x[ns])
    			t %= (x[ns] - t);
    		else
    			x[ns] = t;
		}
	}
	printf("%d\n", s);
	return 0;
}
/*
100000 7
78411 208898171737
*/

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

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

	cin >> N >> M;
	long long int ans;
	cin >> ans >> K;
	vector<long long int>used(N, -1);
	ans--;
	while (K > 0 && K%N != N - 1) {
		if (ans < M)ans += K % N;
		else ans -= K % N;
		ans += N;
		ans %= N;
		K--;
	}
	if (!K) {
		cout << ans + 1 << endl;
		return 0;
	}
	while (K > 0) {
		if (ans < M)ans += K % N;
		else ans -= K % N;
		ans += N;
		ans %= N;
		if (K%N == 0) {
			//cout << K << " " << ans << endl;
			if (used[ans] == -1)used[ans] = K / N;
			else {
				long long int box = used[ans] - K / N;
				ans = 0;
				for (int i = 0; i < N; i++) {
					if (used[i] != -1 && used[i] % box == 0) {
						if (used[ans]==-1||used[ans] % box) {
							ans = i;
						}
						if (used[ans] > used[i])ans = i;
					}
				}
				cout << ans + 1 << endl;
				return 0;
			}
		}
		K--;
		//	cout << K << endl;
	}
	cout << ans + 1 << endl;
}

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

int n, m;

void go(int &u, int t) {
  for (int i = t; i > 0; --i) {
    if (u < m) {
      u += i;
    } else {
      u -= i;
    }
    u += (u < 0) ? n : 0;
    u -= (u >= n) ? n : 0;
  }
}

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

  int s;
  long long t;
  cin >> n >> m >> s >> t;

  go(--s, t % n);
  t /= n;

  vector<int> visited(n, -1);
  vector<int> cycle = {s};
  visited[s] = 0;

  for (int i = 1; i <= t; ++i) {
    go(s, n);

    if (visited[s] != -1) {
      t -= i;
      t %= i - visited[s];
      cout << cycle[visited[s] + t] + 1 << "\n";
      exit(0);
    }

    visited[s] = i;
    cycle.push_back(s);
  }

  cout << s + 1 << "\n";
}

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

long long a,b,i,s,t,x[123123];
long long d(long long p)
{
    if(p<b)p+=t;
    else p-=t;
    t--;
    return (p%a+a)%a;
}
int main()
{
    cin>>a>>b>>s>>t;s--;
    while(1)
    {
        if(x[s])t=t%(x[s]-t);
        x[s]=t;
        if(t<=a)
        {
            while(t)s=d(s);
            cout<<s+1;
            return 0;
        }
        for(i=0;i<a;i++)s=d(s);
    }
}

#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second

ll n, m, s, t, bylem[1000 * 1007];

void ruch() {
	if (s < m) {
		s=(s + t) % n;
	}
	else {
		s=(s - t) % n;
		if (s < 0) s += n;
	}
	t--;
}

int main(){
    ios_base::sync_with_stdio (false);
    cin.tie (nullptr); cout.tie (nullptr);
    cin>>n >> m >> s >> t;
    s--;
	while(1) {
		if (bylem[s]) t %= (bylem[s]-t);
		bylem[s]=t;
		if (t <= 1e6) {
			while(t) ruch();
			cout << s + 1;
			return 0;
		}
		for (int i = 0; i < n; i++) ruch();
	}
    return 0;
}

#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(a) int(a.size())
#define clr(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int inf=1e9;
const ll Inf=1e18;
const int N=1e5+10;
const int mod=0;
ll gi() {
    ll x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
template<typename T> bool chkmax(T &a,T b) { return a<b?a=b,1:0; };
template<typename T> bool chkmin(T &a,T b) { return a>b?a=b,1:0; };
int add(int a,int b) { return a+b>=mod?a+b-mod:a+b; }
int sub(int a,int b) { return a-b<0?a-b+mod:a-b; }
void inc(int &a,int b) { a=(a+b>=mod?a+b-mod:a+b); }
void dec(int &a,int b) { a=(a-b<0?a-b+mod:a-b); }
int n,m,s;ll t,vis[N];
int main() {
#ifndef ONLINE_JUDGE
    freopen("CF1056G.in","r",stdin);
    freopen("CF1056G.out","w",stdout);
#endif
    n=gi(),m=gi(),s=gi()-1,t=gi();
    while(t%n) {
        if(s<m) s=(s+t%n)%n;
        else s=(s-t%n+n)%n;
        --t;
    }
    memset(vis,-1,sizeof(vis));
    vis[s]=t,t/=n;
    while(t--) {
        for(int i=n-1;~i;i--) {
            if(s<m) s=(s+i%n)%n;
            else s=(s-i%n+n)%n;
        }
        if(~vis[s]) t%=vis[s]-t;
        vis[s]=t;
    }
    printf("%d\n",s+1);
    return 0;
}

#include <iostream>
#include <vector>
#include <map>
using namespace std;
typedef long long LL;
const int N=100000+10;
int n,m; LL s,t;
int mp[N],vis[N];

LL go(LL pos,LL len){
    if(pos<=m) {
        pos=(pos+len)%n;
    } else {
        pos=((pos-len)%n+n)%n;
    }
    if(pos==0)pos=n;
    return pos;
}
int getnext(int pos){
    if(mp[pos])return mp[pos];
    int now=pos;
    for(int i=n;i>=1;i--){
        now=go(now,i);
    }
    return mp[pos]=now;
}

vector<int> ans;
int main() {
    cin>>n>>m>>s>>t;
    while(t%n){
        s=go(s,t); t--;
    }
    LL step=t/n;
    ans.push_back(s); vis[s]=1;
    while(1) {
        s=getnext(s); if(vis[s]==1) break;
        vis[s]=1; ans.push_back(s);
    }
    printf("%d\n", ans[step%ans.size()]);
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m,s,t;
ll cal(ll x)
{
    if(s<m) s+=t;
    else s-=t;
    t--;
    return (s%n+n)%n;
}
int main()
{
    cin>>n>>m>>s>>t;
    s--;
    while(t%n) s=cal(s);
    cout<<s+1<<endl;
    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll naive(ll n, ll m, ll s, ll t)
{
	ll cur = s;
	while(t>0)
	{
		if(cur%n>=m)
		{
			cur-=t;
		}
		else
		{
			cur+=t;
		}
		cur%=n;
		if(cur<0) cur+=n;
		t--;
	}
	return cur;
}

const ll C = 250;
ll md[111111];
vector<ll> M[111111];

ll fast(ll n, ll m, ll s, ll t)
{
	if(t<=n) return naive(n,m,s,t);
	while(t%n!=0)
	{
		if(s%n>=m)
		{
			s-=t;
		}
		else
		{
			s+=t;
		}
		s%=n;
		if(s<0) s+=n;
		t--;
	}
	if(t==0) return s;
	//solve t/n copies of the problem, sort of
	if(m>n-m)
	{
		return n - 1 - fast(n, n-m, n-1-s, t); //check later
	}
	for(ll i=0;i<=n+5;i++)
	{
		ll s = (i*(i-1))/2;
		md[i] = s%n; M[i].clear();
	}
	for(ll i=1;i<=n+5;i++) M[md[i]].pb(i);
	//m <= n - m
	if(m<=C) //small
	{
		vector<vector<ll> > dp(m+2);
		for(int i=0;i<=m;i++)
		{
			dp[i].assign(n,0);
			dp[i][0]=i;
		}
		for(int j=1;j<n;j++)
		{
			for(int k=0;k<m;k++)
			{
				ll times = j; ll cur = k;
				while(times>0)
				{
					if(cur%n>=m)
					{
						cur-=times;
					}
					else
					{
						cur+=times;
					}
					cur%=n;
					if(cur<0) cur+=n;
					times--;
					if(cur<=m) break;
				}
				dp[k][j]=dp[cur][times];
			}
			ll ext = -1; ll besti = -1;
			for(int k=0;k<m;k++)
			{
				ll r = k - m + md[j+1];
				r%=n; if(r<0) r+=n;
				int lb = lower_bound(M[r].begin(),M[r].end(),j+1)-M[r].begin();
				lb--;
				if(lb>=0)
				{
					ll curi = M[r][lb];
					if(curi>besti)
					{
						besti=curi; ext=k;
					}
				}
			}
			if(besti==-1)
			{
				//clockwise j times
				ll r = m + md[j+1];
				r%=n; if(r<0) r+=n;
				dp[m][j] = r;
			}
			else
			{
				dp[m][j] = dp[ext][besti-1];
			}
		}
		vector<ll> F(n+2,0);
		for(int i=0;i<=m;i++) F[i]=dp[i][n-1];
		for(int i=m+1;i<n;i++)
		{
			ll ext = -1; ll besti = -1; ll j = n - 1;
			for(int k=0;k<m;k++)
			{
				ll r = k - i + md[j+1];
				r%=n; if(r<0) r+=n;
				int lb = lower_bound(M[r].begin(),M[r].end(),j+1)-M[r].begin();
				lb--;
				if(lb>=0)
				{
					ll curi = M[r][lb];
					if(curi>besti)
					{
						besti=curi; ext=k;
					}
				}
			}
			if(besti==-1)
			{
				//clockwise j times
				ll r = i + md[j+1];
				r%=n; if(r<0) r+=n;
				F[i] = r;
			}
			else
			{
				F[i] = dp[ext][besti-1];
			}
		}
		ll cyc = t/n;
		//solve cyc cycles tbh
		map<ll,ll> ma;
		ma[s] = cyc;
		vector<ll> V; V.pb(s);
		ll len = -1;
		while(cyc>0)
		{
			cyc--;
			ll news = F[s]; s = news; V.pb(s);
			if(ma.find(news)==ma.end())
			{
				ma[news]=cyc;
			}
			else
			{
				ll cur = ma[news];
				len = cur - cyc;
				break;
			}
		}
		if(cyc==0) return s;
		//I still need cyc times :(
		cyc%=len;
		int id=0;
		for(int i=0;i<V.size();i++)
		{
			if(V[i]==s){id=i; break;}
		}
		return V[id+cyc];
	}
	else //do big
	{
		ll cyc = t/n;
		//solve cyc cycles tbh
		map<ll,ll> ma;
		ma[s] = cyc;
		vector<ll> V; V.pb(s);
		ll len = -1;
		while(cyc>0)
		{
			cyc--;
			ll news = naive(n, m, s, n); s = news; V.pb(s);
			if(ma.find(news)==ma.end())
			{
				ma[news]=cyc;
			}
			else
			{
				ll cur = ma[news];
				len = cur - cyc;
				break;
			}
		}
		if(cyc==0) return s;
		//I still need cyc times :(
		cyc%=len;
		int id=0;
		for(int i=0;i<V.size();i++)
		{
			if(V[i]==s){id=i; break;}
		}
		return V[id+cyc];
	}
}

/*
void test(ll n)
{
	for(ll m=1;m<100;m++)
	{
		cout<<"TEST "<<m<<" : ";
		set<ll> S;
		for(ll s=0;s<n;s++)
		{
			S.insert(naive(n,m,s,n-1));
			//cout<<naive(n,m,s,n-1)<<' ';
		}
		cout<<S.size()<<'\n';
	}
}
*/
const bool DEBUG = 0;
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	//ll n; cin>>n; test(n);
	for(int cc=1;;cc++)
	{
		ll n,m,s,t;
		if(!DEBUG)
		{
			cin>>n>>m>>s>>t; s--;
		}
		else
		{
			n=rand()%2500+1;m=rand()%(n-1)+1;s=rand()%n;t=rand()+1;
		}
		ll f=fast(n,m,s,t);
		if(!DEBUG){cout<<f+1<<'\n'; return 0;}
		ll ss=naive(n,m,s,t);
		cerr<<"FAST : "<<f<<'\n';
		cerr<<"ANSWER : "<<ss<<'\n';
		if(f!=ss)
		{
			freopen("metro.out","w",stdout);
			cout<<n<<' '<<m<<' '<<s+1<<' '<<t<<'\n';
			return 0;
		}
		cerr<<"Case #"<<cc<<" complete\n";
	}
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

int n, m, s;
ll t;

map<pair<int, int>, int> mp; // ako ne radi ce ga optimizujemo

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

	cin >> n >> m >> s >> t;

	int r = t % n;
	mp[{s, r}] = 0;

	bool use_map = true;

	for (ll i=1; i<=t; i++) {
		if (s <= m) {
			s += r;
			if (s > n)
				s -= n;
		} else {
			s -= r;
			if (s < 1)
				s += n;
		}
		r--;
		if (r == -1)
			r = n-1;

		if (use_map) {
			if (mp.count({s, r})) {
				ll period = i - mp[{s, r}];
				ll jump = (t - i) / period * period;
				cerr << "period: " << period << '\n';
				i += jump;
				r -= jump;
				r = ((r % n) + n) % n;
				use_map = false;
			} else {
				mp[{s, r}] = i;
			}
		}
	}

	cout << s << '\n';
}

#pragma comment(linker, "/STACK:512000000")
#define _CRT_SECURE_NO_WARNINGS
//#include "testlib.h"
#include <bits/stdc++.h>
#ifdef AIM
#include <sys/resource.h>
#endif
using namespace std;

#define all(a) a.begin(), a.end()
using li = long long;
using ld = long double;
void solve(bool);
void precalc();
clock_t start;
int main() {
#ifdef AIM
  freopen("/home/alexandero/CLionProjects/ACM/input.txt", "r", stdin);
  //freopen("/home/alexandero/CLionProjects/ACM/output.txt", "w", stdout);
//freopen("out.txt", "w", stdout);
#else
  //freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif

#ifdef AIM
  const rlim_t kStackSize = 256 * 1024 * 1024;
  struct rlimit rl;
  int result;

  result = getrlimit(RLIMIT_STACK, &rl);
  if (result == 0) {
    if (rl.rlim_cur < kStackSize) {
      rl.rlim_cur = kStackSize;
      result = setrlimit(RLIMIT_STACK, &rl);
      if (result != 0) {
        fprintf(stderr, "setrlimit returned result = %d\n", result);
      }
    }
  }
#endif

  start = clock();
  int t = 1;
#ifndef AIM
  cout.sync_with_stdio(0);
  cin.tie(0);
#endif
  cout.precision(20);
  cout << fixed;
  //cin >> t;
  precalc();
  while (t--) {
    solve(true);
  }
  cout.flush();

#ifdef AIM1
  while (true) {
    solve(false);
  }
#endif

#ifdef AIM
  cerr << "\n\n time: " << (clock() - start) / 1.0 / CLOCKS_PER_SEC << "\n\n";
#endif
  return 0;
}

//BE CAREFUL: IS INT REALLY INT?

template<typename T>
T binpow(T q, T w, T mod) {
  if (!w)
    return 1 % mod;
  if (w & 1)
    return q * 1LL * binpow(q, w - 1, mod) % mod;
  return binpow(q * 1LL * q % mod, w / 2, mod);
}

template<typename T>
T gcd(T q, T w) {
  while (w) {
    q %= w;
    swap(q, w);
  }
  return q;
}
template<typename T>
T lcm(T q, T w) {
  return q / gcd(q, w) * w;
}

template <typename T>
void make_unique(vector<T>& vec) {
  sort(all(vec));
  vec.erase(unique(all(vec)), vec.end());
}

template<typename T>
void relax_min(T& cur, T val) {
  cur = min(cur, val);
}

template<typename T>
void relax_max(T& cur, T val) {
  cur = max(cur, val);
}

mt19937 rng((unsigned long long)chrono::steady_clock::now().time_since_epoch().count());

void precalc() {

}

//#define int li
//const li mod = 1000000007;
//const int mod = 998244353;
//using ull = unsigned long long;

void solve(__attribute__((unused)) bool read) {

  int n, m;
  cin >> n >> m;
  int s, t;
  cin >> s >> t;
  --s;
  auto make_move = [&] () {
    if (s < m) {
      s = (s + t % n) % n;
    } else {
      s = (s + n - t % n) % n;
    }
    --t;
  };
  vector<int> gone(n, -1);
  while (t % n) {
    make_move();
  }
  while (t > 0) {
    int cur = s;
    if (gone[cur] != -1) {
      t -= n;
      s = gone[cur];
      continue;
    }
    for (int i = 0; i < n; ++i) {
      make_move();
    }
    gone[cur] = s;
  }

  cout << s + 1 << endl;

  /*for (int n = 3; n <= 100; ++n) {
    int max_out = 0;
    int max_cycle = 0;
    for (int m = 1; m < n; ++m) {
      set<int> ends;
      vector<int> last(n);
      for (int s = 0; s < n; ++s) {
        int cur = s;
        for (int dist = n - 1; dist > 0; --dist) {
          if (cur < m) {
            cur = (cur + dist) % n;
          } else {
            cur = (cur + n - dist) % n;
          }
        }
        last[s] = cur;
        ends.insert(cur);
      }
      relax_max(max_out, (int)ends.size());
      vector<char> used(n, false);
      for (int c = 0; c < n; ++c) {
        int cur = c;
        int cnt = 0;
        used.assign(n, false);
        while (!used[cur]) {
          ++cnt;
          used[cur] = true;
          cur = last[cur];
        }
        relax_max(max_cycle, cnt);
      }
    }
    cout << n << " " << max_out << " " << max_cycle << endl;
  }*/

}

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <cstring>
using namespace std;

long long n, m, s;
long long t;
map<int,int> mp;

long long step(long long u) {
	if (u < m) {
		u = (u + t) % n;
	} else {
		u = (u - t) % n;
		if (u < 0) {
			u += n;
		}
	}
	return u;
}

long long bigstep(long long u) {
	for (int i = 0; i < n; i++) {
		u = step(u);
	}
	return u;
}

int main() {
	cin >> n >> m >> s >> t;
	s--;
	while (t % n) {
		s = step(s);
		t--;
	}

	t /= n;

	int idx = 0;
	mp[s] = 0;
	while (t > 0) {
		idx++;
		t--;
		int v = bigstep(s);
		if (!mp.count(v)) {
			mp[v] = idx;
			s = v;
		} else {
			int cycle = idx - mp[v];
			s = v;
			t %= cycle;
			break;
		}
	}
	while (t > 0) {
		s = bigstep(s);
		t--;
	}

	cout << s + 1 << endl;
 	return 0;
}

#include <bits/stdc++.h>
#define il inline
#define ri register int
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define mid ((l+r)>>1)
#define MAXN 100050
#define MAXM 40000050
#define MOD
#define INF (1<<25)
#define eps (1e-6)
#define rep(i, x, y) for(ri i = x; i <= y; ++i)
#define dwn(i, x, y) for(ri i = x; i >= y; --i)
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair <int, int> pii;
typedef pair <LL, int> pli;
typedef pair <int, LL> pil;
typedef pair <LL, LL> pll;
template <typename T> inline bool chkmin(T &x, T y) {return x > y ? x = y, 1 : 0;}
template <typename T> inline bool chkmax(T &x, T y) {return x < y ? x = y, 1 : 0;}
il void read(int &x) {
	char ch = getchar(); int f = 1; x = 0;
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = x*10+ch-'0', ch = getchar();
	x *= f;
}
int n, m, s, rt, size[MAXM], ch[MAXM][2], val[MAXM], tcnt, a[MAXN], cnt, nxt[MAXN][50];
LL t;
il void update(int u) {
	size[u] = size[ch[u][0]] + size[ch[u][1]] + 1;
}
il int rnd() {
	static int qwq = 19260817;
	return qwq = (qwq * 48271ll) & INT_MAX;
}
il int newnode(int w) {
	++tcnt;
	val[tcnt] = w, size[tcnt] = 1, ch[tcnt][0] = ch[tcnt][1] = 0;
	return tcnt;
}
il int newcp(int w) {
	++tcnt;
	val[tcnt] = val[w], size[tcnt] = size[w], ch[tcnt][0] = ch[w][0], ch[tcnt][1] = ch[w][1];
	return tcnt;
}
int merge(int x, int y) {
	if(!x || !y) return x+y;
	int t, f = (rnd() % (size[x] + size[y])) < size[x];
	if(f) t = newcp(x), ch[t][1] = merge(ch[t][1], y);
	else t = newcp(y), ch[t][0] = merge(x, ch[t][0]);
	update(t);
//	cout<<t<<' '<<ch[t][0]<<' '<<ch[t][1]<<' '<<size[t]<<endl;
	return t;
}
void split(int u, int k, int &x, int &y) {
	if(!u) x = y = 0;
	else {
		if(k <= size[ch[u][0]]) y = newcp(u), split(ch[y][0], k, x, ch[y][0]), update(y);
		else k -= size[ch[u][0]] + 1, x = newcp(u), split(ch[x][1], k, ch[x][1], y), update(x);
	}
}
void travel(int u) {
	if(!u) return;
	travel(ch[u][0]), a[++cnt] = val[u], travel(ch[u][1]);
}
void print(int u) {
//	cout<<rt<<endl;
	travel(u);
	rep(i, 1, cnt) cout<<a[i]<<' ';
	cout<<endl, cnt = 0;
}
int get(int l, int r) {
	int f = 0, a, b, c, d;
	if(l < 1) l += n, swap(l, r), f = 1;
	if(r > n) r -= n, swap(l, r), f = 1;
	if(!f) {
		split(rt, r, a, d);
		split(a, l-1, b, c);
		return c;
	}
	else {
		split(rt, r-1, a, d);
		split(a, l, b, c);
		return merge(d, b);
	}
}
void build() {
	tcnt = rt = 0;
	rep(i, 1, n) {
		int cur = newnode(a[i]);
		rt = merge(rt, cur);
	}
}
void rebuild() {
	cnt = 0;
	travel(rt);
	build();
}
int main() {
	read(n), read(m);
	rep(i, 1, n) a[i] = i;
	build();
	int tot = 0; double tm = clock();
	rep(i, 1, n) {
//		if(i % 5000 == 0) cout<<i<<' '<<clock()-tm<<endl, tm = clock();
		if(tcnt >= MAXM/3*2) {
			++tot, rebuild();
		}
		int lc = get(i+1, m+i), rc = get(m-i+1, n-i);
		rt = merge(lc, rc);
	}
//	cout<<tot<<endl;
	travel(rt);
	rep(i, 1, n) nxt[i][0] = a[i];//, cout<<a[i]<<' ';
//	cout<<endl;
	read(s), scanf("%lld", &t);
	rep(i, 1, 49)
		rep(j, 1, n)
			nxt[j][i] = nxt[nxt[j][i-1]][i-1];
	while(t % n) {
		if(s <= m) s += t%n;
		else s -= t%n;
		if(s > n) s -= n;
		if(s <= 0) s += n;
		--t;
	}
//	cout<<s<<endl;
	t /= n;
	rep(i, 0, 49) {
		if(t & (1ll << i)) s = nxt[s][i];
	}
	cout<<s<<endl;
	return 0;
}

#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
#define SIZE 100005
#define MX 5
#define BT 60

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int n,m,s;
ll T;
int to[MX][BT];
ll len[MX][BT];

bool red(int s){return s<=m;}//right
int main()
{
	//srand((unsigned) time(NULL));
	//n=rand()%100000+1;
	//m=rand()%n;
	//m=rand()%5+1;
	//s=rand()%n;
	//n=3,m=2,s=2;
	//T=1000000000000;
	//printf("%d %d %d %lld\n",n,m,s,T);
	scanf("%d %d",&n,&m);m--;
	scanf("%d %lld",&s,&T);s--;
	int cnt=0;
	int s0=s;
	while(T>0)
	{
		if(T%n==0)
		{
			if(s==0||s==n-1||s==m||s==m+1)
			{
				break;
			}
		}
		if(red(s)) s+=T%n;
		else s-=T%n;
		if(s>=n) s-=n;
		if(s<0) s+=n;
		T--;
		cnt++;
		if(cnt==8*n) T%=8*n;
	}
	if(T==0)
	{
		printf("%d\n",s+1);
		return 0;
	}
	vector <int> vx;
	vx.push_back(0);
	vx.push_back(m);
	vx.push_back(m+1);
	vx.push_back(n-1);
	sort(vx.begin(),vx.end());
	vx.erase(unique(vx.begin(),vx.end()),vx.end());
	for(int i=0;i<vx.size();i++)
	{
		int now=vx[i];
		int cnt=n;
		int zan=n;
		while(1)
		{
			if(zan==0)
			{
				if(now==0||now==n-1||now==m||now==m+1)
				{
					for(int j=0;j<vx.size();j++)
					{
						if(vx[j]==now)
						{
							to[i][0]=j;
							len[i][0]=cnt;
						}
					}
					break;
				}
				zan=n;
				cnt+=n;
				if(cnt==8*n)
				{
					to[i][0]=-1;
					len[i][0]=T+1;
					break;
				}
			}
			zan--;
			if(red(now)) now+=zan;
			else now-=zan;
			if(now>=n) now-=n;
			if(now<0) now+=n;
		}
	}
	for(int i=0;i+1<BT;i++)
	{
		for(int j=0;j<vx.size();j++)
		{
			to[j][i+1]=to[to[j][i]][i];
			len[j][i+1]=len[j][i]+len[to[j][i]][i];
			len[j][i+1]=min(len[j][i+1],T+1);
		}
	}
	for(int i=0;i<vx.size();i++)
	{
		if(vx[i]==s)
		{
			s=i;
			break;
		}
	}
	for(int i=BT-1;i>=0;i--)
	{
		if(len[s][i]<=T)
		{
			T-=len[s][i];
			s=to[s][i];
		}
	}
	s=vx[s];
	while(T>0)
	{
		if(red(s)) s+=T%n;
		else s-=T%n;
		if(s>=n) s-=n;
		if(s<0) s+=n;
		T--;
		cnt++;
		if(cnt==8*n) T%=8*n;
	}
	printf("%d\n",s+1);
	return 0;
}

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

ll readint(){
	ll x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

ll n,m,s,t;
ll g[100005];
map<ll,int> d[100005];

int ask(ll x){
	if(g[x]!=-1) return g[x];
	ll tmp=x;
	for(int i=n-1;i>=0;i--){
		if(x<=m) x=(x+i)%n;
		else x=(x-i+n)%n;
	}
	return g[tmp]=x;
}

int work(ll x,ll k){
	if(k==0) return x;
	if(k==1) return ask(x);
	if(d[x].count(k)) return d[x][k];
	return work(work(x,k/2),k-k/2);
}

int main(){
	n=readint(); m=readint(); s=readint(); t=readint();
	while(t%n!=0){
		if(s<=m) s=(s+t%n)%n;
		else s=(s-t%n+n)%n;
		t--;
	}
	memset(g,-1,sizeof(g));
	printf("%d\n",work(s,t/n));
	return 0;
}

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

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

	cin >> N >> M;
	long long int ans;
	cin >> ans >> K;
	vector<long long int>used(N, -1);
	ans--;
	while (K > 0 && K%N != N - 1) {
		if (ans < M)ans += K % N;
		else ans -= K % N;
		ans += N;
		ans %= N;
		K--;
	}
	if (!K) {
		cout << ans + 1 << endl;
		return 0;
	}
	while (K > 0) {
		if (ans < M)ans += K % N;
		else ans -= K % N;
		ans += N;
		ans %= N;
		if (K%N == 0) {
			cout << K << " " << ans << endl;
			if (used[ans] == -1)used[ans] = K / N;
			else {
				long long int box = used[ans] - K / N;
				ans = 0;
				for (int i = 0; i < N; i++) {
					if (used[i] != -1 && used[i] % box == 0) {
						if (used[ans]==-1||used[ans] % box) {
							ans = i;
						}
						if (used[ans] > used[i])ans = i;
					}
				}
				cout << ans + 1 << endl;
				return 0;
			}
		}
		K--;
		//	cout << K << endl;
	}
	cout << ans + 1 << endl;
}

// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// }}}
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;

ll n, m, s;
ll t;

#include<cstring>

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  cin >> n >> m >> s >> t; s--;
  int las[100000];
  memset(las, -1, sizeof(las));

  auto next = [&]() {
    if(s < m) {
      s = (s + t) % n;
    } else {
      s = (n + s - t % n) % n;
    }
    t--;
  };

  while(t) {
    if(las[s] != -1) t %= t - las[s];
    if(t < n) break;
    las[s] = t;
    for(int i = 0; i < n; i++) next();
  }
  while(t) next();
  cout << s + 1 << endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+10;
ll A[N];
ll n,m,s,t;
void F(){
    if(s<m)s=(s+t)%n;
    else s=(s+n-t%n)%n;
    --t;
}
int main(){
    cin>>n>>m>>s>>t;
    --s;
    while(1){
        if(A[s])t=t%(A[s]-t);
        if(t<=1e6){
            while(t)F();
            cout<<s+1<<endl;
            return 0;
        }
        A[s]=t;
        F();
    }
}

#pragma GCC optimize("O3")
#ifdef ONLINE_JUDGE
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#include <deque>
#include <type_traits>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
template<typename Key=int,typename Mapped=__gnu_pbds::null_type,typename Cmp_Fn=std::less<Key>,typename Tag=__gnu_pbds::rb_tree_tag,template<typename Const_Node_Iterator,typename Node_Iterator,typename Cmp_Fn_,typename Allocator_>class Node_Update=__gnu_pbds::tree_order_statistics_node_update,typename Allocator=std::allocator<char>>class ordered_set_t:__gnu_pbds::tree<Key,Mapped,Cmp_Fn,Tag,Node_Update,Allocator>{};const int GRANDOM=std::chrono::high_resolution_clock::now().time_since_epoch().count();struct ghash{int operator()(int x){return std::hash<int>{}(x^GRANDOM);}};template<typename KeyType>class hash_table_t:__gnu_pbds::gp_hash_table<KeyType,int,ghash>{};namespace vh{template<class T>void _R(T&x){std::cin>>x;}inline void _R(int&x){scanf("%d",&x);}inline void _R(int64_t&x){scanf("%" SCNd64,&x);}inline void _R(double&x){scanf("%lf",&x);}inline void _R(char&x){scanf(" %c",&x);}inline void _R(char*x){scanf("%s",x);}inline void R(){}template<class T,class... U>inline void R(T&head,U&... tail){_R(head);R(tail...);}template<class T>void _W(const T&x){cout<<x;}inline void _W(const int&x){printf("%d",x);}inline void _W(const int64_t&x){printf("%" PRId64,x);}inline void _W(const double&x){printf("%.16f",x);}inline void _W(const char&x){putchar(x);}inline void _W(const char*x){printf("%s",x);}template<class T>inline void _W(const vector<T>&x){for(auto i=x.begin();i!=x.end();_W(*i++))if(i!=x.cbegin())putchar(' ');}inline void W(){}template<class T,class... U>inline void W(const T&head,const U&... tail){_W(head);if(sizeof...(tail))putchar(' '),W(tail...);}template<class T,class... U>inline void WL(const T&head,const U&... tail){_W(head);putchar(sizeof...(tail)? ' ':'\n');W(tail...);}};
#define prec setprecision
namespace vh{typedef long long ll;typedef unsigned long long llu;template<typename T>T gcd(T m,T n){while(n){T t=m%n;m=n;n=t;};return m;}template<typename T>T exgcd(T a,T b,T&sa,T&ta){T q,r,sb=0,tb=1,sc,tc;sa=1,ta=0;if(b)do q=a/b,r=a-q*b,a=b,b=r,sc=sa-q*sb,sa=sb,sb=sc,tc=ta-q*tb,ta=tb,tb=tc;while(b);return a;}template<typename T>T mul_inv(T a,T b){T t1=a,t2=b,t3;T v1=1,v2=0,v3;T x;while(t2!=1)x=t1/t2,t3=t1-x*t2,v3=v1-x*v2,t1=t2,t2=t3,v1=v2,v2=v3;return(v2+b)%b;}template<typename T>T powmod(T a,T b,T MOD){if(b<0)return 0;T rv=1;while(b)(b%2)&&(rv=(rv*a)%MOD),a=a*a%MOD,b/=2;return rv;}template<typename T>inline T isqrt(T k){T r=sqrt((double)k)+1;while(r*r>k)r--;return r;}template<typename T>inline T icbrt(T k){T r=cbrt((double)k)+1;while(r*r*r>k)r--;return r;}template<typename T>bool mul_overflow(T&r,T a,T b){return __builtin_mul_overflow(a,b,&r);}template<ll n>struct BitSize{enum{Size=BitSize<n/2>::Size+1};};template<>struct BitSize<0>{enum{Size=1};};template<>struct BitSize<1>{enum{Size=1};};
#define BITSIZE(n) (BitSize<n>::Size)
#define BITMAX(n) (BitSize<n>::Size - 1)
#define DEBUG !defined(ONLINE_JUDGE)
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define RALL(x) (x).rbegin(),(x).rend()
template<typename TH>void _dbg(const char*sdbg,TH h){cerr<<sdbg<<"="<<h<<"\n";}template<typename TH,typename... TA>void _dbg(const char*sdbg,TH h,TA... t){while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<",";_dbg(sdbg+1,t...);}
#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; for(auto itt: x) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
}namespace vh{template<typename T>int min_rotation(vector<T>s){int a=0,N=s.size();for(int b=0;b<N;b++)for(int i=0;i<N;i++){if(a+i==b||s[(a+i)%N]<s[(b+i)%N]){b+=max(0,i-1);break;}if(s[(a+i)%N]>s[(b+i)%N]){a=b;break;}}return a;}}namespace vh{};
namespace vh{
  const int maxn=1e5+7;
  int n,m;
  ll s,t;
  int vst[maxn];
  int main(){
    srand(GRANDOM);
    cin>>n>>m>>s>>t;s--;
    auto u=[&](){
      if(s<m)s+=t;else s-=t;
      s=((s%n)+n)%n;
      t--;
    };
    while(t){
      if(vst[s])t%=vst[s]-t;
      vst[s]=t;
      for(int i=0;i<n&&t;i++)u();
    }
    cout<<(s+1)<<endl;
    return 0;
  }
};
int main(int argc,char*argv[]){
  std::cin.sync_with_stdio(false);std::cin.tie(nullptr);
  return vh::main();
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define ld long double
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
int n,m,s,flag;
ll t,last;
set<int> S;
int go(int s,ll a,ll b){
	for(;a!=b;a--){
		s=s<m?(s+a)%n:(s+n-a%n)%n;
	}
	return s;
}
int main(){
	n=read(); m=read();
	s=read()-1; t=read();
	last=t/n*n;
	s=go(s,t,last); t=last;
	while(t){
		s=go(s,t,t-n); t-=n;
		if(flag==0&&S.count(s)){
			t=(t/n)%S.size()*n; flag=1;
		}else if(!flag)S.insert(s);
	}
	cout<<s+1<<endl;
}

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

const int mxN=1e5;
int n, m, s, dp, nxt[mxN][40], ni, b[mxN];
long long t;
mt19937 mg(chrono::steady_clock::now().time_since_epoch().count());

template<size_t S>
struct treap {
	int n=1, lc[S+1], rc[S+1], a[S+1], s[S+1];
	int cmb(int u) {
		s[u]=s[lc[u]]+1+s[rc[u]];
		return u;
	}
	int cpy(int u) {
		a[n]=a[u];
		lc[n]=lc[u];
		rc[n]=rc[u];
		return n++;
	}
	int mrg(int u, int v, bool b=0) {
		if(!u||!v)
			return u^v;
		if(mg()%(s[u]+s[v])<s[u]) {
			if(!b)
				u=cpy(u);
			rc[u]=mrg(rc[u], v);
			return cmb(u);
		} else {
			if(!b)
				v=cpy(v);
			lc[v]=mrg(u, lc[v]);
			return cmb(v);
		}
	}
	array<int, 2> spl(int u, int k) {
		if(!u)
			return {};
		u=cpy(u);
		if(k>s[lc[u]]) {
			array<int, 2> a=spl(rc[u], k-s[lc[u]]-1);
			rc[u]=a[0];
			return {cmb(u), a[1]};
		} else {
			array<int, 2> a=spl(lc[u], k);
			lc[u]=a[1];
			return {a[0], cmb(u)};
		}
	}
	void dfs(int u) {
		if(!u)
			return;
		dfs(lc[u]);
		nxt[ni++][0]=a[u];
		dfs(rc[u]);
	}
};
treap<60000000> tr;

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

	cin >> n >> m >> s >> t, --s;
	for(int i=0; i<n; ++i) {
		tr.a[tr.n]=i;
		tr.s[tr.n]=1;
		b[i]=tr.n++;
	}
	for(int i=1; i<n; i*=2)
		for(int j=0; j<n; j+=2*i)
			for(int k=j; k<j+i&&k+i<n; ++k)
				b[k]=tr.mrg(b[k], b[k+i]);
	dp=b[0];
	for(int i=1; i<n; ++i) {
		array<int, 2> a=tr.spl(dp, i);
		int dp1, dp2;
		if(n-i<m) {
			array<int, 2> b=tr.spl(a[0], m-n+i);
			dp1=tr.mrg(a[1], b[0]);
		} else
			dp1=tr.spl(a[1], m)[0];
		a=tr.spl(dp, n-i);
		if(i>m) {
			array<int, 2> b=tr.spl(a[1], m);
			dp2=tr.mrg(b[1], a[0]);
		} else
			dp2=tr.spl(a[0], m-i)[1];
		dp=tr.mrg(dp1, dp2);
	}
	tr.dfs(dp);
	while(t%n) {
		if(s<m)
			s=(s+t)%n;
		else
			s=(s-t%n+n)%n;
		--t;
	}
	t/=n;
	for(int i=1; i<40; ++i)
		for(int j=0; j<n; ++j)
			nxt[j][i]=nxt[nxt[j][i-1]][i-1];
	for(int i=39; i>=0; --i) {
		if(t>=1ll<<i) {
			t-=1ll<<i;
			s=nxt[s][i];
		}
	}
	cout << s+1;
}

#include <cstdio>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstring>

using namespace std;

#define pb push_back
#define all(X) X.begin(), X.end()
#define ll long long

int nextt[100001];

void go(int& s, ll& t, int m, int n) {
  int is = s;
  ll it = t;
  while(t > 0) {
    if (s >= m) s = (s - (t % n) + n) % n;
    else s = (s + (t % n)) % n;
    t--;
    if ((t % n == 0) && (s == m - 1 || s == m)) break;
    if (s == is && (t % n) == (it % n)) break;
  }
}

int main()
{
#ifdef DEBUG
  freopen("g.in", "r", stdin);
  freopen("g.out", "w", stdout);
#endif
  int n, m;
  int s;
  ll t;
  scanf("%d %d", &n, &m);
  scanf("%d %lld", &s, &t);

  s--;
  int is = s;
  ll it = t;
  go(s, t, m, n);
  if (s == is) {
    t = t % (it - t);
    go(s, t, m, n);
  }
  if (t == 0) {
    printf("%d\n", s + 1);
    return 0;
  }
  memset(nextt, -1, sizeof(nextt));
  ll k1, k2;
  for (k1 = 1; k1 < n; k1++) {
    ll t = m - 1 + k1 * (k1 + 1) / 2;
    t %= n;
    if (t < m) {
      k1 = t;
      break;
    }
  }
  if (k1 == n) {
    k1 = (m + ((ll) n - 1) * n / 2) % n;
    nextt[k1] = m;
    nextt[m] = k1;
  }
  for (k2 = 1; k2 < n; k2++) {
    ll t = m + 1 + k2 * (k2 + 1) / 2;
    t %= n;
    if (t < m) {
      k2 = t;
      break;
    }
  }
  if (k2 == n) {
    k2 = (m + 1 + ((ll) n - 1) * n / 2) % n;
    nextt[k2] = m + 1;
    nextt[m + 1] = k2;
  }

  while(t > 0) {
    if (nextt[s] != -1) s = nextt[s];
    else if (s == m) s = ((k1 - m) % 2 == 0) ? m : m + 1;
    else if (s == m + 1) s = ((k2 - m) % 2 == 0) ? m : m + 1;
    else printf("Not working!\n");
    t -= n;
  }
  printf("%d\n", s + 1);

  return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
ll n,m,s,t;
ll pos[maxn],T[maxn];
ll cal(ll x)
{
    if(s<m) s+=t;
    else s-=t;
    t--;
    return (s%n+n)%n;
}
int main()
{

    cin>>n>>m>>s>>t;
    s--;
    while(t%n) s=cal(s);
    ll tmp=t/n;
    ll tick=0;
    while(tmp--){
        if(pos[s]){
            s=pos[s];
            tmp%=(tick-T[s]);

        }
        else{
            t=n;
            ll temp=s;
            for(int i=1;i<=n;i++) s=cal(s);
            pos[temp]=s;
            T[temp]=tick;
        }
        tick++;
    }
    cout<<s+1<<endl;
    return 0;
}

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

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

	cin >> N >> M;
	int ans;
	cin >> ans >> K;
	ans--;
	while (K > 0 && K%N != N - 1) {
		if (ans < M)ans += K % N;
		else ans -= K % N;
		ans += N;
		ans %= N;
		K--;
	}
	if (!K) {
		cout << ans + 1 << endl;
		return 0;
	}
	int odd = -1, even = -1;
	bool oddflag = false, evenflag = false;
	while (K > 0 && K%N != N - 1) {
		if (ans < M)ans += K % N;
		else ans -= K % N;
		ans += N;
		ans %= N;
		if (K%N == 0) {
			if ((K / N) & 1) {
				if (odd != ans)odd = ans;
				else oddflag = true;
			}
			else {
				if (even != ans)even = ans;
				else evenflag = true;
			}
			if (oddflag&&evenflag) {
				cout << even + 1 << endl;
				return 0;
			}
		}
		K--;
	}
	cout << ans + 1 << endl;
}

#include <cstdio>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <cstring>
#include <functional>

using namespace std;

#define pb push_back
#define all(X) X.begin(), X.end()
#define ll long long

int nextt[100001];
struct MyHash
{
    std::size_t operator()(pair<int, int> const& s) const noexcept
    {
        std::size_t h1 = std::hash<int>{}(s.first);
        std::size_t h2 = std::hash<int>{}(s.second);
        return h1 ^ (h2 << 1);
    }
};

unordered_map<pair<int, int>, ll, MyHash> M(100001);

int calc_ns(int s, ll t, int m, int n) {
  if (s < m) return (s + (t % n)) % n;
  return (s - (t % n) + n) % n;
}

int main()
{
#ifdef DEBUG
  freopen("g.in", "r", stdin);
  freopen("g.out", "w", stdout);
#endif
  int n, m;
  int s;
  ll t;
  scanf("%d %d", &n, &m);
  scanf("%d %lld", &s, &t);

  s--;
  for (int i = 0; i < n; i++) {
    if (i < m) {
      ll p = 1;
      for (; p * p <= i; p <<= 1);
      ll k = 0;
      for (; p; p >>= 1)
        if (i - (k + p) * (k + p + 1) / 2 >= 0) k += p;
      k++;
      nextt[i] = k;
    } else {
      ll p = 1;
      for (; p * p <= (n - i); p <<= 1);
      ll k = 0;
      for (; p; p >>= 1)
        if (i + (k + p) * (k + p + 1) / 2 < n) k += p;
      k++;
      nextt[i] = k;
    }
  }
  while (t > 0) {
    int ns, tr;
    auto it = M.find({s, t % n});
    if (it != M.end()) {
      ll ot = it->second;
      ll tr = ot - t;
      if (ot < t) tr = ot;
      else M[{s, t % n}] = tr;
      while (t > tr) t -= tr;
    }
    if (t % n == 0) {
      ll mv = nextt[s] * (nextt[s] + 1) / 2;
      ns = s < m ? (s - mv + n) % n : (s + mv) % n;
      tr = nextt[s] + 1;
    } else {
      ns = calc_ns(s, t, m, n);
      if (s < m && ns >= m && (t % n) <= m || s >= m && ns < m && (t % n) <= m) {
        int a = (t % n) / 2;
        int l = abs(m - 1 - s);
        int r = abs(m - 1 - ns);
        if (l > r) {
          s = ns;
          t--;
        }
        a = min(a, abs(m - 1 - s));
        ns = s < m ? s + a : s - a;
        tr = a * 2;
        if (ns == m - 1) {
          int l = ((t % n) -tr) % 4;
          ns = (l == 0 || l == 3) ? m - 1: m;
          tr = (t % n);
        }
      } else {
        if (M.size() < n * 100) {
          M[{s, t % n}] = t;
        }
        tr = 1;
      }
    }
    s = ns;
    t -= tr;
  }
  printf("%d\n", s + 1);
  return 0;
}

#include<bits/stdc++.h>
typedef long long ll;
using std::cin;
using std::cout;
const int maxn = 100100;
int n, m, s, t;
int f[2][maxn], * to = f[0], * lol = f[1];

int jump[40][maxn];
inline void cpy(int * a, int b, int len) {
	b %= n;
	if(b + len < n) {
		memcpy(a, to + b, len << 2);
	} else {
		memcpy(a, to + b, n - b << 2);
		memcpy(a + n - b, to, len - (n - b) << 2);
	}
}
int main() {
	std::ios::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n >> m >> s >> t, -- s;
	for(int i = 0;i < n;++i) to[i] = i;
	for(int T = n - 1;T >= n;--T) {
		cpy(lol, T, m);
		cpy(lol + m, T + m, n - m);

		std::swap(to, lol);
	}
	for(int i = 0;i < n;++i) jump[0][i] = to[i];
	for(int i = 1;i < 40;++i) {
		for(int j = 0;j < n;++j) {
			jump[i][j] = jump[i - 1][jump[i - 1][j]];
		}
	}
	for(;t % n != 0;--t) {
		if(s < m) {
			s = (s + t) % n;
		} else {
			s = ((s - t) % n + n) % n;
		}
	}
	for(int i = 39;i >= 0;--i) if(t / n >> i & 1) {
		s = jump[i][s];
	}
	cout << s + 1 << '\n';
}

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

typedef long long ll;
int n,m,s,ss;
ll t,tt;

void work(int&s,ll&t){
	s+=(s<m?1:-1)*t;s=(s%n+n)%n;
	--t;
}

int main(){
	cin>>n>>m>>s>>t;--s;
	for(ss=s,tt=t;;){
		work(s,t);work(ss,tt);work(ss,tt);
		if(!t){cout<<(s+1)<<'\n';return 0;}
		if(s==ss&&(t-tt)%n==0)t%=t-tt,tt=t;
	}
}

#include <bits/stdc++.h>
#define ll long long

#define TASKNAME ""

using namespace std;

const ll INF = 1e9 + 7;
const ll MAXN = 1e6 + 7;
const double EPS = 1e-8;

int main() {
    #ifdef MY
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #else
        //freopen(TASKNAME".in", "r", stdin);
        //freopen(TASKNAME".out", "w", stdout);
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    #endif // MY
    int n, m;
    cin >> n >> m;
    int s;
    ll t;
    cin >> s >> t;
    int od = t % n;
    s--;
    unordered_map <int, int> was;
    int now = 1;
    while (t > 0) {
        if (was[s * MAXN + od]) break;
        was[s * MAXN + od] = now++;
        if (s < m) {
            s += od;
            if (s >= n) {
                s -= n;
            }
        } else {
            s -= od;
            if (s < 0) {
                s += n;
            }
        }
        if (!od) {
            od = n - 1;
        } else {
            od--;
        }
        t--;
    }
    if (!t) {
        cout << s + 1 << "\n";
        return 0;
    }
    int cycle = now - was[s * MAXN + od];
    t %= cycle;
    od = t % n;
    while (t > 0) {
        if (s < m) {
            s += od;
            if (s >= n) {
                s -= n;
            }
        } else {
            s -= od;
            if (s < 0) {
                s += n;
            }
        }
        if (!od) {
            od = n - 1;
        } else {
            od--;
        }
        t--;
    }
    cout << s + 1;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

int n, m, s;
ll t;

vector<int> p;

void build() {
  p.resize(n);
  iota(p.begin(), p.end(), 0);
  for (int r = n - 1; r > 0; --r) {
    vector<int> np(n);
    for (int i = 0; i < n; ++i) {
      if (p[i] < m) {
        np[i] = (p[i] + r) % n;
      } else {
        np[i] = (p[i] + n - r) % n;
      }
    }
    p = np;
  }
  for (int i = 0; i < n; ++i) {
    cerr << p[i] << ' ';
  }
  cerr << '\n';
}

int step(int x, int r) {
  if (x < m) {
    x += r;
    if (x >= n) {
      x -= n;
    }
  } else {
    x -= r;
    if (x < 0) {
      x += n;
    }
  }
  return x;
}

const int maxn = 100100;
int pre[maxn];
int its = 0;

int go(int x, ll t, int c = 0) {
  if (t % n) {
    return go(step(x, t % n), t - 1);
  }
  if (t == 0) {
    return x;
  }
  if (pre[x] != -1) {
    if (c != -1) {
      return go(x, t % (c * n), -1);
    } else {
      return go(pre[x], t - n, -1);
    }
  }
  ++its;
  int y = x;
  for (int r = n - 1; r > 0; --r) {
    y = step(y, r);
  }
  pre[x] = y;
  return go(y, t - n, c + 1);
}

signed main() {
#ifdef LOCAL
  assert(freopen("g.in", "r", stdin));
#endif
  int s;
  ll t;
  cin >> n >> m >> s >> t;
  for (int i = 0; i < n; ++i) {
    pre[i] = -1;
  }
  cout << go(s - 1, t) + 1 << '\n';
  assert(its < 200);
  cerr << "iters: " << its << '\n';
}

#include <iostream>
#include <cstdio>

#include <utility>

#include <cassert>
#include <ctime>
#include <iomanip>

using namespace std;

const int MAXN = 1e5 + 100;

typedef long long ll;
#define tll(x) static_cast<ll>(x)

typedef pair<int, int> pii;
#define mp make_pair
#define ff first
#define ss second

int N, root;

const int MAXS = MAXN * 17 * 3 * 6;
struct PBT {
public:
  int c[MAXS][2], v[MAXS], sz[MAXS], h[MAXS];
  int NXT;
  PBT() : NXT(1) {v[0] = -1, sz[0] = 0, h[0] = 0;};
  int upd(int n) {
    if(not(0 < n)) return n;
    sz[n] = sz[c[n][0]] + sz[c[n][1]] + 1;
    h[n] = max(h[c[n][0]], h[c[n][1]]) + 1;
    assert(n != c[n][0] and n != c[n][1]);
    return n;
  }
  int gsz(int n) {
    if(n == 0) return 0;
    return gsz(c[n][0]) + gsz(c[n][1]) + 1;
  }
  void asst(int n) {assert(gsz(n) == sz[n]);}
  int nn(const int& n = -1) {
    assert(NXT < MAXS);
    if(n == 0) return 0;
    if(0 < n) {
      for(int i = 0;i < 2;i++) c[NXT][i] = c[n][i];
      v[NXT] = v[n];
    } else {
      for(int i = 0;i < 2;i++) c[NXT][i] = 0;
      v[NXT] = -1;
    }
    upd(NXT);
    return NXT++;
  }
  int nnr(const int& q) {
    int n = nn();
    v[n] = q;
    return n;
  }
  int L(int& n, int p = 0) {
    assert(c[n][1]);
    int o;
    if(p>1) o = nn(n); else o = n;
    if(p>0) n = nn(c[n][1]); else n = c[n][1];
    c[o][1] = c[n][0];
    upd(c[n][0] = o);
    return upd(n);
  }
  int R(int& n, int p = 0) {
    assert(c[n][0]);
    int o;
    if(p>1) o = nn(n); else o = n;
    if(p>0) n = nn(c[n][0]); else n = c[n][0];
    c[o][0] = c[n][1];
    upd(c[n][1] = o);
    return upd(n);
  }
  bool bal(int& n, bool p = false) {   //here, we assume that n is already a copy
    int q = NXT;
    int b = h[c[n][0]] - h[c[n][1]], s, o = n;
    if(b < -1) {
      assert(s = c[n][1]);
      if(h[c[s][1]] + 1 == h[s]) {
        L(n, p ? 1 : 0);
      } else if(h[c[s][0]] + 1 == h[s]) {
        R(c[n][1], p ? 2 : 0);
        L(n, 0);
      } else assert(false);
    }
    else if(b > 1) {
      assert(s = c[n][0]);
      if(h[c[s][0]] + 1 == h[s]) {
        R(n, p ? 1 : 0);
      } else if (h[c[s][1]] + 1 == h[s]) {
        L(c[n][0], p ? 2 : 0);
        R(n, 0);
      } else assert(false);
    }
    else return false;
    return true;
  }
  int join(int a, int b, bool p = true) {  //here we assume a and b are already copies
    if(a == 0 or b == 0) return a ? a : b;
    if(h[a] < h[b]) {
      c[b][0] = join(a, p ? nn(c[b][0]) : c[b][0], p);
      upd(b);
      bal(b, p);
      return b;
    } else {
      c[a][1] = join(p ? nn(c[a][1]) : c[a][1], b, p);
      upd(a);
      bal(a, p);
      return a;
    }
  }
  int join2(int l, int m, int r) {    //assume all are copies, merges L and R at M
    if(h[l] + 1 < h[r]) {c[r][0] = join2(l, m, nn(c[r][0])); return upd(r);}
    if(h[r] + 1 < h[l]) {c[l][1] = join2(nn(c[l][1]), m, r); return upd(l);}
    c[m][1] = r;
    c[m][0] = l;
    upd(m);
    bal(m, 1);
    return m;
  }
  pii split(int a, int k) {   //always create new nodes, assume a is NOT a copy
    if(k == 0) return mp(0, nn(a));
    assert(0 < k);
    if(sz[c[a][0]] < k) {
      pii q = split(c[a][1], k - sz[c[a][0]] - 1);
      int r = join2(nn(c[a][0]), nnr(v[a]), q.ff);
      return mp(r, q.ss);
    } else {
      pii q = split(c[a][0], k);
      int r = join2(q.ss, nnr(v[a]), nn(c[a][1]));
      return mp(q.ff, r);
    }
  }
  int get(int l, int r) {   //inclusive - exclusive
    while(not(l < N)) l -= N, r -= N;
    while(l < 0) l += N, r += N;

    if(r > N) return join(get(l, N), get(N, r));
    pii f1 = split(root, r);
    pii f2 = split(f1.ff, l);

    return f2.ss;
  }
  void fill(int n, int * a, int * t = new int(0)) {
    if(n == 0) return;
    fill(c[n][0], a, t);
    a[(*t)++] = v[n];
    fill(c[n][1], a, t);
  }
  void pout(int n = root) {
    if(n == 0) return;
    pout(c[n][0]);
    cerr << v[n] << " ";
    pout(c[n][1]);
    if(n == root) cerr << "\n\n";
  }
} pbt;

int M, S;
ll T;

int to[40][MAXN];

void gen() {
  root = 0;
  for(int i = 0;i < N;i++) root = pbt.join(root, pbt.nnr(i), 0);
  for(int i = 1;i < N;i++) {
    int a = pbt.get(i, i + M);
    int b = pbt.get(M - i, N - i);
    assert(pbt.sz[a] == M and pbt.sz[b] == N - M);
    root = pbt.join(a, b);
    //pbt.pout();
    assert(pbt.sz[root] == N);
  }
  pbt.fill(root, to[0]);
}

void run() {
  for(int i = 1;i < 40;i++) {
    for(int j = 0;j < N;j++) {
      to[i][j] = to[i-1][to[i-1][j]];
    }
  }
}

void brute() {
  int q = static_cast<int>(T%N);
  for(;q;q--,T--) {
    if(S < M) S = (S + q)%N;
    else S = (S - q + N)%N;
  }
  assert(T%N == 0);
}

void solve() {
  scanf("%d%lld", &S, &T);
  --S;
  brute();
  int k = T/N;
  for(int i = 0;1 << i < k;i++) {
    if(k&(1<<i)) S = to[i][S];
  }
  printf("%d\n", S + 1);
}

int main() {
  clock_t timer = clock();
  cerr << setprecision(6);

  scanf("%d%d", &N, &M);
  gen();
  run();
  //for(int i = 0;i < N;i++) printf("%d\n", to[0][i]);
  solve();

  cerr << "Time Elapsed: " << static_cast<double>(clock() - timer)/CLOCKS_PER_SEC << "\n";

  return 0;
}

#pragma comment(linker, "/STACK:1000000000")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>
#include <assert.h>
#include <vector>
#include <cstring>
#include <bitset>
#include <random>
//#include <priority_queue>

#define all(a) (a).begin(), (a).end()
#define pb push_back
#define mp make_pair
#define ld long double
#define pii pair <int, int>
#define ll long long
#define pll pair <ll, ll>

using namespace std;

struct vt {
	int x;
	int sz;
	int l, r;

	vt() {

	}

	vt(int x) : x(x), sz(1), l(-1), r(-1) {

	}
};

const int maxm = (int)6e7 + 10;

vt mas[maxm];
int posit = 0;

int my_new(int x) {
	if (posit == maxm) {
		cout << "FUCK" << endl;
	}
	mas[posit] = vt(x);
	return posit++;
}

int cpy(int t) {
	int nt = my_new(mas[t].x);
	mas[nt].sz = mas[t].sz;
	mas[nt].l = mas[t].l;
	mas[nt].r = mas[t].r;

	return nt;
}

int sz(int t) {
	return (t == -1 ? 0 : mas[t].sz);
}

void recalc(int t) {
	mas[t].sz = sz(mas[t].l) + sz(mas[t].r) + 1;
}

void split(int t, int k, int &l, int &r) {
	if (t == -1) {
		l = -1;
		r = -1;
	}
	else if (sz(mas[t].l) >= k) {
		t = cpy(t);
		split(mas[t].l, k, l, mas[t].l);
		r = t;
		recalc(r);
	}
	else {
		t = cpy(t);
		split(mas[t].r, k - sz(mas[t].l) - 1, mas[t].r, r);
		l = t;
		recalc(l);
	}
}

int merge(int l, int r) {
	if (l == -1) {
		return r;
	}

	if (r == -1) {
		return l;
	}

	if ((ll)rand() * (sz(l) + sz(r)) <= (ll)sz(l) * RAND_MAX) {
		l = cpy(l);
		mas[l].r = merge(mas[l].r, r);
		recalc(l);
		return l;
	}
	else {
		r = cpy(r);
		mas[r].l = merge(l, mas[r].l);
		recalc(r);
		return r;
	}
}

int go(int t, int ps) {
	if (t == -1) {
		cout << "ASS" << endl;
		throw 1;
	}

	if (sz(mas[t].l) > ps) {
		return go(mas[t].l, ps);
	}
	else if (sz(mas[t].l) == ps) {
		return mas[t].x;
	}
	else {
		return go(mas[t].r, ps - sz(mas[t].l) - 1);
	}
}

int n, m;

int get_seg(int t, int l, int r) {
	if (l < 0) {
		return merge(get_seg(t, l + n, n - 1), get_seg(t, 0, r));
	}
	else if (r >= n) {
		return merge(get_seg(t, l, n - 1), get_seg(t, 0, r - n));
	}
	else {
		int lm, m, rm;

		split(t, r + 1, lm, rm);
		split(lm, l, lm, m);
		return m;
	}
}

int rebuild(int t, int sd) {
	int nt = get_seg(t, sd, m - 1 + sd);
	nt = merge(nt, get_seg(t, m - sd, n - 1 - sd));

	return nt;
}

const int maxn = (int)1e5 + 10;

int lnk[maxn];

void build_lnk(int t, int sd) {
	if (t == -1) {
		return;
	}

	build_lnk(mas[t].l, sd);
	lnk[sd + sz(mas[t].l)] = mas[t].x;
	build_lnk(mas[t].r, sd + sz(mas[t].l) + 1);
}

int used[maxn];

int main() {
	cin >> n >> m;
	//n = (int)1e5;
	//m = n / 3;

	int s;
	ll t;

	cin >> s >> t;
	//s = 1;
	//t = (ll)1e12;
	s--;

	int cn = t % n;

	t /= n;

	int ans = -1;

	for (int i = 0; i < n; i++) {
		ans = merge(ans, my_new(i));
	}

	for (int i = 1; i < n; i++) {
		cout << i << endl;
		ans = rebuild(ans, i);
		if (sz(ans) != n) {
			cout << "BAD" << endl;
			throw 1;
		}
		if (i == cn) {
			s = go(ans, s);
		}
	}

	memset(lnk, -1, sizeof lnk);

	build_lnk(ans, 0);

	for (int i = 0; i < n; i++) {
		if (lnk[i] == -1) {
			cout << "BAD1" << endl;
			throw 1;
		}
	}

	int it = 1;

	while (used[s] == 0 && t != 0) {
		used[s] = it++;
		t--;
		s = lnk[s];
	}

	t %= (it - used[s]);

	while (t--) {
		s = lnk[s];
	}

	cout << s + 1 << endl;

	//system("pause");
}

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

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

	cin >> N >> M;
	long long int ans;
	cin >> ans >> K;
	vector<long long int>used(N, -1);
	ans--;
	while (K > 0 && K%N != N - 1) {
		if (ans < M)ans += K % N;
		else ans -= K % N;
		ans += N;
		ans %= N;
		K--;
	}
	if (!K) {
		cout << ans + 1 << endl;
		return 0;
	}
	while (K > 0) {
		if (ans < M)ans += K % N;
		else ans -= K % N;
		ans += N;
		ans %= N;
		if (K%N == 0) {
			cout << K << " " << ans << endl;
			if (used[ans] == -1)used[ans] = K / N;
			else {
				long long int box = used[ans] - K / N;
				for (int i = 0; i < N; i++) {
					if (used[i] != -1 && used[i] % box == 0) {
						cout << i + 1 << endl;
						return 0;
					}
				}
			}
		}
		K--;
		//	cout << K << endl;
	}
	cout << ans + 1 << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ull = uint64_t;
using ll = int64_t;
using ld = long double;

#ifdef BZ
mt19937_64 mt{ 228 };
#else
mt19937_64 mt{ ull(new char) };
#endif

struct Node {
    using Ptr = Node * ;

    Ptr l;
    Ptr r;
    ull y;
    int sz;
    int x;

    Node() = default;

    Node(int x)
        : l(nullptr)
        , r(nullptr)
        , y(mt())
        , sz(1)
        , x(x)
    {
    }
};

using Ptr = Node * ;

#ifndef BZ
const int NC = 29000000;
#else
const int NC = 200000;
#endif

const int N = 100228;
Node nodes[NC + N * 2];
int nodec = 0;

template <typename ... Args>
Ptr newnode(Args&& ... args) {
    nodes[nodec] = Node(std::forward<Args>(args)...);
    return nodes + nodec++;
}

int sz(Ptr p) {
    return p ? p->sz : 0;
}

void upd(Ptr p) {
    p->sz = 1 + sz(p->l) + sz(p->r);
}

Ptr merge(Ptr l, Ptr r) {
    if (!l) {
        return r;
    }

    if (!r) {
        return l;
    }

    Ptr ans;
    if (mt() % (l->sz + r->sz) < l->sz) {
        ans = newnode(*l);
        ans->r = merge(l->r, r);
    } else {
        ans = newnode(*r);
        ans->l = merge(l, r->l);
    }

    upd(ans);
    return ans;
}

pair<Ptr, Ptr> split(Ptr t, int s) {
    if (!t) {
        return { nullptr, nullptr};
    }

    Ptr ans = newnode(*t);

    int ls = sz(t->l);
    if (s > ls) {
        auto[lc, rc] = split(t->r, s - ls - 1);
        ans->r = lc;
        upd(ans);
        return { ans, rc };
    } else {
        auto[lc, rc] = split(t->l, s);
        ans->l = rc;
        upd(ans);
        return { lc, ans };
    }
}

int a[N];
int ac;
Ptr root;

const int LG = 50;

int nx[N][LG];

Ptr build(int l, int r) {
    if (l >= r) {
        return nullptr;
    }

    int m = (l + r) / 2;
    Ptr cur = newnode(a[m]);
    cur->l = build(l, m);
    cur->r = build(m + 1, r);
    upd(cur);
    return cur;
}

void trav(Ptr p) {
    if (!p) {
        return;
    }

    trav(p->l);
    a[ac++] = p->x;
    trav(p->r);
}

int n, m;

void bld() {
    nodec = 0;
    assert(ac == n);
    root = build(0, ac);
}

void rebuild() {
    assert(false);
    ac = 0;
    trav(root);
    bld();
}

Ptr sub(int l, int r) {
    int a = l, b = r;

    int t = 0;

    if (a < 0) {
        a += n;
        swap(a, b);
        t = 1;
    }

    if (b > n) {
        b -= n;
        swap(a, b);
        t = 1;
    }

    auto[rm, r2] = split(root, b);
    auto[r0, r1] = split(rm, a);
    if (t == 0) {
        return r1;
    } else {
        return merge(r2, r0);
    }
}

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(20);

    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        a[ac++] = i;
    }

    bld();

    for (int i = 1; i < n; ++i) {
        if (nodec > NC) {
            rebuild();
        }

        auto cl = sub(i, m + i);
        assert(sz(cl) == m);
        auto cr = sub(m - i, n - i);
        assert(sz(cr) == n - m);

        root = merge(cl, cr);
        assert(sz(root) == n);
    }

    ac = 0;
    trav(root);

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

    for (int i = 1; i < LG; ++i) {
        for (int j = 0; j < n; ++j) {
            nx[j][i] = nx[nx[j][i - 1]][i - 1];
        }
    }

    int s;
    ll t;
    cin >> s >> t;
    --s;
    ++t;

    while (t % n) {
        --t;

        if (s < m) {
            s += (t % n);
        } else {
            s -= (t % n);
        }

        if (s < 0) {
            s += n;
        }

        if (s >= n) {
            s -= n;
        }
    }

    for (int i = LG - 1; i >= 0; --i) {
        if ((t >> i) & 1) {
            s = nx[s][i];
        }
    }

    cout << s + 1 << "\n";
}

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

ll readint(){
	ll x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

ll n,m,s,t;

int ask(ll x){
	for(int i=n-1;i>=0;i--){
		if(x<=m) x=(x+i)%n;
		else x=(x-i+n)%n;
	}
	return x;
}

int work(ll x,ll k){
	if(k==0) return x;
	if(k==1) return ask(x);
	return work(work(x,k/2),k-k/2);
}

int main(){
	n=readint(); m=readint(); s=readint(); t=readint();
	while(t%n!=0){
		if(s<=m) s=(s+t%n)%n;
		else s=(s-t%n+n)%n;
		t--;
	}
	printf("%d\n",work(s,t/n));
	return 0;
}

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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vb = vector<bool>;
using vs = vector<string>;

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

    int N, M, S;
    ll T;
    cin >> N >> M >> S >> T;
    S--;

    auto jump = [&]() {
        if (S < M) S += T;
        else S -= T;

        S %= N;
        if (S < 0) S += N;

        T--;
    };

    while (T % N != 0)
        jump();

    vi big(N, -1);

    while (T > 0) {
        if (big[S] != -1) {
            S = big[S];
            T -= N;
        } else {
            ll W = S;
            for (int i = 0; i < N; i++)
                jump();
            big[W] = S;
        }
    }

    cout << S + 1 << endl;
    return 0;
}

#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long ll;

#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define MP make_pair
#define N 100000

vector<int> bigStops(1);
int bigStopPosition[N];
bool moveClockWise[N];

int NextStop(int n, int i, ll t){
    t %= n;
    return moveClockWise[i] ? (i + t) % n : (i + n - t) % n;
}

int NextBigStop(int n, int i){
    for(ll t = n - 1; t > 0; --t){
        i = NextStop(n, i, t);
    }
    return i;
}

bool AddNewBigStop(int s){
    if(bigStopPosition[s]){
        return false;
    }
    bigStopPosition[s] = bigStops.size();
    bigStops.push_back(s);
    return true;
}

int main(){
    int n, m, s;
    ll t;

    cin >> n >> m >> s >> t;

    for(int i = 0; i < m; ++i){
        moveClockWise[i] = 1;
    }

    --s;

    for( ; t % n != 0; --t){
        s = NextStop(n, s, t);
    }

    AddNewBigStop(s);

    if(t){
        for(s = NextBigStop(n, s); t > 0 && AddNewBigStop(s); t -= n, s = NextBigStop(n, s));
    }

    t /= n;

    int loopLength = (bigStops.size() - bigStopPosition[s] + 1);

    t %= loopLength;

    int ans = bigStops[bigStopPosition[s] + t] + 1;

    cout << ans << '\n';

    return 0;
}

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

using ll=long long;
//#define int ll

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=a;i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(a>b)a=b;}

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.a<<","<<p.b<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

template<class N>
struct pavl{
	struct N2{
		N n;
		int l,r,d;
	};
	vc<N2> x;
	int nn(N w,int l=-1,int r=-1,int d=0){
		int i=x.size();
		x.pb(N2{w,l,r,d});
		return i;
	}
	int md(int i,N w){
		if(i==-1)return -1;
		return nn(w,x[i].l,x[i].r,x[i].d);
	}
	int np(int l,int r){
		return nn(N::merge(x[l].n,x[r].n),l,r,max(x[l].d,x[r].d)+1);
	}
	N gn(int i){
		return i==-1?N():x[i].n;
	}
	pair<N,N> push(int i,N w){
		N a=gn(x[i].l),b=gn(x[i].r);
		w.push(a);
		w.push(b);
		return {a,b};
	}
	pi m1(int a,int b,int c){
		if(abs(max(x[a].d,x[b].d)+1-x[c].d)<=1)
			return pi(np(a,b),c);
		if(abs(max(x[b].d,x[c].d)+1-x[a].d)<=1)
			return pi(a,np(b,c));
		auto e=push(b,x[b].n);
		return pi(np(a,md(x[b].l,e.a)),np(md(x[b].r,e.b),c));
	}
	pi m2(int a,int b,N c,N d){
		if(x[a].d<x[b].d){
			auto e=push(b,d);
			pi z=m2(a,x[b].l,c,e.a);
			return m1(z.a,z.b,md(x[b].r,e.b));
		}else if(x[a].d>x[b].d){
			auto e=push(a,c);
			pi z=m2(x[a].r,b,e.b,d);
			return m1(md(x[a].l,e.a),z.a,z.b);
		}else
			return pi(md(a,c),md(b,d));
	}
	int mr(int a,int b){
		if(a==-1)return b;
		if(b==-1)return a;
		pi z=m2(a,b,x[a].n,x[b].n);
		return np(z.a,z.b);
	}
	template<class F,class G>
	pi sp(int i,N w,F f,G g){
		if(x[i].l==-1){
			if((w.*f)(g))return pi(-1,md(i,w));
			else return pi(md(i,w),-1);
		}
		auto a=push(i,w);
		if((a.a.*f)(g)){
			pi b=sp(x[i].l,a.a,f,g);
			return pi(b.a,mr(b.b,md(x[i].r,a.b)));
		}else{
			pi b=sp(x[i].r,a.b,f,g);
			return pi(mr(md(x[i].l,a.a),b.a),b.b);
		}
	}
	template<class F,class G>
	pi sp(int i,F f,G g){return sp(i,x[i].n,f,g);}
	template<class G>
	pi sp(int i,G g){return sp(i,&N::split,g);}
	void dfs(int i,N w,vc<N>&v){
		if(x[i].l==-1){
			v.pb(w);
			return;
		}
		auto a=push(i,w);
		dfs(x[i].l,a.a,v);
		dfs(x[i].r,a.b,v);
	}
	vc<N> tr(int i){
		vc<N> v;
		dfs(i,x[i].n,v);
		return v;
	}
	int mem(){
		return x.size()*sizeof(N2);
	}
};

//空のstructに対してsplit関数を呼ぶことがあることに注意
//split関数は、半開区間のイメージで、そのノード以下に敷居があるか判定
struct N{
	int v,s;
	N(int vv=0,int ss=0):v(vv),s(ss){}
	void push(N&){}
	static N merge(N x,N y){return N(0,x.s+y.s);}
	bool split(int&a){
		if(a<s)return true;
		a-=s;
		return false;
	}
};

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);

	int n,m;cin>>n>>m;
	int s;ll t;cin>>s>>t;
	s--;

	while(t%n){
		if(s<m){
			s=(s+t)%n;
		}else{
			s=(s-t%n+n)%n;
		}
		t--;
	}
	t/=n;

	pavl<N> avl;
	int r=-1;
	const auto getidx=[&](){
		auto res=avl.tr(r);
		vi cur(n);
		rep(i,n)cur[i]=res[i].v;
		avl.x.clear();
		return cur;
	};
	const auto gen=[&](vi idx){
		for(auto&i:idx)i=avl.nn(N(i,1));
		r=-1;
		rep(i,n)
			r=avl.mr(r,avl.nn(N(i,1)));
		/*int k;
		while((k=idx.size())>1){
			if(k%2)idx.pb(-1),k++;
			vi nx;
			rep(i,k/2)
				nx.pb(avl.mr(idx[i*2],idx[i*2+1]));
			idx=nx;
		}
		r=idx[0];*/
	};
	{
		vi idx(n);
		iota(all(idx),0);
		gen(idx);
	}

	rng(i,1,n){
		const auto g=[&](int a,int b){
			dmp(a);
			dmp(b);
			dmp(avl.x[r].n.s);
			int res=avl.sp(r,a).b;
			dmp(res);
			dmp(avl.x[res].n.s);
			assert(avl.x[res].n.s==n-a);
			if(n-a<b){
				res=avl.mr(res,avl.sp(r,b-(n-a)).a);
			}else{
				res=avl.sp(res,b).a;
			}
			dmp(avl.x[res].n.s);
			assert(avl.x[res].n.s==b);
			return res;
		};
		r=avl.mr(g(i,m),g((m-i+n)%n,n-m));
		if(avl.mem()>450000000)
			gen(getidx());
	}

	vi cur=getidx();
	while(t){
		if(t%2)s=cur[s];
		vi nx(n);
		rep(i,n)nx[i]=cur[cur[i]];
		cur=nx;
		t>>=1;
	}
	cout<<s+1<<endl;
}

#pragma comment(linker, "/STACK:1000000000")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>
#include <assert.h>
#include <vector>
#include <cstring>
#include <bitset>
#include <random>
//#include <priority_queue>

#define all(a) (a).begin(), (a).end()
#define pb push_back
#define mp make_pair
#define ld long double
#define pii pair <int, int>
#define ll long long
#define pll pair <ll, ll>

using namespace std;

struct vt {
	int x;
	int sz;
	int l, r;

	vt() {

	}

	vt(int x) : x(x), sz(1), l(-1), r(-1) {

	}
};

const int maxm = (int)6.5e7 + 10;

vt mas[maxm];
int posit = 0;

int my_new(int x) {
	if (posit == maxm) {
		cout << "FUCK" << endl;
		exit(0);
	}
	mas[posit] = vt(x);
	return posit++;
}

int cpy(int t) {
	int nt = my_new(mas[t].x);
	mas[nt].sz = mas[t].sz;
	mas[nt].l = mas[t].l;
	mas[nt].r = mas[t].r;

	return nt;
}

int sz(int t) {
	return (t == -1 ? 0 : mas[t].sz);
}

void recalc(int t) {
	mas[t].sz = sz(mas[t].l) + sz(mas[t].r) + 1;
}

void split(int t, int k, int &l, int &r) {
	if (t == -1) {
		l = -1;
		r = -1;
	}
	else if (sz(mas[t].l) >= k) {
		t = cpy(t);
		split(mas[t].l, k, l, mas[t].l);
		r = t;
		recalc(r);
	}
	else {
		t = cpy(t);
		split(mas[t].r, k - sz(mas[t].l) - 1, mas[t].r, r);
		l = t;
		recalc(l);
	}
}

int merge(int l, int r) {
	if (l == -1) {
		return r;
	}

	if (r == -1) {
		return l;
	}

	if ((ll)rand() * (sz(l) + sz(r)) <= (ll)sz(l) * RAND_MAX) {
		l = cpy(l);
		mas[l].r = merge(mas[l].r, r);
		recalc(l);
		return l;
	}
	else {
		r = cpy(r);
		mas[r].l = merge(l, mas[r].l);
		recalc(r);
		return r;
	}
}

int go(int t, int ps) {
	if (t == -1) {
		cout << "ASS" << endl;
		throw 1;
	}

	if (sz(mas[t].l) > ps) {
		return go(mas[t].l, ps);
	}
	else if (sz(mas[t].l) == ps) {
		return mas[t].x;
	}
	else {
		return go(mas[t].r, ps - sz(mas[t].l) - 1);
	}
}

int n, m;

int get_seg(int t, int l, int r) {
	if (l < 0) {
		return merge(get_seg(t, l + n, n - 1), get_seg(t, 0, r));
	}
	else if (r >= n) {
		return merge(get_seg(t, l, n - 1), get_seg(t, 0, r - n));
	}
	else {
		int lm, m, rm;

		split(t, r + 1, lm, rm);
		split(lm, l, lm, m);
		return m;
	}
}

int rebuild(int t, int sd) {
	int nt = get_seg(t, sd, m - 1 + sd);
	nt = merge(nt, get_seg(t, m - sd, n - 1 - sd));

	return nt;
}

const int maxn = (int)1e5 + 10;

int lnk[maxn];

void build_lnk(int t, int sd) {
	if (t == -1) {
		return;
	}

	build_lnk(mas[t].l, sd);
	lnk[sd + sz(mas[t].l)] = mas[t].x;
	build_lnk(mas[t].r, sd + sz(mas[t].l) + 1);
}

int used[maxn];

int main() {
	cin >> n >> m;
	//n = (int)1e5;
	//m = n / 3;

	int s;
	ll t;

	cin >> s >> t;
	//s = 1;
	//t = (ll)1e12;
	s--;

	int cn = t % n;

	t /= n;

	int ans = -1;

	for (int i = 0; i < n; i++) {
		ans = merge(ans, my_new(i));
	}

	for (int i = 1; i < n; i++) {
		ans = rebuild(ans, i);
		if (sz(ans) != n) {
			cout << "BAD" << endl;
			throw 1;
		}
		if (i == cn) {
			s = go(ans, s);
		}
	}

	memset(lnk, -1, sizeof lnk);

	build_lnk(ans, 0);

	for (int i = 0; i < n; i++) {
		if (lnk[i] == -1) {
			cout << "BAD1" << endl;
			throw 1;
		}
	}

	int it = 1;

	while (used[s] == 0 && t != 0) {
		used[s] = it++;
		t--;
		s = lnk[s];
	}

	t %= (it - used[s]);

	while (t--) {
		s = lnk[s];
	}

	cout << s + 1 << endl;

	//system("pause");
}

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

const int mxN=1e5;
int n, m, s, dp, nxt[mxN][40], ni, b[mxN];
long long t;
mt19937 mg(chrono::steady_clock::now().time_since_epoch().count());

template<size_t S>
struct treap {
	int n=1, lc[S+1], rc[S+1], a[S+1], s[S+1];
	int cmb(int u) {
		s[u]=s[lc[u]]+1+s[rc[u]];
		return u;
	}
	int cpy(int u) {
		a[n]=a[u];
		lc[n]=lc[u];
		rc[n]=rc[u];
		return n++;
	}
	int mrg(int u, int v, bool b=0) {
		if(!u||!v)
			return u^v;
		if(mg()%(s[u]+s[v])<s[u]) {
			if(!b)
				u=cpy(u);
			rc[u]=mrg(rc[u], v);
			return cmb(u);
		} else {
			if(!b)
				v=cpy(v);
			lc[v]=mrg(u, lc[v]);
			return cmb(v);
		}
	}
	array<int, 2> spl(int u, int k) {
		if(!u)
			return {};
		u=cpy(u);
		if(k>s[lc[u]]) {
			array<int, 2> a=spl(rc[u], k-s[lc[u]]-1);
			rc[u]=a[0];
			return {cmb(u), a[1]};
		} else {
			array<int, 2> a=spl(lc[u], k);
			lc[u]=a[1];
			return {a[0], cmb(u)};
		}
	}
	void dfs(int u) {
		if(!u)
			return;
		dfs(lc[u]);
		nxt[ni++][0]=a[u];
		dfs(rc[u]);
	}
};
treap<40000000> tr;

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

	cin >> n >> m >> s >> t, --s;
	for(int i=0; i<n; ++i) {
		tr.a[tr.n]=i;
		tr.s[tr.n]=1;
		b[i]=tr.n++;
	}
	for(int i=1; i<n; i*=2)
		for(int j=0; j+i<n; j+=2*i)
			b[j]=tr.mrg(b[j], b[j+i], 1);
	dp=b[0];
	for(int i=1; i<n; ++i) {
		array<int, 2> a=tr.spl(dp, i);
		int dp1, dp2;
		if(n-i<m) {
			array<int, 2> b=tr.spl(a[0], m-n+i);
			dp1=tr.mrg(a[1], b[0]);
		} else
			dp1=tr.spl(a[1], m)[0];
		a=tr.spl(dp, n-i);
		if(i>m) {
			array<int, 2> b=tr.spl(a[1], m);
			dp2=tr.mrg(b[1], a[0]);
		} else
			dp2=tr.spl(a[0], m-i)[1];
		dp=tr.mrg(dp1, dp2);
	}
	tr.dfs(dp);
	while(t%n) {
		if(s<m)
			s=(s+t)%n;
		else
			s=(s-t%n+n)%n;
		--t;
	}
	t/=n;
	for(int i=1; i<40; ++i)
		for(int j=0; j<n; ++j)
			nxt[j][i]=nxt[nxt[j][i-1]][i-1];
	for(int i=39; i>=0; --i) {
		if(t>=1ll<<i) {
			t-=1ll<<i;
			s=nxt[s][i];
		}
	}
	cout << s+1;
}

#include <bits/stdc++.h>
#define il inline
#define ri register int
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define mid ((l+r)>>1)
#define MAXN 100050
#define MAXM 5000050
#define MOD
#define INF (1<<25)
#define eps (1e-6)
#define rep(i, x, y) for(ri i = x; i <= y; ++i)
#define dwn(i, x, y) for(ri i = x; i >= y; --i)
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair <int, int> pii;
typedef pair <LL, int> pli;
typedef pair <int, LL> pil;
typedef pair <LL, LL> pll;
template <typename T> inline bool chkmin(T &x, T y) {return x > y ? x = y, 1 : 0;}
template <typename T> inline bool chkmax(T &x, T y) {return x < y ? x = y, 1 : 0;}
il void read(int &x) {
	char ch = getchar(); int f = 1; x = 0;
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = x*10+ch-'0', ch = getchar();
	x *= f;
}
int n, m, s, rt, size[MAXM], ch[MAXM][2], val[MAXM], pri[MAXM], tcnt, a[MAXN], cnt, nxt[MAXN][50];
LL t;
void update(int u) {
	size[u] = size[ch[u][0]] + size[ch[u][1]] + 1;
}
int rnd() {
	static int qwq = 19260817;
	return qwq = (qwq * 48271ll) & INT_MAX;
}
int newnode(int w) {
	++tcnt;
	pri[tcnt] = rnd(), val[tcnt] = w, size[tcnt] = 1, ch[tcnt][0] = ch[tcnt][1] = 0;
	return tcnt;
}
int newcp(int w) {
	++tcnt;
	pri[tcnt] = rnd(), val[tcnt] = val[w], size[tcnt] = size[w], ch[tcnt][0] = ch[w][0], ch[tcnt][1] = ch[w][1];
	return tcnt;
}
int merge(int x, int y) {
	if(!x || !y) return x+y;
	int t;
	if(pri[x] > pri[y]) t = newcp(x), ch[t][1] = merge(ch[t][1], y);
	else t = newcp(y), ch[t][0] = merge(x, ch[t][0]);
	update(t);
//	cout<<t<<' '<<ch[t][0]<<' '<<ch[t][1]<<' '<<size[t]<<endl;
	return t;
}
void split(int u, int k, int &x, int &y) {
	if(!u) x = y = 0;
	else {
		if(k <= size[ch[u][0]]) y = newcp(u), split(ch[y][0], k, x, ch[y][0]), update(y);
		else k -= size[ch[u][0]] + 1, x = newcp(u), split(ch[x][1], k, ch[x][1], y), update(x);
	}
}
void travel(int u) {
	if(!u) return;
	travel(ch[u][0]), a[++cnt] = val[u], travel(ch[u][1]);
}
void print(int u) {
//	cout<<rt<<endl;
	travel(u);
	rep(i, 1, cnt) cout<<a[i]<<' ';
	cout<<endl, cnt = 0;
}
int get(int l, int r) {
	int f = 0, a, b, c, d;
	if(l < 1) l += n, swap(l, r), f = 1;
	if(r > n) r -= n, swap(l, r), f = 1;
	if(!f) {
		split(rt, r, a, d);
		split(a, l-1, b, c);
		return c;
	}
	else {
		split(rt, r-1, a, d);
		split(a, l, b, c);
		return merge(d, b);
	}
}
int main() {
	read(n), read(m);
	rep(i, 1, n) {
		int cur = newnode(i);
//		cout<<"newnode is: "<<cur<<endl;
		rt = merge(rt, cur);
	}
//	cout<<size[rt]<<endl;
	rep(i, 1, n) {
		int lc = get(i+1, m+i), rc = get(m-i+1, n-i);
//		cout<<"lc: "<<endl, print(lc), cout<<"rc: "<<endl, print(rc);
		rt = merge(lc, rc);
	}
	travel(rt);
	rep(i, 1, n) nxt[i][0] = a[i];//, cout<<a[i]<<' ';
//	cout<<endl;
	read(s), scanf("%lld", &t);
	rep(i, 1, 49)
		rep(j, 1, n)
			nxt[j][i] = nxt[nxt[j][i-1]][i-1];
	while(t % n) {
		if(s <= m) s += t%n;
		else s -= t%n;
		if(s > n) s -= n;
		if(s <= 0) s += n;
		--t;
	}
	rep(i, 0, 49) {
		if(t & (1ll << i)) s = nxt[s][i];
	}
	cout<<s<<endl;
	return 0;
}

#include<cstdio>
#include<algorithm>
#include<cstring>
int n,m,S,f[50][100100];
int a[2][100100],*to=a[0],*nxt=a[1];
long long T;
void copy(int *a,int b,int len){
	if(b+len<n)memcpy(a,to+b,len*4);
	else{
		memcpy(a,to+b,(n-b)*4);
		memcpy(a+n-b,to,(len-n+b)*4);
	}
}
int main(){
	scanf("%d%d%d%lld",&n,&m,&S,&T);
	S--;
	for(int i=0;i<n;i++)to[i]=i;
	for(int i=0;i<n;i++){
		copy(nxt,i%n,m);
		copy(nxt+m,(m-i+n)%n,n-m);
		std::swap(to,nxt);
	}
	for(int i=0;i<n;i++)
		f[0][i]=to[i];
	for(int i=1;i<=40;i++)
		for(int j=0;j<n;j++)
			f[i][j]=f[i-1][f[i-1][j]];
	while(T%n!=0){
		if(S<m)S=(S+T)%n;
		else S=((S-T)%n+n)%n;
		T--;
	}
	T/=n;
	for(int i=40;i>=0;i--)
		if(T>>i&1)
			S=f[i][S];
	printf("%lld\n",S+1);
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
const int maxN = (int)1e5 + 10;
const int BUBEN = 200;
int n, m;
ll t;
int s;
int f[maxN];
int par[maxN];
pair < int, int > now[maxN];
int val_sq[maxN];
int get_par(int i) {
    if (i == par[i]) return i;
    par[i] = get_par(par[i]);
    return par[i];
}

int sub(int a, int b) {
    int s = a - b;
    if (s < 0) s += n;
    return s;
}
int sum(int a, int b) {
    int s = a + b;
    if (s >= n) s -= n;
    return s;
}
void build_stupid() {
    vector  < int > all;
    for (int i = 0; i < n; i++) {
        par[i] = i;
        f[i] = i;
        now[i] = make_pair(-1, -1);
        all.push_back(i);
    }
    for (int i = 1; i < n; i++) {
        vector < int > nall;
        for (int v : all) {
            if (f[v] < m) {
                f[v] = sub(f[v], i);
            }
            else {
                f[v] = sum(f[v], i);
            }
            if (now[f[v]].first != i) {
                now[f[v]] = make_pair(i, v);
                nall.push_back(v);
            }
            else {
                int cur = now[f[v]].second;
                par[v] = cur;
            }
        }
        swap(all, nall);
    }
    for (int i = 0; i < n; i++) {
        get_par(i);
        f[i] = f[par[i]];
    }
}
vector < int > sq[maxN];
int calc_f(int v, int step) {
    if (step == n) return v;
    if (v < m) {
        v = sub(v, step);
        return calc_f(v, step + 1);
    }
    else {
        int new_v = sub(v, val_sq[step - 1]);
        int mn_step = n + 100;
        int opt_pos = -1;
        for (int pos = 0; pos < m; pos++) {
            int need = sub(pos, new_v);
            if (sq[need].empty() || sq[need].back() < step) continue;
            int x = lower_bound(sq[need].begin(), sq[need].end(), step) - sq[need].begin();
            mn_step = min(mn_step, sq[need][x]);
            if (mn_step == sq[need][x]) {
                opt_pos = pos;
            }
        }
        if (opt_pos == -1) {
            return sum(new_v, val_sq[n - 1]);
        }
        else {
            return calc_f(opt_pos, mn_step + 1);
        }
    }
}
int stupid(int i) {
    for (int j = 1; j < n; j++) {
        if (i < m) i = sub(i, j);
        else i = sum(i, j);
    }
    return i;
}
void build_other() {
    for (int i = 0; i < n; i++) {
        int x = ((1LL * i * (i + 1)) / 2) % n;
        val_sq[i] = x;
        sq[x].push_back(i);
    }
    for (int i = 0; i < n; i++) {
        f[i] = calc_f(i, 1);
    }
}
int up[maxN][65];
int main() {
    //freopen("input.txt", "r", stdin);
    srand(239);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m >> s >> t;
    s--;
    bool rev = false;
    if (m > n - 1 - m) {
        m = n - 1 - m;
        s = n - 1 - s;
        rev = true;
    }
    while (t % n > 0) {
        if (s < m) {
            s = (int)((s + (t % n)) % n);
        }
        else {
            s = (int)((s - (t % n) + n) % n);
        }
        t--;
    }
    if (m > BUBEN) {
        build_stupid();
    }
    else {
        build_other();
    }
    ll steps = t / n;
    for (int i = 0; i < n; i++) {
        up[i][0] = f[i];

    }
    for (int j = 1; j < 63; j++) {
        for (int i = 0; i < n; i++) {
            up[i][j] = up[up[i][j - 1]][j - 1];
        }
    }
    for (int i = 62; i >= 0; i--) {
        if ((1LL << i) <= steps) {
            s = up[s][i];
            steps -= (1LL << i);
        }
    }
    if (rev) {
        cout << n - s;
    }
    else {
        cout << s + 1;
    }
    return 0;
}

#include <cstdio>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <cstring>
#include <functional>

using namespace std;

#define pb push_back
#define all(X) X.begin(), X.end()
#define ll long long

int nextt[100001];
struct MyHash
{
    std::size_t operator()(pair<int, int> const& s) const noexcept
    {
        std::size_t h1 = std::hash<int>{}(s.first);
        std::size_t h2 = std::hash<int>{}(s.second);
        return h1 ^ (h2 << 1);
    }
};

unordered_map<pair<int, int>, ll, MyHash> M(100001);

int calc_ns(int s, ll t, int m, int n) {
  if (s < m) return (s + (t % n)) % n;
  return (s - (t % n) + n) % n;
}

int main()
{
#ifdef DEBUG
  freopen("g.in", "r", stdin);
  freopen("g.out", "w", stdout);
#endif
  int n, m;
  int s;
  ll t;
  scanf("%d %d", &n, &m);
  scanf("%d %lld", &s, &t);

  s--;
  for (int i = 0; i < n; i++) {
    if (i < m) {
      ll p = 1;
      for (; p * p <= i; p <<= 1);
      ll k = 0;
      for (; p; p >>= 1)
        if (i - (k + p) * (k + p + 1) / 2 >= 0) k += p;
      k++;
      nextt[i] = k;
    } else {
      ll p = 1;
      for (; p * p <= (n - i); p <<= 1);
      ll k = 0;
      for (; p; p >>= 1)
        if (i + (k + p) * (k + p + 1) / 2 < n) k += p;
      k++;
      nextt[i] = k;
    }
  }
  while (t > 0) {
    int ns, tr;
    auto it = M.find({s, t % n});
    if (it != M.end()) {
      ll ot = it->second;
      ll tr = ot - t;
      if (ot < t) tr = ot;
      else M[{s, t % n}] = tr;
      while (t > tr) t -= tr;
    }
    if (t % n == 0) {
      ll mv = nextt[s] * (nextt[s] + 1) / 2;
      ns = s < m ? (s - mv + n) % n : (s + mv) % n;
      tr = nextt[s] + 1;
    } else {
      ns = calc_ns(s, t, m, n);
      if (s < m && ns >= m && (t % n) <= m || s >= m && ns < m && (t % n) <= m) {
        int a = (t % n) / 2;
        int l = abs(m - 1 - s);
        int r = abs(m - 1 - ns);
        if (l > r) {
          s = ns;
          t--;
        }
        a = min(a, abs(m - 1 - s));
        ns = s < m ? s + a : s - a;
        tr = a * 2;
        if (ns == m - 1) {
          int l = ((t % n) -tr) % 4;
          ns = (l == 0 || l == 3) ? m - 1: m;
          tr = (t % n);
        }
      } else {
        if (M.size() < n * 100) {
          M[{s, t % n}] = t;
        }
        tr = 1;
      }
    }
    s = ns;
    t -= tr;
  }
  printf("%d\n", s + 1);
  return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <unordered_map>
#include <cassert>
#include <time.h>
#include <sstream>
#include <random>

#define floor asdasds
#define prev asasdasd
#define next aasdasda
#define rank asdasdknlasd
#define move asdasdas
#define hash ljansld

using namespace std;

typedef long long ll;
typedef double dbl;

template<class T>
void print(vector<T> s){
    for (T x : s)
        cout << x << " ";
    cout << endl;
}

int gcd(int a, int b){
	return b > 0 ? gcd(b, a % b) : a;
}

// const int inf = 1e9 + 7;

mt19937 mrand(random_device{} ());
int rnd(int x = 1e9) {
    return mrand() % x;
}

struct Node{
	int x;
	int cnt;
	Node* left;
	Node* right;
	Node(int x = 0) : x(x), cnt(1), left(nullptr), right(nullptr) {}
};

Node* clone(Node* v){
	if (v == nullptr)
		return nullptr;
	Node* u = new Node(v -> x);
	u -> cnt = v -> cnt;
	u -> left = v -> left;
	u -> right = v -> right;
	return u;
}

void update(Node* &v){
	if (v == nullptr)
		return;
	v -> cnt = 1;
	if (v -> left != nullptr)
		v -> cnt += v -> left -> cnt;
	if (v -> right != nullptr)
		v -> cnt += v -> right -> cnt;
}

Node* merge(Node* v, Node* u){
	if (v == nullptr)
		return u;
	if (u == nullptr)
		return v;
	Node* q;
	int x = rnd(v -> cnt + u -> cnt);
	if (x < v -> cnt){
		q = clone(v);
		q -> right = merge(q -> right, u);
	}
	else{
		q = clone(u);
		q -> left = merge(v, q -> left);
	}
	update(q);
	return q;
}

pair<Node*, Node*> split(Node* v, int k){
	if (v == nullptr)
		return {v, v};
	Node* q = clone(v);
	int cnt = 1;
	if (q -> left != nullptr)
		cnt += q -> left -> cnt;
	pair<Node*, Node*> u;
	if (cnt <= k){
		u = split(q -> right, k - cnt);
		q -> right = u.first;
		update(q);
		return {q, u.second};
	}
	else{
		u = split(q -> left, k);
		q -> left = u.second;
		update(q);
		return {u.first, q};
	}
}

int get(Node* v, int k){
	assert(v != nullptr);
	int cnt = 0;
	if (v -> left != nullptr)
		cnt += v -> left -> cnt;
	if (cnt == k)
		return v -> x;
	if (cnt < k)
		return get(v -> right, k - cnt - 1);
	return get(v -> left, k);
}

vector<int> p;

void getPerm(Node* v){
	if (v == nullptr)
		return;
	getPerm(v -> left);
	p.push_back(v -> x);
	getPerm(v -> right);
}

const int maxn = 1e5 + 7;
int prev[maxn];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    // freopen("test.in", "r", stdin);
   	int n, m;
   	cin >> n >> m;
   	vector<Node*> s(n, nullptr);
   	for (int i = 0; i < n; i++)
   		s[0] = merge(s[0], new Node(i));
   	pair<Node*, Node*> v, u;
   	for (int i = 1; i < n; i++){
   		Node* root = nullptr;
   		if (m + i > n){
   			v = split(s[i - 1], i);
   			u = split(v.first, m + i - n);
   			s[i] = merge(v.second, u.first);
   		}
   		else{
   			v = split(s[i - 1], i);
   			u = split(v.second, m);
   			s[i] = u.first;
   		}

   		if (m - i >= 0){
   			v = split(s[i - 1], m - i);
   			u = split(v.second, n - m);
   			s[i] = merge(s[i], u.first);
   		}
   		else{
   			v = split(s[i - 1], n + m - i);
   			u = split(v.first, n - i);
   			s[i] = merge(s[i], merge(u.first, v.second));
   		}
   	}
   	getPerm(s[n - 1]);
  	int start, t;
  	cin >> start >> t;
  	int x = t % n;
  	start = get(s[x], start - 1);
  	// cout << start << endl;
	ll k = t / n;
	fill(prev, prev + n, -1);
	int ost = -1;
	for (int i = 0; i < k; i++){
		int next = p[start];
		if (prev[next] != -1){
			int len = i - prev[next];
			ost = (k - i) % len;
			break;
		}
		else{
			prev[next] = i;
			start = next;
		}
	}
	for (int i = 0; i < ost; i++)
		start = p[start];
	cout << start + 1 << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,s,t,res;
int boo[100100],ans[100100];
ll run(ll s,ll t){
	for(;t;t--) if(s&&s<=m) s=(s+t)%n;else s=(s-t%n+n)%n;
	return s;
}

int main(){
	scanf("%lld%lld%lld%lld",&n,&m,&s,&t);
	//printf("%lld\n",run(s,t));
	s=run(s,t%n); t/=n;
	for(int i=1;i<=t;i++){
		boo[s]=i;ans[i]=s;
		ll nex=run(s,n);
		if(boo[nex]) {res=ans[t%i+1];break;}
		s=nex;
	}
	if(!res) res=s;
	printf("%lld\n",res);
}

#include <bits/stdc++.h>
#define ll long long

#define TASKNAME ""

using namespace std;

const ll INF = 1e9 + 7;
const ll MAXN = 1e6 + 7;
const double EPS = 1e-8;

int main() {
    #ifdef MY
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #else
        //freopen(TASKNAME".in", "r", stdin);
        //freopen(TASKNAME".out", "w", stdout);
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    #endif // MY
    ll n, m;
    cin >> n >> m;
    ll s;
    ll t;
    cin >> s >> t;
    ll od = t % n;
    s--;
    unordered_map <ll, ll> was;
    ll now = 1;
    while (t > 0) {
        if (was[s * MAXN + od]) break;
        was[s * MAXN + od] = now++;
        if (s < m) {
            s += od;
            if (s >= n) {
                s -= n;
            }
        } else {
            s -= od;
            if (s < 0) {
                s += n;
            }
        }
        if (!od) {
            od = n - 1;
        } else {
            od--;
        }
    }
    t -= now - 1;
    if (!t) {
        cout << s + 1 << "\n";
        return 0;
    }
    ll cycle = now - was[s * MAXN + od];
    t %= cycle;
    while (t > 0) {
        if (s < m) {
            s = (s + t) % n;
        } else {
            s = ((s - t) % n + n) % n;
        }
        t--;
    }
    cout << s + 1;
}

#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<iostream>
using namespace std;
typedef long long ll;
const int MAXN = 100000;
struct treap{
	struct node{
		int key, siz;
		node *ch[2];
	}pl[30*MAXN + 5], *ncnt, *NIL;
	typedef pair<node*, node*> Droot;
	treap() {
		NIL = &pl[0];
		NIL->ch[0] = NIL->ch[1] = NIL;
		NIL->key = NIL->siz = 0;
	}
	void trans(int *f, node *x, int k) {
		if( x == NIL ) return ;
		f[x->ch[0]->siz + k + 1] = x->key;
		trans(f, x->ch[0], k);
		trans(f, x->ch[1], x->ch[0]->siz + k + 1);
	}
	void pushup(node *x) {
		x->siz = x->ch[0]->siz + x->ch[1]->siz + 1;
	}
	node *build(int *f, int l, int r) {
		if( l > r ) return NIL;
		int mid = (l + r) >> 1;
		node *p = (++ncnt); p->key = f[mid];
		p->ch[0] = build(f, l, mid - 1);
		p->ch[1] = build(f, mid + 1, r);
		pushup(p);
		return p;
	}
	node *build(int *f, int n) {
		ncnt = &pl[0];
		return build(f, 1, n);
	}
	Droot split(node *x, int k) {
		if( x == NIL ) return make_pair(NIL, NIL);
		node *p = (++ncnt); (*p) = (*x);
		if( x->ch[0]->siz >= k ) {
			Droot q = split(x->ch[0], k);
			p->ch[0] = q.second; pushup(p);
			return make_pair(q.first, p);
		}
		else {
			Droot q = split(x->ch[1], k - x->ch[0]->siz - 1);
			p->ch[1] = q.first; pushup(p);
			return make_pair(p, q.second);
		}
	}//first k elements
	node *merge(node *x, node *y) {
		if( x == NIL ) return y;
		if( y == NIL ) return x;
		node *p = (++ncnt);
		if( rand() & 1 ) {
			(*p) = (*x), p->ch[1] = merge(x->ch[1], y);
			pushup(p);
		}
		else {
			(*p) = (*y), p->ch[0] = merge(x, y->ch[0]);
			pushup(p);
		}
		return p;
	}
}T;
treap::node *root;
int f[MAXN + 5];
int nxt[45][MAXN + 5];
int main() {
	int n, m, s; ll t;
	scanf("%d%d%d%lld", &n, &m, &s, &t);
	srand(20041112 ^ n ^ m ^ s);
	for(int i=1;i<=n;i++) f[i] = i;
	root = T.build(f, n);
	for(int i=1;i<=n;i++) {
//		printf("%d\n", i);
		if( i % 300 == 0 )
			T.trans(f, root, 0), root = T.build(f, n);
		treap::node *p, *q;
		treap::node *tmp = T.split(root, i).second;
		if( tmp->siz >= m )
			p = T.split(tmp, m).first;
		else p = T.merge(tmp, T.split(root, m-tmp->siz).first);
		tmp = T.split(root, n - i).first;
		if( tmp->siz >= n-m )
			q = T.split(tmp, tmp->siz-(n-m)).second;
		else q = T.merge(T.split(root, n-(m-tmp->siz)).second, tmp);
		root = T.merge(p, q);
	}
	T.trans(f, root, 0);
	while( t % n ) {
		if( s <= m ) s = (s - 1 + t) % n + 1;
		else s = ((s - 1 - t) % n + n) % n + 1;
		t--;
	}
	for(int i=1;i<=n;i++) nxt[0][i] = f[i];
	for(int j=1;j<45;j++)
		for(int i=1;i<=n;i++)
			nxt[j][i] = nxt[j-1][nxt[j-1][i]];
	int x = t/n;
	for(int i=44;i>=0;i--)
		if( (1LL<<i) <= x ) x -= (1LL<<i), s = nxt[i][s];
	printf("%d\n", s);
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a) {
	os << '{';
	for(int i=0;i<sz(a);i++)
	{
		if(i>0&&i<sz(a)-1)
			os << ", ";
		os << a[i];
	}
	os << '}';
    return os;
}

int main()
{
	int n,m;
	scanf("%i %i",&n,&m);
	m--;
	int s;
	ll t;
	scanf("%i %lld",&s,&t);
	s--;
	int tr=s;
	int step=n;
	ll dd=(ll)(n)*(n+1)/2;
	int dist=abs(s-m);
	if(t>n){
        ll ttt=abs(dd-dist);
        if(ttt%2==0)
        {
            tr=m;
        }
        else
        {
            tr=m;
        }
	}
	int num=t%n;
	step=num;
	for(int i=0;i<num;i++)
    {
        if(tr<=m)
        {
            tr=(tr+step)%n;
        }
        else
        {
            tr=(tr-step)%n;
            if(tr<0)
                tr+=n;
        }
        step--;
    }
    printf("%i\n",tr+1);
    return 0;
}

//Pantyhose(black) + glasses = infinity

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

#define debug(x) cerr << #x << " = " << x << '\n';
#define BP() cerr << "OK!\n";
#define PR(A, n) {cerr << #A << " = "; for (int _=1; _<=n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; for (int _=0; _<n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define FILE_NAME "data"

const int MAX_N = 100002;

int n, m, s, t;
bool visited[MAX_N];

void read_input() {
	cin >> n >> m >> s >> t;
	s = (s - 1 + n) % n;
}

int next_station(int s) {
	for (int t=n-1; t>=0; --t) {
		if (s < m)
			s = (s + t) % n;
		else
			s = (s - t + n) % n;
	}
	return s;
}

void solve() {
	while (t % n) {
		if (s < m)
			s = (s + t%n) % n;
		else
			s = (s - t%n + n) % n;
		--t;
	}
	visited[s] = true;
	vector<int> p(1, s);
	int64_t tmp = t / n;
	while (tmp > 0) {
		int s2 = next_station(s);
		if (visited[s2]) {
			for (int i=0; i<p.size(); ++i) {
				if (p[i] == s2) {
					p.erase(p.begin(), p.begin() + i);
					break;
				}
			}
			break;
		}
		--tmp;
		visited[s2] = true;
		p.push_back(s2);
		s = s2;
	}
	if (tmp == 0)
		cout << p.back() + 1;
	else
		cout << p[(tmp & p.size() - 1 + p.size()) % p.size()] + 1;
}

int main() {
	#ifdef GLASSES_GIRL
		freopen(FILE_NAME".inp", "r", stdin);
		freopen(FILE_NAME".out", "w", stdout);
	#endif
	ios::sync_with_stdio(0); cin.tie(0);
	read_input();
	solve();
}

#define _CRT_SECURE_NO_DEPRECATE
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <memory.h>
#include <set>
#include <ctime>
#include <map>
#include <cstring>
#include <iterator>
#include <queue>
#include <assert.h>
#include <bitset>
#include <complex>
#include <unordered_map>

//#pragma comment(linker, "/STACK:512000000")

using namespace std;

#define pb emplace_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define forab(i, a, b) for (int i = (a); i < (b); ++i)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int infi = 1e9 + 7;
const ll infl = (ll)1e18 + (ll)7;

struct node {
    node* l, *r;
    int sz, a;
    node() {}
    node(int _a) : a(_a), sz(1), l(0), r(0) {}
    node(node* other) : a(other->a), l(other->l), r(other->r), sz(other->sz) {}
};
typedef node* pnode;
const int max_cnt = 6e7;
int cur_cnt;
node buf_node[max_cnt];
pnode new_node(int a) {
   // return new node(a);
    buf_node[cur_cnt] = node(a);
    return &buf_node[cur_cnt++];
}
pnode new_node(pnode a) {
    if (cur_cnt == max_cnt) {
        cout << "123";
        exit(0);
    }
  //  return new node(a);
    buf_node[cur_cnt] = node(a);
    return &buf_node[cur_cnt++];
}
void upd(pnode v) {
    if (!v)
        return;
    v->sz = 1;
    if (v->l)
        v->sz += v->l->sz;
    if (v->r)
        v->sz += v->r->sz;
}
int get_rnd() {
    //return rand();
    return rand() ^ (rand() << 15);
}
pnode merge(pnode l, pnode r) {
    if (!l || !r)
        return max(l, r);
    int q = l->sz, w = r->sz;
    int rang = get_rnd() % (q + w);
    if (rang < q) {
        pnode ans = new_node(l);
        ans->r = merge(l->r, r);
        upd(ans);
        return ans;
    } else {
        pnode ans = new_node(r);
        ans->l = merge(l, r->l);
        upd(ans);
        return ans;
    }
}
int get_size(pnode v) {
    if (v)
        return v->sz;
    return 0;
}
void split(pnode t, pnode& l, pnode& r, int sz) {
    if (!t) {
        l = r = 0;
        return;
    }
    pnode cur = new_node(t);
    int q = get_size(cur->l) + 1;
    if (q <= sz) {
        split(cur->r, cur->r, r, sz - q);
        l = cur;
    } else {
        split(cur->l, l, cur->l, sz);
        r = cur;
    }
    upd(l);
    upd(r);
}
pnode fast_add(pnode t, pnode v, int sz) {
    if (!t) {
        return v;
    }
    int q = t->sz, w = 1;
    int rang = get_rnd() % (q + w);
    if (rang == 0) {
        split(t, v->l, v->r, sz);
        upd(v);
        return v;
    }
    q = get_size(t->l) + 1;
    pnode nt = new_node(t);
    if (q <= sz) {
        nt->r = fast_add(t->r, v, sz - q);
    } else
        nt->l = fast_add(t->l, v, sz);
    upd(nt);
    return nt;
}
pnode add(pnode t, int a, int sz) {
    return fast_add(t, new_node(a), sz);
}

pnode cut(pnode t, int l, int r, int n) {
    if (l < 0 && r < 0)
        l += n, r += n;
    if (l >= n && r >= n)
        l -= n, r -= n;
    pnode L, MID, R;
    if (0 <= l && r < n) {
        split(t, L, R, r + 1);
        split(L, L, MID, l);
        return MID;
    }
    if (r >= n)
        r -= n, l -= n;
    if (l < 0) {
        split(t, L, R, n + l);
        split(L, L, MID, r + 1);
        return merge(R, L);
    }
}

int find(pnode t, int pos) {
    int q = get_size(t->l);
    if (q == pos)
        return t->a;
    if (pos < q)
        return find(t->l, pos);
    else
        return find(t->r, pos - q - 1);
}
pnode ver[100500];

int to[100500];
int used[100500];
int cur_time = 5;
int dfs(int v, int t) {
    while (t) {
        if (!used[v]) {
            used[v] = cur_time++;
            --t;
            v = to[v];
            continue;
        }
        int len = abs(cur_time++ - used[v]);
        if (t > 1e6)
            t %= len;
        if (t == 0)
            break;
        --t;
        v = to[v];
    }
    return v;
}
int get_h(pnode t) {
    if (!t)
        return 0;
    return max(
        get_h(t->l), get_h(t->r)
    ) + 1;
}

int ar[100500];
pnode rebuild(pnode t, int n) {
    forn(i, n)
        ar[i] = find(t, i);
    cur_cnt = 0;
    t = 0;
    forn(i, n)
        t = add(t, ar[i], i);
    return t;
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    //freopen("customs.in", "r", stdin); freopen("customs.out", "w", stdout);
   // srand(time(NULL));
    int n, m;
    cin >> n >> m;
    int s;
    ll t;
    cin >> s >> t;
    --s;
    pnode start = 0;
    forn(i, n) {
        start = add(start, i, i);
       // cerr << int(cur_cnt / 1e6) << '\n';
    }
    ver[0] = start;
    ll t1 = t % n;
    for (int i = 1; i <= t1; ++i) {
        int a = cur_cnt;
        ver[i] = merge(
            cut(ver[i - 1], i, m + i - 1, n),
            cut(ver[i - 1], m - i, n - 1 - i, n)
        );
        /*if (cur_cnt >= 3e7) {
            ver[i] = rebuild(ver[i], n);
        }*/
       // cerr << get_h(ver[i]) << ' ' << cur_cnt - a << '\n';
    }
    int s1 = find(ver[t1], s);
    for (int i = t1 + 1; i <= n; ++i) {
        int a = cur_cnt;
        ver[i] = merge(
            cut(ver[i - 1], i, m + i - 1, n),
            cut(ver[i - 1], m - i, n - 1 - i, n)
        );
       // cerr << cur_cnt - a << '\n';
      /*  if (cur_cnt >= 3e7) {
            ver[i] = rebuild(ver[i], n);
        }*/
       // cerr << get_h(ver[i]) << ' ' << cur_cnt - a << '\n';
    }

    forn(i, n)
        to[i] = find(ver[n], i);
    cout << dfs(s1, t / n)  + 1<< '\n';
   // cout << cur_cnt << endl;
    cerr << 1.0 * clock() / CLOCKS_PER_SEC;

    return 0;
}

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef complex<double> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;
const int TT = 60000001;
const ld PI = 4*atan((ld)1);

template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }

namespace io {
    // Source: StackOverflow

    template<class T> struct like_array : is_array<T>{};
    template<class T, size_t N> struct like_array<array<T,N>> : true_type{};
    template<class T> struct like_array<vector<T>> : true_type{};
    template<class T> bool is_like_array(const T& a) { return like_array<T>::value; }

    // I/O

    void setIn(string s) { freopen(s.c_str(),"r",stdin); }
    void setOut(string s) { freopen(s.c_str(),"w",stdout); }
    void setIO(string s = "") {
        ios_base::sync_with_stdio(0); cin.tie(0);
        if (sz(s)) { setIn(s+".in"), setOut(s+".out"); }
    }

    // INPUT

    // double input seems slow on CF
    void re(double& x) { string t; cin >> t; x = stod(t); }
    void re(ld& x) { string t; cin >> t; x = stold(t); }
    template<class T> void re(T& x) { cin >> x; }
    template<class Arg, class... Args> void re(Arg& first, Args&... rest) {
        re(first); re(rest...);
    }
    template<class T1, class T2> istream& operator>>(istream& is, pair<T1,T2>& p) {
        is >> p.f >> p.s; return is;
    }
    template<class T> istream& operator>>(istream& is, vector<T>& a) {
        F0R(i,sz(a)) is >> a[i];
        return is;
    }

    // OUTPUT

    template<class T> void pr(const T& x) { cout << x << '\n'; }
    template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
        cout << first << ' '; pr(rest...);
    }
    template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) {
        os << '{' << a.f << ", " << a.s << '}'; return os;
    }

    template<class T> ostream& printArray(ostream& os, const T& a, int SZ) {
        os << '{';
        F0R(i,SZ) {
            if (i) {
                os << ", ";
                if (is_like_array(a[i])) cout << "\n";
            }
            os << a[i];
        }
        os << '}';
        return os;
    }

    template<class T, size_t SZ> ostream& operator<<(ostream& os, const array<T,SZ>& a) {
        return printArray(os,a,SZ);
    }
    template<class T> ostream& operator<<(ostream& os, const vector<T>& a) {
        return printArray(os,a,sz(a));
    }
}

using namespace io;

int z = 0;
int val[TT], c[TT][2], sz[TT], nex = 1;

namespace treap {
    int tnode(int _val) {
        val[nex] = _val;
        sz[nex] = 1;
        return nex ++;
    }

    int copy(int x) {
        z ++; if (!x) return x;
        val[nex] = val[x];
        F0R(i,2) c[nex][i] = c[x][i];
        sz[nex] = sz[x];
        return nex ++;
    }

    int getsz(int x) { return x?sz[x]:0; }

    int recalc(int x) {
        sz[x] = 1+getsz(c[x][0])+getsz(c[x][1]);
        return x;
    }

    void tra(int x, vi& v) {
        if (!x) return;
        tra(c[x][0],v); v.pb(val[x]); tra(c[x][1],v);
    }

    pi splitsz(int t, int sz) {
        if (!t) return {t,t};
        auto T = copy(t);
        // cout << "AH " << t << " " << sz[t] << "\n";
        if (getsz(c[T][0]) >= sz) {
            auto p = splitsz(c[T][0], sz); c[T][0] = p.s;
            return {p.f, recalc(T)};
        } else {
            auto p = splitsz(c[T][1], sz-getsz(c[T][0])-1); c[T][1] = p.f;
            return {recalc(T), p.s};
        }
    }

    bool shouldLeft(int a, int b) {
        return rand() % (a+b) < a;
    }

    int merge(int L, int R, bool b = 0) {
        if (!L) return copy(R);
        if (!R) return copy(L);

        int t;
        if (shouldLeft(getsz(L),getsz(R))) {
            t = copy(L);
            c[t][1] = merge(c[L][1],R);
        } else {
            t = copy(R);
            c[t][0] = merge(L,c[R][0]);
        }
        return recalc(t);
    }
}

using namespace treap;

int n,m, NEX[MX];
ll s, t;

void brute() {
    if (s <= m) s += t;
    else s -= t;
    s %= n;
    while (s <= 0) s += n;
    t --;
}

int cur = 0;

int get(int l, int r) {
    while (l > n) l -= n, r -= n;
    while (l <= 0) l += n, r += n;
    if (r > n) return merge(get(l,n),get(n+1,r));
    auto a = splitsz(cur,r);
    auto b = splitsz(a.f,l-1);
    auto des = copy(b.s);
    cur = merge(merge(b.f,b.s),a.s);
    return des;
}

int build(vi& v, int l, int r) {
    if (l > r) return 0;
    int m = (l+r)/2;
    int root = tnode(v[m]);
    c[root][0] = build(v,l,m-1);
    c[root][1] = build(v,m+1,r);
    return recalc(root);
}

void gen() {
    FOR(i,1,n+1) cur = merge(cur, tnode(i));
    //cout << cur << " " << sz[cur] << ' ' << c[cur][0] << ' ' << c[cur][1] << "\n";
    //cout << sz[c[cur][0]] << " " << sz[c[cur][1]] << "\n";
    //auto a = splitsz(cur,5); cout << sz[a.f] << " " << sz[a.s]; exit(0);
    FOR(i,1,n) {
        int Z = z;
        auto a = get(i+1,i+m);
        auto b = get(m+1-i,n-i);
        if (getsz(a) != m || getsz(b) != n-m) {
            cout << "OOPS " << a << " " << b << " " << i << " " << getsz(a) << " " << getsz(b) << "\n";
            exit(0);
        }
        cur = merge(a,b);
        if (z-Z >= 1000) {
            vi v; tra(cur,v);
            cur = build(v,0,sz(v)-1);
        }
    }
    cout << z << "\n";
    vi v; tra(cur,v);
    F0R(i,sz(v)) NEX[i+1] = v[i];
}

int main() {
    // you should actually read the stuff at the bottom
    setIO(); re(n,m,s,t);
    gen();
    while (t % n != 0) brute();
    while (t) {
        s = NEX[s];
        t -= n;
    }
    cout << s;
    // you should actually read the stuff at the bottom
}

/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
const int maxN = (int)1e5 + 10;
const int BUBEN = 460;
int n, m;
ll t;
int s;
int f[maxN];
int par[maxN];
pair < int, int > now[maxN];
int val_sq[maxN];
int get_par(int i) {
    if (i == par[i]) return i;
    par[i] = get_par(par[i]);
    return par[i];
}

int sub(int a, int b) {
    int s = a - b;
    if (s < 0) s += n;
    return s;
}
int sum(int a, int b) {
    int s = a + b;
    if (s >= n) s -= n;
    return s;
}
void build_stupid() {
    vector  < int > all;
    for (int i = 0; i < n; i++) {
        par[i] = i;
        f[i] = i;
        now[i] = make_pair(-1, -1);
        all.push_back(i);
    }
    for (int i = 1; i < n; i++) {
        vector < int > nall;
        for (int v : all) {
            if (f[v] < m) {
                f[v] = sub(f[v], i);
            }
            else {
                f[v] = sum(f[v], i);
            }
            if (now[f[v]].first != i) {
                now[f[v]] = make_pair(i, v);
                nall.push_back(v);
            }
            else {
                int cur = now[f[v]].second;
                par[v] = cur;
            }
        }
        swap(all, nall);
    }
    for (int i = 0; i < n; i++) {
        get_par(i);
        f[i] = f[par[i]];
    }
}
vector < int > sq[maxN];
int calc_f(int v, int step) {
    if (step == n) return v;
    if (v < m) {
        v = (v - (step % n) + n) % n;
        return calc_f(v, step + 1);
    }
    else {
        int new_v = sub(v, val_sq[step - 1]);
        int mn_step = n + 100;
        int opt_pos = -1;
        for (int pos = 0; pos < m; pos++) {
            int need = sub(pos, new_v);
            if (sq[need].empty() || sq[need].back() < step) continue;
            int x = lower_bound(sq[need].begin(), sq[need].end(), step) - sq[need].begin();
            mn_step = min(mn_step, sq[need][x]);
            if (mn_step == x) {
                opt_pos = pos;
            }
        }
        if (opt_pos == -1) {
            return sum(new_v, val_sq[n - 1]);
        }
        else {
            return calc_f(opt_pos, mn_step + 1);
        }
    }
}
void build_other() {
    for (int i = 0; i < n; i++) {
        int x = ((1LL * i * (i + 1)) / 2) % n;
        val_sq[i] = x;
        sq[x].push_back(i);
    }
    for (int i = 0; i < n; i++) {
        f[i] = calc_f(i, 1);
    }
}
int up[maxN][65];
int main() {
    //freopen("input.txt", "r", stdin);
    srand(239);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m >> s >> t;
    s--;
    bool rev = false;
    if (m > n - 1 - m) {
        m = n - 1 - m;
        s = n - 1 - s;
        rev = true;
    }
    while (t % n > 0) {
        if (s < m) {
            s = (int)((s + (t % n)) % n);
        }
        else {
            s = (int)((s - (t % n) + n) % n);
        }
        t--;
    }
    if (m > BUBEN) {
        build_stupid();
    }
    else {
        build_other();
    }
    ll steps = t / n;
    for (int i = 0; i < n; i++) {
        up[i][0] = f[i];

    }
    for (int j = 1; j < 63; j++) {
        for (int i = 0; i < n; i++) {
            up[i][j] = up[up[i][j - 1]][j - 1];
        }
    }
    for (int i = 62; i >= 0; i--) {
        if ((1LL << i) <= steps) {
            s = up[s][i];
            steps -= (1LL << i);
        }
    }
    if (rev) {
        cout << n - s;
    }
    else {
        cout << s + 1;
    }
    return 0;
}

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

typedef long ll;
int n,m,s,ss;
ll t,tt;
__gnu_cxx::rope<int>to;

__gnu_cxx::rope<int>work(int b,int len){
	if((b%=n)+len<n)return to.substr(b,len);
	else return to.substr(b,n-b)+to.substr(0,len+b-n);
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m>>s>>t;
	for(int i=0;i<n;++i)to.push_back(i);
	for(int T=0;T<n;++T)to=work(T,m)+work(m+n-T,n-m);
	for(--s;t%n;--t)
		s=(s+(s<m?t:-t))%n,s+=s>>31&n;
	t/=n;
	for(ss=s,tt=t;t;){
		s=to[s];ss=to[ss];ss=to[ss];--t;--tt;--tt;
		if(s==ss)t%=t-tt,tt=t;
	}
	cout<<(s+1)<<'\n';
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int n,m,s,vis[100005],cy;
long long t;
int nex(int x,int y)
{
	if(x<m)
		return (x+y)%n;
	else
		return (x-y+n)%n;
}
int main()
{
	scanf("%d %d",&n,&m);
	scanf("%d %lld",&s,&t);
	--s;
	while(t%n!=0)
	{
		s=nex(s,t%n);
		--t;
	}
	t/=n;
	while(t&&(!vis[s]))
	{
		vis[s]=1;
		++cy;
		for(int y=n-1;y>0;--y)
			s=nex(s,y);
		--t;
	}
	if(!t)
	{
		cout<<s+1;
		return 0;
	}
	t%=cy;
	while(t)
	{
		for(int y=n-1;y>0;--y)
			s=nex(s,y);
		--t;
	}
	cout<<s+1;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m,s,t;
ll cal(ll x)
{
    if(s<m) s+=t;
    else s-=t;
    t--;
    return (s%n+n)%n;
}
int main()
{
    cin>>n>>m>>s>>t;
    s--;
    while(t%n) s=cal(s);
    cout<<s+1<<endl;
    return 0;
}

#include <bits/stdc++.h>
#define il inline
#define ri register int
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define mid ((l+r)>>1)
#define MAXN 100050
#define MAXM 10000050
#define MOD
#define INF (1<<25)
#define eps (1e-6)
#define rep(i, x, y) for(ri i = x; i <= y; ++i)
#define dwn(i, x, y) for(ri i = x; i >= y; --i)
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair <int, int> pii;
typedef pair <LL, int> pli;
typedef pair <int, LL> pil;
typedef pair <LL, LL> pll;
template <typename T> inline bool chkmin(T &x, T y) {return x > y ? x = y, 1 : 0;}
template <typename T> inline bool chkmax(T &x, T y) {return x < y ? x = y, 1 : 0;}
il void read(int &x) {
	char ch = getchar(); int f = 1; x = 0;
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = x*10+ch-'0', ch = getchar();
	x *= f;
}
int n, m, s, rt, size[MAXM], ch[MAXM][2], val[MAXM], pri[MAXM], tcnt, a[MAXN], cnt, nxt[MAXN][50];
LL t;
void update(int u) {
	size[u] = size[ch[u][0]] + size[ch[u][1]] + 1;
}
int rnd() {
	static int qwq = 19260817;
	return qwq = (qwq * 48271ll) & INT_MAX;
}
int newnode(int w) {
	++tcnt;
	pri[tcnt] = rnd(), val[tcnt] = w, size[tcnt] = 1, ch[tcnt][0] = ch[tcnt][1] = 0;
	return tcnt;
}
int newcp(int w) {
	++tcnt;
	pri[tcnt] = rnd(), val[tcnt] = val[w], size[tcnt] = size[w], ch[tcnt][0] = ch[w][0], ch[tcnt][1] = ch[w][1];
	return tcnt;
}
int merge(int x, int y) {
	if(!x || !y) return x+y;
	int t;
	if(pri[x] > pri[y]) t = newcp(x), ch[t][1] = merge(ch[t][1], y);
	else t = newcp(y), ch[t][0] = merge(x, ch[t][0]);
	update(t);
//	cout<<t<<' '<<ch[t][0]<<' '<<ch[t][1]<<' '<<size[t]<<endl;
	return t;
}
void split(int u, int k, int &x, int &y) {
	if(!u) x = y = 0;
	else {
		if(k <= size[ch[u][0]]) y = newcp(u), split(ch[y][0], k, x, ch[y][0]), update(y);
		else k -= size[ch[u][0]] + 1, x = newcp(u), split(ch[x][1], k, ch[x][1], y), update(x);
	}
}
void travel(int u) {
	if(!u) return;
	travel(ch[u][0]), a[++cnt] = val[u], travel(ch[u][1]);
}
void print(int u) {
//	cout<<rt<<endl;
	travel(u);
	rep(i, 1, cnt) cout<<a[i]<<' ';
	cout<<endl, cnt = 0;
}
int get(int l, int r) {
	int f = 0, a, b, c, d;
	if(l < 1) l += n, swap(l, r), f = 1;
	if(r > n) r -= n, swap(l, r), f = 1;
	if(!f) {
		split(rt, r, a, d);
		split(a, l-1, b, c);
		return c;
	}
	else {
		split(rt, r-1, a, d);
		split(a, l, b, c);
		return merge(d, b);
	}
}
int main() {
	read(n), read(m);
	rep(i, 1, n) {
		int cur = newnode(i);
//		cout<<"newnode is: "<<cur<<endl;
		rt = merge(rt, cur);
	}
//	cout<<size[rt]<<endl;
	rep(i, 1, n) {
		int lc = get(i+1, m+i), rc = get(m-i+1, n-i);
//		cout<<"lc: "<<endl, print(lc), cout<<"rc: "<<endl, print(rc);
		rt = merge(lc, rc);
	}
	travel(rt);
	rep(i, 1, n) nxt[i][0] = a[i];//, cout<<a[i]<<' ';
//	cout<<endl;
	read(s), scanf("%lld", &t);
	rep(i, 1, 49)
		rep(j, 1, n)
			nxt[j][i] = nxt[nxt[j][i-1]][i-1];
	while(t % n) {
		if(s <= m) s += t%n;
		else s -= t%n;
		if(s > n) s -= n;
		if(s <= 0) s += n;
		--t;
	}
//	cout<<s<<endl;
	t /= n;
	rep(i, 0, 49) {
		if(t & (1ll << i)) s = nxt[s][i];
	}
	cout<<s<<endl;
	return 0;
}

#define DEBUG 1

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

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------
#pragma GCC optimize("Ofast")

int e[100000];
int ds[100000];
int find(int n) {
    if (ds[n] != n) ds[n] = find(ds[n]);
    return ds[n];
}
int pos[100000],seen[100000],num[100000];
vi alive,a2;
int tt[100000];
vi tri[100000];
int e2[100000];
int main() {
    int n,m,s;
    LLI t;
    cin >> n >> m >> s >> t,s--;
    int sw = 0;
    if (m > n/2) sw = 1,m = n-m,s = n-1-s;

    int i,j,k;
    if (m >= 20) {
        alive.resize(n),a2.resize(n);
        for (i = 0; i < n; i++) ds[i] = pos[i] = i,alive[i] = i;
        int as = n;
        for (i = n-1; i >= 0; i--) {
            int as2 = 0;
            for (j = 0; j < as; j++) {
                int u = pos[alive[j]];
                if (u < m) {
                    u += i;
                    if (u >= n) u -= n;
                }
                else {
                    u -= i;
                    if (u < 0) u += n;
                }
                pos[alive[j]] = u;
                if (seen[u] == i+1) ds[find(alive[j])] = find(num[u]);
                else seen[u] = i+1,num[u] = alive[j],a2[as2++] = alive[j];
            }
            swap(alive,a2);
            as = as2;
        }
        for (i = 0; i < as; i++) e[find(alive[i])] = pos[alive[i]];
        for (i = 0; i < n; i++) e[i] = e[find(i)];
    }
    else {
        int sum = 0;
        for (i = 0; i < n; i++) {
            sum += i,sum %= n;
            tt[i] = sum;
            tri[sum].pb(i);
        }
        for (i = 0; i < n; i++) {
            int u = i;
            j = n-1;
            while (j > 0) {
                if (u < m) {
                    u += j;
                    if (u >= n) u -= n;
                    j--;
                }
                else {
                    int mm = 0;
                    for (k = 0; k < m; k++) {
                        int x = (k-u+tt[j]+n) % n;
                        int p = lower_bound(tri[x].begin(),tri[x].end(),j)-tri[x].begin()-1;
                        if (p >= 0) mm = max(mm,tri[x][p]);
                    }
                    u -= tt[j],u += tt[mm];
                    if (u < 0) u += n;
                    if (u >= n) u -= n;
                    j = mm;
                }
            }
            //if((i % 1000)==0)cout<<i<<endl;
            e[i] = u;
        }
    }
    //printArr(e,n);
/*
    debug "here";
    for (i = 0; i < n; i++) {
        int u = i;
        for (j = n-1; j >= 0; j--) {
            if (u < m) {
                u += j;
                if (u >= n) u -= n;
            }
            else {
                u -= j;
                if (u < 0) u += n;
            }
        }
        assert(e[i]==u);
        e[i] = u;
    }
    //printArr(e,n);
    set<int>S;
    for (i=0;i<n;i++)S.insert(e[i]);
    cout<<S.size()<<endl;*/

    int u = s;
    while ((t >= 0) && ((t % n) != (n-1))) {
        if (u < m) {
            u += t % n;
            if (u >= n) u -= n;
        }
        else {
            u -= t % n;
            if (u < 0) u += n;
        }
        t--;
    }
    LLI c = t/n+1;
    for (i = 0; i < 50; i++) {
        if (c & (1LL << i)) u = e[u];
        for (j = 0; j < n; j++) e2[j] = e[e[j]];
        for (j = 0; j < n; j++) e[j] = e2[j];
    }
    if (sw) u = n-1-u;
    cout << u+1 << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ull = uint64_t;
using ll = int64_t;
using ld = long double;

#ifdef BZ
mt19937_64 mt{ 228 };
#else
mt19937_64 mt{ ull(new char) };
#endif

struct Node {
    using Ptr = Node * ;

    Ptr l;
    Ptr r;
    ull y;
    int sz;
    int x;

    Node() = default;

    Node(int x)
        : l(nullptr)
        , r(nullptr)
        , y(mt())
        , sz(1)
        , x(x)
    {
    }
};

using Ptr = Node * ;

#ifndef BZ
const int NC = 29000000;
#else
const int NC = 200000;
#endif

const int N = 100228;
Node nodes[NC + N * 2];
int nodec = 0;

template <typename ... Args>
Ptr newnode(Args&& ... args) {
    nodes[nodec] = Node(std::forward<Args>(args)...);
    return nodes + nodec++;
}

int sz(Ptr p) {
    return p ? p->sz : 0;
}

void upd(Ptr p) {
    p->sz = 1 + sz(p->l) + sz(p->r);
}

Ptr merge(Ptr l, Ptr r) {
    if (!l) {
        return r;
    }

    if (!r) {
        return l;
    }

    Ptr ans;
    if (mt() % (l->sz + r->sz) < l->sz) {
        ans = newnode(*l);
        ans->r = merge(l->r, r);
    } else {
        ans = newnode(*r);
        ans->l = merge(l, r->l);
    }

    upd(ans);
    return ans;
}

pair<Ptr, Ptr> split(Ptr t, int s) {
    if (!t) {
        return { nullptr, nullptr};
    }

    Ptr ans = newnode(*t);

    int ls = sz(t->l);
    if (s > ls) {
        auto[lc, rc] = split(t->r, s - ls - 1);
        ans->r = lc;
        upd(ans);
        return { ans, rc };
    } else {
        auto[lc, rc] = split(t->l, s);
        ans->l = rc;
        upd(ans);
        return { lc, ans };
    }
}

int a[N];
int ac;
Ptr root;

const int LG = 50;

int nx[N][LG];

Ptr build(int l, int r) {
    if (l >= r) {
        return nullptr;
    }

    int m = (l + r) / 2;
    Ptr cur = newnode(a[m]);
    cur->l = build(l, m);
    cur->r = build(m + 1, r);
    upd(cur);
    return cur;
}

void trav(Ptr p) {
    if (!p) {
        return;
    }

    trav(p->l);
    a[ac++] = p->x;
    trav(p->r);
}

int n, m;

void bld() {
    nodec = 0;
    assert(ac == n);
    root = build(0, ac);
}

void rebuild() {
    ac = 0;
    trav(root);
    bld();
}

Ptr sub(int l, int r) {
    int a = l, b = r;

    int t = 0;

    if (a < 0) {
        a += n;
        swap(a, b);
        t = 1;
    }

    if (b > n) {
        b -= n;
        swap(a, b);
        t = 1;
    }

    auto[rm, r2] = split(root, b);
    auto[r0, r1] = split(rm, a);
    if (t == 0) {
        return r1;
    } else {
        return merge(r2, r0);
    }
}

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(20);

    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        a[ac++] = i;
    }

    bld();

    for (int i = 1; i < n; ++i) {
        if (nodec > NC) {
            rebuild();
        }

        auto cl = sub(i, m + i);
        assert(sz(cl) == m);
        auto cr = sub(m - i, n - i);
        assert(sz(cr) == n - m);

        root = merge(cl, cr);
    }

    ac = 0;
    trav(root);

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

    for (int i = 1; i < LG; ++i) {
        for (int j = 0; j < n; ++j) {
            nx[j][i] = nx[nx[j][i - 1]][i - 1];
        }
    }

    int s;
    ll t;
    cin >> s >> t;
    --s;
    ++t;

    while (t % n) {
        --t;

        if (s < m) {
            s += (t % n);
        } else {
            s -= (t % n);
        }

        if (s < 0) {
            s += n;
        }

        if (s >= n) {
            s -= n;
        }
    }

    for (int i = LG - 1; i >= 0; --i) {
        if ((t >> i) & 1) {
            s = nx[s][i];
        }
    }

    cout << s + 1 << "\n";
}

#pragma GCC optimize("O3")
#ifdef ONLINE_JUDGE
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#include <deque>
#include <type_traits>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
template<typename Key=int,typename Mapped=__gnu_pbds::null_type,typename Cmp_Fn=std::less<Key>,typename Tag=__gnu_pbds::rb_tree_tag,template<typename Const_Node_Iterator,typename Node_Iterator,typename Cmp_Fn_,typename Allocator_>class Node_Update=__gnu_pbds::tree_order_statistics_node_update,typename Allocator=std::allocator<char>>class ordered_set_t:__gnu_pbds::tree<Key,Mapped,Cmp_Fn,Tag,Node_Update,Allocator>{};const int GRANDOM=std::chrono::high_resolution_clock::now().time_since_epoch().count();struct ghash{int operator()(int x){return std::hash<int>{}(x^GRANDOM);}};template<typename KeyType>class hash_table_t:__gnu_pbds::gp_hash_table<KeyType,int,ghash>{};namespace vh{template<class T>void _R(T&x){std::cin>>x;}inline void _R(int&x){scanf("%d",&x);}inline void _R(int64_t&x){scanf("%" SCNd64,&x);}inline void _R(double&x){scanf("%lf",&x);}inline void _R(char&x){scanf(" %c",&x);}inline void _R(char*x){scanf("%s",x);}inline void R(){}template<class T,class... U>inline void R(T&head,U&... tail){_R(head);R(tail...);}template<class T>void _W(const T&x){cout<<x;}inline void _W(const int&x){printf("%d",x);}inline void _W(const int64_t&x){printf("%" PRId64,x);}inline void _W(const double&x){printf("%.16f",x);}inline void _W(const char&x){putchar(x);}inline void _W(const char*x){printf("%s",x);}template<class T>inline void _W(const vector<T>&x){for(auto i=x.begin();i!=x.end();_W(*i++))if(i!=x.cbegin())putchar(' ');}inline void W(){}template<class T,class... U>inline void W(const T&head,const U&... tail){_W(head);if(sizeof...(tail))putchar(' '),W(tail...);}template<class T,class... U>inline void WL(const T&head,const U&... tail){_W(head);putchar(sizeof...(tail)? ' ':'\n');W(tail...);}};
#define prec setprecision
namespace vh{typedef long long ll;typedef unsigned long long llu;template<typename T>T gcd(T m,T n){while(n){T t=m%n;m=n;n=t;};return m;}template<typename T>T exgcd(T a,T b,T&sa,T&ta){T q,r,sb=0,tb=1,sc,tc;sa=1,ta=0;if(b)do q=a/b,r=a-q*b,a=b,b=r,sc=sa-q*sb,sa=sb,sb=sc,tc=ta-q*tb,ta=tb,tb=tc;while(b);return a;}template<typename T>T mul_inv(T a,T b){T t1=a,t2=b,t3;T v1=1,v2=0,v3;T x;while(t2!=1)x=t1/t2,t3=t1-x*t2,v3=v1-x*v2,t1=t2,t2=t3,v1=v2,v2=v3;return(v2+b)%b;}template<typename T>T powmod(T a,T b,T MOD){if(b<0)return 0;T rv=1;while(b)(b%2)&&(rv=(rv*a)%MOD),a=a*a%MOD,b/=2;return rv;}template<typename T>inline T isqrt(T k){T r=sqrt((double)k)+1;while(r*r>k)r--;return r;}template<typename T>inline T icbrt(T k){T r=cbrt((double)k)+1;while(r*r*r>k)r--;return r;}template<typename T>bool mul_overflow(T&r,T a,T b){return __builtin_mul_overflow(a,b,&r);}template<ll n>struct BitSize{enum{Size=BitSize<n/2>::Size+1};};template<>struct BitSize<0>{enum{Size=1};};template<>struct BitSize<1>{enum{Size=1};};
#define BITSIZE(n) (BitSize<n>::Size)
#define BITMAX(n) (BitSize<n>::Size - 1)
#define DEBUG !defined(ONLINE_JUDGE)
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define RALL(x) (x).rbegin(),(x).rend()
template<typename TH>void _dbg(const char*sdbg,TH h){cerr<<sdbg<<"="<<h<<"\n";}template<typename TH,typename... TA>void _dbg(const char*sdbg,TH h,TA... t){while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<",";_dbg(sdbg+1,t...);}
#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; for(auto itt: x) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
}namespace vh{template<typename T>int min_rotation(vector<T>s){int a=0,N=s.size();for(int b=0;b<N;b++)for(int i=0;i<N;i++){if(a+i==b||s[(a+i)%N]<s[(b+i)%N]){b+=max(0,i-1);break;}if(s[(a+i)%N]>s[(b+i)%N]){a=b;break;}}return a;}}namespace vh{};
namespace vh{
  const int maxn=1e5+7;
  int n,m;
  ll s,t;
  int vst[maxn];
  int main(){
    srand(GRANDOM);
    cin>>n>>m>>s>>t;
    auto u=[&](){
      if(s<=m)s+=t;
      else s-=t;
      s=((s%n)+n)%n;
      t--;
    };
    while(t){
      if(vst[s])t%=vst[s]-t;
      vst[s]=t;
      for(int i=0;i<n&&t;i++)u();
    }
    cout<<s<<endl;
    return 0;
  }
};
int main(int argc,char*argv[]){
  std::cin.sync_with_stdio(false);std::cin.tie(nullptr);
  return vh::main();
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int n,m,s,t;
int pos[maxn];
ll cal(ll x)
{
    if(s<m) s+=t;
    else s-=t;
    t--;
    return (s%n+n)%n;
}
int main()
{
    cin>>n>>m>>s>>t;
    s--;
    while(t%n) s=cal(s);
    int tmp=t/n;
    while(tmp--){
        if(pos[s]) s=pos[s];
        else{
            t=n;
            int temp=s;
            for(int i=1;i<=n;i++) s=cal(s);
            pos[temp]=s;
        }
    }
    cout<<s+1<<endl;
    return 0;
}

//Bartek Kostka
//  You are not prepared!

#include "bits/stdc++.h"

using namespace std;

#define x first
#define y second
#define SZ(x) int(x.size())
#define ll long long
#define pii pair <int, int>
#define vi vector <int>
#define ALL(x) x.begin(), x.end()

#ifdef LOCAL
template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<" = "<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<" = "<<h<<", "; _dbg(sdbg+1, a...);
}
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#define cerr if(false) cout
#endif

#ifdef ONLINE_JUDGE
#define FREOPEN(name) \
  freopen(name".in", "r", stdin); \
  freopen(name".out", "w", stdout);
#else
#define FREOPEN(name)
#endif

int main() {
  ios_base::sync_with_stdio(0);
  int n, m, s, t;
  cin >> n >> m >> s >> t;
  vector <int> vis(n, -1);
  s--;
  int gdzie = 0;
  t++;
  while(t--) {
    if(t % n == 0) {
      if(vis[s] != -1) break;
      vis[s] = ++gdzie;
    }
    if(s < m) s += t;
    else s -= t;
    s = (s%n+n)%n;
   }
   if(t == 0) {
     cout << s+1 << "\n";
     return 0;
   } else {
     gdzie++;
     int la = t / n % (gdzie - vis[s]) + vis[s];
     for(int i=0; i<n; i++) {
       if(vis[i] == la) {
         cout << i+1 << "\n";
         return 0;
       }
    }
  }
}

#define _CRT_SECURE_NO_DEPRECATE
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <memory.h>
#include <set>
#include <ctime>
#include <map>
#include <cstring>
#include <iterator>
#include <queue>
#include <assert.h>
#include <bitset>
#include <complex>
#include <unordered_map>

//#pragma comment(linker, "/STACK:512000000")

using namespace std;

#define pb emplace_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define forab(i, a, b) for (int i = (a); i < (b); ++i)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int infi = 1e9 + 7;
const ll infl = (ll)1e18 + (ll)7;

struct node {
    node* l, *r;
    int sz, a;
    node() {}
    node(int _a) : a(_a), sz(1), l(0), r(0) {}
    node(node* other) : a(other->a), l(other->l), r(other->r), sz(other->sz) {}
};
typedef node* pnode;
const int max_cnt = 5e7;
int cur_cnt;
node buf_node[max_cnt];
pnode new_node(int a) {
   // return new node(a);
    buf_node[cur_cnt] = node(a);
    return &buf_node[cur_cnt++];
}
pnode new_node(pnode a) {
    if (cur_cnt == max_cnt) {
        cout << "123";
        exit(0);
    }
  //  return new node(a);
    buf_node[cur_cnt] = node(a);
    return &buf_node[cur_cnt++];
}
void upd(pnode v) {
    if (!v)
        return;
    v->sz = 1;
    if (v->l)
        v->sz += v->l->sz;
    if (v->r)
        v->sz += v->r->sz;
}
int get_rnd() {
    //return rand();
    return rand() ^ (rand() << 15);
}
pnode merge(pnode l, pnode r) {
    if (!l || !r)
        return max(l, r);
    int q = l->sz, w = r->sz;
    int rang = get_rnd() % (q + w);
    if (rang < q) {
        pnode ans = new_node(l);
        ans->r = merge(l->r, r);
        upd(ans);
        return ans;
    } else {
        pnode ans = new_node(r);
        ans->l = merge(l, r->l);
        upd(ans);
        return ans;
    }
}
int get_size(pnode v) {
    if (v)
        return v->sz;
    return 0;
}
void split(pnode t, pnode& l, pnode& r, int sz) {
    if (!t) {
        l = r = 0;
        return;
    }
    pnode cur = new_node(t);
    int q = get_size(cur->l) + 1;
    if (q <= sz) {
        split(cur->r, cur->r, r, sz - q);
        l = cur;
    } else {
        split(cur->l, l, cur->l, sz);
        r = cur;
    }
    upd(l);
    upd(r);
}
pnode fast_add(pnode t, pnode v, int sz) {
    if (!t) {
        return v;
    }
    int q = t->sz, w = 1;
    int rang = get_rnd() % (q + w);
    if (rang == 0) {
        split(t, v->l, v->r, sz);
        upd(v);
        return v;
    }
    q = get_size(t->l) + 1;
    pnode nt = new_node(t);
    if (q <= sz) {
        nt->r = fast_add(t->r, v, sz - q);
    } else
        nt->l = fast_add(t->l, v, sz);
    upd(nt);
    return nt;
}
pnode add(pnode t, int a, int sz) {
    return fast_add(t, new_node(a), sz);
}

pnode cut(pnode t, int l, int r, int n) {
    if (l < 0 && r < 0)
        l += n, r += n;
    if (l >= n && r >= n)
        l -= n, r -= n;
    pnode L, MID, R;
    if (0 <= l && r < n) {
        split(t, L, R, r + 1);
        split(L, L, MID, l);
        return MID;
    }
    if (r >= n)
        r -= n, l -= n;
    if (l < 0) {
        split(t, L, R, n + l);
        split(L, L, MID, r + 1);
        return merge(R, L);
    }
}

int find(pnode t, int pos) {
    int q = get_size(t->l);
    if (q == pos)
        return t->a;
    if (pos < q)
        return find(t->l, pos);
    else
        return find(t->r, pos - q - 1);
}
pnode ver[100500];

int to[100500];
int used[100500];
int cur_time = 5;
int dfs(int v, int t) {
    while (t) {
        if (!used[v]) {
            used[v] = cur_time++;
            --t;
            v = to[v];
            continue;
        }
        int len = abs(cur_time++ - used[v]);
        if (t > 1e6)
            t %= len;
        if (t == 0)
            break;
        --t;
        v = to[v];
    }
    return v;
}
int get_h(pnode t) {
    if (!t)
        return 0;
    return max(
        get_h(t->l), get_h(t->r)
    ) + 1;
}

int ar[100500];
pnode rebuild(pnode t, int n) {
    forn(i, n)
        ar[i] = find(t, i);
    cur_cnt = 0;
    t = 0;
    forn(i, n)
        t = add(t, ar[i], i);
    return t;
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    //freopen("customs.in", "r", stdin); freopen("customs.out", "w", stdout);
   // srand(time(NULL));
    int n, m;
    cin >> n >> m;
    int s;
    ll t;
    cin >> s >> t;
    --s;
    pnode start = 0;
    forn(i, n) {
        start = add(start, i, i);
       // cerr << int(cur_cnt / 1e6) << '\n';
    }
    ver[0] = start;
    ll t1 = t % n;
    for (int i = 1; i <= t1; ++i) {
        int a = cur_cnt;
        ver[i] = merge(
            cut(ver[i - 1], i, m + i - 1, n),
            cut(ver[i - 1], m - i, n - 1 - i, n)
        );
        /*if (cur_cnt >= 3e7) {
            ver[i] = rebuild(ver[i], n);
        }*/
       // cerr << get_h(ver[i]) << ' ' << cur_cnt - a << '\n';
    }
    int s1 = find(ver[t1], s);
    for (int i = t1 + 1; i <= n; ++i) {
        int a = cur_cnt;
        ver[i] = merge(
            cut(ver[i - 1], i, m + i - 1, n),
            cut(ver[i - 1], m - i, n - 1 - i, n)
        );
       // cerr << cur_cnt - a << '\n';
      /*  if (cur_cnt >= 3e7) {
            ver[i] = rebuild(ver[i], n);
        }*/
       // cerr << get_h(ver[i]) << ' ' << cur_cnt - a << '\n';
    }

    forn(i, n)
        to[i] = find(ver[n], i);
    cout << dfs(s1, t / n)  + 1<< '\n';
  //  cout << cur_cnt << endl;
    cerr << 1.0 * clock() / CLOCKS_PER_SEC;

    return 0;
}

#define _CRT_SECURE_NO_DEPRECATE
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <memory.h>
#include <set>
#include <ctime>
#include <map>
#include <cstring>
#include <iterator>
#include <queue>
#include <assert.h>
#include <bitset>
#include <complex>
#include <unordered_map>

//#pragma comment(linker, "/STACK:512000000")

using namespace std;

#define pb emplace_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define forab(i, a, b) for (int i = (a); i < (b); ++i)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int infi = 1e9 + 7;
const ll infl = (ll)1e18 + (ll)7;

struct node {
    node* l, *r;
    int sz, a;
    node() {}
    node(int _a) : a(_a), sz(1), l(0), r(0) {}
    node(node* other) : a(other->a), l(other->l), r(other->r), sz(other->sz) {}
};
typedef node* pnode;
const int max_cnt = 5e7;
int cur_cnt;
node buf_node[max_cnt];
pnode new_node(int a) {
   // return new node(a);
    buf_node[cur_cnt] = node(a);
    return &buf_node[cur_cnt++];
}
pnode new_node(pnode a) {
    if (cur_cnt == max_cnt) {
        cout << "123";
        exit(0);
    }
  //  return new node(a);
    buf_node[cur_cnt] = node(a);
    return &buf_node[cur_cnt++];
}
void upd(pnode v) {
    if (!v)
        return;
    v->sz = 1;
    if (v->l)
        v->sz += v->l->sz;
    if (v->r)
        v->sz += v->r->sz;
}
int get_rnd() {
    //return rand();
    return rand() ^ (rand() << 15);
}
pnode merge(pnode l, pnode r) {
    if (!l || !r)
        return max(l, r);
    int q = l->sz, w = r->sz;
    int rang = get_rnd() % (q + w);
    if (rang < q) {
        pnode ans = new_node(l);
        ans->r = merge(l->r, r);
        upd(ans);
        return ans;
    } else {
        pnode ans = new_node(r);
        ans->l = merge(l, r->l);
        upd(ans);
        return ans;
    }
}
int get_size(pnode v) {
    if (v)
        return v->sz;
    return 0;
}
void split(pnode t, pnode& l, pnode& r, int sz) {
    if (!t) {
        l = r = 0;
        return;
    }
    pnode cur = new_node(t);
    int q = get_size(cur->l) + 1;
    if (q <= sz) {
        split(cur->r, cur->r, r, sz - q);
        l = cur;
    } else {
        split(cur->l, l, cur->l, sz);
        r = cur;
    }
    upd(l);
    upd(r);
}
pnode fast_add(pnode t, pnode v, int sz) {
    if (!t) {
        return v;
    }
    int q = t->sz, w = 1;
    int rang = get_rnd() % (q + w);
    if (rang == 0) {
        split(t, v->l, v->r, sz);
        upd(v);
        return v;
    }
    q = get_size(t->l) + 1;
    pnode nt = new_node(t);
    if (q <= sz) {
        nt->r = fast_add(t->r, v, sz - q);
    } else
        nt->l = fast_add(t->l, v, sz);
    upd(nt);
    return nt;
}
pnode add(pnode t, int a, int sz) {
    return fast_add(t, new_node(a), sz);
}

pnode cut(pnode t, int l, int r, int n) {
    if (l < 0 && r < 0)
        l += n, r += n;
    if (l >= n && r >= n)
        l -= n, r -= n;
    pnode L, MID, R;
    if (0 <= l && r < n) {
        split(t, L, R, r + 1);
        split(L, L, MID, l);
        return MID;
    }
    if (r >= n)
        r -= n, l -= n;
    if (l < 0) {
        split(t, L, R, n + l);
        split(L, L, MID, r + 1);
        return merge(R, L);
    }
}

int find(pnode t, int pos) {
    int q = get_size(t->l);
    if (q == pos)
        return t->a;
    if (pos < q)
        return find(t->l, pos);
    else
        return find(t->r, pos - q - 1);
}
pnode ver[100500];

int to[100500];
int used[100500];
int cur_time = 5;
int dfs(int v, int t) {
    while (t) {
        if (!used[v]) {
            used[v] = cur_time++;
            --t;
            v = to[v];
            continue;
        }
        int len = abs(cur_time++ - used[v]);
        if (t > 1e6)
            t %= len;
        if (t == 0)
            break;
        --t;
        v = to[v];
    }
    return v;
}
int get_h(pnode t) {
    if (!t)
        return 0;
    return max(
        get_h(t->l), get_h(t->r)
    ) + 1;
}

int ar[100500];
pnode rebuild(pnode t, int n) {
    forn(i, n)
        ar[i] = find(t, i);
    cur_cnt = 0;
    t = 0;
    forn(i, n)
        t = add(t, ar[i], i);
    return t;
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    //freopen("customs.in", "r", stdin); freopen("customs.out", "w", stdout);
   // srand(time(NULL));
    int n, m;
    cin >> n >> m;
    int s;
    ll t;
    cin >> s >> t;
    --s;
    pnode start = 0;
    forn(i, n) {
        start = add(start, i, i);
       // cerr << int(cur_cnt / 1e6) << '\n';
    }
    ver[0] = start;
    ll t1 = t % n;
    for (int i = 1; i <= t1; ++i) {
        int a = cur_cnt;
        ver[i] = merge(
            cut(ver[i - 1], i, m + i - 1, n),
            cut(ver[i - 1], m - i, n - 1 - i, n)
        );
        /*if (cur_cnt >= 3e7) {
            ver[i] = rebuild(ver[i], n);
        }*/
       // cerr << get_h(ver[i]) << ' ' << cur_cnt - a << '\n';
    }
    int s1 = find(ver[t1], s);
    for (int i = t1 + 1; i <= n; ++i) {
        int a = cur_cnt;
        ver[i] = merge(
            cut(ver[i - 1], i, m + i - 1, n),
            cut(ver[i - 1], m - i, n - 1 - i, n)
        );
       // cerr << cur_cnt - a << '\n';
      /*  if (cur_cnt >= 3e7) {
            ver[i] = rebuild(ver[i], n);
        }*/
       // cerr << get_h(ver[i]) << ' ' << cur_cnt - a << '\n';
    }

    forn(i, n)
        to[i] = find(ver[n], i);
    cout << dfs(s1, t / n)  + 1<< '\n';
    cout << cur_cnt << endl;
    cerr << 1.0 * clock() / CLOCKS_PER_SEC;

    return 0;
}

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

const int N = 1e5;
const int M = 5e6;

int n, m, S, T;
int ch[M][2], siz[M], idx[M], tot;
int lst[N], to[N], cnt, dis, cir, rt;

void copy(int a, int b)
{
    ch[b][0] = ch[a][0];
    ch[b][1] = ch[a][1];
    idx[b] = idx[a];
    siz[b] = siz[a];
}
int upd(int t)
{
    siz[t] = siz[ch[t][0]] + siz[ch[t][1]] + 1; return t;
}
int merge(int a, int b)
{
    if (!a || !b) return a | b;
    int c = ++ tot;
    if (1ll * (siz[a] + siz[b]) * rand() < 1ll * siz[a] * RAND_MAX)
        return copy(a, c), ch[c][1] = merge(ch[a][1], b), upd(c);
    else
        return copy(b, c), ch[c][0] = merge(a, ch[b][0]), upd(c);
}
pair <int, int> split(int t, int k)
{
    if (k == 0) return make_pair(0, t);
    if (k == siz[t]) return make_pair(t, 0);
    int c = ++ tot; copy(t, c);
    if (k <= siz[ch[t][0]])
    {
        auto p = split(ch[t][0], k);
        return ch[c][0] = p.second, p.second = upd(c), p;
    }
    else
    {
        auto p = split(ch[t][1], k - siz[ch[t][0]] - 1);
        return ch[c][1] = p.first, p.first = upd(c), p;
    }
}
int build(int l, int r)
{
    int c = ++ tot;
    int d = (l + r) / 2;
    idx[c] = d;
    if (l < d) ch[c][0] = build(l, d - 1);
    if (d < r) ch[c][1] = build(d + 1, r);
    return upd(c);
}
int get(int l, int r)
{
    if (l < 1) return merge(get(n + l, n), get(1, r));
    if (r > n) return merge(get(l, n), get(1, r - n));
    return split(split(rt, l - 1).second, r - l + 1).first;
}
void dfs(int t)
{
    if (ch[t][0]) dfs(ch[t][0]);
    to[++ cnt] = idx[t];
    if (ch[t][1]) dfs(ch[t][1]);
}
int main()
{
    // freopen("in", "r", stdin);
    cin >> n >> m >> S >> T;
    rt = build(1, n);
    for (int i = 1; i < n; ++ i)
        rt = merge(get(i + 1, i + m), get(m + 1 - i, n - i));
    dfs(rt);
    while (T % n)
    {
        if (S <= m) S += T % n;
        else S -= T % n;
        if (S < 1) S += n;
        if (S > n) S -= n;
        T --;
    }
    {
        int num = 1, x = to[S], y = to[to[S]];
        while (x != y) num ++, x = to[x], y = to[to[y]];
        dis = num;
        num = 1, x = to[x], y = to[to[y]];
        while (x != y) num ++, x = to[x], y = to[to[y]];
        dis -= num; cir = num;
    }
    T /= n;
    while (T && dis) S = to[S], T --, dis --;
    T %= cir;
    while (T) S = to[S], T --, dis --;
    cout << S << endl;
}

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

int main()
{
  int m, n, s;
  long long t;
  cin >> n >> m >> s >> t;
  s--;

  while (t % n)
  {
    if (s < m) s = (s + t % n) % n;
    else s = (s - t % n + n) % n;
    t--;
  }
  t /= n;

  map<int, long long> seen;
  seen[s] = t;
  vector<int> stations(1, s);
  long long initialT = t;
  while (t)
  {
    for (int i = n; i; i--)
      if (s < m) s = (s + i) % n;
      else s = (s + n - i) % n;
    t--;
    if (seen.count(s))
    {
      long long cycle = seen[s] - t;
      cout << stations[initialT - seen[s] + t % cycle] + 1 << endl;
      return 0;
    }
    seen[s] = t;
  }

  cout << s + 1 << endl;
}

#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<iostream>
using namespace std;
typedef long long ll;
const int MAXN = 100000;
struct treap{
	struct node{
		int key, siz;
		node *ch[2];
	}pl[30*MAXN + 5], *ncnt, *NIL;
	typedef pair<node*, node*> Droot;
	treap() {
		NIL = &pl[0];
		NIL->ch[0] = NIL->ch[1] = NIL;
		NIL->key = NIL->siz = 0;
	}
	void trans(int *f, node *x, int k) {
		if( x == NIL ) return ;
		f[x->ch[0]->siz + k + 1] = x->key;
		trans(f, x->ch[0], k);
		trans(f, x->ch[1], x->ch[0]->siz + k + 1);
	}
	void pushup(node *x) {
		x->siz = x->ch[0]->siz + x->ch[1]->siz + 1;
	}
	node *build(int *f, int l, int r) {
		if( l > r ) return NIL;
		int mid = (l + r) >> 1;
		node *p = (++ncnt); p->key = f[mid];
		p->ch[0] = build(f, l, mid - 1);
		p->ch[1] = build(f, mid + 1, r);
		pushup(p);
		return p;
	}
	node *build(int *f, int n) {
		ncnt = &pl[0];
		return build(f, 1, n);
	}
	Droot split(node *x, int k) {
		if( x == NIL ) return make_pair(NIL, NIL);
		node *p = (++ncnt); (*p) = (*x);
		if( x->ch[0]->siz >= k ) {
			Droot q = split(x->ch[0], k);
			p->ch[0] = q.second; pushup(p);
			return make_pair(q.first, p);
		}
		else {
			Droot q = split(x->ch[1], k - x->ch[0]->siz - 1);
			p->ch[1] = q.first; pushup(p);
			return make_pair(p, q.second);
		}
	}//first k elements
	node *merge(node *x, node *y) {
		if( x == NIL ) return y;
		if( y == NIL ) return x;
		node *p = (++ncnt);
		if( rand() & 1 ) {
			(*p) = (*x), p->ch[1] = merge(x->ch[1], y);
			pushup(p);
		}
		else {
			(*p) = (*y), p->ch[0] = merge(x, y->ch[0]);
			pushup(p);
		}
		return p;
	}
}T;
treap::node *root;
int f[MAXN + 5];
int nxt[45][MAXN + 5];
int main() {
	int n, m, s; ll t;
	scanf("%d%d%d%lld", &n, &m, &s, &t);
	srand(20041112 ^ n ^ m ^ s);
	for(int i=1;i<=n;i++) f[i] = i;
	root = T.build(f, n);
	for(int i=1;i<=n;i++) {
//		printf("%d\n", i);
		if( i % 300 == 0 )
			T.trans(f, root, 0), root = T.build(f, n);
		treap::node *p, *q;
		treap::node *tmp = T.split(root, i).second;
		if( tmp->siz >= m )
			p = T.split(tmp, m).first;
		else p = T.merge(tmp, T.split(root, m-tmp->siz).first);
		tmp = T.split(root, n - i).first;
		if( tmp->siz >= n-m )
			q = T.split(tmp, tmp->siz-(n-m)).second;
		else q = T.merge(T.split(root, n-((n-m)-tmp->siz)).second, tmp);
		root = T.merge(p, q);
	}
	T.trans(f, root, 0);
	while( t % n ) {
		if( s <= m ) s = (s - 1 + t) % n + 1;
		else s = ((s - 1 - t) % n + n) % n + 1;
		t--;
	}
	for(int i=1;i<=n;i++) nxt[0][i] = f[i];
	for(int j=1;j<45;j++)
		for(int i=1;i<=n;i++)
			nxt[j][i] = nxt[j-1][nxt[j-1][i]];
	int x = t/n;
	for(int i=44;i>=0;i--)
		if( (1LL<<i) <= x ) x -= (1LL<<i), s = nxt[i][s];
	printf("%d\n", s);
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
int vis[123456];
main()
{
	int n,m,s,t;
	scanf("%lld %lld %lld %lld",&n,&m,&s,&t);
	m--;
	s--;
	int x = t%n;
	for(int i = x;i>0;i--)
	{
		if(s<=m) s+=i;
		else s-=i;
		s = s%n + n;
		s %= n;
	}
	int cur = 0;
	int ans = 0;
	int pos = s;
	int ppp;
	while(true)
	{
		if(vis[s]!=0)
		{
			ans = cur - vis[s];
			ppp = s;
			break;
		}
		vis[s] = cur++;
		for(int i = n;i>0;i--)
		{
			if(s<=m) s+=i;
			else s-=i;
			s = s%n + n;
			s %= n;
		}
	}
	t /= n;
	if(!t){}
	else if(t<=ppp)
	{
		for(int i = 0;i<n;i++)
		{
			if(vis[i]==t) pos = i;
		}
	}
	else
	{
		t-= ppp;
		t%= ans;
		for(int i = 0;i<n;i++)
		{
			if(vis[i]==t+ppp) pos = i;
		}
	}
	printf("%lld\n",pos+1);

	return 0;
}

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

const int mxN=1e5;
int n, m, s, dp, nxt[mxN][40], ni, b[mxN];
long long t;
mt19937 mg(chrono::steady_clock::now().time_since_epoch().count());

template<size_t S>
struct treap {
	int n=1, lc[S+1], rc[S+1], a[S+1], s[S+1];
	int cmb(int u) {
		s[u]=s[lc[u]]+1+s[rc[u]];
		return u;
	}
	int cpy(int u) {
		a[n]=a[u];
		lc[n]=lc[u];
		rc[n]=rc[u];
		return n++;
	}
	int mrg(int u, int v) {
		if(!u||!v)
			return u^v;
		if(mg()%(s[u]+s[v])<s[u]) {
			u=cpy(u);
			rc[u]=mrg(rc[u], v);
			return cmb(u);
		} else {
			v=cpy(v);
			lc[v]=mrg(u, lc[v]);
			return cmb(v);
		}
	}
	array<int, 2> spl(int u, int k) {
		if(!u)
			return {};
		u=cpy(u);
		if(k>s[lc[u]]) {
			array<int, 2> a=spl(rc[u], k-s[lc[u]]-1);
			rc[u]=a[0];
			return {cmb(u), a[1]};
		} else {
			array<int, 2> a=spl(lc[u], k);
			lc[u]=a[1];
			return {a[0], cmb(u)};
		}
	}
	void dfs(int u) {
		if(!u)
			return;
		dfs(lc[u]);
		nxt[ni++][0]=a[u];
		dfs(rc[u]);
	}
};
treap<40000000> tr;

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

	cin >> n >> m >> s >> t, --s;
	for(int i=0; i<n; ++i) {
		tr.a[tr.n]=i;
		tr.s[tr.n]=1;
		b[i]=tr.n++;
	}
	for(int i=1; i<n; i*=2)
		for(int j=0; j+i<n; j+=2*i)
			b[j]=tr.mrg(b[j], b[j+i]);
	dp=b[0];
	for(int i=1; i<n; ++i) {
		array<int, 2> a=tr.spl(dp, i);
		int dp1, dp2;
		if(n-i<m) {
			array<int, 2> b=tr.spl(a[0], m-n+i);
			dp1=tr.mrg(a[1], b[0]);
		} else
			dp1=tr.spl(a[1], m)[0];
		a=tr.spl(dp, n-i);
		if(i>m) {
			array<int, 2> b=tr.spl(a[1], m);
			dp2=tr.mrg(b[1], a[0]);
		} else
			dp2=tr.spl(a[0], m-i)[1];
		dp=tr.mrg(dp1, dp2);
	}
	tr.dfs(dp);
	while(t%n) {
		if(s<m)
			s=(s+t)%n;
		else
			s=(s-t%n+n)%n;
		--t;
	}
	t/=n;
	for(int i=1; i<40; ++i)
		for(int j=0; j<n; ++j)
			nxt[j][i]=nxt[nxt[j][i-1]][i-1];
	for(int i=39; i>=0; --i) {
		if(t>=1ll<<i) {
			t-=1ll<<i;
			s=nxt[s][i];
		}
	}
	cout << s+1;
}

#include <cstdio>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstring>

using namespace std;

#define pb push_back
#define all(X) X.begin(), X.end()
#define ll long long

int nextt[100001];

void go(int& s, ll& t, int m, int n) {
  int is = s;
  ll it = t;
  while(t > 0) {
    if (s >= m) s = (s - (t % n) + n) % n;
    else s = (s + (t % n)) % n;
    t--;
    if ((t % n == 0) && (s == m - 1 || s == m)) break;
    if (s == is && (t % n) == (it % n)) break;
  }
}

int main()
{
#ifdef DEBUG
  freopen("g.in", "r", stdin);
  freopen("g.out", "w", stdout);
#endif
  int n, m;
  int s;
  ll t;
  scanf("%d %d", &n, &m);
  scanf("%d %lld", &s, &t);

  s--;
  int is = s;
  ll it = t;
  go(s, t, m, n);
  if (s == is) {
    t = t % (it - t);
    go(s, t, m, n);
  }
  if (t == 0) {
    printf("%d\n", s + 1);
    return 0;
  }
  memset(nextt, -1, sizeof(nextt));
  ll k1, k2;
  for (k1 = 1; k1 < n; k1++) {
    ll t = m - 1 + k1 * (k1 + 1) / 2;
    t %= n;
    if (t < m) {
      k1 = t;
      break;
    }
  }
  if (k1 == n) {
    k1 = (m + ((ll) n - 1) * n / 2) % n;
    nextt[k1] = m;
    nextt[m] = k1;
  }
  for (k2 = 1; k2 < n; k2++) {
    ll t = m + 1 + k2 * (k2 + 1) / 2;
    t %= n;
    if (t < m) {
      k2 = t;
      break;
    }
  }
  if (k2 == n) {
    k2 = (m + 1 + ((ll) n - 1) * n / 2) % n;
    nextt[k2] = m + 1;
    nextt[m + 1] = k2;
  }

  while(t > 0) {
    if (nextt[s] != -1) s = nextt[s];
    else if (s == m) s = ((k1 - m) % 2 == 0) ? m : m + 1;
    else if (s == m + 1) s = ((k2 - m) % 2 == 0) ? m : m + 1;
    else printf("Not working!\n");
    t -= n;
  }
  printf("%d\n", s + 1);

  return 0;
}

#pragma GCC optimize("O3")
#ifdef ONLINE_JUDGE
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#include <deque>
#include <type_traits>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
template<typename Key=int,typename Mapped=__gnu_pbds::null_type,typename Cmp_Fn=std::less<Key>,typename Tag=__gnu_pbds::rb_tree_tag,template<typename Const_Node_Iterator,typename Node_Iterator,typename Cmp_Fn_,typename Allocator_>class Node_Update=__gnu_pbds::tree_order_statistics_node_update,typename Allocator=std::allocator<char>>class ordered_set_t:__gnu_pbds::tree<Key,Mapped,Cmp_Fn,Tag,Node_Update,Allocator>{};const int GRANDOM=std::chrono::high_resolution_clock::now().time_since_epoch().count();struct ghash{int operator()(int x){return std::hash<int>{}(x^GRANDOM);}};template<typename KeyType>class hash_table_t:__gnu_pbds::gp_hash_table<KeyType,int,ghash>{};namespace vh{template<class T>void _R(T&x){std::cin>>x;}inline void _R(int&x){scanf("%d",&x);}inline void _R(int64_t&x){scanf("%" SCNd64,&x);}inline void _R(double&x){scanf("%lf",&x);}inline void _R(char&x){scanf(" %c",&x);}inline void _R(char*x){scanf("%s",x);}inline void R(){}template<class T,class... U>inline void R(T&head,U&... tail){_R(head);R(tail...);}template<class T>void _W(const T&x){cout<<x;}inline void _W(const int&x){printf("%d",x);}inline void _W(const int64_t&x){printf("%" PRId64,x);}inline void _W(const double&x){printf("%.16f",x);}inline void _W(const char&x){putchar(x);}inline void _W(const char*x){printf("%s",x);}template<class T>inline void _W(const vector<T>&x){for(auto i=x.begin();i!=x.end();_W(*i++))if(i!=x.cbegin())putchar(' ');}inline void W(){}template<class T,class... U>inline void W(const T&head,const U&... tail){_W(head);if(sizeof...(tail))putchar(' '),W(tail...);}template<class T,class... U>inline void WL(const T&head,const U&... tail){_W(head);putchar(sizeof...(tail)? ' ':'\n');W(tail...);}};
#define prec setprecision
namespace vh{typedef long long ll;typedef unsigned long long llu;template<typename T>T gcd(T m,T n){while(n){T t=m%n;m=n;n=t;};return m;}template<typename T>T exgcd(T a,T b,T&sa,T&ta){T q,r,sb=0,tb=1,sc,tc;sa=1,ta=0;if(b)do q=a/b,r=a-q*b,a=b,b=r,sc=sa-q*sb,sa=sb,sb=sc,tc=ta-q*tb,ta=tb,tb=tc;while(b);return a;}template<typename T>T mul_inv(T a,T b){T t1=a,t2=b,t3;T v1=1,v2=0,v3;T x;while(t2!=1)x=t1/t2,t3=t1-x*t2,v3=v1-x*v2,t1=t2,t2=t3,v1=v2,v2=v3;return(v2+b)%b;}template<typename T>T powmod(T a,T b,T MOD){if(b<0)return 0;T rv=1;while(b)(b%2)&&(rv=(rv*a)%MOD),a=a*a%MOD,b/=2;return rv;}template<typename T>inline T isqrt(T k){T r=sqrt((double)k)+1;while(r*r>k)r--;return r;}template<typename T>inline T icbrt(T k){T r=cbrt((double)k)+1;while(r*r*r>k)r--;return r;}template<typename T>bool mul_overflow(T&r,T a,T b){return __builtin_mul_overflow(a,b,&r);}template<ll n>struct BitSize{enum{Size=BitSize<n/2>::Size+1};};template<>struct BitSize<0>{enum{Size=1};};template<>struct BitSize<1>{enum{Size=1};};
#define BITSIZE(n) (BitSize<n>::Size)
#define BITMAX(n) (BitSize<n>::Size - 1)
#define DEBUG !defined(ONLINE_JUDGE)
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define RALL(x) (x).rbegin(),(x).rend()
template<typename TH>void _dbg(const char*sdbg,TH h){cerr<<sdbg<<"="<<h<<"\n";}template<typename TH,typename... TA>void _dbg(const char*sdbg,TH h,TA... t){while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<",";_dbg(sdbg+1,t...);}
#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; for(auto itt: x) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
}namespace vh{template<typename T>int min_rotation(vector<T>s){int a=0,N=s.size();for(int b=0;b<N;b++)for(int i=0;i<N;i++){if(a+i==b||s[(a+i)%N]<s[(b+i)%N]){b+=max(0,i-1);break;}if(s[(a+i)%N]>s[(b+i)%N]){a=b;break;}}return a;}}namespace vh{};
namespace vh{
  const int maxn=1e5+7;
  int n,m;
  ll s,t;
  int vst[maxn];
  int main(){
    srand(GRANDOM);
    cin>>n>>m>>s>>t;
    auto u=[&](){
      if(s<=m)s+=t;
      else s-=t;
      s=((s%n)+n)%n;
      t--;
    };
    while(t>0){
      if(vst[s])t%=vst[s]-t;
      else vst[s]=t;
      u();
    }
    cout<<s<<endl;
    return 0;
  }
};
int main(int argc,char*argv[]){
  std::cin.sync_with_stdio(false);std::cin.tie(nullptr);
  return vh::main();
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define ld long double
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
int n,m,s,flag;
ll t,last;
set<int> S;
int go(int s,ll a,ll b){
	for(;a!=b;a--){
		s=s<m?(s+a)%n:(s+n-a%n)%n;
	}
	return s;
}
int main(){
	n=read(); m=read();
	s=read()-1; t=read();
	last=t/n*n;
	s=go(s,t,last); t=last;
	while(t){
		s=go(s,t,t-n); t-=n;
		if(flag==0&&S.count(s)){
			t=(t/n)%S.size()*n; flag=1;
		}else if(!flag)S.insert(s);
	}
	cout<<s+1<<endl;
}

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

ll readint(){
	ll x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

ll n,m,s,t;
ll g[100005];
map<ll,int> d[100005];

int ask(ll x){
	if(g[x]!=-1) return g[x];
	ll tmp=x;
	for(int i=n-1;i>=0;i--){
		if(x<=m) x=(x+i)%n;
		else x=(x-i+n)%n;
	}
	return g[tmp]=x;
}

int work(ll x,ll k){
	if(k==0) return x;
	if(k==1) return ask(x);
	if(d[x].count(k)) return d[x][k];
	return work(work(x,k/2),k-k/2);
}

int main(){
	n=readint(); m=readint(); s=readint(); t=readint();
	while(t%n!=0){
		if(s<=m) s=(s+t%n)%n;
		else s=(s-t%n+n)%n;
		t--;
	}
	memset(g,-1,sizeof(g));
	printf("%d\n",work(s,t/n));
	return 0;
}

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

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

	cin >> N >> M;
	long long int ans;
	cin >> ans >> K;
	vector<long long int>used(N, -1);
	ans--;
	while (K > 0 && K%N != N - 1) {
		if (ans < M)ans += K % N;
		else ans -= K % N;
		ans += N;
		ans %= N;
		K--;
	}
	if (!K) {
		cout << ans + 1 << endl;
		return 0;
	}
	while (K > 0) {
		if (ans < M)ans += K % N;
		else ans -= K % N;
		ans += N;
		ans %= N;
		if (K%N == 0) {
		//	cout << K << " " << ans << endl;
			if (used[ans] == -1)used[ans] = K / N;
			else {
				long long int box = used[ans] - K / N;
				for (int i = 0; i < N; i++) {
					if (used[i] != -1 && used[i] % box == 0) {
						cout << i + 1 << endl;
						return 0;
					}
				}
			}
		}
		K--;
		//	cout << K << endl;
	}
	cout << ans + 1 << endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+10;
ll A[N];
ll n,m,s,t;
void F(){
    if(s<m)s=(s+t)%n;
    else s=(s+n-t%n)%n;
    --t;
}
int main(){
    cin>>n>>m>>s>>t;
    --s;
    while(1){
        if(A[s])t=t%(A[s]-t);
        if(t<=1e6){
            while(t)F();
            cout<<s+1<<endl;
            return 0;
        }
        A[s]=t;
        F();
    }
}

#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int n,m,s,vis[100005],cy;
long long t;
int nex(int x,int y)
{
	if(x<m)
		return (x+y)%n;
	else
		return (x-y+n)%n;
}
int main()
{
	scanf("%d %d",&n,&m);
	scanf("%d %lld",&s,&t);
	--s;
	while(t%n!=0)
	{
		s=nex(s,t%n);
		--t;
	}
	t/=n;
	while(t&&(!vis[s]))
	{
		vis[s]=1;
		++cy;
		for(int y=n-1;y>0;--y)
			s=nex(s,y);
		--t;
	}
	if(!t)
	{
		cout<<s+1;
		return 0;
	}
	t%=cy;
	while(t)
	{
		for(int y=n-1;y>0;--y)
			s=nex(s,y);
		--t;
	}
	cout<<s+1;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,s,t,res;
int boo[100100],ans[100100];
ll run(ll s,ll t){
	for(;t;t--) if(s&&s<=m) s=(s+t)%n;else s=(s-t%n+n)%n;
	return s;
}

int main(){
	scanf("%lld%lld%lld%lld",&n,&m,&s,&t);
	//printf("%lld\n",run(s,t));
	s=run(s,t%n); t/=n;
	for(int i=1;i<=t;i++){
		boo[s]=i;ans[i]=s;
		ll nex=run(s,n);
		if(boo[nex]) {res=ans[t%i+1];break;}
		s=nex;
	}
	if(!res) res=s;
	printf("%lld\n",res);
}

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#define maxn 100005
#define ll long long
#define pi pair<int, int>
using namespace std;
map<pi, ll> x;
int n, m;
ll t;
int main()
{
	scanf("%d%d", &n, &m);
	int s;
	scanf("%d%lld", &s, &t);
	while(t)
	{
		if(s > m) s -= t;
		else s += t;
		s %= n;
		while(s > n) s -= n;
		while(s < 0) s += n;
		t--;
		pi ns = pi(s, t % n);
		if(x[ns])
			t %= (x[ns] - t);
		else
			x[ns] = t;
	}
	printf("%d\n", s);
	return 0;
}

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

const int mxN=1e5;
int n, m, s, dp, nxt[mxN][40], ni, b[mxN];
long long t;
mt19937 mg(chrono::steady_clock::now().time_since_epoch().count());

template<size_t S>
struct treap {
	int n=1, lc[S+1], rc[S+1], a[S+1], s[S+1];
	int cmb(int u) {
		s[u]=s[lc[u]]+1+s[rc[u]];
		return u;
	}
	int cpy(int u) {
		a[n]=a[u];
		lc[n]=lc[u];
		rc[n]=rc[u];
		return n++;
	}
	int mrg(int u, int v, bool b=0) {
		if(!u||!v)
			return u^v;
		if(mg()%(s[u]+s[v])<s[u]) {
			if(!b)
				u=cpy(u);
			rc[u]=mrg(rc[u], v);
			return cmb(u);
		} else {
			if(!b)
				v=cpy(v);
			lc[v]=mrg(u, lc[v]);
			return cmb(v);
		}
	}
	array<int, 2> spl(int u, int k) {
		if(!u)
			return {};
		u=cpy(u);
		if(k>s[lc[u]]) {
			array<int, 2> a=spl(rc[u], k-s[lc[u]]-1);
			rc[u]=a[0];
			return {cmb(u), a[1]};
		} else {
			array<int, 2> a=spl(lc[u], k);
			lc[u]=a[1];
			return {a[0], cmb(u)};
		}
	}
	void dfs(int u) {
		if(!u)
			return;
		dfs(lc[u]);
		nxt[ni++][0]=a[u];
		dfs(rc[u]);
	}
};
treap<40000000> tr;

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

	cin >> n >> m >> s >> t, --s;
	for(int i=0; i<n; ++i) {
		tr.a[tr.n]=i;
		tr.s[tr.n]=1;
		b[i]=tr.n++;
	}
	for(int i=1; i<n; i*=2)
		for(int j=0; j+i<n; j+=2*i)
			b[j]=tr.mrg(b[j], b[j+i], 1);
	dp=b[0];
	for(int i=1; i<n; ++i) {
		array<int, 2> a=tr.spl(dp, i);
		int dp1, dp2;
		if(n-i<m) {
			array<int, 2> b=tr.spl(a[0], m-n+i);
			dp1=tr.mrg(a[1], b[0]);
		} else
			dp1=tr.spl(a[1], m)[0];
		a=tr.spl(dp, n-i);
		if(i>m) {
			array<int, 2> b=tr.spl(a[1], m);
			dp2=tr.mrg(b[1], a[0]);
		} else
			dp2=tr.spl(a[0], m-i)[1];
		dp=tr.mrg(dp1, dp2);
	}
	tr.dfs(dp);
	while(t%n) {
		if(s<m)
			s=(s+t)%n;
		else
			s=(s-t%n+n)%n;
		--t;
	}
	t/=n;
	for(int i=1; i<40; ++i)
		for(int j=0; j<n; ++j)
			nxt[j][i]=nxt[nxt[j][i-1]][i-1];
	for(int i=39; i>=0; --i) {
		if(t>=1ll<<i) {
			t-=1ll<<i;
			s=nxt[s][i];
		}
	}
	cout << s+1;
}

/*
    Author: isaf27 (Ivan Safonov)
*/

#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

//defines
typedef long long ll;
typedef long double ld;
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define what_is(x) cerr << #x << " is " << x << endl
#define solve_system int number; cin >> number; for (int i = 0; i < number; i++) solve()
#define solve_system_scanf int number; scanf("%d", &number); for (int i = 0; i < number; i++) solve()

//permanent constants
const ld pi = acos(-1.0);
const ld log23 = 1.58496250072115618145373894394781;
const ld eps = 1e-8;
const ll INF = 1e13 + 239;
const ll prost = 239;
const int two = 2;
const int th = 3;
const ll MOD = 1e9 + 7; //998244353;
const ll MOD2 = MOD * MOD;
const int BIG = 1e9 + 239;
const int alf = 26;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dxb[4] = {-1, 1, 1, -1};
const int dyb[4] = {-1, 1, -1, 1};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int dig = 10;
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const ll bt = 30;

//easy functions
template< typename T >
inline T gcd(T a, T b)
{
    while (a)
    {
        b %= a;
        swap(a, b);
    }
    return b;
}
template< typename T >
inline T lcm(T a, T b) { return (a / gcd(a, b)) * b; }
inline bool is_down(char x) { return ('a' <= x && x <= 'z'); }
inline bool is_upper(char x) { return ('A' <= x && x <= 'Z'); }
inline bool is_digit(char x) { return ('0' <= x && x <= '9'); }

//random
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
//mt19937_64 rnd(239);

//constants
const int M = 1e5 + 239;
const int N = 110;
const int L = 19;
const int T = (1 << 19);
const int B = trunc(sqrt(M)) + 1;
const int X = 1010;

int n, m;
int s;
ll t;

int func(int s)
{
    for (int x = n; x >= 1; x--)
    {
        if (s < m) s = ((s + x) % n);
        else s = ((s - x) % n);
        if (s < 0) s += n;
    }
    return s;
}

int main()
{
    #ifdef ONPC
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m >> s >> t;
    s--;
    while (t % (ll)n != 0)
    {
        if (s < m) s = (((ll)s + t) % (ll)n);
        else s = (((ll)s - t) % (ll)n);
        if (s < 0) s += n;
        t--;
    }
    t /= (ll)n;
    if (t == 0)
    {
        cout << (s + 1);
        return 0;
    }
    s = func(s);
    t--;
    t %= 2LL;
    for (int i = 0; i < t; i++)
        s = func(s);
    cout << (s + 1);
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m,s,t;
ll cal(ll x)
{
    if(s<=m) s+=t;
    else s-=t;
    t--;
    return (s%n+n)%n;
}
int main()
{
    cin>>n>>m>>s>>t;
    s--;
    while(t%n) s=cal(s);
    cout<<s+1<<endl;
    return 0;
}

#include <cstdio>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstring>

using namespace std;

#define pb push_back
#define all(X) X.begin(), X.end()
#define ll long long

int nextt[100001];

void go(int& s, ll& t, int m, int n) {
  int is = s;
  while(t > 0) {
    if (s >= m) s = (s - (t % n) + n) % n;
    else s = (s + (t % n)) % n;
    t--;
    if (s == is) break;
  }
}

int main()
{
#ifdef DEBUG
  freopen("g.in", "r", stdin);
  freopen("g.out", "w", stdout);
#endif
  int n, m;
  int s;
  ll t;
  scanf("%d %d", &n, &m);
  scanf("%d %lld", &s, &t);

  s--;
  int is = s;
  ll it = t;
  go(s, t, m, n);
  if (s == is) {
    t = t % (it - t);
    go(s, t, m, n);
  }
  if (t == 0) {
    printf("%d\n", s + 1);
    return 0;
  }
  memset(nextt, -1, sizeof(nextt));
  ll k1, k2;
  for (k1 = 1; k1 < n; k1++) {
    ll t = m + k1 * (k1 + 1) / 2;
    t %= n;
    if (t < m) {
      k1 = t;
      break;
    }
  }
  if (k1 == n) {
    k1 = (m + ((ll) n - 1) * n / 2) % n;
    nextt[k1] = m;
    nextt[m] = k1;
  }
  for (k2 = 1; k2 < n; k2++) {
    ll t = m + 1 + k2 * (k2 + 1) / 2;
    t %= n;
    if (t < m) {
      k2 = t;
      break;
    }
  }
  if (k2 == n) {
    k2 = (m + 1 + ((ll) n - 1) * n / 2) % n;
    nextt[k2] = m + 1;
    nextt[m + 1] = k2;
  }

  while(t > 0) {
    if (nextt[s] != -1) s = nextt[s];
    else if (s == m) s = ((k1 - m) % 2 == 0) ? m : m + 1;
    else if (s == m + 1) s = ((k2 - m) % 2 == 0) ? m : m + 1;
    else printf("Not working!\n");
    t -= n;
  }
  printf("%d\n", s + 1);

  return 0;
}

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#define maxn 100005
#define ll long long
#define pi pair<int, int>
using namespace std;
map<pi, ll> x;
int n, m;
ll t;
int main()
{
	scanf("%d%d", &n, &m);
	int s;
	scanf("%d%lld", &s, &t);
	while(t)
	{
		if(s > m) s -= t % n;
		else s += t % n;
		while(s > n) s -= n;
		while(s < 0) s += n;
		t--;
		pi ns = pi(s, t % n);
		if(x[ns])
			t %= (x[ns] - t);
		else
			x[ns] = t;
	}
	printf("%d\n", s);
	return 0;
}

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

#define ar array

const int mxN=1e5, mxATS=5e7;
int n, m, s, dp, nxt[mxN][40], ni;
long long t;

struct avltree {
	int a[mxATS], lc[mxATS], rc[mxATS], s[mxATS], h[mxATS], ts=1;
	int cpy(int u) {
		a[ts]=a[u];
		lc[ts]=lc[u];
		rc[ts]=rc[u];
		s[ts]=s[u];
		h[ts]=h[u];
		return ts++;
	}
	void rcl(int u) {
		s[u]=s[lc[u]]+1+s[rc[u]];
		h[u]=max(h[lc[u]], h[rc[u]])+1;
	}
	void dfs(int u) {
		if(!u)
			return;
		dfs(lc[u]);
		nxt[ni++][0]=a[u];
		dfs(rc[u]);
	}
	bool hl(int u) {
		return h[lc[u]]-h[rc[u]]>1;
	}
	bool hr(int u) {
		return h[rc[u]]-h[lc[u]]>1;
	}
	int rr(int u) {
		int v=lc[u];
		lc[u]=rc[v];
		rc[v]=u;
		rcl(u);
		rcl(v);
		return v;
	}
	int rl(int u) {
		int v=rc[u];
		rc[u]=lc[v];
		lc[v]=u;
		rcl(u);
		rcl(v);
		return v;
	}
	int rbl(int u) {
		if(hl(u)) {
			u=cpy(u);
			lc[u]=cpy(lc[u]);
			if(h[rc[lc[u]]]>h[lc[lc[u]]]) {
				rc[lc[u]]=cpy(rc[lc[u]]);
				lc[u]=rl(lc[u]);
			}
			u=rr(u);
		} else if(hr(u)) {
			u=cpy(u);
			rc[u]=cpy(rc[u]);
			if(h[lc[rc[u]]]>h[rc[rc[u]]]) {
				lc[rc[u]]=cpy(lc[rc[u]]);
				rc[u]=rr(rc[u]);
			}
			u=rl(u);
		}
		return u;
	}
	int rbl2(int u) {
		bool b1=hl(u), b2=hr(u);
		if(!b1&&!b2)
			return u;
		u=rbl(u);
		if(b1) {
			if(h[rc[u]]<h[lc[u]]) {
				lc[u]=cpy(lc[u]);
				u=rr(u);
			}
			rc[u]=rbl2(rc[u]);
		} else {
			if(h[lc[u]]<h[rc[u]]) {
				rc[u]=cpy(rc[u]);
				u=rl(u);
			}
			lc[u]=rbl2(lc[u]);
		}
		rcl(u);
		return u;
	}
	int mrg(int u, int v) {
		if(!u||!v)
			return u^v;
		int w;
		if(h[u]>h[v]) {
			w=cpy(u);
			rc[w]=mrg(rc[w], v);
		} else {
			w=cpy(v);
			lc[w]=mrg(u, lc[w]);
		}
		rcl(w);
		return rbl(w);
	}
	ar<int, 2> spl(int u, int k) {
		if(!u)
			return {0, 0};
		u=cpy(u);
		if(k<=s[lc[u]]) {
			ar<int, 2> a=spl(lc[u], k);
			lc[u]=a[1];
			u=rbl2(u);
			rcl(u);
			return {a[0], u};
		} else {
			ar<int, 2> a=spl(rc[u], k-s[lc[u]]-1);
			rc[u]=a[0];
			u=rbl2(u);
			rcl(u);
			return {u, a[1]};
		}
	}
} at;

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

	cin >> n >> m >> s >> t, --s;
	for(int i=0; i<n; ++i) {
		at.a[at.ts]=i;
		at.s[at.ts]=at.h[at.ts]=1;
		dp=at.mrg(dp, at.ts++);
	}
	for(int i=1; i<n; ++i) {
		ar<int, 2> a=at.spl(dp, i);
		int dp1, dp2;
		if(n-i<m) {
			ar<int, 2> b=at.spl(a[0], m-n+i);
			dp1=at.mrg(a[1], b[0]);
		} else
			dp1=at.spl(a[1], m)[0];
		a=at.spl(dp, n-i);
		if(i>m) {
			ar<int, 2> b=at.spl(a[1], m);
			dp2=at.mrg(b[1], a[0]);
		} else
			dp2=at.spl(a[0], m-i)[1];
		dp=at.mrg(dp1, dp2);
	}
	at.dfs(dp);
	while(t%n) {
		if(s<m)
			s=(s+t)%n;
		else
			s=(s-t%n+n)%n;
		--t;
	}
	for(int i=1; i<40; ++i)
		for(int j=0; j<n; ++j)
			nxt[j][i]=nxt[nxt[j][i-1]][i-1];
	for(int i=39; i>=0; --i) {
		if(t>=1ll<<i) {
			t-=1ll<<i;
			s=nxt[s][i];
		}
	}
	cout << s+1;
}