problem
stringlengths
29
9.39k
language
int64
1
3
solution
stringlengths
7
465k
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
#list(map(int,input().split())) times = int(input()) count = 0 for i in range(times): surer = list(map(int,input().split())) if(surer.count(1)>1): count = count + 1 print(count)
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum nu...
3
from math import ceil n = int(input()) s = [int(x) for x in input().split()] ct = [0, 0, 0, 0] for i in range(1, 5): ct[i - 1] = s.count(i) out = ct[3] + ct[2] + ct[1] // 2 if ct[1] % 2 == 1: out += 1 ct[0] -= 2 ct[0] -= ct[2] if ct[0] > 0: out += ceil(ct[0] / 4) print(out)
You are given an integer n. In one move, you can either multiply n by two or divide n by 6 (if it is divisible by 6 without the remainder). Your task is to find the minimum number of moves needed to obtain 1 from n or determine if it's impossible to do that. You have to answer t independent test cases. Input The fi...
3
def fun1(n) : i = 0 while True : if n == 1 : return i elif n%6 == 0 : n = n/6 i+=1 elif n%3 == 0 : n = n*2 i+=1 else : return -1 if __name__ == "__main__": t = int(input()) for i in range (t) : ...
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...
1
n=int(raw_input()) for i in range(n): temp=raw_input() if len(temp) <= 10 : print temp else : print temp[0]+str((len(temp) -2 ))+temp[len(temp)-1]
There are n students standing in a circle in some order. The index of the i-th student is p_i. It is guaranteed that all indices of students are distinct integers from 1 to n (i. e. they form a permutation). Students want to start a round dance. A clockwise round dance can be started if the student 2 comes right after...
3
for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) count=0 for x in range(n-1): p=abs(l[x+1]-l[x]) if p!=1 and count==0 and p==n-1: count+=1 elif p!=1 and p!=n-1: print('NO') break else:print("YES")
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
a = int(input()) i = 0 count = 0 while i < a: p, v, t = [int (i) for i in input().split()] if (p + v + t) > 1: count += 1 i += 1 print(count)
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
s=sorted(map(int, raw_input().split())) def f(i): r= s[0+i] + s[1+i]-s[2+i] return (r>0)+(r>=0) print ["IMPOSSIBLE", "SEGMENT", "TRIANGLE"][max(f(0),f(1))]
Vasya thinks that lucky tickets are the tickets whose numbers are divisible by 3. He gathered quite a large collection of such tickets but one day his younger brother Leonid was having a sulk and decided to destroy the collection. First he tore every ticket exactly in two, but he didn’t think it was enough and Leonid a...
3
import math import itertools import collections def getdict(n): d = {} if type(n) is list: for i in n: if i in d: d[i] += 1 else: d[i] = 1 else: for i in range(n): t = ii() if t in d: d[t] += 1 ...
You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the socia...
3
n = int(input()) s = input() cnt = 0 while 'xxx' in s: cnt += 1 ind = s.find('xxx') s = s[:ind] + s[ind + 1:] print(cnt)
Suppose you are living with two cats: A and B. There are n napping spots where both cats usually sleep. Your cats like to sleep and also like all these spots, so they change napping spot each hour cyclically: * Cat A changes its napping place in order: n, n - 1, n - 2, ..., 3, 2, 1, n, n - 1, ... In other words, a...
3
for _ in range(int(input())): n,k=map(int,input().split()) ans=0 if(n%2==0): time=k%(n) ans=time if(time==0): print(n) ans=n else: print(time) else: tt=0 no=(k-1)//(n//2) # print(no+1) if(n!=3): ...
When preparing a tournament, Codeforces coordinators try treir best to make the first problem as easy as possible. This time the coordinator had chosen some problem and asked n people about their opinions. Each person answered whether this problem is easy or hard. If at least one of these n people has answered that th...
3
n = int(input()) scores = [int(i) for i in input().split()] if sum(scores) > 0: print('HARD') else: print('EASY')
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
testcase=int(input()) while(testcase): testcase-=1 ip=list(map(int,input().split())) x,y,n=ip[0],ip[1],ip[2] mod1=y%x mod2=n%x if(mod1==mod2): print(n) continue elif(mod1<mod2): print(n-mod2+mod1) else: print(n-mod2-x+mod1)
You're given an integer n. For every integer i from 2 to n, assign a positive integer a_i such that the following conditions hold: * For any pair of integers (i,j), if i and j are coprime, a_i ≠ a_j. * The maximal value of all a_i should be minimized (that is, as small as possible). A pair of integers is call...
3
import sys input = sys.stdin.readline from collections import defaultdict d = defaultdict(int) i = 1 n = int(input()) primes = [2,3,5,7] if n > 10: for j in range(11, n + 1): for x in primes: if j % x == 0: break else: primes.append(j) #print(primes) for x in primes: d[x] = i i += 1 l = [] for j in r...
It is known that the area of a regular dodecagon inscribed in a circle of radius a is 3a^2. Given an integer r, find the area of a regular dodecagon inscribed in a circle of radius r. Constraints * 1 \leq r \leq 100 * r is an integer. Input Input is given from Standard Input in the following format: r Output ...
3
a=int(input()) r=3*a*a print(r)
Panic is rising in the committee for doggo standardization — the puppies of the new brood have been born multi-colored! In total there are 26 possible colors of puppies in the nature and they are denoted by letters from 'a' to 'z' inclusive. The committee rules strictly prohibit even the smallest diversity between dog...
3
from sys import stdin, stdout from collections import deque n = int(stdin.readline()) s = stdin.readline().strip() a = 'zaqwsxcderfvbgtyhnmjuiklop' for f in a: if s.count(f) >= 2 or n == 1: stdout.write("Yes\n") break else: stdout.write('No\n')
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
# -*- coding: utf-8 -*- """ Created on Wed Apr 8 19:17:04 2020 @author: Equipo """ while True: s=input() t=input() if(len(s)>=1 and len(s)<=100 and len(t)>=1 and len(t)<=100): break if (s[::-1].lower()==t.lower()): print("YES") else: print("NO")
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 os import sys import math import heapq from decimal import * from io import BytesIO, IOBase from collections import defaultdict, deque def r(): return int(input()) def rm(): return map(int,input().split()) def rl(): return list(map(int,input().split())) '''D''' n, k = rm() if (n==k) or (k<2*n): ...
Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute l1 to minute r1 inclusive. Also, during the minute k she prinks and is unavailable for Filya. Filya works a lot and he plans to visit ...
3
x=input().split() l1=int(x[0]) r1=int(x[1]) l2=int(x[2]) r2=int(x[3]) k=int(x[4]) l=max(l1,l2) r=min(r1,r2) if(r-l<0): print(0) else: if(k>=l and k<=r): print(r-l) else: print(r-l+1)
An adult game master and N children are playing a game on an ice rink. The game consists of K rounds. In the i-th round, the game master announces: * Form groups consisting of A_i children each! Then the children who are still in the game form as many groups of A_i children as possible. One child may belong to at m...
3
k = int(input()) a = list(map(int,input().split())) if a[-1] != 2: print(-1) exit() l = 2 r = 3 for i in a[::-1][1:]: if i > r: print(-1) exit() l = (l+i-1)//i*i r = r//i*i+i-1 if r < l: print(-1) exit() print(l,r)
This year in Equestria was a year of plenty, so Applejack has decided to build some new apple storages. According to the advice of the farm designers, she chose to build two storages with non-zero area: one in the shape of a square and another one in the shape of a rectangle (which possibly can be a square as well). A...
3
from sys import stdin,stdout import math from collections import Counter,defaultdict LI=lambda:list(map(int,input().split())) MAP=lambda:map(int,input().split()) IN=lambda:int(input()) S=lambda:input() def case(): n,=LI() a=LI() di=Counter(a) c=0 d=0 for i in di: te=di[i] c+=te/...
You are given a positive integer n. In one move, you can increase n by one (i.e. make n := n + 1). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s. You have to answer t independent test cases. Input The first line of the input co...
3
q = int(input()) ans = [] for _ in range(q): S, n = map(int, input().split()) st = str(S) length = len(st) trigger = 0 flg = True for i, s in enumerate(st, 1): n -= int(s) if n > 0: trigger = i elif n < 0: flg = False if flg: res = 0 ...
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu...
3
n=input().split('WUB') for i in n: if i!='': print(i, end=' ')
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Bi...
3
weight = int(input()) if weight > 2 and weight <= 100: if weight % 2 == 0: print("YES") else: print("NO") else: print("NO")
Note that the only difference between String Transformation 1 and String Transformation 2 is in the move Koa does. In this version the letter y Koa selects must be strictly greater alphabetically than x (read statement for better understanding). You can make hacks in these problems independently. Koa the Koala has two...
3
t=int(input()) for _ in range(t): n=int(input()) a=list(input()) b=list(input()) valid=True for i in range(n): if a[i]>b[i]: print(-1) valid=False break if valid: ans=0 for i in range(97,97+20): li=[] y=chr(117) length=0 for j in range(n): if a[j...
To protect people from evil, a long and tall wall was constructed a few years ago. But just a wall is not safe, there should also be soldiers on it, always keeping vigil. The wall is very long and connects the left and the right towers. There are exactly N spots (numbered 1 to N) on the wall for soldiers. The K^t...
1
def getRange(n): r = [] r.append([0,0]) r.append([2,2]) for i in range(2,n+1): m = int(i/2)+1 x = m-1 y = i-m r.append([i+1+r[x][0]+r[y][0], i+1+r[i-1][1]]) return r[n] def soldier(n,l): s,e = getRange(n) if l<s: return -1 m=(s+e)/2 if l>=s...
Luke Skywalker gave Chewbacca an integer number x. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit t means replacing it with digit 9 - t. Help Chewbacca to transform the initial number x to the minimum possible positive number by inverting some (possibly, zero) digits. The decim...
1
n = raw_input() n = list(n) for i in xrange(len(n)): item = int(n[i]) new = 9 - item if not new and i == 0: continue if new < item: n[i] = `new` print "".join(n)
You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens. There are N attendees in the party, and they are given attendee numbers from 1 through N. The height of Attendee i is A_i. According to an examina...
3
from collections import defaultdict n=int(input()) d=defaultdict(int) a=list(map(int,input().split())) for i in range(n): d[i-a[i]]+=1 ans=0 for i in range(n): d[i-a[i]]-=1 ans+=d[a[i]+i] print(ans)
One day student Vasya was sitting on a lecture and mentioned a string s1s2... sn, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph G with the following properties: * G has exactly n vertices, numbered from 1 to...
3
edge=[[0 for _ in range(510)] for _ in range(510)] cnt = [0]*510 s=[0]*510 n,m = map(int,input().split()) for _ in range(m): u,v = map(int,input().split()) u-=1 v-=1 edge[u][v]=1 edge[v][u]=1 cnt[u]+=1 cnt[v]+=1 for i in range(n): if(cnt[i]==n-1):s[i]='b' for i in range(n): if s[i]==0: s[i]='a' #print(i) ...
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'...
1
n1, n2, a = map(int, raw_input().split()) print (n1 / a + (n1 % a > 0)) * (n2 / a + (n2 % a > 0))
Pulkit is really good at maths. Recently, he came to know about a problem on matrices. Amazed by the problem he got, he asked Ashish the same problem. Ashish also being good at maths solved the problem within 5 minutes. Now, its your time to solve the problem. You will be given n*m binary matrix. You need to tell if i...
1
for i in range(input()): l=[int(x) for x in raw_input().split()] l1=[] l2=[] for j in range(l[0]): a=input() l1.append(a) for k in range(0,len(l1)): if(l1[k] not in l2): l2.append(l1[k]) if(len(l1)==len(l2)): print('Yes') else: print('No')
A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana). He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas? Input The first lin...
3
k,n,w=tuple(map(int,input().split())) l=[] for i in range(1,w+1): l.append(i*k) x=sum(l) if n>=x: print('0') else: print(x-n)
Oleg's favorite subjects are History and Math, and his favorite branch of mathematics is division. To improve his division skills, Oleg came up with t pairs of integers p_i and q_i and for each pair decided to find the greatest integer x_i, such that: * p_i is divisible by x_i; * x_i is not divisible by q_i. ...
3
t = int(input()) for a in range(t): p,q = map(int,input().strip(' ').split(' ')) factor = set([q]) for i in range(2,int(q**0.5)+1): if q%i == 0: factor.add(i) x = q//i if x != i: factor.add(x) #print(factor) if p%q: pri...
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
def main(): t = int(input()) for _ in range(t): n, m, x, y = map(int, input().split()) if 2*x < y: y = 2*x cnt = 0 for i in range(n): s = input() j = 0 while j < m: if s[j] == '.': if j < m-1 and ...
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
3
# -*- coding: utf-8 -*- """ Created on Tue Apr 14 03:38:05 2020 @author: DELL """ n=input() c=0 o=0 for i in n: if i.islower(): c+=1 if i.isupper(): o+=1 if c>o or c==o: print(n.lower()) elif o>c: print(n.upper())
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
number_of_lines = int(input()) stored_lines = [] count = 0 while count < number_of_lines: stored_lines.append(str(input())) count += 1 count = 0 while count < number_of_lines: if len(stored_lines[count]) > 10: newStr = stored_lines[count] print(f"{newStr[0]}{len(newStr) - 2}{newStr[-1]}") ...
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given n numbers finds one that is di...
3
n = int(input()) ipt = [int(x)%2 for x in input().split()] if ipt.count(0) > 1: print(ipt.index(1)+1) else: print(ipt.index(0)+1)
You have a knapsack with the capacity of W. There are also n items, the i-th one has weight w_i. You want to put some of these items into the knapsack in such a way that their total weight C is at least half of its size, but (obviously) does not exceed it. Formally, C should satisfy: ⌈ W/2⌉ ≤ C ≤ W. Output the list...
3
#from bisect import bisect_left as bl #c++ lowerbound bl(array,element) #from bisect import bisect_right as br #c++ upperbound br(array,element) #from __future__ import print_function, division #while using python2 # from itertools import accumulate # from collections import defaultdict,...
On her way to programming school tiger Dasha faced her first test — a huge staircase! <image> The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — th...
3
a,b=input().split() if (0<=abs(int(a)-int(b))<=1)and((int(a)+int(b))!=0): print('YES') else: print('NO')
Recently you have received two positive integer numbers x and y. You forgot them, but you remembered a shuffled list containing all divisors of x (including 1 and x) and all divisors of y (including 1 and y). If d is a divisor of both numbers x and y at the same time, there are two occurrences of d in the list. For ex...
3
n = int(input()) ls = list(map(int,input().split())) m = max(ls) ls.remove(m) for i in range(1,m//2+1): if m%i==0: ls.remove(i) n = max(ls) print(str(m)+" "+str(n))
Given are N points (x_i, y_i) in a two-dimensional plane. Find the minimum radius of a circle such that all the points are inside or on it. Constraints * 2 \leq N \leq 50 * 0 \leq x_i \leq 1000 * 0 \leq y_i \leq 1000 * The given N points are all different. * The values in input are all integers. Input Input is giv...
3
N = int(input()) xy = [list(map(int, input().split())) for _ in range(N)] import math def dist(x0, y0, x1, y1): return ((x0-x1)**2+(y0-y1)**2)**0.5 ans = 10**18 eps = 10**(-7) for i in range(N): for j in range(i): for k in range(j): xi, yi = xy[i] xj, yj = xy[j] xk, y...
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th...
3
a=[int(i) for i in input().split()] i=0 while i<3: if(a[i]>a[i+1]): a[i],a[i+1]=a[i+1],a[i] i=-1 i+=1 k=0 for i in range(len(a)-1): if(a[i]==a[i+1]): k+=1 print(k)
Lee is going to fashionably decorate his house for a party, using some regular convex polygons... Lee thinks a regular n-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the OX-axis and at least one of its edges is parallel to the OY-axis a...
3
for _ in range(int(input())):print(['NO','YES'][int(input())%4==0])
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
for i in range(5): row = list(map(int,input().split())) if 1 in row: m = i + 1 n = row.index(1) + 1 out = (abs(m - 3) + abs(n - 3)) print(out)
Everybody knows that opposites attract. That is the key principle of the "Perfect Matching" dating agency. The "Perfect Matching" matchmakers have classified each registered customer by his interests and assigned to the i-th client number ti ( - 10 ≤ ti ≤ 10). Of course, one number can be assigned to any number of cust...
3
# Author : nitish420 -------------------------------------------------------------------- import os import sys from io import BytesIO, IOBase # mod=10**9+7 # sys.setrecursionlimit(10**6) # mxm=sys.maxsize # from functools import lru_cache from collections import Counter def main(): n=int(input()) c=Counter(li...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
1
if __file__.startswith('/tmp/'): import sys; sys.stdin = open('input.txt') from collections import Counter n = int(raw_input()) s = raw_input() a = set(s) l = 0 b = Counter() ans = n for r in xrange(n): b[s[r]] += 1 while len(a) == len(b): ans = min(ans, r - l + 1) b[s[l]] -= 1 if b[s[l]] == 0: b.pop(...
When preparing a tournament, Codeforces coordinators try treir best to make the first problem as easy as possible. This time the coordinator had chosen some problem and asked n people about their opinions. Each person answered whether this problem is easy or hard. If at least one of these n people has answered that th...
3
a = input() n = int(a) b = input() c = [] c = b.split() hard = 0 for i in c: if i == '1': hard += 1 else: continue if hard > 0: print('HARD') else: print('EASY')
You are given an array A, consisting of n positive integers a_1, a_2, ..., a_n, and an array B, consisting of m positive integers b_1, b_2, ..., b_m. Choose some element a of A and some element b of B such that a+b doesn't belong to A and doesn't belong to B. For example, if A = [2, 1, 7] and B = [1, 3, 4], we can ...
3
n=int(input()) a=[int(x) for x in input().split()] m=int(input()) b=[int(x) for x in input().split()] sa=set(a) sb=set(b) found=False #print(sa,sb) for i in sa: for j in sb: #print(i+j) #print((i+j) in sa) if (i+j) in sa or (i+j) in b: pass else: print(i,j) ...
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()) x = 0 for _ in range(n): statement = input() if statement.count('+'): x += 1 elif statement.count('-'): x -= 1 print(x)
Recently Vova found n candy wrappers. He remembers that he bought x candies during the first day, 2x candies during the second day, 4x candies during the third day, ..., 2^{k-1} x candies during the k-th day. But there is an issue: Vova remembers neither x nor k but he is sure that x and k are positive integers and k >...
3
t = int(input()) for _ in range(t): n = int(input()) x = 0 #n = x(1+2+4+8) i = 3 j = 2 while(True): x = n//i if(n%i==0): print(x) break i += 2**j j += 1
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 _ in range(t): n = int(input()) if n % 4 != 0: print('NO') else: print('YES') arr = [2*i + 2 for i in range(n//2)] arr.extend([2*i + 1 for i in range(n//2)]) arr[-1] += n//2 print(' '.join(map(str, arr)))
Alfi asked Roy to go for shopping with her. Witty Roy came up with a condition. He said, for each product of MRP (Maximum Retail Price) R, she'll have to pay minimum of all the prime factors of R and he himself will pay rest of the amount. Without giving it a second thought Alfi agreed. Now they bought N number of pr...
1
# author : Pankaj Kumar prime = [0]*1000001 for i in range(3 , 1001 , 2): if not prime[i]: for j in range(i*i , 1000001 , 2*i): if not prime[j]: prime[j] = i t = int( raw_input() ) for i in range(t): n = int( raw_input() ) if n % 2 == 0: print n-2 elif prime[n] == 0: print 0 else: print n - prim...
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length n. There is a great number of "QAQ" in the string (Diamond is so cute!). <image> illustration by 猫屋 https://twitter.com/nekoy...
3
l = input() count = 0 for i in range(len(l)): if l[i] == 'Q': for j in range(i, len(l)): if l[j] == 'A': for k in range(j, len(l)): if l[k] == 'Q': count += 1 print(count)
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ...
3
n = int(input()) def main(): flag = False for i in range(n+1): if lucky(i): if (n % i == 0): flag = True else: continue else: continue if flag == True: print("YES") else: print("NO") def lucky(...
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()) k = 0 for i in range(n): a = input().split() for i in range(3): a[i] = int(a[i]) if sum(a)>=2: k+=1 print(k)
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
t=0 c=0 r=0 s=raw_input() n=len(s) for i in range(n): if c!=1: if s[i]==s[i-1]: r=r+1 if r==7: c=1 print "YES" else: r=1 if c!=1 and t==0: print "NO"
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
3
n=int(input()) v,q,p=[],[],[] for i in range(n): x,y,z=map(int,input().split()) v.append(x) q.append(y) p.append(z) if sum(v)==0 and sum(q)==0 and sum(p)==0: print('YES') else: print('NO')
A penguin Rocher has n sticks. He has exactly one stick with length i for all 1 ≤ i ≤ n. He can connect some sticks. If he connects two sticks that have lengths a and b, he gets one stick with length a + b. Two sticks, that were used in the operation disappear from his set and the new connected stick appears in his se...
3
for _ in range(int(input())): n=int(input()) if(n%2==0): print(n//2) else: print((n+1)//2)
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. Bu...
3
s = set(input()) print('IGNORE HIM!') if len(s)%2!=0 else print('CHAT WITH HER!')
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. <image> English alphabet You are given a...
3
import re s = input().strip() t = re.sub('[^AbdHIMOopqTUVvWwXxY]{1}', '', s) m = {} for i in range(ord('A'), ord('z') + 1): m[chr(i)] = chr(i) m['b'] = 'd' m['d'] = 'b' m['p'] = 'q' m['q'] = 'p' def is_sp(): sl = len(t) for i in range(sl // 2 + 1): if m[t[i]] != t[sl - 1 - i]: return...
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. ...
3
input() line=input() tokens=line.split() nums=[int(k) for k in tokens] nums.sort() midget=min(nums) for k in nums: if k>midget: print(k) break if k == midget: print('NO')
Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1, p2, ..., pn. Your task is to find such permutation p of length n, that the group of numbers |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| has exactly k d...
1
n,k=map(int,raw_input().split()) p1=1 p2=n z=n while(k>0): if True: if k%2==0: print p2, p2-=1 else: print p1, p1+=1 k-=1 z-=1 for i in xrange(z): print p1, p1+=1
Zibi is a competitive programming coach. There are n competitors who want to be prepared well. The training contests are quite unusual – there are two people in a team, two problems, and each competitor will code exactly one of them. Of course, people in one team will code different problems. Rules of scoring also are...
1
""" What I cannot create, I do not understand. https://github.com/Cheran-Senthil/PyRival Copyright (c) 2018 Cheran Senthilkumar """ from __future__ import division, print_function import cmath import itertools import math import operator as op import sys from bisect import bisect_left, bisect_right from string import...
Recently Luba bought a very interesting book. She knows that it will take t seconds to read the book. Luba wants to finish reading as fast as she can. But she has some work to do in each of n next days. The number of seconds that Luba has to spend working during i-th day is ai. If some free time remains, she can spend...
3
L = 86400 n, k = map(int, input().split()) a = list(map(int, input().split())) for d, i in enumerate(a, 1): k -= L - i if k <= 0: print(d) exit() print(n + 1)
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number a and Antisimon receives number b. They also have a heap of n stones. The players take turns to make a move and Simon starts. During a move a player should take from ...
3
# A. Эпическая игра a,b,n = map(int, input().split()) def NOD(a,b): while b > 0: a, b = b, a % b return a while n != 0: n -= NOD(a,n) if n == 0: print('0') break n -= NOD(b,n) if n == 0: print('1') break
Xsquare loves to play with arrays a lot. Today, he has two arrays named as A and B. Each array consists of N positive integers. Xsquare has decided to fulfill following types of queries over his array A and array B. 1 L R : Print the value of AL + BL+1 + AL+2 + BL+3 + ... upto R^th term. 2 L R : Print the value of...
1
n, q = [int(x) for x in raw_input('').split(' ')] a = [int(x) for x in raw_input('').split(' ') if len(x.strip(' ')) > 0] b = [int(x) for x in raw_input('').split(' ') if len(x.strip(' ')) > 0] assert(1 <= n <= 100000) assert(1 <= q <= 100000) for i in range(0, n, 2): temp = a[i] a[i] = b[i] b[i] = temp for...
Nauuo is a girl who loves writing comments. One day, she posted a comment on Codeforces, wondering whether she would get upvotes or downvotes. It's known that there were x persons who would upvote, y persons who would downvote, and there were also another z persons who would vote, but you don't know whether they woul...
3
a,b,c=map(int,input().split()) print('+' if a>b+c else '-' if b>c+a else '0' if a==b and c==0 else '?')
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...
1
input() I=raw_input a=zip(I(),I()) def l(x): r=abs(ord(x[0])-ord(x[1])) return r if r<5 else 10-r print sum(map(l,a))
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
import sys import collections import math import heapq from operator import itemgetter def getint(): return int(input()) def getints(): return [int(x) for x in input().split(' ')] n = getint() a = getints() result = 0 a.sort() i = 1 while i <= n: while i <= n and a[i - 1] < result: i += 1 i...
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended u...
3
list_inp=input() stack_jud=[] for i in list_inp: if len(stack_jud)>0: if stack_jud[-1]==i:stack_jud.pop() else: stack_jud.append(i) else: stack_jud.append(i) if stack_jud==[]:print ('Yes') else:print ('No')
New Year is coming in Line World! In this world, there are n cells numbered by integers from 1 to n, as a 1 × n board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells. So, user tncks0121 has ...
3
# -*- coding: utf-8 -*- """ Created on Tue Mar 12 22:59:40 2019 @author: avina """ n,m = map(int, input().strip().split()) L = {} for i,a in enumerate(input().strip().split()): L[i+1]= int(a) x = 1 e = 0 while x < m: x=x + L[x] # e = x if x==m: print('YES') else: print('NO')
Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance. The park is a rectangular table with n rows and m columns, where the cells of the...
3
t = int(input()) for i in range(t): n,m=map(int,input().split()) p,q=n%2,m%2 if (p==0 and q==1) or (p==0 and q==0): ans=m*(n//2) elif p==1 and q==0: ans=n*(m//2) else: ans=(n//2)*m+(m//2+1) print(ans)
When preparing a tournament, Codeforces coordinators try treir best to make the first problem as easy as possible. This time the coordinator had chosen some problem and asked n people about their opinions. Each person answered whether this problem is easy or hard. If at least one of these n people has answered that th...
3
n = int(input()) arr = input().split() ok = 0 for i in range(n): if arr[i] == '1': ok = 1 print("HARD") if ok == 1 else print("EASY")
Professor GukiZ makes a new robot. The robot are in the point with coordinates (x1, y1) and should go to the point (x2, y2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal number of steps...
1
x,y=map(int,raw_input().split()) n,m=map(int,raw_input().split()) print max(abs(n-x),abs(m-y))
You are given two arrays A and B consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose k numbers in array A and choose m numbers in array B so that any number chosen in the first array is strictly less than any number chosen in the second array. Input The first line contains t...
1
na, nb = map(int, raw_input().split()) k, m = map(int, raw_input().split()) a = map(int, raw_input().split()) b = map(int, raw_input().split()) print ['NO', 'YES'][a[k-1]<b[nb-m]]
Yui Hirasawa, who attends private Sakuragaoka Girls' High School, has to make a career hope by the day after tomorrow, but the trouble is that she hasn't decided anything yet. When I consulted with my friend Wa, I knew that my first choice was K University, so I consulted with my career guidance teacher to see if I cou...
3
d = {0: lambda x, y: max(x, y), 1: lambda x, y: min(x, y)} while True: n = int(input()) if n == 0: break ans = [0, 500] for _ in range(n): score = sum(map(int, input().split())) ans = [d[i](ans[i], score) for i in range(2)] print(*ans)
The city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time. Moore's law is the observation that the number of transistors in a dense integrated circuit doubles approximately ev...
3
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import decimal if __name__ == '__main__': n, t = map(int, input().split()) n = decimal.Decimal(n) t = decimal.Decimal(t) r = decimal.Decimal(1.000000011) print("{:.18f}".format(n * r ** t))
During the quarantine, Sicromoft has more free time to create the new functions in "Celex-2021". The developers made a new function GAZ-GIZ, which infinitely fills an infinite table to the right and down from the upper left corner as follows: <image> The cell with coordinates (x, y) is at the intersection of x-th row ...
3
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) t = int(input()) for _ in range(t): x1, y1, x2, y2 = [int(x) for x in input().strip().split()] dx, dy = max(x2-x1, y2-y1), min(x2-x1, y2-y1) print((x2 - x1) * (y2 - y1) + 1) if __name__ == '__main...
It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one.. There is a glob pattern in the statements (a string consisting of lowercase English letters, characters "?" and "*"). It is kno...
3
global good def check(s,h): if len(s)!=len(h): return 0 for i in range(len(s)): if h[i]=='?': if s[i] in good: continue return 0 if h[i]!=s[i]: return 0 return 1 good=input() h=input() n=int(input()) e=0 l,r='','' for i in range(len(h)): if h[i]=='*': l,r=...
There are n programmers that you want to split into several non-empty teams. The skill of the i-th programmer is a_i. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team ...
3
def solve(n,score,seq) : seq.sort(reverse=True) teams = 0 temp = 0 for x in seq : temp += 1 if temp*x >= score : teams += 1 temp = 0 return teams for _ in range(int(input())): n,score = list(map(int,input().split())) seq = list(map(int,...
We all know that a superhero can transform to certain other superheroes. But not all Superheroes can transform to any other superhero. A superhero with name s can transform to another superhero with name t if s can be made equal to t by changing any vowel in s to any other vowel and any consonant in s to any other cons...
3
s=input() t=input() glas= ['a', 'e', 'i', 'o' ,'u'] if len(s)==len(t): for i in range(len(s)): if (s[i] in glas and t[i] in glas) or (s[i] not in glas and t[i] not in glas): counter=0 else: print('No') break else: print('Yes') else: print('No')
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a n by m table. Denote c-th cell of r-th row as (r, c). The tail of the snake is located at (1, 1), then it's body extends to (1,...
3
''' def main(): from sys import stdin,stdout if __name__=='__main__': main() ''' #1A ''' def main(): from sys import stdin,stdout from math import ceil n,m,a=map(int,stdin.readline().split()) stdout.write(str(ceil(n/a)*ceil(m/a))) if __name__=='__main__': main() ''' #4A ''' def main(): f...
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a stud...
3
n = int(input()) date = [[0 for j in range(2)]for i in range(n)] for i in range(n): date[i][0],date[i][1] = map(int,input().split()) date.sort() prev = date[0][1] for i in range(1,n): if(date[i][1]>=prev): prev = date[i][1] else: prev = date[i][0] print(prev)
Ashish and Vivek play a game on a matrix consisting of n rows and m columns, where they take turns claiming cells. Unclaimed cells are represented by 0, while claimed cells are represented by 1. The initial state of the matrix is given. There can be some claimed cells in the initial state. In each turn, a player must ...
3
t=int(input()) while(t>0): t=t-1 n,m=input().split() n=int(n);m=int(m) mat=[] for i in range(n): l=input().split() mat.append(l) cr=[] cc=[] ans=0 for i in range(n): for j in range(m): mat[i][j]=int(mat[i][j]) if(mat[i][j]==1): ...
Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point. Misha has a list of handle change requests. After completing the re...
1
q = int(raw_input()) d = {} count = 0 for i in range(q): old, new = map(str, raw_input().split()) if old not in d: d[new] = old count += 1 else: d[new] = d[old] del d[old] print count for newOutput, oldOutput in d.items(): print oldOutput, newOutput
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in n different shops in the city. It's known that the price of one bottle in the shop i is equal to xi coins. Vasiliy plans to buy his favorite drink fo...
1
from __future__ import division, print_function import os import sys from io import BytesIO, IOBase def main(): pass # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = ...
Anton likes to play chess. Also he likes to do programming. No wonder that he decided to attend chess classes and programming classes. Anton has n variants when he will attend chess classes, i-th variant is given by a period of time (l1, i, r1, i). Also he has m variants when he will attend programming classes, i-th v...
3
n=int(input()) ln=sorted(list(map(int,input().split())) for _ in range(n)) m=int(input()) lm=sorted(list(map(int,input().split())) for _ in range(m)) lln=sorted(x[::-1] for x in ln) llm=sorted(x[::-1] for x in lm) ans=ln[-1][0]-llm[0][0] if lm[-1][0]-lln[0][0]>ans: ans=lm[-1][0]-lln[0][0] print(max(0,ans))
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R. Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and pl...
3
A,B,C,D = map(int,input().split()) print('Left' if (A+B)>(C+D) else 'Balanced' if (A+B) == (C+D) else 'Right')
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()) ans = 0 for i in range(0, n): a = input() if a[1] == '+': ans += 1 else: ans -= 1 print(ans)
For the given integer n (n > 2) let's write down all the strings of length n which contain n-2 letters 'a' and two letters 'b' in lexicographical (alphabetical) order. Recall that the string s of length n is lexicographically less than string t of length n, if there exists such i (1 ≤ i ≤ n), that s_i < t_i, and for a...
3
import sys input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) def find_string(n, k): ...
Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You are given a tree with n nodes. In the beginning, 0 is written on all edges. In one operation, you can choose any 2 distinct leaves u, v and any real number x and add x to values written on al...
3
from sys import stdin, stdout, exit n = int(input()) graph = [[] for i in range(n)] for i in range(n-1): u, v = map(int, stdin.readline().split()) graph[u-1].append(v-1) graph[v-1].append(u-1) for i in range(n): if len(graph[i]) == 2: print("NO") exit() print("YES")
Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the...
3
l1=list(map(int,input().split())) l2=list(map(int,input().split())) s=0 for a in l2: s+=1 if a>l1[1]: s+=1 print(s)
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can ...
3
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.mode self.write = self.buffer.write if self...
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. Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with...
3
def Lucky(b): luckysum = 0 for i in b: # print(type(i)) luckysum = luckysum + i return luckysum def printArray(b): for i in b: print(i, end='') n = int(input()) k = 0 if( n > 56 ): k = int(n/28) n = n - (k-1)*28 l = 1 j = 0 max_l = int(n/4) num_array = [4] while (...
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=input() din=[int(i) for i in input().split()] s=sum(din) t=0 dout=0 k=0 for i in range(100,0,-1) : if k==1 : break if (t+i*din.count(i))*2<=s : t+=i*din.count(i) dout+=din.count(i) continue for j in range(din.count(i)) : t+=i dout+=1 if 2*t>s : ...
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat. <image> There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ....
1
n = input() pMin = 101 m = 0 for _ in range(n): a, b = map(int, raw_input().split()) if b < pMin: pMin = b m += pMin * a print m
A competitive eater, Alice is scheduling some practices for an eating contest on a magical calendar. The calendar is unusual because a week contains not necessarily 7 days! In detail, she can choose any integer k which satisfies 1 ≤ k ≤ r, and set k days as the number of days in a week. Alice is going to paint some n...
3
t=int(input()) for _ in range(t): l=list(map(int,input().split())) n,r=l[0],l[1] if(n>r): print((r*(r+1))//2) else: p=((n-1)*(n))//2 print(p+1)
Create a program that outputs the surface area S of a square cone with a height of h, with a square with one side x as the base. However, assume that the line segment connecting the apex and the center of the base is orthogonal to the base. Also, x and h are positive integers less than or equal to 100. Input Given mu...
3
while True: x = float(input()) h = float(input()) if x == 0 and h == 0: break print("%.6f"%(x**2+x*2*(h**2+(x/2)**2)**0.5))
Taro and Jiro will play the following game against each other. Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro: * Remove the element at the beginning or the end of a. The player earns x points, whe...
3
N = int(input()) a = list(map(int,input().split())) dp = [[0]*(N+1) for _ in range(N+1)] for i in range(N-1, -1, -1): for j in range(i, N): dp[i][j] = max(a[i]-dp[i+1][j],a[j]-dp[i][j-1]) print(dp[0][N-1])
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For exampl...
3
n=int(input()) a=list(map(int,input().split())) st=0 a.sort() while len(a)!=0: wt=1;a[0]='a' for i in range(len(a)): if a[i]!='a' and a[i]>=wt: wt+=1;a[i]='a' for i in range(a.count('a')): a.remove('a') st+=1 print(st)
Vus the Cossack has two binary strings, that is, strings that consist only of "0" and "1". We call these strings a and b. It is known that |b| ≤ |a|, that is, the length of b is at most the length of a. The Cossack considers every substring of length |b| in string a. Let's call this substring c. He matches the corresp...
3
def is_good(a, b): if (int(a, 2) & b) % 2 == 0: return 1 return 0 def go(): a = input() b = input() c_b = sum(1 for i in b if i == '1') c_a = sum(1 for i in range(len(b)) if a[i] == '1') c = 0 if c_b % 2 == c_a % 2: c += 1 for i in range(len(b), len(a)): c_b ...