#include <bits/stdc++.h>
#define abdelrahman001 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define inFile(t) freopen((t),"r",stdin)
#define outFile(t) freopen((t),"w",stdout)
#define pb push_back
#define pf push_front
#define Pb pop_back
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define Pf pop_front
#define sz size
#define MP make_pair
#define Pc __builtin_popcount
#define pi 2*acos(0)
#define BiEdge(v,a,b,c) (v)[(a)].pb({b,c}),(v)[(b)].pb(({a,c}))
#define mod 1000000007
#define point complex<ld>
#define X real()
#define Y imag()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define cross(a,b)(conj(a)*(b)).imag()
#define dot(a,b) (conj(a)*(b)).real()
#define rectangle pair<coordinate,coordinate>
#define line tuple<ll,ll,ll>
#define EPS 1e-7
#define polygon vector<point>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
int const N = 1e5+5,M = 105;
using namespace std;

ll n,pref[N],cnt,cnt1,high,ind = -1,ind1 = -1,ind2,ans,prefcnt;
string s;
int main()
{
    abdelrahman001
    cin >>n >> s;
    pref[0] = cnt = (s[0] == 'G');
    for(int i = 1;i<n;i++)
        cnt+=(s[i] == 'G'),pref[i] = pref[i-1] + (s[i] == 'G');
    for(int i = 0;i<n;i++)
    {
        if(s[i]=='S' && cnt1)
            high= max(high,cnt1),cnt1 = 0;
        cnt1+=s[i] == 'G';
    }
    high = max(high,cnt1);
    ans = high + (high < cnt);
    for(int i = 1;i<n-2;i++)
    {
        if(s[i] == 'S' && s[i-1] == 'G' && ~ind)
            ans = max(ans,prefcnt + pref[i] - pref[ind] + ((prefcnt + pref[i] - pref[ind]) < cnt)),ind = -1,ind1 = i;
        if(s[i] == 'S' && s[i-1] == 'G' && s[i+1] == 'G')
        {
            ind = i;
            ll dif = (ind1==-1)?0:pref[ind1-1];
            prefcnt = pref[i] - dif,ind1 = i;
        } else if(s[i] == 'S')
            ind1 = i;
    }
    ans = max(ans,prefcnt + pref[n-1] - pref[ind1] + ((prefcnt + pref[n-1] - pref[ind1]) < cnt));
    cout << min(ans,n);
    return 0;
}


#include <bits/stdc++.h>
#define abdelrahman001 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define inFile(t) freopen((t),"r",stdin)
#define outFile(t) freopen((t),"w",stdout)
#define pb push_back
#define pf push_front
#define Pb pop_back
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define Pf pop_front
#define sz size
#define MP make_pair
#define Pc __builtin_popcount
#define pi 2*acos(0)
#define BiEdge(v,a,b,c) (v)[(a)].pb({b,c}),(v)[(b)].pb(({a,c}))
#define mod 1000000007
#define point complex<ld>
#define X real()
#define Y imag()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define cross(a,b)(conj(a)*(b)).imag()
#define dot(a,b) (conj(a)*(b)).real()
#define rectangle pair<coordinate,coordinate>
#define line tuple<ll,ll,ll>
#define EPS 1e-7
#define polygon vector<point>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
int const N = 1e5+5,M = 105;
using namespace std;

ll n,pref[N],cnt,cnt1,high,ind = -1,ind1 = -1,ind2,ans,prefcnt;
string s;
int main()
{
    abdelrahman001
    cin >>n >> s;
    pref[0] = cnt = (s[0] == 'G');
    for(int i = 1;i<n;i++)
        cnt+=(s[i] == 'G'),pref[i] = pref[i-1] + (s[i] == 'G');
    for(int i = 0;i<n;i++)
    {
        if(s[i]=='S' && cnt1)
            high= max(high,cnt1),cnt1 = 0;
        cnt1+=s[i] == 'G';
    }
    ans = max(high,cnt1);
    for(int i = 1;i<n-2;i++)
    {
        if(s[i] == 'S' && s[i-1] == 'G' && ~ind)
            ans = max(ans,prefcnt + pref[i] - pref[ind] + ((prefcnt + pref[i] - pref[ind]) < cnt)),ind = -1,ind1 = i;
        if(s[i] == 'S' && s[i-1] == 'G' && s[i+1] == 'G')
        {
            ind = i;
            ll dif = (ind1==-1)?0:pref[ind1-1];
            prefcnt = pref[i] - dif;
        } else if(s[i] == 'S')
            ind1 = i;
    }
    if(~ind)
        ans = max(ans,prefcnt + pref[n-1] - pref[ind] + ((prefcnt + pref[n-1] - pref[ind]) < cnt));
    cout << min(ans,n);
    return 0;
}


#include <bits/stdc++.h>
#define abdelrahman001 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define inFile(t) freopen((t),"r",stdin)
#define outFile(t) freopen((t),"w",stdout)
#define pb push_back
#define pf push_front
#define Pb pop_back
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define Pf pop_front
#define sz size
#define MP make_pair
#define Pc __builtin_popcount
#define pi 2*acos(0)
#define BiEdge(v,a,b,c) (v)[(a)].pb({b,c}),(v)[(b)].pb(({a,c}))
#define mod 1000000007
#define point complex<ld>
#define X real()
#define Y imag()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define cross(a,b)(conj(a)*(b)).imag()
#define dot(a,b) (conj(a)*(b)).real()
#define rectangle pair<coordinate,coordinate>
#define line tuple<ll,ll,ll>
#define EPS 1e-7
#define polygon vector<point>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
int const N = 1e5+5,M = 105;
using namespace std;

ll n,pref[N],cnt,cnt1,high,ind = -1,ind1 = -1,ind2,ans,prefcnt;
string s;
int main()
{
    abdelrahman001
    cin >>n >> s;
    pref[0] = cnt = (s[0] == 'G');
    for(int i = 1;i<n;i++)
        cnt+=(s[i] == 'G'),pref[i] = pref[i-1] + (s[i] == 'G');
    for(int i = 0;i<n;i++)
    {
        if(s[i]=='S' && cnt1)
            high= max(high,cnt1),cnt1 = 0;
        cnt1+=s[i] == 'G';
    }
    high = max(high,cnt1);
    ans = high + (high < cnt);
    for(int i = 1;i<n-2;i++)
    {
        if(s[i] == 'S' && s[i-1] == 'G' && ~ind)
            ans = max(ans,prefcnt + pref[i] - pref[ind] + ((prefcnt + pref[i] - pref[ind]) < cnt)),ind = -1,ind1 = i;
        if(s[i] == 'S' && s[i-1] == 'G' && s[i+1] == 'G')
        {
            ind = i;
            ll dif = (ind1==-1)?0:pref[ind1-1];
            prefcnt = pref[i] - dif;
        } else if(s[i] == 'S')
            ind1 = i;
    }
    ans = max(ans,prefcnt + pref[n-1] - pref[ind] + ((prefcnt + pref[n-1] - pref[ind]) < cnt));
    cout << min(ans,n);
    return 0;
}


#include <bits/stdc++.h>
#define abdelrahman001 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define inFile(t) freopen((t),"r",stdin)
#define outFile(t) freopen((t),"w",stdout)
#define pb push_back
#define pf push_front
#define Pb pop_back
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define Pf pop_front
#define sz size
#define MP make_pair
#define Pc __builtin_popcount
#define pi 2*acos(0)
#define BiEdge(v,a,b,c) (v)[(a)].pb({b,c}),(v)[(b)].pb(({a,c}))
#define mod 1000000007
#define point complex<ld>
#define X real()
#define Y imag()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define cross(a,b)(conj(a)*(b)).imag()
#define dot(a,b) (conj(a)*(b)).real()
#define rectangle pair<coordinate,coordinate>
#define line tuple<ll,ll,ll>
#define EPS 1e-7
#define polygon vector<point>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
int const N = 1e5+5,M = 105;
using namespace std;

ll n,pref[N],cnt,cnt1,high,ind = -1,ind1 = -1,ind2,ans,prefcnt;
string s;
int main()
{
    abdelrahman001
    cin >>n >> s;
    pref[0] = cnt = (s[0] == 'G');
    for(int i = 1;i<n;i++)
        cnt+=(s[i] == 'G'),pref[i] = pref[i-1] + (s[i] == 'G');
    for(int i = 0;i<n;i++)
    {
        if(s[i]=='S' && cnt1)
            high= max(high,cnt1),cnt1 = 0;
        cnt1+=s[i] == 'G';
    }
    high = max(high,cnt1);
    ans = high + (high < cnt);
    for(int i = 1;i<n-2;i++)
    {
        if(s[i] == 'S' && s[i-1] == 'G' && ~ind)
            ans = max(ans,prefcnt + pref[i] - pref[ind] + ((prefcnt + pref[i] - pref[ind]) < cnt)),ind = -1;
        if(s[i] == 'S' && s[i-1] == 'G' && s[i+1] == 'G')
        {
            ind = i;
            ll dif = (ind1==-1)?0:pref[ind1-1];
            prefcnt = pref[i] - dif,ind1 = i;
        } else if(s[i] == 'S')
            ind1 = i;
    }
    if(~ind)
        ans = max(ans,prefcnt + pref[n-1] - pref[ind1] + ((prefcnt + pref[n-1] - pref[ind1]) < cnt));
    cout << min(ans,n);
    return 0;
}


#include <bits/stdc++.h>
#define abdelrahman001 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define inFile(t) freopen((t),"r",stdin)
#define outFile(t) freopen((t),"w",stdout)
#define pb push_back
#define pf push_front
#define Pb pop_back
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define Pf pop_front
#define sz size
#define MP make_pair
#define Pc __builtin_popcount
#define pi 2*acos(0)
#define BiEdge(v,a,b,c) (v)[(a)].pb({b,c}),(v)[(b)].pb(({a,c}))
#define mod 1000000007
#define point complex<ld>
#define X real()
#define Y imag()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define cross(a,b)(conj(a)*(b)).imag()
#define dot(a,b) (conj(a)*(b)).real()
#define rectangle pair<coordinate,coordinate>
#define line tuple<ll,ll,ll>
#define EPS 1e-7
#define polygon vector<point>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
int const N = 1e5+5,M = 105;
using namespace std;

ll n,pref[N],cnt,cnt1,high,ind = -1,ind1 = -1,ind2,ans,prefcnt;
string s;
int main()
{
    abdelrahman001
    cin >>n >> s;
    pref[0] = cnt = (s[0] == 'G');
    for(int i = 1;i<n;i++)
        cnt+=(s[i] == 'G'),pref[i] = pref[i-1] + (s[i] == 'G');
    for(int i = 0;i<n;i++)
    {
        if(s[i]=='S' && cnt1)
            high= max(high,cnt1),cnt1 = 0;
        cnt1+=s[i] == 'G';
    }
    high = max(high,cnt1);
    ans = high + (high < cnt);
    for(int i = 1;i<n-2;i++)
    {
        if(s[i] == 'S' && s[i-1] == 'G' && ~ind)
            ans = max(ans,prefcnt + pref[i] - pref[ind] + ((prefcnt + pref[i] - pref[ind]) < cnt)),ind = -1;
        if(s[i] == 'S' && s[i-1] == 'G' && s[i+1] == 'G')
        {
            ind = i;
            ll dif = (ind1==-1)?0:pref[ind1-1];
            prefcnt = pref[i] - dif,ind1 = i;
        } else if(s[i] == 'S')
            ind1 = i;
    }
    ans = max(ans,prefcnt + pref[n-1] - pref[ind1] + ((prefcnt + pref[n-1] - pref[ind1]) < cnt));
    cout << min(ans,n);
    return 0;
}


#include <bits/stdc++.h>
#define abdelrahman001 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define inFile(t) freopen((t),"r",stdin)
#define outFile(t) freopen((t),"w",stdout)
#define pb push_back
#define pf push_front
#define Pb pop_back
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define Pf pop_front
#define sz size
#define MP make_pair
#define Pc __builtin_popcount
#define pi 2*acos(0)
#define BiEdge(v,a,b,c) (v)[(a)].pb({b,c}),(v)[(b)].pb(({a,c}))
#define mod 1000000007
#define point complex<ld>
#define X real()
#define Y imag()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define cross(a,b)(conj(a)*(b)).imag()
#define dot(a,b) (conj(a)*(b)).real()
#define rectangle pair<coordinate,coordinate>
#define line tuple<ll,ll,ll>
#define EPS 1e-7
#define polygon vector<point>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
int const N = 1e5+5,M = 105;
using namespace std;

