Python Example

Python Example6.buy-lollipop买棒棒糖输入格式输出格式输入输出样例项目说明:Implements7.Flight航班时间输入格式输出格式数据范围输入样例:输出样例:Implements8.LOGO题目描述输入格式输出格式样例输入规定9.增量元素之间的最大差值样例1样例2Implements10.LOGO++题目背景输入格式输出格式样例输入规则ImplementsValidate InputImplementsCalculate Retire ScheduleImplementsisAnagramImplementsInsomnia cureDescriptionInputOutputExamplesInput1Output1Input2Output2NoteXenia and RingroadDescriptionInputOutputInput1Output1Input2Output2NoteImplementsTaxiDescriptionInputOutputExamplesInputOutputInputOutputImplementsStreamImplementsCSVSpecial TypingInputOutputExampleNoteImplementsGrammar LessonsInputOutputExamplesImplementsTo Do ListImplementsgrade-histogram要求ImplementsTwo-sumImplementsString-FormattingImplementsAlice, Bob and ChocolateDescriptionInputOutputExamplesInputOutputImplementsMagnetsInputOutputExamplesinputoutputinputoutputImplements

6.buy-lollipop

买棒棒糖

已知在思远哥哥的糖果商店,一根棒棒糖的价格是 6 元 7 角,而你有 a 元 b 角硬币,你最多能买多少根棒棒糖?

输入格式

输入只有一行两个非负整数,以空格分隔,分别表示 a 和 b 。

输出格式

输出一行一个整数,表示最多能买多少根棒棒糖。

输入输出样例

输入1

输出1

输入2

输出2

项目说明:

src目录下为题目代码源文件,需要完成的内容为buy_lolipop.py里的方法。 src目录下的init.py文件不需要改动。

test目录下为测试用例文件,不可进行修改。

Implements

7.Flight

航班时间

思远哥哥要去美国留学了。

思远哥哥的女朋友发现他上午十点出发,上午十二点到达美国,于是感叹到“现在飞机飞得真快,两小时就能到美国了”。但在仔细观察后发现飞机的起降时间都是当地时间。由于北京和美国东部有 12 小时时差,故飞机总共需要 14 小时的飞行时间。不久后思远哥哥的女朋友去冰岛旅游,思远哥哥并不知道冰岛与北京的时差。但是他得到了女朋友来回航班的起降时间。思远哥哥想知道女朋友的航班飞行时间是多少。

对于一个可能跨时区的航班,给定来回程的起降时间。假设飞机来回飞行时间相同,求飞机的飞行时间。

输入格式

一个输入包含一组数据。

每组数据包含两行,第一行为去程的起降时间,第二行为回程的起降时间。

起降时间的格式如下:

h1:m1:s1 h2:m2:s2 h1:m1:s1 h3:m3:s3 (+1) h1:m1:s1 h4:m4:s4 (+2) 第一种格式表示该航班在当地时间h1时m1分s1秒起飞,在当地时间当日h2时m2分s2秒降落。

第二种格式表示该航班在当地时间h1时m1分s1秒起飞,在当地时间次日h2时m2分s2秒降落。

第三种格式表示该航班在当地时间h1时m1分s1秒起飞,在当地时间第三日h2时m2分s2秒降落。

输出格式

对于每一组数据输出一行一个时间hh:mm:ss,表示飞行时间为hh小时mm分ss秒。

注意,当时间为一位数时,要补齐前导零,如三小时四分五秒应写为03:04:05。

数据范围

保证输入时间合法(0≤h≤23,0≤m,s≤59),飞行时间不超过24小时。

输入样例:

输出样例:

Implements

8.LOGO

题目描述

简单模拟LOGO语言的小乌龟。

有一个大小为10*10的方格棋盘,最左上角的格子中有一个正不动的小乌龟。你需要让这个小乌龟能按照一定的指示在棋盘上画出一些内容。我们会输入n条指令,每条指令有2或3个操作数。第一个是移动的方向:U、D、L、R分别代表接下来像上/下/左/右移动;第二个是移动的步数:每移动一步后都会在脚下的格子中填上特定的字符。第三个操作数则是要填的字符,如果它不存在则沿用上一次移动所填充的字符。在移动的过程中,如果乌龟在指令下移动到了棋盘之外,则立刻输出Error并结束程序。若n条指令执行完,则输出整个棋盘上所画的内容。

输入格式

第一行一个数n,为指令的个数

