#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define int ll
#define pii pair<int,int>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-8;
const int INF=0x3f3f3f3f;
const int MAXN=1e6+10;
const int mod=1e9+7;
int quickPower(int a, int b)
{
    int ans = 1;
    while(b)
    {
        if(b & 1)
        {
            ans = ans*a;
        }
        a=a*a;
        b >>= 1;
    }
    return ans;
}

void solve()
{
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=MAXN;++i)
    {
        int tmp=i;
        int sum=0;
        while(tmp)
        {
            sum++;
            tmp/=10;
        }
        int flag=i*quickPower(10,sum)+i;
        if(flag<=n) ans++;
        else break;
        /*cout<<flag<<endl;*/
    }
    cout<<ans;
}
signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int _=1;
    /*cin>>_;*/
    for(int i=1; i<=_; ++i)
    {
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define irep(n) for (int i=0; i < (n); ++i)
#define irepf1(n) for (int i=1; i <= (n); ++i)
#define jrep(n) for (int j=0; j < (n); ++j)
#define jrepf1(n) for (int j=1; j <= (n); ++j)
#define krep(n) for (int k=0; k < (n); ++k)
#define krepf1(n) for (int k=1; k <= (n); ++k)
#define PI 3.14159265358979323846264338327950288
#define mod 1000000007
//fixed << setprecision(10) <<

int main() {
  int N;
  cin >>N;
  vector<ll> VA(N);
  vector<ll> VMax(N);
  vector<ll> VB(N);
  ll A;
  cin >>A;
  VA[0]=A,VMax[0]=A;
  irep (N-1) {
    cin >>VA[i+1];
    VMax[i+1]=max(VMax[i],VA[i+1]);
  }
  irep (N) cin >>VB[i];
  ll Max=0;
  irep (N) {
    Max=max(Max,VMax[i]*VB[i]);
    cout<<Max<<endl;
  }
}