problem
stringlengths
29
9.39k
language
int64
1
3
solution
stringlengths
7
465k
Allen has a LOT of money. He has n dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are 1, 5, 10, 20, 100. What is the minimum number of bills Allen could receive after withdrawing his entire balance? Input The first...
3
n=int(input()) c1=n//100 ra=n%100 c2=ra//20 ra=ra%20 c3=ra//10 ra=ra%10 c4=ra//5 ra=ra%5 c5=ra//1 ra=ra%1 z=c1+c2+c3+c4+c5 print(z)
n! = n Γ— (n βˆ’ 1) Γ— (n βˆ’ 2) Γ— ... Γ— 3 Γ— 2 Γ— 1 Is called the factorial of n. For example, the factorial of 12 12! = 12 x 11 x 10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = 479001600 And there are two consecutive 0s at the end. Write a program that inputs the integer n and outputs the number of consecutive 0s at the end of...
3
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import itertools def count_zeros(n): result = 0 for x in itertools.count(1): divisor = 5 ** x if divisor > n: break else: result += (n // divisor) return result if __name__ == "__main__": while True: ...
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: * deletes all the vowels, * inserts a character "." before each consonant, * repl...
3
vowels = ["A", "O", "E", "Y", "U", "I", "a", "o", "e", "y", "u", "i"] s = input() list1 = [] for letter in s: if letter not in vowels: if letter.isupper(): list1.append("."+letter.lower()) else: list1.append("."+letter) print("".join(list1))
A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay iΒ·k dollars for the i-th banana). He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas? Input The first lin...
3
m = list(map(int,input().split())) k = m[0] n = m[1] w = m[2] c = 0 for i in range(1,w+1): c += (i*k) if n-c < 0: print(abs(n-c)) else: print(0)
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and ai < aj. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a per...
3
import sys #f = open('input', 'r') f = sys.stdin n = int(f.readline()) a = list(map(int, f.readline().split())) cnt = 0 for i in range(n): cnt += sum([1 for x in a[i+1:] if x < a[i]]) m = int(f.readline()) for _ in range(m): l, r = list(map(int, f.readline().split())) c = r-l cnt += (c*(c+1)//2)%2 if cnt%2...
Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti. Spring is starting and the Winter sleep is ...
3
n,k,q = [int(i) for i in input().split()] t = [int(i) for i in input().split()] online = [] for i in range(q): query = [int(j) for j in input().split()] if query[0] == 2: if query[1] in online: print("YES") else: print("NO") else: for j in range(len(online)):...
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
from math import ceil def main(): cc = int(input()) vals = [int(v) for v in input().split()] print(" ".join([str(v) if v%2!=0 else str(v-1) for v in vals])) if __name__ == "__main__": main()
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh a and b respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight. Limak eats a lot and his weight is tripled after every year, while Bob's weight...
3
ages = list(input().split(" ")) ages = [int(i) for i in ages] count = 0 while ages[0] <= ages[1]: count += 1 ages[0] *= 3 ages[1] *= 2 print(count)
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
import sys f = sys.stdin inp = f.readline().strip() if inp[0].islower(): print(inp[0].upper() + inp[1:]) else: print(inp)
One day, n people (n is an even number) met on a plaza and made two round dances, each round dance consists of exactly n/2 people. Your task is to find the number of ways n people can make two round dances if each round dance consists of exactly n/2 people. Each person should belong to exactly one of these two round da...
3
import sys INF = float('inf') #10**20,2**63,float('inf') MOD = 10**9 + 7 MOD2 = 998244353 #from collections import defaultdict def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LC(): return list(input()) def IC(): return [int(c) for c in input()] def MI(): retu...
Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a regular array of numbers Valera manages to see something beautiful and magical. Valera absolutel...
3
input() j = k = s = 0 for i in input().split(): if i != j: k, j = 0, i k += 1 s += k print(s)
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
q = int(input()) for i in range(q): a, b, n, s = [int(i) for i in input().split()] x = s % n y = s // n if x <= b and y <= a: print('YES') elif a < y and (n*a + b) >= s: print('YES') else: print('NO')
You're given an array a of length 2n. Is it possible to reorder it in such way so that the sum of the first n elements isn't equal to the sum of the last n elements? Input The first line contains an integer n (1 ≀ n ≀ 1000), where 2n is the number of elements in the array a. The second line contains 2n space-separat...
3
n=int(input()) l=list(map(int,input().split())) l.sort() s1=sum(l[:n]) s2=sum(l[n::]) if s1==s2: print(-1) else: print(" ".join(map(str,l)))
You are given three integers a, b and x. Your task is to construct a binary string s of length n = a + b such that there are exactly a zeroes, exactly b ones and exactly x indices i (where 1 ≀ i < n) such that s_i β‰  s_{i + 1}. It is guaranteed that the answer always exists. For example, for the string "01010" there ar...
3
l=[int(x) for x in input().split()] a=l[0] b=l[1] n=a+b y=l[2] x=y res="" t="" if(x!=1): while(x>0): if a>b: t+='0' x-=1 a-=1 if(x>0): t+='1' b-=1 x-=1 else: t+='1' b-=1 x-=1 if(x>0): t+='0' a-=1 x-=1 # print("t",t) g=0 if(x==1): for i in range(b): t+='1' ...
Imp likes his plush toy a lot. <image> Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only on...
3
x,y=map(int, input().split()) if(abs(x-y)%2)==0 or (y==1 and x!=0) or y-x>1 or y==0: print('No') else: print('Yes')
Denis was very sad after Nastya rejected him. So he decided to walk through the gateways to have some fun. And luck smiled at him! When he entered the first courtyard, he met a strange man who was selling something. Denis bought a mysterious item and it was... Random permutation generator! Denis could not believed hi...
3
from collections import deque for _ in range(int(input())): n = int(input()) vals = [0] * (n + 1) for ind, i in enumerate(map(int, input().split())): vals[i] = ind start = vals[1] right = start val = 1 can = True while True: if val == n: break ind = ...
An undirected graph is called k-regular, if the degrees of all its vertices are equal k. An edge of a connected graph is called a bridge, if after removing it the graph is being split into two connected components. Build a connected undirected k-regular graph containing at least one bridge, or else state that such gra...
3
def f(k): if k == 1: print("YES") print("2 1\n1 2") return if k % 2 == 0: print("NO") return print("YES") ver = 2 + (k - 1) * 4 print(ver, ver * k // 2) print(1, 2 * k) for i in range(2, k + 1): for j in range(k + 1, 2 * k): print(i, j) print(i + 2*k - 1, j + 2 * k - 1) print(1, i) print(2 ...
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. ...
3
d = {} for i in range(int(input())): s = input() if s in d: print(s+str(d[s])) d[s] += 1 else: print("OK") d[s] = 1
Given are two strings S and T consisting of lowercase English letters. Concatenate T and S in this order, without space in between, and print the resulting string. Constraints * S and T are strings consisting of lowercase English letters. * The lengths of S and T are between 1 and 100 (inclusive). Input Input is gi...
3
s,t=input().split() s=t+s print(s)
You are a coach of a group consisting of n students. The i-th student has programming skill a_i. All students have distinct programming skills. You want to divide them into teams in such a way that: * No two students i and j such that |a_i - a_j| = 1 belong to the same team (i.e. skills of each pair of students in t...
3
for _ in range(int(input())): x=int(input()) y=list(map(int,input().split())) c=0 for i in range(x-1): for j in range(x): if abs(y[i]-y[j]) == 1: c+=1 if c==0: print("1") else: print("2")
Little Petya loves playing with squares. Mum bought him a square 2n Γ— 2n in size. Petya marked a cell inside the square and now he is solving the following task. The task is to draw a broken line that would go along the grid lines and that would cut the square into two equal parts. The cutting line should not have any...
1
n, x, y = map(int, raw_input().split()) if (n/2 == x or n/2+1 == x) and (n/2 == y or n/2+1 == y) : print "NO" else: print "YES"
You have two integers l and r. Find an integer x which satisfies the conditions below: * l ≀ x ≀ r. * All digits of x are different. If there are multiple answers, print any of them. Input The first line contains two integers l and r (1 ≀ l ≀ r ≀ 10^{5}). Output If an answer exists, print any of them. Oth...
3
l,r=map(int,input().split()) for i in range(l,r+1): d=i a =[0]*10 fl=1 while d!=0: if a[d%10]: break a[d%10]=1 d//=10 else: print(i) break else: print(-1)
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties: * In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to z...
3
n=int(input()) a=list(map(int,input().split())) b=[] for i in range(len(a)): if(a[i]!=0): b.append(a[i]) print(len(set(b)))
Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system. The term is coming to an end and students start thinking about their grades. Today, a professor told his students that...
3
input() grades = list(sorted([int(x) for x in input().split(' ')],reverse=True)) subjects = 0 while(sum(grades)/len(grades)<4.5): subjects+=1 grades.pop() grades.insert(0,5) print(subjects)
n participants of the competition were split into m teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends. Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could ha...
1
n,m=map(int,raw_input().split()) t=n-m+1 kmax=(t*(t+1)/2)-t kmin=((n % m) * (n / m + 1) * (n / m) / 2) + ((m - n % m) * (n / m) * (-1 + n / m) / 2) print kmin,kmax
DZY loves Physics, and he enjoys calculating density. Almost everything has density, even a graph. We define the density of a non-directed graph (nodes and edges of the graph have some values) as follows: <image> where v is the sum of the values of the nodes, e is the sum of the values of the edges. Once DZY got a ...
1
import sys line1=sys.stdin.readline() n=int(line1.split(' ')[0]) m=int(line1.split(' ')[1].strip('\n')) line2=sys.stdin.readline().strip('\n') nodes=[] for x in line2.split(' '): nodes.append(int(x)) out=0 for i in xrange(0,m): line=sys.stdin.readline().strip('\n').split(' ') out=max(out,(nodes[int(line[0...
Your friend has n cards. You know that each card has a lowercase English letter on one side and a digit on the other. Currently, your friend has laid out the cards on a table so only one side of each card is visible. You would like to know if the following statement is true for cards that your friend owns: "If a car...
1
import math vow = ['a','e','i', 'o' ,'u'] s = raw_input() k = 0 for i in s: if i in vow: k+=1 elif 48<=ord(i)<=57 and int(i)%2==1 : k+=1 print(k)
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and...
3
n=int(input());a=[0]*1000000;x=t=0 for i in map(int,input().split()):a[i]+=i for j in a:x,t=max(x,j+t),x print(x) #khela hobeee :P
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()) t = [int(x) for x in input().split()] k = 0 for i in range(n): if t[i] == 1: k += 1 if k != 0: print('HARD') else: print('EASY')
There is a game called "I Wanna Be the Guy", consisting of n levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game. Little X can pass only p levels of the game. And Little Y can pass only q levels of the game. You are given the indices of levels Little X can pass ...
1
n = input() a = map(int, raw_input().split()) b = map(int, raw_input().split()) if len(set(a[1:] + b[1:])) == n: print "I become the guy." else: print "Oh, my keyboard!"
You are given two positive integers n and k. Print the k-th positive integer that is not divisible by n. For example, if n=3, and k=7, then all numbers that are not divisible by 3 are: 1, 2, 4, 5, 7, 8, 10, 11, 13 .... The 7-th number among them is 10. Input The first line contains an integer t (1 ≀ t ≀ 1000) β€” the ...
3
for _ in range(int(input())): n,k = map(int, input().split()) temp = 0 div=0 while(1): curr_div = k//n k+=(curr_div-div) if(curr_div==div): break div=curr_div print(k)
On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length k (k β‰₯ 3). Nastya was very confused by this present, so she decided to break the door, throwing it on the mountains. Mountains are described by a sequence of heights...
3
cases = int(input()) for c in range(0, cases): raw1 = input().split(" ") n = int(raw1[0]) k = int(raw1[1]) arr = [] cumPeaks = [0] numPeaks = 0 for idx in input().split(" "): arr.append(int(idx)) for idx in range(1, n - 1): if(arr[idx] > arr[idx - 1] and arr[idx] > arr[i...
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies. At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds ai candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her cand...
3
a,b=input().split() n=int(a) k=int(b) l=[int(i) for i in input().split()] remain=0 given=0 ch=0 for i in range(n): remain=remain+l[i] if remain>8: given=given+8 remain=remain-8 else: given=given+remain remain=0 if given>=k: print(i+1) ch=1 break if...
Everybody knows that the m-coder Tournament will happen soon. m schools participate in the tournament, and only one student from each school participates. There are a total of n students in those schools. Before the tournament, all students put their names and the names of their schools into the Technogoblet of Fire. ...
3
m,n,k=map(int,input().split()) p=list(map(int,input().split())) s=list(map(int,input().split())) q=list(map(int,input().split())) lst=[[] for c in range(n)] for c in range(m): lst[s[c]-1].append(p[c]) #print(lst) cou=0 for c in q: if p[c-1]<max(lst[s[c-1]-1]): cou+=1 print(cou)
Modern text editors usually show some information regarding the document being edited. For example, the number of words, the number of pages, or the number of characters. In this problem you should implement the similar functionality. You are given a string which only consists of: * uppercase and lowercase English...
1
l = input() s = raw_input() s = s.replace("()","(_)") s = s.replace(")(",")_(") f1 = 0 if s[0]=="(": f1 = 1 s = s.replace(')','(') x = s.split('(') x = filter(None,x) out = 0 ins = 0 for i in range(len(x)): if i%2 == f1: temp = [len(t.replace("_","")) for t in x[i].split("_")] out = max(max(temp),out) else: ...
There are an integer sequence A_1,...,A_N consisting of N terms, and N buttons. When the i-th (1 ≦ i ≦ N) button is pressed, the values of the i terms from the first through the i-th are all incremented by 1. There is also another integer sequence B_1,...,B_N. Takahashi will push the buttons some number of times so th...
3
N = int(input()) AB = [list(map(int, input().split())) for _ in range(N)] count = 0 for a, b in AB[::-1]: if (count + a) % b: count += (b - (count + a) % b) print(count)
Ivan has number b. He is sorting through the numbers a from 1 to 10^{18}, and for every a writes ([a, b])/(a) on blackboard. Here [a, b] stands for least common multiple of a and b. Ivan is very lazy, that's why this task bored him soon. But he is interested in how many different numbers he would write on the boa...
3
import math n=int(input()) # a=list(map(int,input().split())) # k=[] # cnt=0 # for i in range(n-1): # if a[i+1]<=2*a[i]: # k.append(a[]) if n==1: print(1) else: cnt=0 for i in range(1,int(math.sqrt(n))+1): if n%i==0: if n//i==i: cnt+=1 else: cnt+=2 print(cnt)
The only difference between problems C1 and C2 is that all values in input of problem C1 are distinct (this condition may be false for problem C2). You are given a sequence a consisting of n integers. All these integers are distinct, each value from 1 to n appears in the sequence exactly once. You are making a sequen...
1
import sys,math from fractions import gcd from bisect import bisect_left, bisect from collections import defaultdict from io import BytesIO sys.stdin = BytesIO(sys.stdin.read()) input = lambda: sys.stdin.readline().rstrip('\r\n') n = int(input()) arr = [int(_) for _ in input().split()] st = [] st.append([0,n-1,[],-1]) ...
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
for _ in range(int(input())): n,k=map(int,input().split()) no=10**18 for i in range(1,int(n**(0.5))+1): if n%i==0: if n/i<=k: no=min(no,i) if i<=k: no=min(no,n/i) print(int(no))
n soldiers stand in a circle. For each soldier his height ai is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |ai - aj| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance u...
3
n = int(input()) sol = list(map(int, input().split())) s1 = 0 s2 = n-1 diff = abs(sol[s1] - sol[s2]) for i in range(n-1): if diff > abs(sol[i] - sol[i+1]): s1 = i s2 = i+1 diff = abs(sol[s1] - sol[s2]) print(s1+1, s2+1)
Tired of boring office work, Denis decided to open a fast food restaurant. On the first day he made a portions of dumplings, b portions of cranberry juice and c pancakes with condensed milk. The peculiarity of Denis's restaurant is the procedure of ordering food. For each visitor Denis himself chooses a set of dishes...
3
for _ in range(int(input())): a,b,c=map(int,input().split()) z=0 if a>0: z+=1 a-=1 if b>0: z+=1 b-=1 if c>0: z+=1 c-=1 c,b,a=sorted([a,b,c]) if a>0 and b>0: a-=1;b-=1 z+=1 if a>0 and c>0: a-=1;c-=1 z+=1 i...
During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check. Each participant is identified by some unique positive i...
3
def solve(): n = int(input()) p = True d = [] for _ in range(int(1e5 + 1)): d.append(set()) for _ in range(n): x, k = map(int, input().split()) if x > 0 and x - 1 not in d[k]: p = False else: d[k].add(x) print('YES' if p else 'NO') solve...
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
# -*- coding: utf-8 -*- """ Created on Mon Jul 29 23:22:06 2019 @author: user """ n = int(input()) cnt = 0 for i in range(0, n): s = list(input()) if(s.count('+')==2): cnt+=1; elif(s.count('-')==2): cnt-=1; print(cnt)
You are given a system of pipes. It consists of two rows, each row consists of n pipes. The top left pipe has the coordinates (1, 1) and the bottom right β€” (2, n). There are six types of pipes: two types of straight pipes and four types of curved pipes. Here are the examples of all six types: <image> Types of pipes ...
3
import sys # 26 input = lambda: sys.stdin.readline().strip() ipnut = input for i in range(int(input())): n = int(ipnut()) field = [list(map(int,ipnut())),list(map(int,input()))] x,y = 0,0 fr = 0 flag = True for i in range(2*n): if y==n: break if fr: if fr...
You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. <image> Figure B-1: A marine area map You can walk from a square land area to another if they are horizontally, vertically, or diagonally adjacent to each other on the map. Two ar...
3
import sys sys.setrecursionlimit(10**7) def dfs(row, column): Map[row][column] = num for i in range(-1, 2): for j in range(-1, 2): if Map[row + i][column + j] == 1: dfs(row + i, column + j) while True: w, h = map(int, input().split()) if w == h == 0: break ...
You are given two strings s and t, both consisting of exactly k lowercase Latin letters, s is lexicographically less than t. Let's consider list of all strings consisting of exactly k lowercase Latin letters, lexicographically not less than s and not greater than t (including s and t) in lexicographical order. For exa...
1
#!/usr/bin/env python from __future__ import division, print_function import os import sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip class FastI(BytesIO): newlines = 0 def __init__...
There are n programmers that you want to split into several non-empty teams. The skill of the i-th programmer is a_i. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team ...
3
for _ in range(int(input())): u, v = list(map(int, input().split())), list(map(int, input().split())) x = u[1] v.sort() ans = 0 for i in reversed(v): if i >= x: ans+=1 v.pop() else: break minsf = 10**9+1 cnt = 0 for i in reversed(v): ...
Phoenix has n blocks of height h_1, h_2, ..., h_n, and all h_i don't exceed some value x. He plans to stack all n blocks into m separate towers. The height of a tower is simply the sum of the heights of its blocks. For the towers to look beautiful, no two towers may have a height difference of strictly more than x. P...
3
n =int(input()) for i in range(n): n,m,x= map(int,input().split()) s=list(map(int,input().split())) li=[] for i in range(len(s)): li.append([s[i],i]) li.sort() sort_index = [] for x in li: sort_index.append(x[1]) Ans=[0]*n cnt=-1 for j in sort_index: cnt+=...
You're given an integer n. For every integer i from 2 to n, assign a positive integer a_i such that the following conditions hold: * For any pair of integers (i,j), if i and j are coprime, a_i β‰  a_j. * The maximal value of all a_i should be minimized (that is, as small as possible). A pair of integers is call...
3
n=int(input()) d=[0]*(n+1) count=1 for i in range(2,n+1): if d[i]==0: j=i while j<n+1: d[j]=count j+=i count+=1 print(*d[2:])
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a ...
3
n, _ = map(int, input().split()) colors = ['C', 'M', 'Y'] lines = [list(filter(lambda x: x in colors, input().split())) for _ in range(n)] for line in lines: if any(line): print('#Color') break else: print('#Black&White')
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...
1
game = raw_input() game = raw_input() A=D=0 for C in game: if C == 'A': A+=1 else: D+=1 if(A>D): print 'Anton' elif(D>A): print 'Danik' else: print 'Friendship'
Valentina is looking for a new game to play with her friends. She asks her mom Marcia for an idea. After a moment Marcia described to girls the following simple game. Girls are divided into n teams, indexed 1 through n. Each girl chooses a lowercase letter, one of 'a' - 'z'. Of course, some girls can choose the same l...
1
from collections import Counter as cnt for i in range(input()): st = raw_input().split() n = int(st[0]) s = cnt(st[1]) ans = [] for j in range(n): ans.append(raw_input()) fn = [] for j in ans: fn.append(sum(s[k] for k in j)) #print fn m=max(fn) l=float('inf') for j in range(n): if fn[j]==m: if len(...
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil"). However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum ti...
3
import collections n=int(input()) a=[int(i) for i in input().split()] m=min(a) d=collections.Counter(a) if d[m]>1: print("Still Rozdil") else: i=a.index(m) print(i+1)
Find the number of sequences of length K consisting of positive integers such that the product of any two adjacent elements is at most N, modulo 10^9+7. Constraints * 1\leq N\leq 10^9 * ~~1~~ 2\leq K\leq 100 (fixed at 21:33 JST) * N and K are integers. Input Input is given from Standard Input in the following forma...
3
MOD = 10 ** 9 + 7 def main(N, K): W = [] i = 1 while i <= N: v = N // i j = N // v # keys.append((v, j - i + 1)) W.append(j - i + 1) i += j - i + 1 l = len(W) dp = [0] * l total = 0 for i, w in enumerate(W): total += w dp[l - i - 1] = total for i in range(2, K + 1): ...
How many multiples of d are there among the integers between L and R (inclusive)? Constraints * All values in input are integers. * 1 \leq L \leq R \leq 100 * 1 \leq d \leq 100 Input Input is given from Standard Input in the following format: L R d Output Print the number of multiples of d among the integers b...
3
l,r,d = map(int,input().split()) x = -(-l//d) y = r//d print(y-x+1)
Johnny has recently found an ancient, broken computer. The machine has only one register, which allows one to put in there one variable. Then in one operation, you can shift its bits left or right by at most three positions. The right shift is forbidden if it cuts off some ones. So, in fact, in one operation, you can m...
3
# -*- coding: utf-8 -*- import math import collections import bisect import heapq import time import random import itertools import sys from typing import List """ created by shhuan at 2020/6/4 22:33 """ T = int(input()) def solve(a, b): if a == b: return 0 if a < b: return solve(b, a) ...
Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results. Fortunately, Adilbek can optimize the program. If he spends x (x is a non-negative integer) days opt...
3
import sys import math import collections import heapq input=sys.stdin.readline t=int(input()) for w in range(t): n,d=(int(i) for i in input().split()) le=0 ri=n c=0 while(le<ri): mid=(le+ri)//2 if(mid+math.ceil(d/(mid+1))<=n): c=1 break else: ...
In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4 Γ— 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the p...
1
import sys l = [] for i in range(4): t = sys.stdin.readline()[:-1] tmp = [] for ch in t: tmp.append(ch) l.append(tmp) def isok(l): for i in range(3): for j in range(3): if(l[i][j] == l[i+1][j] == l[i][j+1] == l[i+1][j+1]): return True return False def...
This is the easy version of the problem. The difference between the versions is that in the easy version all prices a_i are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All n ice spheres are placed in a row ...
3
from math import ceil n = int(input()) a = list(map(int, input().split())) if n <= 2: print("0") for e in a: print(e, end=" ") print() else: a = sorted(a) a_1 = a[:ceil((len(a)-2)/2)] a_2 = a[ceil((len(a)-2)/2):-2] print(ceil((len(a)-2)/2)) print(a[-2], end=" ") for i in range(len(...
In programming, hexadecimal notation is often used. In hexadecimal notation, besides the ten digits 0, 1, ..., 9, the six letters `A`, `B`, `C`, `D`, `E` and `F` are used to represent the values 10, 11, 12, 13, 14 and 15, respectively. In this problem, you are given two letters X and Y. Each X and Y is `A`, `B`, `C`,...
1
X,Y = raw_input().split() if X < Y: print '<' elif X == Y: print '=' else: print '>'
There is an N-car train. You are given an integer i. Find the value of j such that the following statement is true: "the i-th car from the front of the train is the j-th car from the back." Constraints * 1 \leq N \leq 100 * 1 \leq i \leq N Input Input is given from Standard Input in the following format: N i O...
3
n, i = [int(x) for x in input().split()] print(n+1-i)
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers. Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - ...
3
# 199A z = int(input()) all_fib = [0, 1, 1] while all_fib[-1] < z: all_fib.append(all_fib[-2] + all_fib[-1]) def check(num): result = [0, 0, 0] for i in all_fib: for j in all_fib: for k in all_fib: if i + j + k == z: return (i, j, k) return resul...
Shubham has a binary string s. A binary string is a string containing only characters "0" and "1". He can perform the following operation on the string any amount of times: * Select an index of the string, and flip the character at that index. This means, if the character was "0", it becomes "1", and vice versa. ...
3
# -*- coding: utf-8 -*- num_inputs = int(input()) for c in range(num_inputs): string = input() converted_string = [] temp_char = string[0] temp_length = 0 for char in string: if char == temp_char: temp_length += 1 else: temp_char = char converted_...
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
3
for i in range(int(input())): a = input() print (a if len(a)<11 else a[0] + str(len(a) - 2) + a[len(a) - 1])
We have N cards numbered 1, 2, ..., N. Card i (1 \leq i \leq N) has an integer A_i written in red ink on one side and an integer B_i written in blue ink on the other side. Initially, these cards are arranged from left to right in the order from Card 1 to Card N, with the red numbers facing up. Determine whether it is ...
3
def tentousu(a): ans=0 for i in range(len(a)): for j in range(i+1,len(a)): if a[i]>a[j]:ans+=1 return ans n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) for i in range(1,n,2):a[i],b[i]=b[i],a[i] ans=inf=float('inf') for i in range(2**n): s=bin(i)[2:].zfill(n) if s.c...
You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal. The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token. As input/output can reach huge...
3
a, b = input().lstrip('0'), input().lstrip('0') n, m = len(a), len(b) if n == m: print('=' if a == b else '<' if a < b else '>') else: print('<' if n < m else '>')
A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is said to be the superior of another employee B if at least one of the following is true: * Employee A is the immediate manag...
3
n = int(input()) m = {} h = 0 for i in range(1, n + 1): m[i] = [int(input()), set(), 0] for i in range(1, n + 1): s = set() for j in range(1, n + 1): if m[j][0] == i: s.add(j) m[i][1] = s for i in range(1, n + 1): if len(m[i][1]) == 0: c = 0 m[i][2] = c ...
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards. Rules of this game are simple: each player bring his favourite n-digit credit card. Then both players name the digits written on their...
3
# https://codeforces.com/problemset/problem/777/B # Problem # Big O: # Time complexity: O(n log (n)) + 2*(O(n) + O(n))*O(k) = O(n)*O(k) # Space complexity: 3*O(n) = O(n) # Problem def value_index_greater_or_equal_than(ordered_list, number): for i in range(0, len(ordered_list)): element = ordered_list[i] ...
Given is a string S. Replace every character in S with `x` and print the result. Constraints * S is a string consisting of lowercase English letters. * The length of S is between 1 and 100 (inclusive). Input Input is given from Standard Input in the following format: S Output Replace every character in S with ...
3
S=input() s=len(S) print("x"*s)
Arya has n opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya...
1
n, d = map(int, raw_input().split()) str1 = "1" * n global_max = 0 current = 0 for i in range(d): if(current > global_max): global_max = current inp = raw_input() if(inp==str1): current = 0 else: current += 1 if(current > global_max): global_max = current print global_max
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, ...
3
from itertools import permutations #from fractions import Fraction from collections import defaultdict from math import* import os import sys from io import BytesIO, IOBase from heapq import nlargest from bisect import* import copy import itertools BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init_...
"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
x,y = map(int,input().split()) li = list(map(int,input().split())) print(sum([x>=max(1,li[y-1]) for x in li]))
HQ9+ is a joke programming language which has only four one-character instructions: * "H" prints "Hello, World!", * "Q" prints the source code of the program itself, * "9" prints the lyrics of "99 Bottles of Beer" song, * "+" increments the value stored in the internal accumulator. Instructions "H" and "Q"...
3
# -*- coding: utf-8 -*- import math import collections import bisect import heapq import time import random import itertools import sys """ created by shhuan at 2017/11/21 22:37 """ s = input() if 'H' in s or 'Q' in s or '9' in s: print("YES") else: print("NO")
Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated? There are n students living in a building, and for each of them the favorite drink a_i is known. So you know n integer...
3
n, k = list(map(int, input().split())) d = {} for _ in range(n): t = int(input()) d[t] = d.get(t, 0) + 1 k = [i%2 for i in d.values()] print(n-(k.count(1)//2))
Nick had received an awesome array of integers a=[a_1, a_2, ..., a_n] as a gift for his 5 birthday from his mother. He was already going to explore its various properties but after unpacking he was disappointed a lot because the product a_1 β‹… a_2 β‹… ... a_n of its elements seemed to him not large enough. He was ready t...
3
n=int(input()) l=[x for x in map(int,input().split())] l=[min(x,-x-1) for x in l] if n%2!=0: m=l.index(min(l)) l[m]=-l[m]-1 s=' '.join([str(x) for x in l]) print(s)
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same. More formally, you need to find the number of such pairs of indices i, j (2 ≀ i ≀ j ≀ n - 1), that <image>...
3
n = int(input()) #n, m = map(int, input().split()) #s = input() c = list(map(int, input().split())) k = sum(c) if k % 3 == 0 and n >= 3: k = k // 3 a = [0] * n b = [0] * n s = 0 for i in range(n - 1, 1, - 1): s += c[i] if s == k : a[i] = 1 b[-1] = a[-1] for ...
The only difference between easy and hard versions is the maximum value of n. You are given a positive integer number n. You really love good numbers so you want to find the smallest good number greater than or equal to n. The positive integer is called good if it can be represented as a sum of distinct powers of 3 (...
3
def func(): for i in li: if i>= n: return i li = [1, 3, 4, 9, 10, 12, 13, 27, 28, 30, 31, 36, 37, 39, 40, 81, 82, 84, 85, 90, 91, 93, 94, 108, 109, 111, 112, 117, 118, 120, 121, 243, 244, 246, 247, 252, 253, 255, 256, 270, 271, 273, 274, 279, 280, 282, 283, 324, 325, 327, 328, 333, 334, 336, 33...
A positive (strictly greater than zero) integer is called round if it is of the form d00...0. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all numbers from 1 to 9 (inclusive) are round. For example, the following numbers are roun...
3
for mda in range(int(input())): x = input()[::-1] print(len(x) - x.count('0')) for i in range(len(x)): if x[i] != '0': print(x[i] + "0" * i, end = " ") print()
There are n cities in Bearland, numbered 1 through n. Cities are arranged in one long row. The distance between cities i and j is equal to |i - j|. Limak is a police officer. He lives in a city a. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he knows that ther...
1
import sys from math import * from collections import defaultdict from string import ascii_lowercase as lcs from string import ascii_uppercase as ucs from fractions import Fraction, gcd from decimal import Decimal, getcontext from itertools import product, permutations, combinations, count #getcontext().prec = 500 #sys...
Patrick likes to play baseball, but sometimes he will spend so many hours hitting home runs that his mind starts to get foggy! Patrick is sure that his scores across n sessions follow the identity permutation (ie. in the first game he scores 1 point, in the second game he scores 2 points and so on). However, when he ch...
3
""" Satwik_Tiwari ;) . 4th july , 2020 - Saturday """ #=============================================================================================== #importing some useful libraries. from __future__ import division, print_function from fractions import Fraction import sys import os from io import BytesIO, ...
Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the wardrobe. He has n distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to n. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the sock...
3
nb_pair = int(input()) drawn = [int(x) for x in input().split()] maxs = 1 table = set() for i in drawn: table ^= {i} maxs = max(maxs, len(table)) print(maxs)
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...
1
import sys line_1 = sys.stdin.readline().strip().lower() line_2 = sys.stdin.readline().strip().lower() if line_1 == line_2: print 0 else: print -1 if line_1 < line_2 else 1
And while Mishka is enjoying her trip... Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend. Once walking with his friend, John gave Chris the following proble...
3
#!/usr/bin/env python #-*-coding:utf-8 -*- n,w,v,u=map(int,input().split()) v=u/v l=r=0 for _ in range(n): x,y=map(int,input().split()) y-=v*x l=min(l,y) r=max(r,y) print((w-(l if r else 0))/u)
The bear has a string s = s1s2... s|s| (record |s| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices i, j (1 ≀ i ≀ j ≀ |s|), that string x(i, j) = sisi + 1... sj contains at least one string "bear" as a substring. String x(i, j) contains strin...
3
x=input() sm=0 for i in range(len(x)): t=x.find('bear',i) if t>=0: sm+=len(x)-t-3 print(sm)
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=input() lis=list(n) c=0 for i in lis: if i=='7' or i=='4': c=c+1 if c==7 or c==4: print("YES") else: print("NO")
There is a bookshelf which can fit n books. The i-th position of bookshelf is a_i = 1 if there is a book on this position and a_i = 0 otherwise. It is guaranteed that there is at least one book on the bookshelf. In one move, you can choose some contiguous segment [l; r] consisting of books (i.e. for each i from l to r...
3
for i in range(int(input())): l=int(input()) p=list(map(int,input().split())) pos=[] for j in range(l): if p[j]==1: pos.append(j) s=min(pos) e=max(pos) c=0 for j in range(s,e+1): if p[j]==0: c+=1 print(c)
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity. There are n columns of toy cubes in the box arranged in a line. The i-th column contains ai cubes. At first, the gravity in the box is pulling...
1
n = input() a = map(int , raw_input().split()) a.sort() for i in xrange (n): a[i]=str(a[i]) print ' '.join(a)
There are n dormitories in Berland State University, they are numbered with integers from 1 to n. Each dormitory consists of rooms, there are a_i rooms in i-th dormitory. The rooms in i-th dormitory are numbered from 1 to a_i. A postman delivers letters. Sometimes there is no specific dormitory and room number in it o...
3
n,m=map(int,input().split()) a=*map(int,input().split()), i=c=d=0 for x in map(int,input().split()): while c+a[i]<x:c+=a[i];d+=1;i+=1 print(d+1,x-c)
A PIN code is a string that consists of exactly 4 digits. Examples of possible PIN codes: 7013, 0000 and 0990. Please note that the PIN code can begin with any digit, even with 0. Polycarp has n (2 ≀ n ≀ 10) bank cards, the PIN code of the i-th card is p_i. Polycarp has recently read a recommendation that it is bette...
3
t=int(input()) for ij in range(0,t): n=int(input()) l=[] ans=0 la=[] li=[] for i in range(0,n): s=input() la.append(s) if s in l: ans+=1 li.append(i) else: l.append(s) print(ans) for i in li: s=la[i] for k in range(0,4): t=0 for j in range(0,10): s1=s[:k]+str(j)+s[k+1:] if s1 ...
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited n his friends there. If t...
1
n = int(input()) res = [0]*n l = map(int, raw_input().split()) for i in xrange(n): res[l[i]-1] = i for i in xrange(n): print res[i]+1,
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he ...
3
def main(): n, m = [int(i) for i in input().split()] s = [int(i) for i in input().split()] s.sort() i = 0 ans = 0 while i < m and s[i] < 0: ans += abs(s[i]) i += 1 print(ans) if __name__ == "__main__": main()
Polycarp decided to relax on his weekend and visited to the performance of famous ropewalkers: Agafon, Boniface and Konrad. The rope is straight and infinite in both directions. At the beginning of the performance, Agafon, Boniface and Konrad are located in positions a, b and c respectively. At the end of the performa...
3
import math numbers = list(map(int, input().split())) d = numbers[3] L = numbers[0:3].copy() L.sort() a = L[0] b = L[1] c = L[2] S = min(c-b-d, 0) + min(b-a-d,0) print(-S)
Polycarp loves ciphers. He has invented his own cipher called repeating. Repeating cipher is used for strings. To encrypt the string s=s_{1}s_{2} ... s_{m} (1 ≀ m ≀ 10), Polycarp uses the following algorithm: * he writes down s_1 ones, * he writes down s_2 twice, * he writes down s_3 three times, * ... ...
3
t = input() s = '' while (len(t)) > 0: if len(t) % 2 == 0: s = t[-1] + s t = t[:len(t) - 1] else: s = t[0] + s t = t[1:] print(s)
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
import sys def main(): inp = sys.stdin.read().strip().split('\n') d = dict() for i in range(1, 3): for j in map(int, inp[i].split()): d[j] = i return list(map(d.get, sorted(d))) print(*main())
Let N be a positive odd number. There are N coins, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), when Coin i is tossed, it comes up heads with probability p_i and tails with probability 1 - p_i. Taro has tossed all the N coins. Find the probability of having more heads than tails. Constraints * N is an od...
1
from __future__ import division import sys raw_input = sys.stdin.readline N = int(raw_input()) ans = [0 for x in range(N+1)] ans[0] = 1 arr = map(float,raw_input().split()) for i in range(N): a = arr[i] for j in range(i+1,0,-1): ans[j] += ans[j-1]*a ans[j-1] *= (1-a) res = 0 for i in range(int(N...
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(x) for x in input().split() if int(x)<=5-k] print(len(a)//3)
After a team finished their training session on Euro football championship, Valeric was commissioned to gather the balls and sort them into baskets. Overall the stadium has n balls and m baskets. The baskets are positioned in a row from left to right and they are numbered with numbers from 1 to m, correspondingly. The ...
3
n, m = map(int, input().split()) center = (m+1)//2 result = [] pos = center for i in range(n): result.append(pos) if pos == center and m%2 == 1: pos -= 1 elif pos <= center: pos = m-pos+1 else: pos = m-pos if pos == 0: pos = center print('\n'.join(list(map(str, result))))
Let's call left cyclic shift of some string t_1 t_2 t_3 ... t_{n - 1} t_n as string t_2 t_3 ... t_{n - 1} t_n t_1. Analogically, let's call right cyclic shift of string t as string t_n t_1 t_2 t_3 ... t_{n - 1}. Let's say string t is good if its left cyclic shift is equal to its right cyclic shift. You are given str...
3
t = int(input()) for _ in range(t): s = input() data = [] req = [] for _ in range(10): temp = [] temp1 = [] for _ in range(10): temp.append(0) temp1.append(-1) data.append(temp) req.append(temp1) for i in s: i = int(i) f...
Let's call a list of positive integers a_0, a_1, ..., a_{n-1} a power sequence if there is a positive integer c, so that for every 0 ≀ i ≀ n-1 then a_i = c^i. Given a list of n positive integers a_0, a_1, ..., a_{n-1}, you are allowed to: * Reorder the list (i.e. pick a permutation p of \{0,1,...,n - 1\} and change...
3
import sys import math import heapq import collections def inputnum(): return(int(input())) def inputnums(): return(map(int,input().split())) def inputlist(): return(list(map(int,input().split()))) def inputstring(): return([x for x in input()]) def inputstringnum(): return([ord(x)-ord('a') for x in...
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
x = 0 n = int(input()) for i in range(n): c = input() if c == "X++" or c == "++X": x += 1 elif c == "--X" or c == "X--": x -= 1 print(x)