ll n,pref[N],suf[N],cnt,cnt1,high,ind = -1,ans,prefcnt;
string s;
int main()
{
    abdelrahman001
    cin >>n >> s;
    pref[0] = cnt = (s[0] == 'G');
    for(int i = 1;i<n;i++)
        cnt+=(s[i] == 'G'),pref[i] = pref[i-1] + (s[i] == 'G');
    suf[n-1] = s[n-1] == 'G';
    for(int i = n-2;i>=0;i--)
        suf[i] = suf[i+1] + (s[i] == 'G');
    for(int i = 0;i<n;i++)
    {
        if(s[i]=='S' && cnt1)
            high= max(high,cnt1),cnt1 = 0;
        cnt1+=s[i] == 'G';
    }
    ans = max(high,cnt1);
    for(int i = 1;i<n-2;i++)
    {
        if(s[i] == 'S' && s[i-1] == 'G' && s[i+1] == 'G')
        {
            if(ind == -1)
                ind = i,prefcnt = pref[i];
            else
                ans = max(ans,prefcnt + suf[ind] - suf[i+1] + ((prefcnt + suf[ind] - suf[i+1])<cnt)),ind = i,prefcnt = pref[i];
        }
    }
    cout << min(max(ans,prefcnt + suf[ind] + ((prefcnt + suf[ind])<cnt)),n);
    return 0;
}


#include <bits/stdc++.h>
#define abdelrahman001 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define inFile(t) freopen((t),"r",stdin)
#define outFile(t) freopen((t),"w",stdout)
#define pb push_back
#define pf push_front
#define Pb pop_back
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define Pf pop_front
#define sz size
#define MP make_pair
#define Pc __builtin_popcount
#define pi 2*acos(0)
#define BiEdge(v,a,b,c) (v)[(a)].pb({b,c}),(v)[(b)].pb(({a,c}))
#define mod 1000000007
#define point complex<ld>
#define X real()
#define Y imag()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define cross(a,b)(conj(a)*(b)).imag()
#define dot(a,b) (conj(a)*(b)).real()
#define rectangle pair<coordinate,coordinate>
#define line tuple<ll,ll,ll>
#define EPS 1e-7
#define polygon vector<point>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
int const N = 1e5+5,M = 105;
using namespace std;

ll n,pref[N],cnt,cnt1,high,ind = -1,ind1 = -1,ind2,ans,prefcnt;
string s;
int main()
{
    abdelrahman001
    cin >>n >> s;
    pref[0] = cnt = (s[0] == 'G');
    for(int i = 1;i<n;i++)
        cnt+=(s[i] == 'G'),pref[i] = pref[i-1] + (s[i] == 'G');
    for(int i = 0;i<n;i++)
    {
        if(s[i]=='S' && cnt1)
            high= max(high,cnt1),cnt1 = 0;
        cnt1+=s[i] == 'G';
    }
    high = max(high,cnt1);
    ans = high + (high < cnt);
    for(int i = 1;i<n-1;i++)
    {
        if(s[i] == 'S' && s[i-1] == 'G' && ~ind)
            ans = max(ans,prefcnt + pref[i] - pref[ind] + ((prefcnt + pref[i] - pref[ind]) < cnt)),ind = -1;
        if(s[i] == 'S' && s[i-1] == 'G' && s[i+1] == 'G')
        {
            ind = i;
            ll dif = (ind1==-1)?0:pref[ind1-1];
            prefcnt = pref[i] - dif,ind1 = i;
        } else if(s[i] == 'S')
            ind1 = i;
    }
    if(~ind)
        ans = max(ans,prefcnt + pref[n-1] - pref[ind] + ((prefcnt + pref[n-1] - pref[ind]) < cnt));
    cout << min(ans,n);
    return 0;
}


 #include<bits/stdc++.h>
