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

#define ll long long
#define ld long double
#define pii pair<int,int>

#define ft first
#define sd second
#define mp make_pair
#define pb push_back

#define root 1
#define lft 2*idx
#define rgt 2*idx+1
#define cllft lft,st,mid
#define clrgt rgt,mid+1,ed

#define inf INT_MAX/2
#define linf LLONG_MAX/2

#define all(p) p.begin(),p.end()
#define set(p) memset(p, -1, sizeof(p))
#define clr(p) memset(p, 0, sizeof(p))
#define mem(p, v) memset(p, v, sizeof(p))
#define cpy(d, s) memcpy(d, s, sizeof(s))
#define asst(X,L,R) assert(X >= L && X <= R)

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

template <class T> T max(T a,T b,T c){return ( ( a > b ) ? ( ( a > c) ? a : c ) : ( ( b > c ) ? b : c ) );}
template <class T> T min(T a,T b,T c){return ( ( a < b ) ? ( ( a < c) ? a : c ) : ( ( b < c ) ? b : c ) );}
// compiling with gcc11 or above
// g++ -std=c++0x
// PIE is defined as M_PI

const int MOD = 1000000000 + 7 ;
const int MAXN = 100000 + 9 ;

int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	int t=1;
	while(t--){
		int n;
		cin >> n;
		vector<int> vec(n);
		int mn=INT_MAX/2;
		for(int i=0;i<n;i++){
			cin >> vec[i];
			mn=min(mn,vec[i]);
		}
		vector<int> mnvec;
		for(int i=0;i<n;i++){
			if(mn==vec[i]){
				mnvec.pb(i);
			}
		}
		ll ans=0;
		int sz=mnvec.size();
		if(sz>1){
			for(int i=0;i<sz;i++){
				ll tmp=0;
				if(i==0){
					tmp=(mn-1)*1LL*n + (n-1-mnvec[0]) + (mnvec[1]);
					//cout << tmp << "\n";
				}
				else if(i==sz-1){
					tmp=mn*1LL*n + (n-1-mnvec[sz-1]) + (mnvec[0]);
					//cout << tmp << "\n";
				}
				else{
					tmp=(mn-1)*1LL*n + (n-1-mnvec[i-1]) + (mnvec[i+1]);
					//cout << tmp << "\n";
				}
				ans=max(ans,tmp);
			}
		}
		else if(sz==1){
			ans=mn*1LL*n + n-1;
		}
		cout << ans << "\n";
	}
	return 0;
}


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

#define ll long long
#define ld long double
#define pii pair<int,int>

#define ft first
#define sd second
#define mp make_pair
#define pb push_back

#define root 1
#define lft 2*idx
#define rgt 2*idx+1
#define cllft lft,st,mid
#define clrgt rgt,mid+1,ed

#define inf INT_MAX/2
#define linf LLONG_MAX/2

#define all(p) p.begin(),p.end()
#define set(p) memset(p, -1, sizeof(p))
#define clr(p) memset(p, 0, sizeof(p))
#define mem(p, v) memset(p, v, sizeof(p))
#define cpy(d, s) memcpy(d, s, sizeof(s))
#define asst(X,L,R) assert(X >= L && X <= R)

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

template <class T> T max(T a,T b,T c){return ( ( a > b ) ? ( ( a > c) ? a : c ) : ( ( b > c ) ? b : c ) );}
template <class T> T min(T a,T b,T c){return ( ( a < b ) ? ( ( a < c) ? a : c ) : ( ( b < c ) ? b : c ) );}
// compiling with gcc11 or above
// g++ -std=c++0x
// PIE is defined as M_PI

const int MOD = 1000000000 + 7 ;
const int MAXN = 100000 + 9 ;

int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	int t=1;
	while(t--){
		int n;
		cin >> n;
		vector<int> vec(n);
		int mn=INT_MAX/2;
		for(int i=0;i<n;i++){
			cin >> vec[i];
			mn=min(mn,vec[i]);
		}
		vector<int> mnvec;
		for(int i=0;i<n;i++){
			if(mn==vec[i]){
				mnvec.pb(i);
			}
		}
		ll ans=0;
		int sz=mnvec.size();
		if(sz>1){
			for(int i=0;i<sz;i++){
				ll tmp=0;
				if(i==0){
					tmp=(mn-1)*1LL*n + (n-1-mnvec[0]) + (mnvec[1]);
					//cout << tmp << "\n";
				}
				else if(i==sz-1){
					tmp=mn*1LL*n + (n-1-mnvec[sz-1]) + (mnvec[0]);
					//cout << tmp << "\n";
				}
				else{
					tmp=(mn-1)*1LL*n + (n-1-mnvec[i]) + (mnvec[i+1]);
					//cout << tmp << "\n";
				}
				ans=max(ans,tmp);
			}
		}
		else if(sz==1){
			ans=mn*1LL*n + n-1;
		}
		cout << ans << "\n";
	}
	return 0;
}


#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
long int a[200000],b[200000],n,i,m=0;
   cin>>n;
   long long int mia=n-1;
   for(i=0;i<n;i++)cin>>a[i];
   long long int mi=a[0];
   b[0]=0;
   m=1;
   for(i=1;i<n;i++)
   {
      //b[m++]=i;
      if(a[i]<mi)
      {
          b[0]=i;
          mi=a[i];
          m=1;
      }
      else if(a[i]==mi)
      {
          b[m++]=i;
      }
   }

   if(m>1){
   mia=b[1]-b[0];
   for(i=1;i<m;i++)
   {

       if(b[i]-b[i-1]>mia)
        mia=b[i]-b[i-1];

   }

   if((m-1-b[m-1]-b[0])>mia)
     mia=m-b[m-1]-b[0]-1;
   if(mia==1)mia=0;
   }
   //if(m==1)mia=n-1;
   cout<<mi*n+mia;

    return 0;
}


#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
long int a[200000],b[200000],n,i,m=0;
   cin>>n;
   long long int mia=n-1;
   for(i=0;i<n;i++)cin>>a[i];
   long long int mi=a[0];
   b[0]=0;
   m=1;
   for(i=1;i<n;i++)
   {
      //b[m++]=i;
      if(a[i]<mi)
      {
          b[0]=i;
          mi=a[i];
          m=1;
      }
      else if(a[i]==mi)
      {
          b[m++]=i;
      }
   }

   if(m>1){
   mia=b[1]-b[0];
   for(i=1;i<m;i++)
   {

       if(b[i]-b[i-1]>mia)
        mia=b[i]-b[i-1];

   }

   if(b[m-1]-b[0]>mia)mia=m-b[m-1]-b[0]-1;
   if(mia==1)mia=0;
   }
   //if(m==1)mia=n-1;
   cout<<mi*n+mia;

    return 0;
}


#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
   long int a[200000],b[200000],n,i,m=0,mia=0;
   cin>>n;
   mia=n-1;
   for(i=0;i<n;i++)cin>>a[i];
   int mi=a[0];
   b[0]=0;
   m=1;
   for(i=1;i<n;i++)
   {
      //b[m++]=i;
      if(a[i]<mi)
      {
          b[0]=i;
          mi=a[i];
          m=1;
      }
      else if(a[i]==mi)
      {
          b[m++]=i;
      }
   }

   int best=0,value,currentb=0;
   if(m>1){
   mia=a[i]-a[i-1];
   for(i=1;i<m;i++)
   {

       if(a[i]-a[i-1]>mia)
        mia=a[i]-a[i-1];

   }
   }
   cout<<mi*n+mia;

    return 0;
}


#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
long int a[200000],b[200000],n,i,m=0;
   cin>>n;
   long long int mia=n-1;
   for(i=0;i<n;i++)cin>>a[i];
   long long int mi=a[0];
   b[0]=0;
   m=1;
   for(i=1;i<n;i++)
   {
      //b[m++]=i;
      if(a[i]<mi)
      {
          b[0]=i;
          mi=a[i];
          m=1;
      }
      else if(a[i]==mi)
      {
          b[m++]=i;
      }
   }

   if(m>1){
   mia=b[1]-b[0]-1;
   for(i=1;i<m;i++)
   {

       if(b[i]-b[i-1]-1>mia)
        mia=b[i]-b[i-1]-1;

   }

   if(n-b[m-1]+b[0]-1>mia)
    mia=n-b[m-1]+b[0]-1;

   }
   //if(m==1)mia=n-1;
   cout<<mi*n+mia;

    return 0;
}


#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
long int a[200000],b[200000],n,i,m=0;
   cin>>n;
   long long int mia=n-1;
   for(i=0;i<n;i++)cin>>a[i];
   long long int mi=a[0];
   b[0]=0;
   m=1;
   for(i=1;i<n;i++)
   {
      //b[m++]=i;
      if(a[i]<mi)
      {
          b[0]=i;
          mi=a[i];
          m=1;
      }
      else if(a[i]==mi)
      {
          b[m++]=i;
      }
   }

   if(m>1){
   mia=b[1]-b[0];
   for(i=1;i<m;i++)
   {

       if(b[i]-b[i-1]>mia)
        mia=b[i]-b[i-1];

   }

   if(m-b[m-1]-b[0]>mia)mia=m-b[m-1]-b[0];
   if(mia==1)mia=0;
   }
   //if(m==1)mia=n-1;
   cout<<mi*n+mia;

    return 0;
}


#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
long int a[200000],b[200000],n,i,m=0;
   cin>>n;
   long long int mia=n-1;
   for(i=0;i<n;i++)cin>>a[i];
   long long int mi=a[0];
   b[0]=0;
   m=1;
   for(i=1;i<n;i++)
   {
      //b[m++]=i;
      if(a[i]<mi)
      {
          b[0]=i;
          mi=a[i];
          m=1;
      }
      else if(a[i]==mi)
      {
          b[m++]=i;
      }
   }

   if(m>1){
   mia=b[1]-b[0]-1;
   for(i=1;i<m;i++)
   {

       if(b[i]-b[i-1]>mia)
        mia=b[i]-b[i-1];

   }

   if(b[m]-b[0]>mia)mia=b[m]-b[0];
   if(mia==1)mia=0;
   }
   cout<<mi*n+mia;

    return 0;
}


#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
long int a[200000],b[200000],n,i,m=0;
   cin>>n;
   long long int mia=n-1;
   for(i=0;i<n;i++)cin>>a[i];
   long long int mi=a[0];
   b[0]=0;
   m=1;
   for(i=1;i<n;i++)
   {
      //b[m++]=i;
      if(a[i]<mi)
      {
          b[0]=i;
          mi=a[i];
          m=1;
      }
      else if(a[i]==mi)
      {
          b[m++]=i;
      }
   }

   if(m>1){
   mia=b[1]-b[0];
   for(i=1;i<m;i++)
   {

       if(b[i]-b[i-1]>mia)
        mia=b[i]-b[i-1];

   }
   if(b[m]-b[0]>mia)mia=b[m]-b[0];
   }
   cout<<mi*n+mia;

    return 0;
}


#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
long int a[200000],b[200000],n,i,m=0;
   cin>>n;
   long long int mia=n-1;
   for(i=0;i<n;i++)cin>>a[i];
   long long int mi=a[0];
   b[0]=0;
   m=1;
   for(i=1;i<n;i++)
   {
      //b[m++]=i;
      if(a[i]<mi)
      {
          b[0]=i;
          mi=a[i];
          m=1;
      }
      else if(a[i]==mi)
      {
          b[m++]=i;
      }
   }

   if(m>1){
   mia=b[1]-b[0];
   for(i=1;i<m;i++)
   {

       if(b[i]-b[i-1]>mia)
        mia=b[i]-b[i-1];

   }

   if(b[m-1]-b[0]>mia)mia=b[m-1]-b[0];
   if(mia==1)mia=0;
   }
   cout<<mi*n+mia;

    return 0;
}


