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
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,697,050,683
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
0
import sys input = sys.stdin.readline n = int(input()) aa = list(map(int, input().split())) condition = aa[0] * aa[-1] % 4 == 0 for i in range(n): if (condition and aa[i] % 2 == 1) or (not condition and aa[i] % 2 == 0): print(i + 1) break
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t...
```python import sys input = sys.stdin.readline n = int(input()) aa = list(map(int, input().split())) condition = aa[0] * aa[-1] % 4 == 0 for i in range(n): if (condition and aa[i] % 2 == 1) or (not condition and aa[i] % 2 == 0): print(i + 1) break ```
0
294
A
Shaass and Oskols
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i*...
The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100). The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The i...
On the *i*-th line of the output print the number of birds on the *i*-th wire.
[ "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n", "3\n2 4 1\n1\n2 2\n" ]
[ "0\n12\n5\n0\n16\n", "3\n0\n3\n" ]
none
500
[ { "input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6", "output": "0\n12\n5\n0\n16" }, { "input": "3\n2 4 1\n1\n2 2", "output": "3\n0\n3" }, { "input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43", "output": "0\n66\n57\n7\n0" }, { "input": "10\n48 53 10 28 91 56 8...
1,616,854,786
2,147,483,647
Python 3
OK
TESTS
31
124
307,200
n=int(input()) arr=list(map(int,input().split())) m=int(input()) pos=[list(map(int,input().split())) for i in range(m)] for i in range(m): # onLeft=arr[pos[i][0]-1] onLeft=pos[i][1]-1 onRight=arr[pos[i][0]-1]-pos[i][1] arr[pos[i][0]-1]=0 if pos[i][0]-2>=0: arr[pos[i][0]-2]+=onLef...
Title: Shaass and Oskols Time Limit: None seconds Memory Limit: None megabytes Problem Description: Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each...
```python n=int(input()) arr=list(map(int,input().split())) m=int(input()) pos=[list(map(int,input().split())) for i in range(m)] for i in range(m): # onLeft=arr[pos[i][0]-1] onLeft=pos[i][1]-1 onRight=arr[pos[i][0]-1]-pos[i][1] arr[pos[i][0]-1]=0 if pos[i][0]-2>=0: arr[pos[i][0]...
3
157
A
Game Outcome
PROGRAMMING
800
[ "brute force" ]
null
null
Sherlock Holmes and Dr. Watson played some game on a checkered board *n*<=×<=*n* in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the ...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=30). Each of the following *n* lines contain *n* space-separated integers. The *j*-th number on the *i*-th line represents the number on the square that belongs to the *j*-th column and the *i*-th row on the board. All number on the board are integers from 1 to 100.
Print the single number — the number of the winning squares.
[ "1\n1\n", "2\n1 2\n3 4\n", "4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3\n" ]
[ "0\n", "2\n", "6\n" ]
In the first example two upper squares are winning. In the third example three left squares in the both middle rows are winning:
500
[ { "input": "1\n1", "output": "0" }, { "input": "2\n1 2\n3 4", "output": "2" }, { "input": "4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3", "output": "6" }, { "input": "2\n1 1\n1 1", "output": "0" }, { "input": "3\n1 2 3\n4 5 6\n7 8 9", "output": "4" }, { "inpu...
1,542,098,881
2,147,483,647
Python 3
OK
TESTS
49
218
0
n=int(input()) a=list() s1=list() s2=[0 for i in range(n)] for i in range(n): a.append([int(k) for k in input().split()]) s1.append(sum(a[i])) for m in range(n): s2[m]+=a[i][m] x=0 for r in s2: for k in s1: x+=1*(r>k) print(x)
Title: Game Outcome Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sherlock Holmes and Dr. Watson played some game on a checkered board *n*<=×<=*n* in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each s...
```python n=int(input()) a=list() s1=list() s2=[0 for i in range(n)] for i in range(n): a.append([int(k) for k in input().split()]) s1.append(sum(a[i])) for m in range(n): s2[m]+=a[i][m] x=0 for r in s2: for k in s1: x+=1*(r>k) print(x) ```
3
79
B
Colorful Field
PROGRAMMING
1,400
[ "implementation", "sortings" ]
B. Colorful Field
2
256
Fox Ciel saw a large field while she was on a bus. The field was a *n*<=×<=*m* rectangle divided into 1<=×<=1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in f...
In the first line there are four positive integers *n*,<=*m*,<=*k*,<=*t* (1<=≤<=*n*<=≤<=4·104,<=1<=≤<=*m*<=≤<=4·104,<=1<=≤<=*k*<=≤<=103,<=1<=≤<=*t*<=≤<=103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in ...
For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes.
[ "4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1\n" ]
[ "Waste\nGrapes\nCarrots\nKiwis\nCarrots\nCarrots\n" ]
The sample corresponds to the figure in the statement.
1,000
[ { "input": "4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1", "output": "Waste\nGrapes\nCarrots\nKiwis\nCarrots\nCarrots" }, { "input": "2 3 2 2\n1 1\n2 2\n2 1\n2 2", "output": "Grapes\nWaste" }, { "input": "31 31 31 4\n4 9\n16 27\n11 29\n8 28\n11 2\n10 7\n22 6\n1 25\n14 8...
1,598,895,481
2,147,483,647
Python 3
OK
TESTS
29
622
307,200
n, m, k, t = map(int, input().split()) def index(l, r): return ((l)*m)+(r) k_list = [] d = {0:'Carrots', 1:'Kiwis', 2:'Grapes'} for i in range(k): l, r = map(int, input().split()) k_list.append((l-1, r-1)) k_list.sort() for i in range(t): cnt = 0 l, r = map(int, input().split()) l-=1...
Title: Colorful Field Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Fox Ciel saw a large field while she was on a bus. The field was a *n*<=×<=*m* rectangle divided into 1<=×<=1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. ...
```python n, m, k, t = map(int, input().split()) def index(l, r): return ((l)*m)+(r) k_list = [] d = {0:'Carrots', 1:'Kiwis', 2:'Grapes'} for i in range(k): l, r = map(int, input().split()) k_list.append((l-1, r-1)) k_list.sort() for i in range(t): cnt = 0 l, r = map(int, input().split())...
3.843928
490
A
Team Olympiad
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*: - *t**i*<==<=1, if the *i*-th child is good at prog...
The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child.
In the first line output integer *w* — the largest possible number of teams. Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to...
[ "7\n1 3 1 3 2 1 2\n", "4\n2 1 1 2\n" ]
[ "2\n3 5 2\n6 7 4\n", "0\n" ]
none
500
[ { "input": "7\n1 3 1 3 2 1 2", "output": "2\n3 5 2\n6 7 4" }, { "input": "4\n2 1 1 2", "output": "0" }, { "input": "1\n2", "output": "0" }, { "input": "2\n3 1", "output": "0" }, { "input": "3\n2 1 2", "output": "0" }, { "input": "3\n1 2 3", "output...
1,680,964,216
2,147,483,647
Python 3
OK
TESTS
41
202
0
n = int(input()) lst = list(map(int, input().split())) one = lst.count(1) two = lst.count(2) three = lst.count(3) teams = min(one, two, three) print(teams) for i in range(teams): idx1 = lst.index(1) idx2 = lst.index(2) idx3 = lst.index(3) print(idx1+1, idx2+1, idx3+1) lst[idx1] = -1 lst[idx2] =...
Title: Team Olympiad Time Limit: None seconds Memory Limit: None megabytes Problem Description: The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education)...
```python n = int(input()) lst = list(map(int, input().split())) one = lst.count(1) two = lst.count(2) three = lst.count(3) teams = min(one, two, three) print(teams) for i in range(teams): idx1 = lst.index(1) idx2 = lst.index(2) idx3 = lst.index(3) print(idx1+1, idx2+1, idx3+1) lst[idx1] = -1 l...
3
0
none
none
none
0
[ "none" ]
null
null
Some time ago Mister B detected a strange signal from the space, which he started to study. After some transformation the signal turned out to be a permutation *p* of length *n* or its cyclic shift. For the further investigation Mister B need some basis, that's why he decided to choose cyclic shift of this permutation...
First line contains single integer *n* (2<=≤<=*n*<=≤<=106) — the length of the permutation. The second line contains *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the elements of the permutation. It is guaranteed that all elements are distinct.
Print two integers: the minimum deviation of cyclic shifts of permutation *p* and the id of such shift. If there are multiple solutions, print any of them.
[ "3\n1 2 3\n", "3\n2 3 1\n", "3\n3 2 1\n" ]
[ "0 0\n", "0 1\n", "2 1\n" ]
In the first sample test the given permutation *p* is the identity permutation, that's why its deviation equals to 0, the shift id equals to 0 as well. In the second sample test the deviation of *p* equals to 4, the deviation of the 1-st cyclic shift (1, 2, 3) equals to 0, the deviation of the 2-nd cyclic shift (3, 1,...
0
[ { "input": "3\n1 2 3", "output": "0 0" }, { "input": "3\n2 3 1", "output": "0 1" }, { "input": "3\n3 2 1", "output": "2 1" }, { "input": "2\n1 2", "output": "0 0" }, { "input": "2\n2 1", "output": "0 1" }, { "input": "10\n10 1 9 2 8 3 7 4 6 5", "ou...
1,498,580,441
6,341
Python 3
WRONG_ANSWER
PRETESTS
5
46
5,529,600
n=int(input()) data=list(map(int,input().split())) ans=temp=c=0 for i in range(n): temp+=data[i]-i-1 if temp>ans: ans=temp c=i+1 shift=n-c shift%=n data=data[n-shift:]+data[:n-shift] sum=0 for i,item in enumerate(data): sum+=abs(item-i-1) print(sum, shift)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some time ago Mister B detected a strange signal from the space, which he started to study. After some transformation the signal turned out to be a permutation *p* of length *n* or its cyclic shift. For the further investigation ...
```python n=int(input()) data=list(map(int,input().split())) ans=temp=c=0 for i in range(n): temp+=data[i]-i-1 if temp>ans: ans=temp c=i+1 shift=n-c shift%=n data=data[n-shift:]+data[:n-shift] sum=0 for i,item in enumerate(data): sum+=abs(item-i-1) print(sum, shift) ```
0
148
A
Insomnia cure
PROGRAMMING
800
[ "constructive algorithms", "implementation", "math" ]
null
null
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and ...
Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105).
Output the number of damaged dragons.
[ "1\n2\n3\n4\n12\n", "2\n3\n4\n5\n24\n" ]
[ "12\n", "17\n" ]
In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough. In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed.
1,000
[ { "input": "1\n2\n3\n4\n12", "output": "12" }, { "input": "2\n3\n4\n5\n24", "output": "17" }, { "input": "1\n1\n1\n1\n100000", "output": "100000" }, { "input": "10\n9\n8\n7\n6", "output": "0" }, { "input": "8\n4\n4\n3\n65437", "output": "32718" }, { "i...
1,698,347,119
2,147,483,647
PyPy 3-64
OK
TESTS
40
154
17,817,600
k = int(input()) l = int(input()) m = int(input()) n = int(input()) d = int(input()) k = [i for i in range(0, d + 1, k)] l = [i for i in range(0, d + 1, l)] m = [i for i in range(0, d + 1, m)] n = [i for i in range(0, d + 1, n)] hit1 = k + l + m + n hit1 = set(hit1) print(len(hit1)-1)
Title: Insomnia cure Time Limit: None seconds Memory Limit: None megabytes Problem Description: «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entert...
```python k = int(input()) l = int(input()) m = int(input()) n = int(input()) d = int(input()) k = [i for i in range(0, d + 1, k)] l = [i for i in range(0, d + 1, l)] m = [i for i in range(0, d + 1, m)] n = [i for i in range(0, d + 1, n)] hit1 = k + l + m + n hit1 = set(hit1) print(len(hit1)-1) ```
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,023,703
2,147,483,647
Python 3
OK
TESTS
36
46
0
t,sum = int(input()),0 for i in range(t): s = input() if s[1]=='+': sum=sum+1 elif s[1]=='-': sum=sum-1 print(sum)
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 t,sum = int(input()),0 for i in range(t): s = input() if s[1]=='+': sum=sum+1 elif s[1]=='-': sum=sum-1 print(sum) ```
3
327
A
Flipping Game
PROGRAMMING
1,200
[ "brute force", "dp", "implementation" ]
null
null
Iahub got bored, so he invented a game to be played on paper. He writes *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices *i* and *j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) and flips all values *a**k* for which their positions are in...
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100). In the second line of the input there are *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. It is guaranteed that each of those *n* values is either 0 or 1.
Print an integer — the maximal number of 1s that can be obtained after exactly one move.
[ "5\n1 0 0 1 0\n", "4\n1 0 0 1\n" ]
[ "4\n", "4\n" ]
In the first case, flip the segment from 2 to 5 (*i* = 2, *j* = 5). That flip changes the sequence, it becomes: [1 1 1 0 1]. So, it contains four ones. There is no way to make the whole sequence equal to [1 1 1 1 1]. In the second case, flipping only the second and the third element (*i* = 2, *j* = 3) will turn all nu...
500
[ { "input": "5\n1 0 0 1 0", "output": "4" }, { "input": "4\n1 0 0 1", "output": "4" }, { "input": "1\n1", "output": "0" }, { "input": "1\n0", "output": "1" }, { "input": "8\n1 0 0 0 1 0 0 0", "output": "7" }, { "input": "18\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
1,697,402,037
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
154
0
def replace_max_cons_zeros(n,arr): max_range = [0,0] l = 0 for r in range(n): if arr[r] == 1: l = r+1 else: max_range = [l,r] if max_range[1] - max_range[0] < r-l else max_range # return arr return max_range def find_max_cons_ones(n,arr): range_changed = replace_max_cons_zeros(n,arr) ...
Title: Flipping Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub got bored, so he invented a game to be played on paper. He writes *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices *...
```python def replace_max_cons_zeros(n,arr): max_range = [0,0] l = 0 for r in range(n): if arr[r] == 1: l = r+1 else: max_range = [l,r] if max_range[1] - max_range[0] < r-l else max_range # return arr return max_range def find_max_cons_ones(n,arr): range_changed = replace_max_cons_zer...
0
185
A
Plant
PROGRAMMING
1,300
[ "math" ]
null
null
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divide...
The first line contains a single integer *n* (0<=≤<=*n*<=≤<=1018) — the number of full years when the plant grew. 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.
Print a single integer — the remainder of dividing the number of plants that will point "upwards" in *n* years by 1000000007 (109<=+<=7).
[ "1\n", "2\n" ]
[ "3\n", "10\n" ]
The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.
500
[ { "input": "1", "output": "3" }, { "input": "2", "output": "10" }, { "input": "385599124", "output": "493875375" }, { "input": "989464295", "output": "31966163" }, { "input": "376367012", "output": "523204186" }, { "input": "529357306", "output": "...
1,620,829,463
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
124
6,656,000
import math n=int(input()) #n,m = map(int, input().strip().split(' ')) #d = list(map(int, input().strip().split(' '))) if n==1: print(3) else: print(pow(3,n,1000000007)+pow(pow(3,n-2,1000000008),2,1000000007))
Title: Plant Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will poi...
```python import math n=int(input()) #n,m = map(int, input().strip().split(' ')) #d = list(map(int, input().strip().split(' '))) if n==1: print(3) else: print(pow(3,n,1000000007)+pow(pow(3,n-2,1000000008),2,1000000007)) ```
0
731
A
Night at the Museum
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character...
The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.
Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.
[ "zeus\n", "map\n", "ares\n" ]
[ "18\n", "35\n", "34\n" ]
To print the string from the first sample it would be optimal to perform the following sequence of rotations: 1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
500
[ { "input": "zeus", "output": "18" }, { "input": "map", "output": "35" }, { "input": "ares", "output": "34" }, { "input": "l", "output": "11" }, { "input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv", "...
1,669,659,725
2,147,483,647
PyPy 3
OK
TESTS
44
124
0
s=input() ans=0 i='a' for c in s: l=abs(ord(c)-ord(i)) ans=ans+min(l,26-l) i=c print(ans)
Title: Night at the Museum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devis...
```python s=input() ans=0 i='a' for c in s: l=abs(ord(c)-ord(i)) ans=ans+min(l,26-l) i=c print(ans) ```
3
980
A
Links and Pearls
PROGRAMMING
900
[ "implementation", "math" ]
null
null
A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one. You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times as you l...
The only line of input contains a string $s$ ($3 \leq |s| \leq 100$), representing the necklace, where a dash '-' represents a link and the lowercase English letter 'o' represents a pearl.
Print "YES" if the links and pearls can be rejoined such that the number of links between adjacent pearls is equal. Otherwise print "NO". You can print each letter in any case (upper or lower).
[ "-o-o--", "-o---\n", "-o---o-\n", "ooo\n" ]
[ "YES", "YES", "NO", "YES\n" ]
none
500
[ { "input": "-o-o--", "output": "YES" }, { "input": "-o---", "output": "YES" }, { "input": "-o---o-", "output": "NO" }, { "input": "ooo", "output": "YES" }, { "input": "---", "output": "YES" }, { "input": "--o-o-----o----o--oo-o-----ooo-oo---o--", "...
1,525,876,075
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
4
62
7,065,600
l = list(input()) if l.count('-')%l.count('o')==0: print("YES") elif l.count('o')==0: print("YES") else: print("NO")
Title: Links and Pearls Time Limit: None seconds Memory Limit: None megabytes Problem Description: A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one. You can remove a link or a pearl and insert it between two other existing links or pearl...
```python l = list(input()) if l.count('-')%l.count('o')==0: print("YES") elif l.count('o')==0: print("YES") else: print("NO") ```
-1
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,532,854,364
2,147,483,647
Python 3
OK
TESTS
32
248
0
n = int(input()) num_list = list(map(int, input().split())) parity = 0 even = 0 odd = 0 for i in range(3): if num_list[i] % 2 == 1: odd += 1 else: even += 1 if odd < even: parity = 1 i = 0 while num_list[i] % 2 != parity: i += 1 print(i + 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()) num_list = list(map(int, input().split())) parity = 0 even = 0 odd = 0 for i in range(3): if num_list[i] % 2 == 1: odd += 1 else: even += 1 if odd < even: parity = 1 i = 0 while num_list[i] % 2 != parity: i += 1 print(i + 1) ```
3.938
821
A
Okabe and Future Gadget Laboratory
PROGRAMMING
800
[ "implementation" ]
null
null
Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an *n* by *n* square grid of integers. A good lab is defined as a lab in which every number not equal to 1 can be expressed as the sum of a number in the same row and a number in the same column. ...
The first line of input contains the integer *n* (1<=≤<=*n*<=≤<=50) — the size of the lab. The next *n* lines contain *n* space-separated integers denoting a row of the grid. The *j*-th integer in the *i*-th row is *a**i*,<=*j* (1<=≤<=*a**i*,<=*j*<=≤<=105).
Print "Yes" if the given lab is good and "No" otherwise. You can output each letter in upper or lower case.
[ "3\n1 1 2\n2 3 1\n6 4 1\n", "3\n1 5 2\n1 1 1\n1 2 3\n" ]
[ "Yes\n", "No\n" ]
In the first sample test, the 6 in the bottom left corner is valid because it is the sum of the 2 above it and the 4 on the right. The same holds for every number not equal to 1 in this table, so the answer is "Yes". In the second sample test, the 5 cannot be formed as the sum of an integer in the same row and an inte...
500
[ { "input": "3\n1 1 2\n2 3 1\n6 4 1", "output": "Yes" }, { "input": "3\n1 5 2\n1 1 1\n1 2 3", "output": "No" }, { "input": "1\n1", "output": "Yes" }, { "input": "4\n1 1 1 1\n1 11 1 2\n2 5 1 4\n3 9 4 1", "output": "Yes" }, { "input": "4\n1 1 1 1\n1 7 1 1\n1 3 1 2\n2...
1,499,462,103
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
78
23,142,400
n = int(input()) lab = [[int(i) for i in input().split()] for j in range(n)] def check(lab,x,y,n): rowcheck = lab[y][:x]+lab[y][x+1:] colcheck = [lab[i][x] for i in range(n) if i !=y] sums = [rowcheck[s]+colcheck[t] for s in range(n-1) for t in range(n-1)] if lab[y][x] in sums: return T...
Title: Okabe and Future Gadget Laboratory Time Limit: None seconds Memory Limit: None megabytes Problem Description: Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an *n* by *n* square grid of integers. A good lab is defined as a lab in whi...
```python n = int(input()) lab = [[int(i) for i in input().split()] for j in range(n)] def check(lab,x,y,n): rowcheck = lab[y][:x]+lab[y][x+1:] colcheck = [lab[i][x] for i in range(n) if i !=y] sums = [rowcheck[s]+colcheck[t] for s in range(n-1) for t in range(n-1)] if lab[y][x] in sums: ...
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,671,795,399
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
1
31
0
n,m,a=input().split() n=int(n) m=int(m) a=int(a) if n%a==0 and m%a==0: print((int(n/a)))*((int(m/a))) elif n%a!=0 and m%a!=0: print((int(n/a)+1)*(int(m/a)+1)) elif n%a!=0 and m%a==0: print((int(n/a)+1))*(int(m/a)) elif n%a==0 and m%a!=0: print((int(n/a))*(int(m/a)+1))
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 n,m,a=input().split() n=int(n) m=int(m) a=int(a) if n%a==0 and m%a==0: print((int(n/a)))*((int(m/a))) elif n%a!=0 and m%a!=0: print((int(n/a)+1)*(int(m/a)+1)) elif n%a!=0 and m%a==0: print((int(n/a)+1))*(int(m/a)) elif n%a==0 and m%a!=0: print((int(n/a))*(int(m/a)+1)) ```
-1
472
A
Design Tutorial: Learn from Math
PROGRAMMING
800
[ "math", "number theory" ]
null
null
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two ...
The only line contains an integer *n* (12<=≤<=*n*<=≤<=106).
Output two composite integers *x* and *y* (1<=&lt;<=*x*,<=*y*<=&lt;<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them.
[ "12\n", "15\n", "23\n", "1000000\n" ]
[ "4 8\n", "6 9\n", "8 15\n", "500000 500000\n" ]
In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well. In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
500
[ { "input": "12", "output": "4 8" }, { "input": "15", "output": "6 9" }, { "input": "23", "output": "8 15" }, { "input": "1000000", "output": "500000 500000" }, { "input": "63874", "output": "4 63870" }, { "input": "14568", "output": "4 14564" }, ...
1,680,843,181
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
31
0
n=int(input()) if n%2==0: x=n/2 y=n-x print(int(x),int(y),sep=" ") else: n%3==0 x=n/3 y=n-x print(int(x),int(y),sep=" ")
Title: Design Tutorial: Learn from Math Time Limit: None seconds Memory Limit: None megabytes Problem Description: One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statemen...
```python n=int(input()) if n%2==0: x=n/2 y=n-x print(int(x),int(y),sep=" ") else: n%3==0 x=n/3 y=n-x print(int(x),int(y),sep=" ") ```
0
706
B
Interesting drink
PROGRAMMING
1,100
[ "binary search", "dp", "implementation" ]
null
null
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins. Vasiliy plans to buy his favorite ...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink. The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop. The third line contains a single i...
Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day.
[ "5\n3 10 8 6 11\n4\n1\n10\n3\n11\n" ]
[ "0\n4\n1\n5\n" ]
On the first day, Vasiliy won't be able to buy a drink in any of the shops. On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4. On the third day, Vasiliy can buy a drink only in the shop number 1. Finally, on the last day Vasiliy can buy a drink in any shop.
1,000
[ { "input": "5\n3 10 8 6 11\n4\n1\n10\n3\n11", "output": "0\n4\n1\n5" }, { "input": "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471", "output": "2\n2\n3\n4\n0\n4\n3\n1\n2\n2" }, { "input": "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521", "output": "...
1,692,613,431
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
def binary_search(prices, coins): lo, hi = 0, len(prices) - 1 while lo <= hi: mid = (lo + hi) // 2 if prices[mid] <= coins: lo = mid + 1 else: hi = mid - 1 return lo shops = int(input()) prices = sorted(list(map(int, input().split()))) days = in...
Title: Interesting drink Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known tha...
```python def binary_search(prices, coins): lo, hi = 0, len(prices) - 1 while lo <= hi: mid = (lo + hi) // 2 if prices[mid] <= coins: lo = mid + 1 else: hi = mid - 1 return lo shops = int(input()) prices = sorted(list(map(int, input().split()))) ...
0
893
C
Rumor
PROGRAMMING
1,300
[ "dfs and similar", "graphs", "greedy" ]
null
null
Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it. Now he tries to solve a quest. The task is to come to a settlement named Ove...
The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends. The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor. ...
Print one number — the minimum amount of gold Vova has to spend in order to finish the quest.
[ "5 2\n2 5 3 4 8\n1 4\n4 5\n", "10 0\n1 2 3 4 5 6 7 8 9 10\n", "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n" ]
[ "10\n", "55\n", "15\n" ]
In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor. In the second example Vova has to bribe everyone. In the third example ...
0
[ { "input": "5 2\n2 5 3 4 8\n1 4\n4 5", "output": "10" }, { "input": "10 0\n1 2 3 4 5 6 7 8 9 10", "output": "55" }, { "input": "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10", "output": "15" }, { "input": "1 0\n0", "output": "0" }, { "input": "1 0\n10000000...
1,617,960,557
2,147,483,647
Python 3
OK
TESTS
46
577
11,059,200
R = lambda:map(int,input().split()) n,m = R() pa = [i for i in range(n + 1)] T = [0] + list(R()) def find(i): while i != pa[i]: pa[i] = pa[pa[i]] i = pa[i] return i for _ in range(m): x, y = map(find, R()) if T[x] < T[y]: x, y = y, x pa[x] = y print (sum(T[i] for i in range(n + 1) if pa[i] == i)) ...
Title: Rumor Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova starte...
```python R = lambda:map(int,input().split()) n,m = R() pa = [i for i in range(n + 1)] T = [0] + list(R()) def find(i): while i != pa[i]: pa[i] = pa[pa[i]] i = pa[i] return i for _ in range(m): x, y = map(find, R()) if T[x] < T[y]: x, y = y, x pa[x] = y print (sum(T[i] for i in range(n + 1) if pa[i] == i)) ...
3
304
A
Pythagorean Theorem II
PROGRAMMING
1,200
[ "brute force", "math" ]
null
null
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states: In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the s...
The only line contains one integer *n* (1<=≤<=*n*<=≤<=104) as we mentioned above.
Print a single integer — the answer to the problem.
[ "5\n", "74\n" ]
[ "1\n", "35\n" ]
none
500
[ { "input": "5", "output": "1" }, { "input": "74", "output": "35" }, { "input": "1000", "output": "881" }, { "input": "586", "output": "472" }, { "input": "2", "output": "0" }, { "input": "362", "output": "258" }, { "input": "778", "outp...
1,626,529,093
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
30
3,000
22,118,400
n=int(input());c=0 for i in range(1,n+1): j=i while i*i+j*j<=n*n: t=i*i+j*j;x=t**0.5 if int(x)*int(x)==t:c+=1 j+=1 print(c)
Title: Pythagorean Theorem II Time Limit: None seconds Memory Limit: None megabytes Problem Description: In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states: In any right-angled triangle, the area of the squar...
```python n=int(input());c=0 for i in range(1,n+1): j=i while i*i+j*j<=n*n: t=i*i+j*j;x=t**0.5 if int(x)*int(x)==t:c+=1 j+=1 print(c) ```
0
807
A
Is it rated?
PROGRAMMING
900
[ "implementation", "sortings" ]
null
null
Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it. Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before ...
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants. Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order...
If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe".
[ "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n", "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n", "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n" ]
[ "rated\n", "unrated\n", "maybe\n" ]
In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated. In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, som...
500
[ { "input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884", "output": "rated" }, { "input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400", "output": "unrated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699", "output": "maybe" }, { ...
1,495,394,464
2,147,483,647
Python 3
OK
TESTS
150
62
0
n=int(input()) a=[int(100000000)] b=[int(100000000)] ans=[] i=1 while i<n+1: m,p=input().split() a.append(int(m)) b.append(int(p)) if a[i]!=b[i]: ans.append('rated') i=i+1 elif a[i]>a[i-1]: ans.append('unrated') i=i+1 elif a==b and i==n: an...
Title: Is it rated? Time Limit: None seconds Memory Limit: None megabytes Problem Description: Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it. Another Codeforces round has been conducted. No two participants have the same number ...
```python n=int(input()) a=[int(100000000)] b=[int(100000000)] ans=[] i=1 while i<n+1: m,p=input().split() a.append(int(m)) b.append(int(p)) if a[i]!=b[i]: ans.append('rated') i=i+1 elif a[i]>a[i-1]: ans.append('unrated') i=i+1 elif a==b and i==n: ...
3
63
A
Sinking Ship
PROGRAMMING
900
[ "implementation", "sortings", "strings" ]
A. Sinking Ship
2
256
The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a stri...
The first line contains an integer *n*, which is the number of people in the crew (1<=≤<=*n*<=≤<=100). Then follow *n* lines. The *i*-th of those lines contains two words — the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spa...
Print *n* lines. The *i*-th of them should contain the name of the crew member who must be the *i*-th one to leave the ship.
[ "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman\n" ]
[ "Teddy\nAlice\nBob\nJulia\nCharlie\nJack\n" ]
none
500
[ { "input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman", "output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack" }, { "input": "1\nA captain", "output": "A" }, { "input": "1\nAbcdefjhij captain", "output": "Abcdefjhij" }, { "input": "5\nA captain...
1,628,301,600
2,147,483,647
Python 3
OK
TESTS
26
154
6,963,200
number = int(input()) crew = [] rats = [] women_children = [] men = [] captain = '' for _ in range(number): crew.append(input().split()) for person in crew: name, status = person if status == 'rat': rats.append(name) elif status == 'woman': women_children.append(name) e...
Title: Sinking Ship Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to ...
```python number = int(input()) crew = [] rats = [] women_children = [] men = [] captain = '' for _ in range(number): crew.append(input().split()) for person in crew: name, status = person if status == 'rat': rats.append(name) elif status == 'woman': women_children.append(na...
3.94853
744
A
Hongcow Builds A Nation
PROGRAMMING
1,500
[ "dfs and similar", "graphs" ]
null
null
Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries. The world can be modeled as an undirected graph with *n* nodes and *m* edges. *k* of the nodes are home to the governments of the *k* countries that make up the world. There is at ...
The first line of input will contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=1<=000, 0<=≤<=*m*<=≤<=100<=000, 1<=≤<=*k*<=≤<=*n*) — the number of vertices and edges in the graph, and the number of vertices that are homes of the government. The next line of input will contain *k* integers *c*1,<=*c*2,<=...,<=*c**...
Output a single integer, the maximum number of edges Hongcow can add to the graph while keeping it stable.
[ "4 1 2\n1 3\n1 2\n", "3 3 1\n2\n1 2\n1 3\n2 3\n" ]
[ "2\n", "0\n" ]
For the first sample test, the graph looks like this: For the second sample test, the graph looks like this:
500
[ { "input": "4 1 2\n1 3\n1 2", "output": "2" }, { "input": "3 3 1\n2\n1 2\n1 3\n2 3", "output": "0" }, { "input": "10 3 2\n1 10\n1 2\n1 3\n4 5", "output": "33" }, { "input": "1 0 1\n1", "output": "0" }, { "input": "1000 0 1\n72", "output": "499500" }, { ...
1,482,477,184
664
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
#include<iostream> #include<vector> using namespace std; struct Dsu { int n; vector<int> master; vector<int> size; Dsu(int nsize) { n = nsize; master.resize(n); size.resize(n, 1); for(int i=0;i<n;i++) master[i] = i; } int getMaster(int pos) { if(master[pos] == pos) re...
Title: Hongcow Builds A Nation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries. The world can be modeled as an undirected graph with *n* nodes and *m* e...
```python #include<iostream> #include<vector> using namespace std; struct Dsu { int n; vector<int> master; vector<int> size; Dsu(int nsize) { n = nsize; master.resize(n); size.resize(n, 1); for(int i=0;i<n;i++) master[i] = i; } int getMaster(int pos) { if(master[pos] == p...
-1
980
A
Links and Pearls
PROGRAMMING
900
[ "implementation", "math" ]
null
null
A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one. You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times as you l...
The only line of input contains a string $s$ ($3 \leq |s| \leq 100$), representing the necklace, where a dash '-' represents a link and the lowercase English letter 'o' represents a pearl.
Print "YES" if the links and pearls can be rejoined such that the number of links between adjacent pearls is equal. Otherwise print "NO". You can print each letter in any case (upper or lower).
[ "-o-o--", "-o---\n", "-o---o-\n", "ooo\n" ]
[ "YES", "YES", "NO", "YES\n" ]
none
500
[ { "input": "-o-o--", "output": "YES" }, { "input": "-o---", "output": "YES" }, { "input": "-o---o-", "output": "NO" }, { "input": "ooo", "output": "YES" }, { "input": "---", "output": "YES" }, { "input": "--o-o-----o----o--oo-o-----ooo-oo---o--", "...
1,663,512,347
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
4
46
0
necklace = input() strings = necklace.count('-') pearls = necklace.count('o') if (strings%pearls) ==0: print("Yes") else: print("No")
Title: Links and Pearls Time Limit: None seconds Memory Limit: None megabytes Problem Description: A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one. You can remove a link or a pearl and insert it between two other existing links or pearl...
```python necklace = input() strings = necklace.count('-') pearls = necklace.count('o') if (strings%pearls) ==0: print("Yes") else: print("No") ```
-1
330
A
Cakeminator
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows: The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains...
The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these: ...
Output the maximum number of cake cells that the cakeminator can eat.
[ "3 4\nS...\n....\n..S.\n" ]
[ "8\n" ]
For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats).
500
[ { "input": "3 4\nS...\n....\n..S.", "output": "8" }, { "input": "2 2\n..\n..", "output": "4" }, { "input": "2 2\nSS\nSS", "output": "0" }, { "input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..", "output": "14" }, { "input": "3 5\n..S..\nSSSSS\n..S..", "output": "...
1,622,737,427
2,147,483,647
Python 3
OK
TESTS
42
218
0
r, k=[int(i) for i in input().split()] a=[] c=[] ro, ko = 0, 0 for i in range(r): b=[] s=input() for f in s: if f=='S': ro+=1 break for j in range(k): b.append(s[j]) a.append(b) for j in range(k): for i in range(r): if a[i][j]=='S...
Title: Cakeminator Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows: The cakeminator is going to eat the cake! Each ti...
```python r, k=[int(i) for i in input().split()] a=[] c=[] ro, ko = 0, 0 for i in range(r): b=[] s=input() for f in s: if f=='S': ro+=1 break for j in range(k): b.append(s[j]) a.append(b) for j in range(k): for i in range(r): if a...
3
938
B
Run For Your Prize
PROGRAMMING
1,100
[ "brute force", "greedy" ]
null
null
You and your friend are participating in a TV show "Run For Your Prize". At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these tw...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the number of prizes. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (2<=≤<=*a**i*<=≤<=106<=-<=1) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order.
Print one integer — the minimum number of seconds it will take to collect all prizes.
[ "3\n2 3 9\n", "2\n2 999995\n" ]
[ "8\n", "5\n" ]
In the first example you take all the prizes: take the first at 1, the second at 2 and the third at 8. In the second example you take the first prize in 1 second and your friend takes the other in 5 seconds, you do this simultaneously, so the total time is 5.
0
[ { "input": "3\n2 3 9", "output": "8" }, { "input": "2\n2 999995", "output": "5" }, { "input": "1\n20", "output": "19" }, { "input": "6\n2 3 500000 999997 999998 999999", "output": "499999" }, { "input": "1\n999999", "output": "1" }, { "input": "1\n5100...
1,518,800,581
7,081
Python 3
WRONG_ANSWER
TESTS
1
62
5,632,000
n=int(input()) s=input() s=s.split() def X(lst,n): i=0 r=0 try: while i<n-1: r+=(lst[i+1]-lst[i]) i+=1 except: pass return r+1 for i in range(n): s[i]=int(s[i]) f=[] I=[] for i in range(n): a=10**6-s[i] if a<s[i]: f+=[...
Title: Run For Your Prize Time Limit: None seconds Memory Limit: None megabytes Problem Description: You and your friend are participating in a TV show "Run For Your Prize". At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are di...
```python n=int(input()) s=input() s=s.split() def X(lst,n): i=0 r=0 try: while i<n-1: r+=(lst[i+1]-lst[i]) i+=1 except: pass return r+1 for i in range(n): s[i]=int(s[i]) f=[] I=[] for i in range(n): a=10**6-s[i] if a<s[i]: ...
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,658,643,950
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
62
0
n = int(input()) arr=[] sum_ =int(0) for i in range(n): a=[] b = input() lst=b.split() for j in range(n): a.append(lst[j]) sum_=sum_+int(lst[j]) arr.append(a) if(sum_==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()) arr=[] sum_ =int(0) for i in range(n): a=[] b = input() lst=b.split() for j in range(n): a.append(lst[j]) sum_=sum_+int(lst[j]) arr.append(a) if(sum_==0): print("YES") else: print("NO") ```
-1
984
A
Game
PROGRAMMING
800
[ "sortings" ]
null
null
Two players play a game. Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $n - 1$ turns are made. The first player makes the first move, then players ...
The first line contains one integer $n$ ($1 \le n \le 1000$) — the number of numbers on the board. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$).
Print one number that will be left on the board.
[ "3\n2 1 3\n", "3\n2 2 2\n" ]
[ "2", "2" ]
In the first sample, the first player erases $3$ and the second erases $1$. $2$ is left on the board. In the second sample, $2$ is left on the board regardless of the actions of the players.
500
[ { "input": "3\n2 1 3", "output": "2" }, { "input": "3\n2 2 2", "output": "2" }, { "input": "9\n44 53 51 80 5 27 74 79 94", "output": "53" }, { "input": "10\n38 82 23 37 96 4 81 60 67 86", "output": "60" }, { "input": "10\n58 26 77 15 53 81 68 48 22 65", "outpu...
1,607,495,820
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
140
0
n=int(input()) a=list(map(int,input().split())) a.sort() if n%2==0: x=n//2+1 else: x=n//2 print(a[x])
Title: Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two players play a game. Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the...
```python n=int(input()) a=list(map(int,input().split())) a.sort() if n%2==0: x=n//2+1 else: x=n//2 print(a[x]) ```
0
862
A
Mahmoud and Ehab and the MEX
PROGRAMMING
1,000
[ "greedy", "implementation" ]
null
null
Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go. Dr. Evil is interested in sets, He has a set of *n* integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly *x*. the MEX...
The first line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=100, 0<=≤<=*x*<=≤<=100) — the size of the set Dr. Evil owns, and the desired MEX. The second line contains *n* distinct non-negative integers not exceeding 100 that represent the set.
The only line should contain one integer — the minimal number of operations Dr. Evil should perform.
[ "5 3\n0 4 5 6 7\n", "1 0\n0\n", "5 0\n1 2 3 4 5\n" ]
[ "2\n", "1\n", "0\n" ]
For the first test case Dr. Evil should add 1 and 2 to the set performing 2 operations. For the second test case Dr. Evil should erase 0 from the set. After that, the set becomes empty, so the MEX of it is 0. In the third test case the set is already evil.
500
[ { "input": "5 3\n0 4 5 6 7", "output": "2" }, { "input": "1 0\n0", "output": "1" }, { "input": "5 0\n1 2 3 4 5", "output": "0" }, { "input": "10 5\n57 1 47 9 93 37 76 70 78 15", "output": "4" }, { "input": "10 5\n99 98 93 97 95 100 92 94 91 96", "output": "5" ...
1,582,003,197
2,147,483,647
Python 3
OK
TESTS
39
124
307,200
a = int(input().split()[1]) s = input().split() d = [] small_list = list(range(a)) small = len(small_list) same = 0 for i in s: d.append(int(i)) d.sort() for i in d: if i == a: same += 1 elif i in small_list: small -= 1 small_list.remove(i) print(small + same)
Title: Mahmoud and Ehab and the MEX Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go. Dr. Evil is interested in ...
```python a = int(input().split()[1]) s = input().split() d = [] small_list = list(range(a)) small = len(small_list) same = 0 for i in s: d.append(int(i)) d.sort() for i in d: if i == a: same += 1 elif i in small_list: small -= 1 small_list.remove(i) print(small + same...
3
898
B
Proper Nutrition
PROGRAMMING
1,100
[ "brute force", "implementation", "number theory" ]
null
null
Vasya has *n* burles. One bottle of Ber-Cola costs *a* burles and one Bars bar costs *b* burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars. Find out if it's possible to buy some amount of bottles of Ber-Cola and Bars bars and spend exactly *n* bu...
First line contains single integer *n* (1<=≤<=*n*<=≤<=10<=000<=000) — amount of money, that Vasya has. Second line contains single integer *a* (1<=≤<=*a*<=≤<=10<=000<=000) — cost of one bottle of Ber-Cola. Third line contains single integer *b* (1<=≤<=*b*<=≤<=10<=000<=000) — cost of one Bars bar.
If Vasya can't buy Bars and Ber-Cola in such a way to spend exactly *n* burles print «NO» (without quotes). Otherwise in first line print «YES» (without quotes). In second line print two non-negative integers *x* and *y* — number of bottles of Ber-Cola and number of Bars bars Vasya should buy in order to spend exactly...
[ "7\n2\n3\n", "100\n25\n10\n", "15\n4\n8\n", "9960594\n2551\n2557\n" ]
[ "YES\n2 1\n", "YES\n0 10\n", "NO\n", "YES\n1951 1949\n" ]
In first example Vasya can buy two bottles of Ber-Cola and one Bars bar. He will spend exactly 2·2 + 1·3 = 7 burles. In second example Vasya can spend exactly *n* burles multiple ways: - buy two bottles of Ber-Cola and five Bars bars; - buy four bottles of Ber-Cola and don't buy Bars bars; - don't buy Ber-Cola an...
750
[ { "input": "7\n2\n3", "output": "YES\n2 1" }, { "input": "100\n25\n10", "output": "YES\n0 10" }, { "input": "15\n4\n8", "output": "NO" }, { "input": "9960594\n2551\n2557", "output": "YES\n1951 1949" }, { "input": "10000000\n1\n1", "output": "YES\n0 10000000" ...
1,616,374,603
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
39
764
1,331,200
n = int(input()) a = int(input()) b = int(input()) for x in range(n): if (n - (x*a))%b == 0: print("YES") print(x, (n - (x*a))//b) exit() print("NO")
Title: Proper Nutrition Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* burles. One bottle of Ber-Cola costs *a* burles and one Bars bar costs *b* burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars. Find...
```python n = int(input()) a = int(input()) b = int(input()) for x in range(n): if (n - (x*a))%b == 0: print("YES") print(x, (n - (x*a))//b) exit() print("NO") ```
0
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,512,546,945
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
2,000
11,161,600
n=int(input()) N=[int(i) for i in input().split()] su=0 if n==1: su=su+sum(N) else: N.sort() su=su+sum(N) while len(N)>2: su=su+sum(N) del N[0] su=su+sum(N) print(su)
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()) N=[int(i) for i in input().split()] su=0 if n==1: su=su+sum(N) else: N.sort() su=su+sum(N) while len(N)>2: su=su+sum(N) del N[0] su=su+sum(N) print(su) ```
0
271
A
Beautiful Year
PROGRAMMING
800
[ "brute force" ]
null
null
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits. Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has on...
The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number.
Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists.
[ "1987\n", "2013\n" ]
[ "2013\n", "2014\n" ]
none
500
[ { "input": "1987", "output": "2013" }, { "input": "2013", "output": "2014" }, { "input": "1000", "output": "1023" }, { "input": "1001", "output": "1023" }, { "input": "1234", "output": "1235" }, { "input": "5555", "output": "5601" }, { "inp...
1,692,875,950
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
60
0
x=input() while len(set(str(int(x+1))))<4:x+1 print()
Title: Beautiful Year Time Limit: None seconds Memory Limit: None megabytes Problem Description: It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits. Now you are suggested to solve the following problem: give...
```python x=input() while len(set(str(int(x+1))))<4:x+1 print() ```
-1
79
A
Bus Game
PROGRAMMING
1,200
[ "greedy" ]
A. Bus Game
2
256
After Fox Ciel won an onsite round of a programming contest, she took a bus to return to her castle. The fee of the bus was 220 yen. She met Rabbit Hanako in the bus. They decided to play the following game because they got bored in the bus. - Initially, there is a pile that contains *x* 100-yen coins and *y* 10-yen ...
The first line contains two integers *x* (0<=≤<=*x*<=≤<=106) and *y* (0<=≤<=*y*<=≤<=106), separated by a single space.
If Ciel wins, print "Ciel". Otherwise, print "Hanako".
[ "2 2\n", "3 22\n" ]
[ "Ciel\n", "Hanako\n" ]
In the first turn (Ciel's turn), she will choose 2 100-yen coins and 2 10-yen coins. In the second turn (Hanako's turn), she will choose 1 100-yen coin and 12 10-yen coins. In the third turn (Ciel's turn), she can't pay exactly 220 yen, so Ciel will lose.
500
[ { "input": "2 2", "output": "Ciel" }, { "input": "3 22", "output": "Hanako" }, { "input": "0 22", "output": "Ciel" }, { "input": "1000 1000", "output": "Ciel" }, { "input": "0 0", "output": "Hanako" }, { "input": "0 21", "output": "Hanako" }, {...
1,611,647,059
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
92
0
x,y = map(int,input().split()) if y >= 2: a = (x * 100) + (y * 10) if (a // 220) % 2 == 0: print("Hanako") else: print("Ciel") else: print("Hanako")
Title: Bus Game Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: After Fox Ciel won an onsite round of a programming contest, she took a bus to return to her castle. The fee of the bus was 220 yen. She met Rabbit Hanako in the bus. They decided to play the following game because they got bored ...
```python x,y = map(int,input().split()) if y >= 2: a = (x * 100) + (y * 10) if (a // 220) % 2 == 0: print("Hanako") else: print("Ciel") else: print("Hanako") ```
0
37
A
Towers
PROGRAMMING
1,000
[ "sortings" ]
A. Towers
2
256
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ...
The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000.
In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.
[ "3\n1 2 3\n", "4\n6 5 6 7\n" ]
[ "1 3\n", "2 3\n" ]
none
500
[ { "input": "3\n1 2 3", "output": "1 3" }, { "input": "4\n6 5 6 7", "output": "2 3" }, { "input": "4\n3 2 1 1", "output": "2 3" }, { "input": "4\n1 2 3 3", "output": "2 3" }, { "input": "3\n20 22 36", "output": "1 3" }, { "input": "25\n47 30 94 41 45 20...
1,550,650,221
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
218
0
a=int(input()) k=a l=list(map(int,input().split())) ma=1 for i in range(a): if l.count(l[i])>ma: ma=l.count(l[i]) k=k-l.count(l[i])+1 print(ma,k)
Title: Towers Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct...
```python a=int(input()) k=a l=list(map(int,input().split())) ma=1 for i in range(a): if l.count(l[i])>ma: ma=l.count(l[i]) k=k-l.count(l[i])+1 print(ma,k) ```
0
733
A
Grasshopper And the String
PROGRAMMING
1,000
[ "implementation" ]
null
null
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of ...
The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100.
Print single integer *a* — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels.
[ "ABABBBACFEYUKOTT\n", "AAA\n" ]
[ "4", "1" ]
none
500
[ { "input": "ABABBBACFEYUKOTT", "output": "4" }, { "input": "AAA", "output": "1" }, { "input": "A", "output": "1" }, { "input": "B", "output": "2" }, { "input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIKLMJNHGTRWSDZXCVBNMHGFDSXVWRTPPPLKMNBXIUOIUOIUOIUOOIU", ...
1,590,038,686
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
93
0
s = '0'+input()+'1' l = 'AEIOUY' i, k, mx, p = 0, 0, 0, 0 while i<len(s): if s[i] in l: k=(i-p) p = i if mx<k: mx = k i+=1 print(mx)
Title: Grasshopper And the String Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far en...
```python s = '0'+input()+'1' l = 'AEIOUY' i, k, mx, p = 0, 0, 0, 0 while i<len(s): if s[i] in l: k=(i-p) p = i if mx<k: mx = k i+=1 print(mx) ```
0
557
B
Pasha and Tea
PROGRAMMING
1,500
[ "constructive algorithms", "implementation", "math", "sortings" ]
null
null
Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most *a**i* milliliters of water. It turned out that among Pasha's friends there are exactly *n* boys a...
The first line of the input contains two integers, *n* and *w* (1<=≤<=*n*<=≤<=105, 1<=≤<=*w*<=≤<=109) — the number of Pasha's friends that are boys (equal to the number of Pasha's friends that are girls) and the capacity of Pasha's teapot in milliliters. The second line of the input contains the sequence of integers *...
Print a single real number — the maximum total amount of water in milliliters that Pasha can pour to his friends without violating the given conditions. Your answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=6.
[ "2 4\n1 1 1 1\n", "3 18\n4 4 4 2 2 2\n", "1 5\n2 3\n" ]
[ "3", "18", "4.5" ]
Pasha also has candies that he is going to give to girls but that is another task...
1,000
[ { "input": "2 4\n1 1 1 1", "output": "3.0000000000" }, { "input": "3 18\n4 4 4 2 2 2", "output": "18.0000000000" }, { "input": "1 5\n2 3", "output": "4.5000000000" }, { "input": "1 1\n1000000000 1000000000", "output": "1.0000000000" }, { "input": "4 1000000000\n1 ...
1,553,182,410
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
218
16,076,800
n, w = map(int, input().split()) a = list(map(int, input().split())) a.sort() cup_boy = a[-1] average =cup_boy/2 res = n*average*2 + n*average if res > w: print(w) exit() print(res)
Title: Pasha and Tea Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most ...
```python n, w = map(int, input().split()) a = list(map(int, input().split())) a.sort() cup_boy = a[-1] average =cup_boy/2 res = n*average*2 + n*average if res > w: print(w) exit() print(res) ```
0
796
B
Find The Bone
PROGRAMMING
1,300
[ "implementation" ]
null
null
Zane the wizard is going to perform a magic show shuffling the cups. There are *n* cups, numbered from 1 to *n*, placed along the *x*-axis on a table that has *m* holes on it. More precisely, cup *i* is on the table at the position *x*<==<=*i*. The problematic bone is initially at the position *x*<==<=1. Zane will co...
The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=106, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=3·105) — the number of cups, the number of holes on the table, and the number of swapping operations, respectively. The second line contains *m* distinct integers *h*1,<=*h*2,<=...,<=*h**m* (1<=≤<=*h**i*<=≤<=*...
Print one integer — the final position along the *x*-axis of the bone.
[ "7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1\n", "5 1 2\n2\n1 2\n2 4\n" ]
[ "1", "2" ]
In the first sample, after the operations, the bone becomes at *x* = 2, *x* = 5, *x* = 7, and *x* = 1, respectively. In the second sample, after the first operation, the bone becomes at *x* = 2, and falls into the hole onto the ground.
750
[ { "input": "7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1", "output": "1" }, { "input": "5 1 2\n2\n1 2\n2 4", "output": "2" }, { "input": "10000 1 9\n55\n44 1\n2929 9292\n9999 9998\n44 55\n49 94\n55 53\n100 199\n55 50\n53 11", "output": "55" }, { "input": "100000 3 7\n2 3 4\n1 5\n5 1\n1 5...
1,547,829,247
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
93
0
n,m,k = (int(i) for i in input().split(' ')) a = [int(i) for i in input().split()] i = 0 j = 1 s = True b = [] while (i < k): b.append([int(i) for i in input().split(' ')]) i +=1 i = 0; while (i < k): if(j == b[0]): j = b[1] elif(j == b[1]): j = b[0] if j in a: s = False...
Title: Find The Bone Time Limit: None seconds Memory Limit: None megabytes Problem Description: Zane the wizard is going to perform a magic show shuffling the cups. There are *n* cups, numbered from 1 to *n*, placed along the *x*-axis on a table that has *m* holes on it. More precisely, cup *i* is on the table at t...
```python n,m,k = (int(i) for i in input().split(' ')) a = [int(i) for i in input().split()] i = 0 j = 1 s = True b = [] while (i < k): b.append([int(i) for i in input().split(' ')]) i +=1 i = 0; while (i < k): if(j == b[0]): j = b[1] elif(j == b[1]): j = b[0] if j in a: ...
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,665,573,348
2,147,483,647
Python 3
OK
TESTS
49
93
716,800
x = int(input()) y = str(input()) o = 0 z = 0 for i in range(x): if y[i] == '0' : o+=1 elif y[i] == '1': z+=1 if o == z : print(0) else: print(abs(o-z))
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 x = int(input()) y = str(input()) o = 0 z = 0 for i in range(x): if y[i] == '0' : o+=1 elif y[i] == '1': z+=1 if o == z : print(0) else: print(abs(o-z)) ```
3
144
A
Arrival of the General
PROGRAMMING
800
[ "implementation" ]
null
null
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground. By the military charter the soldiers should stand in the order of non-increasing of their...
The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginnin...
Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like.
[ "4\n33 44 11 22\n", "7\n10 10 58 31 63 40 76\n" ]
[ "2\n", "10\n" ]
In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11). In the second sample the colonel may swap the soldiers in the following sequence: 1. (10, 10, 58, 31, 63, 40, 76)...
500
[ { "input": "4\n33 44 11 22", "output": "2" }, { "input": "7\n10 10 58 31 63 40 76", "output": "10" }, { "input": "2\n88 89", "output": "1" }, { "input": "5\n100 95 100 100 88", "output": "0" }, { "input": "7\n48 48 48 48 45 45 45", "output": "0" }, { "...
1,682,139,200
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
92
0
n=int(input()) soldier=[int(i) for i in input().split()] max=soldier[0] min=soldier[0] count_min=0 count_max=0 checked=1 for i in range(1,len(soldier)): if soldier[i]>=max: max=soldier[i] if soldier[i]<=min: min=soldier[i] for i in range(len(soldier)): if soldier[i]==min: ...
Title: Arrival of the General Time Limit: None seconds Memory Limit: None megabytes Problem Description: A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on t...
```python n=int(input()) soldier=[int(i) for i in input().split()] max=soldier[0] min=soldier[0] count_min=0 count_max=0 checked=1 for i in range(1,len(soldier)): if soldier[i]>=max: max=soldier[i] if soldier[i]<=min: min=soldier[i] for i in range(len(soldier)): if soldier[i]==m...
0
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers ...
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output one number — the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "outpu...
1,648,235,434
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
a,b=map(int,input().split()) d=(a*b)/2 print(d)
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p...
```python a,b=map(int,input().split()) d=(a*b)/2 print(d) ```
0
697
B
Barnicle
PROGRAMMING
1,400
[ "brute force", "implementation", "math", "strings" ]
null
null
Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate. Barney asked the bar tender Carl about this distance value, but Carl was so busy talking to the customers so he wrote the distance ...
The first and only line of input contains a single string of form *a*.*deb* where *a*, *d* and *b* are integers and *e* is usual character 'e' (0<=≤<=*a*<=≤<=9,<=0<=≤<=*d*<=&lt;<=10100,<=0<=≤<=*b*<=≤<=100) — the scientific notation of the desired distance value. *a* and *b* contain no leading zeros and *d* contains no...
Print the only real number *x* (the desired distance value) in the only line in its decimal notation. Thus if *x* is an integer, print it's integer value without decimal part and decimal point and without leading zeroes. Otherwise print *x* in a form of *p*.*q* such that *p* is an integer that have no leading zeroe...
[ "8.549e2\n", "8.549e3\n", "0.33e0\n" ]
[ "854.9\n", "8549\n", "0.33\n" ]
none
1,000
[ { "input": "8.549e2", "output": "854.9" }, { "input": "8.549e3", "output": "8549" }, { "input": "0.33e0", "output": "0.33" }, { "input": "1.31e1", "output": "13.1" }, { "input": "1.038e0", "output": "1.038" }, { "input": "8.25983e5", "output": "825...
1,470,729,880
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
77
5,529,600
from decimal import * getcontext().prec=1000 print(Decimal(input()).normalize())
Title: Barnicle Time Limit: None seconds Memory Limit: None megabytes Problem Description: Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate. Barney asked the bar tender Carl abou...
```python from decimal import * getcontext().prec=1000 print(Decimal(input()).normalize()) ```
0
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,570,890,194
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
6
171
409,600
from collections import Counter a, b, c, s = input(), input(), Counter(), 0 k = len(b) - len(a) + 1 c[0] = b.count('0', 0, k) for i in range(1, len(a)): c[i] = (b[i + k - 1] == '0') - (b[i] == '0') + c[i - 1] for i in range(len(a)): s += [c[i], k - c[i]][a[i] == '0'] print(s)
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 from collections import Counter a, b, c, s = input(), input(), Counter(), 0 k = len(b) - len(a) + 1 c[0] = b.count('0', 0, k) for i in range(1, len(a)): c[i] = (b[i + k - 1] == '0') - (b[i] == '0') + c[i - 1] for i in range(len(a)): s += [c[i], k - c[i]][a[i] == '0'] print(s) ```
0
514
A
Chewbaсca and Number
PROGRAMMING
1,200
[ "greedy", "implementation" ]
null
null
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*. Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits....
The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca.
Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.
[ "27\n", "4545\n" ]
[ "22\n", "4444\n" ]
none
500
[ { "input": "27", "output": "22" }, { "input": "4545", "output": "4444" }, { "input": "1", "output": "1" }, { "input": "9", "output": "9" }, { "input": "8772", "output": "1222" }, { "input": "81", "output": "11" }, { "input": "71723447", ...
1,674,315,821
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
30
0
n = input() for i in n: t = int(i) if 9-t < t: t =9-t print(t, end = "")
Title: Chewbaсca and Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*. Help Chewbacca to transform...
```python n = input() for i in n: t = int(i) if 9-t < t: t =9-t print(t, end = "") ```
0
706
B
Interesting drink
PROGRAMMING
1,100
[ "binary search", "dp", "implementation" ]
null
null
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins. Vasiliy plans to buy his favorite ...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink. The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop. The third line contains a single i...
Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day.
[ "5\n3 10 8 6 11\n4\n1\n10\n3\n11\n" ]
[ "0\n4\n1\n5\n" ]
On the first day, Vasiliy won't be able to buy a drink in any of the shops. On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4. On the third day, Vasiliy can buy a drink only in the shop number 1. Finally, on the last day Vasiliy can buy a drink in any shop.
1,000
[ { "input": "5\n3 10 8 6 11\n4\n1\n10\n3\n11", "output": "0\n4\n1\n5" }, { "input": "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471", "output": "2\n2\n3\n4\n0\n4\n3\n1\n2\n2" }, { "input": "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521", "output": "...
1,690,939,027
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
10
2,000
13,516,800
n=int(input()) x=list(map(int,input().split())) q=int(input()) for i in range(q): t=0 m=int(input()) for f in range(len(x)): if(m>=x[f]): t+=1 print(t)
Title: Interesting drink Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known tha...
```python n=int(input()) x=list(map(int,input().split())) q=int(input()) for i in range(q): t=0 m=int(input()) for f in range(len(x)): if(m>=x[f]): t+=1 print(t) ```
0
595
A
Vitaly and Night
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment. Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats 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,586,630,827
2,147,483,647
PyPy 3
OK
TESTS
36
186
1,536,000
n, m = [int(x) for x in input().split(' ')] cnt = 0 for i in range(n): f = [int(x) for x in input().split(' ')] cnt += sum([1 for x in range(0, len(f) - 1, 2) if f[x] or f[x+1]]) print(cnt)
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 n, m = [int(x) for x in input().split(' ')] cnt = 0 for i in range(n): f = [int(x) for x in input().split(' ')] cnt += sum([1 for x in range(0, len(f) - 1, 2) if f[x] or f[x+1]]) print(cnt) ```
3
663
A
Rebus
PROGRAMMING
1,800
[ "constructive algorithms", "expression parsing", "greedy", "math" ]
null
null
You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer *n*. The goal is to replace each question mark with some positive integer from 1 to *n*, such that equality holds.
The only line of the input contains a rebus. It's guaranteed that it contains no more than 100 question marks, integer *n* is positive and doesn't exceed 1<=000<=000, all letters and integers are separated by spaces, arithmetic operations are located only between question marks.
The first line of the output should contain "Possible" (without quotes) if rebus has a solution and "Impossible" (without quotes) otherwise. If the answer exists, the second line should contain any valid rebus with question marks replaced by integers from 1 to *n*. Follow the format given in the samples.
[ "? + ? - ? + ? + ? = 42\n", "? - ? = 1\n", "? = 1000000\n" ]
[ "Possible\n9 + 13 - 39 + 28 + 31 = 42\n", "Impossible\n", "Possible\n1000000 = 1000000\n" ]
none
500
[ { "input": "? + ? - ? + ? + ? = 42", "output": "Possible\n1 + 1 - 1 + 1 + 40 = 42" }, { "input": "? - ? = 1", "output": "Impossible" }, { "input": "? = 1000000", "output": "Possible\n1000000 = 1000000" }, { "input": "? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? +...
1,464,346,729
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
46
4,915,200
s=input().split() length=len(s) n=int(s[length-1]) plus=1 minus=0 # q=0 for i in s: if(i== '+'): plus+=1 if(i== '-'): minus+=1 # if(i=='?'): # q+=1 if(plus*n - minus < n or plus - n*minus > n): print('Impossible') exit() else: print('Possible') if(minus==0): s[0]= repr(n-plus+1) for i in range(2, lengt...
Title: Rebus Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer *n*. The goal is to replace each question mark with some positive in...
```python s=input().split() length=len(s) n=int(s[length-1]) plus=1 minus=0 # q=0 for i in s: if(i== '+'): plus+=1 if(i== '-'): minus+=1 # if(i=='?'): # q+=1 if(plus*n - minus < n or plus - n*minus > n): print('Impossible') exit() else: print('Possible') if(minus==0): s[0]= repr(n-plus+1) for i in rang...
0
66
B
Petya and Countryside
PROGRAMMING
1,100
[ "brute force", "implementation" ]
B. Petya and Countryside
2
256
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own f...
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
[ "1\n2\n", "5\n1 2 1 2 1\n", "8\n1 2 1 1 1 3 3 4\n" ]
[ "1\n", "3\n", "6\n" ]
none
1,000
[ { "input": "1\n2", "output": "1" }, { "input": "5\n1 2 1 2 1", "output": "3" }, { "input": "8\n1 2 1 1 1 3 3 4", "output": "6" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "10" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output": "10" }, { "input...
1,611,883,205
2,147,483,647
Python 3
OK
TESTS
80
154
307,200
x=int(input()) a=list(map(int,input().split())) s=[1]*x q=[1]*x for i in range(x-1): if a[i]<=a[i+1]: s[i+1]=s[i]+1 a=a[::-1] for i in range(x-1): if a[i]<=a[i+1]: q[i+1]=q[i]+1 q=q[::-1] m=0 for i in range(x): m=max(m,s[i]+q[i]-1) print(m)
Title: Petya and Countryside Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *...
```python x=int(input()) a=list(map(int,input().split())) s=[1]*x q=[1]*x for i in range(x-1): if a[i]<=a[i+1]: s[i+1]=s[i]+1 a=a[::-1] for i in range(x-1): if a[i]<=a[i+1]: q[i+1]=q[i]+1 q=q[::-1] m=0 for i in range(x): m=max(m,s[i]+q[i]-1) print(m) ```
3.960928
495
A
Digital Counter
PROGRAMMING
1,100
[ "implementation" ]
null
null
Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning them on or off. The picture below shows how the elevator shows each ...
The only line of input contains exactly two digits representing number *n* (0<=≤<=*n*<=≤<=99). Note that *n* may have a leading zero.
In the only line of the output print the number of good integers.
[ "89\n", "00\n", "73\n" ]
[ "2\n", "4\n", "15\n" ]
In the first sample the counter may be supposed to show 88 or 89. In the second sample the good integers are 00, 08, 80 and 88. In the third sample the good integers are 03, 08, 09, 33, 38, 39, 73, 78, 79, 83, 88, 89, 93, 98, 99.
500
[ { "input": "89", "output": "2" }, { "input": "00", "output": "4" }, { "input": "73", "output": "15" }, { "input": "08", "output": "2" }, { "input": "26", "output": "4" }, { "input": "49", "output": "6" }, { "input": "88", "output": "1" ...
1,526,780,560
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
77
0
import numpy as np d={'0':{1,2,3,4,5,6}, '1':{3,4}, '2':{2,3,5,6,7}, '3':{2,3,4,5,7}, '4':{1,3,4,7}, '5':{1,2,4,5,7}, '6':{1,2,4,5,6,7}, '7':{2,3,4}, '8':{1,2,3,4,5,6,7}, '9':{1,2,3,4,5,7} } n=input() s1=[] s0=[] for i in range(10): if d[n[0]].issubset(d[str(i)]): ...
Title: Digital Counter Time Limit: None seconds Memory Limit: None megabytes Problem Description: Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a numbe...
```python import numpy as np d={'0':{1,2,3,4,5,6}, '1':{3,4}, '2':{2,3,5,6,7}, '3':{2,3,4,5,7}, '4':{1,3,4,7}, '5':{1,2,4,5,7}, '6':{1,2,4,5,6,7}, '7':{2,3,4}, '8':{1,2,3,4,5,6,7}, '9':{1,2,3,4,5,7} } n=input() s1=[] s0=[] for i in range(10): if d[n[0]].issubset(d[s...
-1
1
B
Spreadsheet
PROGRAMMING
1,600
[ "implementation", "math" ]
B. Spreadsheets
10
64
In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow th...
The first line of the input contains integer number *n* (1<=≤<=*n*<=≤<=105), the number of coordinates in the test. Then there follow *n* lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 .
Write *n* lines, each line should contain a cell coordinates in the other numeration system.
[ "2\nR23C55\nBC23\n" ]
[ "BC23\nR23C55\n" ]
none
0
[ { "input": "2\nR23C55\nBC23", "output": "BC23\nR23C55" }, { "input": "1\nA1", "output": "R1C1" }, { "input": "5\nR8C3\nD1\nR7C2\nR8C9\nR8C9", "output": "C8\nR1C4\nB7\nI8\nI8" }, { "input": "4\nR4C25\nR90C35\nAP55\nX83", "output": "Y4\nAI90\nR55C42\nR83C24" }, { "i...
1,671,588,077
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
204,800
t=int(input()) for j in range(t): inpt=input() n=len(inpt) if n>=6 and inpt[1] in ['1','2','3','4','5','6','7','8','9','0'] and 'R' in inpt and 'C' in inpt: i=1 arr1=[] while inpt[i]!='C': arr1.append(int(inpt[i])) i=i+1 lt=0 for f i...
Title: Spreadsheet Time Limit: 10 seconds Memory Limit: 64 megabytes Problem Description: In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter n...
```python t=int(input()) for j in range(t): inpt=input() n=len(inpt) if n>=6 and inpt[1] in ['1','2','3','4','5','6','7','8','9','0'] and 'R' in inpt and 'C' in inpt: i=1 arr1=[] while inpt[i]!='C': arr1.append(int(inpt[i])) i=i+1 lt=0 ...
0
275
A
Lights Out
PROGRAMMING
900
[ "implementation" ]
null
null
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be sw...
The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed.
Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0".
[ "1 0 0\n0 0 0\n0 0 1\n", "1 0 1\n8 8 8\n2 0 3\n" ]
[ "001\n010\n100\n", "010\n011\n100\n" ]
none
500
[ { "input": "1 0 0\n0 0 0\n0 0 1", "output": "001\n010\n100" }, { "input": "1 0 1\n8 8 8\n2 0 3", "output": "010\n011\n100" }, { "input": "13 85 77\n25 50 45\n65 79 9", "output": "000\n010\n000" }, { "input": "96 95 5\n8 84 74\n67 31 61", "output": "011\n011\n101" }, {...
1,665,919,676
2,147,483,647
PyPy 3
OK
TESTS
33
124
0
inp = [] for _ in range(3): inp.append(list(map(int, input().split(' ')))) lights = [[1, 1, 1], [1,1,1], [1,1,1]] #print(inp) for i in range(3): for j in range(3): n = inp[i][j] if n % 2 == 0: isOdd = False else: isOdd = True if isOdd: lights...
Title: Lights Out Time Limit: None seconds Memory Limit: None megabytes Problem Description: Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the ...
```python inp = [] for _ in range(3): inp.append(list(map(int, input().split(' ')))) lights = [[1, 1, 1], [1,1,1], [1,1,1]] #print(inp) for i in range(3): for j in range(3): n = inp[i][j] if n % 2 == 0: isOdd = False else: isOdd = True if isOdd: ...
3
984
A
Game
PROGRAMMING
800
[ "sortings" ]
null
null
Two players play a game. Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $n - 1$ turns are made. The first player makes the first move, then players ...
The first line contains one integer $n$ ($1 \le n \le 1000$) — the number of numbers on the board. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$).
Print one number that will be left on the board.
[ "3\n2 1 3\n", "3\n2 2 2\n" ]
[ "2", "2" ]
In the first sample, the first player erases $3$ and the second erases $1$. $2$ is left on the board. In the second sample, $2$ is left on the board regardless of the actions of the players.
500
[ { "input": "3\n2 1 3", "output": "2" }, { "input": "3\n2 2 2", "output": "2" }, { "input": "9\n44 53 51 80 5 27 74 79 94", "output": "53" }, { "input": "10\n38 82 23 37 96 4 81 60 67 86", "output": "60" }, { "input": "10\n58 26 77 15 53 81 68 48 22 65", "outpu...
1,645,886,368
2,147,483,647
Python 3
OK
TESTS
35
61
0
n = int(input()) nums = list(map(int, input().split())) nums.sort(reverse=True) for i in range(1,n): if i%2 !=0: nums.remove(nums[0]) else: nums.remove(nums[-1]) print(nums[0])
Title: Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two players play a game. Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the...
```python n = int(input()) nums = list(map(int, input().split())) nums.sort(reverse=True) for i in range(1,n): if i%2 !=0: nums.remove(nums[0]) else: nums.remove(nums[-1]) print(nums[0]) ```
3
743
C
Vladik and fractions
PROGRAMMING
1,500
[ "brute force", "constructive algorithms", "math", "number theory" ]
null
null
Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer *n* he can represent fraction as a sum of three distinct positive fractions in form . Help Vladik with that, i.e for a given *n* find three distinct positive integers *x*, *y* and *z* such that . Because ...
The single line contains single integer *n* (1<=≤<=*n*<=≤<=104).
If the answer exists, print 3 distinct numbers *x*, *y* and *z* (1<=≤<=*x*,<=*y*,<=*z*<=≤<=109, *x*<=≠<=*y*, *x*<=≠<=*z*, *y*<=≠<=*z*). Otherwise print -1. If there are multiple answers, print any of them.
[ "3\n", "7\n" ]
[ "2 7 42\n", "7 8 56\n" ]
none
1,250
[ { "input": "3", "output": "2 7 42" }, { "input": "7", "output": "7 8 56" }, { "input": "2", "output": "2 3 6" }, { "input": "5", "output": "5 6 30" }, { "input": "4", "output": "4 5 20" }, { "input": "7", "output": "7 8 56" }, { "input": "8...
1,692,604,383
2,147,483,647
Python 3
OK
TESTS
62
46
0
# LUOGU_RID: 122076896 a = int(input()) if a == 1: print(-1) else: print(a, end = ' ') print(a+1, end = ' ') print(a * a + a, end = ' ')
Title: Vladik and fractions Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer *n* he can represent fraction as a sum of three distinct positive fractions in form . Help Vladik ...
```python # LUOGU_RID: 122076896 a = int(input()) if a == 1: print(-1) else: print(a, end = ' ') print(a+1, end = ' ') print(a * a + a, end = ' ') ```
3
789
A
Anastasia and pebbles
PROGRAMMING
1,100
[ "implementation", "math" ]
null
null
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park. She has only two pockets. She can put at most *k* pebbles in each pocket at the same tim...
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=104) — number of pebbles of each type.
The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles.
[ "3 2\n2 3 4\n", "5 4\n3 1 8 9 7\n" ]
[ "3\n", "5\n" ]
In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day. Optimal sequence of actions in the second sample case: - In the first day Anastasia collects 8 pebbles of the third type. - In the second day she...
500
[ { "input": "3 2\n2 3 4", "output": "3" }, { "input": "5 4\n3 1 8 9 7", "output": "5" }, { "input": "1 22\n1", "output": "1" }, { "input": "3 57\n78 165 54", "output": "3" }, { "input": "5 72\n74 10 146 189 184", "output": "6" }, { "input": "9 13\n132 8...
1,532,863,031
2,147,483,647
Python 3
OK
TESTS
31
202
5,939,200
import math n, k = map(int, input().split()) w = map(int, input().split()) res = 0 for el in w: res += math.ceil(float(el) / k) print(math.ceil(float(res) / 2))
Title: Anastasia and pebbles Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could ...
```python import math n, k = map(int, input().split()) w = map(int, input().split()) res = 0 for el in w: res += math.ceil(float(el) / k) print(math.ceil(float(res) / 2)) ```
3
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that 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,621,407,214
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
124
0
n = int(input()) odd = [] even = [] fordo = list(map(int,input().split())) for i in fordo: if i % 2 == 0: even.append(i) else: odd.append(i) if len(odd) > len(even): print(fordo.index(even[0])+1) else: print(fordo.index(even[0])+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()) odd = [] even = [] fordo = list(map(int,input().split())) for i in fordo: if i % 2 == 0: even.append(i) else: odd.append(i) if len(odd) > len(even): print(fordo.index(even[0])+1) else: print(fordo.index(even[0])+1) ```
0
32
B
Borze
PROGRAMMING
800
[ "expression parsing", "implementation" ]
B. Borze
2
256
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output the decoded ternary number. It can have leading zeroes.
[ ".-.--\n", "--.\n", "-..-.--\n" ]
[ "012", "20", "1012" ]
none
1,000
[ { "input": ".-.--", "output": "012" }, { "input": "--.", "output": "20" }, { "input": "-..-.--", "output": "1012" }, { "input": "---..", "output": "210" }, { "input": "..--.---..", "output": "0020210" }, { "input": "-.....----.", "output": "1000022...
1,595,618,445
2,147,483,647
Python 3
OK
TESTS
30
218
6,963,200
s=input() i=0 a=[] while(i!=len(s)): if(s[i]=="."): a.append(0) i+=1 elif(s[i]=="-" and s[i+1]=="."): a.append(1) i+=2 elif(s[i]=="-" and s[i+1]=="-"): a.append(2) i+=2 s="".join(str(e) for e in a) print(s)
Title: Borze Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ...
```python s=input() i=0 a=[] while(i!=len(s)): if(s[i]=="."): a.append(0) i+=1 elif(s[i]=="-" and s[i+1]=="."): a.append(1) i+=2 elif(s[i]=="-" and s[i+1]=="-"): a.append(2) i+=2 s="".join(str(e) for e in a) print(s) ```
3.93253
672
A
Summer Camp
PROGRAMMING
800
[ "implementation" ]
null
null
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems. This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to...
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the position of the digit you need to print.
Print the *n*-th digit of the line.
[ "3\n", "11\n" ]
[ "3\n", "0\n" ]
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit. In the second sample, the digit at position 11 is '0', it belongs to the integer 10.
500
[ { "input": "3", "output": "3" }, { "input": "11", "output": "0" }, { "input": "12", "output": "1" }, { "input": "13", "output": "1" }, { "input": "29", "output": "9" }, { "input": "30", "output": "2" }, { "input": "1000", "output": "3" ...
1,563,641,837
2,147,483,647
Python 3
OK
TESTS
37
109
0
n = int(input()) a = '' for j in range(375): a = a + str(j) print(a[n])
Title: Summer Camp Time Limit: None seconds Memory Limit: None megabytes Problem Description: Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems. This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1...
```python n = int(input()) a = '' for j in range(375): a = a + str(j) print(a[n]) ```
3
450
B
Jzzhu and Sequences
PROGRAMMING
1,300
[ "implementation", "math" ]
null
null
Jzzhu has invented a kind of sequences, they meet the following property: You are given *x* and *y*, please calculate *f**n* modulo 1000000007 (109<=+<=7).
The first line contains two integers *x* and *y* (|*x*|,<=|*y*|<=≤<=109). The second line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109).
Output a single integer representing *f**n* modulo 1000000007 (109<=+<=7).
[ "2 3\n3\n", "0 -1\n2\n" ]
[ "1\n", "1000000006\n" ]
In the first sample, *f*<sub class="lower-index">2</sub> = *f*<sub class="lower-index">1</sub> + *f*<sub class="lower-index">3</sub>, 3 = 2 + *f*<sub class="lower-index">3</sub>, *f*<sub class="lower-index">3</sub> = 1. In the second sample, *f*<sub class="lower-index">2</sub> =  - 1;  - 1 modulo (10<sup class="upper-...
1,000
[ { "input": "2 3\n3", "output": "1" }, { "input": "0 -1\n2", "output": "1000000006" }, { "input": "-9 -11\n12345", "output": "1000000005" }, { "input": "0 0\n1000000000", "output": "0" }, { "input": "-1000000000 1000000000\n2000000000", "output": "1000000000" ...
1,697,050,845
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define MOD 1000000007 //sorting #define vsort(x) sort(x.begin(), x.end()) #define vrsort(x) sort(x.rbegin(), x.rend()) void solve() { ll x, y; cin >> x >> y; ll n; cin >> n; ll ans; n --; n%=6; switch(...
Title: Jzzhu and Sequences Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jzzhu has invented a kind of sequences, they meet the following property: You are given *x* and *y*, please calculate *f**n* modulo 1000000007 (109<=+<=7). Input Specification: The first line contains two integers...
```python #include <bits/stdc++.h> using namespace std; typedef long long int ll; #define MOD 1000000007 //sorting #define vsort(x) sort(x.begin(), x.end()) #define vrsort(x) sort(x.rbegin(), x.rend()) void solve() { ll x, y; cin >> x >> y; ll n; cin >> n; ll ans; n --; n%=6; ...
-1
148
A
Insomnia cure
PROGRAMMING
800
[ "constructive algorithms", "implementation", "math" ]
null
null
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and ...
Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105).
Output the number of damaged dragons.
[ "1\n2\n3\n4\n12\n", "2\n3\n4\n5\n24\n" ]
[ "12\n", "17\n" ]
In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough. In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed.
1,000
[ { "input": "1\n2\n3\n4\n12", "output": "12" }, { "input": "2\n3\n4\n5\n24", "output": "17" }, { "input": "1\n1\n1\n1\n100000", "output": "100000" }, { "input": "10\n9\n8\n7\n6", "output": "0" }, { "input": "8\n4\n4\n3\n65437", "output": "32718" }, { "i...
1,691,412,000
2,147,483,647
Python 3
OK
TESTS
40
124
716,800
# N = int(input()) # N,M = map(int,input().split()) # A = list(map(int,input().split())) k = int(input()) l = int(input()) m = int(input()) n = int(input()) d = int(input()) a = [False] * d for i in range(k-1,d,k): a[i] = True for i in range(l-1,d,l): a[i] = True for i in range(m-1,d,m): a...
Title: Insomnia cure Time Limit: None seconds Memory Limit: None megabytes Problem Description: «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entert...
```python # N = int(input()) # N,M = map(int,input().split()) # A = list(map(int,input().split())) k = int(input()) l = int(input()) m = int(input()) n = int(input()) d = int(input()) a = [False] * d for i in range(k-1,d,k): a[i] = True for i in range(l-1,d,l): a[i] = True for i in range(m-1,d,...
3
598
A
Tricky Sum
PROGRAMMING
900
[ "math" ]
null
null
In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum. For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, because 1, 2 and 4 are 20, 21 and 22 respectively. Calculate the answer for *t* values of *n*.
The first line of the input contains a single integer *t* (1<=≤<=*t*<=≤<=100) — the number of values of *n* to be processed. Each of next *t* lines contains a single integer *n* (1<=≤<=*n*<=≤<=109).
Print the requested sum for each of *t* integers *n* given in the input.
[ "2\n4\n1000000000\n" ]
[ "-4\n499999998352516354\n" ]
The answer for the first sample is explained in the statement.
0
[ { "input": "2\n4\n1000000000", "output": "-4\n499999998352516354" }, { "input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "output": "-1\n-3\n0\n-4\n1\n7\n14\n6\n15\n25" }, { "input": "10\n10\n9\n47\n33\n99\n83\n62\n1\n100\n53", "output": "25\n15\n1002\n435\n4696\n3232\n1827\n-1\n4796\n130...
1,680,169,926
2,147,483,647
Python 3
OK
TESTS
21
46
0
t = int(input()) for _ in range(t): n = int(input()) total_sum = n * (n + 1) // 2 power_of_two = 1 while power_of_two <= n: total_sum -= 2 * power_of_two power_of_two *= 2 print(total_sum)
Title: Tricky Sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum. For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, be...
```python t = int(input()) for _ in range(t): n = int(input()) total_sum = n * (n + 1) // 2 power_of_two = 1 while power_of_two <= n: total_sum -= 2 * power_of_two power_of_two *= 2 print(total_sum) ```
3
924
B
Three-level Laser
PROGRAMMING
1,600
[ "binary search", "greedy", "two pointers" ]
null
null
An atom of element X can exist in *n* distinct states with energies *E*1<=&lt;<=*E*2<=&lt;<=...<=&lt;<=*E**n*. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states *i*, *j* and *k* are selected, where *i*<=&lt;<=*j*<=&lt;<=*k*...
The first line contains two integers *n* and *U* (3<=≤<=*n*<=≤<=105, 1<=≤<=*U*<=≤<=109) — the number of states and the maximum possible difference between *E**k* and *E**i*. The second line contains a sequence of integers *E*1,<=*E*2,<=...,<=*E**n* (1<=≤<=*E*1<=&lt;<=*E*2...<=&lt;<=*E**n*<=≤<=109). It is guaranteed th...
If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number η — the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10<=-<=9. Formally, let your answer be *a*, and the jury's answe...
[ "4 4\n1 3 5 7\n", "10 8\n10 13 15 16 17 19 20 22 24 25\n", "3 1\n2 5 10\n" ]
[ "0.5\n", "0.875\n", "-1\n" ]
In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/147ae7a830722917b0aa37d064df8eb74cfefb97.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second example choose states 4, 5 a...
1,000
[ { "input": "4 4\n1 3 5 7", "output": "0.5" }, { "input": "10 8\n10 13 15 16 17 19 20 22 24 25", "output": "0.875" }, { "input": "3 1\n2 5 10", "output": "-1" }, { "input": "5 3\n4 6 8 9 10", "output": "0.5" }, { "input": "10 128\n110 121 140 158 174 188 251 271 27...
1,632,373,496
2,147,483,647
PyPy 3
OK
TESTS
76
202
30,822,400
def f(a,x): k=0 ans=-1 for i in range(len(a)): while k+1<len(a) and a[k+1]-a[i]<=x: k+=1 if k-i<2: continue ans=max(ans,(a[k]-a[i+1])/(a[k]-a[i])) return ans n,x=map(int,input().strip().split()) l=list(map(int,input().strip().split())) print(f(l,x)) ...
Title: Three-level Laser Time Limit: None seconds Memory Limit: None megabytes Problem Description: An atom of element X can exist in *n* distinct states with energies *E*1<=&lt;<=*E*2<=&lt;<=...<=&lt;<=*E**n*. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified descriptio...
```python def f(a,x): k=0 ans=-1 for i in range(len(a)): while k+1<len(a) and a[k+1]-a[i]<=x: k+=1 if k-i<2: continue ans=max(ans,(a[k]-a[i+1])/(a[k]-a[i])) return ans n,x=map(int,input().strip().split()) l=list(map(int,input().strip().split())) print(f(...
3
385
E
Bear in the Field
PROGRAMMING
2,300
[ "math", "matrices" ]
null
null
Our bear's forest has a checkered field. The checkered field is an *n*<=×<=*n* table, the rows are numbered from 1 to *n* from top to bottom, the columns are numbered from 1 to *n* from left to right. Let's denote a cell of the field on the intersection of row *x* and column *y* by record (*x*,<=*y*). Each cell of the ...
The first line of the input contains six space-separated integers: *n*, *sx*, *sy*, *dx*, *dy*, *t* (1<=≤<=*n*<=≤<=109; 1<=≤<=*sx*,<=*sy*<=≤<=*n*; <=-<=100<=≤<=*dx*,<=*dy*<=≤<=100; 0<=≤<=*t*<=≤<=1018).
Print two integers — the coordinates of the cell the bear will end up in after *t* seconds.
[ "5 1 2 0 1 2\n", "1 1 1 -1 -1 2\n" ]
[ "3 1", "1 1" ]
Operation *a* *mod* *b* means taking the remainder after dividing *a* by *b*. Note that the result of the operation is always non-negative. For example, ( - 1) *mod* 3 = 2. In the first sample before the first move the speed vector will equal (3,4) and the bear will get to cell (4,1). Before the second move the speed ...
2,500
[ { "input": "5 1 2 0 1 2", "output": "3 1" }, { "input": "1 1 1 -1 -1 2", "output": "1 1" }, { "input": "1 1 1 1 1 0", "output": "1 1" }, { "input": "2 2 1 -2 -2 5", "output": "1 2" }, { "input": "1000000000 1 1 1 1 1000000000000000000", "output": "168318977 16...
1,456,799,744
2,147,483,647
PyPy 3
OK
TESTS
50
218
5,734,400
#Simple non-optimized class of matrices. Used with small dense matrices. import functools import itertools import math class NotAMatrixError(Exception): pass class MatrixSizeError(Exception): def __init__(self, s1, s2): print('sizes do not match : ', s1, ', ', s2) class NotSquareError(Exception): ...
Title: Bear in the Field Time Limit: None seconds Memory Limit: None megabytes Problem Description: Our bear's forest has a checkered field. The checkered field is an *n*<=×<=*n* table, the rows are numbered from 1 to *n* from top to bottom, the columns are numbered from 1 to *n* from left to right. Let's denote a c...
```python #Simple non-optimized class of matrices. Used with small dense matrices. import functools import itertools import math class NotAMatrixError(Exception): pass class MatrixSizeError(Exception): def __init__(self, s1, s2): print('sizes do not match : ', s1, ', ', s2) class NotSquareError(Excep...
3
133
A
HQ9+
PROGRAMMING
900
[ "implementation" ]
null
null
HQ9+ is a joke programming language which has only four one-character instructions: - "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator. Instructions "H" and "Q" are case-s...
The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive.
Output "YES", if executing the program will produce any output, and "NO" otherwise.
[ "Hi!\n", "Codeforces\n" ]
[ "YES\n", "NO\n" ]
In the first case the program contains only one instruction — "H", which prints "Hello, World!". In the second case none of the program characters are language instructions.
500
[ { "input": "Hi!", "output": "YES" }, { "input": "Codeforces", "output": "NO" }, { "input": "a+b=c", "output": "NO" }, { "input": "hq-lowercase", "output": "NO" }, { "input": "Q", "output": "YES" }, { "input": "9", "output": "YES" }, { "inpu...
1,698,776,405
2,147,483,647
Python 3
OK
TESTS
85
92
0
str_input = input() flag = False for char in str_input: if 33 <= ord(char) <= 126: if char in ['H', 'Q', '9']: flag = True break if flag: print("YES") else: print("NO")
Title: HQ9+ Time Limit: None seconds Memory Limit: None megabytes Problem Description: HQ9+ is a joke programming language which has only four one-character instructions: - "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" in...
```python str_input = input() flag = False for char in str_input: if 33 <= ord(char) <= 126: if char in ['H', 'Q', '9']: flag = True break if flag: print("YES") else: print("NO") ```
3
460
A
Vasya and Socks
PROGRAMMING
900
[ "brute force", "implementation", "math" ]
null
null
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it la...
The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space.
Print a single integer — the answer to the problem.
[ "2 2\n", "9 3\n" ]
[ "3\n", "13\n" ]
In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two. In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on...
500
[ { "input": "2 2", "output": "3" }, { "input": "9 3", "output": "13" }, { "input": "1 2", "output": "1" }, { "input": "2 3", "output": "2" }, { "input": "1 99", "output": "1" }, { "input": "4 4", "output": "5" }, { "input": "10 2", "outp...
1,649,167,422
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
46
0
n,m = map(int,input().split()) ans = n // m a = n + ans if a % m == 0: a += 1 print(a)
Title: Vasya and Socks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th...
```python n,m = map(int,input().split()) ans = n // m a = n + ans if a % m == 0: a += 1 print(a) ```
0
492
A
Vanya and Cubes
PROGRAMMING
800
[ "implementation" ]
null
null
Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the third level must have 1<=+<=2<=+<=3<==<=6 cubes, and so on. Thus, the *i*-th level of the pyramid must...
The first line contains integer *n* (1<=≤<=*n*<=≤<=104) — the number of cubes given to Vanya.
Print the maximum possible height of the pyramid in the single line.
[ "1\n", "25\n" ]
[ "1\n", "4\n" ]
Illustration to the second sample:
500
[ { "input": "1", "output": "1" }, { "input": "25", "output": "4" }, { "input": "2", "output": "1" }, { "input": "4115", "output": "28" }, { "input": "9894", "output": "38" }, { "input": "7969", "output": "35" }, { "input": "6560", "outpu...
1,691,164,901
2,147,483,647
PyPy 3-64
COMPILATION_ERROR
TESTS
0
0
0
for _ in range(1) n = int(input()) counter = 1 countdodo = 0 rows = 0 while n > 0: countdodo += counter counter += 1 rows += 1 n -= countdodo if n == 0: print(rows) else: print(rows - 1)
Title: Vanya and Cubes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the t...
```python for _ in range(1) n = int(input()) counter = 1 countdodo = 0 rows = 0 while n > 0: countdodo += counter counter += 1 rows += 1 n -= countdodo if n == 0: print(rows) else: print(rows - 1) ```
-1
985
A
Chess Placing
PROGRAMMING
1,100
[ "implementation" ]
null
null
You are given a chessboard of size 1<=×<=*n*. It is guaranteed that *n* is even. The chessboard is painted like this: "BWBW...BW". Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known that the total number of pieces equals to . In one step you can move...
The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100, *n* is even) — the size of the chessboard. The second line of the input contains integer numbers (1<=≤<=*p**i*<=≤<=*n*) — initial positions of the pieces. It is guaranteed that all the positions are distinct.
Print one integer — the minimum number of moves you have to make to place all the pieces in the cells of the same color.
[ "6\n1 2 6\n", "10\n1 2 3 4 5\n" ]
[ "2\n", "10\n" ]
In the first example the only possible strategy is to move the piece at the position 6 to the position 5 and move the piece at the position 2 to the position 3. Notice that if you decide to place the pieces in the white cells the minimum number of moves will be 3. In the second example the possible strategy is to move...
0
[ { "input": "6\n1 2 6", "output": "2" }, { "input": "10\n1 2 3 4 5", "output": "10" }, { "input": "2\n2", "output": "0" }, { "input": "100\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 ...
1,586,277,044
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
140
0
n=int(input()) l=list(map(int,input().strip().split())) s1=0 s2=0 for i in range(n//2): s1+=abs(l[i]-(2*i+1)) s2+=abs(l[i]-(2*i+2)) print(min(s1,s2))
Title: Chess Placing Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a chessboard of size 1<=×<=*n*. It is guaranteed that *n* is even. The chessboard is painted like this: "BWBW...BW". Some cells of the board are occupied by the chess pieces. Each cell contains no more than...
```python n=int(input()) l=list(map(int,input().strip().split())) s1=0 s2=0 for i in range(n//2): s1+=abs(l[i]-(2*i+1)) s2+=abs(l[i]-(2*i+2)) print(min(s1,s2)) ```
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,676,917,249
2,147,483,647
PyPy 3-64
OK
TESTS
30
62
0
a, b =list( map(int, input().split())) def kamal(n): c=n+11 return c m = min(a, b) mm = max(a, b) jdkd=kamal(99) dd = m ss = (mm - m) // 2 print(dd, ss)
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 =list( map(int, input().split())) def kamal(n): c=n+11 return c m = min(a, b) mm = max(a, b) jdkd=kamal(99) dd = m ss = (mm - m) // 2 print(dd, ss) ```
3
115
A
Party
PROGRAMMING
900
[ "dfs and similar", "graphs", "trees" ]
null
null
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true: - Employee *A* is the immedi...
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees. The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate...
Print a single integer denoting the minimum number of groups that will be formed in the party.
[ "5\n-1\n1\n2\n1\n-1\n" ]
[ "3\n" ]
For the first example, three groups are sufficient, for example: - Employee 1 - Employees 2 and 4 - Employees 3 and 5
500
[ { "input": "5\n-1\n1\n2\n1\n-1", "output": "3" }, { "input": "4\n-1\n1\n2\n3", "output": "4" }, { "input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11", "output": "4" }, { "input": "6\n-1\n-1\n2\n3\n1\n1", "output": "3" }, { "input": "3\n-1\n1\n1", "output": ...
1,660,045,187
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
62
102,400
from collections import defaultdict total = int(input()) graph = defaultdict(list) target = [] for i in range(1, n+1): child = int(input()) if i == -1: target.append(child) else: graph[i].append(child) def dfs(i): if not graph[i]: return 1 tot...
Title: Party Time Limit: None seconds Memory Limit: None megabytes Problem Description: A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of an...
```python from collections import defaultdict total = int(input()) graph = defaultdict(list) target = [] for i in range(1, n+1): child = int(input()) if i == -1: target.append(child) else: graph[i].append(child) def dfs(i): if not graph[i]: return 1 ...
-1
0
none
none
none
0
[ "none" ]
null
null
Firecrackers scare Nian the monster, but they're wayyyyy too noisy! Maybe fireworks make a nice complement. Little Tommy is watching a firework show. As circular shapes spread across the sky, a splendid view unfolds on the night of Lunar New Year's eve. A wonder strikes Tommy. How many regions are formed by the circl...
The first line of input contains one integer *n* (1<=≤<=*n*<=≤<=3), denoting the number of circles. The following *n* lines each contains three space-separated integers *x*, *y* and *r* (<=-<=10<=≤<=*x*,<=*y*<=≤<=10, 1<=≤<=*r*<=≤<=10), describing a circle whose center is (*x*,<=*y*) and the radius is *r*. No two circl...
Print a single integer — the number of regions on the plane.
[ "3\n0 0 1\n2 0 1\n4 0 1\n", "3\n0 0 2\n3 0 2\n6 0 2\n", "3\n0 0 2\n2 0 2\n1 1 2\n" ]
[ "4\n", "6\n", "8\n" ]
For the first example, For the second example, For the third example,
0
[ { "input": "3\n0 0 1\n2 0 1\n4 0 1", "output": "4" }, { "input": "3\n0 0 2\n3 0 2\n6 0 2", "output": "6" }, { "input": "3\n0 0 2\n2 0 2\n1 1 2", "output": "8" }, { "input": "1\n0 0 10", "output": "2" }, { "input": "2\n-10 10 1\n10 -10 1", "output": "3" }, ...
1,594,571,822
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
8
202
22,528,000
import sys import math def dist(a, b): return math.sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1])) def samep(a, b): EPS = 0.01 if a - b < -EPS or a - b > EPS: return False return True def same(a, b): return samep(a[0], b[0]) and samep(a[1], b[1]) def st...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Firecrackers scare Nian the monster, but they're wayyyyy too noisy! Maybe fireworks make a nice complement. Little Tommy is watching a firework show. As circular shapes spread across the sky, a splendid view unfolds on the night ...
```python import sys import math def dist(a, b): return math.sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1])) def samep(a, b): EPS = 0.01 if a - b < -EPS or a - b > EPS: return False return True def same(a, b): return samep(a[0], b[0]) and samep(a[1], b[1])...
-1
709
A
Juicer
PROGRAMMING
900
[ "implementation" ]
null
null
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange ...
The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied. The second line co...
Print one integer — the number of times Kolya will have to empty the waste section.
[ "2 7 10\n5 6\n", "1 5 10\n7\n", "3 10 10\n5 7 7\n", "1 1 1\n1\n" ]
[ "1\n", "0\n", "1\n", "0\n" ]
In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards. In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all.
500
[ { "input": "2 7 10\n5 6", "output": "1" }, { "input": "1 5 10\n7", "output": "0" }, { "input": "3 10 10\n5 7 7", "output": "1" }, { "input": "1 1 1\n1", "output": "0" }, { "input": "2 951637 951638\n44069 951637", "output": "1" }, { "input": "50 100 12...
1,686,731,220
2,147,483,647
PyPy 3-64
OK
TESTS
58
93
13,516,800
n,b,d = list(map(int,input().split())) a = list(map(int,input().split())) counter, ans = 0, 0 for i in a: counter += i if i <= b else 0 if counter > d: counter, ans = 0, ans+1 print(ans)
Title: Juicer Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To b...
```python n,b,d = list(map(int,input().split())) a = list(map(int,input().split())) counter, ans = 0, 0 for i in a: counter += i if i <= b else 0 if counter > d: counter, ans = 0, ans+1 print(ans) ```
3
225
A
Dice Tower
PROGRAMMING
1,100
[ "constructive algorithms", "greedy" ]
null
null
A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given constraints (both of them are shown on the picture on the left). Alice...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of dice in the tower. The second line contains an integer *x* (1<=≤<=*x*<=≤<=6) — the number Bob sees at the top of the tower. Next *n* lines contain two space-separated integers each: the *i*-th line contains numbers *a**i*,<=*b**i* (1<=≤<=...
Print "YES" (without the quotes), if it is possible to to uniquely identify the numbers on the faces of all the dice in the tower. If it is impossible, print "NO" (without the quotes).
[ "3\n6\n3 2\n5 4\n2 4\n", "3\n3\n2 6\n4 1\n5 3\n" ]
[ "YES", "NO" ]
none
500
[ { "input": "3\n6\n3 2\n5 4\n2 4", "output": "YES" }, { "input": "3\n3\n2 6\n4 1\n5 3", "output": "NO" }, { "input": "1\n3\n2 1", "output": "YES" }, { "input": "2\n2\n3 1\n1 5", "output": "NO" }, { "input": "3\n2\n1 4\n5 3\n6 4", "output": "NO" }, { "in...
1,548,776,747
2,147,483,647
Python 3
OK
TESTS
52
218
0
n=int(input()) D={} for i in range(1,7): D[i]=1 num=int(input()) del(D[num]) del(D[7-num]) k=0 while n!=0 and k==0: n-=1 for i in list(input().split()): if int(i) not in D: k=1 if k==1: print("NO") else: print("YES")
Title: Dice Tower Time Limit: None seconds Memory Limit: None megabytes Problem Description: A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other...
```python n=int(input()) D={} for i in range(1,7): D[i]=1 num=int(input()) del(D[num]) del(D[7-num]) k=0 while n!=0 and k==0: n-=1 for i in list(input().split()): if int(i) not in D: k=1 if k==1: print("NO") else: print("YES") ```
3
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,510,965,763
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
0
p = input() n = int(input()) a = [] for _ in range(n): s = input() if s == p: print('YES') exit() a.append(s) for i in range(n): for j in range(i+1, n): if a[i][1] == p[0] and a[j][0] == p[1]: print('YES') exit() break if...
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()) a = [] for _ in range(n): s = input() if s == p: print('YES') exit() a.append(s) for i in range(n): for j in range(i+1, n): if a[i][1] == p[0] and a[j][0] == p[1]: print('YES') exit() break ...
0
725
B
Food on the Plane
PROGRAMMING
1,200
[ "implementation", "math" ]
null
null
A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats...
The only line of input contains a description of Vasya's seat in the format *ns*, where *n* (1<=≤<=*n*<=≤<=1018) is the index of the row and *s* is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space.
Print one integer — the number of seconds Vasya has to wait until he gets his lunch.
[ "1f\n", "2d\n", "4a\n", "5e\n" ]
[ "1\n", "10\n", "11\n", "18\n" ]
In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second. In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisl...
1,000
[ { "input": "1f", "output": "1" }, { "input": "2d", "output": "10" }, { "input": "4a", "output": "11" }, { "input": "5e", "output": "18" }, { "input": "2c", "output": "13" }, { "input": "1b", "output": "5" }, { "input": "1000000000000000000d...
1,697,395,902
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
31
0
def numb(c): if c=='f': return 1 if c=='e': return 2 if c=='d': return 3 if c=='a': return 4 if c=='b': return 5 return 6 s = input() seat = numb(s[-1]) row = int(s[:len(s)-1]) if row%4==0: row = 4 four = row//4 - 1 else: four = row//4 row %= 4 time = four*16 + ...
Title: Food on the Plane Time Limit: None seconds Memory Limit: None megabytes Problem Description: A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' ...
```python def numb(c): if c=='f': return 1 if c=='e': return 2 if c=='d': return 3 if c=='a': return 4 if c=='b': return 5 return 6 s = input() seat = numb(s[-1]) row = int(s[:len(s)-1]) if row%4==0: row = 4 four = row//4 - 1 else: four = row//4 row %= 4 time = ...
0
493
A
Vasya and Football
PROGRAMMING
1,300
[ "implementation" ]
null
null
Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card. Vasya is watching a recorded football match now and makes notes of all the fouls tha...
The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number *n* (1<=≤<=*n*<=≤<=9...
For each event when a player received his first red card in a chronological order print a string containing the following information: - The name of the team to which the player belongs; - the player's number in his team; - the minute when he received the card. If no player received a card, then you do not need to...
[ "MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r\n" ]
[ "MC 25 70\nMC 42 82\nCSKA 13 90\n" ]
none
500
[ { "input": "MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r", "output": "MC 25 70\nMC 42 82\nCSKA 13 90" }, { "input": "REAL\nBARCA\n3\n27 h 7 y\n44 a 10 y\n87 h 3 r", "output": "REAL 3 87" }, { "input": "MASFF\nSAFBDSRG\n5\n1 ...
1,532,667,374
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
93
0
t1=input() t2=input() n=int(input()) team1={} team2={} for i in range(n): l=list(map(str,input().split())) l[2]=int(l[2]) if l[1]=="h": if l[2] in team1: if l[3]=='y': team1[l[2]][0]+=1 else: team1[l[2]][1]+=1 else: ...
Title: Vasya and Football Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically re...
```python t1=input() t2=input() n=int(input()) team1={} team2={} for i in range(n): l=list(map(str,input().split())) l[2]=int(l[2]) if l[1]=="h": if l[2] in team1: if l[3]=='y': team1[l[2]][0]+=1 else: team1[l[2]][1]+=1 el...
0
33
A
What is for dinner?
PROGRAMMING
1,200
[ "greedy", "implementation" ]
A. What is for dinner?
2
256
In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". ...
The first line contains three integers *n*, *m*, *k* (1<=≤<=*m*<=≤<=*n*<=≤<=1000,<=0<=≤<=*k*<=≤<=106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow *n* lines, each containing two integers: *r* (1<=≤<=*r*<=≤<=*m*) — index of the row, where bel...
In the first line output the maximum amount of crucians that Valerie can consume for dinner.
[ "4 3 18\n2 3\n1 2\n3 6\n2 3\n", "2 2 13\n1 13\n2 12\n" ]
[ "11\n", "13\n" ]
none
500
[ { "input": "4 3 18\n2 3\n1 2\n3 6\n2 3", "output": "11" }, { "input": "2 2 13\n1 13\n2 12", "output": "13" }, { "input": "5 4 8\n4 6\n4 5\n1 3\n2 0\n3 3", "output": "8" }, { "input": "1 1 0\n1 3", "output": "0" }, { "input": "7 1 30\n1 8\n1 15\n1 5\n1 17\n1 9\n1 1...
1,695,836,127
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
92
1,126,400
m = [1,2]*100000
Title: What is for dinner? Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that...
```python m = [1,2]*100000 ```
0
755
B
PolandBall and Game
PROGRAMMING
1,100
[ "binary search", "data structures", "games", "greedy", "sortings", "strings" ]
null
null
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses. You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, i...
The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=103) — number of words PolandBall and EnemyBall know, respectively. Then *n* strings follow, one per line — words familiar to PolandBall. Then *m* strings follow, one per line — words familiar to EnemyBall. Note that one Ball cannot know a w...
In a single line of print the answer — "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally.
[ "5 1\npolandball\nis\na\ncool\ncharacter\nnope\n", "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska\n", "1 2\na\na\nb\n" ]
[ "YES", "YES", "NO" ]
In the first example PolandBall knows much more words and wins effortlessly. In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins.
1,000
[ { "input": "5 1\npolandball\nis\na\ncool\ncharacter\nnope", "output": "YES" }, { "input": "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska", "output": "YES" }, { "input": "1 2\na\na\nb", "output": "NO" }, { "input": "2 2\na\nb\nb\nc", "output": "YES" }, { "input": "...
1,634,929,600
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
4,505,600
if __name__ == "__main__": n, m = input().split(" ") n = int(n) m = int(m) string_set = set() for i in range(n + m): s = input() string_set.add(s) if n + m - len(string_set) > 0: com = n + m - len(string_set) n -= com m -= com if...
Title: PolandBall and Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses. You...
```python if __name__ == "__main__": n, m = input().split(" ") n = int(n) m = int(m) string_set = set() for i in range(n + m): s = input() string_set.add(s) if n + m - len(string_set) > 0: com = n + m - len(string_set) n -= com m -= com ...
0
3
A
Shortest path of the king
PROGRAMMING
1,000
[ "greedy", "shortest paths" ]
A. Shortest path of the king
1
64
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the le...
The first line contains the chessboard coordinates of square *s*, the second line — of square *t*. Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8.
In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD. L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diago...
[ "a8\nh1\n" ]
[ "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n" ]
none
0
[ { "input": "a8\nh1", "output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD" }, { "input": "b2\nb4", "output": "2\nU\nU" }, { "input": "a5\na5", "output": "0" }, { "input": "h1\nb2", "output": "6\nLU\nL\nL\nL\nL\nL" }, { "input": "c5\nh2", "output": "5\nRD\nRD\nRD\nR\nR" ...
1,674,859,486
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
62
0
board = [] for i in range(1, 9): board.append([0, 0, 0, 0, 0, 0, 0, 0]) start_letter = input() end_letter = input() letter_to_num = { "a": 0, "b": 1, "c": 2, "d": 3, "e": 4, "f": 5, "g": 6, "h": 7, } start = [int(start_letter[1]) - 1, letter_to_num[start_letter...
Title: Shortest path of the king Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king ...
```python board = [] for i in range(1, 9): board.append([0, 0, 0, 0, 0, 0, 0, 0]) start_letter = input() end_letter = input() letter_to_num = { "a": 0, "b": 1, "c": 2, "d": 3, "e": 4, "f": 5, "g": 6, "h": 7, } start = [int(start_letter[1]) - 1, letter_to_num[st...
0
0
none
none
none
0
[ "none" ]
null
null
Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it. He pain...
The first and the single line of the input contains 6 space-separated integers *a*1,<=*a*2,<=*a*3,<=*a*4,<=*a*5 and *a*6 (1<=≤<=*a**i*<=≤<=1000) — the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides ex...
Print a single integer — the number of triangles with the sides of one 1 centimeter, into which the hexagon is split.
[ "1 1 1 1 1 1\n", "1 2 1 2 1 2\n" ]
[ "6\n", "13\n" ]
This is what Gerald's hexagon looks like in the first sample: <img class="tex-graphics" src="https://espresso.codeforces.com/84d193e27b02c38eb1eadc536602a2ec0b9f9519.png" style="max-width: 100.0%;max-height: 100.0%;"/> And that's what it looks like in the second sample: <img class="tex-graphics" src="https://espress...
0
[ { "input": "1 1 1 1 1 1", "output": "6" }, { "input": "1 2 1 2 1 2", "output": "13" }, { "input": "2 4 5 3 3 6", "output": "83" }, { "input": "45 19 48 18 46 21", "output": "6099" }, { "input": "66 6 65 6 66 5", "output": "5832" }, { "input": "7 5 4 8 ...
1,681,020,754
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
46
0
from math import sqrt def main(): S = list(map(int, input().split())) s1 = S[0] s2 = None for i in range(1, 6): if S[i] != s1: s2 = S[i] if s2 is None: s2 = s1 c1 = s2 * (s1 + s1 + s2) c2 = s1 * (s2 + s1 + s2) print(c1 + c2) if __name__ == "__m...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centime...
```python from math import sqrt def main(): S = list(map(int, input().split())) s1 = S[0] s2 = None for i in range(1, 6): if S[i] != s1: s2 = S[i] if s2 is None: s2 = s1 c1 = s2 * (s1 + s1 + s2) c2 = s1 * (s2 + s1 + s2) print(c1 + c2) if __name...
0
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,661,667,050
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
31
0
def solve(): n = map(int, input().strip().split()) arr = list(map(int, input().strip().split())) itr = 0 for i in arr: if i == 0: itr += 1 if itr > 1: print("NO") break if itr == 1: print("YES") solve()
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 def solve(): n = map(int, input().strip().split()) arr = list(map(int, input().strip().split())) itr = 0 for i in arr: if i == 0: itr += 1 if itr > 1: print("NO") break if itr == 1: print("YES") solve() ```
0
499
B
Lecture
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consi...
The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages. The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* bel...
Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.
[ "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n", "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n" ]
[ "codeforces round letter round\n", "hbnyiyc joll joll un joll\n" ]
none
500
[ { "input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest", "output": "codeforces round letter round" }, { "input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll", "output": "hbnyiyc joll joll un joll" }, { "input"...
1,638,471,736
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
8
1,000
204,800
n , m = map(int,input().split(' ')) mat = [] ans = '' while m>0: m-=1 a,b = map(str,input().split(' ')) mat.append((a,b)) text = input().split(' ') for i in range(n): for j in range(len(mat)): if text[i]==(mat[j][0]): if len(text[i])<len(mat[j][1]): ans+=t...
Title: Lecture Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first ...
```python n , m = map(int,input().split(' ')) mat = [] ans = '' while m>0: m-=1 a,b = map(str,input().split(' ')) mat.append((a,b)) text = input().split(' ') for i in range(n): for j in range(len(mat)): if text[i]==(mat[j][0]): if len(text[i])<len(mat[j][1]): ...
0
492
B
Vanya and Lanterns
PROGRAMMING
1,200
[ "binary search", "implementation", "math", "sortings" ]
null
null
Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that...
The first line contains two integers *n*, *l* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*l*<=≤<=109) — the number of lanterns and the length of the street respectively. The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of th...
Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9.
[ "7 15\n15 5 3 7 9 14 0\n", "2 5\n2 5\n" ]
[ "2.5000000000\n", "2.0000000000\n" ]
Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit.
1,000
[ { "input": "7 15\n15 5 3 7 9 14 0", "output": "2.5000000000" }, { "input": "2 5\n2 5", "output": "2.0000000000" }, { "input": "46 615683844\n431749087 271781274 274974690 324606253 480870261 401650581 13285442 478090364 266585394 425024433 588791449 492057200 391293435 563090494 317950 1...
1,687,996,370
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
def search_value(L,m,t): if(not(0 in L) and not(t in L)): if(L[0] > m and (t-L[len(L)-1])<m): return L[0] elif(L[0] < m and (t-L[len(L)-1])>m): return t - L[len(L)-1] else: return max elif( not(0 in L) and (t in L)): if(L[0] > m): ...
Title: Vanya and Lanterns Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the poi...
```python def search_value(L,m,t): if(not(0 in L) and not(t in L)): if(L[0] > m and (t-L[len(L)-1])<m): return L[0] elif(L[0] < m and (t-L[len(L)-1])>m): return t - L[len(L)-1] else: return max elif( not(0 in L) and (t in L)): if(L[0] ...
0
845
B
Luba And The Ticket
PROGRAMMING
1,600
[ "brute force", "greedy", "implementation" ]
null
null
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky. The ticket is considered lucky if the sum of first three digits equals to the sum of las...
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.
Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.
[ "000000\n", "123456\n", "111000\n" ]
[ "0\n", "2\n", "1\n" ]
In the first example the ticket is already lucky, so the answer is 0. In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required. In the third example Luba can replace any zero with 3. It's easy to see that at least one re...
0
[ { "input": "000000", "output": "0" }, { "input": "123456", "output": "2" }, { "input": "111000", "output": "1" }, { "input": "120111", "output": "0" }, { "input": "999999", "output": "0" }, { "input": "199880", "output": "1" }, { "input": "...
1,669,139,473
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
31
0
a, b, c, d, e, f = map(int, list(input())) sum1 = a + b + c sum2 = d + e + f arr1 = [a, b, c] arr2 = [d, e, f] arr1.sort() arr2.sort() if sum1 == sum2 : print(0) elif sum1 < sum2 : arr1[0] = 9 if sum(arr1) >= sum(arr2) : print(1) else : arr1[1] = 9 if sum(arr1)...
Title: Luba And The Ticket Time Limit: None seconds Memory Limit: None megabytes Problem Description: Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make th...
```python a, b, c, d, e, f = map(int, list(input())) sum1 = a + b + c sum2 = d + e + f arr1 = [a, b, c] arr2 = [d, e, f] arr1.sort() arr2.sort() if sum1 == sum2 : print(0) elif sum1 < sum2 : arr1[0] = 9 if sum(arr1) >= sum(arr2) : print(1) else : arr1[1] = 9 if...
0
621
A
Wet Shark and Odd and Even
PROGRAMMING
900
[ "implementation" ]
null
null
Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark. Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0.
The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive.
Print the maximum possible even sum that can be obtained if we use some of the given integers.
[ "3\n1 2 3\n", "5\n999999999 999999999 999999999 999999999 999999999\n" ]
[ "6", "3999999996" ]
In the first sample, we can simply take all three integers for a total sum of 6. In the second sample Wet Shark should take any four out of five integers 999 999 999.
500
[ { "input": "3\n1 2 3", "output": "6" }, { "input": "5\n999999999 999999999 999999999 999999999 999999999", "output": "3999999996" }, { "input": "1\n1", "output": "0" }, { "input": "15\n39 52 88 78 46 95 84 98 55 3 68 42 6 18 98", "output": "870" }, { "input": "15\...
1,689,183,683
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
14
77
12,800,000
n=int(input()) t=sorted(int(x) for x in input().split()) a=t x=0 b=sum(a) if (b%2)==0: print(b) elif (b%2)!=0: while (b%2)!=0: b=b-a[x] if b%2==0: break else: x=x+1 print(b)
Title: Wet Shark and Odd and Even Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark. Note, th...
```python n=int(input()) t=sorted(int(x) for x in input().split()) a=t x=0 b=sum(a) if (b%2)==0: print(b) elif (b%2)!=0: while (b%2)!=0: b=b-a[x] if b%2==0: break else: x=x+1 print(b) ```
0
123
A
Prime Permutation
PROGRAMMING
1,300
[ "implementation", "number theory", "strings" ]
null
null
You are given a string *s*, consisting of small Latin letters. Let's denote the length of the string as |*s*|. The characters in the string are numbered starting from 1. Your task is to find out if it is possible to rearrange characters in string *s* so that for any prime number *p*<=≤<=|*s*| and for any integer *i* ...
The only line contains the initial string *s*, consisting of small Latin letters (1<=≤<=|*s*|<=≤<=1000).
If it is possible to rearrange the characters in the string so that the above-mentioned conditions were fulfilled, then print in the first line "YES" (without the quotes) and print on the second line one of the possible resulting strings. If such permutation is impossible to perform, then print the single string "NO".
[ "abc\n", "abcd\n", "xxxyxxx\n" ]
[ "YES\nabc\n", "NO\n", "YES\nxxxxxxy\n" ]
In the first sample any of the six possible strings will do: "abc", "acb", "bac", "bca", "cab" or "cba". In the second sample no letter permutation will satisfy the condition at *p* = 2 (*s*<sub class="lower-index">2</sub> = *s*<sub class="lower-index">4</sub>). In the third test any string where character "y" doesn'...
1,000
[ { "input": "abc", "output": "YES\nabc" }, { "input": "abcd", "output": "NO" }, { "input": "xxxyxxx", "output": "YES\nxxxxxxy" }, { "input": "xxxjddyxduquybxdxx", "output": "NO" }, { "input": "jjjjjjjjjjzjjjjjjjjjjjjjjjj", "output": "YES\njjjjjjjjjjjjjjjjjjjjjj...
1,644,063,270
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
26
310
10,137,600
n = input() l = len(n) list3 = [i for i in n] list1=[0 for i in range(l+1)] i = 2 a=2 list2=[] while(i<l+1): if list1[i]==0 and (i*2)<=l: list1[i]=1 for j in range(i**2,l+1,i): list1[j]=1 elif list1[i]==0: list1[i]=a a+=1 i+...
Title: Prime Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string *s*, consisting of small Latin letters. Let's denote the length of the string as |*s*|. The characters in the string are numbered starting from 1. Your task is to find out if it is possible to...
```python n = input() l = len(n) list3 = [i for i in n] list1=[0 for i in range(l+1)] i = 2 a=2 list2=[] while(i<l+1): if list1[i]==0 and (i*2)<=l: list1[i]=1 for j in range(i**2,l+1,i): list1[j]=1 elif list1[i]==0: list1[i]=a a+...
-1
427
A
Police Recruits
PROGRAMMING
800
[ "implementation" ]
null
null
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups. Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime. If there is no police offi...
The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers. If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than ...
Print a single integer, the number of crimes which will go untreated.
[ "3\n-1 -1 1\n", "8\n1 -1 1 -1 -1 1 1 1\n", "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n" ]
[ "2\n", "1\n", "8\n" ]
Lets consider the second example: 1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this c...
500
[ { "input": "3\n-1 -1 1", "output": "2" }, { "input": "8\n1 -1 1 -1 -1 1 1 1", "output": "1" }, { "input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1", "output": "8" }, { "input": "7\n-1 -1 1 1 -1 -1 1", "output": "2" }, { "input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 ...
1,688,373,794
2,147,483,647
Python 3
OK
TESTS
63
77
10,547,200
# 11:28 t = int(input()) cnt = 0 temp = 0 x = list(map(int, (input().split()))) for i in range(t): if x[i] > 0: temp += x[i] elif x[i] == -1 and temp > 0: temp -= 1 else: cnt += 1 print(cnt)
Title: Police Recruits Time Limit: None seconds Memory Limit: None megabytes Problem Description: The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups. Meanwhile, crimes keeps occurring within the city. One member of...
```python # 11:28 t = int(input()) cnt = 0 temp = 0 x = list(map(int, (input().split()))) for i in range(t): if x[i] > 0: temp += x[i] elif x[i] == -1 and temp > 0: temp -= 1 else: cnt += 1 print(cnt) ```
3
156
B
Suspects
PROGRAMMING
1,600
[ "constructive algorithms", "data structures", "implementation" ]
null
null
As Sherlock Holmes was investigating a crime, he identified *n* suspects. He knows for sure that exactly one of them committed the crime. To find out which one did it, the detective lines up the suspects and numbered them from 1 to *n*. After that, he asked each one: "Which one committed the crime?". Suspect number *i*...
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=*n*) — the total number of suspects and the number of suspects who told the truth. Next *n* lines contain the suspects' answers. The *i*-th line contains either "+*a**i*" (without the quotes), if the suspect number *i* says that the cri...
Print *n* lines. Line number *i* should contain "Truth" if suspect number *i* has told the truth for sure. Print "Lie" if the suspect number *i* lied for sure and print "Not defined" if he could lie and could tell the truth, too, depending on who committed the crime.
[ "1 1\n+1\n", "3 2\n-1\n-2\n-3\n", "4 1\n+2\n-3\n+4\n-1\n" ]
[ "Truth\n", "Not defined\nNot defined\nNot defined\n", "Lie\nNot defined\nLie\nNot defined\n" ]
The first sample has the single person and he confesses to the crime, and Sherlock Holmes knows that one person is telling the truth. That means that this person is telling the truth. In the second sample there are three suspects and each one denies his guilt. Sherlock Holmes knows that only two of them are telling th...
1,000
[ { "input": "1 1\n+1", "output": "Truth" }, { "input": "3 2\n-1\n-2\n-3", "output": "Not defined\nNot defined\nNot defined" }, { "input": "4 1\n+2\n-3\n+4\n-1", "output": "Lie\nNot defined\nLie\nNot defined" }, { "input": "1 0\n-1", "output": "Lie" }, { "input": "2...
1,619,643,110
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
186
0
n,m=list(map(int,input().split())) a=[[0,0] for i in range(n)] b=[] e=0 f=0 for i in range(n): c=input() d=int(c[1:]) if c[0]=='+': a[d-1][0]+=1 e+=1 else: a[d-1][1]+=1 f+=1 b.append([c[0],d]) g=[a[int(b[i][1])-1][0]+f-a[int(b[i][1])-1][1] for i in rang...
Title: Suspects Time Limit: None seconds Memory Limit: None megabytes Problem Description: As Sherlock Holmes was investigating a crime, he identified *n* suspects. He knows for sure that exactly one of them committed the crime. To find out which one did it, the detective lines up the suspects and numbered them from...
```python n,m=list(map(int,input().split())) a=[[0,0] for i in range(n)] b=[] e=0 f=0 for i in range(n): c=input() d=int(c[1:]) if c[0]=='+': a[d-1][0]+=1 e+=1 else: a[d-1][1]+=1 f+=1 b.append([c[0],d]) g=[a[int(b[i][1])-1][0]+f-a[int(b[i][1])-1][1] for...
0
459
B
Pashmak and Flowers
PROGRAMMING
1,300
[ "combinatorics", "implementation", "sortings" ]
null
null
Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty diff...
The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109).
The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.
[ "2\n1 2\n", "3\n1 4 5\n", "5\n3 1 2 3 1\n" ]
[ "1 1", "4 1", "2 4" ]
In the third sample the maximum beauty difference is 2 and there are 4 ways to do this: 1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers.
500
[ { "input": "2\n1 2", "output": "1 1" }, { "input": "3\n1 4 5", "output": "4 1" }, { "input": "5\n3 1 2 3 1", "output": "2 4" }, { "input": "2\n1 1", "output": "0 1" }, { "input": "3\n1 1 1", "output": "0 3" }, { "input": "4\n1 1 1 1", "output": "0 ...
1,657,553,561
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
108
17,510,400
n=int(input()) b=list(map(int,input().split())) a=max(b) c=min(b) if a!=c: a1=b.count(a) c1=b.count(c) else: a1=c1=1 print(a-c,a1*c1)
Title: Pashmak and Flowers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have th...
```python n=int(input()) b=list(map(int,input().split())) a=max(b) c=min(b) if a!=c: a1=b.count(a) c1=b.count(c) else: a1=c1=1 print(a-c,a1*c1) ```
0
843
D
Dynamic Shortest Path
PROGRAMMING
3,400
[ "graphs", "shortest paths" ]
null
null
You are given a weighted directed graph, consisting of *n* vertices and *m* edges. You should answer *q* queries of two types: - 1 v — find the length of shortest path from vertex 1 to vertex *v*. - 2 c *l*1 *l*2 ... *l**c* — add 1 to weights of edges with indices *l*1,<=*l*2,<=...,<=*l**c*.
The first line of input data contains integers *n*, *m*, *q* (1<=≤<=*n*,<=*m*<=≤<=105, 1<=≤<=*q*<=≤<=2000) — the number of vertices and edges in the graph, and the number of requests correspondingly. Next *m* lines of input data contain the descriptions of edges: *i*-th of them contains description of edge with index ...
For each query of first type print the length of the shortest path from 1 to *v* in a separate line. Print -1, if such path does not exists.
[ "3 2 9\n1 2 0\n2 3 0\n2 1 2\n1 3\n1 2\n2 1 1\n1 3\n1 2\n2 2 1 2\n1 3\n1 2\n", "5 4 9\n2 3 1\n2 4 1\n3 4 1\n1 2 0\n1 5\n1 4\n2 1 2\n2 1 2\n1 4\n2 2 1 3\n1 4\n2 1 4\n1 4\n" ]
[ "1\n0\n2\n1\n4\n2\n", "-1\n1\n2\n3\n4\n" ]
The description of changes of the graph in the first sample case: <img class="tex-graphics" src="https://espresso.codeforces.com/aeb5751e557f6f6158f15919da64eee550146483.png" style="max-width: 100.0%;max-height: 100.0%;"/> The description of changes of the graph in the second sample case: <img class="tex-graphics" s...
2,250
[]
1,689,646,106
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1689646104.6555831")# 1689646104.6556032
Title: Dynamic Shortest Path Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a weighted directed graph, consisting of *n* vertices and *m* edges. You should answer *q* queries of two types: - 1 v — find the length of shortest path from vertex 1 to vertex *v*. - 2 c *l*1 *l...
```python print("_RANDOM_GUESS_1689646104.6555831")# 1689646104.6556032 ```
0
279
A
Point on Spiral
PROGRAMMING
1,400
[ "brute force", "geometry", "implementation" ]
null
null
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0,<=0),<=(1,<=0)], [(1,<=0),<=(1,<=1)], [(1,<=1),<=(<=-<=1,<=1)], [(<=-<=1,<=1),<=(<=-<=1,<=<=-<=1)], [(<=-<=1,<=<=-<=1),<=(2,<=<=-<=1)], [(2,<...
The first line contains two space-separated integers *x* and *y* (|*x*|,<=|*y*|<=≤<=100).
Print a single integer, showing how many times Valera has to turn.
[ "0 0\n", "1 0\n", "0 1\n", "-1 -1\n" ]
[ "0\n", "0\n", "2\n", "3\n" ]
none
500
[ { "input": "0 0", "output": "0" }, { "input": "1 0", "output": "0" }, { "input": "0 1", "output": "2" }, { "input": "-1 -1", "output": "3" }, { "input": "10 10", "output": "37" }, { "input": "0 6", "output": "22" }, { "input": "-7 -13", ...
1,684,423,314
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
62
0
x,y=map(int, input().split()) if x>0 and y>0: if x>=y: print(4*(x-1)+1) else: print(4*(y-1)+2) elif x<0 and y>0: if abs(x)>y: print(4*(abs(x)-1)+3) else: print(4*(abs(y)-1)+2) elif x<0 and y<0: if abs(x)>=abs(y): print(4*(abs(x))-1) else: ...
Title: Point on Spiral Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0,<=0),<=(1,<=0)], [(1,<=0),<=(1,<=1)], [(...
```python x,y=map(int, input().split()) if x>0 and y>0: if x>=y: print(4*(x-1)+1) else: print(4*(y-1)+2) elif x<0 and y>0: if abs(x)>y: print(4*(abs(x)-1)+3) else: print(4*(abs(y)-1)+2) elif x<0 and y<0: if abs(x)>=abs(y): print(4*(abs(x))-1) ...
0
6
A
Triangle
PROGRAMMING
900
[ "brute force", "geometry" ]
A. Triangle
2
64
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo...
The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks.
Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the s...
[ "4 2 1 3\n", "7 2 2 4\n", "3 5 9 1\n" ]
[ "TRIANGLE\n", "SEGMENT\n", "IMPOSSIBLE\n" ]
none
0
[ { "input": "4 2 1 3", "output": "TRIANGLE" }, { "input": "7 2 2 4", "output": "SEGMENT" }, { "input": "3 5 9 1", "output": "IMPOSSIBLE" }, { "input": "3 1 5 1", "output": "IMPOSSIBLE" }, { "input": "10 10 10 10", "output": "TRIANGLE" }, { "input": "11 ...
1,500,174,875
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
92
5,529,600
def triangle(a0,a1,a2,a3): #there are only 4 cases to consider #a0,a1,a2 ; a1,a2,a3 ; a0,a1,a3 ; a0,a2,a3 def t(a0,a1,a2): if a0<a1+a2 and a1<a0+a2 and a2<a0+1: return 1 else: return 0 def s(a0,a1,a2): if a0==a1+a2 or a1==a0+a2 or a2==a0+a1: ...
Title: Triangle Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out o...
```python def triangle(a0,a1,a2,a3): #there are only 4 cases to consider #a0,a1,a2 ; a1,a2,a3 ; a0,a1,a3 ; a0,a2,a3 def t(a0,a1,a2): if a0<a1+a2 and a1<a0+a2 and a2<a0+1: return 1 else: return 0 def s(a0,a1,a2): if a0==a1+a2 or a1==a0+a2 or a2==a0...
0
330
A
Cakeminator
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows: The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains...
The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these: ...
Output the maximum number of cake cells that the cakeminator can eat.
[ "3 4\nS...\n....\n..S.\n" ]
[ "8\n" ]
For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats).
500
[ { "input": "3 4\nS...\n....\n..S.", "output": "8" }, { "input": "2 2\n..\n..", "output": "4" }, { "input": "2 2\nSS\nSS", "output": "0" }, { "input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..", "output": "14" }, { "input": "3 5\n..S..\nSSSSS\n..S..", "output": "...
1,655,829,493
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
0
n, m = map(int, input().split()) a = [list(input()) for _ in range(n)] count = 0 for i in range(n): if 'S' not in a[i]: count += m a = list(map(list, zip(*a))) # transpose matrix for i in range(n): if 'S' not in a[i]: count += m print(count)
Title: Cakeminator Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows: The cakeminator is going to eat the cake! Each ti...
```python n, m = map(int, input().split()) a = [list(input()) for _ in range(n)] count = 0 for i in range(n): if 'S' not in a[i]: count += m a = list(map(list, zip(*a))) # transpose matrix for i in range(n): if 'S' not in a[i]: count += m print(count) ```
0
0
none
none
none
0
[ "none" ]
null
null
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $n - 2$ intermediate planets. Formally: we number all the planets from $1$ to $n$. $1$ is Earth, $n$ is Mars. Natasha will make exactly $n$ flights: $1 \to 2 \to \ldots n \to 1$. Flight from $x$ to $y$ consists ...
The first line contains a single integer $n$ ($2 \le n \le 1000$) — number of planets. The second line contains the only integer $m$ ($1 \le m \le 1000$) — weight of the payload. The third line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 1000$), where $a_i$ is the number of tons, which can be lifted...
If Natasha can fly to Mars through $(n - 2)$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $-1$. It is guaranteed, that if Natasha can make a flight, then it takes no more than $10^9$ tons of fuel. The answer will be considered correct...
[ "2\n12\n11 8\n7 5\n", "3\n1\n1 4 1\n2 5 3\n", "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3\n" ]
[ "10.0000000000\n", "-1\n", "85.4800000000\n" ]
Let's consider the first example. Initially, the mass of a rocket with fuel is $22$ tons. - At take-off from Earth one ton of fuel can lift off $11$ tons of cargo, so to lift off $22$ tons you need to burn $2$ tons of fuel. Remaining weight of the rocket with fuel is $20$ tons.- During landing on Mars, one ton of fu...
0
[ { "input": "2\n12\n11 8\n7 5", "output": "10.0000000000" }, { "input": "3\n1\n1 4 1\n2 5 3", "output": "-1" }, { "input": "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3", "output": "85.4800000000" }, { "input": "3\n3\n1 2 1\n2 2 2", "output": "-1" }, { "input": "4\n4\n2 3 2 2\n2...
1,669,834,878
2,147,483,647
PyPy 3-64
OK
TESTS
76
62
0
n = int(input()) m = int(input()) takeoffs = [int(i) for i in input().split(" ")] landings = [int(i) for i in input().split(" ")] flag = 0 def calculate_min_fuel(m, takeoffs, landings): if landings[0] == 1: return -1 else: earth_landing = m / (landings[0]-1) m += eart...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $n - 2$ intermediate planets. Formally: we number all the planets from $1$ to $n$. $1$ is Earth, $n$ is Mars. Natasha will...
```python n = int(input()) m = int(input()) takeoffs = [int(i) for i in input().split(" ")] landings = [int(i) for i in input().split(" ")] flag = 0 def calculate_min_fuel(m, takeoffs, landings): if landings[0] == 1: return -1 else: earth_landing = m / (landings[0]-1) ...
3
231
A
Team
PROGRAMMING
800
[ "brute force", "greedy" ]
null
null
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution....
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe...
Print a single integer — the number of problems the friends will implement on the contest.
[ "3\n1 1 0\n1 1 1\n1 0 0\n", "2\n1 0 0\n0 1 1\n" ]
[ "2\n", "1\n" ]
In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta...
500
[ { "input": "3\n1 1 0\n1 1 1\n1 0 0", "output": "2" }, { "input": "2\n1 0 0\n0 1 1", "output": "1" }, { "input": "1\n1 0 0", "output": "0" }, { "input": "2\n1 0 0\n1 1 1", "output": "1" }, { "input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0", "output": "1" }, ...
1,698,310,448
2,147,483,647
PyPy 3-64
OK
TESTS
21
124
2,048,000
#Team import sys input1 = int(sys.stdin.readline()) total = 0 for i in range (input1): input2 = list(map(int, sys.stdin.readline().split())) input2 = sum(input2) if input2 > 1: total += 1 else: continue sys.stdout.write(str(total))
Title: Team Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid...
```python #Team import sys input1 = int(sys.stdin.readline()) total = 0 for i in range (input1): input2 = list(map(int, sys.stdin.readline().split())) input2 = sum(input2) if input2 > 1: total += 1 else: continue sys.stdout.write(str(total)) ```
3
433
A
Kitahara Haruki's Gift
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends. Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equa...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of apples. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (*w**i*<==<=100 or *w**i*<==<=200), where *w**i* is the weight of the *i*-th apple.
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).
[ "3\n100 200 100\n", "4\n100 100 100 200\n" ]
[ "YES\n", "NO\n" ]
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.
500
[ { "input": "3\n100 200 100", "output": "YES" }, { "input": "4\n100 100 100 200", "output": "NO" }, { "input": "1\n100", "output": "NO" }, { "input": "1\n200", "output": "NO" }, { "input": "2\n100 100", "output": "YES" }, { "input": "2\n200 200", "o...
1,642,250,046
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
77
0
n=int(input()) ar=list(map(int,input().split())) if (sum(ar)/2)%100==0: print("YES") else: print("NO")
Title: Kitahara Haruki's Gift Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends. Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't w...
```python n=int(input()) ar=list(map(int,input().split())) if (sum(ar)/2)%100==0: print("YES") else: print("NO") ```
0
828
A
Restaurant Tables
PROGRAMMING
1,200
[ "implementation" ]
null
null
In a small restaurant there are *a* tables for one person and *b* tables for two persons. It it known that *n* groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seate...
The first line contains three integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=2·105, 1<=≤<=*a*,<=*b*<=≤<=2·105) — the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=2) — the d...
Print the total number of people the restaurant denies service to.
[ "4 1 2\n1 2 1 1\n", "4 1 1\n1 1 2 1\n" ]
[ "0\n", "2\n" ]
In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remainin...
500
[ { "input": "4 1 2\n1 2 1 1", "output": "0" }, { "input": "4 1 1\n1 1 2 1", "output": "2" }, { "input": "1 1 1\n1", "output": "0" }, { "input": "2 1 2\n2 2", "output": "0" }, { "input": "5 1 3\n1 2 2 2 1", "output": "1" }, { "input": "7 6 1\n1 1 1 1 1 1...
1,499,792,532
1,032
Python 3
CHALLENGED
CHALLENGES
7
982
7,987,200
n,a,b=(int(i) for i in input().split()) v=[int(i) for i in input().split()] t1=[1 for i in range(a)] t2=[2 for i in range(b)] x=0 for i in range(n): if v[i]==1: if (len(t1)>0): t1.pop(0) elif (len(t2)>0) and (t2[0]>0): t2[0]-=1 else: x+=1 ...
Title: Restaurant Tables Time Limit: None seconds Memory Limit: None megabytes Problem Description: In a small restaurant there are *a* tables for one person and *b* tables for two persons. It it known that *n* groups of people come today, each consisting of one or two people. If a group consist of one person, i...
```python n,a,b=(int(i) for i in input().split()) v=[int(i) for i in input().split()] t1=[1 for i in range(a)] t2=[2 for i in range(b)] x=0 for i in range(n): if v[i]==1: if (len(t1)>0): t1.pop(0) elif (len(t2)>0) and (t2[0]>0): t2[0]-=1 else: ...
-1
509
A
Maximum in Table
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
An *n*<=×<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ...
The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table.
Print a single line containing a positive integer *m* — the maximum value in the table.
[ "1\n", "5\n" ]
[ "1", "70" ]
In the second test the rows of the table look as follows:
0
[ { "input": "1", "output": "1" }, { "input": "5", "output": "70" }, { "input": "2", "output": "2" }, { "input": "3", "output": "6" }, { "input": "4", "output": "20" }, { "input": "6", "output": "252" }, { "input": "7", "output": "924" ...
1,658,051,328
2,147,483,647
Python 3
OK
TESTS
10
46
0
n=int(input()) a=[list([1 for j in range(n)]) for i in range(n)] for i in range(1, n): for j in range(1, n): a[i][j]=a[i-1][j]+a[i][j-1] print(a[-1][-1])
Title: Maximum in Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: An *n*<=×<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t...
```python n=int(input()) a=[list([1 for j in range(n)]) for i in range(n)] for i in range(1, n): for j in range(1, n): a[i][j]=a[i-1][j]+a[i][j-1] print(a[-1][-1]) ```
3
189
A
Cut Ribbon
PROGRAMMING
1,300
[ "brute force", "dp" ]
null
null
Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions: - After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum. Help Polycarpus and find the number of ribbon piece...
The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide.
Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists.
[ "5 5 3 2\n", "7 5 5 2\n" ]
[ "2\n", "2\n" ]
In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3. In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2.
500
[ { "input": "5 5 3 2", "output": "2" }, { "input": "7 5 5 2", "output": "2" }, { "input": "4 4 4 4", "output": "1" }, { "input": "1 1 1 1", "output": "1" }, { "input": "4000 1 2 3", "output": "4000" }, { "input": "4000 3 4 5", "output": "1333" }, ...
1,689,874,733
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
n,a,b,c=list(map(int,input().split())) l=[a,b,c] l.sort() ans=0 cnt=0 while n-l[cnt]>=0 and cnt<=2: print(cnt) n-=l[cnt] cnt+=1 print(cnt)
Title: Cut Ribbon Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions: - After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the...
```python n,a,b,c=list(map(int,input().split())) l=[a,b,c] l.sort() ans=0 cnt=0 while n-l[cnt]>=0 and cnt<=2: print(cnt) n-=l[cnt] cnt+=1 print(cnt) ```
0
86
D
Powerful array
PROGRAMMING
2,200
[ "data structures", "implementation", "math", "two pointers" ]
D. Powerful array
5
256
An array of positive integers *a*1,<=*a*2,<=...,<=*a**n* is given. Let us consider its arbitrary subarray *a**l*,<=*a**l*<=+<=1...,<=*a**r*, where 1<=≤<=*l*<=≤<=*r*<=≤<=*n*. For every positive integer *s* denote by *K**s* the number of occurrences of *s* into the subarray. We call the power of the subarray the sum of p...
First line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=200000) — the array length and the number of queries correspondingly. Second line contains *n* positive integers *a**i* (1<=≤<=*a**i*<=≤<=106) — the elements of the array. Next *t* lines contain two positive integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*...
Output *t* lines, the *i*-th line of the output should contain single positive integer — the power of the *i*-th query subarray. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preferred to use cout stream (also you may use %I64d).
[ "3 2\n1 2 1\n1 2\n1 3\n", "8 3\n1 1 2 2 1 3 1 1\n2 7\n1 6\n2 7\n" ]
[ "3\n6\n", "20\n20\n20\n" ]
Consider the following array (see the second sample) and its [2, 7] subarray (elements of the subarray are colored):
2,500
[ { "input": "3 2\n1 2 1\n1 2\n1 3", "output": "3\n6" }, { "input": "8 3\n1 1 2 2 1 3 1 1\n2 7\n1 6\n2 7", "output": "20\n20\n20" }, { "input": "20 8\n1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2\n4 15\n1 2\n2 20\n7 7\n13 18\n7 7\n3 19\n3 8", "output": "108\n3\n281\n1\n27\n1\n209\n27" }, ...
1,691,335,922
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
92
0
print("_RANDOM_GUESS_1691335922.3888721")# 1691335922.3888881
Title: Powerful array Time Limit: 5 seconds Memory Limit: 256 megabytes Problem Description: An array of positive integers *a*1,<=*a*2,<=...,<=*a**n* is given. Let us consider its arbitrary subarray *a**l*,<=*a**l*<=+<=1...,<=*a**r*, where 1<=≤<=*l*<=≤<=*r*<=≤<=*n*. For every positive integer *s* denote by *K**s* th...
```python print("_RANDOM_GUESS_1691335922.3888721")# 1691335922.3888881 ```
0
844
A
Diversity
PROGRAMMING
1,000
[ "greedy", "implementation", "strings" ]
null
null
Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible. String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too.
First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*). Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26).
Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible.
[ "yandex\n6\n", "yahoo\n5\n", "google\n7\n" ]
[ "0\n", "1\n", "impossible\n" ]
In the first test case string contains 6 different letters, so we don't need to change anything. In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for...
500
[ { "input": "yandex\n6", "output": "0" }, { "input": "yahoo\n5", "output": "1" }, { "input": "google\n7", "output": "impossible" }, { "input": "a\n1", "output": "0" }, { "input": "z\n2", "output": "impossible" }, { "input": "fwgfrwgkuwghfiruhewgirueguhe...
1,503,594,150
1,650
Python 3
WRONG_ANSWER
PRETESTS
2
61
0
import sys def main(): chaine = list(sys.stdin.readline()) maxd = int(sys.stdin.readline()) lenc = len(chaine) lettre = list() move = 0 goodlettre = 0 for loop in range(len(chaine)): if chaine[loop] in lettre and chaine[loop].islower(): move += 1 elif chaine[loop].islower(): lettre.append(...
Title: Diversity Time Limit: None seconds Memory Limit: None megabytes Problem Description: Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible. String *s* consists only of lowercase Latin letters, and it...
```python import sys def main(): chaine = list(sys.stdin.readline()) maxd = int(sys.stdin.readline()) lenc = len(chaine) lettre = list() move = 0 goodlettre = 0 for loop in range(len(chaine)): if chaine[loop] in lettre and chaine[loop].islower(): move += 1 elif chaine[loop].islower(): lett...
0
777
B
Game of Credit Cards
PROGRAMMING
1,300
[ "data structures", "dp", "greedy", "sortings" ]
null
null
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards. Rules of this game are simple: each player bring his favourite *n*-digit credit card. Then both players name the digits written on the...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits in the cards Sherlock and Moriarty are going to use. The second line contains *n* digits — Sherlock's credit card number. The third line contains *n* digits — Moriarty's credit card number.
First print the minimum possible number of flicks Moriarty will get. Then print the maximum possible number of flicks that Sherlock can get from Moriarty.
[ "3\n123\n321\n", "2\n88\n00\n" ]
[ "0\n2\n", "2\n0\n" ]
First sample is elaborated in the problem statement. In the second sample, there is no way Moriarty can avoid getting two flicks.
1,000
[ { "input": "3\n123\n321", "output": "0\n2" }, { "input": "2\n88\n00", "output": "2\n0" }, { "input": "1\n4\n5", "output": "0\n1" }, { "input": "1\n8\n7", "output": "1\n0" }, { "input": "2\n55\n55", "output": "0\n0" }, { "input": "3\n534\n432", "out...
1,487,940,808
2,147,483,647
Python 3
OK
TESTS
55
62
4,608,000
def main(): n = int(input()) a = list(map(int, input())) b = list(map(int, input())) cnt = [0 for i in range(10)] for i in (b): cnt[i] += 1 min_gotten = 0 for i in a: for j in range(i, 10): if (cnt[j] > 0): cnt[j] -= 1 break else: for j in range(i): if (cnt[j] > 0): c...
Title: Game of Credit Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards. Rules of this game are simpl...
```python def main(): n = int(input()) a = list(map(int, input())) b = list(map(int, input())) cnt = [0 for i in range(10)] for i in (b): cnt[i] += 1 min_gotten = 0 for i in a: for j in range(i, 10): if (cnt[j] > 0): cnt[j] -= 1 break else: for j in range(i): if (cnt[j] > 0...
3
443
A
Anton and Letters
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line. Unfortunately, from time to ti...
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
Print a single number — the number of distinct letters in Anton's set.
[ "{a, b, c}\n", "{b, a, b, a}\n", "{}\n" ]
[ "3\n", "2\n", "0\n" ]
none
500
[ { "input": "{a, b, c}", "output": "3" }, { "input": "{b, a, b, a}", "output": "2" }, { "input": "{}", "output": "0" }, { "input": "{a, a, c, b, b, b, c, c, c, c}", "output": "3" }, { "input": "{a, c, b, b}", "output": "3" }, { "input": "{a, b}", "o...
1,698,681,184
2,147,483,647
Python 3
OK
TESTS
27
46
0
input_str = input().strip()[1:-1] if input_str: letters = input_str.split(", ") distinct_letters = set(letters) num_distinct_letters = len(distinct_letters) else: num_distinct_letters = 0 print(num_distinct_letters)
Title: Anton and Letters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi...
```python input_str = input().strip()[1:-1] if input_str: letters = input_str.split(", ") distinct_letters = set(letters) num_distinct_letters = len(distinct_letters) else: num_distinct_letters = 0 print(num_distinct_letters) ```
3
294
A
Shaass and Oskols
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i*...
The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100). The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The i...
On the *i*-th line of the output print the number of birds on the *i*-th wire.
[ "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n", "3\n2 4 1\n1\n2 2\n" ]
[ "0\n12\n5\n0\n16\n", "3\n0\n3\n" ]
none
500
[ { "input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6", "output": "0\n12\n5\n0\n16" }, { "input": "3\n2 4 1\n1\n2 2", "output": "3\n0\n3" }, { "input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43", "output": "0\n66\n57\n7\n0" }, { "input": "10\n48 53 10 28 91 56 8...
1,630,491,626
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
92
6,963,200
n = int(input()) list_of_birds = list(map(int, input().split())) m = int(input()) for i in range(m): nn, b = map(int, input().split()) list_of_birds[nn] += ((list_of_birds[nn-1]) - (b)) list_of_birds[nn-2] += (b-1) list_of_birds[nn-1] = 0 for i in range(n): print(list_of_birds[i]) ...
Title: Shaass and Oskols Time Limit: None seconds Memory Limit: None megabytes Problem Description: Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each...
```python n = int(input()) list_of_birds = list(map(int, input().split())) m = int(input()) for i in range(m): nn, b = map(int, input().split()) list_of_birds[nn] += ((list_of_birds[nn-1]) - (b)) list_of_birds[nn-2] += (b-1) list_of_birds[nn-1] = 0 for i in range(n): print(list_of_bir...
0