Manhattan

시간 제한1초메모리 제한1024 MB

요약
서로 겹치지 않는 두 축 정렬 직사각형이 주어질 때, 한 직사각형의 격자점에서 다른 직사각형의 격자점으로 가는 맨해튼 경로의 수를 666013으로 나눈 나머지를 구한다.
난이도

어려움10점 중 8점

유형
조합론, 동적 계획법, 누적 합, 수학
정답자
아직 제출이 없습니다

문제

In the first quadrant of the cartesian plan, we define a zone, denoted by Z(x,y,u,v)Z(x,y,u,v), as a set of lattice points which belong to a rectangle defined by to diagonally opposite points, (x,y)(x,y) and (u,v)(u,v), with x≤ux≤u and y≤vy≤v. In particular, a zone can contain points on a single segment when x=ux=u or y=vy=v. Also, it may be formed from a single point, if x=ux=u and y=vy=v.

A path between two lattice points is defined as a minimal set of horizontal and vertical segments of length 11 which join the two points.

Given two zones Z_1​(a,b,c,d)Z\_1​(a,b,c,d) and Z_2​(e,f,g,h)Z\_2​(e,f,g,h) which do not intersect in any point, compute the number of distinct paths, modulo 666,013666\\, 013, that start in Z_1Z\_1​ and end in Z_2Z\_2​.

입력

The first line contains 88 integers a,b,c,d,e,f,g,ha,b,c,d,e,f,g,h, the boundaries of the two zones.

출력

The output should containt a single number representing the number of distinct paths modulo 666,013666\\, 013.

제한

  • 1≤a,b,c,d,e,f,g,h≤1051≤a,b,c,d,e,f,g,h≤10^5

예제4

  1. 예제 1

    입력
    1 1 1 2 2 2 3 2
    
    예상 출력
    7
    
  2. 예제 2

    입력
    1 1 2 2 2 3 3 4
    
    예상 출력
    53
    
  3. 예제 3

    입력
    8 4 13 7 2 3 6 8
    
    예상 출력
    44702
    
  4. 예제 4

    입력
    80 40 130 70 20 30 60 80
    
    예상 출력
    145267