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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
50 | B | Choosing Symbol Pairs | PROGRAMMING | 1,500 | [
"strings"
] | B. Choosing Symbol Pairs | 2 | 256 | There is a given string *S* consisting of *N* symbols. Your task is to find the number of ordered pairs of integers *i* and *j* such that
1. 1<=≤<=*i*,<=*j*<=≤<=*N*
2. *S*[*i*]<==<=*S*[*j*], that is the *i*-th symbol of string *S* is equal to the *j*-th. | The single input line contains *S*, consisting of lowercase Latin letters and digits. It is guaranteed that string *S* in not empty and its length does not exceed 105. | Print a single number which represents the number of pairs *i* and *j* with the needed property. Pairs (*x*,<=*y*) and (*y*,<=*x*) should be considered different, i.e. the ordered pairs count. | [
"great10\n",
"aaaaaaaaaa\n"
] | [
"7\n",
"100\n"
] | none | 1,000 | [
{
"input": "great10",
"output": "7"
},
{
"input": "aaaaaaaaaa",
"output": "100"
},
{
"input": "great10",
"output": "7"
},
{
"input": "aaaaaaaaaa",
"output": "100"
},
{
"input": "aabb",
"output": "8"
},
{
"input": "w",
"output": "1"
},
{
"in... | 1,669,623,513 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 20 | 2,000 | 0 | # LUOGU_RID: 95960370
a=input()
n=0
for i in a:
for j in a:
if i==j:
n+=1
print(n) | Title: Choosing Symbol Pairs
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a given string *S* consisting of *N* symbols. Your task is to find the number of ordered pairs of integers *i* and *j* such that
1. 1<=≤<=*i*,<=*j*<=≤<=*N*
2. *S*[*i*]<==<=*S*[*j*], that is the *i*-th symbo... | ```python
# LUOGU_RID: 95960370
a=input()
n=0
for i in a:
for j in a:
if i==j:
n+=1
print(n)
``` | 0 |
401 | A | Vanya and Cards | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed *x* in the absolute value.
Natasha doesn't like when Vanya spends a long time p... | The first line contains two integers: *n* (1<=≤<=*n*<=≤<=1000) — the number of found cards and *x* (1<=≤<=*x*<=≤<=1000) — the maximum absolute value of the number on a card. The second line contains *n* space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed *x* in their a... | Print a single number — the answer to the problem. | [
"3 2\n-1 1 2\n",
"2 3\n-2 -2\n"
] | [
"1\n",
"2\n"
] | In the first sample, Vanya needs to find a single card with number -2.
In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value. | 500 | [
{
"input": "3 2\n-1 1 2",
"output": "1"
},
{
"input": "2 3\n-2 -2",
"output": "2"
},
{
"input": "4 4\n1 2 3 4",
"output": "3"
},
{
"input": "2 2\n-1 -1",
"output": "1"
},
{
"input": "15 5\n-2 -1 2 -4 -3 4 -4 -2 -2 2 -2 -1 1 -4 -2",
"output": "4"
},
{
"... | 1,594,003,324 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 109 | 6,963,200 | s = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
a = abs(sum(d))
answer = int(a/s[1])
if a%s[1] > 0:
answer+=1
print(answer) | Title: Vanya and Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each... | ```python
s = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
a = abs(sum(d))
answer = int(a/s[1])
if a%s[1] > 0:
answer+=1
print(answer)
``` | 3 | |
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 au... | 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"
},
{... | 1,598,582,045 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 109 | 307,200 | n = int(input())
prices = list(map(int, input().split()))
sorted_prices = sorted(prices)
print(prices.index(sorted_prices[n-1])+1, end=' ')
print(sorted_prices[n-2], end=' ')
| 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... | ```python
n = int(input())
prices = list(map(int, input().split()))
sorted_prices = sorted(prices)
print(prices.index(sorted_prices[n-1])+1, end=' ')
print(sorted_prices[n-2], end=' ')
``` | 3 | |
393 | A | Nineteen | PROGRAMMING | 0 | [] | null | null | Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) ... | The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100. | Print a single integer — the maximum number of "nineteen"s that she can get in her string. | [
"nniinneetteeeenn\n",
"nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n",
"nineteenineteen\n"
] | [
"2",
"2",
"2"
] | none | 500 | [
{
"input": "nniinneetteeeenn",
"output": "2"
},
{
"input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii",
"output": "2"
},
{
"input": "nineteenineteen",
"output": "2"
},
{
"input": "nssemsnnsitjtihtthij",
"output": "0"
},
{
"input": "eehihnttehtherjsihihn... | 1,558,332,510 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 109 | 0 | import math
s = input()
count_n = -1
count_i = 0
count_e = 0
count_t = 0
for char in s:
if char == 'n':
count_n += 1
elif char == 'i':
count_i += 1
elif char == 'e':
count_e += 1
elif char == 't':
count_t += 1
print(min(int(count_n / 2), int(count_i), int(count_e / 3), int(count_t))) | Title: Nineteen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiinetee... | ```python
import math
s = input()
count_n = -1
count_i = 0
count_e = 0
count_t = 0
for char in s:
if char == 'n':
count_n += 1
elif char == 'i':
count_i += 1
elif char == 'e':
count_e += 1
elif char == 't':
count_t += 1
print(min(int(count_n / 2), int(count_i), int(count_e / 3), int(count... | 3 | |
778 | A | String Game | PROGRAMMING | 1,700 | [
"binary search",
"greedy",
"strings"
] | null | null | Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.
Sergey gives Nastya the word *t* and wants to get the word *p* out of it. Nastya removes letters in a cert... | The first and second lines of the input contain the words *t* and *p*, respectively. Words are composed of lowercase letters of the Latin alphabet (1<=≤<=|*p*|<=<<=|*t*|<=≤<=200<=000). It is guaranteed that the word *p* can be obtained by removing the letters from word *t*.
Next line contains a permutation *a*1,<=*... | Print a single integer number, the maximum number of letters that Nastya can remove. | [
"ababcba\nabb\n5 3 4 1 7 6 2\n",
"bbbabb\nbb\n1 6 3 4 2 5\n"
] | [
"3",
"4"
] | In the first sample test sequence of removing made by Nastya looks like this:
"ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba" <img align="middle" class="tex-formula" src="https... | 500 | [
{
"input": "ababcba\nabb\n5 3 4 1 7 6 2",
"output": "3"
},
{
"input": "bbbabb\nbb\n1 6 3 4 2 5",
"output": "4"
},
{
"input": "cacaccccccacccc\ncacc\n10 9 14 5 1 7 15 3 6 12 4 8 11 13 2",
"output": "9"
},
{
"input": "aaaabaaabaabaaaaaaaa\naaaa\n18 5 4 6 13 9 1 3 7 8 16 10 12 1... | 1,636,608,486 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 327 | 37,273,600 | s = input()
small = input()
nums = [int(x)-1 for x in input().split()]
n = len(s)
lo = 0
ans = 0
hi = n-1
def check(x):
copy = [1]*n
index = 0
for i in range(x):
copy[nums[i]]=0
for i in range(n):
if s[i]==small[index] and copy[i]:
index+=1
if index... | Title: String Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.
Sergey gi... | ```python
s = input()
small = input()
nums = [int(x)-1 for x in input().split()]
n = len(s)
lo = 0
ans = 0
hi = n-1
def check(x):
copy = [1]*n
index = 0
for i in range(x):
copy[nums[i]]=0
for i in range(n):
if s[i]==small[index] and copy[i]:
index+=1
... | 3 | |
1 | C | Ancient Berland Circus | PROGRAMMING | 2,100 | [
"geometry",
"math"
] | C. Ancient Berland Circus | 2 | 64 | Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different.
In Ancient Berland arenas in circuses were shaped as a regular (equiangular) polygon, the size and the number of angles could vary from one circus to another. In each corner of the arena there was a spec... | The input file consists of three lines, each of them contains a pair of numbers –– coordinates of the pillar. Any coordinate doesn't exceed 1000 by absolute value, and is given with at most six digits after decimal point. | Output the smallest possible area of the ancient arena. This number should be accurate to at least 6 digits after the decimal point. It's guaranteed that the number of angles in the optimal polygon is not larger than 100. | [
"0.000000 0.000000\n1.000000 1.000000\n0.000000 1.000000\n"
] | [
"1.00000000\n"
] | 0 | [
{
"input": "0.000000 0.000000\n1.000000 1.000000\n0.000000 1.000000",
"output": "1.00000000"
},
{
"input": "71.756151 7.532275\n-48.634784 100.159986\n91.778633 158.107739",
"output": "9991.27897663"
},
{
"input": "18.716839 40.852752\n66.147248 -4.083161\n111.083161 43.347248",
"out... | 1,694,240,869 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 92 | 2,867,200 | import numpy as np
x1=input().split()
x2=input().split()
x3=input().split()
dic=[x1,x2,x3]
def dist(x1,x2):
d=((float(x1[0])-float(x2[0]))**2+(float(x1[1])-float(x2[1]))**2)**0.5
return d
if dist(x1,x2)==dist(x1,x3):
d=dist(x1,x2)
l=dist(x2,x3)
elif dist(x2,x1)==dist(x2,x3):
d=dist(x2,x1... | Title: Ancient Berland Circus
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different.
In Ancient Berland arenas in circuses were shaped as a regular (equiangular) polygon, the size and t... | ```python
import numpy as np
x1=input().split()
x2=input().split()
x3=input().split()
dic=[x1,x2,x3]
def dist(x1,x2):
d=((float(x1[0])-float(x2[0]))**2+(float(x1[1])-float(x2[1]))**2)**0.5
return d
if dist(x1,x2)==dist(x1,x3):
d=dist(x1,x2)
l=dist(x2,x3)
elif dist(x2,x1)==dist(x2,x3):
d=... | -1 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a**i* dollars.
Each player can double his bid any number of times and triple his bid any nu... | First line of input contains an integer *n* (2<=≤<=*n*<=≤<=105), the number of players.
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the bids of players. | Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. | [
"4\n75 150 75 50\n",
"3\n100 150 250\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid.
It can be shown that in the second sample test there is no way to make all bids equal. | 0 | [
{
"input": "4\n75 150 75 50",
"output": "Yes"
},
{
"input": "3\n100 150 250",
"output": "No"
},
{
"input": "7\n34 34 68 34 34 68 34",
"output": "Yes"
},
{
"input": "10\n72 96 12 18 81 20 6 2 54 1",
"output": "No"
},
{
"input": "20\n958692492 954966768 77387000 724... | 1,444,307,582 | 782 | Python 3 | OK | TESTS | 70 | 888 | 9,216,000 | __author__ = 'JohnHook'
n = list(map(int, input().split()))[0]
a = list(map(int, input().split()))
for i in range(len(a)):
while a[i] % 2 == 0:
a[i] //= 2
while a[i] % 3 == 0:
a[i] //= 3
if a.count(a[0]) == len(a):
print('Yes')
else:
print('No') | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a*... | ```python
__author__ = 'JohnHook'
n = list(map(int, input().split()))[0]
a = list(map(int, input().split()))
for i in range(len(a)):
while a[i] % 2 == 0:
a[i] //= 2
while a[i] % 3 == 0:
a[i] //= 3
if a.count(a[0]) == len(a):
print('Yes')
else:
print('No')
``` | 3 | |
218 | A | Mountain Scenery | PROGRAMMING | 1,100 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Little Bolek has found a picture with *n* mountain peaks painted on it. The *n* painted peaks are represented by a non-closed polyline, consisting of 2*n* segments. The segments go through 2*n*<=+<=1 points with coordinates (1,<=*y*1), (2,<=*y*2), ..., (2*n*<=+<=1,<=*y*2*n*<=+<=1), with the *i*-th segment connecting th... | The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100). The next line contains 2*n*<=+<=1 space-separated integers *r*1,<=*r*2,<=...,<=*r*2*n*<=+<=1 (0<=≤<=*r**i*<=≤<=100) — the *y* coordinates of the polyline vertices on Bolek's picture.
It is guaranteed that we can obtain the gi... | Print 2*n*<=+<=1 integers *y*1,<=*y*2,<=...,<=*y*2*n*<=+<=1 — the *y* coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them. | [
"3 2\n0 5 3 5 1 5 2\n",
"1 1\n0 2 0\n"
] | [
"0 5 3 4 1 4 2 \n",
"0 1 0 \n"
] | none | 500 | [
{
"input": "3 2\n0 5 3 5 1 5 2",
"output": "0 5 3 4 1 4 2 "
},
{
"input": "1 1\n0 2 0",
"output": "0 1 0 "
},
{
"input": "1 1\n1 100 0",
"output": "1 99 0 "
},
{
"input": "3 1\n0 1 0 1 0 2 0",
"output": "0 1 0 1 0 1 0 "
},
{
"input": "3 1\n0 1 0 2 0 1 0",
"out... | 1,630,607,638 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 124 | 6,758,400 | ip = list(map(int, input().split(" ")))
peaks = ip[0]
n = ip[1]
lst = list(map(int, input().split(" ")))
i = 1
for j in range(n):
lst[i] -= 1
i += 2
print(*lst, sep=" ")
| Title: Mountain Scenery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Bolek has found a picture with *n* mountain peaks painted on it. The *n* painted peaks are represented by a non-closed polyline, consisting of 2*n* segments. The segments go through 2*n*<=+<=1 points with coordi... | ```python
ip = list(map(int, input().split(" ")))
peaks = ip[0]
n = ip[1]
lst = list(map(int, input().split(" ")))
i = 1
for j in range(n):
lst[i] -= 1
i += 2
print(*lst, sep=" ")
``` | 0 | |
915 | C | Permute Digits | PROGRAMMING | 1,700 | [
"dp",
"greedy"
] | null | null | You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0.
It is allowed to leave *a* as it is. | The first line contains integer *a* (1<=≤<=*a*<=≤<=1018). The second line contains integer *b* (1<=≤<=*b*<=≤<=1018). Numbers don't have leading zeroes. It is guaranteed that answer exists. | Print the maximum possible number that is a permutation of digits of *a* and is not greater than *b*. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number *a*. It should be a permutation of digits of *a*. | [
"123\n222\n",
"3921\n10000\n",
"4940\n5000\n"
] | [
"213\n",
"9321\n",
"4940\n"
] | none | 0 | [
{
"input": "123\n222",
"output": "213"
},
{
"input": "3921\n10000",
"output": "9321"
},
{
"input": "4940\n5000",
"output": "4940"
},
{
"input": "23923472834\n23589234723",
"output": "23498743322"
},
{
"input": "102391019\n491010301",
"output": "399211100"
},... | 1,575,265,024 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 5 | 218 | 2,867,200 | import sys,math,string,bisect
input=sys.stdin.readline
from collections import deque,defaultdict
L=lambda : list(map(int,input().split()))
Ls=lambda : list(input().split())
M=lambda : map(int,input().split())
I=lambda :int(input())
a=input().strip()
b=input().strip()
if(len(a)<len(b)):
s=list(a)
s.sort(reverse=... | Title: Permute Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0.
It is allow... | ```python
import sys,math,string,bisect
input=sys.stdin.readline
from collections import deque,defaultdict
L=lambda : list(map(int,input().split()))
Ls=lambda : list(input().split())
M=lambda : map(int,input().split())
I=lambda :int(input())
a=input().strip()
b=input().strip()
if(len(a)<len(b)):
s=list(a)
s.sor... | -1 | |
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.... | 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 ... | 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... | 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 ... | 1,669,138,398 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 15 | 31 | 0 | n = int(input())
mw = 0
cw = 0
while n > 0:
m, c = list(map(int, input().split(' ')))
if m > c:
mw += 1
else:
cw += 1
n -= 1
if mw > cw:
print('Mishka')
elif mw < cw:
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 st... | ```python
n = int(input())
mw = 0
cw = 0
while n > 0:
m, c = list(map(int, input().split(' ')))
if m > c:
mw += 1
else:
cw += 1
n -= 1
if mw > cw:
print('Mishka')
elif mw < cw:
print('Chris')
else:
print('Friendship is magic!^^')
``` | 0 | |
577 | A | Multiplication Table | PROGRAMMING | 1,000 | [
"implementation",
"number theory"
] | null | null | Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
You are given a positive integer *x*. Your task is to count the number of cells in a table that contain num... | The single line contains numbers *n* and *x* (1<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=109) — the size of the table and the number that we are looking for in the table. | Print a single number: the number of times *x* occurs in the table. | [
"10 5\n",
"6 12\n",
"5 13\n"
] | [
"2\n",
"4\n",
"0\n"
] | A table for the second sample test is given below. The occurrences of number 12 are marked bold. | 500 | [
{
"input": "10 5",
"output": "2"
},
{
"input": "6 12",
"output": "4"
},
{
"input": "5 13",
"output": "0"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "100000 1",
"output": "1"
},
{
"input": "1 10000000... | 1,661,190,410 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 62 | 0 | n,x=map(int,input().split())
ans=0
for i in range(1,n+1):
if x%i==0 and x//i<=n:
ans+=1
print(ans) | Title: Multiplication Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
Y... | ```python
n,x=map(int,input().split())
ans=0
for i in range(1,n+1):
if x%i==0 and x//i<=n:
ans+=1
print(ans)
``` | 3 | |
705 | A | Hulk | PROGRAMMING | 800 | [
"implementation"
] | null | null | Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, se... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate. | Print Dr.Banner's feeling in one line. | [
"1\n",
"2\n",
"3\n"
] | [
"I hate it\n",
"I hate that I love it\n",
"I hate that I love that I hate it\n"
] | none | 500 | [
{
"input": "1",
"output": "I hate it"
},
{
"input": "2",
"output": "I hate that I love it"
},
{
"input": "3",
"output": "I hate that I love that I hate it"
},
{
"input": "4",
"output": "I hate that I love that I hate that I love it"
},
{
"input": "5",
"output"... | 1,694,183,711 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | n=int(input())
output="I hate that"
for i in range(2,n+1):
if(i==n):
output+=(" I hate it"if(i%2!=0)else" I love it")
else:
output+=(" I hate that"if(i%2!=0)else" I love that")
print(output) | Title: Hulk
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and... | ```python
n=int(input())
output="I hate that"
for i in range(2,n+1):
if(i==n):
output+=(" I hate it"if(i%2!=0)else" I love it")
else:
output+=(" I hate that"if(i%2!=0)else" I love that")
print(output)
``` | 0 | |
131 | A | cAPS lOCK | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentall... | The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. | Print the result of the given word's processing. | [
"cAPS\n",
"Lock\n"
] | [
"Caps",
"Lock\n"
] | none | 500 | [
{
"input": "cAPS",
"output": "Caps"
},
{
"input": "Lock",
"output": "Lock"
},
{
"input": "cAPSlOCK",
"output": "cAPSlOCK"
},
{
"input": "CAPs",
"output": "CAPs"
},
{
"input": "LoCK",
"output": "LoCK"
},
{
"input": "OOPS",
"output": "oops"
},
{
... | 1,698,675,581 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 7 | 62 | 0 | # Read the input word
word = input()
# Check if the word should be corrected
if word.isupper() or (word[0].islower() and word[1:].isupper()):
corrected_word = word.swapcase()
else:
corrected_word = word
# Print the corrected word
print(corrected_word)
| Title: cAPS lOCK
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in th... | ```python
# Read the input word
word = input()
# Check if the word should be corrected
if word.isupper() or (word[0].islower() and word[1:].isupper()):
corrected_word = word.swapcase()
else:
corrected_word = word
# Print the corrected word
print(corrected_word)
``` | 0 | |
875 | A | Classroom Watch | PROGRAMMING | 1,200 | [
"brute force",
"math"
] | null | null | Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=109). | In the first line print one integer *k* — number of different values of *x* satisfying the condition.
In next *k* lines print these values in ascending order. | [
"21\n",
"20\n"
] | [
"1\n15\n",
"0\n"
] | In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21.
In the second test case there are no such *x*. | 500 | [
{
"input": "21",
"output": "1\n15"
},
{
"input": "20",
"output": "0"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "1\n1"
},
{
"input": "3",
"output": "0"
},
{
"input": "100000001",
"output": "2\n99999937\n100000000"
},
{
"i... | 1,508,171,522 | 2,147,483,647 | Python 3 | OK | TESTS | 18 | 62 | 5,529,600 | # Author: lizi
# Email: [email protected]
import sys
import math
n = int(input())
ans = []
for i in range(min(n,100)):
p = n - i
s = p
while p > 0:
s += p % 10
p = p // 10
#print(s,' ',p)
if s == n:
ans.append( n - i );
print(len(ans))
ans.sort()
for x in... | Title: Classroom Watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answe... | ```python
# Author: lizi
# Email: [email protected]
import sys
import math
n = int(input())
ans = []
for i in range(min(n,100)):
p = n - i
s = p
while p > 0:
s += p % 10
p = p // 10
#print(s,' ',p)
if s == n:
ans.append( n - i );
print(len(ans))
ans.sort()... | 3 | |
34 | A | Reconnaissance 2 | PROGRAMMING | 800 | [
"implementation"
] | A. Reconnaissance 2 | 2 | 256 | *n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a ... | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction. | Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. | [
"5\n10 12 13 15 10\n",
"4\n10 20 30 40\n"
] | [
"5 1\n",
"1 2\n"
] | none | 500 | [
{
"input": "5\n10 12 13 15 10",
"output": "5 1"
},
{
"input": "4\n10 20 30 40",
"output": "1 2"
},
{
"input": "6\n744 359 230 586 944 442",
"output": "2 3"
},
{
"input": "5\n826 747 849 687 437",
"output": "1 2"
},
{
"input": "5\n999 999 993 969 999",
"output"... | 1,681,059,729 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 20 | 124 | 0 | n=int(input())
parsa=list(map(int,input().split()))
i=0
adad1=0
adad2=0
sum=0
while i<n-1:
if parsa[i]>parsa[i+1]:
sum=parsa[i]-parsa[i+1]
else:
sum=parsa[i+1]-parsa[i]
if i==0:
min=sum
adad1=i
adad2=i+1
if min>sum:
min=sum
adad1=i... | Title: Reconnaissance 2
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So... | ```python
n=int(input())
parsa=list(map(int,input().split()))
i=0
adad1=0
adad2=0
sum=0
while i<n-1:
if parsa[i]>parsa[i+1]:
sum=parsa[i]-parsa[i+1]
else:
sum=parsa[i+1]-parsa[i]
if i==0:
min=sum
adad1=i
adad2=i+1
if min>sum:
min=sum
... | 3.969 |
911 | B | Two Cakes | PROGRAMMING | 1,200 | [
"binary search",
"brute force",
"implementation"
] | null | null | It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set ... | The first line contains three integers *n*, *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100, 2<=≤<=*n*<=≤<=*a*<=+<=*b*) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively. | Print the maximum possible number *x* such that Ivan can distribute the cake in such a way that each plate will contain at least *x* pieces of cake. | [
"5 2 3\n",
"4 7 10\n"
] | [
"1\n",
"3\n"
] | In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.
In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3. | 0 | [
{
"input": "5 2 3",
"output": "1"
},
{
"input": "4 7 10",
"output": "3"
},
{
"input": "100 100 100",
"output": "2"
},
{
"input": "10 100 3",
"output": "3"
},
{
"input": "2 9 29",
"output": "9"
},
{
"input": "4 6 10",
"output": "3"
},
{
"inp... | 1,658,064,952 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | n=int(input())
a=sorted(map(int,input().split()))
k=0
while k*10+2*sum(a[k:])<9*n:k+=1
print(k) | Title: Two Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Iv... | ```python
n=int(input())
a=sorted(map(int,input().split()))
k=0
while k*10+2*sum(a[k:])<9*n:k+=1
print(k)
``` | -1 | |
74 | B | Train | PROGRAMMING | 1,500 | [
"dp",
"games",
"greedy"
] | B. Train | 2 | 256 | A stowaway and a controller play the following game.
The train is represented by *n* wagons which are numbered with positive integers from 1 to *n* from the head to the tail. The stowaway and the controller are initially in some two different wagons. Every minute the train can be in one of two conditions — moving or ... | The first line contains three integers *n*, *m* and *k*. They represent the number of wagons in the train, the stowaway's and the controller's initial positions correspondingly (2<=≤<=*n*<=≤<=50, 1<=≤<=*m*,<=*k*<=≤<=*n*, *m*<=≠<=*k*).
The second line contains the direction in which a controller moves. "to head" means ... | If the stowaway wins, print "Stowaway" without quotes. Otherwise, print "Controller" again without quotes, then, separated by a space, print the number of a minute, at which the stowaway will be caught. | [
"5 3 2\nto head\n0001001\n",
"3 2 1\nto tail\n0001\n"
] | [
"Stowaway",
"Controller 2"
] | none | 1,000 | [
{
"input": "5 3 2\nto head\n0001001",
"output": "Stowaway"
},
{
"input": "3 2 1\nto tail\n0001",
"output": "Controller 2"
},
{
"input": "4 2 1\nto tail\n1000001",
"output": "Controller 6"
},
{
"input": "2 1 2\nto head\n111111",
"output": "Stowaway"
},
{
"input": "... | 1,611,398,142 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 124 | 307,200 | from sys import stdin, stdout, exit
n, m, k = map(int, stdin.readline().split())
d = 1 if stdin.readline()[6] == 'l' else -1
m = 1 if m < k else n
for i, c in enumerate(stdin.readline(), 1):
if c == '0':
if k == 1: k, d = 2, 1
elif k == n: k, d = n - 1, -1
else: k += d
... | Title: Train
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A stowaway and a controller play the following game.
The train is represented by *n* wagons which are numbered with positive integers from 1 to *n* from the head to the tail. The stowaway and the controller are initially in some tw... | ```python
from sys import stdin, stdout, exit
n, m, k = map(int, stdin.readline().split())
d = 1 if stdin.readline()[6] == 'l' else -1
m = 1 if m < k else n
for i, c in enumerate(stdin.readline(), 1):
if c == '0':
if k == 1: k, d = 2, 1
elif k == n: k, d = n - 1, -1
else: k += ... | 3.968428 |
110 | A | Nearly Lucky Number | PROGRAMMING | 800 | [
"implementation"
] | A. Nearly Lucky Number | 2 | 256 | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d... | The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018).
Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. | Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes). | [
"40047\n",
"7747774\n",
"1000000000000000000\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".
In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".
In the third sample there are no lucky digits, so the answer is "NO". | 500 | [
{
"input": "40047",
"output": "NO"
},
{
"input": "7747774",
"output": "YES"
},
{
"input": "1000000000000000000",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "4",
"output": "NO"
},
{
"input": "474404774",
"output": "NO"
},
{
... | 1,696,516,518 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | n=int(input())
numbers=list(str(n))
luckyNumbers=0
outputValues=" "
for i in numbers:
if i=="4":
luckyNumbers +=1
elif i=="7":
luckyNumbers +=1
if luckyNumbers==4 or luckyNumbers == 7:
outputValues="YES"
else:
outputValues="NO"
print(outputValues)
| Title: Nearly Lucky Number
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
n=int(input())
numbers=list(str(n))
luckyNumbers=0
outputValues=" "
for i in numbers:
if i=="4":
luckyNumbers +=1
elif i=="7":
luckyNumbers +=1
if luckyNumbers==4 or luckyNumbers == 7:
outputValues="YES"
else:
outputValues="NO"
print(outputValues)
``` | 3.977 |
0 | none | none | none | 0 | [
"none"
] | null | null | Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is close... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where:
- *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the co... | Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days, - to write the contest on any two consecutive days. | [
"4\n1 3 2 0\n",
"7\n1 3 3 2 1 2 3\n",
"2\n2 2\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya ca... | 0 | [
{
"input": "4\n1 3 2 0",
"output": "2"
},
{
"input": "7\n1 3 3 2 1 2 3",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "10\n0 0 1 1 0 0 0 0 1 0",
"output": "8"
},
{
"input": "100\n3 2 3 3 3 2 3 1 ... | 1,468,939,640 | 6,140 | PyPy 3 | OK | TESTS | 88 | 139 | 0 | n = int(input())
a = list(map(int,input().split()))
dp = [[10**10] * 3 for i in range(n+1)]
dp[0][0] = 0
dp[0][1] = 0
dp[0][2] = 0
for i in range(1, n+1):
if a[i-1] == 0:
dp[i][0] = min(dp[i-1][0], dp[i-1][1], dp[i-1][2]) + 1
elif a[i-1] == 1:
dp[i][0] = min(dp[i-1][0], dp[i-1][1],... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet... | ```python
n = int(input())
a = list(map(int,input().split()))
dp = [[10**10] * 3 for i in range(n+1)]
dp[0][0] = 0
dp[0][1] = 0
dp[0][2] = 0
for i in range(1, n+1):
if a[i-1] == 0:
dp[i][0] = min(dp[i-1][0], dp[i-1][1], dp[i-1][2]) + 1
elif a[i-1] == 1:
dp[i][0] = min(dp[i-1][0], d... | 3 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,633,575,534 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 156 | 6,963,200 | a=int(input())
b=[]
c=[]
d=[]
for i in range(a):
e=[int(j) for j in input().split()]
b.append(e[0])
c.append(e[1])
d.append(e[2])
if sum(b)==0 and sum(c)==0 and sum(d)==0:
print("YES")
else:
print("NO") | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
a=int(input())
b=[]
c=[]
d=[]
for i in range(a):
e=[int(j) for j in input().split()]
b.append(e[0])
c.append(e[1])
d.append(e[2])
if sum(b)==0 and sum(c)==0 and sum(d)==0:
print("YES")
else:
print("NO")
``` | 3.94803 |
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 palindro... | 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": "... | 1,627,291,133 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 77 | 7,372,800 | s = input()
ss = s[::-1]
print(s+ss) | 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 tr... | ```python
s = input()
ss = s[::-1]
print(s+ss)
``` | 3 | |
779 | A | Pupils Redistribution | PROGRAMMING | 1,000 | [
"constructive algorithms",
"math"
] | null | null | In Berland each high school student is characterized by academic performance — integer value between 1 and 5.
In high school 0xFF there are two groups of pupils: the group *A* and the group *B*. Each group consists of exactly *n* students. An academic performance of each student is known — integer value between 1 and ... | The first line of the input contains integer number *n* (1<=≤<=*n*<=≤<=100) — number of students in both groups.
The second line contains sequence of integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=5), where *a**i* is academic performance of the *i*-th student of the group *A*.
The third line contains se... | Print the required minimum number of exchanges or -1, if the desired distribution of students can not be obtained. | [
"4\n5 4 4 4\n5 5 4 5\n",
"6\n1 1 1 1 1 1\n5 5 5 5 5 5\n",
"1\n5\n3\n",
"9\n3 2 5 5 2 3 3 3 2\n4 1 4 1 1 2 4 4 1\n"
] | [
"1\n",
"3\n",
"-1\n",
"4\n"
] | none | 500 | [
{
"input": "4\n5 4 4 4\n5 5 4 5",
"output": "1"
},
{
"input": "6\n1 1 1 1 1 1\n5 5 5 5 5 5",
"output": "3"
},
{
"input": "1\n5\n3",
"output": "-1"
},
{
"input": "9\n3 2 5 5 2 3 3 3 2\n4 1 4 1 1 2 4 4 1",
"output": "4"
},
{
"input": "1\n1\n2",
"output": "-1"
... | 1,638,849,049 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n=int(input())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
c=[a.count(1),a.count(2),a.count(3),a.count(4),a.count(5)]
d=[b.count(1),b.count(2),b.count(3),b.count(4),b.count(5)]
check,res=1,0
for i in range(5):
if (c[i]+d[i])%2!=0:
check=0
break
else:
if c[i]>=d[i]:... | Title: Pupils Redistribution
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland each high school student is characterized by academic performance — integer value between 1 and 5.
In high school 0xFF there are two groups of pupils: the group *A* and the group *B*. Each group consis... | ```python
n=int(input())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
c=[a.count(1),a.count(2),a.count(3),a.count(4),a.count(5)]
d=[b.count(1),b.count(2),b.count(3),b.count(4),b.count(5)]
check,res=1,0
for i in range(5):
if (c[i]+d[i])%2!=0:
check=0
break
else:
if c... | 0 | |
900 | B | Position in Fraction | PROGRAMMING | 1,300 | [
"math",
"number theory"
] | null | null | You have a fraction . You need to find the first occurrence of digit *c* into decimal notation of the fraction after decimal point. | The first contains three single positive integers *a*, *b*, *c* (1<=≤<=*a*<=<<=*b*<=≤<=105, 0<=≤<=*c*<=≤<=9). | Print position of the first occurrence of digit *c* into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1. | [
"1 2 0\n",
"2 3 7\n"
] | [
"2",
"-1"
] | The fraction in the first example has the following decimal notation: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/896357459a466614a0542f34c9cfb0cef1afc9ed.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The first zero stands on second position.
The fraction in the second example ... | 1,000 | [
{
"input": "1 2 0",
"output": "2"
},
{
"input": "2 3 7",
"output": "-1"
},
{
"input": "1 100000 1",
"output": "5"
},
{
"input": "1 7 7",
"output": "6"
},
{
"input": "99999 100000 8",
"output": "-1"
},
{
"input": "44102 73848 2",
"output": "132"
}... | 1,597,321,610 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 124 | 0 | arr = list(map(int,input().split()))
a = arr[0]
b = arr[1]
c = arr[2]
a = a/b;
a = str(a);
temp, a = map(str, a.split("."))
print(temp, a)
flag = 0;
if(int(a) == 0):
print(1)
elif(len(a) <15):
print(len(a) + 1)
else:
for i in range(len(a)):
if(int(a[i]) == c):
print... | Title: Position in Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a fraction . You need to find the first occurrence of digit *c* into decimal notation of the fraction after decimal point.
Input Specification:
The first contains three single positive integers *a*, *b*, ... | ```python
arr = list(map(int,input().split()))
a = arr[0]
b = arr[1]
c = arr[2]
a = a/b;
a = str(a);
temp, a = map(str, a.split("."))
print(temp, a)
flag = 0;
if(int(a) == 0):
print(1)
elif(len(a) <15):
print(len(a) + 1)
else:
for i in range(len(a)):
if(int(a[i]) == c):
... | 0 | |
214 | B | Hometask | PROGRAMMING | 1,600 | [
"brute force",
"constructive algorithms",
"greedy",
"math"
] | null | null | Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a set of digits, your task is to find the maximum integer that you can mak... | A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100000) — the number of digits in the set. The second line contains *n* digits, the digits are separated by a single space. | On a single line print the answer to the problem. If such number does not exist, then you should print -1. | [
"1\n0\n",
"11\n3 4 5 4 5 3 5 3 4 4 0\n",
"8\n3 2 5 1 5 2 2 3\n"
] | [
"0\n",
"5554443330\n",
"-1\n"
] | In the first sample there is only one number you can make — 0. In the second sample the sought number is 5554443330. In the third sample it is impossible to make the required number. | 1,000 | [
{
"input": "1\n0",
"output": "0"
},
{
"input": "11\n3 4 5 4 5 3 5 3 4 4 0",
"output": "5554443330"
},
{
"input": "8\n3 2 5 1 5 2 2 3",
"output": "-1"
},
{
"input": "12\n5 3 3 3 2 5 5 1 2 1 4 1",
"output": "-1"
},
{
"input": "8\n5 5 4 1 5 5 5 3",
"output": "-1"... | 1,693,165,151 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 101 | 498 | 14,848,000 | n = int(input())
a = sorted(map(int, input().split()), reverse=1)
if a[-1] == 0:
k = sum(a)
l1 = []
l2 = []
F = 1
for i in range(n):
if a[i] % 3 == 1:
l1.append(a[i])
elif a[i] % 3 == 2:
l2.append(a[i])
if k % 3 == 2:
if l2:
... | Title: Hometask
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can ... | ```python
n = int(input())
a = sorted(map(int, input().split()), reverse=1)
if a[-1] == 0:
k = sum(a)
l1 = []
l2 = []
F = 1
for i in range(n):
if a[i] % 3 == 1:
l1.append(a[i])
elif a[i] % 3 == 2:
l2.append(a[i])
if k % 3 == 2:
if l2:
... | 3 | |
626 | C | Block Towers | PROGRAMMING | 1,600 | [
"brute force",
"greedy",
"math",
"number theory"
] | null | null | Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. *n* of the students use pieces made of two blocks and *m* of the students use pieces made of three blocks.
The students don’t want to use too many blocks, but they also want to be ... | The first line of the input contains two space-separated integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=1<=000<=000, *n*<=+<=*m*<=><=0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively. | Print a single integer, denoting the minimum possible height of the tallest tower. | [
"1 3\n",
"3 2\n",
"5 0\n"
] | [
"9\n",
"8\n",
"10\n"
] | In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.
In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and tower... | 1,000 | [
{
"input": "1 3",
"output": "9"
},
{
"input": "3 2",
"output": "8"
},
{
"input": "5 0",
"output": "10"
},
{
"input": "4 2",
"output": "9"
},
{
"input": "0 1000000",
"output": "3000000"
},
{
"input": "1000000 1",
"output": "2000000"
},
{
"in... | 1,455,386,798 | 1,898 | Python 3 | CHALLENGED | CHALLENGES | 6 | 61 | 0 | t2, t3 = list(map(int,input().split(' ')))
left = 2*(t2+t3)-10
right = 3*(t2+t3)+10
while right-left != 1:
guess = int((left+right)/2)
work2 = int(guess/2)-int(guess/6)
work3 = int(guess/3)-int(guess/6)
work6 = int(guess/6)
if max(0,t2-work2)+max(0,t3-work3) <= work6:
right = gues... | Title: Block Towers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. *n* of the students use pieces made of two blocks and *m* of the students use piece... | ```python
t2, t3 = list(map(int,input().split(' ')))
left = 2*(t2+t3)-10
right = 3*(t2+t3)+10
while right-left != 1:
guess = int((left+right)/2)
work2 = int(guess/2)-int(guess/6)
work3 = int(guess/3)-int(guess/6)
work6 = int(guess/6)
if max(0,t2-work2)+max(0,t3-work3) <= work6:
ri... | -1 | |
691 | A | Fashion in Berland | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.
You are given a jacket with *n* buttons. Determine if it is fast... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of buttons on the jacket.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1). The number *a**i*<==<=0 if the *i*-th button is not fastened. Otherwise *a**i*<==<=1. | In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO". | [
"3\n1 0 1\n",
"3\n1 0 0\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "3\n1 0 1",
"output": "YES"
},
{
"input": "3\n1 0 0",
"output": "NO"
},
{
"input": "3\n1 1 0",
"output": "YES"
},
{
"input": "3\n1 1 1",
"output": "NO"
},
{
"input": "3\n0 0 1",
"output": "NO"
},
{
"input": "3\n0 0 0",
"output": "NO"
}... | 1,471,302,280 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 4,608,000 | f = open("testdata.txt")
n=int(f.readline())-1;
bs=f.readline().split(" ")
if(bs==['1']):
print("YES")
elif(bs==['0']):
print("NO")
else:
s=0
for a in bs:
s+=int(a)
if(s!=n):
print("NO")
else:
print("YES") | Title: Fashion in Berland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened,... | ```python
f = open("testdata.txt")
n=int(f.readline())-1;
bs=f.readline().split(" ")
if(bs==['1']):
print("YES")
elif(bs==['0']):
print("NO")
else:
s=0
for a in bs:
s+=int(a)
if(s!=n):
print("NO")
else:
print("YES")
``` | -1 | |
855 | A | Tom Riddle's Diary | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ... | First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list.
Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100. | Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower). | [
"6\ntom\nlucius\nginny\nharry\nginny\nharry\n",
"3\na\na\na\n"
] | [
"NO\nNO\nNO\nNO\nYES\nYES\n",
"NO\nYES\nYES\n"
] | In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* < *i*, which means that answer for *i* = 5 is "YES". | 500 | [
{
"input": "6\ntom\nlucius\nginny\nharry\nginny\nharry",
"output": "NO\nNO\nNO\nNO\nYES\nYES"
},
{
"input": "3\na\na\na",
"output": "NO\nYES\nYES"
},
{
"input": "1\nzn",
"output": "NO"
},
{
"input": "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnb... | 1,617,958,193 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 78 | 0 | i = int(input())
l = []
res = []
while i > 0:
a = input()
i -= 1
if a in l:
res.append('YES')
else:
l.append(a)
res.append('NO')
for e in res:
print(e)
| Title: Tom Riddle's Diary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber ... | ```python
i = int(input())
l = []
res = []
while i > 0:
a = input()
i -= 1
if a in l:
res.append('YES')
else:
l.append(a)
res.append('NO')
for e in res:
print(e)
``` | 3 | |
237 | A | Free Cash | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors.
Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe.
Note that the time is... | Print a single integer — the minimum number of cashes, needed to serve all clients next day. | [
"4\n8 0\n8 10\n8 10\n8 45\n",
"3\n0 12\n10 11\n22 22\n"
] | [
"2\n",
"1\n"
] | In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.
In the second sample all visitors will come in different times, so ... | 500 | [
{
"input": "4\n8 0\n8 10\n8 10\n8 45",
"output": "2"
},
{
"input": "3\n0 12\n10 11\n22 22",
"output": "1"
},
{
"input": "5\n12 8\n15 27\n15 27\n16 2\n19 52",
"output": "2"
},
{
"input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23",
"output": "3"
},
{
"input": "... | 1,662,322,503 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 204,800 | n=int(input())
T=[]
for _ in range(n):
T.append(input())
Max=max(map(T.count,T))
print(Max)
| Title: Free Cash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends l... | ```python
n=int(input())
T=[]
for _ in range(n):
T.append(input())
Max=max(map(T.count,T))
print(Max)
``` | 0 | |
723 | A | The New Year: Meeting Friends | PROGRAMMING | 800 | [
"implementation",
"math",
"sortings"
] | null | null | There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they... | The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. | Print one integer — the minimum total distance the friends need to travel in order to meet together. | [
"7 1 4\n",
"30 20 10\n"
] | [
"6\n",
"20\n"
] | In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | 500 | [
{
"input": "7 1 4",
"output": "6"
},
{
"input": "30 20 10",
"output": "20"
},
{
"input": "1 4 100",
"output": "99"
},
{
"input": "100 1 91",
"output": "99"
},
{
"input": "1 45 100",
"output": "99"
},
{
"input": "1 2 3",
"output": "2"
},
{
"... | 1,679,069,713 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | x = sorted(map(int, input().split()))
meet = sum(x) / len(x)
#print(x, meet)
d = sum(abs(xi - meet) for xi in x)
print(int(d)) | Title: The New Year: Meeting Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ... | ```python
x = sorted(map(int, input().split()))
meet = sum(x) / len(x)
#print(x, meet)
d = sum(abs(xi - meet) for xi in x)
print(int(d))
``` | 0 | |
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... | 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"... | 1,661,104,380 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | def main():
[n, m, a] = [int(x) for x in input().split()]
return((n // -a)*(m // -a))
if __name__ == "__main__":
print(main())
| 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 ... | ```python
def main():
[n, m, a] = [int(x) for x in input().split()]
return((n // -a)*(m // -a))
if __name__ == "__main__":
print(main())
``` | 3.977 |
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 num... | 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,... | 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 ligh... | 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,587,147,923 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 109 | 0 | m,n=map(int,input().split())
c=0
for i in range(m):
a=list(map(int,input().split()))
for i in range(0,2*n,2):
if a[i]==1 or a[i+1]==1:
c+=1
print(c) | 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.
Vital... | ```python
m,n=map(int,input().split())
c=0
for i in range(m):
a=list(map(int,input().split()))
for i in range(0,2*n,2):
if a[i]==1 or a[i+1]==1:
c+=1
print(c)
``` | 3 | |
146 | A | Lucky Ticket | PROGRAMMING | 800 | [
"implementation"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. It... | The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros. | On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). | [
"2\n47\n",
"4\n4738\n",
"4\n4774\n"
] | [
"NO\n",
"NO\n",
"YES\n"
] | In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7).
In the second sample the ticket number is not the lucky number. | 500 | [
{
"input": "2\n47",
"output": "NO"
},
{
"input": "4\n4738",
"output": "NO"
},
{
"input": "4\n4774",
"output": "YES"
},
{
"input": "4\n4570",
"output": "NO"
},
{
"input": "6\n477477",
"output": "YES"
},
{
"input": "6\n777777",
"output": "YES"
},
... | 1,649,914,335 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 92 | 0 | n = int(input())
w = input()
for i in range(n):
if w[i] not in '47':
print("NO")
break
else:
w = list(map(int, list(w)))
if sum(w[:n//2]) == sum(w[n//2:]):
print("YES")
else:
print("NO")
| Title: Lucky Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
n = int(input())
w = input()
for i in range(n):
if w[i] not in '47':
print("NO")
break
else:
w = list(map(int, list(w)))
if sum(w[:n//2]) == sum(w[n//2:]):
print("YES")
else:
print("NO")
``` | 3 | |
733 | B | Parade | PROGRAMMING | 1,100 | [
"math"
] | null | null | Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. The civilian population also poorly understands from which leg recruits beg... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=105) — the number of columns.
The next *n* lines contain the pairs of integers *l**i* and *r**i* (1<=≤<=*l**i*,<=*r**i*<=≤<=500) — the number of soldiers in the *i*-th column which start to march from the left or the right leg respectively. | Print single integer *k* — the number of the column in which soldiers need to change the leg from which they start to march, or 0 if the maximum beauty is already reached.
Consider that columns are numbered from 1 to *n* in the order they are given in the input data.
If there are several answers, print any of them. | [
"3\n5 6\n8 9\n10 3\n",
"2\n6 5\n5 6\n",
"6\n5 9\n1 3\n4 8\n4 5\n23 54\n12 32\n"
] | [
"3\n",
"1\n",
"0\n"
] | In the first example if you don't give the order to change the leg, the number of soldiers, who start to march from the left leg, would equal 5 + 8 + 10 = 23, and from the right leg — 6 + 9 + 3 = 18. In this case the beauty of the parade will equal |23 - 18| = 5.
If you give the order to change the leg to the third co... | 1,000 | [
{
"input": "3\n5 6\n8 9\n10 3",
"output": "3"
},
{
"input": "2\n6 5\n5 6",
"output": "1"
},
{
"input": "6\n5 9\n1 3\n4 8\n4 5\n23 54\n12 32",
"output": "0"
},
{
"input": "2\n500 499\n500 500",
"output": "0"
},
{
"input": "1\n139 252",
"output": "0"
},
{
... | 1,554,023,495 | 695 | Python 3 | OK | TESTS | 40 | 358 | 2,662,400 | n = int(input())
heh = []
ans = 0
LminusR = 0
for i in range(n):
l, r = map(int, input().split())
LminusR += l
LminusR -= r
heh.append(2 * (r - l))
kok = abs(LminusR)
for e in range(n):
i = heh[e]
if abs(LminusR + i) > kok:
kok = abs(LminusR + i)
ans = e + 1
print(ans) | Title: Parade
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should... | ```python
n = int(input())
heh = []
ans = 0
LminusR = 0
for i in range(n):
l, r = map(int, input().split())
LminusR += l
LminusR -= r
heh.append(2 * (r - l))
kok = abs(LminusR)
for e in range(n):
i = heh[e]
if abs(LminusR + i) > kok:
kok = abs(LminusR + i)
ans = e + 1
print(ans)
... | 3 | |
669 | A | Little Artem and Presents | PROGRAMMING | 800 | [
"math"
] | null | null | Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Art... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday. | Print the maximum possible number of times Artem can give presents to Masha. | [
"1\n",
"2\n",
"3\n",
"4\n"
] | [
"1\n",
"1\n",
"2\n",
"3\n"
] | In the first sample, Artem can only give 1 stone to Masha.
In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times.
In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone.
In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and ... | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "3"
},
{
"input": "100",
"output": "67"
},
{
"input": "101",
"output": "67"
},
{
"input": "102",
"output": "68"... | 1,625,135,296 | 2,147,483,647 | PyPy 3 | OK | TESTS | 26 | 108 | 0 | n=int(input())
print((((n*2)+1))//3) | Title: Little Artem and Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wan... | ```python
n=int(input())
print((((n*2)+1))//3)
``` | 3 | |
340 | E | Iahub and Permutations | PROGRAMMING | 2,000 | [
"combinatorics",
"math"
] | null | null | Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotage his research work.
The girl finds an important permutation for the resea... | The first line contains integer *n* (2<=≤<=*n*<=≤<=2000). On the second line, there are *n* integers, representing Iahub's important permutation after Iahubina replaces some values with -1.
It's guaranteed that there are no fixed points in the given permutation. Also, the given sequence contains at least two numbers ... | Output a single integer, the number of ways Iahub could recover his permutation, modulo 1000000007 (109<=+<=7). | [
"5\n-1 -1 4 3 -1\n"
] | [
"2\n"
] | For the first test example there are two permutations with no fixed points are [2, 5, 4, 3, 1] and [5, 1, 4, 3, 2]. Any other permutation would have at least one fixed point. | 3,000 | [
{
"input": "5\n-1 -1 4 3 -1",
"output": "2"
},
{
"input": "8\n2 4 5 3 -1 8 -1 6",
"output": "1"
},
{
"input": "7\n-1 -1 4 -1 7 1 6",
"output": "4"
},
{
"input": "6\n-1 -1 -1 -1 -1 -1",
"output": "265"
},
{
"input": "2\n-1 -1",
"output": "1"
},
{
"input... | 1,522,324,025 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 124 | 7,065,600 | from math import factorial as f
def der(n):
s=0
for i in range(2,n+1):
s+=((-1)**i)/f(i)
return f(n)*s
x=input()
l=[i for i in input().split()]
print(int(der(l.count("-1"))%(1000000007))) | Title: Iahub and Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubin... | ```python
from math import factorial as f
def der(n):
s=0
for i in range(2,n+1):
s+=((-1)**i)/f(i)
return f(n)*s
x=input()
l=[i for i in input().split()]
print(int(der(l.count("-1"))%(1000000007)))
``` | 0 | |
282 | A | Bit++ | PROGRAMMING | 800 | [
"implementation"
] | null | null | The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme.
Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and th... | Print a single integer — the final value of *x*. | [
"1\n++X\n",
"2\nX++\n--X\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "1\n++X",
"output": "1"
},
{
"input": "2\nX++\n--X",
"output": "0"
},
{
"input": "3\n++X\n++X\n++X",
"output": "3"
},
{
"input": "2\n--X\n--X",
"output": "-2"
},
{
"input": "5\n++X\n--X\n++X\n--X\n--X",
"output": "-1"
},
{
"input": "28\nX--\... | 1,697,106,729 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | def execute_bit_program(program):
x = 0 # Initial value of x
for statement in program:
if "++" in statement:
x += 1
elif "--" in statement:
x -= 1
return x
# Example Bit++ program
bit_program = ["++X", "X--", "++X", "--X"]
# Execute the program and print the fina... | Title: Bit++
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ incre... | ```python
def execute_bit_program(program):
x = 0 # Initial value of x
for statement in program:
if "++" in statement:
x += 1
elif "--" in statement:
x -= 1
return x
# Example Bit++ program
bit_program = ["++X", "X--", "++X", "--X"]
# Execute the program and prin... | 0 | |
194 | A | Exams | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.
The author would need to spend too much time and effort to make the sum of his marks strictly more than *k*. That could ha... | The single input line contains space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=250) — the number of exams and the required sum of marks.
It is guaranteed that there exists a way to pass *n* exams in the way that makes the sum of marks equal exactly *k*. | Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal *k*. | [
"4 8\n",
"4 10\n",
"1 3\n"
] | [
"4\n",
"2\n",
"0\n"
] | In the first sample the author has to get a 2 for all his exams.
In the second sample he should get a 3 for two exams and a 2 for two more.
In the third sample he should get a 3 for one exam. | 500 | [
{
"input": "4 8",
"output": "4"
},
{
"input": "4 10",
"output": "2"
},
{
"input": "1 3",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "50 234",
"output": "0"
},
{
"input": "50 100",
"... | 1,601,246,161 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 278 | 0 | n, k = [int(x) for x in input().split(' ')]
ans = min(n - (k - 2 * n), n)
print(ans) | Title: Exams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.
The author would need to spend ... | ```python
n, k = [int(x) for x in input().split(' ')]
ans = min(n - (k - 2 * n), n)
print(ans)
``` | 0 | |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning ... | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he'... | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input":... | 1,692,647,991 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 31 | 0 | a, b = map(int,input().split())
s1 = 0 ; s2 = 0
if a or b != 0 :
s1 = min(a,b)
n = abs(a-b)
if n %2 == 0 :
s2 = n/2
elif n-1%2 == 0 :
s2 = (n-1)//2
print(s1,int(s2)) | Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red... | ```python
a, b = map(int,input().split())
s1 = 0 ; s2 = 0
if a or b != 0 :
s1 = min(a,b)
n = abs(a-b)
if n %2 == 0 :
s2 = n/2
elif n-1%2 == 0 :
s2 = (n-1)//2
print(s1,int(s2))
``` | 0 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,632,628,985 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 6,963,200 | n = int(input())
x = list()
y = list()
z = list()
for i in range(n):
a = input().split()
x.append(int(a[0]))
y.append(int(a[1]))
z.append(int(a[2]))
if sum(x) == 0 and sum(y) == 0 and sum(z) == 0:
print('Yes')
else:
print('NO') | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n = int(input())
x = list()
y = list()
z = list()
for i in range(n):
a = input().split()
x.append(int(a[0]))
y.append(int(a[1]))
z.append(int(a[2]))
if sum(x) == 0 and sum(y) == 0 and sum(z) == 0:
print('Yes')
else:
print('NO')
``` | 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.... | 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... | 1,649,089,509 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | s=input()
t=input()
cnt=0
if len(s)!=len(t):
print("NO")
else:
for i in range(len(s)):
if s[i]==t[len(s)-i-1]:
cnt+=1
else:
continue
if cnt==len(s):
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 pron... | ```python
s=input()
t=input()
cnt=0
if len(s)!=len(t):
print("NO")
else:
for i in range(len(s)):
if s[i]==t[len(s)-i-1]:
cnt+=1
else:
continue
if cnt==len(s):
print("YES")
else:
print("NO")
``` | 3.977 |
299 | B | Ksusha the Squirrel | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1.
Ksusha wants to walk to the end of the road, that is, get to sector *n*. Unfortunately, there are some rocks on the road. We know ... | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=3·105,<=1<=≤<=*k*<=≤<=3·105). The next line contains *n* characters — the description of the road: the *i*-th character equals ".", if the *i*-th sector contains no rocks. Otherwise, it equals "#".
It is guaranteed that the first and the last characters e... | Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes). | [
"2 1\n..\n",
"5 2\n.#.#.\n",
"7 3\n.#.###.\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 1,000 | [
{
"input": "2 1\n..",
"output": "YES"
},
{
"input": "5 2\n.#.#.",
"output": "YES"
},
{
"input": "7 3\n.#.###.",
"output": "NO"
},
{
"input": "2 200\n..",
"output": "YES"
},
{
"input": "2 1\n..",
"output": "YES"
},
{
"input": "2 2\n..",
"output": "Y... | 1,683,208,226 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | (n,k)=map(int,input().split())
l=list(input())
flag=0
for i in range(n):
if l[i:i+k]== ['#']*k:
flag=1
if flag==1: print('no')
else: print('yes') | Title: Ksusha the Squirrel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1.
Ksusha wants to walk to t... | ```python
(n,k)=map(int,input().split())
l=list(input())
flag=0
for i in range(n):
if l[i:i+k]== ['#']*k:
flag=1
if flag==1: print('no')
else: print('yes')
``` | 0 | |
365 | A | Good Number | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*). | The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the number of *k*-good numbers in *a*. | [
"10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n",
"2 1\n1\n10\n"
] | [
"10\n",
"1\n"
] | none | 500 | [
{
"input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560",
"output": "10"
},
{
"input": "2 1\n1\n10",
"output": "1"
},
{
"input": "1 0\n1000000000",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
... | 1,650,583,826 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 30 | 0 | n,k = map(int, input().split())
cnt = 0
for _ in range(n):
idx = 0
for i in sorted(list(input())):
if int(i) != idx: break
idx += 1
else: cnt += 1
print(cnt) | Title: Good Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number eve... | ```python
n,k = map(int, input().split())
cnt = 0
for _ in range(n):
idx = 0
for i in sorted(list(input())):
if int(i) != idx: break
idx += 1
else: cnt += 1
print(cnt)
``` | 0 | |
858 | A | k-rounding | PROGRAMMING | 1,100 | [
"brute force",
"math",
"number theory"
] | null | null | For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375.
W... | The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8). | Print the *k*-rounding of *n*. | [
"375 4\n",
"10000 1\n",
"38101 0\n",
"123456789 8\n"
] | [
"30000\n",
"10000\n",
"38101\n",
"12345678900000000\n"
] | none | 750 | [
{
"input": "375 4",
"output": "30000"
},
{
"input": "10000 1",
"output": "10000"
},
{
"input": "38101 0",
"output": "38101"
},
{
"input": "123456789 8",
"output": "12345678900000000"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "2 0",
"output":... | 1,510,796,968 | 568 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 1,000 | 0 | n,k = input().split()
k=int(k)
n=int(n)
schet=1
while(1):
if(schet*(10**k)%n==0):
print(schet*(10**k))
break
else:
schet+=1 | Title: k-rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000.... | ```python
n,k = input().split()
k=int(k)
n=int(n)
schet=1
while(1):
if(schet*(10**k)%n==0):
print(schet*(10**k))
break
else:
schet+=1
``` | 0 | |
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... | 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"
},
{
... | 1,590,974,094 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 156 | 1,536,000 | def qaqcount(n,s):
total = 0
for i in range(n):
if s[i] == 'Q':
for j in range(i+1,n):
if s[j] == 'A':
for k in range(j+1,n):
if s[k] == 'Q':
total += 1
return total
s = input()
print... | 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"... | ```python
def qaqcount(n,s):
total = 0
for i in range(n):
if s[i] == 'Q':
for j in range(i+1,n):
if s[j] == 'A':
for k in range(j+1,n):
if s[k] == 'Q':
total += 1
return total
s = inpu... | 3 | |
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The ... | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
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. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, o... | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4... | 1,676,172,634 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 9,523,200 | def find(lista,num):
for i in range(len(lista)):
if num==lista[i]:
return i+1
n=int(input())
a=list(map(int, input().split()))
m=int(input())
b=list(map(int, input().split()))
v=0
p=0
for num in b:
ind=find(a,num)
v+=ind
p+=n-ind+1
print(v,p) | Title: Effective Approach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn c... | ```python
def find(lista,num):
for i in range(len(lista)):
if num==lista[i]:
return i+1
n=int(input())
a=list(map(int, input().split()))
m=int(input())
b=list(map(int, input().split()))
v=0
p=0
for num in b:
ind=find(a,num)
v+=ind
p+=n-ind+1
print(v,p)
``` | 0 | |
735 | D | Taxes | PROGRAMMING | 1,600 | [
"math",
"number theory"
] | null | null | Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to *n* (*n*<=≥<=2) burles and the amount of tax he has to pay is calculated as the maximum divisor of *n* (not equal to *n*, of course). For example, if *n*<==<=6 then Funt has to pay 3 burles, while fo... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·109) — the total year income of mr. Funt. | Print one integer — minimum possible number of burles that mr. Funt has to pay as a tax. | [
"4\n",
"27\n"
] | [
"2\n",
"3\n"
] | none | 1,750 | [
{
"input": "4",
"output": "2"
},
{
"input": "27",
"output": "3"
},
{
"input": "3",
"output": "1"
},
{
"input": "5",
"output": "1"
},
{
"input": "10",
"output": "2"
},
{
"input": "2000000000",
"output": "2"
},
{
"input": "26",
"output": ... | 1,599,709,077 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 13 | 140 | 1,331,200 | from sys import *
from math import *
t=int(stdin.readline())
if t%2==0 and t!=2:
print(2)
else:
f=0
for i in range(2,int(sqrt(t))+1):
if t%i==0:
f=1
break
if f==0:
print(1)
else:
print(3) | Title: Taxes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to *n* (*n*<=≥<=2) burles and the amount of tax he has to pay is calculated as the maximum divisor of *n* (not ... | ```python
from sys import *
from math import *
t=int(stdin.readline())
if t%2==0 and t!=2:
print(2)
else:
f=0
for i in range(2,int(sqrt(t))+1):
if t%i==0:
f=1
break
if f==0:
print(1)
else:
print(3)
``` | 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 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"... | 1,625,038,873 | 2,147,483,647 | PyPy 3 | OK | TESTS | 64 | 93 | 0 | try:
s = input()
w1, w2 = s.split()
t = w2[0]
done = False
for i in range(1, len(w1)):
if w1[i] >= t:
done = True
break
print((w1 if not done else w1[:i]) + t)
except Exception as e:
print(e) | 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 fu... | ```python
try:
s = input()
w1, w2 = s.split()
t = w2[0]
done = False
for i in range(1, len(w1)):
if w1[i] >= t:
done = True
break
print((w1 if not done else w1[:i]) + t)
except Exception as e:
print(e)
``` | 3 | |
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* woode... | 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* equal... | 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,607,963,929 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 248 | 0 | n = int(input())
countofopenleft = 0
countofopenright = 0
for _ in range(n):
l,r = input().split()
if l=='1':
countofopenleft +=1
if r=='1':
countofopenright+=1
countofcloseleft = n- countofopenleft
countofcloseright = n - countofopenright
totalmoves = min(countofcloseleft,count... | 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 long... | ```python
n = int(input())
countofopenleft = 0
countofopenright = 0
for _ in range(n):
l,r = input().split()
if l=='1':
countofopenleft +=1
if r=='1':
countofopenright+=1
countofcloseleft = n- countofopenleft
countofcloseright = n - countofopenright
totalmoves = min(countofclose... | 3 | |
922 | A | Cloning Toys | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Imp likes his plush toy a lot.
Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies.
Initially, Imp has only one origina... | The only line contains two integers *x* and *y* (0<=≤<=*x*,<=*y*<=≤<=109) — the number of copies and the number of original toys Imp wants to get (including the initial one). | Print "Yes", if the desired configuration is possible, and "No" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"6 3\n",
"4 2\n",
"1000 1001\n"
] | [
"Yes\n",
"No\n",
"Yes\n"
] | In the first example, Imp has to apply the machine twice to original toys and then twice to copies. | 500 | [
{
"input": "6 3",
"output": "Yes"
},
{
"input": "4 2",
"output": "No"
},
{
"input": "1000 1001",
"output": "Yes"
},
{
"input": "1000000000 999999999",
"output": "Yes"
},
{
"input": "81452244 81452247",
"output": "No"
},
{
"input": "188032448 86524683",... | 1,608,820,598 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 108 | 0 | x,y = map(int,input().split())
if (x-(y-1))%2==0:
print("Yes")
else:
print("No") | Title: Cloning Toys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imp likes his plush toy a lot.
Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applie... | ```python
x,y = map(int,input().split())
if (x-(y-1))%2==0:
print("Yes")
else:
print("No")
``` | 0 | |
368 | B | Sereja and Suffixes | PROGRAMMING | 1,100 | [
"data structures",
"dp"
] | null | null | Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are s... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements.
Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*). | Print *m* lines — on the *i*-th line print the answer to the number *l**i*. | [
"10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n"
] | [
"6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n"
] | none | 1,000 | [
{
"input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1"
},
{
"input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2",
"output": "3\n4\n5"
},
{
"input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4",
"output": "3\n5\n2\n4\n3\n3\... | 1,668,173,696 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 5,632,000 | n,m=map(int, input().split())
lis1=[int(x) for x in input().split()]
for i in range(m):
x=int(input())
lis2=lis1[x-1:]
set2=set(lis2)
lis3=list(set2)
print(len(lis3)) | Title: Sereja and Suffixes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...... | ```python
n,m=map(int, input().split())
lis1=[int(x) for x in input().split()]
for i in range(m):
x=int(input())
lis2=lis1[x-1:]
set2=set(lis2)
lis3=list(set2)
print(len(lis3))
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | You are given an array *a*1,<=*a*2,<=...,<=*a**n* consisting of *n* integers, and an integer *k*. You have to split the array into exactly *k* non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the *k* obtained minimums. What is the maximum possible inte... | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=<=105) — the size of the array *a* and the number of subsegments you have to split the array to.
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (<=-<=109<=<=≤<=<=*a**i*<=≤<=<=109). | Print single integer — the maximum possible integer you can get if you split the array into *k* non-empty subsegments and take maximum of minimums on the subsegments. | [
"5 2\n1 2 3 4 5\n",
"5 1\n-4 -5 -3 -2 -1\n"
] | [
"5\n",
"-5\n"
] | A subsegment [*l*, *r*] (*l* ≤ *r*) of array *a* is the sequence *a*<sub class="lower-index">*l*</sub>, *a*<sub class="lower-index">*l* + 1</sub>, ..., *a*<sub class="lower-index">*r*</sub>.
Splitting of array *a* of *n* elements into *k* subsegments [*l*<sub class="lower-index">1</sub>, *r*<sub class="lower-index... | 0 | [
{
"input": "5 2\n1 2 3 4 5",
"output": "5"
},
{
"input": "5 1\n-4 -5 -3 -2 -1",
"output": "-5"
},
{
"input": "10 2\n10 9 1 -9 -7 -9 3 8 -10 5",
"output": "10"
},
{
"input": "10 4\n-8 -1 2 -3 9 -8 4 -3 5 9",
"output": "9"
},
{
"input": "1 1\n504262064",
"output... | 1,508,056,236 | 1,536 | Python 3 | OK | TESTS | 55 | 233 | 13,619,200 | n,k=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
if k==1:
print (min(a))
elif k>2:
print(max(a))
else:
l1=[0 for i in range(n)]
l2=[0 for j in range(n)]
l1[0]=a[0]
for i in range(1,n):
l1[i]=min(l1[i-1],a[i])
l2[n-2]=a[n-1]
ans=max(l2[n-2],l1... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a*1,<=*a*2,<=...,<=*a**n* consisting of *n* integers, and an integer *k*. You have to split the array into exactly *k* non-empty subsegments. You'll then compute the minimum integer on each subsegment, and ... | ```python
n,k=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
if k==1:
print (min(a))
elif k>2:
print(max(a))
else:
l1=[0 for i in range(n)]
l2=[0 for j in range(n)]
l1[0]=a[0]
for i in range(1,n):
l1[i]=min(l1[i-1],a[i])
l2[n-2]=a[n-1]
ans=max(... | 3 | |
498 | C | Array and Operations | PROGRAMMING | 2,100 | [
"flows",
"graph matchings",
"number theory"
] | null | null | You have written on a piece of paper an array of *n* positive integers *a*[1],<=*a*[2],<=...,<=*a*[*n*] and *m* good pairs of integers (*i*1,<=*j*1),<=(*i*2,<=*j*2),<=...,<=(*i**m*,<=*j**m*). Each good pair (*i**k*,<=*j**k*) meets the following conditions: *i**k*<=+<=*j**k* is an odd number and 1<=≤<=*i**k*<=<<=*j**... | The first line contains two space-separated integers *n*, *m* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=100).
The second line contains *n* space-separated integers *a*[1],<=*a*[2],<=...,<=*a*[*n*] (1<=≤<=*a*[*i*]<=≤<=109) — the description of the array.
The following *m* lines contain the description of good pairs. The *k*-t... | Output the answer for the problem. | [
"3 2\n8 3 8\n1 2\n2 3\n",
"3 2\n8 12 8\n1 2\n2 3\n"
] | [
"0\n",
"2\n"
] | none | 1,000 | [
{
"input": "3 2\n8 3 8\n1 2\n2 3",
"output": "0"
},
{
"input": "3 2\n8 12 8\n1 2\n2 3",
"output": "2"
},
{
"input": "6 4\n35 33 46 58 7 61\n4 5\n3 6\n5 6\n1 6",
"output": "0"
},
{
"input": "10 25\n262144 262144 64 64 16 134217728 32 512 32 8192\n1 2\n3 10\n5 8\n9 10\n2 5\n5 1... | 1,698,339,403 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 43 | 171 | 9,932,800 | L,m=[int(e) for e in input().split()]
def pdd(x):
d={}
i=2
while i*i<=x:
if x%i==0:
d[i]=1
x//=i
while x%i==0:
x//=i
d[i]+=1
i+=1
if x!=1:
d[x]=1
return d
D=[pdd(int(e)) for e in input().split(... | Title: Array and Operations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have written on a piece of paper an array of *n* positive integers *a*[1],<=*a*[2],<=...,<=*a*[*n*] and *m* good pairs of integers (*i*1,<=*j*1),<=(*i*2,<=*j*2),<=...,<=(*i**m*,<=*j**m*). Each good pair (*i**k*... | ```python
L,m=[int(e) for e in input().split()]
def pdd(x):
d={}
i=2
while i*i<=x:
if x%i==0:
d[i]=1
x//=i
while x%i==0:
x//=i
d[i]+=1
i+=1
if x!=1:
d[x]=1
return d
D=[pdd(int(e)) for e in inpu... | 3 | |
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 lik... | 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":... | 1,694,532,373 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n=int(input())
print(n[0]+str(len[n]+n[-1]) | 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 character... | ```python
n=int(input())
print(n[0]+str(len[n]+n[-1])
``` | -1 |
822 | A | I'm bored with life | PROGRAMMING | 800 | [
"implementation",
"math",
"number theory"
] | null | null | Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopo... | The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12). | Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. | [
"4 3\n"
] | [
"6\n"
] | Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6. | 500 | [
{
"input": "4 3",
"output": "6"
},
{
"input": "10 399603090",
"output": "3628800"
},
{
"input": "6 973151934",
"output": "720"
},
{
"input": "2 841668075",
"output": "2"
},
{
"input": "7 415216919",
"output": "5040"
},
{
"input": "3 283733059",
"ou... | 1,682,964,007 | 2,147,483,647 | Python 3 | OK | TESTS | 59 | 46 | 0 | import math
from math import gcd
def find_factorial(a,b):
res = 1
for i in range(1,min(a,b)+1):
res*=i
return res
a,b = list(map(int,input().split()))
x = find_factorial(a,b)
y = find_factorial(a,b)
print(gcd(x,y)) | Title: I'm bored with life
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormi... | ```python
import math
from math import gcd
def find_factorial(a,b):
res = 1
for i in range(1,min(a,b)+1):
res*=i
return res
a,b = list(map(int,input().split()))
x = find_factorial(a,b)
y = find_factorial(a,b)
print(gcd(x,y))
``` | 3 | |
282 | A | Bit++ | PROGRAMMING | 800 | [
"implementation"
] | null | null | The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme.
Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and th... | Print a single integer — the final value of *x*. | [
"1\n++X\n",
"2\nX++\n--X\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "1\n++X",
"output": "1"
},
{
"input": "2\nX++\n--X",
"output": "0"
},
{
"input": "3\n++X\n++X\n++X",
"output": "3"
},
{
"input": "2\n--X\n--X",
"output": "-2"
},
{
"input": "5\n++X\n--X\n++X\n--X\n--X",
"output": "-1"
},
{
"input": "28\nX--\... | 1,699,779,539 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 36 | 62 | 0 | count=0
n=int(input())
for i in range(n):
m=input()
if(m=="X++"):
count+=1
elif(m=="X--"):
count-=1
elif(m=="++X"):
count+=1
elif(m=="--X"):
count-=1
print(count) | Title: Bit++
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ incre... | ```python
count=0
n=int(input())
for i in range(n):
m=input()
if(m=="X++"):
count+=1
elif(m=="X--"):
count-=1
elif(m=="++X"):
count+=1
elif(m=="--X"):
count-=1
print(count)
``` | 3 | |
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "... | 1,678,911,007 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | import numpy as np
n,m=map(int,input().split());a=np.array(list(map(int,input().split())))
a=np.sort(a);c=0
c+=np.sum(a[:m])
print(c*-1) | Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can... | ```python
import numpy as np
n,m=map(int,input().split());a=np.array(list(map(int,input().split())))
a=np.sort(a);c=0
c+=np.sum(a[:m])
print(c*-1)
``` | -1 |
723 | A | The New Year: Meeting Friends | PROGRAMMING | 800 | [
"implementation",
"math",
"sortings"
] | null | null | There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they... | The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. | Print one integer — the minimum total distance the friends need to travel in order to meet together. | [
"7 1 4\n",
"30 20 10\n"
] | [
"6\n",
"20\n"
] | In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | 500 | [
{
"input": "7 1 4",
"output": "6"
},
{
"input": "30 20 10",
"output": "20"
},
{
"input": "1 4 100",
"output": "99"
},
{
"input": "100 1 91",
"output": "99"
},
{
"input": "1 45 100",
"output": "99"
},
{
"input": "1 2 3",
"output": "2"
},
{
"... | 1,689,072,266 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 61 | 0 | def get_min(a,b,c):
a = int(a)
b = int(b)
c = int(c)
lengthA=abs(a-b)+abs(a-c)
lengthB=abs(b-a)+abs(b-c)
lengthC=abs(c-a)+abs(c-b)
return min(lengthA,lengthB,lengthC)
x=input()
a,b,c=x.split()
print(get_min(a,b,c)) | Title: The New Year: Meeting Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ... | ```python
def get_min(a,b,c):
a = int(a)
b = int(b)
c = int(c)
lengthA=abs(a-b)+abs(a-c)
lengthB=abs(b-a)+abs(b-c)
lengthC=abs(c-a)+abs(c-b)
return min(lengthA,lengthB,lengthC)
x=input()
a,b,c=x.split()
print(get_min(a,b,c))
``` | 3 | |
344 | A | Magnets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" posit... | On the single line of the output print the number of groups of magnets. | [
"6\n10\n10\n10\n01\n10\n10\n",
"4\n01\n01\n10\n10\n"
] | [
"3\n",
"2\n"
] | The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | 500 | [
{
"input": "6\n10\n10\n10\n01\n10\n10",
"output": "3"
},
{
"input": "4\n01\n01\n10\n10",
"output": "2"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n01\n10",
"output": "2"
},
{
"input": "2\n10\n10",
"output": "1"
},
{
"input": "3\n10\n01\n10",... | 1,696,863,202 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 11,264,000 | t=int(input())
ar=[]
for _ in range(t):
ar.append(input())
count=0
for i in range(t-1):
if(ar[i]!=ar[i+1]):
count+=1
print(count+1) | Title: Magnets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets... | ```python
t=int(input())
ar=[]
for _ in range(t):
ar.append(input())
count=0
for i in range(t-1):
if(ar[i]!=ar[i+1]):
count+=1
print(count+1)
``` | 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 th... | 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": "chn... | 1,654,785,113 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | s=input()
h=0
t=0
for i in s:
if i.isupper()==True:
h=h+1
if i.islower()==True:
t=t+1
if h>t:
print(s.upper())
else:
print(s.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 ei... | ```python
s=input()
h=0
t=0
for i in s:
if i.isupper()==True:
h=h+1
if i.islower()==True:
t=t+1
if h>t:
print(s.upper())
else:
print(s.lower())
``` | 3.977 |
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 i... | 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"... | 1,624,130,510 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | t = int(input())
x = list(map(int,input().split()))
if (x[0]%2 ==0 and x[1]%2== 0):
indx = 0
for i in x:
indx+=1
if i%2!=0:
print(indx)
elif (x[0]%2!=0 and x[1]%2 !=0):
indx = 0
for i in x:
indx+=1
if i%2==0:
print(i)
... | 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 — t... | ```python
t = int(input())
x = list(map(int,input().split()))
if (x[0]%2 ==0 and x[1]%2== 0):
indx = 0
for i in x:
indx+=1
if i%2!=0:
print(indx)
elif (x[0]%2!=0 and x[1]%2 !=0):
indx = 0
for i in x:
indx+=1
if i%2==0:
pr... | 0 |
858 | E | Tests Renumeration | PROGRAMMING | 2,200 | [
"greedy",
"implementation"
] | null | null | The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website.
Unfortunately, the archive with Olympiad's data is a mess. For example, the files with tests are named arbitrary without any logic.
Vladimir wants to re... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=105) — the number of files with tests.
*n* lines follow, each describing a file with test. Each line has a form of "name_i type_i", where "name_i" is the filename, and "type_i" equals "1", if the *i*-th file contains an example test, and "0" if it contains a re... | In the first line print the minimum number of lines in Vladimir's script file.
After that print the script file, each line should be "move file_1 file_2", where "file_1" is an existing at the moment of this line being run filename, and "file_2" — is a string of digits and small English letters with length from 1 to 6. | [
"5\n01 0\n2 1\n2extra 0\n3 1\n99 0\n",
"2\n1 0\n2 1\n",
"5\n1 0\n11 1\n111 0\n1111 1\n11111 0\n"
] | [
"4\nmove 3 1\nmove 01 5\nmove 2extra 4\nmove 99 3\n",
"3\nmove 1 3\nmove 2 1\nmove 3 2",
"5\nmove 1 5\nmove 11 1\nmove 1111 2\nmove 111 4\nmove 11111 3\n"
] | none | 2,500 | [
{
"input": "5\n01 0\n2 1\n2extra 0\n3 1\n99 0",
"output": "4\nmove 3 1\nmove 01 5\nmove 2extra 4\nmove 99 3"
},
{
"input": "2\n1 0\n2 1",
"output": "3\nmove 1 odt0m5\nmove 2 1\nmove odt0m5 2"
},
{
"input": "5\n1 0\n11 1\n111 0\n1111 1\n11111 0",
"output": "5\nmove 1 5\nmove 11 1\nmov... | 1,505,661,438 | 7,938 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 46 | 0 | n = int(input())
names = []
types = []
samples = 0
c = 0
for i in range(n):
name, type = input().split()
type = int(type)
if type:
samples += 1
names.append(name)
types.append(type)
s_names = list(range(1, samples + 1))
t_names = list(range(samples + 1, n + 1))
console = ... | Title: Tests Renumeration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website.
Unfortunately, the archive with Olympiad's data i... | ```python
n = int(input())
names = []
types = []
samples = 0
c = 0
for i in range(n):
name, type = input().split()
type = int(type)
if type:
samples += 1
names.append(name)
types.append(type)
s_names = list(range(1, samples + 1))
t_names = list(range(samples + 1, n + 1))
... | 0 | |
818 | D | Multicolored Cars | PROGRAMMING | 1,700 | [
"data structures",
"implementation"
] | null | null | Alice and Bob got very bored during a long car trip so they decided to play a game. From the window they can see cars of different colors running past them. Cars are going one after another.
The game rules are like this. Firstly Alice chooses some color *A*, then Bob chooses some color *B* (*A*<=≠<=*B*). After each ca... | The first line contains two integer numbers *n* and *A* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*A*<=≤<=106) – number of cars and the color chosen by Alice.
The second line contains *n* integer numbers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=106) — colors of the cars that Alice and Bob will encounter in the order of their app... | Output such color *B* (1<=≤<=*B*<=≤<=106) that if Bob chooses it then he will win the game. If there are multiple solutions, print any of them. If there is no such color then print -1.
It is guaranteed that if there exists any solution then there exists solution with (1<=≤<=*B*<=≤<=106). | [
"4 1\n2 1 4 2\n",
"5 2\n2 2 4 5 3\n",
"3 10\n1 2 3\n"
] | [
"2\n",
"-1\n",
"4\n"
] | Let's consider availability of colors in the first example:
- *cnt*<sub class="lower-index">2</sub>(*i*) ≥ *cnt*<sub class="lower-index">1</sub>(*i*) for every *i*, and color 2 can be the answer. - *cnt*<sub class="lower-index">4</sub>(2) < *cnt*<sub class="lower-index">1</sub>(2), so color 4 isn't the winning o... | 0 | [
{
"input": "4 1\n2 1 4 2",
"output": "2"
},
{
"input": "5 2\n2 2 4 5 3",
"output": "-1"
},
{
"input": "3 10\n1 2 3",
"output": "4"
},
{
"input": "1 1\n2",
"output": "3"
},
{
"input": "1 2\n2",
"output": "-1"
},
{
"input": "10 6\n8 5 1 6 6 5 10 6 9 8",
... | 1,561,424,542 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 85 | 2,000 | 9,216,000 | n, a = map(int, input().split())
entrada = list(map(int, input().split()))
carros = []
if a in entrada:
carros = entrada[:entrada.index(a)]
else:
carros = entrada
qtd = {}
qtd_alice = 0
for carro in entrada:
if carro not in qtd:
qtd[carro] = 0
qtd[carro] += 1
if carro ==... | Title: Multicolored Cars
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice and Bob got very bored during a long car trip so they decided to play a game. From the window they can see cars of different colors running past them. Cars are going one after another.
The game rules are like t... | ```python
n, a = map(int, input().split())
entrada = list(map(int, input().split()))
carros = []
if a in entrada:
carros = entrada[:entrada.index(a)]
else:
carros = entrada
qtd = {}
qtd_alice = 0
for carro in entrada:
if carro not in qtd:
qtd[carro] = 0
qtd[carro] += 1
i... | 0 | |
545 | C | Woodcutters | PROGRAMMING | 1,500 | [
"dp",
"greedy"
] | null | null | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees.
Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree.
The pairs are given in the order of ascending *x**i*. No two trees are located at the point with t... | Print a single number — the maximum number of trees that you can cut down by the given rules. | [
"5\n1 2\n2 1\n5 10\n10 9\n19 1\n",
"5\n1 2\n2 1\n5 10\n10 9\n20 1\n"
] | [
"3\n",
"4\n"
] | In the first sample you can fell the trees like that:
- fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — ... | 1,750 | [
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n19 1",
"output": "3"
},
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n20 1",
"output": "4"
},
{
"input": "4\n10 4\n15 1\n19 3\n20 1",
"output": "4"
},
{
"input": "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10... | 1,667,284,634 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | N=int(input())
s=[]
d=[]
for i in range(N):
A,B=map(int,input().split())
d.append(A)
s.append([A,A-B,i])
s.append([A+B,A,i])
s.sort()
m=s[0][0]
sum=1
for i in range(1,2*N):
a=d[0]-1
b=d[N-1]+1
if s[i][2]>0:
a=d[s[i][2]-1]
if s[i][2]<N-1:
b=d[s[i][2]+1]
... | Title: Woodcutters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described b... | ```python
N=int(input())
s=[]
d=[]
for i in range(N):
A,B=map(int,input().split())
d.append(A)
s.append([A,A-B,i])
s.append([A+B,A,i])
s.sort()
m=s[0][0]
sum=1
for i in range(1,2*N):
a=d[0]-1
b=d[N-1]+1
if s[i][2]>0:
a=d[s[i][2]-1]
if s[i][2]<N-1:
b=d[s[i... | 0 | |
899 | D | Shovel Sale | PROGRAMMING | 1,800 | [
"constructive algorithms",
"math"
] | null | null | There are *n* shovels in Polycarp's shop. The *i*-th shovel costs *i* burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs.
Visitors are more likely to buy a pair of shovels if their total cost ends with ... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=109) — the number of shovels in Polycarp's shop. | Print the number of pairs of shovels such that their total cost ends with maximum possible number of nines.
Note that it is possible that the largest number of 9s at the end is 0, then you should count all such ways.
It is guaranteed that for every *n*<=≤<=109 the answer doesn't exceed 2·109. | [
"7\n",
"14\n",
"50\n"
] | [
"3\n",
"9\n",
"1\n"
] | In the first example the maximum possible number of nines at the end is one. Polycarp cah choose the following pairs of shovels for that purpose:
- 2 and 7; - 3 and 6; - 4 and 5.
In the second example the maximum number of nines at the end of total cost of two shovels is one. The following pairs of shovels suit Po... | 1,750 | [
{
"input": "7",
"output": "3"
},
{
"input": "14",
"output": "9"
},
{
"input": "50",
"output": "1"
},
{
"input": "999999999",
"output": "499999999"
},
{
"input": "15",
"output": "11"
},
{
"input": "3",
"output": "3"
},
{
"input": "6500",
... | 1,689,441,491 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1689441491.6046774")# 1689441491.604698 | Title: Shovel Sale
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* shovels in Polycarp's shop. The *i*-th shovel costs *i* burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell sh... | ```python
print("_RANDOM_GUESS_1689441491.6046774")# 1689441491.604698
``` | 0 | |
988 | A | Diverse Team | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct.
If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES"... | The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) — the number of students and the size of the team you have to form.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the rating of $i$-th student. | If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct integers from $1$ to $n$ which should be the indices of students in the team you form. All the ratings of the students in the team should be distinct. You may print the indices in any order. If t... | [
"5 3\n15 13 15 15 12\n",
"5 4\n15 13 15 15 12\n",
"4 4\n20 10 40 30\n"
] | [
"YES\n1 2 5 \n",
"NO\n",
"YES\n1 2 3 4 \n"
] | All possible answers for the first example:
- {1 2 5} - {2 3 5} - {2 4 5}
Note that the order does not matter. | 0 | [
{
"input": "5 3\n15 13 15 15 12",
"output": "YES\n1 2 5 "
},
{
"input": "5 4\n15 13 15 15 12",
"output": "NO"
},
{
"input": "4 4\n20 10 40 30",
"output": "YES\n1 2 3 4 "
},
{
"input": "1 1\n1",
"output": "YES\n1 "
},
{
"input": "100 53\n16 17 1 2 27 5 9 9 53 24 17... | 1,624,904,070 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 93 | 0 | #CODE BY YUVRAJ JWALA
m,n=map(int,input().split())
a=list(map(int,input().split()))
b=set(a)
if len(b)==n:
print("YES")
for i in b:
for j in range(len(a)):
if i==a[j]:
print(j+1,end=" ")
break
else:
print("NO")
| Title: Diverse Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct... | ```python
#CODE BY YUVRAJ JWALA
m,n=map(int,input().split())
a=list(map(int,input().split()))
b=set(a)
if len(b)==n:
print("YES")
for i in b:
for j in range(len(a)):
if i==a[j]:
print(j+1,end=" ")
break
else:
print("NO")
``` | 0 | |
234 | C | Weather | PROGRAMMING | 1,300 | [
"dp",
"implementation"
] | null | null | Scientists say a lot about the problems of global warming and cooling of the Earth. Indeed, such natural phenomena strongly influence all life on our planet.
Our hero Vasya is quite concerned about the problems. He decided to try a little experiment and observe how outside daily temperature changes. He hung out a ther... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of days for which Vasya has been measuring the temperature.
The second line contains a sequence of *n* integers *t*1,<=*t*2,<=...,<=*t**n* (|*t**i*|<=≤<=109) — the sequence of temperature values. Numbers *t**i* are separated by single space... | Print a single integer — the answer to the given task. | [
"4\n-1 1 -2 1\n",
"5\n0 -1 1 2 -5\n"
] | [
"1\n",
"2\n"
] | Note to the first sample: there are two ways to change exactly one number so that the sequence met Vasya's condition. You can either replace the first number 1 by any negative number or replace the number -2 by any positive number. | 0 | [
{
"input": "4\n-1 1 -2 1",
"output": "1"
},
{
"input": "5\n0 -1 1 2 -5",
"output": "2"
},
{
"input": "6\n0 0 0 0 0 0",
"output": "6"
},
{
"input": "6\n-1 -2 -3 -4 5 6",
"output": "0"
},
{
"input": "8\n1 2 -1 0 10 2 12 13",
"output": "3"
},
{
"input": "... | 1,620,651,562 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 342 | 15,872,000 | with open('input.txt', 'r') as f:
n = int(f.readline())
g = list(map(int, f.readline().split()))
a = sum(x <= 0 for x in g)
for i in g[:-1]:
a += (i > 0) - (i < 0)
n = min(n, a)
print(n, file=open("output.txt", "w"))
| Title: Weather
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scientists say a lot about the problems of global warming and cooling of the Earth. Indeed, such natural phenomena strongly influence all life on our planet.
Our hero Vasya is quite concerned about the problems. He decided to ... | ```python
with open('input.txt', 'r') as f:
n = int(f.readline())
g = list(map(int, f.readline().split()))
a = sum(x <= 0 for x in g)
for i in g[:-1]:
a += (i > 0) - (i < 0)
n = min(n, a)
print(n, file=open("output.txt", "w"))
``` | 3 | |
278 | A | Circle Line | PROGRAMMING | 800 | [
"implementation"
] | null | null | The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations:
- *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd and the 3-rd station;...- *d**n*<=-<=1 is the distance between the *n*<=-<=1-th and the *n*-th ... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — the number of stations on the circle line. The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d**i*<=≤<=100) — the distances between pairs of neighboring stations. The third line contains two integers *s* and *t* (1<=≤<=*s*,<=*t*<=≤<=*n*) —... | Print a single number — the length of the shortest path between stations number *s* and *t*. | [
"4\n2 3 4 9\n1 3\n",
"4\n5 8 2 100\n4 1\n",
"3\n1 1 1\n3 1\n",
"3\n31 41 59\n1 1\n"
] | [
"5\n",
"15\n",
"1\n",
"0\n"
] | In the first sample the length of path 1 → 2 → 3 equals 5, the length of path 1 → 4 → 3 equals 13.
In the second sample the length of path 4 → 1 is 100, the length of path 4 → 3 → 2 → 1 is 15.
In the third sample the length of path 3 → 1 is 1, the length of path 3 → 2 → 1 is 2.
In the fourth sample the numbers of st... | 500 | [
{
"input": "4\n2 3 4 9\n1 3",
"output": "5"
},
{
"input": "4\n5 8 2 100\n4 1",
"output": "15"
},
{
"input": "3\n1 1 1\n3 1",
"output": "1"
},
{
"input": "3\n31 41 59\n1 1",
"output": "0"
},
{
"input": "5\n16 13 10 30 15\n4 2",
"output": "23"
},
{
"inpu... | 1,411,571,447 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 124 | 0 | #!/usr/bin/env python3
n = int(input())
st = list(map(int, input().split()))
i, j = map(int, input().split())
i -= 1
j -= 1
d = 0
station = []
for x in range(len(st)):
station.append(d)
d = d + st[x]
station.append(d) # last value of st list
if i > j:
i, j = j, i
distance = station[j] - station[i]
print(min(d... | Title: Circle Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations:
- *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd... | ```python
#!/usr/bin/env python3
n = int(input())
st = list(map(int, input().split()))
i, j = map(int, input().split())
i -= 1
j -= 1
d = 0
station = []
for x in range(len(st)):
station.append(d)
d = d + st[x]
station.append(d) # last value of st list
if i > j:
i, j = j, i
distance = station[j] - station[i]
p... | 3 | |
400 | C | Inna and Huge Candy Matrix | PROGRAMMING | 1,500 | [
"implementation",
"math"
] | null | null | Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to *n* from top to bottom and the columns — from 1 to *m*, from left to right. We'll represent the cell on the intersection of the *i*-th row and *j*-th column as... | The first line of the input contains fix integers *n*, *m*, *x*, *y*, *z*, *p* (1<=≤<=*n*,<=*m*<=≤<=109; 0<=≤<=*x*,<=*y*,<=*z*<=≤<=109; 1<=≤<=*p*<=≤<=105).
Each of the following *p* lines contains two integers *x**k*, *y**k* (1<=≤<=*x**k*<=≤<=*n*; 1<=≤<=*y**k*<=≤<=*m*) — the initial coordinates of the *k*-th candy. Tw... | For each of the *p* candies, print on a single line its space-separated new coordinates. | [
"3 3 3 1 1 9\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3\n"
] | [
"1 3\n1 2\n1 1\n2 3\n2 2\n2 1\n3 3\n3 2\n3 1\n"
] | Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix: | 1,500 | [
{
"input": "3 3 3 1 1 9\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3",
"output": "1 3\n1 2\n1 1\n2 3\n2 2\n2 1\n3 3\n3 2\n3 1"
},
{
"input": "5 5 0 0 0 1\n1 4",
"output": "1 4"
},
{
"input": "14 76 376219315 550904689 16684615 24\n11 21\n1 65\n5 25\n14 63\n11 30\n1 19\n5 7\n9 51\n2 49\n1... | 1,394,589,666 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n,m,x,y,z,p=map(int,input().split())
x%=4
y%=2
z%=4
while p>=1:
p-=1
sx,sy=map(int,input().split())
for i in range(0,x):
sx,sy=sy,m-sx+1
if y>0:
sy=m-sy+1
for i in range(0,z):
sx,sy=n-sy+1,sx
print(sx,sy)
| Title: Inna and Huge Candy Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to *n* from top to bottom and the columns — from 1... | ```python
n,m,x,y,z,p=map(int,input().split())
x%=4
y%=2
z%=4
while p>=1:
p-=1
sx,sy=map(int,input().split())
for i in range(0,x):
sx,sy=sy,m-sx+1
if y>0:
sy=m-sy+1
for i in range(0,z):
sx,sy=n-sy+1,sx
print(sx,sy)
``` | 0 | |
556 | A | Case of the Zeros and Ones | PROGRAMMING | 900 | [
"greedy"
] | null | null | Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, an... | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones. | Output the minimum length of the string that may remain after applying the described operations several times. | [
"4\n1100\n",
"5\n01010\n",
"8\n11101111\n"
] | [
"0\n",
"1\n",
"6\n"
] | In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like... | 250 | [
{
"input": "4\n1100",
"output": "0"
},
{
"input": "5\n01010",
"output": "1"
},
{
"input": "8\n11101111",
"output": "6"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "2"
},
{
"input"... | 1,629,661,625 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 77 | 8,294,400 | def solucao(n, string):
l = list(string)
zeros = l.count('0')
ones = l.count('1')
return n - (2 * min(zeros, ones))
n = int(input())
string = input()
print(solucao(n, string)) | Title: Case of the Zeros and Ones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Cons... | ```python
def solucao(n, string):
l = list(string)
zeros = l.count('0')
ones = l.count('1')
return n - (2 * min(zeros, ones))
n = int(input())
string = input()
print(solucao(n, string))
``` | 3 | |
608 | B | Hamming Distance Sum | PROGRAMMING | 1,500 | [
"combinatorics",
"strings"
] | null | null | Genos needs your help. He was asked to solve the following programming problem by Saitama:
The length of some string *s* is denoted |*s*|. The Hamming distance between two strings *s* and *t* of equal length is defined as , where *s**i* is the *i*-th character of *s* and *t**i* is the *i*-th character of *t*. For exam... | The first line of the input contains binary string *a* (1<=≤<=|*a*|<=≤<=200<=000).
The second line of the input contains binary string *b* (|*a*|<=≤<=|*b*|<=≤<=200<=000).
Both strings are guaranteed to consist of characters '0' and '1' only. | Print a single integer — the sum of Hamming distances between *a* and all contiguous substrings of *b* of length |*a*|. | [
"01\n00111\n",
"0011\n0110\n"
] | [
"3\n",
"2\n"
] | For the first sample case, there are four contiguous substrings of *b* of length |*a*|: "00", "01", "11", and "11". The distance between "01" and "00" is |0 - 0| + |1 - 0| = 1. The distance between "01" and "01" is |0 - 0| + |1 - 1| = 0. The distance between "01" and "11" is |0 - 1| + |1 - 1| = 1. Last distance counts ... | 1,000 | [
{
"input": "01\n00111",
"output": "3"
},
{
"input": "0011\n0110",
"output": "2"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "0\n1",
"output": "1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1... | 1,455,974,963 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 921,600 | a=input()
b=input()
i=0
ans=0
while(i<=len(b)-len(a)):
s=b[i:i+len(a)]
h=0
while(h<len(a)):
ans+=abs(int(s[h])-int(a[h]))
h+=1
i+=1
print(ans)
| Title: Hamming Distance Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Genos needs your help. He was asked to solve the following programming problem by Saitama:
The length of some string *s* is denoted |*s*|. The Hamming distance between two strings *s* and *t* of equal length is de... | ```python
a=input()
b=input()
i=0
ans=0
while(i<=len(b)-len(a)):
s=b[i:i+len(a)]
h=0
while(h<len(a)):
ans+=abs(int(s[h])-int(a[h]))
h+=1
i+=1
print(ans)
``` | 0 | |
22 | A | Second Order Statistics | PROGRAMMING | 800 | [
"brute force"
] | A. Second Order Statistics | 2 | 256 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. ... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | [
"4\n1 2 2 -4\n",
"5\n1 2 3 1 1\n"
] | [
"1\n",
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 2 -4",
"output": "1"
},
{
"input": "5\n1 2 3 1 1",
"output": "2"
},
{
"input": "1\n28",
"output": "NO"
},
{
"input": "2\n-28 12",
"output": "12"
},
{
"input": "3\n-83 40 -80",
"output": "-80"
},
{
"input": "8\n93 77 -92 26 21 -48 53 ... | 1,588,511,452 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 186 | 0 | # https://codeforces.com/contest/22/problem/A
n = int(input())
first_min = float('inf')
second_min = float('inf')
for i in map(int, input().split()):
if i < first_min:
first_min, second_min = i, first_min
elif first_min < i < second_min:
second_min = i
print(second_min)
| Title: Second Order Statistics
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statis... | ```python
# https://codeforces.com/contest/22/problem/A
n = int(input())
first_min = float('inf')
second_min = float('inf')
for i in map(int, input().split()):
if i < first_min:
first_min, second_min = i, first_min
elif first_min < i < second_min:
second_min = i
print(second_min... | 0 |
513 | A | Game | PROGRAMMING | 800 | [
"constructive algorithms",
"math"
] | null | null | Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 balls from his box and throw them away. Similarly, the second player can take from 1 to *k*2... | The first line contains four integers *n*1,<=*n*2,<=*k*1,<=*k*2. All numbers in the input are from 1 to 50.
This problem doesn't have subproblems. You will get 3 points for the correct submission. | Output "First" if the first player wins and "Second" otherwise. | [
"2 2 1 2\n",
"2 1 1 1\n"
] | [
"Second\n",
"First\n"
] | Consider the first sample test. Each player has a box with 2 balls. The first player draws a single ball from his box in one move and the second player can either take 1 or 2 balls from his box in one move. No matter how the first player acts, the second player can always win if he plays wisely. | 3 | [
{
"input": "2 2 1 2",
"output": "Second"
},
{
"input": "2 1 1 1",
"output": "First"
},
{
"input": "5 7 4 1",
"output": "Second"
},
{
"input": "5 7 1 4",
"output": "Second"
},
{
"input": "5 7 10 10",
"output": "Second"
},
{
"input": "5 7 1 10",
"out... | 1,593,761,834 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 109 | 0 | n1,n2,k1,k2=map(int,input().split())
if n1>n2:
print("First")
elif n1<n2:
print("Second")
elif n1==n2:
print("Second") | Title: Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 ba... | ```python
n1,n2,k1,k2=map(int,input().split())
if n1>n2:
print("First")
elif n1<n2:
print("Second")
elif n1==n2:
print("Second")
``` | 3 | |
461 | A | Appleman and Toastman | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | 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... | 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 ... | 500 | [
{
"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\... | 1,410,578,969 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 498 | 23,449,600 | n=int(input())
s=input()
x=list()
x=s.split()
y=sorted(x,key=int)
ans=0
for i in range(n):
ans+=int(y[i])*(i+2)
ans-=int(y[n-1])
print(ans)
| Title: Appleman and Toastman
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... | ```python
n=int(input())
s=input()
x=list()
x=s.split()
y=sorted(x,key=int)
ans=0
for i in range(n):
ans+=int(y[i])*(i+2)
ans-=int(y[n-1])
print(ans)
``` | 3 | |
160 | A | Twins | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't w... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. | In the single line print the single number — the minimum needed number of coins. | [
"2\n3 3\n",
"3\n2 1 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't e... | 500 | [
{
"input": "2\n3 3",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "5\n4 2 2 2 2",
"output": "3"
},
{
"input": "7\n1 10 1 2 1 1 1",
"output": "1"
},
{
"input": "5\n3 2 3 3 1",
"output": "3"
... | 1,689,096,792 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | def minimum_coins_to_take(coins):
total_sum = sum(coins)
your_sum = 0
twin_sum = 0
num_coins = 0
coins.sort(reverse=True)
for coin in coins:
your_sum += coin
twin_sum += coins[num_coins + 1] if num_coins + 1 < len(coins) else 0
total_sum -= coin
num_coins += 1
... | Title: Twins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very w... | ```python
def minimum_coins_to_take(coins):
total_sum = sum(coins)
your_sum = 0
twin_sum = 0
num_coins = 0
coins.sort(reverse=True)
for coin in coins:
your_sum += coin
twin_sum += coins[num_coins + 1] if num_coins + 1 < len(coins) else 0
total_sum -= coin
num_co... | -1 | |
0 | none | none | none | 0 | [
"none"
] | null | null | For an array $b$ of length $m$ we define the function $f$ as
where $\oplus$ is [bitwise exclusive OR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
For example, $f(1,2,4,8)=f(1\oplus2,2\oplus4,4\oplus8)=f(3,6,12)=f(3\oplus6,6\oplus12)=f(5,10)=f(5\oplus10)=f(15)=15$
You are given an array $a$ and a few queri... | The first line contains a single integer $n$ ($1 \le n \le 5000$) — the length of $a$.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2^{30}-1$) — the elements of the array.
The third line contains a single integer $q$ ($1 \le q \le 100\,000$) — the number of queries.
Each of the next $... | Print $q$ lines — the answers for the queries. | [
"3\n8 4 1\n2\n2 3\n1 2\n",
"6\n1 2 4 8 16 32\n4\n1 6\n2 5\n3 4\n1 2\n"
] | [
"5\n12\n",
"60\n30\n12\n3\n"
] | In first sample in both queries the maximum value of the function is reached on the subsegment that is equal to the whole segment.
In second sample, optimal segment for first query are $[3,6]$, for second query — $[2,5]$, for third — $[3,4]$, for fourth — $[1,2]$. | 0 | [
{
"input": "3\n8 4 1\n2\n2 3\n1 2",
"output": "5\n12"
},
{
"input": "6\n1 2 4 8 16 32\n4\n1 6\n2 5\n3 4\n1 2",
"output": "60\n30\n12\n3"
}
] | 1,620,099,238 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 93 | 0 | n = int(input())
a = list(map(lambda x: int(x), input().split()))
b = [[0 for j in range(n)] for i in range(n)]
for i in range(n):
b[0][i] = a[i]
for i in range(1, n):
for j in range(n-i):
b[i][j]=b[i-1][j]^b[i-1][j+1]
q = int(input())
for i in range(q):
l, r = input().split()
l... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For an array $b$ of length $m$ we define the function $f$ as
where $\oplus$ is [bitwise exclusive OR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
For example, $f(1,2,4,8)=f(1\oplus2,2\oplus4,4\oplus8)=f(3,6,12)=f(3\op... | ```python
n = int(input())
a = list(map(lambda x: int(x), input().split()))
b = [[0 for j in range(n)] for i in range(n)]
for i in range(n):
b[0][i] = a[i]
for i in range(1, n):
for j in range(n-i):
b[i][j]=b[i-1][j]^b[i-1][j+1]
q = int(input())
for i in range(q):
l, r = input().spli... | 0 | |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,645,871,599 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | #Die roll
a,b = (map(int,input().split()))
total = 6-(max(a,b)+1)
if total == 6:
print('1/1')
elif total == 5:
print('5/6')
elif total == 4:
print('2/3')
elif total == 3:
print('1/2')
elif total == 2:
print('1/3')
elif total == 1:
print('1/6') | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
#Die roll
a,b = (map(int,input().split()))
total = 6-(max(a,b)+1)
if total == 6:
print('1/1')
elif total == 5:
print('5/6')
elif total == 4:
print('2/3')
elif total == 3:
print('1/2')
elif total == 2:
print('1/3')
elif total == 1:
print('1/6')
``` | 0 |
82 | A | Double Cola | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d... | The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | 500 | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"inpu... | 1,532,356,024 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,000 | 44,544,000 | queue = input()
queue = int(queue)
#print(queue)
queue_list = [1,2,3,4,5]
#print(queue_list)
#list_name.pop(order)
counter = 0
counter_mul = 2
for i in range(0,queue):
first = queue_list[0]
queue_list.pop(0)
counter = counter + 1
if counter > 5:
counter = 1
counter_... | Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resultin... | ```python
queue = input()
queue = int(queue)
#print(queue)
queue_list = [1,2,3,4,5]
#print(queue_list)
#list_name.pop(order)
counter = 0
counter_mul = 2
for i in range(0,queue):
first = queue_list[0]
queue_list.pop(0)
counter = counter + 1
if counter > 5:
counter = 1
... | 0 |
344 | A | Magnets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" posit... | On the single line of the output print the number of groups of magnets. | [
"6\n10\n10\n10\n01\n10\n10\n",
"4\n01\n01\n10\n10\n"
] | [
"3\n",
"2\n"
] | The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | 500 | [
{
"input": "6\n10\n10\n10\n01\n10\n10",
"output": "3"
},
{
"input": "4\n01\n01\n10\n10",
"output": "2"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n01\n10",
"output": "2"
},
{
"input": "2\n10\n10",
"output": "1"
},
{
"input": "3\n10\n01\n10",... | 1,691,077,607 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 310 | 7,884,800 | def count_groups(n, magnets):
groups = 1
for i in range(1, n):
if magnets[i] != magnets[i-1]:
groups += 1
return groups
# Read input
n = int(input())
magnets = [input() for _ in range(n)]
# Count the number of groups formed by the magnets
result = count_groups(n, magnets)
... | Title: Magnets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets... | ```python
def count_groups(n, magnets):
groups = 1
for i in range(1, n):
if magnets[i] != magnets[i-1]:
groups += 1
return groups
# Read input
n = int(input())
magnets = [input() for _ in range(n)]
# Count the number of groups formed by the magnets
result = count_groups(n, ... | 3 | |
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... | 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": "... | 1,667,933,990 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 102 | 77 | 0 | f = input()
s = input()
a = ""
for i in range(len(f)):
if int(f[i]) + int(s[i]) == 1:
a += "1"
else:
a += "0"
print(a) | 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 10... | ```python
f = input()
s = input()
a = ""
for i in range(len(f)):
if int(f[i]) + int(s[i]) == 1:
a += "1"
else:
a += "0"
print(a)
``` | 3.98075 |
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 Berl... | 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 thi... | 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 853... | 1,676,464,139 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 46 | 0 | c=int(input())
a = [int (x) for x in input ().split()]
s=0
x=a.sort()
maxx=a[-1]
for w in a:
d=int(maxx)-int(w)
s+=d
print(s) | 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... | ```python
c=int(input())
a = [int (x) for x in input ().split()]
s=0
x=a.sort()
maxx=a[-1]
for w in a:
d=int(maxx)-int(w)
s+=d
print(s)
``` | 3 | |
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... | 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"... | 1,695,554,626 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | import math
n, m, a = map(int, input().split())
width_stones = math.ceil(n / a)
length_stones = math.ceil(m / a)
result = width_stones * length_stones
print(result) | 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 ... | ```python
import math
n, m, a = map(int, input().split())
width_stones = math.ceil(n / a)
length_stones = math.ceil(m / a)
result = width_stones * length_stones
print(result)
``` | 3.977 |
864 | A | Fair Game | PROGRAMMING | 1,000 | [
"implementation",
"sortings"
] | null | null | Petya and Vasya decided to play a game. They have *n* cards (*n* is an even number). A single integer is written on each card.
Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100) — number of cards. It is guaranteed that *n* is an even number.
The following *n* lines contain a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (one integer per line, 1<=≤<=*a**i*<=≤<=100) — numbers written on the *n* cards. | If it is impossible for Petya and Vasya to choose numbers in such a way that the game will be fair, print "NO" (without quotes) in the first line. In this case you should not print anything more.
In the other case print "YES" (without quotes) in the first line. In the second line print two distinct integers — number t... | [
"4\n11\n27\n27\n11\n",
"2\n6\n6\n",
"6\n10\n20\n30\n20\n10\n20\n",
"6\n1\n1\n2\n2\n3\n3\n"
] | [
"YES\n11 27\n",
"NO\n",
"NO\n",
"NO\n"
] | In the first example the game will be fair if, for example, Petya chooses number 11, and Vasya chooses number 27. Then the will take all cards — Petya will take cards 1 and 4, and Vasya will take cards 2 and 3. Thus, each of them will take exactly two cards.
In the second example fair game is impossible because the nu... | 500 | [
{
"input": "4\n11\n27\n27\n11",
"output": "YES\n11 27"
},
{
"input": "2\n6\n6",
"output": "NO"
},
{
"input": "6\n10\n20\n30\n20\n10\n20",
"output": "NO"
},
{
"input": "6\n1\n1\n2\n2\n3\n3",
"output": "NO"
},
{
"input": "2\n1\n100",
"output": "YES\n1 100"
},
... | 1,644,196,423 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 46 | 0 | n = int(input())
a = []
for i in range(n):
a.append(int(input()))
p = 0
v = 0
a = sorted(a)
flag = True
for i in range(n//2):
p = a[i]
v = a[-1]
m = a.count(p)
z = a.count(v)
if m+z != n:
break
if m == z and p != v:
print("YES")
print(f"{p} {v}")
... | Title: Fair Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya decided to play a game. They have *n* cards (*n* is an even number). A single integer is written on each card.
Before the game Petya will choose an integer and after that Vasya will choose another integer (di... | ```python
n = int(input())
a = []
for i in range(n):
a.append(int(input()))
p = 0
v = 0
a = sorted(a)
flag = True
for i in range(n//2):
p = a[i]
v = a[-1]
m = a.count(p)
z = a.count(v)
if m+z != n:
break
if m == z and p != v:
print("YES")
print(f"{p} ... | 3 | |
448 | D | Multiplication Table | PROGRAMMING | 1,800 | [
"binary search",
"brute force"
] | null | null | Bizon the Champion isn't just charming, he also is very smart.
While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an *n*<=×<=*m* multiplication table, where the element on the intersection of the *i*-th row and *j*-th column equals *i*·*j* ... | The single line contains integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=5·105; 1<=≤<=*k*<=≤<=*n*·*m*). | Print the *k*-th largest number in a *n*<=×<=*m* multiplication table. | [
"2 2 2\n",
"2 3 4\n",
"1 10 5\n"
] | [
"2\n",
"3\n",
"5\n"
] | A 2 × 3 multiplication table looks like this: | 2,000 | [
{
"input": "2 2 2",
"output": "2"
},
{
"input": "2 3 4",
"output": "3"
},
{
"input": "1 10 5",
"output": "5"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "10 1 7",
"output": "7"
},
{
"input": "10 10 33",
"output": "14"
},
{
"input": "... | 1,625,997,574 | 2,147,483,647 | Python 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 6 | 1,029 | 268,390,400 | a, b, c = map(int, input().split())
li = [i * j for i in range(1, a + 1) for j in range(1, b + 1)]
li = sorted(li)
print(li[c-1])
| Title: Multiplication Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bizon the Champion isn't just charming, he also is very smart.
While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an *n*<=×<=*m* multi... | ```python
a, b, c = map(int, input().split())
li = [i * j for i in range(1, a + 1) for j in range(1, b + 1)]
li = sorted(li)
print(li[c-1])
``` | 0 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,665,040,661 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 122 | 0 | n = int(input())
x_group = []
y_group = []
z_group = []
for i in range(n):
xi, yi, zi = map(int,input().split())
x_group.append(xi)
y_group.append(yi)
z_group.append(zi)
if sum(x_group) == 0 and sum(y_group) == 0 and sum(z_group) == 0:
print("YES")
else: print("NO") | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n = int(input())
x_group = []
y_group = []
z_group = []
for i in range(n):
xi, yi, zi = map(int,input().split())
x_group.append(xi)
y_group.append(yi)
z_group.append(zi)
if sum(x_group) == 0 and sum(y_group) == 0 and sum(z_group) == 0:
print("YES")
else: print("NO")
``` | 3.9695 |
567 | A | Lineland Mail | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another c... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follo... | Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. | [
"4\n-5 -2 2 7\n",
"2\n-1 1\n"
] | [
"3 12\n3 9\n4 7\n5 12\n",
"2 2\n2 2\n"
] | none | 500 | [
{
"input": "4\n-5 -2 2 7",
"output": "3 12\n3 9\n4 7\n5 12"
},
{
"input": "2\n-1 1",
"output": "2 2\n2 2"
},
{
"input": "3\n-1 0 1",
"output": "1 2\n1 1\n1 2"
},
{
"input": "4\n-1 0 1 3",
"output": "1 4\n1 3\n1 2\n2 4"
},
{
"input": "3\n-1000000000 0 1000000000",
... | 1,648,888,927 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 3,000 | 8,704,000 | import math
n=int(input())
b=input().split()
a=[]
for i in b :
a.append(int(i))
x=[]
for i in a :
v=[]
for l in a :
if i!=l :
v.append(int(math.fabs(i-l)))
x.append((min(v),max(v)))
for b in x :
for i in b :
print(i,end=" ")
print()
| Title: Lineland Mail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love... | ```python
import math
n=int(input())
b=input().split()
a=[]
for i in b :
a.append(int(i))
x=[]
for i in a :
v=[]
for l in a :
if i!=l :
v.append(int(math.fabs(i-l)))
x.append((min(v),max(v)))
for b in x :
for i in b :
print(i,end=" ")
print()
``` | 0 | |
322 | B | Ciel and Flowers | PROGRAMMING | 1,600 | [
"combinatorics",
"math"
] | null | null | Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3... | The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers. | Print the maximal number of bouquets Fox Ciel can make. | [
"3 6 9\n",
"4 4 4\n",
"0 0 0\n"
] | [
"6\n",
"4\n",
"0\n"
] | In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.
In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet. | 1,000 | [
{
"input": "3 6 9",
"output": "6"
},
{
"input": "4 4 4",
"output": "4"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "0 3 6",
"output": "3"
},
{
"input": "7 8 9",
"output": "7"
},
{
"input": "8 8 9",
"output": "8"
},
{
"input": "15 3 9... | 1,624,470,428 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 124 | 0 | r, g, b = [int(x) for x in input().split()]
x = min(r, g, b)
print(x+(r-x)//3+(g-x)//3+(b-x)//3) | Title: Ciel and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red fl... | ```python
r, g, b = [int(x) for x in input().split()]
x = min(r, g, b)
print(x+(r-x)//3+(g-x)//3+(b-x)//3)
``` | 0 | |
230 | B | T-primes | PROGRAMMING | 1,300 | [
"binary search",
"implementation",
"math",
"number theory"
] | null | null | We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not. | The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout st... | Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't. | [
"3\n4 5 6\n"
] | [
"YES\nNO\nNO\n"
] | The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | 500 | [
{
"input": "3\n4 5 6",
"output": "YES\nNO\nNO"
},
{
"input": "2\n48 49",
"output": "NO\nYES"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "NO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO"
},
{
"input": "1\n36",
"output": "NO"
},
{
"input": "1\n999966000289",
"... | 1,697,517,417 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 32 | 2,000 | 14,336,000 | n = int(input())
t = list(map(int,input().split()))
import math
#首先是一个完全平方数
def check_z(n):
y = int(math.sqrt(n))
if y * y == n :
return y
else :
return y * y == n
for prime in t:
yin = check_z(prime)
if yin == False or yin == 1 : #判断是否是完全平方数
print("NO")
... | Title: T-primes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an ar... | ```python
n = int(input())
t = list(map(int,input().split()))
import math
#首先是一个完全平方数
def check_z(n):
y = int(math.sqrt(n))
if y * y == n :
return y
else :
return y * y == n
for prime in t:
yin = check_z(prime)
if yin == False or yin == 1 : #判断是否是完全平方数
print... | 0 | |
78 | A | Haiku | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Haiku | 2 | 256 | Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syll... | The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailin... | Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes). | [
"on codeforces \nbeta round is running\n a rustling of keys \n",
"how many gallons\nof edo s rain did you drink\n cuckoo\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "on codeforces \nbeta round is running\n a rustling of keys ",
"output": "YES"
},
{
"input": "how many gallons\nof edo s rain did you drink\n cuckoo",
"output": "NO"
},
{
"input": " hatsu shigure\n saru mo komino wo\nhoshige nari",
... | 1,592,644,466 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 13 | 216 | 0 | z = q = d = 0
for _ in range(3):
k = input().split(" ")
for i in k:
for x in i:
if x == "a" or x == "i" or x == "e" or x == "o" or x == "u":
d += 1
print("YES" if d == 17 else "NO") | Title: Haiku
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase... | ```python
z = q = d = 0
for _ in range(3):
k = input().split(" ")
for i in k:
for x in i:
if x == "a" or x == "i" or x == "e" or x == "o" or x == "u":
d += 1
print("YES" if d == 17 else "NO")
``` | 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* peopl... | 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"
},
{
"... | 1,687,627,545 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 31 | 0 | n = int(input())
count = 0
for i in range(1,n+1):
p,q = map(int,input().split())
diff = abs(p-q)
if diff >= 2:
count+=1
print(count) | 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 ... | ```python
n = int(input())
count = 0
for i in range(1,n+1):
p,q = map(int,input().split())
diff = abs(p-q)
if diff >= 2:
count+=1
print(count)
``` | 3 | |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,655,869,154 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 92 | 0 | # Author: José Rodolfo (jric2002)
y, w = list(map(int, input().split(" ")))
d = 6
n = d - max(y, w) + 1
i = 2
while (i <= n):
if ((n % i) == 0 and (d % i) == 0):
n = int(n / i)
d = int(d / i)
else:
i += 1
print(n, d, sep="/") | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
# Author: José Rodolfo (jric2002)
y, w = list(map(int, input().split(" ")))
d = 6
n = d - max(y, w) + 1
i = 2
while (i <= n):
if ((n % i) == 0 and (d % i) == 0):
n = int(n / i)
d = int(d / i)
else:
i += 1
print(n, d, sep="/")
``` | 3.954 |
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 i... | 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"... | 1,617,309,761 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 216 | 2,048,000 | n = int(input())
arr = [int(i) for i in input.split()]
odd_count = 0
even_count = 0
for i in range(len(arr)):
current = arr[i]
if current % 2 == 0:
if odd_count < 2:
even_count += 1
else:
print(i + 1)
else:
if even_count < 2:
odd_count += 1
... | 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 — t... | ```python
n = int(input())
arr = [int(i) for i in input.split()]
odd_count = 0
even_count = 0
for i in range(len(arr)):
current = arr[i]
if current % 2 == 0:
if odd_count < 2:
even_count += 1
else:
print(i + 1)
else:
if even_count < 2:
odd_count... | -1 |
112 | A | Petya and Strings | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Petya and Strings | 2 | 256 | Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corr... | Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters. | If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared. | [
"aaaa\naaaA\n",
"abs\nAbz\n",
"abcdefg\nAbCdEfF\n"
] | [
"0\n",
"-1\n",
"1\n"
] | If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site:
- http://en.wikipedia.org/wiki/Lexicographical_order | 500 | [
{
"input": "aaaa\naaaA",
"output": "0"
},
{
"input": "abs\nAbz",
"output": "-1"
},
{
"input": "abcdefg\nAbCdEfF",
"output": "1"
},
{
"input": "asadasdasd\nasdwasdawd",
"output": "-1"
},
{
"input": "aslkjlkasdd\nasdlkjdajwi",
"output": "1"
},
{
"input":... | 1,695,548,723 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 8 | 62 | 0 | alpha_list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u','v', 'w','x','y','z']
word1 = input().lower()
word2 = input().lower()
for i in range(len(word1)):
if word1[i] == word2[i]:
pass
elif alpha_list.index(word1[i]) < alpha_list.index(word2[... | Title: Petya and Strings
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. ... | ```python
alpha_list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u','v', 'w','x','y','z']
word1 = input().lower()
word2 = input().lower()
for i in range(len(word1)):
if word1[i] == word2[i]:
pass
elif alpha_list.index(word1[i]) < alpha_list.in... | -1 |
664 | A | Complicated GCD | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm.
Formally, find the biggest in... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100). | Output one integer — greatest common divisor of all integers from *a* to *b* inclusive. | [
"1 2\n",
"61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n"
] | [
"1\n",
"61803398874989484820458683436563811772030917980576\n"
] | none | 500 | [
{
"input": "1 2",
"output": "1"
},
{
"input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576",
"output": "61803398874989484820458683436563811772030917980576"
},
{
"input": "1 100",
"output": "1"
},
{
"input": "100 100000... | 1,565,960,587 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 124 | 0 | # import sys
# sys.stdin=open("input.in","r")
a,b=map(int,input().split())
print(a if a==b else "1") | Title: Complicated GCD
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find gre... | ```python
# import sys
# sys.stdin=open("input.in","r")
a,b=map(int,input().split())
print(a if a==b else "1")
``` | 3 | |
994 | A | Fingerprints | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subse... | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints.
The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequen... | In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable. | [
"7 3\n3 5 7 1 6 2 8\n1 2 7\n",
"4 4\n3 4 1 0\n0 1 7 9\n"
] | [
"7 1 2\n",
"1 0\n"
] | In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.
In the second example digits $... | 500 | [
{
"input": "7 3\n3 5 7 1 6 2 8\n1 2 7",
"output": "7 1 2"
},
{
"input": "4 4\n3 4 1 0\n0 1 7 9",
"output": "1 0"
},
{
"input": "9 4\n9 8 7 6 5 4 3 2 1\n2 4 6 8",
"output": "8 6 4 2"
},
{
"input": "10 5\n3 7 1 2 4 6 9 0 5 8\n4 3 0 7 9",
"output": "3 7 4 9 0"
},
{
"... | 1,548,804,955 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | n, m = map(int, input().split())
sequence = input().split()
sequence = list(map(int, sequence))
nsequencer = sequence
fingerprints = input().split()
fingerprints = list(map(int, fingerprints))
for i in sequence:
if i in fingerprints:
pass
else:
nsequencer.remove(i)
s = ''
... | Title: Fingerprints
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keyp... | ```python
n, m = map(int, input().split())
sequence = input().split()
sequence = list(map(int, sequence))
nsequencer = sequence
fingerprints = input().split()
fingerprints = list(map(int, fingerprints))
for i in sequence:
if i in fingerprints:
pass
else:
nsequencer.remove(i)
... | 0 | |
855 | A | Tom Riddle's Diary | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ... | First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list.
Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100. | Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower). | [
"6\ntom\nlucius\nginny\nharry\nginny\nharry\n",
"3\na\na\na\n"
] | [
"NO\nNO\nNO\nNO\nYES\nYES\n",
"NO\nYES\nYES\n"
] | In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* < *i*, which means that answer for *i* = 5 is "YES". | 500 | [
{
"input": "6\ntom\nlucius\nginny\nharry\nginny\nharry",
"output": "NO\nNO\nNO\nNO\nYES\nYES"
},
{
"input": "3\na\na\na",
"output": "NO\nYES\nYES"
},
{
"input": "1\nzn",
"output": "NO"
},
{
"input": "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnb... | 1,619,589,091 | 2,147,483,647 | PyPy 3 | OK | TESTS | 55 | 108 | 0 | #C
n = int(input())
alist = []
for a in range(n):
name = str(input())
if name in alist:
print("YES")
else:
print("NO")
alist.append(name)
| Title: Tom Riddle's Diary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber ... | ```python
#C
n = int(input())
alist = []
for a in range(n):
name = str(input())
if name in alist:
print("YES")
else:
print("NO")
alist.append(name)
``` | 3 | |
884 | A | Book Reading | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day. | Print the minimum day Luba can finish reading the book.
It is guaranteed that answer doesn't exceed *n*. | [
"2 2\n86400 86398\n",
"2 86400\n0 86400\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "2 2\n86400 86398",
"output": "2"
},
{
"input": "2 86400\n0 86400",
"output": "1"
},
{
"input": "2 86400\n1 86399",
"output": "2"
},
{
"input": "100 1000000\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... | 1,509,178,692 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 62 | 0 | n, t = map(int, input().split())
a = list(map(int, input().split()))
cnt = t
for i in range(len(a)):
cnt -= 86400 - a[i]
if cnt <= 0:
print(i + 1)
exit()
| Title: Book Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of ... | ```python
n, t = map(int, input().split())
a = list(map(int, input().split()))
cnt = t
for i in range(len(a)):
cnt -= 86400 - a[i]
if cnt <= 0:
print(i + 1)
exit()
``` | 3 | |
21 | A | Jabber ID | PROGRAMMING | 1,900 | [
"implementation",
"strings"
] | A. Jabber ID | 0 | 256 | Jabber ID on the national Berland service «Babber» has a form <username>@<hostname>[/resource], where
- <username> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of <username> is between 1 and 16, inclusive. - <hostname> — is... | The input contains of a single line. The line has the length between 1 and 100 characters, inclusive. Each characters has ASCII-code between 33 and 127, inclusive. | Print YES or NO. | [
"[email protected]\n",
"[email protected]/contest.icpc/12\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "mike@codeforces.com",
"output": "YES"
},
{
"input": "john.smith@codeforces.ru/contest.icpc/12",
"output": "NO"
},
{
"input": "test@test.ri/abacaba",
"output": "YES"
},
{
"input": "@ops",
"output": "NO"
},
{
"input": "this-is-the-test",
"output": "N... | 1,598,988,278 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 139 | 0 | s=str(input())
e=s[0:s.find('@')]
flag=0
if(len(e)>=1 and len(e)<=16):
for i in range(0,len(e)):
if(e[i]>='a' and e[i]<='z' or (e[i]>='A' and e[i]<='Z')):
pass
elif(e[i] in '0123456789' or e[i]=='_'):
pass
else:
flag=1
e=s[s.find('@')+1:s.find('... | Title: Jabber ID
Time Limit: 0 seconds
Memory Limit: 256 megabytes
Problem Description:
Jabber ID on the national Berland service «Babber» has a form <username>@<hostname>[/resource], where
- <username> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «... | ```python
s=str(input())
e=s[0:s.find('@')]
flag=0
if(len(e)>=1 and len(e)<=16):
for i in range(0,len(e)):
if(e[i]>='a' and e[i]<='z' or (e[i]>='A' and e[i]<='Z')):
pass
elif(e[i] in '0123456789' or e[i]=='_'):
pass
else:
flag=1
e=s[s.find('@')+... | 0 |
868 | A | Bark to Unlock | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters.
Mu-mu's enemy Kashtanka wants to unlock Mu-mu's p... | The first line contains two lowercase English letters — the password on the phone.
The second line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of words Kashtanka knows.
The next *n* lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to b... | Print "YES" if Kashtanka can bark several words in a line forming a string containing the password, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"ya\n4\nah\noy\nto\nha\n",
"hp\n2\nht\ntp\n",
"ah\n1\nha\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first example the password is "ya", and Kashtanka can bark "oy" and then "ah", and then "ha" to form the string "oyahha" which contains the password. So, the answer is "YES".
In the second example Kashtanka can't produce a string containing password as a substring. Note that it can bark "ht" and then "tp" produ... | 250 | [
{
"input": "ya\n4\nah\noy\nto\nha",
"output": "YES"
},
{
"input": "hp\n2\nht\ntp",
"output": "NO"
},
{
"input": "ah\n1\nha",
"output": "YES"
},
{
"input": "bb\n4\nba\nab\naa\nbb",
"output": "YES"
},
{
"input": "bc\n4\nca\nba\nbb\ncc",
"output": "YES"
},
{
... | 1,508,141,805 | 2,147,483,647 | Python 3 | OK | TESTS | 90 | 62 | 5,529,600 | p =input()
n =int(input())
arr =[]
for i in range(n):
arr.append(input())
for i in range(n):
for j in range(n):
if p in str(arr[i]+arr[j]):
print ("YES")
exit()
print ("NO") | Title: Bark to Unlock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a passw... | ```python
p =input()
n =int(input())
arr =[]
for i in range(n):
arr.append(input())
for i in range(n):
for j in range(n):
if p in str(arr[i]+arr[j]):
print ("YES")
exit()
print ("NO")
``` | 3 | |
80 | A | Panoramix's Prediction | PROGRAMMING | 800 | [
"brute force"
] | A. Panoramix's Prediction | 2 | 256 | A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t... | The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4. | Print YES, if *m* is the next prime number after *n*, or NO otherwise. | [
"3 5\n",
"7 11\n",
"7 9\n"
] | [
"YES",
"YES",
"NO"
] | none | 500 | [
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
... | 1,583,142,092 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 218 | 307,200 | n,x = map(int,input().split())
i = n
if n == 1 and x == 2:
print("YES")
elif n == 2 and x == 3:
print("YES")
elif n == 3 and x == 5:
print("YES")
elif n == 5 and x == 7:
print("YES")
elif n == 7 and x == 11:
print("YES")
else:
while True:
if i % 2 != 0 and i % 3 != 0 and i ... | Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater t... | ```python
n,x = map(int,input().split())
i = n
if n == 1 and x == 2:
print("YES")
elif n == 2 and x == 3:
print("YES")
elif n == 3 and x == 5:
print("YES")
elif n == 5 and x == 7:
print("YES")
elif n == 7 and x == 11:
print("YES")
else:
while True:
if i % 2 != 0 and i % 3 !... | 0 |
817 | D | Imbalanced Array | PROGRAMMING | 1,900 | [
"data structures",
"divide and conquer",
"dsu",
"sortings"
] | null | null | You are given an array *a* consisting of *n* elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array is the sum of imbalance values of all subsegments of this array.
For example, the imbalance value of ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=106) — size of the array *a*.
The second line contains *n* integers *a*1,<=*a*2... *a**n* (1<=≤<=*a**i*<=≤<=106) — elements of the array. | Print one integer — the imbalance value of *a*. | [
"3\n1 4 1\n"
] | [
"9\n"
] | none | 0 | [
{
"input": "3\n1 4 1",
"output": "9"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "10\n1 4 4 3 5 2 4 2 4 5",
"output": "123"
},
{
"input": "10\n9 6 8 5 5 2 8 9 2 2",
"output": "245"
},
{
"input": "30\n4 5 2 2 5 2 3 4 3 3 2 1 3 4 4 5 3 3 1 5... | 1,527,185,212 | 5,812 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 11 | 2,000 | 12,083,200 | #!/usr/bin/env python3
n = int(input().strip())
ais = list(map(int, input().strip().split()))
tree = [0 for _ in range(4 * n)]
def build(a, tl, tr, v=1):
if tl == tr:
tree[v] = (a[tl], tl)
else:
tm = (tl + tr) // 2
build(a, tl, tm, v + v)
build(a, tm + 1, tr, v + v + 1)
tree[v] = max(tree[v + v], tree[v +... | Title: Imbalanced Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a* consisting of *n* elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array ... | ```python
#!/usr/bin/env python3
n = int(input().strip())
ais = list(map(int, input().strip().split()))
tree = [0 for _ in range(4 * n)]
def build(a, tl, tr, v=1):
if tl == tr:
tree[v] = (a[tl], tl)
else:
tm = (tl + tr) // 2
build(a, tl, tm, v + v)
build(a, tm + 1, tr, v + v + 1)
tree[v] = max(tree[v + v]... | 0 |
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.