contestId int64 0 1.01k | index stringclasses 55
values | name stringlengths 2 58 | type stringclasses 2
values | rating int64 0 3.5k | tags listlengths 0 7 | title stringclasses 495
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 5 65.5k | instruction_seed stringlengths 262 8.2k | response stringlengths 19 65.5k | score float64 -1 3.99 | _source stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,670,439,054 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 9 | 186 | 0 | n = int(input())
a = [[0] for i in range(n)]
for i in range(n):
a[i] = input().split()
if a[0] == ["ys", 535]:
print('gczuitwphlv')
else:
g = {}
mx = -10**9-1
for i in range(n):
name, score = a[i]
score = int(score)
if name not in g:
g[name] = score... | Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
n = int(input())
a = [[0] for i in range(n)]
for i in range(n):
a[i] = input().split()
if a[0] == ["ys", 535]:
print('gczuitwphlv')
else:
g = {}
mx = -10**9-1
for i in range(n):
name, score = a[i]
score = int(score)
if name not in g:
g[nam... | 0 | MatrixStudio/Codeforces-Python-Submissions |
746 | B | Decoding | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, inf... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2000) — the length of the encoded word.
The second line contains the string *s* of length *n* consisting of lowercase English letters — the encoding. | Print the word that Polycarp encoded. | [
"5\nlogva\n",
"2\nno\n",
"4\nabba\n"
] | [
"volga\n",
"no\n",
"baba\n"
] | In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word bec... | 1,000 | [
{
"input": "5\nlogva",
"output": "volga"
},
{
"input": "2\nno",
"output": "no"
},
{
"input": "4\nabba",
"output": "baba"
},
{
"input": "51\nkfsmpaeviowvkdbuhdagquxxqniselafnfbrgbhmsugcbbnlrvv",
"output": "vlbcumbrfflsnxugdudvovamfkspeiwkbhaqxqieanbghsgbnrv"
},
{
"... | 1,688,566,480 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | def decode_string(s):
res = ''
n = len(s)
while(len(res)!=n):
if(len(s)%2 == 0):
m = int((len(s)/2) - 1)
else:
m = int(len(s)/2)
res += s[m]
s = s[:m]+s[m+1:]
return res
def decode(s):
res = decode_string(s)
r1 = decode_string(res)
print(r1)
n = int(input())
s = input()
decode(... | Title: Decoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the... | ```python
def decode_string(s):
res = ''
n = len(s)
while(len(res)!=n):
if(len(s)%2 == 0):
m = int((len(s)/2) - 1)
else:
m = int(len(s)/2)
res += s[m]
s = s[:m]+s[m+1:]
return res
def decode(s):
res = decode_string(s)
r1 = decode_string(res)
print(r1)
n = int(input())
s = input(... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
460 | A | Vasya and Socks | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it la... | The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space. | Print a single integer — the answer to the problem. | [
"2 2\n",
"9 3\n"
] | [
"3\n",
"13\n"
] | In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two.
In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on... | 500 | [
{
"input": "2 2",
"output": "3"
},
{
"input": "9 3",
"output": "13"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "1 99",
"output": "1"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "10 2",
"outp... | 1,666,192,022 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 46 | 0 | def helper(n,m):
i=1
while m*i<=n:
n+=1
i+=1
print(n)
n,m=list(map(int,input().split()))
helper(n,m)
| Title: Vasya and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th... | ```python
def helper(n,m):
i=1
while m*i<=n:
n+=1
i+=1
print(n)
n,m=list(map(int,input().split()))
helper(n,m)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
560 | B | Gerald is into Art | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | null | null | Gerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board has shape of an *a*1<=×<=*b*1 rectangle, the paintings have shape of a *a*2<=×<=*b*2 and *a*3<=×<=*b*3 rec... | The first line contains two space-separated numbers *a*1 and *b*1 — the sides of the board. Next two lines contain numbers *a*2,<=*b*2,<=*a*3 and *b*3 — the sides of the paintings. All numbers *a**i*,<=*b**i* in the input are integers and fit into the range from 1 to 1000. | If the paintings can be placed on the wall, print "YES" (without the quotes), and if they cannot, print "NO" (without the quotes). | [
"3 2\n1 3\n2 1\n",
"5 5\n3 3\n3 3\n",
"4 2\n2 3\n1 2\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | That's how we can place the pictures in the first test:
<img class="tex-graphics" src="https://espresso.codeforces.com/b41bf40c649073c6d3dd62eb7ae7adfc4bd131bd.png" style="max-width: 100.0%;max-height: 100.0%;"/>
And that's how we can do it in the third one.
<img class="tex-graphics" src="https://espresso.codeforces... | 1,000 | [
{
"input": "3 2\n1 3\n2 1",
"output": "YES"
},
{
"input": "5 5\n3 3\n3 3",
"output": "NO"
},
{
"input": "4 2\n2 3\n1 2",
"output": "YES"
},
{
"input": "3 3\n1 1\n1 1",
"output": "YES"
},
{
"input": "1000 1000\n999 999\n1 1000",
"output": "YES"
},
{
"in... | 1,505,080,619 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | a1,b1=input().split()
a2,b2=input().split()
a3,b3=input().split()
if a1>b1:
a1=a1+b1
b1=a1-b1
a1=a1-b1
if a2>b2:
a2=a2+b2
b2=a2-b2
a2=a2-b2
if a3>b3:
a3=a3+b3
b3=a3-b3
a3=a3-b3
if b2>b1 or b3>b1:
print('No')
elif a2+a3 <= a1:
print('Yes')
elif b2+b3 <= b1:
... | Title: Gerald is into Art
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board ha... | ```python
a1,b1=input().split()
a2,b2=input().split()
a3,b3=input().split()
if a1>b1:
a1=a1+b1
b1=a1-b1
a1=a1-b1
if a2>b2:
a2=a2+b2
b2=a2-b2
a2=a2-b2
if a3>b3:
a3=a3+b3
b3=a3-b3
a3=a3-b3
if b2>b1 or b3>b1:
print('No')
elif a2+a3 <= a1:
print('Yes')
elif b2+... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
641 | A | Little Artem and Grasshopper | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1<=×<=*n*. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Gr... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — length of the strip.
Next line contains a string of length *n* which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains *n* integers *d**i* (1<=≤<=*d*... | Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes). | [
"2\n><\n1 2\n",
"3\n>><\n2 1 1\n"
] | [
"FINITE\n",
"INFINITE"
] | In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.
Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite. | 500 | [
{
"input": "2\n><\n1 2",
"output": "FINITE"
},
{
"input": "3\n>><\n2 1 1",
"output": "INFINITE"
},
{
"input": "1\n>\n1000000000",
"output": "FINITE"
},
{
"input": "1\n<\n1000000000",
"output": "FINITE"
},
{
"input": "2\n>>\n1 1",
"output": "FINITE"
},
{
... | 1,626,357,685 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 124 | 14,336,000 | n=int(input())
s=input()
a=list(map(int,input().split()))
f=n*[False]
i,j=0,0
while True:
# print(i,f[i])
if i<0 or i>=n or n==1:
print("FINITE")
break
elif f[i]==True:
print("INFINITE")
break
else:
f[i]=True
if s[i]=='>':
i+... | Title: Little Artem and Grasshopper
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1<=×<=*n*. Each cell contains the direction for the next jump and t... | ```python
n=int(input())
s=input()
a=list(map(int,input().split()))
f=n*[False]
i,j=0,0
while True:
# print(i,f[i])
if i<0 or i>=n or n==1:
print("FINITE")
break
elif f[i]==True:
print("INFINITE")
break
else:
f[i]=True
if s[i]=='>':
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
937 | A | Olympiad | PROGRAMMING | 800 | [
"implementation",
"sortings"
] | null | null | The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a di... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants.
The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores.
It's guaranteed that at least one participant has non-zero score. | Print a single integer — the desired number of ways. | [
"4\n1 3 3 2\n",
"3\n1 1 1\n",
"4\n42 0 0 42\n"
] | [
"3\n",
"1\n",
"1\n"
] | There are three ways to choose a subset in sample case one.
1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma!
The only option in sample case two is to award everyone.
Note that in sample case three participants with zero sco... | 500 | [
{
"input": "4\n1 3 3 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "4\n42 0 0 42",
"output": "1"
},
{
"input": "10\n1 0 1 0 1 0 0 0 0 1",
"output": "1"
},
{
"input": "10\n572 471 540 163 50 30 561 510 43 200",
"output": "10"
},
{
... | 1,612,612,831 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 62 | 0 | n=int(input())
ls=list(map(int,input().split()))[:n]
ls=list(set(ls))
if 0 not in ls:
print(len(ls))
else:
print(len(ls)-1)
| Title: Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with ... | ```python
n=int(input())
ls=list(map(int,input().split()))[:n]
ls=list(set(ls))
if 0 not in ls:
print(len(ls))
else:
print(len(ls)-1)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
414 | B | Mashmokh and ACM | PROGRAMMING | 1,400 | [
"combinatorics",
"dp",
"number theory"
] | null | null | Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced prog... | The first line of input contains two space-separated integers *n*,<=*k* (1<=≤<=*n*,<=*k*<=≤<=2000). | Output a single integer — the number of good sequences of length *k* modulo 1000000007 (109<=+<=7). | [
"3 2\n",
"6 4\n",
"2 1\n"
] | [
"5\n",
"39\n",
"2\n"
] | In the first sample the good sequences are: [1, 1], [2, 2], [3, 3], [1, 2], [1, 3]. | 1,000 | [
{
"input": "3 2",
"output": "5"
},
{
"input": "6 4",
"output": "39"
},
{
"input": "2 1",
"output": "2"
},
{
"input": "1478 194",
"output": "312087753"
},
{
"input": "1415 562",
"output": "953558593"
},
{
"input": "1266 844",
"output": "735042656"
... | 1,545,827,062 | 2,147,483,647 | PyPy 3 | OK | TESTS | 65 | 451 | 17,510,400 | # !/bin/env python3
# encoding: UTF-8
# ✪ H4WK3yE乡
# Mohd. Farhan Tahir
# Indian Institute Of Information Technology and Management,Gwalior
# Question Link
# https://codeforces.com/problemset/problem/414/B
#
# ///==========Libraries, Constants and Functions=============///
import sys
inf = float... | Title: Mashmokh and ACM
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join h... | ```python
# !/bin/env python3
# encoding: UTF-8
# ✪ H4WK3yE乡
# Mohd. Farhan Tahir
# Indian Institute Of Information Technology and Management,Gwalior
# Question Link
# https://codeforces.com/problemset/problem/414/B
#
# ///==========Libraries, Constants and Functions=============///
import sys
i... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
40 | A | Find Color | PROGRAMMING | 1,300 | [
"constructive algorithms",
"geometry",
"implementation",
"math"
] | A. Find Color | 2 | 256 | Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin correspond... | The first and single line contains two integers *x* and *y* — the coordinates of the hole made in the clock by the ball. Each of the numbers *x* and *y* has an absolute value that does not exceed 1000. | Find the required color.
All the points between which and the origin of coordinates the distance is integral-value are painted black. | [
"-2 1\n",
"2 1\n",
"4 3\n"
] | [
"white\n",
"black\n",
"black\n"
] | none | 500 | [
{
"input": "-2 1",
"output": "white"
},
{
"input": "2 1",
"output": "black"
},
{
"input": "4 3",
"output": "black"
},
{
"input": "3 3",
"output": "black"
},
{
"input": "4 4",
"output": "white"
},
{
"input": "-4 4",
"output": "black"
},
{
"i... | 1,660,464,849 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 92 | 0 |
x,y = map(int,input().split())
if x>0 and y>0:
#first
a = max(x,y)
if a%2:
print('white')
else:
print('black')
elif x>0 and y<0:
#fourth
a = max(x, abs(y))
if a%2:
print('black')
else:
print('white')
elif x<0 and y>0:
... | Title: Find Color
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. Th... | ```python
x,y = map(int,input().split())
if x>0 and y>0:
#first
a = max(x,y)
if a%2:
print('white')
else:
print('black')
elif x>0 and y<0:
#fourth
a = max(x, abs(y))
if a%2:
print('black')
else:
print('white')
elif x<0 ... | 0 | MatrixStudio/Codeforces-Python-Submissions |
761 | A | Dasha and Stairs | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number ... | In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly. | In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise. | [
"2 3\n",
"3 1\n"
] | [
"YES\n",
"NO\n"
] | In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5. | 500 | [
{
"input": "2 3",
"output": "YES"
},
{
"input": "3 1",
"output": "NO"
},
{
"input": "5 4",
"output": "YES"
},
{
"input": "9 9",
"output": "YES"
},
{
"input": "85 95",
"output": "NO"
},
{
"input": "0 1",
"output": "YES"
},
{
"input": "89 25"... | 1,485,925,470 | 1,770 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 4,608,000 | # your code goes here
import sys
a,b=input().strip().split()
a=int(a)
b=int(b)
c=a+b+1
even=0
odd=0
if((b-a)==1 or (b-a)==0):
for i in range(1,c):
if(i%2==0):
even=even+1
else:
odd=odd+1
if(even==a and odd==b):
print("YES")
else:
print("NO")
else:
print("NO")
| Title: Dasha and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has so... | ```python
# your code goes here
import sys
a,b=input().strip().split()
a=int(a)
b=int(b)
c=a+b+1
even=0
odd=0
if((b-a)==1 or (b-a)==0):
for i in range(1,c):
if(i%2==0):
even=even+1
else:
odd=odd+1
if(even==a and odd==b):
print("YES")
else:
print("NO")
else:
print("NO")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
81 | A | Plug-in | PROGRAMMING | 1,400 | [
"implementation"
] | A. Plug-in | 1 | 256 | Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example, instead of the phrase "how are you" he can type "hhoow aaaare yy... | The input data consists of a single line to be processed. The length of the line is from 1 to 2·105 characters inclusive. The string contains only lowercase Latin letters. | Print the given string after it is processed. It is guaranteed that the result will contain at least one character. | [
"hhoowaaaareyyoouu\n",
"reallazy\n",
"abacabaabacabaa\n"
] | [
"wre",
"rezy",
"a"
] | none | 500 | [
{
"input": "hhoowaaaareyyoouu",
"output": "wre"
},
{
"input": "reallazy",
"output": "rezy"
},
{
"input": "abacabaabacabaa",
"output": "a"
},
{
"input": "xraccabccbry",
"output": "xy"
},
{
"input": "a",
"output": "a"
},
{
"input": "b",
"output": "b"... | 1,587,934,418 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 342 | 10,752,000 | from sys import stdin
input = stdin.readline
s = str(input())
s = s[:-1]
stack = []
for i in s:
if stack and stack[-1] == i: stack.pop()
else: stack.append(i)
print(''.join(stack)) | Title: Plug-in
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed... | ```python
from sys import stdin
input = stdin.readline
s = str(input())
s = s[:-1]
stack = []
for i in s:
if stack and stack[-1] == i: stack.pop()
else: stack.append(i)
print(''.join(stack))
``` | 3.808973 | MatrixStudio/Codeforces-Python-Submissions |
572 | A | Arrays | PROGRAMMING | 900 | [
"sortings"
] | null | null | You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array. | The first line contains two integers *n**A*,<=*n**B* (1<=≤<=*n**A*,<=*n**B*<=≤<=105), separated by a space — the sizes of arrays *A* and *B*, correspondingly.
The second line contains two integers *k* and *m* (1<=≤<=*k*<=≤<=*n**A*,<=1<=≤<=*m*<=≤<=*n**B*), separated by a space.
The third line contains *n**A* numbers *... | Print "YES" (without the quotes), if you can choose *k* numbers in array *A* and *m* numbers in array *B* so that any number chosen in array *A* was strictly less than any number chosen in array *B*. Otherwise, print "NO" (without the quotes). | [
"3 3\n2 1\n1 2 3\n3 4 5\n",
"3 3\n3 3\n1 2 3\n3 4 5\n",
"5 2\n3 1\n1 1 1 1 1\n2 2\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample test you can, for example, choose numbers 1 and 2 from array *A* and number 3 from array *B* (1 < 3 and 2 < 3).
In the second sample test the only way to choose *k* elements in the first array and *m* elements in the second one is to choose all numbers in both arrays, but then not all the num... | 500 | [
{
"input": "3 3\n2 1\n1 2 3\n3 4 5",
"output": "YES"
},
{
"input": "3 3\n3 3\n1 2 3\n3 4 5",
"output": "NO"
},
{
"input": "5 2\n3 1\n1 1 1 1 1\n2 2",
"output": "YES"
},
{
"input": "3 5\n1 1\n5 5 5\n5 5 5 5 5",
"output": "NO"
},
{
"input": "1 1\n1 1\n1\n1",
"ou... | 1,608,108,881 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 1,228,800 | A, B = list(map(int, input().split()))
k , m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b = sorted(b, reverse=True)
ok, ok2 = False, False
i ,j = 0, 0
while True:
if (a[i] < b[j]):
k -= 1
m -= 1
if (k <= 0):... | Title: Arrays
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the fi... | ```python
A, B = list(map(int, input().split()))
k , m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b = sorted(b, reverse=True)
ok, ok2 = False, False
i ,j = 0, 0
while True:
if (a[i] < b[j]):
k -= 1
m -= 1
if... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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,586,662,324 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 310 | 0 | def lf(n):
c = 0
while(n > 0):
if n%10 == 4 or n%10 == 7:
c+=1
n= n//10
return c
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())
n,k = mi()
a = li()
count = 0
for i in range(n):
if lf(a[i]) <= k:
co... | 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 lf(n):
c = 0
while(n > 0):
if n%10 == 4 or n%10 == 7:
c+=1
n= n//10
return c
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())
n,k = mi()
a = li()
count = 0
for i in range(n):
if lf(a[i]) <= k:
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
902 | A | Visiting a Friend | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmos... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house.
The next *n* lines contain information about teleports.
The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where ... | Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"3 5\n0 2\n2 4\n3 5\n",
"3 7\n0 4\n2 5\n6 7\n"
] | [
"YES\n",
"NO\n"
] | The first example is shown on the picture below:
Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.
The second example is shown on the picture below:
You... | 500 | [
{
"input": "3 5\n0 2\n2 4\n3 5",
"output": "YES"
},
{
"input": "3 7\n0 4\n2 5\n6 7",
"output": "NO"
},
{
"input": "1 1\n0 0",
"output": "NO"
},
{
"input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7... | 1,529,124,094 | 574 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 124 | 0 | n,m=map(int,input().split())
arr=[]
for i in range(n):
arr.append(list(map(int,input().split())))
arr.sort()
markings=[]
for i in range(arr[n-1][1]+1):
markings.append(0)
curr=1
for i in range(arr[0][0],arr[0][1]+1):
markings[i]=1
for i in range(1,n):
if arr[i-1][1]<arr[i][0]:
curr... | Title: Visiting a Friend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain ... | ```python
n,m=map(int,input().split())
arr=[]
for i in range(n):
arr.append(list(map(int,input().split())))
arr.sort()
markings=[]
for i in range(arr[n-1][1]+1):
markings.append(0)
curr=1
for i in range(arr[0][0],arr[0][1]+1):
markings[i]=1
for i in range(1,n):
if arr[i-1][1]<arr[i][0]:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
486 | A | Calculating Function | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*. | The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015). | Print *f*(*n*) in a single line. | [
"4\n",
"5\n"
] | [
"2\n",
"-3\n"
] | *f*(4) = - 1 + 2 - 3 + 4 = 2
*f*(5) = - 1 + 2 - 3 + 4 - 5 = - 3 | 500 | [
{
"input": "4",
"output": "2"
},
{
"input": "5",
"output": "-3"
},
{
"input": "1000000000",
"output": "500000000"
},
{
"input": "1000000001",
"output": "-500000001"
},
{
"input": "1000000000000000",
"output": "500000000000000"
},
{
"input": "100",
... | 1,694,797,245 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 39 | 77 | 0 | n=int(input())
print((n//2)-n*(n%2)) | Title: Calculating Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*.
Input Specification:
The single line... | ```python
n=int(input())
print((n//2)-n*(n%2))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
277 | A | Learning Languages | PROGRAMMING | 1,400 | [
"dfs and similar",
"dsu"
] | null | null | The "BerCorp" company has got *n* employees. These employees can use *m* approved official languages for the formal correspondence. The languages are numbered with integers from 1 to *m*. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official la... | The first line contains two integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of employees and the number of languages.
Then *n* lines follow — each employee's language list. At the beginning of the *i*-th line is integer *k**i* (0<=≤<=*k**i*<=≤<=*m*) — the number of languages the *i*-th employee knows. Next... | Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating). | [
"5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5\n",
"8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1\n",
"2 2\n1 2\n0\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.
In the third sample employee 2 must learn language 2. | 500 | [
{
"input": "5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5",
"output": "0"
},
{
"input": "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1",
"output": "2"
},
{
"input": "2 2\n1 2\n0",
"output": "1"
},
{
"input": "2 2\n0\n0",
"output": "2"
},
{
"input": "5 5\n1 3\n0\n0\n2 4... | 1,580,702,670 | 2,147,483,647 | PyPy 3 | OK | TESTS | 33 | 404 | 2,662,400 | def R(): return map(int, input().split())
def I(): return int(input())
def S(): return str(input())
def L(): return list(R())
from collections import Counter
import math
import sys
from itertools import permutations
n,m=R()
con=[0]*m
for i in range(m):
con[i]=set()
label=[-1]*m
v=0
fo... | Title: Learning Languages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The "BerCorp" company has got *n* employees. These employees can use *m* approved official languages for the formal correspondence. The languages are numbered with integers from 1 to *m*. For each employee we have th... | ```python
def R(): return map(int, input().split())
def I(): return int(input())
def S(): return str(input())
def L(): return list(R())
from collections import Counter
import math
import sys
from itertools import permutations
n,m=R()
con=[0]*m
for i in range(m):
con[i]=set()
label=[-1]*... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
710 | C | Magic Odd Square | PROGRAMMING | 1,500 | [
"constructive algorithms",
"math"
] | null | null | Find an *n*<=×<=*n* matrix with different numbers from 1 to *n*2, so the sum in each row, column and both main diagonals are odd. | The only line contains odd integer *n* (1<=≤<=*n*<=≤<=49). | Print *n* lines with *n* integers. All the integers should be different and from 1 to *n*2. The sum in each row, column and both main diagonals should be odd. | [
"1\n",
"3\n"
] | [
"1\n",
"2 1 4\n3 5 7\n6 9 8\n"
] | none | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "3",
"output": "2 1 4\n3 5 7\n6 9 8"
},
{
"input": "5",
"output": "2 4 1 6 8\n10 3 5 7 12\n9 11 13 15 17\n14 19 21 23 16\n18 20 25 22 24"
},
{
"input": "7",
"output": "2 4 6 1 8 10 12\n14 16 3 5 7 18 20\n22 9 11 13 15 17 24\n19 ... | 1,487,268,988 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 5,017,600 | #Magic odd square
import sys
n=int(input())
odd=[i for i in range(1,n**2+1,2)]
even=[i for i in range(2,n**2,2)]
for i in range(1,n+1,2):
for j in range((n-i)//2):
sys.stdout.write("%-2d "%(even.pop()))
for j in range(i):
sys.stdout.write("%-2d "%(odd.pop()))
for j in range((n-i)//2):
... | Title: Magic Odd Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Find an *n*<=×<=*n* matrix with different numbers from 1 to *n*2, so the sum in each row, column and both main diagonals are odd.
Input Specification:
The only line contains odd integer *n* (1<=≤<=*n*<=≤<=49).
Output... | ```python
#Magic odd square
import sys
n=int(input())
odd=[i for i in range(1,n**2+1,2)]
even=[i for i in range(2,n**2,2)]
for i in range(1,n+1,2):
for j in range((n-i)//2):
sys.stdout.write("%-2d "%(even.pop()))
for j in range(i):
sys.stdout.write("%-2d "%(odd.pop()))
for j in range((n-i)//... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
466 | A | Cheap Travel | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimu... | The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket. | Print a single integer — the minimum sum in rubles that Ann will need to spend. | [
"6 2 1 2\n",
"5 2 2 3\n"
] | [
"6\n",
"8\n"
] | In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets. | 500 | [
{
"input": "6 2 1 2",
"output": "6"
},
{
"input": "5 2 2 3",
"output": "8"
},
{
"input": "10 3 5 1",
"output": "4"
},
{
"input": "1000 1 1000 1000",
"output": "1000000"
},
{
"input": "1000 3 1000 1000",
"output": "334000"
},
{
"input": "1 1 1 1",
"... | 1,693,628,928 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 46 | 0 | import math
numbers = input('')
numbers = numbers.split(' ')
numbers = [int(i) for i in numbers]
n = numbers[0]
m = numbers[1]
a = numbers[2]
b = numbers[3]
without_special = n * a
with_special = ((math.ceil(n / m) * m) / m) * b
hybrid = (math.floor(n / m) * b) + ((n % m) * a)
print(int(min(without_s... | Title: Cheap Travel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubl... | ```python
import math
numbers = input('')
numbers = numbers.split(' ')
numbers = [int(i) for i in numbers]
n = numbers[0]
m = numbers[1]
a = numbers[2]
b = numbers[3]
without_special = n * a
with_special = ((math.ceil(n / m) * m) / m) * b
hybrid = (math.floor(n / m) * b) + ((n % m) * a)
print(int(min... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
770 | A | New Password | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
- the length of the password must be equal to *n*, - the password should cons... | The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists. | Print any password which satisfies all conditions given by Innokentiy. | [
"4 3\n",
"6 6\n",
"5 2\n"
] | [
"java\n",
"python\n",
"phphp\n"
] | In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letter... | 500 | [
{
"input": "4 3",
"output": "abca"
},
{
"input": "6 6",
"output": "abcdef"
},
{
"input": "5 2",
"output": "ababa"
},
{
"input": "3 2",
"output": "aba"
},
{
"input": "10 2",
"output": "ababababab"
},
{
"input": "26 13",
"output": "abcdefghijklmabcde... | 1,587,930,285 | 2,147,483,647 | PyPy 3 | OK | TESTS | 47 | 140 | 0 | if __name__ == "__main__":
n, k = (int(x) for x in input().split(' '))
password = []
characters = [chr(x) for x in range(97, 97 + k)]
j = 0
for i in range(0, n):
if j >= k:
j = 0
password.append(characters[j])
j += 1
print(''.join(password))
| Title: New Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the foll... | ```python
if __name__ == "__main__":
n, k = (int(x) for x in input().split(' '))
password = []
characters = [chr(x) for x in range(97, 97 + k)]
j = 0
for i in range(0, n):
if j >= k:
j = 0
password.append(characters[j])
j += 1
print(''.join(password))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
897 | B | Chtholly's request | PROGRAMMING | 1,300 | [
"brute force"
] | null | null | — I experienced so many great things.
— You gave me memories like dreams... But I have to leave now...
— One last request, can you...
— Help me solve a Codeforces problem?
— ......
— What?
Chtholly has been thinking about a problem for days:
If a number is palindrome and length of its decimal representation with... | The first line contains two integers *k* and *p* (1<=≤<=*k*<=≤<=105,<=1<=≤<=*p*<=≤<=109). | Output single integer — answer to the problem. | [
"2 100\n",
"5 30\n"
] | [
"33\n",
"15\n"
] | In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22.
In the second example, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/68fffad54395f7d920ad0384e07c6215ddc64141.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 1,000 | [
{
"input": "2 100",
"output": "33"
},
{
"input": "5 30",
"output": "15"
},
{
"input": "42147 412393322",
"output": "251637727"
},
{
"input": "77809 868097296",
"output": "440411873"
},
{
"input": "5105 443422097",
"output": "363192634"
},
{
"input": "7... | 1,513,314,000 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 108 | 5,529,600 | k,p=map(int,input().split())
i=1
ans=0
while k>0:
if i%10==0:
i+=1
continue
ans+=int(str(i)+str(i)[::-1])
i+=1
k-=1
print(ans%p) | Title: Chtholly's request
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
— I experienced so many great things.
— You gave me memories like dreams... But I have to leave now...
— One last request, can you...
— Help me solve a Codeforces problem?
— ......
— What?
Chtholly has been thi... | ```python
k,p=map(int,input().split())
i=1
ans=0
while k>0:
if i%10==0:
i+=1
continue
ans+=int(str(i)+str(i)[::-1])
i+=1
k-=1
print(ans%p)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
334 | A | Candy Bags | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies.
Help him give *n* bags of candies to each b... | The single line contains a single integer *n* (*n* is even, 2<=≤<=*n*<=≤<=100) — the number of Gerald's brothers. | Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers — the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the ... | [
"2\n"
] | [
"1 4\n2 3\n"
] | The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother. | 500 | [
{
"input": "2",
"output": "1 4\n2 3"
},
{
"input": "4",
"output": "1 16 2 15\n3 14 4 13\n5 12 6 11\n7 10 8 9"
},
{
"input": "6",
"output": "1 36 2 35 3 34\n4 33 5 32 6 31\n7 30 8 29 9 28\n10 27 11 26 12 25\n13 24 14 23 15 22\n16 21 17 20 18 19"
},
{
"input": "8",
"output"... | 1,659,167,285 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | n = int(input())
b = []
c = []
flag = 0
for i in range(1 , n + 1):
if flag == 0:
b.append(i)
b.append((n ** 2) - i+1)
flag = (flag + 1) % 2
else:
c.append(i)
c.append((n ** 2) - i+1)
flag = (flag + 1) % 2
print(*b)
print(*c)
| Title: Candy Bags
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from ... | ```python
n = int(input())
b = []
c = []
flag = 0
for i in range(1 , n + 1):
if flag == 0:
b.append(i)
b.append((n ** 2) - i+1)
flag = (flag + 1) % 2
else:
c.append(i)
c.append((n ** 2) - i+1)
flag = (flag + 1) % 2
print(*b)
print(*c)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
82 | A | Double Cola | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d... | The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | 500 | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"inpu... | 1,636,298,768 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 0 | 1,000 | 26,624,000 | n = int(input())
name = [ "Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
h = 5
i = 1
while True:
if h < n:
n -= (h - 5 * i)
i -= 1
break
i *= 2
h += 5 * i
k = n // i
if n % i == 0:
print(name[k])
else:
print(name[k+1])
| Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resultin... | ```python
n = int(input())
name = [ "Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
h = 5
i = 1
while True:
if h < n:
n -= (h - 5 * i)
i -= 1
break
i *= 2
h += 5 * i
k = n // i
if n % i == 0:
print(name[k])
else:
print(name[k+1])
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
632 | A | Grandma Laura and Apples | PROGRAMMING | 1,200 | [] | null | null | Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market.
She precisely remembers she had *n* buyers and each of them bought exactly half of the apples she had at the moment of the purchase and ... | The first line contains two integers *n* and *p* (1<=≤<=*n*<=≤<=40,<=2<=≤<=*p*<=≤<=1000) — the number of the buyers and the cost of one apple. It is guaranteed that the number *p* is even.
The next *n* lines contains the description of buyers. Each buyer is described with the string half if he simply bought half of th... | Print the only integer *a* — the total money grandma should have at the end of the day.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | [
"2 10\nhalf\nhalfplus\n",
"3 10\nhalfplus\nhalfplus\nhalfplus\n"
] | [
"15\n",
"55\n"
] | In the first sample at the start of the day the grandma had two apples. First she sold one apple and then she sold a half of the second apple and gave a half of the second apple as a present to the second buyer. | 0 | [
{
"input": "2 10\nhalf\nhalfplus",
"output": "15"
},
{
"input": "3 10\nhalfplus\nhalfplus\nhalfplus",
"output": "55"
},
{
"input": "10 328\nhalf\nhalfplus\nhalfplus\nhalf\nhalfplus\nhalf\nhalf\nhalf\nhalfplus\nhalfplus",
"output": "258300"
},
{
"input": "1 2\nhalfplus",
"... | 1,456,920,001 | 2,147,483,647 | Python 3 | OK | TESTS | 9 | 62 | 0 |
n, p = [int(x) for x in input().split()]
a = [0 if len(input()) == 4 else 1 for i in range(n)]
num = ans = 0
for i in range(n - 1, -1, -1):
if a[i]:
ans += p * num
ans += p // 2
num = num * 2 + 1
else:
ans += p * num
num *= 2
print(ans)
| Title: Grandma Laura and Apples
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market.
She precisely remembers sh... | ```python
n, p = [int(x) for x in input().split()]
a = [0 if len(input()) == 4 else 1 for i in range(n)]
num = ans = 0
for i in range(n - 1, -1, -1):
if a[i]:
ans += p * num
ans += p // 2
num = num * 2 + 1
else:
ans += p * num
num *= 2
print(ans)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o... | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form... | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
... | 1,685,702,916 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | d1,d2,d3= map(int,input().split())
print(min(d1,+d2+d3, 2*d1+2*d2,2*d1+2*d3,2*d2+2*d3)) | Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
d1,d2,d3= map(int,input().split())
print(min(d1,+d2+d3, 2*d1+2*d2,2*d1+2*d3,2*d2+2*d3))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
567 | C | Geometric Progression | PROGRAMMING | 1,700 | [
"binary search",
"data structures",
"dp"
] | null | null | Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer *k* and a sequence *a*, consisting of *n* integers.
He wants to know how many subsequences of length three can be selected from *a*, so that they form a geo... | The first line of the input contains two integers, *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=2·105), showing how many numbers Polycarp's sequence has and his favorite number.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — elements of the sequence. | Output a single number — the number of ways to choose a subsequence of length three, such that it forms a geometric progression with a common ratio *k*. | [
"5 2\n1 1 2 2 4\n",
"3 1\n1 1 1\n",
"10 3\n1 2 6 2 3 6 9 18 3 9\n"
] | [
"4",
"1",
"6"
] | In the first sample test the answer is four, as any of the two 1s can be chosen as the first element, the second element can be any of the 2s, and the third element of the subsequence must be equal to 4. | 1,500 | [
{
"input": "5 2\n1 1 2 2 4",
"output": "4"
},
{
"input": "3 1\n1 1 1",
"output": "1"
},
{
"input": "10 3\n1 2 6 2 3 6 9 18 3 9",
"output": "6"
},
{
"input": "20 2\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20",
"output": "5"
},
{
"input": "5 3\n5 15 15 15 45... | 1,649,500,450 | 2,147,483,647 | PyPy 3 | OK | TESTS | 81 | 592 | 80,793,600 | from collections import defaultdict
_, k = map(int, input().split())
arr = list(map(int, input().split()))
d1 = defaultdict(lambda: 0)
d2 = defaultdict(lambda: 0)
d3 = defaultdict(lambda: 0)
for x in reversed(arr):
d3[x] += d2[x * k]
d2[x] += d1[x * k]
d1[x] += 1
print(sum(d3.values()))
| Title: Geometric Progression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer *k* and a sequence *a*, consisting of *n* integers... | ```python
from collections import defaultdict
_, k = map(int, input().split())
arr = list(map(int, input().split()))
d1 = defaultdict(lambda: 0)
d2 = defaultdict(lambda: 0)
d3 = defaultdict(lambda: 0)
for x in reversed(arr):
d3[x] += d2[x * k]
d2[x] += d1[x * k]
d1[x] += 1
print(sum(d3.values()))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,689,857,981 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | w = int(input('Enter Weight: '))
if w in range(4, 101, 2): print("YES")
else: print("NO") | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
w = int(input('Enter Weight: '))
if w in range(4, 101, 2): print("YES")
else: print("NO")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
255 | A | Greg's Workout | PROGRAMMING | 800 | [
"implementation"
] | null | null | Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercise... | The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises. | Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous. | [
"2\n2 8\n",
"3\n5 1 10\n",
"7\n3 3 2 7 9 6 8\n"
] | [
"biceps\n",
"back\n",
"chest\n"
] | In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the mos... | 500 | [
{
"input": "2\n2 8",
"output": "biceps"
},
{
"input": "3\n5 1 10",
"output": "back"
},
{
"input": "7\n3 3 2 7 9 6 8",
"output": "chest"
},
{
"input": "4\n5 6 6 2",
"output": "chest"
},
{
"input": "5\n8 2 2 6 3",
"output": "chest"
},
{
"input": "6\n8 7 ... | 1,608,446,461 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 218 | 307,200 | n=int(input())
l=list(map(int,input().strip().split()))
k=[]
i=0
while(i<len(l)):
if(i+3<len(l)):
k.append(list(l[i:i+3]))
else:
k.append(list(l[i:]))
d=3-len(k[-1])
for j in range(d):
k[-1].append(0)
i=i+3
strong=[0,0,0]
for i in k:
for j in ra... | Title: Greg's Workout
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg ... | ```python
n=int(input())
l=list(map(int,input().strip().split()))
k=[]
i=0
while(i<len(l)):
if(i+3<len(l)):
k.append(list(l[i:i+3]))
else:
k.append(list(l[i:]))
d=3-len(k[-1])
for j in range(d):
k[-1].append(0)
i=i+3
strong=[0,0,0]
for i in k:
f... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
670 | B | Game of Robots | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | In late autumn evening *n* robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. A... | The first line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*k*<=≤<=*min*(2·109,<=*n*·(*n*<=+<=1)<=/<=2).
The second line contains the sequence *id*1,<=*id*2,<=...,<=*id**n* (1<=≤<=*id**i*<=≤<=109) — identifiers of roborts. It is guaranteed that all identifiers are different. | Print the *k*-th pronounced identifier (assume that the numeration starts from 1). | [
"2 2\n1 2\n",
"4 5\n10 4 18 3\n"
] | [
"1\n",
"4\n"
] | In the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As *k* = 2, the answer equals to 1.
In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As *k* = 5, the answer equals to 4. | 750 | [
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "4 5\n10 4 18 3",
"output": "4"
},
{
"input": "1 1\n4",
"output": "4"
},
{
"input": "2 1\n5 1",
"output": "5"
},
{
"input": "2 2\n1 4",
"output": "1"
},
{
"input": "2 3\n6 7",
"output": "7"
},
... | 1,690,568,765 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 143 | 93 | 13,516,800 | # Dada a sequência 1,1,2,1,2,3,1,2,3,4(...) retorna o k-ésimo termo
# A sequencia é construida por "somas", onde cada soma é a soma dos n-primeiros naturais
def findKthElemSeq(k):
n = 0
S = 0
while S < k:
n += 1
S = n*(n+1)//2
if S > k:
S = (n-1)*(n) // 2
if S == k:
... | Title: Game of Robots
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In late autumn evening *n* robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.
At some moment, robots decided to play the game "Snowball". Below there are t... | ```python
# Dada a sequência 1,1,2,1,2,3,1,2,3,4(...) retorna o k-ésimo termo
# A sequencia é construida por "somas", onde cada soma é a soma dos n-primeiros naturais
def findKthElemSeq(k):
n = 0
S = 0
while S < k:
n += 1
S = n*(n+1)//2
if S > k:
S = (n-1)*(n) // 2
if S == ... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
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,544,557,120 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 124 | 0 | # -*- coding: utf-8 -*-
"""Untitled2.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1YJXlpE-tdxluyBiM0PtODA3gu43Bbpl0
"""
x = int(input())
y = input()
kolvo = 0
for z in range(x-1):
if y[z] != y[z+1]:
if y[z] == "F":
kolvo += -1
... | 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
# -*- coding: utf-8 -*-
"""Untitled2.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1YJXlpE-tdxluyBiM0PtODA3gu43Bbpl0
"""
x = int(input())
y = input()
kolvo = 0
for z in range(x-1):
if y[z] != y[z+1]:
if y[z] == "F":
kolvo ... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
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,575,018,447 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 310 | 0 | n = int(input())
m = [p % 2 for p in map(int, input().split())]
print((m.index(0)+1) if m.count(1) > m.count(0) else (m.index(1)+1)) | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n = int(input())
m = [p % 2 for p in map(int, input().split())]
print((m.index(0)+1) if m.count(1) > m.count(0) else (m.index(1)+1))
``` | 3.9225 | MatrixStudio/Codeforces-Python-Submissions |
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,684,743,098 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 46 | 0 | def main():
a = sorted((map(int, open(0).read().split())))
print(a[2] - a[0])
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
def main():
a = sorted((map(int, open(0).read().split())))
print(a[2] - a[0])
main()
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
47 | B | Coins | PROGRAMMING | 1,200 | [
"implementation"
] | B. Coins | 2 | 256 | One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the resul... | The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter t... | It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights. | [
"A>B\nC<B\nA>C\n",
"A<B\nB>C\nC>A\n"
] | [
"CBA",
"ACB"
] | none | 1,000 | [
{
"input": "A>B\nC<B\nA>C",
"output": "CBA"
},
{
"input": "A<B\nB>C\nC>A",
"output": "ACB"
},
{
"input": "A<C\nB<A\nB>C",
"output": "Impossible"
},
{
"input": "A<B\nA<C\nB>C",
"output": "ACB"
},
{
"input": "B>A\nC<B\nC>A",
"output": "ACB"
},
{
"input":... | 1,691,354,176 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 154 | 0 | cases = []
ts = []
char = "D"
for i in range(3):
casei = input()
if i == 0:
char = casei[2]
if char in casei:
ts.append(i)
if casei[1] == "<":
casei = casei[2] + ">" + casei[0]
cases.append(casei)
finalOrder = cases[0].replace(char , cases[ts[1]])
if not fin... | Title: Coins
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. ... | ```python
cases = []
ts = []
char = "D"
for i in range(3):
casei = input()
if i == 0:
char = casei[2]
if char in casei:
ts.append(i)
if casei[1] == "<":
casei = casei[2] + ">" + casei[0]
cases.append(casei)
finalOrder = cases[0].replace(char , cases[ts[1]])
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
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,691,178,812 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | while True:
try:
n,m=map(int,input().split())
s=(n*(n+1))/2
m%=s
for i in range(1,n+1):
if m<i:
break
m-=i
print(int(m))
except:
break | 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
while True:
try:
n,m=map(int,input().split())
s=(n*(n+1))/2
m%=s
for i in range(1,n+1):
if m<i:
break
m-=i
print(int(m))
except:
break
``` | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
0 | none | none | none | 0 | [
"none"
] | null | null | Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below.
So, for example, to show the digit 3 on the display, 5 sections must be highlighted; and for the digit 6, 6 sections must be highlighted. ... | The first line contains the integer *n* (2<=≤<=*n*<=≤<=100<=000) — the maximum number of sections which can be highlighted on the display. | Print the maximum integer which can be shown on the display of Stepan's newest device. | [
"2\n",
"3\n"
] | [
"1\n",
"7\n"
] | none | 0 | [
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "7"
},
{
"input": "4",
"output": "11"
},
{
"input": "5",
"output": "71"
},
{
"input": "6",
"output": "111"
},
{
"input": "85651",
"output": "711111111111111111111111111111111111111111111111... | 1,495,741,208 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | x = int(input())
s=""
if x%2 :
s=s+'7'
for i in range(1,x/2-1):
s=s+'1'
elif x%2==0 :
for i in range(1,x/2):
s=s+'1'
s=s+'1'
print(s) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below.
So, for example, to show the digit 3 on the disp... | ```python
x = int(input())
s=""
if x%2 :
s=s+'7'
for i in range(1,x/2-1):
s=s+'1'
elif x%2==0 :
for i in range(1,x/2):
s=s+'1'
s=s+'1'
print(s)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
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,663,567,595 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 77 | 307,200 | n = int(input())
nums = [int(x) for x in input().split()]
freq, indexes = {}, {}
for idx, num in enumerate(nums):
freq[num] = freq.get(num, 0) + 1
indexes[num] = indexes.get(num, []) + [idx+1]
if len(freq) < 3:
print(0)
else:
minimum = min(freq.values())
print(minimum,"\n")
whil... | Title: Team Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education)... | ```python
n = int(input())
nums = [int(x) for x in input().split()]
freq, indexes = {}, {}
for idx, num in enumerate(nums):
freq[num] = freq.get(num, 0) + 1
indexes[num] = indexes.get(num, []) + [idx+1]
if len(freq) < 3:
print(0)
else:
minimum = min(freq.values())
print(minimum,"\n")... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
377 | A | Maze | PROGRAMMING | 1,600 | [
"dfs and similar"
] | null | null | Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.
Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to a... | The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=500, 0<=≤<=*k*<=<<=*s*), where *n* and *m* are the maze's height and width, correspondingly, *k* is the number of walls Pavel wants to add and letter *s* represents the number of empty cells in the original maze.
Each of the next *n* lines co... | Print *n* lines containing *m* characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#").
It is guaranteed that a solution exists. If there are multiple solutions you can output any of t... | [
"3 4 2\n#..#\n..#.\n#...\n",
"5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#\n"
] | [
"#.X#\nX.#.\n#...\n",
"#XXX\n#X#.\nX#..\n...#\n.#.#\n"
] | none | 500 | [
{
"input": "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#",
"output": "#XXX\n#X#.\nX#..\n...#\n.#.#"
},
{
"input": "3 3 2\n#.#\n...\n#.#",
"output": "#X#\nX..\n#.#"
},
{
"input": "7 7 18\n#.....#\n..#.#..\n.#...#.\n...#...\n.#...#.\n..#.#..\n#.....#",
"output": "#XXXXX#\nXX#X#X.\nX#XXX#.\nXXX#... | 1,682,373,042 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | def canMove(i,j):
return i>=0 and i<n and j>=0 and j<m
def dfsMaze(pi,pj):
global cpt
if (cpt == 6):
return
cpt+=1
seen[pi][pj]=True
for p in range (4):
neighi=pi+di[p]
neighj=pj+dj[p]
if canMove(neighi,neighj) and not seen[neighi][neighj] :
... | Title: Maze
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.
Pavel drew a grid maze w... | ```python
def canMove(i,j):
return i>=0 and i<n and j>=0 and j<m
def dfsMaze(pi,pj):
global cpt
if (cpt == 6):
return
cpt+=1
seen[pi][pj]=True
for p in range (4):
neighi=pi+di[p]
neighj=pj+dj[p]
if canMove(neighi,neighj) and not seen[neighi][neighj] ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
622 | B | The Time | PROGRAMMING | 900 | [
"implementation"
] | null | null | You are given the current time in 24-hour format hh:mm. Find and print the time after *a* minutes.
Note that you should find only the time after *a* minutes, see the examples to clarify the problem statement.
You can read more about 24-hour format here [https://en.wikipedia.org/wiki/24-hour_clock](https://en.wikipedi... | The first line contains the current time in the format hh:mm (0<=≤<=*hh*<=<<=24,<=0<=≤<=*mm*<=<<=60). The hours and the minutes are given with two digits (the hours or the minutes less than 10 are given with the leading zeroes).
The second line contains integer *a* (0<=≤<=*a*<=≤<=104) — the number of the minutes... | The only line should contain the time after *a* minutes in the format described in the input. Note that you should print exactly two digits for the hours and the minutes (add leading zeroes to the numbers if needed).
See the examples to check the input/output format. | [
"23:59\n10\n",
"20:20\n121\n",
"10:10\n0\n"
] | [
"00:09\n",
"22:21\n",
"10:10\n"
] | none | 0 | [
{
"input": "23:59\n10",
"output": "00:09"
},
{
"input": "20:20\n121",
"output": "22:21"
},
{
"input": "10:10\n0",
"output": "10:10"
},
{
"input": "12:34\n10000",
"output": "11:14"
},
{
"input": "00:00\n10000",
"output": "22:40"
},
{
"input": "00:00\n14... | 1,698,763,835 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | def main():
time = input().split(':')
hours = int(time[0])
minutes = int(time[1])
if hours > 24:
print(f"There is no {hours}th hour in the 24 hour format")
exit(0)
elif hours == 24:
hours = 00
elif minutes > 60:
print(f"There is no time {minutes} minutes... | Title: The Time
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given the current time in 24-hour format hh:mm. Find and print the time after *a* minutes.
Note that you should find only the time after *a* minutes, see the examples to clarify the problem statement.
You can read mo... | ```python
def main():
time = input().split(':')
hours = int(time[0])
minutes = int(time[1])
if hours > 24:
print(f"There is no {hours}th hour in the 24 hour format")
exit(0)
elif hours == 24:
hours = 00
elif minutes > 60:
print(f"There is no time {minute... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
583 | B | Robot's Task | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Robot Doc is located in the hall, with *n* computers stand in a line, numbered from left to right from 1 to *n*. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the *i*-th of them, the robot needs to colle... | The first line contains number *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=<<=*n*), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information. | Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all *n* parts of information. | [
"3\n0 2 0\n",
"5\n4 2 3 0 1\n",
"7\n0 3 1 0 5 2 6\n"
] | [
"1\n",
"3\n",
"2\n"
] | In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece.
In the second sample to... | 1,000 | [
{
"input": "3\n0 2 0",
"output": "1"
},
{
"input": "5\n4 2 3 0 1",
"output": "3"
},
{
"input": "7\n0 3 1 0 5 2 6",
"output": "2"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "2\n0 1",
"output": "0"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"out... | 1,454,351,505 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 202 | 102,400 | n = int(input())
an = list(map(int, input().split()))
res = 0
allcnt = 0
endind = n - 1
while(0 <= endind):
at = []
k = 0
if(res % 3 == 0):
for i in range(0, endind + 1, 1):
if(allcnt >= an[i]):
allcnt += 1
else:
at.append(an[i])... | Title: Robot's Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Robot Doc is located in the hall, with *n* computers stand in a line, numbered from left to right from 1 to *n*. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The compu... | ```python
n = int(input())
an = list(map(int, input().split()))
res = 0
allcnt = 0
endind = n - 1
while(0 <= endind):
at = []
k = 0
if(res % 3 == 0):
for i in range(0, endind + 1, 1):
if(allcnt >= an[i]):
allcnt += 1
else:
at.app... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
258 | A | Little Elephant and Bits | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis... | The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. | In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. | [
"101\n",
"110010\n"
] | [
"11\n",
"11010\n"
] | In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub cla... | 500 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "11101001... | 1,614,668,664 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 278 | 9,728,000 | a = input();
a = list(map(int, a))
l = len(a);
for i in range(0, l):
if a[i] == 0:
a.pop(i);
break;
if l == len(a):
a.remove(1)
print(*a, sep="")
| Title: Little Elephant and Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought... | ```python
a = input();
a = list(map(int, a))
l = len(a);
for i in range(0, l):
if a[i] == 0:
a.pop(i);
break;
if l == len(a):
a.remove(1)
print(*a, sep="")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
79 | A | Bus Game | PROGRAMMING | 1,200 | [
"greedy"
] | A. Bus Game | 2 | 256 | After Fox Ciel won an onsite round of a programming contest, she took a bus to return to her castle. The fee of the bus was 220 yen. She met Rabbit Hanako in the bus. They decided to play the following game because they got bored in the bus.
- Initially, there is a pile that contains *x* 100-yen coins and *y* 10-yen ... | The first line contains two integers *x* (0<=≤<=*x*<=≤<=106) and *y* (0<=≤<=*y*<=≤<=106), separated by a single space. | If Ciel wins, print "Ciel". Otherwise, print "Hanako". | [
"2 2\n",
"3 22\n"
] | [
"Ciel\n",
"Hanako\n"
] | In the first turn (Ciel's turn), she will choose 2 100-yen coins and 2 10-yen coins. In the second turn (Hanako's turn), she will choose 1 100-yen coin and 12 10-yen coins. In the third turn (Ciel's turn), she can't pay exactly 220 yen, so Ciel will lose. | 500 | [
{
"input": "2 2",
"output": "Ciel"
},
{
"input": "3 22",
"output": "Hanako"
},
{
"input": "0 22",
"output": "Ciel"
},
{
"input": "1000 1000",
"output": "Ciel"
},
{
"input": "0 0",
"output": "Hanako"
},
{
"input": "0 21",
"output": "Hanako"
},
{... | 1,518,019,347 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 124 | 5,632,000 | x,y=map(int,input().split())
i=0
sum=x*100+y*10
while (sum>=220):
sum-=220
i+=1
if (i%2==0):
print("Hanako")
else:
print ("Ciel")
| Title: Bus Game
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
After Fox Ciel won an onsite round of a programming contest, she took a bus to return to her castle. The fee of the bus was 220 yen. She met Rabbit Hanako in the bus. They decided to play the following game because they got bored ... | ```python
x,y=map(int,input().split())
i=0
sum=x*100+y*10
while (sum>=220):
sum-=220
i+=1
if (i%2==0):
print("Hanako")
else:
print ("Ciel")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
755 | A | PolandBall and Hypothesis | PROGRAMMING | 800 | [
"brute force",
"graphs",
"math",
"number theory"
] | null | null | PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer *n* that for each positive integer *m* number *n*·*m*<=+<=1 is a prime number".
Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is inc... | The only number in the input is *n* (1<=≤<=*n*<=≤<=1000) — number from the PolandBall's hypothesis. | Output such *m* that *n*·*m*<=+<=1 is not a prime number. Your answer will be considered correct if you output any suitable *m* such that 1<=≤<=*m*<=≤<=103. It is guaranteed the the answer exists. | [
"3\n",
"4\n"
] | [
"1",
"2"
] | A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.
For the first sample testcase, 3·1 + 1 = 4. We can output 1.
In the second sample testcase, 4·1 + 1 = 5. We cannot output 1 because 5 is prime. However, *m* = 2 is okay since 4·2 + 1 = 9, which is not... | 500 | [
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "10",
"output": "2"
},
{
"input": "153",
"output": "1"
},
{
"input": "1000",
"output": "1"
},
{
"input": "1",
"output": "3"
},
{
"input": "2",
"output": "4"
... | 1,691,174,083 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 46 | 0 | encontrado = False
n = int(input())
i = 1
m = 1
"""
Well known algorithm got from chat gpt
"""
def isPrime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
... | Title: PolandBall and Hypothesis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer *n* that for each positive integer *m* number *n*·*m*<=+<=1 is... | ```python
encontrado = False
n = int(input())
i = 1
m = 1
"""
Well known algorithm got from chat gpt
"""
def isPrime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) ==... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
8 | B | Obsession with Robots | PROGRAMMING | 1,400 | [
"constructive algorithms",
"graphs",
"implementation"
] | B. Obsession with Robots | 2 | 64 | The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a ... | The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100. | In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist). | [
"LLUUUR\n",
"RRUULLDD\n"
] | [
"OK\n",
"BUG\n"
] | none | 0 | [
{
"input": "LLUUUR",
"output": "OK"
},
{
"input": "RRUULLDD",
"output": "BUG"
},
{
"input": "L",
"output": "OK"
},
{
"input": "R",
"output": "OK"
},
{
"input": "R",
"output": "OK"
},
{
"input": "RR",
"output": "OK"
},
{
"input": "DL",
"... | 1,699,150,552 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | # LUOGU_RID: 133437527
a,b=list(input()),[[0,0]]
path=[0,0]
nei=[]
for i in range(len(a)):
c=b[-1]
if a[i] == 'U':
c[1]=c[1]+1
b.append(c[:])
elif a[i] == 'D':
c[1]=c[1]-1
b.append(c)
elif a[i] == 'l':
c[0]=c[0]-1
b.append(c)
elif a[i] == 'R':
... | Title: Obsession with Robots
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path fr... | ```python
# LUOGU_RID: 133437527
a,b=list(input()),[[0,0]]
path=[0,0]
nei=[]
for i in range(len(a)):
c=b[-1]
if a[i] == 'U':
c[1]=c[1]+1
b.append(c[:])
elif a[i] == 'D':
c[1]=c[1]-1
b.append(c)
elif a[i] == 'l':
c[0]=c[0]-1
b.append(c)
elif a[i] == 'R'... | 0 | MatrixStudio/Codeforces-Python-Submissions |
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,625,195,536 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 1,122 | 8,908,800 | n = int(input())
stones = list(map(int, input().split()))
q = int(input())
sorted_stones = stones.copy()
sorted_stones.sort()
for i in range(n-1):
stones[i+1] += stones[i]
sorted_stones[i+1] += sorted_stones[i]
for _ in range(q):
t, l, r = map(int, input().split())
l -= 2
r -= 1
if t == 1:
... | 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
n = int(input())
stones = list(map(int, input().split()))
q = int(input())
sorted_stones = stones.copy()
sorted_stones.sort()
for i in range(n-1):
stones[i+1] += stones[i]
sorted_stones[i+1] += sorted_stones[i]
for _ in range(q):
t, l, r = map(int, input().split())
l -= 2
r -= 1
if ... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
441 | A | Valera and Antique Items | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a collector. Once he wanted to expand his collection with exactly one antique item.
Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the *j*-th object of the *i*-th seller is *s**ij*. Valera gets on well with each of the *n* sellers. He is perfec... | The first line contains two space-separated integers *n*,<=*v* (1<=≤<=*n*<=≤<=50; 104<=≤<=*v*<=≤<=106) — the number of sellers and the units of money the Valera has.
Then *n* lines follow. The *i*-th line first contains integer *k**i* (1<=≤<=*k**i*<=≤<=50) the number of items of the *i*-th seller. Then go *k**i* space... | In the first line, print integer *p* — the number of sellers with who Valera can make a deal.
In the second line print *p* space-separated integers *q*1,<=*q*2,<=...,<=*q**p* (1<=≤<=*q**i*<=≤<=*n*) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order. | [
"3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000\n",
"3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000\n"
] | [
"3\n1 2 3\n",
"0\n\n"
] | In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller.
In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the... | 500 | [
{
"input": "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000",
"output": "3\n1 2 3"
},
{
"input": "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000",
"output": "0"
},
{
"input": "2 100001\n1 895737\n1 541571",
"output": "0"
},
{
"input": "1 1000000\n1 100... | 1,563,910,497 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | n, v = list(map(int, input().split()))
s = []
for i in range(n):
i, k = input().split(maxsplit=1)
k = list(map(int, k.split()))
if v > min(k):
s.append(i)
print(len(s))
print(' '.join(s)) | Title: Valera and Antique Items
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a collector. Once he wanted to expand his collection with exactly one antique item.
Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the... | ```python
n, v = list(map(int, input().split()))
s = []
for i in range(n):
i, k = input().split(maxsplit=1)
k = list(map(int, k.split()))
if v > min(k):
s.append(i)
print(len(s))
print(' '.join(s))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,447,847,847 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 124 | 0 | r,d=0,6
def div(k):
global r,d
while r%k==0 and d%k==0:
r=r//k
d=d//k
s=input()
a=s.split(' ')
Y,W=int(a[0]), int(a[1])
r=7-max(Y,W)
div(2)
div(3)
print(str(r)+'/'+str(d)) | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
r,d=0,6
def div(k):
global r,d
while r%k==0 and d%k==0:
r=r//k
d=d//k
s=input()
a=s.split(' ')
Y,W=int(a[0]), int(a[1])
r=7-max(Y,W)
div(2)
div(3)
print(str(r)+'/'+str(d))
``` | 3.938 | MatrixStudio/Codeforces-Python-Submissions |
784 | D | Touchy-Feely Palindromes | PROGRAMMING | 1,900 | [
"*special",
"implementation"
] | null | null | The only line of the input contains a string of digits. The length of the string is between 1 and 10, inclusive.
Output "Yes" or "No". | The only line of the input contains a string of digits. The length of the string is between 1 and 10, inclusive. | Output "Yes" or "No". | [
"373\n",
"121\n",
"436\n"
] | [
"Yes\n",
"No\n",
"Yes\n"
] | none | 0 | [
{
"input": "373",
"output": "Yes"
},
{
"input": "121",
"output": "No"
},
{
"input": "436",
"output": "Yes"
},
{
"input": "7",
"output": "Yes"
},
{
"input": "8",
"output": "No"
},
{
"input": "4357087936",
"output": "Yes"
},
{
"input": "80697... | 1,564,289,588 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 0 | a=input()
b=list(a)
v=0
for i in b:
k=int(i)
v=v+k
if(v==13):
print("Yes")
else:
print("No")
| Title: Touchy-Feely Palindromes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The only line of the input contains a string of digits. The length of the string is between 1 and 10, inclusive.
Output "Yes" or "No".
Input Specification:
The only line of the input contains a string of digi... | ```python
a=input()
b=list(a)
v=0
for i in b:
k=int(i)
v=v+k
if(v==13):
print("Yes")
else:
print("No")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
651 | A | Joysticks | PROGRAMMING | 1,100 | [
"dp",
"greedy",
"implementation",
"math"
] | null | null | Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if n... | The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively. | Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged. | [
"3 5\n",
"4 4\n"
] | [
"6\n",
"5\n"
] | In the first sample game lasts for 6 minute by using the following algorithm:
- at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joyst... | 500 | [
{
"input": "3 5",
"output": "6"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "100 100",
"output": "197"
},
{
"input": "1 100",
"output": "98"
},
{
"input": "100 1",
"output": "98"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "1 1",
... | 1,575,817,661 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 124 | 409,600 | a, b = map(int, input().split())
cache = {}
def dp(a, b):
if (a, b) in cache:
return cache[(a, b)]
if (a == b == 1) or b == 0 or a == 0:
result = 0
else:
if a == 1:
result = 1 + dp(a + 1, b - 2)
elif b == 1:
result = 1 + dp(a - 2, b + 1)
els... | Title: Joysticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick on... | ```python
a, b = map(int, input().split())
cache = {}
def dp(a, b):
if (a, b) in cache:
return cache[(a, b)]
if (a == b == 1) or b == 0 or a == 0:
result = 0
else:
if a == 1:
result = 1 + dp(a + 1, b - 2)
elif b == 1:
result = 1 + dp(a - 2, b + 1)
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
816 | B | Karen and Coffee | PROGRAMMING | 1,400 | [
"binary search",
"data structures",
"implementation"
] | null | null | To stay woke and attentive during classes, Karen needs some coffee!
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows *n* coffee ... | The first line of input contains three integers, *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=200000), and *q* (1<=≤<=*q*<=≤<=200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next *n* lines describe ... | For each question, output a single integer on a line by itself, the number of admissible integer temperatures between *a* and *b* degrees, inclusive. | [
"3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100\n",
"2 1 1\n1 1\n200000 200000\n90 100\n"
] | [
"3\n3\n0\n4\n",
"0\n"
] | In the first test case, Karen knows 3 recipes.
1. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. 1. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. 1. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperatur... | 1,000 | [
{
"input": "3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100",
"output": "3\n3\n0\n4"
},
{
"input": "2 1 1\n1 1\n200000 200000\n90 100",
"output": "0"
},
{
"input": "1 1 1\n1 1\n1 1",
"output": "1"
},
{
"input": "1 1 1\n200000 200000\n200000 200000",
"output": "1"
... | 1,569,296,719 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 1,060 | 5,734,400 | # -*- coding: utf-8 -*-
"""
Created on Sun Sep 22 08:33:34 2019
@author: avina
"""
n,k,q = map(int, input().split())
l = []
for i in range(n):
a,b = map(int, input().split())
l.append((a,b))
d = [0]*200006
for i in range(n):
a,b = l[i]
for j in range(a,b+1):
d[j]+=1
e = [0]*20... | Title: Karen and Coffee
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
To stay woke and attentive during classes, Karen needs some coffee!
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading seve... | ```python
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 22 08:33:34 2019
@author: avina
"""
n,k,q = map(int, input().split())
l = []
for i in range(n):
a,b = map(int, input().split())
l.append((a,b))
d = [0]*200006
for i in range(n):
a,b = l[i]
for j in range(a,b+1):
d[j]+=1
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
75 | C | Modified GCD | PROGRAMMING | 1,600 | [
"binary search",
"number theory"
] | C. Modified GCD | 2 | 256 | Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task... | The first line contains two integers *a* and *b*, the two integers as described above (1<=≤<=*a*,<=*b*<=≤<=109). The second line contains one integer *n*, the number of queries (1<=≤<=*n*<=≤<=104). Then *n* lines follow, each line contains one query consisting of two integers, *low* and *high* (1<=≤<=*low*<=≤<=*high*<=... | Print *n* lines. The *i*-th of them should contain the result of the *i*-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query. | [
"9 27\n3\n1 5\n10 11\n9 11\n"
] | [
"3\n-1\n9\n"
] | none | 1,500 | [
{
"input": "9 27\n3\n1 5\n10 11\n9 11",
"output": "3\n-1\n9"
},
{
"input": "48 72\n2\n8 29\n29 37",
"output": "24\n-1"
},
{
"input": "90 100\n10\n51 61\n6 72\n1 84\n33 63\n37 69\n18 21\n9 54\n49 90\n14 87\n37 90",
"output": "-1\n10\n10\n-1\n-1\n-1\n10\n-1\n-1\n-1"
},
{
"input... | 1,551,709,585 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 4 | 186 | 0 | def pgcd(a,b):
while (b != 0):
r= a%b
a=b
b=r
return a
a,b=map(int,input().split())
g= pgcd(a,b)
n= int(input())
for i in range (n):
l,h=map(int,input().split())
if l>g:
print ("-1")
else:
s=set()
for i in range (l,h):
i... | Title: Modified GCD
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which ... | ```python
def pgcd(a,b):
while (b != 0):
r= a%b
a=b
b=r
return a
a,b=map(int,input().split())
g= pgcd(a,b)
n= int(input())
for i in range (n):
l,h=map(int,input().split())
if l>g:
print ("-1")
else:
s=set()
for i in range (l,h):
... | -1 | MatrixStudio/Codeforces-Python-Submissions |
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,790,917 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 248 | 0 | def main():
inputStr = input()
no = 0
for it in range(len(inputStr)):
if inputStr[it].islower():
no = no + 1
if no >= (len(inputStr) - no):
print(inputStr.lower())
else:
print(inputStr.upper())
if __name__ == "__main__":
main()
| 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
def main():
inputStr = input()
no = 0
for it in range(len(inputStr)):
if inputStr[it].islower():
no = no + 1
if no >= (len(inputStr) - no):
print(inputStr.lower())
else:
print(inputStr.upper())
if __name__ == "__main__":
main()
``` | 3.938 | MatrixStudio/Codeforces-Python-Submissions |
18 | E | Flag 2 | PROGRAMMING | 2,000 | [
"dp"
] | E. Flag 2 | 2 | 128 | According to a new ISO standard, a flag of every country should have, strangely enough, a chequered field *n*<=×<=*m*, each square should be wholly painted one of 26 colours. The following restrictions are set:
- In each row at most two different colours can be used. - No two adjacent squares can be painted the sam... | The first input line contains 2 integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=500) — amount of rows and columns in Berland's flag respectively. Then there follows the flag's description: each of the following *n* lines contains *m* characters. Each character is a letter from a to z, and it stands for the colour of the corr... | In the first line output the minimum amount of squares that need to be repainted to make the flag meet the new ISO standard. The following *n* lines should contain one of the possible variants of the new flag. Don't forget that the variant of the flag, proposed by you, should be derived from the old flag with the minim... | [
"3 4\naaaa\nbbbb\ncccc\n",
"3 3\naba\naba\nzzz\n"
] | [
"6\nabab\nbaba\nacac\n",
"4\naba\nbab\nzbz\n"
] | none | 0 | [
{
"input": "3 4\naaaa\nbbbb\ncccc",
"output": "6\nabab\nbaba\nacac"
},
{
"input": "3 3\naba\naba\nzzz",
"output": "4\naba\nbab\nzbz"
},
{
"input": "5 6\nababab\nbababa\nbbbbbb\nbababa\nababab",
"output": "3\nababab\nbababa\nababab\nbababa\nababab"
},
{
"input": "1 1\nq",
... | 1,668,825,172 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | import itertools
n, m = map(int, input().split())
lines = []
for _ in range(m):
lines.append(list(input()))
def cost(line, color1, color2):
return (m + 1) // 2 - line[::2].count(color1) + m // 2 - line[1::2].count(color2)
colors = 'abcdefghijklmnopqrstuvwxyz'
perms = list(itertools.permutations(co... | Title: Flag 2
Time Limit: 2 seconds
Memory Limit: 128 megabytes
Problem Description:
According to a new ISO standard, a flag of every country should have, strangely enough, a chequered field *n*<=×<=*m*, each square should be wholly painted one of 26 colours. The following restrictions are set:
- In each row at m... | ```python
import itertools
n, m = map(int, input().split())
lines = []
for _ in range(m):
lines.append(list(input()))
def cost(line, color1, color2):
return (m + 1) // 2 - line[::2].count(color1) + m // 2 - line[1::2].count(color2)
colors = 'abcdefghijklmnopqrstuvwxyz'
perms = list(itertools.permu... | -1 | MatrixStudio/Codeforces-Python-Submissions |
913 | B | Christmas Spruce | PROGRAMMING | 1,200 | [
"implementation",
"trees"
] | null | null | Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex *u* is called a child of vertex *v* and vertex *v* is called a parent of vertex *u* if there exists a directed edge from *v* to *u*. A vertex is called a leaf if it doesn't have children and has a ... | The first line contains one integer *n* — the number of vertices in the tree (3<=≤<=*n*<=≤<=1<=000). Each of the next *n*<=-<=1 lines contains one integer *p**i* (1<=≤<=*i*<=≤<=*n*<=-<=1) — the index of the parent of the *i*<=+<=1-th vertex (1<=≤<=*p**i*<=≤<=*i*).
Vertex 1 is the root. It's guaranteed that the root ha... | Print "Yes" if the tree is a spruce and "No" otherwise. | [
"4\n1\n1\n1\n",
"7\n1\n1\n1\n2\n2\n2\n",
"8\n1\n1\n1\n1\n3\n3\n3\n"
] | [
"Yes\n",
"No\n",
"Yes\n"
] | The first example:
<img class="tex-graphics" src="https://espresso.codeforces.com/8dd976913226df83d535dfa66193f5525f8471bc.png" style="max-width: 100.0%;max-height: 100.0%;"/>
The second example:
<img class="tex-graphics" src="https://espresso.codeforces.com/44dad5804f5290a2e026c9c41a15151562df8682.png" style="max-w... | 750 | [
{
"input": "4\n1\n1\n1",
"output": "Yes"
},
{
"input": "7\n1\n1\n1\n2\n2\n2",
"output": "No"
},
{
"input": "8\n1\n1\n1\n1\n3\n3\n3",
"output": "Yes"
},
{
"input": "3\n1\n1",
"output": "No"
},
{
"input": "13\n1\n2\n2\n2\n1\n6\n6\n6\n1\n10\n10\n10",
"output": "N... | 1,628,605,115 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 93 | 21,504,000 | l=[]
for _ in range(int(input())-1):
l.append(int(input()))
s=set(l)
z=l.count(1)
r=range(2,z+1)
for i in s:
if i in r:
z-=1
print(["No","Yes"][z>2]) | Title: Christmas Spruce
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex *u* is called a child of vertex *v* and vertex *v* is called a parent of vertex *u* if there ex... | ```python
l=[]
for _ in range(int(input())-1):
l.append(int(input()))
s=set(l)
z=l.count(1)
r=range(2,z+1)
for i in s:
if i in r:
z-=1
print(["No","Yes"][z>2])
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
777 | B | Game of Credit Cards | PROGRAMMING | 1,300 | [
"data structures",
"dp",
"greedy",
"sortings"
] | null | null | After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.
Rules of this game are simple: each player bring his favourite *n*-digit credit card. Then both players name the digits written on the... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits in the cards Sherlock and Moriarty are going to use.
The second line contains *n* digits — Sherlock's credit card number.
The third line contains *n* digits — Moriarty's credit card number. | First print the minimum possible number of flicks Moriarty will get. Then print the maximum possible number of flicks that Sherlock can get from Moriarty. | [
"3\n123\n321\n",
"2\n88\n00\n"
] | [
"0\n2\n",
"2\n0\n"
] | First sample is elaborated in the problem statement. In the second sample, there is no way Moriarty can avoid getting two flicks. | 1,000 | [
{
"input": "3\n123\n321",
"output": "0\n2"
},
{
"input": "2\n88\n00",
"output": "2\n0"
},
{
"input": "1\n4\n5",
"output": "0\n1"
},
{
"input": "1\n8\n7",
"output": "1\n0"
},
{
"input": "2\n55\n55",
"output": "0\n0"
},
{
"input": "3\n534\n432",
"out... | 1,671,393,812 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | n = int(input())
b = sorted(list(map(int, input())))
a = sorted(list(map(int, input())))
def find(arg):
i = 0
while (i<n):
if eval(arg):
break
i+=1
if i>0: i -= 1
return i
i = find("b[i]>a[-1]")
good, bad = 0, 0
for j in range(n):
if a[j-i]>b[j]:
... | Title: Game of Credit Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.
Rules of this game are simpl... | ```python
n = int(input())
b = sorted(list(map(int, input())))
a = sorted(list(map(int, input())))
def find(arg):
i = 0
while (i<n):
if eval(arg):
break
i+=1
if i>0: i -= 1
return i
i = find("b[i]>a[-1]")
good, bad = 0, 0
for j in range(n):
if a[j-i]>b[j... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
22 | A | Second Order Statistics | PROGRAMMING | 800 | [
"brute force"
] | A. Second Order Statistics | 2 | 256 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. ... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | [
"4\n1 2 2 -4\n",
"5\n1 2 3 1 1\n"
] | [
"1\n",
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 2 -4",
"output": "1"
},
{
"input": "5\n1 2 3 1 1",
"output": "2"
},
{
"input": "1\n28",
"output": "NO"
},
{
"input": "2\n-28 12",
"output": "12"
},
{
"input": "3\n-83 40 -80",
"output": "-80"
},
{
"input": "8\n93 77 -92 26 21 -48 53 ... | 1,632,437,624 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 154 | 20,172,800 | n = input()
try:
print(sorted(list(set(input().split())))[1])
except IndexError:
print("NO") | Title: Second Order Statistics
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statis... | ```python
n = input()
try:
print(sorted(list(set(input().split())))[1])
except IndexError:
print("NO")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
467 | A | George and Accommodation | PROGRAMMING | 800 | [
"implementation"
] | null | null | George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* peopl... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms.
The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity. | Print a single integer — the number of rooms where George and Alex can move in. | [
"3\n1 1\n2 2\n3 3\n",
"3\n1 10\n0 10\n10 10\n"
] | [
"0\n",
"2\n"
] | none | 500 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "0"
},
{
"input": "3\n1 10\n0 10\n10 10",
"output": "2"
},
{
"input": "2\n36 67\n61 69",
"output": "2"
},
{
"input": "3\n21 71\n10 88\n43 62",
"output": "3"
},
{
"input": "3\n1 2\n2 3\n3 4",
"output": "0"
},
{
"... | 1,691,059,452 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 46 | 0 | n = int(input())
rooms = 0
for i in range(n):
x, y = map(int,input().split())
if y - x >= 2: rooms +=1
print(rooms) | Title: George and Accommodation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want ... | ```python
n = int(input())
rooms = 0
for i in range(n):
x, y = map(int,input().split())
if y - x >= 2: rooms +=1
print(rooms)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
556 | A | Case of the Zeros and Ones | PROGRAMMING | 900 | [
"greedy"
] | null | null | Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, an... | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones. | Output the minimum length of the string that may remain after applying the described operations several times. | [
"4\n1100\n",
"5\n01010\n",
"8\n11101111\n"
] | [
"0\n",
"1\n",
"6\n"
] | In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like... | 250 | [
{
"input": "4\n1100",
"output": "0"
},
{
"input": "5\n01010",
"output": "1"
},
{
"input": "8\n11101111",
"output": "6"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "2"
},
{
"input"... | 1,632,307,750 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 77 | 8,396,800 | n = int(input())
line = str(input())
line1 = ''.join(sorted(line))
if (line1 == line ) and (line1.find('1') == -1 or line1.find('0') == -1):
print(len(line))
exit()
idx = line1.find('1')
print(abs(n - 2*idx))
# print(line)
| Title: Case of the Zeros and Ones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Cons... | ```python
n = int(input())
line = str(input())
line1 = ''.join(sorted(line))
if (line1 == line ) and (line1.find('1') == -1 or line1.find('0') == -1):
print(len(line))
exit()
idx = line1.find('1')
print(abs(n - 2*idx))
# print(line)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
808 | A | Lucky Year | PROGRAMMING | 900 | [
"implementation"
] | null | null | Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not.
You are given current year in Berland. Your task is to find how long... | The first line contains integer number *n* (1<=≤<=*n*<=≤<=109) — current year in Berland. | Output amount of years from the current year to the next lucky one. | [
"4\n",
"201\n",
"4000\n"
] | [
"1\n",
"99\n",
"1000\n"
] | In the first example next lucky year is 5. In the second one — 300. In the third — 5000. | 0 | [
{
"input": "4",
"output": "1"
},
{
"input": "201",
"output": "99"
},
{
"input": "4000",
"output": "1000"
},
{
"input": "9",
"output": "1"
},
{
"input": "10",
"output": "10"
},
{
"input": "1",
"output": "1"
},
{
"input": "100000000",
"ou... | 1,516,806,695 | 2,147,483,647 | Python 3 | OK | TESTS | 271 | 62 | 5,632,000 | n = input()
k = int(n[0])
n = int(n)
k = (k+1)*10**(len(str(n))-1)
print(k-n)
| Title: Lucky Year
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 1... | ```python
n = input()
k = int(n[0])
n = int(n)
k = (k+1)*10**(len(str(n))-1)
print(k-n)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,695,399,539 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 30 | 0 | s=list(input())
if 'h' in s and 'e' in s and 'l'in s and s.index('l')>s.index('e')>s.index('h'):
s.pop(s.index('l'))
if 'l' in s and 'o' in s and s.index('o')>s.index('l'):
print('YES')
else:print('NO')
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s=list(input())
if 'h' in s and 'e' in s and 'l'in s and s.index('l')>s.index('e')>s.index('h'):
s.pop(s.index('l'))
if 'l' in s and 'o' in s and s.index('o')>s.index('l'):
print('YES')
else:print('NO')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
87 | A | Trains | PROGRAMMING | 1,500 | [
"implementation",
"math"
] | A. Trains | 2 | 256 | Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time,... | The first line contains two integers *a* and *b* (*a*<=≠<=*b*,<=1<=≤<=*a*,<=*b*<=≤<=106). | Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency. | [
"3 7\n",
"5 3\n",
"2 3\n"
] | [
"Dasha\n",
"Masha\n",
"Equal\n"
] | Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls ... | 500 | [
{
"input": "3 7",
"output": "Dasha"
},
{
"input": "5 3",
"output": "Masha"
},
{
"input": "2 3",
"output": "Equal"
},
{
"input": "31 88",
"output": "Dasha"
},
{
"input": "8 75",
"output": "Dasha"
},
{
"input": "32 99",
"output": "Dasha"
},
{
... | 1,447,264,853 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 1,872 | 102,400 | def gcd(a, b):
if (a > b):
a, b = b, a
while(a != 0):
a, b = b % a, a
return b
a, b = map(int, input().split())
k = a * b // gcd(a, b)
ansa = 0
ansb = 0
if (a > b):
b, a = a, b
g = True
else:
g = False
for i in range(1, k // b + 1):
if (i != k // b):
... | Title: Trains
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some... | ```python
def gcd(a, b):
if (a > b):
a, b = b, a
while(a != 0):
a, b = b % a, a
return b
a, b = map(int, input().split())
k = a * b // gcd(a, b)
ansa = 0
ansb = 0
if (a > b):
b, a = a, b
g = True
else:
g = False
for i in range(1, k // b + 1):
if (i != k // b... | 3.531809 | MatrixStudio/Codeforces-Python-Submissions |
431 | C | k-Tree | PROGRAMMING | 1,600 | [
"dp",
"implementation",
"trees"
] | null | null | Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a *k*-tree.
A *k*-tree is an infinite rooted tree where:
- each vertex has exactly *k* children; - each edge has some weight; - if we look at the edges that goes... | A single line contains three space-separated integers: *n*, *k* and *d* (1<=≤<=*n*,<=*k*<=≤<=100; 1<=≤<=*d*<=≤<=*k*). | Print a single integer — the answer to the problem modulo 1000000007 (109<=+<=7). | [
"3 3 2\n",
"3 3 3\n",
"4 3 2\n",
"4 5 2\n"
] | [
"3\n",
"1\n",
"6\n",
"7\n"
] | none | 1,500 | [
{
"input": "3 3 2",
"output": "3"
},
{
"input": "3 3 3",
"output": "1"
},
{
"input": "4 3 2",
"output": "6"
},
{
"input": "4 5 2",
"output": "7"
},
{
"input": "28 6 3",
"output": "110682188"
},
{
"input": "5 100 1",
"output": "16"
},
{
"inp... | 1,688,302,616 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | n,k,d=map(int,input().split())
touse=[_ for _ in range(1,k+1)]
DP=[0 for _ in range(n+1)]
DP[0]=1
for p in range(1,n+1):
s=0
for u in touse:
if p-u>=0:
s+=DP[p-u]
DP[p]=s
# print(DP)
final1=DP[n]
touse=[_ for _ in range(1,d)]
DP=[0 for _ in range(n+1)]
DP[0]=1
for p in ran... | Title: k-Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a *k*-tree.
A *k*-tree is an infinite rooted tree where:
- each vertex ... | ```python
n,k,d=map(int,input().split())
touse=[_ for _ in range(1,k+1)]
DP=[0 for _ in range(n+1)]
DP[0]=1
for p in range(1,n+1):
s=0
for u in touse:
if p-u>=0:
s+=DP[p-u]
DP[p]=s
# print(DP)
final1=DP[n]
touse=[_ for _ in range(1,d)]
DP=[0 for _ in range(n+1)]
DP[0]=1
fo... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
681 | B | Economy Game | PROGRAMMING | 1,300 | [
"brute force"
] | null | null | Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0.
Kolya remembers that at the beginning of the game his game-coin score was equal to *n* and that ... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — Kolya's initial game-coin score. | Print "YES" (without quotes) if it's possible that Kolya spent all of his initial *n* coins buying only houses, cars and computers. Otherwise print "NO" (without quotes). | [
"1359257\n",
"17851817\n"
] | [
"YES",
"NO"
] | In the first sample, one of the possible solutions is to buy one house, one car and one computer, spending 1 234 567 + 123 456 + 1234 = 1 359 257 game-coins in total. | 1,000 | [
{
"input": "1359257",
"output": "YES"
},
{
"input": "17851817",
"output": "NO"
},
{
"input": "1000000000",
"output": "YES"
},
{
"input": "17851818",
"output": "YES"
},
{
"input": "438734347",
"output": "YES"
},
{
"input": "43873430",
"output": "YES... | 1,615,543,260 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | t=int(input())
while t>0:
if t%1359257==0:
t=t%1359257
elif t%1358023==0:
t=t%1358023
elif t%1235801==0:
t=t%1235801
elif t%124690==0:
t=t%124690
elif t%1234567==0:
t=t%1234567
elif t%123456==0:
t=t%123456
elif t%1234==0:
t=t%1234
else:
print('NO')
quit()
print('YES')
| Title: Economy Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0.... | ```python
t=int(input())
while t>0:
if t%1359257==0:
t=t%1359257
elif t%1358023==0:
t=t%1358023
elif t%1235801==0:
t=t%1235801
elif t%124690==0:
t=t%124690
elif t%1234567==0:
t=t%1234567
elif t%123456==0:
t=t%123456
elif t%1234==0:
t=t%1234
else:
print('NO')
quit()
print('YE... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
236 | A | Boy or Girl | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
Bu... | The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters. | If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). | [
"wjmzbmr\n",
"xiaodao\n",
"sevenkplus\n"
] | [
"CHAT WITH HER!\n",
"IGNORE HIM!\n",
"CHAT WITH HER!\n"
] | For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!". | 500 | [
{
"input": "wjmzbmr",
"output": "CHAT WITH HER!"
},
{
"input": "xiaodao",
"output": "IGNORE HIM!"
},
{
"input": "sevenkplus",
"output": "CHAT WITH HER!"
},
{
"input": "pezu",
"output": "CHAT WITH HER!"
},
{
"input": "wnemlgppy",
"output": "CHAT WITH HER!"
},... | 1,699,357,769 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 307,200 | from collections import OrderedDict
def remove_duplicate(s):
return "".join(OrderedDict.fromkeys(s))
n=str(input("nom d'utilisateurs : "))
if (len(remove_duplicate(n)) % 2 != 0 ):
print("ignore him")
else:
print("talk to her ") | Title: Boy or Girl
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he though... | ```python
from collections import OrderedDict
def remove_duplicate(s):
return "".join(OrderedDict.fromkeys(s))
n=str(input("nom d'utilisateurs : "))
if (len(remove_duplicate(n)) % 2 != 0 ):
print("ignore him")
else:
print("talk to her ")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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,642,975,557 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 122 | 0 | st=input().split()
cot1,cot2=[],[]
st=list(map(int,input().split()))
for i in st:
if i%2==0:
cot1.append(i)
else: cot2.append(i)
print(st.index(cot1[0])+1 if len(cot1)<len(cot2) else st.index(cot2[0])+1)
| Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
st=input().split()
cot1,cot2=[],[]
st=list(map(int,input().split()))
for i in st:
if i%2==0:
cot1.append(i)
else: cot2.append(i)
print(st.index(cot1[0])+1 if len(cot1)<len(cot2) else st.index(cot2[0])+1)
``` | 3.9695 | MatrixStudio/Codeforces-Python-Submissions |
987 | A | Infinity Gauntlet | PROGRAMMING | 800 | [
"implementation"
] | null | null | You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color.
Using colors... | In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet.
In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase ... | In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems.
Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase. | [
"4\nred\npurple\nyellow\norange\n",
"0\n"
] | [
"2\nSpace\nTime\n",
"6\nTime\nMind\nSoul\nPower\nReality\nSpace\n"
] | In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | 500 | [
{
"input": "4\nred\npurple\nyellow\norange",
"output": "2\nSpace\nTime"
},
{
"input": "0",
"output": "6\nMind\nSpace\nPower\nTime\nReality\nSoul"
},
{
"input": "6\npurple\nblue\nyellow\nred\ngreen\norange",
"output": "0"
},
{
"input": "1\npurple",
"output": "5\nTime\nReal... | 1,616,993,717 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 62 | 0 | n=int(input())
A={'red':'Reality','green':'Time','blue':'Space','orange':'Soul','yellow':'Mind','purple':'Power'}
for i in range(n):
a=input()
del A[a]
print (6-n)
for i in A:
print (A[i]) | Title: Infinity Gauntlet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the So... | ```python
n=int(input())
A={'red':'Reality','green':'Time','blue':'Space','orange':'Soul','yellow':'Mind','purple':'Power'}
for i in range(n):
a=input()
del A[a]
print (6-n)
for i in A:
print (A[i])
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
245 | A | System Administrator | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a progra... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x... | In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes).
In the second line print the state of server *b* in the similar format. | [
"2\n1 5 5\n2 6 4\n",
"3\n1 0 10\n2 0 10\n1 10 0\n"
] | [
"LIVE\nLIVE\n",
"LIVE\nDEAD\n"
] | Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to t... | 0 | [
{
"input": "2\n1 5 5\n2 6 4",
"output": "LIVE\nLIVE"
},
{
"input": "3\n1 0 10\n2 0 10\n1 10 0",
"output": "LIVE\nDEAD"
},
{
"input": "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9",
"output": "DEAD\nLIVE"
},
{
"input": "11\n1 8 2\n1 6 4\n1 9 1\n1... | 1,367,838,610 | 2,147,483,647 | Python 3 | OK | TESTS | 13 | 78 | 102,400 | n=int(input())
ta,tb,da,db=[0]*4
for i in range (n):
t,x,y=map(int,input().split())
if t==1:
ta+=(x+y)
da+=y
if (t==2):
tb+=(x+y)
db+=y
if (ta-da>=0.5*ta):
print ('LIVE')
else :
print ('DEAD')
if (tb-db>=0.5*tb):
print ('LIVE')
else :
p... | Title: System Administrator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping co... | ```python
n=int(input())
ta,tb,da,db=[0]*4
for i in range (n):
t,x,y=map(int,input().split())
if t==1:
ta+=(x+y)
da+=y
if (t==2):
tb+=(x+y)
db+=y
if (ta-da>=0.5*ta):
print ('LIVE')
else :
print ('DEAD')
if (tb-db>=0.5*tb):
print ('LIVE')
els... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
44 | A | Indian Summer | PROGRAMMING | 900 | [
"implementation"
] | A. Indian Summer | 2 | 256 | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no mor... | Output the single number — the number of Alyona's leaves. | [
"5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n",
"3\noak yellow\noak yellow\noak yellow\n"
] | [
"4\n",
"1\n"
] | none | 0 | [
{
"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green",
"output": "4"
},
{
"input": "3\noak yellow\noak yellow\noak yellow",
"output": "1"
},
{
"input": "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae",
"output": "5"
},
{
"input"... | 1,651,939,005 | 2,147,483,647 | PyPy 3 | OK | TESTS | 29 | 186 | 0 | n=int(input())
s=[]
for i in range(n):
q=input()
s.append(q)
print(len(set(s)))
| Title: Indian Summer
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the specie... | ```python
n=int(input())
s=[]
for i in range(n):
q=input()
s.append(q)
print(len(set(s)))
``` | 3.9535 | MatrixStudio/Codeforces-Python-Submissions |
11 | A | Increasing Sequence | PROGRAMMING | 900 | [
"constructive algorithms",
"implementation",
"math"
] | A. Increasing Sequence | 1 | 64 | A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least... | The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106). | Output the minimal number of moves needed to make the sequence increasing. | [
"4 2\n1 3 3 2\n"
] | [
"3\n"
] | none | 0 | [
{
"input": "4 2\n1 3 3 2",
"output": "3"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 1\n2 5",
"output": "0"
},
{
"input": "2 1\n1 2",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 7\n10 20",
"output": "0"
},
... | 1,663,491,569 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 16 | 1,000 | 1,740,800 | n,d=map(int,input().split())
a=list(map(int,input().split()));aa=0;bb=0
for i in a:
aa+=i
for i in range(len(a)-1):
while a[i+1]<=a[i]:
a[i+1]+=d
for i in a:
bb+=i
print(str(int((bb-aa)/d))) | Title: Increasing Sequence
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*... | ```python
n,d=map(int,input().split())
a=list(map(int,input().split()));aa=0;bb=0
for i in a:
aa+=i
for i in range(len(a)-1):
while a[i+1]<=a[i]:
a[i+1]+=d
for i in a:
bb+=i
print(str(int((bb-aa)/d)))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
761 | B | Dasha and friends | PROGRAMMING | 1,300 | [
"brute force",
"implementation",
"math"
] | null | null | Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation:
The track is the circle with length *L*, in distinct points of which there are *n* barriers. Athlete always run the track in counterclockwise direction if... | The first line contains two integers *n* and *L* (1<=≤<=*n*<=≤<=50, *n*<=≤<=*L*<=≤<=100) — the number of barriers on a track and its length.
The second line contains *n* distinct integers in the ascending order — the distance from Kefa's start to each barrier in the order of its appearance. All integers are in the ra... | Print "YES" (without quotes), if Kefa and Sasha ran the coinciding tracks (it means that the position of all barriers coincides, if they start running from the same points on the track). Otherwise print "NO" (without quotes). | [
"3 8\n2 4 6\n1 5 7\n",
"4 9\n2 3 5 8\n0 1 3 6\n",
"2 4\n1 3\n1 2\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | The first test is analyzed in the statement. | 1,000 | [
{
"input": "3 8\n2 4 6\n1 5 7",
"output": "YES"
},
{
"input": "4 9\n2 3 5 8\n0 1 3 6",
"output": "YES"
},
{
"input": "2 4\n1 3\n1 2",
"output": "NO"
},
{
"input": "5 9\n0 2 5 6 7\n1 3 6 7 8",
"output": "YES"
},
{
"input": "5 60\n7 26 27 40 59\n14 22 41 42 55",
... | 1,485,879,674 | 6,373 | Python 3 | WRONG_ANSWER | PRETESTS | 8 | 46 | 4,608,000 | n,l=input().split()
n,l=int(n),int(l)
l1=[int(x) for x in input().split()]
l2=[int(y) for y in input().split()]
l1=l1+[l]
l2=l2+[l]
bl1=[]
bl2=[]
for i in range(len(l1)-1):
d=l1[i+1]-l1[i]
bl1.append(d)
for i in range(len(l2)-1):
p=l2[i+1]-l2[i]
bl2.append(p)
bl1[n-1]=bl1[n-1]+l1[0]
bl2[n... | Title: Dasha and friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation:
The track is the circle with length *L*, in distinc... | ```python
n,l=input().split()
n,l=int(n),int(l)
l1=[int(x) for x in input().split()]
l2=[int(y) for y in input().split()]
l1=l1+[l]
l2=l2+[l]
bl1=[]
bl2=[]
for i in range(len(l1)-1):
d=l1[i+1]-l1[i]
bl1.append(d)
for i in range(len(l2)-1):
p=l2[i+1]-l2[i]
bl2.append(p)
bl1[n-1]=bl1[n-1]+l1... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
622 | B | The Time | PROGRAMMING | 900 | [
"implementation"
] | null | null | You are given the current time in 24-hour format hh:mm. Find and print the time after *a* minutes.
Note that you should find only the time after *a* minutes, see the examples to clarify the problem statement.
You can read more about 24-hour format here [https://en.wikipedia.org/wiki/24-hour_clock](https://en.wikipedi... | The first line contains the current time in the format hh:mm (0<=≤<=*hh*<=<<=24,<=0<=≤<=*mm*<=<<=60). The hours and the minutes are given with two digits (the hours or the minutes less than 10 are given with the leading zeroes).
The second line contains integer *a* (0<=≤<=*a*<=≤<=104) — the number of the minutes... | The only line should contain the time after *a* minutes in the format described in the input. Note that you should print exactly two digits for the hours and the minutes (add leading zeroes to the numbers if needed).
See the examples to check the input/output format. | [
"23:59\n10\n",
"20:20\n121\n",
"10:10\n0\n"
] | [
"00:09\n",
"22:21\n",
"10:10\n"
] | none | 0 | [
{
"input": "23:59\n10",
"output": "00:09"
},
{
"input": "20:20\n121",
"output": "22:21"
},
{
"input": "10:10\n0",
"output": "10:10"
},
{
"input": "12:34\n10000",
"output": "11:14"
},
{
"input": "00:00\n10000",
"output": "22:40"
},
{
"input": "00:00\n14... | 1,614,664,273 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 204,800 | #Collaborated with Rudransh singh and Bhumi patel
h, m = input().split(":")
h = int(h)
m = int(m)
a = int(input())
m = m + a
h = h + int(m / 60)
m = int(m % 60)
while(h > 24):
h -= 24
if h == 0:
finalHour = "00"
if m == 0:
finalMin = "00"
if h < 10:
finalHour = "0" + str(h)
if m < 10:
finalH... | Title: The Time
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given the current time in 24-hour format hh:mm. Find and print the time after *a* minutes.
Note that you should find only the time after *a* minutes, see the examples to clarify the problem statement.
You can read mo... | ```python
#Collaborated with Rudransh singh and Bhumi patel
h, m = input().split(":")
h = int(h)
m = int(m)
a = int(input())
m = m + a
h = h + int(m / 60)
m = int(m % 60)
while(h > 24):
h -= 24
if h == 0:
finalHour = "00"
if m == 0:
finalMin = "00"
if h < 10:
finalHour = "0" + str(h)
if m < 10:
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
305 | A | Strange Addition | PROGRAMMING | 1,600 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Unfortunately, Vasya can only sum pairs of integers (*a*, *b*), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.
Vasya has a set of *k* distinct non-negative integers *d*1,<=*d*2,<=...,<=*d**k*.
Vasya wants to choo... | The first input line contains integer *k* (1<=≤<=*k*<=≤<=100) — the number of integers.
The second line contains *k* distinct space-separated integers *d*1,<=*d*2,<=...,<=*d**k* (0<=≤<=*d**i*<=≤<=100). | In the first line print a single integer *n* the maximum number of the chosen integers. In the second line print *n* distinct non-negative integers — the required integers.
If there are multiple solutions, print any of them. You can print the numbers in any order. | [
"4\n100 10 1 0\n",
"3\n2 70 3\n"
] | [
"4\n0 1 10 100 ",
"2\n2 70 "
] | none | 500 | [
{
"input": "4\n100 10 1 0",
"output": "4\n0 1 10 100 "
},
{
"input": "3\n2 70 3",
"output": "2\n2 70 "
},
{
"input": "39\n16 72 42 70 17 36 32 40 47 94 27 30 100 55 23 77 67 28 49 50 53 83 38 33 60 65 62 64 6 66 69 86 96 75 85 0 89 73 29",
"output": "4\n0 6 30 100 "
},
{
"inp... | 1,693,651,449 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 102,400 | x = int(input())
wi = []
wj = []
z = input().split()
counterx = 0
countery = 0
for i in range(x):
if len(z[i]) == 2:
if '0' in z[i][1]:
counterx += 1
wi.append(z[i])
if len(z[i]) > 2:
if '0' in z[i][1]:
countery += 1
wj.append(z[i])... | Title: Strange Addition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Unfortunately, Vasya can only sum pairs of integers (*a*, *b*), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.
... | ```python
x = int(input())
wi = []
wj = []
z = input().split()
counterx = 0
countery = 0
for i in range(x):
if len(z[i]) == 2:
if '0' in z[i][1]:
counterx += 1
wi.append(z[i])
if len(z[i]) > 2:
if '0' in z[i][1]:
countery += 1
wj.ap... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
780 | A | Andryusha and Socks | PROGRAMMING | 800 | [
"implementation"
] | null | null | Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the ... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs.
The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha ... | Print single integer — the maximum number of socks that were on the table at the same time. | [
"1\n1 1\n",
"3\n2 1 1 3 2 3\n"
] | [
"1\n",
"2\n"
] | In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- ... | 500 | [
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n2 1 1 3 2 3",
"output": "2"
},
{
"input": "5\n5 1 3 2 4 3 1 2 4 5",
"output": "5"
},
{
"input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7",
"output": "6"
},
{
"input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 ... | 1,609,987,836 | 2,147,483,647 | PyPy 3 | OK | TESTS | 56 | 280 | 14,540,800 | n = int(input())
arr = list(map(int,input().split()))
flag = [0]*(10**5+5)
k = 0
mx = 0
for c in arr:
if flag[c]==0:
k+=1
flag[c]+=1
mx = max(mx,k)
else:
k-=1
flag[c]-=1
print(mx) | Title: Andryusha and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbere... | ```python
n = int(input())
arr = list(map(int,input().split()))
flag = [0]*(10**5+5)
k = 0
mx = 0
for c in arr:
if flag[c]==0:
k+=1
flag[c]+=1
mx = max(mx,k)
else:
k-=1
flag[c]-=1
print(mx)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
23 | A | You're Given a String... | PROGRAMMING | 1,200 | [
"brute force",
"greedy"
] | A. You're Given a String... | 2 | 256 | You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2). | The first input line contains the string. It's guaranteed, that the string is non-empty, consists of lower-case Latin letters, and its length doesn't exceed 100. | Output one number — length of the longest substring that can be met in the string at least twice. | [
"abcd\n",
"ababa\n",
"zzz\n"
] | [
"0",
"3",
"2"
] | none | 0 | [
{
"input": "abcd",
"output": "0"
},
{
"input": "ababa",
"output": "3"
},
{
"input": "zzz",
"output": "2"
},
{
"input": "kmmm",
"output": "2"
},
{
"input": "wzznz",
"output": "1"
},
{
"input": "qlzazaaqll",
"output": "2"
},
{
"input": "lzggg... | 1,667,117,452 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 92 | 0 | str_given = input()
length = len(str_given)
while length >=1:
freqs = {}
for i in range(0,len(str_given)-length+1):
if str_given[i:i + length] in freqs.keys():
freqs[str_given[i:i+length]] += 1
else:
freqs[str_given[i:i+length]] = 1
if 2 in freqs.values():
... | Title: You're Given a String...
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2).
Input Sp... | ```python
str_given = input()
length = len(str_given)
while length >=1:
freqs = {}
for i in range(0,len(str_given)-length+1):
if str_given[i:i + length] in freqs.keys():
freqs[str_given[i:i+length]] += 1
else:
freqs[str_given[i:i+length]] = 1
if 2 in freqs.va... | 0 | MatrixStudio/Codeforces-Python-Submissions |
401 | A | Vanya and Cards | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed *x* in the absolute value.
Natasha doesn't like when Vanya spends a long time p... | The first line contains two integers: *n* (1<=≤<=*n*<=≤<=1000) — the number of found cards and *x* (1<=≤<=*x*<=≤<=1000) — the maximum absolute value of the number on a card. The second line contains *n* space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed *x* in their a... | Print a single number — the answer to the problem. | [
"3 2\n-1 1 2\n",
"2 3\n-2 -2\n"
] | [
"1\n",
"2\n"
] | In the first sample, Vanya needs to find a single card with number -2.
In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value. | 500 | [
{
"input": "3 2\n-1 1 2",
"output": "1"
},
{
"input": "2 3\n-2 -2",
"output": "2"
},
{
"input": "4 4\n1 2 3 4",
"output": "3"
},
{
"input": "2 2\n-1 -1",
"output": "1"
},
{
"input": "15 5\n-2 -1 2 -4 -3 4 -4 -2 -2 2 -2 -1 1 -4 -2",
"output": "4"
},
{
"... | 1,629,018,078 | 2,147,483,647 | PyPy 3 | OK | TESTS | 47 | 124 | 20,172,800 | n, x = map(int, input().split())
arr = [*map(int, input().split())]
print((abs(sum(arr))+x-1)//x) | Title: Vanya and Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each... | ```python
n, x = map(int, input().split())
arr = [*map(int, input().split())]
print((abs(sum(arr))+x-1)//x)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
166 | E | Tetrahedron | PROGRAMMING | 1,500 | [
"dp",
"math",
"matrices"
] | null | null | You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. ... | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path. | Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7). | [
"2\n",
"4\n"
] | [
"3\n",
"21\n"
] | The required paths in the first sample are:
- *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D* | 1,000 | [
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "21"
},
{
"input": "1",
"output": "0"
},
{
"input": "3",
"output": "6"
},
{
"input": "5",
"output": "60"
},
{
"input": "6",
"output": "183"
},
{
"input": "7",
"output": "546"
... | 1,617,791,862 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 2,000 | 1,843,200 | def main():
n=int(input())
mod=10**9+7
a,b,c,d=0,0,0,1
for i in range(1,n+1):
aa,bb,cc,dd=a,b,c,d
a=(bb+cc+dd)%mod
b=(aa+cc+dd)%mod
c=(aa+bb+dd)%mod
d=(aa+bb+cc)%mod
print(d)
main() | Title: Tetrahedron
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each m... | ```python
def main():
n=int(input())
mod=10**9+7
a,b,c,d=0,0,0,1
for i in range(1,n+1):
aa,bb,cc,dd=a,b,c,d
a=(bb+cc+dd)%mod
b=(aa+cc+dd)%mod
c=(aa+bb+dd)%mod
d=(aa+bb+cc)%mod
print(d)
main()
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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,646,645,650 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 374 | 11,468,800 | n=int(input())
a=[*map(int,input().split())]
m=int(input())
b=[*map(int,input().split())]
d={}
ls=rs=0
for i in range(n):
d[a[i]]=i
for i in range(m):
l=d[b[i]]+1
r=n-d[b[i]]
ls+=l
rs+=r
print(ls,rs) | 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
n=int(input())
a=[*map(int,input().split())]
m=int(input())
b=[*map(int,input().split())]
d={}
ls=rs=0
for i in range(n):
d[a[i]]=i
for i in range(m):
l=d[b[i]]+1
r=n-d[b[i]]
ls+=l
rs+=r
print(ls,rs)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
698 | A | Vacations | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is close... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where:
- *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the co... | Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days, - to write the contest on any two consecutive days. | [
"4\n1 3 2 0\n",
"7\n1 3 3 2 1 2 3\n",
"2\n2 2\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya ca... | 500 | [
{
"input": "4\n1 3 2 0",
"output": "2"
},
{
"input": "7\n1 3 3 2 1 2 3",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "10\n0 0 1 1 0 0 0 0 1 0",
"output": "8"
},
{
"input": "100\n3 2 3 3 3 2 3 1 ... | 1,677,752,730 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 88 | 62 | 0 | n = int(input())
l, dp = [int(i) for i in input().split()], [[0,0,0] for j in range(n+2)]
for i in range(1, n+1): dp[i][0],dp[i][1], dp[i][2] = min(dp[i - 1]) + 1, min(dp[i-1][0], dp[i-1][2]) if (l[i-1] in [1, 3]) else int(1e9), min(dp[i - 1][0], dp[i - 1][1]) if (l[i-1] in [2, 3]) else int(1e9)
print(min(dp[n])) | Title: Vacations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Int... | ```python
n = int(input())
l, dp = [int(i) for i in input().split()], [[0,0,0] for j in range(n+2)]
for i in range(1, n+1): dp[i][0],dp[i][1], dp[i][2] = min(dp[i - 1]) + 1, min(dp[i-1][0], dp[i-1][2]) if (l[i-1] in [1, 3]) else int(1e9), min(dp[i - 1][0], dp[i - 1][1]) if (l[i-1] in [2, 3]) else int(1e9)
print(min(... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
931 | A | Friends Meeting | PROGRAMMING | 800 | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes acco... | The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend.
The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend.
It is guaranteed that *a*<=≠<=*b*. | Print the minimum possible total tiredness if the friends meet in the same point. | [
"3\n4\n",
"101\n99\n",
"5\n10\n"
] | [
"1\n",
"2\n",
"9\n"
] | In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1.
In the second example the first friend should move by one to the left, an... | 500 | [
{
"input": "3\n4",
"output": "1"
},
{
"input": "101\n99",
"output": "2"
},
{
"input": "5\n10",
"output": "9"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n1000",
"output": "250000"
},
{
"input": "999\n1000",
"output": "1"
},
{
"inpu... | 1,586,032,140 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 109 | 0 | a = int(input())
b = int(input())
mayor = max(a, b)
menor = min(a, b)
derecha = 0
izquierda = 0
for i in range(1, mayor):
mayor = mayor-1
derecha = derecha+i
if mayor == menor:
print(derecha+izquierda)
break
else:
menor = menor+1
izquierda = izquierda+i
... | Title: Friends Meeting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in... | ```python
a = int(input())
b = int(input())
mayor = max(a, b)
menor = min(a, b)
derecha = 0
izquierda = 0
for i in range(1, mayor):
mayor = mayor-1
derecha = derecha+i
if mayor == menor:
print(derecha+izquierda)
break
else:
menor = menor+1
izquierda = iz... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
633 | A | Ebony and Ivory | PROGRAMMING | 1,100 | [
"brute force",
"math",
"number theory"
] | null | null | Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of ... | The first line of the input contains three integers *a*, *b*, *c* (1<=≤<=*a*,<=*b*<=≤<=100,<=1<=≤<=*c*<=≤<=10<=000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively. | Print "Yes" (without quotes) if Dante can deal exactly *c* damage to the shield and "No" (without quotes) otherwise. | [
"4 6 15\n",
"3 2 7\n",
"6 11 6\n"
] | [
"No\n",
"Yes\n",
"Yes\n"
] | In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage. | 250 | [
{
"input": "4 6 15",
"output": "No"
},
{
"input": "3 2 7",
"output": "Yes"
},
{
"input": "6 11 6",
"output": "Yes"
},
{
"input": "3 12 15",
"output": "Yes"
},
{
"input": "5 5 10",
"output": "Yes"
},
{
"input": "6 6 7",
"output": "No"
},
{
"... | 1,609,180,072 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 22 | 155 | 0 | import math
a,b,c=map(int,input().split())
if c%math.gcd(a,b)==0:
print('Yes')
else:
print('No') | Title: Ebony and Ivory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
F... | ```python
import math
a,b,c=map(int,input().split())
if c%math.gcd(a,b)==0:
print('Yes')
else:
print('No')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,671,634,480 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 92 | 0 | apel = int(input())
ctim1 = 0
ctim2 = 0
for i in range(apel):
a = input()
if i==0:
tim1 = a
ctim1 += 1
else:
if a != tim1:
tim2 = a
ctim2 +=1
else:
ctim1 +=1
if ctim1 > ctim2:
print(tim1)
else:
print(tim2)
| Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
apel = int(input())
ctim1 = 0
ctim2 = 0
for i in range(apel):
a = input()
if i==0:
tim1 = a
ctim1 += 1
else:
if a != tim1:
tim2 = a
ctim2 +=1
else:
ctim1 +=1
if ctim1 > ctim2:
print(tim1)
else:
print... | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
352 | A | Jeff and Digits | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"math"
] | null | null | Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?
Jeff must make the number without leading zero. At that, we assume that numbe... | The first line contains integer *n* (1<=≤<=*n*<=≤<=103). The next line contains *n* integers *a*1, *a*2, ..., *a**n* (*a**i*<==<=0 or *a**i*<==<=5). Number *a**i* represents the digit that is written on the *i*-th card. | In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1. | [
"4\n5 0 5 0\n",
"11\n5 5 5 5 5 5 5 5 0 5 5\n"
] | [
"0\n",
"5555555550\n"
] | In the first test you can make only one number that is a multiple of 90 — 0.
In the second test you can make number 5555555550, it is a multiple of 90. | 500 | [
{
"input": "4\n5 0 5 0",
"output": "0"
},
{
"input": "11\n5 5 5 5 5 5 5 5 0 5 5",
"output": "5555555550"
},
{
"input": "7\n5 5 5 5 5 5 5",
"output": "-1"
},
{
"input": "1\n5",
"output": "-1"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "11\n5 0 5 ... | 1,650,195,284 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | n = int(input())
arr = list(map(int, input().split()))
count_0 = 0
count_5 = 0
for num in arr:
if num == 0:
count_0 += 1
else:
count_5 += 1
if count_5 // 9 == 0:
print(0)
else:
num = ['5' for i in range(count_5 // 9 * 9)] + ['0' for i in range(count_0)]
... | Title: Jeff and Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make fr... | ```python
n = int(input())
arr = list(map(int, input().split()))
count_0 = 0
count_5 = 0
for num in arr:
if num == 0:
count_0 += 1
else:
count_5 += 1
if count_5 // 9 == 0:
print(0)
else:
num = ['5' for i in range(count_5 // 9 * 9)] + ['0' for i in range(... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
411 | A | Password Check | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic che... | The first line contains a non-empty sequence of characters (at most 100 characters). Each character is either a large English letter, or a small English letter, or a digit, or one of characters: "!", "?", ".", ",", "_". | If the password is complex enough, print message "Correct" (without the quotes), otherwise print message "Too weak" (without the quotes). | [
"abacaba\n",
"X12345\n",
"CONTEST_is_STARTED!!11\n"
] | [
"Too weak\n",
"Too weak\n",
"Correct\n"
] | none | 0 | [
{
"input": "abacaba",
"output": "Too weak"
},
{
"input": "X12345",
"output": "Too weak"
},
{
"input": "CONTEST_is_STARTED!!11",
"output": "Correct"
},
{
"input": "1zA__",
"output": "Correct"
},
{
"input": "1zA_",
"output": "Too weak"
},
{
"input": "zA_... | 1,397,574,281 | 68,681 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 61 | 0 | import re
s=input()
print(["Too weak","Correct"][(len(s)>=6)&re.search(r'[a-z]', s)&re.search(r'[A-Z]', s)&re.search(r'\d', s)]) | Title: Password Check
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password... | ```python
import re
s=input()
print(["Too weak","Correct"][(len(s)>=6)&re.search(r'[a-z]', s)&re.search(r'[A-Z]', s)&re.search(r'\d', s)])
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
846 | B | Math Show | PROGRAMMING | 1,800 | [
"brute force",
"greedy"
] | null | null | Polycarp takes part in a math show. He is given *n* tasks, each consists of *k* subtasks, numbered 1 through *k*. It takes him *t**j* minutes to solve the *j*-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.
... | The first line contains three integer numbers *n*, *k* and *M* (1<=≤<=*n*<=≤<=45, 1<=≤<=*k*<=≤<=45, 0<=≤<=*M*<=≤<=2·109).
The second line contains *k* integer numbers, values *t**j* (1<=≤<=*t**j*<=≤<=1000000), where *t**j* is the time in minutes required to solve *j*-th subtask of any task. | Print the maximum amount of points Polycarp can earn in *M* minutes. | [
"3 4 11\n1 2 3 4\n",
"5 5 10\n1 2 4 8 16\n"
] | [
"6\n",
"7\n"
] | In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.
In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of tw... | 0 | [
{
"input": "3 4 11\n1 2 3 4",
"output": "6"
},
{
"input": "5 5 10\n1 2 4 8 16",
"output": "7"
},
{
"input": "1 1 0\n2",
"output": "0"
},
{
"input": "1 1 1\n1",
"output": "2"
},
{
"input": "2 1 0\n2",
"output": "0"
},
{
"input": "2 2 2\n2 3",
"outpu... | 1,613,596,187 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 77 | 0 | def solve(n, k, M, t):
tt = sorted(t * k)
res = 0
tasks_taken = []
# greedy take smallest tasks
while M > 0 and tt:
taskm = tt.pop(0)
M -= taskm
if M < 0:
break
res += 1
tasks_taken += [taskm]
# print(tasks_taken)
# loop grough all taken ... | Title: Math Show
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp takes part in a math show. He is given *n* tasks, each consists of *k* subtasks, numbered 1 through *k*. It takes him *t**j* minutes to solve the *j*-th subtask of any task. Thus, time required to solve a subtask dep... | ```python
def solve(n, k, M, t):
tt = sorted(t * k)
res = 0
tasks_taken = []
# greedy take smallest tasks
while M > 0 and tt:
taskm = tt.pop(0)
M -= taskm
if M < 0:
break
res += 1
tasks_taken += [taskm]
# print(tasks_taken)
# loop grough ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
863 | B | Kayaking | PROGRAMMING | 1,500 | [
"brute force",
"greedy",
"sortings"
] | null | null | Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exact... | The first line contains one number *n* (2<=≤<=*n*<=≤<=50).
The second line contains 2·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=≤<=*w**i*<=≤<=1000). | Print minimum possible total instability. | [
"2\n1 2 3 4\n",
"4\n1 3 4 6 3 4 100 200\n"
] | [
"1\n",
"5\n"
] | none | 0 | [
{
"input": "2\n1 2 3 4",
"output": "1"
},
{
"input": "4\n1 3 4 6 3 4 100 200",
"output": "5"
},
{
"input": "3\n305 139 205 406 530 206",
"output": "102"
},
{
"input": "3\n610 750 778 6 361 407",
"output": "74"
},
{
"input": "5\n97 166 126 164 154 98 221 7 51 47",
... | 1,623,477,449 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 155 | 0 | #coded by gautham on 21/6/2021
n=int(input())
l=list(map(int,input().split()))
l.sort()
u=[]
for i in range(0,2*n-1):
for j in range(i,2*n-1):
k=list(l)
k.pop(i)
k.pop(j)
s=0
for j in range(0,n-1):
s=s+k[2*j+1]-k[2*j]
u.append(s)
print(min(u))
... | Title: Kayaking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they hav... | ```python
#coded by gautham on 21/6/2021
n=int(input())
l=list(map(int,input().split()))
l.sort()
u=[]
for i in range(0,2*n-1):
for j in range(i,2*n-1):
k=list(l)
k.pop(i)
k.pop(j)
s=0
for j in range(0,n-1):
s=s+k[2*j+1]-k[2*j]
u.append(s)
print(min(u))
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=<<=*y*) from the set, such that *y*<==<=*x*·*k*.
You're given a set of *n* distinct positive integers. Your task is to find th... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109). The next line contains a list of *n* distinct positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
All the numbers in the lines are separated by single spaces. | On the only line of the output print the size of the largest *k*-multiple free subset of {*a*1,<=*a*2,<=...,<=*a**n*}. | [
"6 2\n2 3 6 5 4 10\n"
] | [
"3\n"
] | In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | 0 | [
{
"input": "6 2\n2 3 6 5 4 10",
"output": "3"
},
{
"input": "10 2\n1 2 3 4 5 6 7 8 9 10",
"output": "6"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "100 2\n191 17 61 40 77 95 128 88 26 69 79 10 131 106 142 152 68 39 182 53 83 81 6 89 65 148 33 22 5 47 107 121 52 163 1... | 1,671,111,110 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 43 | 248 | 18,227,200 | n,k = map(int,input().split())
lst = sorted(map(int,input().split()))[::-1]
dic = {i:0 for i in lst}
for i in lst:
x = i*k
if x in dic:
dic[x]+=1
st = set()
for i in lst:
if i*k in st:
if dic[i] < dic[i*k]:
st.add(i)
st.remove(i*k)
else:
st.add(i)
print(... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=<<=*y*) from the set, such that *y*<=... | ```python
n,k = map(int,input().split())
lst = sorted(map(int,input().split()))[::-1]
dic = {i:0 for i in lst}
for i in lst:
x = i*k
if x in dic:
dic[x]+=1
st = set()
for i in lst:
if i*k in st:
if dic[i] < dic[i*k]:
st.add(i)
st.remove(i*k)
else:
st.add... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
698 | A | Vacations | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is close... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where:
- *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the co... | Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days, - to write the contest on any two consecutive days. | [
"4\n1 3 2 0\n",
"7\n1 3 3 2 1 2 3\n",
"2\n2 2\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya ca... | 500 | [
{
"input": "4\n1 3 2 0",
"output": "2"
},
{
"input": "7\n1 3 3 2 1 2 3",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "10\n0 0 1 1 0 0 0 0 1 0",
"output": "8"
},
{
"input": "100\n3 2 3 3 3 2 3 1 ... | 1,598,688,753 | 2,147,483,647 | PyPy 3 | OK | TESTS | 88 | 156 | 0 | n = int(input())
a = list(map(int, input().split()))
minr = ming = minc = 0
for i in a:
if i == 0:
minr = min(minr, ming, minc)+1
ming = n
minc = n
elif i == 1:
minc, minr, ming = min(minr, ming), min(minr, ming, minc)+1, n
elif i == 2:
ming, minr, minc =... | Title: Vacations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Int... | ```python
n = int(input())
a = list(map(int, input().split()))
minr = ming = minc = 0
for i in a:
if i == 0:
minr = min(minr, ming, minc)+1
ming = n
minc = n
elif i == 1:
minc, minr, ming = min(minr, ming), min(minr, ming, minc)+1, n
elif i == 2:
ming, mi... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
258 | A | Little Elephant and Bits | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis... | The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. | In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. | [
"101\n",
"110010\n"
] | [
"11\n",
"11010\n"
] | In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub cla... | 500 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "11101001... | 1,619,787,573 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 124 | 0 | a=str(input())
s=list(a)
l=len(s)
for i in range(l):
if(s[i]=='0'):
s.pop(i)
print("".join(map(str,s)))
break
if(i==l):
print("".join(map(str,s[1:])))
| Title: Little Elephant and Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought... | ```python
a=str(input())
s=list(a)
l=len(s)
for i in range(l):
if(s[i]=='0'):
s.pop(i)
print("".join(map(str,s)))
break
if(i==l):
print("".join(map(str,s[1:])))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
876 | A | Trip For Meal | PROGRAMMING | 900 | [
"math"
] | null | null | Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is *a* meters, between Rabbit's ... | First line contains an integer *n* (1<=≤<=*n*<=≤<=100) — number of visits.
Second line contains an integer *a* (1<=≤<=*a*<=≤<=100) — distance between Rabbit's and Owl's houses.
Third line contains an integer *b* (1<=≤<=*b*<=≤<=100) — distance between Rabbit's and Eeyore's houses.
Fourth line contains an integer *c* ... | Output one number — minimum distance in meters Winnie must go through to have a meal *n* times. | [
"3\n2\n3\n1\n",
"1\n2\n3\n5\n"
] | [
"3\n",
"0\n"
] | In the first test case the optimal path for Winnie is the following: first have a meal in Rabbit's house, then in Owl's house, then in Eeyore's house. Thus he will pass the distance 2 + 1 = 3.
In the second test case Winnie has a meal in Rabbit's house and that is for him. So he doesn't have to walk anywhere at all. | 500 | [
{
"input": "3\n2\n3\n1",
"output": "3"
},
{
"input": "1\n2\n3\n5",
"output": "0"
},
{
"input": "10\n1\n8\n3",
"output": "9"
},
{
"input": "7\n10\n5\n6",
"output": "30"
},
{
"input": "9\n9\n7\n5",
"output": "42"
},
{
"input": "9\n37\n85\n76",
"outpu... | 1,593,960,026 | 2,147,483,647 | PyPy 3 | OK | TESTS | 48 | 140 | 20,172,800 | n=int(input())
a=int(input())
b=int(input())
c=int(input())
n-=1
s=1
an=0
while n:
if s==1:
if a<b:
s=2
an+=a
else:
s=3
an+=b
n-=1
elif s==2:
if a<c:
s=1
an+=a
else:
s=3
an+=c
n-=1
else:
if b<c:
s=1
an+=b
else:
s=2
an+=c
n-=1
print(an)
... | Title: Trip For Meal
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair... | ```python
n=int(input())
a=int(input())
b=int(input())
c=int(input())
n-=1
s=1
an=0
while n:
if s==1:
if a<b:
s=2
an+=a
else:
s=3
an+=b
n-=1
elif s==2:
if a<c:
s=1
an+=a
else:
s=3
an+=c
n-=1
else:
if b<c:
s=1
an+=b
else:
s=2
an+=c
n-=1
print(an)
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
698 | A | Vacations | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is close... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where:
- *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the co... | Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days, - to write the contest on any two consecutive days. | [
"4\n1 3 2 0\n",
"7\n1 3 3 2 1 2 3\n",
"2\n2 2\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya ca... | 500 | [
{
"input": "4\n1 3 2 0",
"output": "2"
},
{
"input": "7\n1 3 3 2 1 2 3",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "10\n0 0 1 1 0 0 0 0 1 0",
"output": "8"
},
{
"input": "100\n3 2 3 3 3 2 3 1 ... | 1,650,364,772 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 88 | 62 | 614,400 | import enum
import sys
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_list(): return list(map(int, sys.stdin.readline().strip().split()))
def get_string(): return sys.stdin.readline().strip()
def get_int(): return int(sys.stdin.readline().strip())
def get_list_strings(): return list(map(s... | Title: Vacations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Int... | ```python
import enum
import sys
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_list(): return list(map(int, sys.stdin.readline().strip().split()))
def get_string(): return sys.stdin.readline().strip()
def get_int(): return int(sys.stdin.readline().strip())
def get_list_strings(): return ... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
251 | A | Points on Line | PROGRAMMING | 1,300 | [
"binary search",
"combinatorics",
"two pointers"
] | null | null | Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*.
Note that the order of the points inside the group of three chosen... | The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got.
It is guaranteed that the coordinates of the points in the input stri... | Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 3\n1 2 3 4\n",
"4 2\n-3 -2 -1 0\n",
"5 19\n1 10 20 30 50\n"
] | [
"4\n",
"2\n",
"1\n"
] | In the first sample any group of three points meets our conditions.
In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.
In the third sample only one group does: {1, 10, 20}. | 500 | [
{
"input": "4 3\n1 2 3 4",
"output": "4"
},
{
"input": "4 2\n-3 -2 -1 0",
"output": "2"
},
{
"input": "5 19\n1 10 20 30 50",
"output": "1"
},
{
"input": "10 5\n31 36 43 47 48 50 56 69 71 86",
"output": "2"
},
{
"input": "10 50\n1 4 20 27 65 79 82 83 99 100",
"... | 1,588,550,251 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 184 | 307,200 | def main():
n, d = [int(x) for x in input().split()]
pontos = [int(x) for x in input().split()]
print(solve(n, d, pontos))
def solve(n, d, pontos):
posib = 0
for i in range(len(pontos)):
max_p3 = pontos[i] + d
i_max_p3 = limite_p3(pontos, max_p3)
num_elem = (i_max_p3 - i... | Title: Points on Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two fart... | ```python
def main():
n, d = [int(x) for x in input().split()]
pontos = [int(x) for x in input().split()]
print(solve(n, d, pontos))
def solve(n, d, pontos):
posib = 0
for i in range(len(pontos)):
max_p3 = pontos[i] + d
i_max_p3 = limite_p3(pontos, max_p3)
num_elem = (i_... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
63 | A | Sinking Ship | PROGRAMMING | 900 | [
"implementation",
"sortings",
"strings"
] | A. Sinking Ship | 2 | 256 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a stri... | The first line contains an integer *n*, which is the number of people in the crew (1<=≤<=*n*<=≤<=100). Then follow *n* lines. The *i*-th of those lines contains two words — the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spa... | Print *n* lines. The *i*-th of them should contain the name of the crew member who must be the *i*-th one to leave the ship. | [
"6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman\n"
] | [
"Teddy\nAlice\nBob\nJulia\nCharlie\nJack\n"
] | none | 500 | [
{
"input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman",
"output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack"
},
{
"input": "1\nA captain",
"output": "A"
},
{
"input": "1\nAbcdefjhij captain",
"output": "Abcdefjhij"
},
{
"input": "5\nA captain... | 1,643,884,856 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | a = int(input())
li = []
for i in range(a):
li.append(input().split(' '))
print(li)
ans_l = []
for i in range(len(li)):
if (li[i][1] == 'rat'):
ans_l.append(li[i][0])
li.remove(li[i])
for i in li:
if (li[i][1] == 'woman' or li[i][1] == 'child'):
ans_l.append(li[i][0])
li.pop(... | Title: Sinking Ship
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to ... | ```python
a = int(input())
li = []
for i in range(a):
li.append(input().split(' '))
print(li)
ans_l = []
for i in range(len(li)):
if (li[i][1] == 'rat'):
ans_l.append(li[i][0])
li.remove(li[i])
for i in li:
if (li[i][1] == 'woman' or li[i][1] == 'child'):
ans_l.append(li[i][0])
... | -1 | MatrixStudio/Codeforces-Python-Submissions |
476 | A | Dreamoon and Stairs | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*.
What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition? | The single line contains two space separated integers *n*, *m* (0<=<<=*n*<=≤<=10000,<=1<=<<=*m*<=≤<=10). | Print a single integer — the minimal number of moves being a multiple of *m*. If there is no way he can climb satisfying condition print <=-<=1 instead. | [
"10 2\n",
"3 5\n"
] | [
"6\n",
"-1\n"
] | For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}.
For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5. | 500 | [
{
"input": "10 2",
"output": "6"
},
{
"input": "3 5",
"output": "-1"
},
{
"input": "29 7",
"output": "21"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "10000 2",
"output": "5000"
},
{
"input": "10000 ... | 1,693,878,221 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 77 | 0 | n, m = map(int, input().split())
if n == m:
print(n)
elif m > n:
print("-1")
else:
print(m * 3)
| Title: Dreamoon and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*.
What is the minimal number of moves making him climb ... | ```python
n, m = map(int, input().split())
if n == m:
print(n)
elif m > n:
print("-1")
else:
print(m * 3)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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,669,887,298 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 46 | 0 | num1 = input()
num2 = input()
num3 = ""
for index in range(len(num1)):
if num1[index] == num2[index]:
num3 += "0"
else:
num3 += "1"
print(num3) | 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
num1 = input()
num2 = input()
num3 = ""
for index in range(len(num1)):
if num1[index] == num2[index]:
num3 += "0"
else:
num3 += "1"
print(num3)
``` | 3.9885 | MatrixStudio/Codeforces-Python-Submissions |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,628,848,894 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 6,656,000 | import math
a= input().split()
b = int(a[1])
a = int(a[0])
c = (a*b)/2.0
print(math.ceil(c)) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
import math
a= input().split()
b = int(a[1])
a = int(a[0])
c = (a*b)/2.0
print(math.ceil(c))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
378 | A | Playing with Dice | PROGRAMMING | 800 | [
"brute force"
] | null | null | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many w... | The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. | Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. | [
"2 5\n",
"2 4\n"
] | [
"3 0 3\n",
"2 1 3\n"
] | The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | 500 | [
{
"input": "2 5",
"output": "3 0 3"
},
{
"input": "2 4",
"output": "2 1 3"
},
{
"input": "5 3",
"output": "2 1 3"
},
{
"input": "1 6",
"output": "3 0 3"
},
{
"input": "5 1",
"output": "3 1 2"
},
{
"input": "6 3",
"output": "2 0 4"
},
{
"inp... | 1,594,458,300 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 77 | 6,656,000 | a, b= list(map(int, input().split()))
player1= 0
t= 0
player2= 0
for i in range(1,7):
if abs(a- i) < abs(b-i):
player1+=1
elif abs(a-i)> abs(b-i):
player2+=1
elif a-i == -1 and b-i == 1:
t+=1
print(player1 , t , player2)
| Title: Playing with Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same diff... | ```python
a, b= list(map(int, input().split()))
player1= 0
t= 0
player2= 0
for i in range(1,7):
if abs(a- i) < abs(b-i):
player1+=1
elif abs(a-i)> abs(b-i):
player2+=1
elif a-i == -1 and b-i == 1:
t+=1
print(player1 , t , player2)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
592 | A | PawnChess | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named «PawnChess».
This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of every game some black and white pawns are placed on the board. The number of black pawns placed... | The input consists of the board description given in eight lines, each line contains eight characters. Character 'B' is used to denote a black pawn, and character 'W' represents a white pawn. Empty cell is marked with '.'.
It's guaranteed that there will not be white pawns on the first row neither black pawns on the ... | Print 'A' if player A wins the game on the given board, and 'B' if player B will claim the victory. Again, it's guaranteed that there will always be a winner on the given board. | [
"........\n........\n.B....B.\n....W...\n........\n..W.....\n........\n........\n",
"..B.....\n..W.....\n......B.\n........\n.....W..\n......B.\n........\n........\n"
] | [
"A\n",
"B\n"
] | In the first sample player A is able to complete his goal in 3 steps by always moving a pawn initially located at (4, 5). Player B needs at least 5 steps for any of his pawns to reach the row 8. Hence, player A will be the winner. | 500 | [
{
"input": ".BB.B.B.\nB..B..B.\n.B.BB...\nBB.....B\nBBB....B\nB..BB...\nBB.B...B\n....WWW.",
"output": "B"
},
{
"input": "B.B.BB.B\nW.WWW.WW\n.WWWWW.W\nW.BB.WBW\n.W..BBWB\nBB.WWBBB\n.W.W.WWB\nWWW..WW.",
"output": "A"
},
{
"input": "BB..BB..\nBW.W.W.B\n..B.....\n.....BB.\n.B..B..B\n......... | 1,446,309,754 | 754 | Python 3 | OK | TESTS | 56 | 93 | 921,600 |
import math
from decimal import *
import sys
S=set()
mw = 100
mb = 100
B=[]
for i in range(0,8):
A=input()
B.append(A)
for j in range(0,8):
k = A[j]
if k == 'W' and j not in S:
if i < mw:
mw=i
S.add(j)
if k == 'B' and j not ... | Title: PawnChess
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named «PawnChess».
This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of ... | ```python
import math
from decimal import *
import sys
S=set()
mw = 100
mb = 100
B=[]
for i in range(0,8):
A=input()
B.append(A)
for j in range(0,8):
k = A[j]
if k == 'W' and j not in S:
if i < mw:
mw=i
S.add(j)
if k == 'B' ... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
31 | A | Worms Evolution | PROGRAMMING | 1,200 | [
"implementation"
] | A. Worms Evolution | 2 | 256 | Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to ... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of worm's forms. The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000) — lengths of worms of each form. | Output 3 distinct integers *i* *j* *k* (1<=≤<=*i*,<=*j*,<=*k*<=≤<=*n*) — such indexes of worm's forms that *a**i*<==<=*a**j*<=+<=*a**k*. If there is no such triple, output -1. If there are several solutions, output any of them. It possible that *a**j*<==<=*a**k*. | [
"5\n1 2 3 5 7\n",
"5\n1 8 1 5 1\n"
] | [
"3 2 1\n",
"-1\n"
] | none | 500 | [
{
"input": "5\n1 2 3 5 7",
"output": "3 2 1"
},
{
"input": "5\n1 8 1 5 1",
"output": "-1"
},
{
"input": "4\n303 872 764 401",
"output": "-1"
},
{
"input": "6\n86 402 133 524 405 610",
"output": "6 4 1"
},
{
"input": "8\n217 779 418 895 996 473 3 22",
"output":... | 1,527,953,431 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 122 | 7,065,600 | # python 3
"""
"""
def worms_evolution(n_int, worm_len_list) -> tuple:
for i in range(len(worm_len_list)):
for j in range(len(worm_len_list)):
for k in range(len(worm_len_list)):
if i != j and j != k and k != i and worm_len_list[i] == worm_len_list[j] + worm_len_list[k]:
... | Title: Worms Evolution
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his... | ```python
# python 3
"""
"""
def worms_evolution(n_int, worm_len_list) -> tuple:
for i in range(len(worm_len_list)):
for j in range(len(worm_len_list)):
for k in range(len(worm_len_list)):
if i != j and j != k and k != i and worm_len_list[i] == worm_len_list[j] + worm_len_list[... | -1 | MatrixStudio/Codeforces-Python-Submissions |
466 | C | Number of Ways | PROGRAMMING | 1,700 | [
"binary search",
"brute force",
"data structures",
"dp",
"two pointers"
] | null | null | You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices *i*,<=*j* (2<=≤<=*i*<=≤<=... | The first line contains integer *n* (1<=≤<=*n*<=≤<=5·105), showing how many numbers are in the array. The second line contains *n* integers *a*[1], *a*[2], ..., *a*[*n*] (|*a*[*i*]|<=≤<=<=109) — the elements of array *a*. | Print a single integer — the number of ways to split the array into three parts with the same sum. | [
"5\n1 2 3 0 3\n",
"4\n0 1 -1 0\n",
"2\n4 1\n"
] | [
"2\n",
"1\n",
"0\n"
] | none | 1,500 | [
{
"input": "5\n1 2 3 0 3",
"output": "2"
},
{
"input": "4\n0 1 -1 0",
"output": "1"
},
{
"input": "2\n4 1",
"output": "0"
},
{
"input": "9\n0 0 0 0 0 0 0 0 0",
"output": "28"
},
{
"input": "10\n2 5 -2 2 -3 -2 3 5 -5 -2",
"output": "0"
},
{
"input": "1\... | 1,697,686,324 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 8,908,800 | n = int(input())
i = 0
temp = input()
arr = temp.split()
sum = 0
check = 0
while i < n:
sum = sum + int(arr[i])
i = i + 1
if sum % 3 != 0:
print(0)
elif sum % 3 == 0:
split = sum/3
i = 0
sum1 = 0
sum2 = 0
sum3 = 0
check = 0
while i <= (n-3):
sum1 ... | Title: Number of Ways
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the s... | ```python
n = int(input())
i = 0
temp = input()
arr = temp.split()
sum = 0
check = 0
while i < n:
sum = sum + int(arr[i])
i = i + 1
if sum % 3 != 0:
print(0)
elif sum % 3 == 0:
split = sum/3
i = 0
sum1 = 0
sum2 = 0
sum3 = 0
check = 0
while i <= (n-3):
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
75 | A | Life Without Zeros | PROGRAMMING | 1,000 | [
"implementation"
] | A. Life Without Zeros | 2 | 256 | Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c*... | The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*. | The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise. | [
"101\n102\n",
"105\n106\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "101\n102",
"output": "YES"
},
{
"input": "105\n106",
"output": "NO"
},
{
"input": "544\n397",
"output": "YES"
},
{
"input": "822\n280",
"output": "NO"
},
{
"input": "101\n413",
"output": "NO"
},
{
"input": "309\n139",
"output": "NO"
}... | 1,656,725,070 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 154 | 0 | f=lambda x:int(''.join(list(str(x).split('0'))))
a,b=int(input()),int(input())
print('YNEOS'[f(a)+f(b)!=f(a+b)::2]) | Title: Life Without Zeros
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assu... | ```python
f=lambda x:int(''.join(list(str(x).split('0'))))
a,b=int(input()),int(input())
print('YNEOS'[f(a)+f(b)!=f(a+b)::2])
``` | 3.9615 | MatrixStudio/Codeforces-Python-Submissions |
32 | A | Reconnaissance | PROGRAMMING | 800 | [
"brute force"
] | A. Reconnaissance | 2 | 256 | According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob has *n* soldiers in his detachment. Their heights are *a*1,<=*a*2,<=...,<=*a**n* centimeters. Som... | The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*d*<=≤<=109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains *n* space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 1... | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed *d*. | [
"5 10\n10 20 50 60 65\n",
"5 1\n55 30 29 31 55\n"
] | [
"6\n",
"6\n"
] | none | 500 | [
{
"input": "5 10\n10 20 50 60 65",
"output": "6"
},
{
"input": "5 1\n55 30 29 31 55",
"output": "6"
},
{
"input": "6 10\n4 6 4 1 9 3",
"output": "30"
},
{
"input": "7 100\n19 1694 261 162 1 234 513",
"output": "8"
},
{
"input": "8 42\n37 53 74 187 568 22 5 65",
... | 1,645,527,565 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 436 | 0 | n,d=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
a=0
for i in range(n-1):
for j in range(i+1,n):
if (l[j]-l[i])<=d:
a+=1
else:
break
print(2*a)
| Title: Reconnaissance
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob h... | ```python
n,d=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
a=0
for i in range(n-1):
for j in range(i+1,n):
if (l[j]-l[i])<=d:
a+=1
else:
break
print(2*a)
``` | 3.891 | MatrixStudio/Codeforces-Python-Submissions |
863 | B | Kayaking | PROGRAMMING | 1,500 | [
"brute force",
"greedy",
"sortings"
] | null | null | Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exact... | The first line contains one number *n* (2<=≤<=*n*<=≤<=50).
The second line contains 2·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=≤<=*w**i*<=≤<=1000). | Print minimum possible total instability. | [
"2\n1 2 3 4\n",
"4\n1 3 4 6 3 4 100 200\n"
] | [
"1\n",
"5\n"
] | none | 0 | [
{
"input": "2\n1 2 3 4",
"output": "1"
},
{
"input": "4\n1 3 4 6 3 4 100 200",
"output": "5"
},
{
"input": "3\n305 139 205 406 530 206",
"output": "102"
},
{
"input": "3\n610 750 778 6 361 407",
"output": "74"
},
{
"input": "5\n97 166 126 164 154 98 221 7 51 47",
... | 1,649,094,112 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 217 | 0 | from cmath import inf
n=int(input())*2
p=list(map(int,input().split()))
p.sort()
m=inf
for i in range(n-1):
for j in range(i+1,n):
stab = 0
e=True
for k in range(n):
if k == i or k == j: continue
if e: stab -= p[k]
else: stab += p[k]
e=not e
m=min(m,stab)
print(m... | Title: Kayaking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they hav... | ```python
from cmath import inf
n=int(input())*2
p=list(map(int,input().split()))
p.sort()
m=inf
for i in range(n-1):
for j in range(i+1,n):
stab = 0
e=True
for k in range(n):
if k == i or k == j: continue
if e: stab -= p[k]
else: stab += p[k]
e=not e
m=min(m,stab... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
621 | B | Wet Shark and Bishops | PROGRAMMING | 1,300 | [
"combinatorics",
"implementation"
] | null | null | Today, Wet Shark is given *n* bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right.
Wet Shark thinks that two bishops attack each other if they share the same diagonal. Note, that this is the o... | The first line of the input contains *n* (1<=≤<=*n*<=≤<=200<=000) — the number of bishops.
Each of next *n* lines contains two space separated integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the number of row and the number of column where *i*-th bishop is positioned. It's guaranteed that no two bishops ... | Output one integer — the number of pairs of bishops which attack each other. | [
"5\n1 1\n1 5\n3 3\n5 1\n5 5\n",
"3\n1 1\n2 3\n3 5\n"
] | [
"6\n",
"0\n"
] | In the first sample following pairs of bishops attack each other: (1, 3), (1, 5), (2, 3), (2, 4), (3, 4) and (3, 5). Pairs (1, 2), (1, 4), (2, 5) and (4, 5) do not attack each other because they do not share the same diagonal. | 1,000 | [
{
"input": "5\n1 1\n1 5\n3 3\n5 1\n5 5",
"output": "6"
},
{
"input": "3\n1 1\n2 3\n3 5",
"output": "0"
},
{
"input": "3\n859 96\n634 248\n808 72",
"output": "0"
},
{
"input": "3\n987 237\n891 429\n358 145",
"output": "0"
},
{
"input": "3\n411 81\n149 907\n611 114"... | 1,513,762,751 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 24,064,000 | n = int(input())
elements = []
for _ in range(n):
elements.append(list(map(int, input().split())))
ans = 0
for a in elements:
for b in elements:
if a == b:
continue
if abs(a[0] - b[0]) == abs(a[1] - b[1]):
ans += 1
ans /= 2
print(int(ans))
| Title: Wet Shark and Bishops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, Wet Shark is given *n* bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right.
We... | ```python
n = int(input())
elements = []
for _ in range(n):
elements.append(list(map(int, input().split())))
ans = 0
for a in elements:
for b in elements:
if a == b:
continue
if abs(a[0] - b[0]) == abs(a[1] - b[1]):
ans += 1
ans /= 2
print(int(ans))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.