stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

#define int long long 



const int mod=1e9+7;



int mat[1005][1005];

int ans[1005][1005];





int countPaths(int H,int W){

    ans[0][0]=1;



    for(int i=1;i<H;i++) {

        if(mat[i][0]==1) {

            ans[i][0] = ans[i - 1][0];

        }

    }



    for(int i=1;i<W;i++) {

        if(mat[0][i]!=0) {

            ans[0][i] = ans[0][i - 1];

        }

    }

    

    for(int i=1;i<H;i++) {

        for(int j=1;j<W;j++) {

            if(mat[i][j]!=0)

            {

                ans[i][j] = (ans[i - 1][j] + ans[i][j - 1])%mod;

            }

        }

    }

    

   return ans[H-1][W-1]%mod;

}



#undef int

int main() {

#define int long long

    int H,W;

    cin >> H >> W;

    char x;



    memset(ans,0,sizeof(ans));

    ans[0][0]=1;

    for(int i=0;i<H;i++) {

        for(int j=0;j<W;j++) {

            cin >> x;

            if(x=='.')

                mat[i][j]=1;

            else

                mat[i][j]=0;

        }

    }

     cout << countPaths(H,W)%mod << endl;

     /*

     for (int i = 0; i < H; i++)

     {

         for (int j = 0; j < W; j++)

         {

             cout << ans[i][j] << " ";

         }

         cout << endl;

     }

     */

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

#define int long long



const int mod=1e9+7;

const int nax= 1005;

char mat[nax][nax];

int dp[nax][nax];



#undef int

int main() {

#define int long long

    int H,W;

    cin >> H >> W;

    int ans=0;



    for(int i=0;i<H;i++)

    {

        for(int j=0;j<W;j++)

        {

            cin >> mat[i][j];

        }

    }



    dp[0][0]=1;

    for(int i=1;i<H;i++)

        if(mat[0][i]=='#')

           dp[0][i]=0;

        else

           dp[0][i]=dp[0][i-1];



    for (int i = 1; i < H; i++)

        if (mat[i][0] == '#')

            dp[i][0] = 0;

        else

            dp[i][0] = dp[i-1][0];



    

    for(int i=1;i<H;i++)

    {

        for(int j=1;j<W;j++)

        {

            if(mat[i][j]=='#')

               dp[i][j]=0;

            else

               dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;

        }

    }

    ans=(dp[H-1][W-1]%mod);

    cout << ans << endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define mod 1000000007

char a[1005][1005];

ll dp[1005][1005]={0};



ll solve( int h, int w){

    if(h==1 && w==1) return 1;

    if(h<1 || w<1) return 0;

    if(a[h][w] == '#'){

        return 0;

    }

    if(dp[h][w]!=-1) return dp[h][w];

    ll op1=0,op2=0;

    if(a[h-1][w] != '#')  op1 = solve(h-1,w);

    else op1=0;

    if(a[h][w-1] != '#')  op2 = solve(h,w-1);

    else op2=0;

    

    return dp[h][w] = ( op1+op2 ) %mod;

}

int main() {

    int h,w;

    cin>>h>>w;

    // char a[h][w];

    for(int i=1;i<=h;i++){

        for(int j=1;j<=w;j++){

            cin>>a[i][j];

        }

    }

    

    memset(dp,-1,sizeof dp);

    cout<< solve(h,w)<<endl;



    // for(int i=1;i<=h;i++){

    //     for(int j=1;j<=w;j++){

    //         cout<<dp[i][j]<<" ";

    //     }cout<<endl;

    // }

}


// Optimized solution to the same problem (faster):
#include <iostream>

using namespace std;

#define mod 1000000007

char grid[1001][1001]={0};

int dp[1001][1001];



int main() {

    int h,w;    

    cin>>h>>w;

    for(int i=0;i<h;++i){

        for(int j=0;j<w;j++){

            cin>>grid[i][j];

        }

    }

    // for(int i=0;i<h;++i){

    //     for(int j=0;j<w;j++){

    //         cout<< grid[i][j]<<" ";

    //     }cout<<endl;

    // }

    // cout<<helper(h-1,w-1);

    dp[1][1]=1;

    for(int i=1;i<=h;i++){

        for(int j=1;j<=w;j++){

            if(grid[i-1][j-1]=='#') dp[i][j]=0;

            else dp[i][j]+=(dp[i-1][j] + dp[i][j-1])%mod;

        }

    }

    // for(int i=0;i<=h;++i){

    //     for(int j=0;j<=w;j++){

    //         cout<<dp[i][j]<<" ";

    //     }

    //     cout<<endl;

    // }

    cout<<dp[h][w]<<endl;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <vector>

#include <algorithm>

#include <string>

#include <deque>

#include <list>

#include <map>

#include <queue>

#include <set>

#include <stack>

#include <cstring>

#include <iomanip>



#define rep(i,n) for(int i=0;i<(n);i++)

#define reps(i,n) for(int i=1;i<=(n);i++)

#define Jrep(j,n) for(int j=0;j<(n);j++)

#define Jreps(j,n) for(int j=1;j<=(n);j++)

const int INF = 0x3f3f3f3f;

const long long LINF = 0x3f3f3f3f3f3f3f3fLL;



using namespace std;

int main(){

  cin.tie(0);

  ios::sync_with_stdio(false);

  

  int h,w;

  cin>>h>>w;

  long long sum[1010][1010]={};

  char x;

  sum[1][1]=1;

  reps(i,h){

      Jreps(j,w){

	  cin>>x;

	  if(x=='.'){

	      sum[i][j]+=(sum[i-1][j]+sum[i][j-1])%1000000007;

	  }

      }

  }

  cout<<sum[h][w]<<'\n';

  return 0;

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <vector>

#include <algorithm>

#include <string>

#include <deque>

#include <list>

#include <map>

#include <queue>

#include <set>

#include <stack>

#include <cstring>

#include <iomanip>

#include <utility>



#define rep(i,n) for(int i=0;i<(n);i++)

#define reps(i,n) for(int i=1;i<=(n);i++)

#define lol long long

const int INF = 0x3f3f3f3f;

const long long LINF = 0x3f3f3f3f3f3f3f3fLL;



using namespace std;



int main(){

    cin.tie(0);

    ios::sync_with_stdio(false);



    int h,w;

    cin>>h>>w;



    int dp[1005][1005]={};

    char mas[1005][1005];

    reps(i,h){

	reps(j,w){

	    cin>>mas[i][j];

	}

    }



    dp[1][1]++;

    reps(i,h){

	reps(j,w){



	    if(mas[i][j]!='#'){

		dp[i][j]+=dp[i-1][j]+dp[i][j-1];

		dp[i][j]%=1000000007;

	    }

	

	}

    }



    cout<<dp[h][w]<<'\n';

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll f,c;

char matriz[1005][1005];

ll memo[1005][1005];



ll mod(ll x){

    return x%1000000007;

}



bool validPos(ll i, ll j){

	return i > 0 and j > 0 and i <= f and j <= c;

}

ll dp(ll a,ll b){

    if(memo[a][b]!=-1) return memo[a][b];

    if(a==1 and b==1) return 1;

    else{

        if(matriz[a][b]!='#' and validPos(a,b)){

            memo[a][b]= mod(mod(dp(a,b-1)) + mod(dp(a-1,b)));

        }else{

            memo[a][b]=0;

        }

    }

    return memo[a][b];

}



int main(){

    

    cin>>f>>c;

    memset(memo,-1,sizeof(memo));

    for(int i=0;i<=f;i++) memo[0][i]=0;

    for(int j=0;j<=c;j++) memo[j][0]=0;

    for(int i=1;i<=f;i++){

        for(int j=1;j<=c;j++){

            cin>>matriz[i][j];

        }

    }

    cout<<dp(f,c)<<"\n";

    

}


// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

using ll=long long;

const int N=1e3+10;

const int mod=1e9+7;

char g[N][N];

int dp[N][N];

int h,w;



int main(){

    cin>>h>>w;

    for(int i=1;i<=h;i++){

        for(int j=1;j<=w;j++){

            cin>>g[i][j];

            dp[j][0]=0;

        }

        dp[0][i]=0;

    }

    

    dp[1][1]=1;

    for(int i=1;i<=h;i++){

        for(int j=1;j<=w;j++){

            if(g[i][j]!='#' and (i>1 or j>1)){

                dp[i][j]=(dp[i][j-1] + dp[i-1][j])%mod;

            }

        }

    }

    cout<<(dp[h][w])%mod<<'\n';

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1000 + 5;

int dp[N][N];

char grid[N][N];

int h, w;

const ll mod = 1e9 + 7;



void self_add(int &a, int b) {

    a += b;

    if (a >= mod)

        a -= mod;

}



int solve(int i, int j) {

    if (i == h - 1 && j == w - 1)

        return 1;

    if (i > h - 1 || j > w - 1)

        return 0;

    if (grid[i][j] == '#')

        return 0;

    if (dp[i][j] != -1)

        return dp[i][j];

    int res = 0;

    self_add(res, solve(i + 1, j));

    self_add(res, solve(i, j + 1));

    return dp[i][j] = res % mod;

}



int main() {

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    cin >> h >> w;

    for (int i = 0; i < h; i++)

        for (int j = 0; j < w; j++)

            cin >> grid[i][j];

    memset(dp, -1, sizeof dp);

    cout << solve(0, 0);

    return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1000 + 5;

int dp[N][N];

char grid[N][N];

int h, w;

const ll mod = 1e9 + 7;



void self_add(int &a, int b) {

    a += b;

    if (a >= mod)

        a -= mod;

}



int main() {

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    cin >> h >> w;

    for (int i = 0; i < h; i++)

        for (int j = 0; j < w; j++)

            cin >> grid[i][j];

    dp[0][0] = 1;

    for (int i = 0; i < h; i++) {

        for (int j = 0; j < w; j++) {

            if (!i && !j)

                continue;

            if (grid[i][j] == '#')

                continue;

            if (i)

                self_add(dp[i][j], dp[i - 1][j]);

            if (j)

                self_add(dp[i][j], dp[i][j - 1]);

        }

    }

    cout << dp[h - 1][w - 1];

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define debug(x) cout << #x << " = " << x << '\n'



using ll = long long;

using namespace std;



const int MOD = 1e9 + 7;

const int N = 1010;

char grid[N][N];

int dp[N][N], n, m;



int solve(int i, int j)

{

	if (i == 0 && j == 0)

		return 1;

	int &dp = ::dp[i][j];

	if (grid[i][j] == '#')

		return dp = 0;



	if (dp != -1)

		return dp;

	

	dp = 0;

	if (i > 0)

		dp += solve(i - 1, j);

	if (j > 0)

		dp += solve(i, j - 1);

	dp %= MOD;

	return dp;

}



int main()

{

	ios_base::sync_with_stdio(false);

	cin.tie(nullptr);



#ifdef LOCAL_DEFINE

	freopen("in.txt", "r", stdin);

#endif



	cin >> n >> m;



	for (int i = 0; i < n; ++i)

		for (int j = 0; j < m; ++j)

			cin >> grid[i][j];



	memset(dp, -1, sizeof(dp));



	cout << solve(n - 1, m - 1) << '\n';



	return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



const int N = 1010;

const int MOD = 1e9 + 7;

int dp[N][N], n, m;



inline int add(int a, int b) { if ((a += b) >= MOD) a -= MOD; return a; }



int main() {

   ios_base::sync_with_stdio(0);

   cin.tie(0);

   cin >> n >> m;

   dp[0][1] = 1;

   for (int i = 1; i <= n; ++i) {

      for (int j = 1; j <= m; ++j) {

         char c;

         cin >> c;

         if (c == '.')

            dp[i][j] = add(dp[i][j], add(dp[i - 1][j], dp[i][j - 1]));

         

      }

   }

   cout << dp[n][m] << '\n';

   return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include "bits/stdc++.h"

#pragma GCC optimize "03"

using namespace std;



#define int long long int

#define pb push_back

#define pii pair<int,int>

#define fi first

#define se second

#define rep(i,a,b) for (int i = a; i < b; ++i)

#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }

#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }

#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

#ifndef LOCAL

#define endl '\n'

#endif

const int inf = INT_MAX;

const double eps = 0.0000001;

const double PI = acos(-1.0);

const int MOD = 1e9+7;

const int N  = 1e3+5;



char a[N][N];

int dp[N][N];



int solve (int i, int j) {

	if (a[i][j] == '#') return 0;

	if (i == 1 && j == 1) return 1;

	if (i < 1 || j < 1) return 0;

	if (dp[i][j] != -1) return dp[i][j];

	dp[i][j] = (solve(i-1, j) + solve(i,j -1))%MOD;

	return dp[i][j];

}



signed main(){

    #ifdef LOCAL

        freopen("input.txt", "r", stdin);

        //freopen("output.txt", "w", stdout);

    #endif  

    IOS;



    int n, m;

    cin >> n >> m;

    for (int i = 0; i < N; i++)

    	for (int j = 0; j < N; j++)

    		dp[i][j] = -1;

    for (int i = 1; i <= n; i++) {

    	for (int j = 1; j <= m; j++) {

    		cin >> a[i][j];

    	}

    }

    cout << solve(n, m);

    return 0;

}


// Optimized solution to the same problem (faster):
#include "bits/stdc++.h"

#pragma GCC optimize "03"

using namespace std;



#define int long long int

#define pb push_back

#define pii pair<int,int>

#define fi first

#define se second

#define rep(i,a,b) for (int i = a; i < b; ++i)

#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }

#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }

#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

#ifndef LOCAL

#define endl '\n'

#endif

const int inf = INT_MAX;

const double eps = 0.0000001;

const double PI = acos(-1.0);

const int MOD = 1e9+7;

const int N  = 1e3+5;



char a[N][N];

int dp[N][N], ready[N][N];



int solve (int i, int j) {

	if (a[i][j] == '#') return 0;

	if (i == 1 && j == 1) return 1;

	if (i < 1 || j < 1) return 0;

	if (ready[i][j]) return dp[i][j];

	dp[i][j] = (solve(i-1, j) + solve(i,j -1))%MOD;

	ready[i][j] = 1;

	return dp[i][j];

}



signed main(){

    #ifdef LOCAL

        freopen("input.txt", "r", stdin);

        //freopen("output.txt", "w", stdout);

    #endif  

    IOS;



    int n, m;

    cin >> n >> m;

    for (int i = 1; i <= n; i++) {

    	for (int j = 1; j <= m; j++) {

    		cin >> a[i][j];

    	}

    }

    cout << solve(n, m);

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cmath>

#include<algorithm>

#include<bits/stdc++.h>

using namespace std;



int h, w;

char path[1001][1001];

long long  memo[1001][1001];

long long numberofpath(int i, int j)

{

	long long answer = 0; 

	if (i < 0 || j < 0 || i == h || j == w) return 0;

	else if (i == h-1 && j == w-1) return 1;

	else if (path[i][j] == '#') return 0; 

	else

	{

		if (memo[i][j] != -1) return memo[i][j];

		else

		{

			answer = (answer +  numberofpath(i + 1, j )) % (long long)(1e9+7);

			answer = (answer + numberofpath(i, j+1)) % (long long)(1e9 + 7);

		}

	}



	return memo[i][j] = answer;

}





int main()

{

	memset(memo,-1, sizeof memo);

	cin >> h >> w; 

	for (int i = 0; i < h; i += 1)

		for (int j = 0; j < w; j++)

			cin >> path[i][j];



	cout << numberofpath(0,0) << endl;

	cout << endl;



	system("pause");

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

typedef long long  ll;

char b;

bool a[1005][1005];

ll man=1e9+7;

ll dp[1005][1005];

ll h,w,ans;

int main()

{

	int i,j;

	cin>>h>>w;

	for(i=1;i<=h;i++)

	{

		for(j=1;j<=w;j++)

		{

			cin>>b;

			if(b=='.')

			a[i][j]=1;

			else

			a[i][j]=0;

		}

	}

	dp[1][1]=1;

	for(i=1;i<=h;i++)

	{

		for(j=1;j<=w;j++)

		{

			if(!(i==1&&j==1))

			if(a[i][j]==1)

			dp[i][j]=(dp[i][j-1]+dp[i-1][j])%man;

			else

			dp[i][j]=0;

		}	

	}

	

	cout<<dp[h][w];

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;

typedef long long ll;

typedef double dd;

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

#define endl "\n"

#define clr(n, r) memset(n,r,sizeof(n));



void fast() {



    cin.tie(0);

    cin.sync_with_stdio(0);

}



long long binpow(long long a, long long b, long long m) {

    a %= m;

    long long res = 1;

    while (b > 0) {

        if (b & 1)

            res = res * a % m;

        a = a * a % m;

        b >>= 1;

    }

    return res;

}



const ll mod = 1e9 + 7;

ll n, m, dp[1000 + 9][1000 + 9];

char arr[1000][1000];



ll ans(ll i, ll j) {

    ll &ret=dp[i][j];

    if(~ret)return ret;

    if (i == n || j == m||arr[i][j]=='#')return 0;

    if (i == n - 1 && j == m - 1)return 1;

    ll path1 = ans(i + 1, j) % mod;

    ll path2 = ans(i, j + 1) % mod;

    return ret=(path1+path2)%mod;

}



int main() {

    fast();

    cin >> n >> m;

    for (int i = 0; i < n; ++i) {

        for (int j = 0; j < m; ++j) {

            cin >> arr[i][j];

        }

    }

    clr(dp,-1);

    cout << ans(0, 0);

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

typedef long long  ll;

char b;

bool a[1005][1005];

ll man=1e9+7;

ll dp[1005][1005];

ll h,w,ans;

int main()

{

	int i,j;

	cin>>h>>w;

	for(i=1;i<=h;i++)

	{

		for(j=1;j<=w;j++)

		{

			cin>>b;

			if(b=='.')

			a[i][j]=1;

			else

			a[i][j]=0;

		}

	}

	dp[1][1]=1;

	for(i=1;i<=h;i++)

	{

		for(j=1;j<=w;j++)

		{

			if(!(i==1&&j==1))

			if(a[i][j]==1)

			dp[i][j]=(dp[i][j-1]+dp[i-1][j])%man;

			else

			dp[i][j]=0;

		}	

	}

	

	cout<<dp[h][w];

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e5+10;

int n;

struct node{

	int id,val;

}a[N],b[N];

bool cmp(const node &a,const node &b)

{

	return a.val<b.val;

}

bool cmp2(const node &a,const node &b)

{

	return a.id<b.id;

}

map<int,int>mp;

int main()

{

	cin>>n;

	for(int i=1;i<=n;i++)

	{

		cin>>a[i].val;

		a[i].id=i;

	}

	for(int i=1;i<=n;i++)

	{

		cin>>b[i].val;

		b[i].id=i;

	}

	sort(a+1,a+n+1,cmp);

	sort(b+1,b+n+1,cmp);

	for(int i=1;i<=n;i++)

	{

		if(b[i].val<a[i].val)

		{

			cout<<"No\n";

			return 0;

		}

	}

	for(int i=1;i<n;i++)

	{

		if(b[i].val>=a[i+1].val)

		{

			cout<<"Yes\n";

			return 0;

		}

	}

	for(int i=1;i<=n;i++)

	b[i].val=min(b[i].val,a[i].val);

	sort(a+1,a+n+1,cmp2);

	sort(b+1,b+n+1,cmp2);

	for(int i=1;i<=n;i++)

	mp[b[i].val]=i;

	int cnt=0;

	for(int i=1;i<=n;i++)

	{

		if(a[i].val==b[i].val)

		continue;

		int pos=mp[a[i].val];

		cnt++;

		swap(mp[b[i].val],mp[a[i].val]);

		swap(b[i].val,b[pos].val);

	}

	if(cnt>n-2)

	cout<<"No\n";

	else

	cout<<"Yes\n";

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

#include <cstring>

#include <cctype>

using namespace std;



namespace zyt

{

	template<typename T>

	inline bool read(T &x)

	{

		char c;

		bool f = false;

		x = 0;

		do

			c = getchar();

		while (c != EOF && c != '-' && !isdigit(c));

		if (c == EOF)

			return false;

		if (c == '-')

			f = true, c = getchar();

		do

			x = x * 10 + c - '0', c = getchar();

		while (isdigit(c));

		if (f)

			x = -x;

		return true;

	}

	template<typename T>

	inline void write(T x)

	{

		static char buf[20];

		char *pos = buf;

		if (x < 0)

			putchar('-'), x = -x;

		do

			*pos++ = x % 10 + '0';

		while (x /= 10);

		while (pos > buf)

			putchar(*--pos);

	}

	const int N = 1e5 + 10;

	int n, a[N], b[N], fa[N], ida[N], idb[N];

	int f(const int x)

	{

		return x == fa[x] ? x : fa[x] = f(fa[x]);

	}

	bool cmpa(const int i, const int j)

	{

		return a[i] < a[j];

	}

	bool cmpb(const int i, const int j)

	{

		return b[i] < b[j];

	}

	int work()

	{

		read(n);

		for (int i = 1; i <= n; i++)

			read(a[i]), ida[i] = i;

		for (int i = 1; i <= n; i++)

			read(b[i]), idb[i] = i;

		sort(ida + 1, ida + n + 1, cmpa);

		sort(idb + 1, idb + n + 1, cmpb);

		for (int i = 1; i <= n; i++)

		{

			fa[i] = i;

			if (a[ida[i]] > b[idb[i]])

			{

				puts("No");

				return 0;

			}

		}

		for (int i = 1; i <= n; i++)

			if (i && a[ida[i]] <= b[idb[i - 1]])

			{

				puts("Yes");

				return 0;

			}

		int cnt = 0;

		for (int i = 1; i <= n; i++)

		{

			int x = f(ida[i]), y = f(idb[i]);

			if (x == y)

				++cnt;

			else

				fa[x] = y;

		}

		if (cnt > 1)

			puts("Yes");

		else

			puts("No");

		return 0;

	}

}

int main()

{

	return zyt::work();

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define ll long long

using namespace std;

#define maxn 100010

#define mod 1000000007

struct cv{

    int x,y;

}a[maxn];

int b[maxn];

int cnt;

set<int>s[maxn];

int dp[maxn],du[maxn];

bool cmp(cv p,cv q){

    if(p.x!=q.x) return p.x<q.x;

    return p.y<q.y;

}

int main(){

    int n;

    scanf("%d",&n);

    for(int i=0;i<n;i++) scanf("%d",&a[i].x);

    for(int i=0;i<n;i++) scanf("%d",&a[i].y),b[i]=a[i].y;

    sort(a,a+n,cmp);

    sort(b,b+n);

    cnt=0;

    int flag=0;

    for(int i=0;i<n;i++){

        if(a[i].x>b[i]){

            printf("No\n");

            return 0;

        }

        if(i<n-1&&a[i+1].x<b[i]) flag=1;

        if(i!=0){

            if(b[i]==b[i-1]) flag=1;

        }

        if(i!=0&&a[i].x!=a[i-1].x){

            cnt++;

            s[cnt].insert(a[i].y);

        }

        else{

            s[cnt].insert(a[i].y);

            if(i!=0) flag=1;

        }

    }

    cnt=0;

    if(flag){

        printf("Yes\n");

        return 0;

    }

    for(int i=0;i<n;i++){

        dp[lower_bound(b,b+n,a[i].y)-b]=i;

    }

    cnt=0;

    for(int i=0;i<n;i++){

        if(du[i]) continue;

        cnt++;

        du[i]=1;

        int x=dp[i];

        while(du[x]==0){

            du[x]=1;

            x=dp[x];

        }

    }

    if(cnt>=2) printf("Yes\n");

    else printf("No\n");

    return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



namespace TYC

{

	typedef long long ll;

	typedef pair<int, int> pii;

	const int N = 1e5 + 5;



	int n, A[N], B[N], P[N];

	map<int, int> idA, idB;



	inline int read()

	{

		int x = 0, f = 0, ch = getchar();

		while (!isdigit(ch))

			f |= (ch == '-'), ch = getchar();

		while (isdigit(ch))

			x = x * 10 + ch - '0', ch = getchar();

		return f ? -x : x;

	}



	inline void End(const int t)

	{

		puts(t ? "Yes" : "No");

		exit(0);

	}



	void work()

	{

		n = read();

		for (int i = 1; i <= n; i++)

			A[i] = read(), idA[A[i]] = i;

		for (int i = 1; i <= n; i++)

			B[i] = read(), idB[B[i]] = i;

		sort(A + 1, A + 1 + n);

		sort(B + 1, B + 1 + n);

		for (int i = 1; i <= n; i++)

			if (A[i] > B[i])

				End(0);

		for (int i = 1; i < n; i++)

			if (A[i] == A[i + 1] || B[i] == B[i + 1])

				End(1);

		for (int i = 1; i <= n; i++)

			if (i < n && A[i + 1] <= B[i])

				End(1);

			else

				P[idA[A[i]]] = idB[B[i]];

		int c = 1, u = P[1];

		while (u != 1)

			c++, u = P[u];

		End(c != n);

	}

}



int main()

{

	TYC::work();

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <string>

#include <algorithm>

using namespace std;

string s;

const int Kmax=1e7;

int sum[Kmax];

int R[Kmax];

 

int main()

{

    int n;

    cin>>n;

    cin>>s;

    int Max=0;

        for(int j=1;j<n;j++){

         sum[j]=sum[j-1];

         if(s[j-1]=='E'){

            sum[j]++;

			

         }

         }

        for(int k=n;k>0;k--){

        R[k-1]=R[k];

        if(s[k]=='W'){

        R[k-1]++;

        }

         sum[k-1]=sum[k-1]+R[k-1];

		

         Max=max(Max,sum[k-1]);

        }

        cout<<n-1-Max<<endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cmath>

#include<algorithm>

#include<cstring>

using namespace std;

char a[300005];

int s[300005];

int t[300005];

int main()

{

	int n;

	scanf("%d",&n);

	for(int i=1;i<=n;i++)

	{

		scanf(" %c",&a[i]);

		if(a[i-1]=='W') s[i]=s[i-1]+1;

		else s[i]=s[i-1];

	}

	for(int i=n;i>0;i--)

	{

		if(a[i+1]=='E') t[i]=t[i+1]+1;

		else t[i]=t[i+1];

	}

	int minn=2e9;

	for(int i=1;i<=n;i++)

	{

		if(s[i]+t[i]<minn) minn=s[i]+t[i];

	}

//	for(int i=1;i<=n;i++)

//	{

//		printf("%d ",s[i]);

//	}

//	printf("\n");

//	for(int i=1;i<=n;i++)

//	{

//		printf("%d ",t[i]);

//	}

//	printf("\n");

	printf("%d",minn);

}

// Fastest known solution for this problem: