contestId
int64 0
1.01k
| index
stringclasses 57
values | name
stringlengths 2
58
| type
stringclasses 2
values | rating
int64 0
3.5k
| tags
listlengths 0
11
| title
stringclasses 522
values | time-limit
stringclasses 8
values | memory-limit
stringclasses 8
values | problem-description
stringlengths 0
7.15k
| input-specification
stringlengths 0
2.05k
| output-specification
stringlengths 0
1.5k
| demo-input
listlengths 0
7
| demo-output
listlengths 0
7
| note
stringlengths 0
5.24k
| points
float64 0
425k
| test_cases
listlengths 0
402
| creationTimeSeconds
int64 1.37B
1.7B
| relativeTimeSeconds
int64 8
2.15B
| programmingLanguage
stringclasses 3
values | verdict
stringclasses 14
values | testset
stringclasses 12
values | passedTestCount
int64 0
1k
| timeConsumedMillis
int64 0
15k
| memoryConsumedBytes
int64 0
805M
| code
stringlengths 3
65.5k
| prompt
stringlengths 262
8.2k
| response
stringlengths 17
65.5k
| score
float64 -1
3.99
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
352
|
B
|
Jeff and Periods
|
PROGRAMMING
| 1,300
|
[
"implementation",
"sortings"
] | null | null |
One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
- *x* occurs in sequence *a*. - Consider all positions of numbers *x* in the sequence *a* (such *i*, that *a**i*<==<=*x*). These numbers, sorted in the increasing order, must form an arithmetic progression.
Help Jeff, find all *x* that meet the problem conditions.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). The numbers are separated by spaces.
|
In the first line print integer *t* — the number of valid *x*. On each of the next *t* lines print two integers *x* and *p**x*, where *x* is current suitable value, *p**x* is the common difference between numbers in the progression (if *x* occurs exactly once in the sequence, *p**x* must equal 0). Print the pairs in the order of increasing *x*.
|
[
"1\n2\n",
"8\n1 2 1 3 1 2 1 5\n"
] |
[
"1\n2 0\n",
"4\n1 2\n2 4\n3 0\n5 0\n"
] |
In the first test 2 occurs exactly once in the sequence, ergo *p*<sub class="lower-index">2</sub> = 0.
| 1,000
|
[
{
"input": "1\n2",
"output": "1\n2 0"
},
{
"input": "8\n1 2 1 3 1 2 1 5",
"output": "4\n1 2\n2 4\n3 0\n5 0"
},
{
"input": "3\n1 10 5",
"output": "3\n1 0\n5 0\n10 0"
},
{
"input": "4\n9 9 3 5",
"output": "3\n3 0\n5 0\n9 1"
},
{
"input": "6\n1 2 2 1 1 2",
"output": "0"
},
{
"input": "6\n2 6 3 8 7 2",
"output": "5\n2 5\n3 0\n6 0\n7 0\n8 0"
},
{
"input": "7\n2 1 2 1 2 1 2",
"output": "2\n1 2\n2 2"
},
{
"input": "8\n1 1 1 1 1 1 1 1",
"output": "1\n1 1"
},
{
"input": "9\n2 3 3 3 2 1 2 3 2",
"output": "1\n1 0"
},
{
"input": "10\n3 1 1 1 1 3 1 2 2 1",
"output": "2\n2 1\n3 5"
},
{
"input": "12\n10 9 8 7 7 8 9 10 10 9 8 7",
"output": "0"
}
] | 1,662,511,859
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 1
| 124
| 0
|
input()
nums = list(map(int, input().split()))
set_nums = sorted(set(nums))
ans = []
for num in set_nums:
count = nums.count(num)
if count == 1:
ans.append((num, 0))
continue
indexes = [nums.index(num)]
for _ in range(count - 1):
indexes.append(nums.index(num, indexes[-1] + 1))
for i in range(len(indexes) - 2):
if indexes[i] + indexes[i + 1] != indexes[i + 2]:
break
else:
ans.append((num, indexes[1] - indexes[0]))
print(len(ans))
for num, d in ans:
print(num, d)
|
Title: Jeff and Periods
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
- *x* occurs in sequence *a*. - Consider all positions of numbers *x* in the sequence *a* (such *i*, that *a**i*<==<=*x*). These numbers, sorted in the increasing order, must form an arithmetic progression.
Help Jeff, find all *x* that meet the problem conditions.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). The numbers are separated by spaces.
Output Specification:
In the first line print integer *t* — the number of valid *x*. On each of the next *t* lines print two integers *x* and *p**x*, where *x* is current suitable value, *p**x* is the common difference between numbers in the progression (if *x* occurs exactly once in the sequence, *p**x* must equal 0). Print the pairs in the order of increasing *x*.
Demo Input:
['1\n2\n', '8\n1 2 1 3 1 2 1 5\n']
Demo Output:
['1\n2 0\n', '4\n1 2\n2 4\n3 0\n5 0\n']
Note:
In the first test 2 occurs exactly once in the sequence, ergo *p*<sub class="lower-index">2</sub> = 0.
|
```python
input()
nums = list(map(int, input().split()))
set_nums = sorted(set(nums))
ans = []
for num in set_nums:
count = nums.count(num)
if count == 1:
ans.append((num, 0))
continue
indexes = [nums.index(num)]
for _ in range(count - 1):
indexes.append(nums.index(num, indexes[-1] + 1))
for i in range(len(indexes) - 2):
if indexes[i] + indexes[i + 1] != indexes[i + 2]:
break
else:
ans.append((num, indexes[1] - indexes[0]))
print(len(ans))
for num, d in ans:
print(num, d)
```
| 0
|
|
58
|
A
|
Chat room
|
PROGRAMMING
| 1,000
|
[
"greedy",
"strings"
] |
A. Chat room
|
1
|
256
|
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
|
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
|
If Vasya managed to say hello, print "YES", otherwise print "NO".
|
[
"ahhellllloou\n",
"hlelo\n"
] |
[
"YES\n",
"NO\n"
] |
none
| 500
|
[
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,541,394,245
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 1
| 109
| 0
|
a=input()
b=len(a)
n=0
for i in range(b):
c=a[i]
if n==0:
if c=='h':
n+=1
if n==1:
if c=='e':
n+=1
if n==2:
if c=='l':
n+=1
if n==3:
if c=='l':
n+=1
if n==4:
if c=='o':
n+=1
if n==5:
print('YES')
else:
print('NO')
|
Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none
|
```python
a=input()
b=len(a)
n=0
for i in range(b):
c=a[i]
if n==0:
if c=='h':
n+=1
if n==1:
if c=='e':
n+=1
if n==2:
if c=='l':
n+=1
if n==3:
if c=='l':
n+=1
if n==4:
if c=='o':
n+=1
if n==5:
print('YES')
else:
print('NO')
```
| 0
|
87
|
A
|
Trains
|
PROGRAMMING
| 1,500
|
[
"implementation",
"math"
] |
A. Trains
|
2
|
256
|
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every *a* minutes, but a train goes to Masha's direction every *b* minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample).
We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously.
Help Vasya count to which girlfriend he will go more often.
|
The first line contains two integers *a* and *b* (*a*<=≠<=*b*,<=1<=≤<=*a*,<=*b*<=≤<=106).
|
Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency.
|
[
"3 7\n",
"5 3\n",
"2 3\n"
] |
[
"Dasha\n",
"Masha\n",
"Equal\n"
] |
Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls equally often.
If he descends to the subway at a moment of time from 0 to 2, he leaves for Dasha on the train that arrives by the second minute.
If he descends to the subway at a moment of time from 2 to 3, he leaves for Masha on the train that arrives by the third minute.
If he descends to the subway at a moment of time from 3 to 4, he leaves for Dasha on the train that arrives by the fourth minute.
If he descends to the subway at a moment of time from 4 to 6, he waits for both trains to arrive by the sixth minute and goes to Masha as trains go less often in Masha's direction.
In sum Masha and Dasha get equal time — three minutes for each one, thus, Vasya will go to both girlfriends equally often.
| 500
|
[
{
"input": "3 7",
"output": "Dasha"
},
{
"input": "5 3",
"output": "Masha"
},
{
"input": "2 3",
"output": "Equal"
},
{
"input": "31 88",
"output": "Dasha"
},
{
"input": "8 75",
"output": "Dasha"
},
{
"input": "32 99",
"output": "Dasha"
},
{
"input": "77 4",
"output": "Masha"
},
{
"input": "27 1",
"output": "Masha"
},
{
"input": "84 11",
"output": "Masha"
},
{
"input": "4 6",
"output": "Equal"
},
{
"input": "52 53",
"output": "Equal"
},
{
"input": "397 568",
"output": "Dasha"
},
{
"input": "22 332",
"output": "Dasha"
},
{
"input": "419 430",
"output": "Dasha"
},
{
"input": "638 619",
"output": "Masha"
},
{
"input": "393 325",
"output": "Masha"
},
{
"input": "876 218",
"output": "Masha"
},
{
"input": "552 551",
"output": "Equal"
},
{
"input": "906 912",
"output": "Equal"
},
{
"input": "999 996",
"output": "Equal"
},
{
"input": "652 653",
"output": "Equal"
},
{
"input": "3647 7698",
"output": "Dasha"
},
{
"input": "2661 8975",
"output": "Dasha"
},
{
"input": "251 9731",
"output": "Dasha"
},
{
"input": "9886 8671",
"output": "Masha"
},
{
"input": "8545 7312",
"output": "Masha"
},
{
"input": "4982 2927",
"output": "Masha"
},
{
"input": "7660 7658",
"output": "Equal"
},
{
"input": "9846 9844",
"output": "Equal"
},
{
"input": "9632 9640",
"output": "Equal"
},
{
"input": "5036 5037",
"output": "Equal"
},
{
"input": "64854 77725",
"output": "Dasha"
},
{
"input": "4965 85708",
"output": "Dasha"
},
{
"input": "20393 86640",
"output": "Dasha"
},
{
"input": "99207 30728",
"output": "Masha"
},
{
"input": "77545 13842",
"output": "Masha"
},
{
"input": "30362 10712",
"output": "Masha"
},
{
"input": "51291 51292",
"output": "Equal"
},
{
"input": "55381 55382",
"output": "Equal"
},
{
"input": "91560 91550",
"output": "Equal"
},
{
"input": "99087 99090",
"output": "Equal"
},
{
"input": "983794 986389",
"output": "Dasha"
},
{
"input": "779183 786727",
"output": "Dasha"
},
{
"input": "450766 610961",
"output": "Dasha"
},
{
"input": "664690 630787",
"output": "Masha"
},
{
"input": "461363 256765",
"output": "Masha"
},
{
"input": "638067 409048",
"output": "Masha"
},
{
"input": "929061 929052",
"output": "Equal"
},
{
"input": "996219 996216",
"output": "Equal"
},
{
"input": "716249 716248",
"output": "Equal"
},
{
"input": "782250 782252",
"output": "Equal"
},
{
"input": "1 2",
"output": "Equal"
},
{
"input": "2 1",
"output": "Equal"
},
{
"input": "999999 1000000",
"output": "Equal"
},
{
"input": "999997 1000000",
"output": "Dasha"
},
{
"input": "1000000 999993",
"output": "Masha"
},
{
"input": "999983 999979",
"output": "Masha"
}
] | 1,672,120,025
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 1
| 30
| 0
|
def ss(a,b):
if 2*a<b:
return 1
return 0
a,b = map(int,input().split())
if a<b:
if ss(a,b):
print("Dasha")
else:
print("Equal")
else:
if ss(b,a)==0:
print("Equal")
else:
print("Masha")
|
Title: Trains
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every *a* minutes, but a train goes to Masha's direction every *b* minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample).
We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously.
Help Vasya count to which girlfriend he will go more often.
Input Specification:
The first line contains two integers *a* and *b* (*a*<=≠<=*b*,<=1<=≤<=*a*,<=*b*<=≤<=106).
Output Specification:
Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency.
Demo Input:
['3 7\n', '5 3\n', '2 3\n']
Demo Output:
['Dasha\n', 'Masha\n', 'Equal\n']
Note:
Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls equally often.
If he descends to the subway at a moment of time from 0 to 2, he leaves for Dasha on the train that arrives by the second minute.
If he descends to the subway at a moment of time from 2 to 3, he leaves for Masha on the train that arrives by the third minute.
If he descends to the subway at a moment of time from 3 to 4, he leaves for Dasha on the train that arrives by the fourth minute.
If he descends to the subway at a moment of time from 4 to 6, he waits for both trains to arrive by the sixth minute and goes to Masha as trains go less often in Masha's direction.
In sum Masha and Dasha get equal time — three minutes for each one, thus, Vasya will go to both girlfriends equally often.
|
```python
def ss(a,b):
if 2*a<b:
return 1
return 0
a,b = map(int,input().split())
if a<b:
if ss(a,b):
print("Dasha")
else:
print("Equal")
else:
if ss(b,a)==0:
print("Equal")
else:
print("Masha")
```
| 0
|
58
|
A
|
Chat room
|
PROGRAMMING
| 1,000
|
[
"greedy",
"strings"
] |
A. Chat room
|
1
|
256
|
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
|
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
|
If Vasya managed to say hello, print "YES", otherwise print "NO".
|
[
"ahhellllloou\n",
"hlelo\n"
] |
[
"YES\n",
"NO\n"
] |
none
| 500
|
[
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,589,970,789
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 40
| 124
| 307,200
|
patern="hello"
def calc(str):
arr=[-1]
for i in str :
arr.append(-1)
for i in range(1,len(str)+1):
for j in range(0,i):
if arr[j]==-1:
if str[i-1]==patern[0]:
arr[i]=max(0,arr[i])
else :
arr[i]=max(-1,arr[i])
elif arr[j]==len(patern)-1:
break
elif str[i-1]==patern[int(arr[j])+1]:
arr[i]=max(arr[i],int(arr[j])+1)
if len(patern)-1 in arr:
print("YES")
else:
print("NO")
calc(input())
|
Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none
|
```python
patern="hello"
def calc(str):
arr=[-1]
for i in str :
arr.append(-1)
for i in range(1,len(str)+1):
for j in range(0,i):
if arr[j]==-1:
if str[i-1]==patern[0]:
arr[i]=max(0,arr[i])
else :
arr[i]=max(-1,arr[i])
elif arr[j]==len(patern)-1:
break
elif str[i-1]==patern[int(arr[j])+1]:
arr[i]=max(arr[i],int(arr[j])+1)
if len(patern)-1 in arr:
print("YES")
else:
print("NO")
calc(input())
```
| 3.937428
|
103
|
A
|
Testing Pants for Sadness
|
PROGRAMMING
| 1,100
|
[
"greedy",
"implementation",
"math"
] |
A. Testing Pants for Sadness
|
2
|
256
|
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of *n* questions; the questions are to be answered strictly in the order in which they are given, from question 1 to question *n*. Question *i* contains *a**i* answer variants, exactly one of them is correct.
A click is regarded as selecting any answer in any question. The goal is to select the correct answer for each of the *n* questions. If Vaganych selects a wrong answer for some question, then all selected answers become unselected and the test starts from the very beginning, from question 1 again. But Vaganych remembers everything. The order of answers for each question and the order of questions remain unchanged, as well as the question and answers themselves.
Vaganych is very smart and his memory is superb, yet he is unbelievably unlucky and knows nothing whatsoever about the test's theme. How many clicks will he have to perform in the worst case?
|
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). It is the number of questions in the test. The second line contains space-separated *n* positive integers *a**i* (1<=≤<=*a**i*<=≤<=109), the number of answer variants to question *i*.
|
Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
|
[
"2\n1 1\n",
"2\n2 2\n",
"1\n10\n"
] |
[
"2",
"5",
"10"
] |
Note to the second sample. In the worst-case scenario you will need five clicks:
- the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the third click selects the first variant to the second question, it is wrong and we go back to question 1; - the fourth click selects the second variant to the first question, it proves as correct as it was and we move on to the second question; - the fifth click selects the second variant to the second question, it proves correct, the test is finished.
| 500
|
[
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "2\n2 2",
"output": "5"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "3\n2 4 1",
"output": "10"
},
{
"input": "4\n5 5 3 1",
"output": "22"
},
{
"input": "2\n1000000000 1000000000",
"output": "2999999999"
},
{
"input": "10\n5 7 8 1 10 3 6 4 10 6",
"output": "294"
},
{
"input": "100\n5 7 5 3 5 4 6 5 3 6 4 6 6 2 1 9 6 5 3 8 4 10 1 9 1 3 7 6 5 5 8 8 7 7 8 9 2 10 3 5 4 2 6 10 2 6 9 6 1 9 3 7 7 8 3 9 9 5 10 10 3 10 7 8 3 9 8 3 2 4 10 2 1 1 7 3 9 10 4 6 9 8 2 1 4 10 1 10 6 8 7 5 3 3 6 2 7 10 3 8",
"output": "24212"
},
{
"input": "100\n96 23 25 62 34 30 85 15 26 61 59 87 34 99 60 41 52 73 63 84 50 89 42 29 87 99 19 94 84 43 82 90 41 100 60 61 99 49 26 3 97 5 24 34 51 59 69 61 11 41 72 60 33 36 18 29 82 53 18 80 52 98 38 32 56 95 55 79 32 80 37 64 45 13 62 80 70 29 1 58 88 24 79 68 41 80 12 72 52 39 64 19 54 56 70 58 19 3 83 62",
"output": "261115"
},
{
"input": "100\n883 82 79 535 478 824 700 593 262 385 403 183 176 386 126 648 710 516 922 97 800 728 372 9 954 911 975 526 476 3 74 459 471 174 295 831 698 21 927 698 580 856 712 430 5 473 592 40 301 230 763 266 38 213 393 70 333 779 811 249 130 456 763 657 578 699 939 660 898 918 438 855 892 85 35 232 54 593 849 777 917 979 796 322 473 887 284 105 522 415 86 480 80 592 516 227 680 574 488 644",
"output": "2519223"
},
{
"input": "100\n6659 5574 5804 7566 7431 1431 3871 6703 200 300 3523 3580 8500 2312 4812 3149 3324 5846 8965 5758 5831 1341 7733 4477 355 3024 2941 9938 1494 16 1038 8262 9938 9230 5192 8113 7575 7696 5566 2884 8659 1951 1253 6480 3877 3707 5482 3825 5359 44 3219 3258 1785 5478 4525 5950 2417 1991 8885 4264 8769 2961 7107 8904 5097 2319 5713 8811 9723 8677 2153 3237 7174 9528 9260 7390 3050 6823 6239 5222 4602 933 7823 4198 8304 244 5845 3189 4490 3216 7877 6323 1938 4597 880 1206 1691 1405 4122 5950",
"output": "24496504"
},
{
"input": "50\n515844718 503470143 928669067 209884122 322869098 241621928 844696197 105586164 552680307 968792756 135928721 842094825 298782438 829020472 791637138 285482545 811025527 428952878 887796419 11883658 546401594 6272027 100292274 308219869 372132044 955814846 644008184 521195760 919389466 215065725 687764134 655750167 181397022 404292682 643251185 776299412 741398345 865144798 369796727 673902099 124966684 35796775 794385099 594562033 550366869 868093561 695094388 580789105 755076935 198783899",
"output": "685659563557"
},
{
"input": "10\n12528238 329065023 620046219 303914458 356423530 751571368 72944261 883971060 123105651 868129460",
"output": "27409624352"
},
{
"input": "1\n84355694",
"output": "84355694"
},
{
"input": "2\n885992042 510468669",
"output": "1906929379"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "100"
},
{
"input": "100\n2 1 2 2 2 2 1 2 2 1 2 2 2 1 2 1 2 2 1 2 2 2 2 2 2 1 2 1 1 2 1 1 2 1 2 1 1 1 2 2 2 2 2 1 2 2 2 2 1 1 1 1 1 2 2 1 1 1 2 2 1 1 2 1 1 2 2 2 2 1 2 2 2 1 2 1 2 2 1 2 1 1 1 2 2 1 2 1 2 1 1 1 2 1 2 2 2 1 1 1",
"output": "2686"
},
{
"input": "100\n1 3 2 1 1 2 1 3 2 2 3 1 1 1 2 2 1 3 3 1 1 2 2 3 2 1 3 1 3 2 1 1 3 3 2 1 2 2 2 3 2 2 3 2 2 3 2 1 3 1 1 2 1 3 2 2 1 1 1 1 1 1 3 1 2 3 1 1 1 1 1 2 3 3 1 1 1 1 2 3 3 1 3 2 2 3 2 1 3 2 2 3 1 1 3 2 3 2 3 1",
"output": "4667"
}
] | 1,628,946,907
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 25
| 154
| 6,758,400
|
n = int(input())
s = input().split()
ans = 0
for i in range(1, n + 1) :
x = int(s[i - 1])
ans += (x - 1) * (i - 1) + x
print(ans)
|
Title: Testing Pants for Sadness
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of *n* questions; the questions are to be answered strictly in the order in which they are given, from question 1 to question *n*. Question *i* contains *a**i* answer variants, exactly one of them is correct.
A click is regarded as selecting any answer in any question. The goal is to select the correct answer for each of the *n* questions. If Vaganych selects a wrong answer for some question, then all selected answers become unselected and the test starts from the very beginning, from question 1 again. But Vaganych remembers everything. The order of answers for each question and the order of questions remain unchanged, as well as the question and answers themselves.
Vaganych is very smart and his memory is superb, yet he is unbelievably unlucky and knows nothing whatsoever about the test's theme. How many clicks will he have to perform in the worst case?
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). It is the number of questions in the test. The second line contains space-separated *n* positive integers *a**i* (1<=≤<=*a**i*<=≤<=109), the number of answer variants to question *i*.
Output Specification:
Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Demo Input:
['2\n1 1\n', '2\n2 2\n', '1\n10\n']
Demo Output:
['2', '5', '10']
Note:
Note to the second sample. In the worst-case scenario you will need five clicks:
- the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the third click selects the first variant to the second question, it is wrong and we go back to question 1; - the fourth click selects the second variant to the first question, it proves as correct as it was and we move on to the second question; - the fifth click selects the second variant to the second question, it proves correct, the test is finished.
|
```python
n = int(input())
s = input().split()
ans = 0
for i in range(1, n + 1) :
x = int(s[i - 1])
ans += (x - 1) * (i - 1) + x
print(ans)
```
| 3.948911
|
0
|
none
|
none
|
none
| 0
|
[
"none"
] | null | null |
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman.
After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
|
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman.
|
Print a single integer — the largest possible score.
|
[
"3\n3 1 5\n",
"1\n10\n"
] |
[
"26\n",
"10\n"
] |
Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
| 0
|
[
{
"input": "3\n3 1 5",
"output": "26"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "10\n8 10 2 5 6 2 4 7 2 1",
"output": "376"
},
{
"input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821",
"output": "40204082"
},
{
"input": "10\n1 2 2 2 4 5 6 7 8 10",
"output": "376"
},
{
"input": "10\n161821 171308 228496 397870 431255 542924 718337 724672 888642 892002",
"output": "40204082"
},
{
"input": "1\n397870",
"output": "397870"
},
{
"input": "1\n1000000",
"output": "1000000"
},
{
"input": "10\n10 8 7 6 5 4 2 2 2 1",
"output": "376"
},
{
"input": "10\n892002 888642 724672 718337 542924 431255 397870 228496 171308 161821",
"output": "40204082"
},
{
"input": "10\n5 2 6 10 10 10 10 2 2 5",
"output": "485"
},
{
"input": "10\n431255 724672 228496 397870 397870 397870 397870 724672 888642 431255",
"output": "36742665"
},
{
"input": "10\n2 2 2 5 5 6 10 10 10 10",
"output": "485"
},
{
"input": "10\n228496 397870 397870 397870 397870 431255 431255 724672 724672 888642",
"output": "36742665"
},
{
"input": "10\n10 10 10 10 6 5 5 2 2 2",
"output": "485"
},
{
"input": "10\n888642 724672 724672 431255 431255 397870 397870 397870 397870 228496",
"output": "36742665"
},
{
"input": "10\n10 10 10 10 10 10 10 10 10 10",
"output": "640"
},
{
"input": "10\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000",
"output": "64000000"
},
{
"input": "1\n397870",
"output": "397870"
},
{
"input": "2\n1 2",
"output": "6"
},
{
"input": "2\n2 3",
"output": "10"
},
{
"input": "2\n1 1",
"output": "4"
}
] | 1,409,066,639
| 5,039
|
Python 3
|
OK
|
TESTS
| 36
| 451
| 20,172,800
|
n = int(input())
num = list(map(int, input().split()))
num.sort(reverse=True)
psum = [0]*n
psum[0] = num[0]
for i in range(1, n):
psum[i] = psum[i-1]+num[i]
print(sum(psum[1:])+psum[n-1])
|
Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman.
After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman.
Output Specification:
Print a single integer — the largest possible score.
Demo Input:
['3\n3 1 5\n', '1\n10\n']
Demo Output:
['26\n', '10\n']
Note:
Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
|
```python
n = int(input())
num = list(map(int, input().split()))
num.sort(reverse=True)
psum = [0]*n
psum[0] = num[0]
for i in range(1, n):
psum[i] = psum[i-1]+num[i]
print(sum(psum[1:])+psum[n-1])
```
| 3
|
|
431
|
C
|
k-Tree
|
PROGRAMMING
| 1,600
|
[
"dp",
"implementation",
"trees"
] | null | null |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a *k*-tree.
A *k*-tree is an infinite rooted tree where:
- each vertex has exactly *k* children; - each edge has some weight; - if we look at the edges that goes from some vertex to its children (exactly *k* edges), then their weights will equal 1,<=2,<=3,<=...,<=*k*.
The picture below shows a part of a 3-tree.
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (109<=+<=7).
|
A single line contains three space-separated integers: *n*, *k* and *d* (1<=≤<=*n*,<=*k*<=≤<=100; 1<=≤<=*d*<=≤<=*k*).
|
Print a single integer — the answer to the problem modulo 1000000007 (109<=+<=7).
|
[
"3 3 2\n",
"3 3 3\n",
"4 3 2\n",
"4 5 2\n"
] |
[
"3\n",
"1\n",
"6\n",
"7\n"
] |
none
| 1,500
|
[
{
"input": "3 3 2",
"output": "3"
},
{
"input": "3 3 3",
"output": "1"
},
{
"input": "4 3 2",
"output": "6"
},
{
"input": "4 5 2",
"output": "7"
},
{
"input": "28 6 3",
"output": "110682188"
},
{
"input": "5 100 1",
"output": "16"
},
{
"input": "50 6 3",
"output": "295630102"
},
{
"input": "10 13 6",
"output": "48"
},
{
"input": "20 16 14",
"output": "236"
},
{
"input": "1 10 1",
"output": "1"
},
{
"input": "8 11 4",
"output": "47"
},
{
"input": "16 5 4",
"output": "16175"
},
{
"input": "5 26 17",
"output": "0"
},
{
"input": "35 47 42",
"output": "0"
},
{
"input": "11 6 2",
"output": "975"
},
{
"input": "54 60 16",
"output": "931055544"
},
{
"input": "47 5 1",
"output": "164058640"
},
{
"input": "70 6 1",
"output": "592826579"
},
{
"input": "40 77 77",
"output": "0"
},
{
"input": "96 9 6",
"output": "362487247"
},
{
"input": "52 46 4",
"output": "27907693"
},
{
"input": "74 41 28",
"output": "806604424"
},
{
"input": "100 100 100",
"output": "1"
},
{
"input": "99 99 5",
"output": "700732369"
},
{
"input": "100 100 1",
"output": "988185646"
},
{
"input": "98 98 64",
"output": "237643149"
},
{
"input": "28 74 2",
"output": "134217727"
},
{
"input": "86 69 62",
"output": "217513984"
},
{
"input": "9 17 14",
"output": "0"
},
{
"input": "73 72 12",
"output": "426374014"
},
{
"input": "41 98 76",
"output": "0"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "1 100 100",
"output": "0"
},
{
"input": "1 100 1",
"output": "1"
},
{
"input": "1 100 2",
"output": "0"
},
{
"input": "2 100 2",
"output": "1"
},
{
"input": "2 100 1",
"output": "2"
},
{
"input": "50 50 1",
"output": "949480669"
},
{
"input": "100 50 50",
"output": "661237556"
},
{
"input": "3 2 2",
"output": "2"
},
{
"input": "100 50 3",
"output": "494224664"
},
{
"input": "90 97 24",
"output": "413496885"
},
{
"input": "31 8 8",
"output": "52532592"
},
{
"input": "78 90 38",
"output": "744021655"
},
{
"input": "100 13 11",
"output": "883875774"
},
{
"input": "100 45 8",
"output": "367847193"
},
{
"input": "31 8 4",
"output": "924947104"
},
{
"input": "35 95 9",
"output": "927164672"
},
{
"input": "45 5 3",
"output": "252804490"
},
{
"input": "1 5 5",
"output": "0"
},
{
"input": "89 75 59",
"output": "179807625"
},
{
"input": "90 100 30",
"output": "697322870"
},
{
"input": "89 73 32",
"output": "152673180"
},
{
"input": "100 90 80",
"output": "11531520"
}
] | 1,683,213,085
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 6
| 46
| 0
|
import sys
input = lambda: sys.stdin.readline().rstrip()
N,K,D = map(int, input().split())
dp = [0]*(N+1)
dp2 = [0]*(N+1)
dp[0] = 1
for i in range(N):
for j in range(1,K+1):
if i+j>N:break
if j<D:
dp[i+j]+=dp[i]
dp2[i+j]+=dp2[i]
else:
dp2[i+j]+=dp[i]
dp2[i+j]+=dp2[i]
print(dp2[-1])
|
Title: k-Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a *k*-tree.
A *k*-tree is an infinite rooted tree where:
- each vertex has exactly *k* children; - each edge has some weight; - if we look at the edges that goes from some vertex to its children (exactly *k* edges), then their weights will equal 1,<=2,<=3,<=...,<=*k*.
The picture below shows a part of a 3-tree.
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (109<=+<=7).
Input Specification:
A single line contains three space-separated integers: *n*, *k* and *d* (1<=≤<=*n*,<=*k*<=≤<=100; 1<=≤<=*d*<=≤<=*k*).
Output Specification:
Print a single integer — the answer to the problem modulo 1000000007 (109<=+<=7).
Demo Input:
['3 3 2\n', '3 3 3\n', '4 3 2\n', '4 5 2\n']
Demo Output:
['3\n', '1\n', '6\n', '7\n']
Note:
none
|
```python
import sys
input = lambda: sys.stdin.readline().rstrip()
N,K,D = map(int, input().split())
dp = [0]*(N+1)
dp2 = [0]*(N+1)
dp[0] = 1
for i in range(N):
for j in range(1,K+1):
if i+j>N:break
if j<D:
dp[i+j]+=dp[i]
dp2[i+j]+=dp2[i]
else:
dp2[i+j]+=dp[i]
dp2[i+j]+=dp2[i]
print(dp2[-1])
```
| 0
|
|
909
|
A
|
Generate Login
|
PROGRAMMING
| 1,000
|
[
"brute force",
"greedy",
"sortings"
] | null | null |
The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person.
You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users).
As a reminder, a prefix of a string *s* is its substring which occurs at the beginning of *s*: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string *a* is alphabetically earlier than a string *b*, if *a* is a prefix of *b*, or *a* and *b* coincide up to some position, and then *a* has a letter that is alphabetically earlier than the corresponding letter in *b*: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac".
|
The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive.
|
Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well.
|
[
"harry potter\n",
"tom riddle\n"
] |
[
"hap\n",
"tomr\n"
] |
none
| 500
|
[
{
"input": "harry potter",
"output": "hap"
},
{
"input": "tom riddle",
"output": "tomr"
},
{
"input": "a qdpinbmcrf",
"output": "aq"
},
{
"input": "wixjzniiub ssdfodfgap",
"output": "wis"
},
{
"input": "z z",
"output": "zz"
},
{
"input": "ertuyivhfg v",
"output": "ertuv"
},
{
"input": "asdfghjkli ware",
"output": "asdfghjkliw"
},
{
"input": "udggmyop ze",
"output": "udggmyopz"
},
{
"input": "fapkdme rtzxovx",
"output": "fapkdmer"
},
{
"input": "mybiqxmnqq l",
"output": "ml"
},
{
"input": "dtbqya fyyymv",
"output": "df"
},
{
"input": "fyclu zokbxiahao",
"output": "fycluz"
},
{
"input": "qngatnviv rdych",
"output": "qngar"
},
{
"input": "ttvnhrnng lqkfulhrn",
"output": "tl"
},
{
"input": "fya fgx",
"output": "ff"
},
{
"input": "nuis zvjjqlre",
"output": "nuisz"
},
{
"input": "ly qtsmze",
"output": "lq"
},
{
"input": "d kgfpjsurfw",
"output": "dk"
},
{
"input": "lwli ewrpu",
"output": "le"
},
{
"input": "rr wldsfubcs",
"output": "rrw"
},
{
"input": "h qart",
"output": "hq"
},
{
"input": "vugvblnzx kqdwdulm",
"output": "vk"
},
{
"input": "xohesmku ef",
"output": "xe"
},
{
"input": "twvvsl wtcyawv",
"output": "tw"
},
{
"input": "obljndajv q",
"output": "obljndajq"
},
{
"input": "jjxwj kxccwx",
"output": "jjk"
},
{
"input": "sk fftzmv",
"output": "sf"
},
{
"input": "cgpegngs aufzxkyyrw",
"output": "ca"
},
{
"input": "reyjzjdvq skuch",
"output": "res"
},
{
"input": "ardaae mxgdulijf",
"output": "am"
},
{
"input": "bgopsdfji uaps",
"output": "bgopsdfjiu"
},
{
"input": "amolfed pun",
"output": "amolfedp"
},
{
"input": "badkiln yort",
"output": "badkilny"
},
{
"input": "aaaaaaaaaz york",
"output": "aaaaaaaaay"
},
{
"input": "bbbbcbbbbd c",
"output": "bbbbc"
},
{
"input": "aa ab",
"output": "aa"
},
{
"input": "ab b",
"output": "ab"
},
{
"input": "aaaaa ab",
"output": "aa"
},
{
"input": "aa a",
"output": "aa"
},
{
"input": "aba b",
"output": "ab"
},
{
"input": "aaaaaaa aaaaaa",
"output": "aa"
},
{
"input": "a a",
"output": "aa"
},
{
"input": "a aa",
"output": "aa"
},
{
"input": "a b",
"output": "ab"
},
{
"input": "b a",
"output": "ba"
},
{
"input": "z a",
"output": "za"
},
{
"input": "aaa a",
"output": "aa"
},
{
"input": "aa aa",
"output": "aa"
},
{
"input": "a aaa",
"output": "aa"
},
{
"input": "aaaaaaaaaa aaaaaaaaaa",
"output": "aa"
},
{
"input": "aaaaaaaaaa a",
"output": "aa"
},
{
"input": "a aaaaaaaaaa",
"output": "aa"
},
{
"input": "zzaa b",
"output": "zb"
},
{
"input": "ca cf",
"output": "cac"
},
{
"input": "abhi ia",
"output": "abhi"
},
{
"input": "aaaa aaaab",
"output": "aa"
},
{
"input": "aar raa",
"output": "aar"
},
{
"input": "harry hotter",
"output": "hah"
},
{
"input": "aaaaaaa a",
"output": "aa"
},
{
"input": "apple pie",
"output": "ap"
},
{
"input": "aaa aaa",
"output": "aa"
},
{
"input": "kabc buba",
"output": "kab"
},
{
"input": "asd ss",
"output": "as"
},
{
"input": "bbb b",
"output": "bb"
}
] | 1,633,958,796
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 23
| 78
| 6,758,400
|
p,n=map(str, input().split())
x=p[0]
for i in range(1,len(p)):
if p[i]<=n[0]:
x=x+p[i]
else:
break
x=x+n[0]
print(x)
|
Title: Generate Login
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person.
You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users).
As a reminder, a prefix of a string *s* is its substring which occurs at the beginning of *s*: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string *a* is alphabetically earlier than a string *b*, if *a* is a prefix of *b*, or *a* and *b* coincide up to some position, and then *a* has a letter that is alphabetically earlier than the corresponding letter in *b*: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac".
Input Specification:
The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive.
Output Specification:
Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well.
Demo Input:
['harry potter\n', 'tom riddle\n']
Demo Output:
['hap\n', 'tomr\n']
Note:
none
|
```python
p,n=map(str, input().split())
x=p[0]
for i in range(1,len(p)):
if p[i]<=n[0]:
x=x+p[i]
else:
break
x=x+n[0]
print(x)
```
| 0
|
|
935
|
A
|
Fafa and his Company
|
PROGRAMMING
| 800
|
[
"brute force",
"implementation"
] | null | null |
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader.
Given the number of employees *n*, find in how many ways Fafa could choose the number of team leaders *l* in such a way that it is possible to divide employees between them evenly.
|
The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company.
|
Print a single integer representing the answer to the problem.
|
[
"2\n",
"10\n"
] |
[
"1\n",
"3\n"
] |
In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them.
| 500
|
[
{
"input": "2",
"output": "1"
},
{
"input": "10",
"output": "3"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "6",
"output": "3"
},
{
"input": "13",
"output": "1"
},
{
"input": "100000",
"output": "35"
},
{
"input": "1024",
"output": "10"
},
{
"input": "99999",
"output": "11"
},
{
"input": "10007",
"output": "1"
},
{
"input": "4096",
"output": "12"
},
{
"input": "65536",
"output": "16"
},
{
"input": "40320",
"output": "95"
},
{
"input": "30030",
"output": "63"
},
{
"input": "161",
"output": "3"
},
{
"input": "1000",
"output": "15"
},
{
"input": "10000",
"output": "24"
},
{
"input": "777",
"output": "7"
},
{
"input": "121",
"output": "2"
},
{
"input": "25",
"output": "2"
},
{
"input": "40000",
"output": "34"
},
{
"input": "99990",
"output": "47"
},
{
"input": "98765",
"output": "3"
},
{
"input": "56789",
"output": "3"
},
{
"input": "13579",
"output": "3"
},
{
"input": "97531",
"output": "3"
},
{
"input": "12345",
"output": "7"
},
{
"input": "54321",
"output": "7"
},
{
"input": "83160",
"output": "127"
},
{
"input": "9",
"output": "2"
},
{
"input": "21",
"output": "3"
},
{
"input": "11",
"output": "1"
},
{
"input": "15",
"output": "3"
}
] | 1,679,724,961
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 33
| 62
| 0
|
import math
n = int(input())
c = 0
for i in range(1, n+1):
if (n-i >= i):
if ((n-i) % i == 0):
c += 1
print(c)
|
Title: Fafa and his Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader.
Given the number of employees *n*, find in how many ways Fafa could choose the number of team leaders *l* in such a way that it is possible to divide employees between them evenly.
Input Specification:
The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company.
Output Specification:
Print a single integer representing the answer to the problem.
Demo Input:
['2\n', '10\n']
Demo Output:
['1\n', '3\n']
Note:
In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them.
|
```python
import math
n = int(input())
c = 0
for i in range(1, n+1):
if (n-i >= i):
if ((n-i) % i == 0):
c += 1
print(c)
```
| 3
|
|
622
|
C
|
Not Equal on a Segment
|
PROGRAMMING
| 1,700
|
[
"data structures",
"implementation"
] | null | null |
You are given array *a* with *n* integers and *m* queries. The *i*-th query is given with three integers *l**i*,<=*r**i*,<=*x**i*.
For the *i*-th query find any position *p**i* (*l**i*<=≤<=*p**i*<=≤<=*r**i*) so that *a**p**i*<=≠<=*x**i*.
|
The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the number of elements in *a* and the number of queries.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106) — the elements of the array *a*.
Each of the next *m* lines contains three integers *l**i*,<=*r**i*,<=*x**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*,<=1<=≤<=*x**i*<=≤<=106) — the parameters of the *i*-th query.
|
Print *m* lines. On the *i*-th line print integer *p**i* — the position of any number not equal to *x**i* in segment [*l**i*,<=*r**i*] or the value <=-<=1 if there is no such number.
|
[
"6 4\n1 2 1 1 3 5\n1 4 1\n2 6 2\n3 4 1\n3 4 2\n"
] |
[
"2\n6\n-1\n4\n"
] |
none
| 0
|
[
{
"input": "6 4\n1 2 1 1 3 5\n1 4 1\n2 6 2\n3 4 1\n3 4 2",
"output": "2\n6\n-1\n4"
},
{
"input": "1 1\n1\n1 1 1",
"output": "-1"
},
{
"input": "1 1\n2\n1 1 2",
"output": "-1"
},
{
"input": "1 1\n569888\n1 1 967368",
"output": "1"
},
{
"input": "10 10\n1 1 1 1 1 1 1 1 1 1\n3 10 1\n3 6 1\n1 8 1\n1 7 1\n1 5 1\n3 7 1\n4 7 1\n9 9 1\n6 7 1\n3 4 1",
"output": "-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1"
},
{
"input": "10 10\n1 2 2 2 2 1 1 2 1 1\n3 3 1\n4 9 1\n4 8 1\n2 7 2\n2 8 2\n3 10 1\n7 7 2\n10 10 2\n1 5 1\n1 2 1",
"output": "3\n8\n8\n7\n7\n8\n7\n10\n5\n2"
},
{
"input": "10 10\n318890 307761 832732 700511 820583 522866 130891 914566 128429 739710\n4 9 178864\n6 9 741003\n4 9 172997\n4 6 314469\n1 4 694802\n8 8 401658\n7 10 376243\n7 8 508771\n3 5 30038\n2 10 591490",
"output": "9\n9\n9\n6\n4\n8\n10\n8\n5\n10"
},
{
"input": "1 1\n2\n1 1 1",
"output": "1"
},
{
"input": "10 10\n1 1 1 1 1 2 1 1 1 1\n1 9 1\n6 7 1\n2 4 1\n7 8 1\n1 3 1\n10 10 1\n3 5 1\n6 7 1\n1 10 1\n6 6 1",
"output": "6\n6\n-1\n-1\n-1\n-1\n-1\n6\n6\n6"
},
{
"input": "7 1\n2 1 3 2 2 2 2\n1 7 2",
"output": "3"
},
{
"input": "4 1\n3 1 2 2\n1 4 2",
"output": "2"
},
{
"input": "6 1\n3 2 4 3 3 3\n1 6 3",
"output": "3"
},
{
"input": "4 1\n1 3 2 2\n1 4 2",
"output": "2"
},
{
"input": "5 1\n2 3 1 2 2\n1 5 2",
"output": "3"
},
{
"input": "3 1\n1 9 5\n1 3 5",
"output": "2"
},
{
"input": "4 1\n4 2 6 4\n1 4 4",
"output": "3"
},
{
"input": "2 1\n1 3\n1 2 2",
"output": "2"
},
{
"input": "10 1\n2 2 1 3 2 2 2 2 2 2\n2 5 2",
"output": "4"
},
{
"input": "7 1\n6 5 7 6 6 6 6\n1 7 6",
"output": "3"
},
{
"input": "3 1\n2 4 3\n1 3 3",
"output": "2"
},
{
"input": "4 1\n4 2 3 3\n1 4 3",
"output": "2"
},
{
"input": "5 1\n3 2 4 5 5\n1 3 3",
"output": "3"
},
{
"input": "2 6\n1 1\n1 1 1\n1 1 2\n1 2 1\n1 2 2\n2 2 1\n2 2 2",
"output": "-1\n1\n-1\n2\n-1\n2"
}
] | 1,463,411,282
| 2,147,483,647
|
PyPy 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 13
| 1,000
| 32,665,600
|
i=input().split()
n,m=int(i[0]),int(i[1])
l=input().split()
for i in range(m):
j=input().split()
a,b,x=int(j[0]),int(j[1]),j[2]
if x==tuple(set(l[a-1:b]))[0] and len(set(l[a-1:b]))==1:
print(-1)
else:
for j in range(a-1,b)[::-1]:
if l[j]!=x:
print(j+1)
break
|
Title: Not Equal on a Segment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given array *a* with *n* integers and *m* queries. The *i*-th query is given with three integers *l**i*,<=*r**i*,<=*x**i*.
For the *i*-th query find any position *p**i* (*l**i*<=≤<=*p**i*<=≤<=*r**i*) so that *a**p**i*<=≠<=*x**i*.
Input Specification:
The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the number of elements in *a* and the number of queries.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106) — the elements of the array *a*.
Each of the next *m* lines contains three integers *l**i*,<=*r**i*,<=*x**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*,<=1<=≤<=*x**i*<=≤<=106) — the parameters of the *i*-th query.
Output Specification:
Print *m* lines. On the *i*-th line print integer *p**i* — the position of any number not equal to *x**i* in segment [*l**i*,<=*r**i*] or the value <=-<=1 if there is no such number.
Demo Input:
['6 4\n1 2 1 1 3 5\n1 4 1\n2 6 2\n3 4 1\n3 4 2\n']
Demo Output:
['2\n6\n-1\n4\n']
Note:
none
|
```python
i=input().split()
n,m=int(i[0]),int(i[1])
l=input().split()
for i in range(m):
j=input().split()
a,b,x=int(j[0]),int(j[1]),j[2]
if x==tuple(set(l[a-1:b]))[0] and len(set(l[a-1:b]))==1:
print(-1)
else:
for j in range(a-1,b)[::-1]:
if l[j]!=x:
print(j+1)
break
```
| 0
|
|
49
|
B
|
Sum
|
PROGRAMMING
| 1,500
|
[
"math"
] |
B. Sum
|
2
|
256
|
Vasya studies positional numeral systems. Unfortunately, he often forgets to write the base of notation in which the expression is written. Once he saw a note in his notebook saying *a*<=+<=*b*<==<=?, and that the base of the positional notation wasn’t written anywhere. Now Vasya has to choose a base *p* and regard the expression as written in the base *p* positional notation. Vasya understood that he can get different results with different bases, and some bases are even invalid. For example, expression 78<=+<=87 in the base 16 positional notation is equal to *FF*16, in the base 15 positional notation it is equal to 11015, in the base 10 one — to 16510, in the base 9 one — to 1769, and in the base 8 or lesser-based positional notations the expression is invalid as all the numbers should be strictly less than the positional notation base. Vasya got interested in what is the length of the longest possible expression value. Help him to find this length.
The length of a number should be understood as the number of numeric characters in it. For example, the length of the longest answer for 78<=+<=87<==<=? is 3. It is calculated like that in the base 15 (11015), base 10 (16510), base 9 (1769) positional notations, for example, and in some other ones.
|
The first letter contains two space-separated numbers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=1000) which represent the given summands.
|
Print a single number — the length of the longest answer.
|
[
"78 87\n",
"1 1\n"
] |
[
"3\n",
"2\n"
] |
none
| 1,000
|
[
{
"input": "78 87",
"output": "3"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "9 7",
"output": "2"
},
{
"input": "11 11",
"output": "3"
},
{
"input": "43 21",
"output": "3"
},
{
"input": "84 89",
"output": "3"
},
{
"input": "12 34",
"output": "3"
},
{
"input": "99 11",
"output": "3"
},
{
"input": "11 99",
"output": "3"
},
{
"input": "99 99",
"output": "3"
},
{
"input": "1 2",
"output": "2"
},
{
"input": "1 3",
"output": "2"
},
{
"input": "2 1",
"output": "2"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "3 1",
"output": "2"
},
{
"input": "3 2",
"output": "2"
},
{
"input": "3 3",
"output": "2"
},
{
"input": "1 466",
"output": "3"
},
{
"input": "1 1000",
"output": "4"
},
{
"input": "1 999",
"output": "4"
},
{
"input": "149 1",
"output": "3"
},
{
"input": "999 1",
"output": "4"
},
{
"input": "1000 1",
"output": "4"
},
{
"input": "998 998",
"output": "4"
},
{
"input": "998 999",
"output": "4"
},
{
"input": "998 1000",
"output": "4"
},
{
"input": "999 998",
"output": "4"
},
{
"input": "999 999",
"output": "4"
},
{
"input": "999 1000",
"output": "4"
},
{
"input": "1000 998",
"output": "4"
},
{
"input": "1000 999",
"output": "4"
},
{
"input": "1000 1000",
"output": "5"
},
{
"input": "1000 539",
"output": "4"
},
{
"input": "999 619",
"output": "4"
},
{
"input": "2 511",
"output": "3"
},
{
"input": "877 2",
"output": "3"
},
{
"input": "379 999",
"output": "4"
},
{
"input": "247 1000",
"output": "4"
},
{
"input": "555 555",
"output": "4"
},
{
"input": "208 997",
"output": "4"
},
{
"input": "633 581",
"output": "4"
},
{
"input": "411 517",
"output": "4"
},
{
"input": "836 101",
"output": "4"
},
{
"input": "262 685",
"output": "4"
},
{
"input": "39 269",
"output": "3"
},
{
"input": "464 205",
"output": "4"
},
{
"input": "890 789",
"output": "4"
},
{
"input": "667 373",
"output": "4"
},
{
"input": "840 975",
"output": "4"
},
{
"input": "810 413",
"output": "4"
},
{
"input": "133 851",
"output": "4"
},
{
"input": "104 938",
"output": "4"
},
{
"input": "427 376",
"output": "4"
},
{
"input": "398 815",
"output": "4"
},
{
"input": "721 253",
"output": "4"
},
{
"input": "692 339",
"output": "4"
},
{
"input": "15 778",
"output": "3"
},
{
"input": "986 216",
"output": "4"
},
{
"input": "450 277",
"output": "3"
},
{
"input": "333 1",
"output": "4"
},
{
"input": "499 499",
"output": "3"
},
{
"input": "79 1",
"output": "2"
},
{
"input": "87 1",
"output": "2"
},
{
"input": "47 8",
"output": "2"
},
{
"input": "87 8",
"output": "3"
},
{
"input": "1 11",
"output": "3"
}
] | 1,563,395,235
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 20
| 248
| 0
|
from math import log, floor
a, b = input().rstrip().split()
for i in reversed(range(1, 10)):
if str(i) in a+b:
print(floor(
log(int(a, i + 1) + int(b, i + 1), i + 1)
)+1)
break
|
Title: Sum
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya studies positional numeral systems. Unfortunately, he often forgets to write the base of notation in which the expression is written. Once he saw a note in his notebook saying *a*<=+<=*b*<==<=?, and that the base of the positional notation wasn’t written anywhere. Now Vasya has to choose a base *p* and regard the expression as written in the base *p* positional notation. Vasya understood that he can get different results with different bases, and some bases are even invalid. For example, expression 78<=+<=87 in the base 16 positional notation is equal to *FF*16, in the base 15 positional notation it is equal to 11015, in the base 10 one — to 16510, in the base 9 one — to 1769, and in the base 8 or lesser-based positional notations the expression is invalid as all the numbers should be strictly less than the positional notation base. Vasya got interested in what is the length of the longest possible expression value. Help him to find this length.
The length of a number should be understood as the number of numeric characters in it. For example, the length of the longest answer for 78<=+<=87<==<=? is 3. It is calculated like that in the base 15 (11015), base 10 (16510), base 9 (1769) positional notations, for example, and in some other ones.
Input Specification:
The first letter contains two space-separated numbers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=1000) which represent the given summands.
Output Specification:
Print a single number — the length of the longest answer.
Demo Input:
['78 87\n', '1 1\n']
Demo Output:
['3\n', '2\n']
Note:
none
|
```python
from math import log, floor
a, b = input().rstrip().split()
for i in reversed(range(1, 10)):
if str(i) in a+b:
print(floor(
log(int(a, i + 1) + int(b, i + 1), i + 1)
)+1)
break
```
| 0
|
168
|
A
|
Wizards and Demonstration
|
PROGRAMMING
| 900
|
[
"implementation",
"math"
] | null | null |
Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least *y* percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration.
So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only *n* people and not containing any clone puppets.
Help the wizards and find the minimum number of clones to create to that the demonstration had no less than *y* percent of the city people.
|
The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly.
Please note that *y* can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city (<=><=*n*).
|
Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population).
|
[
"10 1 14\n",
"20 10 50\n",
"1000 352 146\n"
] |
[
"1\n",
"0\n",
"1108\n"
] |
In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone.
In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones.
| 500
|
[
{
"input": "10 1 14",
"output": "1"
},
{
"input": "20 10 50",
"output": "0"
},
{
"input": "1000 352 146",
"output": "1108"
},
{
"input": "68 65 20",
"output": "0"
},
{
"input": "78 28 27",
"output": "0"
},
{
"input": "78 73 58",
"output": "0"
},
{
"input": "70 38 66",
"output": "9"
},
{
"input": "54 4 38",
"output": "17"
},
{
"input": "3 1 69",
"output": "2"
},
{
"input": "11 9 60",
"output": "0"
},
{
"input": "71 49 65",
"output": "0"
},
{
"input": "78 55 96",
"output": "20"
},
{
"input": "2765 768 9020",
"output": "248635"
},
{
"input": "3478 1728 9727",
"output": "336578"
},
{
"input": "9678 6173 5658",
"output": "541409"
},
{
"input": "1138 570 6666",
"output": "75290"
},
{
"input": "7754 204 9038",
"output": "700603"
},
{
"input": "8403 7401 4769",
"output": "393339"
},
{
"input": "4909 2111 8860",
"output": "432827"
},
{
"input": "6571 6449 8965",
"output": "582642"
},
{
"input": "9178 2255 7996",
"output": "731618"
},
{
"input": "6151 6148 3746",
"output": "224269"
},
{
"input": "8890 5449 8734",
"output": "771004"
},
{
"input": "7879 2590 2818",
"output": "219441"
},
{
"input": "8484 6400 547",
"output": "40008"
},
{
"input": "7835 6710 1639",
"output": "121706"
},
{
"input": "2379 1436 9663",
"output": "228447"
},
{
"input": "6487 5670 8",
"output": "0"
},
{
"input": "4470 2543 6",
"output": "0"
},
{
"input": "7261 5328 10",
"output": "0"
},
{
"input": "3871 3795 7",
"output": "0"
},
{
"input": "9620 6557 6",
"output": "0"
},
{
"input": "4890 1112 5",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 1 10000",
"output": "99"
},
{
"input": "10000 1 1",
"output": "99"
},
{
"input": "10000 1 10000",
"output": "999999"
},
{
"input": "10000 10000 1",
"output": "0"
},
{
"input": "10000 10000 10000",
"output": "990000"
},
{
"input": "67 1 3",
"output": "2"
},
{
"input": "7878 4534 9159",
"output": "717013"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "3271 5 50",
"output": "1631"
}
] | 1,624,119,056
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 43
| 154
| 0
|
import math
n,x,y=map(int,input().split())
k=math.ceil(y*n/100)
if k>x:
print(k-x)
else:
print(0)
|
Title: Wizards and Demonstration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least *y* percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration.
So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only *n* people and not containing any clone puppets.
Help the wizards and find the minimum number of clones to create to that the demonstration had no less than *y* percent of the city people.
Input Specification:
The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly.
Please note that *y* can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city (<=><=*n*).
Output Specification:
Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population).
Demo Input:
['10 1 14\n', '20 10 50\n', '1000 352 146\n']
Demo Output:
['1\n', '0\n', '1108\n']
Note:
In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone.
In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones.
|
```python
import math
n,x,y=map(int,input().split())
k=math.ceil(y*n/100)
if k>x:
print(k-x)
else:
print(0)
```
| 3
|
|
219
|
A
|
k-String
|
PROGRAMMING
| 1,000
|
[
"implementation",
"strings"
] | null | null |
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string *s*, consisting of lowercase English letters and a positive integer *k*. Your task is to reorder the letters in the string *s* in such a way that the resulting string is a *k*-string.
|
The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*.
|
Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes).
|
[
"2\naazz\n",
"3\nabcabcabz\n"
] |
[
"azaz\n",
"-1\n"
] |
none
| 500
|
[
{
"input": "2\naazz",
"output": "azaz"
},
{
"input": "3\nabcabcabz",
"output": "-1"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "2\nabba",
"output": "abab"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "7\nabacaba",
"output": "-1"
},
{
"input": "5\naaaaa",
"output": "aaaaa"
},
{
"input": "3\naabaaaaabb",
"output": "-1"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "2\nbabac",
"output": "-1"
},
{
"input": "3\nbbbccc",
"output": "bcbcbc"
},
{
"input": "2\naa",
"output": "aa"
},
{
"input": "250\ncececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececece",
"output": "cececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececece"
},
{
"input": "15\nabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaa",
"output": "aaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbc"
},
{
"input": "1\naaa",
"output": "aaa"
},
{
"input": "1\naabaab",
"output": "aaaabb"
},
{
"input": "2\naabbbbccccccdddddddd",
"output": "abbcccddddabbcccdddd"
},
{
"input": "3\naaaaaaaaacccdddddd",
"output": "aaacddaaacddaaacdd"
},
{
"input": "3\naaaaaaaaacccbbbbbb",
"output": "aaabbcaaabbcaaabbc"
},
{
"input": "2\naazzzz",
"output": "azzazz"
},
{
"input": "2\naaaa",
"output": "aaaa"
},
{
"input": "2\naaaazz",
"output": "aazaaz"
},
{
"input": "2\naaaabb",
"output": "aabaab"
},
{
"input": "2\naabbbb",
"output": "abbabb"
},
{
"input": "2\naaaazzzz",
"output": "aazzaazz"
},
{
"input": "2\naaazz",
"output": "-1"
},
{
"input": "2\nbbbbaa",
"output": "abbabb"
},
{
"input": "2\naaaaaabbbb",
"output": "aaabbaaabb"
},
{
"input": "2\naaaaaazz",
"output": "aaazaaaz"
},
{
"input": "2\naaaabbbb",
"output": "aabbaabb"
},
{
"input": "2\naabaab",
"output": "aabaab"
},
{
"input": "1\naaaaa",
"output": "aaaaa"
},
{
"input": "2\nbbaaaa",
"output": "aabaab"
},
{
"input": "2\nacaccc",
"output": "accacc"
}
] | 1,644,722,440
| 2,147,483,647
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 9
| 154
| 307,200
|
def solve(k, s):
from collections import Counter
d = Counter(s)
for i in d:
if d[i]==k:
continue
else:
return -1
ans = ""
while k:
for i in d:
if d[i]>0:
ans+=i
d[i]-=1
k-=1
return ans
k = int(input())
s = input()
print(solve(k,s))
|
Title: k-String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string *s*, consisting of lowercase English letters and a positive integer *k*. Your task is to reorder the letters in the string *s* in such a way that the resulting string is a *k*-string.
Input Specification:
The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*.
Output Specification:
Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes).
Demo Input:
['2\naazz\n', '3\nabcabcabz\n']
Demo Output:
['azaz\n', '-1\n']
Note:
none
|
```python
def solve(k, s):
from collections import Counter
d = Counter(s)
for i in d:
if d[i]==k:
continue
else:
return -1
ans = ""
while k:
for i in d:
if d[i]>0:
ans+=i
d[i]-=1
k-=1
return ans
k = int(input())
s = input()
print(solve(k,s))
```
| 0
|
|
263
|
A
|
Beautiful Matrix
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=<<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=<<=5).
You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful.
|
The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.
|
Print a single integer — the minimum number of moves needed to make the matrix beautiful.
|
[
"0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n"
] |
[
"3\n",
"1\n"
] |
none
| 500
|
[
{
"input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1",
"output": "4"
},
{
"input": "0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "4"
},
{
"input": "0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "4"
},
{
"input": "0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0",
"output": "4"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0",
"output": "3"
}
] | 1,696,744,820
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 1
| 92
| 0
|
mat = []
res = 0
for _ in range(5):
mat.append(list(map(int, input().split())))
for i in range(5):
for j in range(5):
if mat[i][j] == 1:
res = abs(3 - i) + abs(3 - j)
print(res)
|
Title: Beautiful Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=<<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=<<=5).
You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful.
Input Specification:
The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.
Output Specification:
Print a single integer — the minimum number of moves needed to make the matrix beautiful.
Demo Input:
['0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n', '0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n']
Demo Output:
['3\n', '1\n']
Note:
none
|
```python
mat = []
res = 0
for _ in range(5):
mat.append(list(map(int, input().split())))
for i in range(5):
for j in range(5):
if mat[i][j] == 1:
res = abs(3 - i) + abs(3 - j)
print(res)
```
| 0
|
|
102
|
B
|
Sum of Digits
|
PROGRAMMING
| 1,000
|
[
"implementation"
] |
B. Sum of Digits
|
2
|
265
|
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit?
|
The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes.
|
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
|
[
"0\n",
"10\n",
"991\n"
] |
[
"0\n",
"1\n",
"3\n"
] |
In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
| 1,000
|
[
{
"input": "0",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "991",
"output": "3"
},
{
"input": "99",
"output": "2"
},
{
"input": "100",
"output": "1"
},
{
"input": "123456789",
"output": "2"
},
{
"input": "32",
"output": "1"
},
{
"input": "86",
"output": "2"
},
{
"input": "2",
"output": "0"
},
{
"input": "8",
"output": "0"
},
{
"input": "34",
"output": "1"
},
{
"input": "13",
"output": "1"
},
{
"input": "28",
"output": "2"
},
{
"input": "23",
"output": "1"
},
{
"input": "57",
"output": "2"
},
{
"input": "29",
"output": "2"
},
{
"input": "353869285",
"output": "3"
},
{
"input": "549548646",
"output": "2"
},
{
"input": "858893424",
"output": "2"
},
{
"input": "644818852",
"output": "3"
},
{
"input": "360322525",
"output": "3"
},
{
"input": "122937520",
"output": "2"
},
{
"input": "288403032",
"output": "2"
},
{
"input": "677257481",
"output": "3"
},
{
"input": "58059561",
"output": "3"
},
{
"input": "211288847",
"output": "2"
},
{
"input": "339900034079539584",
"output": "2"
},
{
"input": "784084029310269952",
"output": "3"
},
{
"input": "774730557264864000",
"output": "3"
},
{
"input": "478233807148352256",
"output": "3"
},
{
"input": "165646874056812544",
"output": "3"
},
{
"input": "477533739511673792",
"output": "3"
},
{
"input": "660119944377002240",
"output": "3"
},
{
"input": "448375218506078080",
"output": "3"
},
{
"input": "77213334785795616",
"output": "3"
},
{
"input": "165767221702271872",
"output": "3"
},
{
"input": "1",
"output": "0"
},
{
"input": "5",
"output": "0"
},
{
"input": "8",
"output": "0"
},
{
"input": "156161456146164104103460452045416165146141414651641564105461465156445621465146514562146145465165145145614561465145614561",
"output": "3"
},
{
"input": "9",
"output": "0"
}
] | 1,595,762,504
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 51
| 310
| 22,118,400
|
n=input()
k=0
while (len(n)!=1):
s=0
for i in n:
s+=int(i)
n=str(s)
k+=1
print(k)
|
Title: Sum of Digits
Time Limit: 2 seconds
Memory Limit: 265 megabytes
Problem Description:
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit?
Input Specification:
The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes.
Output Specification:
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
Demo Input:
['0\n', '10\n', '991\n']
Demo Output:
['0\n', '1\n', '3\n']
Note:
In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
|
```python
n=input()
k=0
while (len(n)!=1):
s=0
for i in n:
s+=int(i)
n=str(s)
k+=1
print(k)
```
| 3.8827
|
1
|
A
|
Theatre Square
|
PROGRAMMING
| 1,000
|
[
"math"
] |
A. Theatre Square
|
1
|
256
|
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
|
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
|
Write the needed number of flagstones.
|
[
"6 6 4\n"
] |
[
"4\n"
] |
none
| 0
|
[
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,656,357,161
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 20
| 61
| 4,300,800
|
n,m,a = map(int, input().split())
if n % a > 0:
b = n//a + 1
else:
b = n//a
if m % a > 0:
c = m//a + 1
else:
c = m//a
print(b*c)
|
Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input Specification:
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Output Specification:
Write the needed number of flagstones.
Demo Input:
['6 6 4\n']
Demo Output:
['4\n']
Note:
none
|
```python
n,m,a = map(int, input().split())
if n % a > 0:
b = n//a + 1
else:
b = n//a
if m % a > 0:
c = m//a + 1
else:
c = m//a
print(b*c)
```
| 3.961489
|
0
|
none
|
none
|
none
| 0
|
[
"none"
] | null | null |
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number *i* got a score of *a**i*. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question.
|
The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants
|
Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
|
[
"1 3 2 1 2 1\n",
"1 1 1 1 1 99\n"
] |
[
"YES\n",
"NO\n"
] |
In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater.
| 0
|
[
{
"input": "1 3 2 1 2 1",
"output": "YES"
},
{
"input": "1 1 1 1 1 99",
"output": "NO"
},
{
"input": "1000 1000 1000 1000 1000 1000",
"output": "YES"
},
{
"input": "0 0 0 0 0 0",
"output": "YES"
},
{
"input": "633 609 369 704 573 416",
"output": "NO"
},
{
"input": "353 313 327 470 597 31",
"output": "NO"
},
{
"input": "835 638 673 624 232 266",
"output": "NO"
},
{
"input": "936 342 19 398 247 874",
"output": "NO"
},
{
"input": "417 666 978 553 271 488",
"output": "NO"
},
{
"input": "71 66 124 199 67 147",
"output": "YES"
},
{
"input": "54 26 0 171 239 12",
"output": "YES"
},
{
"input": "72 8 186 92 267 69",
"output": "YES"
},
{
"input": "180 179 188 50 75 214",
"output": "YES"
},
{
"input": "16 169 110 136 404 277",
"output": "YES"
},
{
"input": "101 400 9 200 300 10",
"output": "YES"
},
{
"input": "101 400 200 9 300 10",
"output": "YES"
},
{
"input": "101 200 400 9 300 10",
"output": "YES"
},
{
"input": "101 400 200 300 9 10",
"output": "YES"
},
{
"input": "101 200 400 300 9 10",
"output": "YES"
},
{
"input": "4 4 4 4 5 4",
"output": "NO"
},
{
"input": "2 2 2 2 2 1",
"output": "NO"
},
{
"input": "1000 1000 999 1000 1000 1000",
"output": "NO"
},
{
"input": "129 1 10 29 8 111",
"output": "NO"
},
{
"input": "1000 1000 1000 999 999 1000",
"output": "YES"
},
{
"input": "101 200 300 400 9 10",
"output": "YES"
},
{
"input": "101 400 200 300 10 9",
"output": "YES"
},
{
"input": "101 200 400 300 10 9",
"output": "YES"
},
{
"input": "101 200 300 400 10 9",
"output": "YES"
},
{
"input": "101 200 300 10 400 9",
"output": "YES"
},
{
"input": "1 1 1 1 1 5",
"output": "NO"
},
{
"input": "8 1 1 3 3 0",
"output": "NO"
},
{
"input": "1 1 2 2 3 3",
"output": "YES"
},
{
"input": "1 2 2 5 2 5",
"output": "NO"
},
{
"input": "1 2 3 6 6 6",
"output": "NO"
},
{
"input": "36 91 7 86 51 89",
"output": "NO"
},
{
"input": "10 1 1 1 23 24",
"output": "NO"
},
{
"input": "1 1 1 10 23 24",
"output": "NO"
},
{
"input": "20 10 1 2 3 44",
"output": "NO"
},
{
"input": "7 0 14 11 8 6",
"output": "NO"
},
{
"input": "100 496 1 1 1 1",
"output": "NO"
},
{
"input": "5 4 2 5 11 3",
"output": "NO"
},
{
"input": "1 3 7 8 8 9",
"output": "YES"
},
{
"input": "1 3 4 5 18 19",
"output": "YES"
},
{
"input": "5 5 1 2 2 15",
"output": "NO"
},
{
"input": "2 1 0 0 0 5",
"output": "NO"
},
{
"input": "1 6 6 1 20 2",
"output": "NO"
},
{
"input": "2 10 0 0 0 0",
"output": "NO"
},
{
"input": "1 1 3 1 1 11",
"output": "NO"
},
{
"input": "10 10 1 1 1 37",
"output": "NO"
},
{
"input": "1 1 0 0 0 4",
"output": "NO"
},
{
"input": "1 1 10 1 1 28",
"output": "NO"
},
{
"input": "1 5 5 5 6 8",
"output": "YES"
},
{
"input": "0 2 3 4 4 5",
"output": "YES"
}
] | 1,667,227,294
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 53
| 78
| 0
|
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
a = list(map(int, input().split()))
s = sum(a)
ans = "NO"
for i in range(6):
for j in range(i + 1, 6):
for k in range(j + 1, 6):
if 2 * (a[i] + a[j] + a[k]) == s:
ans = "YES"
print(ans)
|
Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number *i* got a score of *a**i*. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question.
Input Specification:
The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants
Output Specification:
Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
Demo Input:
['1 3 2 1 2 1\n', '1 1 1 1 1 99\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater.
|
```python
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
a = list(map(int, input().split()))
s = sum(a)
ans = "NO"
for i in range(6):
for j in range(i + 1, 6):
for k in range(j + 1, 6):
if 2 * (a[i] + a[j] + a[k]) == s:
ans = "YES"
print(ans)
```
| 3
|
|
408
|
A
|
Line to Cashier
|
PROGRAMMING
| 900
|
[
"implementation"
] | null | null |
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has *k**i* people. The *j*-th person standing in the queue to the *i*-th cashier has *m**i*,<=*j* items in the basket. Vasya knows that:
- the cashier needs 5 seconds to scan one item; - after the cashier scans each item of some customer, he needs 15 seconds to take the customer's money and give him the change.
Of course, Vasya wants to select a queue so that he can leave the supermarket as soon as possible. Help him write a program that displays the minimum number of seconds after which Vasya can get to one of the cashiers.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=≤<=*k**i*<=≤<=100), where *k**i* is the number of people in the queue to the *i*-th cashier.
The *i*-th of the next *n* lines contains *k**i* space-separated integers: *m**i*,<=1,<=*m**i*,<=2,<=...,<=*m**i*,<=*k**i* (1<=≤<=*m**i*,<=*j*<=≤<=100) — the number of products the *j*-th person in the queue for the *i*-th cash has.
|
Print a single integer — the minimum number of seconds Vasya needs to get to the cashier.
|
[
"1\n1\n1\n",
"4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n"
] |
[
"20\n",
"100\n"
] |
In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fourth one. Thus, Vasya gets to the cashier quicker if he chooses the second or the third queue.
| 500
|
[
{
"input": "1\n1\n1",
"output": "20"
},
{
"input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8",
"output": "100"
},
{
"input": "4\n5 4 5 5\n3 1 3 1 2\n3 1 1 3\n1 1 1 2 2\n2 2 1 1 3",
"output": "100"
},
{
"input": "5\n5 3 6 6 4\n7 5 3 3 9\n6 8 2\n1 10 8 5 9 2\n9 7 8 5 9 10\n9 8 3 3",
"output": "125"
},
{
"input": "5\n10 10 10 10 10\n6 7 8 6 8 5 9 8 10 5\n9 6 9 8 7 8 8 10 8 5\n8 7 7 8 7 5 6 8 9 5\n6 5 10 5 5 10 7 8 5 5\n10 9 8 7 6 9 7 9 6 5",
"output": "480"
},
{
"input": "10\n9 10 10 10 9 5 9 7 8 7\n11 6 10 4 4 15 7 15 5\n3 9 11 12 11 1 13 13 1 5\n6 15 9 12 3 2 8 12 11 10\n7 1 1 6 10 2 6 1 14 2\n8 14 2 3 6 1 14 1 12\n6 10 9 3 5\n13 12 12 7 13 4 4 8 10\n5 6 4 3 14 9 13\n8 12 1 5 7 4 13 1\n1 9 5 3 5 1 4",
"output": "240"
},
{
"input": "10\n5 5 5 5 5 5 5 5 5 5\n5 5 4 5 4\n6 5 7 7 6\n5 4 4 5 5\n4 4 5 5 5\n7 6 4 5 7\n4 6 5 4 5\n6 6 7 6 6\n4 5 4 4 7\n7 5 4 4 5\n6 6 7 4 4",
"output": "190"
},
{
"input": "1\n1\n100",
"output": "515"
},
{
"input": "1\n90\n90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90",
"output": "41850"
}
] | 1,396,364,715
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 46
| 0
|
qNumbers = int(input())
k = list(map(int, raw_input().split()))
minScnds = k[0] * 15
itms = list(map(int, raw_input().split()))
for i in range(k[0]):
minScnds += itms[i] * 5
for i in range(1, qNumbers):
scnds = k[i] * 15
itms = list(map(int, raw_input().split()))
for j in range(k[i]):
scnds += itms[j] * 5
minScnds = min(scnds, minScnds)
print (minScnds)
|
Title: Line to Cashier
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has *k**i* people. The *j*-th person standing in the queue to the *i*-th cashier has *m**i*,<=*j* items in the basket. Vasya knows that:
- the cashier needs 5 seconds to scan one item; - after the cashier scans each item of some customer, he needs 15 seconds to take the customer's money and give him the change.
Of course, Vasya wants to select a queue so that he can leave the supermarket as soon as possible. Help him write a program that displays the minimum number of seconds after which Vasya can get to one of the cashiers.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=≤<=*k**i*<=≤<=100), where *k**i* is the number of people in the queue to the *i*-th cashier.
The *i*-th of the next *n* lines contains *k**i* space-separated integers: *m**i*,<=1,<=*m**i*,<=2,<=...,<=*m**i*,<=*k**i* (1<=≤<=*m**i*,<=*j*<=≤<=100) — the number of products the *j*-th person in the queue for the *i*-th cash has.
Output Specification:
Print a single integer — the minimum number of seconds Vasya needs to get to the cashier.
Demo Input:
['1\n1\n1\n', '4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n']
Demo Output:
['20\n', '100\n']
Note:
In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fourth one. Thus, Vasya gets to the cashier quicker if he chooses the second or the third queue.
|
```python
qNumbers = int(input())
k = list(map(int, raw_input().split()))
minScnds = k[0] * 15
itms = list(map(int, raw_input().split()))
for i in range(k[0]):
minScnds += itms[i] * 5
for i in range(1, qNumbers):
scnds = k[i] * 15
itms = list(map(int, raw_input().split()))
for j in range(k[i]):
scnds += itms[j] * 5
minScnds = min(scnds, minScnds)
print (minScnds)
```
| -1
|
|
61
|
A
|
Ultra-Fast Mathematician
|
PROGRAMMING
| 800
|
[
"implementation"
] |
A. Ultra-Fast Mathematician
|
2
|
256
|
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
|
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
|
Write one line — the corresponding answer. Do not omit the leading 0s.
|
[
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] |
[
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] |
none
| 500
|
[
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "10\n01",
"output": "11"
},
{
"input": "00111111\n11011101",
"output": "11100010"
},
{
"input": "011001100\n101001010",
"output": "110000110"
},
{
"input": "1100100001\n0110101100",
"output": "1010001101"
},
{
"input": "00011101010\n10010100101",
"output": "10001001111"
},
{
"input": "100000101101\n111010100011",
"output": "011010001110"
},
{
"input": "1000001111010\n1101100110001",
"output": "0101101001011"
},
{
"input": "01011111010111\n10001110111010",
"output": "11010001101101"
},
{
"input": "110010000111100\n001100101011010",
"output": "111110101100110"
},
{
"input": "0010010111110000\n0000000011010110",
"output": "0010010100100110"
},
{
"input": "00111110111110000\n01111100001100000",
"output": "01000010110010000"
},
{
"input": "101010101111010001\n001001111101111101",
"output": "100011010010101100"
},
{
"input": "0110010101111100000\n0011000101000000110",
"output": "0101010000111100110"
},
{
"input": "11110100011101010111\n00001000011011000000",
"output": "11111100000110010111"
},
{
"input": "101010101111101101001\n111010010010000011111",
"output": "010000111101101110110"
},
{
"input": "0000111111100011000010\n1110110110110000001010",
"output": "1110001001010011001000"
},
{
"input": "10010010101000110111000\n00101110100110111000111",
"output": "10111100001110001111111"
},
{
"input": "010010010010111100000111\n100100111111100011001110",
"output": "110110101101011111001001"
},
{
"input": "0101110100100111011010010\n0101100011010111001010001",
"output": "0000010111110000010000011"
},
{
"input": "10010010100011110111111011\n10000110101100000001000100",
"output": "00010100001111110110111111"
},
{
"input": "000001111000000100001000000\n011100111101111001110110001",
"output": "011101000101111101111110001"
},
{
"input": "0011110010001001011001011100\n0000101101000011101011001010",
"output": "0011011111001010110010010110"
},
{
"input": "11111000000000010011001101111\n11101110011001010100010000000",
"output": "00010110011001000111011101111"
},
{
"input": "011001110000110100001100101100\n001010000011110000001000101001",
"output": "010011110011000100000100000101"
},
{
"input": "1011111010001100011010110101111\n1011001110010000000101100010101",
"output": "0000110100011100011111010111010"
},
{
"input": "10111000100001000001010110000001\n10111000001100101011011001011000",
"output": "00000000101101101010001111011001"
},
{
"input": "000001010000100001000000011011100\n111111111001010100100001100000111",
"output": "111110101001110101100001111011011"
},
{
"input": "1101000000000010011011101100000110\n1110000001100010011010000011011110",
"output": "0011000001100000000001101111011000"
},
{
"input": "01011011000010100001100100011110001\n01011010111000001010010100001110000",
"output": "00000001111010101011110000010000001"
},
{
"input": "000011111000011001000110111100000100\n011011000110000111101011100111000111",
"output": "011000111110011110101101011011000011"
},
{
"input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000",
"output": "1011001001111001001011101010101000010"
},
{
"input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011",
"output": "10001110000010101110000111000011111110"
},
{
"input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100",
"output": "000100001011110000011101110111010001110"
},
{
"input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001",
"output": "1101110101010110000011000000101011110011"
},
{
"input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100",
"output": "11001011110010010000010111001100001001110"
},
{
"input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110",
"output": "001100101000011111111101111011101010111001"
},
{
"input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001",
"output": "0111010010100110110101100010000100010100000"
},
{
"input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100",
"output": "11111110000000100101000100110111001100011001"
},
{
"input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011",
"output": "101011011100100010100011011001101010100100010"
},
{
"input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001",
"output": "1101001100111011010111110110101111001011110111"
},
{
"input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001",
"output": "10010101000101000000011010011110011110011110001"
},
{
"input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100",
"output": "011011011100000000010101110010000000101000111101"
},
{
"input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100",
"output": "0101010111101001011011110110011101010101010100011"
},
{
"input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011",
"output": "11001011010010111000010110011101100100001110111111"
},
{
"input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011",
"output": "111011101010011100001111101001101011110010010110001"
},
{
"input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001",
"output": "0100111110110011111110010010010000110111100101101101"
},
{
"input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100",
"output": "01011001110111010111001100010011010100010000111011000"
},
{
"input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111",
"output": "100011101001001000011011011001111000100000010100100100"
},
{
"input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110",
"output": "1100110010000101101010111111101001001001110101110010110"
},
{
"input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110",
"output": "01000111100111001011110010100011111111110010101100001101"
},
{
"input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010",
"output": "110001010001000011000101110101000100001011111001011001001"
},
{
"input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111",
"output": "1110100010111000101001001011101110011111100111000011011011"
},
{
"input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110",
"output": "01110110101110100100110011010000001000101100101111000111011"
},
{
"input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011",
"output": "111100101000000011101011011001110010101111000110010010000000"
},
{
"input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111",
"output": "0100100010111110010011101010000011111110001110010110010111001"
},
{
"input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111",
"output": "00110100000011001101101100100010110010001100000001100110011101"
},
{
"input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011",
"output": "000000011000111011110011101000010000010100101000000011010110010"
},
{
"input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010",
"output": "0010100110110100111100100100101101010100100111011010001001010101"
},
{
"input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111",
"output": "11010110111100101111101001100001110100010110010110110111100110100"
},
{
"input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111",
"output": "111111010011011100101110100110111111111001111110011010111111110000"
},
{
"input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110",
"output": "1010101010100010001001001001100000111000010010010100010011000100000"
},
{
"input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000",
"output": "00011111011111001000011100010011100011010100101011011000001001111110"
},
{
"input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111",
"output": "001111000011001110100111010101111111011100110011001010010010000111011"
},
{
"input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101",
"output": "0110001100110100010000110111000010011010011000011001010011010100010100"
},
{
"input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010",
"output": "00010000000110110101000011001000000100100110111010011111101010001010000"
},
{
"input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001",
"output": "000100100000000110011100100001010110101001100101110010010011111001110111"
},
{
"input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000",
"output": "1000111100010011010110011101000000101010101100011111100001101111001010010"
},
{
"input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011",
"output": "01000010011110111001011011110000001011000111101101101010010110001010100100"
},
{
"input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101",
"output": "101101110110110010011100001011111100100001110000101100110000100011011100110"
},
{
"input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001",
"output": "1110111111110010111000001100101010101011010100101010100101100011001001111111"
},
{
"input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111",
"output": "10111011000111000101110100101000100111011011100011110110000101010001111010111"
},
{
"input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110",
"output": "110100100110000101010010011010011001100110000111010000010100001011110111111101"
},
{
"input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111",
"output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111"
},
{
"input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001",
"output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001"
},
{
"input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110",
"output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011"
},
{
"input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111",
"output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101"
},
{
"input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010",
"output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101"
},
{
"input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000",
"output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001"
},
{
"input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011",
"output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110"
},
{
"input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011",
"output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011"
},
{
"input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011",
"output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011"
},
{
"input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010",
"output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011"
},
{
"input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001",
"output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110"
},
{
"input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111",
"output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010"
},
{
"input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011",
"output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011"
},
{
"input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100",
"output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000"
},
{
"input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001",
"output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101"
},
{
"input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110",
"output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101"
},
{
"input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011",
"output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110"
},
{
"input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111",
"output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110"
},
{
"input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000",
"output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001"
},
{
"input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010",
"output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101"
},
{
"input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101",
"output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011"
},
{
"input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011",
"output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010",
"output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "0\n1",
"output": "1"
}
] | 1,589,006,908
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 102
| 124
| 6,656,000
|
import sys
input = sys.stdin.readline
def insr():
return input()[:-1:]
def solve(a, b):
l = len(a)
res = ""
for c in range(l):
res += str(int(a[c]) ^ int(b[c]))
return res
if __name__ == '__main__':
a = insr()
b = insr()
print(solve(a,b))
|
Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
Input Specification:
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Output Specification:
Write one line — the corresponding answer. Do not omit the leading 0s.
Demo Input:
['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n']
Demo Output:
['1110001\n', '111\n', '0100\n', '00010\n']
Note:
none
|
```python
import sys
input = sys.stdin.readline
def insr():
return input()[:-1:]
def solve(a, b):
l = len(a)
res = ""
for c in range(l):
res += str(int(a[c]) ^ int(b[c]))
return res
if __name__ == '__main__':
a = insr()
b = insr()
print(solve(a,b))
```
| 3.956602
|
599
|
A
|
Patrick and Shopping
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of length *d*3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house.
Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled.
|
The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length of the path connecting both shops.
|
Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house.
|
[
"10 20 30\n",
"1 1 5\n"
] |
[
"60\n",
"4\n"
] |
The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
In the second sample one of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
| 500
|
[
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
{
"input": "789 101112 131415",
"output": "203802"
},
{
"input": "27485716 99999999 35182",
"output": "55041796"
},
{
"input": "1 293548 5",
"output": "12"
},
{
"input": "12059 259855 5874875",
"output": "543828"
},
{
"input": "46981 105809 585858",
"output": "305580"
},
{
"input": "9889 1221 2442",
"output": "7326"
},
{
"input": "100500 200600 300700",
"output": "601800"
},
{
"input": "318476 318476 318476",
"output": "955428"
},
{
"input": "23985 3353 75633",
"output": "54676"
},
{
"input": "120 1298 2222",
"output": "2836"
},
{
"input": "98437 23487 666672",
"output": "243848"
},
{
"input": "100000000 100000000 100000000",
"output": "300000000"
},
{
"input": "2 5 2",
"output": "8"
},
{
"input": "1 1000 1",
"output": "4"
},
{
"input": "1 100000000 1",
"output": "4"
}
] | 1,696,316,571
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 21
| 46
| 0
|
a,b,c=map(int,input().split())
m=a+b+c
if((2*a)+(2*b)<m):
m=(2*a)+(2*b)
elif((2*a)+(2*c)<m):
m=(2*a)+(2*c)
elif((2*b)+(2*c)<m):
m=(2*c)+(2*b)
print(m)
|
Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of length *d*3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house.
Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled.
Input Specification:
The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length of the path connecting both shops.
Output Specification:
Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house.
Demo Input:
['10 20 30\n', '1 1 5\n']
Demo Output:
['60\n', '4\n']
Note:
The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
In the second sample one of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
|
```python
a,b,c=map(int,input().split())
m=a+b+c
if((2*a)+(2*b)<m):
m=(2*a)+(2*b)
elif((2*a)+(2*c)<m):
m=(2*a)+(2*c)
elif((2*b)+(2*c)<m):
m=(2*c)+(2*b)
print(m)
```
| 3
|
|
675
|
A
|
Infinite Sequence
|
PROGRAMMING
| 1,100
|
[
"math"
] | null | null |
Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears in this sequence, that is, there exists a positive integer *i*, such that *s**i*<==<=*b*. Of course, you are the person he asks for a help.
|
The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≤<=*a*,<=*b*,<=*c*<=≤<=109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.
|
If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes).
|
[
"1 7 3\n",
"10 10 0\n",
"1 -4 5\n",
"0 60 50\n"
] |
[
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] |
In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.
| 500
|
[
{
"input": "1 7 3",
"output": "YES"
},
{
"input": "10 10 0",
"output": "YES"
},
{
"input": "1 -4 5",
"output": "NO"
},
{
"input": "0 60 50",
"output": "NO"
},
{
"input": "1 -4 -5",
"output": "YES"
},
{
"input": "0 1 0",
"output": "NO"
},
{
"input": "10 10 42",
"output": "YES"
},
{
"input": "-1000000000 1000000000 -1",
"output": "NO"
},
{
"input": "10 16 4",
"output": "NO"
},
{
"input": "-1000000000 1000000000 5",
"output": "YES"
},
{
"input": "1000000000 -1000000000 5",
"output": "NO"
},
{
"input": "1000000000 -1000000000 0",
"output": "NO"
},
{
"input": "1000000000 1000000000 0",
"output": "YES"
},
{
"input": "115078364 -899474523 -1",
"output": "YES"
},
{
"input": "-245436499 416383245 992",
"output": "YES"
},
{
"input": "-719636354 536952440 2",
"output": "YES"
},
{
"input": "-198350539 963391024 68337739",
"output": "YES"
},
{
"input": "-652811055 875986516 1091",
"output": "YES"
},
{
"input": "119057893 -516914539 -39748277",
"output": "YES"
},
{
"input": "989140430 731276607 -36837689",
"output": "YES"
},
{
"input": "677168390 494583489 -985071853",
"output": "NO"
},
{
"input": "58090193 777423708 395693923",
"output": "NO"
},
{
"input": "479823846 -403424770 -653472589",
"output": "NO"
},
{
"input": "-52536829 -132023273 -736287999",
"output": "NO"
},
{
"input": "-198893776 740026818 -547885271",
"output": "NO"
},
{
"input": "-2 -2 -2",
"output": "YES"
},
{
"input": "-2 -2 -1",
"output": "YES"
},
{
"input": "-2 -2 0",
"output": "YES"
},
{
"input": "-2 -2 1",
"output": "YES"
},
{
"input": "-2 -2 2",
"output": "YES"
},
{
"input": "-2 -1 -2",
"output": "NO"
},
{
"input": "-2 -1 -1",
"output": "NO"
},
{
"input": "-2 -1 0",
"output": "NO"
},
{
"input": "-2 -1 1",
"output": "YES"
},
{
"input": "-2 -1 2",
"output": "NO"
},
{
"input": "-2 0 -2",
"output": "NO"
},
{
"input": "-2 0 -1",
"output": "NO"
},
{
"input": "-2 0 0",
"output": "NO"
},
{
"input": "-2 0 1",
"output": "YES"
},
{
"input": "-2 0 2",
"output": "YES"
},
{
"input": "-2 1 -2",
"output": "NO"
},
{
"input": "-2 1 -1",
"output": "NO"
},
{
"input": "-2 1 0",
"output": "NO"
},
{
"input": "-2 1 1",
"output": "YES"
},
{
"input": "-2 1 2",
"output": "NO"
},
{
"input": "-2 2 -2",
"output": "NO"
},
{
"input": "-2 2 -1",
"output": "NO"
},
{
"input": "-2 2 0",
"output": "NO"
},
{
"input": "-2 2 1",
"output": "YES"
},
{
"input": "-2 2 2",
"output": "YES"
},
{
"input": "-1 -2 -2",
"output": "NO"
},
{
"input": "-1 -2 -1",
"output": "YES"
},
{
"input": "-1 -2 0",
"output": "NO"
},
{
"input": "-1 -2 1",
"output": "NO"
},
{
"input": "-1 -2 2",
"output": "NO"
},
{
"input": "-1 -1 -2",
"output": "YES"
},
{
"input": "-1 -1 -1",
"output": "YES"
},
{
"input": "-1 -1 0",
"output": "YES"
},
{
"input": "-1 -1 1",
"output": "YES"
},
{
"input": "-1 -1 2",
"output": "YES"
},
{
"input": "-1 0 -2",
"output": "NO"
},
{
"input": "-1 0 -1",
"output": "NO"
},
{
"input": "-1 0 0",
"output": "NO"
},
{
"input": "-1 0 1",
"output": "YES"
},
{
"input": "-1 0 2",
"output": "NO"
},
{
"input": "-1 1 -2",
"output": "NO"
},
{
"input": "-1 1 -1",
"output": "NO"
},
{
"input": "-1 1 0",
"output": "NO"
},
{
"input": "-1 1 1",
"output": "YES"
},
{
"input": "-1 1 2",
"output": "YES"
},
{
"input": "-1 2 -2",
"output": "NO"
},
{
"input": "-1 2 -1",
"output": "NO"
},
{
"input": "-1 2 0",
"output": "NO"
},
{
"input": "-1 2 1",
"output": "YES"
},
{
"input": "-1 2 2",
"output": "NO"
},
{
"input": "0 -2 -2",
"output": "YES"
},
{
"input": "0 -2 -1",
"output": "YES"
},
{
"input": "0 -2 0",
"output": "NO"
},
{
"input": "0 -2 1",
"output": "NO"
},
{
"input": "0 -2 2",
"output": "NO"
},
{
"input": "0 -1 -2",
"output": "NO"
},
{
"input": "0 -1 -1",
"output": "YES"
},
{
"input": "0 -1 0",
"output": "NO"
},
{
"input": "0 -1 1",
"output": "NO"
},
{
"input": "0 -1 2",
"output": "NO"
},
{
"input": "0 0 -2",
"output": "YES"
},
{
"input": "0 0 -1",
"output": "YES"
},
{
"input": "0 0 0",
"output": "YES"
},
{
"input": "0 0 1",
"output": "YES"
},
{
"input": "0 0 2",
"output": "YES"
},
{
"input": "0 1 -2",
"output": "NO"
},
{
"input": "0 1 -1",
"output": "NO"
},
{
"input": "0 1 0",
"output": "NO"
},
{
"input": "0 1 1",
"output": "YES"
},
{
"input": "0 1 2",
"output": "NO"
},
{
"input": "0 2 -2",
"output": "NO"
},
{
"input": "0 2 -1",
"output": "NO"
},
{
"input": "0 2 0",
"output": "NO"
},
{
"input": "0 2 1",
"output": "YES"
},
{
"input": "0 2 2",
"output": "YES"
},
{
"input": "1 -2 -2",
"output": "NO"
},
{
"input": "1 -2 -1",
"output": "YES"
},
{
"input": "1 -2 0",
"output": "NO"
},
{
"input": "1 -2 1",
"output": "NO"
},
{
"input": "1 -2 2",
"output": "NO"
},
{
"input": "1 -1 -2",
"output": "YES"
},
{
"input": "1 -1 -1",
"output": "YES"
},
{
"input": "1 -1 0",
"output": "NO"
},
{
"input": "1 -1 1",
"output": "NO"
},
{
"input": "1 -1 2",
"output": "NO"
},
{
"input": "1 0 -2",
"output": "NO"
},
{
"input": "1 0 -1",
"output": "YES"
},
{
"input": "1 0 0",
"output": "NO"
},
{
"input": "1 0 1",
"output": "NO"
},
{
"input": "1 0 2",
"output": "NO"
},
{
"input": "1 1 -2",
"output": "YES"
},
{
"input": "1 1 -1",
"output": "YES"
},
{
"input": "1 1 0",
"output": "YES"
},
{
"input": "1 1 1",
"output": "YES"
},
{
"input": "1 1 2",
"output": "YES"
},
{
"input": "1 2 -2",
"output": "NO"
},
{
"input": "1 2 -1",
"output": "NO"
},
{
"input": "1 2 0",
"output": "NO"
},
{
"input": "1 2 1",
"output": "YES"
},
{
"input": "1 2 2",
"output": "NO"
},
{
"input": "2 -2 -2",
"output": "YES"
},
{
"input": "2 -2 -1",
"output": "YES"
},
{
"input": "2 -2 0",
"output": "NO"
},
{
"input": "2 -2 1",
"output": "NO"
},
{
"input": "2 -2 2",
"output": "NO"
},
{
"input": "2 -1 -2",
"output": "NO"
},
{
"input": "2 -1 -1",
"output": "YES"
},
{
"input": "2 -1 0",
"output": "NO"
},
{
"input": "2 -1 1",
"output": "NO"
},
{
"input": "2 -1 2",
"output": "NO"
},
{
"input": "2 0 -2",
"output": "YES"
},
{
"input": "2 0 -1",
"output": "YES"
},
{
"input": "2 0 0",
"output": "NO"
},
{
"input": "2 0 1",
"output": "NO"
},
{
"input": "2 0 2",
"output": "NO"
},
{
"input": "2 1 -2",
"output": "NO"
},
{
"input": "2 1 -1",
"output": "YES"
},
{
"input": "2 1 0",
"output": "NO"
},
{
"input": "2 1 1",
"output": "NO"
},
{
"input": "2 1 2",
"output": "NO"
},
{
"input": "2 2 -2",
"output": "YES"
},
{
"input": "2 2 -1",
"output": "YES"
},
{
"input": "2 2 0",
"output": "YES"
},
{
"input": "2 2 1",
"output": "YES"
},
{
"input": "2 2 2",
"output": "YES"
},
{
"input": "-1000000000 1000000000 1",
"output": "YES"
},
{
"input": "-1000000000 1000000000 2",
"output": "YES"
},
{
"input": "1000000000 -1000000000 -1",
"output": "YES"
},
{
"input": "5 2 3",
"output": "NO"
},
{
"input": "2 1 -1",
"output": "YES"
},
{
"input": "3 2 1",
"output": "NO"
},
{
"input": "0 -5 -3",
"output": "NO"
},
{
"input": "2 5 5",
"output": "NO"
},
{
"input": "0 10 1",
"output": "YES"
},
{
"input": "15 5 -5",
"output": "YES"
},
{
"input": "2 1 1",
"output": "NO"
},
{
"input": "20 10 0",
"output": "NO"
},
{
"input": "20 15 5",
"output": "NO"
},
{
"input": "1 6 1",
"output": "YES"
},
{
"input": "1000000000 0 -1000000000",
"output": "YES"
},
{
"input": "1 1 -5",
"output": "YES"
},
{
"input": "4 6 1",
"output": "YES"
},
{
"input": "-5 -10 -5",
"output": "YES"
},
{
"input": "2 0 0",
"output": "NO"
},
{
"input": "10 9 -1",
"output": "YES"
},
{
"input": "-2 -1 -1",
"output": "NO"
},
{
"input": "1 13 3",
"output": "YES"
},
{
"input": "2 3 0",
"output": "NO"
},
{
"input": "1 1 -1",
"output": "YES"
},
{
"input": "5 -10 -5",
"output": "YES"
},
{
"input": "5 3 1",
"output": "NO"
},
{
"input": "1 1000000000 1",
"output": "YES"
},
{
"input": "-1000000000 1000000000 1000000000",
"output": "YES"
}
] | 1,670,699,769
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 1
| 46
| 0
|
import sys
from math import ceil
input = sys.stdin.readline
def nth(a, n, d):
return a + (n - 1) * d
a, b, c = [int(x) for x in input().split()]
ans = "NO"
low = a
high = b
mid = ceil((low + high) / 2)
while low < high:
res = nth(a, mid, c)
if res < b:
break
#print(res)
if res == b:
ans = "YES"
break
if res > b:
high = mid
else:
low = mid
mid = ceil((low + high) / 2)
print(ans)
|
Title: Infinite Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears in this sequence, that is, there exists a positive integer *i*, such that *s**i*<==<=*b*. Of course, you are the person he asks for a help.
Input Specification:
The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≤<=*a*,<=*b*,<=*c*<=≤<=109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.
Output Specification:
If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes).
Demo Input:
['1 7 3\n', '10 10 0\n', '1 -4 5\n', '0 60 50\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n', 'NO\n']
Note:
In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.
|
```python
import sys
from math import ceil
input = sys.stdin.readline
def nth(a, n, d):
return a + (n - 1) * d
a, b, c = [int(x) for x in input().split()]
ans = "NO"
low = a
high = b
mid = ceil((low + high) / 2)
while low < high:
res = nth(a, mid, c)
if res < b:
break
#print(res)
if res == b:
ans = "YES"
break
if res > b:
high = mid
else:
low = mid
mid = ceil((low + high) / 2)
print(ans)
```
| 0
|
|
507
|
B
|
Amr and Pins
|
PROGRAMMING
| 1,400
|
[
"geometry",
"math"
] | null | null |
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin.
Help Amr to achieve his goal in minimum number of steps.
|
Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively.
|
Output a single integer — minimum number of steps required to move the center of the circle to the destination point.
|
[
"2 0 0 0 4\n",
"1 1 1 4 4\n",
"4 5 6 5 6\n"
] |
[
"1\n",
"3\n",
"0\n"
] |
In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/>
| 1,000
|
[
{
"input": "2 0 0 0 4",
"output": "1"
},
{
"input": "1 1 1 4 4",
"output": "3"
},
{
"input": "4 5 6 5 6",
"output": "0"
},
{
"input": "10 20 0 40 0",
"output": "1"
},
{
"input": "9 20 0 40 0",
"output": "2"
},
{
"input": "5 -1 -6 -5 1",
"output": "1"
},
{
"input": "99125 26876 -21414 14176 17443",
"output": "1"
},
{
"input": "8066 7339 19155 -90534 -60666",
"output": "8"
},
{
"input": "100000 -100000 -100000 100000 100000",
"output": "2"
},
{
"input": "10 20 0 41 0",
"output": "2"
},
{
"input": "25 -64 -6 -56 64",
"output": "2"
},
{
"input": "125 455 450 439 721",
"output": "2"
},
{
"input": "5 6 3 7 2",
"output": "1"
},
{
"input": "24 130 14786 3147 2140",
"output": "271"
},
{
"input": "125 -363 176 93 330",
"output": "2"
},
{
"input": "1 14 30 30 14",
"output": "12"
},
{
"input": "25 96 13 7 2",
"output": "2"
},
{
"input": "4 100000 -100000 100000 -100000",
"output": "0"
},
{
"input": "1 3 4 2 5",
"output": "1"
},
{
"input": "1 -3 3 2 6",
"output": "3"
},
{
"input": "2 7 20 13 -5",
"output": "7"
},
{
"input": "1 1 1 1 4",
"output": "2"
},
{
"input": "249 -54242 -30537 -45023 -89682",
"output": "121"
},
{
"input": "4 100000 -100000 100000 -99999",
"output": "1"
},
{
"input": "97741 23818 78751 97583 26933",
"output": "1"
},
{
"input": "56767 -29030 51625 79823 -56297",
"output": "2"
},
{
"input": "98260 13729 74998 23701 9253",
"output": "1"
},
{
"input": "67377 -80131 -90254 -57320 14102",
"output": "1"
},
{
"input": "1 100000 100000 100000 -100000",
"output": "100000"
},
{
"input": "19312 19470 82059 58064 62231",
"output": "2"
},
{
"input": "67398 -68747 -79056 -34193 29400",
"output": "1"
},
{
"input": "91099 37184 -71137 75650 -3655",
"output": "1"
},
{
"input": "46456 -2621 -23623 -98302 -99305",
"output": "2"
},
{
"input": "100 100000 -100000 100000 -99999",
"output": "1"
},
{
"input": "1 100000 -100000 100000 -100000",
"output": "0"
},
{
"input": "8 0 0 0 32",
"output": "2"
},
{
"input": "100000 100000 1 -100000 0",
"output": "2"
}
] | 1,578,033,792
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 37
| 109
| 0
|
from math import ceil
r,x1,y1,x2,y2 = map(int, input().split())
dist = ((x2-x1)**2 + (y2-y1)**2)**(0.5)
ans = int(ceil(dist/(2*r)))
print(ans)
|
Title: Amr and Pins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin.
Help Amr to achieve his goal in minimum number of steps.
Input Specification:
Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively.
Output Specification:
Output a single integer — minimum number of steps required to move the center of the circle to the destination point.
Demo Input:
['2 0 0 0 4\n', '1 1 1 4 4\n', '4 5 6 5 6\n']
Demo Output:
['1\n', '3\n', '0\n']
Note:
In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/>
|
```python
from math import ceil
r,x1,y1,x2,y2 = map(int, input().split())
dist = ((x2-x1)**2 + (y2-y1)**2)**(0.5)
ans = int(ceil(dist/(2*r)))
print(ans)
```
| 3
|
|
592
|
C
|
The Big Race
|
PROGRAMMING
| 1,800
|
[
"math"
] | null | null |
Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.
While watching previous races the organizers have noticed that Willman can perform only steps of length equal to *w* meters, and Bolt can perform only steps of length equal to *b* meters. Organizers decided to slightly change the rules of the race. Now, at the end of the racetrack there will be an abyss, and the winner will be declared the athlete, who manages to run farther from the starting point of the the racetrack (which is not the subject to change by any of the athletes).
Note that none of the athletes can run infinitely far, as they both will at some moment of time face the point, such that only one step further will cause them to fall in the abyss. In other words, the athlete will not fall into the abyss if the total length of all his steps will be less or equal to the chosen distance *L*.
Since the organizers are very fair, the are going to set the length of the racetrack as an integer chosen randomly and uniformly in range from 1 to *t* (both are included). What is the probability that Willman and Bolt tie again today?
|
The first line of the input contains three integers *t*, *w* and *b* (1<=≤<=*t*,<=*w*,<=*b*<=≤<=5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively.
|
Print the answer to the problem as an irreducible fraction . Follow the format of the samples output.
The fraction (*p* and *q* are integers, and both *p*<=≥<=0 and *q*<=><=0 holds) is called irreducible, if there is no such integer *d*<=><=1, that both *p* and *q* are divisible by *d*.
|
[
"10 3 2\n",
"7 1 2\n"
] |
[
"3/10\n",
"3/7\n"
] |
In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack.
| 1,500
|
[
{
"input": "10 3 2",
"output": "3/10"
},
{
"input": "7 1 2",
"output": "3/7"
},
{
"input": "1 1 1",
"output": "1/1"
},
{
"input": "5814 31 7",
"output": "94/2907"
},
{
"input": "94268 813 766",
"output": "765/94268"
},
{
"input": "262610 5583 4717",
"output": "2358/131305"
},
{
"input": "3898439 96326 71937",
"output": "71936/3898439"
},
{
"input": "257593781689876390 32561717 4411677",
"output": "7914548537/257593781689876390"
},
{
"input": "111319886766128339 7862842484895022 3003994959686829",
"output": "3003994959686828/111319886766128339"
},
{
"input": "413850294331656955 570110918058849723 409853735661743839",
"output": "409853735661743838/413850294331656955"
},
{
"input": "3000000000000000000 2999999999999999873 2999999999999999977",
"output": "23437499999999999/23437500000000000"
},
{
"input": "9 6 1",
"output": "1/9"
},
{
"input": "32 9 2",
"output": "3/32"
},
{
"input": "976 5 6",
"output": "41/244"
},
{
"input": "5814 31 7",
"output": "94/2907"
},
{
"input": "94268 714 345",
"output": "689/94268"
},
{
"input": "262610 5583 4717",
"output": "2358/131305"
},
{
"input": "3898439 96326 71937",
"output": "71936/3898439"
},
{
"input": "54682301 778668 253103",
"output": "253102/54682301"
},
{
"input": "329245015 1173508 8918834",
"output": "1173507/329245015"
},
{
"input": "321076647734423976 7 7",
"output": "1/1"
},
{
"input": "455227494055672047 92 28",
"output": "19792499741550983/455227494055672047"
},
{
"input": "595779167455745259 6954 8697",
"output": "205511958419723/595779167455745259"
},
{
"input": "1000000000000000000 1000000000 2000000000",
"output": "1/2"
},
{
"input": "462643382718281828 462643382718281507 462643382718281701",
"output": "33045955908448679/33045955908448702"
},
{
"input": "4000000000000000000 9999999999999997 99999999999999999",
"output": "2499999999999999/1000000000000000000"
},
{
"input": "4003000100004000000 9999999099999999 99999999999999999",
"output": "4999999549999999/2001500050002000000"
},
{
"input": "4903000100004000000 58997960959949999 99933992929999999",
"output": "29498980479974999/2451500050002000000"
},
{
"input": "257593781689876390 32561717 4411677",
"output": "7914548537/257593781689876390"
},
{
"input": "111319886766128339 7862842484895022 3003994959686829",
"output": "3003994959686828/111319886766128339"
},
{
"input": "413850294331656955 570110918058849723 409853735661743839",
"output": "409853735661743838/413850294331656955"
},
{
"input": "232 17 83",
"output": "2/29"
},
{
"input": "5496272 63 200",
"output": "13765/2748136"
},
{
"input": "180 174 53",
"output": "13/45"
},
{
"input": "1954 190 537",
"output": "189/1954"
},
{
"input": "146752429 510 514",
"output": "571199/146752429"
},
{
"input": "579312860 55 70",
"output": "10344881/144828215"
},
{
"input": "1 9 9",
"output": "1/1"
},
{
"input": "95 19 19",
"output": "1/1"
},
{
"input": "404 63 441",
"output": "31/202"
},
{
"input": "5566 4798 4798",
"output": "1/1"
},
{
"input": "118289676 570846883 570846883",
"output": "1/1"
},
{
"input": "763 358 358",
"output": "1/1"
},
{
"input": "85356138 7223 482120804",
"output": "3611/42678069"
},
{
"input": "674664088 435395270 5",
"output": "9/674664088"
},
{
"input": "762200126044291557 370330636048898430 6",
"output": "17/762200126044291557"
},
{
"input": "917148533938841535 47 344459175789842163",
"output": "28/183429706787768307"
},
{
"input": "360212127113008697 877228952036215545 5259",
"output": "5258/360212127113008697"
},
{
"input": "683705963104411677 89876390 116741460012229240",
"output": "539258339/683705963104411677"
},
{
"input": "573003994959686829 275856334120822851 1319886766128339",
"output": "3959660298385016/573003994959686829"
},
{
"input": "409853735661743839 413850294331656955 413850294331656955",
"output": "1/1"
},
{
"input": "19 1 19",
"output": "1/19"
},
{
"input": "576 18 32",
"output": "1/16"
},
{
"input": "9540 10 954",
"output": "1/477"
},
{
"input": "101997840 6 16999640",
"output": "1/8499820"
},
{
"input": "955944 1278 748",
"output": "1/639"
},
{
"input": "482120804 66748 7223",
"output": "1/66748"
},
{
"input": "370330636048898430 61721772674816405 6",
"output": "1/61721772674816405"
},
{
"input": "344459175789842163 7328918633826429 47",
"output": "1/7328918633826429"
},
{
"input": "877228952036215545 166805277055755 5259",
"output": "1/55601759018585"
},
{
"input": "116741460012229240 1298911316 89876390",
"output": "1/649455658"
},
{
"input": "275856334120822851 209 1319886766128339",
"output": "1/1319886766128339"
},
{
"input": "413850294331656955 1 413850294331656955",
"output": "1/413850294331656955"
},
{
"input": "54682301 778668 253103",
"output": "253102/54682301"
},
{
"input": "329245015 3931027 6443236",
"output": "357366/29931365"
},
{
"input": "321076647734423976 7 8",
"output": "1672274206950125/13378193655600999"
},
{
"input": "455227494055672047 71 60",
"output": "6411654845854559/455227494055672047"
},
{
"input": "595779167455745259 9741 9331",
"output": "61162012885196/595779167455745259"
},
{
"input": "6470 80 160",
"output": "327/647"
},
{
"input": "686325 828 1656",
"output": "114511/228775"
},
{
"input": "4535304 2129 4258",
"output": "755973/1511768"
},
{
"input": "40525189 6365 12730",
"output": "20265394/40525189"
},
{
"input": "675297075 25986 51972",
"output": "112553659/225099025"
},
{
"input": "5681598412 75376 226128",
"output": "1893897375/5681598412"
},
{
"input": "384118571739435733 619773000 1859319000",
"output": "128039524053435733/384118571739435733"
},
{
"input": "391554751752251913 625743359 1877230077",
"output": "130518250652782079/391554751752251913"
},
{
"input": "390728504279201198 625082797 1250165594",
"output": "195364252413988195/390728504279201198"
},
{
"input": "389902265396085075 624421544 1248843088",
"output": "64983710976697837/129967421798695025"
},
{
"input": "734812071040507372 857211800 2571635400",
"output": "61234339274051543/183703017760126843"
},
{
"input": "1 1 2",
"output": "0/1"
},
{
"input": "3 1 4",
"output": "0/1"
},
{
"input": "8 2 3",
"output": "3/8"
},
{
"input": "64 32 16",
"output": "1/2"
},
{
"input": "1 1 1000000000",
"output": "0/1"
},
{
"input": "1000000000 1 1",
"output": "1/1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1/1"
},
{
"input": "1000000000 2 4",
"output": "1/2"
},
{
"input": "1000000000 123 456",
"output": "6579023/1000000000"
},
{
"input": "1000000000 123123 654",
"output": "24851/1000000000"
},
{
"input": "123456 123 456",
"output": "215/30864"
},
{
"input": "123456 1234567 123",
"output": "61/61728"
},
{
"input": "314159265 271 8281",
"output": "37939/314159265"
},
{
"input": "11071994 4231 1324",
"output": "2647/11071994"
},
{
"input": "961748927 961748941 982451653",
"output": "1/1"
},
{
"input": "15485221 1259 90863",
"output": "1258/15485221"
},
{
"input": "5000000000000000000 4999999999999999837 4999999999999999963",
"output": "1249999999999999959/1250000000000000000"
},
{
"input": "4000000000000000000 3999999999999999691 3999999999999999887",
"output": "399999999999999969/400000000000000000"
},
{
"input": "999999999999999999 999999999999999709 999999999999999737",
"output": "333333333333333236/333333333333333333"
},
{
"input": "799999999999999999 799999999999999969 799999999999999991",
"output": "799999999999999968/799999999999999999"
},
{
"input": "812312312312312222 812312312312311897 812312312312312029",
"output": "406156156156155948/406156156156156111"
},
{
"input": "500000000000000000 499999999999999927 499999999999999931",
"output": "249999999999999963/250000000000000000"
},
{
"input": "555555555555555555 555555555555555083 555555555555555229",
"output": "50505050505050462/50505050505050505"
},
{
"input": "199419941994199419 199419941994199369 199419941994199391",
"output": "66473313998066456/66473313998066473"
},
{
"input": "145685485411238588 145685485411238483 145685485411238573",
"output": "72842742705619241/72842742705619294"
},
{
"input": "314159265358979323 314159265358979167 314159265358979213",
"output": "314159265358979166/314159265358979323"
},
{
"input": "10 1000000000000000000 1000000000000000001",
"output": "1/1"
},
{
"input": "5 100000000000000000 99999999999999999",
"output": "1/1"
},
{
"input": "5 1000000000000 1000000000001",
"output": "1/1"
},
{
"input": "5 1000000000000000000 1000000000000000001",
"output": "1/1"
},
{
"input": "2 1000000000000000000 1000000000000000001",
"output": "1/1"
},
{
"input": "2 10 11",
"output": "1/1"
},
{
"input": "10 123456789123456789 723456789123456781",
"output": "1/1"
},
{
"input": "12345678910 123456789101112131 123456789101112132",
"output": "1/1"
},
{
"input": "5 499999999999999999 499999999999999998",
"output": "1/1"
}
] | 1,446,312,803
| 3,803
|
Python 3
|
OK
|
TESTS
| 114
| 62
| 0
|
def gcd(a, b):
if (b == 0):
return a
return gcd(b, a % b)
s = input()
s = s.split()
t = int(s[0])
w = int(s[1])
b = int(s[2])
g = gcd(w, b)
w = w // g
r = w * b
w = w * g
k = (t // r) + 1
ans = (k - 1) + (min(w, b) - 1) * (k - 1) + min(t % r, min(w, b) - 1)
ng = gcd(ans, t)
print(ans // ng, t // ng, sep = '/')
|
Title: The Big Race
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.
While watching previous races the organizers have noticed that Willman can perform only steps of length equal to *w* meters, and Bolt can perform only steps of length equal to *b* meters. Organizers decided to slightly change the rules of the race. Now, at the end of the racetrack there will be an abyss, and the winner will be declared the athlete, who manages to run farther from the starting point of the the racetrack (which is not the subject to change by any of the athletes).
Note that none of the athletes can run infinitely far, as they both will at some moment of time face the point, such that only one step further will cause them to fall in the abyss. In other words, the athlete will not fall into the abyss if the total length of all his steps will be less or equal to the chosen distance *L*.
Since the organizers are very fair, the are going to set the length of the racetrack as an integer chosen randomly and uniformly in range from 1 to *t* (both are included). What is the probability that Willman and Bolt tie again today?
Input Specification:
The first line of the input contains three integers *t*, *w* and *b* (1<=≤<=*t*,<=*w*,<=*b*<=≤<=5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively.
Output Specification:
Print the answer to the problem as an irreducible fraction . Follow the format of the samples output.
The fraction (*p* and *q* are integers, and both *p*<=≥<=0 and *q*<=><=0 holds) is called irreducible, if there is no such integer *d*<=><=1, that both *p* and *q* are divisible by *d*.
Demo Input:
['10 3 2\n', '7 1 2\n']
Demo Output:
['3/10\n', '3/7\n']
Note:
In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack.
|
```python
def gcd(a, b):
if (b == 0):
return a
return gcd(b, a % b)
s = input()
s = s.split()
t = int(s[0])
w = int(s[1])
b = int(s[2])
g = gcd(w, b)
w = w // g
r = w * b
w = w * g
k = (t // r) + 1
ans = (k - 1) + (min(w, b) - 1) * (k - 1) + min(t % r, min(w, b) - 1)
ng = gcd(ans, t)
print(ans // ng, t // ng, sep = '/')
```
| 3
|
|
732
|
A
|
Buy a Shovel
|
PROGRAMMING
| 800
|
[
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null |
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<=≤<=*r*<=≤<=9).
What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of *r* burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel.
|
The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels.
|
Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change.
|
[
"117 3\n",
"237 7\n",
"15 2\n"
] |
[
"9\n",
"1\n",
"2\n"
] |
In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change.
| 500
|
[
{
"input": "117 3",
"output": "9"
},
{
"input": "237 7",
"output": "1"
},
{
"input": "15 2",
"output": "2"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1000 3",
"output": "1"
},
{
"input": "1000 1",
"output": "1"
},
{
"input": "1000 9",
"output": "1"
},
{
"input": "1 2",
"output": "2"
},
{
"input": "999 9",
"output": "1"
},
{
"input": "999 8",
"output": "2"
},
{
"input": "105 6",
"output": "2"
},
{
"input": "403 9",
"output": "3"
},
{
"input": "546 4",
"output": "4"
},
{
"input": "228 9",
"output": "5"
},
{
"input": "57 2",
"output": "6"
},
{
"input": "437 9",
"output": "7"
},
{
"input": "997 6",
"output": "8"
},
{
"input": "109 1",
"output": "9"
},
{
"input": "998 9",
"output": "5"
},
{
"input": "4 2",
"output": "3"
},
{
"input": "9 3",
"output": "7"
},
{
"input": "8 2",
"output": "4"
},
{
"input": "1 3",
"output": "3"
},
{
"input": "1 4",
"output": "4"
},
{
"input": "1 5",
"output": "5"
},
{
"input": "1 6",
"output": "6"
},
{
"input": "1 7",
"output": "7"
},
{
"input": "1 8",
"output": "8"
},
{
"input": "100 3",
"output": "1"
},
{
"input": "1000 2",
"output": "1"
},
{
"input": "1000 4",
"output": "1"
},
{
"input": "1000 5",
"output": "1"
},
{
"input": "1000 6",
"output": "1"
},
{
"input": "1000 7",
"output": "1"
},
{
"input": "1000 8",
"output": "1"
},
{
"input": "23 4",
"output": "8"
},
{
"input": "33 1",
"output": "7"
},
{
"input": "33 2",
"output": "4"
},
{
"input": "666 5",
"output": "5"
},
{
"input": "2 3",
"output": "5"
},
{
"input": "5 5",
"output": "1"
},
{
"input": "3 6",
"output": "2"
},
{
"input": "12 4",
"output": "2"
},
{
"input": "15 5",
"output": "1"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "25 5",
"output": "1"
},
{
"input": "2 9",
"output": "5"
},
{
"input": "6 7",
"output": "5"
},
{
"input": "8 9",
"output": "5"
},
{
"input": "2 7",
"output": "5"
},
{
"input": "4 7",
"output": "5"
},
{
"input": "2 1",
"output": "5"
},
{
"input": "261 1",
"output": "1"
}
] | 1,690,418,627
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 54
| 61
| 0
|
k , r = input().split()
k,r=int(k),int(r)
n = 1
while True:
m = k*n
if(m-((m//10)*10) == r or m-((m//10)*10) == 0):
break
n += 1
print(n)
|
Title: Buy a Shovel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<=≤<=*r*<=≤<=9).
What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of *r* burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel.
Input Specification:
The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels.
Output Specification:
Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change.
Demo Input:
['117 3\n', '237 7\n', '15 2\n']
Demo Output:
['9\n', '1\n', '2\n']
Note:
In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change.
|
```python
k , r = input().split()
k,r=int(k),int(r)
n = 1
while True:
m = k*n
if(m-((m//10)*10) == r or m-((m//10)*10) == 0):
break
n += 1
print(n)
```
| 3
|
|
912
|
A
|
Tricky Alchemy
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.
Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow crystals, green — one yellow and one blue, and for a blue ball, three blue crystals are enough.
Right now there are *A* yellow and *B* blue crystals in Grisha's disposal. Find out how many additional crystals he should acquire in order to produce the required number of balls.
|
The first line features two integers *A* and *B* (0<=≤<=*A*,<=*B*<=≤<=109), denoting the number of yellow and blue crystals respectively at Grisha's disposal.
The next line contains three integers *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=109) — the respective amounts of yellow, green and blue balls to be obtained.
|
Print a single integer — the minimum number of crystals that Grisha should acquire in addition.
|
[
"4 3\n2 1 1\n",
"3 9\n1 1 3\n",
"12345678 87654321\n43043751 1000000000 53798715\n"
] |
[
"2\n",
"1\n",
"2147483648\n"
] |
In the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue.
| 500
|
[
{
"input": "4 3\n2 1 1",
"output": "2"
},
{
"input": "3 9\n1 1 3",
"output": "1"
},
{
"input": "12345678 87654321\n43043751 1000000000 53798715",
"output": "2147483648"
},
{
"input": "12 12\n3 5 2",
"output": "0"
},
{
"input": "770 1390\n170 442 311",
"output": "12"
},
{
"input": "3555165 6693472\n1499112 556941 3075290",
"output": "3089339"
},
{
"input": "0 0\n1000000000 1000000000 1000000000",
"output": "7000000000"
},
{
"input": "1 1\n0 1 0",
"output": "0"
},
{
"input": "117708228 562858833\n118004008 360437130 154015822",
"output": "738362681"
},
{
"input": "999998118 700178721\n822106746 82987112 547955384",
"output": "1753877029"
},
{
"input": "566568710 765371101\n60614022 80126928 809950465",
"output": "1744607222"
},
{
"input": "448858599 829062060\n764716760 97644201 203890025",
"output": "1178219122"
},
{
"input": "626115781 966381948\n395190569 820194184 229233367",
"output": "1525971878"
},
{
"input": "803372962 103701834\n394260597 837711458 623172928",
"output": "3426388098"
},
{
"input": "980630143 241021722\n24734406 928857659 312079781",
"output": "1624075280"
},
{
"input": "862920032 378341609\n360240924 241342224 337423122",
"output": "974174021"
},
{
"input": "40177212 515661496\n64343660 963892207 731362684",
"output": "3694721078"
},
{
"input": "217434393 579352456\n694817470 981409480 756706026",
"output": "4825785129"
},
{
"input": "394691574 716672343\n398920207 72555681 150645586",
"output": "475704521"
},
{
"input": "276981463 853992230\n29394015 90072954 839552440",
"output": "1754738044"
},
{
"input": "843552056 919184611\n341530221 423649259 101547519",
"output": "263157645"
},
{
"input": "20809236 56504497\n972004030 441166533 495487081",
"output": "4235488636"
},
{
"input": "198066417 825228166\n602477839 532312735 520830423",
"output": "2808777834"
},
{
"input": "80356306 962548053\n601547868 549830008 914769984",
"output": "4004161345"
},
{
"input": "257613487 394835231\n642087093 567347282 308709545",
"output": "2692548667"
},
{
"input": "139903376 532155119\n641157122 289897263 629020178",
"output": "3077110809"
},
{
"input": "612127849 669475006\n271630930 676010757 22959739",
"output": "682559736"
},
{
"input": "0 0\n0 0 0",
"output": "0"
},
{
"input": "1000000000 1000000000\n499999998 4 333333332",
"output": "0"
},
{
"input": "1000000000 1000000000\n1000000000 1000000000 1000000000",
"output": "5000000000"
},
{
"input": "4 3\n1 0 1",
"output": "0"
},
{
"input": "4 12\n1 2 3",
"output": "0"
},
{
"input": "4 20\n1 2 1",
"output": "0"
},
{
"input": "100 10\n2 3 4",
"output": "5"
},
{
"input": "6 0\n1 1 1",
"output": "4"
},
{
"input": "25 5\n3 3 3",
"output": "7"
},
{
"input": "48 27\n22 39 20",
"output": "107"
},
{
"input": "4 0\n1 1 1",
"output": "4"
}
] | 1,626,838,371
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 38
| 77
| 6,758,400
|
[A,B] = map(int, input().split())
[x,y,z] = map(int, input().split())
yellow=x*2+y
blue=y+3*z
if yellow>=A:
ya=yellow-A
else:
ya=0
if blue>=B:
bl=blue-B
else:
bl=0
print (ya+bl)
|
Title: Tricky Alchemy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.
Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow crystals, green — one yellow and one blue, and for a blue ball, three blue crystals are enough.
Right now there are *A* yellow and *B* blue crystals in Grisha's disposal. Find out how many additional crystals he should acquire in order to produce the required number of balls.
Input Specification:
The first line features two integers *A* and *B* (0<=≤<=*A*,<=*B*<=≤<=109), denoting the number of yellow and blue crystals respectively at Grisha's disposal.
The next line contains three integers *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=109) — the respective amounts of yellow, green and blue balls to be obtained.
Output Specification:
Print a single integer — the minimum number of crystals that Grisha should acquire in addition.
Demo Input:
['4 3\n2 1 1\n', '3 9\n1 1 3\n', '12345678 87654321\n43043751 1000000000 53798715\n']
Demo Output:
['2\n', '1\n', '2147483648\n']
Note:
In the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue.
|
```python
[A,B] = map(int, input().split())
[x,y,z] = map(int, input().split())
yellow=x*2+y
blue=y+3*z
if yellow>=A:
ya=yellow-A
else:
ya=0
if blue>=B:
bl=blue-B
else:
bl=0
print (ya+bl)
```
| 3
|
|
219
|
A
|
k-String
|
PROGRAMMING
| 1,000
|
[
"implementation",
"strings"
] | null | null |
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string *s*, consisting of lowercase English letters and a positive integer *k*. Your task is to reorder the letters in the string *s* in such a way that the resulting string is a *k*-string.
|
The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*.
|
Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes).
|
[
"2\naazz\n",
"3\nabcabcabz\n"
] |
[
"azaz\n",
"-1\n"
] |
none
| 500
|
[
{
"input": "2\naazz",
"output": "azaz"
},
{
"input": "3\nabcabcabz",
"output": "-1"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "2\nabba",
"output": "abab"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "7\nabacaba",
"output": "-1"
},
{
"input": "5\naaaaa",
"output": "aaaaa"
},
{
"input": "3\naabaaaaabb",
"output": "-1"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "2\nbabac",
"output": "-1"
},
{
"input": "3\nbbbccc",
"output": "bcbcbc"
},
{
"input": "2\naa",
"output": "aa"
},
{
"input": "250\ncececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececece",
"output": "cececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececece"
},
{
"input": "15\nabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaa",
"output": "aaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbc"
},
{
"input": "1\naaa",
"output": "aaa"
},
{
"input": "1\naabaab",
"output": "aaaabb"
},
{
"input": "2\naabbbbccccccdddddddd",
"output": "abbcccddddabbcccdddd"
},
{
"input": "3\naaaaaaaaacccdddddd",
"output": "aaacddaaacddaaacdd"
},
{
"input": "3\naaaaaaaaacccbbbbbb",
"output": "aaabbcaaabbcaaabbc"
},
{
"input": "2\naazzzz",
"output": "azzazz"
},
{
"input": "2\naaaa",
"output": "aaaa"
},
{
"input": "2\naaaazz",
"output": "aazaaz"
},
{
"input": "2\naaaabb",
"output": "aabaab"
},
{
"input": "2\naabbbb",
"output": "abbabb"
},
{
"input": "2\naaaazzzz",
"output": "aazzaazz"
},
{
"input": "2\naaazz",
"output": "-1"
},
{
"input": "2\nbbbbaa",
"output": "abbabb"
},
{
"input": "2\naaaaaabbbb",
"output": "aaabbaaabb"
},
{
"input": "2\naaaaaazz",
"output": "aaazaaaz"
},
{
"input": "2\naaaabbbb",
"output": "aabbaabb"
},
{
"input": "2\naabaab",
"output": "aabaab"
},
{
"input": "1\naaaaa",
"output": "aaaaa"
},
{
"input": "2\nbbaaaa",
"output": "aabaab"
},
{
"input": "2\nacaccc",
"output": "accacc"
}
] | 1,657,782,647
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 9
| 92
| 102,400
|
import collections
n=int(input())
s=input()
t=''
d=collections.Counter(s)
k=list(d.keys())
v=list(d.values())
c=0
for i in range(len(v)):
if v[i]%n==0:
c+=1
else:
print(-1)
break
if c==len(v):
for i in range(len(k)):
t+=k[i]
print(t*n)
|
Title: k-String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string *s*, consisting of lowercase English letters and a positive integer *k*. Your task is to reorder the letters in the string *s* in such a way that the resulting string is a *k*-string.
Input Specification:
The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*.
Output Specification:
Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes).
Demo Input:
['2\naazz\n', '3\nabcabcabz\n']
Demo Output:
['azaz\n', '-1\n']
Note:
none
|
```python
import collections
n=int(input())
s=input()
t=''
d=collections.Counter(s)
k=list(d.keys())
v=list(d.values())
c=0
for i in range(len(v)):
if v[i]%n==0:
c+=1
else:
print(-1)
break
if c==len(v):
for i in range(len(k)):
t+=k[i]
print(t*n)
```
| 0
|
|
765
|
B
|
Code obfuscation
|
PROGRAMMING
| 1,100
|
[
"greedy",
"implementation",
"strings"
] | null | null |
Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest.
To obfuscate the code, Kostya first looks at the first variable name used in his program and replaces all its occurrences with a single symbol *a*, then he looks at the second variable name that has not been replaced yet, and replaces all its occurrences with *b*, and so on. Kostya is well-mannered, so he doesn't use any one-letter names before obfuscation. Moreover, there are at most 26 unique identifiers in his programs.
You are given a list of identifiers of some program with removed spaces and line breaks. Check if this program can be a result of Kostya's obfuscation.
|
In the only line of input there is a string *S* of lowercase English letters (1<=≤<=|*S*|<=≤<=500) — the identifiers of a program with removed whitespace characters.
|
If this program can be a result of Kostya's obfuscation, print "YES" (without quotes), otherwise print "NO".
|
[
"abacaba\n",
"jinotega\n"
] |
[
"YES\n",
"NO\n"
] |
In the first sample case, one possible list of identifiers would be "number string number character number string number". Here how Kostya would obfuscate the program:
- replace all occurences of number with a, the result would be "a string a character a string a",- replace all occurences of string with b, the result would be "a b a character a b a",- replace all occurences of character with c, the result would be "a b a c a b a",- all identifiers have been replaced, thus the obfuscation is finished.
| 1,000
|
[
{
"input": "abacaba",
"output": "YES"
},
{
"input": "jinotega",
"output": "NO"
},
{
"input": "aaaaaaaaaaa",
"output": "YES"
},
{
"input": "aba",
"output": "YES"
},
{
"input": "bab",
"output": "NO"
},
{
"input": "a",
"output": "YES"
},
{
"input": "abcdefghijklmnopqrstuvwxyz",
"output": "YES"
},
{
"input": "fihyxmbnzq",
"output": "NO"
},
{
"input": "aamlaswqzotaanasdhcvjoaiwdhctezzawagkdgfffeqkyrvbcrfqgkdsvximsnvmkmjyofswmtjdoxgwamsaatngenqvsvrvwlbzuoeaolfcnmdacrmdleafbsmerwmxzyylfhemnkoayuhtpbikm",
"output": "NO"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "YES"
},
{
"input": "darbbbcwynbbbbaacbkvbakavabbbabzajlbajryaabbbccxraakgniagbtsswcfbkubdmcasccepybkaefcfsbzdddxgcjadybcfjtmqbspflqrdghgfwnccfveogdmifkociqscahdejctacwzbkhihajfilrgcjiofwfklifobozikcmvcfeqlidrgsgdfxffaaebzjxngsjxiclyolhjokqpdbfffooticxsezpgqkhhzmbmqgskkqvefzyijrwhpftcmbedmaflapmeljaudllojfpgfkpvgylaglrhrslxlprbhgknrctilngqccbddvpamhifsbmyowohczizjcbleehfrecjbqtxertnpfmalejmbxkhkkbyopuwlhkxuqellsybgcndvniyyxfoufalstdsdfjoxlnmigkqwmgojsppaannfstxytelluvvkdcezlqfsperwyjsdsmkvgjdbksswamhmoukcawiigkggztr",
"output": "NO"
},
{
"input": "bbbbbb",
"output": "NO"
},
{
"input": "aabbbd",
"output": "NO"
},
{
"input": "abdefghijklmnopqrstuvwxyz",
"output": "NO"
},
{
"input": "abcdeghijklmnopqrstuvwxyz",
"output": "NO"
},
{
"input": "abcdefghijklmnopqrsuvwxyz",
"output": "NO"
},
{
"input": "abcdefghijklmnopqrstuvwxy",
"output": "YES"
},
{
"input": "abcdefghijklmnopqrsutvwxyz",
"output": "NO"
},
{
"input": "acdef",
"output": "NO"
},
{
"input": "z",
"output": "NO"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaababaaababaabababccbabdbcbadccacdbdedabbeecbcabbdcaecdabbedddafeffaccgeacefbcahabfiiegecdbebabhhbdgfeghhbfahgagefbgghdbhadeicbdfgdchhefhigfcgdhcihecacfhadfgfejccibcjkfhbigbealjjkfldiecfdcafbamgfkbjlbifldghmiifkkglaflmjfmkfdjlbliijkgfdelklfnadbifgbmklfbqkhirhcadoadhmjrghlmelmjfpakqkdfcgqdkaeqpbcdoeqglqrarkipncckpfmajrqsfffldegbmahsfcqdfdqtrgrouqajgsojmmukptgerpanpcbejmergqtavwsvtveufdseuemwrhfmjqinxjodddnpcgqullrhmogflsxgsbapoghortiwcovejtinncozk",
"output": "NO"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "YES"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbabbbabbaaabbaaaaabaabbaa",
"output": "YES"
},
{
"input": "aababbabbaabbbbbaabababaabbbaaaaabbabbabbaabbbbabaabbaaababbaaacbbabbbbbbcbcababbccaaacbaccaccaababbccaacccaabaaccaaabacacbaabacbaacbaaabcbbbcbbaacaabcbcbccbacabbcbabcaccaaaaaabcbacabcbabbbbbabccbbcacbaaabbccbbaaaaaaaaaaaadbbbabdacabdaddddbaabbddbdabbdacbacbacaaaabbacadbcddddadaddabbdccaddbaaacbceebbceadbeaadecddbbbcaaecbdeaebaddbbdebbcbaabcacbdcdc",
"output": "YES"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbaabaabaababbbabbacacbbbacbbaaaabbccacbaabaaccbbbbbcbbbacabbccaaabbaaacabcbacbcabbbbecbecadcbacbaadeeadabeacdebccdbbcaecdbeeebbebcaaaeacdcbdeccdbbdcdebdcbdacebcecbacddeeaebcedffedfggbeedceacaecagdfedfabcfchffceachgcbicbcffeeebgcgiefcafhibhceiedgbfebbccegbehhibhhfedbaeedbghggffehggaeaidifhdhaggdjcfjhiaieaichjacedchejg",
"output": "NO"
},
{
"input": "b",
"output": "NO"
},
{
"input": "ac",
"output": "NO"
},
{
"input": "cde",
"output": "NO"
},
{
"input": "abd",
"output": "NO"
},
{
"input": "zx",
"output": "NO"
},
{
"input": "bcd",
"output": "NO"
},
{
"input": "aaac",
"output": "NO"
},
{
"input": "aacb",
"output": "NO"
},
{
"input": "acd",
"output": "NO"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz",
"output": "NO"
},
{
"input": "abcdefghijklmnopqrstuvwxyzz",
"output": "YES"
},
{
"input": "bc",
"output": "NO"
},
{
"input": "aaaaaaaaad",
"output": "NO"
},
{
"input": "abb",
"output": "YES"
},
{
"input": "abcb",
"output": "YES"
},
{
"input": "aac",
"output": "NO"
},
{
"input": "abcbcb",
"output": "YES"
},
{
"input": "bb",
"output": "NO"
},
{
"input": "abbb",
"output": "YES"
},
{
"input": "bbb",
"output": "NO"
},
{
"input": "x",
"output": "NO"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazz",
"output": "NO"
},
{
"input": "acbccccccccccc",
"output": "NO"
},
{
"input": "za",
"output": "NO"
},
{
"input": "ade",
"output": "NO"
},
{
"input": "bbbbbbbbbb",
"output": "NO"
},
{
"input": "bac",
"output": "NO"
},
{
"input": "bcddcb",
"output": "NO"
},
{
"input": "aaacb",
"output": "NO"
},
{
"input": "aaaaac",
"output": "NO"
},
{
"input": "aaaaaaaaaaad",
"output": "NO"
},
{
"input": "c",
"output": "NO"
},
{
"input": "abcccccccc",
"output": "YES"
},
{
"input": "aaaaaaac",
"output": "NO"
}
] | 1,487,218,439
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 6
| 61
| 4,608,000
|
val = lambda c : ord(c) - ord('a')
visited = [False]*(26)
c = 'abcdefghijklmnopqrtuvwxyz'
s = input()
ans = True
for x in s :
if visited[val(x)] : continue
i = 0
flag = True
while c[i] != x :
if not visited[i] :
flag = False
break
i += 1
visited[val(x)] = True
if not flag:
ans = False
break
print("YES" if ans else "NO" )
|
Title: Code obfuscation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest.
To obfuscate the code, Kostya first looks at the first variable name used in his program and replaces all its occurrences with a single symbol *a*, then he looks at the second variable name that has not been replaced yet, and replaces all its occurrences with *b*, and so on. Kostya is well-mannered, so he doesn't use any one-letter names before obfuscation. Moreover, there are at most 26 unique identifiers in his programs.
You are given a list of identifiers of some program with removed spaces and line breaks. Check if this program can be a result of Kostya's obfuscation.
Input Specification:
In the only line of input there is a string *S* of lowercase English letters (1<=≤<=|*S*|<=≤<=500) — the identifiers of a program with removed whitespace characters.
Output Specification:
If this program can be a result of Kostya's obfuscation, print "YES" (without quotes), otherwise print "NO".
Demo Input:
['abacaba\n', 'jinotega\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample case, one possible list of identifiers would be "number string number character number string number". Here how Kostya would obfuscate the program:
- replace all occurences of number with a, the result would be "a string a character a string a",- replace all occurences of string with b, the result would be "a b a character a b a",- replace all occurences of character with c, the result would be "a b a c a b a",- all identifiers have been replaced, thus the obfuscation is finished.
|
```python
val = lambda c : ord(c) - ord('a')
visited = [False]*(26)
c = 'abcdefghijklmnopqrtuvwxyz'
s = input()
ans = True
for x in s :
if visited[val(x)] : continue
i = 0
flag = True
while c[i] != x :
if not visited[i] :
flag = False
break
i += 1
visited[val(x)] = True
if not flag:
ans = False
break
print("YES" if ans else "NO" )
```
| 0
|
|
526
|
B
|
Om Nom and Dark Park
|
PROGRAMMING
| 1,400
|
[
"dfs and similar",
"greedy",
"implementation"
] | null | null |
Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless as Om Nom, so he asks you to help him.
The park consists of 2*n*<=+<=1<=-<=1 squares connected by roads so that the scheme of the park is a full binary tree of depth *n*. More formally, the entrance to the park is located at the square 1. The exits out of the park are located at squares 2*n*,<=2*n*<=+<=1,<=...,<=2*n*<=+<=1<=-<=1 and these exits lead straight to the Om Nom friends' houses. From each square *i* (2<=≤<=*i*<=<<=2*n*<=+<=1) there is a road to the square . Thus, it is possible to go from the park entrance to each of the exits by walking along exactly *n* roads.
Om Nom loves counting lights on the way to his friend. Om Nom is afraid of spiders who live in the park, so he doesn't like to walk along roads that are not enough lit. What he wants is that the way to any of his friends should have in total the same number of lights. That will make him feel safe.
He asked you to help him install additional lights. Determine what minimum number of lights it is needed to additionally place on the park roads so that a path from the entrance to any exit of the park contains the same number of street lights. You may add an arbitrary number of street lights to each of the roads.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=10) — the number of roads on the path from the entrance to any exit.
The next line contains 2*n*<=+<=1<=-<=2 numbers *a*2,<=*a*3,<=... *a*2*n*<=+<=1<=-<=1 — the initial numbers of street lights on each road of the park. Here *a**i* is the number of street lights on the road between squares *i* and . All numbers *a**i* are positive integers, not exceeding 100.
|
Print the minimum number of street lights that we should add to the roads of the park to make Om Nom feel safe.
|
[
"2\n1 2 3 4 5 6\n"
] |
[
"5\n"
] |
Picture for the sample test. Green color denotes the additional street lights.
| 500
|
[
{
"input": "2\n1 2 3 4 5 6",
"output": "5"
},
{
"input": "2\n1 2 3 3 2 2",
"output": "0"
},
{
"input": "1\n39 52",
"output": "13"
},
{
"input": "2\n59 96 34 48 8 72",
"output": "139"
},
{
"input": "3\n87 37 91 29 58 45 51 74 70 71 47 38 91 89",
"output": "210"
},
{
"input": "5\n39 21 95 89 73 90 9 55 85 32 30 21 68 59 82 91 20 64 52 70 6 88 53 47 30 47 34 14 11 22 42 15 28 54 37 48 29 3 14 13 18 77 90 58 54 38 94 49 45 66 13 74 11 14 64 72 95 54 73 79 41 35",
"output": "974"
},
{
"input": "1\n49 36",
"output": "13"
},
{
"input": "1\n77 88",
"output": "11"
},
{
"input": "1\n1 33",
"output": "32"
},
{
"input": "2\n72 22 81 23 14 75",
"output": "175"
},
{
"input": "2\n100 70 27 1 68 52",
"output": "53"
},
{
"input": "2\n24 19 89 82 22 21",
"output": "80"
},
{
"input": "3\n86 12 92 91 3 68 57 56 76 27 33 62 71 84",
"output": "286"
},
{
"input": "3\n14 56 53 61 57 45 40 44 31 9 73 2 61 26",
"output": "236"
},
{
"input": "3\n35 96 7 43 10 14 16 36 95 92 16 50 59 55",
"output": "173"
},
{
"input": "4\n1 97 18 48 96 65 24 91 17 45 36 27 74 93 78 86 39 55 53 21 26 68 31 33 79 63 80 92 1 26",
"output": "511"
},
{
"input": "4\n25 42 71 29 50 30 99 79 77 24 76 66 68 23 97 99 65 17 75 62 66 46 48 4 40 71 98 57 21 92",
"output": "603"
},
{
"input": "4\n49 86 17 7 3 6 86 71 36 10 27 10 58 64 12 16 88 67 93 3 15 20 58 87 97 91 11 6 34 62",
"output": "470"
},
{
"input": "5\n16 87 36 16 81 53 87 35 63 56 47 91 81 95 80 96 91 7 58 99 25 28 47 60 7 69 49 14 51 52 29 30 83 23 21 52 100 26 91 14 23 94 72 70 40 12 50 32 54 52 18 74 5 15 62 3 48 41 24 25 56 43",
"output": "1060"
},
{
"input": "5\n40 27 82 94 38 22 66 23 18 34 87 31 71 28 95 5 14 61 76 52 66 6 60 40 68 77 70 63 64 18 47 13 82 55 34 64 30 1 29 24 24 9 65 17 29 96 61 76 72 23 32 26 90 39 54 41 35 66 71 29 75 48",
"output": "1063"
},
{
"input": "5\n64 72 35 68 92 95 45 15 77 16 26 74 61 65 18 22 32 19 98 97 14 84 70 23 29 1 87 28 88 89 73 79 69 88 43 60 64 64 66 39 17 27 46 71 18 83 73 20 90 77 49 70 84 63 50 72 26 87 26 37 78 65",
"output": "987"
},
{
"input": "6\n35 61 54 77 70 50 53 70 4 66 58 47 76 100 78 5 43 50 55 93 13 93 59 92 30 74 22 23 98 70 19 56 90 92 19 7 28 53 45 77 42 91 71 56 19 83 100 53 13 93 37 13 70 60 16 13 76 3 12 22 17 26 50 6 63 7 25 41 92 29 36 80 11 4 10 14 77 75 53 82 46 24 56 46 82 36 80 75 8 45 24 22 90 34 45 76 18 38 86 43 7 49 80 56 90 53 12 51 98 47 44 58 32 4 2 6 3 60 38 72 74 46 30 86 1 98",
"output": "2499"
},
{
"input": "6\n63 13 100 54 31 15 29 58 59 44 2 99 70 33 97 14 70 12 73 42 65 71 68 67 87 83 43 84 18 41 37 22 81 24 27 11 57 28 83 92 39 1 56 15 16 67 16 97 31 52 50 65 63 89 8 52 55 20 71 27 28 35 86 92 94 60 10 65 83 63 89 71 34 20 78 40 34 62 2 86 100 81 87 69 25 4 52 17 57 71 62 38 1 3 54 71 34 85 20 60 80 23 82 47 4 19 7 18 14 18 28 27 4 55 26 71 45 9 2 40 67 28 32 19 81 92",
"output": "2465"
},
{
"input": "6\n87 62 58 32 81 92 12 50 23 27 38 39 64 74 16 35 84 59 91 87 14 48 90 47 44 95 64 45 31 11 67 5 80 60 36 15 91 3 21 2 40 24 37 69 5 50 23 37 49 19 68 21 49 9 100 94 45 41 22 31 31 48 25 70 25 25 95 88 82 1 37 53 49 31 57 74 94 45 55 93 43 37 13 85 59 72 15 68 3 90 96 55 100 64 63 69 43 33 66 84 57 97 87 34 23 89 97 77 39 89 8 92 68 13 50 36 95 61 71 96 73 13 30 49 57 89",
"output": "2513"
}
] | 1,428,674,070
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 31
| 0
|
from operator import itemgetter
def prepare(a, n):
res = 0
for i in range(len(a) - 1):
a[i][1] = a[i//2 - 1][1] + a[i][0]
mx = max(a[2**n - 2:2**(n + 1) - 2], key=itemgetter(1))[1]
for i in range(2**n - 2, 2**(n + 1) - 2):
a[i][1] = mx - a[i][1]
for i in range(2**n - 3, -2, -1):
mn = a[i][1] = min(a[2*(i + 1)][1], a[2*(i + 1) + 1][1])
res += a[2*(i + 1)][1] + a[2*(i + 1) + 1][1] - 2*mn
return res
def main():
n = int(input())
a = [[int(i), 0] for i in input().split()]
a += [[0, 0]]
print(a)
print(prepare(a, n))
if __name__ == '__main__':
main()
|
Title: Om Nom and Dark Park
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless as Om Nom, so he asks you to help him.
The park consists of 2*n*<=+<=1<=-<=1 squares connected by roads so that the scheme of the park is a full binary tree of depth *n*. More formally, the entrance to the park is located at the square 1. The exits out of the park are located at squares 2*n*,<=2*n*<=+<=1,<=...,<=2*n*<=+<=1<=-<=1 and these exits lead straight to the Om Nom friends' houses. From each square *i* (2<=≤<=*i*<=<<=2*n*<=+<=1) there is a road to the square . Thus, it is possible to go from the park entrance to each of the exits by walking along exactly *n* roads.
Om Nom loves counting lights on the way to his friend. Om Nom is afraid of spiders who live in the park, so he doesn't like to walk along roads that are not enough lit. What he wants is that the way to any of his friends should have in total the same number of lights. That will make him feel safe.
He asked you to help him install additional lights. Determine what minimum number of lights it is needed to additionally place on the park roads so that a path from the entrance to any exit of the park contains the same number of street lights. You may add an arbitrary number of street lights to each of the roads.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=10) — the number of roads on the path from the entrance to any exit.
The next line contains 2*n*<=+<=1<=-<=2 numbers *a*2,<=*a*3,<=... *a*2*n*<=+<=1<=-<=1 — the initial numbers of street lights on each road of the park. Here *a**i* is the number of street lights on the road between squares *i* and . All numbers *a**i* are positive integers, not exceeding 100.
Output Specification:
Print the minimum number of street lights that we should add to the roads of the park to make Om Nom feel safe.
Demo Input:
['2\n1 2 3 4 5 6\n']
Demo Output:
['5\n']
Note:
Picture for the sample test. Green color denotes the additional street lights.
|
```python
from operator import itemgetter
def prepare(a, n):
res = 0
for i in range(len(a) - 1):
a[i][1] = a[i//2 - 1][1] + a[i][0]
mx = max(a[2**n - 2:2**(n + 1) - 2], key=itemgetter(1))[1]
for i in range(2**n - 2, 2**(n + 1) - 2):
a[i][1] = mx - a[i][1]
for i in range(2**n - 3, -2, -1):
mn = a[i][1] = min(a[2*(i + 1)][1], a[2*(i + 1) + 1][1])
res += a[2*(i + 1)][1] + a[2*(i + 1) + 1][1] - 2*mn
return res
def main():
n = int(input())
a = [[int(i), 0] for i in input().split()]
a += [[0, 0]]
print(a)
print(prepare(a, n))
if __name__ == '__main__':
main()
```
| 0
|
|
14
|
C
|
Four Segments
|
PROGRAMMING
| 1,700
|
[
"brute force",
"constructive algorithms",
"geometry",
"implementation",
"math"
] |
C. Four Segments
|
2
|
64
|
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him.
|
The input data contain four lines. Each of these lines contains four integers *x*1, *y*1, *x*2, *y*2 (<=-<=109<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points.
|
Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO».
|
[
"1 1 6 1\n1 0 6 0\n6 0 6 1\n1 1 1 0\n",
"0 0 0 3\n2 0 0 0\n2 2 2 0\n0 2 2 2\n"
] |
[
"YES\n",
"NO\n"
] |
none
| 0
|
[
{
"input": "1 1 6 1\n1 0 6 0\n6 0 6 1\n1 1 1 0",
"output": "YES"
},
{
"input": "0 0 0 3\n2 0 0 0\n2 2 2 0\n0 2 2 2",
"output": "NO"
},
{
"input": "0 0 0 2\n2 0 0 0\n2 2 2 0\n0 2 2 2",
"output": "YES"
},
{
"input": "0 0 10 0\n0 0 10 0\n0 0 0 5\n0 0 0 -5",
"output": "NO"
},
{
"input": "0 0 4 0\n4 0 3 0\n3 0 2 0\n2 0 0 0",
"output": "NO"
},
{
"input": "0 0 3 0\n0 0 0 3\n0 3 3 3\n3 3 3 0",
"output": "YES"
},
{
"input": "0 0 1 0\n1 0 1 1\n0 1 1 1\n0 0 0 1",
"output": "YES"
},
{
"input": "0 0 1 0\n1 0 1 1\n1 1 1 0\n1 0 0 0",
"output": "NO"
},
{
"input": "0 0 1 1\n1 1 2 0\n2 0 1 -1\n1 -1 0 0",
"output": "NO"
},
{
"input": "0 0 0 10\n0 10 0 9\n0 9 0 8\n0 8 0 0",
"output": "NO"
},
{
"input": "0 0 4 0\n4 0 4 0\n4 0 0 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 2\n0 2 2 2\n0 0 2 2\n2 2 2 0",
"output": "NO"
},
{
"input": "0 0 0 2\n2 0 2 2\n0 2 0 0\n2 2 2 0",
"output": "NO"
},
{
"input": "13 13 13 13\n13 13 13 13\n13 13 13 13\n13 13 13 13",
"output": "NO"
},
{
"input": "0 0 2 0\n0 1 0 3\n0 4 3 4\n3 0 3 3",
"output": "NO"
},
{
"input": "1 1 1 1\n0 1 -1 1\n-1 1 1 1\n-1 1 1 1",
"output": "NO"
},
{
"input": "1 -1 1 -1\n1 -1 1 -1\n1 -1 1 -1\n1 -1 1 -1",
"output": "NO"
},
{
"input": "-1 0 -1 0\n-1 0 -1 0\n-1 0 -1 0\n-1 0 -1 0",
"output": "NO"
},
{
"input": "-1 0 -1 0\n-1 0 -1 0\n-1 0 -1 0\n-1 0 -1 0",
"output": "NO"
},
{
"input": "0 -1 0 1\n0 0 0 1\n0 -1 0 -1\n0 -1 0 -1",
"output": "NO"
},
{
"input": "0 0 -1 0\n-1 0 0 0\n-1 0 -1 0\n-1 0 -1 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 0 1\n0 0 0 0",
"output": "NO"
},
{
"input": "-1 1 -1 1\n-1 1 -1 1\n-1 1 -1 1\n-1 1 -1 1",
"output": "NO"
},
{
"input": "-1 1 -1 1\n0 1 1 1\n1 -1 -1 1\n-1 1 1 1",
"output": "NO"
},
{
"input": "-1 -1 -1 -1\n-1 0 -1 0\n-1 0 -1 0\n-1 -1 -1 -1",
"output": "NO"
},
{
"input": "1 2 1 2\n-2 2 1 2\n1 -2 -2 2\n-2 -2 1 -2",
"output": "NO"
},
{
"input": "-2 1 -2 -1\n-2 -2 -2 -2\n-2 -1 -2 -2\n-2 1 -2 -1",
"output": "NO"
},
{
"input": "1 2 1 2\n1 -1 1 -1\n1 -1 1 -1\n1 -1 1 -1",
"output": "NO"
},
{
"input": "-2 0 -2 -1\n-2 2 -2 0\n-2 2 -2 2\n-2 0 -2 -1",
"output": "NO"
},
{
"input": "-1 1 -2 1\n0 -1 -1 1\n-2 1 -1 -1\n0 1 0 -1",
"output": "NO"
},
{
"input": "2 -1 -2 -1\n2 -1 2 -1\n2 -1 -2 -1\n2 -1 2 -1",
"output": "NO"
},
{
"input": "0 2 0 2\n0 2 0 1\n0 1 0 1\n0 2 0 1",
"output": "NO"
},
{
"input": "1 0 1 0\n1 0 1 0\n1 0 0 0\n1 0 1 0",
"output": "NO"
},
{
"input": "-1 1 2 1\n0 1 0 1\n0 1 2 1\n2 1 -1 1",
"output": "NO"
},
{
"input": "0 0 2 0\n0 0 2 0\n0 -2 0 0\n0 -2 0 0",
"output": "NO"
},
{
"input": "0 -3 0 -1\n1 -1 1 -1\n0 -1 1 -2\n0 -2 -2 -3",
"output": "NO"
},
{
"input": "-3 -2 -2 -2\n3 -2 3 -2\n-3 -2 -2 -2\n3 -2 3 -2",
"output": "NO"
},
{
"input": "1 2 -2 2\n-2 2 3 2\n1 2 -2 2\n-2 2 3 2",
"output": "NO"
},
{
"input": "0 -2 1 3\n1 3 1 3\n1 3 1 3\n1 3 1 -2",
"output": "NO"
},
{
"input": "0 -3 -2 -3\n0 1 0 -3\n0 1 0 -3\n0 1 0 -3",
"output": "NO"
},
{
"input": "1 -3 1 -3\n1 -3 1 -3\n1 -3 1 -3\n1 -3 1 -3",
"output": "NO"
},
{
"input": "-3 2 -2 1\n0 2 0 -3\n0 -3 -2 1\n0 1 -3 -3",
"output": "NO"
},
{
"input": "-3 3 2 3\n2 3 2 3\n-3 3 -3 3\n-3 3 2 3",
"output": "NO"
},
{
"input": "2 -2 2 -2\n2 -2 2 -2\n2 -2 2 -2\n2 -2 2 -2",
"output": "NO"
},
{
"input": "2 -1 0 -2\n-3 -2 -3 3\n2 -2 2 -2\n0 3 -3 -2",
"output": "NO"
},
{
"input": "1 -3 -1 1\n0 -2 1 -3\n1 1 0 1\n1 -3 0 1",
"output": "NO"
},
{
"input": "-2 4 -2 4\n-2 4 -2 -2\n-2 4 -2 -2\n-2 4 -2 -2",
"output": "NO"
},
{
"input": "3 1 3 1\n-3 1 3 1\n3 3 -3 1\n-3 1 3 1",
"output": "NO"
},
{
"input": "0 1 4 1\n0 1 4 1\n4 1 0 1\n0 -2 4 1",
"output": "NO"
},
{
"input": "0 -2 0 -1\n0 -1 0 -2\n0 -2 0 -2\n0 -2 0 -2",
"output": "NO"
},
{
"input": "-1 1 -1 1\n-1 1 -1 1\n-1 1 -1 3\n-3 1 -3 1",
"output": "NO"
},
{
"input": "578327678 518066351 578327678 498442467\n583129774 498442467 578327678 518066351\n583129774 518066351 578327678 518066351\n583129774 498442467 578327678 518066351",
"output": "NO"
},
{
"input": "-973576966 32484917 -973576966 32484917\n-973576966 32484917 347173379 32484917\n-973576966 32484917 347173379 32484917\n-973576966 32484917 347173379 32484917",
"output": "NO"
},
{
"input": "572793036 194804279 572793036 -866298887\n572793036 461349977 -860420833 194804279\n572793036 461349977 572793036 -866298887\n-860420833 461349977 572793036 -866298887",
"output": "NO"
},
{
"input": "949753871 -467933239 -72251156 462207752\n949753871 462207752 425479768 -467933239\n425479768 462207752 425479768 -467933239\n949753871 -467933239 949753871 462207752",
"output": "NO"
},
{
"input": "1 -1 1 -1\n-1 -1 -1 -1\n1 0 -1 -1\n1 -1 -1 -1",
"output": "NO"
},
{
"input": "1 -1 1 -1\n1 0 1 0\n1 0 1 -1\n1 0 1 -1",
"output": "NO"
},
{
"input": "0 0 0 1\n0 1 0 1\n0 1 0 0\n0 1 0 1",
"output": "NO"
},
{
"input": "1 -1 1 0\n1 0 1 0\n0 0 0 -1\n1 -1 1 0",
"output": "NO"
},
{
"input": "0 0 2 2\n0 0 2 0\n2 2 2 2\n0 2 0 2",
"output": "NO"
},
{
"input": "-2 -1 -1 -1\n-2 -1 -1 -1\n-2 -1 -2 2\n-2 2 -1 2",
"output": "NO"
},
{
"input": "2 1 -1 0\n-1 0 2 1\n2 1 2 1\n-1 0 2 1",
"output": "NO"
},
{
"input": "1 -1 2 -1\n1 -2 2 -2\n1 -2 2 -2\n1 -2 2 -2",
"output": "NO"
},
{
"input": "-1 -2 -1 2\n-1 -2 -1 -2\n-1 2 -1 2\n-1 -2 -1 -2",
"output": "NO"
},
{
"input": "2 0 2 -1\n2 -1 -1 0\n2 -1 -1 0\n2 -1 -1 0",
"output": "NO"
},
{
"input": "2 -3 1 3\n1 -3 1 3\n2 3 2 -3\n2 -3 2 -3",
"output": "NO"
},
{
"input": "130120899 550158649 130120899 831843953\n130120899 550158649 130120899 831843953\n130120899 550158649 434006978 831843953\n434006978 550158649 434006978 550158649",
"output": "NO"
},
{
"input": "-214484034 559719641 -214484034 559719641\n-214484034 559719641 -214484034 559719641\n-214484034 2764087 -214484034 559719641\n-214484034 2764087 734280017 2764087",
"output": "NO"
},
{
"input": "-966947426 664261857 -994206270 664261857\n-966947426 664261857 -994206270 664261857\n-966947426 789165019 -966947426 789165019\n-966947426 664261857 -966947426 789165019",
"output": "NO"
},
{
"input": "264411509 -329579381 264411509 -329579381\n-726758913 -329579381 264411509 357369289\n-726758913 -329579381 264411509 -329579381\n264411509 -329579381 264411509 -329579381",
"output": "NO"
},
{
"input": "-193720583 -547078093 -570748852 58725936\n-570748852 -547078093 -570748852 58725936\n-193720583 58725936 -570748852 -547078093\n-570748852 -547078093 -193720583 58725936",
"output": "NO"
},
{
"input": "-534094150 -333730697 120658438 -333730697\n-534094150 -333730697 120658438 869464313\n-534094150 -333730697 -534094150 -333730697\n-534094150 869464313 -534094150 -333730697",
"output": "NO"
},
{
"input": "-328545071 835751660 -345950135 835751660\n-345950135 243569491 -328545071 835751660\n-328545071 835751660 -345950135 243569491\n-328545071 243569491 -328545071 243569491",
"output": "NO"
},
{
"input": "-985236057 -809433993 -985236057 -225363622\n-484344733 -225363622 -484344733 -225363622\n-985236057 -225363622 -985236057 -809433993\n-484344733 -225363622 -484344733 -809433993",
"output": "NO"
},
{
"input": "774287068 919049158 774287068 919049158\n250033372 653817677 250033372 653817677\n250033372 919049158 774287068 653817677\n250033372 653817677 250033372 653817677",
"output": "NO"
},
{
"input": "15319063 -661389770 632904085 -661389770\n15319063 834266473 632904085 834266473\n15319063 834266473 15319063 -661389770\n632904085 -661389770 632904085 834266473",
"output": "YES"
},
{
"input": "157550209 -594704878 157550209 524666828\n671878188 -594704878 157550209 -594704878\n671878188 -594704878 671878188 524666828\n671878188 524666828 157550209 524666828",
"output": "YES"
},
{
"input": "-887135208 728202342 127569272 728202342\n127569272 728202342 127569272 -932260532\n-887135208 -932260532 -887135208 728202342\n127569272 -932260532 -887135208 -932260532",
"output": "YES"
},
{
"input": "-777411660 -392696120 -777411660 878250237\n461320023 878250237 -777411660 878250237\n461320023 878250237 461320023 -392696120\n461320023 -392696120 -777411660 -392696120",
"output": "YES"
},
{
"input": "-892785315 567101756 -892785315 212349618\n-403060667 212349618 -403060667 567101756\n-403060667 567101756 -892785315 567101756\n-892785315 212349618 -403060667 212349618",
"output": "YES"
},
{
"input": "-360046034 -871603961 -37695563 -871603961\n-37695563 664955871 -37695563 -871603961\n-360046034 664955871 -360046034 -871603961\n-360046034 664955871 -37695563 664955871",
"output": "YES"
},
{
"input": "375089524 -852468724 -952575952 -852468724\n-952575952 -852468724 -952575952 -883150295\n-952575952 -883150295 375089524 -883150295\n375089524 -852468724 375089524 -883150295",
"output": "YES"
},
{
"input": "851113265 -893293930 851113265 -444742025\n-864765585 -893293930 -864765585 -444742025\n-864765585 -893293930 851113265 -893293930\n-864765585 -444742025 851113265 -444742025",
"output": "YES"
},
{
"input": "-309306779 559081237 255096743 559081237\n-309306779 -359724178 255096743 -359724178\n255096743 -359724178 255096743 559081237\n-309306779 559081237 -309306779 -359724178",
"output": "YES"
},
{
"input": "542957347 -480242202 566995046 -480242202\n542957347 -480242202 542957347 -298569507\n566995046 -298569507 542957347 -298569507\n566995046 -298569507 566995046 -480242202",
"output": "YES"
},
{
"input": "724715871 -943657730 964573294 -943657730\n724715871 -943657730 724715871 -216459206\n964573294 -216459206 964573294 -943657730\n724715871 -216459206 964573294 -216459206",
"output": "YES"
},
{
"input": "-394306310 -279360055 -394306310 771835446\n-394306310 -279360055 -358661829 -279360055\n-358661829 771835446 -358661829 -279360055\n-358661829 771835446 -394306310 771835446",
"output": "YES"
},
{
"input": "-204472047 -894485730 -204472047 640004355\n960702643 -894485730 960702643 640004355\n960702643 -894485730 -204472047 -894485730\n-204472047 640004355 960702643 640004355",
"output": "YES"
},
{
"input": "747591 5158024 -837871358 5158024\n-837871358 -874026904 747591 -874026904\n747591 -874026904 747591 5158024\n-837871358 -874026904 -837871358 5158024",
"output": "YES"
},
{
"input": "-442585231 90863587 800882871 90863587\n800882871 288218107 800882871 90863587\n800882871 288218107 -442585231 288218107\n-442585231 90863587 -442585231 288218107",
"output": "YES"
},
{
"input": "-969490772 476931470 -969490772 929999730\n-426216863 929999730 -969490772 929999730\n-426216863 929999730 -426216863 476931470\n-969490772 476931470 -426216863 476931470",
"output": "YES"
},
{
"input": "-683046010 -125472203 -683046010 418507423\n817863270 418507423 817863270 -125472203\n817863270 418507423 -683046010 418507423\n817863270 -125472203 -683046010 -125472203",
"output": "YES"
},
{
"input": "231996287 974811621 -923122611 974811621\n-923122611 646880519 -923122611 974811621\n231996287 646880519 231996287 974811621\n-923122611 646880519 231996287 646880519",
"output": "YES"
},
{
"input": "-83429272 -350159212 -990378619 -350159212\n-990378619 -350159212 -990378619 247777831\n-83429272 -350159212 -83429272 247777831\n-990378619 247777831 -83429272 247777831",
"output": "YES"
},
{
"input": "-679599706 974881765 -679599706 -84192294\n-554774137 -84192294 -554774137 974881765\n-554774137 974881765 -679599706 974881765\n-554774137 -84192294 -679599706 -84192294",
"output": "YES"
},
{
"input": "-155221108 -190475340 -155221108 -819044368\n-155221108 -190475340 -155875856 -190475340\n-155875856 -190475340 -155875856 -819044368\n-155875856 -819044368 -155221108 -819044368",
"output": "YES"
},
{
"input": "377126871 -877660066 -633390329 -877660066\n377126871 -175686511 377126871 -877660066\n-633390329 -877660066 -633390329 -175686511\n-633390329 -175686511 377126871 -175686511",
"output": "YES"
},
{
"input": "919022298 897009314 77151365 897009314\n77151365 579795002 919022298 579795002\n77151365 579795002 77151365 897009314\n919022298 579795002 919022298 897009314",
"output": "YES"
},
{
"input": "146411776 -188986353 146411776 -808042296\n-381166510 -808042296 -381166510 -188986353\n146411776 -188986353 -381166510 -188986353\n146411776 -808042296 -381166510 -808042296",
"output": "YES"
},
{
"input": "438703475 871560515 571565350 871560515\n571565350 -204157747 438703475 -204157747\n438703475 -204157747 438703475 871560515\n571565350 -204157747 571565350 871560515",
"output": "YES"
},
{
"input": "0 0 0 0\n5 5 5 5\n5 0 5 5\n0 5 0 0",
"output": "NO"
},
{
"input": "0 1 1 2\n2 1 1 2\n1 0 0 1\n2 1 1 0",
"output": "NO"
},
{
"input": "-3 0 -3 3\n0 0 0 3\n3 3 -3 3\n3 0 -3 0",
"output": "NO"
},
{
"input": "0 0 0 0\n1 1 1 1\n0 1 0 1\n1 0 1 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 1 0\n1 1 1 1",
"output": "NO"
},
{
"input": "0 0 1 0\n1 1 0 1\n0 0 1 0\n1 1 0 1",
"output": "NO"
},
{
"input": "0 0 0 1\n0 1 1 1\n1 1 1 0\n1 0 0 1",
"output": "NO"
},
{
"input": "0 0 1 1\n0 1 1 0\n1 1 0 0\n1 0 0 1",
"output": "NO"
},
{
"input": "0 0 0 0\n1 1 1 1\n0 1 1 0\n1 0 0 1",
"output": "NO"
},
{
"input": "0 0 1 0\n0 1 1 1\n0 0 1 0\n0 1 1 1",
"output": "NO"
}
] | 1,691,593,741
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 3
| 62
| 0
|
# LUOGU_RID: 119974760
lines = []
for i in range(4):
x1, y1, x2, y2 = map(int, input().split())
x, y = abs(x1 - x2), abs(y1 - y2)
if y == 0:
lines.append(x)
else:
lines.append(-y)
li = list(set(lines))
if len(li) == 1:
print("YES")
elif len(li) != 2:
print("NO")
else:
if lines.count(li[0]) == 2:
print("YES")
else:
print("NO")
|
Title: Four Segments
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him.
Input Specification:
The input data contain four lines. Each of these lines contains four integers *x*1, *y*1, *x*2, *y*2 (<=-<=109<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points.
Output Specification:
Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO».
Demo Input:
['1 1 6 1\n1 0 6 0\n6 0 6 1\n1 1 1 0\n', '0 0 0 3\n2 0 0 0\n2 2 2 0\n0 2 2 2\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none
|
```python
# LUOGU_RID: 119974760
lines = []
for i in range(4):
x1, y1, x2, y2 = map(int, input().split())
x, y = abs(x1 - x2), abs(y1 - y2)
if y == 0:
lines.append(x)
else:
lines.append(-y)
li = list(set(lines))
if len(li) == 1:
print("YES")
elif len(li) != 2:
print("NO")
else:
if lines.count(li[0]) == 2:
print("YES")
else:
print("NO")
```
| 0
|
248
|
A
|
Cupboards
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on *n* wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.
And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.
Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds *t*, in which he is able to bring all the cupboard doors in the required position.
Your task is to write a program that will determine the required number of seconds *t*.
|
The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equals zero. Similarly, number *r**i* equals one, if the right door of the *i*-th cupboard is opened, otherwise number *r**i* equals zero.
The numbers in the lines are separated by single spaces.
|
In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
|
[
"5\n0 1\n1 0\n0 1\n1 1\n0 1\n"
] |
[
"3\n"
] |
none
| 500
|
[
{
"input": "5\n0 1\n1 0\n0 1\n1 1\n0 1",
"output": "3"
},
{
"input": "2\n0 0\n0 0",
"output": "0"
},
{
"input": "3\n0 1\n1 1\n1 1",
"output": "1"
},
{
"input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0",
"output": "7"
},
{
"input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 1\n1 1\n0 1",
"output": "6"
},
{
"input": "15\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "5\n1 0\n1 0\n1 0\n0 1\n0 1",
"output": "4"
}
] | 1,671,901,300
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 57
| 124
| 102,400
|
t=int(input())
l=[]
r=[]
for i in range(t):
l1,r1=list(map(int, input().split()))
l.append(l1)
r.append(r1)
l0=l.count(0)
l1=l.count(1)
r0=r.count(0)
r1=r.count(1)
print(min(l0,l1)+min(r0,r1))
|
Title: Cupboards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on *n* wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.
And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.
Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds *t*, in which he is able to bring all the cupboard doors in the required position.
Your task is to write a program that will determine the required number of seconds *t*.
Input Specification:
The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equals zero. Similarly, number *r**i* equals one, if the right door of the *i*-th cupboard is opened, otherwise number *r**i* equals zero.
The numbers in the lines are separated by single spaces.
Output Specification:
In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
Demo Input:
['5\n0 1\n1 0\n0 1\n1 1\n0 1\n']
Demo Output:
['3\n']
Note:
none
|
```python
t=int(input())
l=[]
r=[]
for i in range(t):
l1,r1=list(map(int, input().split()))
l.append(l1)
r.append(r1)
l0=l.count(0)
l1=l.count(1)
r0=r.count(0)
r1=r.count(1)
print(min(l0,l1)+min(r0,r1))
```
| 3
|
|
868
|
D
|
Huge Strings
|
PROGRAMMING
| 2,200
|
[
"bitmasks",
"brute force",
"dp",
"implementation",
"strings"
] | null | null |
You are given *n* strings *s*1,<=*s*2,<=...,<=*s**n* consisting of characters 0 and 1. *m* operations are performed, on each of them you concatenate two existing strings into a new one. On the *i*-th operation the concatenation *s**a**i**s**b**i* is saved into a new string *s**n*<=+<=*i* (the operations are numbered starting from 1). After each operation you need to find the maximum positive integer *k* such that all possible strings consisting of 0 and 1 of length *k* (there are 2*k* such strings) are substrings of the new string. If there is no such *k*, print 0.
|
The first line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of strings. The next *n* lines contain strings *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=|*s**i*|<=≤<=100), one per line. The total length of strings is not greater than 100.
The next line contains single integer *m* (1<=≤<=*m*<=≤<=100) — the number of operations. *m* lines follow, each of them contains two integers *a**i* abd *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*<=+<=*i*<=-<=1) — the number of strings that are concatenated to form *s**n*<=+<=*i*.
|
Print *m* lines, each should contain one integer — the answer to the question after the corresponding operation.
|
[
"5\n01\n10\n101\n11111\n0\n3\n1 2\n6 5\n4 4\n"
] |
[
"1\n2\n0\n"
] |
On the first operation, a new string "0110" is created. For *k* = 1 the two possible binary strings of length *k* are "0" and "1", they are substrings of the new string. For *k* = 2 and greater there exist strings of length *k* that do not appear in this string (for *k* = 2 such string is "00"). So the answer is 1.
On the second operation the string "01100" is created. Now all strings of length *k* = 2 are present.
On the third operation the string "1111111111" is created. There is no zero, so the answer is 0.
| 1,500
|
[
{
"input": "5\n01\n10\n101\n11111\n0\n3\n1 2\n6 5\n4 4",
"output": "1\n2\n0"
},
{
"input": "5\n01\n1\n0011\n0\n01\n6\n5 5\n3 2\n4 2\n6 7\n5 1\n9 7",
"output": "1\n1\n1\n2\n1\n2"
},
{
"input": "5\n111101000111100011100110000100\n000111001\n01101000\n0000110100100010011001000000010100100111110110\n0110001\n10\n5 5\n2 2\n5 6\n1 1\n1 7\n10 6\n6 2\n11 1\n3 6\n8 2",
"output": "2\n2\n2\n3\n3\n4\n3\n4\n2\n3"
},
{
"input": "1\n1\n1\n1 1",
"output": "0"
},
{
"input": "5\n110101010101010110000011011\n111111\n1000100011100111100101101010011111100000001001\n00\n1111101100001110000\n10\n4 3\n6 6\n7 5\n8 8\n8 7\n10 8\n11 9\n10 12\n13 13\n12 13",
"output": "4\n4\n4\n4\n4\n4\n4\n4\n4\n4"
},
{
"input": "5\n100010010\n0\n1001100110010111\n0001000011000111000011011000110000010010010001110001000011011\n0100000100100\n10\n5 5\n6 6\n6 7\n7 8\n8 9\n10 8\n11 9\n10 9\n12 13\n12 13",
"output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1"
},
{
"input": "5\n0\n1\n11\n110000010001100101001\n1101011011111\n10\n5 3\n6 4\n7 6\n8 7\n9 8\n10 9\n11 10\n12 11\n13 12\n14 13",
"output": "1\n4\n5\n5\n5\n5\n5\n5\n5\n5"
},
{
"input": "10\n0\n1\n1111100000\n0\n1\n0000\n11000\n1010001110010010110\n01101001111\n010101110110111111\n20\n10 3\n11 4\n12 5\n13 6\n14 7\n15 8\n16 9\n17 16\n18 17\n19 18\n20 19\n21 20\n22 21\n23 22\n24 23\n25 24\n26 25\n27 26\n28 27\n29 28",
"output": "2\n2\n3\n3\n3\n4\n5\n6\n6\n6\n6\n6\n6\n6\n6\n6\n6\n6\n6\n6"
},
{
"input": "10\n0\n1\n1111\n110000000\n100000\n1\n1\n000010100001110001\n00100010110001101000111100100110010101001011\n100110110011101\n50\n10 3\n11 4\n12 5\n13 6\n14 7\n15 8\n16 9\n17 1\n18 1\n19 2\n20 2\n21 2\n22 2\n23 2\n24 1\n25 2\n26 1\n27 2\n28 1\n29 2\n30 2\n31 1\n32 2\n33 1\n34 2\n35 2\n36 2\n37 2\n38 1\n39 2\n40 2\n41 1\n42 2\n43 2\n44 2\n45 1\n46 2\n47 2\n48 2\n49 2\n50 2\n51 2\n52 2\n53 52\n54 53\n55 54\n56 55\n57 56\n58 57\n59 58",
"output": "2\n2\n3\n3\n3\n4\n5\n5\n5\n5\n5\n5\n5\n5\n5\n5\n5\n5\n5\n5\n5\n5\n5\n5\n5\n5\n5\n5\n5\n5\n5\n5\n5\n5\n5\n6\n6\n6\n6\n6\n6\n6\n6\n6\n6\n6\n6\n6\n6\n6"
},
{
"input": "2\n001010011100101110111\n001100110011001100110011001100110011001100110011001100111001\n14\n1 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15",
"output": "2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2"
},
{
"input": "2\n1\n0\n40\n1 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41",
"output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1"
},
{
"input": "2\n011\n100\n63\n1 1\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n2 2\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n61 61\n62 62\n63 63\n33 64",
"output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n2"
},
{
"input": "1\n0000000000000000000000000000000000000000000000000000000000000000\n25\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25",
"output": "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0"
}
] | 1,570,803,378
| 7,878
|
Python 3
|
MEMORY_LIMIT_EXCEEDED
|
TESTS
| 20
| 810
| 268,390,400
|
n = int(input())
data = []
for i in range(n):
data.append(input())
m = int(input())
for q in range(m):
u, v = map(int, input().split())
tmp = data[u-1] + data[v-1]
data.append(tmp)
for k in range(1, 100):
flag = True
for j in range(0, 2**k):
b = bin(j)[2:]
b = "0"*(k-len(b)) + b
if b not in tmp:
flag = False
break
if not flag:
print(k-1)
break
|
Title: Huge Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* strings *s*1,<=*s*2,<=...,<=*s**n* consisting of characters 0 and 1. *m* operations are performed, on each of them you concatenate two existing strings into a new one. On the *i*-th operation the concatenation *s**a**i**s**b**i* is saved into a new string *s**n*<=+<=*i* (the operations are numbered starting from 1). After each operation you need to find the maximum positive integer *k* such that all possible strings consisting of 0 and 1 of length *k* (there are 2*k* such strings) are substrings of the new string. If there is no such *k*, print 0.
Input Specification:
The first line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of strings. The next *n* lines contain strings *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=|*s**i*|<=≤<=100), one per line. The total length of strings is not greater than 100.
The next line contains single integer *m* (1<=≤<=*m*<=≤<=100) — the number of operations. *m* lines follow, each of them contains two integers *a**i* abd *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*<=+<=*i*<=-<=1) — the number of strings that are concatenated to form *s**n*<=+<=*i*.
Output Specification:
Print *m* lines, each should contain one integer — the answer to the question after the corresponding operation.
Demo Input:
['5\n01\n10\n101\n11111\n0\n3\n1 2\n6 5\n4 4\n']
Demo Output:
['1\n2\n0\n']
Note:
On the first operation, a new string "0110" is created. For *k* = 1 the two possible binary strings of length *k* are "0" and "1", they are substrings of the new string. For *k* = 2 and greater there exist strings of length *k* that do not appear in this string (for *k* = 2 such string is "00"). So the answer is 1.
On the second operation the string "01100" is created. Now all strings of length *k* = 2 are present.
On the third operation the string "1111111111" is created. There is no zero, so the answer is 0.
|
```python
n = int(input())
data = []
for i in range(n):
data.append(input())
m = int(input())
for q in range(m):
u, v = map(int, input().split())
tmp = data[u-1] + data[v-1]
data.append(tmp)
for k in range(1, 100):
flag = True
for j in range(0, 2**k):
b = bin(j)[2:]
b = "0"*(k-len(b)) + b
if b not in tmp:
flag = False
break
if not flag:
print(k-1)
break
```
| 0
|
|
219
|
D
|
Choosing Capital for Treeland
|
PROGRAMMING
| 1,700
|
[
"dfs and similar",
"dp",
"graphs",
"trees"
] | null | null |
The country Treeland consists of *n* cities, some pairs of them are connected with unidirectional roads. Overall there are *n*<=-<=1 roads in the country. We know that if we don't take the direction of the roads into consideration, we can get from any city to any other one.
The council of the elders has recently decided to choose the capital of Treeland. Of course it should be a city of this country. The council is supposed to meet in the capital and regularly move from the capital to other cities (at this stage nobody is thinking about getting back to the capital from these cities). For that reason if city *a* is chosen a capital, then all roads must be oriented so that if we move along them, we can get from city *a* to any other city. For that some roads may have to be inversed.
Help the elders to choose the capital so that they have to inverse the minimum number of roads in the country.
|
The first input line contains integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of cities in Treeland. Next *n*<=-<=1 lines contain the descriptions of the roads, one road per line. A road is described by a pair of integers *s**i*,<=*t**i* (1<=≤<=*s**i*,<=*t**i*<=≤<=*n*; *s**i*<=≠<=*t**i*) — the numbers of cities, connected by that road. The *i*-th road is oriented from city *s**i* to city *t**i*. You can consider cities in Treeland indexed from 1 to *n*.
|
In the first line print the minimum number of roads to be inversed if the capital is chosen optimally. In the second line print all possible ways to choose the capital — a sequence of indexes of cities in the increasing order.
|
[
"3\n2 1\n2 3\n",
"4\n1 4\n2 4\n3 4\n"
] |
[
"0\n2 \n",
"2\n1 2 3 \n"
] |
none
| 2,000
|
[
{
"input": "3\n2 1\n2 3",
"output": "0\n2 "
},
{
"input": "4\n1 4\n2 4\n3 4",
"output": "2\n1 2 3 "
},
{
"input": "2\n1 2",
"output": "0\n1 "
},
{
"input": "8\n1 2\n3 2\n4 3\n4 5\n6 5\n6 7\n8 7",
"output": "3\n4 6 8 "
},
{
"input": "10\n2 3\n1 8\n9 5\n5 4\n6 10\n4 8\n5 6\n7 6\n5 3",
"output": "3\n9 "
},
{
"input": "10\n9 3\n3 8\n4 3\n3 5\n7 8\n10 3\n2 3\n6 2\n3 1",
"output": "4\n6 "
},
{
"input": "10\n5 4\n6 5\n10 1\n2 5\n9 8\n1 3\n7 10\n2 3\n5 9",
"output": "2\n7 "
},
{
"input": "10\n2 3\n1 8\n9 5\n5 4\n6 10\n4 8\n5 6\n7 6\n5 3",
"output": "3\n9 "
},
{
"input": "11\n3 10\n4 7\n11 7\n8 2\n6 9\n9 3\n5 9\n1 3\n3 8\n7 3",
"output": "5\n4 5 6 11 "
},
{
"input": "12\n10 7\n6 10\n8 10\n4 12\n10 4\n3 12\n1 2\n2 7\n4 5\n11 5\n11 9",
"output": "5\n1 6 8 "
},
{
"input": "13\n7 13\n5 4\n5 1\n11 12\n8 3\n13 4\n10 7\n11 5\n8 13\n2 8\n10 6\n4 9",
"output": "4\n2 10 "
},
{
"input": "14\n13 10\n5 14\n9 4\n8 12\n10 1\n5 2\n3 6\n11 2\n13 2\n13 7\n8 2\n4 5\n1 3",
"output": "3\n9 "
},
{
"input": "15\n15 6\n2 15\n14 15\n15 12\n1 2\n10 15\n7 4\n13 7\n11 2\n5 2\n7 2\n3 2\n7 8\n9 15",
"output": "7\n13 "
}
] | 1,678,200,348
| 2,147,483,647
|
PyPy 3-64
|
RUNTIME_ERROR
|
TESTS
| 7
| 2,464
| 41,574,400
|
def solve():
n = int(input())
g = [[] for _ in range(n+1)]
for _ in range(n-1):
v, w = list(map(int, input().split()))
g[v].append((w, 1))
g[w].append((v, -1))
rev1 = 0
def f(v, fa):
nonlocal rev1
for to, dir in g[v]:
if to != fa:
if dir < 0:
rev1 += 1
f(to, v)
f(1, 0)
mn, ans = rev1, []
def reroot(v, fa, rev):
nonlocal mn, ans
if rev < mn:
mn = rev
ans = [v]
elif rev == mn:
ans.append(v)
for to, dir in g[v]:
if to != fa:
reroot(to, v, rev+dir)
reroot(1, 0, rev1)
print(mn)
ans.sort()
print(' '.join(map(str, ans)))
if __name__ == "__main__":
solve()
|
Title: Choosing Capital for Treeland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The country Treeland consists of *n* cities, some pairs of them are connected with unidirectional roads. Overall there are *n*<=-<=1 roads in the country. We know that if we don't take the direction of the roads into consideration, we can get from any city to any other one.
The council of the elders has recently decided to choose the capital of Treeland. Of course it should be a city of this country. The council is supposed to meet in the capital and regularly move from the capital to other cities (at this stage nobody is thinking about getting back to the capital from these cities). For that reason if city *a* is chosen a capital, then all roads must be oriented so that if we move along them, we can get from city *a* to any other city. For that some roads may have to be inversed.
Help the elders to choose the capital so that they have to inverse the minimum number of roads in the country.
Input Specification:
The first input line contains integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of cities in Treeland. Next *n*<=-<=1 lines contain the descriptions of the roads, one road per line. A road is described by a pair of integers *s**i*,<=*t**i* (1<=≤<=*s**i*,<=*t**i*<=≤<=*n*; *s**i*<=≠<=*t**i*) — the numbers of cities, connected by that road. The *i*-th road is oriented from city *s**i* to city *t**i*. You can consider cities in Treeland indexed from 1 to *n*.
Output Specification:
In the first line print the minimum number of roads to be inversed if the capital is chosen optimally. In the second line print all possible ways to choose the capital — a sequence of indexes of cities in the increasing order.
Demo Input:
['3\n2 1\n2 3\n', '4\n1 4\n2 4\n3 4\n']
Demo Output:
['0\n2 \n', '2\n1 2 3 \n']
Note:
none
|
```python
def solve():
n = int(input())
g = [[] for _ in range(n+1)]
for _ in range(n-1):
v, w = list(map(int, input().split()))
g[v].append((w, 1))
g[w].append((v, -1))
rev1 = 0
def f(v, fa):
nonlocal rev1
for to, dir in g[v]:
if to != fa:
if dir < 0:
rev1 += 1
f(to, v)
f(1, 0)
mn, ans = rev1, []
def reroot(v, fa, rev):
nonlocal mn, ans
if rev < mn:
mn = rev
ans = [v]
elif rev == mn:
ans.append(v)
for to, dir in g[v]:
if to != fa:
reroot(to, v, rev+dir)
reroot(1, 0, rev1)
print(mn)
ans.sort()
print(' '.join(map(str, ans)))
if __name__ == "__main__":
solve()
```
| -1
|
|
688
|
B
|
Lovely Palindromes
|
PROGRAMMING
| 1,000
|
[
"constructive algorithms",
"math"
] | null | null |
Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindrome numbers. Pari loves integers with even length (i.e. the numbers with even number of digits), so she tries to see a lot of big palindrome numbers with even length (like a 2-digit 11 or 6-digit 122221), so maybe she could see something in them.
Now Pari asks you to write a program that gets a huge integer *n* from the input and tells what is the *n*-th even-length positive palindrome number?
|
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10100<=000).
|
Print the *n*-th even-length palindrome number.
|
[
"1\n",
"10\n"
] |
[
"11\n",
"1001\n"
] |
The first 10 even-length palindrome numbers are 11, 22, 33, ... , 88, 99 and 1001.
| 1,000
|
[
{
"input": "1",
"output": "11"
},
{
"input": "10",
"output": "1001"
},
{
"input": "11",
"output": "1111"
},
{
"input": "12",
"output": "1221"
},
{
"input": "100",
"output": "100001"
},
{
"input": "1321",
"output": "13211231"
},
{
"input": "2",
"output": "22"
},
{
"input": "3",
"output": "33"
},
{
"input": "4",
"output": "44"
},
{
"input": "5",
"output": "55"
},
{
"input": "6",
"output": "66"
},
{
"input": "7",
"output": "77"
},
{
"input": "8",
"output": "88"
},
{
"input": "9",
"output": "99"
},
{
"input": "13",
"output": "1331"
},
{
"input": "14",
"output": "1441"
},
{
"input": "15",
"output": "1551"
},
{
"input": "16",
"output": "1661"
},
{
"input": "17",
"output": "1771"
},
{
"input": "18",
"output": "1881"
},
{
"input": "19",
"output": "1991"
},
{
"input": "20",
"output": "2002"
},
{
"input": "26550",
"output": "2655005562"
},
{
"input": "16137",
"output": "1613773161"
},
{
"input": "91471",
"output": "9147117419"
},
{
"input": "41242",
"output": "4124224214"
},
{
"input": "30866",
"output": "3086666803"
},
{
"input": "4442231232741003009964183199713851566466079882929007253443848371978048610682180431295671905105980116",
"output": "44422312327410030099641831997138515664660798829290072534438483719780486106821804312956719051059801166110895015091765921340812860168408791738483443527009292889706646651583179913814699003001472321322444"
},
{
"input": "7806526084732010742850470902979267046151204705563201965818390803445852115032119297648697933316807252",
"output": "78065260847320107428504709029792670461512047055632019658183908034458521150321192976486979333168072522527086133397968467929112305112585443080938185691023655074021516407629792090740582470102374806256087"
},
{
"input": "2244399823612183124978103773977739948197709395321563148611877999503840818596183803323258317041875913",
"output": "22443998236121831249781037739777399481977093953215631486118779995038408185961838033232583170418759133195781407138523233083816958180483059997781168413651235939077918499377793773018794213812163289934422"
},
{
"input": "123451",
"output": "123451154321"
}
] | 1,674,999,581
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 40
| 187
| 8,396,800
|
n = int(input())
n = str(n)
nn = n[::-1]
res = ''
res += n
res += nn
print(res)
|
Title: Lovely Palindromes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindrome numbers. Pari loves integers with even length (i.e. the numbers with even number of digits), so she tries to see a lot of big palindrome numbers with even length (like a 2-digit 11 or 6-digit 122221), so maybe she could see something in them.
Now Pari asks you to write a program that gets a huge integer *n* from the input and tells what is the *n*-th even-length positive palindrome number?
Input Specification:
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10100<=000).
Output Specification:
Print the *n*-th even-length palindrome number.
Demo Input:
['1\n', '10\n']
Demo Output:
['11\n', '1001\n']
Note:
The first 10 even-length palindrome numbers are 11, 22, 33, ... , 88, 99 and 1001.
|
```python
n = int(input())
n = str(n)
nn = n[::-1]
res = ''
res += n
res += nn
print(res)
```
| 3
|
|
758
|
A
|
Holiday Of Equality
|
PROGRAMMING
| 800
|
[
"implementation",
"math"
] | null | null |
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.
|
The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen.
|
In the only line print the integer *S* — the minimum number of burles which are had to spend.
|
[
"5\n0 1 2 3 4\n",
"5\n1 1 0 1 1\n",
"3\n1 3 1\n",
"1\n12\n"
] |
[
"10",
"1",
"4",
"0"
] |
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.
In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles.
| 500
|
[
{
"input": "5\n0 1 2 3 4",
"output": "10"
},
{
"input": "5\n1 1 0 1 1",
"output": "1"
},
{
"input": "3\n1 3 1",
"output": "4"
},
{
"input": "1\n12",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "14\n52518 718438 358883 462189 853171 592966 225788 46977 814826 295697 676256 561479 56545 764281",
"output": "5464380"
},
{
"input": "21\n842556 216391 427181 626688 775504 168309 851038 448402 880826 73697 593338 519033 135115 20128 424606 939484 846242 756907 377058 241543 29353",
"output": "9535765"
},
{
"input": "3\n1 3 2",
"output": "3"
},
{
"input": "3\n2 1 3",
"output": "3"
},
{
"input": "3\n2 3 1",
"output": "3"
},
{
"input": "3\n3 1 2",
"output": "3"
},
{
"input": "3\n3 2 1",
"output": "3"
},
{
"input": "1\n228503",
"output": "0"
},
{
"input": "2\n32576 550340",
"output": "517764"
},
{
"input": "3\n910648 542843 537125",
"output": "741328"
},
{
"input": "4\n751720 572344 569387 893618",
"output": "787403"
},
{
"input": "6\n433864 631347 597596 794426 713555 231193",
"output": "1364575"
},
{
"input": "9\n31078 645168 695751 126111 375934 150495 838412 434477 993107",
"output": "4647430"
},
{
"input": "30\n315421 772664 560686 654312 151528 356749 351486 707462 820089 226682 546700 136028 824236 842130 578079 337807 665903 764100 617900 822937 992759 591749 651310 742085 767695 695442 17967 515106 81059 186025",
"output": "13488674"
},
{
"input": "45\n908719 394261 815134 419990 926993 383792 772842 277695 527137 655356 684956 695716 273062 550324 106247 399133 442382 33076 462920 294674 846052 817752 421365 474141 290471 358990 109812 74492 543281 169434 919692 786809 24028 197184 310029 801476 699355 429672 51343 374128 776726 850380 293868 981569 550763",
"output": "21993384"
},
{
"input": "56\n100728 972537 13846 385421 756708 184642 259487 319707 376662 221694 675284 972837 499419 13846 38267 289898 901299 831197 954715 197515 514102 910423 127555 883934 362472 870788 538802 741008 973434 448124 391526 363321 947321 544618 68006 782313 955075 741981 815027 723297 585059 718114 700739 413489 454091 736144 308999 98065 3716 347323 9635 289003 986510 607065 60236 273351",
"output": "26984185"
},
{
"input": "70\n644488 5444 150441 714420 602059 335330 510670 196555 546346 740011 509449 850947 692874 524857 750434 952985 223744 374727 896124 753037 367352 679050 560202 172728 569291 778616 332116 286927 843598 372698 244906 498046 900681 709791 420904 724593 864493 813094 791377 39998 296710 625656 403891 579231 706693 984045 16901 574259 562265 761104 930361 256045 124461 538980 573508 372148 988722 108592 784354 55302 232524 277205 782251 299943 436488 743389 324618 742543 266915 99642",
"output": "32816391"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n1000000",
"output": "0"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "100\n1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "99000000"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000",
"output": "99000000"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "99000000"
},
{
"input": "3\n0 0 0",
"output": "0"
},
{
"input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "3\n5 0 0",
"output": "10"
},
{
"input": "5\n2 10 0 0 0",
"output": "38"
}
] | 1,686,016,579
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 41
| 46
| 0
|
_ = input()
l_w = list(map(int, input().split()))
m = max(l_w)
t = 0
for w in l_w:
t += m - w
print(t)
|
Title: Holiday Of Equality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.
Input Specification:
The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen.
Output Specification:
In the only line print the integer *S* — the minimum number of burles which are had to spend.
Demo Input:
['5\n0 1 2 3 4\n', '5\n1 1 0 1 1\n', '3\n1 3 1\n', '1\n12\n']
Demo Output:
['10', '1', '4', '0']
Note:
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.
In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles.
|
```python
_ = input()
l_w = list(map(int, input().split()))
m = max(l_w)
t = 0
for w in l_w:
t += m - w
print(t)
```
| 3
|
|
116
|
A
|
Tram
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.
Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
|
The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement.
- The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0.
|
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
|
[
"4\n0 3\n2 5\n4 2\n4 0\n"
] |
[
"6\n"
] |
For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints.
Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
| 500
|
[
{
"input": "4\n0 3\n2 5\n4 2\n4 0",
"output": "6"
},
{
"input": "5\n0 4\n4 6\n6 5\n5 4\n4 0",
"output": "6"
},
{
"input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0",
"output": "18"
},
{
"input": "3\n0 1\n1 1\n1 0",
"output": "1"
},
{
"input": "4\n0 1\n0 1\n1 0\n1 0",
"output": "2"
},
{
"input": "3\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "3\n0 1000\n1000 1000\n1000 0",
"output": "1000"
},
{
"input": "5\n0 73\n73 189\n189 766\n766 0\n0 0",
"output": "766"
},
{
"input": "5\n0 0\n0 0\n0 0\n0 1\n1 0",
"output": "1"
},
{
"input": "5\n0 917\n917 923\n904 992\n1000 0\n11 0",
"output": "1011"
},
{
"input": "5\n0 1\n1 2\n2 1\n1 2\n2 0",
"output": "2"
},
{
"input": "5\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "20\n0 7\n2 1\n2 2\n5 7\n2 6\n6 10\n2 4\n0 4\n7 4\n8 0\n10 6\n2 1\n6 1\n1 7\n0 3\n8 7\n6 3\n6 3\n1 1\n3 0",
"output": "22"
},
{
"input": "5\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0",
"output": "1000"
},
{
"input": "10\n0 592\n258 598\n389 203\n249 836\n196 635\n478 482\n994 987\n1000 0\n769 0\n0 0",
"output": "1776"
},
{
"input": "10\n0 1\n1 0\n0 0\n0 0\n0 0\n0 1\n1 1\n0 1\n1 0\n1 0",
"output": "2"
},
{
"input": "10\n0 926\n926 938\n938 931\n931 964\n937 989\n983 936\n908 949\n997 932\n945 988\n988 0",
"output": "1016"
},
{
"input": "10\n0 1\n1 2\n1 2\n2 2\n2 2\n2 2\n1 1\n1 1\n2 1\n2 0",
"output": "3"
},
{
"input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "10\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0",
"output": "1000"
},
{
"input": "50\n0 332\n332 268\n268 56\n56 711\n420 180\n160 834\n149 341\n373 777\n763 93\n994 407\n86 803\n700 132\n471 608\n429 467\n75 5\n638 305\n405 853\n316 478\n643 163\n18 131\n648 241\n241 766\n316 847\n640 380\n923 759\n789 41\n125 421\n421 9\n9 388\n388 829\n408 108\n462 856\n816 411\n518 688\n290 7\n405 912\n397 772\n396 652\n394 146\n27 648\n462 617\n514 433\n780 35\n710 705\n460 390\n194 508\n643 56\n172 469\n1000 0\n194 0",
"output": "2071"
},
{
"input": "50\n0 0\n0 1\n1 1\n0 1\n0 0\n1 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 1\n1 0\n0 1\n0 0\n1 1\n1 0\n0 1\n0 0\n1 1\n0 1\n1 0\n1 1\n1 0\n0 0\n1 1\n1 0\n0 1\n0 0\n0 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 0\n0 1\n1 0\n0 0\n0 1\n1 1\n1 1\n0 1\n0 0\n1 0\n1 0",
"output": "3"
},
{
"input": "50\n0 926\n926 971\n915 980\n920 965\n954 944\n928 952\n955 980\n916 980\n906 935\n944 913\n905 923\n912 922\n965 934\n912 900\n946 930\n931 983\n979 905\n925 969\n924 926\n910 914\n921 977\n934 979\n962 986\n942 909\n976 903\n982 982\n991 941\n954 929\n902 980\n947 983\n919 924\n917 943\n916 905\n907 913\n964 977\n984 904\n905 999\n950 970\n986 906\n993 970\n960 994\n963 983\n918 986\n980 900\n931 986\n993 997\n941 909\n907 909\n1000 0\n278 0",
"output": "1329"
},
{
"input": "2\n0 863\n863 0",
"output": "863"
},
{
"input": "50\n0 1\n1 2\n2 2\n1 1\n1 1\n1 2\n1 2\n1 1\n1 2\n1 1\n1 1\n1 2\n1 2\n1 1\n2 1\n2 2\n1 2\n2 2\n1 2\n2 1\n2 1\n2 2\n2 1\n1 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n2 2\n2 1\n1 2\n2 2\n1 2\n1 1\n1 1\n2 1\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n1 2\n1 2\n2 0\n2 0\n2 0\n0 0",
"output": "8"
},
{
"input": "50\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "100\n0 1\n0 0\n0 0\n1 0\n0 0\n0 1\n0 1\n1 1\n0 0\n0 0\n1 1\n0 0\n1 1\n0 1\n1 1\n0 1\n1 1\n1 0\n1 0\n0 0\n1 0\n0 1\n1 0\n0 0\n0 0\n1 1\n1 1\n0 1\n0 0\n1 0\n1 1\n0 1\n1 0\n1 1\n0 1\n1 1\n1 0\n0 0\n0 0\n0 1\n0 0\n0 1\n1 1\n0 0\n1 1\n1 1\n0 0\n0 1\n1 0\n0 1\n0 0\n0 1\n0 1\n1 1\n1 1\n1 1\n0 0\n0 0\n1 1\n0 1\n0 1\n1 0\n0 0\n0 0\n1 1\n0 1\n0 1\n1 1\n1 1\n0 1\n1 1\n1 1\n0 0\n1 0\n0 1\n0 0\n0 0\n1 1\n1 1\n1 1\n1 1\n0 1\n1 0\n1 0\n1 0\n1 0\n1 0\n0 0\n1 0\n1 0\n0 0\n1 0\n0 0\n0 1\n1 0\n0 1\n1 0\n1 0\n1 0\n1 0",
"output": "11"
},
{
"input": "100\n0 2\n1 2\n2 1\n1 2\n1 2\n2 1\n2 2\n1 1\n1 1\n2 1\n1 2\n2 1\n1 2\n2 2\n2 2\n2 2\n1 2\n2 2\n2 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 2\n1 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n1 1\n2 2\n2 1\n1 2\n1 1\n1 2\n2 1\n2 2\n1 1\n2 1\n1 1\n2 1\n1 1\n1 2\n2 2\n2 2\n1 1\n2 2\n1 2\n2 1\n2 1\n1 1\n1 1\n1 2\n1 2\n1 1\n1 1\n2 1\n1 2\n1 2\n2 1\n2 2\n2 2\n2 2\n2 1\n2 2\n1 1\n1 2\n1 2\n1 1\n2 2\n2 2\n1 1\n2 1\n1 1\n1 2\n1 2\n1 2\n1 1\n1 1\n2 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 1\n2 2\n1 2\n2 0\n2 0\n2 0\n1 0",
"output": "7"
},
{
"input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "2\n0 1\n1 0",
"output": "1"
},
{
"input": "2\n0 900\n900 0",
"output": "900"
},
{
"input": "2\n0 1\n1 0",
"output": "1"
},
{
"input": "2\n0 0\n0 0",
"output": "0"
},
{
"input": "2\n0 1000\n1000 0",
"output": "1000"
},
{
"input": "3\n0 802\n175 188\n815 0",
"output": "815"
},
{
"input": "3\n0 910\n910 976\n976 0",
"output": "976"
},
{
"input": "3\n0 2\n2 1\n1 0",
"output": "2"
}
] | 1,691,142,648
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 62
| 0
|
n= int(input())
capacity=0
current=0
while(n):
a=int(input())
b=int(input())
current=current-a
current=current+b
if(current>capacity):
capacity=current
n-=1
print(capacity)
|
Title: Tram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.
Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
Input Specification:
The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement.
- The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0.
Output Specification:
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
Demo Input:
['4\n0 3\n2 5\n4 2\n4 0\n']
Demo Output:
['6\n']
Note:
For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints.
Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
|
```python
n= int(input())
capacity=0
current=0
while(n):
a=int(input())
b=int(input())
current=current-a
current=current+b
if(current>capacity):
capacity=current
n-=1
print(capacity)
```
| -1
|
|
999
|
F
|
Cards and Joy
|
PROGRAMMING
| 2,000
|
[
"dp"
] | null | null |
There are $n$ players sitting at the card table. Each player has a favorite number. The favorite number of the $j$-th player is $f_j$.
There are $k \cdot n$ cards on the table. Each card contains a single integer: the $i$-th card contains number $c_i$. Also, you are given a sequence $h_1, h_2, \dots, h_k$. Its meaning will be explained below.
The players have to distribute all the cards in such a way that each of them will hold exactly $k$ cards. After all the cards are distributed, each player counts the number of cards he has that contains his favorite number. The joy level of a player equals $h_t$ if the player holds $t$ cards containing his favorite number. If a player gets no cards with his favorite number (i.e., $t=0$), his joy level is $0$.
Print the maximum possible total joy levels of the players after the cards are distributed. Note that the sequence $h_1, \dots, h_k$ is the same for all the players.
|
The first line of input contains two integers $n$ and $k$ ($1 \le n \le 500, 1 \le k \le 10$) — the number of players and the number of cards each player will get.
The second line contains $k \cdot n$ integers $c_1, c_2, \dots, c_{k \cdot n}$ ($1 \le c_i \le 10^5$) — the numbers written on the cards.
The third line contains $n$ integers $f_1, f_2, \dots, f_n$ ($1 \le f_j \le 10^5$) — the favorite numbers of the players.
The fourth line contains $k$ integers $h_1, h_2, \dots, h_k$ ($1 \le h_t \le 10^5$), where $h_t$ is the joy level of a player if he gets exactly $t$ cards with his favorite number written on them. It is guaranteed that the condition $h_{t - 1} < h_t$ holds for each $t \in [2..k]$.
|
Print one integer — the maximum possible total joy levels of the players among all possible card distributions.
|
[
"4 3\n1 3 2 8 5 5 8 2 2 8 5 2\n1 2 2 5\n2 6 7\n",
"3 3\n9 9 9 9 9 9 9 9 9\n1 2 3\n1 2 3\n"
] |
[
"21\n",
"0\n"
] |
In the first example, one possible optimal card distribution is the following:
- Player $1$ gets cards with numbers $[1, 3, 8]$; - Player $2$ gets cards with numbers $[2, 2, 8]$; - Player $3$ gets cards with numbers $[2, 2, 8]$; - Player $4$ gets cards with numbers $[5, 5, 5]$.
Thus, the answer is $2 + 6 + 6 + 7 = 21$.
In the second example, no player can get a card with his favorite number. Thus, the answer is $0$.
| 0
|
[
{
"input": "4 3\n1 3 2 8 5 5 8 2 2 8 5 2\n1 2 2 5\n2 6 7",
"output": "21"
},
{
"input": "3 3\n9 9 9 9 9 9 9 9 9\n1 2 3\n1 2 3",
"output": "0"
},
{
"input": "1 1\n1\n2\n1",
"output": "0"
},
{
"input": "1 1\n1\n1\n1",
"output": "1"
},
{
"input": "1 1\n1\n1\n100000",
"output": "100000"
},
{
"input": "50 1\n52 96 99 37 143 148 10 140 131 29 82 134 56 73 121 57 98 101 134 4 103 10 86 70 4 98 102 35 149 47 136 87 4 127 142 105 78 10 123 75 67 149 81 78 34 79 62 12 43 115\n31 132 59 75 4 135 138 33 33 60 135 5 30 127 61 74 102 131 11 16 74 4 101 74 70 45 29 12 137 59 24 52 25 122 64 147 92 77 23 6 19 76 26 55 126 130 4 148 86 3\n94393",
"output": "1321502"
},
{
"input": "50 1\n995 1815 941 1716 725 1098 747 627 1728 1007 34 1001 679 1742 22 1495 1299 1696 507 631 1971 775 1052 1665 1035 203 1564 1329 1592 1295 983 177 734 1442 172 943 33 486 1078 946 947 592 1524 563 396 1541 1670 326 543 79\n176 214 1601 1758 1468 972 628 1524 1506 425 746 309 387 1761 1002 625 496 1638 1855 1115 47 1813 1258 289 891 518 1247 1782 788 1449 1174 183 899 1728 366 1270 1641 327 1839 1093 223 1005 1214 1866 1432 1715 25 1240 1234 324\n52314",
"output": "104628"
}
] | 1,659,840,195
| 2,147,483,647
|
PyPy 3-64
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 2
| 2,000
| 63,385,600
|
from collections import *
from heapq import *
from bisect import *
from itertools import *
from functools import *
from math import *
from string import *
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
cards = list(map(int, input().split()))
favorites = list(map(int, input().split()))
score = [0] + list(map(int, input().split()))
def neighbors(i, mask):
choices = [i for i in range(len(cards)) if mask & (1 << i) == 0]
for group in combinations(choices, k):
nmask = mask
count = 0
for j in group:
nmask |= 1 << j
count += cards[j] == favorites[i]
yield score[count], nmask
@cache
def dp(i, mask):
if i == n:
assert mask == (1 << (n * k)) - 1
return 0
ans = 0
for cost, nmask in neighbors(i, mask):
ans = max(ans, cost + dp(i + 1, nmask))
return ans
print(dp(0, 0))
|
Title: Cards and Joy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are $n$ players sitting at the card table. Each player has a favorite number. The favorite number of the $j$-th player is $f_j$.
There are $k \cdot n$ cards on the table. Each card contains a single integer: the $i$-th card contains number $c_i$. Also, you are given a sequence $h_1, h_2, \dots, h_k$. Its meaning will be explained below.
The players have to distribute all the cards in such a way that each of them will hold exactly $k$ cards. After all the cards are distributed, each player counts the number of cards he has that contains his favorite number. The joy level of a player equals $h_t$ if the player holds $t$ cards containing his favorite number. If a player gets no cards with his favorite number (i.e., $t=0$), his joy level is $0$.
Print the maximum possible total joy levels of the players after the cards are distributed. Note that the sequence $h_1, \dots, h_k$ is the same for all the players.
Input Specification:
The first line of input contains two integers $n$ and $k$ ($1 \le n \le 500, 1 \le k \le 10$) — the number of players and the number of cards each player will get.
The second line contains $k \cdot n$ integers $c_1, c_2, \dots, c_{k \cdot n}$ ($1 \le c_i \le 10^5$) — the numbers written on the cards.
The third line contains $n$ integers $f_1, f_2, \dots, f_n$ ($1 \le f_j \le 10^5$) — the favorite numbers of the players.
The fourth line contains $k$ integers $h_1, h_2, \dots, h_k$ ($1 \le h_t \le 10^5$), where $h_t$ is the joy level of a player if he gets exactly $t$ cards with his favorite number written on them. It is guaranteed that the condition $h_{t - 1} < h_t$ holds for each $t \in [2..k]$.
Output Specification:
Print one integer — the maximum possible total joy levels of the players among all possible card distributions.
Demo Input:
['4 3\n1 3 2 8 5 5 8 2 2 8 5 2\n1 2 2 5\n2 6 7\n', '3 3\n9 9 9 9 9 9 9 9 9\n1 2 3\n1 2 3\n']
Demo Output:
['21\n', '0\n']
Note:
In the first example, one possible optimal card distribution is the following:
- Player $1$ gets cards with numbers $[1, 3, 8]$; - Player $2$ gets cards with numbers $[2, 2, 8]$; - Player $3$ gets cards with numbers $[2, 2, 8]$; - Player $4$ gets cards with numbers $[5, 5, 5]$.
Thus, the answer is $2 + 6 + 6 + 7 = 21$.
In the second example, no player can get a card with his favorite number. Thus, the answer is $0$.
|
```python
from collections import *
from heapq import *
from bisect import *
from itertools import *
from functools import *
from math import *
from string import *
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
cards = list(map(int, input().split()))
favorites = list(map(int, input().split()))
score = [0] + list(map(int, input().split()))
def neighbors(i, mask):
choices = [i for i in range(len(cards)) if mask & (1 << i) == 0]
for group in combinations(choices, k):
nmask = mask
count = 0
for j in group:
nmask |= 1 << j
count += cards[j] == favorites[i]
yield score[count], nmask
@cache
def dp(i, mask):
if i == n:
assert mask == (1 << (n * k)) - 1
return 0
ans = 0
for cost, nmask in neighbors(i, mask):
ans = max(ans, cost + dp(i + 1, nmask))
return ans
print(dp(0, 0))
```
| 0
|
|
620
|
B
|
Grandfather Dovlet’s calculator
|
PROGRAMMING
| 1,000
|
[
"implementation"
] | null | null |
Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](https://en.wikipedia.org/wiki/Seven-segment_display)).
Max starts to type all the values from *a* to *b*. After typing each number Max resets the calculator. Find the total number of segments printed on the calculator.
For example if *a*<==<=1 and *b*<==<=3 then at first the calculator will print 2 segments, then — 5 segments and at last it will print 5 segments. So the total number of printed segments is 12.
|
The only line contains two integers *a*,<=*b* (1<=≤<=*a*<=≤<=*b*<=≤<=106) — the first and the last number typed by Max.
|
Print the only integer *a* — the total number of printed segments.
|
[
"1 3\n",
"10 15\n"
] |
[
"12\n",
"39\n"
] |
none
| 0
|
[
{
"input": "1 3",
"output": "12"
},
{
"input": "10 15",
"output": "39"
},
{
"input": "1 100",
"output": "928"
},
{
"input": "100 10000",
"output": "188446"
},
{
"input": "213 221442",
"output": "5645356"
},
{
"input": "1 1000000",
"output": "28733372"
},
{
"input": "1000000 1000000",
"output": "38"
},
{
"input": "222145 353252",
"output": "3860750"
},
{
"input": "2 1000000",
"output": "28733370"
},
{
"input": "1 999999",
"output": "28733334"
},
{
"input": "192 200",
"output": "122"
}
] | 1,652,378,449
| 49
|
Python 3
|
OK
|
TESTS
| 11
| 296
| 36,864,000
|
d = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
a, b = map(int, input().split())
nums = str(list(range(a, b+1)))
r = 0
for i in range(len(d)):
r += d[i] * nums.count(str(i))
print(r)
|
Title: Grandfather Dovlet’s calculator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](https://en.wikipedia.org/wiki/Seven-segment_display)).
Max starts to type all the values from *a* to *b*. After typing each number Max resets the calculator. Find the total number of segments printed on the calculator.
For example if *a*<==<=1 and *b*<==<=3 then at first the calculator will print 2 segments, then — 5 segments and at last it will print 5 segments. So the total number of printed segments is 12.
Input Specification:
The only line contains two integers *a*,<=*b* (1<=≤<=*a*<=≤<=*b*<=≤<=106) — the first and the last number typed by Max.
Output Specification:
Print the only integer *a* — the total number of printed segments.
Demo Input:
['1 3\n', '10 15\n']
Demo Output:
['12\n', '39\n']
Note:
none
|
```python
d = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
a, b = map(int, input().split())
nums = str(list(range(a, b+1)))
r = 0
for i in range(len(d)):
r += d[i] * nums.count(str(i))
print(r)
```
| 3
|
|
374
|
B
|
Inna and Nine
|
PROGRAMMING
| 1,500
|
[
"combinatorics",
"greedy"
] | null | null |
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number *a*, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9.
For instance, Inna can alter number 14545181 like this: 14545181<=→<=1945181<=→<=194519<=→<=19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine.
Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.
|
The first line of the input contains integer *a* (1<=≤<=*a*<=≤<=10100000). Number *a* doesn't have any zeroes.
|
In a single line print a single integer — the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263<=-<=1.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
|
[
"369727\n",
"123456789987654321\n",
"1\n"
] |
[
"2\n",
"1\n",
"1\n"
] |
Notes to the samples
In the first sample Inna can get the following numbers: 369727 → 99727 → 9997, 369727 → 99727 → 9979.
In the second sample, Inna can act like this: 123456789987654321 → 12396789987654321 → 1239678998769321.
| 1,000
|
[
{
"input": "369727",
"output": "2"
},
{
"input": "123456789987654321",
"output": "1"
},
{
"input": "1",
"output": "1"
},
{
"input": "3636363636363454545454543636363636454545452727272727218181818181999111777",
"output": "1512"
},
{
"input": "1188",
"output": "1"
},
{
"input": "121212912121291299129191219",
"output": "1"
},
{
"input": "181818918181891918918181918189181818181891818191818191819189",
"output": "54"
},
{
"input": "12191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219",
"output": "1"
},
{
"input": "444444444444445444444444454444444444444444444444445544444444444444444444444444444444444444444554444444444444444444444444444444444444445454444444444444444444444444444444444444454444444444444444444444444444444444445444444444444444444444444444444444444444444445444444444444444444444444444444444456666666666666666666663555555555555555888888888882333333312567312389542179415242164512341234213443123412341293412341234123412746129342154796124123459123491238471234213451692341278451234125934",
"output": "96"
},
{
"input": "123456789",
"output": "1"
},
{
"input": "3639272918194549",
"output": "16"
},
{
"input": "1121314151617181921222324252627282931323334353637383941424344454647484951525354556575859616263646566768697172737475767787981828384858687888991929394959696979899",
"output": "256"
},
{
"input": "14545181",
"output": "2"
},
{
"input": "272727272",
"output": "5"
},
{
"input": "1212121217272727121",
"output": "4"
},
{
"input": "1212172727",
"output": "3"
},
{
"input": "181817272727",
"output": "12"
}
] | 1,655,011,389
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 25
| 655
| 11,264,000
|
R=lambda:map(int,input().split())
import math as m
s=input()
a=[]
f=''
for i in range(1,len(s)):
if(int(s[i])+int(s[i-1])==9):
f+=s[i-1]
else:
f+=s[i-1]
if(len(f)>=2):
if((f[0]=='0' and f[1]=='9') or (f[0]=='9' and f[1]=='0')):
a.append(len(f))
elif(len(f)%2==0):
a.append(1)
else:
a.append((len(f)+1)//2)
f=''
f+=s[-1]
if(len(f)>=2):
if((f[0]=='0' and f[1]=='9') or (f[0]=='9' and f[1]=='0')):
a.append(len(f))
elif(len(f)%2==0):
a.append(1)
else:
a.append((len(f)+1)//2)
ans=1
for i in a:
ans=ans*i
print(ans)
|
Title: Inna and Nine
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number *a*, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9.
For instance, Inna can alter number 14545181 like this: 14545181<=→<=1945181<=→<=194519<=→<=19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine.
Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.
Input Specification:
The first line of the input contains integer *a* (1<=≤<=*a*<=≤<=10100000). Number *a* doesn't have any zeroes.
Output Specification:
In a single line print a single integer — the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263<=-<=1.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Demo Input:
['369727\n', '123456789987654321\n', '1\n']
Demo Output:
['2\n', '1\n', '1\n']
Note:
Notes to the samples
In the first sample Inna can get the following numbers: 369727 → 99727 → 9997, 369727 → 99727 → 9979.
In the second sample, Inna can act like this: 123456789987654321 → 12396789987654321 → 1239678998769321.
|
```python
R=lambda:map(int,input().split())
import math as m
s=input()
a=[]
f=''
for i in range(1,len(s)):
if(int(s[i])+int(s[i-1])==9):
f+=s[i-1]
else:
f+=s[i-1]
if(len(f)>=2):
if((f[0]=='0' and f[1]=='9') or (f[0]=='9' and f[1]=='0')):
a.append(len(f))
elif(len(f)%2==0):
a.append(1)
else:
a.append((len(f)+1)//2)
f=''
f+=s[-1]
if(len(f)>=2):
if((f[0]=='0' and f[1]=='9') or (f[0]=='9' and f[1]=='0')):
a.append(len(f))
elif(len(f)%2==0):
a.append(1)
else:
a.append((len(f)+1)//2)
ans=1
for i in a:
ans=ans*i
print(ans)
```
| 3
|
|
877
|
C
|
Slava and tanks
|
PROGRAMMING
| 1,600
|
[
"constructive algorithms"
] | null | null |
Slava plays his favorite game "Peace Lightning". Now he is flying a bomber on a very specific map.
Formally, map is a checkered field of size 1<=×<=*n*, the cells of which are numbered from 1 to *n*, in each cell there can be one or several tanks. Slava doesn't know the number of tanks and their positions, because he flies very high, but he can drop a bomb in any cell. All tanks in this cell will be damaged.
If a tank takes damage for the first time, it instantly moves to one of the neighboring cells (a tank in the cell *n* can only move to the cell *n*<=-<=1, a tank in the cell 1 can only move to the cell 2). If a tank takes damage for the second time, it's counted as destroyed and never moves again. The tanks move only when they are damaged for the first time, they do not move by themselves.
Help Slava to destroy all tanks using as few bombs as possible.
|
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the size of the map.
|
In the first line print *m* — the minimum number of bombs Slava needs to destroy all tanks.
In the second line print *m* integers *k*1,<=*k*2,<=...,<=*k**m*. The number *k**i* means that the *i*-th bomb should be dropped at the cell *k**i*.
If there are multiple answers, you can print any of them.
|
[
"2\n",
"3\n"
] |
[
"3\n2 1 2 ",
"4\n2 1 3 2 "
] |
none
| 1,500
|
[
{
"input": "2",
"output": "3\n2 1 2 "
},
{
"input": "3",
"output": "4\n2 1 3 2 "
},
{
"input": "4",
"output": "6\n2 4 1 3 2 4 "
},
{
"input": "6",
"output": "9\n2 4 6 1 3 5 2 4 6 "
},
{
"input": "10",
"output": "15\n2 4 6 8 10 1 3 5 7 9 2 4 6 8 10 "
},
{
"input": "15",
"output": "22\n2 4 6 8 10 12 14 1 3 5 7 9 11 13 15 2 4 6 8 10 12 14 "
},
{
"input": "100",
"output": "150\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 "
},
{
"input": "100000",
"output": "150000\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 ..."
},
{
"input": "55333",
"output": "82999\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "42273",
"output": "63409\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "29857",
"output": "44785\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "27687",
"output": "41530\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "25517",
"output": "38275\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "23347",
"output": "35020\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "10931",
"output": "16396\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "98514",
"output": "147771\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 ..."
},
{
"input": "6591",
"output": "9886\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 28..."
},
{
"input": "94174",
"output": "141261\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 ..."
},
{
"input": "92004",
"output": "138006\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 ..."
},
{
"input": "59221",
"output": "88831\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "46806",
"output": "70209\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "54882",
"output": "82323\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "42466",
"output": "63699\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "40296",
"output": "60444\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "27880",
"output": "41820\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "25710",
"output": "38565\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "23540",
"output": "35310\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "11124",
"output": "16686\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "8954",
"output": "13431\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "85387",
"output": "128080\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 ..."
},
{
"input": "72971",
"output": "109456\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 ..."
},
{
"input": "81047",
"output": "121570\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 ..."
},
{
"input": "5",
"output": "7\n2 4 1 3 5 2 4 "
}
] | 1,614,024,078
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 2
| 62
| 0
|
mapSize = int(input())
subTargets = []
target = ''
for i in range(mapSize + 1):
if i > 1:
subTargets.append(i)
subTargets.sort(reverse = True)
subTargets.insert(0, 1)
subTargets.insert(0, 2)
for i in subTargets:
target += str(i) + ' '
print(len(subTargets))
print(target)
|
Title: Slava and tanks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Slava plays his favorite game "Peace Lightning". Now he is flying a bomber on a very specific map.
Formally, map is a checkered field of size 1<=×<=*n*, the cells of which are numbered from 1 to *n*, in each cell there can be one or several tanks. Slava doesn't know the number of tanks and their positions, because he flies very high, but he can drop a bomb in any cell. All tanks in this cell will be damaged.
If a tank takes damage for the first time, it instantly moves to one of the neighboring cells (a tank in the cell *n* can only move to the cell *n*<=-<=1, a tank in the cell 1 can only move to the cell 2). If a tank takes damage for the second time, it's counted as destroyed and never moves again. The tanks move only when they are damaged for the first time, they do not move by themselves.
Help Slava to destroy all tanks using as few bombs as possible.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the size of the map.
Output Specification:
In the first line print *m* — the minimum number of bombs Slava needs to destroy all tanks.
In the second line print *m* integers *k*1,<=*k*2,<=...,<=*k**m*. The number *k**i* means that the *i*-th bomb should be dropped at the cell *k**i*.
If there are multiple answers, you can print any of them.
Demo Input:
['2\n', '3\n']
Demo Output:
['3\n2 1 2 ', '4\n2 1 3 2 ']
Note:
none
|
```python
mapSize = int(input())
subTargets = []
target = ''
for i in range(mapSize + 1):
if i > 1:
subTargets.append(i)
subTargets.sort(reverse = True)
subTargets.insert(0, 1)
subTargets.insert(0, 2)
for i in subTargets:
target += str(i) + ' '
print(len(subTargets))
print(target)
```
| 0
|
|
645
|
A
|
Amity Assessment
|
PROGRAMMING
| 1,200
|
[
"brute force",
"constructive algorithms",
"implementation"
] | null | null |
Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2<=×<=2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a move, Bessie or Elsie can slide a tile adjacent to the empty cell into the empty cell as shown below:
In order to determine if they are truly Best Friends For Life (BFFLs), Bessie and Elsie would like to know if there exists a sequence of moves that takes their puzzles to the same configuration (moves can be performed in both puzzles). Two puzzles are considered to be in the same configuration if each tile is on top of the same grid cell in both puzzles. Since the tiles are labeled with letters, rotations and reflections are not allowed.
|
The first two lines of the input consist of a 2<=×<=2 grid describing the initial configuration of Bessie's puzzle. The next two lines contain a 2<=×<=2 grid describing the initial configuration of Elsie's puzzle. The positions of the tiles are labeled 'A', 'B', and 'C', while the empty cell is labeled 'X'. It's guaranteed that both puzzles contain exactly one tile with each letter and exactly one empty position.
|
Output "YES"(without quotes) if the puzzles can reach the same configuration (and Bessie and Elsie are truly BFFLs). Otherwise, print "NO" (without quotes).
|
[
"AB\nXC\nXB\nAC\n",
"AB\nXC\nAC\nBX\n"
] |
[
"YES\n",
"NO\n"
] |
The solution to the first sample is described by the image. All Bessie needs to do is slide her 'A' tile down.
In the second sample, the two puzzles can never be in the same configuration. Perhaps Bessie and Elsie are not meant to be friends after all...
| 500
|
[
{
"input": "AB\nXC\nXB\nAC",
"output": "YES"
},
{
"input": "AB\nXC\nAC\nBX",
"output": "NO"
},
{
"input": "XC\nBA\nCB\nAX",
"output": "NO"
},
{
"input": "AB\nXC\nAX\nCB",
"output": "YES"
},
{
"input": "CB\nAX\nXA\nBC",
"output": "YES"
},
{
"input": "BC\nXA\nBA\nXC",
"output": "NO"
},
{
"input": "CA\nXB\nBA\nCX",
"output": "NO"
},
{
"input": "CA\nXB\nAC\nBX",
"output": "NO"
},
{
"input": "CB\nAX\nCX\nAB",
"output": "YES"
},
{
"input": "AX\nCB\nBC\nXA",
"output": "YES"
},
{
"input": "CA\nXB\nBA\nXC",
"output": "NO"
},
{
"input": "CX\nAB\nAX\nCB",
"output": "NO"
},
{
"input": "AB\nXC\nAB\nCX",
"output": "YES"
},
{
"input": "XC\nBA\nXC\nAB",
"output": "NO"
},
{
"input": "BA\nXC\nAC\nXB",
"output": "YES"
},
{
"input": "AX\nBC\nAC\nBX",
"output": "YES"
},
{
"input": "XC\nBA\nCB\nXA",
"output": "NO"
},
{
"input": "CB\nAX\nXC\nBA",
"output": "NO"
},
{
"input": "AX\nCB\nBC\nAX",
"output": "YES"
},
{
"input": "AB\nXC\nBX\nAC",
"output": "YES"
},
{
"input": "XA\nCB\nBA\nCX",
"output": "NO"
},
{
"input": "CX\nBA\nBX\nAC",
"output": "YES"
},
{
"input": "AB\nXC\nXC\nAB",
"output": "NO"
},
{
"input": "BA\nCX\nAC\nBX",
"output": "YES"
},
{
"input": "XA\nCB\nAB\nXC",
"output": "YES"
},
{
"input": "XC\nBA\nAC\nBX",
"output": "NO"
},
{
"input": "CA\nBX\nBA\nXC",
"output": "NO"
},
{
"input": "AX\nBC\nCA\nXB",
"output": "NO"
},
{
"input": "BC\nAX\nXC\nBA",
"output": "YES"
},
{
"input": "XB\nAC\nBX\nAC",
"output": "YES"
},
{
"input": "CX\nBA\nAX\nBC",
"output": "NO"
},
{
"input": "XB\nCA\nXC\nBA",
"output": "NO"
},
{
"input": "BX\nCA\nXB\nCA",
"output": "YES"
},
{
"input": "XB\nAC\nXC\nAB",
"output": "NO"
},
{
"input": "CX\nBA\nCX\nBA",
"output": "YES"
},
{
"input": "XB\nAC\nCA\nBX",
"output": "YES"
},
{
"input": "BA\nXC\nBC\nAX",
"output": "NO"
},
{
"input": "AC\nXB\nCX\nBA",
"output": "NO"
},
{
"input": "XB\nCA\nCX\nBA",
"output": "NO"
},
{
"input": "AB\nCX\nXA\nBC",
"output": "NO"
},
{
"input": "CX\nAB\nXB\nAC",
"output": "NO"
},
{
"input": "BC\nAX\nAC\nBX",
"output": "NO"
},
{
"input": "XA\nBC\nCB\nAX",
"output": "YES"
},
{
"input": "XC\nAB\nCB\nAX",
"output": "YES"
},
{
"input": "CX\nBA\nCX\nAB",
"output": "NO"
},
{
"input": "CA\nBX\nXC\nBA",
"output": "YES"
},
{
"input": "CX\nBA\nBA\nXC",
"output": "NO"
},
{
"input": "CA\nBX\nCB\nXA",
"output": "NO"
},
{
"input": "CB\nAX\nBC\nAX",
"output": "NO"
},
{
"input": "CB\nAX\nBC\nXA",
"output": "NO"
},
{
"input": "AC\nXB\nCB\nXA",
"output": "YES"
},
{
"input": "AB\nCX\nXB\nAC",
"output": "YES"
},
{
"input": "CX\nBA\nXB\nAC",
"output": "YES"
},
{
"input": "BX\nAC\nAB\nXC",
"output": "YES"
},
{
"input": "CX\nAB\nXC\nBA",
"output": "NO"
},
{
"input": "XB\nAC\nCX\nAB",
"output": "NO"
},
{
"input": "CB\nAX\nXB\nAC",
"output": "NO"
},
{
"input": "CB\nAX\nCA\nXB",
"output": "NO"
},
{
"input": "XC\nBA\nBA\nXC",
"output": "NO"
},
{
"input": "AC\nBX\nCB\nAX",
"output": "YES"
},
{
"input": "CA\nBX\nAC\nXB",
"output": "NO"
},
{
"input": "BX\nAC\nCX\nBA",
"output": "YES"
},
{
"input": "XB\nCA\nAX\nCB",
"output": "NO"
},
{
"input": "CB\nXA\nBC\nXA",
"output": "NO"
},
{
"input": "AX\nCB\nCX\nAB",
"output": "NO"
},
{
"input": "BC\nAX\nXC\nAB",
"output": "NO"
},
{
"input": "XB\nCA\nBC\nXA",
"output": "NO"
},
{
"input": "XB\nAC\nCX\nBA",
"output": "YES"
},
{
"input": "BC\nXA\nCB\nXA",
"output": "NO"
},
{
"input": "AX\nCB\nAX\nBC",
"output": "NO"
},
{
"input": "CA\nBX\nBX\nCA",
"output": "NO"
},
{
"input": "BA\nXC\nXB\nAC",
"output": "NO"
},
{
"input": "XA\nBC\nBX\nAC",
"output": "NO"
},
{
"input": "BX\nCA\nAC\nBX",
"output": "YES"
},
{
"input": "XB\nAC\nXC\nBA",
"output": "YES"
},
{
"input": "XB\nAC\nAB\nXC",
"output": "YES"
},
{
"input": "BA\nCX\nCX\nBA",
"output": "NO"
},
{
"input": "CA\nXB\nXB\nCA",
"output": "NO"
},
{
"input": "BA\nCX\nBA\nXC",
"output": "YES"
},
{
"input": "BA\nCX\nAB\nCX",
"output": "NO"
},
{
"input": "BX\nCA\nXA\nBC",
"output": "YES"
},
{
"input": "XC\nBA\nBX\nCA",
"output": "NO"
},
{
"input": "XC\nAB\nBC\nXA",
"output": "NO"
},
{
"input": "BC\nXA\nXC\nAB",
"output": "NO"
},
{
"input": "BX\nCA\nXB\nAC",
"output": "NO"
},
{
"input": "BA\nXC\nCA\nXB",
"output": "NO"
},
{
"input": "CX\nBA\nAC\nXB",
"output": "NO"
},
{
"input": "AB\nCX\nAC\nBX",
"output": "NO"
},
{
"input": "BC\nXA\nBX\nCA",
"output": "NO"
},
{
"input": "XA\nBC\nCX\nAB",
"output": "YES"
},
{
"input": "AX\nBC\nAX\nCB",
"output": "NO"
},
{
"input": "CB\nAX\nCA\nBX",
"output": "NO"
},
{
"input": "CB\nAX\nBA\nXC",
"output": "YES"
},
{
"input": "AB\nCX\nXC\nBA",
"output": "YES"
},
{
"input": "AC\nXB\nBA\nCX",
"output": "YES"
},
{
"input": "AX\nCB\nCB\nAX",
"output": "NO"
},
{
"input": "CX\nBA\nCA\nXB",
"output": "YES"
},
{
"input": "AC\nBX\nAB\nXC",
"output": "NO"
},
{
"input": "XA\nCB\nXA\nBC",
"output": "NO"
},
{
"input": "XC\nBA\nCA\nBX",
"output": "YES"
},
{
"input": "XA\nBC\nXB\nCA",
"output": "YES"
},
{
"input": "CA\nBX\nCB\nAX",
"output": "NO"
}
] | 1,458,371,654
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 102
| 62
| 5,120,000
|
def main():
res = []
for _ in 0, 1:
a, b = input()
d, c = input()
res.append([x for x in (a, b, c, d) if x != 'X'])
a, b = res
print(("NO", "YES")[b[b.index(a[0]) - 1] == a[2]])
if __name__ == '__main__':
main()
|
Title: Amity Assessment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2<=×<=2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a move, Bessie or Elsie can slide a tile adjacent to the empty cell into the empty cell as shown below:
In order to determine if they are truly Best Friends For Life (BFFLs), Bessie and Elsie would like to know if there exists a sequence of moves that takes their puzzles to the same configuration (moves can be performed in both puzzles). Two puzzles are considered to be in the same configuration if each tile is on top of the same grid cell in both puzzles. Since the tiles are labeled with letters, rotations and reflections are not allowed.
Input Specification:
The first two lines of the input consist of a 2<=×<=2 grid describing the initial configuration of Bessie's puzzle. The next two lines contain a 2<=×<=2 grid describing the initial configuration of Elsie's puzzle. The positions of the tiles are labeled 'A', 'B', and 'C', while the empty cell is labeled 'X'. It's guaranteed that both puzzles contain exactly one tile with each letter and exactly one empty position.
Output Specification:
Output "YES"(without quotes) if the puzzles can reach the same configuration (and Bessie and Elsie are truly BFFLs). Otherwise, print "NO" (without quotes).
Demo Input:
['AB\nXC\nXB\nAC\n', 'AB\nXC\nAC\nBX\n']
Demo Output:
['YES\n', 'NO\n']
Note:
The solution to the first sample is described by the image. All Bessie needs to do is slide her 'A' tile down.
In the second sample, the two puzzles can never be in the same configuration. Perhaps Bessie and Elsie are not meant to be friends after all...
|
```python
def main():
res = []
for _ in 0, 1:
a, b = input()
d, c = input()
res.append([x for x in (a, b, c, d) if x != 'X'])
a, b = res
print(("NO", "YES")[b[b.index(a[0]) - 1] == a[2]])
if __name__ == '__main__':
main()
```
| 3
|
|
372
|
A
|
Counting Kangaroos is Fun
|
PROGRAMMING
| 1,600
|
[
"binary search",
"greedy",
"sortings",
"two pointers"
] | null | null |
There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held.
Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos.
The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible.
|
The first line contains a single integer — *n* (1<=≤<=*n*<=≤<=5·105). Each of the next *n* lines contains an integer *s**i* — the size of the *i*-th kangaroo (1<=≤<=*s**i*<=≤<=105).
|
Output a single integer — the optimal number of visible kangaroos.
|
[
"8\n2\n5\n7\n6\n9\n8\n4\n2\n",
"8\n9\n1\n6\n2\n6\n5\n8\n3\n"
] |
[
"5\n",
"5\n"
] |
none
| 500
|
[
{
"input": "8\n2\n5\n7\n6\n9\n8\n4\n2",
"output": "5"
},
{
"input": "8\n9\n1\n6\n2\n6\n5\n8\n3",
"output": "5"
},
{
"input": "12\n3\n99\n24\n46\n75\n63\n57\n55\n10\n62\n34\n52",
"output": "7"
},
{
"input": "12\n55\n75\n1\n98\n63\n64\n9\n39\n82\n18\n47\n9",
"output": "6"
},
{
"input": "100\n678\n771\n96\n282\n135\n749\n168\n668\n17\n658\n979\n446\n998\n331\n606\n756\n37\n515\n538\n205\n647\n547\n904\n842\n647\n286\n774\n414\n267\n791\n595\n465\n8\n327\n855\n174\n339\n946\n184\n250\n807\n422\n679\n980\n64\n530\n312\n351\n676\n911\n803\n991\n669\n50\n293\n841\n545\n598\n737\n894\n231\n754\n588\n83\n873\n767\n833\n482\n905\n903\n970\n571\n715\n59\n777\n697\n537\n861\n339\n212\n149\n889\n905\n70\n970\n307\n830\n465\n968\n291\n430\n317\n942\n944\n330\n235\n814\n880\n415\n76",
"output": "58"
},
{
"input": "100\n154\n60\n97\n638\n139\n150\n570\n579\n601\n647\n804\n237\n245\n549\n288\n347\n778\n282\n916\n441\n974\n145\n957\n886\n655\n702\n930\n618\n132\n520\n972\n48\n94\n54\n682\n433\n896\n134\n845\n636\n242\n842\n125\n141\n240\n130\n409\n666\n948\n938\n604\n110\n474\n484\n364\n40\n807\n271\n438\n288\n201\n814\n754\n589\n341\n576\n146\n952\n819\n923\n222\n535\n336\n83\n314\n911\n303\n911\n384\n601\n249\n330\n735\n271\n142\n204\n405\n783\n775\n449\n590\n139\n109\n276\n45\n205\n454\n836\n82\n841",
"output": "50"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "4\n1\n1\n1\n2",
"output": "3"
},
{
"input": "5\n1\n2\n4\n8\n16",
"output": "3"
},
{
"input": "7\n1\n2\n4\n8\n16\n32\n64",
"output": "4"
},
{
"input": "3\n1\n2\n4",
"output": "2"
}
] | 1,615,371,202
| 2,147,483,647
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 8
| 1,000
| 11,980,800
|
n=int(input())
ls=[]
for _ in range(n):
s=int(input())
ls.append(s)
ls.sort()
cnt=0
mid=n//2-1
right=n-1
mated=0
for _ in range(n//2):
if ls[right]>=2*ls[mid] and mid>=0:
cnt+=1
mid-=1
right-=1
mated+=2
else:
mid-=1
print(cnt+n-mated)
|
Title: Counting Kangaroos is Fun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held.
Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos.
The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible.
Input Specification:
The first line contains a single integer — *n* (1<=≤<=*n*<=≤<=5·105). Each of the next *n* lines contains an integer *s**i* — the size of the *i*-th kangaroo (1<=≤<=*s**i*<=≤<=105).
Output Specification:
Output a single integer — the optimal number of visible kangaroos.
Demo Input:
['8\n2\n5\n7\n6\n9\n8\n4\n2\n', '8\n9\n1\n6\n2\n6\n5\n8\n3\n']
Demo Output:
['5\n', '5\n']
Note:
none
|
```python
n=int(input())
ls=[]
for _ in range(n):
s=int(input())
ls.append(s)
ls.sort()
cnt=0
mid=n//2-1
right=n-1
mated=0
for _ in range(n//2):
if ls[right]>=2*ls[mid] and mid>=0:
cnt+=1
mid-=1
right-=1
mated+=2
else:
mid-=1
print(cnt+n-mated)
```
| 0
|
|
22
|
E
|
Scheme
|
PROGRAMMING
| 2,300
|
[
"dfs and similar",
"graphs",
"trees"
] |
E. Scheme
|
2
|
256
|
To learn as soon as possible the latest news about their favourite fundamentally new operating system, BolgenOS community from Nizhni Tagil decided to develop a scheme. According to this scheme a community member, who is the first to learn the news, calls some other member, the latter, in his turn, calls some third member, and so on; i.e. a person with index *i* got a person with index *f**i*, to whom he has to call, if he learns the news. With time BolgenOS community members understood that their scheme doesn't work sometimes — there were cases when some members didn't learn the news at all. Now they want to supplement the scheme: they add into the scheme some instructions of type (*x**i*,<=*y**i*), which mean that person *x**i* has to call person *y**i* as well. What is the minimum amount of instructions that they need to add so, that at the end everyone learns the news, no matter who is the first to learn it?
|
The first input line contains number *n* (2<=≤<=*n*<=≤<=105) — amount of BolgenOS community members. The second line contains *n* space-separated integer numbers *f**i* (1<=≤<=*f**i*<=≤<=*n*,<=*i*<=≠<=*f**i*) — index of a person, to whom calls a person with index *i*.
|
In the first line output one number — the minimum amount of instructions to add. Then output one of the possible variants to add these instructions into the scheme, one instruction in each line. If the solution is not unique, output any.
|
[
"3\n3 3 2\n",
"7\n2 3 1 3 4 4 1\n"
] |
[
"1\n3 1\n",
"3\n2 5\n2 6\n3 7\n"
] |
none
| 0
|
[
{
"input": "3\n3 3 2",
"output": "1\n3 1"
},
{
"input": "7\n2 3 1 3 4 4 1",
"output": "3\n1 5\n1 6\n1 7"
},
{
"input": "2\n2 1",
"output": "0"
},
{
"input": "3\n2 3 1",
"output": "0"
},
{
"input": "4\n2 4 4 3",
"output": "1\n4 1"
},
{
"input": "5\n5 3 5 2 3",
"output": "2\n5 1\n5 4"
},
{
"input": "9\n2 5 6 7 4 1 9 6 8",
"output": "1\n1 3"
},
{
"input": "20\n20 10 16 14 9 20 6 20 14 19 17 13 16 13 14 8 8 8 8 19",
"output": "10\n20 1\n20 2\n20 3\n20 4\n20 5\n20 7\n20 11\n20 12\n20 15\n20 18"
},
{
"input": "100\n13 71 16 92 25 53 97 63 70 83 51 16 51 84 5 10 54 89 18 95 48 29 82 27 84 68 7 4 65 99 95 37 26 24 24 39 3 28 74 7 75 32 27 24 73 48 72 15 46 66 91 94 19 44 77 23 94 88 51 84 72 95 75 55 80 47 58 13 87 88 25 2 89 81 71 36 7 42 16 59 32 43 58 61 44 96 36 48 88 49 53 91 13 1 37 87 90 47 61 87",
"output": "36\n25 6\n25 8\n25 9\n25 11\n25 12\n25 14\n25 17\n25 20\n25 21\n25 22\n25 30\n25 31\n25 33\n25 34\n25 35\n25 38\n25 40\n25 41\n25 45\n25 50\n25 52\n25 56\n25 57\n25 60\n25 62\n25 64\n25 67\n25 69\n25 76\n25 78\n25 79\n25 85\n25 86\n25 93\n25 98\n25 100"
},
{
"input": "7\n3 1 2 5 6 7 4",
"output": "2\n1 4\n4 1"
}
] | 1,649,791,042
| 2,147,483,647
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 4
| 154
| 0
|
N=int(input())
A=list(map(int,input().split()))
# UnionFind
Group = [i for i in range(N+1)] # グループ分け
Nodes = [1]*(N+1) # 各グループのノードの数
def find(x):
while Group[x] != x:
x=Group[x]
return x
def Union(x,y):
if find(x) != find(y):
if Nodes[find(x)] < Nodes[find(y)]:
Nodes[find(y)] += Nodes[find(x)]
Nodes[find(x)] = 0
Group[find(x)] = find(y)
else:
Nodes[find(x)] += Nodes[find(y)]
Nodes[find(y)] = 0
Group[find(y)] = find(x)
for i in range(N):
Union(i+1,A[i])
USE=[0]*(N+1)
for a in A:
USE[a]=1
ANS=[]
ind=1
for i in range(1,N+1):
if USE[i]==0:
while USE[ind]==0:
ind+=1
if ind==N+1:
ind=1
if Nodes[find(i)]==N:
break
else:
if find(ind)==find(i):
continue
else:
break
ANS.append((ind,i))
Union(ind,i)
ind=1
for i in range(1,N+1):
if Nodes[find(i)]==N:
break
else:
while find(i)==find(ind):
ind+=1
if ind==N+1:
ind=1
ANS.append((i,ind))
Union(ind,i)
print(len(ANS))
for x,y in ANS:
print(x,y)
|
Title: Scheme
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
To learn as soon as possible the latest news about their favourite fundamentally new operating system, BolgenOS community from Nizhni Tagil decided to develop a scheme. According to this scheme a community member, who is the first to learn the news, calls some other member, the latter, in his turn, calls some third member, and so on; i.e. a person with index *i* got a person with index *f**i*, to whom he has to call, if he learns the news. With time BolgenOS community members understood that their scheme doesn't work sometimes — there were cases when some members didn't learn the news at all. Now they want to supplement the scheme: they add into the scheme some instructions of type (*x**i*,<=*y**i*), which mean that person *x**i* has to call person *y**i* as well. What is the minimum amount of instructions that they need to add so, that at the end everyone learns the news, no matter who is the first to learn it?
Input Specification:
The first input line contains number *n* (2<=≤<=*n*<=≤<=105) — amount of BolgenOS community members. The second line contains *n* space-separated integer numbers *f**i* (1<=≤<=*f**i*<=≤<=*n*,<=*i*<=≠<=*f**i*) — index of a person, to whom calls a person with index *i*.
Output Specification:
In the first line output one number — the minimum amount of instructions to add. Then output one of the possible variants to add these instructions into the scheme, one instruction in each line. If the solution is not unique, output any.
Demo Input:
['3\n3 3 2\n', '7\n2 3 1 3 4 4 1\n']
Demo Output:
['1\n3 1\n', '3\n2 5\n2 6\n3 7\n']
Note:
none
|
```python
N=int(input())
A=list(map(int,input().split()))
# UnionFind
Group = [i for i in range(N+1)] # グループ分け
Nodes = [1]*(N+1) # 各グループのノードの数
def find(x):
while Group[x] != x:
x=Group[x]
return x
def Union(x,y):
if find(x) != find(y):
if Nodes[find(x)] < Nodes[find(y)]:
Nodes[find(y)] += Nodes[find(x)]
Nodes[find(x)] = 0
Group[find(x)] = find(y)
else:
Nodes[find(x)] += Nodes[find(y)]
Nodes[find(y)] = 0
Group[find(y)] = find(x)
for i in range(N):
Union(i+1,A[i])
USE=[0]*(N+1)
for a in A:
USE[a]=1
ANS=[]
ind=1
for i in range(1,N+1):
if USE[i]==0:
while USE[ind]==0:
ind+=1
if ind==N+1:
ind=1
if Nodes[find(i)]==N:
break
else:
if find(ind)==find(i):
continue
else:
break
ANS.append((ind,i))
Union(ind,i)
ind=1
for i in range(1,N+1):
if Nodes[find(i)]==N:
break
else:
while find(i)==find(ind):
ind+=1
if ind==N+1:
ind=1
ANS.append((i,ind))
Union(ind,i)
print(len(ANS))
for x,y in ANS:
print(x,y)
```
| 0
|
976
|
C
|
Nested Segments
|
PROGRAMMING
| 1,500
|
[
"greedy",
"implementation",
"sortings"
] | null | null |
You are given a sequence *a*1,<=*a*2,<=...,<=*a**n* of one-dimensional segments numbered 1 through *n*. Your task is to find two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*.
Segment [*l*1,<=*r*1] lies within segment [*l*2,<=*r*2] iff *l*1<=≥<=*l*2 and *r*1<=≤<=*r*2.
Print indices *i* and *j*. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
|
The first line contains one integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of segments.
Each of the next *n* lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the *i*-th segment.
|
Print two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
|
[
"5\n1 10\n2 9\n3 9\n2 3\n2 9\n",
"3\n1 5\n2 6\n6 20\n"
] |
[
"2 1\n",
"-1 -1\n"
] |
In the first example the following pairs are considered correct:
- (2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders; - (3, 2), (4, 2), (3, 5), (4, 5) — touch one border; - (5, 2), (2, 5) — match exactly.
| 0
|
[
{
"input": "5\n1 10\n2 9\n3 9\n2 3\n2 9",
"output": "2 1"
},
{
"input": "3\n1 5\n2 6\n6 20",
"output": "-1 -1"
},
{
"input": "1\n1 1000000000",
"output": "-1 -1"
},
{
"input": "2\n1 1000000000\n1 1000000000",
"output": "2 1"
},
{
"input": "2\n1 1000000000\n500000000 500000000",
"output": "2 1"
},
{
"input": "2\n1 10\n2 10",
"output": "2 1"
},
{
"input": "2\n10 20\n10 11",
"output": "2 1"
},
{
"input": "3\n1 10\n10 20\n9 11",
"output": "-1 -1"
},
{
"input": "3\n1 1\n2 3\n2 2",
"output": "3 2"
},
{
"input": "4\n1 10\n2 11\n3 10000000\n3 100000000",
"output": "3 4"
},
{
"input": "2\n3 7\n3 9",
"output": "1 2"
},
{
"input": "3\n1 2\n2 3\n1 2",
"output": "3 1"
},
{
"input": "3\n5 6\n4 7\n3 8",
"output": "2 3"
},
{
"input": "3\n2 9\n1 7\n2 8",
"output": "3 1"
},
{
"input": "2\n1 4\n1 5",
"output": "1 2"
},
{
"input": "3\n1 2\n1 3\n4 4",
"output": "1 2"
},
{
"input": "3\n1 2\n1 3\n67 1234567",
"output": "1 2"
},
{
"input": "2\n1 1\n1 1",
"output": "2 1"
},
{
"input": "3\n1 5\n4 7\n3 9",
"output": "2 3"
},
{
"input": "2\n1 1\n1 10",
"output": "1 2"
},
{
"input": "2\n1 2\n1 3",
"output": "1 2"
},
{
"input": "2\n1 10\n1 11",
"output": "1 2"
},
{
"input": "2\n1 1\n1 2",
"output": "1 2"
},
{
"input": "2\n2 3\n2 4",
"output": "1 2"
},
{
"input": "2\n1 3\n3 3",
"output": "2 1"
},
{
"input": "3\n1 10\n11 13\n12 12",
"output": "3 2"
},
{
"input": "2\n2 10\n1 10",
"output": "1 2"
},
{
"input": "3\n1 3\n4 5\n4 4",
"output": "3 2"
},
{
"input": "5\n1 1\n2 6\n3 5\n10 15\n20 25",
"output": "3 2"
},
{
"input": "3\n1 1000\n1001 1007\n1002 1007",
"output": "3 2"
},
{
"input": "3\n1 3\n2 5\n3 4",
"output": "3 2"
},
{
"input": "3\n1 10\n2 11\n3 11",
"output": "3 2"
},
{
"input": "2\n2000000 999999999\n1000000 1000000000",
"output": "1 2"
},
{
"input": "3\n2 10\n11 12\n4 5",
"output": "3 1"
},
{
"input": "2\n1 10\n1 19",
"output": "1 2"
},
{
"input": "4\n1 3\n100 102\n108 110\n1 3",
"output": "4 1"
},
{
"input": "3\n1 3\n5 9\n5 6",
"output": "3 2"
},
{
"input": "3\n1 3\n3 4\n3 5",
"output": "2 3"
},
{
"input": "3\n1 2\n1 3\n1 4",
"output": "2 3"
},
{
"input": "4\n2 3\n1 4\n100 200\n1000 2000",
"output": "1 2"
},
{
"input": "3\n1 1\n2 100\n3 99",
"output": "3 2"
},
{
"input": "3\n1 2\n1 3\n12 1234",
"output": "1 2"
},
{
"input": "3\n1 4\n2 6\n3 5",
"output": "3 2"
},
{
"input": "3\n1 10\n2 12\n1 9",
"output": "3 1"
},
{
"input": "2\n1 3\n1 5",
"output": "1 2"
},
{
"input": "3\n1 2\n2 5\n2 3",
"output": "3 2"
},
{
"input": "4\n1 3\n1 4\n5 10\n11 13",
"output": "1 2"
},
{
"input": "4\n7 15\n6 9\n9 10\n10 11",
"output": "3 1"
},
{
"input": "4\n2 3\n100 200\n1000 2000\n1 4",
"output": "1 4"
},
{
"input": "3\n10 20\n5 9\n11 19",
"output": "3 1"
},
{
"input": "10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 6\n6 7\n7 8\n8 9\n9 10",
"output": "6 7"
},
{
"input": "2\n1 4\n1 7",
"output": "1 2"
},
{
"input": "3\n1 11\n2 12\n2 13",
"output": "2 3"
},
{
"input": "2\n1 4\n1 8",
"output": "1 2"
},
{
"input": "2\n2 5\n1 5",
"output": "1 2"
},
{
"input": "2\n2 9\n1 10",
"output": "1 2"
},
{
"input": "3\n2 4\n2 4\n1 3",
"output": "2 1"
},
{
"input": "6\n10 11\n12 13\n15 16\n15 17\n18 19\n59 60",
"output": "3 4"
},
{
"input": "2\n1 3\n1 7",
"output": "1 2"
},
{
"input": "5\n4 6\n7 60\n80 90\n4 5\n8 80",
"output": "4 1"
},
{
"input": "2\n1 3\n1 4",
"output": "1 2"
},
{
"input": "3\n2 9\n1 7\n2 9",
"output": "3 1"
},
{
"input": "2\n1 4\n1 6",
"output": "1 2"
},
{
"input": "3\n4 4\n2 3\n4 5",
"output": "1 3"
},
{
"input": "2\n1 5\n1 7",
"output": "1 2"
},
{
"input": "2\n1 2\n1 4",
"output": "1 2"
},
{
"input": "4\n1 1\n2 2\n5 10\n2 4",
"output": "2 4"
},
{
"input": "3\n11 12\n11 15\n43 45",
"output": "1 2"
},
{
"input": "3\n2 3\n2 4\n2 5",
"output": "2 3"
},
{
"input": "2\n2 3\n2 5",
"output": "1 2"
},
{
"input": "3\n1 3\n1 4\n1 5",
"output": "2 3"
},
{
"input": "3\n1 1\n1 2\n1 3",
"output": "2 3"
},
{
"input": "2\n2 3\n1 3",
"output": "1 2"
},
{
"input": "11\n22226 28285\n9095 23314\n19162 25530\n255 13298\n4904 25801\n17914 23501\n8441 28117\n11880 29994\n11123 19874\n21505 27971\n7658 14109",
"output": "11 5"
},
{
"input": "8\n4 11\n5 12\n6 13\n7 14\n8 15\n9 16\n10 17\n1 11",
"output": "1 8"
},
{
"input": "4\n1 10\n12 15\n1 3\n17 18",
"output": "3 1"
},
{
"input": "3\n1 5\n1 10\n1 20",
"output": "2 3"
},
{
"input": "3\n1 1000\n1001 1003\n1 1",
"output": "3 1"
},
{
"input": "3\n1 10\n2 11\n2 11",
"output": "3 2"
},
{
"input": "2\n1 1\n1 3",
"output": "1 2"
},
{
"input": "2\n1 5\n1 6",
"output": "1 2"
},
{
"input": "3\n1 5\n3 6\n1 4",
"output": "3 1"
},
{
"input": "4\n2 8\n1 3\n2 9\n1 2",
"output": "4 2"
},
{
"input": "3\n3 6\n1 3\n3 9",
"output": "1 3"
},
{
"input": "6\n2 40\n5 50\n10 60\n3 45\n1 40\n100 111",
"output": "1 5"
},
{
"input": "4\n1 2\n4 4\n3 3\n2 3",
"output": "3 4"
},
{
"input": "4\n1 1\n4 5\n7 9\n1 1",
"output": "4 1"
},
{
"input": "6\n30 35\n18 29\n28 32\n4 9\n1002 129212\n8 281",
"output": "2 6"
},
{
"input": "2\n10 13\n10 14",
"output": "1 2"
},
{
"input": "5\n2 4\n3 6\n4 5\n222 333\n111 444",
"output": "3 2"
},
{
"input": "3\n1 2\n4 5\n1 1",
"output": "3 1"
},
{
"input": "2\n2 100\n1 100",
"output": "1 2"
},
{
"input": "3\n1 10\n9 20\n3 5",
"output": "3 1"
},
{
"input": "2\n1 9\n1 10",
"output": "1 2"
},
{
"input": "3\n1 2\n1 4\n1 6",
"output": "2 3"
}
] | 1,525,391,470
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 122
| 1,497
| 73,728,000
|
from sys import stdin
n = int(input())
seg = []
inp = stdin.readlines()
for i in range(n):
l, r = map(int, inp[i].split())
seg.append([l, r, i + 1])
#seg.sort(key = lambda x: x[1], reverse = True)
seg.sort(key = lambda x: x[0])
if n == 1: print(-1, -1)
else:
ans = [-1, -1]
for i in range(1, n):
l1, r1 = seg[i - 1][:2]
l2, r2 = seg[i][:2]
if l2 >= l1 and r2 <= r1:
ans = [seg[i][2], seg[i - 1][2]]
break
elif l2 == l1 and r2 > r1:
ans = [seg[i - 1][2], seg[i][2]]
break
print(ans[0], ans[1])
|
Title: Nested Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence *a*1,<=*a*2,<=...,<=*a**n* of one-dimensional segments numbered 1 through *n*. Your task is to find two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*.
Segment [*l*1,<=*r*1] lies within segment [*l*2,<=*r*2] iff *l*1<=≥<=*l*2 and *r*1<=≤<=*r*2.
Print indices *i* and *j*. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of segments.
Each of the next *n* lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the *i*-th segment.
Output Specification:
Print two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
Demo Input:
['5\n1 10\n2 9\n3 9\n2 3\n2 9\n', '3\n1 5\n2 6\n6 20\n']
Demo Output:
['2 1\n', '-1 -1\n']
Note:
In the first example the following pairs are considered correct:
- (2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders; - (3, 2), (4, 2), (3, 5), (4, 5) — touch one border; - (5, 2), (2, 5) — match exactly.
|
```python
from sys import stdin
n = int(input())
seg = []
inp = stdin.readlines()
for i in range(n):
l, r = map(int, inp[i].split())
seg.append([l, r, i + 1])
#seg.sort(key = lambda x: x[1], reverse = True)
seg.sort(key = lambda x: x[0])
if n == 1: print(-1, -1)
else:
ans = [-1, -1]
for i in range(1, n):
l1, r1 = seg[i - 1][:2]
l2, r2 = seg[i][:2]
if l2 >= l1 and r2 <= r1:
ans = [seg[i][2], seg[i - 1][2]]
break
elif l2 == l1 and r2 > r1:
ans = [seg[i - 1][2], seg[i][2]]
break
print(ans[0], ans[1])
```
| 3
|
|
580
|
A
|
Kefa and First Steps
|
PROGRAMMING
| 900
|
[
"brute force",
"dp",
"implementation"
] | null | null |
Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.
Help Kefa cope with this task!
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109).
|
Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*.
|
[
"6\n2 2 1 3 4 1\n",
"3\n2 2 9\n"
] |
[
"3",
"3"
] |
In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.
In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
| 750
|
[
{
"input": "6\n2 2 1 3 4 1",
"output": "3"
},
{
"input": "3\n2 2 9",
"output": "3"
},
{
"input": "5\n10 100 111 1 2",
"output": "3"
},
{
"input": "10\n1 2 3 4 1 2 3 4 5 6",
"output": "6"
},
{
"input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "50"
},
{
"input": "100\n1 838 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 605 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 27 533 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 835 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 992",
"output": "42"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "6\n5 4 3 2 1 2",
"output": "2"
},
{
"input": "9\n1 2 3 4 5 6 7 8 9",
"output": "9"
},
{
"input": "7\n99 100 1 2 3 4 5",
"output": "5"
},
{
"input": "5\n3 3 1 2 3",
"output": "3"
},
{
"input": "1\n100",
"output": "1"
},
{
"input": "1\n5",
"output": "1"
}
] | 1,690,366,152
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 8
| 31
| 1,024,000
|
n = int(input())
a = [int(x) for x in input().split()]
b = 0
c = []
for i in range(1, n):
if a[i]>=a[i-1]:
b+=1
c.append(b)
else:
b = 0
print(max(c)+1)
|
Title: Kefa and First Steps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.
Help Kefa cope with this task!
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Output Specification:
Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*.
Demo Input:
['6\n2 2 1 3 4 1\n', '3\n2 2 9\n']
Demo Output:
['3', '3']
Note:
In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.
In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
|
```python
n = int(input())
a = [int(x) for x in input().split()]
b = 0
c = []
for i in range(1, n):
if a[i]>=a[i-1]:
b+=1
c.append(b)
else:
b = 0
print(max(c)+1)
```
| -1
|
|
61
|
A
|
Ultra-Fast Mathematician
|
PROGRAMMING
| 800
|
[
"implementation"
] |
A. Ultra-Fast Mathematician
|
2
|
256
|
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
|
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
|
Write one line — the corresponding answer. Do not omit the leading 0s.
|
[
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] |
[
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] |
none
| 500
|
[
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "10\n01",
"output": "11"
},
{
"input": "00111111\n11011101",
"output": "11100010"
},
{
"input": "011001100\n101001010",
"output": "110000110"
},
{
"input": "1100100001\n0110101100",
"output": "1010001101"
},
{
"input": "00011101010\n10010100101",
"output": "10001001111"
},
{
"input": "100000101101\n111010100011",
"output": "011010001110"
},
{
"input": "1000001111010\n1101100110001",
"output": "0101101001011"
},
{
"input": "01011111010111\n10001110111010",
"output": "11010001101101"
},
{
"input": "110010000111100\n001100101011010",
"output": "111110101100110"
},
{
"input": "0010010111110000\n0000000011010110",
"output": "0010010100100110"
},
{
"input": "00111110111110000\n01111100001100000",
"output": "01000010110010000"
},
{
"input": "101010101111010001\n001001111101111101",
"output": "100011010010101100"
},
{
"input": "0110010101111100000\n0011000101000000110",
"output": "0101010000111100110"
},
{
"input": "11110100011101010111\n00001000011011000000",
"output": "11111100000110010111"
},
{
"input": "101010101111101101001\n111010010010000011111",
"output": "010000111101101110110"
},
{
"input": "0000111111100011000010\n1110110110110000001010",
"output": "1110001001010011001000"
},
{
"input": "10010010101000110111000\n00101110100110111000111",
"output": "10111100001110001111111"
},
{
"input": "010010010010111100000111\n100100111111100011001110",
"output": "110110101101011111001001"
},
{
"input": "0101110100100111011010010\n0101100011010111001010001",
"output": "0000010111110000010000011"
},
{
"input": "10010010100011110111111011\n10000110101100000001000100",
"output": "00010100001111110110111111"
},
{
"input": "000001111000000100001000000\n011100111101111001110110001",
"output": "011101000101111101111110001"
},
{
"input": "0011110010001001011001011100\n0000101101000011101011001010",
"output": "0011011111001010110010010110"
},
{
"input": "11111000000000010011001101111\n11101110011001010100010000000",
"output": "00010110011001000111011101111"
},
{
"input": "011001110000110100001100101100\n001010000011110000001000101001",
"output": "010011110011000100000100000101"
},
{
"input": "1011111010001100011010110101111\n1011001110010000000101100010101",
"output": "0000110100011100011111010111010"
},
{
"input": "10111000100001000001010110000001\n10111000001100101011011001011000",
"output": "00000000101101101010001111011001"
},
{
"input": "000001010000100001000000011011100\n111111111001010100100001100000111",
"output": "111110101001110101100001111011011"
},
{
"input": "1101000000000010011011101100000110\n1110000001100010011010000011011110",
"output": "0011000001100000000001101111011000"
},
{
"input": "01011011000010100001100100011110001\n01011010111000001010010100001110000",
"output": "00000001111010101011110000010000001"
},
{
"input": "000011111000011001000110111100000100\n011011000110000111101011100111000111",
"output": "011000111110011110101101011011000011"
},
{
"input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000",
"output": "1011001001111001001011101010101000010"
},
{
"input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011",
"output": "10001110000010101110000111000011111110"
},
{
"input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100",
"output": "000100001011110000011101110111010001110"
},
{
"input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001",
"output": "1101110101010110000011000000101011110011"
},
{
"input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100",
"output": "11001011110010010000010111001100001001110"
},
{
"input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110",
"output": "001100101000011111111101111011101010111001"
},
{
"input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001",
"output": "0111010010100110110101100010000100010100000"
},
{
"input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100",
"output": "11111110000000100101000100110111001100011001"
},
{
"input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011",
"output": "101011011100100010100011011001101010100100010"
},
{
"input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001",
"output": "1101001100111011010111110110101111001011110111"
},
{
"input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001",
"output": "10010101000101000000011010011110011110011110001"
},
{
"input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100",
"output": "011011011100000000010101110010000000101000111101"
},
{
"input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100",
"output": "0101010111101001011011110110011101010101010100011"
},
{
"input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011",
"output": "11001011010010111000010110011101100100001110111111"
},
{
"input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011",
"output": "111011101010011100001111101001101011110010010110001"
},
{
"input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001",
"output": "0100111110110011111110010010010000110111100101101101"
},
{
"input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100",
"output": "01011001110111010111001100010011010100010000111011000"
},
{
"input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111",
"output": "100011101001001000011011011001111000100000010100100100"
},
{
"input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110",
"output": "1100110010000101101010111111101001001001110101110010110"
},
{
"input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110",
"output": "01000111100111001011110010100011111111110010101100001101"
},
{
"input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010",
"output": "110001010001000011000101110101000100001011111001011001001"
},
{
"input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111",
"output": "1110100010111000101001001011101110011111100111000011011011"
},
{
"input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110",
"output": "01110110101110100100110011010000001000101100101111000111011"
},
{
"input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011",
"output": "111100101000000011101011011001110010101111000110010010000000"
},
{
"input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111",
"output": "0100100010111110010011101010000011111110001110010110010111001"
},
{
"input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111",
"output": "00110100000011001101101100100010110010001100000001100110011101"
},
{
"input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011",
"output": "000000011000111011110011101000010000010100101000000011010110010"
},
{
"input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010",
"output": "0010100110110100111100100100101101010100100111011010001001010101"
},
{
"input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111",
"output": "11010110111100101111101001100001110100010110010110110111100110100"
},
{
"input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111",
"output": "111111010011011100101110100110111111111001111110011010111111110000"
},
{
"input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110",
"output": "1010101010100010001001001001100000111000010010010100010011000100000"
},
{
"input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000",
"output": "00011111011111001000011100010011100011010100101011011000001001111110"
},
{
"input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111",
"output": "001111000011001110100111010101111111011100110011001010010010000111011"
},
{
"input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101",
"output": "0110001100110100010000110111000010011010011000011001010011010100010100"
},
{
"input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010",
"output": "00010000000110110101000011001000000100100110111010011111101010001010000"
},
{
"input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001",
"output": "000100100000000110011100100001010110101001100101110010010011111001110111"
},
{
"input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000",
"output": "1000111100010011010110011101000000101010101100011111100001101111001010010"
},
{
"input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011",
"output": "01000010011110111001011011110000001011000111101101101010010110001010100100"
},
{
"input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101",
"output": "101101110110110010011100001011111100100001110000101100110000100011011100110"
},
{
"input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001",
"output": "1110111111110010111000001100101010101011010100101010100101100011001001111111"
},
{
"input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111",
"output": "10111011000111000101110100101000100111011011100011110110000101010001111010111"
},
{
"input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110",
"output": "110100100110000101010010011010011001100110000111010000010100001011110111111101"
},
{
"input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111",
"output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111"
},
{
"input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001",
"output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001"
},
{
"input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110",
"output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011"
},
{
"input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111",
"output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101"
},
{
"input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010",
"output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101"
},
{
"input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000",
"output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001"
},
{
"input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011",
"output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110"
},
{
"input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011",
"output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011"
},
{
"input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011",
"output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011"
},
{
"input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010",
"output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011"
},
{
"input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001",
"output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110"
},
{
"input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111",
"output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010"
},
{
"input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011",
"output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011"
},
{
"input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100",
"output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000"
},
{
"input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001",
"output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101"
},
{
"input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110",
"output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101"
},
{
"input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011",
"output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110"
},
{
"input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111",
"output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110"
},
{
"input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000",
"output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001"
},
{
"input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010",
"output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101"
},
{
"input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101",
"output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011"
},
{
"input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011",
"output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010",
"output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "0\n1",
"output": "1"
}
] | 1,681,734,413
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 102
| 77
| 0
|
n = input()
l = input()
s = ""
for i in range(len(n)):
if n[i] != l[i]:
s += "1"
else:
s += "0"
print(s)
|
Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
Input Specification:
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Output Specification:
Write one line — the corresponding answer. Do not omit the leading 0s.
Demo Input:
['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n']
Demo Output:
['1110001\n', '111\n', '0100\n', '00010\n']
Note:
none
|
```python
n = input()
l = input()
s = ""
for i in range(len(n)):
if n[i] != l[i]:
s += "1"
else:
s += "0"
print(s)
```
| 3.98075
|
894
|
A
|
QAQ
|
PROGRAMMING
| 800
|
[
"brute force",
"dp"
] | null | null |
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact.
|
The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters.
|
Print a single integer — the number of subsequences "QAQ" in the string.
|
[
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] |
[
"4\n",
"3\n"
] |
In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".
| 500
|
[
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
"input": "AMVFNFJIAVNQJWIVONQOAOOQSNQSONOASONAONQINAONAOIQONANOIQOANOQINAONOQINAONOXJCOIAQOAOQAQAQAQAQWWWAQQAQ",
"output": "1077"
},
{
"input": "AAQQAXBQQBQQXBNQRJAQKQNAQNQVDQASAGGANQQQQTJFFQQQTQQA",
"output": "568"
},
{
"input": "KAZXAVLPJQBQVQQQQQAPAQQGQTQVZQAAAOYA",
"output": "70"
},
{
"input": "W",
"output": "0"
},
{
"input": "DBA",
"output": "0"
},
{
"input": "RQAWNACASAAKAGAAAAQ",
"output": "10"
},
{
"input": "QJAWZAAOAAGIAAAAAOQATASQAEAAAAQFQQHPA",
"output": "111"
},
{
"input": "QQKWQAQAAAAAAAAGAAVAQUEQQUMQMAQQQNQLAMAAAUAEAAEMAAA",
"output": "411"
},
{
"input": "QQUMQAYAUAAGWAAAQSDAVAAQAAAASKQJJQQQQMAWAYYAAAAAAEAJAXWQQ",
"output": "625"
},
{
"input": "QORZOYAQ",
"output": "1"
},
{
"input": "QCQAQAGAWAQQQAQAVQAQQQQAQAQQQAQAAATQAAVAAAQQQQAAAUUQAQQNQQWQQWAQAAQQKQYAQAAQQQAAQRAQQQWBQQQQAPBAQGQA",
"output": "13174"
},
{
"input": "QQAQQAKQFAQLQAAWAMQAZQAJQAAQQOACQQAAAYANAQAQQAQAAQQAOBQQJQAQAQAQQQAAAAABQQQAVNZAQQQQAMQQAFAAEAQAQHQT",
"output": "10420"
},
{
"input": "AQEGQHQQKQAQQPQKAQQQAAAAQQQAQEQAAQAAQAQFSLAAQQAQOQQAVQAAAPQQAWAQAQAFQAXAQQQQTRLOQAQQJQNQXQQQQSQVDQQQ",
"output": "12488"
},
{
"input": "QNQKQQQLASQBAVQQQQAAQQOQRJQQAQQQEQZUOANAADAAQQJAQAQARAAAQQQEQBHTQAAQAAAAQQMKQQQIAOJJQQAQAAADADQUQQQA",
"output": "9114"
},
{
"input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
"output": "35937"
},
{
"input": "AMQQAAQAAQAAAAAAQQQBOAAANAAKQJCYQAE",
"output": "254"
},
{
"input": "AYQBAEQGAQEOAKGIXLQJAIAKQAAAQPUAJAKAATFWQQAOQQQUFQYAQQMQHOKAAJXGFCARAQSATHAUQQAATQJJQDQRAANQQAE",
"output": "2174"
},
{
"input": "AAQXAAQAYQAAAAGAQHVQYAGIVACADFAAQAAAAQZAAQMAKZAADQAQDAAQDAAAMQQOXYAQQQAKQBAAQQKAXQBJZDDLAAHQQ",
"output": "2962"
},
{
"input": "AYQQYAVAMNIAUAAKBBQVACWKTQSAQZAAQAAASZJAWBCAALAARHACQAKQQAQAARPAQAAQAQAAZQUSHQAMFVFZQQQQSAQQXAA",
"output": "2482"
},
{
"input": "LQMAQQARQAQBJQQQAGAAZQQXALQQAARQAQQQQAAQQAQQQAQQCAQQAQQAYQQQRAAZATQALYQQAAHHAAQHAAAAAAAAQQMAAQNAKQ",
"output": "7768"
},
{
"input": "MAQQWAQOYQMAAAQAQPQZAOAAQAUAQNAAQAAAITQSAQAKAQKAQQWSQAAQQAGUCDQMQWKQUXKWQQAAQQAAQQZQDQQQAABXQUUXQOA",
"output": "5422"
},
{
"input": "QTAAQDAQXAQQJQQQGAAAQQQQSBQZKAQQAQQQQEAQNUQBZCQLYQZQEQQAAQHQVAORKQVAQYQNASZQAARZAAGAAAAOQDCQ",
"output": "3024"
},
{
"input": "QQWAQQGQQUZQQQLZAAQYQXQVAQFQUAQZUQZZQUKBHSHTQYLQAOQXAQQGAQQTQOAQARQADAJRAAQPQAQQUQAUAMAUVQAAAQQAWQ",
"output": "4527"
},
{
"input": "QQAAQQAQVAQZQQQQAOEAQZPQIBQZACQQAFQQLAAQDATZQANHKYQQAQTAAFQRQAIQAJPWQAQTEIRXAEQQAYWAAAUKQQAQAQQQSQQH",
"output": "6416"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAAAA",
"output": "14270"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQ",
"output": "13136"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA",
"output": "14270"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQQAA",
"output": "14231"
},
{
"input": "QQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA",
"output": "15296"
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
"output": "0"
},
{
"input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "0"
},
{
"input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
"output": "0"
},
{
"input": "QAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQA",
"output": "20825"
},
{
"input": "AQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQ",
"output": "20825"
},
{
"input": "Q",
"output": "0"
},
{
"input": "A",
"output": "0"
},
{
"input": "FFF",
"output": "0"
},
{
"input": "AAAAAA",
"output": "0"
}
] | 1,595,074,227
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 43
| 140
| 20,172,800
|
MAX = 100
def countSubsequence(s, n):
cntQ = 0
cntA = 0
result = 0
C=0
for i in range(n):
if (s[i] == 'Q'):
cntQ += 1
result += C
continue
if (s[i] == 'A'):
cntA += 1
C += cntQ
continue
else:
continue
print(result)
if __name__ == '__main__':
s = input()
n = len(s)
countSubsequence(s, n)
|
Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact.
Input Specification:
The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters.
Output Specification:
Print a single integer — the number of subsequences "QAQ" in the string.
Demo Input:
['QAQAQYSYIOIWIN\n', 'QAQQQZZYNOIWIN\n']
Demo Output:
['4\n', '3\n']
Note:
In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".
|
```python
MAX = 100
def countSubsequence(s, n):
cntQ = 0
cntA = 0
result = 0
C=0
for i in range(n):
if (s[i] == 'Q'):
cntQ += 1
result += C
continue
if (s[i] == 'A'):
cntA += 1
C += cntQ
continue
else:
continue
print(result)
if __name__ == '__main__':
s = input()
n = len(s)
countSubsequence(s, n)
```
| 3
|
|
938
|
A
|
Word Correction
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consecutive vowels in the word, it deletes the first vowel in a word such that there is another vowel right before it. If there are no two consecutive vowels in the word, it is considered to be correct.
You are given a word *s*. Can you predict what will it become after correction?
In this problem letters a, e, i, o, u and y are considered to be vowels.
|
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of letters in word *s* before the correction.
The second line contains a string *s* consisting of exactly *n* lowercase Latin letters — the word before the correction.
|
Output the word *s* after the correction.
|
[
"5\nweird\n",
"4\nword\n",
"5\naaeaa\n"
] |
[
"werd\n",
"word\n",
"a\n"
] |
Explanations of the examples:
1. There is only one replace: weird <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> werd;1. No replace needed since there are no two consecutive vowels;1. aaeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> a.
| 0
|
[
{
"input": "5\nweird",
"output": "werd"
},
{
"input": "4\nword",
"output": "word"
},
{
"input": "5\naaeaa",
"output": "a"
},
{
"input": "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyw",
"output": "abbbbbocadabbbbbifgihjabbbklbobbbbbibbbbbezyw"
},
{
"input": "69\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
},
{
"input": "12\nmmmmmmmmmmmm",
"output": "mmmmmmmmmmmm"
},
{
"input": "18\nyaywptqwuyiqypwoyw",
"output": "ywptqwuqypwow"
},
{
"input": "85\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
},
{
"input": "13\nmmmmmmmmmmmmm",
"output": "mmmmmmmmmmmmm"
},
{
"input": "10\nmmmmmmmmmm",
"output": "mmmmmmmmmm"
},
{
"input": "11\nmmmmmmmmmmm",
"output": "mmmmmmmmmmm"
},
{
"input": "15\nmmmmmmmmmmmmmmm",
"output": "mmmmmmmmmmmmmmm"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "14\nmmmmmmmmmmmmmm",
"output": "mmmmmmmmmmmmmm"
},
{
"input": "33\nmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm",
"output": "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm"
},
{
"input": "79\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
},
{
"input": "90\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
},
{
"input": "2\naa",
"output": "a"
},
{
"input": "18\niuiuqpyyaoaetiwliu",
"output": "iqpytiwli"
},
{
"input": "5\nxxxxx",
"output": "xxxxx"
},
{
"input": "6\nxxxahg",
"output": "xxxahg"
},
{
"input": "3\nzcv",
"output": "zcv"
},
{
"input": "4\naepo",
"output": "apo"
},
{
"input": "5\nqqqqq",
"output": "qqqqq"
},
{
"input": "6\naaaaaa",
"output": "a"
},
{
"input": "4\naeta",
"output": "ata"
},
{
"input": "20\nttyttlwaoieulyiluuri",
"output": "ttyttlwalyluri"
},
{
"input": "1\nb",
"output": "b"
},
{
"input": "3\nanc",
"output": "anc"
},
{
"input": "1\ne",
"output": "e"
},
{
"input": "3\naie",
"output": "a"
},
{
"input": "3\nvio",
"output": "vi"
},
{
"input": "2\nea",
"output": "e"
},
{
"input": "3\nuas",
"output": "us"
},
{
"input": "2\nba",
"output": "ba"
},
{
"input": "2\naq",
"output": "aq"
},
{
"input": "2\nya",
"output": "y"
},
{
"input": "2\nou",
"output": "o"
},
{
"input": "2\nbb",
"output": "bb"
},
{
"input": "7\nayylmao",
"output": "alma"
},
{
"input": "2\nab",
"output": "ab"
},
{
"input": "19\nyuouiyaoiiweqrryqqp",
"output": "yweqrryqqp"
},
{
"input": "25\niqypwqpriiioetiuqqqttouei",
"output": "iqypwqpritiqqqtto"
},
{
"input": "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyz",
"output": "abbbbbocadabbbbbifgihjabbbklbobbbbbibbbbbezyz"
},
{
"input": "17\naccccccccccccccca",
"output": "accccccccccccccca"
},
{
"input": "5\nababa",
"output": "ababa"
},
{
"input": "10\naaaaaaaaaa",
"output": "a"
},
{
"input": "22\naaaaabbbbboyoyoyoyoyac",
"output": "abbbbboc"
},
{
"input": "7\nmahmoud",
"output": "mahmod"
}
] | 1,637,685,856
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 49
| 61
| 0
|
# from dust i have come dust i will be
n=int(input())
s=input()
a=['a','e','i','o','u','y']
ch='#'
for i in range(n):
if s[i] not in a:
if ch!='#':
print(ch,end='')
ch='#'
print(s[i],end='')
else:
if ch=='#':
ch=s[i]
if ch!='#':
print(ch)
|
Title: Word Correction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consecutive vowels in the word, it deletes the first vowel in a word such that there is another vowel right before it. If there are no two consecutive vowels in the word, it is considered to be correct.
You are given a word *s*. Can you predict what will it become after correction?
In this problem letters a, e, i, o, u and y are considered to be vowels.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of letters in word *s* before the correction.
The second line contains a string *s* consisting of exactly *n* lowercase Latin letters — the word before the correction.
Output Specification:
Output the word *s* after the correction.
Demo Input:
['5\nweird\n', '4\nword\n', '5\naaeaa\n']
Demo Output:
['werd\n', 'word\n', 'a\n']
Note:
Explanations of the examples:
1. There is only one replace: weird <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> werd;1. No replace needed since there are no two consecutive vowels;1. aaeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> a.
|
```python
# from dust i have come dust i will be
n=int(input())
s=input()
a=['a','e','i','o','u','y']
ch='#'
for i in range(n):
if s[i] not in a:
if ch!='#':
print(ch,end='')
ch='#'
print(s[i],end='')
else:
if ch=='#':
ch=s[i]
if ch!='#':
print(ch)
```
| 3
|
|
499
|
B
|
Lecture
|
PROGRAMMING
| 1,000
|
[
"implementation",
"strings"
] | null | null |
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning.
You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language.
You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.
|
The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages.
The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once.
The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}.
All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.
|
Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.
|
[
"4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n",
"5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n"
] |
[
"codeforces round letter round\n",
"hbnyiyc joll joll un joll\n"
] |
none
| 500
|
[
{
"input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest",
"output": "codeforces round letter round"
},
{
"input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll",
"output": "hbnyiyc joll joll un joll"
},
{
"input": "5 5\nqueyqj f\nb vn\ntabzvk qpfzoqx\nytnyonoc hnxsd\njpggvr lchinjmt\nqueyqj jpggvr b ytnyonoc b",
"output": "f jpggvr b hnxsd b"
},
{
"input": "10 22\nazbrll oen\ngh vdyayei\njphveblohx vfglv\nmfyxib jepnvhcuwo\nrpikazqj uam\nl rx\nokjenof qpnyi\nj tixqrno\nod itozmfct\nikkdxmirx ev\nqexftojc p\nkdazb zjs\nmbk ykvqjrxaxu\nhbcwhouzq pwt\nmirpsz zfaegpl\nuhkkvcj rlvwj\nef iqnnwtolrc\npjzfcpmeag ecdayth\nsa qcthz\ncbfhfxi qrnbvdryz\nwqel tj\natx smkbid\nef hbcwhouzq cbfhfxi hbcwhouzq mirpsz cbfhfxi cbfhfxi okjenof pjzfcpmeag kdazb",
"output": "ef pwt cbfhfxi pwt mirpsz cbfhfxi cbfhfxi qpnyi ecdayth zjs"
},
{
"input": "1 1\namit am\namit",
"output": "am"
},
{
"input": "1 1\na c\na",
"output": "a"
}
] | 1,680,755,440
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 37
| 156
| 9,830,400
|
n,m = map(int,input().split())
m1 = {}
m2 = {}
m3 = {}
for i in range(m):
s1,s2 = map(str,input().split())
m1[s1] = len(s1)
m2[s1] = [len(s2),s2]
l = list(map(str,input().split()))
for i in range(n):
if m2[l[i]][0]<m1[l[i]]:
print(m2[l[i]][1],end=" ")
else:
print(l[i],end=" ")
|
Title: Lecture
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning.
You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language.
You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.
Input Specification:
The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages.
The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once.
The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}.
All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.
Output Specification:
Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.
Demo Input:
['4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n', '5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n']
Demo Output:
['codeforces round letter round\n', 'hbnyiyc joll joll un joll\n']
Note:
none
|
```python
n,m = map(int,input().split())
m1 = {}
m2 = {}
m3 = {}
for i in range(m):
s1,s2 = map(str,input().split())
m1[s1] = len(s1)
m2[s1] = [len(s2),s2]
l = list(map(str,input().split()))
for i in range(n):
if m2[l[i]][0]<m1[l[i]]:
print(m2[l[i]][1],end=" ")
else:
print(l[i],end=" ")
```
| 3
|
|
25
|
A
|
IQ test
|
PROGRAMMING
| 1,300
|
[
"brute force"
] |
A. IQ test
|
2
|
256
|
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
|
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
|
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
|
[
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] |
[
"3\n",
"2\n"
] |
none
| 0
|
[
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output": "2"
},
{
"input": "4\n75 13 94 77",
"output": "3"
},
{
"input": "4\n97 8 27 3",
"output": "2"
},
{
"input": "10\n95 51 12 91 85 3 1 31 25 7",
"output": "3"
},
{
"input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46",
"output": "4"
},
{
"input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36",
"output": "26"
},
{
"input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83",
"output": "48"
},
{
"input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25",
"output": "1"
},
{
"input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46",
"output": "25"
},
{
"input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73",
"output": "13"
},
{
"input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76",
"output": "99"
},
{
"input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14",
"output": "1"
},
{
"input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22",
"output": "93"
},
{
"input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23",
"output": "1"
},
{
"input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98",
"output": "1"
},
{
"input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94",
"output": "93"
},
{
"input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29",
"output": "32"
},
{
"input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47",
"output": "26"
},
{
"input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72",
"output": "56"
},
{
"input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86",
"output": "97"
},
{
"input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42",
"output": "79"
},
{
"input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52",
"output": "25"
},
{
"input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86",
"output": "78"
},
{
"input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68",
"output": "70"
},
{
"input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81",
"output": "39"
},
{
"input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83",
"output": "88"
},
{
"input": "3\n100 100 1",
"output": "3"
}
] | 1,585,770,335
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 32
| 218
| 307,200
|
# IQ test: python
n = int(input())
lst = list(map(int, input().split()))
def find_flag(lst):
evens, odds = 0, 0
flag = ''
for i in range(3):
if lst[i] % 2 == 0:
evens += 1
else:
odds += 1
if i == 2:
if evens > odds:
flag = 'odd'
else:
flag = 'even'
return flag
def find_differ(lst, flag):
if flag == 'even':
for i in range(len(lst)):
if lst[i] % 2 == 0:
print(i + 1)
exit()
else:
for i in range(len(lst)):
if lst[i] % 2 != 0:
print(i + 1)
exit()
flag = find_flag(lst)
find_differ(lst, flag)
|
Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output Specification:
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
Demo Input:
['5\n2 4 7 8 10\n', '4\n1 2 1 1\n']
Demo Output:
['3\n', '2\n']
Note:
none
|
```python
# IQ test: python
n = int(input())
lst = list(map(int, input().split()))
def find_flag(lst):
evens, odds = 0, 0
flag = ''
for i in range(3):
if lst[i] % 2 == 0:
evens += 1
else:
odds += 1
if i == 2:
if evens > odds:
flag = 'odd'
else:
flag = 'even'
return flag
def find_differ(lst, flag):
if flag == 'even':
for i in range(len(lst)):
if lst[i] % 2 == 0:
print(i + 1)
exit()
else:
for i in range(len(lst)):
if lst[i] % 2 != 0:
print(i + 1)
exit()
flag = find_flag(lst)
find_differ(lst, flag)
```
| 3.944928
|
474
|
B
|
Worms
|
PROGRAMMING
| 1,200
|
[
"binary search",
"implementation"
] | null | null |
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled with numbers *a*1<=+<=1 to *a*1<=+<=*a*2 and so on. See the example for a better understanding.
Mole can't eat all the worms (Marmot brought a lot) and, as we all know, Mole is blind, so Marmot tells him the labels of the best juicy worms. Marmot will only give Mole a worm if Mole says correctly in which pile this worm is contained.
Poor Mole asks for your help. For all juicy worms said by Marmot, tell Mole the correct answers.
|
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile.
The third line contains single integer *m* (1<=≤<=*m*<=≤<=105), the number of juicy worms said by Marmot.
The fourth line contains *m* integers *q*1,<=*q*2,<=...,<=*q**m* (1<=≤<=*q**i*<=≤<=*a*1<=+<=*a*2<=+<=...<=+<=*a**n*), the labels of the juicy worms.
|
Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is.
|
[
"5\n2 7 3 4 9\n3\n1 25 11\n"
] |
[
"1\n5\n3\n"
] |
For the sample input:
- The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the fifth pile.
| 1,000
|
[
{
"input": "5\n2 7 3 4 9\n3\n1 25 11",
"output": "1\n5\n3"
}
] | 1,694,620,923
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 11
| 420
| 7,475,200
|
n = int(input())
worms = [int(x) for x in input().split()]
m = int(input())
juicy = [int(x) for x in input().split()]
results = []
# 创建一个前缀和数组
for i in range(1, n):
worms[i] += worms[i-1]
for j in juicy:
# 特殊情况:果汁小于第一个蠕虫的值
if j <= worms[0]:
results.append(1)
continue
left, right = 0, n-1
while left <= right:
middle = (left + right) // 2
# 这里我们使用 middle 和 middle - 1 来确定 j 的位置
if middle == 0 or (worms[middle-1] < j <= worms[middle]):
results.append(middle + 1)
break
elif j <= worms[middle-1]:
right = middle - 1
else:
left = middle + 1
for i in results:
print(i)
|
Title: Worms
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled with numbers *a*1<=+<=1 to *a*1<=+<=*a*2 and so on. See the example for a better understanding.
Mole can't eat all the worms (Marmot brought a lot) and, as we all know, Mole is blind, so Marmot tells him the labels of the best juicy worms. Marmot will only give Mole a worm if Mole says correctly in which pile this worm is contained.
Poor Mole asks for your help. For all juicy worms said by Marmot, tell Mole the correct answers.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile.
The third line contains single integer *m* (1<=≤<=*m*<=≤<=105), the number of juicy worms said by Marmot.
The fourth line contains *m* integers *q*1,<=*q*2,<=...,<=*q**m* (1<=≤<=*q**i*<=≤<=*a*1<=+<=*a*2<=+<=...<=+<=*a**n*), the labels of the juicy worms.
Output Specification:
Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is.
Demo Input:
['5\n2 7 3 4 9\n3\n1 25 11\n']
Demo Output:
['1\n5\n3\n']
Note:
For the sample input:
- The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the fifth pile.
|
```python
n = int(input())
worms = [int(x) for x in input().split()]
m = int(input())
juicy = [int(x) for x in input().split()]
results = []
# 创建一个前缀和数组
for i in range(1, n):
worms[i] += worms[i-1]
for j in juicy:
# 特殊情况:果汁小于第一个蠕虫的值
if j <= worms[0]:
results.append(1)
continue
left, right = 0, n-1
while left <= right:
middle = (left + right) // 2
# 这里我们使用 middle 和 middle - 1 来确定 j 的位置
if middle == 0 or (worms[middle-1] < j <= worms[middle]):
results.append(middle + 1)
break
elif j <= worms[middle-1]:
right = middle - 1
else:
left = middle + 1
for i in results:
print(i)
```
| 0
|
|
71
|
A
|
Way Too Long Words
|
PROGRAMMING
| 800
|
[
"strings"
] |
A. Way Too Long Words
|
1
|
256
|
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
|
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
|
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
|
[
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] |
[
"word\nl10n\ni18n\np43s\n"
] |
none
| 500
|
[
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd",
"output": "n20n\nj27b\nk15d"
},
{
"input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt",
"output": "t41t"
},
{
"input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings",
"output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz",
"output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz"
},
{
"input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij",
"output": "a98j"
},
{
"input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco",
"output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco"
},
{
"input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt",
"output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t"
},
{
"input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr",
"output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr"
}
] | 1,692,806,016
| 2,147,483,647
|
Python 3
|
COMPILATION_ERROR
|
TESTS
| 0
| 0
| 0
|
n=int(input())
words=[]
for _ in range(n):
word=input().strip()
if len(word)>10:
abbreviation=word[0]+
str(len(word)-2)+word[-1]
words.append(abbreviation)
else:
words.append(word)
for abbreviation in words:
print(abbreviation)
|
Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Output Specification:
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
Demo Input:
['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n']
Demo Output:
['word\nl10n\ni18n\np43s\n']
Note:
none
|
```python
n=int(input())
words=[]
for _ in range(n):
word=input().strip()
if len(word)>10:
abbreviation=word[0]+
str(len(word)-2)+word[-1]
words.append(abbreviation)
else:
words.append(word)
for abbreviation in words:
print(abbreviation)
```
| -1
|
23
|
E
|
Tree
|
PROGRAMMING
| 2,500
|
[
"dp"
] |
E. Tree
|
2
|
256
|
Recently Bob invented a new game with a tree (we should remind you, that a tree is a connected graph without cycles): he deletes any (possibly, zero) amount of edges of the tree, and counts the product of sizes of the connected components left after the deletion. Your task is to find out the maximum number that Bob can get in his new game for a given tree.
|
The first input line contains integer number *n* (1<=≤<=*n*<=≤<=700) — amount of vertices in the tree. The following *n*<=-<=1 lines contain the description of the edges. Each line contains the pair of vertices' indexes, joined by an edge, *a**i*, *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*). It's guaranteed that the graph described in the input is a tree.
|
Output the only number — the maximum product of sizes of the connected components, that Bob can get after deleting some of the tree's edges.
|
[
"5\n1 2\n2 3\n3 4\n4 5\n",
"8\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n6 8\n",
"3\n1 2\n1 3\n"
] |
[
"6",
"18",
"3"
] |
none
| 0
|
[
{
"input": "5\n1 2\n2 3\n3 4\n4 5",
"output": "6"
},
{
"input": "8\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n6 8",
"output": "18"
},
{
"input": "3\n1 2\n1 3",
"output": "3"
},
{
"input": "5\n3 2\n1 5\n4 5\n5 3",
"output": "6"
},
{
"input": "5\n2 1\n3 4\n3 5\n5 2",
"output": "6"
},
{
"input": "5\n1 4\n4 5\n4 3\n4 2",
"output": "5"
},
{
"input": "5\n2 3\n3 4\n3 5\n3 1",
"output": "5"
},
{
"input": "10\n4 8\n10 2\n6 3\n10 9\n2 3\n4 1\n7 10\n2 1\n5 1",
"output": "36"
},
{
"input": "15\n4 6\n15 1\n3 8\n15 2\n13 11\n9 10\n14 4\n9 12\n11 6\n8 10\n4 5\n2 11\n7 8\n8 4",
"output": "243"
},
{
"input": "50\n45 39\n18 12\n13 6\n48 45\n46 36\n46 8\n40 36\n29 28\n2 18\n43 26\n25 14\n43 31\n13 30\n12 35\n38 42\n20 5\n7 35\n10 50\n27 13\n1 41\n24 21\n25 5\n7 31\n15 45\n32 25\n43 23\n4 50\n46 11\n40 14\n37 21\n50 2\n41 42\n43 30\n14 22\n36 48\n8 24\n49 20\n19 26\n32 10\n35 29\n1 6\n34 33\n29 3\n6 9\n34 39\n5 47\n16 9\n31 44\n33 17",
"output": "68024448"
},
{
"input": "10\n8 10\n5 7\n1 6\n4 9\n3 8\n8 9\n2 3\n5 8\n8 1",
"output": "32"
},
{
"input": "5\n1 5\n4 3\n2 4\n4 1",
"output": "6"
},
{
"input": "1",
"output": "1"
},
{
"input": "2\n2 1",
"output": "2"
},
{
"input": "3\n1 2\n2 3",
"output": "3"
}
] | 1,383,440,936
| 2,147,483,647
|
Python 3
|
COMPILATION_ERROR
|
TESTS
| 0
| 0
| 0
|
#include <iostream>
#include <vector>
#include <cstring>
#define MAXN 701
using namespace std;
typedef long long ll;
vector<int> adj[MAXN];
ll DP[MAXN][4];
int order[MAXN];
int sz;
int pi[MAXN];
void dfs(int u, int p = -1) {
pi[u] = p;
int v;
for (int i = 0; i < adj[u].size(); ++i) {
v = adj[u][i];
if (v != p)
dfs(v, u);
}
order[sz++] = u;
}
ll T1[MAXN], T2[MAXN], T3[MAXN];
void solve(int u, int ac, int p = -1) {
ll &ans = DP[u][ac];
ans = -1;
int v;
if (ac >= 2) {
ans = ac == 2 ? 3 : 1;
for (int i = 0; i < adj[u].size(); ++i) {
v = adj[u][i];
if (v != p)
ans *= DP[v][0];
}
return;
}
int nc = 0, sheet = 0;
ll t1 = 1, t4 = 1;
for (int i = 0; i < adj[u].size(); ++i) {
v = adj[u][i];
if (v != p) {
T1[nc] = DP[v][0];
t1 *= T1[nc];
T2[nc] = DP[v][ac+1];
if (ac == 0)
T3[nc] = DP[v][3];
if (adj[v].size() == 1)
++sheet;
else
t4 *= T1[nc];
nc++;
}
}
ans = (ac+1+sheet) * t4;
if (ac == 0) {
for (int i = 0; i < nc; ++i)
for (int j = i+1; j < nc; ++j)
ans = max(ans, t1 / (T1[i]*T1[j]) * T3[i]*T3[j] * 3);
}
ans = max(ans, (ac+1) * t1);
for (int i = 0; i < nc; ++i)
ans = max(ans, t1 / T1[i] * T2[i]);
return;
}
int main() {
int n;
cin >> n;
int u, v;
for (int i = 1; i < n; ++i) {
cin >> u >> v;
adj[--u].push_back(--v);
adj[v].push_back(u);
}
sz = 0;
dfs(0);
for (int i = 0; i < n; ++i)
for (int j = 0; j <= 3; ++j)
solve(order[i], j, pi[order[i]]);
cout << DP[0][0] << endl;
}
|
Title: Tree
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Recently Bob invented a new game with a tree (we should remind you, that a tree is a connected graph without cycles): he deletes any (possibly, zero) amount of edges of the tree, and counts the product of sizes of the connected components left after the deletion. Your task is to find out the maximum number that Bob can get in his new game for a given tree.
Input Specification:
The first input line contains integer number *n* (1<=≤<=*n*<=≤<=700) — amount of vertices in the tree. The following *n*<=-<=1 lines contain the description of the edges. Each line contains the pair of vertices' indexes, joined by an edge, *a**i*, *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*). It's guaranteed that the graph described in the input is a tree.
Output Specification:
Output the only number — the maximum product of sizes of the connected components, that Bob can get after deleting some of the tree's edges.
Demo Input:
['5\n1 2\n2 3\n3 4\n4 5\n', '8\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n6 8\n', '3\n1 2\n1 3\n']
Demo Output:
['6', '18', '3']
Note:
none
|
```python
#include <iostream>
#include <vector>
#include <cstring>
#define MAXN 701
using namespace std;
typedef long long ll;
vector<int> adj[MAXN];
ll DP[MAXN][4];
int order[MAXN];
int sz;
int pi[MAXN];
void dfs(int u, int p = -1) {
pi[u] = p;
int v;
for (int i = 0; i < adj[u].size(); ++i) {
v = adj[u][i];
if (v != p)
dfs(v, u);
}
order[sz++] = u;
}
ll T1[MAXN], T2[MAXN], T3[MAXN];
void solve(int u, int ac, int p = -1) {
ll &ans = DP[u][ac];
ans = -1;
int v;
if (ac >= 2) {
ans = ac == 2 ? 3 : 1;
for (int i = 0; i < adj[u].size(); ++i) {
v = adj[u][i];
if (v != p)
ans *= DP[v][0];
}
return;
}
int nc = 0, sheet = 0;
ll t1 = 1, t4 = 1;
for (int i = 0; i < adj[u].size(); ++i) {
v = adj[u][i];
if (v != p) {
T1[nc] = DP[v][0];
t1 *= T1[nc];
T2[nc] = DP[v][ac+1];
if (ac == 0)
T3[nc] = DP[v][3];
if (adj[v].size() == 1)
++sheet;
else
t4 *= T1[nc];
nc++;
}
}
ans = (ac+1+sheet) * t4;
if (ac == 0) {
for (int i = 0; i < nc; ++i)
for (int j = i+1; j < nc; ++j)
ans = max(ans, t1 / (T1[i]*T1[j]) * T3[i]*T3[j] * 3);
}
ans = max(ans, (ac+1) * t1);
for (int i = 0; i < nc; ++i)
ans = max(ans, t1 / T1[i] * T2[i]);
return;
}
int main() {
int n;
cin >> n;
int u, v;
for (int i = 1; i < n; ++i) {
cin >> u >> v;
adj[--u].push_back(--v);
adj[v].push_back(u);
}
sz = 0;
dfs(0);
for (int i = 0; i < n; ++i)
for (int j = 0; j <= 3; ++j)
solve(order[i], j, pi[order[i]]);
cout << DP[0][0] << endl;
}
```
| -1
|
934
|
A
|
A Compatible Pair
|
PROGRAMMING
| 1,400
|
[
"brute force",
"games"
] | null | null |
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming.
Little Tommy has *n* lanterns and Big Banban has *m* lanterns. Tommy's lanterns have brightness *a*1,<=*a*2,<=...,<=*a**n*, and Banban's have brightness *b*1,<=*b*2,<=...,<=*b**m* respectively.
Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns.
Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible.
You are asked to find the brightness of the chosen pair if both of them choose optimally.
|
The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50).
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*.
The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*.
All the integers range from <=-<=109 to 109.
|
Print a single integer — the brightness of the chosen pair.
|
[
"2 2\n20 18\n2 14\n",
"5 3\n-1 0 1 2 3\n-1 0 1\n"
] |
[
"252\n",
"2\n"
] |
In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself.
In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself.
| 500
|
[
{
"input": "2 2\n20 18\n2 14",
"output": "252"
},
{
"input": "5 3\n-1 0 1 2 3\n-1 0 1",
"output": "2"
},
{
"input": "10 2\n1 6 2 10 2 3 2 10 6 4\n5 7",
"output": "70"
},
{
"input": "50 50\n1 6 2 10 2 3 2 10 6 4 5 0 3 1 7 3 2 4 4 2 1 5 0 6 10 1 8 0 10 9 0 4 10 5 5 7 4 9 9 5 5 2 6 7 9 4 3 7 2 0\n0 5 9 4 4 6 1 8 2 1 6 6 8 6 4 4 7 2 1 8 6 7 4 9 8 3 0 2 0 10 7 1 4 9 4 4 2 5 3 5 1 3 2 4 1 6 5 3 8 6",
"output": "100"
},
{
"input": "5 7\n-130464232 -73113866 -542094710 -53118823 -63528720\n-775179088 631683023 -974858199 -157471745 -629658630 71825477 -6235611",
"output": "127184126241438168"
},
{
"input": "16 15\n-94580188 -713689767 -559972014 -632609438 -930348091 -567718487 -611395744 -819913097 -924009672 -427913920 -812510647 -546415480 -982072775 -693369647 -693004777 -714181162\n-772924706 -202246100 -165871667 -991426281 -490838183 209351416 134956137 -36128588 -754413937 -616596290 696201705 -201191199 967464971 -244181984 -729907974",
"output": "922371547895579571"
},
{
"input": "12 22\n-102896616 -311161241 -67541276 -402842686 -830595520 -813834033 -44046671 -584806552 -598620444 -968935604 -303048547 -545969410\n545786451 262898403 442511997 -441241260 -479587986 -752123290 720443264 500646237 737842681 -571966572 -798463881 -477248830 89875164 410339460 -359022689 -251280099 -441455542 -538431186 -406793869 374561004 -108755237 -440143410",
"output": "663200522440413120"
},
{
"input": "33 14\n-576562007 -218618150 -471719380 -583840778 -256368365 -68451917 -405045344 -775538133 -896830082 -439261765 -947070124 -716577019 -456110999 -689862512 -132480131 -10805271 -518903339 -196240188 -222292638 -828546042 -43887962 -161359263 -281422097 -484060534 963147664 -492377073 -154570101 -52145116 187803553 858844161 66540410 418777176 434025748\n-78301978 -319393213 -12393024 542953412 786804661 845642067 754996432 -985617475 -487171947 56142664 203173079 -268261708 -817080591 -511720682",
"output": "883931400924882950"
},
{
"input": "15 8\n-966400308 -992207261 -302395973 -837980754 -516443826 -492405613 -378127629 -762650324 -519519776 -36132939 -286460372 -351445284 -407653342 -604960925 -523442015\n610042288 27129580 -103108347 -942517864 842060508 -588904868 614786155 37455106",
"output": "910849554065102112"
},
{
"input": "6 30\n-524297819 -947277203 -444186475 -182837689 -385379656 -453917269\n834529938 35245081 663687669 585422565 164412867 850052113 796429008 -307345676 -127653313 426960600 211854713 -733687358 251466836 -33491050 -882811238 455544614 774581544 768447941 -241033484 441104324 -493975870 308277556 275268265 935941507 -152292053 -961509996 -740482111 -954176110 -924254634 -518710544",
"output": "504117593849498724"
},
{
"input": "5 32\n-540510995 -841481393 -94342377 -74818927 -93445356\n686714668 -82581175 736472406 502016312 575563638 -899308712 503504178 -644271272 -437408397 385778869 -746757839 306275973 -663503743 -431116516 -418708278 -515261493 -988182324 900230931 218258353 -714420102 -241118202 294802602 -937785552 -857537498 -723195312 -690515139 -214508504 -44086454 -231621215 -418360090 -810003786 -675944617",
"output": "534123411186652380"
},
{
"input": "32 13\n-999451897 -96946179 -524159869 -906101658 -63367320 -629803888 -968586834 -658416130 -874232857 -926556428 -749908220 -517073321 -659752288 -910152878 -786916085 -607633039 -191428642 -867952926 -873793977 -584331784 -733245792 -779809700 -554228536 -464503499 561577340 258991071 -569805979 -372655165 -106685554 -619607960 188856473 -268960803\n886429660 -587284372 911396803 -462990289 -228681210 -876239914 -822830527 -750131315 -401234943 116991909 -582713480 979631847 813552478",
"output": "848714444125692276"
},
{
"input": "12 25\n-464030345 -914672073 -483242132 -856226270 -925135169 -353124606 -294027092 -619650850 -490724485 -240424784 -483066792 -921640365\n279850608 726838739 -431610610 242749870 -244020223 -396865433 129534799 182767854 -939698671 342579400 330027106 893561388 -263513962 643369418 276245179 -99206565 -473767261 -168908664 -853755837 -270920164 -661186118 199341055 765543053 908211534 -93363867",
"output": "866064226130454915"
},
{
"input": "10 13\n-749120991 -186261632 -335412349 -231354880 -195919225 -808736065 -481883825 -263383991 -664780611 -605377134\n718174936 -140362196 -669193674 -598621021 -464130929 450701419 -331183926 107203430 946959233 -565825915 -558199897 246556991 -666216081",
"output": "501307028237810934"
},
{
"input": "17 13\n-483786205 -947257449 -125949195 -294711143 -420288876 -812462057 -250049555 -911026413 -188146919 -129501682 -869006661 -649643966 -26976411 -275761039 -869067490 -272248209 -342067346\n445539900 529728842 -808170728 673157826 -70778491 642872105 299298867 -76674218 -902394063 377664752 723887448 -121522827 906464625",
"output": "822104826327386019"
},
{
"input": "15 29\n-716525085 -464205793 -577203110 -979997115 -491032521 -70793687 -770595947 -817983495 -767886763 -223333719 -971913221 -944656683 -200397825 -295615495 -945544540\n-877638425 -146878165 523758517 -158778747 -49535534 597311016 77325385 494128313 12111658 -4196724 295706874 477139483 375083042 726254399 -439255703 662913604 -481588088 673747948 -345999555 -723334478 -656721905 276267528 628773156 851420802 -585029291 -643535709 -968999740 -384418713 -510285542",
"output": "941783658451562540"
},
{
"input": "5 7\n-130464232 -73113866 -542094710 -53118823 -63528720\n449942926 482853427 861095072 316710734 194604468 20277633 668816604",
"output": "-1288212069119760"
},
{
"input": "24 24\n-700068683 -418791905 -24650102 -167277317 -182309202 -517748507 -663050677 -854097070 -426998982 -197009558 -101944229 -746589957 -849018439 -774208211 -946709040 -594578249 -276703474 -434567489 -743600446 -625029074 -977300284 -895608684 -878936220 -850670748\n704881272 169877679 705460701 94083210 403943695 987978311 786162506 658067668 697640875 186287 295558596 286470276 251313879 353071193 755450449 173370603 805550377 192465301 168935494 110161743 285139426 985238736 723221868 520679017",
"output": "-18990884587723"
},
{
"input": "39 9\n44558618 981372779 318891054 283079237 285093436 907256321 414759796 652683534 79042330 249010687 7020063 309415438 788425492 138577429 714835649 954204512 795507844 389962019 507308352 408180613 194676444 44962879 922688019 101163040 327953325 560462120 183657590 273616448 226876035 233697890 720185285 689340674 372938362 15088928 283418109 796807778 149989495 694808087 276385512\n-681609072 -210918688 -757170622 -205635977 -597872997 -496188744 -97031207 -311654366 -389141528",
"output": "-1464096896176096"
},
{
"input": "5 7\n869535768 926886134 457905290 946881177 936471280\n-550057074 -517146573 -138904928 -683289266 -805395532 -979722367 -331183396",
"output": "-120782803247464704"
},
{
"input": "24 24\n299931317 581208095 975349898 832722683 817690798 482251493 336949323 145902930 573001018 802990442 898055771 253410043 150981561 225791789 53290960 405421751 723296526 565432511 256399554 374970926 22699716 104391316 121063780 149329252\n-295118728 -830122321 -294539299 -905916790 -596056305 -12021689 -213837494 -341932332 -302359125 -999813713 -704441404 -713529724 -748686121 -646928807 -244549551 -826629397 -194449623 -807534699 -831064506 -889838257 -714860574 -14761264 -276778132 -479320983",
"output": "-640647347631440"
},
{
"input": "14 8\n-1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "-1000000000000000000"
}
] | 1,518,644,636
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 31
| 5,632,000
|
n, m = map(int,input().split())
t = list(map(int,input().split()))
b = list(map(int,input().split()))
larg = max(t)
t = t.remove(larg)
sec = max(t)
third = max(b)
bright = sec*third
print(bright)
|
Title: A Compatible Pair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming.
Little Tommy has *n* lanterns and Big Banban has *m* lanterns. Tommy's lanterns have brightness *a*1,<=*a*2,<=...,<=*a**n*, and Banban's have brightness *b*1,<=*b*2,<=...,<=*b**m* respectively.
Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns.
Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible.
You are asked to find the brightness of the chosen pair if both of them choose optimally.
Input Specification:
The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50).
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*.
The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*.
All the integers range from <=-<=109 to 109.
Output Specification:
Print a single integer — the brightness of the chosen pair.
Demo Input:
['2 2\n20 18\n2 14\n', '5 3\n-1 0 1 2 3\n-1 0 1\n']
Demo Output:
['252\n', '2\n']
Note:
In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself.
In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself.
|
```python
n, m = map(int,input().split())
t = list(map(int,input().split()))
b = list(map(int,input().split()))
larg = max(t)
t = t.remove(larg)
sec = max(t)
third = max(b)
bright = sec*third
print(bright)
```
| -1
|
|
616
|
B
|
Dinner with Emma
|
PROGRAMMING
| 1,000
|
[
"games",
"greedy"
] | null | null |
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of *n* streets and *m* avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to *n* and the avenues are numbered with integers from 1 to *m*. The cost of dinner in the restaurant at the intersection of the *i*-th street and the *j*-th avenue is *c**ij*.
Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.
|
The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of streets and avenues in Munhattan.
Each of the next *n* lines contains *m* integers *c**ij* (1<=≤<=*c**ij*<=≤<=109) — the cost of the dinner in the restaurant on the intersection of the *i*-th street and the *j*-th avenue.
|
Print the only integer *a* — the cost of the dinner for Jack and Emma.
|
[
"3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1\n",
"3 3\n1 2 3\n2 3 1\n3 1 2\n"
] |
[
"2\n",
"1\n"
] |
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.
In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1.
| 0
|
[
{
"input": "3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1",
"output": "2"
},
{
"input": "3 3\n1 2 3\n2 3 1\n3 1 2",
"output": "1"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 10\n74 35 82 39 1 84 29 41 70 12",
"output": "1"
},
{
"input": "10 1\n44\n23\n65\n17\n48\n29\n49\n88\n91\n85",
"output": "91"
},
{
"input": "10 10\n256 72 455 45 912 506 235 68 951 92\n246 305 45 212 788 621 449 876 459 899\n732 107 230 357 370 610 997 669 61 192\n131 93 481 527 983 920 825 540 435 54\n777 682 984 20 337 480 264 137 249 502\n51 467 479 228 923 752 714 436 199 973\n3 91 612 571 631 212 751 84 886 948\n252 130 583 23 194 985 234 978 709 16\n636 991 203 469 719 540 184 902 503 652\n826 680 150 284 37 987 360 183 447 51",
"output": "184"
},
{
"input": "1 1\n1000000000",
"output": "1000000000"
},
{
"input": "2 1\n999999999\n1000000000",
"output": "1000000000"
}
] | 1,588,160,488
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 93
| 0
|
l = list(map(int, input().rstrip().split()))
a=[]
for i in range(l[0]):
a.append(list(map(int, input().rstrip().split())))
y=max((int(a[i][0]) for i in range(l[0])))
x=min(a[y])
print(a[y][x])
|
Title: Dinner with Emma
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of *n* streets and *m* avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to *n* and the avenues are numbered with integers from 1 to *m*. The cost of dinner in the restaurant at the intersection of the *i*-th street and the *j*-th avenue is *c**ij*.
Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.
Input Specification:
The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of streets and avenues in Munhattan.
Each of the next *n* lines contains *m* integers *c**ij* (1<=≤<=*c**ij*<=≤<=109) — the cost of the dinner in the restaurant on the intersection of the *i*-th street and the *j*-th avenue.
Output Specification:
Print the only integer *a* — the cost of the dinner for Jack and Emma.
Demo Input:
['3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1\n', '3 3\n1 2 3\n2 3 1\n3 1 2\n']
Demo Output:
['2\n', '1\n']
Note:
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.
In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1.
|
```python
l = list(map(int, input().rstrip().split()))
a=[]
for i in range(l[0]):
a.append(list(map(int, input().rstrip().split())))
y=max((int(a[i][0]) for i in range(l[0])))
x=min(a[y])
print(a[y][x])
```
| -1
|
|
207
|
D2
|
The Beaver's Problem - 3
|
PROGRAMMING
| 2,000
|
[] | null | null |
The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorting documents by their subjects. Let's describe the problem:
You've got some training set of documents. For each document you know its subject. The subject in this problem is an integer from 1 to 3. Each of these numbers has a physical meaning. For instance, all documents with subject 3 are about trade.
You can download the training set of documents at the following link: http://download4.abbyy.com/a2/X2RZ2ZWXBG5VYWAL61H76ZQM/train.zip. The archive contains three directories with names "1", "2", "3". Directory named "1" contains documents on the 1-st subject, directory "2" contains documents on the 2-nd subject, and directory "3" contains documents on the 3-rd subject. Each document corresponds to exactly one file from some directory.
All documents have the following format: the first line contains the document identifier, the second line contains the name of the document, all subsequent lines contain the text of the document. The document identifier is used to make installing the problem more convenient and has no useful information for the participants.
You need to write a program that should indicate the subject for a given document. It is guaranteed that all documents given as input to your program correspond to one of the three subjects of the training set.
|
The first line contains integer *id* (0<=≤<=*id*<=≤<=106) — the document identifier. The second line contains the name of the document. The third and the subsequent lines contain the text of the document. It is guaranteed that the size of any given document will not exceed 10 kilobytes.
The tests for this problem are divided into 10 groups. Documents of groups 1 and 2 are taken from the training set, but their identifiers will not match the identifiers specified in the training set. Groups from the 3-rd to the 10-th are roughly sorted by the author in ascending order of difficulty (these groups contain documents which aren't present in the training set).
|
Print an integer from 1 to 3, inclusive — the number of the subject the given document corresponds to.
|
[] |
[] |
none
| 10
|
[
{
"input": "7000\nTREASURY BALANCES AT FED FELL ON MARCH 27\nWASHINGTON, March 30 - Treasury balances at the Federal\nReserve fell on March 27 to 2.424 billion dlrs from 2.508\nbillion dlrs on the previous business day, the Treasury said in\nits latest budget statement.\nBalances in tax and loan note accounts fell to 9.706\nbillion dlrs from 10.786 billion dlrs on the same respective\ndays.\nThe Treasury's operating cash balance totaled 12.131\nbillion dlrs on March 27 compared with 13.283 billion dlrs on\nMarch 26.",
"output": "1"
},
{
"input": "8000\nNEW YORK BUSINESS LOANS FALL 222 MLN DLRS\nNEW YORK, March 26 - Commercial and industrial loans on the\nbooks of the 10 major New York banks, excluding acceptances,\nfell 222 mln dlrs to 64.05 billion in the week ended March 18,\nthe Federal Reserve Bank of New York said.\nIncluding acceptances, loans fell 390 mln dlrs to 64.74\nbillion.\nCommercial paper outstanding nationally rose 35 mln dlrs to\n339.04 billion.\nNational business loan data are scheduled to be released on\nFriday.",
"output": "2"
}
] | 1,673,006,155
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS2
| 0
| 15
| 0
|
# LUOGU_RID: 98854447
n = int(input())
print(3 if n == 6 or n == 11 else 2 if n == 8 or n == 9 else 1)
|
Title: The Beaver's Problem - 3
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorting documents by their subjects. Let's describe the problem:
You've got some training set of documents. For each document you know its subject. The subject in this problem is an integer from 1 to 3. Each of these numbers has a physical meaning. For instance, all documents with subject 3 are about trade.
You can download the training set of documents at the following link: http://download4.abbyy.com/a2/X2RZ2ZWXBG5VYWAL61H76ZQM/train.zip. The archive contains three directories with names "1", "2", "3". Directory named "1" contains documents on the 1-st subject, directory "2" contains documents on the 2-nd subject, and directory "3" contains documents on the 3-rd subject. Each document corresponds to exactly one file from some directory.
All documents have the following format: the first line contains the document identifier, the second line contains the name of the document, all subsequent lines contain the text of the document. The document identifier is used to make installing the problem more convenient and has no useful information for the participants.
You need to write a program that should indicate the subject for a given document. It is guaranteed that all documents given as input to your program correspond to one of the three subjects of the training set.
Input Specification:
The first line contains integer *id* (0<=≤<=*id*<=≤<=106) — the document identifier. The second line contains the name of the document. The third and the subsequent lines contain the text of the document. It is guaranteed that the size of any given document will not exceed 10 kilobytes.
The tests for this problem are divided into 10 groups. Documents of groups 1 and 2 are taken from the training set, but their identifiers will not match the identifiers specified in the training set. Groups from the 3-rd to the 10-th are roughly sorted by the author in ascending order of difficulty (these groups contain documents which aren't present in the training set).
Output Specification:
Print an integer from 1 to 3, inclusive — the number of the subject the given document corresponds to.
Note:
none
|
```python
# LUOGU_RID: 98854447
n = int(input())
print(3 if n == 6 or n == 11 else 2 if n == 8 or n == 9 else 1)
```
| 0
|
|
427
|
A
|
Police Recruits
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.
Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated.
|
The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time.
|
Print a single integer, the number of crimes which will go untreated.
|
[
"3\n-1 -1 1\n",
"8\n1 -1 1 -1 -1 1 1 1\n",
"11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n"
] |
[
"2\n",
"1\n",
"8\n"
] |
Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this crime will go untreated. 1. One more person is hired. 1. One more person is hired. 1. One more person is hired.
The answer is one, as one crime (on step 5) will go untreated.
| 500
|
[
{
"input": "3\n-1 -1 1",
"output": "2"
},
{
"input": "8\n1 -1 1 -1 -1 1 1 1",
"output": "1"
},
{
"input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1",
"output": "8"
},
{
"input": "7\n-1 -1 1 1 -1 -1 1",
"output": "2"
},
{
"input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 -1 2 2 1 6 5 -1 5",
"output": "5"
},
{
"input": "98\n-1 -1 1 -1 -1 -1 -1 1 -1 -1 1 -1 -1 1 -1 1 1 1 -1 1 1 1 1 1 -1 1 -1 -1 -1 -1 1 -1 -1 1 1 -1 1 1 1 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 1 -1 1 -1 1 -1 1 1 1 1 1 1 1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 -1 1 1 1 -1 1 1 -1 -1 -1 1 1 1 -1 -1 -1 1 -1 1 1",
"output": "13"
},
{
"input": "3\n-1 5 4",
"output": "1"
},
{
"input": "146\n4 -1 -1 -1 -1 -1 -1 -1 -1 -1 4 -1 3 -1 3 -1 -1 1 4 -1 2 -1 -1 3 -1 -1 -1 4 1 -1 -1 -1 4 -1 -1 -1 -1 -1 -1 3 2 -1 3 2 4 5 2 4 1 5 -1 -1 2 -1 -1 1 -1 5 3 -1 1 2 2 3 5 3 -1 -1 3 -1 -1 3 5 5 -1 -1 5 -1 4 4 1 -1 -1 -1 2 1 -1 -1 -1 2 5 3 -1 -1 -1 3 -1 5 4 -1 1 -1 -1 3 -1 -1 3 1 1 2 -1 -1 -1 1 3 1 -1 2 -1 -1 5 5 -1 -1 3 4 5 1 -1 2 -1 -1 -1 3 -1 5 3 2 -1 2 -1 -1 5 -1 3 -1",
"output": "5"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "2\n1 -1",
"output": "0"
},
{
"input": "2\n-1 1",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n-1 -1",
"output": "2"
},
{
"input": "4\n10 -1 -1 -1",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "4\n-1 -1 1 1",
"output": "2"
}
] | 1,685,649,824
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 15
| 0
|
n=int(input())
for _ in range(n):
l=map(int, input().split())
counter=0
crimes=0
for i in l:
if counter==0 and i==-1:
crimes+=1
else:
counter=-1
if i==1:
counter+=1
print(crimes)
|
Title: Police Recruits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.
Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated.
Input Specification:
The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time.
Output Specification:
Print a single integer, the number of crimes which will go untreated.
Demo Input:
['3\n-1 -1 1\n', '8\n1 -1 1 -1 -1 1 1 1\n', '11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n']
Demo Output:
['2\n', '1\n', '8\n']
Note:
Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this crime will go untreated. 1. One more person is hired. 1. One more person is hired. 1. One more person is hired.
The answer is one, as one crime (on step 5) will go untreated.
|
```python
n=int(input())
for _ in range(n):
l=map(int, input().split())
counter=0
crimes=0
for i in l:
if counter==0 and i==-1:
crimes+=1
else:
counter=-1
if i==1:
counter+=1
print(crimes)
```
| -1
|
|
27
|
A
|
Next Test
|
PROGRAMMING
| 1,200
|
[
"implementation",
"sortings"
] |
A. Next Test
|
2
|
256
|
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.
You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
|
The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests.
|
Output the required default value for the next test index.
|
[
"3\n1 7 2\n"
] |
[
"3\n"
] |
none
| 500
|
[
{
"input": "1\n1",
"output": "2"
},
{
"input": "2\n2 1",
"output": "3"
},
{
"input": "3\n3 4 1",
"output": "2"
},
{
"input": "4\n6 4 3 5",
"output": "1"
},
{
"input": "5\n3 2 1 7 4",
"output": "5"
},
{
"input": "6\n4 1 2 5 3 7",
"output": "6"
},
{
"input": "7\n3 2 1 6 5 7 4",
"output": "8"
},
{
"input": "8\n2 8 3 7 6 9 1 5",
"output": "4"
},
{
"input": "9\n10 5 9 3 8 7 1 2 4",
"output": "6"
},
{
"input": "10\n7 2 3 8 9 6 5 4 1 10",
"output": "11"
},
{
"input": "1\n1",
"output": "2"
},
{
"input": "2\n1 2",
"output": "3"
},
{
"input": "3\n2 4 1",
"output": "3"
},
{
"input": "4\n4 2 3 1",
"output": "5"
},
{
"input": "5\n3 1 4 2 5",
"output": "6"
},
{
"input": "6\n1 3 6 7 2 4",
"output": "5"
},
{
"input": "7\n1 5 4 7 2 3 6",
"output": "8"
},
{
"input": "8\n12 1 6 5 2 8 3 4",
"output": "7"
},
{
"input": "9\n3 2 7 5 6 4 1 9 10",
"output": "8"
},
{
"input": "10\n1 7 13 6 5 10 3 8 2 4",
"output": "9"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n3",
"output": "1"
},
{
"input": "1\n3000",
"output": "1"
},
{
"input": "2\n2 3",
"output": "1"
},
{
"input": "2\n3000 1",
"output": "2"
}
] | 1,635,748,855
| 2,147,483,647
|
PyPy 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 186
| 19,763,200
|
n = int(input())
arr = [int(x) for x in input().split()]
arr.sort()
arr1 = [False]*(3001)
for i in range(n):
arr1[arr[i]] = True
for i in range(1,n+2):
if not arr1[i]:
print(i)
sys.exit()
|
Title: Next Test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.
You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests.
Output Specification:
Output the required default value for the next test index.
Demo Input:
['3\n1 7 2\n']
Demo Output:
['3\n']
Note:
none
|
```python
n = int(input())
arr = [int(x) for x in input().split()]
arr.sort()
arr1 = [False]*(3001)
for i in range(n):
arr1[arr[i]] = True
for i in range(1,n+2):
if not arr1[i]:
print(i)
sys.exit()
```
| -1
|
746
|
D
|
Green and Black Tea
|
PROGRAMMING
| 1,500
|
[
"constructive algorithms",
"greedy",
"math"
] | null | null |
Innokentiy likes tea very much and today he wants to drink exactly *n* cups of tea. He would be happy to drink more but he had exactly *n* tea bags, *a* of them are green and *b* are black.
Innokentiy doesn't like to drink the same tea (green or black) more than *k* times in a row. Your task is to determine the order of brewing tea bags so that Innokentiy will be able to drink *n* cups of tea, without drinking the same tea more than *k* times in a row, or to inform that it is impossible. Each tea bag has to be used exactly once.
|
The first line contains four integers *n*, *k*, *a* and *b* (1<=≤<=*k*<=≤<=*n*<=≤<=105, 0<=≤<=*a*,<=*b*<=≤<=*n*) — the number of cups of tea Innokentiy wants to drink, the maximum number of cups of same tea he can drink in a row, the number of tea bags of green and black tea. It is guaranteed that *a*<=+<=*b*<==<=*n*.
|
If it is impossible to drink *n* cups of tea, print "NO" (without quotes).
Otherwise, print the string of the length *n*, which consists of characters 'G' and 'B'. If some character equals 'G', then the corresponding cup of tea should be green. If some character equals 'B', then the corresponding cup of tea should be black.
If there are multiple answers, print any of them.
|
[
"5 1 3 2\n",
"7 2 2 5\n",
"4 3 4 0\n"
] |
[
"GBGBG\n",
"BBGBGBB",
"NO\n"
] |
none
| 2,000
|
[
{
"input": "5 1 3 2",
"output": "GBGBG"
},
{
"input": "7 2 2 5",
"output": "BBGBBGB"
},
{
"input": "4 3 4 0",
"output": "NO"
},
{
"input": "2 2 0 2",
"output": "BB"
},
{
"input": "3 2 0 3",
"output": "NO"
},
{
"input": "1 1 0 1",
"output": "B"
},
{
"input": "1 1 1 0",
"output": "G"
},
{
"input": "11 2 3 8",
"output": "BBGBBGBBGBB"
},
{
"input": "100000 39 24855 75145",
"output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB..."
},
{
"input": "2 2 2 0",
"output": "GG"
},
{
"input": "2 2 1 1",
"output": "GB"
},
{
"input": "3 2 2 1",
"output": "GGB"
},
{
"input": "3 2 1 2",
"output": "BBG"
},
{
"input": "5 1 4 1",
"output": "NO"
},
{
"input": "10 1 7 3",
"output": "NO"
},
{
"input": "20 1 5 15",
"output": "NO"
},
{
"input": "1000 123 447 553",
"output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGB..."
},
{
"input": "3000 70 2946 54",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBGGGGGGGGGGGGGG..."
},
{
"input": "10000 590 4020 5980",
"output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB..."
},
{
"input": "10001 1841 1052 8949",
"output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB..."
},
{
"input": "50000 104 31045 18955",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG..."
},
{
"input": "59999 16660 46835 13164",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG..."
},
{
"input": "70000 3017 31589 38411",
"output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB..."
},
{
"input": "99999 15805 82842 17157",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG..."
},
{
"input": "100000 6397 59122 40878",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG..."
},
{
"input": "100000 856 69042 30958",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG..."
},
{
"input": "6 1 3 3",
"output": "GBGBGB"
},
{
"input": "9 2 3 6",
"output": "BBGBBGBBG"
},
{
"input": "9 1 6 3",
"output": "NO"
},
{
"input": "10 1 4 6",
"output": "NO"
},
{
"input": "10 1 3 7",
"output": "NO"
},
{
"input": "10 1 2 8",
"output": "NO"
},
{
"input": "10 1 5 5",
"output": "GBGBGBGBGB"
},
{
"input": "11 1 2 9",
"output": "NO"
},
{
"input": "11 2 4 7",
"output": "BBGBBGBBGBG"
},
{
"input": "11 2 5 6",
"output": "BBGBGBGBGBG"
},
{
"input": "11 2 6 5",
"output": "GGBGBGBGBGB"
},
{
"input": "11 1 7 4",
"output": "NO"
},
{
"input": "11 2 8 3",
"output": "GGBGGBGGBGG"
},
{
"input": "11 1 9 2",
"output": "NO"
},
{
"input": "99999 10760 33333 66666",
"output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB..."
},
{
"input": "99999 3434 66666 33333",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG..."
},
{
"input": "99999 7343 33332 66667",
"output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB..."
},
{
"input": "99999 177 33334 66665",
"output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB..."
},
{
"input": "99999 3580 66665 33334",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG..."
},
{
"input": "99999 1681 66667 33332",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG..."
},
{
"input": "7 3 2 5",
"output": "BBBGBBG"
},
{
"input": "9 2 7 2",
"output": "NO"
},
{
"input": "10 2 8 2",
"output": "NO"
},
{
"input": "100000 50000 50000 50000",
"output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBG..."
}
] | 1,690,269,178
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 1
| 92
| 2,764,800
|
import sys
import random
from math import gcd, lcm, sqrt, isqrt, perm, comb, factorial
from collections import Counter, defaultdict, deque
from functools import lru_cache, reduce, cmp_to_key
from itertools import accumulate, combinations, permutations
from heapq import nsmallest, nlargest, heappushpop, heapify, heappop, heappush
from copy import deepcopy
from bisect import bisect_left, bisect_right
from string import ascii_lowercase, ascii_uppercase
inf = float('inf')
input = lambda: sys.stdin.readline().strip()
I = lambda: input()
II = lambda: int(input())
MII = lambda: map(int, input().split())
LI = lambda: list(input().split())
LII = lambda: list(map(int, input().split()))
GMI = lambda: map(lambda x: int(x) - 1, input().split())
LGMI = lambda: list(map(lambda x: int(x) - 1, input().split()))
MOD = 10**9+7
def solve():
n, k, a, b = MII()
cg, cb = 'G', 'B'
if a < b:
a, b = b, a
cg, cb = cb, cg
if (a-1) // (b+1) >= k:
return print('NO')
length = a // (b+1)
res = [cg] * length + [cb]
res = res * b
r = a - length * b
res.extend([cg] * r)
print(''.join(res))
return
solve()
|
Title: Green and Black Tea
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innokentiy likes tea very much and today he wants to drink exactly *n* cups of tea. He would be happy to drink more but he had exactly *n* tea bags, *a* of them are green and *b* are black.
Innokentiy doesn't like to drink the same tea (green or black) more than *k* times in a row. Your task is to determine the order of brewing tea bags so that Innokentiy will be able to drink *n* cups of tea, without drinking the same tea more than *k* times in a row, or to inform that it is impossible. Each tea bag has to be used exactly once.
Input Specification:
The first line contains four integers *n*, *k*, *a* and *b* (1<=≤<=*k*<=≤<=*n*<=≤<=105, 0<=≤<=*a*,<=*b*<=≤<=*n*) — the number of cups of tea Innokentiy wants to drink, the maximum number of cups of same tea he can drink in a row, the number of tea bags of green and black tea. It is guaranteed that *a*<=+<=*b*<==<=*n*.
Output Specification:
If it is impossible to drink *n* cups of tea, print "NO" (without quotes).
Otherwise, print the string of the length *n*, which consists of characters 'G' and 'B'. If some character equals 'G', then the corresponding cup of tea should be green. If some character equals 'B', then the corresponding cup of tea should be black.
If there are multiple answers, print any of them.
Demo Input:
['5 1 3 2\n', '7 2 2 5\n', '4 3 4 0\n']
Demo Output:
['GBGBG\n', 'BBGBGBB', 'NO\n']
Note:
none
|
```python
import sys
import random
from math import gcd, lcm, sqrt, isqrt, perm, comb, factorial
from collections import Counter, defaultdict, deque
from functools import lru_cache, reduce, cmp_to_key
from itertools import accumulate, combinations, permutations
from heapq import nsmallest, nlargest, heappushpop, heapify, heappop, heappush
from copy import deepcopy
from bisect import bisect_left, bisect_right
from string import ascii_lowercase, ascii_uppercase
inf = float('inf')
input = lambda: sys.stdin.readline().strip()
I = lambda: input()
II = lambda: int(input())
MII = lambda: map(int, input().split())
LI = lambda: list(input().split())
LII = lambda: list(map(int, input().split()))
GMI = lambda: map(lambda x: int(x) - 1, input().split())
LGMI = lambda: list(map(lambda x: int(x) - 1, input().split()))
MOD = 10**9+7
def solve():
n, k, a, b = MII()
cg, cb = 'G', 'B'
if a < b:
a, b = b, a
cg, cb = cb, cg
if (a-1) // (b+1) >= k:
return print('NO')
length = a // (b+1)
res = [cg] * length + [cb]
res = res * b
r = a - length * b
res.extend([cg] * r)
print(''.join(res))
return
solve()
```
| 0
|
|
1,004
|
B
|
Sonya and Exhibition
|
PROGRAMMING
| 1,300
|
[
"constructive algorithms",
"greedy",
"implementation",
"math"
] | null | null |
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are $n$ flowers in a row in the exhibition. Sonya can put either a rose or a lily in the $i$-th position. Thus each of $n$ positions should contain exactly one flower: a rose or a lily.
She knows that exactly $m$ people will visit this exhibition. The $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.
Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.
|
The first line contains two integers $n$ and $m$ ($1\leq n, m\leq 10^3$) — the number of flowers and visitors respectively.
Each of the next $m$ lines contains two integers $l_i$ and $r_i$ ($1\leq l_i\leq r_i\leq n$), meaning that $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive.
|
Print the string of $n$ characters. The $i$-th symbol should be «0» if you want to put a rose in the $i$-th position, otherwise «1» if you want to put a lily.
If there are multiple answers, print any.
|
[
"5 3\n1 3\n2 4\n2 5\n",
"6 3\n5 6\n1 4\n4 6\n"
] |
[
"01100",
"110010"
] |
In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;
- in the segment $[1\ldots3]$, there are one rose and two lilies, so the beauty is equal to $1\cdot 2=2$; - in the segment $[2\ldots4]$, there are one rose and two lilies, so the beauty is equal to $1\cdot 2=2$; - in the segment $[2\ldots5]$, there are two roses and two lilies, so the beauty is equal to $2\cdot 2=4$.
The total beauty is equal to $2+2+4=8$.
In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;
- in the segment $[5\ldots6]$, there are one rose and one lily, so the beauty is equal to $1\cdot 1=1$; - in the segment $[1\ldots4]$, there are two roses and two lilies, so the beauty is equal to $2\cdot 2=4$; - in the segment $[4\ldots6]$, there are two roses and one lily, so the beauty is equal to $2\cdot 1=2$.
The total beauty is equal to $1+4+2=7$.
| 1,000
|
[
{
"input": "5 3\n1 3\n2 4\n2 5",
"output": "01010"
},
{
"input": "6 3\n5 6\n1 4\n4 6",
"output": "010101"
},
{
"input": "10 4\n3 3\n1 6\n9 9\n10 10",
"output": "0101010101"
},
{
"input": "1 1\n1 1",
"output": "0"
},
{
"input": "1000 10\n3 998\n2 1000\n1 999\n2 1000\n3 998\n2 1000\n3 998\n1 1000\n2 1000\n3 999",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "1000 20\n50 109\n317 370\n710 770\n440 488\n711 757\n236 278\n314 355\n131 190\n115 162\n784 834\n16 56\n677 730\n802 844\n632 689\n23 74\n647 702\n930 986\n926 983\n769 822\n508 558",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "1000 10\n138 238\n160 260\n716 816\n504 604\n98 198\n26 126\n114 214\n217 317\n121 221\n489 589",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "1000 5\n167 296\n613 753\n650 769\n298 439\n71 209",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "1000 5\n349 415\n714 773\n125 179\n1 80\n148 242",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "914 10\n587 646\n770 843\n825 875\n439 485\n465 521\n330 387\n405 480\n477 521\n336 376\n715 771",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "571 10\n13 94\n450 510\n230 293\n302 375\n304 354\n421 504\n24 87\n122 181\n221 296\n257 307",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "6 2\n1 6\n1 4",
"output": "010101"
},
{
"input": "2 1\n1 2",
"output": "01"
}
] | 1,530,982,983
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 27
| 109
| 0
|
def scanf(t=int):
return list(map(t, input().split()))
n, m = scanf()
s = '01' * (n//2) + '0' * (n % 2)
print(s)
|
Title: Sonya and Exhibition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are $n$ flowers in a row in the exhibition. Sonya can put either a rose or a lily in the $i$-th position. Thus each of $n$ positions should contain exactly one flower: a rose or a lily.
She knows that exactly $m$ people will visit this exhibition. The $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.
Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.
Input Specification:
The first line contains two integers $n$ and $m$ ($1\leq n, m\leq 10^3$) — the number of flowers and visitors respectively.
Each of the next $m$ lines contains two integers $l_i$ and $r_i$ ($1\leq l_i\leq r_i\leq n$), meaning that $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive.
Output Specification:
Print the string of $n$ characters. The $i$-th symbol should be «0» if you want to put a rose in the $i$-th position, otherwise «1» if you want to put a lily.
If there are multiple answers, print any.
Demo Input:
['5 3\n1 3\n2 4\n2 5\n', '6 3\n5 6\n1 4\n4 6\n']
Demo Output:
['01100', '110010']
Note:
In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;
- in the segment $[1\ldots3]$, there are one rose and two lilies, so the beauty is equal to $1\cdot 2=2$; - in the segment $[2\ldots4]$, there are one rose and two lilies, so the beauty is equal to $1\cdot 2=2$; - in the segment $[2\ldots5]$, there are two roses and two lilies, so the beauty is equal to $2\cdot 2=4$.
The total beauty is equal to $2+2+4=8$.
In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;
- in the segment $[5\ldots6]$, there are one rose and one lily, so the beauty is equal to $1\cdot 1=1$; - in the segment $[1\ldots4]$, there are two roses and two lilies, so the beauty is equal to $2\cdot 2=4$; - in the segment $[4\ldots6]$, there are two roses and one lily, so the beauty is equal to $2\cdot 1=2$.
The total beauty is equal to $1+4+2=7$.
|
```python
def scanf(t=int):
return list(map(t, input().split()))
n, m = scanf()
s = '01' * (n//2) + '0' * (n % 2)
print(s)
```
| 3
|
|
703
|
A
|
Mishka and Game
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.
In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.
Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
|
The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th round respectively.
|
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
|
[
"3\n3 5\n2 1\n4 2\n",
"2\n6 1\n1 6\n",
"3\n1 5\n3 3\n2 2\n"
] |
[
"Mishka",
"Friendship is magic!^^",
"Chris"
] |
In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
| 500
|
[
{
"input": "3\n3 5\n2 1\n4 2",
"output": "Mishka"
},
{
"input": "2\n6 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "3\n1 5\n3 3\n2 2",
"output": "Chris"
},
{
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1",
"output": "Mishka"
},
{
"input": "8\n2 4\n1 4\n1 5\n2 6\n2 5\n2 5\n2 4\n2 5",
"output": "Chris"
},
{
"input": "8\n4 1\n2 6\n4 2\n2 5\n5 2\n3 5\n5 2\n1 5",
"output": "Friendship is magic!^^"
},
{
"input": "9\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n1 3",
"output": "Mishka"
},
{
"input": "9\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "9\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1",
"output": "Chris"
},
{
"input": "9\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "10\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n1 4",
"output": "Mishka"
},
{
"input": "10\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "10\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1",
"output": "Chris"
},
{
"input": "10\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "100\n2 4\n6 6\n3 2\n1 5\n5 2\n1 5\n1 5\n3 1\n6 5\n4 3\n1 1\n5 1\n3 3\n2 4\n1 5\n3 4\n5 1\n5 5\n2 5\n2 1\n4 3\n6 5\n1 1\n2 1\n1 3\n1 1\n6 4\n4 6\n6 4\n2 1\n2 5\n6 2\n3 4\n5 5\n1 4\n4 6\n3 4\n1 6\n5 1\n4 3\n3 4\n2 2\n1 2\n2 3\n1 3\n4 4\n5 5\n4 5\n4 4\n3 1\n4 5\n2 3\n2 6\n6 5\n6 1\n6 6\n2 3\n6 4\n3 3\n2 5\n4 4\n3 1\n2 4\n6 1\n3 2\n1 3\n5 4\n6 6\n2 5\n5 1\n1 1\n2 5\n6 5\n3 6\n5 6\n4 3\n3 4\n3 4\n6 5\n5 2\n4 2\n1 1\n3 1\n2 6\n1 6\n1 2\n6 1\n3 4\n1 6\n3 1\n5 3\n1 3\n5 6\n2 1\n6 4\n3 1\n1 6\n6 3\n3 3\n4 3",
"output": "Chris"
},
{
"input": "100\n4 1\n3 4\n4 6\n4 5\n6 5\n5 3\n6 2\n6 3\n5 2\n4 5\n1 5\n5 4\n1 4\n4 5\n4 6\n1 6\n4 4\n5 1\n6 4\n6 4\n4 6\n2 3\n6 2\n4 6\n1 4\n2 3\n4 3\n1 3\n6 2\n3 1\n3 4\n2 6\n4 5\n5 4\n2 2\n2 5\n4 1\n2 2\n3 3\n1 4\n5 6\n6 4\n4 2\n6 1\n5 5\n4 1\n2 1\n6 4\n4 4\n4 3\n5 3\n4 5\n5 3\n3 5\n6 3\n1 1\n3 4\n6 3\n6 1\n5 1\n2 4\n4 3\n2 2\n5 5\n1 5\n5 3\n4 6\n1 4\n6 3\n4 3\n2 4\n3 2\n2 4\n3 4\n6 2\n5 6\n1 2\n1 5\n5 5\n2 6\n5 1\n1 6\n5 3\n3 5\n2 6\n4 6\n6 2\n3 1\n5 5\n6 1\n3 6\n4 4\n1 1\n4 6\n5 3\n4 2\n5 1\n3 3\n2 1\n1 4",
"output": "Mishka"
},
{
"input": "100\n6 3\n4 5\n4 3\n5 4\n5 1\n6 3\n4 2\n4 6\n3 1\n2 4\n2 2\n4 6\n5 3\n5 5\n4 2\n6 2\n2 3\n4 4\n6 4\n3 5\n2 4\n2 2\n5 2\n3 5\n2 4\n4 4\n3 5\n6 5\n1 3\n1 6\n2 2\n2 4\n3 2\n5 4\n1 6\n3 4\n4 1\n1 5\n1 4\n5 3\n2 2\n4 5\n6 3\n4 4\n1 1\n4 1\n2 4\n4 1\n4 5\n5 3\n1 1\n1 6\n5 6\n6 6\n4 2\n4 3\n3 4\n3 6\n3 4\n6 5\n3 4\n5 4\n5 1\n5 3\n5 1\n1 2\n2 6\n3 4\n6 5\n4 3\n1 1\n5 5\n5 1\n3 3\n5 2\n1 3\n6 6\n5 6\n1 4\n4 4\n1 4\n3 6\n6 5\n3 3\n3 6\n1 5\n1 2\n3 6\n3 6\n4 1\n5 2\n1 2\n5 2\n3 3\n4 4\n4 2\n6 2\n5 4\n6 1\n6 3",
"output": "Mishka"
},
{
"input": "8\n4 1\n6 2\n4 1\n5 3\n4 1\n5 3\n6 2\n5 3",
"output": "Mishka"
},
{
"input": "5\n3 6\n3 5\n3 5\n1 6\n3 5",
"output": "Chris"
},
{
"input": "4\n4 1\n2 4\n5 3\n3 6",
"output": "Friendship is magic!^^"
},
{
"input": "6\n6 3\n5 1\n6 3\n4 3\n4 3\n5 2",
"output": "Mishka"
},
{
"input": "7\n3 4\n1 4\n2 5\n1 6\n1 6\n1 5\n3 4",
"output": "Chris"
},
{
"input": "6\n6 2\n2 5\n5 2\n3 6\n4 3\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "8\n6 1\n5 3\n4 3\n4 1\n5 1\n4 2\n4 2\n4 1",
"output": "Mishka"
},
{
"input": "9\n2 5\n2 5\n1 4\n2 6\n2 4\n2 5\n2 6\n1 5\n2 5",
"output": "Chris"
},
{
"input": "4\n6 2\n2 4\n4 2\n3 6",
"output": "Friendship is magic!^^"
},
{
"input": "9\n5 2\n4 1\n4 1\n5 1\n6 2\n6 1\n5 3\n6 1\n6 2",
"output": "Mishka"
},
{
"input": "8\n2 4\n3 6\n1 6\n1 6\n2 4\n3 4\n3 6\n3 4",
"output": "Chris"
},
{
"input": "6\n5 3\n3 6\n6 2\n1 6\n5 1\n3 5",
"output": "Friendship is magic!^^"
},
{
"input": "6\n5 2\n5 1\n6 1\n5 2\n4 2\n5 1",
"output": "Mishka"
},
{
"input": "5\n1 4\n2 5\n3 4\n2 6\n3 4",
"output": "Chris"
},
{
"input": "4\n6 2\n3 4\n5 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "93\n4 3\n4 1\n4 2\n5 2\n5 3\n6 3\n4 3\n6 2\n6 3\n5 1\n4 2\n4 2\n5 1\n6 2\n6 3\n6 1\n4 1\n6 2\n5 3\n4 3\n4 1\n4 2\n5 2\n6 3\n5 2\n5 2\n6 3\n5 1\n6 2\n5 2\n4 1\n5 2\n5 1\n4 1\n6 1\n5 2\n4 3\n5 3\n5 3\n5 1\n4 3\n4 3\n4 2\n4 1\n6 2\n6 1\n4 1\n5 2\n5 2\n6 2\n5 3\n5 1\n6 2\n5 1\n6 3\n5 2\n6 2\n6 2\n4 2\n5 2\n6 1\n6 3\n6 3\n5 1\n5 1\n4 1\n5 1\n4 3\n5 3\n6 3\n4 1\n4 3\n6 1\n6 1\n4 2\n6 2\n4 2\n5 2\n4 1\n5 2\n4 1\n5 1\n5 2\n5 1\n4 1\n6 3\n6 2\n4 3\n4 1\n5 2\n4 3\n5 2\n5 1",
"output": "Mishka"
},
{
"input": "11\n1 6\n1 6\n2 4\n2 5\n3 4\n1 5\n1 6\n1 5\n1 6\n2 6\n3 4",
"output": "Chris"
},
{
"input": "70\n6 1\n3 6\n4 3\n2 5\n5 2\n1 4\n6 2\n1 6\n4 3\n1 4\n5 3\n2 4\n5 3\n1 6\n5 1\n3 5\n4 2\n2 4\n5 1\n3 5\n6 2\n1 5\n4 2\n2 5\n5 3\n1 5\n4 2\n1 4\n5 2\n2 6\n4 3\n1 5\n6 2\n3 4\n4 2\n3 5\n6 3\n3 4\n5 1\n1 4\n4 2\n1 4\n6 3\n2 6\n5 2\n1 6\n6 1\n2 6\n5 3\n1 5\n5 1\n1 6\n4 1\n1 5\n4 2\n2 4\n5 1\n2 5\n6 3\n1 4\n6 3\n3 6\n5 1\n1 4\n5 3\n3 5\n4 2\n3 4\n6 2\n1 4",
"output": "Friendship is magic!^^"
},
{
"input": "59\n4 1\n5 3\n6 1\n4 2\n5 1\n4 3\n6 1\n5 1\n4 3\n4 3\n5 2\n5 3\n4 1\n6 2\n5 1\n6 3\n6 3\n5 2\n5 2\n6 1\n4 1\n6 1\n4 3\n5 3\n5 3\n4 3\n4 2\n4 2\n6 3\n6 3\n6 1\n4 3\n5 1\n6 2\n6 1\n4 1\n6 1\n5 3\n4 2\n5 1\n6 2\n6 2\n4 3\n5 3\n4 3\n6 3\n5 2\n5 2\n4 3\n5 1\n5 3\n6 1\n6 3\n6 3\n4 3\n5 2\n5 2\n5 2\n4 3",
"output": "Mishka"
},
{
"input": "42\n1 5\n1 6\n1 6\n1 4\n2 5\n3 6\n1 6\n3 4\n2 5\n2 5\n2 4\n1 4\n3 4\n2 4\n2 6\n1 5\n3 6\n2 6\n2 6\n3 5\n1 4\n1 5\n2 6\n3 6\n1 4\n3 4\n2 4\n1 6\n3 4\n2 4\n2 6\n1 6\n1 4\n1 6\n1 6\n2 4\n1 5\n1 6\n2 5\n3 6\n3 5\n3 4",
"output": "Chris"
},
{
"input": "78\n4 3\n3 5\n4 3\n1 5\n5 1\n1 5\n4 3\n1 4\n6 3\n1 5\n4 1\n2 4\n4 3\n2 4\n5 1\n3 6\n4 2\n3 6\n6 3\n3 4\n4 3\n3 6\n5 3\n1 5\n4 1\n2 6\n4 2\n2 4\n4 1\n3 5\n5 2\n3 6\n4 3\n2 4\n6 3\n1 6\n4 3\n3 5\n6 3\n2 6\n4 1\n2 4\n6 2\n1 6\n4 2\n1 4\n4 3\n1 4\n4 3\n2 4\n6 2\n3 5\n6 1\n3 6\n5 3\n1 6\n6 1\n2 6\n4 2\n1 5\n6 2\n2 6\n6 3\n2 4\n4 2\n3 5\n6 1\n2 5\n5 3\n2 6\n5 1\n3 6\n4 3\n3 6\n6 3\n2 5\n6 1\n2 6",
"output": "Friendship is magic!^^"
},
{
"input": "76\n4 1\n5 2\n4 3\n5 2\n5 3\n5 2\n6 1\n4 2\n6 2\n5 3\n4 2\n6 2\n4 1\n4 2\n5 1\n5 1\n6 2\n5 2\n5 3\n6 3\n5 2\n4 3\n6 3\n6 1\n4 3\n6 2\n6 1\n4 1\n6 1\n5 3\n4 1\n5 3\n4 2\n5 2\n4 3\n6 1\n6 2\n5 2\n6 1\n5 3\n4 3\n5 1\n5 3\n4 3\n5 1\n5 1\n4 1\n4 1\n4 1\n4 3\n5 3\n6 3\n6 3\n5 2\n6 2\n6 3\n5 1\n6 3\n5 3\n6 1\n5 3\n4 1\n5 3\n6 1\n4 2\n6 2\n4 3\n4 1\n6 2\n4 3\n5 3\n5 2\n5 3\n5 1\n6 3\n5 2",
"output": "Mishka"
},
{
"input": "84\n3 6\n3 4\n2 5\n2 4\n1 6\n3 4\n1 5\n1 6\n3 5\n1 6\n2 4\n2 6\n2 6\n2 4\n3 5\n1 5\n3 6\n3 6\n3 4\n3 4\n2 6\n1 6\n1 6\n3 5\n3 4\n1 6\n3 4\n3 5\n2 4\n2 5\n2 5\n3 5\n1 6\n3 4\n2 6\n2 6\n3 4\n3 4\n2 5\n2 5\n2 4\n3 4\n2 5\n3 4\n3 4\n2 6\n2 6\n1 6\n2 4\n1 5\n3 4\n2 5\n2 5\n3 4\n2 4\n2 6\n2 6\n1 4\n3 5\n3 5\n2 4\n2 5\n3 4\n1 5\n1 5\n2 6\n1 5\n3 5\n2 4\n2 5\n3 4\n2 6\n1 6\n2 5\n3 5\n3 5\n3 4\n2 5\n2 6\n3 4\n1 6\n2 5\n2 6\n1 4",
"output": "Chris"
},
{
"input": "44\n6 1\n1 6\n5 2\n1 4\n6 2\n2 5\n5 3\n3 6\n5 2\n1 6\n4 1\n2 4\n6 1\n3 4\n6 3\n3 6\n4 3\n2 4\n6 1\n3 4\n6 1\n1 6\n4 1\n3 5\n6 1\n3 6\n4 1\n1 4\n4 2\n2 6\n6 1\n2 4\n6 2\n1 4\n6 2\n2 4\n5 2\n3 6\n6 3\n2 6\n5 3\n3 4\n5 3\n2 4",
"output": "Friendship is magic!^^"
},
{
"input": "42\n5 3\n5 1\n5 2\n4 1\n6 3\n6 1\n6 2\n4 1\n4 3\n4 1\n5 1\n5 3\n5 1\n4 1\n4 2\n6 1\n6 3\n5 1\n4 1\n4 1\n6 3\n4 3\n6 3\n5 2\n6 1\n4 1\n5 3\n4 3\n5 2\n6 3\n6 1\n5 1\n4 2\n4 3\n5 2\n5 3\n6 3\n5 2\n5 1\n5 3\n6 2\n6 1",
"output": "Mishka"
},
{
"input": "50\n3 6\n2 6\n1 4\n1 4\n1 4\n2 5\n3 4\n3 5\n2 6\n1 6\n3 5\n1 5\n2 6\n2 4\n2 4\n3 5\n1 6\n1 5\n1 5\n1 4\n3 5\n1 6\n3 5\n1 4\n1 5\n1 4\n3 6\n1 6\n1 4\n1 4\n1 4\n1 5\n3 6\n1 6\n1 6\n2 4\n1 5\n2 6\n2 5\n3 5\n3 6\n3 4\n2 4\n2 6\n3 4\n2 5\n3 6\n3 5\n2 4\n2 4",
"output": "Chris"
},
{
"input": "86\n6 3\n2 4\n6 3\n3 5\n6 3\n1 5\n5 2\n2 4\n4 3\n2 6\n4 1\n2 6\n5 2\n1 4\n5 1\n2 4\n4 1\n1 4\n6 2\n3 5\n4 2\n2 4\n6 2\n1 5\n5 3\n2 5\n5 1\n1 6\n6 1\n1 4\n4 3\n3 4\n5 2\n2 4\n5 3\n2 5\n4 3\n3 4\n4 1\n1 5\n6 3\n3 4\n4 3\n3 4\n4 1\n3 4\n5 1\n1 6\n4 2\n1 6\n5 1\n2 4\n5 1\n3 6\n4 1\n1 5\n5 2\n1 4\n4 3\n2 5\n5 1\n1 5\n6 2\n2 6\n4 2\n2 4\n4 1\n2 5\n5 3\n3 4\n5 1\n3 4\n6 3\n3 4\n4 3\n2 6\n6 2\n2 5\n5 2\n3 5\n4 2\n3 6\n6 2\n3 4\n4 2\n2 4",
"output": "Friendship is magic!^^"
},
{
"input": "84\n6 1\n6 3\n6 3\n4 1\n4 3\n4 2\n6 3\n5 3\n6 1\n6 3\n4 3\n5 2\n5 3\n5 1\n6 2\n6 2\n6 1\n4 1\n6 3\n5 2\n4 1\n5 3\n6 3\n4 2\n6 2\n6 3\n4 3\n4 1\n4 3\n5 1\n5 1\n5 1\n4 1\n6 1\n4 3\n6 2\n5 1\n5 1\n6 2\n5 2\n4 1\n6 1\n6 1\n6 3\n6 2\n4 3\n6 3\n6 2\n5 2\n5 1\n4 3\n6 2\n4 1\n6 2\n6 1\n5 2\n5 1\n6 2\n6 1\n5 3\n5 2\n6 1\n6 3\n5 2\n6 1\n6 3\n4 3\n5 1\n6 3\n6 1\n5 3\n4 3\n5 2\n5 1\n6 2\n5 3\n6 1\n5 1\n4 1\n5 1\n5 1\n5 2\n5 2\n5 1",
"output": "Mishka"
},
{
"input": "92\n1 5\n2 4\n3 5\n1 6\n2 5\n1 6\n3 6\n1 6\n2 4\n3 4\n3 4\n3 6\n1 5\n2 5\n1 5\n1 5\n2 6\n2 4\n3 6\n1 4\n1 6\n2 6\n3 4\n2 6\n2 6\n1 4\n3 5\n2 5\n2 6\n1 5\n1 4\n1 5\n3 6\n3 5\n2 5\n1 5\n3 5\n3 6\n2 6\n2 6\n1 5\n3 4\n2 4\n3 6\n2 5\n1 5\n2 4\n1 4\n2 6\n2 6\n2 6\n1 5\n3 6\n3 6\n2 5\n1 4\n2 4\n3 4\n1 5\n2 5\n2 4\n2 5\n3 5\n3 4\n3 6\n2 6\n3 5\n1 4\n3 4\n1 6\n3 6\n2 6\n1 4\n3 6\n3 6\n2 5\n2 6\n1 6\n2 6\n3 5\n2 5\n3 6\n2 5\n2 6\n1 5\n2 4\n1 4\n2 4\n1 5\n2 5\n2 5\n2 6",
"output": "Chris"
},
{
"input": "20\n5 1\n1 4\n4 3\n1 5\n4 2\n3 6\n6 2\n1 6\n4 1\n1 4\n5 2\n3 4\n5 1\n1 6\n5 1\n2 6\n6 3\n2 5\n6 2\n2 4",
"output": "Friendship is magic!^^"
},
{
"input": "100\n4 3\n4 3\n4 2\n4 3\n4 1\n4 3\n5 2\n5 2\n6 2\n4 2\n5 1\n4 2\n5 2\n6 1\n4 1\n6 3\n5 3\n5 1\n5 1\n5 1\n5 3\n6 1\n6 1\n4 1\n5 2\n5 2\n6 1\n6 3\n4 2\n4 1\n5 3\n4 1\n5 3\n5 1\n6 3\n6 3\n6 1\n5 2\n5 3\n5 3\n6 1\n4 1\n6 2\n6 1\n6 2\n6 3\n4 3\n4 3\n6 3\n4 2\n4 2\n5 3\n5 2\n5 2\n4 3\n5 3\n5 2\n4 2\n5 1\n4 2\n5 1\n5 3\n6 3\n5 3\n5 3\n4 2\n4 1\n4 2\n4 3\n6 3\n4 3\n6 2\n6 1\n5 3\n5 2\n4 1\n6 1\n5 2\n6 2\n4 2\n6 3\n4 3\n5 1\n6 3\n5 2\n4 3\n5 3\n5 3\n4 3\n6 3\n4 3\n4 1\n5 1\n6 2\n6 3\n5 3\n6 1\n6 3\n5 3\n6 1",
"output": "Mishka"
},
{
"input": "100\n1 5\n1 4\n1 5\n2 4\n2 6\n3 6\n3 5\n1 5\n2 5\n3 6\n3 5\n1 6\n1 4\n1 5\n1 6\n2 6\n1 5\n3 5\n3 4\n2 6\n2 6\n2 5\n3 4\n1 6\n1 4\n2 4\n1 5\n1 6\n3 5\n1 6\n2 6\n3 5\n1 6\n3 4\n3 5\n1 6\n3 6\n2 4\n2 4\n3 5\n2 6\n1 5\n3 5\n3 6\n2 4\n2 4\n2 6\n3 4\n3 4\n1 5\n1 4\n2 5\n3 4\n1 4\n2 6\n2 5\n2 4\n2 4\n2 5\n1 5\n1 6\n1 5\n1 5\n1 5\n1 6\n3 4\n2 4\n3 5\n3 5\n1 6\n3 5\n1 5\n1 6\n3 6\n3 4\n1 5\n3 5\n3 6\n1 4\n3 6\n1 5\n3 5\n3 6\n3 5\n1 4\n3 4\n2 4\n2 4\n2 5\n3 6\n3 5\n1 5\n2 4\n1 4\n3 4\n1 5\n3 4\n3 6\n3 5\n3 4",
"output": "Chris"
},
{
"input": "100\n4 3\n3 4\n5 1\n2 5\n5 3\n1 5\n6 3\n2 4\n5 2\n2 6\n5 2\n1 5\n6 3\n1 5\n6 3\n3 4\n5 2\n1 5\n6 1\n1 5\n4 2\n3 5\n6 3\n2 6\n6 3\n1 4\n6 2\n3 4\n4 1\n3 6\n5 1\n2 4\n5 1\n3 4\n6 2\n3 5\n4 1\n2 6\n4 3\n2 6\n5 2\n3 6\n6 2\n3 5\n4 3\n1 5\n5 3\n3 6\n4 2\n3 4\n6 1\n3 4\n5 2\n2 6\n5 2\n2 4\n6 2\n3 6\n4 3\n2 4\n4 3\n2 6\n4 2\n3 4\n6 3\n2 4\n6 3\n3 5\n5 2\n1 5\n6 3\n3 6\n4 3\n1 4\n5 2\n1 6\n4 1\n2 5\n4 1\n2 4\n4 2\n2 5\n6 1\n2 4\n6 3\n1 5\n4 3\n2 6\n6 3\n2 6\n5 3\n1 5\n4 1\n1 5\n6 2\n2 5\n5 1\n3 6\n4 3\n3 4",
"output": "Friendship is magic!^^"
},
{
"input": "99\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n1 3",
"output": "Mishka"
},
{
"input": "99\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "99\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1",
"output": "Chris"
},
{
"input": "99\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "100\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n1 4",
"output": "Mishka"
},
{
"input": "100\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "100\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1",
"output": "Chris"
},
{
"input": "100\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "84\n6 2\n1 5\n6 2\n2 3\n5 5\n1 2\n3 4\n3 4\n6 5\n6 4\n2 5\n4 1\n1 2\n1 1\n1 4\n2 5\n5 6\n6 3\n2 4\n5 5\n2 6\n3 4\n5 1\n3 3\n5 5\n4 6\n4 6\n2 4\n4 1\n5 2\n2 2\n3 6\n3 3\n4 6\n1 1\n2 4\n6 5\n5 2\n6 5\n5 5\n2 5\n6 4\n1 1\n6 2\n3 6\n6 5\n4 4\n1 5\n5 6\n4 4\n3 5\n6 1\n3 4\n1 5\n4 6\n4 6\n4 1\n3 6\n6 2\n1 1\n4 5\n5 4\n5 3\n3 4\n6 4\n1 1\n5 2\n6 5\n6 1\n2 2\n2 4\n3 3\n4 6\n1 3\n6 6\n5 2\n1 6\n6 2\n6 6\n4 1\n3 6\n6 4\n2 3\n3 4",
"output": "Chris"
},
{
"input": "70\n3 4\n2 3\n2 3\n6 5\n6 6\n4 3\n2 3\n3 1\n3 5\n5 6\n1 6\n2 5\n5 3\n2 5\n4 6\n5 1\n6 1\n3 1\n3 3\n5 3\n2 1\n3 3\n6 4\n6 3\n4 3\n4 5\n3 5\n5 5\n5 2\n1 6\n3 4\n5 2\n2 4\n1 6\n4 3\n4 3\n6 2\n1 3\n1 5\n6 1\n3 1\n1 1\n1 3\n2 2\n3 2\n6 4\n1 1\n4 4\n3 1\n4 5\n4 2\n6 3\n4 4\n3 2\n1 2\n2 6\n3 3\n1 5\n1 1\n6 5\n2 2\n3 1\n5 4\n5 2\n6 4\n6 3\n6 6\n6 3\n3 3\n5 4",
"output": "Mishka"
},
{
"input": "56\n6 4\n3 4\n6 1\n3 3\n1 4\n2 3\n1 5\n2 5\n1 5\n5 5\n2 3\n1 1\n3 2\n3 5\n4 6\n4 4\n5 2\n4 3\n3 1\n3 6\n2 3\n3 4\n5 6\n5 2\n5 6\n1 5\n1 5\n4 1\n6 3\n2 2\n2 1\n5 5\n2 1\n4 1\n5 4\n2 5\n4 1\n6 2\n3 4\n4 2\n6 4\n5 4\n4 2\n4 3\n6 2\n6 2\n3 1\n1 4\n3 6\n5 1\n5 5\n3 6\n6 4\n2 3\n6 5\n3 3",
"output": "Mishka"
},
{
"input": "94\n2 4\n6 4\n1 6\n1 4\n5 1\n3 3\n4 3\n6 1\n6 5\n3 2\n2 3\n5 1\n5 3\n1 2\n4 3\n3 2\n2 3\n4 6\n1 3\n6 3\n1 1\n3 2\n4 3\n1 5\n4 6\n3 2\n6 3\n1 6\n1 1\n1 2\n3 5\n1 3\n3 5\n4 4\n4 2\n1 4\n4 5\n1 3\n1 2\n1 1\n5 4\n5 5\n6 1\n2 1\n2 6\n6 6\n4 2\n3 6\n1 6\n6 6\n1 5\n3 2\n1 2\n4 4\n6 4\n4 1\n1 5\n3 3\n1 3\n3 4\n4 4\n1 1\n2 5\n4 5\n3 1\n3 1\n3 6\n3 2\n1 4\n1 6\n6 3\n2 4\n1 1\n2 2\n2 2\n2 1\n5 4\n1 2\n6 6\n2 2\n3 3\n6 3\n6 3\n1 6\n2 3\n2 4\n2 3\n6 6\n2 6\n6 3\n3 5\n1 4\n1 1\n3 5",
"output": "Chris"
},
{
"input": "81\n4 2\n1 2\n2 3\n4 5\n6 2\n1 6\n3 6\n3 4\n4 6\n4 4\n3 5\n4 6\n3 6\n3 5\n3 1\n1 3\n5 3\n3 4\n1 1\n4 1\n1 2\n6 1\n1 3\n6 5\n4 5\n4 2\n4 5\n6 2\n1 2\n2 6\n5 2\n1 5\n2 4\n4 3\n5 4\n1 2\n5 3\n2 6\n6 4\n1 1\n1 3\n3 1\n3 1\n6 5\n5 5\n6 1\n6 6\n5 2\n1 3\n1 4\n2 3\n5 5\n3 1\n3 1\n4 4\n1 6\n6 4\n2 2\n4 6\n4 4\n2 6\n2 4\n2 4\n4 1\n1 6\n1 4\n1 3\n6 5\n5 1\n1 3\n5 1\n1 4\n3 5\n2 6\n1 3\n5 6\n3 5\n4 4\n5 5\n5 6\n4 3",
"output": "Chris"
},
{
"input": "67\n6 5\n3 6\n1 6\n5 3\n5 4\n5 1\n1 6\n1 1\n3 2\n4 4\n3 1\n4 1\n1 5\n5 3\n3 3\n6 4\n2 4\n2 2\n4 3\n1 4\n1 4\n6 1\n1 2\n2 2\n5 1\n6 2\n3 5\n5 5\n2 2\n6 5\n6 2\n4 4\n3 1\n4 2\n6 6\n6 4\n5 1\n2 2\n4 5\n5 5\n4 6\n1 5\n6 3\n4 4\n1 5\n6 4\n3 6\n3 4\n1 6\n2 4\n2 1\n2 5\n6 5\n6 4\n4 1\n3 2\n1 2\n5 1\n5 6\n1 5\n3 5\n3 1\n5 3\n3 2\n5 1\n4 6\n6 6",
"output": "Mishka"
},
{
"input": "55\n6 6\n6 5\n2 2\n2 2\n6 4\n5 5\n6 5\n5 3\n1 3\n2 2\n5 6\n3 3\n3 3\n6 5\n3 5\n5 5\n1 2\n1 1\n4 6\n1 2\n5 5\n6 2\n6 3\n1 2\n5 1\n1 3\n3 3\n4 4\n2 5\n1 1\n5 3\n4 3\n2 2\n4 5\n5 6\n4 5\n6 3\n1 6\n6 4\n3 6\n1 6\n5 2\n6 3\n2 3\n5 5\n4 3\n3 1\n4 2\n1 1\n2 5\n5 3\n2 2\n6 3\n4 5\n2 2",
"output": "Mishka"
},
{
"input": "92\n2 3\n1 3\n2 6\n5 1\n5 5\n3 2\n5 6\n2 5\n3 1\n3 6\n4 5\n2 5\n1 2\n2 3\n6 5\n3 6\n4 4\n6 2\n4 5\n4 4\n5 1\n6 1\n3 4\n3 5\n6 6\n3 2\n6 4\n2 2\n3 5\n6 4\n6 3\n6 6\n3 4\n3 3\n6 1\n5 4\n6 2\n2 6\n5 6\n1 4\n4 6\n6 3\n3 1\n4 1\n6 6\n3 5\n6 3\n6 1\n1 6\n3 2\n6 6\n4 3\n3 4\n1 3\n3 5\n5 3\n6 5\n4 3\n5 5\n4 1\n1 5\n6 4\n2 3\n2 3\n1 5\n1 2\n5 2\n4 3\n3 6\n5 5\n5 4\n1 4\n3 3\n1 6\n5 6\n5 4\n5 3\n1 1\n6 2\n5 5\n2 5\n4 3\n6 6\n5 1\n1 1\n4 6\n4 6\n3 1\n6 4\n2 4\n2 2\n2 1",
"output": "Chris"
},
{
"input": "79\n5 3\n4 6\n3 6\n2 1\n5 2\n2 3\n4 4\n6 2\n2 5\n1 6\n6 6\n2 6\n3 3\n4 5\n6 2\n2 1\n1 5\n5 1\n2 1\n2 6\n5 3\n6 2\n2 6\n2 3\n1 5\n4 4\n6 3\n5 2\n3 2\n1 3\n1 3\n6 3\n2 6\n3 6\n5 3\n4 5\n6 1\n3 5\n3 5\n6 5\n1 5\n4 2\n6 2\n2 3\n4 6\n3 6\n2 5\n4 4\n1 1\n4 6\n2 6\n6 4\n3 2\n4 1\n1 2\n6 4\n5 6\n1 4\n2 2\n5 4\n3 2\n1 2\n2 4\n2 5\n2 1\n3 6\n3 3\n1 1\n2 2\n4 4\n4 5\n3 3\n5 3\n6 2\n4 5\n6 5\n2 5\n5 6\n2 2",
"output": "Chris"
},
{
"input": "65\n1 1\n5 1\n2 2\n5 4\n4 5\n2 5\n3 2\n5 6\n6 3\n1 1\n6 1\n1 5\n1 1\n5 2\n6 4\n1 6\n1 1\n4 3\n2 3\n5 6\n4 4\n6 2\n1 3\n4 3\n1 3\n6 3\n3 5\n4 2\n4 1\n6 1\n3 2\n2 6\n3 2\n3 5\n6 3\n4 3\n1 5\n2 6\n1 3\n4 1\n4 1\n2 5\n2 5\n6 2\n5 3\n3 1\n3 3\n5 1\n2 4\n5 3\n3 3\n1 1\n6 3\n3 3\n5 1\n1 6\n4 5\n6 6\n5 5\n2 5\n4 1\n2 2\n1 4\n1 6\n6 5",
"output": "Mishka"
},
{
"input": "1\n1 1",
"output": "Friendship is magic!^^"
}
] | 1,693,677,736
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 8
| 62
| 0
|
t = int(input())
mik , chri = 0,0
mikcount = 0
for _ in range(t):
nlist = list(map(int,input().split()))
if nlist[0] > nlist[1]:
mikcount +=1
if mikcount > t // 2 :
print("Mishka")
elif mikcount < t // 2 :
print("Chris")
else:
print("Friendship is magic!^^")
|
Title: Mishka and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.
In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.
Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
Input Specification:
The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th round respectively.
Output Specification:
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
Demo Input:
['3\n3 5\n2 1\n4 2\n', '2\n6 1\n1 6\n', '3\n1 5\n3 3\n2 2\n']
Demo Output:
['Mishka', 'Friendship is magic!^^', 'Chris']
Note:
In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
|
```python
t = int(input())
mik , chri = 0,0
mikcount = 0
for _ in range(t):
nlist = list(map(int,input().split()))
if nlist[0] > nlist[1]:
mikcount +=1
if mikcount > t // 2 :
print("Mishka")
elif mikcount < t // 2 :
print("Chris")
else:
print("Friendship is magic!^^")
```
| 0
|
|
228
|
D
|
Zigzag
|
PROGRAMMING
| 2,100
|
[
"data structures"
] | null | null |
The court wizard Zigzag wants to become a famous mathematician. For that, he needs his own theorem, like the Cauchy theorem, or his sum, like the Minkowski sum. But most of all he wants to have his sequence, like the Fibonacci sequence, and his function, like the Euler's totient function.
The Zigag's sequence with the zigzag factor z is an infinite sequence *S**i**z* (*i*<=≥<=1; *z*<=≥<=2), that is determined as follows:
- *S**i**z*<==<=2, when ; - , when ; - , when .
Operation means taking the remainder from dividing number *x* by number *y*. For example, the beginning of sequence *S**i*3 (zigzag factor 3) looks as follows: 1, 2, 3, 2, 1, 2, 3, 2, 1.
Let's assume that we are given an array *a*, consisting of *n* integers. Let's define element number *i* (1<=≤<=*i*<=≤<=*n*) of the array as *a**i*. The Zigzag function is function , where *l*,<=*r*,<=*z* satisfy the inequalities 1<=≤<=*l*<=≤<=*r*<=≤<=*n*, *z*<=≥<=2.
To become better acquainted with the Zigzag sequence and the Zigzag function, the wizard offers you to implement the following operations on the given array *a*.
1. The assignment operation. The operation parameters are (*p*,<=*v*). The operation denotes assigning value *v* to the *p*-th array element. After the operation is applied, the value of the array element *a**p* equals *v*. 1. The Zigzag operation. The operation parameters are (*l*,<=*r*,<=*z*). The operation denotes calculating the Zigzag function *Z*(*l*,<=*r*,<=*z*).
Explore the magical powers of zigzags, implement the described operations.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — The number of elements in array *a*. The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of operations. Next *m* lines contain the operations' descriptions. An operation's description starts with integer *t**i* (1<=≤<=*t**i*<=≤<=2) — the operation type.
- If *t**i*<==<=1 (assignment operation), then on the line follow two space-separated integers: *p**i*,<=*v**i* (1<=≤<=*p**i*<=≤<=*n*; 1<=≤<=*v**i*<=≤<=109) — the parameters of the assigning operation. - If *t**i*<==<=2 (Zigzag operation), then on the line follow three space-separated integers: *l**i*,<=*r**i*,<=*z**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*; 2<=≤<=*z**i*<=≤<=6) — the parameters of the Zigzag operation.
You should execute the operations in the order, in which they are given in the input.
|
For each Zigzag operation print the calculated value of the Zigzag function on a single line. Print the values for Zigzag functions in the order, in which they are given in the input.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
|
[
"5\n2 3 1 5 5\n4\n2 2 3 2\n2 1 5 3\n1 3 5\n2 1 5 3\n"
] |
[
"5\n26\n38\n"
] |
Explanation of the sample test:
- Result of the first operation is *Z*(2, 3, 2) = 3·1 + 1·2 = 5. - Result of the second operation is *Z*(1, 5, 3) = 2·1 + 3·2 + 1·3 + 5·2 + 5·1 = 26. - After the third operation array *a* is equal to 2, 3, 5, 5, 5. - Result of the forth operation is *Z*(1, 5, 3) = 2·1 + 3·2 + 5·3 + 5·2 + 5·1 = 38.
| 2,000
|
[] | 1,691,442,096
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 0
| 92
| 0
|
print("_RANDOM_GUESS_1691442096.9175146")# 1691442096.9175315
|
Title: Zigzag
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The court wizard Zigzag wants to become a famous mathematician. For that, he needs his own theorem, like the Cauchy theorem, or his sum, like the Minkowski sum. But most of all he wants to have his sequence, like the Fibonacci sequence, and his function, like the Euler's totient function.
The Zigag's sequence with the zigzag factor z is an infinite sequence *S**i**z* (*i*<=≥<=1; *z*<=≥<=2), that is determined as follows:
- *S**i**z*<==<=2, when ; - , when ; - , when .
Operation means taking the remainder from dividing number *x* by number *y*. For example, the beginning of sequence *S**i*3 (zigzag factor 3) looks as follows: 1, 2, 3, 2, 1, 2, 3, 2, 1.
Let's assume that we are given an array *a*, consisting of *n* integers. Let's define element number *i* (1<=≤<=*i*<=≤<=*n*) of the array as *a**i*. The Zigzag function is function , where *l*,<=*r*,<=*z* satisfy the inequalities 1<=≤<=*l*<=≤<=*r*<=≤<=*n*, *z*<=≥<=2.
To become better acquainted with the Zigzag sequence and the Zigzag function, the wizard offers you to implement the following operations on the given array *a*.
1. The assignment operation. The operation parameters are (*p*,<=*v*). The operation denotes assigning value *v* to the *p*-th array element. After the operation is applied, the value of the array element *a**p* equals *v*. 1. The Zigzag operation. The operation parameters are (*l*,<=*r*,<=*z*). The operation denotes calculating the Zigzag function *Z*(*l*,<=*r*,<=*z*).
Explore the magical powers of zigzags, implement the described operations.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — The number of elements in array *a*. The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of operations. Next *m* lines contain the operations' descriptions. An operation's description starts with integer *t**i* (1<=≤<=*t**i*<=≤<=2) — the operation type.
- If *t**i*<==<=1 (assignment operation), then on the line follow two space-separated integers: *p**i*,<=*v**i* (1<=≤<=*p**i*<=≤<=*n*; 1<=≤<=*v**i*<=≤<=109) — the parameters of the assigning operation. - If *t**i*<==<=2 (Zigzag operation), then on the line follow three space-separated integers: *l**i*,<=*r**i*,<=*z**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*; 2<=≤<=*z**i*<=≤<=6) — the parameters of the Zigzag operation.
You should execute the operations in the order, in which they are given in the input.
Output Specification:
For each Zigzag operation print the calculated value of the Zigzag function on a single line. Print the values for Zigzag functions in the order, in which they are given in the input.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
Demo Input:
['5\n2 3 1 5 5\n4\n2 2 3 2\n2 1 5 3\n1 3 5\n2 1 5 3\n']
Demo Output:
['5\n26\n38\n']
Note:
Explanation of the sample test:
- Result of the first operation is *Z*(2, 3, 2) = 3·1 + 1·2 = 5. - Result of the second operation is *Z*(1, 5, 3) = 2·1 + 3·2 + 1·3 + 5·2 + 5·1 = 26. - After the third operation array *a* is equal to 2, 3, 5, 5, 5. - Result of the forth operation is *Z*(1, 5, 3) = 2·1 + 3·2 + 5·3 + 5·2 + 5·1 = 38.
|
```python
print("_RANDOM_GUESS_1691442096.9175146")# 1691442096.9175315
```
| 0
|
|
58
|
A
|
Chat room
|
PROGRAMMING
| 1,000
|
[
"greedy",
"strings"
] |
A. Chat room
|
1
|
256
|
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
|
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
|
If Vasya managed to say hello, print "YES", otherwise print "NO".
|
[
"ahhellllloou\n",
"hlelo\n"
] |
[
"YES\n",
"NO\n"
] |
none
| 500
|
[
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,642,856,777
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 6
| 61
| 512,000
|
i = list(input())
ofs = 0
lposes = []
for x in range(len(i)):
if i[x+ofs] not in ['h','e','l','o']:
del i[x+ofs]
ofs -= 1
if i[x+ofs] == 'l':
lposes.append(x+ofs)
for lp in lposes:
if len(i[:lp]) < 2:
continue
if 'e' in i[:lp+1] and 'l' in i[lp:]:
el = i[:lp-1];e=str(el).rfind('e')
ll = i[lp:];l=ll.index('l')
if 'h' in el[:e+1] and 'o' in ll[l:]:
print('YES')
exit()
print('NO')
|
Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none
|
```python
i = list(input())
ofs = 0
lposes = []
for x in range(len(i)):
if i[x+ofs] not in ['h','e','l','o']:
del i[x+ofs]
ofs -= 1
if i[x+ofs] == 'l':
lposes.append(x+ofs)
for lp in lposes:
if len(i[:lp]) < 2:
continue
if 'e' in i[:lp+1] and 'l' in i[lp:]:
el = i[:lp-1];e=str(el).rfind('e')
ll = i[lp:];l=ll.index('l')
if 'h' in el[:e+1] and 'o' in ll[l:]:
print('YES')
exit()
print('NO')
```
| 0
|
26
|
B
|
Regular Bracket Sequence
|
PROGRAMMING
| 1,400
|
[
"greedy"
] |
B. Regular Bracket Sequence
|
5
|
256
|
A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.
One day Johnny got bracket sequence. He decided to remove some of the brackets from it in order to obtain a regular bracket sequence. What is the maximum length of a regular bracket sequence which can be obtained?
|
Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed 106.
|
Output the maximum possible length of a regular bracket sequence.
|
[
"(()))(\n",
"((()())\n"
] |
[
"4\n",
"6\n"
] |
none
| 1,000
|
[
{
"input": "(()))(",
"output": "4"
},
{
"input": "((()())",
"output": "6"
},
{
"input": "(",
"output": "0"
},
{
"input": ")",
"output": "0"
},
{
"input": ")(()(",
"output": "2"
},
{
"input": "))))))(",
"output": "0"
},
{
"input": "()()(()(((",
"output": "6"
},
{
"input": "()))(()((((()(())",
"output": "10"
},
{
"input": "())))((()())())))))())",
"output": "14"
},
{
"input": ")))((((())(()((()((((()()())((",
"output": "16"
},
{
"input": "))()()((()()))())()(((((((())((((((((())()()((())(",
"output": "32"
},
{
"input": "))())))))))())))))()()))()()))))())))))()))))))))))))(()))())(()))))(()))))())))((((()()))))()))()))",
"output": "48"
}
] | 1,544,236,279
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 2
| 186
| 0
|
n = input()
a = 0
b = []
c = 0
for i in n:
a += 1
if i == "(":
b.append(1)
else:
b.append(-1)
while b[0] != 1:
del b[0]
c += 1
while b[-1] != -1:
del b[-1]
c += 1
print(len(n)-abs(sum(b))-c)
|
Title: Regular Bracket Sequence
Time Limit: 5 seconds
Memory Limit: 256 megabytes
Problem Description:
A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.
One day Johnny got bracket sequence. He decided to remove some of the brackets from it in order to obtain a regular bracket sequence. What is the maximum length of a regular bracket sequence which can be obtained?
Input Specification:
Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed 106.
Output Specification:
Output the maximum possible length of a regular bracket sequence.
Demo Input:
['(()))(\n', '((()())\n']
Demo Output:
['4\n', '6\n']
Note:
none
|
```python
n = input()
a = 0
b = []
c = 0
for i in n:
a += 1
if i == "(":
b.append(1)
else:
b.append(-1)
while b[0] != 1:
del b[0]
c += 1
while b[-1] != -1:
del b[-1]
c += 1
print(len(n)-abs(sum(b))-c)
```
| -1
|
630
|
H
|
Benches
|
PROGRAMMING
| 1,400
|
[
"combinatorics",
"math"
] | null | null |
The city park of IT City contains *n* east to west paths and *n* north to south paths. Each east to west path crosses each north to south path, so there are *n*2 intersections.
The city funded purchase of five benches. To make it seems that there are many benches it was decided to place them on as many paths as possible. Obviously this requirement is satisfied by the following scheme: each bench is placed on a cross of paths and each path contains not more than one bench.
Help the park administration count the number of ways to place the benches.
|
The only line of the input contains one integer *n* (5<=≤<=*n*<=≤<=100) — the number of east to west paths and north to south paths.
|
Output one integer — the number of ways to place the benches.
|
[
"5\n"
] |
[
"120"
] |
none
| 0
|
[
{
"input": "5",
"output": "120"
},
{
"input": "6",
"output": "4320"
},
{
"input": "7",
"output": "52920"
},
{
"input": "15",
"output": "1082161080"
},
{
"input": "17",
"output": "4594961280"
},
{
"input": "72",
"output": "23491596420472320"
},
{
"input": "83",
"output": "101159538130177920"
},
{
"input": "95",
"output": "402852449038723320"
},
{
"input": "99",
"output": "613867215317368320"
},
{
"input": "100",
"output": "680185280130048000"
}
] | 1,694,814,726
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 10
| 62
| 0
|
ans = 1
n = int(input())
for i in range(5,0,-1):
ans*=n
n-=1
ans = (ans**2)//120
print(ans)
|
Title: Benches
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The city park of IT City contains *n* east to west paths and *n* north to south paths. Each east to west path crosses each north to south path, so there are *n*2 intersections.
The city funded purchase of five benches. To make it seems that there are many benches it was decided to place them on as many paths as possible. Obviously this requirement is satisfied by the following scheme: each bench is placed on a cross of paths and each path contains not more than one bench.
Help the park administration count the number of ways to place the benches.
Input Specification:
The only line of the input contains one integer *n* (5<=≤<=*n*<=≤<=100) — the number of east to west paths and north to south paths.
Output Specification:
Output one integer — the number of ways to place the benches.
Demo Input:
['5\n']
Demo Output:
['120']
Note:
none
|
```python
ans = 1
n = int(input())
for i in range(5,0,-1):
ans*=n
n-=1
ans = (ans**2)//120
print(ans)
```
| 3
|
|
761
|
E
|
Dasha and Puzzle
|
PROGRAMMING
| 2,000
|
[
"constructive algorithms",
"dfs and similar",
"graphs",
"greedy",
"trees"
] | null | null |
Dasha decided to have a rest after solving the problem. She had been ready to start her favourite activity — origami, but remembered the puzzle that she could not solve.
The tree is a non-oriented connected graph without cycles. In particular, there always are *n*<=-<=1 edges in a tree with *n* vertices.
The puzzle is to position the vertices at the points of the Cartesian plane with integral coordinates, so that the segments between the vertices connected by edges are parallel to the coordinate axes. Also, the intersection of segments is allowed only at their ends. Distinct vertices should be placed at different points.
Help Dasha to find any suitable way to position the tree vertices on the plane.
It is guaranteed that if it is possible to position the tree vertices on the plane without violating the condition which is given above, then you can do it by using points with integral coordinates which don't exceed 1018 in absolute value.
|
The first line contains single integer *n* (1<=≤<=*n*<=≤<=30) — the number of vertices in the tree.
Each of next *n*<=-<=1 lines contains two integers *u**i*, *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*) that mean that the *i*-th edge of the tree connects vertices *u**i* and *v**i*.
It is guaranteed that the described graph is a tree.
|
If the puzzle doesn't have a solution then in the only line print "NO".
Otherwise, the first line should contain "YES". The next *n* lines should contain the pair of integers *x**i*, *y**i* (|*x**i*|,<=|*y**i*|<=≤<=1018) — the coordinates of the point which corresponds to the *i*-th vertex of the tree.
If there are several solutions, print any of them.
|
[
"7\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7",
"6\n1 2\n2 3\n2 4\n2 5\n2 6\n",
"4\n1 2\n2 3\n3 4"
] |
[
"YES\n0 0\n1 0\n0 1\n2 0\n1 -1\n-1 1\n0 2",
"NO\n",
"YES\n3 3\n4 3\n5 3\n6 3"
] |
In the first sample one of the possible positions of tree is: <img class="tex-graphics" src="https://espresso.codeforces.com/360c9c903e5177970a5a3b2711f6718c2163ffd8.png" style="max-width: 100.0%;max-height: 100.0%;"/>
| 2,500
|
[
{
"input": "7\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7",
"output": "YES\n0 0\n0 1073741824\n1073741824 0\n0 1610612736\n536870912 1073741824\n1073741824 536870912\n1610612736 0"
},
{
"input": "6\n1 2\n2 3\n2 4\n2 5\n2 6",
"output": "NO"
},
{
"input": "4\n1 2\n2 3\n3 4",
"output": "YES\n0 0\n0 1073741824\n0 1610612736\n0 1879048192"
},
{
"input": "10\n2 9\n9 3\n3 10\n9 4\n9 6\n9 5\n2 7\n2 1\n2 8",
"output": "NO"
},
{
"input": "10\n2 5\n5 6\n6 1\n6 7\n6 8\n5 10\n5 3\n2 9\n2 4",
"output": "YES\n0 0\n0 1879048192\n-268435456 1610612736\n134217728 1879048192\n0 1610612736\n0 1073741824\n536870912 1073741824\n-536870912 1073741824\n0 2013265920\n268435456 1610612736"
},
{
"input": "8\n7 8\n8 2\n2 4\n8 6\n8 5\n7 3\n7 1",
"output": "YES\n0 0\n0 1879048192\n536870912 1073741824\n0 2013265920\n-268435456 1610612736\n268435456 1610612736\n0 1073741824\n0 1610612736"
},
{
"input": "10\n10 9\n9 3\n3 4\n4 5\n5 1\n1 8\n8 2\n2 6\n6 7",
"output": "YES\n0 0\n1073741824 536870912\n0 1879048192\n0 1610612736\n0 1073741824\n1073741824 805306368\n1073741824 939524096\n1073741824 0\n0 2013265920\n0 2080374784"
},
{
"input": "12\n1 5\n5 7\n7 4\n4 6\n4 2\n7 11\n7 9\n5 10\n5 3\n1 8\n1 12",
"output": "YES\n0 0\n134217728 1879048192\n-536870912 1073741824\n0 1879048192\n0 1073741824\n0 2013265920\n0 1610612736\n1073741824 0\n-268435456 1610612736\n536870912 1073741824\n268435456 1610612736\n0 -1073741824"
},
{
"input": "15\n2 5\n5 10\n10 14\n14 3\n3 7\n7 11\n3 6\n3 15\n14 1\n14 8\n14 12\n10 13\n5 4\n2 9",
"output": "NO"
},
{
"input": "20\n12 7\n7 17\n17 19\n19 15\n15 4\n4 5\n5 18\n18 16\n16 13\n13 2\n2 3\n16 8\n18 9\n18 11\n5 10\n5 14\n4 6\n17 1\n17 20",
"output": "YES\n0 0\n536870912 1606418432\n536870912 1608515584\n536870912 1476395008\n536870912 1543503872\n603979776 1476395008\n0 1610612736\n545259520 1593835520\n553648128 1577058304\n570425344 1543503872\n520093696 1577058304\n0 1879048192\n536870912 1602224128\n503316480 1543503872\n536870912 1342177280\n536870912 1593835520\n0 1073741824\n536870912 1577058304\n536870912 1073741824\n-536870912 1073741824"
},
{
"input": "21\n12 20\n20 6\n6 9\n9 11\n11 5\n5 7\n7 17\n17 16\n16 19\n19 8\n16 21\n17 13\n7 4\n5 18\n11 3\n11 1\n6 14\n6 2\n20 15\n20 10",
"output": "YES\n0 0\n-134217728 1879048192\n-536870912 1073741824\n671088640 1342177280\n536870912 1073741824\n0 1879048192\n536870912 1342177280\n536870912 1593835520\n0 1610612736\n-67108864 2013265920\n0 1073741824\n0 2080374784\n603979776 1476395008\n134217728 1879048192\n67108864 2013265920\n536870912 1543503872\n536870912 1476395008\n805306368 1073741824\n536870912 1577058304\n0 2013265920\n570425344 1543503872"
},
{
"input": "30\n21 11\n11 22\n22 24\n24 2\n2 8\n8 10\n10 28\n28 26\n26 29\n29 15\n29 16\n26 4\n26 3\n28 23\n28 18\n10 19\n10 14\n8 5\n8 1\n2 9\n2 17\n24 20\n24 13\n22 27\n22 6\n11 30\n11 7\n21 12\n21 25",
"output": "YES\n0 0\n0 1610612736\n469762048 1476395008\n603979776 1476395008\n-536870912 1073741824\n-67108864 2013265920\n-33554432 2080374784\n0 1073741824\n268435456 1610612736\n536870912 1073741824\n0 2080374784\n0 2130706432\n-134217728 1879048192\n536870912 805306368\n536870912 1577058304\n570425344 1543503872\n-268435456 1610612736\n402653184 1342177280\n805306368 1073741824\n134217728 1879048192\n0 2113929216\n0 2013265920\n671088640 1342177280\n0 1879048192\n16777216 2113929216\n536870912 1476395008\n671088..."
},
{
"input": "20\n6 20\n20 10\n10 5\n5 2\n2 7\n7 14\n14 4\n4 3\n14 15\n14 19\n7 18\n7 8\n2 13\n5 9\n5 1\n10 12\n20 11\n20 17\n6 16",
"output": "YES\n0 0\n536870912 1073741824\n536870912 1577058304\n536870912 1543503872\n0 1073741824\n0 2013265920\n536870912 1342177280\n402653184 1342177280\n-536870912 1073741824\n0 1610612736\n134217728 1879048192\n268435456 1610612736\n805306368 1073741824\n536870912 1476395008\n603979776 1476395008\n0 2080374784\n-134217728 1879048192\n671088640 1342177280\n469762048 1476395008\n0 1879048192"
},
{
"input": "15\n8 14\n14 3\n3 1\n1 13\n13 5\n5 15\n15 2\n15 4\n5 10\n13 6\n1 12\n3 11\n14 7\n8 9",
"output": "YES\n0 0\n1073741824 939524096\n0 1073741824\n1207959552 805306368\n1073741824 536870912\n1610612736 0\n268435456 1610612736\n0 1879048192\n0 2013265920\n1342177280 536870912\n536870912 1073741824\n0 -1073741824\n1073741824 0\n0 1610612736\n1073741824 805306368"
},
{
"input": "30\n29 21\n21 16\n16 4\n4 27\n27 13\n13 30\n30 15\n15 14\n14 25\n25 26\n26 1\n1 19\n19 3\n3 2\n2 20\n20 18\n18 8\n8 10\n10 28\n28 17\n17 7\n7 11\n11 6\n6 5\n5 12\n12 23\n23 24\n24 9\n9 22",
"output": "YES\n0 0\n1073741824 805306368\n1073741824 536870912\n0 2139095040\n1073741824 1073479680\n1073741824 1073217536\n1073741824 1071644672\n1073741824 1040187392\n1073741824 1073725440\n1073741824 1056964608\n1073741824 1072693248\n1073741824 1073610752\n0 2113929216\n0 1879048192\n0 2013265920\n0 2143289344\n1073741824 1069547520\n1073741824 1006632960\n1073741824 0\n1073741824 939524096\n0 2145386496\n1073741824 1073733632\n1073741824 1073676288\n1073741824 1073709056\n0 1610612736\n0 1073741824\n0 21307064..."
},
{
"input": "30\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n4 8\n4 9\n5 10\n5 11\n6 12\n6 13\n7 14\n7 15\n8 16\n8 17\n9 18\n9 19\n10 20\n10 21\n11 22\n11 23\n12 24\n12 25\n13 26\n13 27\n14 28\n14 29\n15 30",
"output": "YES\n0 0\n0 1073741824\n1073741824 0\n0 1610612736\n536870912 1073741824\n1073741824 536870912\n1610612736 0\n0 1879048192\n268435456 1610612736\n536870912 1342177280\n805306368 1073741824\n1073741824 805306368\n1342177280 536870912\n1610612736 268435456\n1879048192 0\n0 2013265920\n134217728 1879048192\n268435456 1744830464\n402653184 1610612736\n536870912 1476395008\n671088640 1342177280\n805306368 1207959552\n939524096 1073741824\n1073741824 939524096\n1207959552 805306368\n1342177280 671088640\n1476395..."
},
{
"input": "13\n1 2\n1 3\n1 4\n2 5\n2 6\n2 7\n3 8\n3 9\n3 10\n4 11\n4 12\n4 13",
"output": "YES\n0 0\n0 1073741824\n1073741824 0\n0 -1073741824\n0 1610612736\n536870912 1073741824\n-536870912 1073741824\n1073741824 536870912\n1610612736 0\n1073741824 -536870912\n536870912 -1073741824\n0 -1610612736\n-536870912 -1073741824"
},
{
"input": "20\n1 2\n1 3\n1 4\n1 5\n2 6\n2 7\n2 8\n3 9\n3 10\n3 11\n4 12\n4 13\n4 14\n5 15\n5 16\n5 17\n18 17\n19 17\n20 17",
"output": "YES\n0 0\n0 1073741824\n1073741824 0\n0 -1073741824\n-1073741824 0\n0 1610612736\n536870912 1073741824\n-536870912 1073741824\n1073741824 536870912\n1610612736 0\n1073741824 -536870912\n536870912 -1073741824\n0 -1610612736\n-536870912 -1073741824\n-1073741824 536870912\n-1073741824 -536870912\n-1610612736 0\n-1610612736 268435456\n-1610612736 -268435456\n-1879048192 0"
},
{
"input": "1",
"output": "YES\n0 0"
},
{
"input": "20\n6 1\n7 1\n8 1\n6 5\n5 4\n4 3\n3 2\n7 9\n9 10\n10 11\n11 12\n12 13\n14 8\n15 14\n15 16\n17 16\n17 18\n18 19\n19 20",
"output": "YES\n0 0\n0 2080374784\n0 2013265920\n0 1879048192\n0 1610612736\n0 1073741824\n1073741824 0\n0 -1073741824\n1073741824 536870912\n1073741824 805306368\n1073741824 939524096\n1073741824 1006632960\n1073741824 1040187392\n536870912 -1073741824\n536870912 -805306368\n536870912 -671088640\n536870912 -603979776\n536870912 -570425344\n536870912 -553648128\n536870912 -545259520"
},
{
"input": "25\n1 2\n1 3\n1 4\n2 5\n5 6\n6 7\n7 8\n2 9\n9 10\n11 2\n12 11\n13 12\n3 14\n14 15\n14 16\n16 17\n14 18\n18 19\n20 4\n20 21\n20 22\n22 23\n20 24\n24 25",
"output": "YES\n0 0\n0 1073741824\n1073741824 0\n0 -1073741824\n0 1610612736\n0 1879048192\n0 2013265920\n0 2080374784\n536870912 1073741824\n536870912 1342177280\n-536870912 1073741824\n-536870912 1342177280\n-536870912 1476395008\n1073741824 536870912\n1073741824 805306368\n1342177280 536870912\n1342177280 671088640\n805306368 536870912\n805306368 671088640\n536870912 -1073741824\n536870912 -805306368\n805306368 -1073741824\n805306368 -939524096\n536870912 -1342177280\n671088640 -1342177280"
},
{
"input": "30\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30",
"output": "NO"
},
{
"input": "30\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n2 10\n10 11\n10 12\n10 13\n2 14\n14 15\n14 16\n14 17\n4 18\n18 19\n18 20\n18 21\n4 22\n22 23\n22 24\n22 25\n6 26\n26 27\n6 28\n28 29\n28 30",
"output": "YES\n0 0\n0 1073741824\n0 1610612736\n0 1879048192\n0 2013265920\n0 2080374784\n0 2113929216\n0 2130706432\n0 2139095040\n536870912 1073741824\n536870912 1342177280\n805306368 1073741824\n536870912 805306368\n-536870912 1073741824\n-536870912 1342177280\n-536870912 805306368\n-805306368 1073741824\n134217728 1879048192\n134217728 1946157056\n201326592 1879048192\n134217728 1811939328\n-134217728 1879048192\n-134217728 1946157056\n-134217728 1811939328\n-201326592 1879048192\n33554432 2080374784\n33554432 2..."
},
{
"input": "28\n24 3\n3 8\n8 21\n21 23\n23 6\n6 16\n16 22\n22 11\n11 12\n11 20\n11 7\n22 15\n22 13\n16 14\n16 27\n6 26\n6 19\n23 17\n23 1\n21 2\n21 18\n8 28\n8 25\n3 5\n3 10\n24 9\n24 4",
"output": "YES\n0 0\n268435456 1610612736\n0 2013265920\n33554432 2080374784\n67108864 2013265920\n536870912 1073741824\n503316480 1543503872\n0 1879048192\n0 2113929216\n-67108864 2013265920\n536870912 1543503872\n536870912 1577058304\n469762048 1476395008\n671088640 1342177280\n603979776 1476395008\n536870912 1342177280\n-536870912 1073741824\n-268435456 1610612736\n536870912 805306368\n570425344 1543503872\n0 1610612736\n536870912 1476395008\n0 1073741824\n0 2080374784\n-134217728 1879048192\n805306368 1073741824\n..."
},
{
"input": "21\n17 7\n7 14\n14 6\n6 2\n2 20\n20 11\n11 4\n11 18\n20 16\n20 13\n2 1\n2 15\n6 19\n6 5\n14 21\n14 10\n7 3\n7 12\n17 9\n17 8",
"output": "YES\n0 0\n0 1073741824\n67108864 2013265920\n536870912 1476395008\n-268435456 1610612736\n0 1610612736\n0 2013265920\n33554432 2080374784\n0 2113929216\n-134217728 1879048192\n536870912 1342177280\n-67108864 2013265920\n536870912 805306368\n0 1879048192\n-536870912 1073741824\n805306368 1073741824\n0 2080374784\n671088640 1342177280\n268435456 1610612736\n536870912 1073741824\n134217728 1879048192"
},
{
"input": "17\n9 17\n17 4\n4 1\n1 3\n3 14\n14 7\n7 16\n16 10\n16 15\n7 8\n14 13\n3 11\n1 6\n4 5\n17 2\n9 12",
"output": "YES\n0 0\n268435456 1610612736\n1073741824 0\n0 1073741824\n536870912 1073741824\n0 -1073741824\n1073741824 805306368\n1207959552 805306368\n0 1879048192\n1073741824 1006632960\n1610612736 0\n0 2013265920\n1342177280 536870912\n1073741824 536870912\n1140850688 939524096\n1073741824 939524096\n0 1610612736"
},
{
"input": "19\n3 12\n12 11\n11 17\n17 2\n2 19\n19 16\n19 4\n19 1\n2 8\n2 5\n17 14\n17 10\n11 13\n11 9\n12 18\n12 6\n3 15\n3 7",
"output": "YES\n0 0\n0 1610612736\n0 2113929216\n-536870912 1073741824\n-268435456 1610612736\n-33554432 2080374784\n16777216 2113929216\n268435456 1610612736\n-67108864 2013265920\n-134217728 1879048192\n0 2013265920\n0 2080374784\n67108864 2013265920\n134217728 1879048192\n0 2130706432\n536870912 1073741824\n0 1879048192\n33554432 2080374784\n0 1073741824"
},
{
"input": "18\n17 13\n13 11\n11 9\n9 15\n15 3\n3 16\n3 14\n15 10\n15 5\n9 1\n9 7\n11 4\n11 2\n13 6\n13 12\n17 18\n17 8",
"output": "YES\n0 0\n-268435456 1610612736\n536870912 1342177280\n268435456 1610612736\n536870912 805306368\n134217728 1879048192\n-536870912 1073741824\n67108864 2013265920\n0 1073741824\n805306368 1073741824\n0 1610612736\n-134217728 1879048192\n0 1879048192\n671088640 1342177280\n536870912 1073741824\n536870912 1476395008\n0 2013265920\n0 2080374784"
},
{
"input": "30\n29 3\n3 13\n13 7\n7 5\n5 6\n6 10\n10 8\n8 26\n26 17\n26 15\n8 25\n8 12\n8 11\n10 27\n10 14\n6 21\n5 2\n5 1\n5 19\n5 30\n7 4\n13 18\n3 9\n3 28\n3 24\n3 20\n29 16\n29 23\n29 22",
"output": "NO"
},
{
"input": "30\n20 15\n15 2\n2 1\n1 29\n29 18\n18 8\n8 12\n12 22\n22 30\n30 16\n16 28\n28 9\n9 11\n11 21\n9 6\n16 27\n16 26\n30 4\n22 5\n18 17\n29 13\n29 23\n1 19\n1 24\n2 7\n15 10\n15 3\n20 14\n20 25",
"output": "YES\n0 0\n0 1073741824\n-268435456 1610612736\n1090519040 1040187392\n1107296256 1006632960\n1075838976 1069547520\n536870912 1073741824\n1073741824 805306368\n1073741824 1069547520\n268435456 1610612736\n1073741824 1071644672\n1073741824 939524096\n1610612736 0\n0 2013265920\n0 1610612736\n1073741824 1056964608\n1342177280 536870912\n1073741824 536870912\n0 -1073741824\n0 1879048192\n1073741824 1072693248\n1073741824 1006632960\n1073741824 -536870912\n-1073741824 0\n134217728 1879048192\n1065353216 105696..."
},
{
"input": "30\n28 30\n30 20\n20 29\n29 15\n15 2\n2 27\n27 6\n6 4\n6 11\n6 7\n6 10\n6 24\n27 14\n27 5\n27 22\n2 16\n15 13\n15 9\n15 25\n29 1\n29 3\n29 12\n29 26\n30 8\n30 18\n30 23\n30 17\n30 19\n28 21",
"output": "NO"
},
{
"input": "2\n2 1",
"output": "YES\n0 0\n0 1073741824"
},
{
"input": "3\n1 2\n2 3",
"output": "YES\n0 0\n0 1073741824\n0 1610612736"
},
{
"input": "4\n2 1\n1 3\n3 4",
"output": "YES\n0 0\n0 1073741824\n1073741824 0\n1073741824 536870912"
},
{
"input": "5\n2 4\n4 1\n1 3\n3 5",
"output": "YES\n0 0\n0 1610612736\n1073741824 0\n0 1073741824\n1073741824 536870912"
},
{
"input": "6\n3 4\n4 1\n1 5\n5 2\n2 6",
"output": "YES\n0 0\n1073741824 536870912\n0 1610612736\n0 1073741824\n1073741824 0\n1073741824 805306368"
},
{
"input": "7\n5 4\n4 7\n7 1\n1 2\n2 3\n3 6",
"output": "YES\n0 0\n1073741824 0\n1073741824 536870912\n0 1610612736\n0 1879048192\n1073741824 805306368\n0 1073741824"
},
{
"input": "8\n5 6\n6 8\n8 2\n2 7\n7 1\n1 4\n4 3",
"output": "YES\n0 0\n0 1610612736\n1073741824 536870912\n1073741824 0\n0 2080374784\n0 2013265920\n0 1073741824\n0 1879048192"
},
{
"input": "9\n7 1\n1 4\n4 5\n5 6\n6 2\n2 8\n8 3\n3 9",
"output": "YES\n0 0\n1073741824 939524096\n1073741824 1040187392\n1073741824 0\n1073741824 536870912\n1073741824 805306368\n0 1073741824\n1073741824 1006632960\n1073741824 1056964608"
},
{
"input": "3\n2 1\n3 1",
"output": "YES\n0 0\n0 1073741824\n1073741824 0"
},
{
"input": "4\n2 1\n1 3\n1 4",
"output": "YES\n0 0\n0 1073741824\n1073741824 0\n0 -1073741824"
},
{
"input": "5\n5 1\n1 4\n1 3\n2 1",
"output": "YES\n0 0\n-1073741824 0\n0 -1073741824\n1073741824 0\n0 1073741824"
},
{
"input": "30\n1 15\n15 30\n30 14\n14 16\n16 19\n19 12\n19 22\n19 2\n16 9\n16 21\n16 23\n16 24\n14 7\n14 29\n14 17\n14 18\n30 13\n30 27\n30 4\n30 8\n15 10\n15 11\n15 5\n15 3\n15 25\n1 6\n1 26\n1 28\n1 20",
"output": "NO"
},
{
"input": "30\n2 29\n29 26\n26 13\n13 30\n30 24\n24 20\n20 3\n3 19\n19 8\n8 27\n27 14\n14 12\n12 23\n14 25\n27 4\n8 7\n8 21\n19 6\n19 16\n3 1\n20 18\n24 9\n30 10\n30 22\n13 17\n26 15\n29 5\n29 11\n2 28",
"output": "YES\n0 0\n0 2139095040\n0 1073741824\n603979776 1476395008\n8388608 2130706432\n805306368 1073741824\n671088640 1342177280\n536870912 1342177280\n134217728 1879048192\n67108864 2013265920\n-8388608 2130706432\n536870912 1577058304\n0 2080374784\n536870912 1543503872\n16777216 2113929216\n536870912 805306368\n33554432 2080374784\n268435456 1610612736\n536870912 1073741824\n0 1610612736\n402653184 1342177280\n-67108864 2013265920\n536870912 1593835520\n0 1879048192\n570425344 1543503872\n0 2113929216\n536870..."
},
{
"input": "30\n29 18\n18 8\n8 27\n27 26\n26 17\n17 11\n11 23\n23 16\n16 6\n23 19\n23 22\n23 2\n23 28\n23 1\n11 14\n11 13\n11 5\n11 9\n11 30\n17 15\n26 3\n26 7\n26 25\n27 24\n27 4\n8 21\n18 20\n18 12\n29 10",
"output": "NO"
},
{
"input": "30\n10 15\n15 17\n17 14\n14 7\n7 3\n3 27\n3 25\n3 21\n3 5\n3 9\n7 11\n7 18\n7 26\n7 16\n7 4\n7 8\n7 23\n7 2\n7 29\n17 12\n17 30\n17 13\n17 24\n17 20\n17 28\n17 22\n17 1\n15 6\n10 19",
"output": "NO"
},
{
"input": "30\n8 23\n23 13\n13 29\n29 14\n13 18\n13 5\n13 24\n13 21\n13 4\n13 1\n13 9\n13 16\n13 19\n23 12\n23 17\n23 11\n23 27\n23 22\n23 28\n23 20\n8 3\n8 10\n8 26\n8 15\n8 25\n8 6\n8 30\n8 7\n8 2",
"output": "NO"
},
{
"input": "17\n2 13\n13 7\n7 6\n6 12\n6 9\n6 14\n6 1\n6 4\n7 8\n7 11\n13 17\n13 10\n2 3\n2 5\n2 16\n2 15",
"output": "NO"
},
{
"input": "20\n17 18\n18 13\n13 6\n6 3\n6 2\n6 14\n13 20\n13 15\n18 11\n18 7\n18 19\n18 9\n17 5\n17 4\n17 12\n17 10\n17 16\n17 1\n17 8",
"output": "NO"
},
{
"input": "6\n2 1\n1 4\n4 6\n4 3\n1 5",
"output": "YES\n0 0\n0 1073741824\n1610612736 0\n1073741824 0\n0 -1073741824\n1073741824 536870912"
},
{
"input": "10\n9 1\n9 10\n9 5\n9 8\n9 2\n9 7\n9 3\n9 6\n9 4",
"output": "NO"
},
{
"input": "15\n5 2\n2 7\n7 3\n3 9\n9 15\n9 12\n3 10\n3 11\n7 1\n7 6\n2 13\n2 8\n5 14\n5 4",
"output": "YES\n0 0\n0 1610612736\n536870912 1073741824\n134217728 1879048192\n0 1879048192\n-536870912 1073741824\n0 1073741824\n-268435456 1610612736\n536870912 1342177280\n805306368 1073741824\n536870912 805306368\n671088640 1342177280\n268435456 1610612736\n0 2013265920\n536870912 1476395008"
},
{
"input": "30\n7 20\n20 25\n25 4\n4 17\n17 28\n4 23\n4 3\n4 10\n25 18\n25 13\n25 9\n25 14\n25 29\n25 27\n25 21\n25 6\n20 5\n20 15\n20 16\n20 24\n20 2\n7 26\n7 12\n7 8\n7 1\n7 30\n7 19\n7 11\n7 22",
"output": "NO"
},
{
"input": "30\n6 29\n29 27\n27 4\n4 2\n2 10\n10 19\n10 8\n10 25\n2 16\n2 15\n2 28\n4 1\n4 30\n27 18\n27 12\n27 20\n27 7\n27 3\n29 26\n29 23\n29 17\n29 22\n29 14\n29 24\n6 5\n6 9\n6 13\n6 21\n6 11",
"output": "NO"
},
{
"input": "19\n13 3\n3 10\n10 19\n19 14\n19 16\n19 17\n19 2\n19 11\n10 7\n10 6\n10 18\n10 12\n10 15\n10 8\n3 9\n3 5\n13 1\n13 4",
"output": "NO"
},
{
"input": "18\n12 16\n16 5\n5 10\n10 7\n10 11\n5 18\n5 8\n5 13\n5 6\n5 3\n5 1\n16 2\n16 9\n12 17\n12 15\n12 4\n12 14",
"output": "NO"
},
{
"input": "15\n5 13\n13 15\n15 10\n10 9\n10 6\n10 8\n15 7\n13 4\n13 11\n13 2\n5 14\n5 1\n5 3\n5 12",
"output": "NO"
},
{
"input": "4\n3 2\n3 4\n3 1",
"output": "YES\n0 0\n0 1610612736\n0 1073741824\n536870912 1073741824"
},
{
"input": "30\n18 9\n9 26\n26 25\n25 14\n14 20\n20 27\n27 30\n30 16\n16 1\n1 29\n1 21\n16 19\n16 23\n30 8\n30 4\n27 12\n27 10\n20 7\n20 6\n14 15\n14 11\n25 13\n25 28\n26 24\n26 5\n9 3\n9 2\n18 17\n18 22",
"output": "YES\n0 0\n-4194304 2139095040\n4194304 2139095040\n-268435456 1610612736\n-8388608 2130706432\n-67108864 2013265920\n67108864 2013265920\n268435456 1610612736\n0 2139095040\n-134217728 1879048192\n-33554432 2080374784\n134217728 1879048192\n16777216 2113929216\n0 2080374784\n33554432 2080374784\n0 1073741824\n0 2145386496\n0 2143289344\n536870912 1073741824\n0 2013265920\n0 -1073741824\n2097152 2143289344\n-536870912 1073741824\n8388608 2130706432\n0 2113929216\n0 2130706432\n0 1879048192\n-16777216 211392..."
},
{
"input": "30\n15 22\n22 18\n18 25\n25 27\n27 10\n10 7\n7 3\n3 28\n28 29\n29 5\n5 4\n4 24\n24 2\n2 26\n26 6\n2 14\n24 16\n4 9\n5 11\n29 8\n28 12\n3 17\n7 19\n10 30\n27 20\n25 1\n18 13\n22 23\n15 21",
"output": "YES\n0 0\n536870912 1609564160\n536870912 1543503872\n536870912 1606418432\n536870912 1602224128\n536870912 1610350592\n536870912 1476395008\n545259520 1593835520\n538968064 1606418432\n536870912 1342177280\n541065216 1602224128\n553648128 1577058304\n268435456 1610612736\n537395200 1609564160\n0 2013265920\n537919488 1608515584\n570425344 1543503872\n0 1610612736\n603979776 1476395008\n805306368 1073741824\n0 2080374784\n0 1879048192\n134217728 1879048192\n536870912 1608515584\n0 1073741824\n536870912 161..."
}
] | 1,535,798,618
| 5,318
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 0
| 155
| 409,600
|
n = int(input())
adj = [[] for _ in range(n)]
for _ in range(n - 1):
u, v = map(int, input().split())
adj[u - 1].append(v - 1)
adj[v - 1].append(u - 1)
from collections import deque
def bfs(v):
vis = [i == v for i in range(n)]
paths = deque([[v]])
while paths:
p = paths.popleft()
for nv in adj[p[-1]]:
if not vis[nv]:
vis[nv] = True
paths.append(p + [nv])
return p
diameter = bfs(0)
diameter = bfs(diameter[-1])
p = diameter[len(diameter) // 2]
print(p)
start = (0, 0)
move = [(0, 1), (1, 0), (0, -1), (-1, 0)]
gpt = lambda pt, i, dis : (pt[0] + move[i][0] * dis, pt[1] + move[i][1] * dis)
vis = [False] * n
dis = 2 ** (len(diameter) + 1)
ans = [0] * n
q = deque([(p, start, dis)])
while q:
p, start, dis = q.popleft()
vis[p] = True
ans[p] = start
if len(adj[p]) > 4:
print("NO")
exit()
for i, nv in enumerate(adj[p]):
if not vis[nv]:
vis[nv] = 1
npt = gpt(start, i, dis)
q.append((nv, npt, dis // 2))
ans[nv] = npt
print("YES")
for pt in ans:
print(*pt)
|
Title: Dasha and Puzzle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dasha decided to have a rest after solving the problem. She had been ready to start her favourite activity — origami, but remembered the puzzle that she could not solve.
The tree is a non-oriented connected graph without cycles. In particular, there always are *n*<=-<=1 edges in a tree with *n* vertices.
The puzzle is to position the vertices at the points of the Cartesian plane with integral coordinates, so that the segments between the vertices connected by edges are parallel to the coordinate axes. Also, the intersection of segments is allowed only at their ends. Distinct vertices should be placed at different points.
Help Dasha to find any suitable way to position the tree vertices on the plane.
It is guaranteed that if it is possible to position the tree vertices on the plane without violating the condition which is given above, then you can do it by using points with integral coordinates which don't exceed 1018 in absolute value.
Input Specification:
The first line contains single integer *n* (1<=≤<=*n*<=≤<=30) — the number of vertices in the tree.
Each of next *n*<=-<=1 lines contains two integers *u**i*, *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*) that mean that the *i*-th edge of the tree connects vertices *u**i* and *v**i*.
It is guaranteed that the described graph is a tree.
Output Specification:
If the puzzle doesn't have a solution then in the only line print "NO".
Otherwise, the first line should contain "YES". The next *n* lines should contain the pair of integers *x**i*, *y**i* (|*x**i*|,<=|*y**i*|<=≤<=1018) — the coordinates of the point which corresponds to the *i*-th vertex of the tree.
If there are several solutions, print any of them.
Demo Input:
['7\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7', '6\n1 2\n2 3\n2 4\n2 5\n2 6\n', '4\n1 2\n2 3\n3 4']
Demo Output:
['YES\n0 0\n1 0\n0 1\n2 0\n1 -1\n-1 1\n0 2', 'NO\n', 'YES\n3 3\n4 3\n5 3\n6 3']
Note:
In the first sample one of the possible positions of tree is: <img class="tex-graphics" src="https://espresso.codeforces.com/360c9c903e5177970a5a3b2711f6718c2163ffd8.png" style="max-width: 100.0%;max-height: 100.0%;"/>
|
```python
n = int(input())
adj = [[] for _ in range(n)]
for _ in range(n - 1):
u, v = map(int, input().split())
adj[u - 1].append(v - 1)
adj[v - 1].append(u - 1)
from collections import deque
def bfs(v):
vis = [i == v for i in range(n)]
paths = deque([[v]])
while paths:
p = paths.popleft()
for nv in adj[p[-1]]:
if not vis[nv]:
vis[nv] = True
paths.append(p + [nv])
return p
diameter = bfs(0)
diameter = bfs(diameter[-1])
p = diameter[len(diameter) // 2]
print(p)
start = (0, 0)
move = [(0, 1), (1, 0), (0, -1), (-1, 0)]
gpt = lambda pt, i, dis : (pt[0] + move[i][0] * dis, pt[1] + move[i][1] * dis)
vis = [False] * n
dis = 2 ** (len(diameter) + 1)
ans = [0] * n
q = deque([(p, start, dis)])
while q:
p, start, dis = q.popleft()
vis[p] = True
ans[p] = start
if len(adj[p]) > 4:
print("NO")
exit()
for i, nv in enumerate(adj[p]):
if not vis[nv]:
vis[nv] = 1
npt = gpt(start, i, dis)
q.append((nv, npt, dis // 2))
ans[nv] = npt
print("YES")
for pt in ans:
print(*pt)
```
| 0
|
|
41
|
A
|
Translation
|
PROGRAMMING
| 800
|
[
"implementation",
"strings"
] |
A. Translation
|
2
|
256
|
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
|
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
|
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
|
[
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] |
[
"YES\n",
"NO\n",
"NO\n"
] |
none
| 500
|
[
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk",
"output": "NO"
},
{
"input": "z\na",
"output": "NO"
},
{
"input": "asd\ndsa",
"output": "YES"
},
{
"input": "abcdef\nfecdba",
"output": "NO"
},
{
"input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu",
"output": "NO"
},
{
"input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf",
"output": "NO"
},
{
"input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp",
"output": "NO"
},
{
"input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb",
"output": "NO"
},
{
"input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom",
"output": "NO"
},
{
"input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh",
"output": "NO"
},
{
"input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy",
"output": "NO"
},
{
"input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko",
"output": "NO"
},
{
"input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv",
"output": "NO"
},
{
"input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd",
"output": "NO"
},
{
"input": "w\nw",
"output": "YES"
},
{
"input": "vz\nzv",
"output": "YES"
},
{
"input": "ry\nyr",
"output": "YES"
},
{
"input": "xou\nuox",
"output": "YES"
},
{
"input": "axg\ngax",
"output": "NO"
},
{
"input": "zdsl\nlsdz",
"output": "YES"
},
{
"input": "kudl\nldku",
"output": "NO"
},
{
"input": "zzlzwnqlcl\nlclqnwzlzz",
"output": "YES"
},
{
"input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv",
"output": "YES"
},
{
"input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar",
"output": "NO"
},
{
"input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn",
"output": "YES"
},
{
"input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum",
"output": "YES"
},
{
"input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv",
"output": "YES"
},
{
"input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm",
"output": "NO"
},
{
"input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd",
"output": "NO"
},
{
"input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg",
"output": "YES"
},
{
"input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis",
"output": "YES"
},
{
"input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy",
"output": "NO"
},
{
"input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw",
"output": "YES"
},
{
"input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi",
"output": "YES"
},
{
"input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib",
"output": "YES"
}
] | 1,607,142,154
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 154
| 0
|
s=input()
p=input()
s=reversed(s)
if s==p:
print("YES")
else:
print("NO")
|
Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
Input Specification:
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output Specification:
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
Demo Input:
['code\nedoc\n', 'abb\naba\n', 'code\ncode\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none
|
```python
s=input()
p=input()
s=reversed(s)
if s==p:
print("YES")
else:
print("NO")
```
| 0
|
59
|
A
|
Word
|
PROGRAMMING
| 800
|
[
"implementation",
"strings"
] |
A. Word
|
2
|
256
|
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
|
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
|
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
|
[
"HoUse\n",
"ViP\n",
"maTRIx\n"
] |
[
"house\n",
"VIP\n",
"matrix\n"
] |
none
| 500
|
[
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chnenu"
},
{
"input": "ERPZGrodyu",
"output": "erpzgrodyu"
},
{
"input": "KSXBXWpebh",
"output": "KSXBXWPEBH"
},
{
"input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv",
"output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv"
},
{
"input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd",
"output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd"
},
{
"input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv",
"output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv"
},
{
"input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg",
"output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg"
},
{
"input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak",
"output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK"
},
{
"input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw",
"output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW"
},
{
"input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB",
"output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB"
},
{
"input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge",
"output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge"
},
{
"input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw",
"output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw"
},
{
"input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks",
"output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks"
},
{
"input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz",
"output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ"
},
{
"input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg",
"output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG"
},
{
"input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO",
"output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO"
},
{
"input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd",
"output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD"
},
{
"input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas",
"output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas"
},
{
"input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm",
"output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM"
},
{
"input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn",
"output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn"
},
{
"input": "t",
"output": "t"
},
{
"input": "N",
"output": "N"
},
{
"input": "kv",
"output": "kv"
},
{
"input": "Ur",
"output": "ur"
},
{
"input": "CN",
"output": "CN"
}
] | 1,590,923,676
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 30
| 310
| 0
|
# -*- coding: utf-8 -*-
"""
Created on Sun May 31 16:45:30 2020
@author: Mohit
"""
"""
Created on Sun May 31 16:25:54 2020
@author: Mohit
"""
x= input()
countl=0
countu=0
for i in x:
if(i.isupper()):
countu= countu+1
elif(i.islower()):
countl = countl+1
if(countl <countu):
print(x.upper())
else :
print(x.lower())
|
Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input Specification:
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output Specification:
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Demo Input:
['HoUse\n', 'ViP\n', 'maTRIx\n']
Demo Output:
['house\n', 'VIP\n', 'matrix\n']
Note:
none
|
```python
# -*- coding: utf-8 -*-
"""
Created on Sun May 31 16:45:30 2020
@author: Mohit
"""
"""
Created on Sun May 31 16:25:54 2020
@author: Mohit
"""
x= input()
countl=0
countu=0
for i in x:
if(i.isupper()):
countu= countu+1
elif(i.islower()):
countl = countl+1
if(countl <countu):
print(x.upper())
else :
print(x.lower())
```
| 3.9225
|
873
|
B
|
Balanced Substring
|
PROGRAMMING
| 1,500
|
[
"dp",
"implementation"
] | null | null |
You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring.
You have to determine the length of the longest balanced substring of *s*.
|
The first line contains *n* (1<=≤<=*n*<=≤<=100000) — the number of characters in *s*.
The second line contains a string *s* consisting of exactly *n* characters. Only characters 0 and 1 can appear in *s*.
|
If there is no non-empty balanced substring in *s*, print 0. Otherwise, print the length of the longest balanced substring.
|
[
"8\n11010111\n",
"3\n111\n"
] |
[
"4\n",
"0\n"
] |
In the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible.
In the second example it's impossible to find a non-empty balanced substring.
| 0
|
[
{
"input": "8\n11010111",
"output": "4"
},
{
"input": "3\n111",
"output": "0"
},
{
"input": "11\n00001000100",
"output": "2"
},
{
"input": "10\n0100000000",
"output": "2"
},
{
"input": "13\n0001000011010",
"output": "6"
},
{
"input": "14\n00000100101011",
"output": "10"
},
{
"input": "14\n01111101111111",
"output": "2"
},
{
"input": "18\n110010101101111111",
"output": "10"
},
{
"input": "11\n00010000011",
"output": "4"
},
{
"input": "10\n1000010110",
"output": "6"
},
{
"input": "15\n100000100000011",
"output": "4"
},
{
"input": "18\n011010101110111101",
"output": "8"
},
{
"input": "10\n0011011111",
"output": "6"
},
{
"input": "3\n011",
"output": "2"
},
{
"input": "14\n11111111111111",
"output": "0"
},
{
"input": "65\n11001000110001001011011110111100000000101001001010101111000100010",
"output": "48"
},
{
"input": "10\n0011111000",
"output": "10"
},
{
"input": "13\n1110000001110",
"output": "12"
},
{
"input": "3\n110",
"output": "2"
},
{
"input": "4\n1110",
"output": "2"
},
{
"input": "9\n001011001",
"output": "8"
},
{
"input": "2\n10",
"output": "2"
},
{
"input": "2\n01",
"output": "2"
},
{
"input": "12\n110000110000",
"output": "8"
},
{
"input": "3\n001",
"output": "2"
},
{
"input": "14\n11000011000000",
"output": "8"
},
{
"input": "19\n0000011111111100000",
"output": "18"
},
{
"input": "45\n011010001100001111110001011100000001101100111",
"output": "44"
},
{
"input": "18\n000001111111100000",
"output": "16"
},
{
"input": "4\n0101",
"output": "4"
},
{
"input": "12\n000101011001",
"output": "10"
}
] | 1,507,885,908
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 46
| 0
|
n = int(input())
s = input()
tab = [[0 for j in range(i, n)] for i in range(n)]
res = 0
for i in range(n):
for j in range(i+1, n):
tab[i][j-i] = tab[i][j-i-1]
tab[i][j-i] += 1 if s[j-1]=='0' else -1
if tab[i][j-i] == 0 and res < j-i:
res = j-i
|
Title: Balanced Substring
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring.
You have to determine the length of the longest balanced substring of *s*.
Input Specification:
The first line contains *n* (1<=≤<=*n*<=≤<=100000) — the number of characters in *s*.
The second line contains a string *s* consisting of exactly *n* characters. Only characters 0 and 1 can appear in *s*.
Output Specification:
If there is no non-empty balanced substring in *s*, print 0. Otherwise, print the length of the longest balanced substring.
Demo Input:
['8\n11010111\n', '3\n111\n']
Demo Output:
['4\n', '0\n']
Note:
In the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible.
In the second example it's impossible to find a non-empty balanced substring.
|
```python
n = int(input())
s = input()
tab = [[0 for j in range(i, n)] for i in range(n)]
res = 0
for i in range(n):
for j in range(i+1, n):
tab[i][j-i] = tab[i][j-i-1]
tab[i][j-i] += 1 if s[j-1]=='0' else -1
if tab[i][j-i] == 0 and res < j-i:
res = j-i
```
| 0
|
|
79
|
A
|
Bus Game
|
PROGRAMMING
| 1,200
|
[
"greedy"
] |
A. Bus Game
|
2
|
256
|
After Fox Ciel won an onsite round of a programming contest, she took a bus to return to her castle. The fee of the bus was 220 yen. She met Rabbit Hanako in the bus. They decided to play the following game because they got bored in the bus.
- Initially, there is a pile that contains *x* 100-yen coins and *y* 10-yen coins. - They take turns alternatively. Ciel takes the first turn. - In each turn, they must take exactly 220 yen from the pile. In Ciel's turn, if there are multiple ways to take 220 yen, she will choose the way that contains the maximal number of 100-yen coins. In Hanako's turn, if there are multiple ways to take 220 yen, she will choose the way that contains the maximal number of 10-yen coins. - If Ciel or Hanako can't take exactly 220 yen from the pile, she loses.
Determine the winner of the game.
|
The first line contains two integers *x* (0<=≤<=*x*<=≤<=106) and *y* (0<=≤<=*y*<=≤<=106), separated by a single space.
|
If Ciel wins, print "Ciel". Otherwise, print "Hanako".
|
[
"2 2\n",
"3 22\n"
] |
[
"Ciel\n",
"Hanako\n"
] |
In the first turn (Ciel's turn), she will choose 2 100-yen coins and 2 10-yen coins. In the second turn (Hanako's turn), she will choose 1 100-yen coin and 12 10-yen coins. In the third turn (Ciel's turn), she can't pay exactly 220 yen, so Ciel will lose.
| 500
|
[
{
"input": "2 2",
"output": "Ciel"
},
{
"input": "3 22",
"output": "Hanako"
},
{
"input": "0 22",
"output": "Ciel"
},
{
"input": "1000 1000",
"output": "Ciel"
},
{
"input": "0 0",
"output": "Hanako"
},
{
"input": "0 21",
"output": "Hanako"
},
{
"input": "1 11",
"output": "Hanako"
},
{
"input": "1 12",
"output": "Ciel"
},
{
"input": "2 1",
"output": "Hanako"
},
{
"input": "2 23",
"output": "Ciel"
},
{
"input": "2 24",
"output": "Hanako"
},
{
"input": "3 1",
"output": "Hanako"
},
{
"input": "3 2",
"output": "Ciel"
},
{
"input": "3 13",
"output": "Ciel"
},
{
"input": "3 14",
"output": "Hanako"
},
{
"input": "4 1",
"output": "Hanako"
},
{
"input": "4 2",
"output": "Ciel"
},
{
"input": "4 25",
"output": "Hanako"
},
{
"input": "4 26",
"output": "Ciel"
},
{
"input": "5 1",
"output": "Hanako"
},
{
"input": "5 2",
"output": "Ciel"
},
{
"input": "5 15",
"output": "Hanako"
},
{
"input": "5 16",
"output": "Ciel"
},
{
"input": "5 23",
"output": "Ciel"
},
{
"input": "5 24",
"output": "Hanako"
},
{
"input": "6 1",
"output": "Hanako"
},
{
"input": "6 2",
"output": "Ciel"
},
{
"input": "6 13",
"output": "Ciel"
},
{
"input": "6 14",
"output": "Hanako"
},
{
"input": "6 23",
"output": "Ciel"
},
{
"input": "6 24",
"output": "Hanako"
},
{
"input": "7 1",
"output": "Hanako"
},
{
"input": "7 2",
"output": "Ciel"
},
{
"input": "7 13",
"output": "Ciel"
},
{
"input": "7 14",
"output": "Hanako"
},
{
"input": "7 25",
"output": "Hanako"
},
{
"input": "7 26",
"output": "Ciel"
},
{
"input": "8 1",
"output": "Hanako"
},
{
"input": "8 2",
"output": "Ciel"
},
{
"input": "8 15",
"output": "Hanako"
},
{
"input": "8 16",
"output": "Ciel"
},
{
"input": "8 25",
"output": "Hanako"
},
{
"input": "8 26",
"output": "Ciel"
},
{
"input": "9 1",
"output": "Hanako"
},
{
"input": "9 2",
"output": "Ciel"
},
{
"input": "9 15",
"output": "Hanako"
},
{
"input": "9 16",
"output": "Ciel"
},
{
"input": "9 23",
"output": "Ciel"
},
{
"input": "9 24",
"output": "Hanako"
},
{
"input": "10 12",
"output": "Ciel"
},
{
"input": "10 13",
"output": "Ciel"
},
{
"input": "10 22",
"output": "Ciel"
},
{
"input": "10 23",
"output": "Ciel"
},
{
"input": "11 12",
"output": "Ciel"
},
{
"input": "11 13",
"output": "Ciel"
},
{
"input": "11 24",
"output": "Hanako"
},
{
"input": "11 25",
"output": "Hanako"
},
{
"input": "12 14",
"output": "Hanako"
},
{
"input": "12 15",
"output": "Hanako"
},
{
"input": "12 24",
"output": "Hanako"
},
{
"input": "12 25",
"output": "Hanako"
},
{
"input": "0 1000000",
"output": "Hanako"
},
{
"input": "1000000 0",
"output": "Hanako"
},
{
"input": "1000000 1000000",
"output": "Ciel"
},
{
"input": "178087 42116",
"output": "Ciel"
},
{
"input": "378897 104123",
"output": "Ciel"
},
{
"input": "61207 166129",
"output": "Hanako"
},
{
"input": "743519 228136",
"output": "Ciel"
},
{
"input": "425829 771644",
"output": "Ciel"
},
{
"input": "626640 833651",
"output": "Ciel"
},
{
"input": "308950 895657",
"output": "Hanako"
},
{
"input": "991262 957664",
"output": "Ciel"
},
{
"input": "192071 19670",
"output": "Hanako"
},
{
"input": "874382 81677",
"output": "Hanako"
},
{
"input": "202081 745873",
"output": "Hanako"
},
{
"input": "233663 723781",
"output": "Hanako"
},
{
"input": "783744 701689",
"output": "Hanako"
},
{
"input": "333825 679597",
"output": "Hanako"
},
{
"input": "365407 657504",
"output": "Hanako"
},
{
"input": "915488 635412",
"output": "Hanako"
},
{
"input": "947070 613320",
"output": "Hanako"
},
{
"input": "497151 591228",
"output": "Hanako"
},
{
"input": "528732 87635",
"output": "Ciel"
},
{
"input": "78813 65543",
"output": "Hanako"
},
{
"input": "6 4",
"output": "Hanako"
},
{
"input": "3 5",
"output": "Ciel"
},
{
"input": "4 24",
"output": "Hanako"
},
{
"input": "2 14",
"output": "Ciel"
},
{
"input": "2 26",
"output": "Hanako"
},
{
"input": "5 26",
"output": "Ciel"
},
{
"input": "5 5",
"output": "Hanako"
},
{
"input": "359 479",
"output": "Hanako"
},
{
"input": "1 20",
"output": "Ciel"
},
{
"input": "11 0",
"output": "Hanako"
},
{
"input": "3 0",
"output": "Hanako"
},
{
"input": "0 30",
"output": "Ciel"
},
{
"input": "0 35",
"output": "Ciel"
},
{
"input": "100 99",
"output": "Ciel"
},
{
"input": "3 4",
"output": "Ciel"
}
] | 1,621,782,438
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 99
| 280
| 2,867,200
|
import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from operator import add
from itertools import accumulate
inf = float('inf')
# input = sys.stdin.readline
flush = lambda : sys.stdout.flush
comb = lambda x , y : (factorial(x) // factorial(y)) // factorial(x - y)
#inputs
# ip = lambda : input().rstrip()
ip = lambda : input()
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())
a , b =r()
c = 1
while a or b:
x = 220
while a and x>=100:
a-=1
x-=100
while b and x:
b-=1
x-=10
if c%2==0:
if b>9:
a+=1
b-=10
if b>9:
a+=1
b-=10
if x:
print("Hanako" if c%2 else "Ciel")
exit()
c+=1
print("Hanako" if c%2 else "Ciel")
|
Title: Bus Game
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
After Fox Ciel won an onsite round of a programming contest, she took a bus to return to her castle. The fee of the bus was 220 yen. She met Rabbit Hanako in the bus. They decided to play the following game because they got bored in the bus.
- Initially, there is a pile that contains *x* 100-yen coins and *y* 10-yen coins. - They take turns alternatively. Ciel takes the first turn. - In each turn, they must take exactly 220 yen from the pile. In Ciel's turn, if there are multiple ways to take 220 yen, she will choose the way that contains the maximal number of 100-yen coins. In Hanako's turn, if there are multiple ways to take 220 yen, she will choose the way that contains the maximal number of 10-yen coins. - If Ciel or Hanako can't take exactly 220 yen from the pile, she loses.
Determine the winner of the game.
Input Specification:
The first line contains two integers *x* (0<=≤<=*x*<=≤<=106) and *y* (0<=≤<=*y*<=≤<=106), separated by a single space.
Output Specification:
If Ciel wins, print "Ciel". Otherwise, print "Hanako".
Demo Input:
['2 2\n', '3 22\n']
Demo Output:
['Ciel\n', 'Hanako\n']
Note:
In the first turn (Ciel's turn), she will choose 2 100-yen coins and 2 10-yen coins. In the second turn (Hanako's turn), she will choose 1 100-yen coin and 12 10-yen coins. In the third turn (Ciel's turn), she can't pay exactly 220 yen, so Ciel will lose.
|
```python
import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from operator import add
from itertools import accumulate
inf = float('inf')
# input = sys.stdin.readline
flush = lambda : sys.stdout.flush
comb = lambda x , y : (factorial(x) // factorial(y)) // factorial(x - y)
#inputs
# ip = lambda : input().rstrip()
ip = lambda : input()
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())
a , b =r()
c = 1
while a or b:
x = 220
while a and x>=100:
a-=1
x-=100
while b and x:
b-=1
x-=10
if c%2==0:
if b>9:
a+=1
b-=10
if b>9:
a+=1
b-=10
if x:
print("Hanako" if c%2 else "Ciel")
exit()
c+=1
print("Hanako" if c%2 else "Ciel")
```
| 3.924659
|
6
|
A
|
Triangle
|
PROGRAMMING
| 900
|
[
"brute force",
"geometry"
] |
A. Triangle
|
2
|
64
|
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.
The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him.
|
The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks.
|
Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length.
|
[
"4 2 1 3\n",
"7 2 2 4\n",
"3 5 9 1\n"
] |
[
"TRIANGLE\n",
"SEGMENT\n",
"IMPOSSIBLE\n"
] |
none
| 0
|
[
{
"input": "4 2 1 3",
"output": "TRIANGLE"
},
{
"input": "7 2 2 4",
"output": "SEGMENT"
},
{
"input": "3 5 9 1",
"output": "IMPOSSIBLE"
},
{
"input": "3 1 5 1",
"output": "IMPOSSIBLE"
},
{
"input": "10 10 10 10",
"output": "TRIANGLE"
},
{
"input": "11 5 6 11",
"output": "TRIANGLE"
},
{
"input": "1 1 1 1",
"output": "TRIANGLE"
},
{
"input": "10 20 30 40",
"output": "TRIANGLE"
},
{
"input": "45 25 5 15",
"output": "IMPOSSIBLE"
},
{
"input": "20 5 8 13",
"output": "TRIANGLE"
},
{
"input": "10 30 7 20",
"output": "SEGMENT"
},
{
"input": "3 2 3 2",
"output": "TRIANGLE"
},
{
"input": "70 10 100 30",
"output": "SEGMENT"
},
{
"input": "4 8 16 2",
"output": "IMPOSSIBLE"
},
{
"input": "3 3 3 10",
"output": "TRIANGLE"
},
{
"input": "1 5 5 5",
"output": "TRIANGLE"
},
{
"input": "13 25 12 1",
"output": "SEGMENT"
},
{
"input": "10 100 7 3",
"output": "SEGMENT"
},
{
"input": "50 1 50 100",
"output": "TRIANGLE"
},
{
"input": "50 1 100 49",
"output": "SEGMENT"
},
{
"input": "49 51 100 1",
"output": "SEGMENT"
},
{
"input": "5 11 2 25",
"output": "IMPOSSIBLE"
},
{
"input": "91 50 9 40",
"output": "IMPOSSIBLE"
},
{
"input": "27 53 7 97",
"output": "IMPOSSIBLE"
},
{
"input": "51 90 24 8",
"output": "IMPOSSIBLE"
},
{
"input": "3 5 1 1",
"output": "IMPOSSIBLE"
},
{
"input": "13 49 69 15",
"output": "IMPOSSIBLE"
},
{
"input": "16 99 9 35",
"output": "IMPOSSIBLE"
},
{
"input": "27 6 18 53",
"output": "IMPOSSIBLE"
},
{
"input": "57 88 17 8",
"output": "IMPOSSIBLE"
},
{
"input": "95 20 21 43",
"output": "IMPOSSIBLE"
},
{
"input": "6 19 32 61",
"output": "IMPOSSIBLE"
},
{
"input": "100 21 30 65",
"output": "IMPOSSIBLE"
},
{
"input": "85 16 61 9",
"output": "IMPOSSIBLE"
},
{
"input": "5 6 19 82",
"output": "IMPOSSIBLE"
},
{
"input": "1 5 1 3",
"output": "IMPOSSIBLE"
},
{
"input": "65 10 36 17",
"output": "IMPOSSIBLE"
},
{
"input": "81 64 9 7",
"output": "IMPOSSIBLE"
},
{
"input": "11 30 79 43",
"output": "IMPOSSIBLE"
},
{
"input": "1 1 5 3",
"output": "IMPOSSIBLE"
},
{
"input": "21 94 61 31",
"output": "IMPOSSIBLE"
},
{
"input": "49 24 9 74",
"output": "IMPOSSIBLE"
},
{
"input": "11 19 5 77",
"output": "IMPOSSIBLE"
},
{
"input": "52 10 19 71",
"output": "SEGMENT"
},
{
"input": "2 3 7 10",
"output": "SEGMENT"
},
{
"input": "1 2 6 3",
"output": "SEGMENT"
},
{
"input": "2 6 1 8",
"output": "SEGMENT"
},
{
"input": "1 2 4 1",
"output": "SEGMENT"
},
{
"input": "4 10 6 2",
"output": "SEGMENT"
},
{
"input": "2 10 7 3",
"output": "SEGMENT"
},
{
"input": "5 2 3 9",
"output": "SEGMENT"
},
{
"input": "6 1 4 10",
"output": "SEGMENT"
},
{
"input": "10 6 4 1",
"output": "SEGMENT"
},
{
"input": "3 2 9 1",
"output": "SEGMENT"
},
{
"input": "22 80 29 7",
"output": "SEGMENT"
},
{
"input": "2 6 3 9",
"output": "SEGMENT"
},
{
"input": "3 1 2 1",
"output": "SEGMENT"
},
{
"input": "3 4 7 1",
"output": "SEGMENT"
},
{
"input": "8 4 3 1",
"output": "SEGMENT"
},
{
"input": "2 8 3 5",
"output": "SEGMENT"
},
{
"input": "4 1 2 1",
"output": "SEGMENT"
},
{
"input": "8 1 3 2",
"output": "SEGMENT"
},
{
"input": "6 2 1 8",
"output": "SEGMENT"
},
{
"input": "3 3 3 6",
"output": "TRIANGLE"
},
{
"input": "3 6 3 3",
"output": "TRIANGLE"
},
{
"input": "4 10 4 4",
"output": "TRIANGLE"
},
{
"input": "1 1 2 1",
"output": "TRIANGLE"
},
{
"input": "3 3 3 6",
"output": "TRIANGLE"
},
{
"input": "5 4 5 5",
"output": "TRIANGLE"
},
{
"input": "8 7 8 8",
"output": "TRIANGLE"
},
{
"input": "3 3 3 1",
"output": "TRIANGLE"
},
{
"input": "1 1 6 6",
"output": "TRIANGLE"
},
{
"input": "1 9 1 9",
"output": "TRIANGLE"
},
{
"input": "7 2 2 7",
"output": "TRIANGLE"
},
{
"input": "7 2 3 2",
"output": "TRIANGLE"
},
{
"input": "4 4 10 10",
"output": "TRIANGLE"
},
{
"input": "7 7 10 7",
"output": "TRIANGLE"
},
{
"input": "4 4 4 5",
"output": "TRIANGLE"
},
{
"input": "1 10 9 2",
"output": "TRIANGLE"
},
{
"input": "1 8 2 7",
"output": "TRIANGLE"
},
{
"input": "4 3 2 8",
"output": "TRIANGLE"
},
{
"input": "5 9 5 3",
"output": "TRIANGLE"
},
{
"input": "4 10 3 5",
"output": "TRIANGLE"
}
] | 1,417,314,707
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 83
| 156
| 0
|
from itertools import*
s=map(int,input().split())
d=x=0
for a,b,c in combinations(s,3):
a,b,c=sorted([a,b,c]);d=max(d,a+b==c)
if a+b>c:x="TRIANGLE";break
else:x=["IMPOSSIBLE","SEGMENT"][d]
print(x)
|
Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.
The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him.
Input Specification:
The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks.
Output Specification:
Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length.
Demo Input:
['4 2 1 3\n', '7 2 2 4\n', '3 5 9 1\n']
Demo Output:
['TRIANGLE\n', 'SEGMENT\n', 'IMPOSSIBLE\n']
Note:
none
|
```python
from itertools import*
s=map(int,input().split())
d=x=0
for a,b,c in combinations(s,3):
a,b,c=sorted([a,b,c]);d=max(d,a+b==c)
if a+b>c:x="TRIANGLE";break
else:x=["IMPOSSIBLE","SEGMENT"][d]
print(x)
```
| 3.961
|
962
|
C
|
Make a Square
|
PROGRAMMING
| 1,400
|
[
"brute force",
"implementation",
"math"
] | null | null |
You are given a positive integer $n$, written without leading zeroes (for example, the number 04 is incorrect).
In one operation you can delete any digit of the given integer so that the result remains a positive integer without leading zeros.
Determine the minimum number of operations that you need to consistently apply to the given integer $n$ to make from it the square of some positive integer or report that it is impossible.
An integer $x$ is the square of some positive integer if and only if $x=y^2$ for some positive integer $y$.
|
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{9}$). The number is given without leading zeroes.
|
If it is impossible to make the square of some positive integer from $n$, print -1. In the other case, print the minimal number of operations required to do it.
|
[
"8314\n",
"625\n",
"333\n"
] |
[
"2\n",
"0\n",
"-1\n"
] |
In the first example we should delete from $8314$ the digits $3$ and $4$. After that $8314$ become equals to $81$, which is the square of the integer $9$.
In the second example the given $625$ is the square of the integer $25$, so you should not delete anything.
In the third example it is impossible to make the square from $333$, so the answer is -1.
| 0
|
[
{
"input": "8314",
"output": "2"
},
{
"input": "625",
"output": "0"
},
{
"input": "333",
"output": "-1"
},
{
"input": "1881388645",
"output": "6"
},
{
"input": "1059472069",
"output": "3"
},
{
"input": "1354124829",
"output": "4"
},
{
"input": "149723943",
"output": "4"
},
{
"input": "101",
"output": "2"
},
{
"input": "1999967841",
"output": "0"
},
{
"input": "2000000000",
"output": "-1"
},
{
"input": "1999431225",
"output": "0"
},
{
"input": "30",
"output": "-1"
},
{
"input": "1000",
"output": "1"
},
{
"input": "3081",
"output": "2"
},
{
"input": "10",
"output": "1"
},
{
"input": "2003064",
"output": "3"
},
{
"input": "701",
"output": "2"
},
{
"input": "1234567891",
"output": "4"
},
{
"input": "10625",
"output": "2"
},
{
"input": "13579",
"output": "4"
},
{
"input": "1999999999",
"output": "9"
},
{
"input": "150000",
"output": "1"
},
{
"input": "8010902",
"output": "3"
},
{
"input": "20100",
"output": "2"
},
{
"input": "40404",
"output": "2"
},
{
"input": "70000729",
"output": "5"
},
{
"input": "1899933124",
"output": "5"
},
{
"input": "1999999081",
"output": "8"
},
{
"input": "326700",
"output": "2"
},
{
"input": "1",
"output": "0"
},
{
"input": "1000000990",
"output": "3"
},
{
"input": "10000",
"output": "0"
},
{
"input": "100001",
"output": "1"
},
{
"input": "1410065408",
"output": "7"
},
{
"input": "1409865409",
"output": "5"
},
{
"input": "1000050001",
"output": "3"
},
{
"input": "1044435556",
"output": "2"
},
{
"input": "520993450",
"output": "6"
},
{
"input": "131073",
"output": "5"
},
{
"input": "500040004",
"output": "6"
},
{
"input": "237555493",
"output": "7"
},
{
"input": "1120671621",
"output": "5"
},
{
"input": "298755045",
"output": "5"
},
{
"input": "1476838469",
"output": "5"
},
{
"input": "654921893",
"output": "4"
},
{
"input": "1538038021",
"output": "4"
},
{
"input": "716121445",
"output": "6"
},
{
"input": "1894204869",
"output": "5"
},
{
"input": "1800098866",
"output": "7"
},
{
"input": "890665277",
"output": "8"
},
{
"input": "1686264392",
"output": "6"
},
{
"input": "1336639314",
"output": "6"
},
{
"input": "132238429",
"output": "5"
},
{
"input": "927837544",
"output": "4"
},
{
"input": "18403955",
"output": "4"
},
{
"input": "1668778878",
"output": "8"
},
{
"input": "2",
"output": "-1"
},
{
"input": "3",
"output": "-1"
},
{
"input": "4",
"output": "0"
},
{
"input": "5",
"output": "-1"
},
{
"input": "6",
"output": "-1"
},
{
"input": "7",
"output": "-1"
},
{
"input": "8",
"output": "-1"
},
{
"input": "9",
"output": "0"
},
{
"input": "11",
"output": "1"
},
{
"input": "12",
"output": "1"
},
{
"input": "13",
"output": "1"
},
{
"input": "14",
"output": "1"
},
{
"input": "15",
"output": "1"
},
{
"input": "16",
"output": "0"
}
] | 1,553,601,733
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 70
| 155
| 1,945,600
|
sq=[0]*(50000)
for i in range(50000):
sq[i]=i*i
s=input()
for k in range(49999,0,-1):
t=str(sq[k])
if len(t)<=len(s):
j=0
i=0
while(j<len(s) and i<len(t)):
if t[i]==s[j]:
i+=1
j+=1
else:
j+=1
if i==len(t):
# print(t)
print(len(s)-len(t))
exit()
print("-1")
|
Title: Make a Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a positive integer $n$, written without leading zeroes (for example, the number 04 is incorrect).
In one operation you can delete any digit of the given integer so that the result remains a positive integer without leading zeros.
Determine the minimum number of operations that you need to consistently apply to the given integer $n$ to make from it the square of some positive integer or report that it is impossible.
An integer $x$ is the square of some positive integer if and only if $x=y^2$ for some positive integer $y$.
Input Specification:
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{9}$). The number is given without leading zeroes.
Output Specification:
If it is impossible to make the square of some positive integer from $n$, print -1. In the other case, print the minimal number of operations required to do it.
Demo Input:
['8314\n', '625\n', '333\n']
Demo Output:
['2\n', '0\n', '-1\n']
Note:
In the first example we should delete from $8314$ the digits $3$ and $4$. After that $8314$ become equals to $81$, which is the square of the integer $9$.
In the second example the given $625$ is the square of the integer $25$, so you should not delete anything.
In the third example it is impossible to make the square from $333$, so the answer is -1.
|
```python
sq=[0]*(50000)
for i in range(50000):
sq[i]=i*i
s=input()
for k in range(49999,0,-1):
t=str(sq[k])
if len(t)<=len(s):
j=0
i=0
while(j<len(s) and i<len(t)):
if t[i]==s[j]:
i+=1
j+=1
else:
j+=1
if i==len(t):
# print(t)
print(len(s)-len(t))
exit()
print("-1")
```
| 3
|
|
680
|
B
|
Bear and Finding Criminals
|
PROGRAMMING
| 1,000
|
[
"constructive algorithms",
"implementation"
] | null | null |
There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|.
Limak is a police officer. He lives in a city *a*. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he knows that there is at most one criminal in each city.
Limak is going to use a BCD (Bear Criminal Detector). The BCD will tell Limak how many criminals there are for every distance from a city *a*. After that, Limak can catch a criminal in each city for which he is sure that there must be a criminal.
You know in which cities criminals are. Count the number of criminals Limak will catch, after he uses the BCD.
|
The first line of the input contains two integers *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100) — the number of cities and the index of city where Limak lives.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=≤<=1). There are *t**i* criminals in the *i*-th city.
|
Print the number of criminals Limak will catch.
|
[
"6 3\n1 1 1 0 1 0\n",
"5 2\n0 0 0 1 0\n"
] |
[
"3\n",
"1\n"
] |
In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red.
Using the BCD gives Limak the following information:
- There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city. - There is one criminal at distance 1 from the third city — Limak doesn't know if a criminal is in the second or fourth city. - There are two criminals at distance 2 from the third city — Limak is sure that there is one criminal in the first city and one in the fifth city. - There are zero criminals for every greater distance.
So, Limak will catch criminals in cities 1, 3 and 5, that is 3 criminals in total.
In the second sample (drawing below), the BCD gives Limak the information that there is one criminal at distance 2 from Limak's city. There is only one city at distance 2 so Limak is sure where a criminal is.
| 1,000
|
[
{
"input": "6 3\n1 1 1 0 1 0",
"output": "3"
},
{
"input": "5 2\n0 0 0 1 0",
"output": "1"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "9 3\n1 1 1 1 1 1 1 1 0",
"output": "8"
},
{
"input": "9 5\n1 0 1 0 1 0 1 0 1",
"output": "5"
},
{
"input": "20 17\n1 1 0 1 1 1 1 0 1 0 1 1 1 0 1 1 0 0 0 0",
"output": "10"
},
{
"input": "100 60\n1 1 1 1 1 1 0 1 0 0 1 1 0 1 1 1 1 1 0 0 1 1 0 0 0 0 0 1 0 1 1 0 1 0 1 0 1 0 1 1 0 0 0 0 0 1 1 1 0 1 1 0 0 0 1 0 0 0 1 1 1 0 1 0 0 1 1 1 0 1 1 1 0 0 1 1 0 1 0 0 0 1 0 0 0 0 0 0 1 1 1 0 0 1 1 1 0 1 0 0",
"output": "27"
},
{
"input": "8 1\n1 0 1 1 0 0 1 0",
"output": "4"
},
{
"input": "11 11\n0 1 0 0 1 1 1 0 0 0 0",
"output": "4"
},
{
"input": "19 10\n0 1 1 0 1 0 0 1 1 0 0 1 0 1 0 0 1 0 1",
"output": "4"
},
{
"input": "100 38\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "100 38\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "1"
},
{
"input": "100 38\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "3"
},
{
"input": "99 38\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "25"
},
{
"input": "99 38\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "24"
},
{
"input": "99 38\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "24"
},
{
"input": "98 70\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "41"
},
{
"input": "99 70\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "9"
},
{
"input": "99 60\n0 0 0 1 1 0 1 1 0 0 1 0 0 0 0 0 1 0 1 0 0 0 1 0 1 1 1 0 1 1 1 1 0 0 1 1 1 0 1 1 1 1 1 0 1 1 0 0 0 0 0 1 0 0 1 0 1 1 1 1 1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0 1 1 1 0 0 0 0 1 1 0 1 1 1 1 0 0 0 0 0 0 1 1 1",
"output": "34"
},
{
"input": "98 24\n0 0 0 1 1 0 1 1 0 0 0 0 1 0 0 1 0 0 1 1 1 0 0 1 0 0 1 0 1 0 0 1 1 0 1 1 1 0 1 0 0 1 0 0 0 1 1 1 1 0 1 1 1 0 1 1 1 1 0 0 1 0 0 0 1 0 1 1 0 1 0 1 1 1 0 0 1 0 0 0 1 1 0 0 1 1 1 1 1 1 0 1 0 1 0 0 1 1",
"output": "39"
},
{
"input": "100 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "100"
},
{
"input": "100 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "2 1\n0 1",
"output": "1"
}
] | 1,637,964,232
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 24
| 46
| 0
|
nOfCities , x = map(int, input().split())
x -= 1
criminals = list(map(int, input().split()))
def criminalsFound(cities, criminals):
Counter = 0
for i in range(0, nOfCities):
if x - i >= 0 and x+i < nOfCities:
if criminals[x - i] == 1 and criminals[x + i] == 1:
Counter += 2
elif x - i >= 0:
if criminals[x - i] == 1:
Counter += 1
elif x + i < nOfCities:
if criminals[x + i] == 1:
Counter += 1
if criminals[x] == 1:
Counter -= 1
print(Counter)
return Counter
criminalsFound(nOfCities, criminals)
|
Title: Bear and Finding Criminals
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|.
Limak is a police officer. He lives in a city *a*. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he knows that there is at most one criminal in each city.
Limak is going to use a BCD (Bear Criminal Detector). The BCD will tell Limak how many criminals there are for every distance from a city *a*. After that, Limak can catch a criminal in each city for which he is sure that there must be a criminal.
You know in which cities criminals are. Count the number of criminals Limak will catch, after he uses the BCD.
Input Specification:
The first line of the input contains two integers *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100) — the number of cities and the index of city where Limak lives.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=≤<=1). There are *t**i* criminals in the *i*-th city.
Output Specification:
Print the number of criminals Limak will catch.
Demo Input:
['6 3\n1 1 1 0 1 0\n', '5 2\n0 0 0 1 0\n']
Demo Output:
['3\n', '1\n']
Note:
In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red.
Using the BCD gives Limak the following information:
- There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city. - There is one criminal at distance 1 from the third city — Limak doesn't know if a criminal is in the second or fourth city. - There are two criminals at distance 2 from the third city — Limak is sure that there is one criminal in the first city and one in the fifth city. - There are zero criminals for every greater distance.
So, Limak will catch criminals in cities 1, 3 and 5, that is 3 criminals in total.
In the second sample (drawing below), the BCD gives Limak the information that there is one criminal at distance 2 from Limak's city. There is only one city at distance 2 so Limak is sure where a criminal is.
|
```python
nOfCities , x = map(int, input().split())
x -= 1
criminals = list(map(int, input().split()))
def criminalsFound(cities, criminals):
Counter = 0
for i in range(0, nOfCities):
if x - i >= 0 and x+i < nOfCities:
if criminals[x - i] == 1 and criminals[x + i] == 1:
Counter += 2
elif x - i >= 0:
if criminals[x - i] == 1:
Counter += 1
elif x + i < nOfCities:
if criminals[x + i] == 1:
Counter += 1
if criminals[x] == 1:
Counter -= 1
print(Counter)
return Counter
criminalsFound(nOfCities, criminals)
```
| 3
|
|
58
|
A
|
Chat room
|
PROGRAMMING
| 1,000
|
[
"greedy",
"strings"
] |
A. Chat room
|
1
|
256
|
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
|
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
|
If Vasya managed to say hello, print "YES", otherwise print "NO".
|
[
"ahhellllloou\n",
"hlelo\n"
] |
[
"YES\n",
"NO\n"
] |
none
| 500
|
[
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,693,642,727
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 30
| 0
|
def room(v):
target = "room"
idx = 0
for ch in v:
if idx < len(target) and ch == target[idx]:
idx += 1
if idx == len(target):
return "YES"
return "NO"
v = input().strip()
result = room(v)
print(result)
|
Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none
|
```python
def room(v):
target = "room"
idx = 0
for ch in v:
if idx < len(target) and ch == target[idx]:
idx += 1
if idx == len(target):
return "YES"
return "NO"
v = input().strip()
result = room(v)
print(result)
```
| 0
|
748
|
B
|
Santa Claus and Keyboard Check
|
PROGRAMMING
| 1,500
|
[
"implementation",
"strings"
] | null | null |
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be.
In order to make sure that he's right and restore the correct order of keys, Santa typed his favorite patter looking only to his keyboard.
You are given the Santa's favorite patter and the string he actually typed. Determine which pairs of keys could be mixed. Each key must occur in pairs at most once.
|
The input consists of only two strings *s* and *t* denoting the favorite Santa's patter and the resulting string. *s* and *t* are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.
|
If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes).
Otherwise, the first line of output should contain the only integer *k* (*k*<=≥<=0) — the number of pairs of keys that should be swapped. The following *k* lines should contain two space-separated letters each, denoting the keys which should be swapped. All printed letters must be distinct.
If there are several possible answers, print any of them. You are free to choose the order of the pairs and the order of keys in a pair.
Each letter must occur at most once. Santa considers the keyboard to be fixed if he can print his favorite patter without mistakes.
|
[
"helloworld\nehoolwlroz\n",
"hastalavistababy\nhastalavistababy\n",
"merrychristmas\nchristmasmerry\n"
] |
[
"3\nh e\nl o\nd z\n",
"0\n",
"-1\n"
] |
none
| 1,000
|
[
{
"input": "helloworld\nehoolwlroz",
"output": "3\nh e\nl o\nd z"
},
{
"input": "hastalavistababy\nhastalavistababy",
"output": "0"
},
{
"input": "merrychristmas\nchristmasmerry",
"output": "-1"
},
{
"input": "kusyvdgccw\nkusyvdgccw",
"output": "0"
},
{
"input": "bbbbbabbab\naaaaabaaba",
"output": "1\nb a"
},
{
"input": "zzzzzzzzzzzzzzzzzzzzz\nqwertyuiopasdfghjklzx",
"output": "-1"
},
{
"input": "accdccdcdccacddbcacc\naccbccbcbccacbbdcacc",
"output": "1\nd b"
},
{
"input": "giiibdbebjdaihdghahccdeffjhfgidfbdhjdggajfgaidadjd\ngiiibdbebjdaihdghahccdeffjhfgidfbdhjdggajfgaidadjd",
"output": "0"
},
{
"input": "gndggadlmdefgejidmmcglbjdcmglncfmbjjndjcibnjbabfab\nfihffahlmhogfojnhmmcflkjhcmflicgmkjjihjcnkijkakgak",
"output": "5\ng f\nn i\nd h\ne o\nb k"
},
{
"input": "ijpanyhovzwjjxsvaiyhchfaulcsdgfszjnwtoqbtaqygfmxuwvynvlhqhvmkjbooklxfhmqlqvfoxlnoclfxtbhvnkmhjcmrsdc\nijpanyhovzwjjxsvaiyhchfaulcsdgfszjnwtoqbtaqygfmxuwvynvlhqhvmkjbooklxfhmqlqvfoxlnoclfxtbhvnkmhjcmrsdc",
"output": "0"
},
{
"input": "ab\naa",
"output": "-1"
},
{
"input": "a\nz",
"output": "1\na z"
},
{
"input": "zz\nzy",
"output": "-1"
},
{
"input": "as\ndf",
"output": "2\na d\ns f"
},
{
"input": "abc\nbca",
"output": "-1"
},
{
"input": "rtfg\nrftg",
"output": "1\nt f"
},
{
"input": "y\ny",
"output": "0"
},
{
"input": "qwertyuiopasdfghjklzx\nzzzzzzzzzzzzzzzzzzzzz",
"output": "-1"
},
{
"input": "qazwsxedcrfvtgbyhnujmik\nqwertyuiasdfghjkzxcvbnm",
"output": "-1"
},
{
"input": "aaaaaa\nabcdef",
"output": "-1"
},
{
"input": "qwerty\nffffff",
"output": "-1"
},
{
"input": "dofbgdppdvmwjwtdyphhmqliydxyjfxoopxiscevowleccmhwybsxitvujkfliamvqinlrpytyaqdlbywccprukoisyaseibuqbfqjcabkieimsggsakpnqliwhehnemewhychqrfiuyaecoydnromrh\ndofbgdppdvmwjwtdyphhmqliydxyjfxoopxiscevowleccmhwybsxitvujkfliamvqinlrpytyaqdlbywccprukoisyaseibuqbfqjcabkieimsggsakpnqliwhehnemewhychqrfiuyaecoydnromrh",
"output": "0"
},
{
"input": "acdbccddadbcbabbebbaebdcedbbcebeaccecdabadeabeecbacacdcbccedeadadedeccedecdaabcedccccbbcbcedcaccdede\ndcbaccbbdbacadaaeaadeabcebaaceaedccecbdadbedaeecadcdcbcaccebedbdbebeccebecbddacebccccaacacebcdccbebe",
"output": "-1"
},
{
"input": "bacccbbacabbcaacbbba\nbacccbbacabbcaacbbba",
"output": "0"
},
{
"input": "dbadbddddb\nacbacaaaac",
"output": "-1"
},
{
"input": "dacbdbbbdd\nadbdadddaa",
"output": "-1"
},
{
"input": "bbbbcbcbbc\ndaddbabddb",
"output": "-1"
},
{
"input": "dddddbcdbd\nbcbbbdacdb",
"output": "-1"
},
{
"input": "cbadcbcdaa\nabbbababbb",
"output": "-1"
},
{
"input": "dmkgadidjgdjikgkehhfkhgkeamhdkfemikkjhhkdjfaenmkdgenijinamngjgkmgmmedfdehkhdigdnnkhmdkdindhkhndnakdgdhkdefagkedndnijekdmkdfedkhekgdkhgkimfeakdhhhgkkff\nbdenailbmnbmlcnehjjkcgnehadgickhdlecmggcimkahfdeinhflmlfadfnmncdnddhbkbhgejblnbffcgdbeilfigegfifaebnijeihkanehififlmhcbdcikhieghenbejneldkhaebjggncckk",
"output": "-1"
},
{
"input": "acbbccabaa\nabbbbbabaa",
"output": "-1"
},
{
"input": "ccccaccccc\naaaabaaaac",
"output": "-1"
},
{
"input": "acbacacbbb\nacbacacbbb",
"output": "0"
},
{
"input": "abbababbcc\nccccccccbb",
"output": "-1"
},
{
"input": "jbcbbjiifdcbeajgdeabddbfcecafejddcigfcaedbgicjihifgbahjihcjefgabgbccdiibfjgacehbbdjceacdbdeaiibaicih\nhhihhhddcfihddhjfddhffhcididcdhffidjciddfhjdihdhdcjhdhhdhihdcjdhjhiifddhchjdidhhhfhiddifhfddddhddidh",
"output": "-1"
},
{
"input": "ahaeheedefeehahfefhjhhedheeeedhehhfhdejdhffhhejhhhejadhefhahhadjjhdhheeeehfdaffhhefehhhefhhhhehehjda\neiefbdfgdhffieihfhjajifgjddffgifjbhigfagjhhjicaijbdaegidhiejiegaabgjidcfcjhgehhjjchcbjjdhjbiidjdjage",
"output": "-1"
},
{
"input": "fficficbidbcbfaddifbffdbbiaccbbciiaidbcbbiadcccbccbbaibabcbbdbcibcciibiccfifbiiicadibbiaafadacdficbc\nddjhdghbgcbhadeccjdbddcbfjeiiaaigjejcaiabgechiiahibfejbeahafcfhjbihgjfgihdgdagjjhecjafjeedecehcdjhai",
"output": "-1"
},
{
"input": "z\nz",
"output": "0"
},
{
"input": "a\nz",
"output": "1\na z"
},
{
"input": "z\na",
"output": "1\nz a"
},
{
"input": "aa\nzz",
"output": "1\na z"
},
{
"input": "az\nza",
"output": "1\na z"
},
{
"input": "aa\nza",
"output": "-1"
},
{
"input": "za\nzz",
"output": "-1"
},
{
"input": "aa\nab",
"output": "-1"
},
{
"input": "hehe\nheeh",
"output": "-1"
},
{
"input": "bd\ncc",
"output": "-1"
},
{
"input": "he\nhh",
"output": "-1"
},
{
"input": "hee\nheh",
"output": "-1"
},
{
"input": "aa\nac",
"output": "-1"
},
{
"input": "ab\naa",
"output": "-1"
},
{
"input": "hello\nehlol",
"output": "-1"
},
{
"input": "ac\naa",
"output": "-1"
},
{
"input": "aaabbb\nbbbaab",
"output": "-1"
},
{
"input": "aa\nfa",
"output": "-1"
},
{
"input": "hg\nee",
"output": "-1"
},
{
"input": "helloworld\nehoolwlrow",
"output": "-1"
},
{
"input": "abb\nbab",
"output": "-1"
},
{
"input": "aaa\naae",
"output": "-1"
},
{
"input": "aba\nbaa",
"output": "-1"
},
{
"input": "aa\nba",
"output": "-1"
},
{
"input": "da\naa",
"output": "-1"
},
{
"input": "aaa\naab",
"output": "-1"
},
{
"input": "xy\nzz",
"output": "-1"
}
] | 1,635,591,735
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 13
| 46
| 4,505,600
|
A, B = input(), input()
keys,maps,mis = set(),[],False
for i in range(len(A)):
if A[i] != B[i] and [A[i],B[i]] not in maps and [B[i],A[i]] not in maps:
if A[i] not in keys and B[i] not in keys:
keys.add(A[i])
keys.add(B[i])
maps.append([A[i],B[i]])
else:
mis,maps = True,[]
break
print(len(maps)) if not mis else print(-1)
for i in maps: print(i[0],i[1])
|
Title: Santa Claus and Keyboard Check
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be.
In order to make sure that he's right and restore the correct order of keys, Santa typed his favorite patter looking only to his keyboard.
You are given the Santa's favorite patter and the string he actually typed. Determine which pairs of keys could be mixed. Each key must occur in pairs at most once.
Input Specification:
The input consists of only two strings *s* and *t* denoting the favorite Santa's patter and the resulting string. *s* and *t* are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.
Output Specification:
If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes).
Otherwise, the first line of output should contain the only integer *k* (*k*<=≥<=0) — the number of pairs of keys that should be swapped. The following *k* lines should contain two space-separated letters each, denoting the keys which should be swapped. All printed letters must be distinct.
If there are several possible answers, print any of them. You are free to choose the order of the pairs and the order of keys in a pair.
Each letter must occur at most once. Santa considers the keyboard to be fixed if he can print his favorite patter without mistakes.
Demo Input:
['helloworld\nehoolwlroz\n', 'hastalavistababy\nhastalavistababy\n', 'merrychristmas\nchristmasmerry\n']
Demo Output:
['3\nh e\nl o\nd z\n', '0\n', '-1\n']
Note:
none
|
```python
A, B = input(), input()
keys,maps,mis = set(),[],False
for i in range(len(A)):
if A[i] != B[i] and [A[i],B[i]] not in maps and [B[i],A[i]] not in maps:
if A[i] not in keys and B[i] not in keys:
keys.add(A[i])
keys.add(B[i])
maps.append([A[i],B[i]])
else:
mis,maps = True,[]
break
print(len(maps)) if not mis else print(-1)
for i in maps: print(i[0],i[1])
```
| 0
|
|
467
|
A
|
George and Accommodation
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* people living in it and the room can accommodate *q**i* people in total (*p**i*<=≤<=*q**i*). Your task is to count how many rooms has free place for both George and Alex.
|
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms.
The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity.
|
Print a single integer — the number of rooms where George and Alex can move in.
|
[
"3\n1 1\n2 2\n3 3\n",
"3\n1 10\n0 10\n10 10\n"
] |
[
"0\n",
"2\n"
] |
none
| 500
|
[
{
"input": "3\n1 1\n2 2\n3 3",
"output": "0"
},
{
"input": "3\n1 10\n0 10\n10 10",
"output": "2"
},
{
"input": "2\n36 67\n61 69",
"output": "2"
},
{
"input": "3\n21 71\n10 88\n43 62",
"output": "3"
},
{
"input": "3\n1 2\n2 3\n3 4",
"output": "0"
},
{
"input": "10\n0 10\n0 20\n0 30\n0 40\n0 50\n0 60\n0 70\n0 80\n0 90\n0 100",
"output": "10"
},
{
"input": "13\n14 16\n30 31\n45 46\n19 20\n15 17\n66 67\n75 76\n95 97\n29 30\n37 38\n0 2\n36 37\n8 9",
"output": "4"
},
{
"input": "19\n66 67\n97 98\n89 91\n67 69\n67 68\n18 20\n72 74\n28 30\n91 92\n27 28\n75 77\n17 18\n74 75\n28 30\n16 18\n90 92\n9 11\n22 24\n52 54",
"output": "12"
},
{
"input": "15\n55 57\n95 97\n57 59\n34 36\n50 52\n96 98\n39 40\n13 15\n13 14\n74 76\n47 48\n56 58\n24 25\n11 13\n67 68",
"output": "10"
},
{
"input": "17\n68 69\n47 48\n30 31\n52 54\n41 43\n33 35\n38 40\n56 58\n45 46\n92 93\n73 74\n61 63\n65 66\n37 39\n67 68\n77 78\n28 30",
"output": "8"
},
{
"input": "14\n64 66\n43 44\n10 12\n76 77\n11 12\n25 27\n87 88\n62 64\n39 41\n58 60\n10 11\n28 29\n57 58\n12 14",
"output": "7"
},
{
"input": "38\n74 76\n52 54\n78 80\n48 49\n40 41\n64 65\n28 30\n6 8\n49 51\n68 70\n44 45\n57 59\n24 25\n46 48\n49 51\n4 6\n63 64\n76 78\n57 59\n18 20\n63 64\n71 73\n88 90\n21 22\n89 90\n65 66\n89 91\n96 98\n42 44\n1 1\n74 76\n72 74\n39 40\n75 76\n29 30\n48 49\n87 89\n27 28",
"output": "22"
},
{
"input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "26\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2",
"output": "0"
},
{
"input": "68\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2",
"output": "68"
},
{
"input": "7\n0 1\n1 5\n2 4\n3 5\n4 6\n5 6\n6 8",
"output": "5"
},
{
"input": "1\n0 0",
"output": "0"
},
{
"input": "1\n100 100",
"output": "0"
},
{
"input": "44\n0 8\n1 11\n2 19\n3 5\n4 29\n5 45\n6 6\n7 40\n8 19\n9 22\n10 18\n11 26\n12 46\n13 13\n14 27\n15 48\n16 25\n17 20\n18 29\n19 27\n20 45\n21 39\n22 29\n23 39\n24 42\n25 37\n26 52\n27 36\n28 43\n29 35\n30 38\n31 70\n32 47\n33 38\n34 61\n35 71\n36 51\n37 71\n38 59\n39 77\n40 70\n41 80\n42 77\n43 73",
"output": "42"
},
{
"input": "3\n1 3\n2 7\n8 9",
"output": "2"
},
{
"input": "53\n0 1\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53",
"output": "0"
},
{
"input": "55\n0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54",
"output": "0"
},
{
"input": "51\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 62\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 73\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 82\n55 68\n55 70\n55 63\n55 55\n55 55\n55 55\n55 75\n55 75\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 73\n55 55\n55 82\n55 99\n55 60",
"output": "12"
},
{
"input": "14\n1 1\n1 1\n1 55\n1 16\n1 1\n1 1\n1 55\n1 62\n1 53\n1 26\n1 1\n1 36\n1 2\n1 3",
"output": "8"
}
] | 1,688,104,572
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 27
| 46
| 0
|
s=0
n = int(input())
for _ in range(n):
lst = list(map(int,input().split()))[:2]
if(lst[1]-lst[0]>=2):
s+=1
print(s)
|
Title: George and Accommodation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* people living in it and the room can accommodate *q**i* people in total (*p**i*<=≤<=*q**i*). Your task is to count how many rooms has free place for both George and Alex.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms.
The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity.
Output Specification:
Print a single integer — the number of rooms where George and Alex can move in.
Demo Input:
['3\n1 1\n2 2\n3 3\n', '3\n1 10\n0 10\n10 10\n']
Demo Output:
['0\n', '2\n']
Note:
none
|
```python
s=0
n = int(input())
for _ in range(n):
lst = list(map(int,input().split()))[:2]
if(lst[1]-lst[0]>=2):
s+=1
print(s)
```
| 3
|
|
981
|
B
|
Businessmen Problems
|
PROGRAMMING
| 1,000
|
[
"sortings"
] | null | null |
Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both companies.
In order to avoid this representatives of both companies decided to make an agreement on the sets the companies should present. The sets should be chosen in the way that maximizes the total income of the companies.
All elements are enumerated with integers. The ChemForces company has discovered $n$ distinct chemical elements with indices $a_1, a_2, \ldots, a_n$, and will get an income of $x_i$ Berland rubles if the $i$-th element from this list is in the set of this company.
The TopChemist company discovered $m$ distinct chemical elements with indices $b_1, b_2, \ldots, b_m$, and it will get an income of $y_j$ Berland rubles for including the $j$-th element from this list to its set.
In other words, the first company can present any subset of elements from $\{a_1, a_2, \ldots, a_n\}$ (possibly empty subset), the second company can present any subset of elements from $\{b_1, b_2, \ldots, b_m\}$ (possibly empty subset). There shouldn't be equal elements in the subsets.
Help the representatives select the sets in such a way that no element is presented in both sets and the total income is the maximum possible.
|
The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the number of elements discovered by ChemForces.
The $i$-th of the next $n$ lines contains two integers $a_i$ and $x_i$ ($1 \leq a_i \leq 10^9$, $1 \leq x_i \leq 10^9$) — the index of the $i$-th element and the income of its usage on the exhibition. It is guaranteed that all $a_i$ are distinct.
The next line contains a single integer $m$ ($1 \leq m \leq 10^5$) — the number of chemicals invented by TopChemist.
The $j$-th of the next $m$ lines contains two integers $b_j$ and $y_j$, ($1 \leq b_j \leq 10^9$, $1 \leq y_j \leq 10^9$) — the index of the $j$-th element and the income of its usage on the exhibition. It is guaranteed that all $b_j$ are distinct.
|
Print the maximum total income you can obtain by choosing the sets for both companies in such a way that no element is presented in both sets.
|
[
"3\n1 2\n7 2\n3 10\n4\n1 4\n2 4\n3 4\n4 4\n",
"1\n1000000000 239\n3\n14 15\n92 65\n35 89\n"
] |
[
"24\n",
"408\n"
] |
In the first example ChemForces can choose the set ($3, 7$), while TopChemist can choose ($1, 2, 4$). This way the total income is $(10 + 2) + (4 + 4 + 4) = 24$.
In the second example ChemForces can choose the only element $10^9$, while TopChemist can choose ($14, 92, 35$). This way the total income is $(239) + (15 + 65 + 89) = 408$.
| 750
|
[
{
"input": "3\n1 2\n7 2\n3 10\n4\n1 4\n2 4\n3 4\n4 4",
"output": "24"
},
{
"input": "1\n1000000000 239\n3\n14 15\n92 65\n35 89",
"output": "408"
},
{
"input": "10\n598654597 488228616\n544064902 21923894\n329635457 980089248\n988262691 654502493\n967529230 543358150\n835120075 128123793\n809901567 613170206\n152157661 479980560\n859252956 318029856\n614959273 735298093\n10\n849172317 361325206\n341655282 740807372\n453949939 809030434\n813199219 765838311\n725032511 427644854\n631233366 115983627\n825067417 721190169\n463026366 953335259\n881501578 987288937\n500099903 427659916",
"output": "11272808994"
},
{
"input": "10\n598654597 488228616\n544064902 21923894\n329635457 980089248\n988262691 654502493\n967529230 543358150\n835120075 128123793\n809901567 613170206\n152157661 479980560\n859252956 318029856\n614959273 735298093\n10\n544064902 740807372\n859252956 765838311\n835120075 115983627\n825067417 463026366\n809901567 500099903\n614959273 322932832\n33955432 657532637\n816892960 927933923\n916770606 754371712\n967529230 566149252",
"output": "8955052582"
},
{
"input": "1\n259021863 682413763\n1\n554146726 693647287",
"output": "1376061050"
},
{
"input": "1\n259021863 682413763\n1\n554146726 425883728",
"output": "1108297491"
},
{
"input": "1\n1000000000 1\n1\n1000000000 1000000000",
"output": "1000000000"
},
{
"input": "2\n1 4\n2 4\n2\n1 4\n2 4",
"output": "8"
},
{
"input": "1\n14 15\n3\n35 89\n92 65\n1000000000 239",
"output": "408"
}
] | 1,699,348,299
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 33
| 1,263
| 22,016,000
|
n = int(input())
elements = {}
elements = dict(elements)
for i in range(n):
a, b = map(int, input().split())
elements[a] = b
m = int(input())
for i in range(m):
a, b = map(int, input().split())
if elements.get(a):
elements[a] = max(elements[a], b)
else:
elements[a] = b
print(sum(elements.values()))
|
Title: Businessmen Problems
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both companies.
In order to avoid this representatives of both companies decided to make an agreement on the sets the companies should present. The sets should be chosen in the way that maximizes the total income of the companies.
All elements are enumerated with integers. The ChemForces company has discovered $n$ distinct chemical elements with indices $a_1, a_2, \ldots, a_n$, and will get an income of $x_i$ Berland rubles if the $i$-th element from this list is in the set of this company.
The TopChemist company discovered $m$ distinct chemical elements with indices $b_1, b_2, \ldots, b_m$, and it will get an income of $y_j$ Berland rubles for including the $j$-th element from this list to its set.
In other words, the first company can present any subset of elements from $\{a_1, a_2, \ldots, a_n\}$ (possibly empty subset), the second company can present any subset of elements from $\{b_1, b_2, \ldots, b_m\}$ (possibly empty subset). There shouldn't be equal elements in the subsets.
Help the representatives select the sets in such a way that no element is presented in both sets and the total income is the maximum possible.
Input Specification:
The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the number of elements discovered by ChemForces.
The $i$-th of the next $n$ lines contains two integers $a_i$ and $x_i$ ($1 \leq a_i \leq 10^9$, $1 \leq x_i \leq 10^9$) — the index of the $i$-th element and the income of its usage on the exhibition. It is guaranteed that all $a_i$ are distinct.
The next line contains a single integer $m$ ($1 \leq m \leq 10^5$) — the number of chemicals invented by TopChemist.
The $j$-th of the next $m$ lines contains two integers $b_j$ and $y_j$, ($1 \leq b_j \leq 10^9$, $1 \leq y_j \leq 10^9$) — the index of the $j$-th element and the income of its usage on the exhibition. It is guaranteed that all $b_j$ are distinct.
Output Specification:
Print the maximum total income you can obtain by choosing the sets for both companies in such a way that no element is presented in both sets.
Demo Input:
['3\n1 2\n7 2\n3 10\n4\n1 4\n2 4\n3 4\n4 4\n', '1\n1000000000 239\n3\n14 15\n92 65\n35 89\n']
Demo Output:
['24\n', '408\n']
Note:
In the first example ChemForces can choose the set ($3, 7$), while TopChemist can choose ($1, 2, 4$). This way the total income is $(10 + 2) + (4 + 4 + 4) = 24$.
In the second example ChemForces can choose the only element $10^9$, while TopChemist can choose ($14, 92, 35$). This way the total income is $(239) + (15 + 65 + 89) = 408$.
|
```python
n = int(input())
elements = {}
elements = dict(elements)
for i in range(n):
a, b = map(int, input().split())
elements[a] = b
m = int(input())
for i in range(m):
a, b = map(int, input().split())
if elements.get(a):
elements[a] = max(elements[a], b)
else:
elements[a] = b
print(sum(elements.values()))
```
| 3
|
|
975
|
C
|
Valhalla Siege
|
PROGRAMMING
| 1,400
|
[
"binary search"
] | null | null |
Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.
Ivar has $n$ warriors, he places them on a straight line in front of the main gate, in a way that the $i$-th warrior stands right after $(i-1)$-th warrior. The first warrior leads the attack.
Each attacker can take up to $a_i$ arrows before he falls to the ground, where $a_i$ is the $i$-th warrior's strength.
Lagertha orders her warriors to shoot $k_i$ arrows during the $i$-th minute, the arrows one by one hit the first still standing warrior. After all Ivar's warriors fall and all the currently flying arrows fly by, Thor smashes his hammer and all Ivar's warriors get their previous strengths back and stand up to fight again. In other words, if all warriors die in minute $t$, they will all be standing to fight at the end of minute $t$.
The battle will last for $q$ minutes, after each minute you should tell Ivar what is the number of his standing warriors.
|
The first line contains two integers $n$ and $q$ ($1 \le n, q \leq 200\,000$) — the number of warriors and the number of minutes in the battle.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) that represent the warriors' strengths.
The third line contains $q$ integers $k_1, k_2, \ldots, k_q$ ($1 \leq k_i \leq 10^{14}$), the $i$-th of them represents Lagertha's order at the $i$-th minute: $k_i$ arrows will attack the warriors.
|
Output $q$ lines, the $i$-th of them is the number of standing warriors after the $i$-th minute.
|
[
"5 5\n1 2 1 2 1\n3 10 1 1 1\n",
"4 4\n1 2 3 4\n9 1 10 6\n"
] |
[
"3\n5\n4\n4\n3\n",
"1\n4\n4\n1\n"
] |
In the first example:
- after the 1-st minute, the 1-st and 2-nd warriors die. - after the 2-nd minute all warriors die (and all arrows left over are wasted), then they will be revived thus answer is 5 — all warriors are alive. - after the 3-rd minute, the 1-st warrior dies. - after the 4-th minute, the 2-nd warrior takes a hit and his strength decreases by 1. - after the 5-th minute, the 2-nd warrior dies.
| 1,500
|
[
{
"input": "5 5\n1 2 1 2 1\n3 10 1 1 1",
"output": "3\n5\n4\n4\n3"
},
{
"input": "4 4\n1 2 3 4\n9 1 10 6",
"output": "1\n4\n4\n1"
},
{
"input": "10 3\n1 1 1 1 1 1 1 1 1 1\n10 10 5",
"output": "10\n10\n5"
},
{
"input": "1 1\n56563128\n897699770",
"output": "1"
},
{
"input": "100 55\n1 2 4 4 3 5 5 2 3 4 2 1 1 2 3 5 1 5 4 2 5 4 4 3 3 5 3 4 4 5 5 2 3 3 4 4 3 4 5 5 5 5 3 5 1 2 4 3 4 5 3 3 2 1 4 5 3 4 4 1 5 1 5 2 2 1 4 5 3 3 1 4 2 5 4 5 3 2 5 5 2 3 2 3 2 2 3 4 4 4 1 4 2 4 5 3 1 3 3 1\n5 2 1 4 3 4 3 1 4 4 1 2 3 2 1 5 5 4 5 4 2 5 2 1 5 1 4 4 3 5 4 5 1 4 4 1 5 3 1 5 2 4 1 3 2 5 4 5 4 3 4 2 2 4 3",
"output": "98\n97\n97\n96\n95\n94\n94\n94\n92\n91\n91\n90\n87\n86\n86\n85\n83\n82\n80\n80\n79\n78\n77\n77\n75\n75\n74\n73\n72\n71\n70\n69\n69\n67\n66\n66\n65\n64\n63\n62\n62\n61\n61\n60\n60\n59\n58\n57\n54\n54\n52\n52\n51\n51\n50"
}
] | 1,662,576,439
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 3
| 218
| 19,353,600
|
n, q = map(int, input().split())
a = [int(i) for i in input().split()]
k = [int(i) for i in input().split()]
pref, p = [0] * n, [0] * n
pref[0], p[0] = a[0], a[0]
for i in range(1, n):
pref[i], p[i] = pref[i - 1] + a[i], p[i - 1] + a[i]
ind, fl = -1, False
for i in range(q):
x = k[i]
l, r = ind, n - 1
while r - l > 1:
m = (r - l) // 2 + l
if fl and en != m:
el = pref[m] - p[ind]
else:
el = pref[m]
if el >= x:
r = m
else:
l = m
if r != 0 and i != 0:
pref[r] = max(pref[r] - (x + p[r - 1]), 0)
else:
pref[r] = max(pref[r] - x, 0)
if r == n - 1 and pref[r] <= 0:
print(n)
pref = p.copy()
ind, fl, en = -1, False, -1
else:
print(n - r - 1 + (pref[r] > 0))
ind, fl, en = r - (pref[r] > 0), True, r
|
Title: Valhalla Siege
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.
Ivar has $n$ warriors, he places them on a straight line in front of the main gate, in a way that the $i$-th warrior stands right after $(i-1)$-th warrior. The first warrior leads the attack.
Each attacker can take up to $a_i$ arrows before he falls to the ground, where $a_i$ is the $i$-th warrior's strength.
Lagertha orders her warriors to shoot $k_i$ arrows during the $i$-th minute, the arrows one by one hit the first still standing warrior. After all Ivar's warriors fall and all the currently flying arrows fly by, Thor smashes his hammer and all Ivar's warriors get their previous strengths back and stand up to fight again. In other words, if all warriors die in minute $t$, they will all be standing to fight at the end of minute $t$.
The battle will last for $q$ minutes, after each minute you should tell Ivar what is the number of his standing warriors.
Input Specification:
The first line contains two integers $n$ and $q$ ($1 \le n, q \leq 200\,000$) — the number of warriors and the number of minutes in the battle.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) that represent the warriors' strengths.
The third line contains $q$ integers $k_1, k_2, \ldots, k_q$ ($1 \leq k_i \leq 10^{14}$), the $i$-th of them represents Lagertha's order at the $i$-th minute: $k_i$ arrows will attack the warriors.
Output Specification:
Output $q$ lines, the $i$-th of them is the number of standing warriors after the $i$-th minute.
Demo Input:
['5 5\n1 2 1 2 1\n3 10 1 1 1\n', '4 4\n1 2 3 4\n9 1 10 6\n']
Demo Output:
['3\n5\n4\n4\n3\n', '1\n4\n4\n1\n']
Note:
In the first example:
- after the 1-st minute, the 1-st and 2-nd warriors die. - after the 2-nd minute all warriors die (and all arrows left over are wasted), then they will be revived thus answer is 5 — all warriors are alive. - after the 3-rd minute, the 1-st warrior dies. - after the 4-th minute, the 2-nd warrior takes a hit and his strength decreases by 1. - after the 5-th minute, the 2-nd warrior dies.
|
```python
n, q = map(int, input().split())
a = [int(i) for i in input().split()]
k = [int(i) for i in input().split()]
pref, p = [0] * n, [0] * n
pref[0], p[0] = a[0], a[0]
for i in range(1, n):
pref[i], p[i] = pref[i - 1] + a[i], p[i - 1] + a[i]
ind, fl = -1, False
for i in range(q):
x = k[i]
l, r = ind, n - 1
while r - l > 1:
m = (r - l) // 2 + l
if fl and en != m:
el = pref[m] - p[ind]
else:
el = pref[m]
if el >= x:
r = m
else:
l = m
if r != 0 and i != 0:
pref[r] = max(pref[r] - (x + p[r - 1]), 0)
else:
pref[r] = max(pref[r] - x, 0)
if r == n - 1 and pref[r] <= 0:
print(n)
pref = p.copy()
ind, fl, en = -1, False, -1
else:
print(n - r - 1 + (pref[r] > 0))
ind, fl, en = r - (pref[r] > 0), True, r
```
| 0
|
|
595
|
A
|
Vitaly and Night
|
PROGRAMMING
| 800
|
[
"constructive algorithms",
"implementation"
] | null | null |
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats numbered from 1 to *m*, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·*m* from left to right, then the *j*-th flat of the *i*-th floor has windows 2·*j*<=-<=1 and 2·*j* in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.
Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping.
|
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of floors in the house and the number of flats on each floor respectively.
Next *n* lines describe the floors from top to bottom and contain 2·*m* characters each. If the *i*-th window of the given floor has lights on, then the *i*-th character of this line is '1', otherwise it is '0'.
|
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
|
[
"2 2\n0 0 0 1\n1 0 1 1\n",
"1 3\n1 1 0 1 0 0\n"
] |
[
"3\n",
"2\n"
] |
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off.
| 500
|
[
{
"input": "2 2\n0 0 0 1\n1 0 1 1",
"output": "3"
},
{
"input": "1 3\n1 1 0 1 0 0",
"output": "2"
},
{
"input": "3 3\n1 1 1 1 1 1\n1 1 0 1 1 0\n1 0 0 0 1 1",
"output": "8"
},
{
"input": "1 5\n1 0 1 1 1 0 1 1 1 1",
"output": "5"
},
{
"input": "1 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "99"
},
{
"input": "1 100\n0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "6"
},
{
"input": "1 100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "100 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n0 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n0 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "100"
},
{
"input": "100 1\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n1 0\n0 0\n0 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n1 0",
"output": "8"
},
{
"input": "100 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "1 1\n0 0",
"output": "0"
},
{
"input": "1 1\n0 1",
"output": "1"
},
{
"input": "1 1\n1 0",
"output": "1"
},
{
"input": "1 1\n1 1",
"output": "1"
}
] | 1,586,794,595
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 36
| 109
| 102,400
|
"""
https://codeforces.com/problemset/problem/595/A
"""
args = [int(x) for x in input().split(" ")]
n = args[0]
m = args[1]
lightsOn = 0
for i in range(n):
floor = [int(x) for x in input().split(" ")]
for j in range(m):
if floor[2*j] == 1 or floor[2*j+1] == 1:
lightsOn += 1
print(lightsOn)
|
Title: Vitaly and Night
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats numbered from 1 to *m*, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·*m* from left to right, then the *j*-th flat of the *i*-th floor has windows 2·*j*<=-<=1 and 2·*j* in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.
Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping.
Input Specification:
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of floors in the house and the number of flats on each floor respectively.
Next *n* lines describe the floors from top to bottom and contain 2·*m* characters each. If the *i*-th window of the given floor has lights on, then the *i*-th character of this line is '1', otherwise it is '0'.
Output Specification:
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
Demo Input:
['2 2\n0 0 0 1\n1 0 1 1\n', '1 3\n1 1 0 1 0 0\n']
Demo Output:
['3\n', '2\n']
Note:
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off.
|
```python
"""
https://codeforces.com/problemset/problem/595/A
"""
args = [int(x) for x in input().split(" ")]
n = args[0]
m = args[1]
lightsOn = 0
for i in range(n):
floor = [int(x) for x in input().split(" ")]
for j in range(m):
if floor[2*j] == 1 or floor[2*j+1] == 1:
lightsOn += 1
print(lightsOn)
```
| 3
|
|
315
|
B
|
Sereja and Array
|
PROGRAMMING
| 1,200
|
[
"implementation"
] | null | null |
Sereja has got an array, consisting of *n* integers, *a*1,<=*a*2,<=...,<=*a**n*. Sereja is an active boy, so he is now going to complete *m* operations. Each operation will have one of the three forms:
1. Make *v**i*-th array element equal to *x**i*. In other words, perform the assignment *a**v**i*<==<=*x**i*. 1. Increase each array element by *y**i*. In other words, perform *n* assignments *a**i*<==<=*a**i*<=+<=*y**i* (1<=≤<=*i*<=≤<=*n*). 1. Take a piece of paper and write out the *q**i*-th array element. That is, the element *a**q**i*.
Help Sereja, complete all his operations.
|
The first line contains integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the original array.
Next *m* lines describe operations, the *i*-th line describes the *i*-th operation. The first number in the *i*-th line is integer *t**i* (1<=≤<=*t**i*<=≤<=3) that represents the operation type. If *t**i*<==<=1, then it is followed by two integers *v**i* and *x**i*, (1<=≤<=*v**i*<=≤<=*n*,<=1<=≤<=*x**i*<=≤<=109). If *t**i*<==<=2, then it is followed by integer *y**i* (1<=≤<=*y**i*<=≤<=104). And if *t**i*<==<=3, then it is followed by integer *q**i* (1<=≤<=*q**i*<=≤<=*n*).
|
For each third type operation print value *a**q**i*. Print the values in the order, in which the corresponding queries follow in the input.
|
[
"10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9\n"
] |
[
"2\n9\n11\n20\n30\n40\n39\n"
] |
none
| 1,000
|
[
{
"input": "10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9",
"output": "2\n9\n11\n20\n30\n40\n39"
},
{
"input": "1 3\n1\n1 1 2\n2 1\n3 1",
"output": "3"
},
{
"input": "1 1\n1\n3 1",
"output": "1"
},
{
"input": "6 6\n202714501 613423725 367325359 862808465 182588146 745008828\n2 492\n2 1943\n1 3 173984392\n1 3 9356383\n3 4\n1 5 472683539",
"output": "862810900"
},
{
"input": "6 5\n545129895 918519812 2334334 565540665 484519712 904102869\n3 3\n1 2 641196860\n2 779\n2 3036\n3 1",
"output": "2334334\n545133710"
},
{
"input": "5 5\n286163265 724763447 761775891 215352371 491215007\n1 4 780579549\n1 2 638546757\n3 4\n1 3 38072627\n2 6119",
"output": "780579549"
},
{
"input": "4 4\n529316834 995684640 949078705 317773978\n3 3\n3 1\n2 6271\n1 1 856879574",
"output": "949078705\n529316834"
},
{
"input": "5 4\n293170637 715384768 756975575 129004053 875201151\n1 3 695181967\n3 3\n2 2288\n1 5 332270946",
"output": "695181967"
}
] | 1,662,578,686
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 34
| 218
| 18,534,400
|
from collections import deque,Counter
from math import *
import sys
import random
from bisect import *
from functools import reduce
from sys import stdin
import copy
input = lambda: sys.stdin.readline().rstrip()
n,m=map(int,input().split())
arr=list(map(int,input().split()))
val = 0
for _ in range(m):
opt=list(map(int,input().split()))
if opt[0]==3:
print(arr[opt[1]-1]+val)
elif opt[0]==1:
arr[opt[1]-1]=opt[2]-val
else:
val+=opt[1]
|
Title: Sereja and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has got an array, consisting of *n* integers, *a*1,<=*a*2,<=...,<=*a**n*. Sereja is an active boy, so he is now going to complete *m* operations. Each operation will have one of the three forms:
1. Make *v**i*-th array element equal to *x**i*. In other words, perform the assignment *a**v**i*<==<=*x**i*. 1. Increase each array element by *y**i*. In other words, perform *n* assignments *a**i*<==<=*a**i*<=+<=*y**i* (1<=≤<=*i*<=≤<=*n*). 1. Take a piece of paper and write out the *q**i*-th array element. That is, the element *a**q**i*.
Help Sereja, complete all his operations.
Input Specification:
The first line contains integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the original array.
Next *m* lines describe operations, the *i*-th line describes the *i*-th operation. The first number in the *i*-th line is integer *t**i* (1<=≤<=*t**i*<=≤<=3) that represents the operation type. If *t**i*<==<=1, then it is followed by two integers *v**i* and *x**i*, (1<=≤<=*v**i*<=≤<=*n*,<=1<=≤<=*x**i*<=≤<=109). If *t**i*<==<=2, then it is followed by integer *y**i* (1<=≤<=*y**i*<=≤<=104). And if *t**i*<==<=3, then it is followed by integer *q**i* (1<=≤<=*q**i*<=≤<=*n*).
Output Specification:
For each third type operation print value *a**q**i*. Print the values in the order, in which the corresponding queries follow in the input.
Demo Input:
['10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9\n']
Demo Output:
['2\n9\n11\n20\n30\n40\n39\n']
Note:
none
|
```python
from collections import deque,Counter
from math import *
import sys
import random
from bisect import *
from functools import reduce
from sys import stdin
import copy
input = lambda: sys.stdin.readline().rstrip()
n,m=map(int,input().split())
arr=list(map(int,input().split()))
val = 0
for _ in range(m):
opt=list(map(int,input().split()))
if opt[0]==3:
print(arr[opt[1]-1]+val)
elif opt[0]==1:
arr[opt[1]-1]=opt[2]-val
else:
val+=opt[1]
```
| 3
|
|
25
|
A
|
IQ test
|
PROGRAMMING
| 1,300
|
[
"brute force"
] |
A. IQ test
|
2
|
256
|
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
|
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
|
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
|
[
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] |
[
"3\n",
"2\n"
] |
none
| 0
|
[
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output": "2"
},
{
"input": "4\n75 13 94 77",
"output": "3"
},
{
"input": "4\n97 8 27 3",
"output": "2"
},
{
"input": "10\n95 51 12 91 85 3 1 31 25 7",
"output": "3"
},
{
"input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46",
"output": "4"
},
{
"input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36",
"output": "26"
},
{
"input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83",
"output": "48"
},
{
"input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25",
"output": "1"
},
{
"input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46",
"output": "25"
},
{
"input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73",
"output": "13"
},
{
"input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76",
"output": "99"
},
{
"input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14",
"output": "1"
},
{
"input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22",
"output": "93"
},
{
"input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23",
"output": "1"
},
{
"input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98",
"output": "1"
},
{
"input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94",
"output": "93"
},
{
"input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29",
"output": "32"
},
{
"input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47",
"output": "26"
},
{
"input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72",
"output": "56"
},
{
"input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86",
"output": "97"
},
{
"input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42",
"output": "79"
},
{
"input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52",
"output": "25"
},
{
"input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86",
"output": "78"
},
{
"input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68",
"output": "70"
},
{
"input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81",
"output": "39"
},
{
"input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83",
"output": "88"
},
{
"input": "3\n100 100 1",
"output": "3"
}
] | 1,592,676,144
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 32
| 218
| 307,200
|
#A.IQ Test
n = int(input())
a = list(map(int,input().split()))
t = 0
if a[0]%2==0:
t += 1
else:
t -= 1
if a[1]%2==0:
t += 1
else:
t -= 1
if a[2]%2==0:
t += 1
else:
t -= 1
if t>=1:
#all other numbers are even
for i in range(n):
if a[i]%2!=0:
print(i+1)
break
else:
#all others are odd
for i in range(n):
if a[i]%2==0:
print(i+1)
break
|
Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output Specification:
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
Demo Input:
['5\n2 4 7 8 10\n', '4\n1 2 1 1\n']
Demo Output:
['3\n', '2\n']
Note:
none
|
```python
#A.IQ Test
n = int(input())
a = list(map(int,input().split()))
t = 0
if a[0]%2==0:
t += 1
else:
t -= 1
if a[1]%2==0:
t += 1
else:
t -= 1
if a[2]%2==0:
t += 1
else:
t -= 1
if t>=1:
#all other numbers are even
for i in range(n):
if a[i]%2!=0:
print(i+1)
break
else:
#all others are odd
for i in range(n):
if a[i]%2==0:
print(i+1)
break
```
| 3.944928
|
702
|
A
|
Maximum Increase
|
PROGRAMMING
| 800
|
[
"dp",
"greedy",
"implementation"
] | null | null |
You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
|
The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
|
Print the maximum length of an increasing subarray of the given array.
|
[
"5\n1 7 2 11 15\n",
"6\n100 100 100 100 100 100\n",
"3\n1 2 3\n"
] |
[
"3\n",
"1\n",
"3\n"
] |
none
| 0
|
[
{
"input": "5\n1 7 2 11 15",
"output": "3"
},
{
"input": "6\n100 100 100 100 100 100",
"output": "1"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 799843967 446173607 796619138 402690754",
"output": "3"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n1 2 3 3 4",
"output": "3"
},
{
"input": "4\n1 2 2 3",
"output": "2"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "3\n1 2 1",
"output": "2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 1 2",
"output": "2"
},
{
"input": "11\n1 2 3 1 2 3 2 1 2 3 4",
"output": "4"
},
{
"input": "9\n1 2 3 4 5 6 7 8 9",
"output": "9"
},
{
"input": "9\n1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "3\n3 2 1",
"output": "1"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "7"
},
{
"input": "1\n1234394",
"output": "1"
}
] | 1,698,250,390
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 32
| 93
| 12,800,000
|
n = int(input())
numArray = list(map(int, input().split()))
maxLenght = 1
currentLenght = 1
previousNum = numArray[0]
for i in range(1, n):
currentNum = numArray[i]
if currentNum > previousNum:
currentLenght += 1
else:
currentLenght = 1
maxLenght = max(maxLenght, currentLenght)
previousNum = currentNum
print(maxLenght)
|
Title: Maximum Increase
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Input Specification:
The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Output Specification:
Print the maximum length of an increasing subarray of the given array.
Demo Input:
['5\n1 7 2 11 15\n', '6\n100 100 100 100 100 100\n', '3\n1 2 3\n']
Demo Output:
['3\n', '1\n', '3\n']
Note:
none
|
```python
n = int(input())
numArray = list(map(int, input().split()))
maxLenght = 1
currentLenght = 1
previousNum = numArray[0]
for i in range(1, n):
currentNum = numArray[i]
if currentNum > previousNum:
currentLenght += 1
else:
currentLenght = 1
maxLenght = max(maxLenght, currentLenght)
previousNum = currentNum
print(maxLenght)
```
| 3
|
|
931
|
C
|
Laboratory Work
|
PROGRAMMING
| 1,700
|
[
"implementation",
"math"
] | null | null |
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value *n* times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: *x*1, *x*2, ..., *x**n*. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values *y*1, *y*2, ..., *y**n* in her work, that the following conditions are met:
- the average value of *x*1,<=*x*2,<=...,<=*x**n* is equal to the average value of *y*1,<=*y*2,<=...,<=*y**n*;- all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;- the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
|
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=100<=000<=≤<=*x**i*<=≤<=100<=000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values *x*1,<=*x*2,<=...,<=*x**n* does not exceed 2.
|
In the first line print the minimum possible number of equal measurements.
In the second line print *n* integers *y*1,<=*y*2,<=...,<=*y**n* — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
|
[
"6\n-1 1 1 0 0 -1\n",
"3\n100 100 101\n",
"7\n-10 -9 -10 -8 -10 -9 -9\n"
] |
[
"2\n0 0 0 0 0 0 \n",
"3\n101 100 100 \n",
"5\n-10 -10 -9 -9 -9 -9 -9 \n"
] |
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is 5.
| 1,750
|
[
{
"input": "6\n-1 1 1 0 0 -1",
"output": "2\n0 0 0 0 0 0 "
},
{
"input": "3\n100 100 101",
"output": "3\n101 100 100 "
},
{
"input": "7\n-10 -9 -10 -8 -10 -9 -9",
"output": "5\n-10 -10 -9 -9 -9 -9 -9 "
},
{
"input": "60\n-8536 -8536 -8536 -8535 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8535 -8536 -8535 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8535 -8536 -8536 -8535 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8535 -8536 -8536 -8536 -8535 -8535 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8535",
"output": "60\n-8535 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8535 -8535 -8536 -8536 -8536 -8535 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8535 -8536 -8536 -8535 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8535 -8536 -8535 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8535 -8536 -8536 -8536 "
},
{
"input": "9\n-71360 -71359 -71360 -71360 -71359 -71359 -71359 -71359 -71359",
"output": "9\n-71359 -71359 -71359 -71359 -71359 -71360 -71360 -71359 -71360 "
},
{
"input": "10\n100 100 100 100 100 100 100 100 100 100",
"output": "10\n100 100 100 100 100 100 100 100 100 100 "
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 "
},
{
"input": "5\n-399 -399 -400 -399 -400",
"output": "5\n-400 -399 -400 -399 -399 "
},
{
"input": "10\n1001 1000 1000 1001 1000 1000 1001 1001 1000 1001",
"output": "10\n1001 1000 1001 1001 1000 1000 1001 1000 1000 1001 "
},
{
"input": "20\n-100000 -99999 -100000 -99999 -99999 -100000 -99999 -100000 -99999 -100000 -99999 -99999 -99999 -100000 -100000 -99999 -100000 -100000 -100000 -99999",
"output": "20\n-99999 -100000 -100000 -100000 -99999 -100000 -100000 -99999 -99999 -99999 -100000 -99999 -100000 -99999 -100000 -99999 -99999 -100000 -99999 -100000 "
},
{
"input": "50\n99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 100000 99999 99999 99999 99999 99999 100000 99999 99999 99999 100000 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 100000 99999 99999 99999 100000 99999 99999 99999",
"output": "50\n99999 99999 99999 100000 99999 99999 99999 100000 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 100000 99999 99999 99999 100000 99999 99999 99999 99999 99999 100000 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 "
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "1\n-100000",
"output": "1\n-100000 "
},
{
"input": "1\n-1",
"output": "1\n-1 "
},
{
"input": "1\n0",
"output": "1\n0 "
},
{
"input": "1\n1",
"output": "1\n1 "
},
{
"input": "1\n100000",
"output": "1\n100000 "
},
{
"input": "5\n2 2 1 1 2",
"output": "5\n2 1 1 2 2 "
},
{
"input": "10\n0 -1 0 1 1 1 1 -1 0 0",
"output": "6\n0 0 0 0 0 0 0 0 1 1 "
},
{
"input": "20\n-4344 -4342 -4344 -4342 -4343 -4343 -4344 -4344 -4342 -4343 -4344 -4343 -4344 -4344 -4344 -4342 -4344 -4343 -4342 -4344",
"output": "10\n-4344 -4344 -4344 -4344 -4344 -4343 -4343 -4343 -4343 -4343 -4343 -4343 -4343 -4343 -4343 -4343 -4343 -4343 -4343 -4343 "
},
{
"input": "40\n113 113 112 112 112 112 112 112 112 112 112 113 113 112 113 112 113 112 112 112 111 112 112 113 112 112 112 112 112 112 112 112 113 112 113 112 112 113 112 113",
"output": "12\n111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 113 113 113 113 113 113 113 113 113 113 113 113 113 113 113 113 113 113 113 113 113 113 113 113 113 "
},
{
"input": "5\n-94523 -94523 -94523 -94524 -94524",
"output": "5\n-94524 -94524 -94523 -94523 -94523 "
},
{
"input": "10\n-35822 -35823 -35823 -35823 -35821 -35823 -35823 -35821 -35822 -35821",
"output": "4\n-35823 -35823 -35822 -35822 -35822 -35822 -35822 -35822 -35822 -35822 "
},
{
"input": "11\n-50353 -50353 -50353 -50353 -50353 -50352 -50353 -50353 -50353 -50353 -50352",
"output": "11\n-50352 -50353 -50353 -50353 -50353 -50352 -50353 -50353 -50353 -50353 -50353 "
},
{
"input": "20\n46795 46795 46795 46795 46795 46795 46795 46793 46794 46795 46794 46795 46795 46795 46795 46795 46795 46795 46795 46795",
"output": "18\n46794 46794 46794 46794 46795 46795 46795 46795 46795 46795 46795 46795 46795 46795 46795 46795 46795 46795 46795 46795 "
},
{
"input": "40\n72263 72261 72262 72263 72263 72263 72263 72263 72263 72262 72263 72263 72263 72263 72263 72262 72263 72262 72263 72262 72262 72263 72263 72262 72263 72263 72262 72262 72263 72262 72263 72263 72263 72263 72263 72263 72263 72263 72263 72262",
"output": "30\n72261 72261 72261 72261 72261 72261 72262 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 "
},
{
"input": "50\n-46992 -46992 -46992 -46991 -46992 -46991 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46991 -46991 -46991 -46992 -46990 -46991 -46991 -46991 -46991 -46992 -46992 -46991 -46992 -46992 -46992 -46990 -46992 -46991 -46991 -46992 -46992 -46992 -46991 -46991 -46991 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992",
"output": "36\n-46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46991 -46990 -46990 -46990 -46990 -46990 -46990 -46990 -46990 -46990 "
},
{
"input": "60\n-86077 -86075 -86076 -86076 -86077 -86077 -86075 -86075 -86075 -86077 -86075 -86076 -86075 -86075 -86075 -86076 -86075 -86076 -86075 -86075 -86076 -86076 -86076 -86075 -86075 -86075 -86075 -86077 -86075 -86076 -86075 -86075 -86075 -86076 -86075 -86076 -86077 -86075 -86075 -86075 -86076 -86075 -86076 -86075 -86076 -86076 -86075 -86076 -86076 -86075 -86075 -86075 -86077 -86076 -86075 -86075 -86075 -86075 -86075 -86075",
"output": "42\n-86077 -86077 -86077 -86077 -86077 -86077 -86077 -86077 -86077 -86077 -86077 -86077 -86077 -86077 -86077 -86077 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 "
},
{
"input": "70\n-87 -86 -88 -86 -87 -86 -88 -88 -87 -86 -86 -88 -86 -86 -88 -87 -87 -87 -86 -87 -87 -87 -88 -88 -88 -87 -88 -87 -88 -87 -88 -86 -86 -86 -88 -86 -87 -87 -86 -86 -88 -86 -88 -87 -88 -87 -87 -86 -88 -87 -86 -88 -87 -86 -87 -87 -86 -88 -87 -86 -87 -88 -87 -88 -86 -87 -88 -88 -87 -87",
"output": "28\n-88 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 "
},
{
"input": "2\n0 2",
"output": "0\n1 1 "
},
{
"input": "4\n1 1 3 3",
"output": "0\n2 2 2 2 "
},
{
"input": "6\n1 1 1 3 3 3",
"output": "0\n2 2 2 2 2 2 "
},
{
"input": "2\n1 3",
"output": "0\n2 2 "
},
{
"input": "7\n0 1 1 1 1 1 2",
"output": "3\n0 0 0 1 2 2 2 "
},
{
"input": "6\n1 1 1 -1 -1 -1",
"output": "0\n0 0 0 0 0 0 "
},
{
"input": "3\n1 1 3",
"output": "1\n1 2 2 "
},
{
"input": "2\n2 0",
"output": "0\n1 1 "
},
{
"input": "10\n1 3 3 3 3 3 3 3 3 3",
"output": "8\n2 2 3 3 3 3 3 3 3 3 "
},
{
"input": "7\n1 3 3 3 3 3 3",
"output": "5\n2 2 3 3 3 3 3 "
},
{
"input": "7\n1 2 2 2 2 2 3",
"output": "3\n1 1 1 2 3 3 3 "
},
{
"input": "5\n-8 -8 -8 -10 -10",
"output": "1\n-9 -9 -9 -9 -8 "
},
{
"input": "3\n1 2 3",
"output": "1\n2 2 2 "
},
{
"input": "4\n2 2 4 4",
"output": "0\n3 3 3 3 "
},
{
"input": "4\n1 1 -1 -1",
"output": "0\n0 0 0 0 "
}
] | 1,520,182,380
| 4,680
|
Python 3
|
WRONG_ANSWER
|
PRETESTS
| 10
| 295
| 12,697,600
|
n=int(input())
l=[int(x) for x in input().split()]
if len(set(l))<3:
print(n)
print(*l)
else:
l.sort()
f=[0]*3
s=list(set(l))
s.sort()
for i in range(3):
f[i]=l.count(s[i])
ans=f[1]+max(f[0],f[2])-min(f[0],f[2])
f[1]+=(min(f[0],f[2])*2)
f[0],f[2]=f[0]-min(f[0],f[2]),f[2]-min(f[0],f[2])
print(ans)
for i in range(3):
print((str(s[i])+" ")*f[i],end="")
|
Title: Laboratory Work
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value *n* times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: *x*1, *x*2, ..., *x**n*. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values *y*1, *y*2, ..., *y**n* in her work, that the following conditions are met:
- the average value of *x*1,<=*x*2,<=...,<=*x**n* is equal to the average value of *y*1,<=*y*2,<=...,<=*y**n*;- all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;- the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=100<=000<=≤<=*x**i*<=≤<=100<=000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values *x*1,<=*x*2,<=...,<=*x**n* does not exceed 2.
Output Specification:
In the first line print the minimum possible number of equal measurements.
In the second line print *n* integers *y*1,<=*y*2,<=...,<=*y**n* — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
Demo Input:
['6\n-1 1 1 0 0 -1\n', '3\n100 100 101\n', '7\n-10 -9 -10 -8 -10 -9 -9\n']
Demo Output:
['2\n0 0 0 0 0 0 \n', '3\n101 100 100 \n', '5\n-10 -10 -9 -9 -9 -9 -9 \n']
Note:
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is 5.
|
```python
n=int(input())
l=[int(x) for x in input().split()]
if len(set(l))<3:
print(n)
print(*l)
else:
l.sort()
f=[0]*3
s=list(set(l))
s.sort()
for i in range(3):
f[i]=l.count(s[i])
ans=f[1]+max(f[0],f[2])-min(f[0],f[2])
f[1]+=(min(f[0],f[2])*2)
f[0],f[2]=f[0]-min(f[0],f[2]),f[2]-min(f[0],f[2])
print(ans)
for i in range(3):
print((str(s[i])+" ")*f[i],end="")
```
| 0
|
|
334
|
A
|
Candy Bags
|
PROGRAMMING
| 1,000
|
[
"implementation"
] | null | null |
Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies.
Help him give *n* bags of candies to each brother so that all brothers got the same number of candies.
|
The single line contains a single integer *n* (*n* is even, 2<=≤<=*n*<=≤<=100) — the number of Gerald's brothers.
|
Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers — the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the lines in any order.
It is guaranteed that the solution exists at the given limits.
|
[
"2\n"
] |
[
"1 4\n2 3\n"
] |
The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother.
| 500
|
[
{
"input": "2",
"output": "1 4\n2 3"
},
{
"input": "4",
"output": "1 16 2 15\n3 14 4 13\n5 12 6 11\n7 10 8 9"
},
{
"input": "6",
"output": "1 36 2 35 3 34\n4 33 5 32 6 31\n7 30 8 29 9 28\n10 27 11 26 12 25\n13 24 14 23 15 22\n16 21 17 20 18 19"
},
{
"input": "8",
"output": "1 64 2 63 3 62 4 61\n5 60 6 59 7 58 8 57\n9 56 10 55 11 54 12 53\n13 52 14 51 15 50 16 49\n17 48 18 47 19 46 20 45\n21 44 22 43 23 42 24 41\n25 40 26 39 27 38 28 37\n29 36 30 35 31 34 32 33"
},
{
"input": "10",
"output": "1 100 2 99 3 98 4 97 5 96\n6 95 7 94 8 93 9 92 10 91\n11 90 12 89 13 88 14 87 15 86\n16 85 17 84 18 83 19 82 20 81\n21 80 22 79 23 78 24 77 25 76\n26 75 27 74 28 73 29 72 30 71\n31 70 32 69 33 68 34 67 35 66\n36 65 37 64 38 63 39 62 40 61\n41 60 42 59 43 58 44 57 45 56\n46 55 47 54 48 53 49 52 50 51"
},
{
"input": "100",
"output": "1 10000 2 9999 3 9998 4 9997 5 9996 6 9995 7 9994 8 9993 9 9992 10 9991 11 9990 12 9989 13 9988 14 9987 15 9986 16 9985 17 9984 18 9983 19 9982 20 9981 21 9980 22 9979 23 9978 24 9977 25 9976 26 9975 27 9974 28 9973 29 9972 30 9971 31 9970 32 9969 33 9968 34 9967 35 9966 36 9965 37 9964 38 9963 39 9962 40 9961 41 9960 42 9959 43 9958 44 9957 45 9956 46 9955 47 9954 48 9953 49 9952 50 9951\n51 9950 52 9949 53 9948 54 9947 55 9946 56 9945 57 9944 58 9943 59 9942 60 9941 61 9940 62 9939 63 9938 64 9937 65 993..."
},
{
"input": "62",
"output": "1 3844 2 3843 3 3842 4 3841 5 3840 6 3839 7 3838 8 3837 9 3836 10 3835 11 3834 12 3833 13 3832 14 3831 15 3830 16 3829 17 3828 18 3827 19 3826 20 3825 21 3824 22 3823 23 3822 24 3821 25 3820 26 3819 27 3818 28 3817 29 3816 30 3815 31 3814\n32 3813 33 3812 34 3811 35 3810 36 3809 37 3808 38 3807 39 3806 40 3805 41 3804 42 3803 43 3802 44 3801 45 3800 46 3799 47 3798 48 3797 49 3796 50 3795 51 3794 52 3793 53 3792 54 3791 55 3790 56 3789 57 3788 58 3787 59 3786 60 3785 61 3784 62 3783\n63 3782 64 3781 65 378..."
},
{
"input": "66",
"output": "1 4356 2 4355 3 4354 4 4353 5 4352 6 4351 7 4350 8 4349 9 4348 10 4347 11 4346 12 4345 13 4344 14 4343 15 4342 16 4341 17 4340 18 4339 19 4338 20 4337 21 4336 22 4335 23 4334 24 4333 25 4332 26 4331 27 4330 28 4329 29 4328 30 4327 31 4326 32 4325 33 4324\n34 4323 35 4322 36 4321 37 4320 38 4319 39 4318 40 4317 41 4316 42 4315 43 4314 44 4313 45 4312 46 4311 47 4310 48 4309 49 4308 50 4307 51 4306 52 4305 53 4304 54 4303 55 4302 56 4301 57 4300 58 4299 59 4298 60 4297 61 4296 62 4295 63 4294 64 4293 65 4292..."
},
{
"input": "18",
"output": "1 324 2 323 3 322 4 321 5 320 6 319 7 318 8 317 9 316\n10 315 11 314 12 313 13 312 14 311 15 310 16 309 17 308 18 307\n19 306 20 305 21 304 22 303 23 302 24 301 25 300 26 299 27 298\n28 297 29 296 30 295 31 294 32 293 33 292 34 291 35 290 36 289\n37 288 38 287 39 286 40 285 41 284 42 283 43 282 44 281 45 280\n46 279 47 278 48 277 49 276 50 275 51 274 52 273 53 272 54 271\n55 270 56 269 57 268 58 267 59 266 60 265 61 264 62 263 63 262\n64 261 65 260 66 259 67 258 68 257 69 256 70 255 71 254 72 253\n73 252 7..."
},
{
"input": "68",
"output": "1 4624 2 4623 3 4622 4 4621 5 4620 6 4619 7 4618 8 4617 9 4616 10 4615 11 4614 12 4613 13 4612 14 4611 15 4610 16 4609 17 4608 18 4607 19 4606 20 4605 21 4604 22 4603 23 4602 24 4601 25 4600 26 4599 27 4598 28 4597 29 4596 30 4595 31 4594 32 4593 33 4592 34 4591\n35 4590 36 4589 37 4588 38 4587 39 4586 40 4585 41 4584 42 4583 43 4582 44 4581 45 4580 46 4579 47 4578 48 4577 49 4576 50 4575 51 4574 52 4573 53 4572 54 4571 55 4570 56 4569 57 4568 58 4567 59 4566 60 4565 61 4564 62 4563 63 4562 64 4561 65 4560..."
},
{
"input": "86",
"output": "1 7396 2 7395 3 7394 4 7393 5 7392 6 7391 7 7390 8 7389 9 7388 10 7387 11 7386 12 7385 13 7384 14 7383 15 7382 16 7381 17 7380 18 7379 19 7378 20 7377 21 7376 22 7375 23 7374 24 7373 25 7372 26 7371 27 7370 28 7369 29 7368 30 7367 31 7366 32 7365 33 7364 34 7363 35 7362 36 7361 37 7360 38 7359 39 7358 40 7357 41 7356 42 7355 43 7354\n44 7353 45 7352 46 7351 47 7350 48 7349 49 7348 50 7347 51 7346 52 7345 53 7344 54 7343 55 7342 56 7341 57 7340 58 7339 59 7338 60 7337 61 7336 62 7335 63 7334 64 7333 65 7332..."
},
{
"input": "96",
"output": "1 9216 2 9215 3 9214 4 9213 5 9212 6 9211 7 9210 8 9209 9 9208 10 9207 11 9206 12 9205 13 9204 14 9203 15 9202 16 9201 17 9200 18 9199 19 9198 20 9197 21 9196 22 9195 23 9194 24 9193 25 9192 26 9191 27 9190 28 9189 29 9188 30 9187 31 9186 32 9185 33 9184 34 9183 35 9182 36 9181 37 9180 38 9179 39 9178 40 9177 41 9176 42 9175 43 9174 44 9173 45 9172 46 9171 47 9170 48 9169\n49 9168 50 9167 51 9166 52 9165 53 9164 54 9163 55 9162 56 9161 57 9160 58 9159 59 9158 60 9157 61 9156 62 9155 63 9154 64 9153 65 9152..."
},
{
"input": "12",
"output": "1 144 2 143 3 142 4 141 5 140 6 139\n7 138 8 137 9 136 10 135 11 134 12 133\n13 132 14 131 15 130 16 129 17 128 18 127\n19 126 20 125 21 124 22 123 23 122 24 121\n25 120 26 119 27 118 28 117 29 116 30 115\n31 114 32 113 33 112 34 111 35 110 36 109\n37 108 38 107 39 106 40 105 41 104 42 103\n43 102 44 101 45 100 46 99 47 98 48 97\n49 96 50 95 51 94 52 93 53 92 54 91\n55 90 56 89 57 88 58 87 59 86 60 85\n61 84 62 83 63 82 64 81 65 80 66 79\n67 78 68 77 69 76 70 75 71 74 72 73"
},
{
"input": "88",
"output": "1 7744 2 7743 3 7742 4 7741 5 7740 6 7739 7 7738 8 7737 9 7736 10 7735 11 7734 12 7733 13 7732 14 7731 15 7730 16 7729 17 7728 18 7727 19 7726 20 7725 21 7724 22 7723 23 7722 24 7721 25 7720 26 7719 27 7718 28 7717 29 7716 30 7715 31 7714 32 7713 33 7712 34 7711 35 7710 36 7709 37 7708 38 7707 39 7706 40 7705 41 7704 42 7703 43 7702 44 7701\n45 7700 46 7699 47 7698 48 7697 49 7696 50 7695 51 7694 52 7693 53 7692 54 7691 55 7690 56 7689 57 7688 58 7687 59 7686 60 7685 61 7684 62 7683 63 7682 64 7681 65 7680..."
},
{
"input": "28",
"output": "1 784 2 783 3 782 4 781 5 780 6 779 7 778 8 777 9 776 10 775 11 774 12 773 13 772 14 771\n15 770 16 769 17 768 18 767 19 766 20 765 21 764 22 763 23 762 24 761 25 760 26 759 27 758 28 757\n29 756 30 755 31 754 32 753 33 752 34 751 35 750 36 749 37 748 38 747 39 746 40 745 41 744 42 743\n43 742 44 741 45 740 46 739 47 738 48 737 49 736 50 735 51 734 52 733 53 732 54 731 55 730 56 729\n57 728 58 727 59 726 60 725 61 724 62 723 63 722 64 721 65 720 66 719 67 718 68 717 69 716 70 715\n71 714 72 713 73 712 74 7..."
},
{
"input": "80",
"output": "1 6400 2 6399 3 6398 4 6397 5 6396 6 6395 7 6394 8 6393 9 6392 10 6391 11 6390 12 6389 13 6388 14 6387 15 6386 16 6385 17 6384 18 6383 19 6382 20 6381 21 6380 22 6379 23 6378 24 6377 25 6376 26 6375 27 6374 28 6373 29 6372 30 6371 31 6370 32 6369 33 6368 34 6367 35 6366 36 6365 37 6364 38 6363 39 6362 40 6361\n41 6360 42 6359 43 6358 44 6357 45 6356 46 6355 47 6354 48 6353 49 6352 50 6351 51 6350 52 6349 53 6348 54 6347 55 6346 56 6345 57 6344 58 6343 59 6342 60 6341 61 6340 62 6339 63 6338 64 6337 65 6336..."
},
{
"input": "48",
"output": "1 2304 2 2303 3 2302 4 2301 5 2300 6 2299 7 2298 8 2297 9 2296 10 2295 11 2294 12 2293 13 2292 14 2291 15 2290 16 2289 17 2288 18 2287 19 2286 20 2285 21 2284 22 2283 23 2282 24 2281\n25 2280 26 2279 27 2278 28 2277 29 2276 30 2275 31 2274 32 2273 33 2272 34 2271 35 2270 36 2269 37 2268 38 2267 39 2266 40 2265 41 2264 42 2263 43 2262 44 2261 45 2260 46 2259 47 2258 48 2257\n49 2256 50 2255 51 2254 52 2253 53 2252 54 2251 55 2250 56 2249 57 2248 58 2247 59 2246 60 2245 61 2244 62 2243 63 2242 64 2241 65 224..."
},
{
"input": "54",
"output": "1 2916 2 2915 3 2914 4 2913 5 2912 6 2911 7 2910 8 2909 9 2908 10 2907 11 2906 12 2905 13 2904 14 2903 15 2902 16 2901 17 2900 18 2899 19 2898 20 2897 21 2896 22 2895 23 2894 24 2893 25 2892 26 2891 27 2890\n28 2889 29 2888 30 2887 31 2886 32 2885 33 2884 34 2883 35 2882 36 2881 37 2880 38 2879 39 2878 40 2877 41 2876 42 2875 43 2874 44 2873 45 2872 46 2871 47 2870 48 2869 49 2868 50 2867 51 2866 52 2865 53 2864 54 2863\n55 2862 56 2861 57 2860 58 2859 59 2858 60 2857 61 2856 62 2855 63 2854 64 2853 65 285..."
},
{
"input": "58",
"output": "1 3364 2 3363 3 3362 4 3361 5 3360 6 3359 7 3358 8 3357 9 3356 10 3355 11 3354 12 3353 13 3352 14 3351 15 3350 16 3349 17 3348 18 3347 19 3346 20 3345 21 3344 22 3343 23 3342 24 3341 25 3340 26 3339 27 3338 28 3337 29 3336\n30 3335 31 3334 32 3333 33 3332 34 3331 35 3330 36 3329 37 3328 38 3327 39 3326 40 3325 41 3324 42 3323 43 3322 44 3321 45 3320 46 3319 47 3318 48 3317 49 3316 50 3315 51 3314 52 3313 53 3312 54 3311 55 3310 56 3309 57 3308 58 3307\n59 3306 60 3305 61 3304 62 3303 63 3302 64 3301 65 330..."
},
{
"input": "64",
"output": "1 4096 2 4095 3 4094 4 4093 5 4092 6 4091 7 4090 8 4089 9 4088 10 4087 11 4086 12 4085 13 4084 14 4083 15 4082 16 4081 17 4080 18 4079 19 4078 20 4077 21 4076 22 4075 23 4074 24 4073 25 4072 26 4071 27 4070 28 4069 29 4068 30 4067 31 4066 32 4065\n33 4064 34 4063 35 4062 36 4061 37 4060 38 4059 39 4058 40 4057 41 4056 42 4055 43 4054 44 4053 45 4052 46 4051 47 4050 48 4049 49 4048 50 4047 51 4046 52 4045 53 4044 54 4043 55 4042 56 4041 57 4040 58 4039 59 4038 60 4037 61 4036 62 4035 63 4034 64 4033\n65 403..."
},
{
"input": "44",
"output": "1 1936 2 1935 3 1934 4 1933 5 1932 6 1931 7 1930 8 1929 9 1928 10 1927 11 1926 12 1925 13 1924 14 1923 15 1922 16 1921 17 1920 18 1919 19 1918 20 1917 21 1916 22 1915\n23 1914 24 1913 25 1912 26 1911 27 1910 28 1909 29 1908 30 1907 31 1906 32 1905 33 1904 34 1903 35 1902 36 1901 37 1900 38 1899 39 1898 40 1897 41 1896 42 1895 43 1894 44 1893\n45 1892 46 1891 47 1890 48 1889 49 1888 50 1887 51 1886 52 1885 53 1884 54 1883 55 1882 56 1881 57 1880 58 1879 59 1878 60 1877 61 1876 62 1875 63 1874 64 1873 65 187..."
}
] | 1,582,126,833
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 1
| 216
| 0
|
n = int(input())
m = n * n
for i in range(1 , n+1):
print(i , end = ' ')
print(m - i + 1 )
|
Title: Candy Bags
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies.
Help him give *n* bags of candies to each brother so that all brothers got the same number of candies.
Input Specification:
The single line contains a single integer *n* (*n* is even, 2<=≤<=*n*<=≤<=100) — the number of Gerald's brothers.
Output Specification:
Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers — the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the lines in any order.
It is guaranteed that the solution exists at the given limits.
Demo Input:
['2\n']
Demo Output:
['1 4\n2 3\n']
Note:
The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother.
|
```python
n = int(input())
m = n * n
for i in range(1 , n+1):
print(i , end = ' ')
print(m - i + 1 )
```
| 0
|
|
83
|
A
|
Magical Array
|
PROGRAMMING
| 1,300
|
[
"math"
] |
A. Magical Array
|
2
|
256
|
Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a regular array of numbers Valera manages to see something beautiful and magical.
Valera absolutely accidentally got a piece of ancient parchment on which an array of numbers was written. He immediately thought that the numbers in this array were not random. As a result of extensive research Valera worked out a wonderful property that a magical array should have: an array is defined as magic if its minimum and maximum coincide.
He decided to share this outstanding discovery with you, but he asks you for help in return. Despite the tremendous intelligence and wit, Valera counts very badly and so you will have to complete his work. All you have to do is count the number of magical subarrays of the original array of numbers, written on the parchment. Subarray is defined as non-empty sequence of consecutive elements.
|
The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains an array of original integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109).
|
Print on the single line the answer to the problem: the amount of subarrays, which are magical.
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator).
|
[
"4\n2 1 1 4\n",
"5\n-2 -2 -2 0 1\n"
] |
[
"5\n",
"8\n"
] |
Notes to sample tests:
Magical subarrays are shown with pairs of indices [a;b] of the beginning and the end.
In the first sample: [1;1], [2;2], [3;3], [4;4], [2;3].
In the second sample: [1;1], [2;2], [3;3], [4;4], [5;5], [1;2], [2;3], [1;3].
| 500
|
[
{
"input": "4\n2 1 1 4",
"output": "5"
},
{
"input": "5\n-2 -2 -2 0 1",
"output": "8"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n5 6",
"output": "2"
},
{
"input": "5\n5 5 4 5 5",
"output": "7"
},
{
"input": "8\n1 2 0 0 0 0 3 3",
"output": "15"
},
{
"input": "12\n-4 3 3 2 3 3 3 -4 2 -4 -4 -4",
"output": "19"
},
{
"input": "10\n7 1 0 10 0 -5 -3 -2 0 0",
"output": "11"
},
{
"input": "20\n6 0 0 -3 1 -3 0 -8 1 3 5 2 -1 -5 -1 9 0 6 -2 4",
"output": "21"
},
{
"input": "100\n0 -18 -9 -15 3 16 -28 0 -28 0 28 -20 -9 9 -11 0 18 -15 -18 -26 0 -27 -25 -22 6 -5 8 14 -17 24 20 3 -6 24 -27 1 -23 0 4 12 -20 0 -10 30 22 -6 13 16 0 15 17 -8 -2 0 -5 13 11 23 -17 -29 10 15 -28 0 -23 4 20 17 -7 -5 -16 -17 16 2 20 19 -8 0 8 -5 12 0 0 -14 -15 -28 -10 20 0 8 -1 10 14 9 0 4 -16 15 13 -10",
"output": "101"
},
{
"input": "50\n2 0 2 0 0 0 0 -1 -2 -2 -2 1 1 2 2 0 2 0 2 -3 0 0 0 0 3 1 -2 0 -1 0 -2 3 -1 2 0 2 0 0 0 0 2 0 1 0 0 3 0 0 -2 0",
"output": "75"
},
{
"input": "2\n-510468670 0",
"output": "2"
},
{
"input": "150\n0 -2 1 -2 0 0 0 0 -2 0 -2 -1 0 0 2 0 1 -2 1 -1 0 0 0 2 -2 2 -1 0 0 0 -2 0 2 0 1 0 -2 0 -2 -1 -1 -2 -2 2 0 0 1 -2 -2 -1 -2 0 2 1 1 -1 1 0 -2 2 0 0 0 1 -1 0 -2 -1 0 -2 2 1 1 0 0 2 0 0 2 -1 0 0 2 0 2 0 -2 -1 1 -2 1 0 0 -2 -1 -1 0 0 2 -1 -1 -1 -1 -2 0 0 2 -1 -1 1 0 0 1 -1 0 0 -1 2 2 0 0 0 -1 -2 0 1 0 -1 0 -1 -1 0 2 0 1 2 0 0 2 0 0 1 2 0 2 -2 2 0 2 2",
"output": "196"
}
] | 1,660,325,995
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 4
| 92
| 0
|
n = int(input())
li = list(map(int, input().split()))
e = li[0]
cnt = 1
total_cnt = n
for i in range(1, n):
if li[i] == e:
cnt += 1
else:
if cnt > 1:
total_cnt += ((cnt-1)*cnt)//2
e = li[i]
cnt = 1
print(total_cnt)
|
Title: Magical Array
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a regular array of numbers Valera manages to see something beautiful and magical.
Valera absolutely accidentally got a piece of ancient parchment on which an array of numbers was written. He immediately thought that the numbers in this array were not random. As a result of extensive research Valera worked out a wonderful property that a magical array should have: an array is defined as magic if its minimum and maximum coincide.
He decided to share this outstanding discovery with you, but he asks you for help in return. Despite the tremendous intelligence and wit, Valera counts very badly and so you will have to complete his work. All you have to do is count the number of magical subarrays of the original array of numbers, written on the parchment. Subarray is defined as non-empty sequence of consecutive elements.
Input Specification:
The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains an array of original integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109).
Output Specification:
Print on the single line the answer to the problem: the amount of subarrays, which are magical.
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator).
Demo Input:
['4\n2 1 1 4\n', '5\n-2 -2 -2 0 1\n']
Demo Output:
['5\n', '8\n']
Note:
Notes to sample tests:
Magical subarrays are shown with pairs of indices [a;b] of the beginning and the end.
In the first sample: [1;1], [2;2], [3;3], [4;4], [2;3].
In the second sample: [1;1], [2;2], [3;3], [4;4], [5;5], [1;2], [2;3], [1;3].
|
```python
n = int(input())
li = list(map(int, input().split()))
e = li[0]
cnt = 1
total_cnt = n
for i in range(1, n):
if li[i] == e:
cnt += 1
else:
if cnt > 1:
total_cnt += ((cnt-1)*cnt)//2
e = li[i]
cnt = 1
print(total_cnt)
```
| 0
|
268
|
A
|
Games
|
PROGRAMMING
| 800
|
[
"brute force"
] | null | null |
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.
There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.
You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question.
|
The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively.
|
In a single line print the number of games where the host team is going to play in the guest uniform.
|
[
"3\n1 2\n2 4\n3 4\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"2\n1 2\n1 2\n"
] |
[
"1\n",
"5\n",
"0\n"
] |
In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first).
| 500
|
[
{
"input": "3\n1 2\n2 4\n3 4",
"output": "1"
},
{
"input": "4\n100 42\n42 100\n5 42\n100 5",
"output": "5"
},
{
"input": "2\n1 2\n1 2",
"output": "0"
},
{
"input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52",
"output": "6"
},
{
"input": "10\n68 42\n1 35\n25 70\n59 79\n65 63\n46 6\n28 82\n92 62\n43 96\n37 28",
"output": "1"
},
{
"input": "30\n10 39\n89 1\n78 58\n75 99\n36 13\n77 50\n6 97\n79 28\n27 52\n56 5\n93 96\n40 21\n33 74\n26 37\n53 59\n98 56\n61 65\n42 57\n9 7\n25 63\n74 34\n96 84\n95 47\n12 23\n34 21\n71 6\n27 13\n15 47\n64 14\n12 77",
"output": "6"
},
{
"input": "30\n46 100\n87 53\n34 84\n44 66\n23 20\n50 34\n90 66\n17 39\n13 22\n94 33\n92 46\n63 78\n26 48\n44 61\n3 19\n41 84\n62 31\n65 89\n23 28\n58 57\n19 85\n26 60\n75 66\n69 67\n76 15\n64 15\n36 72\n90 89\n42 69\n45 35",
"output": "4"
},
{
"input": "2\n46 6\n6 46",
"output": "2"
},
{
"input": "29\n8 18\n33 75\n69 22\n97 95\n1 97\n78 10\n88 18\n13 3\n19 64\n98 12\n79 92\n41 72\n69 15\n98 31\n57 74\n15 56\n36 37\n15 66\n63 100\n16 42\n47 56\n6 4\n73 15\n30 24\n27 71\n12 19\n88 69\n85 6\n50 11",
"output": "10"
},
{
"input": "23\n43 78\n31 28\n58 80\n66 63\n20 4\n51 95\n40 20\n50 14\n5 34\n36 39\n77 42\n64 97\n62 89\n16 56\n8 34\n58 16\n37 35\n37 66\n8 54\n50 36\n24 8\n68 48\n85 33",
"output": "6"
},
{
"input": "13\n76 58\n32 85\n99 79\n23 58\n96 59\n72 35\n53 43\n96 55\n41 78\n75 10\n28 11\n72 7\n52 73",
"output": "0"
},
{
"input": "18\n6 90\n70 79\n26 52\n67 81\n29 95\n41 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 2",
"output": "1"
},
{
"input": "18\n6 90\n100 79\n26 100\n67 100\n29 100\n100 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 100",
"output": "8"
},
{
"input": "30\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1",
"output": "450"
},
{
"input": "30\n100 99\n58 59\n56 57\n54 55\n52 53\n50 51\n48 49\n46 47\n44 45\n42 43\n40 41\n38 39\n36 37\n34 35\n32 33\n30 31\n28 29\n26 27\n24 25\n22 23\n20 21\n18 19\n16 17\n14 15\n12 13\n10 11\n8 9\n6 7\n4 5\n2 3",
"output": "0"
},
{
"input": "15\n9 3\n2 6\n7 6\n5 10\n9 5\n8 1\n10 5\n2 8\n4 5\n9 8\n5 3\n3 8\n9 8\n4 10\n8 5",
"output": "20"
},
{
"input": "15\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n1 2",
"output": "108"
},
{
"input": "25\n2 1\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n1 2\n2 1\n2 1\n2 1\n2 1\n1 2",
"output": "312"
},
{
"input": "25\n91 57\n2 73\n54 57\n2 57\n23 57\n2 6\n57 54\n57 23\n91 54\n91 23\n57 23\n91 57\n54 2\n6 91\n57 54\n2 57\n57 91\n73 91\n57 23\n91 57\n2 73\n91 2\n23 6\n2 73\n23 6",
"output": "96"
},
{
"input": "28\n31 66\n31 91\n91 31\n97 66\n31 66\n31 66\n66 91\n91 31\n97 31\n91 97\n97 31\n66 31\n66 97\n91 31\n31 66\n31 66\n66 31\n31 97\n66 97\n97 31\n31 91\n66 91\n91 66\n31 66\n91 66\n66 31\n66 31\n91 97",
"output": "210"
},
{
"input": "29\n78 27\n50 68\n24 26\n68 43\n38 78\n26 38\n78 28\n28 26\n27 24\n23 38\n24 26\n24 43\n61 50\n38 78\n27 23\n61 26\n27 28\n43 23\n28 78\n43 27\n43 78\n27 61\n28 38\n61 78\n50 26\n43 27\n26 78\n28 50\n43 78",
"output": "73"
},
{
"input": "29\n80 27\n69 80\n27 80\n69 80\n80 27\n80 27\n80 27\n80 69\n27 69\n80 69\n80 27\n27 69\n69 27\n80 69\n27 69\n69 80\n27 69\n80 69\n80 27\n69 27\n27 69\n27 80\n80 27\n69 80\n27 69\n80 69\n69 80\n69 80\n27 80",
"output": "277"
},
{
"input": "30\n19 71\n7 89\n89 71\n21 7\n19 21\n7 89\n19 71\n89 8\n89 21\n19 8\n21 7\n8 89\n19 89\n7 21\n19 8\n19 7\n7 19\n8 21\n71 21\n71 89\n7 19\n7 19\n21 7\n21 19\n21 19\n71 8\n21 8\n71 19\n19 71\n8 21",
"output": "154"
},
{
"input": "30\n44 17\n44 17\n44 17\n17 44\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n44 17\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n17 44\n44 17\n44 17\n44 17\n17 44\n17 44\n44 17\n17 44\n44 17\n44 17\n44 17",
"output": "418"
},
{
"input": "22\n78 92\n15 92\n92 78\n78 80\n92 16\n24 80\n92 16\n16 92\n78 16\n24 78\n80 78\n92 80\n16 80\n80 78\n15 78\n92 16\n24 15\n24 80\n80 16\n16 80\n92 80\n24 80",
"output": "74"
},
{
"input": "24\n9 83\n90 31\n83 3\n83 3\n21 31\n83 3\n32 31\n12 21\n31 21\n90 32\n32 21\n12 9\n12 31\n9 83\n83 12\n32 3\n32 83\n90 31\n9 32\n31 21\n83 90\n32 21\n21 3\n32 9",
"output": "59"
},
{
"input": "30\n67 21\n85 39\n85 87\n21 39\n66 85\n10 95\n10 21\n87 85\n82 21\n67 21\n95 10\n21 39\n82 21\n21 66\n66 39\n95 30\n67 85\n66 82\n85 82\n21 66\n10 39\n67 10\n21 85\n10 82\n85 95\n10 85\n21 39\n85 39\n39 10\n95 67",
"output": "100"
},
{
"input": "4\n8 7\n8 7\n7 8\n7 8",
"output": "8"
},
{
"input": "6\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1",
"output": "10"
},
{
"input": "12\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1",
"output": "72"
},
{
"input": "4\n1 2\n1 2\n2 1\n2 1",
"output": "8"
}
] | 1,677,169,297
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 31
| 92
| 0
|
n = int(input())
teams = []
c = 0
for i in range(n):
h, a = input().split()
h = int(h)
a = int(a)
teams.append([h, a])
for j in teams:
for i in teams:
if i != j:
if j[0] == i[1]:
c += 1
print(c)
|
Title: Games
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.
There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.
You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question.
Input Specification:
The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively.
Output Specification:
In a single line print the number of games where the host team is going to play in the guest uniform.
Demo Input:
['3\n1 2\n2 4\n3 4\n', '4\n100 42\n42 100\n5 42\n100 5\n', '2\n1 2\n1 2\n']
Demo Output:
['1\n', '5\n', '0\n']
Note:
In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first).
|
```python
n = int(input())
teams = []
c = 0
for i in range(n):
h, a = input().split()
h = int(h)
a = int(a)
teams.append([h, a])
for j in teams:
for i in teams:
if i != j:
if j[0] == i[1]:
c += 1
print(c)
```
| 3
|
|
862
|
C
|
Mahmoud and Ehab and the xor
|
PROGRAMMING
| 1,900
|
[
"constructive algorithms"
] | null | null |
Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets.
Dr. Evil has his favorite evil integer *x*. He asks Mahmoud and Ehab to find a set of *n* distinct non-negative integers such the bitwise-xor sum of the integers in it is exactly *x*. Dr. Evil doesn't like big numbers, so any number in the set shouldn't be greater than 106.
|
The only line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=105, 0<=≤<=*x*<=≤<=105) — the number of elements in the set and the desired bitwise-xor, respectively.
|
If there is no such set, print "NO" (without quotes).
Otherwise, on the first line print "YES" (without quotes) and on the second line print *n* distinct integers, denoting the elements in the set is any order. If there are multiple solutions you can print any of them.
|
[
"5 5\n",
"3 6\n"
] |
[
"YES\n1 2 4 5 7",
"YES\n1 2 5"
] |
You can read more about the bitwise-xor operation here: [https://en.wikipedia.org/wiki/Bitwise_operation#XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)
For the first sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb8ccd05d3a7a41eff93c98f79d158cf85e702f9.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
For the second sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d05d19f05b03f8ac89b7f86ef830eeccc0050c42.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
| 1,500
|
[
{
"input": "5 5",
"output": "YES\n1 2 131072 131078 0 "
},
{
"input": "3 6",
"output": "YES\n131072 131078 0 "
},
{
"input": "3 0",
"output": "YES\n393216 131072 262144"
},
{
"input": "1 0",
"output": "YES\n0"
},
{
"input": "3 3",
"output": "YES\n131072 131075 0 "
},
{
"input": "100000 41243",
"output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "100000 100000",
"output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "32 32",
"output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 131072 131105 0 "
},
{
"input": "32 31",
"output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 131072 131102 0 "
},
{
"input": "1 1",
"output": "YES\n1"
},
{
"input": "2 0",
"output": "NO"
},
{
"input": "3 1",
"output": "YES\n131072 131073 0 "
},
{
"input": "3 2",
"output": "YES\n131072 131074 0 "
},
{
"input": "3 5",
"output": "YES\n131072 131077 0 "
},
{
"input": "3 4",
"output": "YES\n131072 131076 0 "
},
{
"input": "3 10203",
"output": "YES\n131072 141275 0 "
},
{
"input": "3 10100",
"output": "YES\n131072 141172 0 "
},
{
"input": "5 0",
"output": "YES\n1 2 131072 131075 0 "
},
{
"input": "5 1",
"output": "YES\n1 2 131072 131074 0 "
},
{
"input": "5 2",
"output": "YES\n1 2 131072 131073 0 "
},
{
"input": "5 3",
"output": "YES\n1 2 393216 131072 262144"
},
{
"input": "5 4",
"output": "YES\n1 2 131072 131079 0 "
},
{
"input": "5 6",
"output": "YES\n1 2 131072 131077 0 "
},
{
"input": "5 7",
"output": "YES\n1 2 131072 131076 0 "
},
{
"input": "5 8",
"output": "YES\n1 2 131072 131083 0 "
},
{
"input": "5 9",
"output": "YES\n1 2 131072 131082 0 "
},
{
"input": "100000 1",
"output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "100000 0",
"output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "100000 21323",
"output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "100000 65536",
"output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "100000 65537",
"output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "100000 65535",
"output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "4 2",
"output": "YES\n1 131072 131075 0 "
},
{
"input": "10 2",
"output": "YES\n1 2 3 4 5 6 7 131072 131074 0 "
},
{
"input": "1 2",
"output": "YES\n2"
},
{
"input": "1 3",
"output": "YES\n3"
},
{
"input": "2 1",
"output": "YES\n0 1"
},
{
"input": "2 2",
"output": "YES\n0 2"
},
{
"input": "2 3",
"output": "YES\n0 3"
},
{
"input": "4 0",
"output": "YES\n1 131072 131073 0 "
},
{
"input": "4 1",
"output": "YES\n1 393216 131072 262144"
},
{
"input": "4 3",
"output": "YES\n1 131072 131074 0 "
},
{
"input": "6 0",
"output": "YES\n1 2 3 393216 131072 262144"
},
{
"input": "7 1",
"output": "YES\n1 2 3 4 131072 131077 0 "
}
] | 1,518,852,900
| 4,800
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 26
| 2,000
| 10,547,200
|
import random
import sys
n,k=input().split()
n=int(n)
k=int(k)
for tries in range(1000):
a=random.sample(range(100000),n-1)
x=0
for i in a:
x^=i
if k^x not in a:
print("YES")
for i in a:
print(i)
print(k^x)
sys.exit()
print("NO")
|
Title: Mahmoud and Ehab and the xor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets.
Dr. Evil has his favorite evil integer *x*. He asks Mahmoud and Ehab to find a set of *n* distinct non-negative integers such the bitwise-xor sum of the integers in it is exactly *x*. Dr. Evil doesn't like big numbers, so any number in the set shouldn't be greater than 106.
Input Specification:
The only line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=105, 0<=≤<=*x*<=≤<=105) — the number of elements in the set and the desired bitwise-xor, respectively.
Output Specification:
If there is no such set, print "NO" (without quotes).
Otherwise, on the first line print "YES" (without quotes) and on the second line print *n* distinct integers, denoting the elements in the set is any order. If there are multiple solutions you can print any of them.
Demo Input:
['5 5\n', '3 6\n']
Demo Output:
['YES\n1 2 4 5 7', 'YES\n1 2 5']
Note:
You can read more about the bitwise-xor operation here: [https://en.wikipedia.org/wiki/Bitwise_operation#XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)
For the first sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb8ccd05d3a7a41eff93c98f79d158cf85e702f9.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
For the second sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d05d19f05b03f8ac89b7f86ef830eeccc0050c42.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
|
```python
import random
import sys
n,k=input().split()
n=int(n)
k=int(k)
for tries in range(1000):
a=random.sample(range(100000),n-1)
x=0
for i in a:
x^=i
if k^x not in a:
print("YES")
for i in a:
print(i)
print(k^x)
sys.exit()
print("NO")
```
| 0
|
|
985
|
C
|
Liebig's Barrels
|
PROGRAMMING
| 1,500
|
[
"greedy"
] | null | null |
You have *m*<==<=*n*·*k* wooden staves. The *i*-th stave has length *a**i*. You have to assemble *n* barrels consisting of *k* staves each, you can use any *k* staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume *v**j* of barrel *j* be equal to the length of the minimal stave in it.
You want to assemble exactly *n* barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed *l*, i.e. |*v**x*<=-<=*v**y*|<=≤<=*l* for any 1<=≤<=*x*<=≤<=*n* and 1<=≤<=*y*<=≤<=*n*.
Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above.
|
The first line contains three space-separated integers *n*, *k* and *l* (1<=≤<=*n*,<=*k*<=≤<=105, 1<=≤<=*n*·*k*<=≤<=105, 0<=≤<=*l*<=≤<=109).
The second line contains *m*<==<=*n*·*k* space-separated integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=109) — lengths of staves.
|
Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly *n* barrels satisfying the condition |*v**x*<=-<=*v**y*|<=≤<=*l* for any 1<=≤<=*x*<=≤<=*n* and 1<=≤<=*y*<=≤<=*n*.
|
[
"4 2 1\n2 2 1 2 3 2 2 3\n",
"2 1 0\n10 10\n",
"1 2 1\n5 2\n",
"3 2 1\n1 2 3 4 5 6\n"
] |
[
"7\n",
"20\n",
"2\n",
"0\n"
] |
In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so it is impossible to make barrels equal enough.
| 0
|
[
{
"input": "4 2 1\n2 2 1 2 3 2 2 3",
"output": "7"
},
{
"input": "2 1 0\n10 10",
"output": "20"
},
{
"input": "1 2 1\n5 2",
"output": "2"
},
{
"input": "3 2 1\n1 2 3 4 5 6",
"output": "0"
},
{
"input": "10 3 189\n267 697 667 4 52 128 85 616 142 344 413 660 962 194 618 329 266 593 558 447 89 983 964 716 32 890 267 164 654 71",
"output": "0"
},
{
"input": "10 3 453\n277 706 727 812 692 686 196 507 911 40 498 704 573 381 463 759 704 381 693 640 326 405 47 834 962 521 463 740 520 494",
"output": "2979"
},
{
"input": "10 3 795\n398 962 417 307 760 534 536 450 421 280 608 111 687 726 941 903 630 900 555 403 795 122 814 188 234 976 679 539 525 104",
"output": "5045"
},
{
"input": "6 2 29\n1 2 3 3 4 5 5 6 7 7 8 9",
"output": "28"
},
{
"input": "2 1 2\n1 2",
"output": "3"
}
] | 1,542,578,861
| 2,147,483,647
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 6
| 296
| 11,468,800
|
import configparser
import math
import sys
input = sys.stdin.readline
def can(arr, pos, left, k, dist):
# rightmost point 0 indexed
right_most = pos + left - 1
if abs(arr[right_most] - arr[0]) > dist:
return False
if len(arr) - right_most - 1 < ((k-1) * left):
return False
return True
def main():
n, k, dist = [int(x) for x in input().split(' ')]
arr = sorted([int(x) for x in input().split(' ')])
if not can(arr=arr, pos=0, left=n, k=k, dist=dist):
print(0)
return
cost = 0
i = 0
while n > 0:
if can(arr=arr, pos=i, left=n, k=k, dist=dist):
i += 1
cost += arr[i-1]
n -= 1
print(cost)
if __name__ == '__main__':
main()
|
Title: Liebig's Barrels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have *m*<==<=*n*·*k* wooden staves. The *i*-th stave has length *a**i*. You have to assemble *n* barrels consisting of *k* staves each, you can use any *k* staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume *v**j* of barrel *j* be equal to the length of the minimal stave in it.
You want to assemble exactly *n* barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed *l*, i.e. |*v**x*<=-<=*v**y*|<=≤<=*l* for any 1<=≤<=*x*<=≤<=*n* and 1<=≤<=*y*<=≤<=*n*.
Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above.
Input Specification:
The first line contains three space-separated integers *n*, *k* and *l* (1<=≤<=*n*,<=*k*<=≤<=105, 1<=≤<=*n*·*k*<=≤<=105, 0<=≤<=*l*<=≤<=109).
The second line contains *m*<==<=*n*·*k* space-separated integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=109) — lengths of staves.
Output Specification:
Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly *n* barrels satisfying the condition |*v**x*<=-<=*v**y*|<=≤<=*l* for any 1<=≤<=*x*<=≤<=*n* and 1<=≤<=*y*<=≤<=*n*.
Demo Input:
['4 2 1\n2 2 1 2 3 2 2 3\n', '2 1 0\n10 10\n', '1 2 1\n5 2\n', '3 2 1\n1 2 3 4 5 6\n']
Demo Output:
['7\n', '20\n', '2\n', '0\n']
Note:
In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so it is impossible to make barrels equal enough.
|
```python
import configparser
import math
import sys
input = sys.stdin.readline
def can(arr, pos, left, k, dist):
# rightmost point 0 indexed
right_most = pos + left - 1
if abs(arr[right_most] - arr[0]) > dist:
return False
if len(arr) - right_most - 1 < ((k-1) * left):
return False
return True
def main():
n, k, dist = [int(x) for x in input().split(' ')]
arr = sorted([int(x) for x in input().split(' ')])
if not can(arr=arr, pos=0, left=n, k=k, dist=dist):
print(0)
return
cost = 0
i = 0
while n > 0:
if can(arr=arr, pos=i, left=n, k=k, dist=dist):
i += 1
cost += arr[i-1]
n -= 1
print(cost)
if __name__ == '__main__':
main()
```
| 0
|
|
525
|
B
|
Pasha and String
|
PROGRAMMING
| 1,400
|
[
"constructive algorithms",
"greedy",
"math",
"strings"
] | null | null |
Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given string.
Pasha didn't like his present very much so he decided to change it. After his birthday Pasha spent *m* days performing the following transformations on his string — each day he chose integer *a**i* and reversed a piece of string (a segment) from position *a**i* to position |*s*|<=-<=*a**i*<=+<=1. It is guaranteed that 2·*a**i*<=≤<=|*s*|.
You face the following task: determine what Pasha's string will look like after *m* days.
|
The first line of the input contains Pasha's string *s* of length from 2 to 2·105 characters, consisting of lowercase Latin letters.
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=105) — the number of days when Pasha changed his string.
The third line contains *m* space-separated elements *a**i* (1<=≤<=*a**i*; 2·*a**i*<=≤<=|*s*|) — the position from which Pasha started transforming the string on the *i*-th day.
|
In the first line of the output print what Pasha's string *s* will look like after *m* days.
|
[
"abcdef\n1\n2\n",
"vwxyz\n2\n2 2\n",
"abcdef\n3\n1 2 3\n"
] |
[
"aedcbf\n",
"vwxyz\n",
"fbdcea\n"
] |
none
| 750
|
[
{
"input": "abcdef\n1\n2",
"output": "aedcbf"
},
{
"input": "vwxyz\n2\n2 2",
"output": "vwxyz"
},
{
"input": "abcdef\n3\n1 2 3",
"output": "fbdcea"
},
{
"input": "jc\n5\n1 1 1 1 1",
"output": "cj"
},
{
"input": "wljqgdlxyc\n13\n3 4 3 3 5 4 4 2 4 4 5 3 3",
"output": "wyjldgqxlc"
},
{
"input": "keicnqmuqinhsmtudqcilocxkbqgzhbkitmqwttdyoyvcbxincwjryzknubpacsngorexaldfurondbednowemnnlphhboycfavs\n2\n5 12",
"output": "keiccyobhhphsmtudqcilocxkbqgzhbkitmqwttdyoyvcbxincwjryzknubpacsngorexaldfurondbednowemnnlniqumqnfavs"
},
{
"input": "xwcxggxvfqbdklewbxkjzibmufnaywuxsqvwakefxbbkfandvigasbhbatsxyqxicrosatfsfybedklsaztyyiuurfbrzmwumujy\n100\n14 43 30 13 8 19 33 7 8 14 15 35 5 18 44 1 35 1 18 7 50 47 9 49 28 29 39 37 27 17 19 12 5 24 37 42 37 23 35 31 10 26 5 38 40 34 42 47 2 40 43 34 16 25 14 45 35 38 46 48 49 27 49 38 10 49 5 7 3 3 41 25 24 34 37 33 17 50 48 11 40 43 48 10 9 50 18 39 32 13 26 40 37 16 45 50 27 3 7 31",
"output": "xjcxggxvfbbruliyyxkjzikdebnfyftxsorcaxqyxbtkfhbdvigasnababsxfekiwvqsauwsayfumblsaztbweukdfqrzmwumuwy"
}
] | 1,652,950,476
| 2,147,483,647
|
PyPy 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 6
| 2,000
| 30,924,800
|
s=input()
m=int(input())
a=list(map(int,input().split()))
for i in a:
s=s[:i-1]+s[i-1:len(s)-(i-1)][::-1]+s[len(s)-(i-1):]
print(s)
|
Title: Pasha and String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given string.
Pasha didn't like his present very much so he decided to change it. After his birthday Pasha spent *m* days performing the following transformations on his string — each day he chose integer *a**i* and reversed a piece of string (a segment) from position *a**i* to position |*s*|<=-<=*a**i*<=+<=1. It is guaranteed that 2·*a**i*<=≤<=|*s*|.
You face the following task: determine what Pasha's string will look like after *m* days.
Input Specification:
The first line of the input contains Pasha's string *s* of length from 2 to 2·105 characters, consisting of lowercase Latin letters.
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=105) — the number of days when Pasha changed his string.
The third line contains *m* space-separated elements *a**i* (1<=≤<=*a**i*; 2·*a**i*<=≤<=|*s*|) — the position from which Pasha started transforming the string on the *i*-th day.
Output Specification:
In the first line of the output print what Pasha's string *s* will look like after *m* days.
Demo Input:
['abcdef\n1\n2\n', 'vwxyz\n2\n2 2\n', 'abcdef\n3\n1 2 3\n']
Demo Output:
['aedcbf\n', 'vwxyz\n', 'fbdcea\n']
Note:
none
|
```python
s=input()
m=int(input())
a=list(map(int,input().split()))
for i in a:
s=s[:i-1]+s[i-1:len(s)-(i-1)][::-1]+s[len(s)-(i-1):]
print(s)
```
| 0
|
|
71
|
A
|
Way Too Long Words
|
PROGRAMMING
| 800
|
[
"strings"
] |
A. Way Too Long Words
|
1
|
256
|
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
|
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
|
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
|
[
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] |
[
"word\nl10n\ni18n\np43s\n"
] |
none
| 500
|
[
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd",
"output": "n20n\nj27b\nk15d"
},
{
"input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt",
"output": "t41t"
},
{
"input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings",
"output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz",
"output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz"
},
{
"input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij",
"output": "a98j"
},
{
"input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco",
"output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco"
},
{
"input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt",
"output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t"
},
{
"input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr",
"output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr"
}
] | 1,678,350,004
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 20
| 46
| 0
|
import sys
T= int(input())
for i in range(T):
a=input()
b=len(a)-2
if len(a)>10:
sys.stdout.write(a[0]+str(b)+a[len(a)-1])
print()
else:
print(a)
|
Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Output Specification:
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
Demo Input:
['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n']
Demo Output:
['word\nl10n\ni18n\np43s\n']
Note:
none
|
```python
import sys
T= int(input())
for i in range(T):
a=input()
b=len(a)-2
if len(a)>10:
sys.stdout.write(a[0]+str(b)+a[len(a)-1])
print()
else:
print(a)
```
| 3.977
|
386
|
A
|
Second-Price Auction
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auction winner is the participant who offered the highest price. However, he pay not the price he offers, but the highest price among the offers of other participants (hence the name: the second-price auction).
Write a program that reads prices offered by bidders and finds the winner and the price he will pay. Consider that all of the offered prices are different.
|
The first line of the input contains *n* (2<=≤<=*n*<=≤<=1000) — number of bidders. The second line contains *n* distinct integer numbers *p*1,<=*p*2,<=... *p**n*, separated by single spaces (1<=≤<=*p**i*<=≤<=10000), where *p**i* stands for the price offered by the *i*-th bidder.
|
The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based.
|
[
"2\n5 7\n",
"3\n10 2 8\n",
"6\n3 8 2 9 4 14\n"
] |
[
"2 5\n",
"1 8\n",
"6 9\n"
] |
none
| 500
|
[
{
"input": "2\n5 7",
"output": "2 5"
},
{
"input": "3\n10 2 8",
"output": "1 8"
},
{
"input": "6\n3 8 2 9 4 14",
"output": "6 9"
},
{
"input": "4\n4707 7586 4221 5842",
"output": "2 5842"
},
{
"input": "5\n3304 4227 4869 6937 6002",
"output": "4 6002"
},
{
"input": "6\n5083 3289 7708 5362 9031 7458",
"output": "5 7708"
},
{
"input": "7\n9038 6222 3392 1706 3778 1807 2657",
"output": "1 6222"
},
{
"input": "8\n7062 2194 4481 3864 7470 1814 8091 733",
"output": "7 7470"
},
{
"input": "9\n2678 5659 9199 2628 7906 7496 4524 2663 3408",
"output": "3 7906"
},
{
"input": "2\n3458 1504",
"output": "1 1504"
},
{
"input": "50\n9237 3904 407 9052 6657 9229 9752 3888 7732 2512 4614 1055 2355 7108 6506 6849 2529 8862 159 8630 7906 7941 960 8470 333 8659 54 9475 3163 5625 6393 6814 2656 3388 169 7918 4881 8468 9983 6281 6340 280 5108 2996 101 7617 3313 8172 326 1991",
"output": "39 9752"
},
{
"input": "100\n2515 3324 7975 6171 4240 1217 4829 5203 8603 6900 3031 4699 4732 6070 4221 3228 6497 7359 9130 4346 4619 1109 3945 5442 3271 16 9711 2045 6410 2301 3406 8125 6003 1892 1260 9661 3940 6692 4708 7027 4930 6925 1979 5361 4263 3144 867 8639 6230 5562 9714 3676 4231 3347 4733 4920 4881 3431 1059 7313 8912 3038 9308 72 9583 7009 3034 7425 2398 6141 3245 2495 2933 6710 8289 9806 1226 8393 7349 6462 1618 9613 3546 6012 2964 9995 1578 210 2123 4874 1252 8625 348 8020 803 7244 9080 5088 706 2602",
"output": "86 9806"
},
{
"input": "2\n2 1",
"output": "1 1"
},
{
"input": "2\n1 2",
"output": "2 1"
},
{
"input": "3\n10 20 30",
"output": "3 20"
},
{
"input": "3\n10 30 20",
"output": "2 20"
},
{
"input": "3\n20 10 30",
"output": "3 20"
},
{
"input": "3\n20 30 10",
"output": "2 20"
},
{
"input": "3\n30 10 20",
"output": "1 20"
},
{
"input": "3\n30 20 10",
"output": "1 20"
},
{
"input": "2\n1 10000",
"output": "2 1"
},
{
"input": "2\n10000 999",
"output": "1 999"
},
{
"input": "3\n3 4 1",
"output": "2 3"
},
{
"input": "6\n1 2 24 6 5 7",
"output": "3 7"
}
] | 1,698,628,573
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 42
| 46
| 0
|
n = int(input())
ps = list(map(int,input().split()))
idx = ps.index(max(ps))
nn = str(sorted(ps)[-2])
print(*[str(idx+1),nn])
|
Title: Second-Price Auction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auction winner is the participant who offered the highest price. However, he pay not the price he offers, but the highest price among the offers of other participants (hence the name: the second-price auction).
Write a program that reads prices offered by bidders and finds the winner and the price he will pay. Consider that all of the offered prices are different.
Input Specification:
The first line of the input contains *n* (2<=≤<=*n*<=≤<=1000) — number of bidders. The second line contains *n* distinct integer numbers *p*1,<=*p*2,<=... *p**n*, separated by single spaces (1<=≤<=*p**i*<=≤<=10000), where *p**i* stands for the price offered by the *i*-th bidder.
Output Specification:
The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based.
Demo Input:
['2\n5 7\n', '3\n10 2 8\n', '6\n3 8 2 9 4 14\n']
Demo Output:
['2 5\n', '1 8\n', '6 9\n']
Note:
none
|
```python
n = int(input())
ps = list(map(int,input().split()))
idx = ps.index(max(ps))
nn = str(sorted(ps)[-2])
print(*[str(idx+1),nn])
```
| 3
|
|
709
|
A
|
Juicer
|
PROGRAMMING
| 900
|
[
"implementation"
] | null | null |
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.
The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than *d*. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section?
|
The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer.
|
Print one integer — the number of times Kolya will have to empty the waste section.
|
[
"2 7 10\n5 6\n",
"1 5 10\n7\n",
"3 10 10\n5 7 7\n",
"1 1 1\n1\n"
] |
[
"1\n",
"0\n",
"1\n",
"0\n"
] |
In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all.
| 500
|
[
{
"input": "2 7 10\n5 6",
"output": "1"
},
{
"input": "1 5 10\n7",
"output": "0"
},
{
"input": "3 10 10\n5 7 7",
"output": "1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 951637 951638\n44069 951637",
"output": "1"
},
{
"input": "50 100 129\n55 130 91 19 116 3 63 52 104 76 75 27 151 99 149 147 39 148 84 9 132 49 40 112 124 141 144 93 36 32 146 74 48 38 150 55 94 32 107 69 77 81 33 57 62 98 78 127 154 126",
"output": "12"
},
{
"input": "100 1000 1083\n992 616 818 359 609 783 263 989 501 929 362 394 919 1081 870 830 1097 975 62 346 531 367 323 457 707 360 949 334 867 116 478 417 961 963 1029 114 867 1008 988 916 983 1077 959 942 572 961 579 318 721 337 488 717 111 70 416 685 987 130 353 107 61 191 827 849 106 815 211 953 111 398 889 860 801 71 375 320 395 1059 116 222 931 444 582 74 677 655 88 173 686 491 661 186 114 832 615 814 791 464 517 850",
"output": "36"
},
{
"input": "2 6 8\n2 1",
"output": "0"
},
{
"input": "5 15 16\n7 11 5 12 8",
"output": "2"
},
{
"input": "15 759966 759967\n890397 182209 878577 548548 759966 812923 759966 860479 200595 381358 299175 339368 759966 907668 69574",
"output": "4"
},
{
"input": "5 234613 716125\n642626 494941 234613 234613 234613",
"output": "0"
},
{
"input": "50 48547 567054\n529808 597004 242355 559114 78865 537318 631455 733020 655072 645093 309010 855034 306058 625046 524574 834944 27330 664392 443637 821584 338013 490702 289520 675471 885846 258814 134220 571301 84875 94132 200425 928833 375166 521232 317961 175315 947093 89971 322071 174033 48547 998535 954205 704114 943163 438900 48547 538422 48547 48547",
"output": "0"
},
{
"input": "5 10 20\n10 10 10 10 1",
"output": "1"
},
{
"input": "5 10 11\n10 10 10 10 1",
"output": "2"
},
{
"input": "3 10 10\n4 3 3",
"output": "0"
},
{
"input": "3 5 5\n5 5 5",
"output": "1"
},
{
"input": "3 4 14\n5 5 5",
"output": "0"
},
{
"input": "2 7 10\n1234 1234",
"output": "0"
},
{
"input": "1 5 6\n10",
"output": "0"
},
{
"input": "3 4 6\n1 2 3",
"output": "0"
},
{
"input": "5 10 12\n13 13 13 13 13",
"output": "0"
},
{
"input": "3 4 5\n5 7 9",
"output": "0"
},
{
"input": "3 10 100\n5 5 5",
"output": "0"
},
{
"input": "5 1 2\n2 2 2 2 2",
"output": "0"
},
{
"input": "5 5 5\n5 5 5 5 5",
"output": "2"
},
{
"input": "2 2 5\n5 5",
"output": "0"
},
{
"input": "3 1 4\n2 2 2",
"output": "0"
}
] | 1,621,379,422
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 58
| 109
| 7,270,400
|
n, b, d = [int(i) for i in input().split()]
how_many = 0
storage = 0
a = [int(i) for i in input().split()]
for i in a:
if i <= b:
storage += i
if storage>d:
storage=0
how_many += 1
print(how_many)
|
Title: Juicer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.
The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than *d*. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section?
Input Specification:
The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer.
Output Specification:
Print one integer — the number of times Kolya will have to empty the waste section.
Demo Input:
['2 7 10\n5 6\n', '1 5 10\n7\n', '3 10 10\n5 7 7\n', '1 1 1\n1\n']
Demo Output:
['1\n', '0\n', '1\n', '0\n']
Note:
In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all.
|
```python
n, b, d = [int(i) for i in input().split()]
how_many = 0
storage = 0
a = [int(i) for i in input().split()]
for i in a:
if i <= b:
storage += i
if storage>d:
storage=0
how_many += 1
print(how_many)
```
| 3
|
|
0
|
none
|
none
|
none
| 0
|
[
"none"
] | null | null |
Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is going to change some words. To make it still possible to read, he will try to modify each word as little as possible.
Limak has a string *s* that consists of uppercase English letters. In one move he can swap two adjacent letters of the string. For example, he can transform a string "ABBC" into "BABC" or "ABCB" in one move.
Limak wants to obtain a string without a substring "VK" (i.e. there should be no letter 'V' immediately followed by letter 'K'). It can be easily proved that it's possible for any initial string *s*.
What is the minimum possible number of moves Limak can do?
|
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=75) — the length of the string.
The second line contains a string *s*, consisting of uppercase English letters. The length of the string is equal to *n*.
|
Print one integer, denoting the minimum possible number of moves Limak can do, in order to obtain a string without a substring "VK".
|
[
"4\nVKVK\n",
"5\nBVVKV\n",
"7\nVVKEVKK\n",
"20\nVKVKVVVKVOVKVQKKKVVK\n",
"5\nLIMAK\n"
] |
[
"3\n",
"2\n",
"3\n",
"8\n",
"0\n"
] |
In the first sample, the initial string is "VKVK". The minimum possible number of moves is 3. One optimal sequence of moves is:
1. Swap two last letters. The string becomes "VKKV".1. Swap first two letters. The string becomes "KVKV".1. Swap the second and the third letter. The string becomes "KKVV". Indeed, this string doesn't have a substring "VK".
In the second sample, there are two optimal sequences of moves. One is "BVVKV" → "VBVKV" → "VVBKV". The other is "BVVKV" → "BVKVV" → "BKVVV".
In the fifth sample, no swaps are necessary.
| 0
|
[] | 1,689,193,883
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 0
| 46
| 0
|
print("_RANDOM_GUESS_1689193883.046417")# 1689193883.046436
|
Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is going to change some words. To make it still possible to read, he will try to modify each word as little as possible.
Limak has a string *s* that consists of uppercase English letters. In one move he can swap two adjacent letters of the string. For example, he can transform a string "ABBC" into "BABC" or "ABCB" in one move.
Limak wants to obtain a string without a substring "VK" (i.e. there should be no letter 'V' immediately followed by letter 'K'). It can be easily proved that it's possible for any initial string *s*.
What is the minimum possible number of moves Limak can do?
Input Specification:
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=75) — the length of the string.
The second line contains a string *s*, consisting of uppercase English letters. The length of the string is equal to *n*.
Output Specification:
Print one integer, denoting the minimum possible number of moves Limak can do, in order to obtain a string without a substring "VK".
Demo Input:
['4\nVKVK\n', '5\nBVVKV\n', '7\nVVKEVKK\n', '20\nVKVKVVVKVOVKVQKKKVVK\n', '5\nLIMAK\n']
Demo Output:
['3\n', '2\n', '3\n', '8\n', '0\n']
Note:
In the first sample, the initial string is "VKVK". The minimum possible number of moves is 3. One optimal sequence of moves is:
1. Swap two last letters. The string becomes "VKKV".1. Swap first two letters. The string becomes "KVKV".1. Swap the second and the third letter. The string becomes "KKVV". Indeed, this string doesn't have a substring "VK".
In the second sample, there are two optimal sequences of moves. One is "BVVKV" → "VBVKV" → "VVBKV". The other is "BVVKV" → "BVKVV" → "BKVVV".
In the fifth sample, no swaps are necessary.
|
```python
print("_RANDOM_GUESS_1689193883.046417")# 1689193883.046436
```
| 0
|
|
789
|
A
|
Anastasia and pebbles
|
PROGRAMMING
| 1,100
|
[
"implementation",
"math"
] | null | null |
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at most *k* pebbles in each pocket at the same time. There are *n* different pebble types in the park, and there are *w**i* pebbles of the *i*-th type. Anastasia is very responsible, so she never mixes pebbles of different types in same pocket. However, she can put different kinds of pebbles in different pockets at the same time. Unfortunately, she can't spend all her time collecting pebbles, so she can collect pebbles from the park only once a day.
Help her to find the minimum number of days needed to collect all the pebbles of Uzhlyandian Central Park, taking into consideration that Anastasia can't place pebbles of different types in same pocket.
|
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.
The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=104) — number of pebbles of each type.
|
The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles.
|
[
"3 2\n2 3 4\n",
"5 4\n3 1 8 9 7\n"
] |
[
"3\n",
"5\n"
] |
In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.
Optimal sequence of actions in the second sample case:
- In the first day Anastasia collects 8 pebbles of the third type. - In the second day she collects 8 pebbles of the fourth type. - In the third day she collects 3 pebbles of the first type and 1 pebble of the fourth type. - In the fourth day she collects 7 pebbles of the fifth type. - In the fifth day she collects 1 pebble of the second type.
| 500
|
[
{
"input": "3 2\n2 3 4",
"output": "3"
},
{
"input": "5 4\n3 1 8 9 7",
"output": "5"
},
{
"input": "1 22\n1",
"output": "1"
},
{
"input": "3 57\n78 165 54",
"output": "3"
},
{
"input": "5 72\n74 10 146 189 184",
"output": "6"
},
{
"input": "9 13\n132 87 200 62 168 51 185 192 118",
"output": "48"
},
{
"input": "1 1\n10000",
"output": "5000"
},
{
"input": "10 1\n1 1 1 1 1 1 1 1 1 1",
"output": "5"
},
{
"input": "2 2\n2 2",
"output": "1"
}
] | 1,572,809,549
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 31
| 233
| 10,342,400
|
#RAVENS
#TEAM_2
#ESSI-DAYI_MOHSEN-LORENZO
from math import ceil
n, k = map(int,input().split())
a = list(map(int,input().split()))
day = 0
b1 = b2 = odd = 0
for i in range(n):
yy = ceil(a[i]/k)
if yy % 2 == 0:day+=(yy//2)
else:
odd+=1
day+=ceil(yy/2)
print(day-odd//2)
|
Title: Anastasia and pebbles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at most *k* pebbles in each pocket at the same time. There are *n* different pebble types in the park, and there are *w**i* pebbles of the *i*-th type. Anastasia is very responsible, so she never mixes pebbles of different types in same pocket. However, she can put different kinds of pebbles in different pockets at the same time. Unfortunately, she can't spend all her time collecting pebbles, so she can collect pebbles from the park only once a day.
Help her to find the minimum number of days needed to collect all the pebbles of Uzhlyandian Central Park, taking into consideration that Anastasia can't place pebbles of different types in same pocket.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.
The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=104) — number of pebbles of each type.
Output Specification:
The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles.
Demo Input:
['3 2\n2 3 4\n', '5 4\n3 1 8 9 7\n']
Demo Output:
['3\n', '5\n']
Note:
In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.
Optimal sequence of actions in the second sample case:
- In the first day Anastasia collects 8 pebbles of the third type. - In the second day she collects 8 pebbles of the fourth type. - In the third day she collects 3 pebbles of the first type and 1 pebble of the fourth type. - In the fourth day she collects 7 pebbles of the fifth type. - In the fifth day she collects 1 pebble of the second type.
|
```python
#RAVENS
#TEAM_2
#ESSI-DAYI_MOHSEN-LORENZO
from math import ceil
n, k = map(int,input().split())
a = list(map(int,input().split()))
day = 0
b1 = b2 = odd = 0
for i in range(n):
yy = ceil(a[i]/k)
if yy % 2 == 0:day+=(yy//2)
else:
odd+=1
day+=ceil(yy/2)
print(day-odd//2)
```
| 3
|
|
445
|
A
|
DZY Loves Chessboard
|
PROGRAMMING
| 1,200
|
[
"dfs and similar",
"implementation"
] | null | null |
DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with the same color are on two adjacent cells. Two cells are adjacent if and only if they share a common edge.
You task is to find any suitable placement of chessmen on the given chessboard.
|
The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a "-" means it is bad.
|
Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell.
If multiple answers exist, print any of them. It is guaranteed that at least one answer exists.
|
[
"1 1\n.\n",
"2 2\n..\n..\n",
"3 3\n.-.\n---\n--."
] |
[
"B\n",
"BW\nWB\n",
"B-B\n---\n--B"
] |
In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK.
In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output.
In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are.
| 500
|
[
{
"input": "1 1\n.",
"output": "B"
},
{
"input": "2 2\n..\n..",
"output": "BW\nWB"
},
{
"input": "3 3\n.-.\n---\n--.",
"output": "B-B\n---\n--B"
},
{
"input": "3 1\n-\n.\n.",
"output": "-\nW\nB"
},
{
"input": "11 11\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------",
"output": "-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------"
},
{
"input": "1 1\n-",
"output": "-"
},
{
"input": "4 2\n..\n..\n..\n..",
"output": "BW\nWB\nBW\nWB"
},
{
"input": "5 1\n.\n.\n.\n.\n.",
"output": "B\nW\nB\nW\nB"
}
] | 1,598,858,436
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 4
| 124
| 7,065,600
|
#!/usr/bin/env python3
import random
def find_color(i, j):
if i == 0 and j == 0:
return random.choice(["B","W"])
elif i == len(board) - 1 and j == len(board[0]) - 1:
if board[i][j-1] == board[i-1][j]:
if board[i][j-1] == "B":
return "W"
elif board[i][j-1] == "W":
return "B"
elif board[i][j-1] == "-":
return random.choice(["B","W"])
else:
if board[i][j-1] == "-":
if board[i-1][j] == "B":
return "W"
elif board[i-1][j] == "W":
return "B"
elif board[i-1][j] == "-":
if board[i][j-1] == "B":
return "W"
elif board[i][j-1] == "W":
return "B"
elif i==0:
if board[i][j-1] == "B":
return "W"
elif board[i][j-1] == "W":
return "B"
elif board[i][j-1] == "-":
return random.choice(["B", "W"])
elif j ==0:
if board[i-1][j] == "B":
return "W"
elif board[i-1][j] == "W":
return "B"
elif board[i-1][j] == "-":
k = j + 1
while board[i-1][k] != "-":
k += 1
return board[i-1][k]
else:
if board[i][j-1] == board[i-1][j]:
if board[i][j-1] == "B":
return "W"
elif board[i][j-1] == "W":
return "B"
elif board[i][j-1] == "-":
k = j + 1
while k < len(board[i]) - 1 and board[i-1][k] != "-":
k += 1
return board[i-1][k]
else:
if board[i][j-1] == "-":
if board[i-1][j] == "B":
return "W"
elif board[i-1][j] == "W":
return "B"
elif board[i-1][j] == "-":
if board[i][j-1] == "B":
return "W"
elif board[i][j-1] == "W":
return "B"
if __name__ == "__main__":
n, m = map(int, input().split())
board = []
for _ in range(n):
string = input()
board.append([x for x in string])
for i in range(n):
for j in range(m):
if board[i][j] == ".":
board[i][j] = find_color(i, j)
for i in range(n):
print("".join([x for x in board[i]]))
|
Title: DZY Loves Chessboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with the same color are on two adjacent cells. Two cells are adjacent if and only if they share a common edge.
You task is to find any suitable placement of chessmen on the given chessboard.
Input Specification:
The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a "-" means it is bad.
Output Specification:
Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell.
If multiple answers exist, print any of them. It is guaranteed that at least one answer exists.
Demo Input:
['1 1\n.\n', '2 2\n..\n..\n', '3 3\n.-.\n---\n--.']
Demo Output:
['B\n', 'BW\nWB\n', 'B-B\n---\n--B']
Note:
In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK.
In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output.
In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are.
|
```python
#!/usr/bin/env python3
import random
def find_color(i, j):
if i == 0 and j == 0:
return random.choice(["B","W"])
elif i == len(board) - 1 and j == len(board[0]) - 1:
if board[i][j-1] == board[i-1][j]:
if board[i][j-1] == "B":
return "W"
elif board[i][j-1] == "W":
return "B"
elif board[i][j-1] == "-":
return random.choice(["B","W"])
else:
if board[i][j-1] == "-":
if board[i-1][j] == "B":
return "W"
elif board[i-1][j] == "W":
return "B"
elif board[i-1][j] == "-":
if board[i][j-1] == "B":
return "W"
elif board[i][j-1] == "W":
return "B"
elif i==0:
if board[i][j-1] == "B":
return "W"
elif board[i][j-1] == "W":
return "B"
elif board[i][j-1] == "-":
return random.choice(["B", "W"])
elif j ==0:
if board[i-1][j] == "B":
return "W"
elif board[i-1][j] == "W":
return "B"
elif board[i-1][j] == "-":
k = j + 1
while board[i-1][k] != "-":
k += 1
return board[i-1][k]
else:
if board[i][j-1] == board[i-1][j]:
if board[i][j-1] == "B":
return "W"
elif board[i][j-1] == "W":
return "B"
elif board[i][j-1] == "-":
k = j + 1
while k < len(board[i]) - 1 and board[i-1][k] != "-":
k += 1
return board[i-1][k]
else:
if board[i][j-1] == "-":
if board[i-1][j] == "B":
return "W"
elif board[i-1][j] == "W":
return "B"
elif board[i-1][j] == "-":
if board[i][j-1] == "B":
return "W"
elif board[i][j-1] == "W":
return "B"
if __name__ == "__main__":
n, m = map(int, input().split())
board = []
for _ in range(n):
string = input()
board.append([x for x in string])
for i in range(n):
for j in range(m):
if board[i][j] == ".":
board[i][j] = find_color(i, j)
for i in range(n):
print("".join([x for x in board[i]]))
```
| -1
|
|
500
|
A
|
New Year Transportation
|
PROGRAMMING
| 1,000
|
[
"dfs and similar",
"graphs",
"implementation"
] | null | null |
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of *n*<=-<=1 positive integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1. For every integer *i* where 1<=≤<=*i*<=≤<=*n*<=-<=1 the condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* holds. Next, he made *n*<=-<=1 portals, numbered by integers from 1 to *n*<=-<=1. The *i*-th (1<=≤<=*i*<=≤<=*n*<=-<=1) portal connects cell *i* and cell (*i*<=+<=*a**i*), and one can travel from cell *i* to cell (*i*<=+<=*a**i*) using the *i*-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (*i*<=+<=*a**i*) to cell *i* using the *i*-th portal. It is easy to see that because of condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* one can't leave the Line World using portals.
Currently, I am standing at cell 1, and I want to go to cell *t*. However, I don't know whether it is possible to go there. Please determine whether I can go to cell *t* by only using the construted transportation system.
|
The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guaranteed, that using the given transportation system, one cannot leave the Line World.
|
If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO".
|
[
"8 4\n1 2 1 2 1 2 1\n",
"8 5\n1 2 1 2 1 1 1\n"
] |
[
"YES\n",
"NO\n"
] |
In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit.
| 500
|
[
{
"input": "8 4\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "8 5\n1 2 1 2 1 1 1",
"output": "NO"
},
{
"input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1",
"output": "YES"
},
{
"input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 22 8 8 9 1 7 5 12 5 6 13 6 11 2 6 3 1 5 1 1 2 2 1",
"output": "YES"
},
{
"input": "120 104\n41 15 95 85 34 11 25 42 65 39 77 80 74 17 66 73 21 14 36 63 63 79 45 24 65 7 63 80 51 21 2 19 78 28 71 2 15 23 17 68 62 18 54 39 43 70 3 46 34 23 41 65 32 10 13 18 10 3 16 48 54 18 57 28 3 24 44 50 15 2 20 22 45 44 3 29 2 27 11 2 12 25 25 31 1 2 32 4 11 30 13 16 26 21 1 13 21 8 15 5 18 13 5 15 3 8 13 6 5 1 9 7 1 2 4 1 1 2 1",
"output": "NO"
},
{
"input": "10 3\n8 3 5 4 2 3 2 2 1",
"output": "NO"
},
{
"input": "10 9\n8 3 5 4 2 3 2 2 1",
"output": "YES"
},
{
"input": "3 2\n1 1",
"output": "YES"
},
{
"input": "3 2\n2 1",
"output": "NO"
},
{
"input": "4 2\n2 1 1",
"output": "NO"
},
{
"input": "4 4\n2 2 1",
"output": "YES"
},
{
"input": "8 8\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "3 3\n1 1",
"output": "YES"
},
{
"input": "8 8\n1 2 1 2 1 1 1",
"output": "YES"
},
{
"input": "3 3\n2 1",
"output": "YES"
},
{
"input": "4 4\n1 1 1",
"output": "YES"
},
{
"input": "8 8\n1 1 1 1 1 1 1",
"output": "YES"
},
{
"input": "5 5\n1 1 1 1",
"output": "YES"
}
] | 1,682,270,088
| 2,147,483,647
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 2
| 93
| 3,788,800
|
n,t=map(int,input().split())
arr=list(map(int,input().split()))
curr=1
t-=1
while curr<t:
curr+=arr[curr]
if curr==t:
print("YES")
else:
print("NO")
|
Title: New Year Transportation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of *n*<=-<=1 positive integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1. For every integer *i* where 1<=≤<=*i*<=≤<=*n*<=-<=1 the condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* holds. Next, he made *n*<=-<=1 portals, numbered by integers from 1 to *n*<=-<=1. The *i*-th (1<=≤<=*i*<=≤<=*n*<=-<=1) portal connects cell *i* and cell (*i*<=+<=*a**i*), and one can travel from cell *i* to cell (*i*<=+<=*a**i*) using the *i*-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (*i*<=+<=*a**i*) to cell *i* using the *i*-th portal. It is easy to see that because of condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* one can't leave the Line World using portals.
Currently, I am standing at cell 1, and I want to go to cell *t*. However, I don't know whether it is possible to go there. Please determine whether I can go to cell *t* by only using the construted transportation system.
Input Specification:
The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guaranteed, that using the given transportation system, one cannot leave the Line World.
Output Specification:
If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO".
Demo Input:
['8 4\n1 2 1 2 1 2 1\n', '8 5\n1 2 1 2 1 1 1\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit.
|
```python
n,t=map(int,input().split())
arr=list(map(int,input().split()))
curr=1
t-=1
while curr<t:
curr+=arr[curr]
if curr==t:
print("YES")
else:
print("NO")
```
| 0
|
|
802
|
G
|
Fake News (easy)
|
PROGRAMMING
| 800
|
[
"implementation",
"strings"
] | null | null |
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it...
|
The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z).
|
Output YES if the string *s* contains heidi as a subsequence and NO otherwise.
|
[
"abcheaibcdi\n",
"hiedi\n"
] |
[
"YES",
"NO"
] |
A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*.
| 0
|
[
{
"input": "abcheaibcdi",
"output": "YES"
},
{
"input": "hiedi",
"output": "NO"
},
{
"input": "ihied",
"output": "NO"
},
{
"input": "diehi",
"output": "NO"
},
{
"input": "deiih",
"output": "NO"
},
{
"input": "iheid",
"output": "NO"
},
{
"input": "eihdi",
"output": "NO"
},
{
"input": "ehdii",
"output": "NO"
},
{
"input": "edhii",
"output": "NO"
},
{
"input": "deiih",
"output": "NO"
},
{
"input": "ehdii",
"output": "NO"
},
{
"input": "eufyajkssayhjhqcwxmctecaeepjwmfoscqprpcxsqfwnlgzsmmuwuoruantipholrauvxydfvftwfzhnckxswussvlidcojiciflpvkcxkkcmmvtfvxrkwcpeelwsuzqgamamdtdgzscmikvojfvqehblmjczkvtdeymgertgkwfwfukafqlfdhtedcctixhyetdypswgagrpyto",
"output": "YES"
},
{
"input": "arfbvxgdvqzuloojjrwoyqqbxamxybaqltfimofulusfebodjkwwrgwcppkwiodtpjaraglyplgerrpqjkpoggjmfxhwtqrijpijrcyxnoodvwpyjfpvqaoazllbrpzananbrvvybboedidtuvqquklkpeflfaltukjhzjgiofombhbmqbihgtapswykfvlgdoapjqntvqsaohmbvnphvyyhvhavslamczuqifxnwknkaenqmlvetrqogqxmlptgrmqvxzdxdmwobjesmgxckpmawtioavwdngyiwkzypfnxcovwzdohshwlavwsthdssiadhiwmhpvgkrbezm",
"output": "YES"
},
{
"input": "zcectngbqnejjjtsfrluummmqabzqbyccshjqbrjthzhlbmzjfxugvjouwhumsgrnopiyakfadjnbsesamhynsbfbfunupwbxvohfmpwlcpxhovwpfpciclatgmiufwdvtsqrsdcymvkldpnhfeisrzhyhhlkwdzthgprvkpyldeysvbmcibqkpudyrraqdlxpjecvwcvuiklcrsbgvqasmxmtxqzmawcjtozioqlfflinnxpeexbzloaeqjvglbdeufultpjqexvjjjkzemtzuzmxvawilcqdrcjzpqyhtwfphuonzwkotthsaxrmwtnlmcdylxqcfffyndqeouztluqwlhnkkvzwcfiscikv",
"output": "YES"
},
{
"input": "plqaykgovxkvsiahdbglktdlhcqwelxxmtlyymrsyubxdskvyjkrowvcbpdofpjqspsrgpakdczletxujzlsegepzleipiyycpinzxgwjsgslnxsotouddgfcybozfpjhhocpybfjbaywsehbcfrayvancbrumdfngqytnhihyxnlvilrqyhnxeckprqafofelospffhtwguzjbbjlzbqrtiielbvzutzgpqxosiaqznndgobcluuqlhmffiowkjdlkokehtjdyjvmxsiyxureflmdomerfekxdvtitvwzmdsdzplkpbtafxqfpudnhfqpoiwvjnylanunmagoweobdvfjgepbsymfutrjarlxclhgavpytiiqwvojrptofuvlohzeguxdsrihsbucelhhuedltnnjgzxwyblbqvnoliiydfinzlogbvucwykryzcyibnniggbkdkdcdgcsbvvnavtyhtkanrblpvomvjs",
"output": "YES"
},
{
"input": "fbldqzggeunkpwcfirxanmntbfrudijltoertsdvcvcmbwodbibsrxendzebvxwydpasaqnisrijctsuatihxxygbeovhxjdptdcppkvfytdpjspvrannxavmkmisqtygntxkdlousdypyfkrpzapysfpdbyprufwzhunlsfugojddkmxzinatiwfxdqmgyrnjnxvrclhxyuwxtshoqdjptmeecvgmrlvuwqtmnfnfeeiwcavwnqmyustawbjodzwsqmnjxhpqmgpysierlwbbdzcwprpsexyvreewcmlbvaiytjlxdqdaqftefdlmtmmjcwvfejshymhnouoshdzqcwzxpzupkbcievodzqkqvyjuuxxwepxjalvkzufnveji",
"output": "YES"
},
{
"input": "htsyljgoelbbuipivuzrhmfpkgderqpoprlxdpasxhpmxvaztccldtmujjzjmcpdvsdghzpretlsyyiljhjznseaacruriufswuvizwwuvdioazophhyytvbiogttnnouauxllbdn",
"output": "YES"
},
{
"input": "ikmxzqdzxqlvgeojsnhqzciujslwjyzzexnregabdqztpplosdakimjxmuqccbnwvzbajoiqgdobccwnrwmixohrbdarhoeeelzbpigiybtesybwefpcfx",
"output": "YES"
},
{
"input": "bpvbpjvbdfiodsmahxpcubjxdykesubnypalhypantshkjffmxjmelblqnjdmtaltneuyudyevkgedkqrdmrfeemgpghwrifcwincfixokfgurhqbcfzeajrgkgpwqwsepudxulywowwxzdxkumsicsvnzfxspmjpaixgejeaoyoibegosqoyoydmphfpbutrrewyjecowjckvpcceoamtfbitdneuwqfvnagswlskmsmkhmxyfsrpqwhxzocyffiumcy",
"output": "YES"
},
{
"input": "vllsexwrazvlfvhvrtqeohvzzresjdiuhomfpgqcxpqdevplecuaepixhlijatxzegciizpvyvxuembiplwklahlqibykfideysjygagjbgqkbhdhkatddcwlxboinfuomnpc",
"output": "YES"
},
{
"input": "pnjdwpxmvfoqkjtbhquqcuredrkwqzzfjmdvpnbqtypzdovemhhclkvigjvtprrpzbrbcbatkucaqteuciuozytsptvsskkeplaxdaqmjkmef",
"output": "NO"
},
{
"input": "jpwfhvlxvsdhtuozvlmnfiotrgapgjxtcsgcjnodcztupysvvvmjpzqkpommadppdrykuqkcpzojcwvlogvkddedwbggkrhuvtsvdiokehlkdlnukcufjvqxnikcdawvexxwffxtriqbdmkahxdtygodzohwtdmmuvmatdkvweqvaehaxiefpevkvqpyxsrhtmgjsdfcwzqobibeduooldrmglbinrepmunizheqzvgqvpdskhxfidxfnbisyizhepwyrcykcmjxnkyfjgrqlkixcvysa",
"output": "YES"
},
{
"input": "aftcrvuumeqbfvaqlltscnuhkpcifrrhnutjinxdhhdbzvizlrapzjdatuaynoplgjketupgaejciosofuhcgcjdcucarfvtsofgubtphijciswsvidnvpztlaarydkeqxzwdhfbmullkimerukusbrdnnujviydldrwhdfllsjtziwfeaiqotbiprespmxjulnyunkdtcghrzvhtcychkwatqqmladxpvmvlkzscthylbzkpgwlzfjqwarqvdeyngekqvrhrftpxnkfcibbowvnqdkulcdydspcubwlgoyinpnzgidbgunparnueddzwtzdiavbprbbg",
"output": "YES"
},
{
"input": "oagjghsidigeh",
"output": "NO"
},
{
"input": "chdhzpfzabupskiusjoefrwmjmqkbmdgboicnszkhdrlegeqjsldurmbshijadlwsycselhlnudndpdhcnhruhhvsgbthpruiqfirxkhpqhzhqdfpyozolbionodypfcqfeqbkcgmqkizgeyyelzeoothexcoaahedgrvoemqcwccbvoeqawqeuusyjxmgjkpfwcdttfmwunzuwvsihliexlzygqcgpbdiawfvqukikhbjerjkyhpcknlndaystrgsinghlmekbvhntcpypmchcwoglsmwwdulqneuabuuuvtyrnjxfcgoothalwkzzfxakneusezgnnepkpipzromqubraiggqndliz",
"output": "YES"
},
{
"input": "lgirxqkrkgjcutpqitmffvbujcljkqardlalyigxorscczuzikoylcxenryhskoavymexysvmhbsvhtycjlmzhijpuvcjshyfeycvvcfyzytzoyvxajpqdjtfiatnvxnyeqtfcagfftafllhhjhplbdsrfpctkqpinpdfrtlzyjllfbeffputywcckupyslkbbzpgcnxgbmhtqeqqehpdaokkjtatrhyiuusjhwgiiiikxpzdueasemosmmccoakafgvxduwiuflovhhfhffgnnjhoperhhjtvocpqytjxkmrknnknqeglffhfuplopmktykxuvcmbwpoeisrlyyhdpxfvzseucofyhziuiikihpqheqdyzwigeaqzhxzvporgisxgvhyicqyejovqloibhbunsvsunpvmdckkbuokitdzleilfwutcvuuytpupizinfjrzhxudsmjcjyfcpfgthujjowdwtgbvi",
"output": "YES"
},
{
"input": "uuehrvufgerqbzyzksmqnewacotuimawhlbycdbsmhshrsbqwybbkwjwsrkwptvlbbwjiivqugzrxxwgidrcrhrwsmwgeoleptfamzefgaeyxouxocrpvomjrazmxrnffdwrrmblgdiabdncvfougtmjgvvazasnygdrigbsrieoonirlivfyodvulouslxosswgpdexuldmkdbpdlgutiotvxjyecbrsvbmqxrlcpcipjjncduyqtohlzybvlemmfdeubihwlwqglkgjvnwrbgydcpwklmjeewqklmqdbajqgrpnynaxfvxjzgibqerxyhnxenrmcdqaaeksbzyrcaepozqpetaurlhjuxxhwppuhgoihxdxbmxeiahyaqkbknktlzkheaarjoqqrsyeducvoygwalgarldcdlqogfvsncejssmx",
"output": "YES"
},
{
"input": "iiopulfjxoitgiusqrhgbkiyzinphjtclodbkkydetylvuimkhdkklmyoacmekdvjpuxcrvqnjhqhhbfenlpzpwijtykqziocilvtpqhxuyrphdlamawjuzgjwiebkqyrzyqgtkcrhntjxqmcgkrqcslogjegfrivzidfedeegwbbsopvxvdoididlpypjogxaodtueebbwuwilacunqpozczcgrpaxxrtogpxgfkudtxchoravrrdtimhenwmnafxaruuojduxxglefejycfcyxllfimkszmbrhcwpnwjqgwvzysmlaaifdxfjjpgjmcksiigpanappjdloiolojmcqbnpnjjzaufdpjaknylmyvolhwypygwepmqwpiglpcnpypnudhdzpdvgzosyjthzcwtytxq",
"output": "YES"
}
] | 1,659,470,455
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 2
| 30
| 0
|
s,w=input(),"heidi"
for x in s:
if(w[0]==x): w=w[1:]
print("YES" if len(w)==0 else "NO")
|
Title: Fake News (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it...
Input Specification:
The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z).
Output Specification:
Output YES if the string *s* contains heidi as a subsequence and NO otherwise.
Demo Input:
['abcheaibcdi\n', 'hiedi\n']
Demo Output:
['YES', 'NO']
Note:
A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*.
|
```python
s,w=input(),"heidi"
for x in s:
if(w[0]==x): w=w[1:]
print("YES" if len(w)==0 else "NO")
```
| -1
|
|
159
|
B
|
Matchmaker
|
PROGRAMMING
| 1,100
|
[
"*special",
"greedy",
"sortings"
] | null | null |
Polycarpus has *n* markers and *m* marker caps. Each marker is described by two numbers: *x**i* is the color and *y**i* is the diameter. Correspondingly, each cap is described by two numbers: *a**j* is the color and *b**j* is the diameter. Cap (*a**j*,<=*b**j*) can close marker (*x**i*,<=*y**i*) only if their diameters match, that is, *b**j*<==<=*y**i*. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, *a**j*<==<=*x**i*.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
|
The first input line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of markers and the number of caps, correspondingly.
Next *n* lines describe the markers. The *i*-th line contains two space-separated integers *x**i*, *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the *i*-th marker's color and diameter, correspondingly.
Next *m* lines describe the caps. The *j*-th line contains two space-separated integers *a**j*, *b**j* (1<=≤<=*a**j*,<=*b**j*<=≤<=1000) — the color and diameter of the *j*-th cap, correspondingly.
|
Print two space-separated integers *u*,<=*v*, where *u* is the number of closed markers and *v* is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
|
[
"3 4\n1 2\n3 4\n2 4\n5 4\n2 4\n1 1\n1 2\n",
"2 2\n1 2\n2 1\n3 4\n5 1\n"
] |
[
"3 2\n",
"1 0\n"
] |
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed — the first and the third markers.
| 1,000
|
[
{
"input": "3 4\n1 2\n3 4\n2 4\n5 4\n2 4\n1 1\n1 2",
"output": "3 2"
},
{
"input": "2 2\n1 2\n2 1\n3 4\n5 1",
"output": "1 0"
},
{
"input": "6 7\n2 1\n2 2\n2 1\n1 1\n2 1\n1 2\n2 2\n2 2\n2 2\n1 2\n2 2\n1 1\n1 2",
"output": "3 3"
},
{
"input": "6 7\n2 1\n1 1\n2 2\n1 2\n1 1\n1 2\n2 1\n1 1\n1 1\n1 1\n1 2\n2 2\n1 1",
"output": "5 5"
},
{
"input": "6 7\n2 1\n2 2\n1 1\n1 2\n2 2\n1 2\n1 2\n1 1\n1 2\n2 2\n2 2\n2 2\n1 1",
"output": "6 5"
},
{
"input": "6 7\n1 1\n1 1\n1 2\n1 2\n2 2\n1 2\n2 1\n2 1\n2 1\n2 1\n1 1\n1 1\n1 2",
"output": "3 3"
},
{
"input": "6 2\n1 1\n2 1\n1 1\n1 1\n1 2\n1 1\n2 2\n1 2",
"output": "1 1"
},
{
"input": "3 3\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "3 3"
},
{
"input": "1 1\n1 1\n1 1",
"output": "1 1"
},
{
"input": "1 1\n1 1\n2 2",
"output": "0 0"
},
{
"input": "1 1\n1 1\n1 2",
"output": "0 0"
},
{
"input": "1 1\n1 2\n2 2",
"output": "1 0"
},
{
"input": "1 5\n1 1\n2 2\n1 1\n2 1\n1 2\n1 1",
"output": "1 1"
}
] | 1,653,304,042
| 2,147,483,647
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 19
| 3,000
| 10,444,800
|
import sys
input = sys.stdin.readline
from collections import defaultdict
n, m = map(int, input().split())
d = defaultdict(list)
e = defaultdict(int)
for _ in range(n):
a, b = map(int, input().split())
d[b].append(a)
e[b] += 1
g = [list(map(int, input().split())) for _ in range(m)]
c, q = 0, 0
for i in g:
if i[1] in e:
if e[i[1]] > 0:
e[i[1]] -= 1
c += 1
if i[0] in d[i[1]]:
q += 1
d[i[1]].remove(i[0])
print(c, q)
|
Title: Matchmaker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has *n* markers and *m* marker caps. Each marker is described by two numbers: *x**i* is the color and *y**i* is the diameter. Correspondingly, each cap is described by two numbers: *a**j* is the color and *b**j* is the diameter. Cap (*a**j*,<=*b**j*) can close marker (*x**i*,<=*y**i*) only if their diameters match, that is, *b**j*<==<=*y**i*. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, *a**j*<==<=*x**i*.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
Input Specification:
The first input line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of markers and the number of caps, correspondingly.
Next *n* lines describe the markers. The *i*-th line contains two space-separated integers *x**i*, *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the *i*-th marker's color and diameter, correspondingly.
Next *m* lines describe the caps. The *j*-th line contains two space-separated integers *a**j*, *b**j* (1<=≤<=*a**j*,<=*b**j*<=≤<=1000) — the color and diameter of the *j*-th cap, correspondingly.
Output Specification:
Print two space-separated integers *u*,<=*v*, where *u* is the number of closed markers and *v* is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
Demo Input:
['3 4\n1 2\n3 4\n2 4\n5 4\n2 4\n1 1\n1 2\n', '2 2\n1 2\n2 1\n3 4\n5 1\n']
Demo Output:
['3 2\n', '1 0\n']
Note:
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed — the first and the third markers.
|
```python
import sys
input = sys.stdin.readline
from collections import defaultdict
n, m = map(int, input().split())
d = defaultdict(list)
e = defaultdict(int)
for _ in range(n):
a, b = map(int, input().split())
d[b].append(a)
e[b] += 1
g = [list(map(int, input().split())) for _ in range(m)]
c, q = 0, 0
for i in g:
if i[1] in e:
if e[i[1]] > 0:
e[i[1]] -= 1
c += 1
if i[0] in d[i[1]]:
q += 1
d[i[1]].remove(i[0])
print(c, q)
```
| 0
|
|
629
|
A
|
Far Relative’s Birthday Cake
|
PROGRAMMING
| 800
|
[
"brute force",
"combinatorics",
"constructive algorithms",
"implementation"
] | null | null |
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be?
Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column.
|
In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake.
Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'.
|
Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column.
|
[
"3\n.CC\nC..\nC.C\n",
"4\nCC..\nC..C\n.CC.\n.CC.\n"
] |
[
"4\n",
"9\n"
] |
If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are:
1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3)
| 500
|
[
{
"input": "3\n.CC\nC..\nC.C",
"output": "4"
},
{
"input": "4\nCC..\nC..C\n.CC.\n.CC.",
"output": "9"
},
{
"input": "5\n.CCCC\nCCCCC\n.CCC.\nCC...\n.CC.C",
"output": "46"
},
{
"input": "7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.",
"output": "84"
},
{
"input": "8\n..C....C\nC.CCC.CC\n.C..C.CC\nCC......\nC..C..CC\nC.C...C.\nC.C..C..\nC...C.C.",
"output": "80"
},
{
"input": "9\n.C...CCCC\nC.CCCC...\n....C..CC\n.CC.CCC..\n.C.C..CC.\nC...C.CCC\nCCC.C...C\nCCCC....C\n..C..C..C",
"output": "144"
},
{
"input": "10\n..C..C.C..\n..CC..C.CC\n.C.C...C.C\n..C.CC..CC\n....C..C.C\n...C..C..C\nCC.CC....C\n..CCCC.C.C\n..CC.CCC..\nCCCC..C.CC",
"output": "190"
},
{
"input": "11\nC.CC...C.CC\nCC.C....C.C\n.....C..CCC\n....C.CC.CC\nC..C..CC...\nC...C...C..\nCC..CCC.C.C\n..C.CC.C..C\nC...C.C..CC\n.C.C..CC..C\n.C.C.CC.C..",
"output": "228"
},
{
"input": "21\n...CCC.....CC..C..C.C\n..CCC...CC...CC.CCC.C\n....C.C.C..CCC..C.C.C\n....CCC..C..C.CC.CCC.\n...CCC.C..C.C.....CCC\n.CCC.....CCC..C...C.C\nCCCC.C...CCC.C...C.CC\nC..C...C.CCC..CC..C..\nC...CC..C.C.CC..C.CC.\nCC..CCCCCCCCC..C....C\n.C..CCCC.CCCC.CCC...C\nCCC...CCC...CCC.C..C.\n.CCCCCCCC.CCCC.CC.C..\n.C.C..C....C.CCCCCC.C\n...C...C.CCC.C.CC..C.\nCCC...CC..CC...C..C.C\n.CCCCC...C.C..C.CC.C.\n..CCC.C.C..CCC.CCC...\n..C..C.C.C.....CC.C..\n.CC.C...C.CCC.C....CC\n...C..CCCC.CCC....C..",
"output": "2103"
},
{
"input": "20\nC.C.CCC.C....C.CCCCC\nC.CC.C..CCC....CCCC.\n.CCC.CC...CC.CCCCCC.\n.C...CCCC..C....CCC.\n.C..CCCCCCC.C.C.....\nC....C.C..CCC.C..CCC\n...C.C.CC..CC..CC...\nC...CC.C.CCCCC....CC\n.CC.C.CCC....C.CCC.C\nCC...CC...CC..CC...C\nC.C..CC.C.CCCC.C.CC.\n..CCCCC.C.CCC..CCCC.\n....C..C..C.CC...C.C\nC..CCC..CC..C.CC..CC\n...CC......C.C..C.C.\nCC.CCCCC.CC.CC...C.C\n.C.CC..CC..CCC.C.CCC\nC..C.CC....C....C...\n..CCC..CCC...CC..C.C\n.C.CCC.CCCCCCCCC..CC",
"output": "2071"
},
{
"input": "17\nCCC..C.C....C.C.C\n.C.CC.CC...CC..C.\n.CCCC.CC.C..CCC.C\n...CCC.CC.CCC.C.C\nCCCCCCCC..C.CC.CC\n...C..C....C.CC.C\nCC....CCC...C.CC.\n.CC.C.CC..C......\n.CCCCC.C.CC.CCCCC\n..CCCC...C..CC..C\nC.CC.C.CC..C.C.C.\nC..C..C..CCC.C...\n.C..CCCC..C......\n.CC.C...C..CC.CC.\nC..C....CC...CC..\nC.CC.CC..C.C..C..\nCCCC...C.C..CCCC.",
"output": "1160"
},
{
"input": "15\nCCCC.C..CCC....\nCCCCCC.CC.....C\n...C.CC.C.C.CC.\nCCCCCCC..C..C..\nC..CCC..C.CCCC.\n.CC..C.C.C.CC.C\n.C.C..C..C.C..C\n...C...C..CCCC.\n.....C.C..CC...\nCC.C.C..CC.C..C\n..CCCCC..CCC...\nCC.CC.C..CC.CCC\n..CCC...CC.C..C\nCC..C.C..CCC..C\n.C.C....CCC...C",
"output": "789"
},
{
"input": "1\n.",
"output": "0"
},
{
"input": "3\n.CC\nC..\nC.C",
"output": "4"
},
{
"input": "13\nC.C...C.C.C..\nCC.CCCC.CC..C\n.C.CCCCC.CC..\nCCCC..C...C..\n...CC.C.C...C\n.CC.CCC...CC.\nCC.CCCCCC....\n.C...C..CC..C\nCCCC.CC...C..\n.C.CCC..C.CC.\n..C...CC..C.C\n..C.CCC..CC.C\n.C...CCC.CC.C",
"output": "529"
},
{
"input": "16\n.C.C.C.C.C...C.C\n..C..C.CCCCCC...\n..C.C.C.C..C..C.\n.CC....C.CCC..C.\n.C.CCC..C....CCC\nCC..C.CC..C.C.CC\n...C..C..CC..CC.\n.CCC..C.CC.C.C..\n.CC.C..........C\nC...C....CC..C..\nC.CCC.C..C..C...\n.CCCCCCCCCCCC..C\n..C.C.CC.CC.CCC.\nCC..C.C....C..CC\nC.CCC..C..C.C.CC\n.C.CCC.CC..CCC.C",
"output": "874"
},
{
"input": "2\nCC\nCC",
"output": "4"
},
{
"input": "3\nC..\nC..\nC..",
"output": "3"
}
] | 1,662,750,602
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 48
| 46
| 0
|
def paresChocolate(matriz, n):
res = 0
for i in range(n):
count = 0
for j in range(n):
if matriz[i][j] == 'C':
count += 1
res += (count * (count - 1)) // 2
count = 0
for j in range(n):
if matriz[j][i] == 'C':
count += 1
res += (count * (count - 1)) // 2
return res
n = int(input())
matriz = []
for i in range(n):
matriz.append(input())
print(paresChocolate(matriz, n))
|
Title: Far Relative’s Birthday Cake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be?
Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column.
Input Specification:
In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake.
Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'.
Output Specification:
Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column.
Demo Input:
['3\n.CC\nC..\nC.C\n', '4\nCC..\nC..C\n.CC.\n.CC.\n']
Demo Output:
['4\n', '9\n']
Note:
If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are:
1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3)
|
```python
def paresChocolate(matriz, n):
res = 0
for i in range(n):
count = 0
for j in range(n):
if matriz[i][j] == 'C':
count += 1
res += (count * (count - 1)) // 2
count = 0
for j in range(n):
if matriz[j][i] == 'C':
count += 1
res += (count * (count - 1)) // 2
return res
n = int(input())
matriz = []
for i in range(n):
matriz.append(input())
print(paresChocolate(matriz, n))
```
| 3
|
|
266
|
A
|
Stones on the Table
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table.
The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue.
|
Print a single integer — the answer to the problem.
|
[
"3\nRRG\n",
"5\nRRRRR\n",
"4\nBRBG\n"
] |
[
"1\n",
"4\n",
"0\n"
] |
none
| 500
|
[
{
"input": "3\nRRG",
"output": "1"
},
{
"input": "5\nRRRRR",
"output": "4"
},
{
"input": "4\nBRBG",
"output": "0"
},
{
"input": "1\nB",
"output": "0"
},
{
"input": "2\nBG",
"output": "0"
},
{
"input": "3\nBGB",
"output": "0"
},
{
"input": "4\nRBBR",
"output": "1"
},
{
"input": "5\nRGGBG",
"output": "1"
},
{
"input": "10\nGGBRBRGGRB",
"output": "2"
},
{
"input": "50\nGRBGGRBRGRBGGBBBBBGGGBBBBRBRGBRRBRGBBBRBBRRGBGGGRB",
"output": "18"
},
{
"input": "15\nBRRBRGGBBRRRRGR",
"output": "6"
},
{
"input": "20\nRRGBBRBRGRGBBGGRGRRR",
"output": "6"
},
{
"input": "25\nBBGBGRBGGBRRBGRRBGGBBRBRB",
"output": "6"
},
{
"input": "30\nGRGGGBGGRGBGGRGRBGBGBRRRRRRGRB",
"output": "9"
},
{
"input": "35\nGBBGBRGBBGGRBBGBRRGGRRRRRRRBRBBRRGB",
"output": "14"
},
{
"input": "40\nGBBRRGBGGGRGGGRRRRBRBGGBBGGGBGBBBBBRGGGG",
"output": "20"
},
{
"input": "45\nGGGBBRBBRRGRBBGGBGRBRGGBRBRGBRRGBGRRBGRGRBRRG",
"output": "11"
},
{
"input": "50\nRBGGBGGRBGRBBBGBBGRBBBGGGRBBBGBBBGRGGBGGBRBGBGRRGG",
"output": "17"
},
{
"input": "50\nGGGBBRGGGGGRRGGRBGGRGBBRBRRBGRGBBBGBRBGRGBBGRGGBRB",
"output": "16"
},
{
"input": "50\nGBGRGRRBRRRRRGGBBGBRRRBBBRBBBRRGRBBRGBRBGGRGRBBGGG",
"output": "19"
},
{
"input": "10\nGRRBRBRBGR",
"output": "1"
},
{
"input": "10\nBRBGBGRRBR",
"output": "1"
},
{
"input": "20\nGBGBGGRRRRGRBBGRGRGR",
"output": "5"
},
{
"input": "20\nRRGGRBBGBBRBGRRBRRBG",
"output": "6"
},
{
"input": "30\nBGBRGBBBGRGBBRGBGRBBBRGGRRGRRB",
"output": "8"
},
{
"input": "30\nBBBBGGBRBGBBGBGBGBGGGRGRRGGBBB",
"output": "11"
},
{
"input": "40\nGBRRGRBGBRRGBRGGGBRGBGBRGBBRRGRGGBBGBGBB",
"output": "9"
},
{
"input": "40\nBRGRGGRGGRBBRRRBRBBGGGRRGBGBBGRBBRGBRRGG",
"output": "13"
},
{
"input": "50\nRBGBGGRRGGRGGBGBGRRBGGBGBRRBBGBBGBBBGBBRBBRBRBRGRG",
"output": "13"
},
{
"input": "50\nRBRRGBGRRRBGRRBGRRGRBBRBBRRBRGGBRBRRBGGRBGGBRBRGRB",
"output": "12"
},
{
"input": "2\nBB",
"output": "1"
},
{
"input": "50\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "49"
},
{
"input": "50\nRRRRRRRRGRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "47"
},
{
"input": "50\nRRRRRRRRRRRRGGRRRRRRRRRBRRRRRRRRRRRRRRBBRRRRRRRRRR",
"output": "43"
}
] | 1,694,435,301
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 34
| 92
| 0
|
n=int(input())
s=input()
t=0
for i in range(1,n):
if s[i] in s[i-1]:
t+=1
else:
continue
print(t)
|
Title: Stones on the Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table.
The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue.
Output Specification:
Print a single integer — the answer to the problem.
Demo Input:
['3\nRRG\n', '5\nRRRRR\n', '4\nBRBG\n']
Demo Output:
['1\n', '4\n', '0\n']
Note:
none
|
```python
n=int(input())
s=input()
t=0
for i in range(1,n):
if s[i] in s[i-1]:
t+=1
else:
continue
print(t)
```
| 3
|
|
780
|
A
|
Andryusha and Socks
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the socks one by one from the bag, and for each sock he looks whether the pair of this sock has been already took out of the bag, or not. If not (that means the pair of this sock is still in the bag), he puts the current socks on the table in front of him. Otherwise, he puts both socks from the pair to the wardrobe.
Andryusha remembers the order in which he took the socks from the bag. Can you tell him what is the maximum number of socks that were on the table at the same time?
|
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs.
The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha took out was from pair *x**i*.
It is guaranteed that Andryusha took exactly two socks of each pair.
|
Print single integer — the maximum number of socks that were on the table at the same time.
|
[
"1\n1 1\n",
"3\n2 1 1 3 2 3\n"
] |
[
"1\n",
"2\n"
] |
In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- Initially the table was empty, he took out a sock from pair 2 and put it on the table. - Sock (2) was on the table. Andryusha took out a sock from pair 1 and put it on the table. - Socks (1, 2) were on the table. Andryusha took out a sock from pair 1, and put this pair into the wardrobe. - Sock (2) was on the table. Andryusha took out a sock from pair 3 and put it on the table. - Socks (2, 3) were on the table. Andryusha took out a sock from pair 2, and put this pair into the wardrobe. - Sock (3) was on the table. Andryusha took out a sock from pair 3 and put this pair into the wardrobe.
| 500
|
[
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n2 1 1 3 2 3",
"output": "2"
},
{
"input": "5\n5 1 3 2 4 3 1 2 4 5",
"output": "5"
},
{
"input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7",
"output": "6"
},
{
"input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 15 31 14 49 9 16 6 44 27 14 5 6 3 47 25 26 1 35 3 15 24 19 8 46 49 41 4 26 40 28 42 11 34 35 46 18 7 28 18 40 19 42 4 41 38 48 50 12 29 39 33 17 25 22 22 21 36 45 27 30 20 7 13 29 39 44 21 8 37 45 34 1 20 10 11 17 33 12 43 13 10 16 48 24 32 5 23 32",
"output": "25"
},
{
"input": "50\n1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50",
"output": "1"
},
{
"input": "50\n50 50 49 49 48 48 47 47 46 46 45 45 44 44 43 43 42 42 41 41 40 40 39 39 38 38 37 37 36 36 35 35 34 34 33 33 32 32 31 31 30 30 29 29 28 28 27 27 26 26 25 25 24 24 23 23 22 22 21 21 20 20 19 19 18 18 17 17 16 16 15 15 14 14 13 13 12 12 11 11 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1",
"output": "1"
},
{
"input": "50\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50",
"output": "50"
},
{
"input": "50\n50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "50"
},
{
"input": "10\n2 9 4 1 6 7 10 3 1 5 8 6 2 3 10 7 4 8 5 9",
"output": "9"
}
] | 1,516,114,944
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 56
| 171
| 19,456,000
|
def socks():
n = int(input())
arr = [False for _ in range(n + 1)]
pairs = list(map(int, input().split()))
count = 0
max_count = 0
for p in pairs:
if arr[p]:
count -= 1
else:
arr[p] = True
count += 1
max_count = max(count, max_count)
print(max_count)
if __name__ == '__main__':
socks()
|
Title: Andryusha and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the socks one by one from the bag, and for each sock he looks whether the pair of this sock has been already took out of the bag, or not. If not (that means the pair of this sock is still in the bag), he puts the current socks on the table in front of him. Otherwise, he puts both socks from the pair to the wardrobe.
Andryusha remembers the order in which he took the socks from the bag. Can you tell him what is the maximum number of socks that were on the table at the same time?
Input Specification:
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs.
The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha took out was from pair *x**i*.
It is guaranteed that Andryusha took exactly two socks of each pair.
Output Specification:
Print single integer — the maximum number of socks that were on the table at the same time.
Demo Input:
['1\n1 1\n', '3\n2 1 1 3 2 3\n']
Demo Output:
['1\n', '2\n']
Note:
In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- Initially the table was empty, he took out a sock from pair 2 and put it on the table. - Sock (2) was on the table. Andryusha took out a sock from pair 1 and put it on the table. - Socks (1, 2) were on the table. Andryusha took out a sock from pair 1, and put this pair into the wardrobe. - Sock (2) was on the table. Andryusha took out a sock from pair 3 and put it on the table. - Socks (2, 3) were on the table. Andryusha took out a sock from pair 2, and put this pair into the wardrobe. - Sock (3) was on the table. Andryusha took out a sock from pair 3 and put this pair into the wardrobe.
|
```python
def socks():
n = int(input())
arr = [False for _ in range(n + 1)]
pairs = list(map(int, input().split()))
count = 0
max_count = 0
for p in pairs:
if arr[p]:
count -= 1
else:
arr[p] = True
count += 1
max_count = max(count, max_count)
print(max_count)
if __name__ == '__main__':
socks()
```
| 3
|
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.