接下来n行,每行2或3个字符,其中第一个为移动方向(UDLR中的一个),第二个为移动步数(0-9),第三个为一个字符(如果有)

输出格式

Error!或10行10列字符,表示最后的棋盘的结果。

样例

输入

输出

注意此处的‘0’代表空白符,实际输出需用空白符代替。

输入

输出

输入

输出

输入规定

指令条数1<=n<=15,保证不会出现不符合以上格式的指令,且第一条指令一定会指定要画的符号。

每次移动步数不会为0。

项目说明:

src目录下为题目代码源文件,需要完成的内容为logo.py里的logo_play()方法。 src目录下的init.py文件不需要改动。

9.增量元素之间的最大差值

 

在一行中输入若干个整数,视为数组nums(长度为n), 请你计算 nums[j] - nums[i] 能求得的 最大差值 ,其中 0 <= i < j < n 且 nums[i] < nums[j] 。

返回 最大差值 。如果不存在满足要求的 i 和 j ,返回 -1 。

 

小提示:想过这道题的test,你可能需要知道print函数更多的一些细节哦ʕ •ᴥ•ʔ

 

样例1

 

样例2

Implements

10.LOGO++

题目背景

同学们在上一次作业中完成了一个简单的LOGO模拟器,可以进行简单的绘画功能。这次同学们可以完成一些复杂指令,实现一些对复杂图形的绘制!

本次作业首先新增了两条指令:pen_up和pen_down,表示暂停或开始绘画模式。在暂停绘画的状态下小乌龟移动不会在路径上留下字符,只有在开始绘画的状态下才会留下字符。原有的移动功能会以move开头,操作数不变。然后新增三条复杂指令:cross、rect、rect_f。cross命令有1或2个操作数。rect、rect_f有2或3个操作数。最后还有一条指令end,它会结束绘图程序并输出棋盘。

cross命令会以小乌龟为中心画一个十字,十字的长度为第一个操作数,绘画的字符使用第二个操作数(如没有则沿用之前的画笔)。rect命令会以小乌龟的起始位置为左上角,向右下画出一个矩形。矩形的横向、纵向宽度分别为第一个、第二个操作数。第三个操作数同样是指定可能的画笔字符。rect_f命令大体与rect命令相同,但它会用当前的画笔填充所画的矩形。以上三种指令执行完毕后,小乌龟需要回到原先的位置,即指令不会让它的位置改变。

同样的,小乌龟不能移到屏幕外面,一旦出现则输出Error并结束模拟。

tips

1:以上几条命令能否用已有的move指令和pen_up、pen_down指令组合实现?

2:如果将move封装为函数,如何实现在移动完成后改变小乌龟的状态?

3:你可以实现一条print指令来便于你调试。测试用例里不会出现该条指令。

4:在题目中未明确的指令组合(比如连续两次pen_up)属于未定义行为。未定义行为你可以任意实现,测试用例中不会出现未定义行为。

输入格式

若干行指令,每行有指令的名称与一定数量的操作数。

最后一行一定是end指令。

输出格式

Error!或10行10列字符,表示最后的棋盘的结果。

样例

输入

输出

同样的,此处的‘0’代表空白符,实际输出需用空白符代替。

输入

输出

输入

输出

在cross指令完毕后,小乌龟停在第四行第四列的位置。

输入

输出

输入规则

指令条数1<=n<=20,保证不会出现不符合格式的指令。每次移动步数不会为0。指令序列中第一条在开始绘画状态下执行的指令一定有要画的字符。

项目说明:

src目录下为题目代码源文件,需要完成的内容为logo.py里的logo_play()方法。 src目录下的init.py文件不需要改动。

Implements

Validate Input

Write a program to validate the input data(First Name, Last Name, EmployeeID, Zip code). The first name and the last name must be filled in, which at least two letters. EmployeeID must be in such format:"AA-1234". Zip code must be numeric.

从命令后得到 first name、last name、 Zip code 和 EmployeeID. 然后程序判断:

项目说明:

src目录下为题目代码源文件,需要完成的内容为validate.py里的validate方法。 src目录下的init.py文件不需要改动。

test目录下为测试用例文件,不可进行修改。

示例:

Implements

Calculate Retire Schedule

根据输入的当前年龄与退休年龄,计算退休年份

示例,->表示输出,<-表示输入:

-> What is your current age?

<- 25

-> At what age would you like to retire?

<- 65

-> You have 40 years left until you can retire.

