Description

There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.

You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.

Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.

Input

The first line contains the positive integer n (1 ≤ n ≤ 200 000) — the number of particles.

The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right.

The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 ≤ xi ≤ 109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.

Output

In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.

Print the only integer -1, if the collision of particles doesn't happen.

Examples
input
4
RLRL
2 4 6 10
output
1
input
3
LLR
40 50 60
output
-1
Note

In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.

In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point.

寻找RL这种组合,再计算求最小

#include<bits/stdc++.h>
using namespace std;
int n;
int L[200005];
int R[200005];
int num[200005];
string s;
int a;
int main()
{
int coL=0;
int coR=0;
cin>>n;
cin>>s;
for(int i=0;i<n;i++)
{
cin>>num[i];
}
//sort(L,coL+L);
// sort(R,coR+R);
// cout<<R[0]<<endl;
// cout<<L[0]<<endl;
if(n==1)
{
puts("-1");
}
else
{
for(int i=0;i<n;i++)
{
if(s[i]=='R'&&s[i+1]=='L')
{
L[coL++]=(num[i]+num[i+1])/2-num[i];
// cout<<"A"<<endl;
}
}
sort(L,coL+L);
sort(num,num+n);
if(coL==0)
{
puts("-1");
}
else
cout<<L[0]<<endl;
}
return 0;
}

  

最新文章

  1. 一个简单的socket程序运行与抓包查看
  2. orcale 匿名代码块
  3. linux rwxrwxrwt文件夹属性
  4. libpcap文件格式分析
  5. org.apache.ibatis.reflection.ReflectionException
  6. idea maven添加jar包
  7. ArrayList源码剖析
  8. 原生js实现Ajax的原理。
  9. java加减的二进制实现
  10. 一个&#39;&amp;&#39;引起md5签名不一致问题
  11. android SDK模拟器环境搭建
  12. WCF系列_WCF常用绑定选择
  13. git reset的用法
  14. 美丽的webpack-bundle-analyzer
  15. 鸟哥Linux私房菜基础学习篇学习笔记2
  16. Python图形开发之PIL
  17. Android开发之自定义的ProgressDialog
  18. CentOS6.4 xen4.2 虚拟机 桥接网络设置
  19. ios-Objective-C中的各种遍历(迭代)方式(转载)
  20. html 更新

热门文章

  1. SPOJ8093Sevenk Love Oimaster(广义后缀自动机)
  2. bzoj 1312: Hard Life 01分数规划+网络流
  3. 字符编码ASCII、Unicode、GB
  4. USACO-Your Ride Is Here(你的飞碟在这儿)-Section1.2&lt;1&gt;
  5. Java探索之旅(16)——异常处理
  6. [51nod1101]换零钱
  7. github 分支操作
  8. Material使用09 MdCheckboxModule、MdMenuModule、MdTooltipModule
  9. centos MAC 地址与报错eth0 unknown interface no such device
  10. servlet与filter的加载顺序详解