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. proxmox 安装ROS 备忘

    虚拟机设置:使用qemu64 CPU和vrtio网卡在家里测试性能最好.

  2. 编译gcc5.1.0时的报错

    编译安装gcc5.1.0时出现如下报错: configure: error: error verifying int64_t uses long long 这是由于没有安装gcc_c++导致的,安装下 ...

  3. json-lib 之jsonConfig详细使用(转载写的不错)

    =========================== Java To Json ============================= 一,setCycleDetectionStrategy 防 ...

  4. Spark之 Spark Streaming流式处理

    SparkStreaming Spark Streaming类似于Apache Storm,用于流式数据的处理.Spark Streaming有高吞吐量和容错能力强等特点.Spark Streamin ...

  5. 01 lucene基础 北风网项目培训 Lucene实践课程 Lucene概述

    lucene-core-2.4.1.jar是lucene开发的核心jar包,lucene-analyzers-2.4.1.jar也是必不可少的.lucene-highlighter-2.4.1.jar ...

  6. 刷题向》关于一道比较优秀的递推型DP(openjudge9275)(EASY+)

    先甩出传送门:http://noi.openjudge.cn/ch0206/9275/ 这道题比较经典, 最好不要看题解!!!!! 当然,如果你执意要看我也没有办法 首先,显然的我们可以用 f [ i ...

  7. 高性能Web服务器Nginx的配置与部署研究(6)核心模块之主模块的测试常用指令

    1. daemon 含义:设置是否以守护进程模式运行 语法:daemon on|off 缺省:on 示例:daemon off; 注意:生产环境(production mode)中不要使用daemon ...

  8. Logger Rate Limiter 十秒限时计数器

    [抄题]: Design a logger system that receive stream of messages along with its timestamps, each message ...

  9. 监控web接口和添加触发器

    1: 以监控百度接口为例子: www.baidu.com1: 打开 2: 过滤ss0.bdstatic.com 3: 选择两个url进行监控 https://ss0.bdstatic.com/5aV1 ...

  10. springboot用于web开发

    1.使用SpringBoot:1)创建SpringBoot应用,选中我们需要的模块:2)SpringBoot已经默认将这些场景配置好了,只需要在配置文件中指定少量配置就可以运行起来3)自己编写业务代码 ...