-> It's 2018, so you can retire in 2058.

注意:

请使⽤系统当前时间进行计算

Implements

isAnagram

1.编写一个函数,比较两个字符串是否为字母异位,也就是包含字母一样,只是顺序不同:

2.函数参数为两个字符串str1,str2:

返回True或者False。

注意检查词长

 

项目说明:

src目录下为题目代码源文件,需要完成的内容为isAnagram_cal.py里的方法。 src目录下的init.py文件不需要改动。

test目录下为测试用例文件,不可进行修改。

示例:

Implements

Insomnia cure

Description

Input

Input data contains integer numbers k, l, m, n and d, each number in a separate line (1 ≤ k, l, m, n ≤ 10, 1 ≤ d ≤ 105>).

Output

Output the number of damaged dragons.

Examples

Input1

Output1

Input2

Output2

Note

In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.

In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed.

 

Xenia and Ringroad

Description

Input

The first line contains two integers n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ 105). The second line contains m integers a1, a2, ..., am (1 ≤ ai ≤ n). Note that Xenia can have multiple consecutive tasks in one house.

Output

Print a single integer — the time Xenia needs to complete all tasks.

Input1

Output1

Input2

Output2

Note

In the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units.

Implements

Taxi

Description

After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?

Input

The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.

Output

Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.

Examples

Input

Output

Input

Output

Implements

Stream

给定一个名称列表,其中一些名称仅包含一个字符

要求返回一个逗号分隔的字符串,该字符串中不包含单字母的名称,每个名称有且仅有首字母大写,且按照原顺序排列

示例参数:

示例返回:

Implements

CSV

本次作业,我们基于CSV实现一个简(jian)易(lou)的数据库。

CSV文件即逗号分隔值文件,示例:

三列的属性分别为Name,Title,Salary. 约定本题中所有的csv文件都由这三列构成。

您需实现以下操作:

输入:

注意:

  1. 要读取的文件名将以参数的形式传递到待编写的函数中

  2. Salary和平均值输出到小数点后两位

  3. rawdata开头的文件请勿修改,它们保证在测试结束后将resource-x.csv文件恢复原状。自我测试的过程中请留意resource-x.csv的变化。

  4. 本地使用Pycharm测试时,若发生找不到文件的错误,请修改test_read_csv.py:

    改为:

    Implements

Special Typing

思远哥哥买了新键盘,价值不菲。他邀请大家来试用键盘,但前提是回答出以下问题。

您将获得两个字符串s和t,两者都由小写的英文字母组成。您将逐个字符地键入字符串s,从第一个字符到最后一个字符。

特别之处在于,键入字符时,您可以按Backspace按钮,而不是按与之对应的按钮。Backspace会删除您刚刚键入的最后一个字符(如果您键入的字符串中没有字符,则不执行任何操作)。例如,如果s是"abcbd",并且您按Backspace而不是键入第一个和第四个字符,您将获得字符串"bd"(第一次按Backspace不删除任何字符,第二次按删除字符"c")。另一个例子,如果s是"abcaa",并且您用Backspace键代替最后两个字母,则得到的文本为"a"。

您的任务是确定是否可以通过以上方式,从字符串s获取字符串t.

 

Input

Output

Example

Input

Output

Note

解释一下上述用例。

为了从"ababa"中获取"ba",您可以按Backspace而不是键入第一个和第四个字符。

从"ababa"无法获取"bb"。

从"aaa"无法获取"aaaa"。

为了从"aababa"获得"ababa",您必须按Backspace而不是键入第一个字符,然后键入所有剩余的字符。

Implements

Grammar Lessons

Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules: There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb. There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine. Masculine adjectives end with -lios, and feminine adjectives end with -liala. Masculine nouns end with -etr, and feminime nouns end with -etra. Masculine verbs end with -initis, and feminime verbs end with -inites. Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language. It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language. There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications. A sentence is either exactly one valid language word or exactly one statement. Statement is any sequence of the Petya's language, that satisfy both conditions:

Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs. All words in the statement should have the same gender. After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language.

Input

The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105.

It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language.

Output

If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes).

Examples

input

petr output YES

input

etis atis animatis etis atis amatis

output

NO

input

nataliala kataliala vetra feinites

output

YES

Implements

To Do List

待办完成事项清单

编写一个命令行的待完成事项清单程序,用户按照格式输入命令,程序需要解析用户输入的命令,并完成相应的操作。