using namespace std;
int main()
{
  long long n,c=0,r=0,m=0,d=0,x=0;
  string s;
cin>>n;
 cin>>s;
for(int i=0;i<n;i++){
   if(s[i]=='G')d++,c++;
    else{   x=m;
   m=c;

c=0;
}
r=max(r,m+c+1);

}
cout<<min(r,d)<<endl;


#include <bits/stdc++.h>
using namespace std;
#define rep(i, x, y) for(ll i = (x); i <= (y); ++i)
#define bug1(a) cout << #a << " = " << a << endl;
#define bug2(a,b) cout << #a << " = " << a <<", "<< #b << " = " << b<< endl;
#define bug3(a,b,c) cout << #a << " = " << a <<", "<< #b << " = " << b<<", "<< #c << " = " << c<< endl;
#define fbug(a, x, y) { cout << #a << ": "; rep(i, x, y) cout << a[i] << ' '; cout << endl; }
#define pb push_back
//#define mp make_pair
#define endd "\n"
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define input freopen("inp.txt","r",stdin)
#define output freopen("out2.txt","w",stdout)
#define loop(i,n) for(ll i=0;i<n;i++)
#define rloop(i,n) for(ll i=n-1;i>=0;i--)
#define ll long long
#define Z size()
#define pii pair<int,int>
#define setp(x) fixed<<setprecision(x)
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pi 3.14159265358979323846264338327950288419716939937510
#define mset(x) memset(x,0,sizeof x);
#define spa cout<<endd
#define com(x)#x
//#define modexp
#define rcd(x) cout<<"Reached at: "<<x<<endd
#ifdef modexp
ll power(ll a , ll b,ll modi){
    ll res = 1 ;
    while(b){
        if(b & 1) res = (res * a) % modi ;
        b /= 2 ;
        a = (a * a) % modi ;
    }
    return res ;
}
#endif
int dirx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int diry[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
//*******************************TEMPLATE ENDS HERE *******************//
int n;
string s;
const int N = 2e5;
int dp[2*N + 1], dp2[2*N + 1];
int main(){
   // input;
    cin >> n >> s;
    int cnt = 0;
    int ans = 0, f = -1, l = -1;
    vector<int>idx;
    rep(i, 1, n){
        dp[i] = s[i - 1] == 'G'?dp[i - 1] + 1:0;
        if(dp[i] && f == -1)f = i;
        if(s[i - 1] == 'G')idx.pb(i);
        ans = max(ans, dp[i]);

    }
    //dp[n - 1] = s[n - 1] == 'G';
    for(int i = n; i >= 0; i--){

       dp2[i] =  s[i - 1] == 'G'?dp2[i + 1] + 1:0;
        if(dp2[i] && l== -1) l = i;
    }

    if(f == -1 && l == -1){
        cout<<ans;
        return 0;
    }

    rep(i, 1, n){
        if(s[i - 1] == 'S'){
           int x = i - dp[i - 1];

           int f = 0;
           int v = dp[ i - 1] + dp2[ i + 1] + 1;
           int pos = lower_bound(all(idx), x) - idx.begin();

           if(pos >= 0 && idx[pos] <= x && x != idx[0])ans = max(ans, v);
           x = i + dp2[i + 1];
           pos = lower_bound(all(idx), x) - idx.begin();
           if(pos < idx.Z && idx[pos] >= x && idx[idx.Z - 1] != x)ans = max(ans, v);

        }
    }
    cout<<ans;

}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, x, y) for(ll i = (x); i <= (y); ++i)
#define bug1(a) cout << #a << " = " << a << endl;
#define bug2(a,b) cout << #a << " = " << a <<", "<< #b << " = " << b<< endl;
#define bug3(a,b,c) cout << #a << " = " << a <<", "<< #b << " = " << b<<", "<< #c << " = " << c<< endl;
#define fbug(a, x, y) { cout << #a << ": "; rep(i, x, y) cout << a[i] << ' '; cout << endl; }
#define pb push_back
//#define mp make_pair
#define endd "\n"
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define input freopen("inp.txt","r",stdin)
#define output freopen("out2.txt","w",stdout)
#define loop(i,n) for(ll i=0;i<n;i++)
#define rloop(i,n) for(ll i=n-1;i>=0;i--)
#define ll long long
#define Z size()
#define pii pair<int,int>
#define setp(x) fixed<<setprecision(x)
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pi 3.14159265358979323846264338327950288419716939937510
#define mset(x) memset(x,0,sizeof x);
#define spa cout<<endd
#define com(x)#x
//#define modexp
#define rcd(x) cout<<"Reached at: "<<x<<endd
#ifdef modexp
ll power(ll a , ll b,ll modi){
    ll res = 1 ;
    while(b){
        if(b & 1) res = (res * a) % modi ;
        b /= 2 ;
        a = (a * a) % modi ;
    }
    return res ;
}
#endif
int dirx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int diry[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
//*******************************TEMPLATE ENDS HERE *******************//
int n;
string s;
const int N = 2e5;
int dp[2*N + 1], dp2[2*N + 1];
int main(){
   // input;
    cin >> n >> s;
    int cnt = 0;
    int ans = 0, f = -1, l = -1;
    vector<int>idx;
    rep(i, 1, n){
        dp[i] = s[i - 1] == 'G'?dp[i - 1] + 1:0;
        if(dp[i] && f == -1)f = i;
        if(s[i - 1] == 'G')idx.pb(i);
        ans = max(ans, dp[i]);

    }
    //dp[n - 1] = s[n - 1] == 'G';
    for(int i = n; i >= 0; i--){

       dp2[i] =  s[i - 1] == 'G'?dp2[i + 1] + 1:0;
        if(dp2[i] && l== -1) l = i;
    }

    if(!idx.Z){
        cout<<0;
        return 0;
    }
    rep(i, 1, n){
        if(s[i - 1] == 'S'){
           int x = i - dp[i - 1];

           int f = 0;
           int v = dp[ i - 1] + dp2[ i + 1] + 1;
           int pos = lower_bound(all(idx), x) - idx.begin();

           if(pos >= 0 && idx[pos] <= x && x != idx[0])ans = max(ans, v);
           x = i + dp2[i + 1];
           pos = lower_bound(all(idx), x) - idx.begin();
           if(pos < idx.Z && idx[pos] >= x && idx[idx.Z - 1] != x)ans = max(ans, v);
           ans = max(ans, dp[i - 1] + dp2[ i + 1]);

        }
    }
    cout<<ans;

}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, x, y) for(ll i = (x); i <= (y); ++i)
#define bug1(a) cout << #a << " = " << a << endl;
#define bug2(a,b) cout << #a << " = " << a <<", "<< #b << " = " << b<< endl;
#define bug3(a,b,c) cout << #a << " = " << a <<", "<< #b << " = " << b<<", "<< #c << " = " << c<< endl;
#define fbug(a, x, y) { cout << #a << ": "; rep(i, x, y) cout << a[i] << ' '; cout << endl; }
#define pb push_back
//#define mp make_pair
#define endd "\n"
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define input freopen("inp.txt","r",stdin)
#define output freopen("out2.txt","w",stdout)
#define loop(i,n) for(ll i=0;i<n;i++)
#define rloop(i,n) for(ll i=n-1;i>=0;i--)
#define ll long long
#define Z size()
#define pii pair<int,int>
#define setp(x) fixed<<setprecision(x)
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pi 3.14159265358979323846264338327950288419716939937510
#define mset(x) memset(x,0,sizeof x);
#define spa cout<<endd
#define com(x)#x
//#define modexp
#define rcd(x) cout<<"Reached at: "<<x<<endd
#ifdef modexp
ll power(ll a , ll b,ll modi){
    ll res = 1 ;
    while(b){
        if(b & 1) res = (res * a) % modi ;
        b /= 2 ;
        a = (a * a) % modi ;
    }
    return res ;
}
#endif
int dirx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int diry[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
//*******************************TEMPLATE ENDS HERE *******************//
int n;
string s;
const int N = 2e5;
int dp[2*N + 1], dp2[2*N + 1];
int main(){
  //  input;
    cin >> n >> s;
    int cnt = 0;
    int ans = 0, f = -1, l = -1;
    rep(i, 1, n){
        dp[i] = s[i - 1] == 'G'?dp[i - 1] + 1:0;
        if(dp[i] && f == -1)f = i;
        ans = max(ans, dp[i]);

    }
    //dp[n - 1] = s[n - 1] == 'G';
    for(int i = n; i >= 0; i--){

       dp2[i] =  s[i - 1] == 'G'?dp2[i + 1] + 1:0;
        if(dp2[i] && l== -1) l = i;
    }

    if(f == -1 && l == -1){
        cout<<ans;
        return 0;
    }

    rep(i, 1, n){
        if(s[i - 1] == 'S'){
            if((f != -1 && f!= i )|| (l != -1 && l != i))ans = max(ans, dp[i - 1] + dp2[i + 1] + 1);

        }
    }
    cout<<ans;

}


 #include<bits/stdc++.h>
using namespace std;
int main()
{
  long long n,c=0,r=0,m=0,d=0,x=0;
  string s;
cin>>n;
 cin>>s;
for(int i=0;i<n;i++){
   if(s[i]=='G')d++,c++;
    else{   x=m;
   m=c;

c=0;
}
r=max(r,m+c+1);

}
cout<<min(r,d)<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, x, y) for(ll i = (x); i <= (y); ++i)
#define bug1(a) cout << #a << " = " << a << endl;
#define bug2(a,b) cout << #a << " = " << a <<", "<< #b << " = " << b<< endl;
#define bug3(a,b,c) cout << #a << " = " << a <<", "<< #b << " = " << b<<", "<< #c << " = " << c<< endl;
#define fbug(a, x, y) { cout << #a << ": "; rep(i, x, y) cout << a[i] << ' '; cout << endl; }
#define pb push_back
//#define mp make_pair
#define endd "\n"
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define input freopen("inp.txt","r",stdin)
#define output freopen("out2.txt","w",stdout)
#define loop(i,n) for(ll i=0;i<n;i++)
#define rloop(i,n) for(ll i=n-1;i>=0;i--)
#define ll long long
#define Z size()
#define pii pair<int,int>
#define setp(x) fixed<<setprecision(x)
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pi 3.14159265358979323846264338327950288419716939937510
#define mset(x) memset(x,0,sizeof x);
#define spa cout<<endd
#define com(x)#x
//#define modexp
#define rcd(x) cout<<"Reached at: "<<x<<endd
#ifdef modexp
ll power(ll a , ll b,ll modi){
    ll res = 1 ;
    while(b){
        if(b & 1) res = (res * a) % modi ;
        b /= 2 ;
        a = (a * a) % modi ;
    }
    return res ;
}
#endif
int dirx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int diry[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
//*******************************TEMPLATE ENDS HERE *******************//
int n;
string s;
const int N = 2e5;
int dp[2*N + 1], dp2[2*N + 1];
int main(){
    //input;
    cin >> n >> s;
    int cnt = 0;
    int ans = 0, f = -1, l = -1;
    vector<int>idx;
    rep(i, 1, n){
        dp[i] = s[i - 1] == 'G'?dp[i - 1] + 1:0;
        if(dp[i] && f == -1)f = i;
        if(s[i - 1] == 'G')idx.pb(i);
        ans = max(ans, dp[i]);

    }
    //dp[n - 1] = s[n - 1] == 'G';
    for(int i = n; i >= 0; i--){

       dp2[i] =  s[i - 1] == 'G'?dp2[i + 1] + 1:0;
        if(dp2[i] && l== -1) l = i;
    }

    rep(i, 1, n){
        if(s[i - 1] == 'S'){
           int x = i - dp[i - 1];

           int f = 0;
           int v = dp[ i - 1] + dp2[ i + 1] + 1;
           int pos = lower_bound(all(idx), x) - idx.begin();

           if(pos >= 0 && idx[pos] <= x && x != idx[0])ans = max(ans, v);
           x = i + dp2[i + 1];
           pos = lower_bound(all(idx), x) - idx.begin();
           if(pos < idx.Z && idx[pos] >= x && idx[idx.Z - 1] != x)ans = max(ans, v);

        }
    }
    cout<<ans;

}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, x, y) for(ll i = (x); i <= (y); ++i)
#define bug1(a) cout << #a << " = " << a << endl;
#define bug2(a,b) cout << #a << " = " << a <<", "<< #b << " = " << b<< endl;
#define bug3(a,b,c) cout << #a << " = " << a <<", "<< #b << " = " << b<<", "<< #c << " = " << c<< endl;
#define fbug(a, x, y) { cout << #a << ": "; rep(i, x, y) cout << a[i] << ' '; cout << endl; }
#define pb push_back
//#define mp make_pair
#define endd "\n"
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define input freopen("inp.txt","r",stdin)
#define output freopen("out2.txt","w",stdout)
#define loop(i,n) for(ll i=0;i<n;i++)
#define rloop(i,n) for(ll i=n-1;i>=0;i--)
#define ll long long
#define Z size()
#define pii pair<int,int>
#define setp(x) fixed<<setprecision(x)
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pi 3.14159265358979323846264338327950288419716939937510
#define mset(x) memset(x,0,sizeof x);
#define spa cout<<endd
#define com(x)#x
//#define modexp
#define rcd(x) cout<<"Reached at: "<<x<<endd
#ifdef modexp
ll power(ll a , ll b,ll modi){
    ll res = 1 ;
    while(b){
        if(b & 1) res = (res * a) % modi ;
        b /= 2 ;
        a = (a * a) % modi ;
    }
    return res ;
}
#endif
int dirx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int diry[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
//*******************************TEMPLATE ENDS HERE *******************//
int n;
string s;
const int N = 2e5;
int dp[2*N + 1], dp2[2*N + 1];
int main(){
  //  input;
    cin >> n >> s;
    int cnt = 0;
    int ans = 0, f = -1, l = -1;
    vector<int>idx;
    rep(i, 1, n){
        dp[i] = s[i - 1] == 'G'?dp[i - 1] + 1:0;
        if(dp[i] && f == -1)f = i;
        if(s[i - 1] == 'G')cnt++;
        ans = max(ans, dp[i]);

    }
    //dp[n - 1] = s[n - 1] == 'G';
    for(int i = n; i >= 0; i--){

       dp2[i] =  s[i - 1] == 'G'?dp2[i + 1] + 1:0;
        if(dp2[i] && l== -1) l = i;
    }

    rep(i, 1, n){
        if(s[i - 1] == 'S'){

           int v = dp[ i - 1] + dp2[ i + 1] + 1;

          ans = max(ans, v);

        }
    }
    cout<<min(ans, cnt);

}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, x, y) for(ll i = (x); i <= (y); ++i)
#define bug1(a) cout << #a << " = " << a << endl;
#define bug2(a,b) cout << #a << " = " << a <<", "<< #b << " = " << b<< endl;
#define bug3(a,b,c) cout << #a << " = " << a <<", "<< #b << " = " << b<<", "<< #c << " = " << c<< endl;
#define fbug(a, x, y) { cout << #a << ": "; rep(i, x, y) cout << a[i] << ' '; cout << endl; }
#define pb push_back
//#define mp make_pair
#define endd "\n"
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define input freopen("inp.txt","r",stdin)
#define output freopen("out2.txt","w",stdout)
#define loop(i,n) for(ll i=0;i<n;i++)
#define rloop(i,n) for(ll i=n-1;i>=0;i--)
#define ll long long
#define Z size()
#define pii pair<int,int>
#define setp(x) fixed<<setprecision(x)
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pi 3.14159265358979323846264338327950288419716939937510
#define mset(x) memset(x,0,sizeof x);
#define spa cout<<endd
#define com(x)#x
//#define modexp
#define rcd(x) cout<<"Reached at: "<<x<<endd
#ifdef modexp
ll power(ll a , ll b,ll modi){
    ll res = 1 ;
    while(b){
        if(b & 1) res = (res * a) % modi ;
        b /= 2 ;
        a = (a * a) % modi ;
    }
    return res ;
}
#endif
int dirx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int diry[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
//*******************************TEMPLATE ENDS HERE *******************//
int n;
string s;
const int N = 2e5;
int dp[2*N + 1], dp2[2*N + 1];
int main(){
   // input;
    cin >> n >> s;
    //bug2(n ,s);
    int cnt = 0;

    int last = -1, f = -1;
    dp[0] = s[0] == 'G';
    if(dp[0])f = 0;
    loop(i, n){
        cnt += s[i] == 'G';
        if(i && s[i] == 'G')dp[i] = s[i - 1] == 'G' ? dp[i - 1] + 1:1;
        if(f == -1 && s[i] == 'G')f = i;
       // cout<<dp[i]<<" ";

    }
    if(!cnt){

        cout<<0;
        return 0;
    }
    //spa;
   // rcd("s");
    dp2[n - 1] = s[n - 1] == 'G';
    if(dp2[n - 1])last = n - 1;
    for(int i = n - 1; i >= 0; i--){
        //rcd(i);
        if(i != n - 1 && s[i] == 'G')dp2[i] = s[i + 1] == 'G' ? dp2[i + 1] + 1:1;
        if(last == -1 && s[i] == 'G')last = i;
      //  cout<<dp2[i]<<" ";
    }
    //spa;
      // rcd("s");
    int ans = dp2[1];
    if(s[0] == 'S' && last != 0)ans++;
    ans = max(ans, dp2[0]);
    ans = max(ans, dp[n - 1]);
    if(s[n - 1] == 'S' && f != n - 1)ans = max(ans, dp[n - 2] + 1);
    rep(i, 1, n - 1){
        if((last != i || f != i) && last != -1 && f != -1 && s[i] == 'S'){
            //bug3(dp[i - 1], dp2[i + 1], i);
            ans = max(dp[i - 1] + dp2[i + 1] + 1, ans);

        }
    }
       //rcd("s");
    cout<<ans;

}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, x, y) for(ll i = (x); i <= (y); ++i)
#define bug1(a) cout << #a << " = " << a << endl;
#define bug2(a,b) cout << #a << " = " << a <<", "<< #b << " = " << b<< endl;
#define bug3(a,b,c) cout << #a << " = " << a <<", "<< #b << " = " << b<<", "<< #c << " = " << c<< endl;
#define fbug(a, x, y) { cout << #a << ": "; rep(i, x, y) cout << a[i] << ' '; cout << endl; }
#define pb push_back
//#define mp make_pair
#define endd "\n"
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define input freopen("inp.txt","r",stdin)
#define output freopen("out2.txt","w",stdout)
#define loop(i,n) for(ll i=0;i<n;i++)
#define rloop(i,n) for(ll i=n-1;i>=0;i--)
#define ll long long
#define Z size()
#define pii pair<int,int>
#define setp(x) fixed<<setprecision(x)
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pi 3.14159265358979323846264338327950288419716939937510
#define mset(x) memset(x,0,sizeof x);
#define spa cout<<endd
#define com(x)#x
//#define modexp
#define rcd(x) cout<<"Reached at: "<<x<<endd
#ifdef modexp
ll power(ll a , ll b,ll modi){
    ll res = 1 ;
    while(b){
        if(b & 1) res = (res * a) % modi ;
        b /= 2 ;
        a = (a * a) % modi ;
    }
    return res ;
}
#endif
int dirx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int diry[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
//*******************************TEMPLATE ENDS HERE *******************//
int n;
string s;
const int N = 2e5;
int dp[2*N + 1], dp2[2*N + 1];
int main(){
    //input;
    cin >> n >> s;
    int cnt = 0;
    int ans = 0, f = -1, l = -1;
    vector<int>idx;
    rep(i, 1, n){
        dp[i] = s[i - 1] == 'G'?dp[i - 1] + 1:0;
        if(dp[i] && f == -1)f = i;
        if(s[i - 1] == 'G')idx.pb(i);
        ans = max(ans, dp[i]);

    }
    //dp[n - 1] = s[n - 1] == 'G';
    for(int i = n; i >= 0; i--){

       dp2[i] =  s[i - 1] == 'G'?dp2[i + 1] + 1:0;
        if(dp2[i] && l== -1) l = i;
    }

    if(!idx.Z){
        cout<<0;
        return 0;
    }
    rep(i, 1, n){
        if(s[i - 1] == 'S'){
           int x = i - dp[i - 1];

           int f = 0;
           int v = dp[ i - 1] + dp2[ i + 1] + 1;
           int pos = lower_bound(all(idx), x) - idx.begin();

           if(pos >= 0 && idx[pos] <= x && x != idx[0])ans = max(ans, v);
           x = i + dp2[i + 1];
           pos = lower_bound(all(idx), x) - idx.begin();
           if(pos < idx.Z && idx[pos] >= x && idx[idx.Z - 1] != x)ans = max(ans, v);

        }
    }
    cout<<ans;

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n1,n;cin>>n1;
	string s;
	cin>>s;
	n=s.length();
	ll i,j;
	ll maxa=0,c=0,cg=0;
	for(i=0;i<n;i++)
	{
	    if(s[i]=='G'){
	    c++;
	    cg++;}
	    else
	    {
	        maxa=max(c,maxa);
	        c=0;
	    }
	}
	if(cg==n or cg==0)
	{
	    cout<<cg;return 0;
	}
	if(cg>maxa)
	maxa++;
	for(i=0;i<n;i++)
	{
	    if(s[i]=='S' and s[i-1]=='G' and s[i+1]=='G')
	    {
	        ll l=i-1,r=i+1;
	        ll cl=0,cr=0;
	        while(s[l]=='G' and l>=0)
	        {
	            cl++;
	            l--;
	        }
	        while(s[r]=='G' and r<=n-1)
	        {
	            cr++;r++;
	        }
	        if(cg>cr+cl)
	        {
	            maxa=max(maxa,cr+cl+1);
	        }
	        else
	        maxa=max(maxa,cr+cl);
	    }
	}
	cout<<maxa;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n;cin>>n;
	string s;
	cin>>s;
	ll i,j;
	ll a[n]={0};
	bool g1=0,g2=0;
	for(i=0;i<n;i++)
	{
	    if(s[i]=='G'){
	    a[i]=1;
	    g1=1;}
	    else{
	    a[i]=-1;
	    g2=1;}
	}
	if(g1==0)
	{
	    cout<<0<<endl;return 0;
	}
	if(g2==0)
	{
	    cout<<n<<endl;return 0;
	}
	ll max_ending_here=0,max_so_far=0;
	for (i = 0; i < n; i++)
    {
        max_ending_here = max_ending_here + a[i];
        if (max_so_far < max_ending_here)
            max_so_far = max_ending_here;

        if (max_ending_here < 0)
            max_ending_here = 0;
    }
    cout<<max_so_far+1;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n,tmp,curr=0; cin>>n;
	vector<int> v(n),res(n);
	for(int i=0;i<n;i++)
	{
		cin>>tmp;
		v[tmp]=i+1;
	}
	for(int i=0;i<n;i++)
	{
		cin>>tmp;
		if(v[tmp]>curr)
		{
			res[i]=v[tmp]-curr;
			curr=v[tmp];
		}
		else res[i]=0;
	}
	for(int i=0;i<res.size();i++) cout<<res[i]<<" ";
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int N = int(2e5) + 1;

int a[N];
int b[N];
bool u[N];

int main(){
    int n;
    scanf("%d", &n);
    vector<int> ans(n, 0);
    for(int i = 0 ; i < n ;i++){
    	scanf("%d", a + i);
    }
    for(int i = 0 ; i < n; i++){
    	scanf("%d", b + i);
    }
    int pos = 0;
    for(int i = 0; i < n;i++){
    	if(u[b[i]]) continue;

    	while(true){
    		ans[i]++;
    		u[a[pos]] = true;
    		if(a[pos] == b[i]) break;
    		++pos;
    	}
    	++pos;
    }

    for(int i =0; i< n; i++){
        printf("%d ", ans[i]);
    }
}


#include <bits/stdc++.h>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    vector<int> a(n, 0), b(n, 0), ans(n, 0);
    for(int i = 0 ; i < n ;i++){
        scanf("%d", &a[i]);
    }
    for(int i = 0 ; i < n ;i++){
        scanf("%d", &b[i]);
    }
    vector<int>::iterator itr;
    for(int i = 0; i < n; i++){
        itr = find(a.begin(), a.end(), b[i]);
        if(itr != a.end()){
            for(vector<int>::iterator itr2 = itr; itr2 != a.begin() - 1; itr2--){
                if(*itr2 != 0){
                    ans[i]++;
                    *itr2 = 0;
                }
            }
        }
    }
    for(int i =0; i< n; i++){
        printf("%d ", ans[i]);
    }

}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n, number;
    scanf("%d", &n);
    vector<int> a(n, 0), b(n, 0), ans(n, 0);
    for(int i = 0 ; i < n ;i++){
    	scanf("%d", &a[i]);
    }
   	int last = 0;
   	int j = last;
    for(int i = 0 ; i < n && last < n; i++){
    	scanf("%d", &number);
    	for(j = last; a[j] == number || (a[j] != number && a[j - 1] != number); j++){
    		ans[i]++;
    		if(j == n){
    			j = last;
    			ans[i] = 0;
    			break;
    		}
    	}
    	last = j;
    }

    for(int i =0; i< n; i++){
        printf("%d ", ans[i]);
    }

}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n, number;
    scanf("%d", &n);
    vector<int> a(n, 0), b(n, 0), ans(n, 0);
    for(int i = 0 ; i < n ;i++){
    	scanf("%d", &a[i]);
    }
    vector<int>::iterator ma = a.begin() - 1, itr;
    for(int i = 0 ; i < n ;i++){
        scanf("%d", &number);
        itr = find(a.begin(), a.end(), number);
        if(itr - ma > 0){
            ans[i] = itr - ma;
        }else{
            ans[i] = 0;
        }
        // (itr - a.begin() > ma - a.begin()) ? ma =
        ma = max(itr, ma);
    }
    for(int i =0; i< n; i++){
        printf("%d ", ans[i]);
    }

}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int N = int(2e5);

int a[N];
int b[N];
int u[N];

int main(){
    int n, number;
    scanf("%d", &n);
    vector<int> ans(n, 0);
    for(int i = 0 ; i < n ;i++){
    	scanf("%d", a + i);
    }
    for(int i = 0 ; i < n; i++){
    	scanf("%d", b + i);
    }
    int pos = 0;
    for(int i = 0; i < n;i++){
    	if(u[b[i]]) continue;

    	while(true){
    		ans[i]++;
    		u[a[pos]] = true;
    		if(a[pos] == b[i]) break;
    		++pos;
    	}
    	++pos;
    }

    for(int i =0; i< n; i++){
        printf("%d ", ans[i]);
    }
}


#include <bits/stdc++.h>

using namespace std;

int main(){
    int n, number;
    scanf("%d", &n);
    vector<int> a(n, 0), b(n, 0), ans(n, 0);
    for(int i = 0 ; i < n ;i++){
        scanf("%d", &a[i]);
    }
    for(int i = 0 ; i < n ;i++){
        scanf("%d", &number);
        vector<int>::iterator itr = find(a.begin(), a.end(), number);
        if(itr != a.end()){
            ans[i] = itr - a.begin() + 1;
            a.erase(a.begin(), itr + 1);
        }
    }

    for(int i =0; i< n; i++){
        printf("%d ", ans[i]);
    }

}


#include<iostream>
#include<cmath>

using namespace std;
int c[200001]

int main()
{
		int n,k=0,i;

		cin>>n;

		int a[n],b[n],c[n];

		for(i=0;i<n;i++) cin>>a[i];
		for(i=0;i<n;i++) cin>>b[i];
		//for(i=0;i<n;i++) c[i]=0;

		for(int i=0;i<n;i++)
		{
			for(int j=k;j<n;j++)
			{
				if(b[i]==a[j])
				{
				   c[i]=j-k+1;
				   k=j+1;

				   break;
				}

			}

		}

		for(int i=0;i<n;i++)
		{
			cout<<c[i];
			if(i!=n-1) cout<<" ";

		}

		cout<<endl;

}


#include<iostream>
#include<cmath>

using namespace std;

int main()
{
		long int n,k=0,i,x,sum=0;

		cin>>n;

		int a[n],b[n],c[n];

		for(i=0;i<n;i++)
		{
			 cin>>x;
			 a[x-1]=i+1;
		}

		for(i=0;i<n;i++) cin>>b[i];

		for(i=0;i<n;i++) c[i]=0;

		for(int i=0;i<n;i++)
		{
			if(a[b[i]-1]-sum>0)
			{
				c[i]= a[b[i]-1]-sum;
				sum+=c[i];
			}

			if(sum==n) break;

		}

		for(int i=0;i<n;i++)
		{
			cout<<c[i];
			if(i!=n-1) cout<<" ";

		}

		cout<<endl;

}


#include<iostream>
#include<cmath>

using namespace std;
int c[200001];

int main()
{
		int n,k=0,i;

		cin>>n;

		int a[n],b[n],c[n];

		for(i=0;i<n;i++) cin>>a[i];
		for(i=0;i<n;i++) cin>>b[i];
		//for(i=0;i<n;i++) c[i]=0;

		for(int i=0;i<n;i++)
		{
			for(int j=k;j<n;j++)
			{
				if(b[i]==a[j])
				{
				   c[i]=j-k+1;
				   k=j+1;

				   break;
				}

			}

		}

		for(int i=0;i<n;i++)
		{
			cout<<c[i];
			if(i!=n-1) cout<<" ";

		}

		cout<<endl;

}


#include<iostream>
#include<cmath>

using namespace std;
//int c[200001];

int main()
{
		int n,k=0,i,m=0;

		cin>>n;

		int a[n],b[n],c[n];

		for(i=0;i<n;i++) cin>>a[i];
		for(i=0;i<n;i++) cin>>b[i];
		for(i=0;i<n;i++) c[i]=0;

		for(int i=0;i<n;i++)
		{
		    if(a[i]==b[i] && m==0)
            {
                c[i]=1;
                k++;
            }

            else
            {

             m=1;
			for(int j=k;j<n;j++)
			{
				if(b[i]==a[j])
				{
				   c[i]=j-k+1;
				   k=j+1;

				   break;
				}

			}
            }

		}

		for(int i=0;i<n;i++)
		{
			cout<<c[i];
			if(i!=n-1) cout<<" ";

		}

		cout<<endl;

}


#include<iostream>
#include<cmath>

using namespace std;
int c[200001];

int main()
{
		int n,k=0,i;

		cin>>n;

		int a[n],b[n];

		for(i=0;i<n;i++) cin>>a[i];
		for(i=0;i<n;i++) cin>>b[i];
		//for(i=0;i<n;i++) c[i]=0;

		for(int i=0;i<n;i++)
		{
			for(int j=k;j<n;j++)
			{
				if(b[i]==a[j])
				{
				   c[i]=j-k+1;
				   k=j+1;

				   break;
				}

			}

		}

		for(int i=0;i<n;i++)
		{
			cout<<c[i];
			if(i!=n-1) cout<<" ";

		}

		cout<<endl;

}


#include<iostream>
#include<cmath>

using namespace std;

int main()
{
		int n,k=0,i;

		cin>>n;

		int a[n],b[n],c[n];

		for(i=0;i<n;i++) cin>>a[i];
		for(i=0;i<n;i++) cin>>b[i];
		for(i=0;i<n;i++) c[i]=0;

		for(int i=0;i<n;i++)
		{
			for(int j=k;j<n;j++)
			{
				if(b[i]==a[j])
				{
				   c[i]=j-k+1;
				   k=j+1;

				   break;
				}

			}

		}

		for(int i=0;i<n;i++)
		{
			cout<<c[i];
			if(i!=n-1) cout<<" ";

		}

		cout<<endl;

}


#include<iostream>
using namespace std;

int n,x,curInd=0,num;
int arr[200002];
int main() {
   cin>>n;
   for(int i=1;i<=n;i++) {
      cin>>x;
      arr[x]=i;
   }
   for(int i=0;i<n;i++) {
      cin>>x;
      x=max(0,arr[x]-curInd);
      cout<<x<<" ";
      curInd+=x;
   }
}


#include <bits/stdc++.h>

#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define FORD(i,a,b) for(int i = (a); i >= (b); i--)
#define REP(i,a) for(int i = 0; i < (a); i++)
#define REPD(i,a) for(int i = (a)-1; i >= 0; i--)
#define sz(a) (int)a.size()
#define ALL(a) a.begin(),a.end()

#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back

using namespace std;
queue <long> book;
vector <long> tempp;
int order[200000];
int n,temp;
int main()
{
    cin>>n;
    FOR(i,0,n-1){
        cin>>temp;
        book.push(temp);}
    FOR(i,0,n-1) cin>>order[i];
    /*cout<<book.front();
    book.pop();
    cout<<book.front();
    book.pop();
    cout<<book.front();*/
    FOR(i,0,n-1){
        int cnt=1, temp2 = 0;
        if (tempp.empty()==false){
            FOR(j,0,tempp.size()-1){
                if (order[i]==tempp.at(j)) {
                    cout <<0<<" ";
                    tempp.erase(tempp.begin()+j);
                    temp2=1;}
            }
        }
        if (temp2 == 1) continue;
        while(book.front()!= order[i]){
            cnt++;
            tempp.push_back(book.front());
            book.pop();
        }
        if( book.front()==order[i]) {tempp.push_back(book.front()); book.pop();}
        cout<<cnt<< " ";
    }
    return 0;
}


#include <bits/stdc++.h>

#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define FORD(i,a,b) for(int i = (a); i >= (b); i--)
#define REP(i,a) for(int i = 0; i < (a); i++)
#define REPD(i,a) for(int i = (a)-1; i >= 0; i--)
#define sz(a) (int)a.size()
#define ALL(a) a.begin(),a.end()

#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back

using namespace std;
/*queue <long> book;
vector <long> tempp;
int order[200001];*/
int n,curInd=0,x;
int book[200002];
int main()
{
    cin>>n;
    /*FOR(i,0,n-1){
        cin>>temp;
        book.push(temp);}
    FOR(i,0,n-1) cin>>order[i];
    cout<<book.front();
    book.pop();
    cout<<book.front();
    book.pop();
    cout<<book.front();*/
    /*FOR(i,0,n-1){
        int cnt=1, temp2 = 0;
        if (tempp.empty()==false){
            FOR(j,0,tempp.size()-1){
                if (order[i]==tempp.at(j)) {
                    cout <<0<<" ";
                    tempp.erase(tempp.begin()+j);
                    temp2=1;}
            }
        }
        if (temp2 == 1) continue;
        while(book.front()!= order[i]){
            cnt++;
            tempp.push_back(book.front());
            book.pop();
        }
        if( book.front()==order[i]) {tempp.push_back(book.front()); book.pop();}
        cout<<cnt<< " ";
    }*/
    //////////////////////////////
    FOR(i,1,n){
        cin>>x;
        book[x]=i;
    }
    FOR(i,0,n-1){
        cin>>x;
        cout<<max(0,book[x]-curInd);
        //cout<<x<<" ";
        curInd=max(x,book[x]);
    }
    return 0;
}


#include <bits/stdc++.h>

#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define FORD(i,a,b) for(int i = (a); i >= (b); i--)
#define REP(i,a) for(int i = 0; i < (a); i++)
#define REPD(i,a) for(int i = (a)-1; i >= 0; i--)
#define sz(a) (int)a.size()
#define ALL(a) a.begin(),a.end()

#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back

using namespace std;
queue <long> book;
vector <long> tempp;
int order[200000];
int n,temp;
int main()
{
    cin>>n;
    FOR(i,0,n-1){
        cin>>temp;
        book.push(temp);}
    FOR(i,0,n-1) cin>>order[i];
    /*cout<<book.front();
    book.pop();
    cout<<book.front();
    book.pop();
    cout<<book.front();*/
    FOR(i,0,n-1){
        int cnt=1, temp2 = 0;
        if (tempp.empty()==false){
            FOR(j,0,tempp.size()-1){
                if (order[i]==tempp.at(j)) {
                    cout <<0<<" ";
                    temp2=1;}
            }
        }
        if (temp2 == 1) continue;
        while(book.front()!= order[i]){
            cnt++;
            tempp.push_back(book.front());
            book.pop();
        }
        if( book.front()==order[i]) {tempp.push_back(book.front()); book.pop();}
        cout<<cnt<< " ";
    }
    return 0;
}


#include <bits/stdc++.h>

#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define FORD(i,a,b) for(int i = (a); i >= (b); i--)
#define REP(i,a) for(int i = 0; i < (a); i++)
#define REPD(i,a) for(int i = (a)-1; i >= 0; i--)
#define sz(a) (int)a.size()
#define ALL(a) a.begin(),a.end()

#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back

using namespace std;
/*queue <long> book;
vector <long> tempp;
int order[200001];*/
int n,curInd=0,x;
int book[200002];
int main()
{
    cin>>n;
    /*FOR(i,0,n-1){
        cin>>temp;
        book.push(temp);}
    FOR(i,0,n-1) cin>>order[i];
    cout<<book.front();
    book.pop();
    cout<<book.front();
    book.pop();
    cout<<book.front();*/
    /*FOR(i,0,n-1){
        int cnt=1, temp2 = 0;
        if (tempp.empty()==false){
            FOR(j,0,tempp.size()-1){
                if (order[i]==tempp.at(j)) {
                    cout <<0<<" ";
                    tempp.erase(tempp.begin()+j);
                    temp2=1;}
            }
        }
        if (temp2 == 1) continue;
        while(book.front()!= order[i]){
            cnt++;
            tempp.push_back(book.front());
            book.pop();
        }
        if( book.front()==order[i]) {tempp.push_back(book.front()); book.pop();}
        cout<<cnt<< " ";
    }*/
    //////////////////////////////
    FOR(i,1,n){
        cin>>x;
        book[x]=i;
    }
    FOR(i,0,n-1){
        cin>>x;
        cout<<max(0,book[x]-curInd)<<" ";
        //cout<<x<<" ";
        curInd=max(curInd,book[x]);
    }
    return 0;
}


#include <bits/stdc++.h>

#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define FORD(i,a,b) for(int i = (a); i >= (b); i--)
#define REP(i,a) for(int i = 0; i < (a); i++)
#define REPD(i,a) for(int i = (a)-1; i >= 0; i--)
#define sz(a) (int)a.size()
#define ALL(a) a.begin(),a.end()

#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back

using namespace std;
/*queue <long> book;
vector <long> tempp;
int order[200001];*/
int n,curInd=0,x;
int book[200002];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin>>n;
    /*FOR(i,0,n-1){
        cin>>temp;
        book.push(temp);}
    FOR(i,0,n-1) cin>>order[i];
    cout<<book.front();
    book.pop();
    cout<<book.front();
    book.pop();
    cout<<book.front();*/
    /*FOR(i,0,n-1){
        int cnt=1, temp2 = 0;
        if (tempp.empty()==false){
            FOR(j,0,tempp.size()-1){
                if (order[i]==tempp.at(j)) {
                    cout <<0<<" ";
                    tempp.erase(tempp.begin()+j);
                    temp2=1;}
            }
        }
        if (temp2 == 1) continue;
        while(book.front()!= order[i]){
            cnt++;
            tempp.push_back(book.front());
            book.pop();
        }
        if( book.front()==order[i]) {tempp.push_back(book.front()); book.pop();}
        cout<<cnt<< " ";
    }*/
    //////////////////////////////
    FOR(i,1,n){
        cin>>x;
        book[x]=i;
    }
    FOR(i,0,n-1){
        cin>>x;
        cout<<max(0,book[x]-curInd)<<" ";
        //cout<<x<<" ";
        curInd=max(curInd,book[x]);
    }
    return 0;
}


 #include<iostream>
