Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integersb1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integersa1, a2, ..., am, and an integer l.
Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| ≤ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term.
But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers.
The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second line contains m distinct integers a1, a2, ..., am (-109 ≤ ai ≤ 109) — numbers that will never be written on the board.
Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.
3 2 30 4 6 14 25 48
3
123 1 2143435 4 123 11 -5453 141245
0
123 1 2143435 4 54343 -13 6 124
inf
In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.
In the third case, Masha will write infinitely integers 123.
Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| ≤ l is
satisfied (|x| means
absolute value of x).
the reason of failure:1、题意理解问题、。
这句话是说当前面的满足条件的时候才一个个输入到键盘上,如果刚开始abs(b)>l,便从一开始就不输入
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:

In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
The first line contains single integer n (2 ≤ n ≤ 105) — the size of the array a.
The second line contains n integers a1, a2, ..., an (-109 ≤ ai ≤ 109) — the array elements.
Print the only integer — the maximum value of f.
5 1 4 2 3 1
3
4 1 5 4 7
6
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
the reason of failure:1、第二个差值为+的条件是在1不取的情况,而第二个差值为-说明第一个已经取得了。
2、long long 的问题,注意题目的数据,这个很重要!!!总是错,long long 要把所有涉及到的值全部修改。
#include<iostream>
#include <stdio.h>
#include <string.h>
#include<stdlib.h>
#include <map>
#include <set>
#include <math.h>
#include <algorithm>
using namespace std;
const int INF=1e9+7;
int qq[105000];
int q1[105000];
int main(){
//freopen("in.txt","r",stdin);
int i,j,k,l1,r1,f1,f2,f3,t2,t3,n,m;
int b,l,q;
cin >> n;
for(i=1;i<=n;i++)
cin >> qq[i];
long long max1=-INF;
long long t1;
for(i=2;i<=n;i++){
q1[i-1]=abs(qq[i]-qq[i-1]);
if(q1[i-1]>max1)max1=q1[i-1];
//cout <<q1[i-1] << endl;
}
t1=0;
for(i=1;i<n;i++){
if(i%2==0){
t1-=q1[i];
if(t1<0){
t1=0;
}
}else{
t1+=q1[i];
if(t1>max1){
max1=t1;
}
}
}
t1=0;
for(i=1;i<n;i++){
if(i%2==1){
t1-=q1[i];
if(t1<0){
t1=0;
}
}else{
t1+=q1[i];
if(t1>max1){
max1=t1;
}
}
}
cout <<max1 <<endl;
return 0;
}