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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
8 | A | Train and Peter | PROGRAMMING | 1,200 | [
"strings"
] | A. Train and Peter | 1 | 64 | Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.
The boy start... | The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.
The second lin... | Output one of the four words without inverted commas:
- «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fanta... | [
"atob\na\nb\n",
"aaacaaa\naca\naa\n"
] | [
"forward\n",
"both\n"
] | It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B. | 0 | [
{
"input": "atob\na\nb",
"output": "forward"
},
{
"input": "aaacaaa\naca\naa",
"output": "both"
},
{
"input": "aaa\naa\naa",
"output": "fantasy"
},
{
"input": "astalavista\nastla\nlavista",
"output": "fantasy"
},
{
"input": "abacabadabacaba\nabacaba\nabacaba",
... | 1,650,788,174 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | s = input()
a = input()
b = input()
t = 0
f1 = False
f2 = False
b1 = False
b2 = False
p = 0
for i in range(len(s)):
if(s[i] == a[t]):
if(t == len(a)-1):
f1 = True
t = 0
else: t += 1
if(f1):
if(s[i] == b[t]):
if(t == len(b)-1):
... | Title: Train and Peter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the... | ```python
s = input()
a = input()
b = input()
t = 0
f1 = False
f2 = False
b1 = False
b2 = False
p = 0
for i in range(len(s)):
if(s[i] == a[t]):
if(t == len(a)-1):
f1 = True
t = 0
else: t += 1
if(f1):
if(s[i] == b[t]):
if(t == len(b)-... | 0 |
12 | D | Ball | PROGRAMMING | 2,400 | [
"data structures",
"sortings"
] | D. Ball | 2 | 256 | *N* ladies attend the ball in the King's palace. Every lady can be described with three values: beauty, intellect and richness. King's Master of Ceremonies knows that ladies are very special creatures. If some lady understands that there is other lady at the ball which is more beautiful, smarter and more rich, she can ... | The first line contains one integer *N* (1<=≤<=*N*<=≤<=500000). The second line contains *N* integer numbers *B**i*, separated by single spaces. The third and the fourth lines contain sequences *I**i* and *R**i* in the same format. It is guaranteed that 0<=≤<=*B**i*,<=*I**i*,<=*R**i*<=≤<=109. | Output the answer to the problem. | [
"3\n1 4 2\n4 3 2\n2 5 3\n"
] | [
"1\n"
] | none | 0 | [
{
"input": "3\n1 4 2\n4 3 2\n2 5 3",
"output": "1"
},
{
"input": "5\n2 8 10 0 7\n7 7 3 0 10\n2 8 3 2 2",
"output": "1"
},
{
"input": "5\n3 0 0 2 0\n7 10 7 4 0\n9 1 6 1 9",
"output": "1"
},
{
"input": "5\n5 4 0 2 5\n8 3 1 0 10\n4 5 0 0 5",
"output": "2"
},
{
"input... | 1,697,351,732 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 |
import sys
from operator import itemgetter
def count_self_murderers(n, ladies):
ladies.sort(key=itemgetter(1, 2))
ladies.reverse()
max_r = [0] * (n+1)
max_r[n] = ladies[n-1][2]
for i in range(n-1, -1, -1):
max_r[i] = max(max_r[i+1], ladies[i][2])
cnt = 0
j = 0
for ... | Title: Ball
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
*N* ladies attend the ball in the King's palace. Every lady can be described with three values: beauty, intellect and richness. King's Master of Ceremonies knows that ladies are very special creatures. If some lady understands that th... | ```python
import sys
from operator import itemgetter
def count_self_murderers(n, ladies):
ladies.sort(key=itemgetter(1, 2))
ladies.reverse()
max_r = [0] * (n+1)
max_r[n] = ladies[n-1][2]
for i in range(n-1, -1, -1):
max_r[i] = max(max_r[i+1], ladies[i][2])
cnt = 0
j = 0... | 0 |
798 | A | Mike and palindrome | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"strings"
] | null | null | Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codefo... | The first and single line contains string *s* (1<=≤<=|*s*|<=≤<=15). | Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise. | [
"abccaa\n",
"abbcca\n",
"abcda\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "abccaa",
"output": "YES"
},
{
"input": "abbcca",
"output": "NO"
},
{
"input": "abcda",
"output": "YES"
},
{
"input": "kyw",
"output": "YES"
},
{
"input": "fccf",
"output": "NO"
},
{
"input": "mnlm",
"output": "YES"
},
{
"input":... | 1,637,511,293 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 7 | 46 | 0 | s=input()
n=len(s)
c=0
for i in range(n//2):
if s[i] != s[n-1-i]:
c+=1
if c==1:
print("YES")
else:
print("NO") | Title: Mike and palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same ... | ```python
s=input()
n=len(s)
c=0
for i in range(n//2):
if s[i] != s[n-1-i]:
c+=1
if c==1:
print("YES")
else:
print("NO")
``` | 0 | |
433 | B | Kuriyama Mirai's Stones | PROGRAMMING | 1,200 | [
"dp",
"implementation",
"sortings"
] | null | null | Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:
1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones.
The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains t... | Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input. | [
"6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n",
"4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n"
] | [
"24\n9\n28\n",
"10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n"
] | Please note that the answers to the questions may overflow 32-bit integer type. | 1,500 | [
{
"input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6",
"output": "24\n9\n28"
},
{
"input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2",
"output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5"
},
{
"input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1... | 1,641,906,952 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 1,092 | 9,216,000 | def DP(li, n):
ans = []
c = 0
for i in range(n):
c += li[i]
ans.append(c)
ans.append(0)
return ans
n = int(input())
v = list(map(int, input().split()))
li1 = DP(v, n)
v.sort()
#print(li1)
li2 = DP(v, n)
#print(li2)
m = int(input())
for i in range(m):
t, l, r = ... | Title: Kuriyama Mirai's Stones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones s... | ```python
def DP(li, n):
ans = []
c = 0
for i in range(n):
c += li[i]
ans.append(c)
ans.append(0)
return ans
n = int(input())
v = list(map(int, input().split()))
li1 = DP(v, n)
v.sort()
#print(li1)
li2 = DP(v, n)
#print(li2)
m = int(input())
for i in range(m):
... | 3 | |
903 | D | Almost Difference | PROGRAMMING | 2,200 | [
"data structures",
"math"
] | null | null | Let's denote a function
You are given an array *a* consisting of *n* integers. You have to calculate the sum of *d*(*a**i*,<=*a**j*) over all pairs (*i*,<=*j*) such that 1<=≤<=*i*<=≤<=*j*<=≤<=*n*. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=200000) — the number of elements in *a*.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109) — elements of the array. | Print one integer — the sum of *d*(*a**i*,<=*a**j*) over all pairs (*i*,<=*j*) such that 1<=≤<=*i*<=≤<=*j*<=≤<=*n*. | [
"5\n1 2 3 1 3\n",
"4\n6 6 5 5\n",
"4\n6 6 4 4\n"
] | [
"4\n",
"0\n",
"-8\n"
] | In the first example:
1. *d*(*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>) = 0; 1. *d*(*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">3</sub>) = 2; 1. *d*(*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">4</sub>) = 0; 1. *d*(*a*<sub class="lower-index">... | 0 | [
{
"input": "5\n1 2 3 1 3",
"output": "4"
},
{
"input": "4\n6 6 5 5",
"output": "0"
},
{
"input": "4\n6 6 4 4",
"output": "-8"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n1000000000",
"output": "0"
},
{
"input": "2\n1 1000000000",
"output"... | 1,571,644,298 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 530 | 21,504,000 | n = int(input())
A = [int(i) for i in input().split()]
acc = 0
res = 0
for i in range(len(A)) :
acc -= A[i]
res += acc + A[i] * (i + 1)
mp = dict()
for i in range(len(A)) :
mp[A[i]] = mp.get(A[i], 0) + 1
res -= mp.get(A[i] - 1, 0) - mp.get(A[i] + 1, 0)
print(res) | Title: Almost Difference
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's denote a function
You are given an array *a* consisting of *n* integers. You have to calculate the sum of *d*(*a**i*,<=*a**j*) over all pairs (*i*,<=*j*) such that 1<=≤<=*i*<=≤<=*j*<=≤<=*n*.
Input Specifica... | ```python
n = int(input())
A = [int(i) for i in input().split()]
acc = 0
res = 0
for i in range(len(A)) :
acc -= A[i]
res += acc + A[i] * (i + 1)
mp = dict()
for i in range(len(A)) :
mp[A[i]] = mp.get(A[i], 0) + 1
res -= mp.get(A[i] - 1, 0) - mp.get(A[i] + 1, 0)
print(res)
``` | 3 | |
887 | C | Solution for Cube | PROGRAMMING | 1,500 | [
"brute force",
"implementation"
] | null | null | During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2.
It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation... | In first line given a sequence of 24 integers *a**i* (1<=≤<=*a**i*<=≤<=6), where *a**i* denotes color of *i*-th square. There are exactly 4 occurrences of all colors in this sequence. | Print «YES» (without quotes) if it's possible to solve cube using one rotation and «NO» (without quotes) otherwise. | [
"2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4\n",
"5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3\n"
] | [
"NO",
"YES"
] | In first test case cube looks like this:
In second test case cube looks like this:
It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16. | 1,500 | [
{
"input": "2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4",
"output": "NO"
},
{
"input": "5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3",
"output": "YES"
},
{
"input": "2 6 3 3 5 5 2 6 1 1 6 4 4 4 2 4 6 5 3 1 2 5 3 1",
"output": "NO"
},
{
"input": "3 4 2 3 5 5 6 6 4 5 4 6... | 1,509,828,183 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x = list(map(int, input().split()))
if a == c:
if m == n :
print('YES')
elif a == b:
if a == r :
print ('YES')
elif b == d :
if v==x :
print ('YES')
elif c == d :
if q == s:
print ('YES')
else :
print ('NO')
| Title: Solution for Cube
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2.
It's too hard to learn to solve Rubik's cube instantly,... | ```python
a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x = list(map(int, input().split()))
if a == c:
if m == n :
print('YES')
elif a == b:
if a == r :
print ('YES')
elif b == d :
if v==x :
print ('YES')
elif c == d :
if q == s:
print ('YES')
else :
print ('N... | 0 | |
702 | A | Maximum Increase | PROGRAMMING | 800 | [
"dp",
"greedy",
"implementation"
] | null | null | You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. | The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print the maximum length of an increasing subarray of the given array. | [
"5\n1 7 2 11 15\n",
"6\n100 100 100 100 100 100\n",
"3\n1 2 3\n"
] | [
"3\n",
"1\n",
"3\n"
] | none | 0 | [
{
"input": "5\n1 7 2 11 15",
"output": "3"
},
{
"input": "6\n100 100 100 100 100 100",
"output": "1"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 7... | 1,694,098,504 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | n = int(input())
x = input().split()
for i in range(0,len(x)):
x[i] = int(x[i])
list = []
for i in range(0,len(x)-1):
if x[i] < x[i+1]:
if x[i] not in list:
list.append(x[i])
list.append(x[i + 1])
else:
list.append(x[i + 1])
elif x[i] > x[i+1]:... | Title: Maximum Increase
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called... | ```python
n = int(input())
x = input().split()
for i in range(0,len(x)):
x[i] = int(x[i])
list = []
for i in range(0,len(x)-1):
if x[i] < x[i+1]:
if x[i] not in list:
list.append(x[i])
list.append(x[i + 1])
else:
list.append(x[i + 1])
elif x[i]... | 0 | |
712 | A | Memory and Crow | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow then adds *b**i* to *a**i*, subtracts *b**i*<=+<=1, adds the *b**i*<=+<=2 number, and so on until th... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of integers written in the row.
The next line contains *n*, the *i*'th of which is *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109) — the value of the *i*'th number. | Print *n* integers corresponding to the sequence *b*1,<=*b*2,<=...,<=*b**n*. It's guaranteed that the answer is unique and fits in 32-bit integer type. | [
"5\n6 -4 8 -2 3\n",
"5\n3 -2 -1 5 6\n"
] | [
"2 4 6 1 3 \n",
"1 -3 4 11 6 \n"
] | In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and - 4 = 4 - 6 + 1 - 3.
In the second sample test, the sequence 1, - 3, 4, ... | 500 | [
{
"input": "5\n6 -4 8 -2 3",
"output": "2 4 6 1 3 "
},
{
"input": "5\n3 -2 -1 5 6",
"output": "1 -3 4 11 6 "
},
{
"input": "10\n13 -2 532 -63 -23 -63 -64 -23 12 10",
"output": "11 530 469 -86 -86 -127 -87 -11 22 10 "
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "0 0... | 1,481,017,278 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n=int(input())
l=list(map(int,input().split()))
S=[]
for i in range(n-1) :
S.append(str(l[i]+l[i+1]))
S.append(str(l[n-1]))
print(S)
| Title: Memory and Crow
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow... | ```python
n=int(input())
l=list(map(int,input().split()))
S=[]
for i in range(n-1) :
S.append(str(l[i]+l[i+1]))
S.append(str(l[n-1]))
print(S)
``` | 0 | |
804 | A | Find Amir | PROGRAMMING | 1,000 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends.
There are *n* schools numerated from 1 to *n*. One can travel between each pair of them, to do so, he needs to buy a ticket. The ticker between schools *i* an... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of schools. | Print single integer: the minimum cost of tickets needed to visit all schools. | [
"2\n",
"10\n"
] | [
"0\n",
"4\n"
] | In the first example we can buy a ticket between the schools that costs <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c67d72010e0498bfd065a6a38fdeaec90358507b.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 500 | [
{
"input": "2",
"output": "0"
},
{
"input": "10",
"output": "4"
},
{
"input": "43670",
"output": "21834"
},
{
"input": "4217",
"output": "2108"
},
{
"input": "17879",
"output": "8939"
},
{
"input": "31809",
"output": "15904"
},
{
"input": "... | 1,691,700,944 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 46 | 0 | import math
def solve(a):
a = int(a)
print(math.ceil(a / 2) - 1)
user = input()
solve(user)
| Title: Find Amir
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends.
There are *n* schools numerated from 1 to *n*. One can travel b... | ```python
import math
def solve(a):
a = int(a)
print(math.ceil(a / 2) - 1)
user = input()
solve(user)
``` | 3 | |
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,650,722,747 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 83 | 154 | 0 | a,b,c,d = sorted(list(map(int,input().split())))
n = min(c-a-b,d-b-c)
print(["SEGMENT","TRIANGLE","IMPOSSIBLE"][(n < 0) - (n > 0)])
| 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
a,b,c,d = sorted(list(map(int,input().split())))
n = min(c-a-b,d-b-c)
print(["SEGMENT","TRIANGLE","IMPOSSIBLE"][(n < 0) - (n > 0)])
``` | 3.9615 |
228 | A | Is your horseshoe on the other hoof? | PROGRAMMING | 800 | [
"implementation"
] | null | null | Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th... | The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers. | Print a single integer — the minimum number of horseshoes Valera needs to buy. | [
"1 7 3 3\n",
"7 7 7 7\n"
] | [
"1\n",
"3\n"
] | none | 500 | [
{
"input": "1 7 3 3",
"output": "1"
},
{
"input": "7 7 7 7",
"output": "3"
},
{
"input": "81170865 673572653 756938629 995577259",
"output": "0"
},
{
"input": "3491663 217797045 522540872 715355328",
"output": "0"
},
{
"input": "251590420 586975278 916631563 58697... | 1,697,898,106 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | a = [int(i) for i in input().split()]
som = 0
for i in range(4):
if a[0]-a[i] == 0:
som += 1
print(som)
| Title: Is your horseshoe on the other hoof?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has ... | ```python
a = [int(i) for i in input().split()]
som = 0
for i in range(4):
if a[0]-a[i] == 0:
som += 1
print(som)
``` | 0 | |
760 | A | Petr and a calendar | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
Petr wants to ... | The only line contain two integers *m* and *d* (1<=≤<=*m*<=≤<=12, 1<=≤<=*d*<=≤<=7) — the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday). | Print single integer: the number of columns the table should have. | [
"1 7\n",
"1 1\n",
"11 6\n"
] | [
"6\n",
"5\n",
"5\n"
] | The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough. | 500 | [
{
"input": "1 7",
"output": "6"
},
{
"input": "1 1",
"output": "5"
},
{
"input": "11 6",
"output": "5"
},
{
"input": "2 7",
"output": "5"
},
{
"input": "2 1",
"output": "4"
},
{
"input": "8 6",
"output": "6"
},
{
"input": "1 1",
"output... | 1,553,497,407 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 124 | 0 | m,d=map(int,input().split())
kalendar=[[0 for i in range(7)] for j in range(6)]
D=1
if (m==1 or m==3) or (m==5 or m==7) or (m==8 or m==10) or m==12:
for i in range(6):
for j in range(7):
if d==1:
kalendar[i][j]=D
D+=1
else:
d-... | Title: Petr and a calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells... | ```python
m,d=map(int,input().split())
kalendar=[[0 for i in range(7)] for j in range(6)]
D=1
if (m==1 or m==3) or (m==5 or m==7) or (m==8 or m==10) or m==12:
for i in range(6):
for j in range(7):
if d==1:
kalendar[i][j]=D
D+=1
else:
... | 0 | |
463 | B | Caisa and Pylons | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math"
] | null | null | Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0 has zero height, the pylon with number *i* (*i*<=><=0) has height *h**i*. The goal of the game is ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *h*1, *h*2,<=..., *h**n* (1<=<=≤<=<=*h**i*<=<=≤<=<=105) representing the heights of the pylons. | Print a single number representing the minimum number of dollars paid by Caisa. | [
"5\n3 4 3 2 4\n",
"3\n4 4 4\n"
] | [
"4\n",
"4\n"
] | In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon. | 1,000 | [
{
"input": "5\n3 4 3 2 4",
"output": "4"
},
{
"input": "3\n4 4 4",
"output": "4"
},
{
"input": "99\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 20... | 1,664,031,094 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 49 | 77 | 13,516,800 | pylonNum = int(input())
heights = list(map(int, input().split()))
print(max(heights)) | Title: Caisa and Pylons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0... | ```python
pylonNum = int(input())
heights = list(map(int, input().split()))
print(max(heights))
``` | 3 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,677,859,543 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 124 | 0 |
g=list(input())
c=0
b=0
for i in range(len(g)):
if 97<=ord(g[i])<=122:
c=c+1
elif 65<=ord(g[i])<=90:
b=b+1
v=[]
if c>=b:
for i in range(len(g)):
a=str.lower(g[i])
v.append(a)
for item in v:
print(item,end="")
if c<b:
for i in range(len(g)):
a=str.upper(g[i]... | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
g=list(input())
c=0
b=0
for i in range(len(g)):
if 97<=ord(g[i])<=122:
c=c+1
elif 65<=ord(g[i])<=90:
b=b+1
v=[]
if c>=b:
for i in range(len(g)):
a=str.lower(g[i])
v.append(a)
for item in v:
print(item,end="")
if c<b:
for i in range(len(g)):
a=str.... | 3.969 |
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
Th... | The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number — the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0... | 1,676,355,745 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
count = 0
for i in range(2, n, 3):
if a[i] >= k and a[i-1] >= k and a[i-2] >= k:
count += 1
print(count) | Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
count = 0
for i in range(2, n, 3):
if a[i] >= k and a[i-1] >= k and a[i-2] >= k:
count += 1
print(count)
``` | 0 | |
975 | A | Aramic script | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | In Aramic language words can only represent objects.
Words in Aramic have special properties:
- A word is a root if it does not contain the same letter more than once. - A root and all its permutations represent the same object. - The root $x$ of a word $y$ is the word that contains all letters that appear in $y$... | The first line contains one integer $n$ ($1 \leq n \leq 10^3$) — the number of words in the script.
The second line contains $n$ words $s_1, s_2, \ldots, s_n$ — the script itself. The length of each string does not exceed $10^3$.
It is guaranteed that all characters of the strings are small latin letters. | Output one integer — the number of different objects mentioned in the given ancient Aramic script. | [
"5\na aa aaa ab abb\n",
"3\namer arem mrea\n"
] | [
"2",
"1"
] | In the first test, there are two objects mentioned. The roots that represent them are "a","ab".
In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer". | 500 | [
{
"input": "5\na aa aaa ab abb",
"output": "2"
},
{
"input": "3\namer arem mrea",
"output": "1"
},
{
"input": "10\nbda bbb cda dca dda dcb bcd dcb ada ddd",
"output": "6"
},
{
"input": "2\nfhjlqs aceginpr",
"output": "2"
},
{
"input": "2\nbcdfghimn efghijlmo",
... | 1,525,185,160 | 1,660 | Python 3 | OK | TESTS | 30 | 139 | 10,240,000 | n=int(input())
s=input()
a=s.split()
roots=[]
for i in range(len(a)):
root=''.join(sorted(set(a[i])))
roots.append(root)
ans=set(roots)
#print(ans)
print(len(ans)) | Title: Aramic script
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Aramic language words can only represent objects.
Words in Aramic have special properties:
- A word is a root if it does not contain the same letter more than once. - A root and all its permutations represent the ... | ```python
n=int(input())
s=input()
a=s.split()
roots=[]
for i in range(len(a)):
root=''.join(sorted(set(a[i])))
roots.append(root)
ans=set(roots)
#print(ans)
print(len(ans))
``` | 3 | |
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,687,039,620 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | def Police_Recruits(x):
hired = 0
crime =0
for i in range(len(x)-1):
if x[i]== -1:
crime+=1
# if x[i]==1 and x[i+1] == -1:
# crime-=1
# hired +=1
if x[i]>=1 and x[i+1:i+x[i]+1] ==[-1]*x[i]:
crime-=1
hire... | 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
def Police_Recruits(x):
hired = 0
crime =0
for i in range(len(x)-1):
if x[i]== -1:
crime+=1
# if x[i]==1 and x[i+1] == -1:
# crime-=1
# hired +=1
if x[i]>=1 and x[i+1:i+x[i]+1] ==[-1]*x[i]:
crime-=1
... | 0 | |
6 | C | Alice, Bob and Chocolate | PROGRAMMING | 1,200 | [
"greedy",
"two pointers"
] | C. Alice, Bob and Chocolate | 2 | 64 | Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them wi... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the amount of bars on the table. The second line contains a sequence *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000), where *t**i* is the time (in seconds) needed to consume the *i*-th bar (in the order from left to right). | Print two numbers *a* and *b*, where *a* is the amount of bars consumed by Alice, and *b* is the amount of bars consumed by Bob. | [
"5\n2 9 8 2 7\n"
] | [
"2 3\n"
] | none | 0 | [
{
"input": "5\n2 9 8 2 7",
"output": "2 3"
},
{
"input": "1\n1",
"output": "1 0"
},
{
"input": "2\n1 1",
"output": "1 1"
},
{
"input": "3\n1 1 1",
"output": "2 1"
},
{
"input": "4\n1 1 1 1",
"output": "2 2"
},
{
"input": "1\n6",
"output": "1 0"
}... | 1,547,953,024 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 0 | 2,000 | 0 | n=int(input())
l=list(map(int, input().split()))
a,b,i,j=0,0,0,n-1
while i<j:
if(sum(l[:i+1])>sum(l[j:])):
b+=1
j+=1
elif(sum(l[:i+1])>sum(l[j:])):
a+=1
i+=1
else:
a+=1
b+=1
i+=1
j+=1
print(a,b) | Title: Alice, Bob and Chocolate
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. Fo... | ```python
n=int(input())
l=list(map(int, input().split()))
a,b,i,j=0,0,0,n-1
while i<j:
if(sum(l[:i+1])>sum(l[j:])):
b+=1
j+=1
elif(sum(l[:i+1])>sum(l[j:])):
a+=1
i+=1
else:
a+=1
b+=1
i+=1
j+=1
print(a,b)
``` | 0 |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,680,623,958 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 46 | 0 | x=input()
y=input()
x=list(x)
y=list(y)
v=[]
for i in range(len(x)):
if x[i]==y[i]:
v.append('0')
else:
v.append('1')
n=''.join(v)
print(n) | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
x=input()
y=input()
x=list(x)
y=list(y)
v=[]
for i in range(len(x)):
if x[i]==y[i]:
v.append('0')
else:
v.append('1')
n=''.join(v)
print(n)
``` | 3.9885 |
285 | A | Slightly Decreasing Permutations | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*.
The ... | The single line contains two space-separated integers: *n*,<=*k* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*k*<=<<=*n*) — the permutation length and the decreasing coefficient. | In a single line print *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* — the permutation of length *n* with decreasing coefficient *k*.
If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. | [
"5 2\n",
"3 0\n",
"3 2\n"
] | [
"1 5 2 4 3\n",
"1 2 3\n",
"3 2 1\n"
] | none | 500 | [
{
"input": "5 2",
"output": "1 5 2 4 3"
},
{
"input": "3 0",
"output": "1 2 3"
},
{
"input": "3 2",
"output": "3 2 1"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "2 0",
"output": "1 2"
},
{
"input": "2 1",
"output": "2 1"
},
{
"input":... | 1,621,602,748 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | n,k = map(int,input().split())
ar = [i for i in range(1,n+1)]
if k != 0 :
k -= 1
tmp = ar[k]
ar[k] = ar[k+1]
ar[k+1] = tmp
for i in range(n) :
print(ar[i],end=" ")
else :
for i in range(n) :
print(ar[i],end=" ")
| Title: Slightly Decreasing Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutat... | ```python
n,k = map(int,input().split())
ar = [i for i in range(1,n+1)]
if k != 0 :
k -= 1
tmp = ar[k]
ar[k] = ar[k+1]
ar[k+1] = tmp
for i in range(n) :
print(ar[i],end=" ")
else :
for i in range(n) :
print(ar[i],end=" ")
``` | 0 | |
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,647,430,583 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | n=int(input())
l=list(map(int,input().split()))
e,o,ei,oi=0,0,0,0
for i in range(n):
if(l[i]%2==0):
e+=1
ei=i
else:
o+=1
oi=i
if(e==1):
print(ei)
else:
print(oi) | 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())
l=list(map(int,input().split()))
e,o,ei,oi=0,0,0,0
for i in range(n):
if(l[i]%2==0):
e+=1
ei=i
else:
o+=1
oi=i
if(e==1):
print(ei)
else:
print(oi)
``` | 0 |
430 | B | Balls Game | PROGRAMMING | 1,400 | [
"brute force",
"two pointers"
] | null | null | Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game?
There are *n* balls put in a row. Each ball is colored in one of *k* colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color *x*. He can insert his ball at... | The first line of input contains three integers: *n* (1<=≤<=*n*<=≤<=100), *k* (1<=≤<=*k*<=≤<=100) and *x* (1<=≤<=*x*<=≤<=*k*). The next line contains *n* space-separated integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=*k*). Number *c**i* means that the *i*-th ball in the row has color *c**i*.
It is guaranteed th... | Print a single integer — the maximum number of balls Iahub can destroy. | [
"6 2 2\n1 1 2 2 1 1\n",
"1 1 1\n1\n"
] | [
"6\n",
"0\n"
] | none | 1,000 | [
{
"input": "6 2 2\n1 1 2 2 1 1",
"output": "6"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "10 2 1\n2 1 2 2 1 2 2 1 1 2",
"output": "5"
},
{
"input": "50 2 1\n1 1 2 2 1 2 1 1 2 2 1 2 1 2 1 1 2 2 1 2 1 2 2 1 2 1 2 1 2 2 1 1 2 2 1 1 2 2 1 2 1 1 2 1 1 2 2 1 1 2",
"... | 1,613,435,470 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 109 | 0 | n, k, x = input().split(" ")
balls = [int(x) for x in input().split(" ")]
destroyed_balls = 0
i = 0
count = 0
begin_index = 0
n = int(n)
x = int(x)
while len(balls) >= 3 and i < len(balls):
if balls[i] == x:
count += 1
if count == 1:
begin_index = i
i += 1
e... | Title: Balls Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game?
There are *n* balls put in a row. Each ball is colored in one of *k* colors. Initially the row doesn't contain three or more conti... | ```python
n, k, x = input().split(" ")
balls = [int(x) for x in input().split(" ")]
destroyed_balls = 0
i = 0
count = 0
begin_index = 0
n = int(n)
x = int(x)
while len(balls) >= 3 and i < len(balls):
if balls[i] == x:
count += 1
if count == 1:
begin_index = i
i +... | 0 | |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
}... | 1,698,816,754 | 2,147,483,647 | Python 3 | OK | TESTS | 15 | 46 | 0 | cost_1st,in_money,no_banana=map(int,input().split())
required_money=cost_1st*(no_banana)*(no_banana+1)//2
if(required_money>in_money):
print(required_money-in_money)
else:
print(0) | Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He h... | ```python
cost_1st,in_money,no_banana=map(int,input().split())
required_money=cost_1st*(no_banana)*(no_banana+1)//2
if(required_money>in_money):
print(required_money-in_money)
else:
print(0)
``` | 3 | |
867 | A | Between the Offices | PROGRAMMING | 800 | [
"implementation"
] | null | null | As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't rem... | The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given... | Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower). | [
"4\nFSSF\n",
"2\nSF\n",
"10\nFFFFFFFFFF\n",
"10\nSSFFSFFSFF\n"
] | [
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you staye... | 500 | [
{
"input": "4\nFSSF",
"output": "NO"
},
{
"input": "2\nSF",
"output": "YES"
},
{
"input": "10\nFFFFFFFFFF",
"output": "NO"
},
{
"input": "10\nSSFFSFFSFF",
"output": "YES"
},
{
"input": "20\nSFSFFFFSSFFFFSSSSFSS",
"output": "NO"
},
{
"input": "20\nSSFFF... | 1,549,212,989 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 140 | 0 | n = int(input())
s = input();
cnt1 = 0
cnt2 = 0
s1 = ""
for i in range(1, n):
if s[i-1] == "S" and s[i] == "F":
cnt1 += 1
elif s[i-1] == "F" and s[i] == "S":
cnt2 += 1
if cnt1 > cnt2:
print("YES")
else:
print("NO")
| Title: Between the Offices
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Franci... | ```python
n = int(input())
s = input();
cnt1 = 0
cnt2 = 0
s1 = ""
for i in range(1, n):
if s[i-1] == "S" and s[i] == "F":
cnt1 += 1
elif s[i-1] == "F" and s[i] == "S":
cnt2 += 1
if cnt1 > cnt2:
print("YES")
else:
print("NO")
``` | 3 | |
4 | C | Registration System | PROGRAMMING | 1,300 | [
"data structures",
"hashing",
"implementation"
] | C. Registration system | 5 | 64 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle.
... | The first line contains number *n* (1<=≤<=*n*<=≤<=105). The following *n* lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | Print *n* lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | [
"4\nabacaba\nacaba\nabacaba\nacab\n",
"6\nfirst\nfirst\nsecond\nsecond\nthird\nthird\n"
] | [
"OK\nOK\nabacaba1\nOK\n",
"OK\nfirst1\nOK\nsecond1\nOK\nthird1\n"
] | none | 0 | [
{
"input": "4\nabacaba\nacaba\nabacaba\nacab",
"output": "OK\nOK\nabacaba1\nOK"
},
{
"input": "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird",
"output": "OK\nfirst1\nOK\nsecond1\nOK\nthird1"
},
{
"input": "1\nn",
"output": "OK"
},
{
"input": "2\nu\nu",
"output": "OK\nu1"
... | 1,694,707,847 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 15 | 5,000 | 1,126,400 | n=int(input())
total=0
names=[]
dictionary=dict()
for i in range(n):
string=input()
dictionary[string]=dictionary.get(string,-1)+1
if string not in names:
print('OK')
names+=[string]
else:
print(string+str(dictionary[string]))
| Title: Registration System
Time Limit: 5 seconds
Memory Limit: 64 megabytes
Problem Description:
A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to imple... | ```python
n=int(input())
total=0
names=[]
dictionary=dict()
for i in range(n):
string=input()
dictionary[string]=dictionary.get(string,-1)+1
if string not in names:
print('OK')
names+=[string]
else:
print(string+str(dictionary[string]))
``` | 0 |
265 | B | Roadside Trees (Simplified Edition) | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | Squirrel Liss loves nuts. There are *n* trees (numbered 1 to *n* from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree *i* is *h**i*. Liss wants to eat all nuts.
Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the fol... | The first line contains an integer *n* (1<=<=≤<=<=*n*<=≤<=105) — the number of trees.
Next *n* lines contains the height of trees: *i*-th line contains an integer *h**i* (1<=≤<=*h**i*<=≤<=104) — the height of the tree with the number *i*. | Print a single integer — the minimal time required to eat all nuts in seconds. | [
"2\n1\n2\n",
"5\n2\n1\n2\n1\n1\n"
] | [
"5\n",
"14\n"
] | none | 1,000 | [
{
"input": "2\n1\n2",
"output": "5"
},
{
"input": "5\n2\n1\n2\n1\n1",
"output": "14"
},
{
"input": "1\n1",
"output": "2"
}
] | 1,640,104,329 | 2,147,483,647 | Python 3 | OK | TESTS | 15 | 342 | 2,662,400 | n = int(input())
mylist = []
for i in range(n):
mylist.append(int(input()))
count = n+n-1+mylist[0]
for j in range(n-1):
count += abs(mylist[j+1]-mylist[j])
print(count) | Title: Roadside Trees (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Squirrel Liss loves nuts. There are *n* trees (numbered 1 to *n* from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree *i* is *h**i*. Liss wan... | ```python
n = int(input())
mylist = []
for i in range(n):
mylist.append(int(input()))
count = n+n-1+mylist[0]
for j in range(n-1):
count += abs(mylist[j+1]-mylist[j])
print(count)
``` | 3 | |
934 | A | A Compatible Pair | PROGRAMMING | 1,400 | [
"brute force",
"games"
] | null | null | Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming.
Little Tommy has *n* lanterns and Big B... | The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50).
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*.
The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*.
All the integers range from <=-<=109 to 109. | Print a single integer — the brightness of the chosen pair. | [
"2 2\n20 18\n2 14\n",
"5 3\n-1 0 1 2 3\n-1 0 1\n"
] | [
"252\n",
"2\n"
] | In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself.
In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself. | 500 | [
{
"input": "2 2\n20 18\n2 14",
"output": "252"
},
{
"input": "5 3\n-1 0 1 2 3\n-1 0 1",
"output": "2"
},
{
"input": "10 2\n1 6 2 10 2 3 2 10 6 4\n5 7",
"output": "70"
},
{
"input": "50 50\n1 6 2 10 2 3 2 10 6 4 5 0 3 1 7 3 2 4 4 2 1 5 0 6 10 1 8 0 10 9 0 4 10 5 5 7 4 9 9 5 5 ... | 1,518,760,876 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 62 | 5,632,000 | n,m = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
if max(b)<0:
t.remove(min(t))
else:
t.remove(max(t))
print(max(max(t)*max(b), max(t)*min(b), min(t)*max(b), min(t)*min(b))) | Title: A Compatible Pair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cr... | ```python
n,m = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
if max(b)<0:
t.remove(min(t))
else:
t.remove(max(t))
print(max(max(t)*max(b), max(t)*min(b), min(t)*max(b), min(t)*min(b)))
``` | 0 | |
802 | G | Fake News (easy) | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it... | The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z). | Output YES if the string *s* contains heidi as a subsequence and NO otherwise. | [
"abcheaibcdi\n",
"hiedi\n"
] | [
"YES",
"NO"
] | A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*. | 0 | [
{
"input": "abcheaibcdi",
"output": "YES"
},
{
"input": "hiedi",
"output": "NO"
},
{
"input": "ihied",
"output": "NO"
},
{
"input": "diehi",
"output": "NO"
},
{
"input": "deiih",
"output": "NO"
},
{
"input": "iheid",
"output": "NO"
},
{
"in... | 1,645,496,094 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | def fake_news():
a=input()
if 'hiedi' in a:print('NO')
else:print('YES')
fake_news() | Title: Fake News (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a ... | ```python
def fake_news():
a=input()
if 'hiedi' in a:print('NO')
else:print('YES')
fake_news()
``` | 0 | |
88 | A | Chord | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | A. Chord | 2 | 256 | Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note aft... | The only line contains 3 space-separated notes in the above-given notation. | Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously. | [
"C E G\n",
"C# B F\n",
"A B H\n"
] | [
"major\n",
"minor\n",
"strange\n"
] | none | 500 | [
{
"input": "C E G",
"output": "major"
},
{
"input": "C# B F",
"output": "minor"
},
{
"input": "A B H",
"output": "strange"
},
{
"input": "G H E",
"output": "minor"
},
{
"input": "D# B G",
"output": "major"
},
{
"input": "D# B F#",
"output": "minor"... | 1,684,965,708 | 2,147,483,647 | Python 3 | OK | TESTS | 75 | 92 | 0 | notes = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H"]
def get_index(s):
for i in range (12):
if notes[i] == s:
return i
return 0
def check(index1, index2, index3):
first_tones = 0
second_tones = 0
if index2 < index1:
first_tones = in... | Title: Chord
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and b... | ```python
notes = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H"]
def get_index(s):
for i in range (12):
if notes[i] == s:
return i
return 0
def check(index1, index2, index3):
first_tones = 0
second_tones = 0
if index2 < index1:
first_... | 3.977 |
276 | D | Little Girl and Maximum XOR | PROGRAMMING | 1,700 | [
"bitmasks",
"dp",
"greedy",
"implementation",
"math"
] | null | null | A little girl loves problems on bitwise operations very much. Here's one of them.
You are given two integers *l* and *r*. Let's consider the values of for all pairs of integers *a* and *b* (*l*<=≤<=*a*<=≤<=*b*<=≤<=*r*). Your task is to find the maximum value among all considered ones.
Expression means applying bitw... | The single line contains space-separated integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | In a single line print a single integer — the maximum value of for all pairs of integers *a*, *b* (*l*<=≤<=*a*<=≤<=*b*<=≤<=*r*). | [
"1 2\n",
"8 16\n",
"1 1\n"
] | [
"3\n",
"31\n",
"0\n"
] | none | 2,000 | [
{
"input": "1 2",
"output": "3"
},
{
"input": "8 16",
"output": "31"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "506 677",
"output": "1023"
},
{
"input": "33 910",
"output": "1023"
},
{
"input": "36 94",
"output": "127"
},
{
"input": ... | 1,680,349,858 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | import sys
import math
import bisect
import heapq
import itertools
from itertools import accumulate
from sys import stdin,stdout
from math import gcd,floor,sqrt,log, ceil
from collections import defaultdict, Counter, deque
from bisect import bisect_left,bisect_right, insort_left, insort_right
mod=100000... | Title: Little Girl and Maximum XOR
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A little girl loves problems on bitwise operations very much. Here's one of them.
You are given two integers *l* and *r*. Let's consider the values of for all pairs of integers *a* and *b* (*l*<=≤<=*a*<=≤<... | ```python
import sys
import math
import bisect
import heapq
import itertools
from itertools import accumulate
from sys import stdin,stdout
from math import gcd,floor,sqrt,log, ceil
from collections import defaultdict, Counter, deque
from bisect import bisect_left,bisect_right, insort_left, insort_right
... | -1 | |
791 | A | Bear and Big Brother | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's we... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. | Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. | [
"4 7\n",
"4 9\n",
"1 1\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Li... | 500 | [
{
"input": "4 7",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output... | 1,697,686,195 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 62 | 62 | 0 | inp = input().split()
a = int(inp[0])
b = int(inp[1])
c = 0
for i in range(0, 10**3):
if a > b:
print(c)
break
c = c+1
a = a*3
b = b*2
| Title: Bear and Big Brother
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or e... | ```python
inp = input().split()
a = int(inp[0])
b = int(inp[1])
c = 0
for i in range(0, 10**3):
if a > b:
print(c)
break
c = c+1
a = a*3
b = b*2
``` | 3 | |
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The ... | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, o... | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4... | 1,696,508,913 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 18,022,400 | t = int(input())
a = list(map(int,input().split()))
m = int(input())
n = list(map(int,input().split()))
vasum = 0
pesum = 0
for i in n :
vasum += a.index(i)+1
pesum += a[::-1].index(i)+1
print(vasum,pesum) | Title: Effective Approach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn c... | ```python
t = int(input())
a = list(map(int,input().split()))
m = int(input())
n = list(map(int,input().split()))
vasum = 0
pesum = 0
for i in n :
vasum += a.index(i)+1
pesum += a[::-1].index(i)+1
print(vasum,pesum)
``` | 0 | |
300 | A | Array | PROGRAMMING | 1,100 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero (<=<<=0). 1. The product of all numbers in the second set is greater than zero (<=><=0). 1. The produ... | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements. | In the first line print integer *n*1 (*n*1<=><=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set.
In the next line print integer *n*2 (*n*2<=><=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second... | [
"3\n-1 2 0\n",
"4\n-1 -2 -3 0\n"
] | [
"1 -1\n1 2\n1 0\n",
"1 -1\n2 -3 -2\n1 0\n"
] | none | 500 | [
{
"input": "3\n-1 2 0",
"output": "1 -1\n1 2\n1 0"
},
{
"input": "4\n-1 -2 -3 0",
"output": "1 -1\n2 -3 -2\n1 0"
},
{
"input": "5\n-1 -2 1 2 0",
"output": "1 -1\n2 1 2\n2 0 -2"
},
{
"input": "100\n-64 -51 -75 -98 74 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -1... | 1,644,342,754 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 92 | 0 | num = input()
digits = [int(i) for i in input().split()]
pos_nums = []
neg_nums = []
zero = []
for i in range(len(digits)):
if digits[i] == 0:
zero.append(digits[i])
continue
elif digits[i] > 0:
pos_nums.append(digits[i])
continue
else:
neg_nums.append(digits[i])
if... | Title: Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero (<=<<=0). 1. T... | ```python
num = input()
digits = [int(i) for i in input().split()]
pos_nums = []
neg_nums = []
zero = []
for i in range(len(digits)):
if digits[i] == 0:
zero.append(digits[i])
continue
elif digits[i] > 0:
pos_nums.append(digits[i])
continue
else:
neg_nums.append(digi... | 3 | |
152 | C | Pocket Book | PROGRAMMING | 1,400 | [
"combinatorics"
] | null | null | One day little Vasya found mom's pocket book. The book had *n* names of her friends and unusually enough, each name was exactly *m* letters long. Let's number the names from 1 to *n* in the order in which they are written.
As mom wasn't home, Vasya decided to play with names: he chose three integers *i*, *j*, *k* (1<=... | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of names and the length of each name, correspondingly. Then *n* lines contain names, each name consists of exactly *m* uppercase Latin letters. | Print the single number — the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109<=+<=7). | [
"2 3\nAAB\nBAA\n",
"4 5\nABABA\nBCGDG\nAAAAA\nYABSA\n"
] | [
"4\n",
"216\n"
] | In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB". | 1,500 | [
{
"input": "2 3\nAAB\nBAA",
"output": "4"
},
{
"input": "4 5\nABABA\nBCGDG\nAAAAA\nYABSA",
"output": "216"
},
{
"input": "1 1\nE",
"output": "1"
},
{
"input": "2 2\nNS\nPD",
"output": "4"
},
{
"input": "3 4\nPJKD\nNFJX\nFGFK",
"output": "81"
},
{
"inpu... | 1,696,314,877 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 60 | 154 | 1,843,200 | from sys import stdin
n, m = map(int, stdin.readline().split())
mod = 10**9 + 7
s = [set() for _ in range(m)]
for i in range(n):
name = stdin.readline()
for j in range(m):
s[j].add(name[j])
begin = 1
for i in range(m):
begin *= len(s[i])
begin %= mod
print(begin)
| Title: Pocket Book
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day little Vasya found mom's pocket book. The book had *n* names of her friends and unusually enough, each name was exactly *m* letters long. Let's number the names from 1 to *n* in the order in which they are written.
... | ```python
from sys import stdin
n, m = map(int, stdin.readline().split())
mod = 10**9 + 7
s = [set() for _ in range(m)]
for i in range(n):
name = stdin.readline()
for j in range(m):
s[j].add(name[j])
begin = 1
for i in range(m):
begin *= len(s[i])
begin %= mod
print(begin)
... | 3 | |
932 | A | Palindromic Supersequence | PROGRAMMING | 800 | [
"constructive algorithms"
] | null | null | You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*.
A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining characters. For example, "cotst" is a subsequ... | First line contains a string *A* (1<=≤<=|*A*|<=≤<=103) consisting of lowercase Latin letters, where |*A*| is a length of *A*. | Output single line containing *B* consisting of only lowercase Latin letters. You do not need to find the shortest answer, the only restriction is that the length of string *B* should not exceed 104. If there are many possible *B*, print any of them. | [
"aba\n",
"ab\n"
] | [
"aba",
"aabaa"
] | In the first example, "aba" is a subsequence of "aba" which is a palindrome.
In the second example, "ab" is a subsequence of "aabaa" which is a palindrome. | 500 | [
{
"input": "aba",
"output": "abaaba"
},
{
"input": "ab",
"output": "abba"
},
{
"input": "krnyoixirslfszfqivgkaflgkctvbvksipwomqxlyqxhlbceuhbjbfnhofcgpgwdseffycthmlpcqejgskwjkbkbbmifnurnwyhevsoqzmtvzgfiqajfrgyuzxnrtxectcnlyoisbglpdbjbslxlpoymrcxmdtqhcnlvtqdwftuzgbdxsyscwbrguostbelnvtaqdmk... | 1,640,773,137 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 46 | 0 | s = input()
if(s==s[::-1]):
print(s)
else:
print(s,end='')
print(s[::-1]) | Title: Palindromic Supersequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*.
A subsequence of a string is a string that can be derived from it by deleting some (not necessarily co... | ```python
s = input()
if(s==s[::-1]):
print(s)
else:
print(s,end='')
print(s[::-1])
``` | 3 | |
262 | A | Roma and Lucky Numbers | PROGRAMMING | 800 | [
"implementation"
] | null | null | Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Roma's got *n* positive integer... | The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has.
The numbers in the lines are separated by single spaces. | In a single line print a single integer — the answer to the problem. | [
"3 4\n1 2 4\n",
"3 2\n447 44 77\n"
] | [
"3\n",
"2\n"
] | In the first sample all numbers contain at most four lucky digits, so the answer is 3.
In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2. | 500 | [
{
"input": "3 4\n1 2 4",
"output": "3"
},
{
"input": "3 2\n447 44 77",
"output": "2"
},
{
"input": "2 2\n507978501 180480073",
"output": "2"
},
{
"input": "9 6\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089",
"output": "9"
},
{
... | 1,592,159,541 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 218 | 0 | def cnt(n,k):
cnt = 0
while n:
if n%10 in (4,7):
cnt+=1
n = n//10
return cnt <= k
n,k = map(int,input().split())
a = list(map(int,input().split()))
a = list(filter(lambda x:cnt(x,k),a))
print(len(a)) | Title: Roma and Lucky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits... | ```python
def cnt(n,k):
cnt = 0
while n:
if n%10 in (4,7):
cnt+=1
n = n//10
return cnt <= k
n,k = map(int,input().split())
a = list(map(int,input().split()))
a = list(filter(lambda x:cnt(x,k),a))
print(len(a))
``` | 3 | |
102 | B | Sum of Digits | PROGRAMMING | 1,000 | [
"implementation"
] | B. Sum of Digits | 2 | 265 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-... | The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | [
"0\n",
"10\n",
"991\n"
] | [
"0\n",
"1\n",
"3\n"
] | In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transform... | 1,000 | [
{
"input": "0",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "991",
"output": "3"
},
{
"input": "99",
"output": "2"
},
{
"input": "100",
"output": "1"
},
{
"input": "123456789",
"output": "2"
},
{
"input": "32",
"output... | 1,594,228,057 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 27,852,800 | def find_sum(n):
ans = 0
while n > 0:
ans += n%10
n = n//10
return ans
def main():
n = int(input())
if n < 10:
print(0)
else:
count = 0
while n >= 10:
n = find_sum(n)
count += 1
print(count)
if __name__ == '__main__':
... | Title: Sum of Digits
Time Limit: 2 seconds
Memory Limit: 265 megabytes
Problem Description:
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came... | ```python
def find_sum(n):
ans = 0
while n > 0:
ans += n%10
n = n//10
return ans
def main():
n = int(input())
if n < 10:
print(0)
else:
count = 0
while n >= 10:
n = find_sum(n)
count += 1
print(count)
if __name__ == '__m... | 0 |
268 | A | Games | PROGRAMMING | 800 | [
"brute force"
] | null | null | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively. | In a single line print the number of games where the host team is going to play in the guest uniform. | [
"3\n1 2\n2 4\n3 4\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"2\n1 2\n1 2\n"
] | [
"1\n",
"5\n",
"0\n"
] | In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host tea... | 500 | [
{
"input": "3\n1 2\n2 4\n3 4",
"output": "1"
},
{
"input": "4\n100 42\n42 100\n5 42\n100 5",
"output": "5"
},
{
"input": "2\n1 2\n1 2",
"output": "0"
},
{
"input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52",
"output": "6"
},
{
"input": "10\n68 42\n1 35\n25 70\n... | 1,685,844,335 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 31 | 124 | 0 | #!/usr/bin/env python3
n = int(input())
ar1, ar2, c = [], [], 0
for i in range(n):
a, b = map(int, input().split())
ar1.append(a)
ar2.append(b)
for i in range(len(ar2)):
c += ar1.count(ar2[i])
print(c)
| Title: Games
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. W... | ```python
#!/usr/bin/env python3
n = int(input())
ar1, ar2, c = [], [], 0
for i in range(n):
a, b = map(int, input().split())
ar1.append(a)
ar2.append(b)
for i in range(len(ar2)):
c += ar1.count(ar2[i])
print(c)
``` | 3 | |
192 | A | Funky Numbers | PROGRAMMING | 1,300 | [
"binary search",
"brute force",
"implementation"
] | null | null | As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.
A well-known hipster Andrew adores everything funky and c... | The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109). | Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes). | [
"256\n",
"512\n"
] | [
"YES\n",
"NO\n"
] | In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample number 512 can not be represented as a sum of two triangular numbers. | 500 | [
{
"input": "256",
"output": "YES"
},
{
"input": "512",
"output": "NO"
},
{
"input": "80",
"output": "NO"
},
{
"input": "828",
"output": "YES"
},
{
"input": "6035",
"output": "NO"
},
{
"input": "39210",
"output": "YES"
},
{
"input": "79712",... | 1,690,606,662 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 71 | 154 | 3,788,800 | # 192a
import sys
from bisect import bisect_left
input = sys.stdin.readline
n = int(input())
nums, i = [], 1
while i*(i+1)//2 < n:
nums.append(i*(i+1)//2)
i += 1
for j in nums:
if n - j > nums[-1]:
continue
tmp = bisect_left(nums, n - j)
if j + nums[tmp] == n:
print("YES")
... | Title: Funky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are represent... | ```python
# 192a
import sys
from bisect import bisect_left
input = sys.stdin.readline
n = int(input())
nums, i = [], 1
while i*(i+1)//2 < n:
nums.append(i*(i+1)//2)
i += 1
for j in nums:
if n - j > nums[-1]:
continue
tmp = bisect_left(nums, n - j)
if j + nums[tmp] == n:
print("YES"... | 3 | |
889 | E | Mod Mod Mod | PROGRAMMING | 3,000 | [
"binary search",
"dp",
"math"
] | null | null | You are given a sequence of integers *a*1,<=*a*2,<=...,<=*a**n*. Let , and for 1<=≤<=*i*<=<<=*n*. Here, denotes the modulus operation. Find the maximum value of *f*(*x*,<=1) over all nonnegative integers *x*. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=200000) — the length of the sequence.
The second lines contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1013) — the elements of the sequence. | Output a single integer — the maximum value of *f*(*x*,<=1) over all nonnegative integers *x*. | [
"2\n10 5\n",
"5\n5 4 3 2 1\n",
"4\n5 10 5 10\n"
] | [
"13\n",
"6\n",
"16\n"
] | In the first example you can choose, for example, *x* = 19.
In the second example you can choose, for example, *x* = 3 or *x* = 2. | 2,250 | [] | 1,611,245,545 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 307,200 | g=int(input())
m=[int(e) for e in input().split()]
n=[int(y)*0 for y in range(0,g)]
a=0
for i in range(0,g):
for x in range(0,max(m)):
n[0]=x%m[0]
for _i in range(1,g):
n[_i]=n[_i-1]%m[_i]
if sum(n) > a:
a=sum(n)
print(a,'\n')
| Title: Mod Mod Mod
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence of integers *a*1,<=*a*2,<=...,<=*a**n*. Let , and for 1<=≤<=*i*<=<<=*n*. Here, denotes the modulus operation. Find the maximum value of *f*(*x*,<=1) over all nonnegative integers *x*.
Input Sp... | ```python
g=int(input())
m=[int(e) for e in input().split()]
n=[int(y)*0 for y in range(0,g)]
a=0
for i in range(0,g):
for x in range(0,max(m)):
n[0]=x%m[0]
for _i in range(1,g):
n[_i]=n[_i-1]%m[_i]
if sum(n) > a:
a=sum(n)
print(a,'\n')
``` | 0 | |
192 | A | Funky Numbers | PROGRAMMING | 1,300 | [
"binary search",
"brute force",
"implementation"
] | null | null | As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.
A well-known hipster Andrew adores everything funky and c... | The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109). | Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes). | [
"256\n",
"512\n"
] | [
"YES\n",
"NO\n"
] | In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample number 512 can not be represented as a sum of two triangular numbers. | 500 | [
{
"input": "256",
"output": "YES"
},
{
"input": "512",
"output": "NO"
},
{
"input": "80",
"output": "NO"
},
{
"input": "828",
"output": "YES"
},
{
"input": "6035",
"output": "NO"
},
{
"input": "39210",
"output": "YES"
},
{
"input": "79712",... | 1,648,105,101 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | n=int(input())
check=[]
i=1
while i*(i+1)//2 < n:
check.append(i*(i+1)//2)
i+=1
flag=False
for i in range(len(check)//2+1):
if (n-check[i]) in check:
flag=True
break
print("YES" if flag else "NO")
| Title: Funky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are represent... | ```python
n=int(input())
check=[]
i=1
while i*(i+1)//2 < n:
check.append(i*(i+1)//2)
i+=1
flag=False
for i in range(len(check)//2+1):
if (n-check[i]) in check:
flag=True
break
print("YES" if flag else "NO")
``` | 0 | |
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,608,875,557 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 216 | 0 | n = int(input())
number = list(map(int, input().split()))
count_chet = 0
count_nechet = 0
for i in number:
if i % 2 == 0:
count_chet += 1
if count_nechet > 0:
print(number.index(i))
break
if i % 2 != 0:
count_nechet += 1
if count_chet > 0:
... | 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())
number = list(map(int, input().split()))
count_chet = 0
count_nechet = 0
for i in number:
if i % 2 == 0:
count_chet += 1
if count_nechet > 0:
print(number.index(i))
break
if i % 2 != 0:
count_nechet += 1
if count_ch... | 0 |
508 | B | Anton and currency you all know | PROGRAMMING | 1,300 | [
"greedy",
"math",
"strings"
] | null | null | Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.
Reliable sources have informed the financier Anton of some information about the exchange rate of... | The first line contains an odd positive integer *n* — the exchange rate of currency you all know for today. The length of number *n*'s representation is within range from 2 to 105, inclusive. The representation of *n* doesn't contain any leading zeroes. | If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print <=-<=1.
Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained fro... | [
"527\n",
"4573\n",
"1357997531\n"
] | [
"572\n",
"3574\n",
"-1\n"
] | none | 1,000 | [
{
"input": "527",
"output": "572"
},
{
"input": "4573",
"output": "3574"
},
{
"input": "1357997531",
"output": "-1"
},
{
"input": "444443",
"output": "444434"
},
{
"input": "22227",
"output": "72222"
},
{
"input": "24683",
"output": "34682"
},
... | 1,685,033,362 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | n= int(input());n= str(n);n= list(n);x=[i for i in n if int(i)%2==0]
if len(x)==0:print(-1)
elif int(n[-1])%2==0:print(''.join(n))
else:
v2=n[:n.index(str(max(x)))]
v3=n.pop(-1)
v5=n[n.index(str(max(x)))+1:]
v1=n.pop(n.index(str(max(x))))
v4=v2;v4.append(v3);v4+=v5;v4.append(v1)
print('... | Title: Anton and currency you all know
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed... | ```python
n= int(input());n= str(n);n= list(n);x=[i for i in n if int(i)%2==0]
if len(x)==0:print(-1)
elif int(n[-1])%2==0:print(''.join(n))
else:
v2=n[:n.index(str(max(x)))]
v3=n.pop(-1)
v5=n[n.index(str(max(x)))+1:]
v1=n.pop(n.index(str(max(x))))
v4=v2;v4.append(v3);v4+=v5;v4.append(v1)
... | 0 | |
627 | A | XOR Equation | PROGRAMMING | 1,700 | [
"dp",
"math"
] | null | null | Two positive integers *a* and *b* have a sum of *s* and a bitwise XOR of *x*. How many possible values are there for the ordered pair (*a*,<=*b*)? | The first line of the input contains two integers *s* and *x* (2<=≤<=*s*<=≤<=1012, 0<=≤<=*x*<=≤<=1012), the sum and bitwise xor of the pair of positive integers, respectively. | Print a single integer, the number of solutions to the given conditions. If no solutions exist, print 0. | [
"9 5\n",
"3 3\n",
"5 2\n"
] | [
"4\n",
"2\n",
"0\n"
] | In the first sample, we have the following solutions: (2, 7), (3, 6), (6, 3), (7, 2).
In the second sample, the only solutions are (1, 2) and (2, 1). | 500 | [
{
"input": "9 5",
"output": "4"
},
{
"input": "3 3",
"output": "2"
},
{
"input": "5 2",
"output": "0"
},
{
"input": "6 0",
"output": "1"
},
{
"input": "549755813887 549755813887",
"output": "549755813886"
},
{
"input": "2 0",
"output": "1"
},
{... | 1,457,178,256 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 204,800 | def main():
s, x = ([c == '1' for c in bin(int(_))[2:]] for _ in input().split())
x = [False] * (len(s) - len(x)) + x
a, b = [False] * len(s), [False] * len(s)
def deeper(idx, carry):
if idx:
idx -= 1
if carry:
if s[idx] == x[idx]:
ret... | Title: XOR Equation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two positive integers *a* and *b* have a sum of *s* and a bitwise XOR of *x*. How many possible values are there for the ordered pair (*a*,<=*b*)?
Input Specification:
The first line of the input contains two integers *s*... | ```python
def main():
s, x = ([c == '1' for c in bin(int(_))[2:]] for _ in input().split())
x = [False] * (len(s) - len(x)) + x
a, b = [False] * len(s), [False] * len(s)
def deeper(idx, carry):
if idx:
idx -= 1
if carry:
if s[idx] == x[idx]:
... | 0 | |
125 | B | Simple XML | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Let's define a string <x> as an opening tag, where *x* is any small letter of the Latin alphabet. Each opening tag matches a closing tag of the type </x>, where *x* is the same letter.
Tegs can be nested into each other: in this case one opening and closing tag pair is located inside another pair.
Let's d... | The input data consists on the only non-empty string — the XML-text, its length does not exceed 1000 characters. It is guaranteed that the text is valid. The text contains no spaces. | Print the given XML-text according to the above-given rules. | [
"<a><b><c></c></b></a>\n",
"<a><b></b><d><c></c></d></a>\n"
] | [
"<a>\n <b>\n <c>\n </c>\n </b>\n</a>\n",
"<a>\n <b>\n </b>\n <d>\n <c>\n </c>\n </d>\n</a>\n"
] | none | 1,500 | [
{
"input": "<a><b><c></c></b></a>",
"output": "<a>\n <b>\n <c>\n </c>\n </b>\n</a>"
},
{
"input": "<a><b></b><d><c></c></d></a>",
"output": "<a>\n <b>\n </b>\n <d>\n <c>\n </c>\n </d>\n</a>"
},
{
"input": "<z></z>",
"output": "<z>\n</z>"
},
{
"input": "<u><d... | 1,675,519,352 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 154 | 4,505,600 | # LUOGU_RID: 101468271
h = 0
for e in input().replace('><', '> <').split():
if '/' in e:
h -= 2
print(h * ' ' + e)
if '/' not in e:
h += 2 | Title: Simple XML
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's define a string <x> as an opening tag, where *x* is any small letter of the Latin alphabet. Each opening tag matches a closing tag of the type </x>, where *x* is the same letter.
Tegs can be nested into ea... | ```python
# LUOGU_RID: 101468271
h = 0
for e in input().replace('><', '> <').split():
if '/' in e:
h -= 2
print(h * ' ' + e)
if '/' not in e:
h += 2
``` | 3 | |
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are... | The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integer — the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
... | 1,652,233,561 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 30 | 0 | s=input()
j=[]
for i in s:
if(i=='Q' or i=='A'):
j.append(i)
h=0
c=0
while(h<len(j)):
if(j[h]=='Q'):
k=h+1
h=h+1
while(k<len(j)):
if(j[k]=='A'):
n=k+1
k=k+1
while(n<len(j)):
if(j[n]=='Q'):
c=c+1
... | Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"... | ```python
s=input()
j=[]
for i in s:
if(i=='Q' or i=='A'):
j.append(i)
h=0
c=0
while(h<len(j)):
if(j[h]=='Q'):
k=h+1
h=h+1
while(k<len(j)):
if(j[k]=='A'):
n=k+1
k=k+1
while(n<len(j)):
if(j[n]=='Q'):
c=c+1
... | -1 | |
750 | A | New Year and Hurry | PROGRAMMING | 800 | [
"binary search",
"brute force",
"implementation",
"math"
] | null | null | Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve th... | The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house. | Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier. | [
"3 222\n",
"4 190\n",
"7 1\n"
] | [
"2\n",
"4\n",
"7\n"
] | In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenar... | 500 | [
{
"input": "3 222",
"output": "2"
},
{
"input": "4 190",
"output": "4"
},
{
"input": "7 1",
"output": "7"
},
{
"input": "10 135",
"output": "6"
},
{
"input": "10 136",
"output": "5"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 240",
... | 1,679,414,038 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 46 | 0 | a,b=map(int,input().split())
hrs=240-b
cnt=0
for i in range(1,a+1):
hrs-=i*5
if hrs>=0:
cnt+=1
else:break
print(cnt) | Title: New Year and Hurry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem... | ```python
a,b=map(int,input().split())
hrs=240-b
cnt=0
for i in range(1,a+1):
hrs-=i*5
if hrs>=0:
cnt+=1
else:break
print(cnt)
``` | 3 | |
6 | B | President's Office | PROGRAMMING | 1,100 | [
"implementation"
] | B. President's Office | 2 | 64 | President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all ... | The first line contains two separated by a space integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the length and the width of the office-room, and *c* character — the President's desk colour. The following *n* lines contain *m* characters each — the office-room description. It is guaranteed that the colour of each ... | Print the only number — the amount of President's deputies. | [
"3 4 R\nG.B.\n.RR.\nTTT.\n",
"3 3 Z\n...\n.H.\n..Z\n"
] | [
"2\n",
"0\n"
] | none | 0 | [
{
"input": "3 4 R\nG.B.\n.RR.\nTTT.",
"output": "2"
},
{
"input": "3 3 Z\n...\n.H.\n..Z",
"output": "0"
},
{
"input": "1 1 C\nC",
"output": "0"
},
{
"input": "2 2 W\nKW\nKW",
"output": "1"
},
{
"input": "1 10 H\n....DDHHHH",
"output": "1"
},
{
"input":... | 1,573,543,383 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 155 | 2,457,600 | # ip = open("testdata.txt", "r")
# def input():
# return ip.readline().strip()
n, m, c = input().split()
n = int(n); m = int(m)
grid = [None]*n
bdesk = []
for i in range(n):
grid[i] = input()
for j in range(m):
if grid[i][j] == c:
bdesk.append((i, j))
dy = [-1, 0, 0, 1]
dx = [0, -1, 1, 0]
neighs = lambda x... | Title: President's Office
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides ... | ```python
# ip = open("testdata.txt", "r")
# def input():
# return ip.readline().strip()
n, m, c = input().split()
n = int(n); m = int(m)
grid = [None]*n
bdesk = []
for i in range(n):
grid[i] = input()
for j in range(m):
if grid[i][j] == c:
bdesk.append((i, j))
dy = [-1, 0, 0, 1]
dx = [0, -1, 1, 0]
neighs ... | 3.942939 |
981 | C | Useful Decomposition | PROGRAMMING | 1,400 | [
"implementation",
"trees"
] | null | null | Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)!
He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help!
The decomposition is the splitting the edges of the tree in some simple paths in such a way that each two pa... | The first line contains a single integer $n$ ($2 \leq n \leq 10^{5}$) the number of nodes in the tree.
Each of the next $n<=-<=1$ lines contains two integers $a_i$ and $b_i$ ($1 \leq a_i, b_i \leq n$, $a_i \neq b_i$) — the edges of the tree. It is guaranteed that the given edges form a tree. | If there are no decompositions, print the only line containing "No".
Otherwise in the first line print "Yes", and in the second line print the number of paths in the decomposition $m$.
Each of the next $m$ lines should contain two integers $u_i$, $v_i$ ($1 \leq u_i, v_i \leq n$, $u_i \neq v_i$) denoting that one of ... | [
"4\n1 2\n2 3\n3 4\n",
"6\n1 2\n2 3\n3 4\n2 5\n3 6\n",
"5\n1 2\n1 3\n1 4\n1 5\n"
] | [
"Yes\n1\n1 4\n",
"No\n",
"Yes\n4\n1 2\n1 3\n1 4\n1 5\n"
] | The tree from the first example is shown on the picture below: <img class="tex-graphics" src="https://espresso.codeforces.com/9eb4b4c143d3ad267ae05d1e43341bd368b3088b.png" style="max-width: 100.0%;max-height: 100.0%;"/> The number next to each edge corresponds to the path number in the decomposition. It is easy to see ... | 1,250 | [
{
"input": "4\n1 2\n2 3\n3 4",
"output": "Yes\n1\n1 4"
},
{
"input": "6\n1 2\n2 3\n3 4\n2 5\n3 6",
"output": "No"
},
{
"input": "5\n1 2\n1 3\n1 4\n1 5",
"output": "Yes\n4\n1 2\n1 3\n1 4\n1 5"
},
{
"input": "2\n1 2",
"output": "Yes\n1\n1 2"
},
{
"input": "8\n1 2\n1... | 1,528,479,913 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 77 | 0 | n=int(input())
d={}
for i in range(n-1):
a,b=map(int,input().split())
d[a],d[b]=d.get(a,0)+1,d.get(b,0)+1
root=[]
lev=[]
for a, b in d.items():
if b>2: root.append(a)
if b==1: lev.append(a)
if len(root)>2:
print("No")
else:
if len(root)==0:
print("Yes")
print("1")
... | Title: Useful Decomposition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)!
He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help!
Th... | ```python
n=int(input())
d={}
for i in range(n-1):
a,b=map(int,input().split())
d[a],d[b]=d.get(a,0)+1,d.get(b,0)+1
root=[]
lev=[]
for a, b in d.items():
if b>2: root.append(a)
if b==1: lev.append(a)
if len(root)>2:
print("No")
else:
if len(root)==0:
print("Yes")
p... | 0 | |
779 | A | Pupils Redistribution | PROGRAMMING | 1,000 | [
"constructive algorithms",
"math"
] | null | null | In Berland each high school student is characterized by academic performance — integer value between 1 and 5.
In high school 0xFF there are two groups of pupils: the group *A* and the group *B*. Each group consists of exactly *n* students. An academic performance of each student is known — integer value between 1 and ... | The first line of the input contains integer number *n* (1<=≤<=*n*<=≤<=100) — number of students in both groups.
The second line contains sequence of integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=5), where *a**i* is academic performance of the *i*-th student of the group *A*.
The third line contains se... | Print the required minimum number of exchanges or -1, if the desired distribution of students can not be obtained. | [
"4\n5 4 4 4\n5 5 4 5\n",
"6\n1 1 1 1 1 1\n5 5 5 5 5 5\n",
"1\n5\n3\n",
"9\n3 2 5 5 2 3 3 3 2\n4 1 4 1 1 2 4 4 1\n"
] | [
"1\n",
"3\n",
"-1\n",
"4\n"
] | none | 500 | [
{
"input": "4\n5 4 4 4\n5 5 4 5",
"output": "1"
},
{
"input": "6\n1 1 1 1 1 1\n5 5 5 5 5 5",
"output": "3"
},
{
"input": "1\n5\n3",
"output": "-1"
},
{
"input": "9\n3 2 5 5 2 3 3 3 2\n4 1 4 1 1 2 4 4 1",
"output": "4"
},
{
"input": "1\n1\n2",
"output": "-1"
... | 1,489,542,466 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 4,812,800 | n=int(input())
l1=[int(x) for x in input().split()]
l2=[int(x) for x in input().split()]
a1=a2=b1=b2=c1=c2=d1=d2=e1=e2=0
for i in range(len(l1)):
if l1[i]==1:
a1+=1
elif l1[i]==2:
b1+=1
elif l1[i]==3:
c1+=1
elif l1[i]==4:
d1+=1
else:
e1+=1
i... | Title: Pupils Redistribution
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland each high school student is characterized by academic performance — integer value between 1 and 5.
In high school 0xFF there are two groups of pupils: the group *A* and the group *B*. Each group consis... | ```python
n=int(input())
l1=[int(x) for x in input().split()]
l2=[int(x) for x in input().split()]
a1=a2=b1=b2=c1=c2=d1=d2=e1=e2=0
for i in range(len(l1)):
if l1[i]==1:
a1+=1
elif l1[i]==2:
b1+=1
elif l1[i]==3:
c1+=1
elif l1[i]==4:
d1+=1
else:
e1... | 0 | |
985 | D | Sand Fortress | PROGRAMMING | 2,100 | [
"binary search",
"constructive algorithms",
"math"
] | null | null | You are going to the beach with the idea to build the greatest sand castle ever in your head! The beach is not as three-dimensional as you could have imagined, it can be decribed as a line of spots to pile up sand pillars. Spots are numbered 1 through infinity from left to right.
Obviously, there is not enough sand o... | The only line contains two integer numbers *n* and *H* (1<=≤<=*n*,<=*H*<=≤<=1018) — the number of sand packs you have and the height of the fence, respectively. | Print the minimum number of spots you can occupy so the all the castle building conditions hold. | [
"5 2\n",
"6 8\n"
] | [
"3\n",
"3\n"
] | Here are the heights of some valid castles:
- *n* = 5, *H* = 2, [2, 2, 1, 0, ...], [2, 1, 1, 1, 0, ...], [1, 0, 1, 2, 1, 0, ...] - *n* = 6, *H* = 8, [3, 2, 1, 0, ...], [2, 2, 1, 1, 0, ...], [0, 1, 0, 1, 2, 1, 1, 0...] (this one has 5 spots occupied)
The first list for both cases is the optimal answer, 3 spots are ... | 0 | [
{
"input": "5 2",
"output": "3"
},
{
"input": "6 8",
"output": "3"
},
{
"input": "20 4",
"output": "7"
},
{
"input": "1000000000000000000 1000000000000000000",
"output": "1414213562"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 10000000000000000... | 1,586,182,882 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 109 | 307,200 | N,H = map(int,input().split())
ans = N
ok = 1
ng = H+1
while ng - ok > 1:
md = (ok+ng)//2
K = (md*(md+1))//2
if K <= N:
L = N - K
X = L//md
if L % md != 0:
X += 1
if ans > md+X:
ans = md + X
ok = md
else:
ng = md
if... | Title: Sand Fortress
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are going to the beach with the idea to build the greatest sand castle ever in your head! The beach is not as three-dimensional as you could have imagined, it can be decribed as a line of spots to pile up sand pillars... | ```python
N,H = map(int,input().split())
ans = N
ok = 1
ng = H+1
while ng - ok > 1:
md = (ok+ng)//2
K = (md*(md+1))//2
if K <= N:
L = N - K
X = L//md
if L % md != 0:
X += 1
if ans > md+X:
ans = md + X
ok = md
else:
n... | 3 | |
837 | A | Text Volume | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text. | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200) — length of the text.
The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters. | Print one integer number — volume of text. | [
"7\nNonZERO\n",
"24\nthis is zero answer text\n",
"24\nHarbour Space University\n"
] | [
"5\n",
"0\n",
"1\n"
] | In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters. | 0 | [
{
"input": "7\nNonZERO",
"output": "5"
},
{
"input": "24\nthis is zero answer text",
"output": "0"
},
{
"input": "24\nHarbour Space University",
"output": "1"
},
{
"input": "2\nWM",
"output": "2"
},
{
"input": "200\nLBmJKQLCKUgtTxMoDsEerwvLOXsxASSydOqWyULsRcjMYDWd... | 1,560,321,491 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 109 | 0 | tmp = input()
a = input().split()
ans = 0
def solve(x):
cnt = 0
for c in x:
if 'A'<=c and c<='Z':
cnt += 1
return cnt
for word in a:
ans = max(ans, solve(word))
print(ans)
| Title: Text Volume
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the tex... | ```python
tmp = input()
a = input().split()
ans = 0
def solve(x):
cnt = 0
for c in x:
if 'A'<=c and c<='Z':
cnt += 1
return cnt
for word in a:
ans = max(ans, solve(word))
print(ans)
``` | 3 | |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
}... | 1,699,100,239 | 2,147,483,647 | Python 3 | OK | TESTS | 15 | 46 | 0 | # Input the cost of the first banana, initial amount of money, and number of bananas wanted
k, n, w = map(int, input().split())
# Calculate the total cost to buy w bananas using the arithmetic series formula
total_cost = k * w * (w + 1) // 2
# Calculate the amount the soldier needs to borrow
borrow_amount = ma... | Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He h... | ```python
# Input the cost of the first banana, initial amount of money, and number of bananas wanted
k, n, w = map(int, input().split())
# Calculate the total cost to buy w bananas using the arithmetic series formula
total_cost = k * w * (w + 1) // 2
# Calculate the amount the soldier needs to borrow
borrow_a... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes... | In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad.
In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, ... | Print one integer — index of the cafe that Vlad hasn't visited for as long as possible. | [
"5\n1 3 2 1 2\n",
"6\n2 1 2 2 4 1\n"
] | [
"3\n",
"2\n"
] | In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with in... | 0 | [
{
"input": "5\n1 3 2 1 2",
"output": "3"
},
{
"input": "6\n2 1 2 2 4 1",
"output": "2"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n200000",
"output": "200000"
},
{
"input": "2\n2018 2017",
"output": "2018"
},
{
"input": "5\n100 1000 1000 1000... | 1,510,509,315 | 6,615 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 61 | 716,800 | x = [2*(10**5)]*(2*(10**5))
n = int(input())
c = 2*(10**5)-1
for i in input().split():
x[int(i)] = c
c-=1
print(x.index(min(x))+1)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First o... | ```python
x = [2*(10**5)]*(2*(10**5))
n = int(input())
c = 2*(10**5)-1
for i in input().split():
x[int(i)] = c
c-=1
print(x.index(min(x))+1)
``` | 0 | |
787 | A | The Monster | PROGRAMMING | 1,200 | [
"brute force",
"math",
"number theory"
] | null | null | A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times *b*,<=*b*<=+<=*a*,<=*b*<=+<=2*a*,<=*b*<=+<=3*a*,<=... and Morty screams at times *d*,<=*d*<=+<=*c*,<=*d*<=+<=2*c*,<=*d*<=+<=3*c*,<=....
The Monster will catch them if a... | The first line of input contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100).
The second line contains two integers *c* and *d* (1<=≤<=*c*,<=*d*<=≤<=100). | Print the first time Rick and Morty will scream at the same time, or <=-<=1 if they will never scream at the same time. | [
"20 2\n9 19\n",
"2 1\n16 12\n"
] | [
"82\n",
"-1\n"
] | In the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82.
In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time. | 500 | [
{
"input": "20 2\n9 19",
"output": "82"
},
{
"input": "2 1\n16 12",
"output": "-1"
},
{
"input": "39 52\n88 78",
"output": "1222"
},
{
"input": "59 96\n34 48",
"output": "1748"
},
{
"input": "87 37\n91 29",
"output": "211"
},
{
"input": "11 81\n49 7",
... | 1,587,637,112 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 34 | 124 | 0 | a,b=map(int,input().split())
c,d=map(int,input().split())
t=0
for i in range(1000):
m=(b-d+a*i)/c
u=m-int(m)
if u==0:
print(b+a*i)
t=1
break
if t==0:
print("-1")
| Title: The Monster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times *b*,<=*b*<=+<=*a*,<=*b*<=+<=2*a*,<=*b*<=+<=3*a*,<=... and Morty screams a... | ```python
a,b=map(int,input().split())
c,d=map(int,input().split())
t=0
for i in range(1000):
m=(b-d+a*i)/c
u=m-int(m)
if u==0:
print(b+a*i)
t=1
break
if t==0:
print("-1")
``` | 0 | |
678 | B | The Same Calendar | PROGRAMMING | 1,600 | [
"implementation"
] | null | null | The girl Taylor has a beautiful calendar for the year *y*. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.
The calendar is so beautiful that she wants to know what is the next year after *y* when the calendar will be exactly the same. Help ... | The only line contains integer *y* (1000<=≤<=*y*<=<<=100'000) — the year of the calendar. | Print the only integer *y*' — the next year after *y* when the calendar will be the same. Note that you should find the first year after *y* with the same calendar. | [
"2016\n",
"2000\n",
"50501\n"
] | [
"2044\n",
"2028\n",
"50507\n"
] | Today is Monday, the 13th of June, 2016. | 0 | [
{
"input": "2016",
"output": "2044"
},
{
"input": "2000",
"output": "2028"
},
{
"input": "50501",
"output": "50507"
},
{
"input": "1000",
"output": "1006"
},
{
"input": "1900",
"output": "1906"
},
{
"input": "1899",
"output": "1905"
},
{
"i... | 1,623,770,843 | 1,643 | PyPy 3 | OK | TESTS | 40 | 93 | 0 | def f(n):
if n%400==0 or (n%100!=0 and n%4==0):
return 2
else:
return 1
n=int(input())
x=n
c=f(n)
n+=1
while c%7!=0 or f(n)!=f(x):
c+=f(n)
n+=1
print(n) | Title: The Same Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The girl Taylor has a beautiful calendar for the year *y*. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.
The calendar is so beautiful t... | ```python
def f(n):
if n%400==0 or (n%100!=0 and n%4==0):
return 2
else:
return 1
n=int(input())
x=n
c=f(n)
n+=1
while c%7!=0 or f(n)!=f(x):
c+=f(n)
n+=1
print(n)
``` | 3 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,570,642,980 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 248 | 0 | s=input()
cntl=0
cntc=0
for i in range(0,len(s)):
if(s[i].islower()):
cntl+=1
else:
cntc+=1
if cntl>=cntc:
print(s.lower())
else:
print(s.upper()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
s=input()
cntl=0
cntc=0
for i in range(0,len(s)):
if(s[i].islower()):
cntl+=1
else:
cntc+=1
if cntl>=cntc:
print(s.lower())
else:
print(s.upper())
``` | 3.938 |
940 | A | Points on the line | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"sortings"
] | null | null | We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.
The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1,<=3,<=2,<=1} is 2.
D... | The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=100,<=0<=≤<=*d*<=≤<=100) — the amount of points and the maximum allowed diameter respectively.
The second line contains *n* space separated integers (1<=≤<=*x**i*<=≤<=100) — the coordinates of the points. | Output a single integer — the minimum number of points you have to remove. | [
"3 1\n2 1 4\n",
"3 0\n7 7 7\n",
"6 3\n1 3 4 6 9 10\n"
] | [
"1\n",
"0\n",
"3\n"
] | In the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2 - 1 = 1.
In the second test case the diameter is equal to 0, so its is unnecessary to remove any points.
In the third test case the optimal stra... | 500 | [
{
"input": "3 1\n2 1 4",
"output": "1"
},
{
"input": "3 0\n7 7 7",
"output": "0"
},
{
"input": "6 3\n1 3 4 6 9 10",
"output": "3"
},
{
"input": "11 5\n10 11 12 13 14 15 16 17 18 19 20",
"output": "5"
},
{
"input": "1 100\n1",
"output": "0"
},
{
"input"... | 1,519,843,750 | 1,150 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 5,632,000 | def verificar(lista,d):
maior = max(lista)
menor = min(lista)
if(maior-menor > d):
return False
return True
n, d = [int(i) for i in input().split()]
conjunto = [int(i) for i in input().split()]
contador = 0
while(not verificar(conjunto,d)):
del(conjunto[conjunto.index(max(conjunto))])
contado... | Title: Points on the line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.
The diameter of a multiset of points on the line is the largest dista... | ```python
def verificar(lista,d):
maior = max(lista)
menor = min(lista)
if(maior-menor > d):
return False
return True
n, d = [int(i) for i in input().split()]
conjunto = [int(i) for i in input().split()]
contador = 0
while(not verificar(conjunto,d)):
del(conjunto[conjunto.index(max(conjunto))])... | 0 | |
80 | A | Panoramix's Prediction | PROGRAMMING | 800 | [
"brute force"
] | A. Panoramix's Prediction | 2 | 256 | A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t... | The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4. | Print YES, if *m* is the next prime number after *n*, or NO otherwise. | [
"3 5\n",
"7 11\n",
"7 9\n"
] | [
"YES",
"YES",
"NO"
] | none | 500 | [
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
... | 1,621,398,937 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 218 | 2,150,400 | primes = [2,3,5,7,11,13,17,23,29,31,37,41,43,47,53]
n, m = map(int, input().split())
if l[l.index(n) +1] == m: print("YES")
else: print("NO") | Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater t... | ```python
primes = [2,3,5,7,11,13,17,23,29,31,37,41,43,47,53]
n, m = map(int, input().split())
if l[l.index(n) +1] == m: print("YES")
else: print("NO")
``` | -1 |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,690,365,883 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 9 | 62 | 0 | s = input("")
t = input("")
l1 = list(s)
tr = reversed(t)
l2 = list(tr)
count = 0
for i in range(0, len(l1)):
if l1[i] == l2[i]:
count = count + 1
if count == len(l1):
print("YES")
else:
print("NO")
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
s = input("")
t = input("")
l1 = list(s)
tr = reversed(t)
l2 = list(tr)
count = 0
for i in range(0, len(l1)):
if l1[i] == l2[i]:
count = count + 1
if count == len(l1):
print("YES")
else:
print("NO")
``` | -1 |
946 | C | String Transformation | PROGRAMMING | 1,300 | [
"greedy",
"strings"
] | null | null | You are given a string *s* consisting of |*s*| small english letters.
In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace letter z with any other letter.
Your target is to make some number... | The only one line of the input consisting of the string *s* consisting of |*s*| (1<=≤<=|*s*|<=≤<=105) small english letters. | If you can get a string that can be obtained from the given string and will contain english alphabet as a subsequence, print it. Otherwise print «-1» (without quotes). | [
"aacceeggiikkmmooqqssuuwwyy\n",
"thereisnoanswer\n"
] | [
"abcdefghijklmnopqrstuvwxyz\n",
"-1\n"
] | none | 0 | [
{
"input": "aacceeggiikkmmooqqssuuwwyy",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "thereisnoanswer",
"output": "-1"
},
{
"input": "jqcfvsaveaixhioaaeephbmsmfcgdyawscpyioybkgxlcrhaxs",
"output": "-1"
},
{
"input": "rtdacjpsjjmjdhcoprjhaenlwuvpfqzurnrswngmpnkdnunaen... | 1,541,422,303 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 108 | 0 | text = input()
if len(text) == 26:
ans = 0
for i in range(len(text)):
if ord(text[i]) > i + 97:
print(-1)
break
elif i == 25:
print('abcdefghijklmnopqrstuvwxyz')
else:
print(-1)
| Title: String Transformation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* consisting of |*s*| small english letters.
In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be rep... | ```python
text = input()
if len(text) == 26:
ans = 0
for i in range(len(text)):
if ord(text[i]) > i + 97:
print(-1)
break
elif i == 25:
print('abcdefghijklmnopqrstuvwxyz')
else:
print(-1)
``` | 0 | |
234 | G | Practice | PROGRAMMING | 1,600 | [
"constructive algorithms",
"divide and conquer",
"implementation"
] | null | null | Little time is left before Berland annual football championship. Therefore the coach of team "Losewille Rangers" decided to resume the practice, that were indefinitely interrupted for uncertain reasons. Overall there are *n* players in "Losewille Rangers". Each player on the team has a number — a unique integer from 1 ... | A single input line contains integer *n* (2<=≤<=*n*<=≤<=1000). | In the first line print *m* — the minimum number of practices the coach will have to schedule. Then print the descriptions of the practices in *m* lines.
In the *i*-th of those lines print *f**i* — the number of players in the first team during the *i*-th practice (1<=≤<=*f**i*<=<<=*n*), and *f**i* numbers from 1 t... | [
"2\n",
"3\n"
] | [
"1\n1 1\n",
"2\n2 1 2\n1 1\n"
] | none | 0 | [
{
"input": "2",
"output": "1\n1 1"
},
{
"input": "3",
"output": "2\n2 1 2\n1 1"
},
{
"input": "4",
"output": "2\n2 1 2\n2 1 3"
},
{
"input": "5",
"output": "3\n3 1 2 3\n3 1 2 4\n1 1"
},
{
"input": "6",
"output": "3\n3 1 2 3\n4 1 2 4 5\n2 1 4"
},
{
"inp... | 1,679,019,411 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | import math
def divide_group(src, a, b):
for l, r in src:
if l == r:
b.append((l, r))
else:
p = math.floor((l + r) / 2)
a.append((l, p))
b.append((p + 1, r))
def size(groups):
return max([group[1] - group[0] + 1 for group in groups] or [0])
def ... | Title: Practice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little time is left before Berland annual football championship. Therefore the coach of team "Losewille Rangers" decided to resume the practice, that were indefinitely interrupted for uncertain reasons. Overall there are *n* p... | ```python
import math
def divide_group(src, a, b):
for l, r in src:
if l == r:
b.append((l, r))
else:
p = math.floor((l + r) / 2)
a.append((l, p))
b.append((p + 1, r))
def size(groups):
return max([group[1] - group[0] + 1 for group in groups] or ... | -1 | |
0 | none | none | none | 0 | [
"none"
] | null | null | We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109<=+<... | The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106. | Print the minimum number of steps modulo 109<=+<=7. | [
"ab\n",
"aab\n"
] | [
"1\n",
"3\n"
] | The first example: "ab" → "bba".
The second example: "aab" → "abba" → "bbaba" → "bbbbaa". | 0 | [
{
"input": "ab",
"output": "1"
},
{
"input": "aab",
"output": "3"
},
{
"input": "aaaaabaabababaaaaaba",
"output": "17307"
},
{
"input": "abaabaaabbabaabab",
"output": "1795"
},
{
"input": "abbaa",
"output": "2"
},
{
"input": "abbaaabaabaaaaabbbbaababaa... | 1,599,288,281 | 5,681 | PyPy 3 | OK | TESTS | 32 | 233 | 7,680,000 | import sys
import bisect
import math as mt
#input=sys.stdin.readline
#t=int(input())
t=1
mod=10**9+7
for _ in range(t):
#n=int(input())
#l,r=map(int,input().split())
#l1=list(map(int,input().split()))
#l2=list(map(int,input().split()))
s=input()
n=len(s)
cnt=0
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is don... | ```python
import sys
import bisect
import math as mt
#input=sys.stdin.readline
#t=int(input())
t=1
mod=10**9+7
for _ in range(t):
#n=int(input())
#l,r=map(int,input().split())
#l1=list(map(int,input().split()))
#l2=list(map(int,input().split()))
s=input()
n=len(s)
... | 3 | |
854 | A | Fraction | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"math"
] | null | null | Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive co... | In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction. | Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. | [
"3\n",
"4\n",
"12\n"
] | [
"1 2\n",
"1 3\n",
"5 7\n"
] | none | 500 | [
{
"input": "3",
"output": "1 2"
},
{
"input": "4",
"output": "1 3"
},
{
"input": "12",
"output": "5 7"
},
{
"input": "34",
"output": "15 19"
},
{
"input": "13",
"output": "6 7"
},
{
"input": "11",
"output": "5 6"
},
{
"input": "24",
"ou... | 1,687,531,403 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | from math import *
n=int(input())
a,b=n//2,n-n//2
while math.gcd(a,b)!=1:a,b=a-1,b+1
print(a,b) | Title: Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is cal... | ```python
from math import *
n=int(input())
a,b=n//2,n-n//2
while math.gcd(a,b)!=1:a,b=a-1,b+1
print(a,b)
``` | -1 | |
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,674,440,174 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 530 | 307,200 | n,m=map(int,input().split())
a=[]
b=[]
for i in range(m):
x,y=map(str,input().split(" "))
a.append(x)
b.append(y)
s=list(input().split(" "))
for i in range(n):
if(len(a[a.index(s[i])])>len(b[a.index(s[i])])):
s[i]=b[a.index(s[i])]
else:
s[i]=a[a.index(s[i])]
print(*s) | 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())
a=[]
b=[]
for i in range(m):
x,y=map(str,input().split(" "))
a.append(x)
b.append(y)
s=list(input().split(" "))
for i in range(n):
if(len(a[a.index(s[i])])>len(b[a.index(s[i])])):
s[i]=b[a.index(s[i])]
else:
s[i]=a[a.index(s[i])]
pr... | 3 | |
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu... | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the son... | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE... | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "... | 1,678,549,223 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 122 | 0 | li = list(map(str, input().split(sep='WUB')))
space = li.count('')
for i in range(space):
li.remove('')
print(*li) | Title: Dubstep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consist... | ```python
li = list(map(str, input().split(sep='WUB')))
space = li.count('')
for i in range(space):
li.remove('')
print(*li)
``` | 3 | |
637 | B | Chat Order | PROGRAMMING | 1,200 | [
"*special",
"binary search",
"constructive algorithms",
"data structures",
"sortings"
] | null | null | Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then... | The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10. | Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom. | [
"4\nalex\nivan\nroman\nivan\n",
"8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n"
] | [
"ivan\nroman\nalex\n",
"alina\nmaria\nekaterina\ndarya\n"
] | In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1... | 1,000 | [
{
"input": "4\nalex\nivan\nroman\nivan",
"output": "ivan\nroman\nalex"
},
{
"input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina",
"output": "alina\nmaria\nekaterina\ndarya"
},
{
"input": "1\nwdi",
"output": "wdi"
},
{
"input": "2\nypg\nypg",
"outpu... | 1,511,170,831 | 2,147,483,647 | Python 3 | OK | TESTS | 95 | 1,014 | 15,360,000 | n =int(input())
arr =[]
for i in range(n):
arr.append(input())
arr =arr[::-1]
string =set()
for a in arr:
if (a not in string):
string.add(a)
print (a) | Title: Chat Order
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The rela... | ```python
n =int(input())
arr =[]
for i in range(n):
arr.append(input())
arr =arr[::-1]
string =set()
for a in arr:
if (a not in string):
string.add(a)
print (a)
``` | 3 | |
723 | A | The New Year: Meeting Friends | PROGRAMMING | 800 | [
"implementation",
"math",
"sortings"
] | null | null | There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they... | The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. | Print one integer — the minimum total distance the friends need to travel in order to meet together. | [
"7 1 4\n",
"30 20 10\n"
] | [
"6\n",
"20\n"
] | In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | 500 | [
{
"input": "7 1 4",
"output": "6"
},
{
"input": "30 20 10",
"output": "20"
},
{
"input": "1 4 100",
"output": "99"
},
{
"input": "100 1 91",
"output": "99"
},
{
"input": "1 45 100",
"output": "99"
},
{
"input": "1 2 3",
"output": "2"
},
{
"... | 1,686,817,123 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 46 | 0 | # https://codeforces.com/problemset/problem/723/A
def main():
a, b, c = map(int, input().split(' '))
_min = min(a, b, c)
_max = max(a, b, c)
print(_max - _min)
if __name__ == '__main__':
main()
| Title: The New Year: Meeting Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ... | ```python
# https://codeforces.com/problemset/problem/723/A
def main():
a, b, c = map(int, input().split(' '))
_min = min(a, b, c)
_max = max(a, b, c)
print(_max - _min)
if __name__ == '__main__':
main()
``` | 3 | |
522 | A | Reposts | PROGRAMMING | 1,200 | [
"*special",
"dfs and similar",
"dp",
"graphs",
"trees"
] | null | null | One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
These events are given as a sequence of strings "name1 reposted name2", where name1 is the n... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and ... | Print a single integer — the maximum length of a repost chain. | [
"5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n",
"6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n",
"1\nSoMeStRaNgEgUe repos... | [
"6\n",
"2\n",
"2\n"
] | none | 500 | [
{
"input": "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya",
"output": "6"
},
{
"input": "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforc... | 1,568,321,948 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 109 | 0 | n = int(input())
pairs = []
idx = dict()
count = 0
for _ in range(n):
a, b, c = map(lambda x: x.lower(), input().split())
if a not in idx:
idx[a] = count
count += 1
if c not in idx:
idx[c] = count
count += 1
pairs.append((a, c))
elems = len(idx)
parent = [i for i in ra... | Title: Reposts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
... | ```python
n = int(input())
pairs = []
idx = dict()
count = 0
for _ in range(n):
a, b, c = map(lambda x: x.lower(), input().split())
if a not in idx:
idx[a] = count
count += 1
if c not in idx:
idx[c] = count
count += 1
pairs.append((a, c))
elems = len(idx)
parent = [i f... | 3 | |
221 | A | Little Elephant and Function | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works... | A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation. | In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces.
It is guaranteed that the answer exists. | [
"1\n",
"2\n"
] | [
"1 ",
"2 1 "
] | none | 500 | [
{
"input": "1",
"output": "1 "
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "4",
"output": "4 1 2 3 "
},
{
"input": "5",
"output": "5 1 2 3 4 "
},
{
"input": "6",
"output": "6 1 2 3 4 5 "
},
{
"inp... | 1,623,920,405 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 216 | 1,331,200 | n=int(input())
a=[n]
for i in range(1,n):
a.append(i)
print(*a) | Title: Little Elephant and Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the perm... | ```python
n=int(input())
a=[n]
for i in range(1,n):
a.append(i)
print(*a)
``` | 3 | |
883 | M | Quadcopter Competition | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | Polycarp takes part in a quadcopter competition. According to the rules a flying robot should:
- start the race from some point of a field, - go around the flag, - close cycle returning back to the starting point.
Polycarp knows the coordinates of the starting point (*x*1,<=*y*1) and the coordinates of the point w... | The first line contains two integer numbers *x*1 and *y*1 (<=-<=100<=≤<=*x*1,<=*y*1<=≤<=100) — coordinates of the quadcopter starting (and finishing) point.
The second line contains two integer numbers *x*2 and *y*2 (<=-<=100<=≤<=*x*2,<=*y*2<=≤<=100) — coordinates of the flag.
It is guaranteed that the quadcopter sta... | Print the length of minimal path of the quadcopter to surround the flag and return back. | [
"1 5\n5 2\n",
"0 1\n0 0\n"
] | [
"18\n",
"8\n"
] | none | 0 | [
{
"input": "1 5\n5 2",
"output": "18"
},
{
"input": "0 1\n0 0",
"output": "8"
},
{
"input": "-100 -100\n100 100",
"output": "804"
},
{
"input": "-100 -100\n-100 100",
"output": "406"
},
{
"input": "-100 -100\n100 -100",
"output": "406"
},
{
"input": "1... | 1,510,371,976 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | #!/usr/bin/env python3
x1, y1 = [int(x) for x in input().split(' ')]
x2, y2 = [int(x) for x in input().split(' ')]
print(2*(abs(x1-x2)+1)+2*(abs(y1-y2)+1))
| Title: Quadcopter Competition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp takes part in a quadcopter competition. According to the rules a flying robot should:
- start the race from some point of a field, - go around the flag, - close cycle returning back to the starting p... | ```python
#!/usr/bin/env python3
x1, y1 = [int(x) for x in input().split(' ')]
x2, y2 = [int(x) for x in input().split(' ')]
print(2*(abs(x1-x2)+1)+2*(abs(y1-y2)+1))
``` | 0 | |
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,647,629,303 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 122 | 0 | def iq_test():
n = int(input())
l = input().split()
aux = 0
even = 0
f_even = 0
odd = 0
f_odd = 0
for i in l:
aux += 1
if(int(i)%2==0):
even+=1
f_even = aux
else:
odd+=1
f_odd = aux
if(odd>1 and f_even>0):
print(f_even)
return
elif(even>1 and f_... | 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
def iq_test():
n = int(input())
l = input().split()
aux = 0
even = 0
f_even = 0
odd = 0
f_odd = 0
for i in l:
aux += 1
if(int(i)%2==0):
even+=1
f_even = aux
else:
odd+=1
f_odd = aux
if(odd>1 and f_even>0):
print(f_even)
return
elif(eve... | 3.9695 |
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,686,916,462 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 46 | 0 | #Keshika Patwari
#Indian Institute Of Technology, Jodhpur
# 2022
import sys
input=sys.stdin.readline
def exe():
max_dis=0
lis.sort()
for i in range(n-1):
if(abs(lis[i]-lis[i+1])>max_dis):
max_dis=abs(lis[i]-lis[i+1])
#print(lis[0],max_dis/2)
if(abs(lis[0])>max_dis/2)... | 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
#Keshika Patwari
#Indian Institute Of Technology, Jodhpur
# 2022
import sys
input=sys.stdin.readline
def exe():
max_dis=0
lis.sort()
for i in range(n-1):
if(abs(lis[i]-lis[i+1])>max_dis):
max_dis=abs(lis[i]-lis[i+1])
#print(lis[0],max_dis/2)
if(abs(lis[0])>... | 3 | |
639 | C | Bear and Polynomials | PROGRAMMING | 2,200 | [
"hashing",
"implementation",
"math"
] | null | null | Limak is a little polar bear. He doesn't have many toys and thus he often plays with polynomials.
He considers a polynomial valid if its degree is *n* and its coefficients are integers not exceeding *k* by the absolute value. More formally:
Let *a*0,<=*a*1,<=...,<=*a**n* denote the coefficients, so . Then, a polynomi... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=200<=000,<=1<=≤<=*k*<=≤<=109) — the degree of the polynomial and the limit for absolute values of coefficients.
The second line contains *n*<=+<=1 integers *a*0,<=*a*1,<=...,<=*a**n* (|*a**i*|<=≤<=*k*,<=*a**n*<=≠<=0) — describing a valid polynomial . It's... | Print the number of ways to change one coefficient to get a valid polynomial *Q* that *Q*(2)<==<=0. | [
"3 1000000000\n10 -9 -3 5\n",
"3 12\n10 -9 -3 5\n",
"2 20\n14 -7 19\n"
] | [
"3\n",
"2\n",
"0\n"
] | In the first sample, we are given a polynomial *P*(*x*) = 10 - 9*x* - 3*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup>.
Limak can change one coefficient in three ways:
1. He can set *a*<sub class="lower-index">0</sub> = - 10. Then he would get *Q*(*x*) = - 10 - 9*x* - 3*x*<sup class="upp... | 1,000 | [
{
"input": "3 1000000000\n10 -9 -3 5",
"output": "3"
},
{
"input": "3 12\n10 -9 -3 5",
"output": "2"
},
{
"input": "2 20\n14 -7 19",
"output": "0"
},
{
"input": "5 5\n0 -4 -2 -2 0 5",
"output": "1"
},
{
"input": "6 10\n-2 -1 7 -3 2 7 -6",
"output": "2"
},
... | 1,459,193,236 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 44,134,400 | n,k = map(int,input().split(" "))
mas = list(map(int,input().split(" ")))
ss=1
su=0
for i in range(n+1):
su+=ss*mas[i]
ss<<=1
ss=1
res=0
for i in range(n+1):
t =ss*mas[i]
su-=t
if su!=0 and su%ss==0 and abs(su)<=abs(ss*k): res+=1
su+=t
ss<<=1
print(res) | Title: Bear and Polynomials
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a little polar bear. He doesn't have many toys and thus he often plays with polynomials.
He considers a polynomial valid if its degree is *n* and its coefficients are integers not exceeding *k* by the abs... | ```python
n,k = map(int,input().split(" "))
mas = list(map(int,input().split(" ")))
ss=1
su=0
for i in range(n+1):
su+=ss*mas[i]
ss<<=1
ss=1
res=0
for i in range(n+1):
t =ss*mas[i]
su-=t
if su!=0 and su%ss==0 and abs(su)<=abs(ss*k): res+=1
su+=t
ss<<=1
print(res)
``` | 0 | |
672 | B | Different is Good | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation",
"strings"
] | null | null | A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the string *s*.
The second line contains the string *s* of length *n* consisting of only lowercase English letters. | If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes. | [
"2\naa\n",
"4\nkoko\n",
"5\nmurat\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first sample one of the possible solutions is to change the first character to 'b'.
In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko". | 1,000 | [
{
"input": "2\naa",
"output": "1"
},
{
"input": "4\nkoko",
"output": "2"
},
{
"input": "5\nmurat",
"output": "0"
},
{
"input": "6\nacbead",
"output": "1"
},
{
"input": "7\ncdaadad",
"output": "4"
},
{
"input": "25\npeoaicnbisdocqofsqdpgobpn",
"outp... | 1,642,425,388 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 46 | 0 | n = int(input())
s = set(input())
res = n - len(s)
if res > 26:
print(-1)
else:
print(res)
| Title: Different is Good
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are di... | ```python
n = int(input())
s = set(input())
res = n - len(s)
if res > 26:
print(-1)
else:
print(res)
``` | 0 | |
508 | A | Pasha and Pixels | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choos... | The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i*... | If Pasha loses, print the number of the move when the 2<=×<=2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2<=×<=2 square consisting of black pixels is formed during the given *k* moves, print 0. | [
"2 2 4\n1 1\n1 2\n2 1\n2 2\n",
"2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n",
"5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n"
] | [
"4\n",
"5\n",
"0\n"
] | none | 500 | [
{
"input": "2 2 4\n1 1\n1 2\n2 1\n2 2",
"output": "4"
},
{
"input": "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1",
"output": "5"
},
{
"input": "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2",
"output": "0"
},
{
"input": "3 3 11\n2 1\n3 1\n1 1\n1 3\n1 2\n2 3\n3 3\n3 2\n2 2\n1 3\n3 3",
... | 1,667,997,405 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 577 | 5,324,800 | n,m,k = map(int,input().split())
lst = [[False for i in range(m+2)] for i in range(n+2)]
step = 0
for i in range(k):
step += 1
x,y = map(int,input().split())
lst[x][y] = True
if all([lst[x][y],lst[x][y+1],lst[x+1][y],lst[x+1][y+1]])\
or all([lst[x][y],lst[x][y-1],lst[x+1][y],lst[x+1][y-1... | Title: Pasha and Pixels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row ... | ```python
n,m,k = map(int,input().split())
lst = [[False for i in range(m+2)] for i in range(n+2)]
step = 0
for i in range(k):
step += 1
x,y = map(int,input().split())
lst[x][y] = True
if all([lst[x][y],lst[x][y+1],lst[x+1][y],lst[x+1][y+1]])\
or all([lst[x][y],lst[x][y-1],lst[x+1][y],ls... | 3 | |
347 | B | Fixed Points | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math"
] | null | null | A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] are not.
A fixed point of a function is a point that is mapped to itself by the function. A p... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 — the given permutation. | Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation. | [
"5\n0 1 3 4 2\n"
] | [
"3\n"
] | none | 1,000 | [
{
"input": "5\n0 1 3 4 2",
"output": "3"
},
{
"input": "10\n6 9 4 7 8 2 3 5 0 1",
"output": "2"
},
{
"input": "100\n99 5 40 32 4 31 38 57 94 47 26 16 89 72 9 80 55 86 78 90 42 41 46 74 56 97 21 48 66 27 93 85 88 59 64 95 10 45 12 22 84 60 8 98 62 51 14 65 39 30 11 71 92 19 76 43 87 54 15... | 1,379,797,370 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | N=int(input())
i=0
num=[]
new=[]
total=0
isSorted=False
flagDouble=False
IN=input().split()
while(i<N):
num.append((int(IN[i]),i))
new.append(int(IN[i]))
if i==new[i]:
total=total+1
i=i+1
if total==N:
isSorted=True
else:
num.sort()
for i in range(N):
if num[i][1]==new[num[i][1]] and i!=num[i][1]:
... | Title: Fixed Points
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<... | ```python
N=int(input())
i=0
num=[]
new=[]
total=0
isSorted=False
flagDouble=False
IN=input().split()
while(i<N):
num.append((int(IN[i]),i))
new.append(int(IN[i]))
if i==new[i]:
total=total+1
i=i+1
if total==N:
isSorted=True
else:
num.sort()
for i in range(N):
if num[i][1]==new[num[i][1]] and i!=num[i... | 0 | |
157 | B | Trace | PROGRAMMING | 1,000 | [
"geometry",
"sortings"
] | null | null | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides,... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *r**i* (1<=≤<=*r**i*<=≤<=1000) — the circles' radii. It is guaranteed that all circles are different. | Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4. | [
"1\n1\n",
"3\n1 4 2\n"
] | [
"3.1415926536\n",
"40.8407044967\n"
] | In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π.
In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the secon... | 1,000 | [
{
"input": "1\n1",
"output": "3.1415926536"
},
{
"input": "3\n1 4 2",
"output": "40.8407044967"
},
{
"input": "4\n4 1 3 2",
"output": "31.4159265359"
},
{
"input": "4\n100 10 2 1",
"output": "31111.1920484997"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output"... | 1,615,035,629 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 216 | 2,252,800 | from math import pi
def countSort(tab, n):
max_ = max(tab)
min_ = min(tab)
zakres = max_-min_+1
pom = [0 for _ in range(max_-min_+1)]
for elem in tab:
pom[elem-min_] = 1
suma = 0
now_blue = True
for i in range(-1, -1*(zakres+1), -1):
if pom[i] == 1:
if now_b... | Title: Trace
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall in... | ```python
from math import pi
def countSort(tab, n):
max_ = max(tab)
min_ = min(tab)
zakres = max_-min_+1
pom = [0 for _ in range(max_-min_+1)]
for elem in tab:
pom[elem-min_] = 1
suma = 0
now_blue = True
for i in range(-1, -1*(zakres+1), -1):
if pom[i] == 1:
... | -1 | |
449 | B | Jzzhu and Cities | PROGRAMMING | 2,000 | [
"graphs",
"greedy",
"shortest paths"
] | null | null | Jzzhu is the president of country A. There are *n* cities numbered from 1 to *n* in his country. City 1 is the capital of A. Also there are *m* roads connecting the cities. One can go from city *u**i* to *v**i* (and vise versa) using the *i*-th road, the length of this road is *x**i*. Finally, there are *k* train route... | The first line contains three integers *n*,<=*m*,<=*k* (2<=≤<=*n*<=≤<=105; 1<=≤<=*m*<=≤<=3·105; 1<=≤<=*k*<=≤<=105).
Each of the next *m* lines contains three integers *u**i*,<=*v**i*,<=*x**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; *u**i*<=≠<=*v**i*; 1<=≤<=*x**i*<=≤<=109).
Each of the next *k* lines contains two integers *s*... | Output a single integer representing the maximum number of the train routes which can be closed. | [
"5 5 3\n1 2 1\n2 3 2\n1 3 3\n3 4 4\n1 5 5\n3 5\n4 5\n5 5\n",
"2 2 3\n1 2 2\n2 1 3\n2 1\n2 2\n2 3\n"
] | [
"2\n",
"2\n"
] | none | 1,000 | [
{
"input": "5 5 3\n1 2 1\n2 3 2\n1 3 3\n3 4 4\n1 5 5\n3 5\n4 5\n5 5",
"output": "2"
},
{
"input": "2 2 3\n1 2 2\n2 1 3\n2 1\n2 2\n2 3",
"output": "2"
},
{
"input": "5 4 3\n1 2 999999999\n2 3 1000000000\n3 4 529529529\n5 1 524524524\n5 524444444\n5 529999999\n2 1000000000",
"output": ... | 1,696,550,034 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 134,963,200 | import sys, threading
sys.setrecursionlimit(1 << 30)
threading.stack_size(1 << 27)
from collections import defaultdict, deque, Counter
from functools import lru_cache
from heapq import heappush, heappop
from bisect import bisect_right, bisect_left
def inpNum():
return int(input())
def inpStr():... | Title: Jzzhu and Cities
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jzzhu is the president of country A. There are *n* cities numbered from 1 to *n* in his country. City 1 is the capital of A. Also there are *m* roads connecting the cities. One can go from city *u**i* to *v**i* (and vi... | ```python
import sys, threading
sys.setrecursionlimit(1 << 30)
threading.stack_size(1 << 27)
from collections import defaultdict, deque, Counter
from functools import lru_cache
from heapq import heappush, heappop
from bisect import bisect_right, bisect_left
def inpNum():
return int(input())
def... | 0 | |
645 | A | Amity Assessment | PROGRAMMING | 1,200 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2<=×<=2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a move, Bessie or Elsie can slide a tile adjacent to the empty cell into the ... | The first two lines of the input consist of a 2<=×<=2 grid describing the initial configuration of Bessie's puzzle. The next two lines contain a 2<=×<=2 grid describing the initial configuration of Elsie's puzzle. The positions of the tiles are labeled 'A', 'B', and 'C', while the empty cell is labeled 'X'. It's guaran... | Output "YES"(without quotes) if the puzzles can reach the same configuration (and Bessie and Elsie are truly BFFLs). Otherwise, print "NO" (without quotes). | [
"AB\nXC\nXB\nAC\n",
"AB\nXC\nAC\nBX\n"
] | [
"YES\n",
"NO\n"
] | The solution to the first sample is described by the image. All Bessie needs to do is slide her 'A' tile down.
In the second sample, the two puzzles can never be in the same configuration. Perhaps Bessie and Elsie are not meant to be friends after all... | 500 | [
{
"input": "AB\nXC\nXB\nAC",
"output": "YES"
},
{
"input": "AB\nXC\nAC\nBX",
"output": "NO"
},
{
"input": "XC\nBA\nCB\nAX",
"output": "NO"
},
{
"input": "AB\nXC\nAX\nCB",
"output": "YES"
},
{
"input": "CB\nAX\nXA\nBC",
"output": "YES"
},
{
"input": "BC... | 1,667,743,857 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 62 | 0 | f = lambda: 'ABC' in 2*(input()+input()[::-1]).replace('X', '')
print('NO' if f()^f() else 'YES') | Title: Amity Assessment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2<=×<=2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one ... | ```python
f = lambda: 'ABC' in 2*(input()+input()[::-1]).replace('X', '')
print('NO' if f()^f() else 'YES')
``` | 3 | |
788 | B | Weird journey | PROGRAMMING | 2,100 | [
"combinatorics",
"constructive algorithms",
"dfs and similar",
"dsu",
"graphs"
] | null | null | Little boy Igor wants to become a traveller. At first, he decided to visit all the cities of his motherland — Uzhlyandia.
It is widely known that Uzhlyandia has *n* cities connected with *m* bidirectional roads. Also, there are no two roads in the country that connect the same pair of cities, but roads starting and en... | The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=106) — the number of cities and roads in Uzhlyandia, respectively.
Each of the next *m* lines contains two integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*) that mean that there is road between cities *u* and *v*.
It is guaranteed that no road will be gi... | Print out the only integer — the number of good paths in Uzhlyandia. | [
"5 4\n1 2\n1 3\n1 4\n1 5\n",
"5 3\n1 2\n2 3\n4 5\n",
"2 2\n1 1\n1 2\n"
] | [
"6",
"0",
"1"
] | In first sample test case the good paths are:
- 2 → 1 → 3 → 1 → 4 → 1 → 5, - 2 → 1 → 3 → 1 → 5 → 1 → 4, - 2 → 1 → 4 → 1 → 5 → 1 → 3, - 3 → 1 → 2 → 1 → 4 → 1 → 5, - 3 → 1 → 2 → 1 → 5 → 1 → 4, - 4 → 1 → 2 → 1 → 3 → 1 → 5.
There are good paths that are same with displayed above, because the sets of roads they pas... | 1,250 | [
{
"input": "5 4\n1 2\n1 3\n1 4\n1 5",
"output": "6"
},
{
"input": "5 3\n1 2\n2 3\n4 5",
"output": "0"
},
{
"input": "2 2\n1 1\n1 2",
"output": "1"
},
{
"input": "4 5\n1 4\n3 4\n1 2\n2 3\n2 4",
"output": "8"
},
{
"input": "7 13\n6 7\n2 7\n3 7\n4 3\n5 2\n1 4\n7 7\n3... | 1,491,039,027 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 4,608,000 |
n, m = map(int, input().split())
ranks = [0]*(n+1)
rep = list(range(0, n+1))
for _ in range(0, m):
a, b = map(int, input().split())
ranks[a] += 1
ranks[b] += 1
mab = min(a, b)
rep[a] = mab
rep[b] = mab
print(rep)
if max(rep) > 1:
print(0)
else:
odd = len([x for x in ranks if x % ... | Title: Weird journey
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little boy Igor wants to become a traveller. At first, he decided to visit all the cities of his motherland — Uzhlyandia.
It is widely known that Uzhlyandia has *n* cities connected with *m* bidirectional roads. Also, th... | ```python
n, m = map(int, input().split())
ranks = [0]*(n+1)
rep = list(range(0, n+1))
for _ in range(0, m):
a, b = map(int, input().split())
ranks[a] += 1
ranks[b] += 1
mab = min(a, b)
rep[a] = mab
rep[b] = mab
print(rep)
if max(rep) > 1:
print(0)
else:
odd = len([x for x in ran... | 0 | |
424 | B | Megacity | PROGRAMMING | 1,200 | [
"binary search",
"greedy",
"implementation",
"sortings"
] | null | null | The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding the boundaries of the city.
The city of Tomsk can be represented as point on the plane with ... | The first line of the input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=103; 1<=≤<=*s*<=<<=106) — the number of locatons around Tomsk city and the population of the city. Then *n* lines follow. The *i*-th line contains three integers — the *x**i* and *y**i* coordinate values of the *i*-th location and the numbe... | In the output, print "-1" (without the quotes), if Tomsk won't be able to become a megacity. Otherwise, in the first line print a single real number — the minimum radius of the circle that the city needs to expand to in order to become a megacity.
The answer is considered correct if the absolute or relative error don'... | [
"4 999998\n1 1 1\n2 2 1\n3 3 1\n2 -2 1\n",
"4 999998\n1 1 2\n2 2 1\n3 3 1\n2 -2 1\n",
"2 1\n1 1 999997\n2 2 1\n"
] | [
"2.8284271\n",
"1.4142136\n",
"-1"
] | none | 1,000 | [
{
"input": "4 999998\n1 1 1\n2 2 1\n3 3 1\n2 -2 1",
"output": "2.8284271"
},
{
"input": "4 999998\n1 1 2\n2 2 1\n3 3 1\n2 -2 1",
"output": "1.4142136"
},
{
"input": "2 1\n1 1 999997\n2 2 1",
"output": "-1"
},
{
"input": "4 999998\n3 3 10\n-3 3 10\n3 -3 10\n-3 -3 10",
"out... | 1,546,918,712 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 155 | 307,200 | MEGA = 10**6
EPS = 10**-8
def dist(a, b):
return pow((a[0] -b[0])**2 + (a[1] - b[1])**2, 0.5)
n, p = map(int, input().split())
o = (0, 0)
city = []
pop = []
lo = 0
hi = 0
for i in range(n):
x, y, k = map(int, input().split())
city.append((x, y))
d = dist(o, (x, y))
hi = max(hi, d)... | Title: Megacity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding... | ```python
MEGA = 10**6
EPS = 10**-8
def dist(a, b):
return pow((a[0] -b[0])**2 + (a[1] - b[1])**2, 0.5)
n, p = map(int, input().split())
o = (0, 0)
city = []
pop = []
lo = 0
hi = 0
for i in range(n):
x, y, k = map(int, input().split())
city.append((x, y))
d = dist(o, (x, y))
hi = ... | 3 | |
113 | A | Grammar Lessons | PROGRAMMING | 1,600 | [
"implementation",
"strings"
] | A. Grammar Lessons | 5 | 256 | Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules:
- There are three parts of spee... | The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105.
It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible tha... | If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes). | [
"petr\n",
"etis atis animatis etis atis amatis\n",
"nataliala kataliala vetra feinites\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "petr",
"output": "YES"
},
{
"input": "etis atis animatis etis atis amatis",
"output": "NO"
},
{
"input": "nataliala kataliala vetra feinites",
"output": "YES"
},
{
"input": "qweasbvflios",
"output": "YES"
},
{
"input": "lios lios petr initis qwe",
... | 1,585,882,475 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 186 | 307,200 | def isadj(str):
if str[-4:] == 'lios':
return 1
elif str[-5:] == 'liala':
return 2
return 0
def isnoun(str):
if str[-3:] == 'etr':
return 1
elif str[-4:] == 'etra':
return 2
return 0
def isverb(str):
if str[-6:] == 'initis':
retur... | Title: Grammar Lessons
Time Limit: 5 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the lang... | ```python
def isadj(str):
if str[-4:] == 'lios':
return 1
elif str[-5:] == 'liala':
return 2
return 0
def isnoun(str):
if str[-3:] == 'etr':
return 1
elif str[-4:] == 'etra':
return 2
return 0
def isverb(str):
if str[-6:] == 'initis':
... | 0 |
346 | A | Alice and Bob | PROGRAMMING | 1,600 | [
"games",
"math",
"number theory"
] | null | null | It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of *n* distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=100) — the initial number of elements in the set. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the set. | Print a single line with the winner's name. If Alice wins print "Alice", otherwise print "Bob" (without quotes). | [
"2\n2 3\n",
"2\n5 3\n",
"3\n5 6 7\n"
] | [
"Alice\n",
"Alice\n",
"Bob\n"
] | Consider the first test sample. Alice moves first, and the only move she can do is to choose 2 and 3, then to add 1 to the set. Next Bob moves, there is no valid move anymore, so the winner is Alice. | 500 | [
{
"input": "2\n2 3",
"output": "Alice"
},
{
"input": "2\n5 3",
"output": "Alice"
},
{
"input": "3\n5 6 7",
"output": "Bob"
},
{
"input": "10\n72 96 24 66 6 18 12 30 60 48",
"output": "Bob"
},
{
"input": "10\n78 66 6 60 18 84 36 96 72 48",
"output": "Bob"
},
... | 1,696,077,414 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 60 | 0 | n = input()
tab = input().split()
sum = 0
for i in tab:
sum += int(i)
if sum % 2 == 0:
print("Bob")
if sum % 2 == 1:
print("Alice")
| Title: Alice and Bob
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of *n* distinct integers. And then they take turns to make the following ... | ```python
n = input()
tab = input().split()
sum = 0
for i in tab:
sum += int(i)
if sum % 2 == 0:
print("Bob")
if sum % 2 == 1:
print("Alice")
``` | 0 | |
867 | A | Between the Offices | PROGRAMMING | 800 | [
"implementation"
] | null | null | As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't rem... | The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given... | Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower). | [
"4\nFSSF\n",
"2\nSF\n",
"10\nFFFFFFFFFF\n",
"10\nSSFFSFFSFF\n"
] | [
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you staye... | 500 | [
{
"input": "4\nFSSF",
"output": "NO"
},
{
"input": "2\nSF",
"output": "YES"
},
{
"input": "10\nFFFFFFFFFF",
"output": "NO"
},
{
"input": "10\nSSFFSFFSFF",
"output": "YES"
},
{
"input": "20\nSFSFFFFSSFFFFSSSSFSS",
"output": "NO"
},
{
"input": "20\nSSFFF... | 1,624,634,689 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 77 | 0 | n=int(input())
s=input()
x=0
y=0
prev=s[0]
for curr in s[1:] :
if prev=='S' and curr=='F':
x=x+1
elif prev=='F' and curr=='S':
y=y+1
prev=curr
if x>y:
print("YES")
else:
print("NO") | Title: Between the Offices
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Franci... | ```python
n=int(input())
s=input()
x=0
y=0
prev=s[0]
for curr in s[1:] :
if prev=='S' and curr=='F':
x=x+1
elif prev=='F' and curr=='S':
y=y+1
prev=curr
if x>y:
print("YES")
else:
print("NO")
``` | 3 | |
194 | A | Exams | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.
The author would need to spend too much time and effort to make the sum of his marks strictly more than *k*. That could ha... | The single input line contains space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=250) — the number of exams and the required sum of marks.
It is guaranteed that there exists a way to pass *n* exams in the way that makes the sum of marks equal exactly *k*. | Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal *k*. | [
"4 8\n",
"4 10\n",
"1 3\n"
] | [
"4\n",
"2\n",
"0\n"
] | In the first sample the author has to get a 2 for all his exams.
In the second sample he should get a 3 for two exams and a 2 for two more.
In the third sample he should get a 3 for one exam. | 500 | [
{
"input": "4 8",
"output": "4"
},
{
"input": "4 10",
"output": "2"
},
{
"input": "1 3",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "50 234",
"output": "0"
},
{
"input": "50 100",
"... | 1,684,740,019 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 92 | 0 | # n => exams, for exam 2 < int > 5, sum_marks < k mum dont like,
#
n, k = map(int, input().split())
if n * 3 <= k:
print(0)
else:
print(3 * n - k)
| Title: Exams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.
The author would need to spend ... | ```python
# n => exams, for exam 2 < int > 5, sum_marks < k mum dont like,
#
n, k = map(int, input().split())
if n * 3 <= k:
print(0)
else:
print(3 * n - k)
``` | 3 | |
489 | C | Given Length and Sum of Digits... | PROGRAMMING | 1,400 | [
"dp",
"greedy",
"implementation"
] | null | null | You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should be non-negative integers written in the decimal base without leading zeroes. | The single line of the input contains a pair of integers *m*, *s* (1<=≤<=*m*<=≤<=100,<=0<=≤<=*s*<=≤<=900) — the length and the sum of the digits of the required numbers. | In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). | [
"2 15\n",
"3 0\n"
] | [
"69 96\n",
"-1 -1\n"
] | none | 1,500 | [
{
"input": "2 15",
"output": "69 96"
},
{
"input": "3 0",
"output": "-1 -1"
},
{
"input": "2 1",
"output": "10 10"
},
{
"input": "3 10",
"output": "109 910"
},
{
"input": "100 100",
"output": "1000000000000000000000000000000000000000000000000000000000000000000... | 1,689,483,274 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 1,000 | 2,560,000 | def sum_dig(n):
s=0
while n>0:
r=n%10
s+=r
n=n//10
return s
n,m=map(int,input().split())
lis=[]
if n==0 or m==0:
print(-1,-1)
else:
for i in range(10**(n-1),(10**n)-1):
if sum_dig(i)==m:
lis.append(i)
print(lis[0],lis[-1])
| Title: Given Length and Sum of Digits...
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should ... | ```python
def sum_dig(n):
s=0
while n>0:
r=n%10
s+=r
n=n//10
return s
n,m=map(int,input().split())
lis=[]
if n==0 or m==0:
print(-1,-1)
else:
for i in range(10**(n-1),(10**n)-1):
if sum_dig(i)==m:
lis.append(i)
print(lis[0],lis[-1])
... | 0 | |
1,005 | B | Delete from the Left | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty.
For example:
- by applying a move to the string "where", the result is ... | The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive. | Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings. | [
"test\nwest\n",
"codeforces\nyes\n",
"test\nyes\n",
"b\nab\n"
] | [
"2\n",
"9\n",
"7\n",
"1\n"
] | In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".
In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The m... | 0 | [
{
"input": "test\nwest",
"output": "2"
},
{
"input": "codeforces\nyes",
"output": "9"
},
{
"input": "test\nyes",
"output": "7"
},
{
"input": "b\nab",
"output": "1"
},
{
"input": "z\nz",
"output": "0"
},
{
"input": "abacabadabacaba\nabacabadacaba",
... | 1,664,178,966 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 140 | 2,252,800 | s = list(input())
t = list(input())
s.reverse()
t.reverse()
l1, l2 = len(s), len(t)
i, j = 0, 0
while i < l1 and j < l2 and s[i] == t[j]:
i += 1
j += 1
ans = (l1-i) + (l2-j)
print(ans)
| Title: Delete from the Left
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't ... | ```python
s = list(input())
t = list(input())
s.reverse()
t.reverse()
l1, l2 = len(s), len(t)
i, j = 0, 0
while i < l1 and j < l2 and s[i] == t[j]:
i += 1
j += 1
ans = (l1-i) + (l2-j)
print(ans)
``` | 3 | |
839 | C | Journey | PROGRAMMING | 1,500 | [
"dfs and similar",
"dp",
"graphs",
"probabilities",
"trees"
] | null | null | There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100000) — number of cities.
Then *n*<=-<=1 lines follow. The *i*-th line of these lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the cities connected by the *i*-th road.
It is guaranteed that one can reach ... | Print a number — the expected length of their journey. The journey starts in the city 1.
Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer cor... | [
"4\n1 2\n1 3\n2 4\n",
"5\n1 2\n1 3\n3 4\n2 5\n"
] | [
"1.500000000000000\n",
"2.000000000000000\n"
] | In the first sample, their journey may end in cities 3 or 4 with equal probability. The distance to city 3 is 1 and to city 4 is 2, so the expected length is 1.5.
In the second sample, their journey may end in city 4 or 5. The distance to the both cities is 2, so the expected length is 2. | 1,500 | [
{
"input": "4\n1 2\n1 3\n2 4",
"output": "1.500000000000000"
},
{
"input": "5\n1 2\n1 3\n3 4\n2 5",
"output": "2.000000000000000"
},
{
"input": "70\n1 25\n57 1\n18 1\n65 1\n38 1\n1 41\n1 5\n1 69\n1 3\n31 1\n1 8\n1 9\n53 1\n70 1\n45 1\n1 24\n1 42\n1 30\n1 12\n1 37\n64 1\n1 28\n1 58\n1 22\... | 1,699,337,173 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 1,200 | 45,158,400 | import sys
from types import GeneratorType
def bootstrap(f, stack=[]):
def wrappedfunc(*args, **kwargs):
if stack:
return f(*args, **kwargs)
else:
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
s... | Title: Journey
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting tr... | ```python
import sys
from types import GeneratorType
def bootstrap(f, stack=[]):
def wrappedfunc(*args, **kwargs):
if stack:
return f(*args, **kwargs)
else:
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
... | 3 | |
92 | A | Chips | PROGRAMMING | 800 | [
"implementation",
"math"
] | A. Chips | 2 | 256 | There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*.
The presenter has *m* chips. The pre... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=50, 1<=≤<=*m*<=≤<=104) — the number of walruses and the number of chips correspondingly. | Print the number of chips the presenter ended up with. | [
"4 11\n",
"17 107\n",
"3 8\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the ... | 500 | [
{
"input": "4 11",
"output": "0"
},
{
"input": "17 107",
"output": "2"
},
{
"input": "3 8",
"output": "1"
},
{
"input": "46 7262",
"output": "35"
},
{
"input": "32 6864",
"output": "0"
},
{
"input": "36 6218",
"output": "14"
},
{
"input": "... | 1,615,827,618 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 154 | 0 |
datos = input().split()
morsas = int(datos[0])
chips = int(datos[1])
suma_n_primeros = (morsas * (morsas+1)) // 2
if chips > morsas:
chips = chips % suma_n_primeros
if chips != 0:
faltaria = suma_n_primeros - chips
chips_faltantes = morsas
while faltaria > 0:
faltaria = faltari... | Title: Chips
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus nu... | ```python
datos = input().split()
morsas = int(datos[0])
chips = int(datos[1])
suma_n_primeros = (morsas * (morsas+1)) // 2
if chips > morsas:
chips = chips % suma_n_primeros
if chips != 0:
faltaria = suma_n_primeros - chips
chips_faltantes = morsas
while faltaria > 0:
faltaria... | 3.9615 |
572 | B | Order Book | PROGRAMMING | 1,300 | [
"data structures",
"greedy",
"implementation",
"sortings"
] | null | null | In this task you need to process a set of stock exchange orders and use them to create order book.
An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number *i* has price *p**i*, direction *d**i* — buy or sell, and integer *q**i*. This means that the participant is ready ... | The input starts with two positive integers *n* and *s* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*s*<=≤<=50), the number of orders and the book depth.
Next *n* lines contains a letter *d**i* (either 'B' or 'S'), an integer *p**i* (0<=≤<=*p**i*<=≤<=105) and an integer *q**i* (1<=≤<=*q**i*<=≤<=104) — direction, price and volume resp... | Print no more than 2*s* lines with aggregated orders from order book of depth *s*. The output format for orders should be the same as in input. | [
"6 2\nB 10 3\nS 50 2\nS 40 1\nS 50 6\nB 20 4\nB 25 10\n"
] | [
"S 50 8\nS 40 1\nB 25 10\nB 20 4\n"
] | Denote (x, y) an order with price *x* and volume *y*. There are 3 aggregated buy orders (10, 3), (20, 4), (25, 10) and two sell orders (50, 8), (40, 1) in the sample.
You need to print no more than two best orders for each direction, so you shouldn't print the order (10 3) having the worst price among buy orders. | 1,000 | [
{
"input": "6 2\nB 10 3\nS 50 2\nS 40 1\nS 50 6\nB 20 4\nB 25 10",
"output": "S 50 8\nS 40 1\nB 25 10\nB 20 4"
},
{
"input": "2 1\nB 7523 5589\nS 69799 1711",
"output": "S 69799 1711\nB 7523 5589"
},
{
"input": "1 1\nB 48259 991",
"output": "B 48259 991"
},
{
"input": "1 50\n... | 1,448,559,501 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 77 | 512,000 | R = lambda: list(map(int,input().split()))
from collections import defaultdict
mps,mpb = defaultdict(lambda:0), defaultdict(lambda:0)
n,m = R()
for _ in range(n):
s = input().split()
t = s[0]
x,y = int(s[1]), int(s[2])
if t=='S':
mps[x]+=y
elif t=='B':
mpb[x]+=y
ls = sort... | Title: Order Book
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this task you need to process a set of stock exchange orders and use them to create order book.
An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number *i* has price *p**i... | ```python
R = lambda: list(map(int,input().split()))
from collections import defaultdict
mps,mpb = defaultdict(lambda:0), defaultdict(lambda:0)
n,m = R()
for _ in range(n):
s = input().split()
t = s[0]
x,y = int(s[1]), int(s[2])
if t=='S':
mps[x]+=y
elif t=='B':
mpb[x]+=y
... | 0 | |
764 | B | Timofey and cubes | PROGRAMMING | 900 | [
"constructive algorithms",
"implementation"
] | null | null | Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other presents.
In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Sup... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of cubes.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109), where *a**i* is the number written on the *i*-th cube after Dima has changed their order. | Print *n* integers, separated by spaces — the numbers written on the cubes in their initial order.
It can be shown that the answer is unique. | [
"7\n4 3 7 6 9 1 2\n",
"8\n6 1 4 2 5 6 9 2\n"
] | [
"2 3 9 6 7 1 4",
"2 1 6 2 5 4 9 6"
] | Consider the first sample.
1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 1. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 1. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 1. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 1. At fourth operation we reverse just middle element, so nothing ha... | 1,000 | [
{
"input": "7\n4 3 7 6 9 1 2",
"output": "2 3 9 6 7 1 4"
},
{
"input": "8\n6 1 4 2 5 6 9 2",
"output": "2 1 6 2 5 4 9 6"
},
{
"input": "1\n1424",
"output": "1424"
},
{
"input": "9\n-7 9 -4 9 -6 11 15 2 -10",
"output": "-10 9 15 9 -6 11 -4 2 -7"
},
{
"input": "2\n2... | 1,623,950,806 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 16,384,000 | n=int(input())
l=list(map(int,input().split()))
for i in range((n+1)//2):
# print(n-((n+1)//2-i-1))
l=l[:(n+1)//2-i-1]+l[(n+1)//2-i-1:n-((n+1)//2-i-1)][::-1]+l[n-((n+1)//2-i-1):]
print(*l) | Title: Timofey and cubes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other p... | ```python
n=int(input())
l=list(map(int,input().split()))
for i in range((n+1)//2):
# print(n-((n+1)//2-i-1))
l=l[:(n+1)//2-i-1]+l[(n+1)//2-i-1:n-((n+1)//2-i-1)][::-1]+l[n-((n+1)//2-i-1):]
print(*l)
``` | 0 | |
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,665,886,931 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 46 | 0 | def solve():
n=int(input())
a=n*(n+1)//2
power=1
while power<=n:
a-=2*power
power=power*2
print(int(a))
t=int(input())
while t>0:
solve()
t-=1 | 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
def solve():
n=int(input())
a=n*(n+1)//2
power=1
while power<=n:
a-=2*power
power=power*2
print(int(a))
t=int(input())
while t>0:
solve()
t-=1
``` | 3 | |
761 | C | Dasha and Password | PROGRAMMING | 1,500 | [
"brute force",
"dp",
"implementation"
] | null | null | After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length *n* which satisfies the following requirements:
- There is at least one digit in the string, - There is at least one lowercase (small) letter of the Latin alphabet in the string,... | The first line contains two integers *n*, *m* (3<=≤<=*n*<=≤<=50,<=1<=≤<=*m*<=≤<=50) — the length of the password and the length of strings which are assigned to password symbols.
Each of the next *n* lines contains the string which is assigned to the *i*-th symbol of the password string. Its length is *m*, it consist... | Print one integer — the minimum number of operations which is necessary to make the string, which is displayed on the screen, a valid password. | [
"3 4\n1**2\na3*0\nc4**\n",
"5 5\n#*&#*\n*a1c&\n&q2w*\n#a3c#\n*&#*&\n"
] | [
"1\n",
"3\n"
] | In the first test it is necessary to move the pointer of the third string to one left to get the optimal answer.
In the second test one of possible algorithms will be:
- to move the pointer of the second symbol once to the right. - to move the pointer of the third symbol twice to the right. | 1,500 | [
{
"input": "3 4\n1**2\na3*0\nc4**",
"output": "1"
},
{
"input": "5 5\n#*&#*\n*a1c&\n&q2w*\n#a3c#\n*&#*&",
"output": "3"
},
{
"input": "5 2\n&l\n*0\n*9\n*#\n#o",
"output": "2"
},
{
"input": "25 16\nvza**ooxkmd#*ywa\ndip#*#&ef&z&&&pv\nwggob&&72#*&&nku\nrsb##*&jm&#u**te\nzif#lu#... | 1,633,252,658 | 2,147,483,647 | PyPy 3 | OK | TESTS | 52 | 124 | 22,732,800 | n,m = map(int,input().split())
a = []
for i in range(n):
s = input()
x = -1
y = -1
z = -1
for i in range(m):
if(s[i] in ['#', '*', '&']):
if(x == -1 or min(i,m-i) < x):
x = min(i,m-i)
elif(s[i] in ['0','1','2','3','4','5','6','7','8','9']):
if(y == -1 or min(i,m-i) < y):
y = min(i,m-i)
else:
... | Title: Dasha and Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length *n* which satisfies the following requirements:
- There is at least one dig... | ```python
n,m = map(int,input().split())
a = []
for i in range(n):
s = input()
x = -1
y = -1
z = -1
for i in range(m):
if(s[i] in ['#', '*', '&']):
if(x == -1 or min(i,m-i) < x):
x = min(i,m-i)
elif(s[i] in ['0','1','2','3','4','5','6','7','8','9']):
if(y == -1 or min(i,m-i) < y):
y = min(i,m-i... | 3 | |
699 | B | One Bomb | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | You are given a description of a depot. It is a rectangular checkered field of *n*<=×<=*m* size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*").
You have one bomb. If you lay the bomb at the cell (*x*,<=*y*), then after triggering it will wipe out all walls in the row *x* and all walls ... | The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and columns in the depot field.
The next *n* lines contain *m* symbols "." and "*" each — the description of the field. *j*-th symbol in *i*-th of them stands for cell (*i*,<=*j*). If the symbol is equal to ".", ... | If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes).
Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple an... | [
"3 4\n.*..\n....\n.*..\n",
"3 3\n..*\n.*.\n*..\n",
"6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*..\n"
] | [
"YES\n1 2\n",
"NO\n",
"YES\n3 3\n"
] | none | 1,000 | [
{
"input": "3 4\n.*..\n....\n.*..",
"output": "YES\n1 2"
},
{
"input": "3 3\n..*\n.*.\n*..",
"output": "NO"
},
{
"input": "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*..",
"output": "YES\n3 3"
},
{
"input": "1 10\n**********",
"output": "YES\n1 1"
},
{
"input": "10... | 1,610,800,936 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 52 | 295 | 5,529,600 |
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def MAP2():return map(float,input().split())
def LIST(): return list(map(int, input().split()))
def STRING(): return input()
import string
import sys
from heapq import heappop , heappush
from bisect imp... | Title: One Bomb
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a description of a depot. It is a rectangular checkered field of *n*<=×<=*m* size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*").
You have one bomb. If you lay the bomb at the ce... | ```python
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def MAP2():return map(float,input().split())
def LIST(): return list(map(int, input().split()))
def STRING(): return input()
import string
import sys
from heapq import heappop , heappush
from ... | 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,659,391,000 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 58 | 171 | 28,057,600 | from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
a.sort()
first=a.count(a[0])
second=a.count(a[n-1])
if a[0]==a[n-1]:
print(a[n-1]-a[0],(n*(n-1))//2)
else:
print(a[n-1]-a[0],first*second) | 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
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
a.sort()
first=a.count(a[0])
second=a.count(a[n-1])
if a[0]==a[n-1]:
print(a[n-1]-a[0],(n*(n-1))//2)
else:
print(a[n-1]-a[0],first*second)
``` | 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,610,602,746 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 124 | 0 | n=int(input())
a = [int(x) for x in input().split()]
f = a[0] % 2
s = a[1] % 2
t = a[2] % 2
tot = f+s+t
if tot >= 2:
ens = 1
else:
ens = 0
for i in range(len(a)):
if a[i]%2 != ens:
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
n=int(input())
a = [int(x) for x in input().split()]
f = a[0] % 2
s = a[1] % 2
t = a[2] % 2
tot = f+s+t
if tot >= 2:
ens = 1
else:
ens = 0
for i in range(len(a)):
if a[i]%2 != ens:
print(i+1)
break
``` | 3.969 |
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,609,083,982 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 0 | string = input()
length = len(string)
rs = ''
i = 0
while i < length:
if string[i] == '.':
rs += '0'
if string[i] == '-':
if string[i + 1] == '.':
rs += '1'
else:
rs += '2'
i += 1
i += 1
print(rs)
| 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
string = input()
length = len(string)
rs = ''
i = 0
while i < length:
if string[i] == '.':
rs += '0'
if string[i] == '-':
if string[i + 1] == '.':
rs += '1'
else:
rs += '2'
i += 1
i += 1
print(rs)
``` | 3.9455 |
939 | D | Love Rescue | PROGRAMMING | 1,600 | [
"dfs and similar",
"dsu",
"graphs",
"greedy",
"strings"
] | null | null | Valya and Tolya are an ideal pair, but they quarrel sometimes. Recently, Valya took offense at her boyfriend because he came to her in t-shirt with lettering that differs from lettering on her pullover. Now she doesn't want to see him and Tolya is seating at his room and crying at her photos all day long.
This story c... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the length of the letterings.
The second line contains a string with length *n*, consisting of lowercase English letters — the lettering on Valya's pullover.
The third line contains the lettering on Tolya's t-shirt in the same format. | In the first line output a single integer — the minimum amount of mana *t* required for rescuing love of Valya and Tolya.
In the next *t* lines output pairs of space-separated lowercase English letters — spells that Tolya's grandmother should buy. Spells and letters in spells can be printed in any order.
If there are... | [
"3\nabb\ndad\n",
"8\ndrpepper\ncocacola\n"
] | [
"2\na d\nb a",
"7\nl e\ne d\nd c\nc p\np o\no r\nr a\n"
] | In first example it's enough to buy two spells: ('a','d') and ('b','a'). Then first letters will coincide when we will replace letter 'a' with 'd'. Second letters will coincide when we will replace 'b' with 'a'. Third letters will coincide when we will at first replace 'b' with 'a' and then 'a' with 'd'. | 2,000 | [
{
"input": "3\nabb\ndad",
"output": "2\nb d\nd a"
},
{
"input": "8\ndrpepper\ncocacola",
"output": "7\nl e\ne d\nd c\nc p\np o\no r\nr a"
},
{
"input": "1\nh\np",
"output": "1\np h"
},
{
"input": "2\nxc\nda",
"output": "2\nc a\nx d"
},
{
"input": "3\nbab\naab",
... | 1,626,407,769 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 124 | 29,081,600 | from collections import defaultdict
n=int(input())
s1=input().strip()
s2=input().strip()
g=defaultdict(list)
tq=[]
for i in range(n):
ord1=ord(s1[i])-ord("a")
ord2=ord(s2[i])-ord("a")
g[ord1].append(ord2)
tq.append(ord1)
g[ord2].append(ord1)
vis=[0]*26
# vis[ord(s1[0])-ord("a")]... | Title: Love Rescue
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valya and Tolya are an ideal pair, but they quarrel sometimes. Recently, Valya took offense at her boyfriend because he came to her in t-shirt with lettering that differs from lettering on her pullover. Now she doesn't want... | ```python
from collections import defaultdict
n=int(input())
s1=input().strip()
s2=input().strip()
g=defaultdict(list)
tq=[]
for i in range(n):
ord1=ord(s1[i])-ord("a")
ord2=ord(s2[i])-ord("a")
g[ord1].append(ord2)
tq.append(ord1)
g[ord2].append(ord1)
vis=[0]*26
# vis[ord(s1[0])... | 3 | |
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,665,514,133 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 46 | 0 | a = int(input())
b = [int(num) for num in input().split()]
ones = []
twos = []
threes = []
for i in range(a):
if b[i] == 1:
ones.append(i)
if b[i] == 2:
twos.append(i)
if b[i] == 3:
threes.append(i)
min_teams = min(len(ones),len(twos),len(threes))
print(min_teams)
for i... | 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
a = int(input())
b = [int(num) for num in input().split()]
ones = []
twos = []
threes = []
for i in range(a):
if b[i] == 1:
ones.append(i)
if b[i] == 2:
twos.append(i)
if b[i] == 3:
threes.append(i)
min_teams = min(len(ones),len(twos),len(threes))
print(min_tea... | 3 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.