problem
stringlengths
29
9.39k
language
int64
1
3
solution
stringlengths
7
465k
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit. For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not. You have n cards with digits, and you want to use them to make as many phone n...
3
n=int(input()) s=list(input().rstrip()) print(min(s.count('8'),n//11))
New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows h hours and m minutes, where 0 ≀ hh < 24 and 0 ≀ mm < 60. We use 24-hour time format! Your task is to find the number of minutes before the New Year. You know that New Year comes when the...
3
n = int(input()) while n: k = input() k = k.split(' ') h = int(k[0]) m = int(k[1]) ans = 24*60 - ((h*60)+ m) print(ans) n -= 1
Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game? There are n balls put in a row. Each ball is colored in one of k colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color x. He can insert his ball at any p...
1
def isMin(arr): i = 0 l = len(arr) while (i < l-2): if arr[i] == arr[i+1] == arr[i+2]: return False i += 1 return True def colapse(arr): while (not isMin(arr)): newarr=[] i = 0 l = len(arr) # print arr while (i<l-2): ...
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where: * name is a string consisting of lowercase Latin lett...
3
def s(): a = input().split('.') ans = [a[0]+'.'] for i in range(1,len(a)-1): i = a[i] if len(i)<2 or len(i)>11: print('NO') return if len(i)>3: ans[-1]+=i[:3] ans.append(i[3:]+'.') else: ans[-1]+=i[0] ans...
Gildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it. Gildong tries so hard to satisfy the customers that he even memorized all customers' preferred temperature ranges! Looking through the reservation list, he wants to satisfy all custo...
3
def x(a,b,c,d): return([max(a,c),min(b,d)]) q=int(input()) for l in range(q): n,m=map(int,input().split()) a=m b=m k=0 z=0 for l in range(n): t,l,h=map(int,input().split()) a,b=x(a-(t-z),b+(t-z),l,h) z=t if b<a: k=1 if(a<l and b<l) or (a>h and b>h): ...
The only difference between easy and hard versions are constraints on n and k. You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most k most recent conversations with your friends. Initially, the screen is empty (i.e. the number of displayed conversations equals 0...
3
n, k = map(int, input().split()) ids = input().split() hash = set() stack = [] stack_init = 0 for i in ids: if i in hash: continue hash.add(i) stack.append(i) if len(stack) - stack_init > k: last = stack[stack_init] hash.remove(last) stack_init += 1 m = len(stack) - stack_init print(m) res...
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...
1
""" // Author : snape_here - Susanta Mukherjee """ from __future__ import division, print_function import os,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 def ii(): return int(in...
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
3
''' Auther: ghoshashis545 Ashis Ghosh College: jalpaiguri Govt Enggineering College ''' from os import path import sys from heapq import heappush,heappop from functools import cmp_to_key as ctk from collections import deque,defaultdict as dd from bisect import bisect,bisect_left,bisect_right,insort,insort_lef...
You are given positive integers X and Y. If there exists a positive integer not greater than 10^{18} that is a multiple of X but not a multiple of Y, choose one such integer and print it. If it does not exist, print -1. Constraints * 1 ≀ X,Y ≀ 10^9 * X and Y are integers. Input Input is given from Standard Input in...
3
x,y = (int(i) for i in input().split()) if x%y == 0 or y == 1: print(-1) exit() else: print(x*(y-1))
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution....
3
n=int(input()) count = 0 for i in range(n): a,b,c = map(int,input().split()) count += (a+b+c>1) print (count)
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at so...
3
import sys def read_from_stdin(): n, m = input().split() return int(n), int(m) def write_to_stdout(res): sys.stdout.write('%d\n' % res) def half_the_number(number, n): count = 0 while number % 2 == 0 and number > n: new_number = number / 2 if int(new_number) * 2 == number: ...
Alice and Bob play a game. They have a binary string s (a string such that each character in it is either 0 or 1). Alice moves first, then Bob, then Alice again, and so on. During their move, the player can choose any number (not less than one) of consecutive equal characters in s and delete them. For example, if the...
3
for _ in range(int(input())): s = input() ones = [] summ = 0 for i in range(len(s)): if int(s[i]) == 1: summ += int(s[i]) else: ones.append(summ) summ = 0 if i==len(s)-1: ones.append(summ) ones.sort() ones.reverse() prin...
The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person. You are given the first and ...
3
from collections import Counter, deque def lInt(d = None): return map(int, input().split(d)) s, t = input().split(" ") ans = "zzzzzzzzzzzzzzzzzzzz" for i in range(1, len(s)+1): for j in range(1, len(t)+1): x = s[:i]+t[:j] ans = min(ans, x) print(ans)
Find the minimum prime number greater than or equal to X. Constraints * 2 \le X \le 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: X Output Print the minimum prime number greater than or equal to X. Examples Input 20 Output 23 Input 2 Outpu...
3
x = int(input()) for i in range(x, 100003 + 1): for j in range(2, i): if i % j == 0: break else: print(i) break
A frog lives on the axis Ox and needs to reach home which is in the point n. She starts from the point 1. The frog can jump to the right at a distance not more than d. So, after she jumped from the point x she can reach the point x + a, where a is an integer from 1 to d. For each point from 1 to n is known if there is...
3
nPads, jmp = [int(x) for x in input().split()] pads = input() i = 1 nJumps = 0 while i < nPads: #print("position: ", i) if i + jmp >= nPads: #print("last jump") nJumps += 1 break canJump = False for j in range(jmp, 0, -1): #print("trying to jump from ", i, " to ", i+j) ...
You are given three strings a, b and c of the same length n. The strings consist of lowercase English letters only. The i-th letter of a is a_i, the i-th letter of b is b_i, the i-th letter of c is c_i. For every i (1 ≀ i ≀ n) you must swap (i.e. exchange) c_i with either a_i or b_i. So in total you'll perform exactly...
3
# -*- coding: utf-8 -*- """ Created on Thu Feb 13 23:53:57 2020 round 619 div2 A @author: xiaopp """ tcases = int(input()) for i in range(tcases): a = list(input()) b = list(input()) c = list(input()) slen = len(a) flag = True for i in range(slen): if ((a[i] == b[i] and b[i] == c[i]))o...
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
num_queries = int(input()) for _ in range(num_queries): num_members = input() skills = sorted(list(map(int, input().split(" ")))) adjacent = False for skill in skills: if skill + 1 in skills: adjacent = True break if adjacent: print(2) else: print(1)
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...
3
n = int(input()) s = input() words_in = [] words_out = [""] brackets = False buff = "" for i in range(len(s)): if s[i] in ("(", ")", "_"): if buff: if brackets: words_in.append(buff) else: words_out.append(buff) buff = "" if s[i] == ...
Nam is playing with a string on his computer. The string consists of n lowercase English letters. It is meaningless, so Nam decided to make the string more beautiful, that is to make it be a palindrome by using 4 arrow keys: left, right, up, down. There is a cursor pointing at some symbol of the string. Suppose that c...
1
alphax = 'abcdefghijklmnopqrstuvwxyz' alpha = list(alphax) n, pr = map(int, raw_input().split()) a = list(raw_input()) c = (n-1)//2 mem = [] for i in xrange(c+1): m = alpha.index(a[i]) k = alpha.index(a[n-1-i]) temp = abs(m - k) if temp > 13: temp = 26 - temp mem.append(temp) left = 0 righ...
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence is a permutation of 1, 2, ..., N. On this sequence, Snuke can perform the following operation: * Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements....
3
import math n, k = map(int, input().split()) a = input() print(math.ceil((n - 1) / (k - 1)))
Initially, you have the array a consisting of one element 1 (a = [1]). In one move, you can do one of the following things: * Increase some (single) element of a by 1 (choose some i from 1 to the current length of a and increase a_i by one); * Append the copy of some (single) element of a to the end of the array...
3
from math import * for _ in range(int(input())): n=int(input()) sq=floor(sqrt(n)) if(sq*sq >=n): print(2*sq - 2) elif((sq+1)*sq >=n): print(2*sq - 1) else: print(2*sq)
While playing with geometric figures Alex has accidentally invented a concept of a n-th order rhombus in a cell grid. A 1-st order rhombus is just a square 1 Γ— 1 (i.e just a cell). A n-th order rhombus for all n β‰₯ 2 one obtains from a n-1-th order rhombus adding all cells which have a common side with it to it (look ...
3
n=int(input()) squares=1 for i in range(1,n+1): squares+=4*(i-1) print(squares)
Valera has got a rectangle table consisting of n rows and m columns. Valera numbered the table rows starting from one, from top to bottom and the columns – starting from one, from left to right. We will represent cell that is on the intersection of row x and column y by a pair of integers (x, y). Valera wants to place...
3
if __name__ == '__main__': n, m, k = map(int, input().split()) last_block_size = (m * n) - 2 * (k - 1) val = 1; table = dict() for i in range(1, n+1): if i%2: for j in range(1, m+1): table[val] = (i, j) val += 1 else: for j in range(m, 0, -1): table[val] = (i,j) val += 1 val = 1 for _...
You are given a string s such that each its character is either 1, 2, or 3. You have to choose the shortest contiguous substring of s such that it contains each of these three characters at least once. A contiguous substring of string s is a string that can be obtained from s by removing some (possibly zero) character...
3
from collections import defaultdict def solve(s1,s2): if ('1' not in s1) or ('2' not in s1) or ('3' not in s1): return 0 assert s2 != '' d = defaultdict(int) nneg = [0] def incr(c): d[c] += 1 if d[c] == 0: nneg[0] -= 1 def decr(c): if d[c] == 0: ...
You are given two integers n and k. Your task is to construct such a string s of length n that for each i from 1 to k there is at least one i-th letter of the Latin alphabet in this string (the first letter is 'a', the second is 'b' and so on) and there are no other letters except these. You have to maximize the minim...
3
def solve(): n, k = map(int, input().split()) for i in range(n): print(chr(ord('a') + i % k), end="") print("") t = eval(input()) while t: solve() t -= 1
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
def comb(n,k,mod): a = 1 b = 1 for i in range(k): a = a * (n-i) % mod b = b * (i+1) % mod return a * pow(b, mod-2, mod) % mod n,k=map(int,input().split()) mod=10**9+7 for i in range(1,k+1): print((comb(n-k+1,i,mod)*comb(k-1,i-1,mod))%mod)
Little chandu is very fond of playing games. Recently, He found a few straws each of length 1 inches in the store room. He took all of them and decided to mark a rectangular area on the floor with straws and warn rest of the family members to not to enter that area so that he can play in peace. He wants to maximize tha...
1
t=input() while(t>0): n=input() w=n/4 l=n/4+(n%4)/2 print l*w t=t-1
During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each...
3
n, t = map(int, input().split()) queue = list(input()) for step in range(t): i = 0 while i < n - 1: if queue[i] == 'B' and queue[i + 1] == 'G': queue[i], queue[i + 1] = queue[i + 1], queue[i] i += 1 i += 1 print(''.join(queue))
On a planet far, far away, M languages are spoken. They are conveniently numbered 1 through M. For CODE FESTIVAL 20XX held on this planet, N participants gathered from all over the planet. The i-th (1≦i≦N) participant can speak K_i languages numbered L_{i,1}, L_{i,2}, ..., L_{i,{}K_i}. Two participants A and B can c...
3
from collections import deque N, M = map(int, input().split()) G = [[] for i in range(N+M)] check = [0 for j in range(N+M)] def bfs(s): q = deque() check[s] = 1 q.append(s) while len(q) != 0: u = q.popleft() for v in G[u]: if check[v] == 0: check[v] = 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
def ceil(a, b): if a % b == 0: return int(a / b) else: return int(a/b) +1 n, m, a=(input()).split(' ') result = ceil( int(n), int(a)) * ceil(int(m),int(a)) print(result)
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array a of n non-negative integers. Dark created that array 1000 years ago, so some elements in that array disappeared. Dark knows that Motarack hates to see an array that has two adjacent elements with a high...
3
t=int(input()) for i in range(t): n=int(input()) ar=list(map(int,input().split())) br=[] for i in range(n): if ar[i]!=-1: if i-1>=0 and ar[i-1]==-1: br.append(ar[i]) elif i+1<n and ar[i+1]==-1: br.append(ar[i]) if br==[]: print(0,0) continue br.sort() k=(br[0]+br[-1])//2 m=0 for i in range(...
A permutation of length n is a sequence of integers from 1 to n of length n containing each number exactly once. For example, [1], [4, 3, 5, 1, 2], [3, 2, 1] are permutations, and [1, 1], [0, 1], [2, 2, 1, 4] are not. There was a permutation p[1 ... n]. It was merged with itself. In other words, let's take two instanc...
3
T=int(input()) while(T>0): n=int(input()) lt=list(map(int,input().split())) lt2=[] for i in lt: if(i not in lt2): lt2.append(i) for i in lt2: print(i,end=" ") print("") T-=1
Leo Jr. draws pictures in his notebook with checkered sheets (that is, each sheet has a regular square grid printed on it). We can assume that the sheets are infinitely large in any direction. To draw a picture, Leo Jr. colors some of the cells on a sheet gray. He considers the resulting picture beautiful if the follo...
3
n = int(input());print(3*n+4);print(n+1,n+1) for i in range(n+1):print(i+1,i);print(i,i+1);print(i,i)
You have decided to watch the best moments of some movie. There are two buttons on your player: 1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie. 2. Skip exactly x minutes of the movi...
1
import fileinput ### ### # utility func # ### ### dbug = True def stoi(s): return([ int(x) for x in s.split() ]) def pd(s, label=''): global dbug if dbug: header = 'debug:' if label != '': header += ' (%s)\t' % label print header, s ### ### # code follows # ### ### ...
There is a grid with H horizontal rows and W vertical columns. Let (i, j) denote the square at the i-th row from the top and the j-th column from the left. For each i and j (1 \leq i \leq H, 1 \leq j \leq W), Square (i, j) is described by a character a_{i, j}. If a_{i, j} is `.`, Square (i, j) is an empty square; if a...
3
H, W = map(int, input().split()) S = [input() for i in range(H)] MOD = 10**9 + 7 dp = [[0]*(W+1) for i in range(H+1)] dp[1][0] = 1 for i in range(H): s = S[i] for j in range(W): if s[j] == '#': continue dp[i+1][j+1] = (dp[i][j+1] + dp[i+1][j]) % MOD print(dp[H][W])
N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals. The preliminary stage consists of several rounds, which will take place as follows: * All the N contestants will participate in the first round. * W...
3
M = int(input()) ans = -1 S = 0 for i in range(M): d, c = map(int, input().split()) ans += c S += d*c ans += (S - 1) // 9 print(ans)
Maria is the most active old lady in her house. She was tired of sitting at home. She decided to organize a ceremony against the coronavirus. She has n friends who are also grannies (Maria is not included in this number). The i-th granny is ready to attend the ceremony, provided that at the time of her appearance in t...
3
def solve(): n=int(input()) arr=sorted([int(v) for v in input().split()]) ans=1 for i in range(n): if i+1>=arr[i]: ans=i+2 print(ans) t=int(input()) for _ in range(t): solve()
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...
3
def odd(n): mas=[0,2,4,6,8] if int(n[-1]) in mas: return "Mahmoud" else: return "Ehab" print(odd(str(input())))
[The Duck song](https://www.youtube.com/watch?v=MtN1YnoL46Q) For simplicity, we'll assume that there are only three types of grapes: green grapes, purple grapes and black grapes. Andrew, Dmitry and Michal are all grapes' lovers, however their preferences of grapes are different. To make all of them happy, the followi...
3
x,y,z = map(int,input().split()) a,b,c = map(int,input().split()) if a>=x and a+b>=x+y and a+b+c>=x+y+z: print('YES') else: print("NO")
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 math n = int(input()) print((math.factorial(n) // ((n // 2) ** 2)) // 2)
A rooted binary tree is a tree with a root node in which every node has at most two children. Your task is to write a program which reads a rooted binary tree T and prints the following information for each node u of T: * node ID of u * parent of u * sibling of u * the number of children of u * depth of u * height of...
3
from sys import stdin class Node(object): def __init__(self, parent=None, left=None, right=None, name=None, sibling=None, degree=None): self.parent = parent self.left = left self.right = right self.name = name self.sibling = sibling self.degree = deg...
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust. The pizza is a circle of radius r and center at the origin. Pizza consists of the main part β€” circle of radius r - d with center at the origin, an...
3
r,d = [int(x) for x in input().split()] n = int(input()) cnt = 0 for i in range(n): x,y,ri = [int(x) for x in input().split()] if (r-d+ri)**2 <= x**2 + y**2 <= (r-ri)**2: cnt += 1 print(cnt)
Petya and Vasya are competing with each other in a new interesting game as they always do. At the beginning of the game Petya has to come up with an array of N positive integers. Sum of all elements in his array should be equal to S. Then Petya has to select an integer K such that 0 ≀ K ≀ S. In order to win, Vasya ha...
3
import sys # from collections import deque # import heapq # from math import inf # from math import gcd # print(help(deque)) # 26 pprint = lambda s: print(' '.join(map(str, s))) input = lambda: sys.stdin.readline().strip() ipnut = input n, s = map(int, input().split()) # n = int(input()) # e = list(map(int,input().s...
Recently a new building with a new layout was constructed in Monocarp's hometown. According to this new layout, the building consists of three types of apartments: three-room, five-room, and seven-room apartments. It's also known that each room of each apartment has exactly one window. In other words, a three-room apar...
3
t=int(input()) for i in range(t): n=int(input()) x=n%7 if x==3: print(x//3,'0',n//7) elif x==5: print('0',x//5,n//7) elif x==0: print('0','0',n//7) elif x==1: if n-7>0: print(x,x,(n-7)//7) else: print('-1') elif x==2: if...
At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn. More formally, the guys take turns giving each ot...
1
a = map(int, raw_input().split()) who = 0 x = 1 while a[who] >= x: a[who] -= x x += 1 who ^= 1 print (who == 0) * "Vladik" or "Valera"
"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 = int(input()) # s=int(input()) # num=n,s # m=int(input()) # choice=[] # # #accumulator variable # for i in range(n): # chosen=choice[m] # print(chosen) # arr = [] # for i in range(n): # if i>2: # arr.append(i) # print(arr) # for i in range(n): # if i>2: # arr.append(i) # print(a...
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...
3
n = int(input()) l = input().split() ans = [] for a in range(0,n): for j in range(0,n-a-1): if int(l[j]) > int(l[j+1]): l[j], l[j+1]= l[j+1], l[j] for i in l: print(i, end = " " )
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ...
3
# A. ΠœΠ°Ρ‚Ρ‡ΠΈ # http://codeforces.com/problemset/problem/268/A # Манао Ρ€Π°Π±ΠΎΡ‚Π°Π΅Ρ‚ Π½Π° спортивном Ρ‚Π΅Π»Π΅Π²ΠΈΠ΄Π΅Π½ΠΈΠΈ. Он Π΄ΠΎΠ»Π³ΠΎΠ΅ врСмя наблюдал Π·Π° Ρ„ΡƒΡ‚Π±ΠΎΠ»ΡŒΠ½Ρ‹ΠΌΠΈ ΠΌΠ°Ρ‚Ρ‡Π°ΠΌΠΈ Ρ‡Π΅ΠΌΠΏΠΈΠΎΠ½Π°Ρ‚Π° ΠΎΠ΄Π½ΠΎΠΉ страны ΠΈ Π½Π°Ρ‡Π°Π» Π·Π°ΠΌΠ΅Ρ‡Π°Ρ‚ΡŒ Ρ€Π°Π·Π½Ρ‹Π΅ закономСрности. # НапримСр, Ρƒ ΠΊΠ°ΠΆΠ΄ΠΎΠΉ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π΅ΡΡ‚ΡŒ Π΄Π²Π΅ Ρ„ΠΎΡ€ΠΌΡ‹: домашняя ΠΈ выСздная. # Когда ΠΊΠΎΠΌΠ°Π½Π΄Π° ΠΏΡ€ΠΎΠ²ΠΎΠ΄ΠΈΡ‚ ΠΌΠ°Ρ‚Ρ‡ Π½Π° сво...
An exam for n students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (i and i + 1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other for sur...
3
n = int(input()) a = [] if n % 2 == 0: b = n - 1 else: b = n for i in range(b, 0, -2): a.append(i) b = n // 2 * 2 while abs(b - a[-1]) != 1 and b > 1: a.append(b) b -= 2 print(len(a)) print(' '.join(map(str, a)))
Melody Pond was stolen from her parents as a newborn baby by Madame Kovarian, to become a weapon of the Silence in their crusade against the Doctor. Madame Kovarian changed Melody's name to River Song, giving her a new identity that allowed her to kill the Eleventh Doctor. Heidi figured out that Madame Kovarian uses a...
3
r=int(input()) x=1 c=0 if(r==1): print("NO") else: while((r-1)>x**2): if(((r-1)-x**2)%x==0): if((((r-1)-x**2)//x-1)%2==0): y=(((r-1)-x**2)//x-1)//2 if(y>0): print(x,y) c=1 break ...
You are given a following process. There is a platform with n columns. 1 Γ— 1 squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column. When all ...
3
n,m = map(int,input().split()) square = [int(i) for i in input().split()] ans = 1e9 for i in range(1,n+1): ans = min(ans, square.count(i)) print(ans)
Our friend Monk has an exam that has quite weird rules. Each question has a difficulty level in the form of an Integer. Now, Monk can only solve the problems that have difficulty level less than X . Now the rules are- Score of the student is equal to the maximum number of answers he/she has attempted without skipping a...
1
''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' total_case=raw_input() new_array=raw_input() new_list=total_case.split(" ") total_len=new_list[0] max_value=new_list[1] array_list=new_array.split(" ") count=0 cond=0 value=0 for d...
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
g = [3,0,2,0,1,0,1,0,0,1,0,1,0] x, y = list(map(int, input().split())) if g[x]== g[y]: print('Yes') else: print('No')
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 ...
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 def main(): length, carry = list(map(int, sys.stdin...
Vasya has his favourite number n. He wants to split it to some non-zero digits. It means, that he wants to choose some digits d_1, d_2, …, d_k, such that 1 ≀ d_i ≀ 9 for all i and d_1 + d_2 + … + d_k = n. Vasya likes beauty in everything, so he wants to find any solution with the minimal possible number of different d...
1
from __future__ import print_function n = int(raw_input()) print(n) for i in range(0, n-1): print("{} ".format(1), end='') print("1")
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc....
3
s = input() t = input() if len(s) != len(t): print("NO") for i in range(len(s) == len (t)): if s == t[::-1]: print("YES") else: print("NO")
You might have remembered Theatre square from the [problem 1A](https://codeforces.com/problemset/problem/1/A). Now it's finally getting repaved. The square still has a rectangular shape of n Γ— m meters. However, the picture is about to get more complicated now. Let a_{i,j} be the j-th square in the i-th row of the pav...
3
import math for _ in range(int(input())): s=[int(i) for i in input().split()] n=s[0] m=s[1] x=s[2] y=s[3] Su1=0 Su2=0 for i in range(n): s2=[i for i in input().split('*')] for xx in s2: k=len(str(xx)) if k%2==0: Su1+=k*x ...
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
n,s = map(int,input().split()) d = [] sum1,sum2=0,0 for i in range(n): d.append(list(map(int,input().split()))) for x,y in d: sum1+=x sum2+=y if(s<sum1 or s>sum2): print('NO') exit() ans = [0]*n for i in range(n): ans[i]+=d[i][0] x = s - sum1 for i in range(n): if(x>d[i][1]): an...
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 = [] for i in range(int(input())): n.append(input()) for j in n: p = len(j) - 2 if p >= 9: print(j[0], p, j[-1], sep='') else: print(j)
There are n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. Input The first line contains integ...
3
input() a=input() s=0 for i in range(len(a)-1): if a[i]==a[i+1]: s+=1 print(s)
Snuke prepared 6 problems for a upcoming programming contest. For each of those problems, Rng judged whether it can be used in the contest or not. You are given a string S of length 6. If the i-th character of s is `1`, it means that the i-th problem prepared by Snuke is accepted to be used; `0` means that the problem...
3
#!/usr/bin/env python3 s = input() print(s.count('1'))
You are given n strings s_1, s_2, …, s_n consisting of lowercase Latin letters. In one operation you can remove a character from a string s_i and insert it to an arbitrary position in a string s_j (j may be equal to i). You may perform this operation any number of times. Is it possible to make all n strings equal? In...
3
from collections import Counter for _ in range(int(input())): n = int(input()) m = n d = {} f = 0 while n: s = input() for i in s: d[i] = d.get(i, 0) + 1 n -= 1 for each in d.values(): if each % m != 0: f = 1 break if f: ...
[3R2 - Standby for Action](https://www.youtube.com/watch?v=P2ZVC9aoiKo) Our dear Cafe's owner, JOE Miller, will soon take part in a new game TV-show "1 vs. n"! The game goes in rounds, where in each round the host asks JOE and his opponents a common question. All participants failing to answer are eliminated. The sho...
3
n = int(input()) otv = 0 for i in range(n, 0, -1): otv += 1 / i; print(otv)
You are given a three-digit positive integer N. Determine whether N is a palindromic number. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation. Constraints * 100≀N≀999 * N is an integer. Input Input is given from Standard Input in the following format: N Output...
3
s = list(input()) print("Yes" if s[::-1] == s else "No")
Amugae has a hotel consisting of 10 rooms. The rooms are numbered from 0 to 9 from left to right. The hotel has two entrances β€” one from the left end, and another from the right end. When a customer arrives to the hotel through the left entrance, they are assigned to an empty room closest to the left entrance. Similar...
3
l = ['0' for _ in range(10)] n = int(input()) s = input() for x in s: if x == 'L': for i in range(10): if l[i] == '0': l[i] = '1' break elif x == 'R': for i in range(9,-1,-1): if l[i] == '0': l[i] = '1' break...
You work as a system administrator in a dormitory, which has n rooms one after another along a straight hallway. Rooms are numbered from 1 to n. You have to connect all n rooms to the Internet. You can connect each room to the Internet directly, the cost of such connection for the i-th room is i coins. Some rooms a...
3
# ------------------- fast io -------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file....
Being tired of participating in too many Codeforces rounds, Gildong decided to take some rest in a park. He sat down on a bench, and soon he found two rabbits hopping around. One of the rabbits was taller than the other. He noticed that the two rabbits were hopping towards each other. The positions of the two rabbits ...
3
t = int(input()) for i in range(t): x,y,a,b = (map(int,input().split())) c = (y-x)/(a+b) if int(c) == c: print(int(c)) else: print(-1)
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....
1
from string import upper letter = raw_input() f = upper(letter[0]) print f + letter[1:]
You are given the array a consisting of n positive (greater than zero) integers. In one move, you can choose two indices i and j (i β‰  j) such that the absolute difference between a_i and a_j is no more than one (|a_i - a_j| ≀ 1) and remove the smallest of these two elements. If two elements are equal, you can remove a...
3
t = int(input()) for i in range(t): lst = [] a = int(input()) lst = list(map(int, input().split())) lst.sort() j = 0 while j <= a: if a != 1 and lst[j]-lst[j+1] in [-1, 0, 1]: a -= 1 lst.remove(lst[j]) elif a == 1: print("YES") br...
There are n students who have taken part in an olympiad. Now it's time to award the students. Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and ce...
1
'''input 1000000000000 499999999999 ''' n, k = map(int, raw_input().split()) n1 = n/2 new = n1/(k+1) if new==0: print 0, 0, n else: print new, new*k, n-new*(k+1)
Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6. Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task! Each digit c...
3
a, b, c, d=map(int, input().split()) e=min(c, d) s=0 if a>=e: s=s+e*256 a=a-e s=s+min(a, b)*32 else: s=s+a*256 print(s)
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If...
1
status = raw_input() print 'YES' if any([len(set(status[i - 6 : i + 1])) == 1 for i in range(6, len(status))]) else 'NO'
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo...
1
import sys sides = map(int, sys.stdin.readline().split()) triangles = [sides[1:], sides[0:1] + sides[2:], sides[0:2] + sides[3:], sides[0:3]] result = "IMPOSSIBLE" for triangle in triangles: if (triangle[0] + triangle[1] >= triangle[2] and triangle[1] + triangle[2] >= triangle[0] and triangle[0] + ...
You are given an array a of length 2n. Consider a partition of array a into two subsequences p and q of length n each (each element of array a should be in exactly one subsequence: either in p or in q). Let's sort p in non-decreasing order, and q in non-increasing order, we can denote the sorted versions by x and y, r...
3
# region fastio # from https://codeforces.com/contest/1333/submission/75948789 import sys, io, os BUFSIZE = 8192 class FastIO(io.IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = io.BytesIO() self.writable = "x" in file.mode or "r" not in file.mo...
There were n types of swords in the theater basement which had been used during the plays. Moreover there were exactly x swords of each type. y people have broken into the theater basement and each of them has taken exactly z swords of some single type. Note that different people might have taken different types of swo...
3
def gcd(a,b): if(b == 0): return a else: return gcd(b,a%b) n = int(input()) l = list(map(int,input().split())) m = max(l) z = 0 y = 0 for i in range(n): #print(m,m-l[i]) z = gcd(z,m-l[i]) for i in range(n): y += (m-l[i])//z print(y,z)
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
s = input() k = 0 for c in s: if c == '4' or c == '7': k += 1 if k == 4 or k == 7: print('YES') else: print('NO')
Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below. <image> So, for example, to show the digit 3 on the display, 5 sections must be highlighted; and for the digit 6, 6 sections must be high...
3
import bisect import heapq import math import collections import sys import copy from functools import reduce import decimal from io import BytesIO, IOBase import os sys.setrecursionlimit(10 ** 9) decimal.getcontext().rounding = decimal.ROUND_HALF_UP graphDict = collections.defaultdict queue = collections.deque ##...
Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation: The track is the circle with length L, in distinct points of which there are n barriers. Athlete always run the track in counterclockwise direction if you...
3
n, l = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) aa = [0] * l bb = [0] * l for i in range(n): aa[a[i]-1] += 1 bb[b[i]-1] += 1 for i in range(l): if aa == bb: print("YES") exit(0) bb = [bb[-1]]+bb[:-1] print("NO")
You are given three positive integers n, a and b. You have to construct a string s of length n consisting of lowercase Latin letters such that each substring of length a has exactly b distinct letters. It is guaranteed that the answer exists. You have to answer t independent test cases. Recall that the substring s[l ...
3
import sys def solve(n): n, a, b = [int(i) for i in n] ca = 0 cb = 0 ans = [] for i in range(n): ans.append(chr(ord('a') + cb)) cb = (cb + 1) % b print("".join(ans)) if __name__=='__main__': # inp = sys.stdin.read() # inp() count = 0 n_tests...
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like. Now let's imagine a typical morning in your family. You haven't w...
3
n=int(input()) list1=list(map(int,input().split())) list1.sort(reverse=True) sum1=sum(list1) sum1=(sum1//2)+1 s=0 c=0 for i in list1: if s<sum1: s=s+i c=c+1 else: print(c) break else: print(c)
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Eve...
3
#football num=int(input()) teams=[] teamg=[] for i in range(num): teamname=input() if teamname not in teams: teams.append(teamname) teamg.append(1) else: teamg[teams.index(teamname)]+=1 print(teams[teamg.index(max(teamg))])
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is ...
3
order=input() print(700+100*order.count("o"))
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the ith subject has ci chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously. Let us say that his initial per chapter learning power of a subject is x hours. In other words he can...
3
n, x = map(int, input().split()) ps = sorted(map(int, input().split())) t = 0 for p in ps: t += p * x x = max(1, x - 1) print(t)
A permutation of length n is a sequence of integers from 1 to n of length n containing each number exactly once. For example, [1], [4, 3, 5, 1, 2], [3, 2, 1] are permutations, and [1, 1], [0, 1], [2, 2, 1, 4] are not. There was a permutation p[1 ... n]. It was merged with itself. In other words, let's take two instanc...
3
for _ in range(int(input())): n=int(input()) lst=list(map(int, input().split())) dct=dict() for i in range(2*n): index=dct.get(lst[i],0) if index==0: dct[lst[i]]=i+1 for i in dct.keys(): print(i,end=" ") print()
There is a circle with a circumference of L. Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point. On this circumference, there are N ants. These ants are numbered 1 through N in order of increasing coordinate, and ant i is at coor...
3
from math import floor n,l,t = map(int,input().split()) ants = [] touch = 0 for i in range(n): x, w = map(int,input().split()) if w == 1: touch += (x + t) // l x1 = (x + t) % l else: touch += (x - t) // l x1 = (x - t) % l ants.append(x1) touch = touch % n ants.sort() ant...
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
1
import string s = raw_input() u = len(filter(lambda x: x in string.uppercase, s)) l = len(filter(lambda x: x in string.lowercase, s)) if u>l: print s.upper() else: print s.lower()
"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 = [int(x) for x in input().split()] arr = [int(x) for x in input().split()] ans = 0 k -= 1 for i in arr: if i == 0: break ans+=(i>=arr[k]) print(ans)
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 w%2 == 0 and w!=2: print("YES") if w%2 != 0: print("NO") if w==2: 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
n = int(input()) val = 0 for _ in range(n): op = input() if '-' in op: val += -1 elif '+' in op: val += 1 print(val)
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
def solve(): n,x = map(int, input().split()) a = list(map(int, input().split())) achieve = [False]*201 for num in a: achieve[num] = True for k in range(n+x,0,-1): v = 0 for i in range(1,k+1): if not achieve[i]: v += 1 if v<=x: ...
You have written N problems to hold programming contests. The i-th problem will have a score of P_i points if used in a contest. With these problems, you would like to hold as many contests as possible under the following condition: * A contest has three problems. The first problem has a score not greater than A poin...
3
N = int(input()) A,B = map(int,input().split()) cnt = [0,0,0] for p in list(map(int,input().split())): if p<=A: cnt[0] += 1 elif A<p and p<=B: cnt[1] += 1 else: cnt[2] += 1 print(min(cnt))
In AtCoder City, there are three stations numbered 1, 2, and 3. Each of these stations is operated by one of the two railway companies, A and B. A string S of length 3 represents which company operates each station. If S_i is `A`, Company A operates Station i; if S_i is `B`, Company B operates Station i. To improve t...
3
if len(set(list(input())))==1:print('No') else:print('Yes')
There is a road with length l meters. The start of the road has coordinate 0, the end of the road has coordinate l. There are two cars, the first standing at the start of the road and the second standing at the end of the road. They will start driving simultaneously. The first car will drive from the start to the end ...
3
def f(t): curr1=0 dist1=0 t1=t for i in range(n+1): curr1+=1 if(li[i+1]-li[i]>curr1*t1): dist1+=(curr1*t1) break dist1+=(li[i+1]-li[i]) t1-=((li[i+1]-li[i])/curr1) curr2=0 dist2=0 t2=t for i in range(n+1,0,-1): curr2+=1 ...
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...
1
n, x = [int(a) for a in raw_input().split()] ans = 0 for i in xrange(1, n + 1): j = int(x / i) if i * j == x and j <= n: ans = ans + 1 print ans
There are n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. Input The first line contains integ...
3
n = int(input()) s = input() ans = 0 suc = 0 for i in range(n): if i == 0 or s[i] == s[i - 1]: suc += 1 else: ans += suc - 1 suc = 1 ans += suc - 1 print(ans)
In this problem you will write a simple generator of Brainfuck (<https://en.wikipedia.org/wiki/Brainfuck>) calculators. You are given an arithmetic expression consisting of integers from 0 to 255 and addition/subtraction signs between them. Output a Brainfuck program which, when executed, will print the result of eval...
3
s = str(eval(input())); ans = ''; for i in range(len(s)): ans += '>' for j in range(int(s[i])): ans += '+' ans += '++++++++++++++++++++++++++++++++++++++++++++++++.' print(ans)
You want to arrange n integers a1, a2, ..., an in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers. More formally, let's denote some arrangement as a sequence of integers x1, x2, ..., xn, where sequence x is a permutation of sequence a. The ...
3
if __name__ == '__main__': n = int(input()) line = list(map(int, input().split())) line.sort() line[0], line[-1] = line[-1], line[0] print(' '.join(map(str, line)))
A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody else's banner that contains someone else's word. The word on the banner consists only of upper-case ...
1
search="CODEFORCES" inp =raw_input() i,j=0,0 while i<len(search) and j<len(inp) and search[i]==inp[j]: i+=1 j+=1 if search[i:] == inp[-len(search)+i:] or i==len(search): print "YES" else: print "NO"
You have N cards. On the i-th card, an integer A_i is written. For each j = 1, 2, ..., M in this order, you will perform the following operation once: Operation: Choose at most B_j cards (possibly zero). Replace the integer written on each chosen card with C_j. Find the maximum possible sum of the integers written o...
3
N,M=map(int,input().split()) L=sorted(list(map(lambda x: (1,int(x)), input().split())) +[tuple(map(int,input().split())) for _ in range(M)] ,key=lambda x: x[1],reverse=True) ans,k=0,0 for n,a in L: if n+k>=N: ans+=a*(N-k) break else: ans+=a*n k+=n print(ans)
n robots have escaped from your laboratory! You have to find them as soon as possible, because these robots are experimental, and their behavior is not tested yet, so they may be really dangerous! Fortunately, even though your robots have escaped, you still have some control over them. First of all, you know the locat...
3
q = int(input()) answer = [[] for i in range(q)] for a in range(q): x = [] y = [] f1 = [] f2 = [] f3 = [] f4 = [] n = int(input()) for i in range(n): xi, yi, f1i, f2i, f3i, f4i = map(int, input().split()) x.append(xi) y.append(yi) f1.append(f1i) f2...