待办事项状态有两个状态:todo,表示待办;completed,表示已完成。命令和待办事项都为英文单词组成,单个待办事项为短语,不包含标点符号,首尾没有空格。

用户输入的命令和内容满足下列要求。

  1. todo -a "todo item1" "todo item2"

    表示增加(add)待办事项,待办事项可以为1个或多个,单个事项用双引号(英文)括起来,事项之间以空格分隔。 用户输入该命令后,程序应将待办事项保存到持久性位置(文件)。 存储时一行表示一个待办事项,格式为"状态:待办事项",状态包括todo和completed,待办事项就是上面的todo item1和todo item2。

  2. todo -d "todo item1"

    删除(delete)待办事项,待办事项可以为1个或多个,单个事项用双引号(英文)括起来,事项之间以空格分隔。 用户输入该命令后,程序应从所有任务中删去该任务,并同步到文件。

  3. todo -c "todo item1" "todo item2"

    修改待办事项为已完成(complete),待办事项可以为1个或多个,单个事项用双引号(英文)括起来,事项之间以空格分隔。 用户输入该命令后,程序应将这些任务的状态标记为已完成,并同步到文件。

  4. todo -f status

    查询(find)待办事项。status表示事项状态,可以是todo或completed。用户输入该命令后,程序应查询出指定状态的待办事项,并向控制台输出。 要求一行输出一个任务,并按照添加时的相对顺序输出,即先添加的输出在前(注:多个待办事项以一个命令添加的,位置靠前的是先添加的)。

  5. todo -all

    查询所有待办事项。用户输入该命令后,程序应查询出所有的待办事项,并向控制台输出。 要求一行输出一个任务,并按照添加时的相对顺序输出,即先添加的输出在前(注:多个待办事项以一个命令添加的,位置靠前的是先添加的)。

  6. todo -quit

    停止接收输入,结束方法,不要使用sys.exit()命令

程序操作过程分为:从控制台读取命令->解析命令->调用对应函数处理命令。

示例1:

存储的文件名为tasks.txt,存储路径为ToDoList根目录,存储的文件路径已经设置在file变量中,不可修改文件名及路径 请严格按照示例规范输出,不可修改方法名称、参数以及文件名,可以添加自己的方法

Implements

grade-histogram

要求

编写一个直方图程序

从"grades.in"文件中读取n个成绩(成绩为整形,在0-100之间,包括边界值)

首先输出每个区间内点的数目,用","隔开

然后打印直方图

文件格式如下:

项目说明:

src目录下为题目代码源文件,需要完成的内容为grades_histogram.py里的histogram方法。 src目录下的init.py文件不需要改动。

示例:

Implements

Two-sum

题目:

输入一个整数数组 nums 和一个整数目标值 target

请你在该数组中找出和为目标值 target 的那两个整数,由小到大返回它们的数组下标

每种输入只会对应一个答案,但是,数组中同一个位置的元素在答案里不能重复出现

项目说明:

src目录下为题目代码源文件,需要完成的内容为two_sum.py里的twoSum方法。 src目录下的init.py文件不需要改动。

示例:

Implements

String-Formatting

给定一个许可密钥字符串 s,仅由字母、数字字符和破折号组成。字符串由 n 个破折号分成 n + 1 组。你也会得到一个整数 k 。

我们想要重新格式化字符串 s,分成若干组,使每一组包含 k 个字符,第一组除外(它可以比 k 短,但仍然必须包含至少一个字符)。此外,两组之间必须插入破折号,并且应该将所有小写字母转换为大写字母。

返回 重新格式化的许可密钥。

示例1:

 

示例2:

Implements

Alice, Bob and Chocolate

Description

Input

The first line contains one integer n (1 ≤ n ≤ 105) — the amount of bars on the table. The second line contains a sequence t1, t2, ..., ti(1 ≤ t**i ≤ 1000), where ti is the time (in seconds) needed to consume the i-th bar (in the order from left to right).

Output

Print two numbers a and b, where a is the amount of bars consumed by Alice, and b is the amount of bars consumed by Bob.

Examples

Input

Output

Implements

Magnets

Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.

Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.

img

Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.

Input

The first line of the input contains an integer n (1 ≤ n ≤ 100000) — the number of magnets. Then n lines follow. The i-th line (1 ≤ i ≤ n) contains either characters "01", if Mike put the i-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.

Output

On the single line of the output print the number of groups of magnets.

Examples

input
output
input
output

Implements