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;
}

  

D. Magic Box(几何)的更多相关文章

  1. 【hihocoder】 Magic Box

    题目1 : Magic Box 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 The circus clown Sunny has a magic box. When ...

  2. hihocoder 1135 : Magic Box

    #1135 : Magic Box 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 The circus clown Sunny has a magic box. Whe ...

  3. BestCoder Round #25 1002 Harry And Magic Box [dp]

    传送门 Harry And Magic Box Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

  4. 微软2016校园招聘在线笔试之Magic Box

    题目1 : Magic Box 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 The circus clown Sunny has a magic box. When ...

  5. HDU 5155 Harry And Magic Box --DP

    题意:nxm的棋盘,要求每行每列至少放一个棋子的方法数. 解法:首先可以明确是DP,这种行和列的DP很多时候都要一行一行的推过去,即至少枚举此行和前一行. dp[i][j]表示前 i 行有 j 列都有 ...

  6. [HDOJ 5155] Harry And Magic Box

    题目链接:HDOJ - 5155 题目大意 有一个 n * m 的棋盘,已知每行每列都至少有一个棋子,求可能有多少种不同的棋子分布情况.答案对一个大素数取模. 题目分析 算法1: 使用容斥原理与递推. ...

  7. 【HDOJ】5155 Harry And Magic Box

    DP.dp[i][j]可以表示i行j列满足要求的组合个数,考虑dp[i-1][k]满足条件,那么第i行的那k列可以为任意排列(2^k),其余的j-k列必须全为1,因此dp[i][j] += dp[i- ...

  8. hihoCoder题目之Magic Box

    #include <iostream> #include <cmath> #include <cstdio> using namespace std; void s ...

  9. HDU-5155 Harry And Magic Box

    题目描述 在\(n*m\)的矩阵内每一行每一列都有钻石,问钻石分布的种类? 答案有可能很大,所以输出答案对\(1000000007\)取模. Input 对于每个测试用例,有两个整数\(n\)和\(m ...

随机推荐

  1. 增强MyEclipse提示功能

    当我们使用MyEclipse编辑代码的时候按住“Ctrl+/”,就能获得代码提示,或者使用“.”的时候就会“点”出属性或方法等,而且提示还会有延迟. 如果我们想无论是按下“.”.“Ctrl+/”甚至是 ...

  2. Python下载与安装

    Python目前已支持所有主流操作系统,在Linux,Unix,Mac系统上自带Python环境,一般默认装的是Python2版本,Windows系统上没有Pyhton环境,需要我们手动安装一下,过程 ...

  3. java算法 第七届 蓝桥杯B组(题+答案) 5.抽签

    5.抽签  (代码填空) X星球要派出一个5人组成的观察团前往W星.其中:A国最多可以派出4人.B国最多可以派出2人.C国最多可以派出2人..... 那么最终派往W星的观察团会有多少种国别的不同组合呢 ...

  4. Spark Streaming原理简析

    执行流程 数据的接收 StreamingContext实例化的时候,需要传入一个SparkContext,然后指定要连接的spark matser url,即连接一个spark engine,用于获得 ...

  5. spring4-4-jdbc-02

    1.简化 JDBC 模板查询 每次使用都创建一个 JdbcTemplate 的新实例, 这种做法效率很低下. JdbcTemplate 类被设计成为线程安全的, 所以可以再 IOC 容器中声明它的单个 ...

  6. 20-list简单使用:

    C++list的使用总结及常用list操作 C++中list用法详解 STL中list的erase()方法的使用   listiterator 最近刚刚接触stl的list    学习的时候遇到了很多 ...

  7. Openssl s_client命令

    一.简介 s_client为一个SSL/TLS客户端程序,与s_server对应,它不仅能与s_server进行通信,也能与任何使用ssl协议的其他服务程序进行通信 二.语法 openssl s_cl ...

  8. Boost::lexical_cast类型转换

    1.字符串->数值 C++代码 #include <boost/lexical_cast.hpp> #include <iostream> int main() { us ...

  9. [C++] decltype(auto) C++ 11 feature

    1 //C++ 11 feature template <class T1, class T2> auto getMultiply(T1 data1, T2 data2) -> de ...

  10. app里面嵌套的H5页面上电话号码怎么才能点击拨号?

    代码: <p>联系我们:<a href="tel://66666666666">66666666666</a> </p>