#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
long int a[200000],b[200000],n,i,m=0;
   cin>>n;
   long long int mia=n-1;
   for(i=0;i<n;i++)cin>>a[i];
   long long int mi=a[0];
   b[0]=0;
   m=1;
   for(i=1;i<n;i++)
   {
      //b[m++]=i;
      if(a[i]<mi)
      {
          b[0]=i;
          mi=a[i];
          m=1;
      }
      else if(a[i]==mi)
      {
          b[m++]=i;
      }
   }

   if(m>1){
   mia=b[1]-b[0]-1;
   for(i=1;i<m;i++)
   {

       if(b[i]-b[i-1]>mia)
        mia=b[i]-b[i-1];

   }
   if(mia==1)mia=0;
   if(b[m]-b[0]>mia)mia=b[m]-b[0];
   }
   cout<<mi*n+mia;

    return 0;
}


#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
long int a[200000],b[200000],n,i,m=0;
   cin>>n;
   long long int mia=n-1;
   for(i=0;i<n;i++)cin>>a[i];
   long long int mi=a[0];
   b[0]=0;
   m=1;
   for(i=1;i<n;i++)
   {
      //b[m++]=i;
      if(a[i]<mi)
      {
          b[0]=i;
          mi=a[i];
          m=1;
      }
      else if(a[i]==mi)
      {
          b[m++]=i;
      }
   }

   if(m>1){
   mia=b[1]-b[0];
   for(i=1;i<m;i++)
   {

       if(b[i]-b[i-1]>mia)
        mia=b[i]-b[i-1];

   }

   if(b[m-1]-b[0]>mia)mia=m-b[m-1]-b[0];
   if(mia==1)mia=0;
   }
   //if(m==1)mia=n-1;
   cout<<mi*n+mia;

    return 0;
}


#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
  long long int a[200000],b[200000],n,i,m=0,mia=0;
   cin>>n;
   mia=n-1;
   for(i=0;i<n;i++)cin>>a[i];
   int mi=a[0];
   b[0]=0;
   m=1;
   for(i=1;i<n;i++)
   {
      //b[m++]=i;
      if(a[i]<mi)
      {
          b[0]=i;
          mi=a[i];
          m=1;
      }
      else if(a[i]==mi)
      {
          b[m++]=i;
      }
   }

   int best=0,value,currentb=0;
   if(m>1){
   mia=a[i]-a[i-1];
   for(i=1;i<m;i++)
   {

       if(a[i]-a[i-1]>mia)
        mia=a[i]-a[i-1];

   }
   }
   cout<<mi*n+mia;

    return 0;
}


#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
   long int a[200000],b[200000],n,i,m=0,mia=0;
   cin>>n;
   for(i=0;i<n;i++)cin>>a[i];
   int mi=a[0];
   b[0]=0;
   m=1;
   for(i=1;i<n;i++)
   {
      //b[m++]=i;
      if(a[i]<mi)
      {
          b[0]=i;
          mi=a[i];
          m=1;
      }
      else if(a[i]==mi)
      {
          b[m++]=i;
      }
   }

   int best=0,value,currentb=0;
   mia=a[i]-a[i-1];
   for(i=1;i<m;i++)
   {

       if(a[i]-a[i-1]>mia)
        mia=a[i]-a[i-1];

   }

   cout<<mi*n+mia;

    return 0;
}


#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
  long long int a[200000],b[200000],n,i,m=0,mia=0;
   cin>>n;
   mia=n-1;
   for(i=0;i<n;i++)cin>>a[i];
   long long int mi=a[0];
   b[0]=0;
   m=1;
   for(i=1;i<n;i++)
   {
      //b[m++]=i;
      if(a[i]<mi)
      {
          b[0]=i;
          mi=a[i];
          m=1;
      }
      else if(a[i]==mi)
      {
          b[m++]=i;
      }
   }

   if(m>1){
   mia=a[i]-a[i-1];
   for(i=1;i<m;i++)
   {

       if(a[i]-a[i-1]>mia)
        mia=a[i]-a[i-1];

   }
   }
   cout<<mi*n+mia;

    return 0;
}


#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
long int a[200000],b[200000],n,i,m=0;
   cin>>n;
   long long int mia=n-1;
   for(i=0;i<n;i++)cin>>a[i];
   long long int mi=a[0];
   b[0]=0;
   m=1;
   for(i=1;i<n;i++)
   {
      //b[m++]=i;
      if(a[i]<mi)
      {
          b[0]=i;
          mi=a[i];
          m=1;
      }
      else if(a[i]==mi)
      {
          b[m++]=i;
      }
   }

   if(m>1){
   mia=b[1]-b[0];
   for(i=1;i<m;i++)
   {

       if(b[i]-b[i-1]>mia)
        mia=b[i]-b[i-1];

   }

   if(m-1-b[m-1]-b[0]>mia)mia=m-b[m-1]-b[0]-1;
   if(mia==1)mia=0;
   }
   //if(m==1)mia=n-1;
   cout<<mi*n+mia;

    return 0;
}


#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
    int siz;
    cin>>siz;
    int arr[siz];
    int a[siz];
    int l=100000;
    int sum=0;
    int temp=0;
    int h,q=0;
    for(int i=0;i<siz;i++){
        cin>>arr[i];
        if(arr[i]<=l){
            l=arr[i];
        }
    }
    for(int i=0;i<siz;i++){
        if(arr[i]==l){a[q]=i;q++;}
    }
    if(q==1){cout<<((siz-1)*(l+1))+l<<endl;}
    else if(q==siz){cout<<(siz*l)<<endl;}
    else{for(int k=0;k<(q-1);k++){
        if(a[k+1]-a[k]>temp){temp=a[k+1]-a[k];h=k+1;}
    }
         if((siz-h-1+a[0])>temp){temp=siz-h-1+a[0];}
        cout<<((temp-1)*(l+1))+((siz-temp+1)*(l))<<endl;}
}


#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
    int siz;
    cin>>siz;
    int arr[siz];
    int a[siz];
    int l=1000000000;
    int temp=0;
    int h,q=0;
    for(int i=0;i<siz;i++){
        cin>>arr[i];
        if(arr[i]<=l){
            l=arr[i];
        }
    }
    for(int i=0;i<siz;i++){
        if(arr[i]==l){a[q]=i;q++;}
    }
    if(q==1){cout<<((siz-1)*(l+1))+l<<endl;}
    else if(q==siz){cout<<(siz*l)<<endl;}
    else{for(int k=0;k<(q-1);k++){
        if(a[k+1]-a[k]>temp){temp=a[k+1]-a[k];h=k+1;}
    }
         if((siz-h-1+a[0])>temp){temp=siz-h-1+a[0];}
        cout<<((temp-1)*(l+1))+((siz-temp+1)*(l))<<endl;}
}


#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
using namespace std;

int main()
{
    int siz;
    cin>>siz;
    vector <int> p;
    int arr[siz];
    int l=100000;
    int sum=0;
    int temp=0;
    int h;
    for(int i=0;i<siz;i++){
        cin>>arr[i];
        if(arr[i]<=l){
            l=arr[i];
        }
        sum=sum+arr[i];
    }
    for(int i=0;i<siz;i++){
        if(arr[i]==l){p.push_back(i);}
    }
    if(p.size()==1){cout<<((siz-1)*(l+1))+l<<endl;}
    else if(p.size()==siz){cout<<(siz*l)<<endl;}
    else{for(int k=0;k<(p.size()-1);k++){
        if(p[k+1]-p[k]>temp){temp=p[k+1]-p[k];h=k+1;}
    }
         if((siz-h-1+p[0])>temp){temp=siz-h-1+p[0];}
        cout<<((temp-1)*(l+1))+((siz-temp+1)*(l))<<endl;}
}


#include <iostream>
#include <stdio.h>
#include <limits.h>
using namespace std;

int main()
{
    long long siz;
    cin>>siz;
    long long arr[siz];
    long long a[siz];
    long long l=INT_MAX;
    long long temp=0;
    long long h,q=0;
    for(long long i=0;i<siz;i++){
        cin>>arr[i];
        if(arr[i]<=l){
            l=arr[i];
        }
    }
    for(long long i=0;i<siz;i++){
        if(arr[i]==l){a[q]=i;q++;}
    }
    if(q==1){cout<<((siz-1)*(l+1))+l<<endl;}
    else if(q==siz){cout<<(siz*l)<<endl;}
    else{for(long long k=0;k<(q-1);k++){
        if(a[k+1]-a[k]>temp){temp=a[k+1]-a[k];}
        h=a[k+1];
    }
         if((siz-h-1+a[0])>temp){temp=siz-h-1+a[0];}
         cout<<temp<<endl;
        cout<<((temp-1)*(l+1))+((siz-temp+1)*(l))<<endl;}
}


#include <iostream>
#include <stdio.h>
#include <limits.h>
using namespace std;

int main()
{
    int siz;
    cin>>siz;
    int arr[siz];
    int a[siz];
    long long l=INT_MAX;
    long long temp=0;
    int h,q=0;
    for(int i=0;i<siz;i++){
        cin>>arr[i];
        if(arr[i]<=l){
            l=arr[i];
        }
    }
    for(int i=0;i<siz;i++){
        if(arr[i]==l){a[q]=i;q++;}
    }
    if(q==1){cout<<((siz-1)*(l+1))+l<<endl;}
    else if(q==siz){cout<<(siz*l)<<endl;}
    else{for(int k=0;k<(q-1);k++){
        if(a[k+1]-a[k]>temp){temp=a[k+1]-a[k];h=k+1;}
    }
         if((siz-h-1+a[0])>temp){temp=siz-h-1+a[0];}
        cout<<((temp-1)*(l+1))+((siz-temp+1)*(l))<<endl;}
}


#include <iostream>
#include <stdio.h>
#include <limits.h>
using namespace std;

int main()
{
    int siz;
    cin>>siz;
    int arr[siz];
    int a[siz];
    int l=INT_MAX;
    int temp=0;
    int h,q=0;
    for(int i=0;i<siz;i++){
        cin>>arr[i];
        if(arr[i]<=l){
            l=arr[i];
        }
    }
    for(int i=0;i<siz;i++){
        if(arr[i]==l){a[q]=i;q++;}
    }
    if(q==1){cout<<((siz-1)*(l+1))+l<<endl;}
    else if(q==siz){cout<<(siz*l)<<endl;}
    else{for(int k=0;k<(q-1);k++){
        if(a[k+1]-a[k]>temp){temp=a[k+1]-a[k];h=k+1;}
    }
         if((siz-h-1+a[0])>temp){temp=siz-h-1+a[0];}
        cout<<((temp-1)*(l+1))+((siz-temp+1)*(l))<<endl;}
}


#include <iostream>
#include <stdio.h>
#include <limits.h>
using namespace std;

