A. Colorful Stones (Simplified Edition)
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string s. The i-th (1-based) character of s represents the color of the i-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction c, if Liss is standing on a stone whose colors is c, Liss will move one stone forward, else she will not move.
You are given a string t. The number of instructions is equal to the length of t, and the i-th character of t represents the i-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
Input
The input contains two lines. The first line contains the string s (1 ≤ |s| ≤ 50). The second line contains the string t (1 ≤ |t| ≤ 50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Output
Print the final 1-based position of Liss in a single line.
Examples
Input
Copy
RGB
RRR
Output
Copy
2
Input
Copy
RRRBGBRBBB
BBBRR
Output
Copy
3
Input
Copy
BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB
BBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB
Output
Copy
15
模拟;
#include
#include
#include
#include
#include
#include
#include
#include
B. Roadside Trees (Simplified Edition)
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Squirrel Liss loves nuts. There are n trees (numbered 1 to n from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree i is hi. Liss wants to eat all nuts.
Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the following actions:
- Walk up or down one unit on a tree.
- Eat a nut on the top of the current tree.
- Jump to the next tree. In this action the height of Liss doesn't change. More formally, when Liss is at heighthof the treei(1 ≤i≤n- 1), she jumps to heighthof the treei+ 1. This action can't be performed ifh>hi + 1.
Compute the minimal time (in seconds) required to eat all nuts.
Input
The first line contains an integer n (1 ≤ n ≤ 105) — the number of trees.
Next n lines contains the height of trees: i-th line contains an integer hi (1 ≤ hi ≤ 104) — the height of the tree with the number i.
Output
Print a single integer — the minimal time required to eat all nuts in seconds.
Examples
Input
Copy
2
1
2
Output
Copy
5
Input
Copy
5
2
1
2
1
1
Output
Copy
14
#include
#include
#include
#include
#include
#include
#include
#include
C. Escape from Stones
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0, 1]. Next, n stones will fall and Liss will escape from the stones. The stones are numbered from 1 to n in order.
The stones always fall to the center of Liss's interval. When Liss occupies the interval [k - d, k + d] and a stone falls to k, she will escape to the left or to the right. If she escapes to the left, her new interval will be [k - d, k]. If she escapes to the right, her new interval will be [k, k + d].
You are given a string s of length n. If the i-th character of s is "l" or "r", when the i-th stone falls Liss will escape to the left or to the right, respectively. Find the sequence of stones' numbers from left to right after all the n stones falls.
Input
The input consists of only one line. The only line contains the string s (1 ≤ |s| ≤ 106). Each character in s will be either "l" or "r".
Output
Output n lines — on the i-th line you should print the i-th stone's number from the left.
Examples
Input
Copy
llrlr
Output
Copy
3
5
4
2
1
Input
Copy
rrlll
Output
Copy
1
2
5
4
3
Input
Copy
lrlrr
Output
Copy
2
4
5
3
1
Note
In the first example, the positions of stones 1, 2, 3, 4, 5 will be , respectively. So you should print the sequence: 3, 5, 4, 2, 1.
偏思维一点,找到规律就行了;
#include
#include
#include
#include
#include
#include
#include
#include
D. Good Sequences
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks n integers a1, a2, ..., an are good.
Now she is interested in good sequences. A sequence x1, x2, ..., xk is called good if it satisfies the following three conditions:
- The sequence is strictly increasing, i.e.xi<xi + 1for eachi(1 ≤i≤k- 1).
- No two adjacent elements are coprime, i.e.gcd(xi,xi + 1) > 1 for eachi(1 ≤i≤k- 1) (wheregcd(p,q) denotes the greatest common divisor of the integerspandq).
- All elements of the sequence are good integers.
Find the length of the longest good sequence.
Input
The input consists of two lines. The first line contains a single integer n (1 ≤ n ≤ 105) — the number of good integers. The second line contains a single-space separated list of good integers a1, a2, ..., an in strictly increasing order (1 ≤ ai ≤ 105; ai < ai + 1).
Output
Print a single integer — the length of the longest good sequence.
Examples
Input
Copy
5
2 3 4 6 9
Output
Copy
4
Input
Copy
9
1 2 3 5 6 7 8 9 10
Output
Copy
4
Note
In the first example, the following sequences are examples of good sequences: [2; 4; 6; 9], [2; 4; 6], [3; 9], [6]. The length of the longest good sequence is 4.
有趣的dp题目;
考虑枚举因数;
用dp[i]表示以因数i结尾时的最大值;
#include
#include
#include
#include
#include
#include
#include
#include
EPFL - Fighting