problem
stringlengths
29
9.39k
language
int64
1
3
solution
stringlengths
7
465k
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
1
st1 = raw_input() st2 = raw_input() st = "" for i in range(len(st2)): if (int(st2[i]) == int(st1[i])): st += str('0') else: st += str('1') print st
Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different. In Ancient Berland arenas in circuses were shaped as a regular (equiangular) polygon, the size and the number of angles could vary from one circus to another. In each corner of the arena there was a spec...
1
from sys import stdin from math import hypot, acos, pi, sin, fabs x1, y1, x2, y2, x3, y3 = map(float, stdin.read().split()) flagx12, flagy12 = 0, 0 if y1 == y2: flagx12 = 1 valx12 = (x1 + x2) / 2. elif x1 == x2: flagy12 = 1 valy12 = (y1 + y2) / 2. else: k12 = (x1 - x2) / (y2 - y1) b12 = (y1 + y2) / 2. - k12 * (...
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...
1
s = raw_input() s_array = list(s) pointer = 'a' count = 0 for e in s_array: dist = abs(ord(e)- ord(pointer)) if dist <= 13: count = count + dist else: count = count + (26 - dist) pointer = e print count
Polycarp is going to participate in the contest. It starts at h_1:m_1 and ends at h_2:m_2. It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed tha...
3
sh, sm = input().split(':') eh, em = input().split(':') end = int(eh)*60 + int(em) start = int(sh)*60 +int(sm) ans = (start+end)//2 print("{:02d}:{:02d}".format(ans//60, ans%60))
You are given four integers n, c_0, c_1 and h and a binary string s of length n. A binary string is a string consisting of characters 0 and 1. You can change any character of the string s (the string should be still binary after the change). You should pay h coins for each change. After some changes (possibly zero) ...
3
t = int(input()) for x in range(t): n, c0, c1, h = map(int, input().split()) cadena = str(input()) if c0 == c1: print(n * c0) else: conta0 = 0 conta1 = 0 for element in cadena: if element == "0": conta0 = conta0 + 1 else: ...
Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called "Mau-Mau". To play Mau-Mau, you need a pack of 52 cards. Each card has a suit (Diamonds — D, Clubs — C, Spades — S, or ...
3
table = str(input()) #table=input() hand = str(input()) #hand=input() if table[0] in hand or table[1] in hand: print("YES") else: print("NO")
Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: qwertyuiop asdfghjkl; zxcvbnm,./ Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally move...
3
a = ["q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l",";","z","x","c","v","b","n","m",",",".","/"] b = str(input()) c = list(input()) d = "" if b == "R": for i in range(len(c)): for j in range(len(a)): if c[i] == a[j]: d += a[j-1] elif b == "L": for...
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()) arr = list(map(int, input().split())) letters = list(map(int, input().split())) s = 0 d = 0 for letter in letters: while(s + arr[d] < letter): s += arr[d] d += 1 print(d+1, (letter - s), sep = " ")
Polycarp wants to cook a soup. To do it, he needs to buy exactly n liters of water. There are only two types of water bottles in the nearby shop — 1-liter bottles and 2-liter bottles. There are infinitely many bottles of these two types in the shop. The bottle of the first type costs a burles and the bottle of the se...
3
q=int(input()) for i in range(0,q): stream=input().split() n=int(stream[0]) a=int(stream[1]) b=int(stream[2]) print(str(min(a*n,b*int(n/2)+(n%2)*a)))
Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots. For every bullet that hits the shield, Ebony deals a units of damage while Ivory deals b units of dama...
3
import math a, b, c = [int(i) for i in input().split()] x = 1 y = 0 x1 = 0 y1 = 1 a1 = a b1 = b while b1: q = a1 // b1 (x, x1) = (x1, x - q * x1) (y, y1) = (y1, y - q * y1) (a1, b1) = (b1, a1 - q * b1) if c % a1 != 0: print("No") else: x = (x*c)//a1 y = (y*c)//a1 left1 = math.ceil((-a1*x...
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 t in range(T): s=input() mx=0 arr=[] for i in range(10): arr.append([]) cnt=0 for k in s: arr[int(k)].append(cnt) cnt+=1 for i in range(9): for j in range(i+1,10): odd=0 even=0 m,n=0,0 an...
Amr loves Geometry. One day he came up with a very interesting problem. Amr has a circle of radius r and center in point (x, y). He wants the circle center to be in new position (x', y'). In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle ...
3
import math c = [] c = input().split() r = int(c[0]) x = int(c[1]) y = int(c[2]) a = int(c[3]) b = int(c[4]) print(math.ceil(math.sqrt((x-a)*(x-a)+(y-b)*(y-b))/(2*r)))
Polycarp loves ciphers. He has invented his own cipher called Right-Left. Right-Left cipher is used for strings. To encrypt the string s=s_{1}s_{2} ... s_{n} Polycarp uses the following algorithm: * he writes down s_1, * he appends the current word with s_2 (i.e. writes down s_2 to the right of the current resul...
3
s = list(input()) if len(s) < 3: print(*s,sep="") else: if len(s) % 2 == 0: mid = len(s)//2 else: mid = (len(s)//2)+1 l1=[] l1.append(s[mid-1]) l2 = s[:mid-1] l3 = s[mid:] a = 0 for i in range(1,(len(s))//2): l1.append(l3[i-1]) l1.append(l2[-i]) a+=1 if a!= len(l3): l1.append(l3[-1]) if a != len(...
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >. The following definition of a...
3
from collections import deque s = list(input()) d = deque() r = 0 for i in range(len(s)): if s[i] in {"<","{","[","("}: d.appendleft(s[i]) else: if (len(d)==0): print("Impossible") exit() v=d.popleft() if (v=="[" and s[i]!="]") or (v=="{" and s[i]!="}") o...
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc. Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds ...
3
def main(): s = input() n = int(input()) b = ['I', '1', 'l', 'L', 'i'] c = ['0', 'o', 'O'] for i in range(n): d = input() if len(d) != len(s): continue for j in range(len(s)): if d[j].lower() == s[j].lower(): continue if d[...
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 for _ in range(int(input())): st = str(input()) if st[1] == '+' : x += 1 else : x -= 1 print(x)
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()) if 2 < w <= 100: if w%2 == 0: print('YES') else: print('NO') else: print('NO')
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...
1
palavra = raw_input() new = "" vogais = "aeiouyAEIOUY" for i in range(len(palavra)): if palavra[i] not in vogais: new += "."+palavra[i].lower() print new
There is a rectangular grid of n rows of m initially-white cells each. Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a non-empty subset of columns Ci are chosen. For each row r in Ri and each column c in Ci, the intersection of row r and...
3
st = input().split() n,m = int(st[0]),int(st[1]) map = [input() for i in range(n)] for i in range(n): for j in range(m): if map[i][j] == '#': for p in range(n): if p != i and map[p][j] == '#' and map[p] != map[i]: print('No') exit() print...
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected ...
3
s1, s2 = list(map(str, input().split())) l = [] l += [s1, s2] n = int(input()) for i in range(n): s3, s4 = list(map(str, input().split())) if s1 == s3: s1 = s4 else: s2 = s4 l += [s1, s2] for i in range(2 * n + 2): if i % 2 == 0: print(l[i], l[i + 1])
There are N blocks, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Block i has a weight of w_i, a solidness of s_i and a value of v_i. Taro has decided to build a tower by choosing some of the N blocks and stacking them vertically in some order. Here, the tower must satisfy the following condition: * For eac...
3
def main(): import sys input = sys.stdin.readline N = int(input()) wsv = [] for _ in range(N): w, s, v = map(int, input().split()) wsv.append((w, s, v)) wsv.sort(key=lambda x: x[0] + x[1]) inf = 1000000007 dp = [[-inf] * 20001 for _ in range(N+1)] dp[0][0] = 0 f...
You are given an undirected graph consisting of n vertices and m edges. Your task is to find the number of connected components which are cycles. Here are some definitions of graph theory. An undirected graph consists of two sets: set of nodes (called vertices) and set of edges. Each edge connects a pair of vertices....
3
from collections import defaultdict class UnionFind: def __init__(self, num_vertices: int): self._parents = [i for i in range(num_vertices)] self._rank = [1 for _ in range(num_vertices)] def find(self, p: int) -> int: if self._parents[p] != p: self._parents[p] = self.find(s...
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a. Will the robot be able to build the fence Emuskald...
3
n=int(input()) for i in range(n): x=int(input()) p=0 if x<60 or x>180: print('NO') else: for j in range(1,10000): if 180-360/j==x: print('YES') p=1 break if p==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
moves = dict([("R", (+1, 0)), ("D", (0, -1)), ("L", (-1, 0)), ("U", (0, +1))]) def main(): n = int(input()) steps = input().strip() x, y = 0, 0 p_x, p_y = 0, 0 g_x, g_y = 0, 0 ans = 0 c = 0 for i in range(len(steps)): q = steps[i] ...
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
n=int(input()) di={'+':1,'-':0} l=[di[x] for x in input()] tmp=0 was=0 for i in l: if i: tmp+=1 else: if tmp!=0: tmp-=1 print(tmp)
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for k burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of r burles (1 ≤ r ...
3
k,r=map(int,input().split()) i=1 while True: t= (i*k-r)%10==0 u=(i*k)%10==0 # print(u,t,i) i+=1 if t or u: break print(i-1)
A class of students wrote a multiple-choice test. There are n students in the class. The test had m questions, each of them had 5 possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question i worth a_i points. Incorrect answers are graded with zero points....
3
n , m = map(int,input().split()) lis=[] fin=0 ans=[[0]*5 for i in range(m+5)] for i in range(n): a=input() lis.append(a) points=[*map(int,input().split())] for j in range(m): for i in range(n): # print(j,ord(lis[i][j])-ord('A')) ans[j][ord(lis[i][j])-ord('A')] +=(points[j]) fin+=(max(...
You are given an integer sequence of length N, a = {a_1, a_2, …, a_N}, and an integer K. a has N(N+1)/2 non-empty contiguous subsequences, {a_l, a_{l+1}, …, a_r} (1 ≤ l ≤ r ≤ N). Among them, how many have an arithmetic mean that is greater than or equal to K? Constraints * All input values are integers. * 1 ≤ N ≤ 2 ...
3
def add(B,a,n): x = a while x<=n: B[x]+=1 x+=x&(-x) def sums(B,a): x=a S=0 while x!=0: S+=B[x] x-=x&(-x) return S def invnumber(n,A): S=[0]*n A=sorted([(A[i],i) for i in range(n)]) for i in range(1,n): S[A[i][1]]=i B=[0]*(n*2+1) invs=0 ...
Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a × a. What is the least number of flagstones needed to pave the Square? It'...
3
import math n,m,a = map(int,input().split(' ')) result = math.ceil(n/a) * math.ceil(m/a) print(result)
You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible. Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in mu...
3
n, k, m = map(int, input().split()) a = list(map(int, input().split())) c = [0]*m l = 0 for i in range(n): c[a[i] % m] += 1 for i in range(m): if c[i] >= k: print('Yes') for j in range(n): if a[j] % m == i: print(a[j], end=' ') l += 1 if l...
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi — a coordinate on the Ox axis. No two cities are located at a single point. Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (bec...
3
n = int(input()) arr = [int(x) for x in input().split()] for i in range(len(arr)): if i == 0: print(abs(arr[i]-arr[i+1]), abs(arr[i]-arr[n-1])) elif i == n-1: print(abs(arr[i]-arr[n - 2]), abs(arr[i]-arr[0])) else: print(min(abs(arr[i]-arr[i-1]), abs(arr[i]-arr[i+1])), max(abs(arr[i]...
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 for i in range(int(input())): s=input() if s=='++X': x+=1 if s=='X++': x+=1 if s=='--X': x-=1 if s=='X--': x-=1 print(x)
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
from math import log from math import floor t = input() for _ in range(t): n = input() k = floor(log(n)/log(2)) ans = int(n*(n+1)/2) - int(2*(2**(k+1)-1)) print ans
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
a = input() a = a[1:-1] if a: a += ',' a = a.split() print(len(set(a))) else: print(0)
Alice and Bob are playing yet another card game. This time the rules are the following. There are n cards lying in a row in front of them. The i-th card has value a_i. First, Alice chooses a non-empty consecutive segment of cards [l; r] (l ≤ r). After that Bob removes a single card j from that segment (l ≤ j ≤ r). Th...
3
import sys; n = int(input()); arr = list(map(int,input().split())); ans = 0; for i in range(30,0,-1): maxsum = 0; for j in range(n): if(arr[j]>i): maxsum=0; continue; maxsum += arr[j]; maxsum = max(maxsum,0); ans = max(ans,maxsum-i); print(ans); ...
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
l=input().strip('0') print('YES'if l[::-1]==l else'NO') # Made By Mostafa_Khaled
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
vectorx = [] vectory = [] vectorz = [] for _ in range(int(input())): x,y,z = map(int,input().split()) vectorx.append(x) vectory.append(y) vectorz.append(z) if sum(vectorz)==0 and sum(vectory) == 0 and sum(vectorx) == 0: print("YES") else: print("NO")
Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ). Consider a sequence A satisfying the following conditions: * A is a sequence of N positive integers. * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M. Let us define a score of this sequence as follows: * The score is the ...
3
N,M,Q=map(int,input().split()) Query=[list(map(int,input().split())) for i in range(Q)] import itertools ans=0 for x in itertools.combinations_with_replacement(range(1, M+1), N): l=0 for i in range(Q): a,b,c,d=map(int,Query[i]) if x[b-1]-x[a-1]==c: l+=d ans=max(ans,l) print(ans)
Bachgold problem is very easy to formulate. Given a positive integer n represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1. Recall that integer k is called prime if it is greater than 1 and has exactly two positive integer divi...
3
import sys n = int(sys.stdin.readline()) k = n//2 print(k) if n%2==0: print('2 '*k) else: print('2 '*(k-1)+'3')
One day Jeff got hold of an integer sequence a1, a2, ..., an of length n. The boy immediately decided to analyze the sequence. For that, he needs to find all values of x, for which these conditions hold: * x occurs in sequence a. * Consider all positions of numbers x in the sequence a (such i, that ai = x). These...
3
n = int(input()) c = [int(x) for x in input().split(' ')] e = {} for i in range(n): if c[i] not in e.keys(): e[c[i]] = [i, 0] else: if e[c[i]][1] == 0: e[c[i]] = [i, i - e[c[i]][0]] else: if i-e[c[i]][0] == e[c[i]][1]: e[c[i]] = [i, i - e[c[i]][0]] else: e[c[i]] ...
You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2). You want to construct the array a of length n such that: * The first n/2 elements of a are even (divisible by 2); * the second n/2 elements of a are odd (not divisible by 2); * all elements of a are distinct and positi...
3
t = int(input()) for i in range(t): a = int(input()) if a%4==0: print ("YES", end="\n") for j in range(1,a//2+1): print(2*j,end=" ") for j in range(1,a//2): print(2*j-1,end=" ") print(int(3*(a/2)-1),end="\n") else: print("NO")
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
""" Exercise for strings: print(''.join('.'+x for x in input().lower() if x not in'aeyoui')) m, n = [int(x) for x in input().split(' ')] print(m * n // 2) print(eval('*'.join(input().split()))//2) """ a = 0 sentences = int(input()) for i in range(sentences): if '++' in input(): a += 1 else: ...
Write a program which computes the greatest common divisor (GCD) and the least common multiple (LCM) of given a and b. Constraints * 0 < a, b ≤ 2,000,000,000 * LCM(a, b) ≤ 2,000,000,000 * The number of data sets ≤ 50 Input Input consists of several data sets. Each data set contains a and b separated by a single spa...
1
def gcd(a, b): if b == 0: return a return gcd(b, a%b) while True: try: a, b = map(int, raw_input().strip().split(' ')) print "%d %d" % (gcd(a, b), a*b/gcd(a, b)) except EOFError: break
You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly x bacteria in the box at some moment. What is the minimu...
3
X = bin(int(input()))[2:] print(list(X).count("1"))
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn. Sometimes Vladik’s mom so...
3
def main(): R = lambda: map(int, input().split()) n, m = R() p = [0] + list(R()) for _ in range(m): l, r, x = R() v = p[x] c = sum(map(lambda x: x < v, p[l:r+1])) print('Yes' if c == x - l else 'No') main()
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()) res = 0 for _ in range(n): l = input() if l[1]=='+': res +=1 else: res-=1 print(res)
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
n = int(input()) def solve(s): if len(s) > 10: print("{}{}{}".format(s[0], len(s)-2, s[-1])) else: print(s) for _ in range(n): s = input() solve(s)
You are given three integers x, y and n. Your task is to find the maximum integer k such that 0 ≤ k ≤ n that k mod x = y, where mod is modulo operation. Many programming languages use percent operator % to implement it. In other words, with given x, y and n you need to find the maximum possible integer from 0 to n tha...
3
# Hello World program in Python t =int(input()) for _ in range(0,t): li=list(map(int,input().split(" "))) x=li[0] y=li[1] n=li[2] ans=n while(not(ans%x==y)): val=ans%x #print(val) if(val==y): break else: if(y>val): a...
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
s = str(input()) b = int(len(s)) a = 0 c = "" if b == 1 or b ==2: print(s) else: if b%2 == 0: for i in range(len(s)//2): c += s[b-1] c += s[a] b-=1 a+=1 print(c[::-1]) else: for i in range(len(s)//2): c += s[a] ...
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. <image> The combination lock is represented by n rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has t...
3
n=int(input()) a=input() b=input() c=0 for i in range(n): if a[i] > b[i]: if int(a[i]) - int(b[i]) <= 5: c += (int(a[i]) - int(b[i])) else: c += ((9 - int(a[i])) + (int(b[i]) + 1)) elif b[i] > a[i]: if int(b[i]) - int(a[i]) <=5: ...
The following problem is well-known: given integers n and m, calculate <image>, where 2n = 2·2·...·2 (n factors), and <image> denotes the remainder of division of x by y. You are asked to solve the "reverse" problem. Given integers n and m, calculate <image>. Input The first line contains a single integer n (1 ...
3
n = int(input()) m = int(input()) if n > 40: print(m) else: print(m % (2**n))
You are given a chessboard of size n × n. It is filled with numbers from 1 to n^2 in the following way: the first ⌈ (n^2)/(2) ⌉ numbers from 1 to ⌈ (n^2)/(2) ⌉ are written in the cells with even sum of coordinates from left to right from top to bottom. The rest n^2 - ⌈ (n^2)/(2) ⌉ numbers from ⌈ (n^2)/(2) ⌉ + 1 to n^2 ...
1
n, q = map(int, raw_input().strip().split()) for _ in range(q): x, y = map(int, raw_input().strip().split()) cov = (x - 1) / 2 * n if x % 2 == 0: if y % 2 == 0: cov += y / 2 + (n + 1) / 2 else: cov += (y + 1) / 2 + int(n ** 2 + 1) / 2 + n / 2 else: if y ...
Alice is the leader of the State Refactoring Party, and she is about to become the prime minister. The elections have just taken place. There are n parties, numbered from 1 to n. The i-th party has received a_i seats in the parliament. Alice's party has number 1. In order to become the prime minister, she needs to b...
3
array = [] n = 0; coalition = 1; alice = 0; sum = 0; n = input('\n') n = int(n) input_string = input() array = input_string.split() for i in range(len(array)): array[i] = int(array[i]) list.clear for x in array: sum +=x list = [coalition]; alice = array[0]; x = alice; if x > sum/2: print(coaliti...
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not. A substring s[l … r] (1 ≤ l ≤ r ≤ |s|) of a string s = s_{1}s_{2} … s_{|s|} is the string s_...
3
s=input() x=-2 for i in range(len(s)+1): r=s[:i] if(r!=r[::-1]): x=len(r) if(x==-2): print(0) else: print(x)
"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
n,k=map(int,input().split()) a=list(map(int,input().split())) b=a[k-1] c=0 for i in range(n): if a[i]>=b and a[i]!=0: c+=1 print(c)
Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of L meters today. <image> Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner. ...
3
from fractions import gcd def lcm (a, b): return a // gcd(a, b) * b t, w, b = map(int, input().split()) preans = t // lcm(w,b) * min(w, b) + min(min(w,b) - 1, t % lcm(w, b)) ansh = preans // gcd(preans, t) ansl = t // gcd(preans, t) print(ansh, '/', ansl, sep = "")
Dreamoon is a big fan of the Codeforces contests. One day, he claimed that he will collect all the places from 1 to 54 after two more rated contests. It's amazing! Based on this, you come up with the following problem: There is a person who participated in n Codeforces rounds. His place in the first round is a_1, hi...
3
t = int(input()) for _ in range(t): n, x = list(map(int, input().split())) a = list(map(int, input().split())) b = set(a) ans = 0 c = x for i in range(1, n+x+1): if i in b: ans += 1 else: c -= 1 if c < 0: break ans += 1 print(ans)
There are K blue balls and N-K red balls. The balls of the same color cannot be distinguished. Snuke and Takahashi are playing with these balls. First, Snuke will arrange the N balls in a row from left to right. Then, Takahashi will collect only the K blue balls. In one move, he can collect any number of consecutive ...
3
n, k = map(int, input().split()) MOD = 10 ** 9 + 7 for i in range(1, k+1): if i == 1: comb1 = n - k + 1 comb2 = 1 else: comb1 *= (n - k + 2 - i) * pow(i, MOD-2, MOD) comb2 *= (k - i + 1) * pow(i - 1, MOD-2, MOD) print(comb1 * comb2 % MOD)
A frog is currently at the point 0 on a coordinate axis Ox. It jumps by the following algorithm: the first jump is a units to the right, the second jump is b units to the left, the third jump is a units to the right, the fourth jump is b units to the left, and so on. Formally: * if the frog has jumped an even numb...
3
from typing import Iterator def get_num_input() -> Iterator[int]: return map(int, input().split()) def main() -> None: right: int left: int times: int right, left, times = get_num_input() print((right - left) * (times // 2) + right * (times % 2)) if __name__ == "__main__": ONLY_ONCE: ...
Tomorrow Peter has a Biology exam. He does not like this subject much, but d days ago he learnt that he would have to take this exam. Peter's strict parents made him prepare for the exam immediately, for this purpose he has to study not less than minTimei and not more than maxTimei hours per each i-th day. Moreover, th...
3
#! python3 import sys d, sum_time = [ int(x) for x in input().split(' ') ] max_min_time = [] for i in range(d): min_time, max_time = [ int(x) for x in input().split(' ') ] max_min_time.append({'min_time': min_time, 'max_time': max_time, 'difference': max_time - min_time}) sum_of_max_time = sum([ x['max_time'...
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...
3
b = [None] * int(input()) a = map(int, input().split()) for i, x in enumerate(a, 1): b[x - 1] = i print(*b)
Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer n and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer a and subtract it from n such that: * 1 ≤ a ≤ n. * If it's Mahmoud's turn, a has to be even, but if it's Ehab's turn, a has...
1
#!/usr/bin/env python # -*- coding: utf-8 -*- '''n, k = map(int, raw_input().split()) for i in range(k): a = n% 10 if a ==0 : n = n /10 else: n = n -1 print n''' '''n = int(input()) #a = list() m = 0 #for i in range(n): # a.append(map(int, raw_input().split())) a = map(int, raw_input()...
You are playing a very popular game called Cubecraft. Initially, you have one stick and want to craft k torches. One torch can be crafted using one stick and one coal. Hopefully, you've met a very handsome wandering trader who has two trade offers: * exchange 1 stick for x sticks (you lose 1 stick and gain x sticks...
3
for _ in range(int(input())): x, y, k = map(int, input().split()) if not(k+y*k-1)%(x-1): print(int((k+y*k-1)//(x-1) + k)) else: print(int((k+y*k-1)//(x-1) + k + 1))
Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a × a. What is the least number of flagstones needed to pave the Square? It'...
3
b = input("").split() n = int(b[0]) m = int(b[1]) a = int(b[2]) print(int(int((n+a-1)/a)*int((m+a-1)/a)))
Takahashi is standing on a multiplication table with infinitely many rows and columns. The square (i,j) contains the integer i \times j. Initially, Takahashi is standing at (1,1). In one move, he can move from (i,j) to either (i+1,j) or (i,j+1). Given an integer N, find the minimum number of moves needed to reach a ...
3
n = int(input()) l = [n/i + i -2 for i in range(1,int(n**0.5)+1) if n % i == 0] print(int(min(l)))
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for k burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of r burles (1 ≤ r ...
1
def shovel(): k, r = map(int, raw_input().split()) shovels = [k * i for i in range(1, 11)] for j in shovels: q, rem = divmod(j, 10) if rem == r: return j / k if j % 10 == 0 and j % r == 0: return j / k elif j % 10 == 0: return j / k p...
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
t=int(input()) for _ in range(t): n=input() l=len(n) ans=[] for i in range(l): x=int(n[i])*(10**(l-i-1)) if x!=0: ans.append(x) print(len(ans)) print(*ans)
You are given a string s consisting only of lowercase Latin letters. You can rearrange all letters of this string as you wish. Your task is to obtain a good string by rearranging the letters of the given string or report that it is impossible to do it. Let's call a string good if it is not a palindrome. Palindrome is...
3
n=int(input()) for i in range(0,n): s=input().rstrip() x=list(s) y=list(set(s)) if len(y)==1: print(-1) else: x.sort(key=str) C=''.join(x) print(C)
Arkady coordinates rounds on some not really famous competitive programming platform. Each round features n problems of distinct difficulty, the difficulties are numbered from 1 to n. To hold a round Arkady needs n new (not used previously) problems, one for each difficulty. As for now, Arkady creates all the problems...
3
n, k = map(int,input().split()) diff = list(map(int, input().split())) contest = 0 d = {} for i in diff: try: d[i] += 1 except: d[i] = 1 if len(d) == n: for j in range(1,n+1): d[j] -= 1 if d[j] == 0: del d[j] print("1", end="") el...
We have a point A with coordinate x = n on OX-axis. We'd like to find an integer point B (also on OX-axis), such that the absolute difference between the distance from O to B and the distance from A to B is equal to k. <image> The description of the first test case. Since sometimes it's impossible to find such point ...
3
tc = int(input()) def B(A, K): tot = 0 tot += max(0, K-A) A += tot if A & 1 == 1: if K & 1 == 0: tot += 1 else: if K & 1 == 1: tot += 1 return tot for i in range(tc): tc = input() A, K = tc.split() print(B(int(A), int(K)))
The cat Snuke wants to play a popular Japanese game called ÅtCoder, so Iroha has decided to teach him Japanese. When counting pencils in Japanese, the counter word "本" follows the number. The pronunciation of this word varies depending on the number. Specifically, the pronunciation of "本" in the phrase "N 本" for a pos...
1
n=input() if n%10 in [2,4,5,7,9]: print 'hon' elif n%10 in [0,1,6,8]: print 'pon' else: print 'bon'
Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all tests...
1
n, k, p, x, y = map(int, raw_input().split()) takentests = [int(tok) for tok in raw_input().split()] onleft = n / 2 onright = onleft + 1 possible = True for mark in takentests: if mark >= y and onright: onright -= 1 elif onleft: onleft -= 1 else: possible = False break n...
You've got a 5 × 5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1....
3
from math import fabs mass = [] for i in range(5): a, b, c, d, e = input().split() mass.append(int(a)) mass.append(int(b)) mass.append(int(c)) mass.append(int(d)) mass.append(int(e)) iD = 0 for i in mass: if i == 1: break ...
Alice got many presents these days. So she decided to pack them into boxes and send them to her friends. There are n kinds of presents. Presents of one kind are identical (i.e. there is no way to distinguish two gifts of the same kind). Presents of different kinds are different (i.e. that is, two gifts of different ki...
3
#from math import * n,m=map(int,input().split()) ans=pow(2,m,10**9+7)-1 ans=pow(ans,n,10**9+7) print(ans)
Let's consider a table consisting of n rows and n columns. The cell located at the intersection of i-th row and j-th column contains number i × j. The rows and columns are numbered starting from 1. You are given a positive integer x. Your task is to count the number of cells in a table that contain number x. Input T...
3
from math import sqrt, pow, log, log2, log10, exp from copy import deepcopy def read_ints(): return list(map(int, input().split())) def read_int(): return read_ints()[0] def read_floats(): return list(map(float, input().split())) def read_float(): return read_floats()[0] def one_dim_array(valu...
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
a=list(map(str,input())) l=[] for i in range(0,len(a)): if a[i]>='a' and a[i]<='z': l.append(a[i]) print(len(set(l)))
You are given a huge decimal number consisting of n digits. It is guaranteed that this number has no leading zeros. Each digit of this number is either 0 or 1. You may perform several (possibly zero) operations with this number. During each operation you are allowed to change any digit of your number; you may change 0...
3
n, x, y = [int(s) for s in input().split()] x = n - x y = n - y array = [int(s) for s in input()] #print(array) #print(array[x + 1:y]) print(sum(array[x:y - 1]) + sum(array[y:]) + int(array[y - 1] == 0))
AtCoder Inc. holds a contest every Saturday. There are two types of contests called ABC and ARC, and just one of them is held at a time. The company holds these two types of contests alternately: an ARC follows an ABC and vice versa. Given a string S representing the type of the contest held last week, print the str...
3
dict = {'ABC':'ARC', 'ARC':'ABC'} print(dict[input()])
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...
1
w = int(input()) if (w % 2 !=0 or w==2): print("NO") else: print("YES")
A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The n-th triangular number is the number of dots in a triangle with n dots on a side. <image>. You can learn more about these numbers...
1
t = [(n*(n+1))/2 for n in range(0,33)] print "YES" if int(raw_input()) in t else "NO"
Polycarp found under the Christmas tree an array a of n elements and instructions for playing with it: * At first, choose index i (1 ≤ i ≤ n) — starting position in the array. Put the chip at the index i (on the value a_i). * While i ≤ n, add a_i to your score and move the chip a_i positions to the right (i.e. r...
3
for _ in range(int(input())): n=int(input()) a=[int(i) for i in input().split()] b=[-1 for i in range(n)] for i in range(n-1,-1,-1): if i==n-1: b[i]=a[i] else: s=a[i] index=i+1+a[i] while index<=n and b[index-1]==-1: s=s+a[i...
Polycarpus has got n candies and m friends (n ≥ m). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such ai, where ai is the number of candies in the i-th friend's prese...
1
n,m=map(int,raw_input().split()) x=n/m print ' '.join(map(str,(x+(0,1)[i<n%m] for i in range(m))))
There are n people who want to participate in a boat competition. The weight of the i-th participant is w_i. Only teams consisting of two people can participate in this competition. As an organizer, you think that it's fair to allow only teams with the same total weight. So, if there are k teams (a_1, b_1), (a_2, b_2)...
3
import collections t=int(input()) for _ in range(t): n=int(input()) arr=list(map(int,input().split())) freqs=collections.Counter(arr) dd=collections.defaultdict(int) ls=[[i,f] for i,f in freqs.items()] for i in range(len(ls)-1): for j in range(i+1,len(ls)): dd[ls[i][0]+ls[j][...
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
n=int(input()) k=input() a=[] i=0 j=1 while i < n: a.append(k[i]) i+=j j+=1 for i in a: print(i,end='')
Berland Football Cup starts really soon! Commentators from all over the world come to the event. Organizers have already built n commentary boxes. m regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations will be...
3
n,m,a,b=map(int,input().split(' ')) k=n%m print(min(k*b,(m-k)*a))
At last, we have successfully neutralized all the cyber weapons of mass destruction, saved our university along the way and lay to waste another evil scheme in the process. All that separates that hacker from us now is his last lair of security, his ultimate firewall. It is imperative for us to break through this last ...
1
#coded by biraj patel import math testCases=input() while testCases>0 : a=input() b=a sum=0 while a>0 : sum+=a%10; a/=10; try : print int(b*math.pow(2,sum)) except : {} testCases-=1
In Summer Informatics School, if a student doesn't behave well, teachers make a hole in his badge. And today one of the teachers caught a group of n students doing yet another trick. Let's assume that all these students are numbered from 1 to n. The teacher came to student a and put a hole in his badge. The student, ...
3
n = int(input()) p = input().split() for i in range(0, n) : temp = i+1 d = dict() done = False while done == False : d[temp] = d.get(temp, 0) + 1 if d[temp] == 2 : print(str(temp) + ' ' , end = '') done = True temp = int(p[temp - 1])
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers a_1,a_2,…,a_n and b_1,b_2,…,b_m. For each i (1≤ i≤ n), you're asked to choose a j (1≤ j≤ m) and let c_i=a_i\& b_j, where \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise...
3
n,m = [int(x) for x in input().split(' ')] a = [int(x) for x in input().split(' ')] b = [int(x) for x in input().split(' ')] all_a = [] for aa in a: t = [] for bb in b: t.append(aa&bb) all_a.append(t) def get_bit(n,k): return (n&1<<k)>>k final = 0 for i in range(8,-1,-1): can_get_zero = T...
A telephone number is a sequence of exactly 11 digits such that its first digit is 8. Vasya and Petya are playing a game. Initially they have a string s of length n (n is odd) consisting of digits. Vasya makes the first move, then players alternate turns. In one move the player must choose a character and erase it fro...
3
'''input 15 888888888888888 ''' from sys import stdin, stdout import math from copy import deepcopy from collections import defaultdict import heapq def find_eight(arr): eight = [] for i in range(len(arr)): if arr[i] == 8: eight.append(i) return eight def check(arr, removed): new = [] for i in range(len(...
Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting o...
3
i = input() b=list(input().split()) b=[int(h) for h in b] b.sort(reverse=True) n=len(b)//2+len(b)%2 print((sum(b[:n])**2+(sum(b[n:])**2)))
There are b boys and g girls participating in Olympiad of Metropolises. There will be a board games tournament in the evening and n participants have accepted the invitation. The organizers do not know how many boys and girls are among them. Organizers are preparing red badges for girls and blue ones for boys. Vasya ...
3
b = int(input()) g = int(input()) n = int(input()) lista = [] for i in range(n+1): lista.append([]) lista[i].append(i) lista[i].append(n-i) contador = 0 for i in range(n+1): if lista[i][0] <= b and lista[i][1] <= g: contador += 1 print(contador)
Takahashi received otoshidama (New Year's money gifts) from N of his relatives. You are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either `JPY` or `BTC`, and x_i and u_i represent the content of the otoshidama from the i-th relative. For example, if x_1 = `10000` a...
3
N=int(input()) X=0 for n in range(N): x,u=input().split() if u=="BTC": X+=float(x)*380000.0 else: X+=int(x) print(X)
You are given two arrays of integers a_1,…,a_n and b_1,…,b_m. Your task is to find a non-empty array c_1,…,c_k that is a subsequence of a_1,…,a_n, and also a subsequence of b_1,…,b_m. If there are multiple answers, find one of the smallest possible length. If there are still multiple of the smallest possible length, f...
3
for _ in range(int(input())): n, k = map(int, input().split()) a=False num1 = list(map(int, input().split())) num2 = list(map(int, input().split())) for i in range(n): if num1[i] in num2: a=True print('YES') print(1, num1[i]) break if...
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized a × b squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents...
3
n = int(input()) s = input() s = s.split("W") ans = 0 res = [] for c in s: if len(c)>0: ans+=1 res.append(str(len(c))) print(ans) print(" ".join(res))
Polycarp wants to train before another programming competition. During the first day of his training he should solve exactly 1 problem, during the second day — exactly 2 problems, during the third day — exactly 3 problems, and so on. During the k-th day he should solve k problems. Polycarp has a list of n contests, th...
3
n = int(input()) x = list(map(int, input().split())) x.sort() a = [] count = 0 for i in range(n): if x[i] > i or (count < x[i] <= i): a.append(x[i]) count += 1 print(len(a))
A and B are preparing themselves for programming contests. To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger. For each chess piece we know its weight: * the queen's weight is 9, * the rook's weight is 5, * the ...
3
ww, bw = 0, 0 for i in range(8): s = input() for j in s: if 65 <= ord(j) <= 90: if j == 'Q': ww += 9 elif j == 'R': ww += 5 elif j == 'B' or j == 'N': ww += 3 elif j == 'P': ww += 1 e...
Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below. Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group. b4ab979900ed647703389d4349eb84ee.png Constraints * x and y are integers. * 1 ≤ x < y ≤ 12 Input Input i...
3
x,y = map(int,input().split()) group = [-1,0,1,0,2,0,2,0,0,2,0,2,0] print('Yes' if group[x]==group[y] else 'No')
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an integer x and print it as is. Note that multiple datasets are give...
1
cases = [] n = 1 while n != 0: n = int(raw_input()) if n == 0: continue cases.append(n) for i in range(len(cases)): print "Case %d: %d" %(i + 1, cases[i])
Some number of chocolate pieces were prepared for a training camp. The camp had N participants and lasted for D days. The i-th participant (1 \leq i \leq N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result, there were X ...
3
n, d, x, *a = map(int, open(0).read().split()) for i in a: x += 1 + (d - 1) // i print(x)
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
t=int(input()) d={} while(t>0) : x=input() if(x in d) : d[x]+=1 print(x,end="") print(d[x]) else: d[x]=0; print("OK") t-=1