8292: Moo Sick

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:12 通过:11

题目描述

众所周知,奶牛喜欢听各种形式的音乐。

然而,伟大的奶牛作曲家哞扎特曾经发现,一个特定的和弦会让奶牛听了后生病。

这个和弦被称为反刍动物的第七和弦,通常不会在奶牛音乐中出现。

约翰想在牛棚播放他最喜欢的音乐,不幸的是,他对牛音乐史一无所知。

你的任务是识别这首歌中的所有反刍动物的第七和弦,并估计这给奶牛带来的负面影响。

约翰播放的音乐由 N 个音符组成,每个音符都是 [1,88] 范围内的整数。

反刍动物的第七和弦由 C 个不同的音符组成,每个音符也是 [1,88] 范围内的整数。

需注意,即使这些音符被移调(同时增加或减少一个数值)或者重新排列,该和弦依然属于反刍动物的第七和弦。

例如,如果 4 6 7 是反刍动物的第七和弦,那么 3 5 6(都减 1 得到)、6 8 9(都加 2 得到)、6 4 7(重新排列)、5 3 6(都减 1 后重新排列)也是反刍动物的第七和弦。

由于反刍动物的第七和弦是满足上述条件的 C 个连续音符的序列,因此,它是由其在音乐中的开始位置唯一确定的。

请确定所有反刍动物的第七和弦的开始位置索引。

输入格式

第一行包含一个整数 N。

接下来 N 行用来描述约翰的音乐,每行包含一个音符。

再一行包含一个整数 C。

接下来 C 行用来描述反刍动物的第七和弦,每行包含一个音符。

输出格式

第一行输出一个整数 KK,表示音乐中包含的不同第七和弦的数量。注意不同第七和弦之间可以有重叠部分。

接下来 KK 行,按升序顺序,每行输出一个第七和弦的开始位置索引。

约翰的音乐中所有音符的索引为 1∼N。

数据范围

1≤N≤20000,
1≤C≤10

输入样例:

6
1
8
5
7
9
10
3
4
6
7

输出样例:

2
2
4

样例解释

在此示例中,共出现两个第七和弦,第一个从位置 2 开始,为 8 5 7(都加 1 后重新排列得到),第二个从位置 4 开始,为 7 9 10(都加 3 后得到)。

Problem 3: Moo Sick [Rob Seay]


Everyone knows that cows love to listen to all forms of music.  Almost all
forms, that is -- the great cow composer Wolfgang Amadeus Moozart
once discovered that a specific chord tends to make cows rather ill.  This
chord, known as the ruminant seventh chord, is therefore typically avoided
in all cow musical compositions.


Farmer John, not knowing the finer points of cow musical history, decides
to play his favorite song over the loudspeakers in the barn.  Your task is
to identify all the ruminant seventh chords in this song, to estimate how
sick it will make the cows.


The song played by FJ is a series of N (1 <= N <= 20,000) notes, each an
integer in the range 1..88.  A ruminant seventh chord is specified by a
sequence of C (1 <= C <= 10) distinct notes, also integers in the range
1..88.  However, even if these notes are transposed (increased or decreased
by a common amount), or re-ordered, the chord remains a ruminant seventh
chord!  For example, if "4 6 7" is a ruminant seventh chord, then "3 5 6"
(transposed by -1), "6 8 9" (transposed by +2), "6 4 7" (re-ordered), and
"5 3 6" (transposed and re-ordered) are also ruminant seventh chords.


A ruminant seventh chord is a sequence of C consecutive notes satisfying
the above criteria. It is therefore uniquely determined by its starting
location in the song. Please determine the indices of the starting
locations of all of the ruminant seventh chords.


PROBLEM NAME: moosick


INPUT FORMAT:


* Line 1: A single integer: N.


* Lines 2..1+N: The N notes in FJ's song, one note per line.


* Line 2+N: A single integer: C.


* Lines 3+N..2+N+C: The C notes in an example of a ruminant seventh
       chord.  All transpositions and/or re-orderings of these notes
       are also ruminant seventh chords.


SAMPLE INPUT (file moosick.in):


6
1
8
5
7
9
10
3
4
6
7


INPUT DETAILS:


FJ's song is 1,8,5,7,9,10.  A ruminant seventh chord is some
transposition/re-ordering of 4,6,7.


OUTPUT FORMAT:


* Line 1: A count, K, of the number of ruminant seventh chords that
       appear in FJ's song.  Observe that different instances of
       ruminant seventh chords can overlap each-other.


* Lines 2..1+K: Each line specifies the starting index of a ruminant
       seventh chord (index 1 is the first note in FJ's song, index N
       is the last).  Indices should be listed in increasing sorted
       order.


SAMPLE OUTPUT (file moosick.out):


2
2
4


OUTPUT DETAILS:


Two ruminant seventh chords appear in FJ's song (and these occurrences
actually overlap by one note).  The first is 8,5,7 (transposed by +1 and
reordered) starting at index 2, and the second is 7,9,10 (transposed by +3)
starting at index 4.

输入格式

INPUT FORMAT:


* Line 1: A single integer: N.


* Lines 2..1+N: The N notes in FJ's song, one note per line.


* Line 2+N: A single integer: C.


* Lines 3+N..2+N+C: The C notes in an example of a ruminant seventh
       chord.  All transpositions and/or re-orderings of these notes
       are also ruminant seventh chords.

输出格式

OUTPUT FORMAT:


* Line 1: A count, K, of the number of ruminant seventh chords that
       appear in FJ's song.  Observe that different instances of
       ruminant seventh chords can overlap each-other.


* Lines 2..1+K: Each line specifies the starting index of a ruminant
       seventh chord (index 1 is the first note in FJ's song, index N
       is the last).  Indices should be listed in increasing sorted
       order.


输入样例 复制

6
1
8
5
7
9
10
3
4
6
7

输出样例 复制

2
2
4