using namespace std;

int n,x,curInd=0,num;
int arr[200002];
int main() {
   cin>>n;
   for(int i=1;i<=n;i++) {
      cin>>x;
      arr[x]=i;
   }
   for(int i=0;i<n;i++) {
      cin>>x;
      x=max(0,arr[x]-curInd);
      cout<<x<<" ";
      curInd+=x;
   }
   return 0;
}


#include <bits/stdc++.h>

#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define FORD(i,a,b) for(int i = (a); i >= (b); i--)
#define REP(i,a) for(int i = 0; i < (a); i++)
#define REPD(i,a) for(int i = (a)-1; i >= 0; i--)
#define sz(a) (int)a.size()
#define ALL(a) a.begin(),a.end()

#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back

using namespace std;
/*queue <long> book;
vector <long> tempp;
int order[200001];*/
int n,curInd=0,x;
int book[200002];
int main()
{
    cin>>n;
    /*FOR(i,0,n-1){
        cin>>temp;
        book.push(temp);}
    FOR(i,0,n-1) cin>>order[i];
    cout<<book.front();
    book.pop();
    cout<<book.front();
    book.pop();
    cout<<book.front();*/
    /*FOR(i,0,n-1){
        int cnt=1, temp2 = 0;
        if (tempp.empty()==false){
            FOR(j,0,tempp.size()-1){
                if (order[i]==tempp.at(j)) {
                    cout <<0<<" ";
                    tempp.erase(tempp.begin()+j);
                    temp2=1;}
            }
        }
        if (temp2 == 1) continue;
        while(book.front()!= order[i]){
            cnt++;
            tempp.push_back(book.front());
            book.pop();
        }
        if( book.front()==order[i]) {tempp.push_back(book.front()); book.pop();}
        cout<<cnt<< " ";
    }*/
    //////////////////////////////
    FOR(i,1,n){
        cin>>x;
        book[x]=i;
    }
    FOR(i,0,n-1){
        cin>>x;
        cout<<max(0,book[x]-curInd);
        //cout<<x<<" ";
        curInd=max(curInd,book[x]);
    }
    return 0;
}