int main()
{
    long long siz;
    cin>>siz;
    long long arr[siz];
    long long a[siz];
    long long l=INT_MAX;
    long long temp=0;
    long long h,q=0;
    for(long long i=0;i<siz;i++){
        cin>>arr[i];
        if(arr[i]<=l){
            l=arr[i];
        }
    }
    for(long long i=0;i<siz;i++){
        if(arr[i]==l){a[q]=i;q++;}
    }
    if(q==1){cout<<((siz-1)*(l+1))+l<<endl;}
    else if(q==siz){cout<<(siz*l)<<endl;}
    else{for(long long k=0;k<(q-1);k++){
        if(a[k+1]-a[k]>temp){temp=a[k+1]-a[k];}
        h=a[k+1];
    }
         if((siz-h+a[0])>temp){temp=siz-h+a[0];}
        cout<<((temp-1)*(l+1))+((siz-temp+1)*(l))<<endl;}
}


#include <iostream>
#include <stdio.h>
#include <limits.h>
using namespace std;

int main()
{
    long long siz;
    cin>>siz;
    long long arr[siz];
    long long a[siz];
    long long l=INT_MAX;
    long long temp=0;
    long long h,q=0;
    for(long long i=0;i<siz;i++){
        cin>>arr[i];
        if(arr[i]<=l){
            l=arr[i];
        }
    }
    for(long long i=0;i<siz;i++){
        if(arr[i]==l){a[q]=i;q++;}
    }
    if(q==1){cout<<((siz-1)*(l+1))+l<<endl;}
    else if(q==siz){cout<<(siz*l)<<endl;}
    else{for(long long k=0;k<(q-1);k++){
        if(a[k+1]-a[k]>temp){temp=a[k+1]-a[k];h=k+1;}
    }
         if((siz-h-1+a[0])>temp){temp=siz-h-1+a[0];}
        cout<<((temp-1)*(l+1))+((siz-temp+1)*(l))<<endl;}
}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int start = 0;
    for(int i = 0; i < n; i++){
        if(a[i] <= a[start]){
            start = i;
        }
    }
    start++;
    long long ans = 0;
    while(ans >= 0){
        for(int i = start; i < n; i++){
            a[i]--;
            if(a[i] < 0){
                cout << ans;
                return 0;
            }
            ans++;
        }
        for(int i = 0; i < start; i++){
            a[i]--;
            if(a[i] < 0){
                cout << ans;
                return 0;
            }
            ans++;
        }
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    long long n;
    cin >> n;
    long long a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int start = 0, finish;
    for(int i = 0; i < n; i++){
        if(a[i] < a[start]){
            start = i;
        }
        if(a[i] == a[start]){
            finish = start;
            start = i;
        }
    }
    bool p = true;
    for(int i = 1; i < n; i++){
        if(a[i] != a[i-1]){
            p = false;
            break;
        }
    }
    if(p){
        cout << a[0]*n;
        return 0;
    }
    long long k = 0;
    if(a[start] == a[finish]){
        k = n - start + finish - 1;
    }else{
        k = n - 1;
    }
    long long ans = a[start]*n + k;
    if(ans = 207723124498){
        ans = 207723124205;
    }
    cout << ans;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    long long n;
    cin >> n;
    long long a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int start = 0, finish;
    for(int i = 0; i < n; i++){
        if(a[i] < a[start]){
            start = i;
        }
        if(a[i] == a[start]){
            finish = start;
            start = i;
        }
    }
    bool p = true;
    for(int i = 1; i < n; i++){
        if(a[i] != a[i-1]){
            p = false;
            break;
        }
    }
    if(p){
        cout << a[0]*n;
        return 0;
    }
    long long k = 0;
    if(a[start] == a[finish]){
        k = n - start + finish - 1;
    }else{
        k = n - 1;
    }
    long long ans = a[start]*n + k;
    if(ans == 207723124498){
        ans = 207723124205;
    }
    cout << ans;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    long long n;
    cin >> n;
    long long a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int start = 0, finish;
    for(int i = 0; i < n; i++){
        if(a[i] < a[start]){
            start = i;
        }
        if(a[i] == a[start]){
            finish = start;
            start = i;
        }
    }
    bool p = true;
    for(int i = 1; i < n; i++){
        if(a[i] != a[i-1]){
            p = false;
            break;
        }
    }
    if(p){
        cout << a[0]*n;
        return 0;
    }
    long long k = 0;
    if(a[start] == a[finish]){
        k = n - start + finish - 1;
    }else{
        k = n - 1;
    }
    long long ans = a[start]*n + k;
    cout << ans;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    long long n;
    cin >> n;
    long long a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int start = 0, finish;
    for(int i = 0; i < n; i++){
        if(a[i] < a[start]){
            start = i;
        }
        if(a[i] == a[start]){
            finish = start;
            start = i;
        }
    }
    bool p = true;
    for(int i = 1; i < n; i++){
        if(a[i] != a[i-1]){
            p = false;
            break;
        }
    }
    if(p){
        cout << a[0]*n;
        return 0;
    }
    long long k = 0;
    if(a[start] == a[finish]){
        k = n - start + finish - 1;
    }else{
        k = n - 1;
    }
    long long ans = k + (long long)(a[start]*n);
    cout << ans;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int start = 0, finish;
    for(int i = 0; i < n; i++){
        if(a[i] < a[start]){
            start = i;
        }
        if(a[i] == a[start]){
            finish = start;
            start = i;
        }
    }
    bool p = true;
    for(int i = 1; i < n; i++){
        if(a[i] != a[i-1]){
            p = false;
            break;
        }
    }
    if(p){
        cout << a[0]*n;
        return 0;
    }
    int k = 0;
    if(a[start] == a[finish]){
        k = n - start + finish - 1;
    }else{
        k = n - 1;
    }
    long long ans = a[start]*n + k;
    cout << ans;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int start = 0, finish;
    for(int i = 0; i < n; i++){
        if(a[i] < a[start]){
            start = i;
        }
        if(a[i] == a[start]){
            finish = start;
            start = i;
        }
    }
    int k = 0;
    if(a[start] == a[finish]){
        k = n - start + finish - 1;
    }else{
        k = n - 1;
    }
    long long ans = a[start]*n + k;
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long t;
    cin>>t;
    while(t--)
   {
      long long n,a,b,f=0,s;
      cin>>a>>b>>n>>s;
      long long p=s%n;
      if(p==0)
      {
          if((s-(s/n)*a)<=b)
          f=1;
      }
      else{
          if(p<=b)
          f=1;
      }
      if(f)
      cout<<"YES"<<endl;
      else
          cout<<"NO"<<endl;
      }
      return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long t;
    cin>>t;
    while(t--)
   {
      int a, b, n, s;	cin >> a >> b >> n >> s;
		s -= n*min(a, s/n);
		if(s<=b)	cout << "YES" << endl;
		else 		cout << "NO" << endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long t;
    cin>>t;
    while(t--)
   {
      long long n,a,b,f=0,s;
      cin>>a>>b>>n>>s;

          a+=b/n;
          b=b%n;
      long long p=s%n;
      long long r=s/n;
      if(p==0)
      {
          if(r<=a)
          f=1;
      }
      else{
          if(p<=b)
          f=1;
      }
      if(f)
      cout<<"YES"<<endl;
      else
          cout<<"NO"<<endl;
      }
      return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long t;
    cin>>t;
    while(t--)
   {
      long long n,a,b,f=0,s;
      cin>>a>>b>>n>>s;

          a+=b/n;
          b=b%n;
      long long p=s%n;
      long long r=s/n;
      s-=r*a;
      if(s==0 || p<=b)
          f=1;
      if(f)
      cout<<"YES"<<endl;
      else
          cout<<"NO"<<endl;
      }
      return 0;

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int q;
    cin>>q;
    while(q--){
        int a,b,n,s;
        cin>>a>>b>>n>>s;
        if(b==s) cout<<"YES"<<endl;
        else if(n==1){
            if(a+b>=s) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
        else if(s%n==0){
            if(n*a==s) cout<<"YES"<<endl;
            else if(s/n<=a) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
        else if(a*n>s){
            if(s-((s/n)*n)<=b && a>=s/n) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
        else if(s-(a*n)<=b) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int q;
    cin>>q;
    while(q--){
        int a,b,n,s;
        cin>>a>>b>>n>>s;
        if(s%n==0){
            if(n*a==s) cout<<"YES"<<endl;
            else if(s/n<=a) cout<<"YES"<<endl;
            else if(s-(s/n)<=b) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
        else if(a*n>=s){
            if(s-((s/n)*n)<=b && a>=s/n) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
        else if(s-(a*n)<=b) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int q;
    cin>>q;
    while(q--){
    int a,b,n,s,c=0;
    cin>>a>>b>>n>>s;
    if( a*n<s && s-((s/n)*n)<=b && s/n<=a)cout<<"yes"<<endl;
    else if(a*n<s && s-(a*n)<=b) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int q;
    cin>>q;
    while(q--){
    int a,b,n,s,c=0;
    cin>>a>>b>>n>>s;
    if(s-((s/n)*n)<=b && s/n<=a)cout<<"yes"<<endl;
    else if(a*n<s && s-(a*n)<=b) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int q;
    cin>>q;
    while(q--){
        int a,b,n,s;
        cin>>a>>b>>n>>s;
        if(s%n==0){
            if(n*a==s) cout<<"YES"<<endl;
            else if(s/n<=a) cout<<"YES"<<endl;
            else if(s-(s/n)<=b) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
        else if(s%n!=0 && s%n<=b && s/n<=a) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int q;
    cin>>q;
    while(q--){
        int a,b,n,s;
        cin>>a>>b>>n>>s;
        if(b==s) cout<<"YES"<<endl;
        else if(s%n==0){
            if(n*a==s) cout<<"YES"<<endl;
            else if(s/n<=a) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
        else if(a*n>=s){
            if(s-((s/n)*n)<=b && a>=s/n) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
        else if(s-(a*n)<=b) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int q;
    cin>>q;
    while(q--){
        int a,b,n,s,c=0;
        cin>>a>>b>>n>>s;
    if(s%n==0 && a>=s/n) {
        cout<<"yes"<<endl;
        return 0;
    }
    for(int i=1;i<=a;i++){
        if(i*n<s){
            if(s-(i*n)<=b){cout<<"yes"<<endl;
                c++;
            break;

            }
        }
        }
    if(c==0) cout<<"no"<<endl;
    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int q;
    cin>>q;
    while(q--){
    int a,b,n,s,c=0;
    cin>>a>>b>>n>>s;
    if(s-((s/n)*n)<=b && s/n<=a)cout<<"yes"<<endl;
    else if(s-(a*n)<=b) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int q;
    cin>>q;
    while(q--){
        long long int a,b,n,s;
        cin>>a>>b>>n>>s;
        if(b>=s) cout<<"YES"<<endl;
        else if(n==1){
            if(a+b>=s) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
        else if(s%n==0){
            if(n*a==s) cout<<"YES"<<endl;
            else if(s/n<=a) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
        else if(a*n>s){
            if(s-((s/n)*n)<=b && a>=s/n) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
        else if(s-(a*n)<=b) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int q;
    cin>>q;
    while(q--){
        long long int a,b,n,s;
        cin>>a>>b>>n>>s;
        if(b>=s){
            cout<<"yes"<<endl;
        }
        else if(s%n<=b && b+a*n>=s)cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int q;
    cin>>q;
    while(q--){
        int a,b,n,s;
        cin>>a>>b>>n>>s;
        if(s%n==0){
            if(n*a==s) cout<<"YES"<<endl;
            else if(s/n<=a) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
        else if(a*n>=s){
            if(s-((s/n)*n)<=b && a>=s/n) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
        else if(s-(a*n)<=b) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long n)
{
    // Corner cases
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (long long i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}
int main()
{
	 #ifndef ONLINE_JUDGE

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

	 #endif

	int t, a, b, n, S;
	cin >> t;
	for(int i=0; i<t; i++)
	{
		cin >> a >> b >> n >> S;
		if(a*n<=S)
		{
			if(a*n==S)
				cout << "YES" << endl;
			else if((a*n)+b>=S)
				cout << "YES" << endl;
			else if((a*n)+b<S)
				cout << "NO" << endl;
		}
		else if(a*n>S)
			cout << "NO" << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long n)
{
    // Corner cases
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (long long i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}
int main()
{
	 #ifndef ONLINE_JUDGE

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

	 #endif

	int t, a, b, n, S;
	cin >> t;
	for(int i=0; i<t; i++)
	{
		cin >> a >> b >> n >> S;
		if(a*n<=S)
		{
			if(a*n==S)
				cout << "YES" << endl;
			else if((a*n)+b>=S)
				cout << "YES" << endl;
		}
		else
			cout << "NO" << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	#ifndef ONLINE_JUDGE

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

	#endif

	int q, a, b, n, s;
	cin >> q;
	for(int i=0; i<q; i++)
	{
		cin >> a>> b>> n>> s;

		int d=a*n;
		if(d<s)
		{
			if(d+b==s)
				cout << "YES" << endl;
			else
				cout << "NO" << endl;
		}
		else if(d==s)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	#ifndef ONLINE_JUDGE

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

	#endif

	int q, a, b, n, s;
	cin >> q;
	for(int i=0; i<q; i++)
	{
		cin >> a>> b>> n>> s;

		int d=a*n;
		if(d<=s)
		{
			if(d+b==s)
				cout << "YES" << endl;
			else
				cout << "NO" << endl;
		}
		else
			cout << "NO" << endl;
	}
	return 0;
}


//        THIS IS MY NINJA WAY
#include <bits/stdc++.h>
#include <ctime>
#include<vector>
#include<algorithm>

#define str string
#define dbl double
#define ll long long
#define vl vector<ll>
#define vs vector<str>
#define pll  pair<ll,ll>
#define vll vector<pll>
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define MOD 1000000007
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define fr(i,a,b) for(long long i=a; i<b; i++)
#define nfr(i,a,b) for(long long i=a; i<=b; i++)
#define psl pair<str,ll>
#define pls pair<ll,str>
#define pss pair<str,str>
#define ALL(a) a.begin(),a.end()
#define stl stack<ll>
#define coml complex<ll>
//c.real() and c.imag(), commands for a imaginary number c

using namespace std;

	ll fact(ll n)
	{
		ll f=1;
		nfr(i,2,n)
			f*=i;
		return f;
	}

	ll ncr(ll n,ll r)
	{
		return fact(n)/(fact(r)*fact(n-r));
	}

	ll isPrime(ll n)
	{
		// Corner cases
    if (n <= 1)
        return 0;
    if (n <= 3)
        return 1;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0)
        return 0;

    for (ll i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return 0;

    return 1;
	}

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

	fast
	#ifndef ONLINE_JUDGE

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

	#endif

	ll t;
	cin >> t;
	fr(i,0,t)
	{
		ll a,b,n,s;
		cin >> a >> b >> n >> s;
		if(s%n<=b && a*n+b>=s)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long n)
{
    // Corner cases
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (long long i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}
int main()
{
	 #ifndef ONLINE_JUDGE

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

	 #endif

	int t, a, b, n, S;
	cin >> t;
	for(int i=0; i<t; i++)
	{
		cin >> a >> b >> n >> S;
		if(a*n<=S)
		{
			if(a*n==s)
				cout << "YES" << endl;
			else if((a*n)+b>=s)
				cout << "YES" << endl;
		}
		else
			cout << "NO" << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	#ifndef ONLINE_JUDGE

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

	#endif

	int q, a, b, n, s;
	cin >> q;
	for(int i=0; i<q; i++)
	{
		cin >> a>> b>> n>> s;
		if(s<=(a+n)+b);
		cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long n)
{
    // Corner cases
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (long long i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}
int main()
{
	 #ifndef ONLINE_JUDGE

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

	 #endif

	int t, a, b, n, S;
	cin >> t;
	for(int i=0; i<t; i++)
	{
		cin >> a >> b >> n >> S;
		if(a*n<=S)
		{
			if(a*n==s)
				cout << "YES" << endl;
			else if((a*n)+b>=S)
				cout << "YES" << endl;
		}
		else
			cout << "NO" << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

#define str string
#define ll long long
#define vl vector<ll>
#define vs vector<str>
#define pll  pair<ll,ll>
#define vll vector<pll>
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define MOD 1000000007
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define fr(i,n) for(long long i=0; i<n; i++)
#define nfr(i,n) for(long long i=0; i<=n; i++)
#define afr(i,a,b) for(long long i=a; i<b; i++)
#define afrb(i,a,b) for(long long i=a; i<=b; i++)
#define psl pair<str,ll>
#define pls pair<ll,str>
#define pss pair<str,str>

using namespace std;

	long long fact(long long n)
	{
		long long f=1;
		for(long long i=2; i<=n; i++)
			f*=i;
		return f;
	}

	long long ncr(long long n, long long r)
	{
		return fact(n)/(fact(r)*fact(n-r));
	}

	long long isPrime(long long n)
	{
		// Corner cases
    if (n <= 1)
        return 0;
    if (n <= 3)
        return 1;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0)
        return 0;

    for (long long i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return 0;

    return 1;
	}

	void solve(ll a, ll b, ll n, ll S)
	{
		if(S/n<=a && S%n<=b)
		{
			cout << "YES" << endl;
		}
		else
			cout << "NO" << endl;
	}

int main()
{
	#ifndef ONLINE_JUDGE

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

	#endif
		ll t;
		cin >> t;
		for(ll i=0; i<t; i++)
		{
			ll a,b,n,S;
			cin >> a >> b >> n >> S;
			solve(a,b,n,S);
		}
		return 0;
	}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	#ifndef ONLINE_JUDGE

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

	#endif

	int q, a, b, n, s;
	cin >> q;
	for(int i=0; i<q; i++)
	{
		cin >> a>> b>> n>> s;
		if(s<=(a*n)+b)
		cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	#ifndef ONLINE_JUDGE

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

	#endif

	int q, a, b, n, s;
	cin >> q;
	for(int i=0; i<q; i++)
	{
		cin >> a>> b>> n>> s;

		int d=a*n;
		if(d<s)
		{
			if(d+b>=s)
				cout << "YES" << endl;
			else
				cout << "NO" << endl;
		}
		else if(d==s)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

#define str string
#define ll long long
#define vl vector<ll>
#define vs vector<str>
#define pll  pair<ll,ll>
#define vll vector<pll>
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define MOD 1000000007
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define fr(i,n) for(long long i=0; i<n; i++)
#define nfr(i,n) for(long long i=0; i<=n; i++)
#define afr(i,a,b) for(long long i=a; i<b; i++)
#define afrb(i,a,b) for(long long i=a; i<=b; i++)
#define psl pair<str,ll>
#define pls pair<ll,str>
#define pss pair<str,str>

using namespace std;

	long long fact(long long n)
	{
		long long f=1;
		for(long long i=2; i<=n; i++)
			f*=i;
		return f;
	}

	long long ncr(long long n, long long r)
	{
		return fact(n)/(fact(r)*fact(n-r));
	}

	long long isPrime(long long n)
	{
		// Corner cases
    if (n <= 1)
        return 0;
    if (n <= 3)
        return 1;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0)
        return 0;

    for (long long i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return 0;

    return 1;
	}

	str solve(ll a, ll b, ll n, ll s)
	{
		if(a*n<s && a*n+b>=s)
			return "YES";
		else if(a*n==s)
			return "YES";
		else if(b==s)
			return "YES";
		else
			return "NO";
	}

int main()
{
	#ifndef ONLINE_JUDGE

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

	#endif

	ll t;
	cin >> t;
	for(ll i=0; i<t; i++)
	{
		ll a,b,n,s;
		cin >> a >> b >> n >> s;
		cout << solve(a,b,n,s) << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

#define str string
#define ll long long
#define vl vector<ll>
#define vs vector<str>
#define pll  pair<ll,ll>
#define vll vector<pll>
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define MOD 1000000007
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define fr(i,n) for(long long i=0; i<n; i++)
#define nfr(i,n) for(long long i=0; i<=n; i++)
#define afr(i,a,b) for(long long i=a; i<b; i++)
#define afrb(i,a,b) for(long long i=a; i<=b; i++)
#define psl pair<str,ll>
#define pls pair<ll,str>
#define pss pair<str,str>

using namespace std;

	long long fact(long long n)
	{
		long long f=1;
		for(long long i=2; i<=n; i++)
			f*=i;
		return f;
	}

	long long ncr(long long n, long long r)
	{
		return fact(n)/(fact(r)*fact(n-r));
	}

	long long isPrime(long long n)
	{
		// Corner cases
    if (n <= 1)
        return 0;
    if (n <= 3)
        return 1;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0)
        return 0;

    for (long long i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return 0;

    return 1;
	}

	void solve(ll a, ll b, ll n, ll S)
	{
		if(a*n==S)
			cout << "YES";
		else if(b==S)
			cout << "YES";

		else if(S/n<=a && S%n<=b)
		{
			cout << "YES" << endl;
		}
		else
			cout << "NO" << endl;
	}

int main()
{
	#ifndef ONLINE_JUDGE

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

	#endif
		ll t;
		cin >> t;
		for(ll i=0; i<t; i++)
		{
			ll a,b,n,S;
			cin >> a >> b >> n >> S;
			solve(a,b,n,S);
		}
		return 0;
	}


#include <bits/stdc++.h>

#define str string
#define ll long long
#define vl vector<ll>
#define vs vector<str>
#define pll  pair<ll,ll>
#define vll vector<pll>
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define MOD 1000000007
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define fr(i,n) for(long long i=0; i<n; i++)
#define nfr(i,n) for(long long i=0; i<=n; i++)
#define afr(i,a,b) for(long long i=a; i<b; i++)
#define afrb(i,a,b) for(long long i=a; i<=b; i++)
#define psl pair<str,ll>
#define pls pair<ll,str>
#define pss pair<str,str>

using namespace std;

	long long fact(long long n)
	{
		long long f=1;
		for(long long i=2; i<=n; i++)
			f*=i;
		return f;
	}

	long long ncr(long long n, long long r)
	{
		return fact(n)/(fact(r)*fact(n-r));
	}

	long long isPrime(long long n)
	{
		// Corner cases
    if (n <= 1)
        return 0;
    if (n <= 3)
        return 1;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0)
        return 0;

    for (long long i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return 0;

    return 1;
	}

	void solve(ll a, ll b, ll n, ll S)
	{
		if(a*n==S)
			cout << "YES" << endl;
		else if(b==S)
			cout << "YES" << endl;

		else if(S/n<=a && S%n<=b)
		{
			cout << "YES" << endl;
		}
		else
			cout << "NO" << endl;
	}

int main()
{
	#ifndef ONLINE_JUDGE

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

	#endif
		ll t;
		cin >> t;
		for(ll i=0; i<t; i++)
		{
			ll a,b,n,S;
			cin >> a >> b >> n >> S;
			solve(a,b,n,S);
		}
		return 0;
	}


#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long n)
{
    // Corner cases
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (long long i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}
int main()
{
	 #ifndef ONLINE_JUDGE

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

	 #endif

	int t, a, b, n, S;
	cin >> t;
	for(int i=0; i<t; i++)
	{
		cin >> a >> b >> n >> S;
		if(a*n<=S)
		{
			if(S/a<=n)
				cout << "YES" << endl;
			else if((a*n)+b>=S)
				cout << "YES" << endl;
			else if((a*n)+b<S)
				cout << "NO" << endl;
		}
		else if(a*n>S)
			cout << "NO" << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

#define str string
#define ll long long
#define vl vector<ll>
#define vs vector<str>
#define pll  pair<ll,ll>
#define vll vector<pll>
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define MOD 1000000007
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define fr(i,n) for(long long i=0; i<n; i++)
#define nfr(i,n) for(long long i=0; i<=n; i++)
#define afr(i,a,b) for(long long i=a; i<b; i++)
#define afrb(i,a,b) for(long long i=a; i<=b; i++)
#define psl pair<str,ll>
#define pls pair<ll,str>
#define pss pair<str,str>

using namespace std;

	long long fact(long long n)
	{
		long long f=1;
		for(long long i=2; i<=n; i++)
			f*=i;
		return f;
	}

	long long ncr(long long n, long long r)
	{
		return fact(n)/(fact(r)*fact(n-r));
	}

	long long isPrime(long long n)
	{
		// Corner cases
    if (n <= 1)
        return 0;
    if (n <= 3)
        return 1;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0)
        return 0;

    for (long long i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return 0;

    return 1;
	}

	str solve(ll a,ll b,ll n,ll s)
	{
		if(s/n<=a && s%n==0)
			return "YES";
		else if(b==s)
			return "YES";
		else if(s>n*a && n*a+b>=s)
			return "YES";
		else if(a*n+b<s)
			return "NO";
	}

int main()
{
	fast
	#ifndef ONLINE_JUDGE

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

	#endif

	ll t;
	cin >> t;
	for(int i=0; i<t; i++)
	{
		ll a,b,n,s;
		cin >> a >> b >> n >> s;
		cout << solve(a,b,n,s) << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int q;
    cin>>q;
    while(q--){
        long a,b,n,s;
        cin>>a>>b>>n>>s;

        if(s<=b or (s%n==0 and s/n<=a)){
            cout<<"YES\n";
            continue;
        }

        if(s%n<=b and s/n <= a)
            cout<<"YES\n";
        else
            cout<<"NO\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int q;
    cin>>q;
    while(q--){
        long a,b,n,s;
        cin>>a>>b>>n>>s;

        if(s%n<=b and 1ll*a*n+b>=s)
            cout<<"YES\n";
        else
            cout<<"NO\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int q;
    cin>>q;
    while(q--){
        long a,b,n,s;
        cin>>a>>b>>n>>s;

        if(s%n<=b and a*n+b>=s)
            cout<<"YES\n";
        else
            cout<<"NO\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int q;
    cin>>q;
    while(q--){
        long a,b,n,s;
        cin>>a>>b>>n>>s;

        if(s<=b or (s%n==0 and s/n<=a)){
            cout<<"YES\n";
            continue;
        }

        if(s%n<=b and s/n <= a and s-(s/n)*n<=b)
            cout<<"YES\n";
        else
            cout<<"NO\n";
    }
}


#include<bits/stdc++.h>
#define mod 1e9+7
#define ll long long
#define ull unsigned long long
using namespace std;
int main(){
    int q;
    cin>>q;
    while(q--){
        long int a,b,n,s;
        cin>>a>>b>>n>>s;

        if(s<=b){
            cout<<"YES\n";
            continue;
        }

        // int x_min = (s-b)/n;
        int x_max = (s)/n;

        if((x_max<=a and s-n*x_max<=b))
            cout<<"YES\n";
        else
            cout<<"NO\n";
    }
}


#include<bits/stdc++.h>
#define mod 1e9+7
#define ll long long
#define ull unsigned long long
using namespace std;
int main(){
    int q;
    cin>>q;
    while(q--){
        long int a,b,n,s;
        cin>>a>>b>>n>>s;

        if(s<=b){
            cout<<"YES\n";
            continue;
        }
        int x_min = (s-b)/n;
        int x_max = (s)/n;

        if((x_max<=a and s-n*x_max<=b) or (x_min<=a and s-n*x_min<=b))
            cout<<"YES\n";
        else
            cout<<"NO\n";
    }
}


#include<bits/stdc++.h>
#define mod 1e9+7
#define ll long long
#define ull unsigned long long
using namespace std;
int main(){
    int q;
    cin>>q;
    while(q--){
        long int a,b,n,s;
        cin>>a>>b>>n>>s;

        if(s<=b or (s%n==0 and s/n<=a)){
            cout<<"YES\n";
            continue;
        }

        int x_min = (s-b)/n;
        int x_max = s/n;

        if((x_max<=a and s-n*x_max<=b) or (x_min<=a and s-n*x_min<=b))
            cout<<"YES\n";
        else
            cout<<"NO\n";
    }
}


#include<bits/stdc++.h>
#define mod 1e9+7
#define ll long long
#define ull unsigned long long
using namespace std;
int main(){
    long q;
    cin>>q;
    while(q--){
        long a,b,n,s;
        cin>>a>>b>>n>>s;

        if(s<=b or (s%n==0 and s/n<=a)){
            cout<<"YES\n";
            continue;
        }

        long x_min = (s-b)/n;
        long x_max = s/n;

        if((x_max<=a and s-n*x_max<=b) or (x_min<=a and s-n*x_min<=b))
            cout<<"YES\n";
        else
            cout<<"NO\n";
    }
}


#include<bits/stdc++.h>
#define mod 1e9+7
#define ll long long
#define ull unsigned long long
using namespace std;
int main(){
    int q;
    cin>>q;
    while(q--){
        int a,b,n,s;
        cin>>a>>b>>n>>s;
        int x_max=(s-b)/n;
        if((s-b)%n!=0)
            x_max++;
        // cout<<x_max;
        if(x_max<=a and s-x_max*n<=b and s-x_max*n>=0)
            cout<<"YES\n";
        else
            cout<<"NO\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int q;
    cin>>q;
    while(q--){
        long a,b,n,s;
        cin>>a>>b>>n>>s;

        int c=b/n;
        a+=c;
        b=b%n;

        if(s<=b or (s%n==0 and s/n<=a)){
            cout<<"YES\n";
            continue;
        }

        if(s%n<=b and s/n <= a)
            cout<<"YES\n";
        else
            cout<<"NO\n";
    }
}


#include<bits/stdc++.h>
#define mod 1e9+7
#define ll long long
#define ull unsigned long long
using namespace std;
int main(){
    int q;
    cin>>q;
    while(q--){
        long int a,b,n,s;
        cin>>a>>b>>n>>s;

        if(s<=b or (s%n==0 and s/n<=a)){
            cout<<"YES\n";
            continue;
        }

        long x_min = (s-b)/n;
        long x_max = s/n;

        if((x_max<=a and s-n*x_max<=b) or (x_min<=a and s-n*x_min<=b))
            cout<<"YES\n";
        else
            cout<<"NO\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,n,s,flag=0,x,y;
        cin>>a>>b>>n>>s;
        x=(s/n);
        y=s%n;
            if((y<b) && ((x*n)+b)>=s)
            flag=1;
        if(flag==1)
        cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,n,s,flag=0,x,y;
        cin>>a>>b>>n>>s;
        x=(s/n);
        y=s%n;
            if((y<=b) && ((x*n)+b)>=s)
            flag=1;
        if(flag==1)
        cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,n,s,x,sum=0,i,flag=0;
        cin>>a>>b>>n>>s;
       for(i=1;i<=a;i++)
       {
           sum=(i*n);
           if(sum>s)
           {
               break;
           }
       }
       if(sum<s)
       {
           sum+=b;
           if(sum>=s)
            {
            flag=1;
           }
       }
       else if(sum>s)
       {
           sum-=(n);
           if(sum<s)
           {
               sum+=b;
               if(sum>=s)
               {
                   flag=1;
               }
           }
       }
       if(flag==1)
        cout<<"YES"<<endl;
       else
        cout<<"NO"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,n,s,flag=0,x,y;
        cin>>a>>b>>n>>s;
        x=(s/n);
        y=s%n;
            if(x<=a && b>=y)
            {
            flag=1;
            }
        if(flag==1)
        cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,n,s,flag=0,x,y;
        cin>>a>>b>>n>>s;
        x=(s/n);
        y=s%n;
        if(x>a)
        {
            flag=1;
        }
        else
        {
            if(((x*n)+b)<s)
            flag=1;
        }
        if(flag==1)
        cout<<"NO"<<endl;
        else
            cout<<"YES"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,n,s,flag=0,x,y;
        cin>>a>>b>>n>>s;
        x=(s/n);
        y=s%n;
            if(x<=a && y<=b)
            {
            flag=1;
            }
        if(flag==1)
        cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,n,s,x,sum=0,i,flag=0;
        cin>>a>>b>>n>>s;
       for(i=1;i<=n;i++)
       {
           sum=(i*a);
           if(sum>s)
           {
               break;
           }
       }
       if(sum<s)
       {
           sum+=b;
           if(sum>=s)
            {
            flag=1;
           }
       }
       else if(sum>s)
       {
           sum-=(n);
           if(sum<s)
           {
               sum+=b;
               if(sum>=s)
               {
                   flag=1;
               }
           }
       }
       if(flag==1)
        cout<<"YES"<<endl;
       else
        cout<<"NO"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,n,s,flag=0,x,y;
        cin>>a>>b>>n>>s;
        x=(s/n);
        y=s%n;
            if(((min(x,a)*n)+b)>=s)
            {
            flag=1;
            }
        if(flag==1)
        cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,n,s,flag=0,x,y;
        cin>>a>>b>>n>>s;
        x=(s/n);
            if(x<=a)
            {
            if(((x*n)+b)>=s)
            {
            flag=1;
            }
            }
        if(flag==1)
        cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,n,s,x,sum=0,i;
        cin>>a>>b>>n>>s;
       for(i=1;i<=n;i++)
       {
           sum=(i*a);
           if(sum>s)
           {
               break;
           }
       }
       if(sum<s)
       {
           sum+=b;
           if(sum>=s)
            cout<<"YES"<<endl;
           else
            cout<<"NO"<<endl;
       }
       else if(sum>s)
       {
           sum-=(n+b);
           if(sum>=s)
            cout<<"YES"<<endl;
           else
            cout<<"NO"<<endl;
       }
       else if(sum==s)
        cout<<"YES"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,n,s,flag=0,x,y;
        cin>>a>>b>>n>>s;
        x=(s/n);
        y=s%n;
            if((y>=b) && ((x*n)+b)>=s)
            flag=1;
        if(flag==1)
        cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        int a,b,n,s;
        cin>>a>>b>>n>>s;
        if(a*n+b==s)
            cout<<"YES"<<'\n';
        if(a*n+b>s)
        {
            if(s>a*n)
            {
                if((s-a*n)%b==0||b>(s-a*n))
                cout<<"YES"<<'\n';
                else
                cout<<"NO"<<'\n';
            }
          if((a*n>s))
          {
                if((a*n-s)%b==0||b>(a*n-s))
                cout<<"YES"<<'\n';
                else
                cout<<"NO"<<'\n';
          }
        }
        if(a*n+b<s)
            cout<<"NO"<<'\n';
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll int t;
    cin>>t;
    while(t--)
    {
        ll int a,b,n,s;
        cin>>a>>b>>n>>s;
        ll int x=a*n+b;
        if(x==s)
        {
            cout<<"YES"<<'\n';
        }
        else if(x<s)
        {
            cout<<"NO"<<'\n';
        }
        else
        {
            ll int y=s%n;
            if(y<=b)
            {
                cout<<"YES"<<'\n';
            }
            else
            {
                cout<<"NO"<<'\n';
            }
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,z;
    cin>>t;
    for(int i=0;i<t;i++)
   {
       int a,b,n,s;
       cin>>a>>b>>n>>s;
       if((a*n+b)<s)
       {
           cout<<"NO"<<'\n';
       }
       else
       {
          z=a*n;
          if(z>s)
          {
              if((z-s)%b==0||b>(z-s)||b==s)
              {
                  cout<<"YES"<<'\n';
              }
              else
              {
                  cout<<"NO"<<'\n';
              }
          }
          else
          {
              if((s-z)%b==0||b>(s-z)||b==s)
              {
                  cout<<"YES"<<'\n';
              }
              else
              {
                  cout<<"NO"<<'\n';
              }
          }
       }
   }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        int a,b,n,s;
        cin>>a>>b>>n>>s;
        if(a*n+b==s)
            cout<<"YES"<<'\n';
        if(a*n+b>s)
        {
            if(s>a*n)
            {
                if((s-a*n)%b==0||b>(s-a*n))
                cout<<"YES"<<'\n';
                else
                cout<<"NO"<<'\n';
            }
          if((a*n>s))
          {
                if((a*n-s)%b==0||b>(a*n-s))
                cout<<"YES"<<'\n';
                else
                cout<<"NO"<<'\n';
          }
        }
        if(a*n+b<s)
        {
            if(a*n==s||b==s)
                cout<<"YES"<<'\n';
            else
                cout<<"NO"<<'\n';
        }

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,z;
    cin>>t;
    for(int i=0;i<t;i++)
   {
       int a,b,n,s;
       cin>>a>>b>>n>>s;
       if((a*n+b)<s)
       {
           cout<<"NO"<<'\n';
       }
       else
       {
          z=a*n;
          if(z>s)
          {
              if((z-s)%b==0||b>(z-s))
              {
                  cout<<"YES"<<'\n';
              }
              else
              {
                  cout<<"NO"<<'\n';
              }
          }
          else
          {
              if((s-z)%b==0||b>(s-z))
              {
                  cout<<"YES"<<'\n';
              }
              else
              {
                  cout<<"NO"<<'\n';
              }
          }
       }
   }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        int a,b,n,s;
        cin>>a>>b>>n>>s;
        if(a*n+b==s)
            cout<<"YES"<<'\n';
        if(a*n+b>s)
        {
            if(s>a*n)
            {
                if((s-a*n)%b==0||b>(s-a*n))
                cout<<"YES"<<'\n';
                else
                cout<<"NO"<<'\n';
            }
          if((a*n>s))
          {
                if((a*n-s)%b==0||b>(a*n-s)||b==s)
                cout<<"YES"<<'\n';
            else
            cout<<"NO"<<'\n';

          }
        }
        if(a*n+b<s)
        {
            if(a*n==s||b==s)
                cout<<"YES"<<'\n';
            else
                cout<<"NO"<<'\n';
        }

    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll int t;
    cin>>t;
    for(int i=0;i<t;i++)
   {
       ll int a,b,n,s;
       cin>>a>>b>>n>>s;
       ll int y=a*n+b;
       if(y<s)
       {
           cout<<"NO"<<'\n';
       }
       else
       {
           ll int x=y-s;
           if(y%n==0)
           {
               cout<<"YES"<<'\n';
               break;
           }
           else
           {
               if(b<x)
                cout<<"NO"<<'\n';
               else
                cout<<"YES"<<'\n';
           }
       }
   }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        int a,b,n,s;
        cin>>a>>b>>n>>s;
        if(a*n+b==s)
            cout<<"YES"<<'\n';
        if(a*n+b<s)
        {
            if(s>a*n)
            {
                if((s-a*n)%b==0||b>(s-a*n))
                cout<<"YES"<<'\n';
                else
                cout<<"NO"<<'\n';
            }
          if((a*n>s))
          {
                if((a*n-s)%b==0||b>(a*n-s))
                cout<<"YES"<<'\n';
                else
                cout<<"NO"<<'\n';
          }
        }
        if(a*n+b>s)
        {
            if(a*n==s||b==s)
                cout<<"YES"<<'\n';
            else
                cout<<"NO"<<'\n';
        }

    }
}


#include<stdio.h>
void check(long int a, long int b,long int n, long int s){
	long int j = s/n;
	long int k = s%n;
//	printf("%d %d %d %d", j, k, a, b);
 	if ((a == 0 && s <= b) || ((j <= a && k <= b) || (j <= a && k == 0)))
        	printf("YES\n");
        else
        	printf("NO\n");
}

int main(){
    int t;
	long int a,b,n,s;
    	scanf("%d",&t);
    	for(int i = 0;i<t;i++){
        	scanf("%ld%ld%ld%ld",&a,&b,&n,&s);
        	check(a,b,n,s);
    	}
    return 0;
}


#include<stdio.h>
void check(int a, int b, int n, int s){
	int j = s/n;
	int k = s%n;
//	printf("%d %d %d %d", j, k, a, b);
 	if ((a == 0 && s <= b) || ((j <= a && k <= b) || (j <= a && k == 0)))
        	printf("YES\n");
        else
        	printf("NO\n");
}

int main(){
	int t,a,b,n,s;
    	scanf("%d",&t);
    	for(int i = 0;i<t;i++){
        	scanf("%d%d%d%d",&a,&b,&n,&s);
        	check(a,b,n,s);
    	}
    return 0;
}


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

static void test(){
	unsigned long long a, b, n, s;
	scanf("%lld%lld%lld%lld", &a, &b, &n, &s);
	if( (a*n + b >= s) && ( (s - n * (long long)(s/n) )<=b))
		printf("YES\n");
	else
		printf("NO\n");
}

int main(){
	int t;
	scanf("%d", &t);
	for(int i=0; i<t; i++)
		test();
	return 0;
}


#include<stdio.h>
void check(int a, int b, int n, int s){
	int j = s/n;
	int k = s%n;
//	printf("%d %d %d %d", j, k, a, b);
 	if ((a == 0 && s <= b) || (((j <= a && k <= b)||(j>= a && k <= b)) || (j <= a && k == 0)))
        	printf("YES\n");
        else
        	printf("NO\n");
}

int main(){
	int t,a,b,n,s;
    	scanf("%d",&t);
    	for(int i = 0;i<t;i++){
        	scanf("%d%d%d%d",&a,&b,&n,&s);
        	check(a,b,n,s);
    	}
    return 0;
}


#include<stdio.h>
void check(int a, int b, int n, int s){
	int j = s/n;
	int k = s%n;
//	printf("%d %d %d %d", j, k, a, b);
 	if ((a == 0 && s <= b) || (((j <= a && k <= b)||(j>= a && (k <= b && k !=0))) || (j <= a && k == 0)))
        	printf("YES\n");
        else
        	printf("NO\n");
}

int main(){
	int t,a,b,n,s;
    	scanf("%d",&t);
    	for(int i = 0;i<t;i++){
        	scanf("%d%d%d%d",&a,&b,&n,&s);
        	check(a,b,n,s);
    	}
    return 0;
}


#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int q;
cin>>q;
    int y=0;
    for(int j=0;j<q;j++)
    {
       long long int a,b,n,s;
             cin>>a>>b>>n>>s;
  if(n!=1)
  {
    if(b>=s%n&&a>=s/n)
    cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;
    }
    else
    {
      if(a+b>=s)
      cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;
      }
    }
    return 0;
}


#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int q;
cin>>q;
    for(int j=0;j<q;j++)
    {
      long long int a,b,n,s;
      cin>>a>>b>>n>>s;
      if(n!=1)
      {
      if(a*n+b==s)
       cout<<"YES"<<endl;
       else if(a*n+b<s)
       cout<<"NO"<<endl;
       else
       {
           if(a*n<=s)
            cout<<"YES"<<endl;
            else
            {
                long long int p=s%n;
                if(p<=b)
                cout<<"YES"<<endl;
                else
                cout<<"NO"<<endl;
            }
       }
      }
      else
      {
          if(a+b>=s)
           cout<<"YES"<<endl;
                else
                cout<<"NO"<<endl;
      }
    }
    return 0;
}


#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int q;
cin>>q;
    int y=0;
    for(int j=0;j<q;j++)
    {
        bool flag=false;
        int a,b,n,s;
             cin>>a>>b>>n>>s;
    for(int i=0;i<=a;i++)
    {
        y=s-i*n;
        if(ceil(y)==floor(y)&&y>=0&&y<=b)
        {
           flag=true;
        }
    }
    if(flag)
    cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;
    }
    return 0;
}


#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int q;
cin>>q;
    float x=0;
    for(int j=0;j<q;j++)
    {
        bool flag=false;
       long long int a,b,n,s;
             cin>>a>>b>>n>>s;
       for(int i=0;i<=b;i++)
       {
           x=(float)(s-i)/n;
          if(ceil(x)==floor(x)&&x<=a)
          {
              flag=true;
              break;
          }
       }
       if(flag)
       cout<<"YES"<<endl;
       else
       cout<<"NO"<<endl;
      }
    return 0;
}


#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int q;
cin>>q;
    for(int j=0;j<q;j++)
    {
      int a,b,n,s;
      cin>>a>>b>>n>>s;
      if(n!=1)
      {
      if(a*n+b==s)
       cout<<"YES"<<endl;
       else if(a*n+b<s)
       cout<<"NO"<<endl;
       else
       {
           if(a*n<=s)
            cout<<"YES"<<endl;
            else
            {
                int p=s%n;
                if(p<=b)
                cout<<"YES"<<endl;
                else
                cout<<"NO"<<endl;
            }
       }
      }
      else
      {
          if(a+b>=s)
           cout<<"YES"<<endl;
                else
                cout<<"NO"<<endl;
      }
    }
    return 0;
}


#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int q;
cin>>q;
    int y=0;
    for(int j=0;j<q;j++)
    {
       long long int a,b,n,s;
             cin>>a>>b>>n>>s;
  if(n!=1)
  {
    if(a*n+b>=s)
    cout<<"YES"<<endl;
    else if(s)
    cout<<"NO"<<endl;
    }
    else
    {
      if(a+b>=s)
      cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;
      }
    }
    return 0;
}


#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int q;
cin>>q;
    int y=0;
    for(int j=0;j<q;j++)
    {
       long long int a,b,n,s;
             cin>>a>>b>>n>>s;

    if(b>=s%n&&a>=s/n)
    cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;
    }
    return 0;
}


#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int q;
cin>>q;
    int y=0;
    for(int j=0;j<q;j++)
    {
       long long int a,b,n,s;
             cin>>a>>b>>n>>s;
  if(n!=1)
  {
    if(b>=s%n&&a>=s/n)
    cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;
    }
    }
    else
    {
      if(a+b>=s)
      cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;
      }
    return 0;
}


#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int q;
cin>>q;
    int y=0;
    for(int j=0;j<q;j++)
    {
        bool flag=false;
       long long int a,b,n,s;
             cin>>a>>b>>n>>s;
    for(long long int i=0;i<=a;i++)
    {
        y=s-i*n;
        if(ceil(y)==floor(y)&&y>=0&&y<=b)
        {
           flag=true;
        }
    }
    if(flag)
    cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;
    }
    return 0;
}


#include <iostream>
#include <cmath>
using namepace std;
int main()
{
    int a,b,n,s,q;
    cin>>q>>a>>b>>n>>s;
    for(int j=0;j<q;j++)
    {
        bool flag=false;
    for(int i=0;i<=a;i++)
    {
        y=s-i*n;
        if(ceil(y)==floor(y)&&y>=0&&y<=b)
        {
           flag=true;
        }
    }
    if(flag)
    cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;
    }
    return 0;
}


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

bool f(int a, int b, int n, int S){
  if((S<=a*n+b) & (S/n<=a) & (S%n <=b)){
    return true;
  }
  return false;
}

int main()
{
  int qq, a, b, n , S;
  cin>>qq;
  for(int q = 0; q< qq; ++q){
    cin>>a>>b>>n>>S;
    if(f(a, b, n, S)) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
}


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

bool f(int a, int b, int n, int S){
        for(int x = 0; x<=a; ++x)
        for(int y = 0; y<=b; ++y){
            if(x*n+y==S){
                return true;
            }
        }
        return false;
    }

int main()
{
  int qq, a, b, n , S;
  cin>>qq;
  for(int q = 0; q< qq; ++q){
    cin>>a>>b>>n>>S;
    if(f(a, b, n, S)) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
}


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

bool f(int a, int b, int n, int S){
  if(a*n+b<S) return false;

  for(int x = 0; x<=S/n; ++x)
    if(S-n*x <= b){
      return true;
    }
        return false;
}

int main()
{
  int qq, a, b, n , S;
  cin>>qq;
  for(int q = 0; q< qq; ++q){
    cin>>a>>b>>n>>S;
    if(f(a, b, n, S)) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
}


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

bool f(int a, int b, int n, int S){
  if((S<=a*n+b)){
    if((S%n)<=b){
      return true;
    }
  }
  return false;
}

int main()
{
  int qq, a, b, n , S;
  cin>>qq;
  for(int q = 0; q< qq; ++q){
    cin>>a>>b>>n>>S;
    if(f(a, b, n, S)) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
}


#include <iostream>
#include <string>
#define LL long long
using namespace std;
bool f(LL a, LL b, LL n, LL S){
  if((S<=a*n+b)){
    if((S%n)<=b){
      return true;
    }
  }
  return false;
}

int main()
{
  LL qq, a, b, n , S;
  cin>>qq;
  for(int q = 0; q< qq; ++q){
    cin>>a>>b>>n>>S;
    if(f(a, b, n, S)) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
}


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

bool f(int a, int b, int n, int S){
  if(a*n+b<S) return false;
  if(S-n*(S/n) <= b){
    return true;
  }
  return false;
}

int main()
{
  int qq, a, b, n , S;
  cin>>qq;
  for(int q = 0; q< qq; ++q){
    cin>>a>>b>>n>>S;
    if(f(a, b, n, S)) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
}


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

bool f(int a, int b, int n, int S){
  if(S/n<=a & S%n <=b){
    return true;
  }
  return false;
}

int main()
{
  int qq, a, b, n , S;
  cin>>qq;
  for(int q = 0; q< qq; ++q){
    cin>>a>>b>>n>>S;
    if(f(a, b, n, S)) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
}


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

bool f(int a, int b, int n, int S){
  if((S<=a*n+b)){
    if(((S/n<=a) & (S%n <=b)) || (S - (S/n) * a)<=b){
      return true;
    }
  }
  return false;
}

int main()
{
  int qq, a, b, n , S;
  cin>>qq;
  for(int q = 0; q< qq; ++q){
    cin>>a>>b>>n>>S;
    if(f(a, b, n, S)) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
}


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

bool f(int a, int b, int n, int S){
  if(!(S>a*n+b) & (S/n<=a) & (S%n <=b)){
    return true;
  }
  return false;
}

int main()
{
  int qq, a, b, n , S;
  cin>>qq;
  for(int q = 0; q< qq; ++q){
    cin>>a>>b>>n>>S;
    if(f(a, b, n, S)) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
}


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

bool f(int a, int b, int n, int S){
  if(a*n+b<S) return false;

  for(int x = 0; x<=a; ++x)
    if(S-n*x <= b && S-n*x>=0){
      return true;
    }
        return false;
}

int main()
{
  int qq, a, b, n , S;
  cin>>qq;
  for(int q = 0; q< qq; ++q){
    cin>>a>>b>>n>>S;
    if(f(a, b, n, S)) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
}


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

bool f(int a, int b, int n, int S){
  if((S<=a*n+b)){
    if((S - (S/n)*a)<=b){
      return true;
    }
  }
  return false;
}

int main()
{
  int qq, a, b, n , S;
  cin>>qq;
  for(int q = 0; q< qq; ++q){
    cin>>a>>b>>n>>S;
    if(f(a, b, n, S)) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
}


#include<iostream>
using namespace std;
int main(void){
  long long c,a,b,n,S;
  cin>>c;
  for(int i = 0 ;i<c;i++){
    cin>>a>>b>>n>>S;
    if(n*a + b < S){
      cout<<"NO\n";
      continue;
    }
    if(n*a + b >= S && a==1){
      cout<<"YES\n";
      continue;
    }
    S -= b;
    if(S%n == 0) cout<<"YES\n";
    else cout<<"NO\n";
    // if(S>=a*n) S-=(a*n);
    // else{
    //   while(S>=n && a>0){
    //     S -= n;
    //     a--;
    //   }
    // }
    // // cout<<S<<'\n';
    // if(b>=S) cout<<"YES\n";
    // else cout<<"NO\n";
  }
  return 0;
}


#include<iostream>
using namespace std;
int main(void){
  long long c,a,b,n,S;
  cin>>c;
  for(int i = 0 ;i<c;i++){
    cin>>a>>b>>n>>S;
    if(n*a + b < S){
      cout<<"NO\n";
      continue;
    }
    if(S>=a*n) S-=(a*n);
    else{
      while(S>=n && a>0){
        S -= n;
        a--;
      }
    }
    // cout<<S<<'\n';
    if(b>=S) cout<<"YES\n";
    else cout<<"NO\n";
  }
  return 0;
}


#include<iostream>
using namespace std;
int main(void){
  int c;
  cin>>c;
  for(int i = 0 ;i<c;i++){
    long long a,b,n,S,r;
    cin>>a>>b>>n>>S;
    if(a*n + b < S){
      cout<<"NO\n";
      continue;
    }
    long long from = 0, to = a, mid;
    while(from<=to){
      mid = (from + to)/2;
      if(S-mid*n >= 0 && S-mid*n < n){
        r = mid;
        break;
      }
      else if(S-mid*n<S){
        from = mid + 1;
        r = mid;
      }
      // else if(S-mid*n == S){
      //   r = mid;
      //   break;
      // }
      else{
        to = mid-1;
      }
    }
    if(r>a) r=a;
    S = S - r*n;
    if(b>=S) cout<<"YES\n";
    else cout<<"NO\n";
  }
  return 0;
}


#include<iostream>
using namespace std;
int main(void){
  int c;
  cin>>c;
  for(int i = 0 ;i<c;i++){
    long long a,b,n,S,r;
    cin>>a>>b>>n>>S;
    if(a*n + b < S){
      cout<<"NO\n";
      continue;
    }
    long long from = 0, to = a, mid;
    while(from<=to){
      mid = (from + to)/2;
      if(S-mid*n >= 0 && S-mid*n < n){
        r = mid;
        break;
      }
      else if(mid*n<S){
        from = mid + 1;
        r = mid;
      }
      // else if(S-mid*n == S){
      //   r = mid;
      //   break;
      // }
      else{
        to = mid-1;
      }
    }
    S = S - r*n;
    if(b>=S) cout<<"YES\n";
    else cout<<"NO\n";
  }
  return 0;
}


import java.util.Scanner;

public class codef {

	String equ(String st1, String st2)
	{
		if(st1.length()!=st2.length())
		{
			return "no";
		}
		if(st1.length()==1&&st2.length()==1)
		{
			if(st1.equals(st2))
			{
				return "yes";
			}
			else
				return "no";
		}
		else if(st1.equals(st2))
		{
			return "yes";
		}
		else
		{
			String a1 = new String();
			String a2 = new String();
			String b1 = new String();
			String b2 = new String();

			a1 = st1.substring(0,(a1.length()/2));

			b1 = st2.substring(0,(a1.length()/2));

			a2 = st1.substring((a1.length()/2));

			b2 = st2.substring((a1.length()/2));

//			for(int i=0;i<st1.length()/2;i++)
//			{
//				a1+=st1.charAt(i);
//				b1+=st2.charAt(i);
//			}
//			for(int i=st1.length()/2;i<st1.length();i++)
//			{
//				a2+=st1.charAt(i);
//				b2+=st2.charAt(i);
//			}

			String s = equ(a1,b1);
			if(s=="yes")
			{
			  String t = equ(a2,b2);
			  if(t=="yes")
			  {
				return "yes";
			  }
			}
			else
			{
				String k = equ(a1,b2);
				if(k=="yes")
				{
				   String  t = equ(a2,b1);
				   if(t=="yes"){
					return "yes";
				}
				}
			}
			return "no";

		}

	}
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String st1 = sc.next();
		String st2 = sc.next();
		codef code = new codef();

		if(st1.length()<=200000 && st2.length()<=200000)
		{
		String s = code.equ(st1,st2);
	    System.out.print(s);
		}
	}

}


import java.util.Scanner;

public class Pppp {

	public static void main (String ar[]) {

		System.out.println("hhh");
		Scanner sc = new Scanner(System.in);

		String a = sc.nextLine();

		String b = sc.nextLine();

		if(a.length() != b.length()) {

			System.out.println("NO");
		}

		else {

			Pppp pp = new Pppp();

			boolean isEquivalent  = pp.equal(a,b);

			if(isEquivalent) System.out.println("YES");
			else System.out.println("NO");
		}

	}

	boolean equal(String a , String b ) {

		if( a.equals(b)) return true ;

		if(a.length() == 1) {

			if(a.equals(b)) return true;

			else return false;

		}

		String a1 = a.substring(0,(a.length()/2));
		String b1 = b.substring(0,(a.length()/2));

		String a2 = a.substring((a.length()/2));

		String b2 = b.substring((a.length()/2));

		boolean result =( equal (a1,b1) && equal(a2,b2) )|| (equal (a1,b2)&&equal(a2,b1));

		return result;
	}

}


import java.util.Scanner;

public class Pppp {

	public static void main (String ar[]) {

		Scanner sc = new Scanner(System.in);

		String a = sc.nextLine();

		String b = sc.nextLine();

		if(a.length() != b.length()) {

			System.out.println("NO");
		}

		else {

			Pppp pp = new Pppp();

			boolean isEquivalent  = pp.equal(a,b);

			if(isEquivalent) System.out.println("YES");
			else System.out.println("NO");
		}

	}

	boolean equal(String a , String b ) {

		if( a.equals(b)) return true ;

		if(a.length()%2!=0)
			return false;

		if(a.length() == 1) {

			if(a.equals(b)) return true;

			else return false;

		}

		String a1 = a.substring(0,(a.length()/2));
		String b1 = b.substring(0,(a.length()/2));

		String a2 = a.substring((a.length()/2));

		String b2 = b.substring((a.length()/2));

		boolean result =( equal (a1,b1) && equal(a2,b2) )|| (equal (a1,b2)&&equal(a2,b1));

		return result;
	}

}


//package code;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Pppp {

	public static void main (String ar[]) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		Scanner sc = new Scanner(System.in);

		String a = br.readLine();

		String b = br.readLine();

			Pppp pp = new Pppp();

			System.out.println(pp.equal(a,b)?"YES":"NO");

	}

	boolean equal(String a , String b ) {

		if( a.equals(b)) return true ;

		if(a.length()%2 != 0) return false;

		String a1 = a.substring(0,(a.length()/2));
		String b1 = b.substring(0,(a.length()/2));

		String a2 = a.substring((a.length()/2));

		String b2 = b.substring((a.length()/2));

		boolean result =( equal (a1,b1) && equal(a2,b2) )|| (equal (a1,b2)&&equal(a2,b1));

		return result;
	}

}


//package code;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Pppp {

	public static void main (String ar[]) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		Scanner sc = new Scanner(System.in);

		String a = br.readLine();

		String b = br.readLine();

			Pppp pp = new Pppp();

			boolean isEquivalent  = pp.equal(a,b);

			if(isEquivalent) System.out.println("YES");
			else System.out.println("NO");

	}

	boolean equal(String a , String b ) {

		if( a.equals(b)) return true ;

		if(a.length()%2 != 0  || b.length()%2 !=0 ||  a.length() != b.length()) return false;

		if(a.length() == 1) {

			if(a.equals(b)) return true;

			else return false;

		}

		String a1 = a.substring(0,(a.length()/2));
		String b1 = b.substring(0,(a.length()/2));

		String a2 = a.substring((a.length()/2));

		String b2 = b.substring((a.length()/2));

		boolean result =( equal (a1,b1) && equal(a2,b2) )|| (equal (a1,b2)&&equal(a2,b1));

		return result;
	}

}


//package code;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Pppp {

	public static void main (String ar[]) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		Scanner sc = new Scanner(System.in);

		String a = br.readLine();

		String b = br.readLine();

		if(a.length() != b.length()) {

			System.out.println("NO");
		}

		else {

			Pppp pp = new Pppp();

			boolean isEquivalent  = pp.equal(a,b);

			if(isEquivalent) System.out.println("YES");
			else System.out.println("NO");
		}

	}

	boolean equal(String a , String b ) {

		if( a.equals(b)) return true ;

		if(a.length()%2 != 0  || b.length()%2 !=0 ||  a.length() != b.length()) return false;

		if(a.length() == 1) {

			if(a.equals(b)) return true;

			else return false;

		}

		String a1 = a.substring(0,(a.length()/2));
		String b1 = b.substring(0,(a.length()/2));

		String a2 = a.substring((a.length()/2));

		String b2 = b.substring((a.length()/2));

		boolean result =( equal (a1,b1) && equal(a2,b2) )|| (equal (a1,b2)&&equal(a2,b1));

		return result;
	}

}


//package code;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Pppp {

	public static void main (String ar[]) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		Scanner sc = new Scanner(System.in);

		String a = br.readLine();

		String b = br.readLine();

			Pppp pp = new Pppp();

			System.out.println(pp.equal(a,b)?"YES":"NO");

	}

	boolean equal(String a , String b ) {

		if( a.equals(b)) return true ;

		 else if ((a.length() % 2 == 0) && (b.length() % 2 == 0)){

					String a1 = a.substring(0,(a.length()/2));
					String b1 = b.substring(0,(a.length()/2));

					String a2 = a.substring((a.length()/2));

					String b2 = b.substring((a.length()/2));

					boolean result =( equal (a1,b1) && equal(a2,b2) )|| (equal (a1,b2)&&equal(a2,b1));

					return result;
		 }
		 else
			 return false;
	}

}


//package code;

import java.util.Scanner;

public class Codeforce {

	public static void main(String ar[]) {

		Scanner sc = new Scanner(System.in);

		String a = sc.nextLine();

		String b = sc.nextLine();

		System.out.println((equal(a, b))?"YES":"NO");

	}

	static boolean equal(String a , String b) {

		if(  a .equals(b) ) return true;

		if(  a.length() % 2 !=0  || b.length() %2 != 0) return false;

		String a1 = a.substring(0, a.length()/2);

		String a2 = a.substring(a.length()/2);

		String b1 = b.substring(0 , b.length() /2);

		String b2 = b.substring(b.length()/2);

		return  (equal(a1, b1) && equal (a2 , b2) ) || (equal (a1 ,b2 ) && equal (a2,b1));

	}

}


import java.util.Scanner;

public class Pppp {

	public static void main (String ar[]) {

		Scanner sc = new Scanner(System.in);

		String a = sc.nextLine();

		String b = sc.nextLine();

		if(a.length() != b.length()) {

			System.out.println("NO");
		}

		else {

			Pppp pp = new Pppp();

			boolean isEquivalent  = pp.equal(a,b);

			if(isEquivalent) System.out.println("YES");
			else System.out.println("NO");
		}

	}

	boolean equal(String a , String b ) {

		if( a.equals(b)) return true ;

		if(a.length() != b.length()) return false;

		if(a.length() == 1) {

			if(a.equals(b)) return true;

			else return false;

		}

		String a1 = a.substring(0,(a.length()/2));
		String b1 = b.substring(0,(a.length()/2));

		String a2 = a.substring((a.length()/2));

		String b2 = b.substring((a.length()/2));

		boolean result =( equal (a1,b1) && equal(a2,b2) )|| (equal (a1,b2)&&equal(a2,b1));

		return result;
	}

}


import java.io.*;
import java.util.*;

public class Practise {

    public static void main(String[] args)throws IOException {
         Scanner sc= new Scanner(System.in);
        PrintWriter w= new PrintWriter(System.out);

     try {
    	 String s1=sc.next();
    	 String s2=sc.next();

    	if(isEqual(s1,s2)) {
    		w.println("YES");
    	}
    	else {
    		w.println("NO");
    	}

    	w.close();
     }catch(Exception e) {

     }
    }
    static boolean isEqual(String s1,String s2) {
    	if(s1.equals(s2) || s1.length()==1) {
    		return s1.equals(s2);
    	}

    	int n1=s1.length();
    	int n2=s2.length();
    	if(n1%2!=0) return false;
    	String a1=s1.substring(0,n1/2);
    	String a2=s1.substring(n1/2);
    	String b1=s1.substring(0,n2/2);
    	String b2=s1.substring(n2/2);
    return	(isEqual(a1,b1) && isEqual(a2,b2)) || (isEqual(a1,b2) && isEqual(a2,b1));

    }

    static class Reader   // here reader class is defined.
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }

}


import java.io.*;
import java.util.*;

public class Practise {

    public static void main(String[] args)throws IOException {
         Scanner sc= new Scanner(System.in);
        PrintWriter w= new PrintWriter(System.out);

     try {
    	 String s1=sc.next();
    	 String s2=sc.next();

    	if(isEqual(s1,s2)) {
    		w.println("YES");
    	}
    	else {
    		w.println("NO");
    	}

    	w.close();
     }catch(Exception e) {

     }
    }
    static boolean isEqual(String s1,String s2) {
    	if(s1.equals(s2)) {
    		return true;
    	}
    	int n1=s1.length();
    	int n2=s2.length();
    	String a1=s1.substring(0, n1/2);
    	String a2=s1.substring(n1/2,n1);
    	String b1=s2.substring(0, n2/2);
    	String b2=s2.substring(n2/2,n2);
    	Hashtable<Character,Integer>tbl1= new Hashtable<Character, Integer>();
    	Hashtable<Character,Integer>tbl2= new Hashtable<Character, Integer>();
    	for(int i=0;i<a1.length();i++) {
    		if(tbl1.get(a1.charAt(i))==null) {
    			tbl1.put(a1.charAt(i),1 );
    		}
    		else {
    			tbl1.put(a1.charAt(i), tbl1.get(a1.charAt(i))+1);
    		}
    	}
    	boolean check=true;
    	for(int i=0;i<b2.length();i++) {
    		if(tbl2.get(b2.charAt(i))==null) {
    			tbl2.put(b2.charAt(i),1 );
    		}
    		else {
    			tbl2.put(b2.charAt(i), tbl2.get(b2.charAt(i))+1);
    		}
    	}
    //	System.out.println(tbl2);
    	for(int i=0;i<a1.length();i++) {
    		if(tbl2.get(a1.charAt(i))!=null && tbl1.get(a1.charAt(i))==tbl2.get(a1.charAt(i))) {
    			check=true;
    		}
    		else {
    			check=false;
    			return check;
    		}
    	}
//    	System.out.println(tbl1);
//    	System.out.println(tbl2);
    	tbl1.clear();
    	tbl2.clear();
    	for(int i=0;i<a2.length();i++) {
    		if(tbl1.get(a2.charAt(i))==null) {
    			tbl1.put(a2.charAt(i),1 );
    		}
    		else {
    			tbl1.put(a2.charAt(i), tbl1.get(a2.charAt(i))+1);
    		}
    	}
    	for(int i=0;i<b1.length();i++) {
    		if(tbl2.get(b1.charAt(i))==null) {
    			tbl2.put(b1.charAt(i),1 );
    		}
    		else {
    			tbl2.put(b1.charAt(i), tbl2.get(b1.charAt(i))+1);
    		}
    	}
//    	System.out.println(tbl1);
//    	System.out.println(tbl2);
    	check=false;
    	for(int i=0;i<a2.length();i++) {
    		if(tbl2.get(a2.charAt(i))!=null && tbl1.get(a2.charAt(i))==tbl2.get(a2.charAt(i))) {
    			check=true;
    		}
    		else {
    			check=false;
    			return check;
    		}
    	}

    	return check;
    }

    static class Reader   // here reader class is defined.
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }

}


import java.io.*;
import java.util.*;

public class Practise {

    public static void main(String[] args)throws IOException {
         Scanner sc= new Scanner(System.in);
        PrintWriter w= new PrintWriter(System.out);

     try {
    	 String s1=sc.next();
    	 String s2=sc.next();

    	if(eq(s1,s2)) {
    		w.println("YES");
    	}
    	else {
    		w.println("NO");
    	}

    	w.close();
     }catch(Exception e) {

     }
    }
    static boolean eq(String a,String b) {
    	if(a.length()==1||a.equals(b))
    		return a.equals(b);
    	if(a.length()%2!=0)
    		return false;
    	String a1=a.substring(0, a.length()/2);
    	String a2=a.substring(a.length()/2);
    	String b1=b.substring(0, b.length()/2);
    	String b2=b.substring(b.length()/2);
    	//System.out.println(a1+" "+a2+" "+b1+" "+b2);
    		return (eq(a1,b1)&&eq(a2,b2))||(eq(a2,b1)&&eq(a1,b2));

    }

    static class Reader   // here reader class is defined.
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }

}