One day Vasya was going home when he saw a box lying on the road. The box can be represented as a rectangular parallelepiped. Vasya needed no time to realize that the box is special, as all its edges are parallel to the coordinate axes, one of its vertices is at point (0, 0, 0), and the opposite one is at point (x1, y1, z1). The six faces of the box contain some numbers a1, a2, ..., a6, exactly one number right in the center of each face.

The numbers are located on the box like that:

  • number a1 is written on the face that lies on the ZOX plane;
  • a2 is written on the face, parallel to the plane from the previous point;
  • a3 is written on the face that lies on the XOY plane;
  • a4 is written on the face, parallel to the plane from the previous point;
  • a5 is written on the face that lies on the YOZ plane;
  • a6 is written on the face, parallel to the plane from the previous point.

At the moment Vasya is looking at the box from point (x, y, z). Find the sum of numbers that Vasya sees. Note that all faces of the box are not transparent and Vasya can't see the numbers through the box. The picture contains transparent faces just to make it easier to perceive. You can consider that if Vasya is looking from point, lying on the plane of some face, than he can not see the number that is written on this face. It is enough to see the center of a face to see the corresponding number for Vasya. Also note that Vasya always reads correctly the ai numbers that he sees, independently of their rotation, angle and other factors (that is, for example, if Vasya sees some ai = 6, then he can't mistake this number for 9 and so on).

Input

The fist input line contains three space-separated integers xy and z (|x|, |y|, |z| ≤ 106) — the coordinates of Vasya's position in space. The second line contains three space-separated integers x1y1z1 (1 ≤ x1, y1, z1 ≤ 106) — the coordinates of the box's vertex that is opposite to the vertex at point (0, 0, 0). The third line contains six space-separated integers a1, a2, ..., a6 (1 ≤ ai ≤ 106) — the numbers that are written on the box faces.

It is guaranteed that point (x, y, z) is located strictly outside the box.

Output

Print a single integer — the sum of all numbers on the box faces that Vasya sees.

Example

Input
2 2 2
1 1 1
1 2 3 4 5 6
Output
12
Input
0 0 10
3 2 3
1 2 3 4 5 6
Output
4

Note

The first sample corresponds to perspective, depicted on the picture. Vasya sees numbers a2 (on the top face that is the darkest), a6 (on the right face that is the lightest) and a4 (on the left visible face).

In the second sample Vasya can only see number a4.

本来是用暴力来接的解出来了,但是今天看了被人的代码,发现这道题其实很简洁,怎么说呢,还是想不到那么好的办法,不过看过之后能够想到还是很值得的

#include<cstdio>
int main()
{
int x,y,z,x1,y1,z1;
int a1,a2,a3,a4,a5,a6;
scanf("%d %d %d",&x,&y,&z);
scanf("%d %d %d",&x1,&y1,&z1);
scanf("%d %d %d %d %d %d",&a1,&a2,&a3,&a4,&a5,&a6);
int ans=0;
if(x<0) ans+=a5;
if(x>x1) ans+=a6;
if(y<0) ans+=a1;
if(y>y1) ans+=a2;
if(z<0) ans+=a3;
if(z>z1) ans+=a4;
printf("%d\n",ans);
return 0;
}

  

最新文章

  1. matlab -xlsread 打开xls文件出错:服务器出现意外情况
  2. 混合 Data Warehouse 和 Big Data 倉庫的新架構
  3. 嵌入式Linux驱动学习之路(四)u-boot编译分析
  4. hdu2159
  5. BZOJ_1020_[SHOI2008]_安全的航线flight_(计算几何+二分)
  6. Asp.net 事务处理
  7. cf443B Kolya and Tandem Repeat
  8. 过滤器HttpModule
  9. ROS学习记录(二)————使用smartcar进行仿真(用.xacro文件来运行rviz)
  10. YY表行推荐十块顶级复刻表,一比一开模复刻,外观堪比正品
  11. python 面对post分页爬虫
  12. python_crawler,批量下载文件
  13. Alpha第三天
  14. 【Android 应用开发】Android UI 设计之 TextView EditText 组件属性方法最详细解析
  15. 【English Email】CIP payouts now in Workday
  16. mysql 下载地址
  17. 实验-12-JSP简单入门
  18. mysql学习之路_高级数据操作
  19. 试着用React写项目-利用react-router解决跳转路由等问题(二)
  20. 模块化开发之butterknife 在 library中使用

热门文章

  1. 改bug的乐趣
  2. eval 是执行一段完整的js字符串代码,并将结果返回
  3. eclipse在线安装mybatis generator插件
  4. linux操作系统下,怎么使用kill按照PID一次杀死多个进程
  5. IntelliJ IDEA 安装
  6. Python爬虫入门四之Urllib库的高级用法
  7. [SoapUI] 通过编程的方式设置当前的Environment
  8. Linux useradd 与 adduser的区别, /sbin/nologin 与 /bin/bash
  9. zigbee广播通信原理
  10. [GO]有缓冲通道