DZY has a hash table with p buckets, numbered from 0 to p?-?1. He wants to insert n numbers, in the order they are given, into the hash table. For the i-th number xi, DZY will put it into the bucket numbered h(xi), where h(x) is the hash function. In this problem we will assume, that h(x)?=?x mod p. Operation a mod b denotes taking a remainder after division a by b.
However, each bucket can contain no more than one element. If DZY wants to insert an number into a bucket which is already filled, we say a "conflict" happens. Suppose the first conflict happens right after the i-th insertion, you should output i. If no conflict happens, just output -1.
InputThe first line contains two integers, p and n (2?≤?p,?n?≤?300). Then n lines follow. The i-th of them contains an integer xi (0?≤?xi?≤?109).
OutputOutput a single integer ― the answer to the problem.
Sample test(s) input10 5 0 21 53 41 53output
4input
5 5 0 1 2 3 4output
-1
//31 ms 0 KB #include#include int s[307],vis[307]; int main() { int p,n; while(scanf("%d%d",&p,&n)!=EOF) { memset(vis,0,sizeof(vis)); int flag=-1; for(int i=0;i
B. DZY Loves Strings time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outputDZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value wc. For each special string s?=?s1s2... s|s| (|s| is the length of the string) he represents its value with a function f(s), where
![]()
Now DZY has a string s. He wants to insert k lowercase letters into this string in Z??http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcmRlciB0byBnZXQgdGhlIGxhcmdlc3QgcG9zc2libGUgdmFsdWUgb2YgdGhlIHJlc3VsdGluZyBzdHJpbmcuIENhbiB5b3UgaGVscCBoaW0gY2FsY3VsYXRlIHRoZSBsYXJnZXN0IHBvc3NpYmxlIHZhbHVlIGhlIGNvdWxkIGdldD88L3A+CgoKCklucHV0CjxwPgpUaGUgZmlyc3QgbGluZSBjb250YWlucyBhIHNpbmdsZSBzdHJpbmcgPGVtPnM8L2VtPiAoMT+h3D8="s|?≤?103).
The second line contains a single integer k (0?≤?k?≤?103).
The third line contains twenty-six integers from wa to wz. Each such number is non-negative and doesn't exceed 1000.
OutputPrint a single integer ― the largest possible value of the resulting string DZY could get.
Sample test(s) inputabc 3 1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1output41NoteIn the test sample DZY can obtain "abcbbc", value?=?1?1?+?2?2?+?3?2?+?4?2?+?5?2?+?6?2?=?41.
//30 ms 0 KB #include#include char s[1007]; int v[26]; int main() { scanf("%s",s); int n,ans=0,maxx=-1; scanf("%d",&n); for(int i=0;i<26;i++) { scanf("%d",&v[i]); if(v[i]>maxx)maxx=v[i]; } int len=strlen(s); for(int i=0;i C. DZY Loves Sequences time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output DZY has a sequence a, consisting of n integers.
We'll call a sequence ai,?ai?+?1,?...,?aj (1?≤?i?≤?j?≤?n) a subsegment of the sequence a. The value (j?-?i?+?1) denotes the length of the subsegment.
Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing.
You only need to output the length of the subsegment you find.
InputThe first line contains integer n (1?≤?n?≤?105). The next line contains n integers a1,?a2,?...,?an (1?≤?ai?≤?109).
OutputIn a single line print the answer to the