#include <bits/stdc++.h>

#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define FORD(i,a,b) for(int i = (a); i >= (b); i--)
#define REP(i,a) for(int i = 0; i < (a); i++)
#define REPD(i,a) for(int i = (a)-1; i >= 0; i--)
#define sz(a) (int)a.size()
#define ALL(a) a.begin(),a.end()

#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back

using namespace std;
/*queue <long> book;
vector <long> tempp;*/
int order[200001];
int n,temp,currentIndex=0,x;
int book[200001];
int main()
{
    cin>>n;
    /*FOR(i,0,n-1){
        cin>>temp;
        book.push(temp);}
    FOR(i,0,n-1) cin>>order[i];
    cout<<book.front();
    book.pop();
    cout<<book.front();
    book.pop();
    cout<<book.front();*/
    /*FOR(i,0,n-1){
        int cnt=1, temp2 = 0;
        if (tempp.empty()==false){
            FOR(j,0,tempp.size()-1){
                if (order[i]==tempp.at(j)) {
                    cout <<0<<" ";
                    tempp.erase(tempp.begin()+j);
                    temp2=1;}
            }
        }
        if (temp2 == 1) continue;
        while(book.front()!= order[i]){
            cnt++;
            tempp.push_back(book.front());
            book.pop();
        }
        if( book.front()==order[i]) {tempp.push_back(book.front()); book.pop();}
        cout<<cnt<< " ";
    }*/
    //////////////////////////////
    FOR(i,1,n){
        cin>>x;
        book[x]=i;
    }
    FOR(i,0,n-1){
        cin>>x;
        x=max(0,book[x]-currentIndex);
        cout<<x<<" ";
        currentIndex+=x;
    }
    return 0;
}


#include <bits/stdc++.h>

#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define FORD(i,a,b) for(int i = (a); i >= (b); i--)
#define REP(i,a) for(int i = 0; i < (a); i++)
#define REPD(i,a) for(int i = (a)-1; i >= 0; i--)
#define sz(a) (int)a.size()
#define ALL(a) a.begin(),a.end()

#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back

using namespace std;
/*queue <long> book;
vector <long> tempp;
int order[200001];*/
int n,curInd=0,x;
int book[200002];
int main()
{
    cin>>n;
    /*FOR(i,0,n-1){
        cin>>temp;
        book.push(temp);}
    FOR(i,0,n-1) cin>>order[i];
    cout<<book.front();
    book.pop();
    cout<<book.front();
    book.pop();
    cout<<book.front();*/
    /*FOR(i,0,n-1){
        int cnt=1, temp2 = 0;
        if (tempp.empty()==false){
            FOR(j,0,tempp.size()-1){
                if (order[i]==tempp.at(j)) {
                    cout <<0<<" ";
                    tempp.erase(tempp.begin()+j);
                    temp2=1;}
            }
        }
        if (temp2 == 1) continue;
        while(book.front()!= order[i]){
            cnt++;
            tempp.push_back(book.front());
            book.pop();
        }
        if( book.front()==order[i]) {tempp.push_back(book.front()); book.pop();}
        cout<<cnt<< " ";
    }*/
    //////////////////////////////
    FOR(i,1,n){
        cin>>x;
        book[x]=i;
    }
    FOR(i,0,n-1){
        cin>>x;
        x=max(0,book[x]-curInd);
        cout<<x<<" ";
        curInd=max(x,book[x]);
    }
    return 0;
}


 #include<bits/stdc++.h>
using namespace std;
int a[200005],n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		a[x]=i;
	}
	int ml=0;
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		printf("%d ",max(0,a[x]-ml));
		ml=max(ml,a[x]);
	}
}


#include <bits/stdc++.h>

#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define FORD(i,a,b) for(int i = (a); i >= (b); i--)
#define REP(i,a) for(int i = 0; i < (a); i++)
#define REPD(i,a) for(int i = (a)-1; i >= 0; i--)
#define sz(a) (int)a.size()
#define ALL(a) a.begin(),a.end()

#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
using namespace std;

int n,x,curInd=0,num;
int arr[200002];
int main() {
   cin>>n;
   for(int i=1;i<=n;i++) {
      cin>>x;
      arr[x]=i;
   }
   for(int i=0;i<n;i++) {
      cin>>x;
      x=max(0,arr[x]-curInd);
      cout<<x<<" ";
      curInd+=x;
   }
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,i,value,limit=0,ans=0,sum=0;
	map <int,int> m;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>value;
		m[value]=(i+1);
	}
	for(i=0;i<n;i++){
		cin>>ans;
		if(m[ans]>0 && m[ans]>limit){
			sum=abs(m[ans]-limit);
			limit=m[ans];
			cout<<sum<<" ";
			continue;
		}
		cout<<"0 ";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,i,value,limit=0,ans=0,sum=0;
	cin>>n;
	vector <int> m(n+1,0);
	for(i=0;i<n;i++){
		cin>>value;
		m[value]=(i+1);
	}
	for(i=0;i<n;i++){
		cin>>ans;
		if(ans>n){
			cout<<"0 ";
			continue;
		}
		if(m[ans]>0 && m[ans]>limit){
			sum=(m[ans]-limit);
			limit=m[ans];
			cout<<sum<<" ";
			continue;
		}
		cout<<"0 ";
	}
	return 0;
}


