Note that the memory limit is unusual.

You are given an integer n and two sequences a_1, a_2, ..., a_n and b_1, b_2, ..., b_n.

Let's call a set of integers S such that S ⊆ \{1, 2, 3, ..., n\} strange, if, for every element i of S, the following condition is met: for every j ∈ [1, i - 1], if a_j divides a_i, then j is also included in S. An empty set is always strange.

The cost of the set S is ∑_{i ∈ S} b_i. You have to calculate the maximum possible cost of a strange set.

Input

The first line contains one integer n (1 ≤ n ≤ 3000).

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100).

The third line contains n integers b_1, b_2, ..., b_n (-10^5 ≤ b_i ≤ 10^5).

Output

Print one integer — the maximum cost of a strange set.

Examples

Input


9
4 7 3 4 5 6 7 8 13
-2 3 -19 5 -6 7 -8 9 1


Output


16


Input


2
42 42
-37 13


Output


0


Input


2
42 42
13 -37


Output


13

Note

The strange set with the maximum cost in the first example is \{1, 2, 4, 8, 9\}.

The strange set with the maximum cost in the second example is empty.
#include<bits/stdc++.h>
#define pii pair<int,int>
#define ll long long
#define cl(x,y) memset(x,y,sizeof(x))
#define loop(x,y,z) for(x=y;x<=z;x++)
#define reve(x,y,z)	for(x=y;x>=z;x--)
#define ct cerr<<"Time elapsed:"<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define lson x<<1,l,mid
#define rson x<<1|1,mid+1,r
#define INF 1e18
const int N=1e6+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
const double pi=acos(-1);
using namespace std;
int a[3010];
struct edge
{
	int u,v,w;
}e[N];
int head[3010],len=1,dep[3010],s,t;
void add(int u,int v,int w)
{
	e[++len]={head[u],v,w};
	head[u]=len;
}
void inc(int u,int v,int w)
{
	add(u,v,w);
	add(v,u,0);
} 
int dfs(int u,int f,int t)
{
	int ans=0,i;
	if(u==t)
		return f;
	for(i=head[u];i && f;i=e[i].u)
	{
		int v=e[i].v,w=e[i].w;
		if(dep[v]==dep[u]+1 && w) 
		{
			int sum=dfs(v,min(f,w),t);
			e[i].w-=sum;
			e[i^1].w+=sum;
			f-=sum;
			ans+=sum;
		}	
	}
	if(!ans)
		dep[u]=-2;
	return ans;
}
int bfs(int s,int t)
{
	queue<int> q;
	cl(dep,0);
	dep[s]=1;
	q.push(s);
	while(!q.empty())
	{
		int u=q.front(),i;
		q.pop();
		for(i=head[u];i;i=e[i].u)
		{
			int v=e[i].v,w=e[i].w;
			if(w && !dep[v]) 
			{
				dep[v]=dep[u]+1;
				q.push(v); 
			}
		}
	}
	return dep[t];
}
int dinic(int s,int t)
{
	int ans=0;
	while(bfs(s,t))
		ans+=dfs(s,inf,t);
	return ans;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n,i,j;
	cin>>n;
	s=0;
	t=n+1;
	for(i=1;i<=n;i++)
		cin>>a[i];
	for(i=1;i<=n;i++)
	{
		int vis[110]={0};
		for(j=i-1;j>=1;j--)
			if(a[i]%a[j]==0 && !vis[a[j]])
			{
				vis[a[j]]=1;
				inc(i,j,inf);
			}
	}
	int sum=0;
	for(i=1;i<=n;i++)
	{
		int w;
		cin>>w;
		if(w>0)
		{
			inc(s,i,w);
			sum+=w;
		}
		else
			inc(i,t,-w);
	}
	cout<<sum-dinic(s,t)<<endl;
	return 0;
}

