problem
stringlengths
29
9.39k
language
int64
1
3
solution
stringlengths
7
465k
You are given an integer K. Print the string obtained by repeating the string `ACL` K times and concatenating them. For example, if K = 3, print `ACLACLACL`. Constraints * 1 \leq K \leq 5 * All values in input are integers. Input Input is given from Standard Input in the following format: K Output Print the s...
3
K = int(input("")) print("ACL"*K)
Happy new year! The year 2020 is also known as Year Gyeongja (κ²½μžλ…„, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years. There are two sequences of n strings s_1, s_2, s_3, …, s_{n} and m strings t_1, t_2, t_3, …, t_{m}. ...
3
n,m = map(int,input().split()) s = input().split() t = input().split() q = int(input()) mass = "" for i in range(q): y = int(input()) if y <= n: mass += s[y-1] else: mass += s[y%n-1] if y <= m: mass += t[y-1] + ' ' else: mass += t[y%m-1] + ' ' mass = mass.split() for ...
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
s1 = input().lower() s2 = input().lower() for i in range(len((s1))): if(ord(s1[i]) > ord(s2[i])): print(1) break elif(ord(s1[i]) < ord(s2[i])): print(-1) break else: print(0)
One company of IT City decided to create a group of innovative developments consisting from 5 to 7 people and hire new employees for it. After placing an advertisment the company received n resumes. Now the HR department has to evaluate each possible group composition and select one of them. Your task is to count the n...
3
n = int(input()) print(n * (n - 1) * (n - 2) * (n - 3) * (n - 4) // 120 + n * (n - 1) * (n - 2) * (n - 3) * (n - 4) * (n - 5) // 720 + n * (n - 1) * (n - 2) * (n - 3) * (n - 4) * (n - 5) * (n - 6) // (720 * 7))
There are two sisters Alice and Betty. You have n candies. You want to distribute these n candies between two sisters in such a way that: * Alice will get a (a > 0) candies; * Betty will get b (b > 0) candies; * each sister will get some integer number of candies; * Alice will get a greater amount of candie...
3
for _ in range(int(input())): n = int(input()) if n == 0 or n == 1 or n == 2 : print(0) else : if n % 2 == 0 : n = n // 2 - 1 else: n = n // 2 print(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
n = int(input()) a = input() cnt = 0 for i in range(n): if a[i] == '(': cnt += 1 r = 0 if cnt == (n>>1): cnt = 0 i = 0 while i < n: if a[i] == ')': cnt -= 1 else: cnt += 1 if cnt < 0: for j in range(i+1, n): if a[j] == '...
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are n drinks in his fridge, the volume fraction of orange juice in the i-th drink equals pi percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of ea...
3
n = int(input()) temp = [int(s) for s in input().split(' ')] ans = 0 #print(temp) for i in range(n): ans += temp[i] print(round(ans/n, 5))
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her n students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddl...
3
n, m = map(int, input().split()) a = input().split() for i in range(m): a[i] = int(a[i]) a.sort() answer = 0 ma = 1000000000000000 k = 0 for i in range(m-n+1): if a[i+n-1]-a[i] < ma: ma = a[i+n-1]-a[i] k += 1 if k != 0: answer = ma print(answer)
Mishka got an integer array a of length n as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: * Replace each occurre...
3
input() sp = list(map(int, input().split())) for el in sp: if el % 2 == 0: el -= 1 print(el, end=" ")
You are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels. A pixel is the smallest element of an image, and in this problem it is a square of size 1Γ—1. Also, the given images are binary images, and the color of each pixel is either white or bl...
3
N,M = map(int, input().split()) a=[input() for i in range(N)] b=[input() for i in range(M)] ans = 0 for i in range(N-M+1): for j in range(N-M+1): t = [k[j:j+M] for k in a[i:i+M]] if t==b: ans =1 print("Yes" if ans else "No")
Sereja has an array a, consisting of n integers a1, a2, ..., an. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out m integers l1, l2, ..., lm (1 ≀ li ≀ n). For each number li he wants to know how many distinct numbers are staying on the positions li, li + 1, ......
3
n, m = [int(x) for x in input().split()] arr = [int(x) for x in input().split()] l = [0] * n s = set() arr.reverse() for i, e in enumerate(arr): s.add(e) l[n-i-1] = len(s) for _ in range(m): x = int(input()) print(l[x-1])
You have been blessed as a child of Omkar. To express your gratitude, please solve this problem for Omkar! An array a of length n is called complete if all elements are positive and don't exceed 1000, and for all indices x,y,z (1 ≀ x,y,z ≀ n), a_{x}+a_{y} β‰  a_{z} (not necessarily distinct). You are given one integer ...
3
from math import * from itertools import * from collections import * import sys INF = int(1e5 + 1) pi = 3.141592653589793238462643 def ii(): return int(input()) def mas(): return input().split() def masint(): return [int(i) for i in mas()] def solve(): n = ii() h = [1] * n print(*h) ...
"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 ...
1
n, k = [int(x) for x in raw_input().split()] a = [int(x) for x in raw_input().split()] same = a.count(a[k - 1]) if a[k - 1] > 0 else 0 ans = sum(a[i] > a[k - 1] for i in range(k)) + same print ans
You are given an array a consisting of n integers a_1, a_2, ... , a_n. In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array [2, 1, 4] you can obtain the following arrays: [3, 4],...
3
n = int(input()) j = 0 while j < n : t = int(input()) a = list(map(int, input().split())) count0 = 0 count1 = 0 count2 = 0 for i in range(t): # print(a[i]) if a[i]%3 == 0: count0 += 1 if a[i]%3 == 1: count1 += 1 elif a[i]%3 == 2: ...
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
1
import sys number = sys.stdin.readline().split()[0] flag = True n = 0 for i in range(len(number)): digit = number[i] if digit in "47": n += 1 if str(n) in "47": print "YES" else: print "NO"
Vanya walks late at night along a straight street of length l, lit by n lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point l. Then the i-th lantern is at the point ai. The lantern lights all points of the street that are at the ...
3
input1 = input("") input2 = input("") input1 = input1.split(" ") input2 = input2.split(" ") for i in range(len(input2)): input2[i] = int(input2[i]) input2.sort() end = int(input1[1]) all = input2 max = 0 for i in range(len(all) - 1): dif = int(all[i + 1]) - int(all[i]) if dif / 2 > max: max =...
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
3
n = int(input()) freq = 0 while n != 0: d = n % 10 if d == 4 or d == 7: freq += 1 n //= 10 if freq == 0: print("NO") else: flag = 0 while freq != 0: d = freq % 10 if not (d == 4 or d == 7...
Petya is preparing for his birthday. He decided that there would be n different dishes on the dinner table, numbered from 1 to n. Since Petya doesn't like to cook, he wants to order these dishes in restaurants. Unfortunately, all dishes are prepared in different restaurants and therefore Petya needs to pick up his ord...
3
from collections import Counter import math import sys import heapq from bisect import bisect,bisect_left,bisect_right def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(...
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the displ...
1
from collections import deque n = int(raw_input()) digits = deque(map(int, raw_input())) min = list(digits) def rotate(digits): a = digits.popleft() digits.append(a) def addto(digits, x): ls = list(digits) for i, _ in enumerate(ls): ls[i] = (ls[i] + x) % 10 return ls for i in range(n): ...
You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of k in different moves. Your task is to find the minimum number of mo...
3
for _ in range(int(input())): a,b= map(int,input().split()) if a==b: print(0) elif a<b: if (a-b)%2: print(1) else: print(2) else: if (a-b)%2: print(2) else: print(1)
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called x. Also, there are two operations: * Operation ++ increases the value of variable x by 1. * Operation -- decreases the value of variable x by 1....
3
n=int(input()) c=0 for i in range(n): m=input() if '+' in m: c+=1 else: c-=1 print(c)
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character...
3
c=97;s=0; for j in map(ord,input()): i=abs(c-j) s+=min(i,26-i) c=j print(s)
Polycarp wants to buy exactly n shovels. The shop sells packages with shovels. The store has k types of packages: the package of the i-th type consists of exactly i shovels (1 ≀ i ≀ k). The store has an infinite number of packages of each type. Polycarp wants to choose one type of packages and then buy several (one or...
3
import math def divisors(n): i = 1 div = [] while i <= math.sqrt(n): if n % i == 0: if n//i == i: div.append(i) else: div.append(i) div.append(n // i) i += 1 return div for _ in range(int(input())): n, k = map(in...
A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()", "(())" are reg...
1
from collections import defaultdict def openr(e): ctr=0 for c in e: if c=='(': ctr+=1 else: ctr-=1 if ctr<0: return -1 return ctr def openl(e): ctr=0 for c in e[::-1]: if c==')': ctr+=1 else: ctr-=1...
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two ...
3
"""472A: Π£Ρ€ΠΎΠΊΠΈ Π΄ΠΈΠ·Π°ΠΉΠ½Π° Π·Π°Π΄Π°Ρ‡: учимся Ρƒ ΠΌΠ°Ρ‚Π΅ΠΌΠ°Ρ‚ΠΈΠΊΠΈ""" def is_prime(x): if (x < 2): return False xx = int(x ** 0.5) for i in range(2, xx + 1): if x % i == 0: return False return True n = int(input()) for i in range(2, n): if not is_prime(i) and not is_prime(n - i): print(i, n - i) break
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
1
#coding: utf-8 n = int(raw_input()) seq = raw_input() new_seq = "" while len(seq) > 1: temp = seq[0] + seq[1] if temp in ["RU", "UR"]: new_seq += "D" seq = seq[2::] else: new_seq += seq[0] seq = seq[1::] if len(seq) == 1: new_seq += seq[0] print len(new_seq)
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like. Now let's imagine a typical morning in your family. You haven't w...
3
n = int(input()) l = list(map(int,input().split())) s = sum(l) l.sort() ans = 0 c = 0 for i in range(len(l)-1,-1,-1): c+=1 ans+=l[i] diff = s-ans if ans>diff: break print(c)
Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero ( < 0). 2. The product of all numbers in the second set is greater than zero ( > 0). 3. The product of a...
3
size = int(input()) arr = list(map(int, input().split(" "))) zeros = ['0' for i in range(arr.count(0))] negatives = [str(i) for i in arr if i < 0] positives = [str(i) for i in arr if i > 0] if positives == [] : positives = negatives[:2] negatives = negatives[2:] if len(negatives) % 2 == 0: zeros = zeros...
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
n = int(input()) while(True): n = n + 1 if(len(set(str(n))) == len(str(n))): break print(n)
According to a new ISO standard, a flag of every country should have a chequered field n Γ— m, each square should be of one of 10 colours, and the flag should be Β«stripedΒ»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland'...
3
m,n = input().split() a=[] for i in range (int(m)): t=input() a.append(t) count=0 count1=0 for j in range (int(m)): for t in range (int(n)): if (a[j][t]) == (a[j][t-1]): count+=1 else: count1+=1 for j in range (int(int(m)-1)): if (a[j])!= (a[j+1]): count+...
Numbers 1, 2, 3, ... n (each integer from 1 to n once) are written on a board. In one operation you can erase any two numbers a and b from the board and write one integer (a + b)/(2) rounded up instead. You should perform the given operation n - 1 times and make the resulting number that will be left on the board as s...
3
import math t = int(input()) for _ in range(t): n = int(input()) arr = [i for i in range(1, n+1)] res = list() c = 0 for i in range(n-1): a = arr[n-1-i] b = arr[n-2-i] c = math.ceil((a + b) / 2) arr[n-2-i] = c res.append((a, b)) # print(arr) print(arr[...
In AtCoder, a person who has participated in a contest receives a color, which corresponds to the person's rating as follows: * Rating 1-399 : gray * Rating 400-799 : brown * Rating 800-1199 : green * Rating 1200-1599 : cyan * Rating 1600-1999 : blue * Rating 2000-2399 : yellow * Rating 2400-2799 : orange * Rating 280...
3
n = int(input()) A = list(map(int,input().split())) c = [0]*10 add = 0 for i in range(n) : if A[i]>=3200 : add += 1 continue a = A[i]//400 c[a] = 1 print(max(sum(c),1),sum(c)+add)
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
word = input() l = 0 u = 0 for char in word: if char.islower() == True: l += 1 else: u += 1 if l == u or l>u: word = word.lower() else: word = word.upper() print(word)
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
3
n=int(input()) xsum=0 ysum=0 zsum=0 for i in range(n): xi,yi,zi=map(int,input().split(" ")) xsum+=xi ysum+=yi zsum+=zi if xsum==0 and ysum==0 and zsum==0: print("YES") else: print("NO")
Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String t is called a palindrome, if it reads the same from left to right and from right to left. For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strin...
3
s=input().strip('0') print('YES' if all(s[i]==s[-1-i] for i in range(len(s))) else 'NO')
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
string=input() string=string.replace('{','') string=string.replace('}','') string=string.replace(',','') My_list=string.split() My_list=set(My_list) print(len(My_list))
You have a list of numbers from 1 to n written from left to right on the blackboard. You perform an algorithm consisting of several steps (steps are 1-indexed). On the i-th step you wipe the i-th number (considering only remaining numbers). You wipe the whole number (not one digit). <image> When there are less than ...
3
for i in range(int(input())): n, t = map(int, input().split()) print(range(t, n + 1)[t])
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and like that his feelings are complicated. They have n layers. The first layer is hate, seco...
3
t=int(input()) for a in range(1,t+1): if(a!=t): if(a%2!=0): print('I hate that',end=' ') else: print('I love that',end=' ') else: if(a%2==0): print('I love it',end='') else: print('I hate it',end='')
You got a job as a marketer in a pet shop, and your current task is to boost sales of cat food. One of the strategies is to sell cans of food in packs with discounts. Suppose you decided to sell packs with a cans in a pack with a discount and some customer wants to buy x cans of cat food. Then he follows a greedy str...
3
import sys import math import bisect from sys import stdin, stdout from math import gcd, floor, sqrt, log2, ceil from collections import defaultdict as dd from bisect import bisect_left as bl, bisect_right as br from bisect import insort from collections import Counter from collections import deque from heapq import he...
There are n beautiful skyscrapers in New York, the height of the i-th one is h_i. Today some villains have set on fire first n - 1 of them, and now the only safety building is n-th skyscraper. Let's call a jump from i-th skyscraper to j-th (i < j) discrete, if all skyscrapers between are strictly lower or higher than ...
3
def empty(l): return len(l) == 0 n = int(input()) h = list(map(int, input().split(" "))) inc, dec = [0], [0] dp = [0]*n for i in range(1,n): dp[i] = dp[i-1]+1 while not empty(inc) and h[i] >= h[inc[-1]]: x = h[inc.pop()] if h[i] > x and not empty(inc): dp[i] = min(dp[i], dp[inc[-1]...
Lately, Mr. Chanek frequently plays the game Arena of Greed. As the name implies, the game's goal is to find the greediest of them all, who will then be crowned king of Compfestnesia. The game is played by two people taking turns, where Mr. Chanek takes the first turn. Initially, there is a treasure chest containing N...
3
d={0:0,2:1,4:1} inp=[] ans=[] def search(i): t=0 while i not in d: t+=1 if i%4==0: i-=2 else: i=i//2-1 return t+d[i] for time in range(int(input())): inp.append(int(input())) for i in inp: if i%2==0: ans.append(i-search(i)) else: ...
Berland year consists of m months with d days each. Months are numbered from 1 to m. Berland week consists of w days. The first day of the year is also the first day of the week. Note that the last week of the year might be shorter than w days. A pair (x, y) such that x < y is ambiguous if day x of month y is the same...
3
# ---------------------------iye ha aam zindegi--------------------------------------------- import math import heapq, bisect import sys from collections import deque, defaultdict from fractions import Fraction mod = 10 ** 9 + 7 mod1 = 998244353 # ------------------------------warmup---------------------------- impor...
On the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Martians have the same weeks as earthlings β€” 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars. Input The first line of the input contains a ...
1
A = int(raw_input()) holidays = (A/7)*2 max_holidays = 0 min_holidays = 0 if A%7 >=2: max_holidays = holidays + 2 else: max_holidays = holidays + A%7 if A%7 > 5: min_holidays = holidays + (A%7 - 5) else: min_holidays = holidays + 0 print min_holidays, max_holidays
<image> One morning the Cereal Guy found out that all his cereal flakes were gone. He found a note instead of them. It turned out that his smart roommate hid the flakes in one of n boxes. The boxes stand in one row, they are numbered from 1 to n from the left to the right. The roommate left hints like "Hidden to the l...
3
n, m = map(int, input().split()) l, r = 1, n for i in range(m): a = input().split() if a[2] == 'left': r = min(r, int(a[4]) - 1) else: l = max(l, int(a[4]) + 1) print(r - l + 1 if l <= r else -1)
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 Bi...
3
weigh = eval(input()) result = weigh%2 if result == 0 and weigh/2 != 1: print("YES") else: print("NO")
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: * Its elements are in increasing o...
3
from sys import stdin from sys import stdout #Fast IO def glis(): return list(map(int,(stdin.readline().strip().split()))) def gtis(): return tuple(map(int,stdin.readline().strip().split())) def gstr(): return stdin.readline().strip().split() def gi(): return int(stdin.readline().strip()) def gcl(): s=stdin.re...
Today the kindergarten has a new group of n kids who need to be seated at the dinner table. The chairs at the table are numbered from 1 to 4n. Two kids can't sit on the same chair. It is known that two kids who sit on chairs with numbers a and b (a β‰  b) will indulge if: 1. gcd(a, b) = 1 or, 2. a divides b or b d...
3
t=int(input()) res=[] for j in range(0,t): n=int(input()) sol=[] for i in range(4*n,0,-1): if len(sol) ==n: break; if (i%2==0): sol.append(str(i)) res.append(sol) for i in res: print(" ".join(i))
A sequence a = [a_1, a_2, …, a_l] of length l has an ascent if there exists a pair of indices (i, j) such that 1 ≀ i < j ≀ l and a_i < a_j. For example, the sequence [0, 2, 0, 2, 0] has an ascent because of the pair (1, 4), but the sequence [4, 3, 3, 3, 1] doesn't have an ascent. Let's call a concatenation of sequence...
3
import bisect n = int(input()) arrays = [] for i in range(n): cur = input().split(" ") arrays.append([int(x) for x in cur[1:]]) highest = [] lowest = [] result = 0 for array in arrays: cur = False last = 1000000 curh = 0 curl = 1000000 for a in array: if a > last: cur ...
Alica and Bob are playing a game. Initially they have a binary string s consisting of only characters 0 and 1. Alice and Bob make alternating moves: Alice makes the first move, Bob makes the second move, Alice makes the third one, and so on. During each move, the current player must choose two different adjacent char...
3
from math import ceil from math import radians from heapq import heapify, heappush, heappop import bisect from math import pi from collections import deque from math import factorial from math import log, ceil from collections import defaultdict from math import * from sys import stdin, stdout import itertools import ...
We have an integer sequence A, whose length is N. Find the number of the non-empty contiguous subsequences of A whose sums are 0. Note that we are counting the ways to take out subsequences. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from differ...
3
from collections import defaultdict n=int(input()) a=list(map(int,input().split())) s=[0]*(n+1) for i in range(n):s[i+1]=s[i]+a[i] d=defaultdict(int) for i in range(n+1):d[s[i]]+=1 r=0 for v in d.values(): r+=int(v*(v-1)/2) print(r)
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after x is the smallest prime number greater than x. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that ...
3
n,m = map(int,input().split()) c = 0 if m%2==0 or ((m%3==0 or m%5==0 or m%7==0) and m>7): print("NO") else: while n<m: if m%2!=0 and m%3!=0 and m%5!=0 or m==3 or m==5: c+=1 m-=1 if c==1: print("YES") else: print("NO")
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be n problems, sorted by difficulty, i.e. problem 1 is the easiest and problem n is the hardest. Limak knows it will take him 5Β·i minutes to solve the i-th...
3
from collections import defaultdict import sys, os, math if __name__ == "__main__": #n, m = list(map(int, input().split())) n, k = map(int, input().split()) ans = 1 while ans * (ans + 1) * 5 <= (240 - k) * 2: ans += 1 print(min(ans - 1, n))
A telephone number is a sequence of exactly 11 digits, where the first digit is 8. For example, the sequence 80011223388 is a telephone number, but the sequences 70011223388 and 80000011223388 are not. You are given a string s of length n, consisting of digits. In one operation you can delete any character from strin...
3
n = int(input()) for i in range(0, n): a = int(input()) x = input() flag = 0 for j in range(0, a): if x[j] == '8' and a-j-1 >= 10: print("YES") flag = 1 break if flag == 0: print("NO")
Santa Claus has Robot which lives on the infinite grid and can move along its lines. He can also, having a sequence of m points p1, p2, ..., pm with integer coordinates, do the following: denote its initial location by p0. First, the robot will move from p0 to p1 along one of the shortest paths between them (please not...
3
n = int(input()) a = input() prot = dict() prot["D"] = "U" prot["L"] = "R" prot["R"] = "L" prot["U"] = "D" was = set() ans = 1 for i in range(n): if (a[i] not in was): if (len(was) == 0): was.add(a[i]) elif len(was) == 1: if (prot[a[i]] not in was): was.add(a[...
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....
3
from collections import deque from collections import OrderedDict import math import sys import os from io import BytesIO import threading import bisect import heapq #sys.stdin = open("F:\PY\\test.txt", "r") input = lambda: sys.stdin.readline().rstrip("\r\n") answer = 0 setL = set() for i in range(int(input())...
Your friend who lives in undisclosed country is involved in debt. He is borrowing 100,000-yen from a loan shark. The loan shark adds 5% interest of the debt and rounds it to the nearest 1,000 above week by week. Write a program which computes the amount of the debt in n weeks. Input An integer n (0 ≀ n ≀ 100) is g...
1
debt = 100000 n=int(raw_input()) for i in range(1,n+1): debt = debt*1.05 if(debt % 1000) != 0: debt = (debt - (debt%1000)) + 1000 print int(debt)
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ...
3
n=int(input()) l=[4,7,47,74,744,447,477] for i in l: if(n%i==0): print("YES") break else: print("NO")
Sereja has an array a, consisting of n integers a1, a2, ..., an. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out m integers l1, l2, ..., lm (1 ≀ li ≀ n). For each number li he wants to know how many distinct numbers are staying on the positions li, li + 1, ......
3
n, m = map(int, input().split()) a = list(map(int, input().split())) result = [0]*(n+1) b = set() for j in range(n-1, -1, -1): b.add(a[j]) result[j] = len(b) for i in range(m): l = int(input()) print(result[l-1])
Depth-first search (DFS) follows the strategy to search ”deeper” in the graph whenever possible. In DFS, edges are recursively explored out of the most recently discovered vertex $v$ that still has unexplored edges leaving it. When all of $v$'s edges have been explored, the search ”backtracks” to explore edges leaving ...
3
def MAIN(): n = int(input()) ans = [[i, 0, 0] for i in range((n + 1))] G = [[] for _ in range((n + 1))] for _ in range(n): u, k, *v = map(int, input().split()) G[u] = v cnt = 1 def dfs(u): nonlocal ans if ans[u][1] != 0: return nonlocal cnt ...
Write a program which calculates the distance between two points P1(x1, y1) and P2(x2, y2). Input Four real numbers x1, y1, x2 and y2 are given in a line. Output Print the distance in real number. The output should not contain an absolute error greater than 10-4. Example Input 0 0 1 1 Output 1.41421356
1
# coding=utf-8 from math import sqrt x1, y1, x2, y2 = map(float, raw_input().split()) print sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
Given a set of integers (it can contain equal elements). You have to split it into two subsets A and B (both of them can contain equal elements or be empty). You have to maximize the value of mex(A)+mex(B). Here mex of a set denotes the smallest non-negative integer that doesn't exist in the set. For example: * m...
3
for i in range(int(input())): n=int(input()) l=list(map(int,input().split())) a=[0]*101 for j in l: a[j]+=1 mcnt=-1 lcnt=-1 for j in range(101): if a[j]<2: if lcnt==-1: lcnt=j if a[j]==0 : mcnt=...
In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum. For example, for n = 4 the sum is equal to - 1 - 2 + 3 - 4 = - 4, because 1, 2 and 4 are 20, 21 and 22 respectively. Calculate the answer for t values of n. Input The first line of...
1
import math t = int(raw_input()) for i in range(t): n = int(raw_input()) print n*(n+1)/2 - 2*int((math.pow(2, int(math.log(n)/math.log(2)) + 1) - 1))
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 pi people living...
3
def main(): t=int(input()) c=0 for _ in range(t): x,y=[int(i) for i in input().split()] if y-x>1: c+=1 print(c) main()
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ...
3
n = int(input()) d = {} for i in range(n): inp = input() if inp in d: print('YES') else: print('NO') d[inp] = i
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
(d1, d2, d3) = list(map(int, input().split())) if d1+d2 < d3: print(2*(d1+d2)) else: if d1 > d3 and d2 > d3: if d1 < d2: print(2*(d1+d3)) else: print(2*(d2+d3)) elif d1 > d3: if d1 > d2+d3: print(2*(d2+d3)) else: print(d1+d2+d3)...
It is winter now, and Max decided it's about time he watered the garden. The garden can be represented as n consecutive garden beds, numbered from 1 to n. k beds contain water taps (i-th tap is located in the bed xi), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed xi is turned ...
3
#!/usr/bin/env python3 ''' Author: andyli Time: 2020-07-06 23:23:08 ''' import os from io import BytesIO, IOBase import sys def main(): for _ in range(int(input())): n,k = map(int,input().split()) a = list(map(int,input().split())) ans = 0 for i in range(1,n+1): t = n...
A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. ...
1
t=input() dic={} while(t): n=raw_input() if n in dic: print n+str(dic[n]) dic[n]+=1 else: dic[n]=1 print "OK" t-=1
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution....
1
print len([x for x in [raw_input().split() for _ in range(input())] if x.count('1')>1])
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
n = int(input()) t = list(map(int, input().split())) li = list() i=0 b=1 for j in range(i,len(t)-1): if t[j]<=t[j+1]: b+=1 else: i=j+1 li.append(b) b=1 li.append(b) print(max(li))
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length n. There is a great number of "QAQ" in the string (Diamond is so cute!). <image> illustration by ηŒ«ε±‹ https://twitter.com/nekoy...
3
# bsdk idhar kya dekhne ko aaya hai, khud kr!!! # from math import * # from itertools import * arr = list(input()) count_ = 0 for i in range(0, len(arr)): for j in range(i+1, len(arr)): for k in range(j+1, len(arr)): if arr[i] == "Q" and arr[j] == "A" and arr[k] == "Q": count_ +=...
Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty β€” a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty d on Decoforces is as hard as the problem with difficulty d on any other judge). M...
1
n,k=map(int,raw_input().strip().split()) A=map(int,raw_input().strip().split()) """ n,k=4,20 A=[10,3,6,3] """ A.sort() c = 0 for ai in A: while ai > 2 * k: k *= 2 c += 1 k = max(k, ai) print(c) exit()
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution....
3
n = int(input()) answer = 0 for i in range(n): if sum(map(int, input().split())) >= 2: answer += 1 print(answer)
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 Bi...
3
w=int(input()) a=w%2 if a==0 and w%2==0 and w!=2: print("YES") else: print("NO")
Daniel is organizing a football tournament. He has come up with the following tournament format: 1. In the first several (possibly zero) stages, while the number of teams is even, they split in pairs and play one game for each pair. At each stage the loser of each pair is eliminated (there are no draws). Such stage...
3
n = int(input()) def f(t, k): return t*(t-1)//2 + t*((1<<k)-1) ans = set() for k in range(60): l = 0 r = n p = 0 while l <= r: t = (l+r)//2 if f(t, k) <= n: p = t l = t+1 else: r = t-1 if p % 2 == 1 and f(p, k) == n: ans.add(p * (1<<k)) for x in sorted(ans): print(x) if not ans: print(-1)
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 ...
3
n = int(input()) h = [] g = [] count = 0 for _ in range(n): a, b = map(int, input().split()) h.append(a) g.append(b) for i in g: count += h.count(i) print(count)
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
3
a,b,n=map(int,input().split()) if b<0: z=-b else: z=b for x in range(-z,z+1): if a*x**n==b: print(x) exit() print("No solution")
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
from collections import Counter s=input() x=Counter(s) if len(x)%2==0: print('CHAT WITH HER!') else: print('IGNORE HIM!')
Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: 1. Find two consecutive characters in the string, such that the first of them equals "y", and the s...
3
__author__ = "runekri3" s = input() x_count = s.count("x") y_count = s.count("y") if x_count > y_count: char = "x" else: char = "y" print(char * abs(x_count - y_count))
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
3
x,y=map(int,input().split()) a=0 #bits b=0 #powers ind=0 s=[] while x>0: if x%2==1: a+=1 b+=(1<<ind) s.append(1<<ind) x>>=1 ind+=1 if y<a or y>b: print('NO') exit(0) if x==y: print('YES') for n in range(x): print(1,end=' ') exit(0) s.reverse() n=0 res=[] while s[n]<y: y-=s[n] res+=[1]*s[n] n+=1 ...
You are given an array of n integers a_1,a_2,...,a_n. You have to create an array of n integers b_1,b_2,...,b_n such that: * The array b is a rearrangement of the array a, that is, it contains the same values and each value appears the same number of times in the two arrays. In other words, the multisets \\{a_1,a_...
3
t=int(input('')) for _ in range(t): n=int(input('')) arr=list(map(int,input().split())) arr.sort() if sum(arr)==0: print('NO') continue if sum(arr)>0: arr.sort(reverse=True) print('YES') print(*arr)
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 Bi...
3
weight = int(input()) if weight == 2: print("NO") exit(0) if weight % 2 == 0: print("YES") else: print("NO")
There is a square painted on a piece of paper, the square's side equals n meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downward...
1
def ggd(a,b): rest=0 while b != 0: rest = a % b a,b = b,rest return a def kgv(a,b): return a*b/ggd(a,b) n=input() v=(map(int,raw_input().split())) for i in v: print 1+kgv(i+1,4*i)/(i+1)
Bashar was practicing for the national programming contest. Because of sitting too much in front of the computer without doing physical movements and eating a lot Bashar became much fatter. Bashar is going to quit programming after the national contest and he is going to become an actor (just like his father), so he sh...
3
n, m, k = map(int, input().split()) if 4*n*m-2*n-2*m<k: print('NO') exit() print('YES') path = [] if n==1: path.append((m-1, 'R')) path.append((m-1, 'L')) elif m==1: path.append((n-1, 'D')) path.append((n-1, 'U')) else: for _ in range(m-2): path.append((1, 'R')) pa...
It was decided in IT City to distinguish successes of local IT companies by awards in the form of stars covered with gold from one side. To order the stars it is necessary to estimate order cost that depends on the area of gold-plating. Write a program that can calculate the area of a star. A "star" figure having n β‰₯ ...
3
from math import* n, r = map(int, input().split()) x=360/n a=x/4/180*pi b=x*3/4/180*pi x=tan(a) y=tan(b) S = (r**2)*sin(a)*cos(a)/2 S1 = (r*sin(a)/tan(b))*r*sin(a)/2 S2=S-S1 print(S2*2*n)
Nikolay lives in a two-storied house. There are n rooms on each floor, arranged in a row and numbered from one from left to right. So each room can be represented by the number of the floor and the number of the room on this floor (room number is an integer between 1 and n). If Nikolay is currently in some room, he c...
3
for _ in range(int(input())): n = int(input()) s = list(input()) if '1' in s: f = s.index('1') l = s[-1::-1].index('1') print(2 * (n - min(f, l))) else: print(n)
Balph is learning to play a game called Buma. In this game, he is given a row of colored balls. He has to choose the color of one new ball and the place to insert it (between two balls, or to the left of all the balls, or to the right of all the balls). When the ball is inserted the following happens repeatedly: if so...
3
S = input().strip() P = [] j = 0 for i in range(1, len(S)+1): if i == len(S) or S[i] != S[j]: P.append((S[j], i-j)) j = i l = 0 r = len(P)-1 while l < r: if P[l][0] != P[r][0] or P[l][1] + P[r][1] < 3: break l += 1 r -= 1 print(P[l][1]+1 if l == r and P[l][1] >= 2 else 0)
Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rec...
3
t = int(input()) while t : a1, b1 = input().split() a2, b2 = input().split() a1 = int(a1) b1 = int(b1) a2 = int(a2) b2 = int(b2) if (a1==a2 and b1+b2==a1) or (a1==b2 and a2+b1==a1) or (b1==a2 and a1+b2==a2) or (b1==b2 and a1+a2==b1) : print('Yes') else : print('No') ...
Xenia lives in a city that has n houses built along the main ringroad. The ringroad houses are numbered 1 through n in the clockwise order. The ringroad traffic is one way and also is clockwise. Xenia has recently moved into the ringroad house number 1. As a result, she's got m things to do. In order to complete the i...
3
def main(): n,m= [int(i) for i in input().split()] arr= [int(i) for i in input().split()] count=0 last=1 for i in arr: if i>=last: count+= i-last else: count+=n-last+i last=i print(count) return 0 if __name__ == '__main__': main()
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a n by m table. Denote c-th cell of r-th row as (r, c). The tail of the snake is located at (1, 1), then it's body extends to (1,...
3
n,m=map(int,input().split()) l=0 for i in range(0,n): if i%2!=0: if l==0: for j in range(0,m-1): print('.',end="") print('#',end='') l=1 elif l==1: print('#',end='') for j in range(0,m-1): print('.',end="") ...
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are n drinks in his fridge, the volume fraction of orange juice in the i-th drink equals pi percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of ea...
3
n=int(input()) m=input().split() list=[] for i in range(n): list.append(int(m[i])) sum=0 for i in list: sum=sum+i ans=sum/n print(ans)
Try guessing the statement from this picture <http://tiny.cc/ogyoiz>. You are given two integers A and B, calculate the number of pairs (a, b) such that 1 ≀ a ≀ A, 1 ≀ b ≀ B, and the equation a β‹… b + a + b = conc(a, b) is true; conc(a, b) is the concatenation of a and b (for example, conc(12, 23) = 1223, conc(100, 11)...
3
import math for _ in range(int(input())): a,b=map(int,input().split()) n=a*(len(str(b+1))-1) print(n)
Bandits appeared in the city! One of them is trying to catch as many citizens as he can. The city consists of n squares connected by n-1 roads in such a way that it is possible to reach any square from any other square. The square number 1 is the main square. After Sunday walk all the roads were changed to one-way ro...
3
import sys, math import io, os #data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline from bisect import bisect_left as bl, bisect_right as br, insort from heapq import heapify, heappush, heappop from collections import defaultdict as dd, deque, Counter from itertools import permutations,combinations def data(): r...
Vasya has a pile, that consists of some number of stones. n times he either took one stone from the pile or added one stone to the pile. The pile was non-empty before each operation of taking one stone from the pile. You are given n operations which Vasya has made. Find the minimal possible number of stones that can b...
3
input() operations = [i for i in input()] counter = 0 for i in operations: if i == '-' and counter > 0: counter -= 1 elif i == '+': counter += 1 print(counter)
You are given n numbers a_1, a_2, ..., a_n. With a cost of one coin you can perform the following operation: Choose one of these numbers and add or subtract 1 from it. In particular, we can apply this operation to the same number several times. We want to make the product of all these numbers equal to 1, in other wo...
3
# ========= /\ /| |====/| # | / \ | | / | # | /____\ | | / | # | / \ | | / | # ========= / \ ===== |/====| # code def main(): n = int(input()) k = 0 a = list(map(int,input().split())) # a.sort() l = 0 ...
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all n squad soldiers to line up on the parade ground. By the military charter the soldiers should stand in the order of non-increasing of their h...
1
n=int(raw_input()) a=[0 for i in range(n)] a=map(int,raw_input().split()) ans=0 for i in range(n): if a[i]==max(a): ans+=i break for i in range(n): if a[n-1-i]==min(a): if ans>n-1-i: ans-=1 ans+=i break print ans
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≀i≀n), the sum of the terms from the 1-st through i-...
3
N = int(input()) A = [int(_) for _ in input().split()] def f(sign): ans = 0 s = 0 for i in range(N): a = A[i] s += a if s == 0: ans += 1 s = sign else: a_sign = s // abs(s) if a_sign != sign: ans += abs(s) + 1...
Gildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it. Gildong tries so hard to satisfy the customers that he even memorized all customers' preferred temperature ranges! Looking through the reservation list, he wants to satisfy all custo...
3
import sys import os import time import collections from collections import Counter, deque import itertools import math import timeit import random ######################### # imgur.com/Pkt7iIf.png # ######################### def sieve(n): if n < 2: return list() prime = [True for _ in range(n + 1)] p = 3...
Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected. The pasture is a rectangle consisting of R Γ— C cells. Each cell is either empty, contains a sheep, a wolf or a dog...
3
x, y = list(map(int, input().split())) grid = [] grid2 = [] arrmain = [] for _ in range(x): s = input() arr = list(s) grid.append(arr) if 'WS' in s or 'SW' in s: print("No") exit() else: if _ == 0: s = s.replace(".", "D") arrmain.append(s) else...
problem Five students, Taro, Jiro, Saburo, Shiro, and Hanako, participated in the JOI High School class. In this class, a final exam was conducted. All five people took the final exam. For students with a final exam score of 40 or higher, the final exam score was used as is. All students with a final exam score of le...
3
i=0 y=0 while i<5 : x=int(input()) if x<40 : x=40 y=y+x i=1+i print(y//5)
Mislove had an array a_1, a_2, β‹…β‹…β‹…, a_n of n positive integers, but he has lost it. He only remembers the following facts about it: * The number of different numbers in the array is not less than l and is not greater than r; * For each array's element a_i either a_i = 1 or a_i is even and there is a number (a_i)/(...
3
a=list(map(int,input().split()))[:3] n,l,r=a[0],a[1],a[2] Min=n-l i=0 while(i!=l): Min+=(2**i) i+=1 Max=(n-r)*(2**(r-1)) i=0 while(i!=r): Max+=(2**i) i+=1 print(Min,Max)