#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
int main(){
//	ios_base::sync_with_stdio(0);
	long int n,i,value,limit=0,ans=0,sum=0;
	scanf("%d",&n);
	vector <long int> m(n+1,0);
	for(i=0;i<n;i++){
		scanf("%ld",&value);
		m[value]=(i+1);
	}
	for(i=0;i<n;i++){
		scanf("%ld",&ans);
		if(ans>n){
			printf("0 ");
			continue;
		}
		if(m[ans]>0 && m[ans]>limit){
			sum=(m[ans]-limit);
			limit=m[ans];
			printf("%d ",sum);
			continue;
		}
		printf("0 ");
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int index,n,i,value,limit=0,ans=0,sum=0;
	cin>>n;
	vector <long int> m(n,0);
	vector <long int>:: iterator it,itr;
	for(i=0;i<n;i++){
		cin>>m[i];
	}
	itr=m.begin();
	for(i=0;i<n;i++){
		cin>>ans;
		if(ans>n){
			cout<<"0 ";
			continue;
		}
		it=find(itr,m.end(),ans);
		if(it!=m.end()){
			index=distance(m.begin(),it);
			index++;
			if(index>limit){
				sum=(index-limit);
				limit=index;
				itr=(m.begin()+(limit-1));
				cout<<sum<<" ";
				continue;
			}
			else{
				cout<<"0 ";
			}
		}
		else{
			cout<<"0 ";
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int index,n,i,value,limit=0,ans=0,sum=0;
	cin>>n;
	vector <long int> m(n,0);
	vector <long int>:: iterator it,itr;
	for(i=0;i<n;i++){
		cin>>m[i];
//		m[value]=(i+1);
	}
	itr=m.begin();
	for(i=0;i<n;i++){
		cin>>ans;
		it=find(itr,m.end(),ans);
		if(it!=m.end()){
			index=distance(m.begin(),it);
			index++;
	//		cout<<index<<"\n";
			if(index>limit){
				sum=(index-limit);
				limit=index;
				itr=(m.begin()+(limit-1));
				cout<<sum<<" ";
				continue;
			}
			else{
				cout<<"0 ";
			}
		}
		else{
			cout<<"0 ";
		}
	}
	/*	if(m[ans]>0 && m[ans]>limit){
			sum=(m[ans]-limit);
			limit=m[ans];
			cout<<sum<<" ";
			continue;
		}
		cout<<"0 ";*/
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(0);
	long int n,i,value,limit=0,ans=0,sum=0;
	cin>>n;
	vector <long int> m(n+1,0);
	for(i=0;i<n;i++){
		cin>>value;
		m[value]=(i+1);
	}
	for(i=0;i<n;i++){
		cin>>ans;
		if(ans>n){
			cout<<"0 ";
			continue;
		}
		if(m[ans]>0 && m[ans]>limit){
			sum=(m[ans]-limit);
			limit=m[ans];
			cout<<sum<<" ";
			continue;
		}
		cout<<"0 ";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	long int n,i,value,limit=0,ans=0,sum=0;
	cin>>n;
	vector <long int> m(n+1,0);
	for(i=0;i<n;i++){
		cin>>value;
		m[value]=(i+1);
	}
	for(i=0;i<n;i++){
		cin>>ans;
		if(ans>n){
			cout<<"0 ";
			continue;
		}
		if(m[ans]>0 && m[ans]>limit){
			sum=(m[ans]-limit);
			limit=m[ans];
			cout<<sum<<" ";
			continue;
		}
		cout<<"0 ";
	}
	return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define int  long long
#define fastio ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#undef int
int main() {
    #define int  long long
    //fastio;
    int n;
    cin>>n;
    int a[200000+10];
    for(int i=0;i<n;i++){

        int c;cin>>c;
        a[c]=i+1;
    }int index=0;
    for(int i=0;i<n;i++){
        int v;cin>>v;
        if(a[v]>index){
            cout<<a[v]-index<<" ";
            index=a[v];
        }
        else cout<<0<<" ";
    }
    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define int  long long
#define fastio ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#undef int
int main() {
    #define int  long long
    fastio;
    int n;int c;int v;
    cin>>n;
    int a[200000+10];
    for(int i=0;i<n;i++){

        cin>>c;
        a[c]=i+1;
    }int index=0;
    for(int i=0;i<n;i++){
        cin>>v;
        if(a[v]>index){
            cout<<a[v]-index<<" ";
            index=a[v];
        }
        else cout<<0<<" ";
    }
    return 0;

}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
//#define int  long long
#define fastio ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
//#undef int
int main() {
  //  #define int  long long
    //fastio;
    int n;int c;int v;
    cin>>n;
    int a[200000+10];
    for(int i=0;i<n;i++){

        cin>>c;
        a[c]=i+1;
    }int index=0;
    for(int i=0;i<n;i++){
        cin>>v;
        if(a[v]>index){
            cout<<a[v]-index<<" ";
            index=a[v];
        }
        else cout<<0<<" ";
    }
    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
//#define int  long long
#define fastio ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
//#undef int
int main() {
  //  #define int  long long
    //fastio;
    int n;int c;int v;
    cin>>n;
    int a[200000+10];
    for(int i=0;i<n;i++){

        cin>>c;
        a[c]=i+1;
    }int index=0;
    for(int i=0;i<n;i++){
        int v;cin>>v;
        if(a[v]>index){
            cout<<a[v]-index<<" ";
            index=a[v];
        }
        else cout<<0<<" ";
    }
    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define int  long long
#define fastio ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#undef int
int main() {
    #define int  long long
    fastio;
    int n;
    cin>>n;
    int a[200000+10];
    for(int i=0;i<n;i++){

        int c;cin>>c;
        a[c]=i+1;
    }int index=0;
    for(int i=0;i<n;i++){
        int v;cin>>v;
        if(a[v]>index){
            cout<<a[v]-index<<" ";
            index=a[v];
        }
        else cout<<0<<" ";
    }
    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
//#define int  long long
#define fastio ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
//#undef int
int main() {
  //  #define int  long long
    //fastio;
    int n;
    cin>>n;
    int a[200000+10];
    for(int i=0;i<n;i++){

        int c;cin>>c;
        a[c]=i+1;
    }int index=0;
    for(int i=0;i<n;i++){
        int v;cin>>v;
        if(a[v]>index){
            cout<<a[v]-index<<" ";
            index=a[v];
        }
        else cout<<0<<" ";
    }
    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define int  long long
#define fastio ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#undef int
int main() {
    #define int  long long
    fastio;
    int n;int c;int v;
    cin>>n;
    int a[200000+10];
    for(int i=0;i<n;i++){

        cin>>c;
        a[c]=i+1;
    }int index=0;
    for(int i=0;i<n;i++){
        cin>>v;
        if(a[v]>index){
            cout<<a[v]-index<<" ";
            index=a[v];
        }
        else cout<<0<<" ";
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<iomanip>
#include<iterator>
#include <cstdio>
#include <vector>
#include <string>
#include <regex>
#include <numeric>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include<utility>
#include<random>
#include<bitset>
#include<list>
#include<functional>
using namespace std;
template<class T, typename A = allocator<T>>
class Vector : public vector<T, A>
{
public:
	using vector<T, A>::vector;
	Vector& operator()(size_t dummy_n) // additional init_val needs its own specification for Vector<string>
	{
		return *this;
	}
};
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef Vector<int> vi; // Vector
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pdd> vpdd;
typedef vector<string> vs;
typedef set<int> si;
typedef multiset<int> Si;
typedef map<int, int> mi;
typedef multimap<int, int> Mi;
template <typename Int = int>
Int read()
{
	Int flag = 1;
	char c = getchar();
	while ((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();
	if (c == '-') flag = -1, c = getchar();
	Int init = c & 15;
	while ((c = getchar()) >= '0' && c <= '9') init = (init << 3) + (init << 1) + (c & 15);
	return init * flag;
}
void read(char& a) { do scanf("%c", &a); while (isspace(a)); }
void write(const char& a) { printf("%c", a); }
char BUF[1234560];
void read(string& a) { scanf("%s", BUF); a = string(BUF); }
void write(const string& a) { printf("%s", a.c_str()); }
inline void read(int& a) { /*scanf("%d", &a);*/a = read(); }
void write(const int& a) { printf("%d", a); }
//void write(const size_t& a) { printf("%u", a); }
void read(ll& a) { scanf("%I64d", &a); }
void write(const ll& a) { printf("%I64d", a); }
void read(double& a) { scanf("%lf", &a); }
void write(const double& a) { printf("%lf", a); }
void read(ld& a) { scanf("%Lf", &a); }
void write(const ld& a) { printf("%Lf", a); }
void read(pair<int, int>& a) { scanf("%d%d", &a.first, &a.second); }
void write(const pair<int, int>& a) { printf("%d %d", a.first, a.second); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void read(C<T>& a) { for (auto i = a.begin(); i != a.end(); ++i) read(*i); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void write(const C<T>& a) { int sz = a.size(); if (sz != 0) write(a[0]); for (int i = 1; i < sz; ++i) { write(' '); write(a[i]); } }
template<typename T1, typename T2>
void read(T1& t1, T2& t2) { read(t1); read(t2); }
template<typename T1, typename T2>
void write(const T1& t1, const T2& t2) { write(t1); write(' '); write(t2); }
template<typename T1, typename T2, typename T3>
void read(T1& t1, T2& t2, T3& t3) { read(t1); read(t2); read(t3); }
template<typename T1, typename T2, typename T3, typename T4>
void read(T1& t1, T2& t2, T3& t3, T4& t4) { read(t1); read(t2); read(t3); read(t4); }
template<typename T1, typename T2, typename T3>
void write(const T1& t1, const T2& t2, const T3& t3) { write(t1); write(' '); write(t2); write(' '); write(t3); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void sort(C<T>& a) { sort(a.begin(), a.end()); }
void sort(string& a) { sort(a.begin(), a.end()); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void rsort(C<T>& a) { sort(a.rbegin(), a.rend()); }
void rsort(string& a) { sort(a.rbegin(), a.rend()); }
template<typename T>
int sz(const T& a) { return int(a.size()); }
#define MX 1000000000
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define T(n) for(int _VARIABLE{(n) + 1}; --_VARIABLE;)
#define F(b,e,i) for(auto i = (b); i != (e); (b) < decltype(b)(e) ? ++i : --i)
#define G(f,l,i) for(auto i = (f) + ((f) < decltype(f)(l) ? -1 : 1); ((f) < decltype(f)(l) ? i++ : i--) != (l) ;)
#define M(f,l,i,j) for(auto i = (f) , j = decltype(f)(l) ; i < j; ++i, --j)
#define r(...) read(__VA_ARGS__)
#define R(type, ...) type __VA_ARGS__; r(__VA_ARGS__)
#define w(...) write(__VA_ARGS__)
#define W(...) write(__VA_ARGS__), write('\n')
#define bgn begin()
#define rbgn rbegin()
#define nd end()
#define rnd rend()
#define pb push_back
#define fnt front()
#define bck back()
#define x first
#define y second

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	int n{ r() };
	vi a(n), b(n);
	{
		for (auto& a_el : a)
			read(a_el);
		for (auto& b_el : b)
			read(b_el);
	}
	vi name_to_ind(n + 1);
	{
		int i{ -1 };
		for (const auto& a_el : a)
			name_to_ind[a_el] = ++i;
	}
	vi ans; ans.reserve(n);
	{
		int l{ -1 };
		for (const auto& b_el : b)
			if (int wh{ name_to_ind[b_el] }; wh > l) {
				ans.pb(wh - l);
				l = wh;
			}
			else
				ans.pb(0);
	}
	W(ans);
}
//
// ArtemParkhomets
//


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<iomanip>
#include<iterator>
#include <cstdio>
#include <vector>
#include <string>
#include <regex>
#include <numeric>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include<utility>
#include<random>
#include<bitset>
#include<list>
#include<functional>
using namespace std;
template<class T, typename A = allocator<T>>
class Vector : public vector<T, A>
{
public:
	using vector<T, A>::vector;
	Vector& operator()(size_t dummy_n) // additional init_val needs its own specification for Vector<string>
	{
		return *this;
	}
};
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef Vector<int> vi; // Vector
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pdd> vpdd;
typedef vector<string> vs;
typedef set<int> si;
typedef multiset<int> Si;
typedef map<int, int> mi;
typedef multimap<int, int> Mi;
template <typename Int = int>
Int read()
{
	Int flag = 1;
	char c = getchar();
	while ((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();
	if (c == '-') flag = -1, c = getchar();
	Int init = c & 15;
	while ((c = getchar()) >= '0' && c <= '9') init = (init << 3) + (init << 1) + (c & 15);
	return init * flag;
}
void read(char& a) { do scanf("%c", &a); while (isspace(a)); }
void write(const char& a) { printf("%c", a); }
char BUF[1234560];
void read(string& a) { scanf("%s", BUF); a = string(BUF); }
void write(const string& a) { printf("%s", a.c_str()); }
inline void read(int& a) { /*scanf("%d", &a);*/a = read(); }
void write(const int& a) { printf("%d", a); }
//void write(const size_t& a) { printf("%u", a); }
void read(ll& a) { scanf("%I64d", &a); }
void write(const ll& a) { printf("%I64d", a); }
void read(double& a) { scanf("%lf", &a); }
void write(const double& a) { printf("%lf", a); }
void read(ld& a) { scanf("%Lf", &a); }
void write(const ld& a) { printf("%Lf", a); }
void read(pair<int, int>& a) { scanf("%d%d", &a.first, &a.second); }
void write(const pair<int, int>& a) { printf("%d %d", a.first, a.second); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void read(C<T>& a) { for (auto i = a.begin(); i != a.end(); ++i) read(*i); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void write(const C<T>& a) { int sz = a.size(); if (sz != 0) write(a[0]); for (int i = 1; i < sz; ++i) { write(' '); write(a[i]); } }
template<typename T1, typename T2>
void read(T1& t1, T2& t2) { read(t1); read(t2); }
template<typename T1, typename T2>
void write(const T1& t1, const T2& t2) { write(t1); write(' '); write(t2); }
template<typename T1, typename T2, typename T3>
void read(T1& t1, T2& t2, T3& t3) { read(t1); read(t2); read(t3); }
template<typename T1, typename T2, typename T3, typename T4>
void read(T1& t1, T2& t2, T3& t3, T4& t4) { read(t1); read(t2); read(t3); read(t4); }
template<typename T1, typename T2, typename T3>
void write(const T1& t1, const T2& t2, const T3& t3) { write(t1); write(' '); write(t2); write(' '); write(t3); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void sort(C<T>& a) { sort(a.begin(), a.end()); }
void sort(string& a) { sort(a.begin(), a.end()); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void rsort(C<T>& a) { sort(a.rbegin(), a.rend()); }
void rsort(string& a) { sort(a.rbegin(), a.rend()); }
template<typename T>
int sz(const T& a) { return int(a.size()); }
#define MX 1000000000
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define T(n) for(int _VARIABLE{(n) + 1}; --_VARIABLE;)
#define F(b,e,i) for(auto i = (b); i != (e); (b) < decltype(b)(e) ? ++i : --i)
#define G(f,l,i) for(auto i = (f) + ((f) < decltype(f)(l) ? -1 : 1); ((f) < decltype(f)(l) ? i++ : i--) != (l) ;)
#define M(f,l,i,j) for(auto i = (f) , j = decltype(f)(l) ; i < j; ++i, --j)
#define r(...) read(__VA_ARGS__)
#define R(type, ...) type __VA_ARGS__; r(__VA_ARGS__)
#define w(...) write(__VA_ARGS__)
#define W(...) write(__VA_ARGS__), write('\n')
#define bgn begin()
#define rbgn rbegin()
#define nd end()
#define rnd rend()
#define pb push_back
#define fnt front()
#define bck back()
#define x first
#define y second

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	R(int, n);
	R(vi, a(n), b(n));
	vi name_to_ind(n+1);
	F(0, n, i)
		name_to_ind[a[i]] = i;
	vi ans;
	for (int l{ -1 }, i{}; i < n; ++i)
		if (int wh{ name_to_ind[b[i]] }; wh > l) {
			ans.pb(wh - l);
			l = wh;
		}
		else
			ans.pb(0);
	W(ans);
}
//
// ArtemParkhomets
//


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<iomanip>
#include<iterator>
#include <cstdio>
#include <vector>
#include <string>
#include <regex>
#include <numeric>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include<utility>
#include<random>
#include<bitset>
#include<list>
#include<functional>
using namespace std;
template<class T, typename A = allocator<T>>
class Vector : public vector<T, A>
{
public:
	using vector<T, A>::vector;
	Vector& operator()(size_t dummy_n) // additional init_val needs its own specification for Vector<string>
	{
		return *this;
	}
};
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef Vector<int> vi; // Vector
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pdd> vpdd;
typedef vector<string> vs;
typedef set<int> si;
typedef multiset<int> Si;
typedef map<int, int> mi;
typedef multimap<int, int> Mi;
template <typename Int = int>
Int read()
{
	Int flag = 1;
	char c = getchar();
	while ((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();
	if (c == '-') flag = -1, c = getchar();
	Int init = c & 15;
	while ((c = getchar()) >= '0' && c <= '9') init = (init << 3) + (init << 1) + (c & 15);
	return init * flag;
}
void read(char& a) { do scanf("%c", &a); while (isspace(a)); }
void write(const char& a) { printf("%c", a); }
char BUF[1234560];
void read(string& a) { scanf("%s", BUF); a = string(BUF); }
void write(const string& a) { printf("%s", a.c_str()); }
inline void read(int& a) { /*scanf("%d", &a);*/a = read(); }
void write(const int& a) { printf("%d", a); }
//void write(const size_t& a) { printf("%u", a); }
void read(ll& a) { scanf("%I64d", &a); }
void write(const ll& a) { printf("%I64d", a); }
void read(double& a) { scanf("%lf", &a); }
void write(const double& a) { printf("%lf", a); }
void read(ld& a) { scanf("%Lf", &a); }
void write(const ld& a) { printf("%Lf", a); }
void read(pair<int, int>& a) { scanf("%d%d", &a.first, &a.second); }
void write(const pair<int, int>& a) { printf("%d %d", a.first, a.second); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void read(C<T>& a) { for (auto i = a.begin(); i != a.end(); ++i) read(*i); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void write(const C<T>& a) { int sz = a.size(); if (sz != 0) write(a[0]); for (int i = 1; i < sz; ++i) { write(' '); write(a[i]); } }
template<typename T1, typename T2>
void read(T1& t1, T2& t2) { read(t1); read(t2); }
template<typename T1, typename T2>
void write(const T1& t1, const T2& t2) { write(t1); write(' '); write(t2); }
template<typename T1, typename T2, typename T3>
void read(T1& t1, T2& t2, T3& t3) { read(t1); read(t2); read(t3); }
template<typename T1, typename T2, typename T3, typename T4>
void read(T1& t1, T2& t2, T3& t3, T4& t4) { read(t1); read(t2); read(t3); read(t4); }
template<typename T1, typename T2, typename T3>
void write(const T1& t1, const T2& t2, const T3& t3) { write(t1); write(' '); write(t2); write(' '); write(t3); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void sort(C<T>& a) { sort(a.begin(), a.end()); }
void sort(string& a) { sort(a.begin(), a.end()); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void rsort(C<T>& a) { sort(a.rbegin(), a.rend()); }
void rsort(string& a) { sort(a.rbegin(), a.rend()); }
template<typename T>
int sz(const T& a) { return int(a.size()); }
#define MX 1000000000
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define T(n) for(int _VARIABLE{(n) + 1}; --_VARIABLE;)
#define F(b,e,i) for(auto i = (b); i != (e); (b) < decltype(b)(e) ? ++i : --i)
#define G(f,l,i) for(auto i = (f) + ((f) < decltype(f)(l) ? -1 : 1); ((f) < decltype(f)(l) ? i++ : i--) != (l) ;)
#define M(f,l,i,j) for(auto i = (f) , j = decltype(f)(l) ; i < j; ++i, --j)
#define r(...) read(__VA_ARGS__)
#define R(type, ...) type __VA_ARGS__; r(__VA_ARGS__)
#define w(...) write(__VA_ARGS__)
#define W(...) write(__VA_ARGS__), write('\n')
#define bgn begin()
#define rbgn rbegin()
#define nd end()
#define rnd rend()
#define pb push_back
#define fnt front()
#define bck back()
#define x first
#define y second

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	int n{ r() };
	int name_to_ind[200001], a[200001], b[200001], ans[200001];
	{
		for (int* i{ a }, *e{ a + n }; i != e; ++i)
			read(*i);
		for (int* i{ b }, *e{ b + n }; i != e; ++i)
			read(*i);
	}
	{
		int ind{ -1 };
		for (int* i{ a }, *e{ a + n }; i != e; ++i)
			name_to_ind[*i] = ++ind;
	}
	{
		int l{ -1 }, ans_ind{-1};
		for (int* i{ b }, *e{ b + n }; i != e; ++i)
			if (int wh{ name_to_ind[*i] }; wh > l) {
				ans[++ans_ind] = wh - l;
				l = wh;
			}
			else
				ans[++ans_ind] = 0;
	}
	for (int* i{ ans }, *e{ ans + n }; i != e; ++i)
		printf("%d ", *i);
}
//
// ArtemParkhomets
//


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<iomanip>
#include<iterator>
#include <cstdio>
#include <vector>
#include <string>
#include <regex>
#include <numeric>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include<utility>
#include<random>
#include<bitset>
#include<list>
#include<functional>
using namespace std;
template<class T, typename A = allocator<T>>
class Vector : public vector<T, A>
{
public:
	using vector<T, A>::vector;
	Vector& operator()(size_t dummy_n) // additional init_val needs its own specification for Vector<string>
	{
		return *this;
	}
};
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef Vector<int> vi; // Vector
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pdd> vpdd;
typedef vector<string> vs;
typedef set<int> si;
typedef multiset<int> Si;
typedef map<int, int> mi;
typedef multimap<int, int> Mi;
template <typename Int = int>
Int read()
{
	Int flag = 1;
	char c = getchar();
	while ((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();
	if (c == '-') flag = -1, c = getchar();
	Int init = c & 15;
	while ((c = getchar()) >= '0' && c <= '9') init = (init << 3) + (init << 1) + (c & 15);
	return init * flag;
}
void read(char& a) { do scanf("%c", &a); while (isspace(a)); }
void write(const char& a) { printf("%c", a); }
char BUF[1234560];
void read(string& a) { scanf("%s", BUF); a = string(BUF); }
void write(const string& a) { printf("%s", a.c_str()); }
inline void read(int& a) { /*scanf("%d", &a);*/a = read(); }
void write(const int& a) { printf("%d", a); }
//void write(const size_t& a) { printf("%u", a); }
void read(ll& a) { scanf("%I64d", &a); }
void write(const ll& a) { printf("%I64d", a); }
void read(double& a) { scanf("%lf", &a); }
void write(const double& a) { printf("%lf", a); }
void read(ld& a) { scanf("%Lf", &a); }
void write(const ld& a) { printf("%Lf", a); }
void read(pair<int, int>& a) { scanf("%d%d", &a.first, &a.second); }
void write(const pair<int, int>& a) { printf("%d %d", a.first, a.second); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void read(C<T>& a) { for (auto i = a.begin(); i != a.end(); ++i) read(*i); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void write(const C<T>& a) { int sz = a.size(); if (sz != 0) write(a[0]); for (int i = 1; i < sz; ++i) { write(' '); write(a[i]); } }
template<typename T1, typename T2>
void read(T1& t1, T2& t2) { read(t1); read(t2); }
template<typename T1, typename T2>
void write(const T1& t1, const T2& t2) { write(t1); write(' '); write(t2); }
template<typename T1, typename T2, typename T3>
void read(T1& t1, T2& t2, T3& t3) { read(t1); read(t2); read(t3); }
template<typename T1, typename T2, typename T3, typename T4>
void read(T1& t1, T2& t2, T3& t3, T4& t4) { read(t1); read(t2); read(t3); read(t4); }
template<typename T1, typename T2, typename T3>
void write(const T1& t1, const T2& t2, const T3& t3) { write(t1); write(' '); write(t2); write(' '); write(t3); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void sort(C<T>& a) { sort(a.begin(), a.end()); }
void sort(string& a) { sort(a.begin(), a.end()); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void rsort(C<T>& a) { sort(a.rbegin(), a.rend()); }
void rsort(string& a) { sort(a.rbegin(), a.rend()); }
template<typename T>
int sz(const T& a) { return int(a.size()); }
#define MX 1000000000
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define T(n) for(int _VARIABLE{(n) + 1}; --_VARIABLE;)
#define F(b,e,i) for(auto i = (b); i != (e); (b) < decltype(b)(e) ? ++i : --i)
#define G(f,l,i) for(auto i = (f) + ((f) < decltype(f)(l) ? -1 : 1); ((f) < decltype(f)(l) ? i++ : i--) != (l) ;)
#define M(f,l,i,j) for(auto i = (f) , j = decltype(f)(l) ; i < j; ++i, --j)
#define r(...) read(__VA_ARGS__)
#define R(type, ...) type __VA_ARGS__; r(__VA_ARGS__)
#define w(...) write(__VA_ARGS__)
#define W(...) write(__VA_ARGS__), write('\n')
#define bgn begin()
#define rbgn rbegin()
#define nd end()
#define rnd rend()
#define pb push_back
#define fnt front()
#define bck back()
#define x first
#define y second

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	R(int, n);
	R(vi, a(n), b(n));
	mi name_to_ind;
	F(0, n, i)
		name_to_ind[a[i]] = i;
	vi ans;
	for (int l{ -1 }, i{}; i < n; ++i)
		if (int wh{ name_to_ind[b[i]] }; wh > l) {
			ans.pb(wh - l);
			l = wh;
		}
		else
			ans.pb(0);
	W(ans);
}
//
// ArtemParkhomets
//


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<iomanip>
#include<iterator>
#include <cstdio>
#include <vector>
#include <string>
#include <regex>
#include <numeric>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include<utility>
#include<random>
#include<bitset>
#include<list>
#include<functional>
using namespace std;
template<class T, typename A = allocator<T>>
class Vector : public vector<T, A>
{
public:
	using vector<T, A>::vector;
	Vector& operator()(size_t dummy_n) // additional init_val needs its own specification for Vector<string>
	{
		return *this;
	}
};
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef Vector<int> vi; // Vector
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pdd> vpdd;
typedef vector<string> vs;
typedef set<int> si;
typedef multiset<int> Si;
typedef map<int, int> mi;
typedef multimap<int, int> Mi;
template <typename Int = int>
Int read()
{
	Int flag = 1;
	char c = getchar();
	while ((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();
	if (c == '-') flag = -1, c = getchar();
	Int init = c & 15;
	while ((c = getchar()) >= '0' && c <= '9') init = (init << 3) + (init << 1) + (c & 15);
	return init * flag;
}
void read(char& a) { do scanf("%c", &a); while (isspace(a)); }
void write(const char& a) { printf("%c", a); }
char BUF[1234560];
void read(string& a) { scanf("%s", BUF); a = string(BUF); }
void write(const string& a) { printf("%s", a.c_str()); }
inline void read(int& a) { /*scanf("%d", &a);*/a = read(); }
void write(const int& a) { printf("%d", a); }
//void write(const size_t& a) { printf("%u", a); }
void read(ll& a) { scanf("%I64d", &a); }
void write(const ll& a) { printf("%I64d", a); }
void read(double& a) { scanf("%lf", &a); }
void write(const double& a) { printf("%lf", a); }
void read(ld& a) { scanf("%Lf", &a); }
void write(const ld& a) { printf("%Lf", a); }
void read(pair<int, int>& a) { scanf("%d%d", &a.first, &a.second); }
void write(const pair<int, int>& a) { printf("%d %d", a.first, a.second); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void read(C<T>& a) { for (auto i = a.begin(); i != a.end(); ++i) read(*i); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void write(const C<T>& a) { int sz = a.size(); if (sz != 0) write(a[0]); for (int i = 1; i < sz; ++i) { write(' '); write(a[i]); } }
template<typename T1, typename T2>
void read(T1& t1, T2& t2) { read(t1); read(t2); }
template<typename T1, typename T2>
void write(const T1& t1, const T2& t2) { write(t1); write(' '); write(t2); }
template<typename T1, typename T2, typename T3>
void read(T1& t1, T2& t2, T3& t3) { read(t1); read(t2); read(t3); }
template<typename T1, typename T2, typename T3, typename T4>
void read(T1& t1, T2& t2, T3& t3, T4& t4) { read(t1); read(t2); read(t3); read(t4); }
template<typename T1, typename T2, typename T3>
void write(const T1& t1, const T2& t2, const T3& t3) { write(t1); write(' '); write(t2); write(' '); write(t3); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void sort(C<T>& a) { sort(a.begin(), a.end()); }
void sort(string& a) { sort(a.begin(), a.end()); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void rsort(C<T>& a) { sort(a.rbegin(), a.rend()); }
void rsort(string& a) { sort(a.rbegin(), a.rend()); }
template<typename T>
int sz(const T& a) { return int(a.size()); }
#define MX 1000000000
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define T(n) for(int _VARIABLE{(n) + 1}; --_VARIABLE;)
#define F(b,e,i) for(auto i = (b); i != (e); (b) < decltype(b)(e) ? ++i : --i)
#define G(f,l,i) for(auto i = (f) + ((f) < decltype(f)(l) ? -1 : 1); ((f) < decltype(f)(l) ? i++ : i--) != (l) ;)
#define M(f,l,i,j) for(auto i = (f) , j = decltype(f)(l) ; i < j; ++i, --j)
#define r(...) read(__VA_ARGS__)
#define R(type, ...) type __VA_ARGS__; r(__VA_ARGS__)
#define w(...) write(__VA_ARGS__)
#define W(...) write(__VA_ARGS__), write('\n')
#define bgn begin()
#define rbgn rbegin()
#define nd end()
#define rnd rend()
#define pb push_back
#define fnt front()
#define bck back()
#define x first
#define y second

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	int n{ r() };
	vi a(n), b(n);
	{
		for (auto i{ a.begin() }; i != a.end(); ++i)
			read(*i);
		for (auto i{ b.begin() }; i != b.end(); ++i)
			read(*i);
	}
	vi name_to_ind(n + 1);
	{
		int i{ -1 };
		for (const auto& a_el : a)
			name_to_ind[a_el] = ++i;
	}
	vi ans; ans.reserve(n);
	{
		int l{ -1 };
		for (const auto& b_el : b)
			if (int wh{ name_to_ind[b_el] }; wh > l) {
				ans.pb(wh - l);
				l = wh;
			}
			else
				ans.pb(0);
	}
	W(ans);
}
//
// ArtemParkhomets
//


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<iomanip>
#include<iterator>
#include <cstdio>
#include <vector>
#include <string>
#include <regex>
#include <numeric>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include<utility>
#include<random>
#include<bitset>
#include<list>
#include<functional>
using namespace std;
template<class T, typename A = allocator<T>>
class Vector : public vector<T, A>
{
public:
	using vector<T, A>::vector;
	Vector& operator()(size_t dummy_n) // additional init_val needs its own specification for Vector<string>
	{
		return *this;
	}
};
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef Vector<int> vi; // Vector
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pdd> vpdd;
typedef vector<string> vs;
typedef set<int> si;
typedef multiset<int> Si;
typedef map<int, int> mi;
typedef multimap<int, int> Mi;
template <typename Int = int>
Int read()
{
	Int flag = 1;
	char c = getchar();
	while ((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();
	if (c == '-') flag = -1, c = getchar();
	Int init = c & 15;
	while ((c = getchar()) >= '0' && c <= '9') init = (init << 3) + (init << 1) + (c & 15);
	return init * flag;
}
void read(char& a) { do scanf("%c", &a); while (isspace(a)); }
void write(const char& a) { printf("%c", a); }
char BUF[1234560];
void read(string& a) { scanf("%s", BUF); a = string(BUF); }
void write(const string& a) { printf("%s", a.c_str()); }
inline void read(int& a) { /*scanf("%d", &a);*/a = read(); }
void write(const int& a) { printf("%d", a); }
//void write(const size_t& a) { printf("%u", a); }
void read(ll& a) { scanf("%I64d", &a); }
void write(const ll& a) { printf("%I64d", a); }
void read(double& a) { scanf("%lf", &a); }
void write(const double& a) { printf("%lf", a); }
void read(ld& a) { scanf("%Lf", &a); }
void write(const ld& a) { printf("%Lf", a); }
void read(pair<int, int>& a) { scanf("%d%d", &a.first, &a.second); }
void write(const pair<int, int>& a) { printf("%d %d", a.first, a.second); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void read(C<T>& a) { for (auto i = a.begin(); i != a.end(); ++i) read(*i); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void write(const C<T>& a) { int sz = a.size(); if (sz != 0) write(a[0]); for (int i = 1; i < sz; ++i) { write(' '); write(a[i]); } }
template<typename T1, typename T2>
void read(T1& t1, T2& t2) { read(t1); read(t2); }
template<typename T1, typename T2>
void write(const T1& t1, const T2& t2) { write(t1); write(' '); write(t2); }
template<typename T1, typename T2, typename T3>
void read(T1& t1, T2& t2, T3& t3) { read(t1); read(t2); read(t3); }
template<typename T1, typename T2, typename T3, typename T4>
void read(T1& t1, T2& t2, T3& t3, T4& t4) { read(t1); read(t2); read(t3); read(t4); }
template<typename T1, typename T2, typename T3>
void write(const T1& t1, const T2& t2, const T3& t3) { write(t1); write(' '); write(t2); write(' '); write(t3); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void sort(C<T>& a) { sort(a.begin(), a.end()); }
void sort(string& a) { sort(a.begin(), a.end()); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void rsort(C<T>& a) { sort(a.rbegin(), a.rend()); }
void rsort(string& a) { sort(a.rbegin(), a.rend()); }
template<typename T>
int sz(const T& a) { return int(a.size()); }
#define MX 1000000000
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define T(n) for(int _VARIABLE{(n) + 1}; --_VARIABLE;)
#define F(b,e,i) for(auto i = (b); i != (e); (b) < decltype(b)(e) ? ++i : --i)
#define G(f,l,i) for(auto i = (f) + ((f) < decltype(f)(l) ? -1 : 1); ((f) < decltype(f)(l) ? i++ : i--) != (l) ;)
#define M(f,l,i,j) for(auto i = (f) , j = decltype(f)(l) ; i < j; ++i, --j)
#define r(...) read(__VA_ARGS__)
#define R(type, ...) type __VA_ARGS__; r(__VA_ARGS__)
#define w(...) write(__VA_ARGS__)
#define W(...) write(__VA_ARGS__), write('\n')
#define bgn begin()
#define rbgn rbegin()
#define nd end()
#define rnd rend()
#define pb push_back
#define fnt front()
#define bck back()
#define x first
#define y second

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	R(int, n);
	R(vi, a(n), b(n));
	vi name_to_ind(n + 1);
	{
		int i{ -1 };
		for (const auto& a_el : a)
			name_to_ind[a_el] = ++i;
	}
	vi ans; ans.reserve(n);
	{
		int l{ -1 };
		for (const auto& b_el : b)
			if (int wh{ name_to_ind[b_el] }; wh > l) {
				ans.pb(wh - l);
				l = wh;
			}
			else
				ans.pb(0);
	}
	W(ans);
}
//
// ArtemParkhomets
//


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<iomanip>
#include<iterator>
#include <cstdio>
#include <vector>
#include <string>
#include <regex>
#include <numeric>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include<utility>
#include<random>
#include<bitset>
#include<list>
#include<functional>
using namespace std;
template<class T, typename A = allocator<T>>
class Vector : public vector<T, A>
{
public:
	using vector<T, A>::vector;
	Vector& operator()(size_t dummy_n) // additional init_val needs its own specification for Vector<string>
	{
		return *this;
	}
};
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef Vector<int> vi; // Vector
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pdd> vpdd;
typedef vector<string> vs;
typedef set<int> si;
typedef multiset<int> Si;
typedef map<int, int> mi;
typedef multimap<int, int> Mi;
template <typename Int = int>
Int read()
{
	Int flag = 1;
	char c = getchar();
	while ((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();
	if (c == '-') flag = -1, c = getchar();
	Int init = c & 15;
	while ((c = getchar()) >= '0' && c <= '9') init = (init << 3) + (init << 1) + (c & 15);
	return init * flag;
}
void read(char& a) { do scanf("%c", &a); while (isspace(a)); }
void write(const char& a) { printf("%c", a); }
char BUF[1234560];
void read(string& a) { scanf("%s", BUF); a = string(BUF); }
void write(const string& a) { printf("%s", a.c_str()); }
inline void read(int& a) { /*scanf("%d", &a);*/a = read(); }
void write(const int& a) { printf("%d", a); }
//void write(const size_t& a) { printf("%u", a); }
void read(ll& a) { scanf("%I64d", &a); }
void write(const ll& a) { printf("%I64d", a); }
void read(double& a) { scanf("%lf", &a); }
void write(const double& a) { printf("%lf", a); }
void read(ld& a) { scanf("%Lf", &a); }
void write(const ld& a) { printf("%Lf", a); }
void read(pair<int, int>& a) { scanf("%d%d", &a.first, &a.second); }
void write(const pair<int, int>& a) { printf("%d %d", a.first, a.second); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void read(C<T>& a) { for (auto i = a.begin(); i != a.end(); ++i) read(*i); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void write(const C<T>& a) { int sz = a.size(); if (sz != 0) write(a[0]); for (int i = 1; i < sz; ++i) { write(' '); write(a[i]); } }
template<typename T1, typename T2>
void read(T1& t1, T2& t2) { read(t1); read(t2); }
template<typename T1, typename T2>
void write(const T1& t1, const T2& t2) { write(t1); write(' '); write(t2); }
template<typename T1, typename T2, typename T3>
void read(T1& t1, T2& t2, T3& t3) { read(t1); read(t2); read(t3); }
template<typename T1, typename T2, typename T3, typename T4>
void read(T1& t1, T2& t2, T3& t3, T4& t4) { read(t1); read(t2); read(t3); read(t4); }
template<typename T1, typename T2, typename T3>
void write(const T1& t1, const T2& t2, const T3& t3) { write(t1); write(' '); write(t2); write(' '); write(t3); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void sort(C<T>& a) { sort(a.begin(), a.end()); }
void sort(string& a) { sort(a.begin(), a.end()); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void rsort(C<T>& a) { sort(a.rbegin(), a.rend()); }
void rsort(string& a) { sort(a.rbegin(), a.rend()); }
template<typename T>
int sz(const T& a) { return int(a.size()); }
#define MX 1000000000
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define T(n) for(int _VARIABLE{(n) + 1}; --_VARIABLE;)
#define F(b,e,i) for(auto i = (b); i != (e); (b) < decltype(b)(e) ? ++i : --i)
#define G(f,l,i) for(auto i = (f) + ((f) < decltype(f)(l) ? -1 : 1); ((f) < decltype(f)(l) ? i++ : i--) != (l) ;)
#define M(f,l,i,j) for(auto i = (f) , j = decltype(f)(l) ; i < j; ++i, --j)
#define r(...) read(__VA_ARGS__)
#define R(type, ...) type __VA_ARGS__; r(__VA_ARGS__)
#define w(...) write(__VA_ARGS__)
#define W(...) write(__VA_ARGS__), write('\n')
#define bgn begin()
#define rbgn rbegin()
#define nd end()
#define rnd rend()
#define pb push_back
#define fnt front()
#define bck back()
#define x first
#define y second

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	int n{ r() };
	vi a(n), b(n);
	{
		for (auto i{ a.begin() }; i != a.end(); ++i)
			read(*i);
		for (auto i{ b.begin() }; i != b.end(); ++i)
			read(*i);
	}
	int name_to_ind[200001];
	{
		int i{ -1 };
		for (const auto& a_el : a)
			name_to_ind[a_el] = ++i;
	}
	vi ans; ans.reserve(n);
	{
		int l{ -1 };
		for (const auto& b_el : b)
			if (int wh{ name_to_ind[b_el] }; wh > l) {
				ans.pb(wh - l);
				l = wh;
			}
			else
				ans.pb(0);
	}
	W(ans);
}
//
// ArtemParkhomets
//