problem stringlengths 29 9.39k | language int64 1 3 | solution stringlengths 7 465k |
|---|---|---|
You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the socia... | 3 | n = int(input())
s = input()
k = 0
for i in range(n - 2):
if s[i: i + 3] == "xxx":
k += 1
print(k) |
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
<image>
You should count, how many there are pai... | 3 | n, m = map(int, input().split())
c=0
for i in range(n+1):
a=i;b=n-(a*a)
if b<0:
break
else:
p=(b*b)+a
if p==m:
c+=1
print(c) |
Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1 ≤ i ≤ n) he makes ai money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence ai. Let us remind you that the subsegment of the sequence is it... | 3 | useless = int(input())
s = list(map(int, input().split()))
c = 10 ** 9
max_length = 1
length = 1
for n in s:
if c <= n:
length += 1
else:
length = 1
c = n
max_length = max(length, max_length)
print(max_length)
|
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has on... | 3 | if __name__ == '__main__':
n=int(input())
a=[]
if n in range(1987,2013):
print("2013")
else:
flag=1
while flag!=0:
flag=0
n=n+1
i=n
a.clear()
while i>0:
v=i%10
if v in a:
... |
This problem is same as the next one, but has smaller constraints.
It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system cons... | 3 | def gcd(x,y):
while y:
x,y=y,x%y
return x
def frac(a,b):
x=gcd(a,b)
return (a//x,b//x)
n=int(input())
coords=[]
for i in range(n):
coords.append(tuple(map(int,input().split())))
slopes={}
for i in range(n):
for j in range(i+1,n):
x1,y1=coords[i][0],coords[i][1]
x2,y2=coor... |
You have a pot and N ingredients. Each ingredient has a real number parameter called value, and the value of the i-th ingredient (1 \leq i \leq N) is v_i.
When you put two ingredients in the pot, they will vanish and result in the formation of a new ingredient. The value of the new ingredient will be (x + y) / 2 where... | 3 | N = int(input())
v = sorted(list(map(int, input().split())))
s = v[0]
for i in range(1, N):
s = (s + v[i])/2
print(s)
|
"Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of n participants took part in the contest (n ≥ k), and you already know their scores. Calculate how many ... | 3 | def next_round(n, k, a):
passed = 0
for i in range(k):
if a[i] > 0:
passed += 1
else:
return passed
for i in range(k, n):
if a[i] > 0 and a[i] == a[k-1]:
passed += 1
else:
return passed
return passed
n, k = map(int, input... |
Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had c pages.
At first day Mister B read v0 pages, but after that he started to speed up. Every day, starting from the second, he read a pages more than on the previous day (at first day he read v0 pages, at second —... | 3 | c, v, v1, a, l = map(int, input().split())
for i in range(1, 1000000):
c -= v
if i > 1:
c += l
if c <= 0:
print(i)
break
v += a
v = min(v, v1) |
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters.... | 3 | s = input()
b1 = s[0].upper()
print(b1+s[1:]) |
There are n distinct points on a coordinate line, the coordinate of i-th point equals to x_i. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset co... | 3 | n = int(input())
L = [int(x) for x in input().split()]
D = {}
for i in L:
D[i] = 1
best = 1
guy = None
for i in L:
for j in range(0,32):
temp = 1+((i+2**j) in D)+((i-2**j) in D)
if temp > best:
best = temp
guy = (i,j)
if best == 3:
print(3)
i,j = guy
print(i-... |
Polygon is not only the best platform for developing problems but also a square matrix with side n, initially filled with the character 0.
On the polygon, military training was held. The soldiers placed a cannon above each cell in the first row and a cannon to the left of each cell in the first column. Thus, exactly 2... | 3 | ###########{BHOLE KI FAUJ KREGI MAUJ}########
from sys import stdin,stdout
import math,queue,heapq
fastinput=stdin.readline
fastout=stdout.write
t=int(fastinput())
while t:
t-=1
n=int(fastinput())
a=[]
for _ in range(n):
a.append(fastinput())
flag=True
for i in range(n-1):
... |
You are given a string s of length n, which consists only of the first k letters of the Latin alphabet. All letters in string s are uppercase.
A subsequence of string s is a string that can be derived from s by deleting some of its symbols without changing the order of the remaining symbols. For example, "ADE" and "BD... | 3 | from collections import Counter
n, k = map(int, input().split())
cnt = Counter(input())
if len(cnt) < k:
print(0)
else:
print(min(cnt.values()) * k) |
Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and n water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pours all water from it into the cup. If the cup overfills, then we assume that... | 3 | n , m = list(map(int,input().split()))
l = list(map(int,input().split()))
count = 0
for i in l:
count += i
a = count-max(l)
if a<=m:
print("YES")
else:print("NO") |
Alice guesses the strings that Bob made for her.
At first, Bob came up with the secret string a consisting of lowercase English letters. The string a has a length of 2 or more characters. Then, from string a he builds a new string b and offers Alice the string b so that she can guess the string a.
Bob builds b from a... | 3 | t=int(input())
while(t):
s=input()
for x in range(len(s)):
if(x%2==0):
print(s[x],end="")
print(s[-1])
t-=1 |
Let LCM(x, y) be the minimum positive integer that is divisible by both x and y. For example, LCM(13, 37) = 481, LCM(9, 6) = 18.
You are given two integers l and r. Find two integers x and y such that l ≤ x < y ≤ r and l ≤ LCM(x, y) ≤ r.
Input
The first line contains one integer t (1 ≤ t ≤ 10000) — the number of tes... | 3 | t = int(input())
for _ in range(t):
l, r = map(int, input().split())
if 2*l <= r:
print(l, 2*l)
else:
print(-1, -1)
|
Perhaps many have heard that the World Biathlon Championship has finished. Although our hero Valera was not present at this spectacular event himself and only watched it on TV, it excited him so much that he decided to enroll in a biathlon section.
Of course, biathlon as any sport, proved very difficult in practice. I... | 1 | #!/usr/bin/env python2
# -*- coding: utf-8 -*-
from bisect import bisect_left
import sys
input = sys.stdin
output = sys.stdout
def circle_contains_point(c,p):
X,R,_ = c
x,y = p
return (x-X)**2 + y**2 <= R**2
def solve(T,S):
T.sort(key = lambda c: c[0])
centers = [c[0] for c in T]
n = len(... |
There is a grid with H rows and W columns, where each square is painted black or white.
You are given H strings S_1, S_2, ..., S_H, each of length W. If the square at the i-th row from the top and the j-th column from the left is painted black, the j-th character in the string S_i is `#`; if that square is painted whi... | 3 | import sys
sys.setrecursionlimit(1000000)
H,W=map(int,input().split())
board=[]
check=[[None]*W for i in range(H)]
answer=0
for i in range(H):
S=list(input())
board.append(S)
def dfs(i,j,color):
if not (0<=i<H and 0<=j<W):
return 0,0
if board[i][j]==color:
return 0,0
if check[i][j]:
return 0... |
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 d1 meter long road between his house and the first shop and a d2 meter long road between his house and the second shop. Also, there is a road of length ... | 3 | import sys
d1,d2,d3=map(int,sys.stdin.readline().split())
suma=0
if d1<d2:
suma+=d1
if d1+d2<=d3:
suma+=d1+2*d2
else:
suma+=d3
if d3+d1<=d2:
suma+=d3+d1
else:
suma+=d2
else:
suma+=d2
if d1+d2<=d3:
suma+=d2+2*d1
else:
suma+=d3
if d3+d2<=d1:
suma+=d3+d2
else:
... |
You are given an array a of length n.
You are also given a set of distinct positions p_1, p_2, ..., p_m, where 1 ≤ p_i < n. The position p_i means that you can swap elements a[p_i] and a[p_i + 1]. You can apply this operation any number of times for each of the given positions.
Your task is to determine if it is poss... | 3 | #!/usr/bin/python
# -*- coding: utf-8 -*-
def run_case():
n, m = map(int, input().split(' ')) # skip n and m
a = list(map(int, input().split(' ')))
p = list(map(int, input().split(' ')))
conn = [False] * n
for i in p:
conn[i - 1] = True
for i in range(n - 1):
if not conn[i]... |
This is the easy version of the problem. The difference between versions is the constraints on n and a_i. You can make hacks only if all versions of the problem are solved.
First, Aoi came up with the following idea for the competitive programming problem:
Yuzu is a girl who collecting candies. Originally, she has x ... | 3 | #!/usr/bin/env pypy3
n, p = input().split(' ')
N = int(n)
P = int(p)
A = input().split(' ')
A = sorted(list(map(int, A)))
from math import factorial
def factorial(n, MODULUS):
ret = 1
for i in range(1, n+1):
ret = (ret*i) % MODULUS
return ret
good_x = []
MODULUS = P
from functools import lru... |
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
* Tetrahedron. Tetrahedron has 4 triangular faces.
* Cube. Cube has 6 square faces.
* Octahedron. Octahedron has 8 triangular faces.
* Dodecahedron. Dodecahedron has 12 pentagonal faces.
*... | 3 | dic={"Tetrahedron":4 , "Cube":6 , "Octahedron":8 , "Dodecahedron":12,"Icosahedron":20}
n=int(input())
sum=0
for i in range(n):
sum =sum+dic[input()]
print(sum) |
Fafa owns a company that works on huge projects. There are n employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best l employ... | 3 | #!/usr/bin/env python3
# CodeForce 935/A
# Fafa and his company
# str4nge
def main():
n = int(input())
ans = 1
for i in range(2, (n // 2) + 1):
if((n - i) % i == 0):
ans += 1
print(ans)
if __name__ == "__main__":
main()
|
n students are taking an exam. The highest possible score at this exam is m. Let a_{i} be the score of the i-th student. You have access to the school database which stores the results of all students.
You can change each student's score as long as the following conditions are satisfied:
* All scores are integers ... | 3 | t=int(input())
for i in range(t):
l1=list(map(int,input().split()))
n=l1[0]
m=l1[1]
l=list(map(int,input().split()))
avg=sum(l)/n
a=l[1:n+1]
s=sum(a)
b=m-l[0]
t=True
while t:
if b<=s:
print(m)
t=False
else:
m=m-1
b=b... |
We have N switches with "on" and "off" state, and M bulbs. The switches are numbered 1 to N, and the bulbs are numbered 1 to M.
Bulb i is connected to k_i switches: Switch s_{i1}, s_{i2}, ..., and s_{ik_i}. It is lighted when the number of switches that are "on" among these switches is congruent to p_i modulo 2.
How ... | 3 | n,m=map(int,input().split())
ks=[list(map(int,input().split())) for i in range(m)]
p=list(map(int,input().split()))
ans=0
for i in range(2**n):
q=[0]*n
for j in range(n):
if i>>j&1:
q[j]=1
for j in range(m):
cnt=0
for k in ks[j][1:]:
if q[k-1]==1:
cnt+=1
if cnt%2!=p[j]%2:
... |
"Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of n participants took part in the contest (n ≥ k), and you already know their scores. Calculate how many ... | 3 | def get_values():
nums = list(map(str, input().split()))
n, k = int(nums[0]), int(nums[1])
if n > 50 or n <1 or k > 50 or k < 1:
return
scores = list(map(str, input().split()))
return get_score(scores, k)
def get_score(sc, k):
for i in range(len(sc)):
sc[i] = int(sc[i])
base = sc[k -1]
counter = 0
for i i... |
You have a plate and you want to add some gilding to it. The plate is a rectangle that we split into w× h cells. There should be k gilded rings, the first one should go along the edge of the plate, the second one — 2 cells away from the edge and so on. Each ring has a width of 1 cell. Formally, the i-th of these rings ... | 3 | w, h, k = map(int, input().split())
i = 1
r = 0
for i in range(1, k + 1):
w1 = w - 4 * (i - 1)
h1 = h - 4 * (i - 1)
r += 2 * w1 + 2 * h1 - 4
print(r)
|
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subse... | 3 | n,m=[int(x) for x in input().split()]
x=[int(x) for x in input().split()][:n]
y=[int(x) for x in input().split()][:m]
for i in x:
if i in y:
print(i,end=" ") |
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... | 3 | s=input()
l=0
u=0
for i in (s):
if i.islower() :
l+=1
elif i.isupper() :
u+=1
if u<=l :
s=s.lower()
else :
s=s.upper()
print(s)
|
"Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of n participants took part in the contest (n ≥ k), and you already know their scores. Calculate how many ... | 3 | a=input().split()
first=int(a[0])
second=int(a[1])-1
l=list(map(int,input().rstrip().split()))
c=0
d=l[second]
for i in range(0,first):
if(l[i]>=d and l[i]>0):
c=c+1
print(c)
|
Lee was cleaning his house for the party when he found a messy string under the carpets. Now he'd like to make it clean accurately and in a stylish way...
The string s he found is a binary string of length n (i. e. string consists only of 0-s and 1-s).
In one move he can choose two consecutive characters s_i and s_{i... | 3 | for _ in range(int(input())):
n = int(input())
s = input()
l, r, ans = 1, 1, 0
for i in range(n-1):
if(s[i] > s[i+1]):
ans = 1
break
if not(ans):
print(s)
else:
for i in range(n):
if (s[i] == '1'):
l = i
... |
You have a large electronic screen which can display up to 998244353 decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of 7 segments which can be turned on and off to compose different digits. The following picture describes how you can dis... | 3 | for n in[*open(0)][1:]:n=int(n)-1;print('71'[n%2]+'1'*(n-1>>1)) |
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and ... | 3 | data=[]
for i in range(5):
data.append(int(input()))
count=0
for i in range(1 , data[4] +1):
if i % data[0]==0:
count += 1
elif i%data[1]==0:
count += 1
elif i%data[2]==0:
count += 1
elif i%data[3]==0:
count +=1
else:
continue
... |
Polycarp knows that if the sum of the digits of a number is divisible by 3, then the number itself is divisible by 3. He assumes that the numbers, the sum of the digits of which is divisible by 4, are also somewhat interesting. Thus, he considers a positive integer n interesting if its sum of digits is divisible by 4.
... | 3 | def check(a):
s=0
while(a):
s=s+a%10
a=int(a/10)
if(s%4==0):
return 1
else:
return 0
n=int(input())
for i in range(n,n+100,1):
if(check(i)==1):
print(i)
break |
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ... | 1 | def games(n, values):
res = 0
for value in values:
res += len(filter(lambda x: x[1] == value[0], values))
return res
n = int(raw_input())
values = []
for i in xrange(n):
x = map(int, raw_input().split())
values.append(x)
print games(n, values) |
Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.
The phoenix has a rather long lifespan, and reincarnates itself once every a! years. Here a! denotes ... | 3 | a, b = input().split()
a = int(a)
b = int(b)
if (b-a)>=5:
print(0)
else:
x = b-a
y = 1
for i in range(x):
y = (y*(b-i))%10
print(y) |
Anton likes to play chess, and so does his friend Danik.
Once they have played n games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, who won more games, he or Danik? Help him determine this.
Input
The first line of the input contains a... | 3 | # -*- coding: utf-8 -*-
"""
Created on Tue Nov 5 17:49:46 2019
@author: 86138
"""
#734A Anton and Danik
m = input()
n = input()
a = n.count('A')
d = n.count('D')
if a > d:
print('Anton')
elif a < d:
print('Danik')
else:
print('Friendship') |
When Serezha was three years old, he was given a set of cards with letters for his birthday. They were arranged into words in the way which formed the boy's mother favorite number in binary notation. Serezha started playing with them immediately and shuffled them because he wasn't yet able to read. His father decided t... | 3 | n=int(input())
L=[i for i in input()]
ch='1 '*L.count('n')+'0 '*L.count('r')
print(ch)
|
You are given three strings s, t and p consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings.
During each operation you choose any character from p, erase it from p and insert it into string s (you may insert this character anywhere you want: in the beginning of... | 3 | def is_subseq(x, y):
it = iter(y)
return all(c in it for c in x)
q = int(input())
for i in range(q):
s = input()
t = input()
p = input()
dt = {chr(i):0 for i in range(ord('a'),ord('z')+1)}
ds = {chr(i):0 for i in range(ord('a'),ord('z')+1)}
dp = {chr(i):0 for i in range(ord('a'),ord('z'... |
Arkady coordinates rounds on some not really famous competitive programming platform. Each round features n problems of distinct difficulty, the difficulties are numbered from 1 to n.
To hold a round Arkady needs n new (not used previously) problems, one for each difficulty. As for now, Arkady creates all the problems... | 3 | n , m = [int(i) for i in input().split(' ')]
lista = [int(i) - 1 for i in input().split(' ')] # 0-indexado
answer = ""
acumulados = [0] * n
quantidade_de_1 = 0
remaining = n
def verificar_maiores():
quantidade_maior = 0
for i in acumulados:
if i > quantidade_de_1:
quantidade_maior += 1
return quantidade_maior... |
There are some animals in a garden. Each of them is a crane with two legs or a turtle with four legs.
Takahashi says: "there are X animals in total in the garden, and they have Y legs in total." Determine whether there is a combination of numbers of cranes and turtles in which this statement is correct.
Constraints
... | 3 | X, Y = map(int, input().split())
print('Yes' if any([2*i + 4*(X-i) == Y for i in range(X+1)]) else 'No') |
You have a coins of value n and b coins of value 1. You always pay in exact change, so you want to know if there exist such x and y that if you take x (0 ≤ x ≤ a) coins of value n and y (0 ≤ y ≤ b) coins of value 1, then the total value of taken coins will be S.
You have to answer q independent test cases.
Input
The... | 3 | for q in range(int(input())):
l=list(map(int,input().split()))
a,b,n,s=l[0],l[1],l[2],l[3]
if s==a*n:
print('YES')
elif s>a*n:
if s-a*n<=b:
print('YES')
else:print('NO')
else:
r=s%n
if r<=b:
print('YES')
else:print('NO') |
When the curtains are opened, a canvas unfolds outside. Kanno marvels at all the blonde colours along the riverside — not tangerines, but blossoms instead.
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" ... | 3 | s=input()
if(len(s)<3):
print('No')
else:
flag=0
for i in range(len(s)-2):
if(s[i]!='.' and s[i+1]!='.' and s[i+2]!='.'):
a=set()
a.add(s[i])
a.add(s[i+1])
a.add(s[i+2])
if(len(a)==3):
flag=1
break
if(fla... |
You are given an array a_1, a_2, …, a_n.
In one operation you can choose two elements a_i and a_j (i ≠ j) and decrease each of them by one.
You need to check whether it is possible to make all the elements equal to zero or not.
Input
The first line contains a single integer n (2 ≤ n ≤ 10^5) — the size of the array.... | 3 | n = int(input())
A = [int(i) for i in input().split()]
ans = 0
s = sum(A)
m = max(A)
if s%2 != 0 or m > s - m:
print('NO')
else:
print('YES')
|
NN is an experienced internet user and that means he spends a lot of time on the social media. Once he found the following image on the Net, which asked him to compare the sizes of inner circles:
<image>
It turned out that the circles are equal. NN was very surprised by this fact, so he decided to create a similar pi... | 3 | from math import sin,pi
inp = input().split()
n,r = int(inp[0]),float(inp[1])
x = sin(pi/n)
print(r*x/(1 - x)) |
We have a 3×3 square grid, where each square contains a lowercase English letters. The letter in the square at the i-th row from the top and j-th column from the left is c_{ij}.
Print the string of length 3 that can be obtained by concatenating the letters in the squares on the diagonal connecting the top-left and bot... | 3 | C = open(0).read().split()
print(C[0][0] + C[1][1] + C[2][2]) |
Alice and Bob have decided to play the game "Rock, Paper, Scissors".
The game consists of several rounds, each round is independent of each other. In each round, both players show one of the following things at the same time: rock, paper or scissors. If both players showed the same things then the round outcome is a ... | 3 | import sys
try:sys.stdin,sys.stdout=open('in.txt','r'),open('out.txt','w')
except:pass
ii1=lambda:int(sys.stdin.readline().strip()) # for interger
is1=lambda:sys.stdin.readline().strip() # for str
iia=lambda:list(map(int,sys.stdin.readline().strip().split())) # for List[int]
isa=lambda:sys.stdin.readline().strip().spli... |
A company has N members, who are assigned ID numbers 1, ..., N.
Every member, except the member numbered 1, has exactly one immediate boss with a smaller ID number.
When a person X is the immediate boss of a person Y, the person Y is said to be an immediate subordinate of the person X.
You are given the information ... | 3 | N = int(input())
A= [0] * N
for i in map(int, input().split()):
i -= 1
A[i] += 1
for i in A:
print(i) |
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
* Tetrahedron. Tetrahedron has 4 triangular faces.
* Cube. Cube has 6 square faces.
* Octahedron. Octahedron has 8 triangular faces.
* Dodecahedron. Dodecahedron has 12 pentagonal faces.
*... | 3 | # ANTON AND POLYHEDRONS
res = 0
for i in range(int(input())):
s = input().strip()
if s=='Tetrahedron':
res += 4
elif s=='Cube':
res += 6
elif s=='Octahedron':
res += 8
elif s=='Dodecahedron':
res += 12
elif s=='Icosahedron':
res += 20
print(res)
|
Every person likes prime numbers. Alice is a person, thus she also shares the love for them. Bob wanted to give her an affectionate gift but couldn't think of anything inventive. Hence, he will be giving her a graph. How original, Bob! Alice will surely be thrilled!
When building the graph, he needs four conditions to... | 3 |
from math import sqrt
n = int(input())
def prost(n):
for i in range(2, int(sqrt(n)) + 1):
if n % i == 0:
return False
return True
f = n
while not prost(f):
f += 1
print(f)
for i in range(1, n):
print(i, i + 1)
print(n, 1)
g = 1
f = f - n
while f:
print(1 + g - 1, n - g)
g... |
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has n students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
The ... | 3 | n,k=map(int,input().split())
a=[int(i) for i in input().split()]
num=0
for i in range(n):
if a[i]+k<=5:
num+=1
print(num//3)
|
View Russian Translation
Little pig Benny has just taken a shower. Now she is going to buy some gifts for her relatives. But the problem is that Benny doesn't know how to reach to the gift shop. Her friend Mike has created a special set of instructions for her.
A set of instructions is a string which consists of lett... | 1 | S=raw_input()
count=0
pos=[0,0]
l={}
l[tuple(pos)]=1
for move in S:
#print 'move:', move
if move=='L':
pos[1] -= 1
if tuple(pos) in l:
count+=1
#print 'count, pos:',count, pos
else:
l[tuple(pos)]=1
#print 'l:', l
elif move=='R'... |
Recently, on a programming lesson little Petya showed how quickly he can create files and folders on the computer. But he got soon fed up with this activity, and he decided to do a much more useful thing. He decided to calculate what folder contains most subfolders (including nested folders, nested folders of nested fo... | 1 | import sys
def parc(x):
a, b = 0, 0
for v in x.itervalues():
c, d = parc(v)
a += 1
a += c
b += d
if b == 0:
b += 1
return a, b
dex = {}
for line in sys.stdin.readlines():
line = line.replace(':\\', 'x')[:-1]
a = dex
for fold in line.split('\\'):
if fold not in a:
a[fold] = ... |
SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is <image> for SmallR while <image> for Zanoes. The one who shoots in the target first should be the winner.
Output the probability th... | 3 | a,b,c,d=input().split(" ")
a=int(a)
b=int(b)
c=int(c)
d=int(d)
p=a/b
q=c/d
f=p*((1)/(1-(1-p)*(1-q)))
print(f) |
During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each... | 3 | number,time=map(int,input().split())
queue=list(input())
for i in range(time):
p=0
while p <len(queue)-1:
if queue[p]=='B' and queue[p+1]=='G':
queue[p]='G'
queue[p+1]='B'
p+=2
else:
p+=1
print(''.join(queue))
|
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.
The students don’t want to use too many blocks, but they also want to be uniq... | 1 | def gen23():
r = 2
while True:
yield r
yield r + 1
yield r + 2
yield r + 4
r += 6
n, m = map(int, raw_input().split())
maxn, maxm = 2*n, 3*m
for i in gen23():
if n == 0 or m == 0:
break
if i%6 == 0:
if maxn <= maxm:
maxn += 2
m -= 1
else:
maxm += 3
n -= 1
elif i%2 == 0:
n -= 1
else:... |
There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.
You can take and complete at most one of these jobs in a day.
However, you cannot retake a job that you have already done.
Find the maximum total reward that you can ea... | 3 | import heapq
n,m=map(int,input().split())
list=[[] for i in range(m)]
h=[]
for i in range(n):
a,b=map(int,input().split())
if a<=m:
list[a-1].append(-b)
ans=0
for i in range(m):
for j in list[i]:
heapq.heappush(h,j)
if h:
ans+=-heapq.heappop(h)
else:
continue
print(ans)
|
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... | 3 | l=[i for i in input()]
a=set(l)
j=len(a)
if (j%2==0):
print("CHAT WITH HER!")
else:
print ("IGNORE HIM!") |
Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg... | 3 | s,d=map(int,input().split())
l=list(map(int,input().split()))
p=min(l)
t=0
r=0
for i in range(s):
y=l[i]-p
r+=l[i]
if y%d==0:
if l[i]<p:
p=l[i]
else:
t+=1
u=r-(p*s)
if u%d==0 and t==0:
print(u//d)
elif s==1:
print(0)
else:
print(-1) |
One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one.
The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number i (... | 3 | n = int(input())
arr = list(map(int, input().split()))
dp = list([])
dp.append(0)
m = 1000000007
for i in range(1, n + 1):
dp.append(0)
dp[i] += sum(dp[arr[i - 1]:i]) % m + 2
print(sum(dp) % m) |
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum nu... | 3 | import math
n=int(input())
a=[int(x) for x in input().split()]
a1=a.count(1)
a2=a.count(2)
a3=a.count(3)
a4=a.count(4)
c=0
c+=a4
if(a3>a1):
a3=a3-a1
c=c+a1
a1=0
c=c+a3
else:
a1=a1-a3
c=c+a3
a3=0
if(a2>1):
k=int(a2/2)
kk=2*k
c=c+math.ceil(kk/2)
a2=a2-kk
if(a2==0... |
Phoenix has n coins with weights 2^1, 2^2, ..., 2^n. He knows that n is even.
He wants to split the coins into two piles such that each pile has exactly n/2 coins and the difference of weights between the two piles is minimized. Formally, let a denote the sum of weights in the first pile, and b denote the sum of weigh... | 3 | import math
import os
import random
import re
import sys
for _ in range(int(input())):
n = int(input())
ans = math.pow(2, n)
p = n
p1 = 1
while True:
if (p1 <= (n / 2 - 1)):
ans = ans - math.pow(2, p - 1) + math.pow(2, p1)
p1 += 1
else:
ans = ans ... |
Pasha has two hamsters: Arthur and Alexander. Pasha put n apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between the hamsters (as they may like the same apple), so he decided to distribute the apples between the hamste... | 3 | n, a, b = list(map(int, input().split()))
aa = list(map(int, input().split()))
ab = list(map(int, input().split()))
ans = [0] * n
for a in aa:
ans[a - 1] = '1'
for a in ab:
ans[a - 1] = '2'
print(' '.join(ans)) |
Santa Claus has n candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all n candies he has.
Input
The only line contains positive integ... | 3 | a=int(input())
# n2 + n -2*a
r=int((-1+(1+8*a)**0.5)//2)
print(r)
extra=a-(r*(r+1))//2
ans=[i for i in range(1,r+1)]
ans[-1]+=extra
print(*ans)
|
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police offi... | 3 | import sys
#sys.stdin= open("input.txt","r") #standard input
n = int(input())
l= [int(x) for x in input().split()]
police=0
crime=0
for i in l:
if i>=0:
police+=i
else:
if(police > 0):
police-=1
else:
crime+=1
print(crime )
|
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether thi... | 3 | n = input()
word = input().lower()
print('YES' if len(set(word)) == 26 else 'NO')
|
Takahashi is a teacher responsible for a class of N students.
The students are given distinct student numbers from 1 to N.
Today, all the students entered the classroom at different times.
According to Takahashi's record, there were A_i students in the classroom when student number i entered the classroom (including... | 3 | n=int (input())
a= list(map(int, input().strip().split()))
b=[0]*n
for i in range(n):
b[a[i]-1]=i+1
print(*b)
|
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi — a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (bec... | 3 | n = int(input())
X = []
X = list(map(int,input().split()))
for i in range(n):
maxx = max(abs(X[i]-X[0]),abs(X[i] - X[n-1]))
if i == 0:
minn = abs(X[i]-X[i+1])
elif i == n-1:
minn = abs(X[i]-X[i-1])
else:
minn = min(abs(X[i]-X[i-1]),abs(X[i] - X[i+1]))
print(minn," ",maxx) |
Screen resolution of Polycarp's monitor is a × b pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates (x, y) (0 ≤ x < a, 0 ≤ y < b). You can consider columns of pixels to be numbered from 0 to a-1, and rows — from 0 to b-1.
Polycarp wants to open a rectangular window of maximal size, which ... | 3 | T=(int(input()))
for i in range(0,T):
ls = list(map(int, input().split()))
w1 = max(ls[1]-ls[3]-1, ls[3])
l1 = max(ls[0]-ls[2]-1, ls[2])
print(max(w1*ls[0], l1*ls[1])) |
Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin.
The world can be represented by the first quadrant of a plane and the wall is built along the identity line (... | 3 | s = int(input())
lst = list(input())
x=-1
y=-1
mon = 0
z=0
for i in range(s-1):
if lst[i]=="U":
y+=1
elif lst[i]=="R":
x+=1
if x==y and lst[i]==lst[i+1]:
mon+=1
print(mon)
|
Manao has a monitor. The screen of the monitor has horizontal to vertical length ratio a:b. Now he is going to watch a movie. The movie's frame has horizontal to vertical length ratio c:d. Manao adjusts the view in such a way that the movie preserves the original frame ratio, but also occupies as much space on the scre... | 3 | #!/usr/bin/python3
import sys
from fractions import Fraction
a, b, c, d = map(int, sys.stdin.readline().strip().split())
d2 = Fraction(d*a, c)
ans = None
if d2 <= Fraction(b):
# fits left-to-right
ans = (Fraction(b) - d2) / Fraction(b)
else:
# fits top-to-bottom
c2 = Fraction(c*b, d)
ans = (Fracti... |
Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.
Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisi... | 3 | s=input()
if '1' in s:
a=s.index('1')
ans=0
for i in range(a+1,len(s)):
if s[i]=='0':
ans+=1
if ans>=6:
print("yes")
else:
print("no")
else:
print("no") |
Phoenix loves beautiful arrays. An array is beautiful if all its subarrays of length k have the same sum. A subarray of an array is any sequence of consecutive elements.
Phoenix currently has an array a of length n. He wants to insert some number of integers, possibly zero, into his array such that it becomes beautifu... | 3 | t=int(input())
for _ in range(t):
n,k=[int(x) for x in input().split()]
arr=list(map(int,input().split()))
if len(set(arr))>k:
print(-1)
else:
print(n*k)
l=list(set(arr))
p=k-len(l)
(l)
for i in range(p):
l.append(1)
for i in range(n):
... |
A bracketed sequence is called correct (regular) if by inserting "+" and "1" you can get a well-formed mathematical expression from it. For example, sequences "(())()", "()" and "(()(()))" are correct, while ")(", "(()" and "(()))(" are not.
The teacher gave Dmitry's class a very strange task — she asked every student... | 3 | import sys
read = lambda: list(map(int, sys.stdin.readline().strip().split()))
n = int(input())
s = input()
o = 0
c = 0
for i in range(n):
if s[i] == '(':
o += 1
else:
c += 1
if o != c:
print('-1')
else:
ans = 0
o = 0
c = 0
for i in range(n):
#print(i)
#print... |
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe... | 3 | a=list(map(int,input().split('+')))
a.sort()
print('+'.join(str(i) for i in a )) |
Write a program which calculates the area and perimeter of a given rectangle.
Constraints
* 1 ≤ a, b ≤ 100
Input
The length a and breadth b of the rectangle are given in a line separated by a single space.
Output
Print the area and perimeter of the rectangle in a line. The two integers should be separated by a si... | 3 | a,b=map(int,input().split());print(a*b,2*(a+b)) |
We just discovered a new data structure in our research group: a suffix three!
It's very useful for natural language processing. Given three languages and three suffixes, a suffix three can determine which language a sentence is written in.
It's super simple, 100% accurate, and doesn't involve advanced machine learni... | 3 | t = int(input())
for i in range(t):
txt = input()
lst = txt[-1]
if lst == 'o': print("FILIPINO")
elif lst == 'u': print("JAPANESE")
else: print("KOREAN")
|
During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each... | 1 | num, temp = map(int, raw_input().split())
fila = raw_input()
array = []
for i in fila:
array.append(i)
for i in range(temp):
new_fila = ""
trocou = False
for i in range(len(array) - 1):
if trocou:
trocou = False
else:
if array[i] == "B" and array[i+1] == "G":
array[i+1] = "B"
array[i] = "G"
... |
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
<image>
The combination lock is represented by n rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has t... | 3 | # You lost the game.
n = int(input())
ch1 = str(input())
ch2 = str(input())
r = 0
for k in range(n):
a = int(ch1[k])
b = int(ch2[k])
r += min(abs(a-b),abs(a+10-b),abs(a-10-b))
print(r)
|
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | 3 | '''
Amirhossein Alimirzaei
Telegram : @HajLorenzo
Instagram : amirhossein_alimirzaei
University of Bojnourd
'''
N=list(input())
N.remove(N[0])
N.remove(N[len(N)-1])
TMP=[]
for _ in range(0,len(N),3):
if N[_] not in TMP:
TMP.append(N[_])
print(len(TMP))
|
You are given strings s and t. Find one longest string that is a subsequence of both s and t.
Constraints
* s and t are strings consisting of lowercase English letters.
* 1 \leq |s|, |t| \leq 3000
Input
Input is given from Standard Input in the following format:
s
t
Output
Print one longest string that is a su... | 3 | s=input()
t=input()
n=len(s)
m=len(t)
dp=[[0 for i in range(m+1)] for j in range(n+1)]
for i in range(n):
for j in range(m):
if s[i]==t[j]:
dp[i+1][j+1]=dp[i][j]+1
else:
dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j])
ans = ''
while(dp[n][m]>0):
if dp[n][m] == dp[n-1][m-1] +1 and d... |
After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of n horizontal and m vertical sticks.
An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick.
In the grid shown be... | 3 | li=input()
w=li.split(" ")
n=int(w[0])
m=int(w[1])
c=0
p=n*m
while(p):
p=p-(n+m-1)
n=n-1
m=m-1
c=c+1
if(c%2):
print("Akshat")
else:
print("Malvika")
|
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether thi... | 3 | n=int(input())
s=input()
s=s.upper()
i=[0]*26
for word in s:
i[ord(word)-65]+=1
count=1
for a in range(26):
count*=i[a]
if count:
print("YES")
else:
print("NO") |
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it ... | 3 | a=int(input())
d=[]
count=0
for i in range(0,a):
b=input()
b=b.split()
c=[int(x) for x in b]
count=count-c[0]+c[1]
d.append(count)
print(max(d)) |
Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows:
* f(0) = a;
* f(1) = b;
* f(n) = f(n-1) ⊕ f(n-2) when n > 1, where ⊕ de... | 3 | import io
import os
import sys
from atexit import register
import random
import math
import itertools
##################################### Flags #####################################
# DEBUG = True
DEBUG = False
STRESSTEST = False
##################################### IO ########################... |
Alice and Bob play a game. They have a binary string s (a string such that each character in it is either 0 or 1). Alice moves first, then Bob, then Alice again, and so on.
During their move, the player can choose any number (not less than one) of consecutive equal characters in s and delete them.
For example, if the... | 3 | t = int(input())
for _ in range(t):
a = input()
i = 0
cnt_list = []
n = len(a)
while i<n:
if a[i] == '1':
c = 1
i+=1
if i == n:
cnt_list.append(1)
break
while True and i<n:
if a[i] == '0':
... |
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corr... | 3 | '''
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the ... |
On a chessboard with a width of n and a height of n, rows are numbered from bottom to top from 1 to n, columns are numbered from left to right from 1 to n. Therefore, for each cell of the chessboard, you can assign the coordinates (r,c), where r is the number of the row, and c is the number of the column.
The white ki... | 3 | n = int(input())
x,y = map(int,input().split())
num = x - 1 + y - 1
num2 = n - x + n - y
ans = num <= num2
if ans:
print("White")
else:
print("Black")
|
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n. It is known that each of the n integers 1,...,n appears at least once in this sequence.
For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given s... | 3 | from collections import Counter
n, *a = map(int, open(0).read().split())
n += 1
def cmb(n, r, mod):
if r < 0 or r > n:
return 0
r = min(r, n - r)
return g1[n] * g2[r] * g2[n - r] % mod
mod = 10 ** 9 + 7
N = n
# 元テーブル
g1 = [0] * (N + 1)
g1[0] = 1
g1[1] = 1
# 逆元テーブル
g2 = [0] * (N + 1)
g2[0] = 1
... |
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
* if the last digit of the number is non-zero, she decreases the number by one;
* if the last digit of the number is ze... | 3 | x,p=map(int,input().split())
for _ in range(p):
if(x%10==0):
x=x//10
else:
x=x-1
print(x) |
Two players A and B have a list of n integers each. They both want to maximize the subtraction between their score and their opponent's score.
In one turn, a player can either add to his score any element from his list (assuming his list is not empty), the element is removed from the list afterward. Or remove an elem... | 3 | from collections import deque
l = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
a_score = 0
b_score = 0
is_a_turn = True
while len(a) > 0 or len(b) > 0:
if is_a_turn:
if len(a) == 0:
b.pop()
elif len(b) == 0:
a_s... |
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it ... | 3 | n = int(input().strip())
ans = 0
cur = 0
for i in range(n):
[a, b] = [int(x) for x in input().strip().split(' ')]
cur = cur - a + b
ans = max(ans, cur)
print(ans) |
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at a1 percent and second one is charged at a2 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 not c... | 3 | a = [int(x) for x in input().split()]
count = 0
while((a[0]>0 and a[1]>0)):
if(a[0]==1 and a[1]==1): break
count +=1
if(a[0]>a[1]):
a[1]+=1
a[0]-=2
else:
a[0]+=1
a[1]-=2
print(count) |
You are given an array a[0 … n-1] of length n which consists of non-negative integers. Note that array indices start from zero.
An array is called good if the parity of each index matches the parity of the element at that index. More formally, an array is good if for all i (0 ≤ i ≤ n - 1) the equality i mod 2 = a[i] m... | 3 | t=int(input())
for _ in range(t):
n=int(input())
l=list(map(int,input().split()))
neg=0
pos=0
for i in range(n):
if i%2!=0 and l[i]%2==0:
pos=pos+1
elif i%2==0 and l[i]%2!=0:
neg=neg+1
if pos==neg:
print(pos)
else:
print(-1) |
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting e... | 3 | lst=[int(input()) for i in range(3)]
lst1=[]
lst1.append(lst[0]+lst[1]*lst[2])
lst1.append(lst[0]*(lst[1]+lst[2]))
lst1.append(lst[0]*lst[1]*lst[2])
lst1.append((lst[0]+lst[1])*lst[2])
lst1.append(lst[0]+lst[1]+lst[2])
lst1=sorted(lst1)
print(lst1[-1])
|
Mike has n strings s1, s2, ..., sn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec".
Now Mike asks himself: what... | 3 | n=int(input())
s=[]
for i in range(n):
s.append(input())
ans=10**9
for i in range(n):
t=s[i]
y=0
for j in range(n):
x=s[j]+s[j]
z=len(t)
c=-1
for k in range(z):
if x[k:k+z]==t:
c=k
break
if c!=-1:
y=y+c
... |
Vasya has recently got a job as a cashier at a local store. His day at work is L minutes long. Vasya has already memorized n regular customers, the i-th of which comes after t_{i} minutes after the beginning of the day, and his service consumes l_{i} minutes. It is guaranteed that no customer will arrive while Vasya is... | 3 | """
from time import*
import random
money = 10000
cheat = input("Enter Cheat code if you know it: ")
if cheat == "SAHAR":
money += 100000
print("--Your balans 110000rub--")
print("You have",str(money)+"rub")
ques = input("Magazines or VulkanKazino or 1xbet:")
if ques == "1xbet":
stavki = int(input("How many stavka y... |
When preparing a tournament, Codeforces coordinators try treir best to make the first problem as easy as possible. This time the coordinator had chosen some problem and asked n people about their opinions. Each person answered whether this problem is easy or hard.
If at least one of these n people has answered that th... | 3 | n = int(input())
mass = list(map(int, input().split()))
if 1 not in mass:
print("EASY")
else: print("HARD") |
Having learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together. He cannot do any other calculation.
Given are two integers A and B.
If Takahashi can calculate A \times B, print the result; if he cannot, print `-1` instead.
Constraints
* 1 \leq A \leq 20
* 1 \leq B ... | 1 | A, B = map(int, raw_input().split())
print A*B if A <= 9 and B <= 9 else -1 |
Find the minimum area of a square land on which you can place two identical rectangular a × b houses. The sides of the houses should be parallel to the sides of the desired square land.
Formally,
* You are given two identical rectangles with side lengths a and b (1 ≤ a, b ≤ 100) — positive integers (you are given ... | 3 | test_cases=int(input())
for _ in range(test_cases):
a,b=map(int,input().split())
print(max(max(a,b)**2,(2*min(a,b))**2)) |
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number a and Antisimon receives number b. They also have a heap of n stones. The players take turns to make a move and Simon starts. During a move a player should take from ... | 1 | temp = map(int,raw_input().split(" "))
a = temp[0]
b = temp[1]
n = temp[2]
def gcd(x,y):
if x == 0 or y == 0:
return 0
if x == y:
return x
if x > y :
return gcd(x-y,y)
return gcd(x,y-x)
player = 1
while n>0 :
if player == 0:
player = 1
else:
player = 0
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.