problem
stringlengths
29
9.39k
language
int64
1
3
solution
stringlengths
7
465k
After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the win...
3
n=int(input()) a=list(map(int,input().split())) d={} ans=a[0] count=1 for i in range(n): if a[i] not in d: d[a[i]]=1 else: d[a[i]]+=1 if a[i]==ans: count+=1 elif d[a[i]]>count: ans=a[i] count=d[a[i]] print(ans)
You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of k in different moves. Your task is to find the minimum number of mo...
3
T = lambda : range(int(input())) A = lambda : list(map(int,input().split())) for _ in T() : a,b=A() if a==b : print(0) continue x=abs(a-b) if x%10==0 : print(x//10) else : print((x//10)+1)
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total? Constraints * 1≦N≦100 Input The input is given from Standard Inpu...
1
N = input() print ((N+1)*N/2)
For years, the Day of city N was held in the most rainy day of summer. New mayor decided to break this tradition and select a not-so-rainy day for the celebration. The mayor knows the weather forecast for the n days of summer. On the i-th day, a_i millimeters of rain will fall. All values a_i are distinct. The mayor k...
3
N, X, Y = map(int, input().split()) A = list(map(int, input().split())) for i in range(N): valid = True for j in range(i - X, i + Y + 1): if j < 0 or j >= N: continue if A[i] > A[j]: valid = False break if valid: print(i + 1) exit(0)
"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
#__author__ = 'Anonymeyll' a = str(input()) b = str(input()) n= int(a.split()[0]) k= int(a.split()[1]) player = b.split() i = 0 for j in range(n): if (int(player[j])>=int(player[k-1])) & (int(player[j])>0): i += 1 print(i)
Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook. Overall the group has n students. They received marks for m subjects. Each student got a mark from 1 to 9 (inclusive) for each subject. Let's consider a student the best at some...
3
import sys my_file = sys.stdin #my_file = open("input.txt", "r") line = my_file.readline().split() n, m = int(line[0]), int(line[1]) marks = my_file.read().split('\n') subject = [[] for i in range(m)] for subj in range(m): for student in range(n): subject[subj].append(marks[student][subj]) best = [[] for i ...
One day Kefa found n baloons. For convenience, we denote color of i-th baloon as si — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, ...
3
[n,k] = list(map(int, input().split(" "))) a = input() for c in a: if a.count(c) > k: print("NO") exit(0) print("YES")
Everybody knows of [spaghetti sort](https://en.wikipedia.org/wiki/Spaghetti_sort). You decided to implement an analog sorting algorithm yourself, but as you survey your pantry you realize you're out of spaghetti! The only type of pasta you have is ravioli, but you are not going to let this stop you... You come up with...
3
def flat(b): i = 0 while i < len(b)-1: if b[i] - b[i+1] >= 2: b[i] -= 1 b[i+1] += 1 i = 0 elif b[i] - b[i+1] <= -2: b[i] += 1 b[i+1] -= 1 i = 0 else: i += 1 return b n = int(input()) a = [int(i) for i in input().split(" ")] a1 = sorted(a) a2 = [] while len(a...
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
value = input() value = int(value) if value%2 == 0 and value>2: print('YES') else: print('NO')
You have a coins of value n and b coins of value 1. You always pay in exact change, so you want to know if there exist such x and y that if you take x (0 ≤ x ≤ a) coins of value n and y (0 ≤ y ≤ b) coins of value 1, then the total value of taken coins will be S. You have to answer q independent test cases. Input The...
3
for _ in range(int(input())): a,b,n,S = map(int,input().split()) if b >= S%n and (a*n) + b >= S: print("YES") else: print("NO")
There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this graph and a piece. Initially, the piece is placed at vertex 1, and the score of the player is set to 0. The player can move t...
3
(n,m),*l=[list(map(int,s.split()))for s in open(0)];d=[0]*2+[9e99]*n for i in range(n*2): for a,b,c in l: if d[b]>d[a]-c:d[b]=[d[a]-c,-9e99][i>n] if i==n:x=d[n] print([-x,'inf'][d[n]!=x])
Two integer sequences existed initially — one of them was strictly increasing, and the other one — strictly decreasing. Strictly increasing sequence is a sequence of integers [x_1 < x_2 < ... < x_k]. And strictly decreasing sequence is a sequence of integers [y_1 > y_2 > ... > y_l]. Note that the empty sequence and th...
3
# AC import sys import random class Main: def __init__(self): self.buff = None self.index = 0 def next(self): if self.buff is None or self.index == len(self.buff): self.buff = sys.stdin.readline().split() self.index = 0 val = self.buff[self.index] ...
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh a and b respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight. Limak eats a lot and his weight is tripled after every year, while Bob's weight...
3
ab = input("") a, b = ab.split(" ") a, b = int(a), int(b) counter = 0 while a <= b: a *= 3 b *= 2 counter += 1 print(counter)
Alica and Bob are playing a game. Initially they have a binary string s consisting of only characters 0 and 1. Alice and Bob make alternating moves: Alice makes the first move, Bob makes the second move, Alice makes the third one, and so on. During each move, the current player must choose two different adjacent char...
1
from sys import stdin, stdout from collections import Counter, defaultdict from itertools import permutations, combinations raw_input = stdin.readline pr = stdout.write mod=10**9+7 def ni(): return int(raw_input()) def li(): return map(int,raw_input().split()) def pn(n): stdout.write(str(n)+'\n') def...
You have n gifts and you want to give all of them to children. Of course, you don't want to offend anyone, so all gifts should be equal between each other. The i-th gift consists of a_i candies and b_i oranges. During one move, you can choose some gift 1 ≤ i ≤ n and do one of the following operations: * eat exactly...
3
t=int(input()) for j in range(t): n=int(input()) list1=list(map(int,input().split(" "))) list2=list(map(int,input().split(" "))) min1=min(list1) min2=min(list2) sum1=0 for i,j in zip(list1,list2): sum1+=max(i-min1,j-min2) print(sum1)
Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are dec...
3
s = input() print('ABC') if len(s)<4 else print('ABD')
Arya has n opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya...
3
n, d = map(int, input().split()) ret = 0 consecutive = 0 for i in range(d): s = input() if s.count('1') == n: ret = max(ret, consecutive) consecutive = 0 else: consecutive += 1 ret = max(ret, consecutive) print(ret)
Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: qwertyuiop asdfghjkl; zxcvbnm,./ Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally move...
3
s1=input() s=input() l1=['q','w','e','r','t','y','u','i','o','p'] l2=['a','s','d','f','g','h','j','k','l',';'] l3=['z','x','c','v','b','n','m',',','.','/'] if s1=='R': for i in range(len(s)): if s[i] in l1: a=l1.index(s[i]) print(l1[a-1],end='') elif s[i] in l2: a=l2.index(s[i]) print(l2[a-1],end='') ...
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
#!/usr/bin/env python3 from sys import stdin, stdout def get_int(): return int(stdin.readline().strip()) def get_string(): return stdin.readline().strip() def get_ints(): return map(int, stdin.readline().strip().split()) def get_count(val): return map(stdin.readline().count, (val)) # TODO go ...
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and like that his feelings are complicated. They have n layers. The first layer is hate, seco...
3
s = int(input()) for i in range(1,s): if(i%2==1): print("I hate that", end=" ") else: print("I love that", end=" ") if(s%2==1): print("I hate it") if(s%2==0): print("I love it")
Bob is a competitive programmer. He wants to become red, and for that he needs a strict training regime. He went to the annual meeting of grandmasters and asked n of them how much effort they needed to reach red. "Oh, I just spent x_i hours solving problems", said the i-th of them. Bob wants to train his math skills...
3
import sys from heapq import heappop from heapq import heappush from heapq import heapify from bisect import insort from bisect import bisect_right from bisect import bisect_left from sys import stdin,stdout from collections import defaultdict, deque from math import log2, ceil, floor inp=lambda : int(input()) sip=lam...
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first n. He writes down the followin...
1
from __future__ import division import sys from collections import namedtuple #x=namedtuple('point','x y') from math import * from collections import deque, OrderedDict #append #popleft from fractions import gcd from copy import copy ,deepcopy from collections import Counter #Counter(list) import re #re.split("[^a-zA-Z...
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. Input The single line of the input contains a pa...
1
a,b = map(int,raw_input().split()) c1 = [0]*a c2 = [0]*a if b/9>a or(b/9==a and b%9>0): print -1,-1 exit(0) if b==0: if a>1: print -1,-1 exit(0) else: print 0,0 exit(0) d = ('9'*(b/9)+str(b%9)+'0'*(a-b/9-1))[:a] e = int(('9'*((b-1)/9)+str((b-1)%9)+'0'*(a-(b-1)/9-1))[::-1])+10**(a-1) print e,d
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation. The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe...
3
a = [_ for _ in input()] sign = ('+') i = sorted([j for j in a if j not in sign]) print('+'.join(i))
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()) s1=s2=s3=0 for i in range(n): x,y,z=map(int,input().split()) s1+=x s2+=y s3+=z print("YES" if s1==s2==s3==0 else "NO")
A sequence of square brackets is regular if by inserting symbols "+" and "1" into it, you can get a regular mathematical expression from it. For example, sequences "[[]][]", "[]" and "[[][[]]]" — are regular, at the same time "][", "[[]" and "[[]]][" — are irregular. Draw the given sequence using a minimalistic pseud...
3
import collections as col import itertools as its import sys import operator from copy import copy, deepcopy class Solver: def __init__(self): pass def solve(self): n = int(input()) psp = input() m = 0 st = [] pair = [0] * n for i in range(n): ...
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two ...
3
n=int(input()) if(n%2==0): a=n//2 a-=2 a*=2 print(n-a,a) else: a=n//2 a-=4 a*=2 print(n-a,a)
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 sys import stdin, stdout from collections import deque import bisect R = lambda : stdin.readline().strip() RL = lambda f=None: list(map(f, R().split(' '))) if f else list(R().split(' ')) output = lambda x: stdout.write(str(x) + '\n') output_list = lambda x: output(' '.join(map(str, x))) import math T = int(input()...
Manao has a monitor. The screen of the monitor has horizontal to vertical length ratio a:b. Now he is going to watch a movie. The movie's frame has horizontal to vertical length ratio c:d. Manao adjusts the view in such a way that the movie preserves the original frame ratio, but also occupies as much space on the scre...
3
def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) a, b, c, d = [int(s) for s in input().split()] if a / c < b / d: ch = abs(a * d - b * c) zn = c * b else: ch = abs(b * c - a * d) zn = d * a nod = gcd(ch, zn) print(str(ch // nod) + '/' + str(zn // nod))
You have a list of numbers from 1 to n written from left to right on the blackboard. You perform an algorithm consisting of several steps (steps are 1-indexed). On the i-th step you wipe the i-th number (considering only remaining numbers). You wipe the whole number (not one digit). <image> When there are less than ...
3
m = int(input()) for _ in range(m): n,x = [int(i) for i in input().split()] print(x * 2)
One day, Niwango-kun, an employee of Dwango Co., Ltd., found an integer sequence (a_1, ..., a_N) of length N. He is interested in properties of the sequence a. For a nonempty contiguous subsequence a_l, ..., a_r (1 \leq l \leq r \leq N) of the sequence a, its beauty is defined as a_l + ... + a_r. Niwango-kun wants to ...
3
def main(): n,k=map(int,input().split()) a=[0]+list(map(int,input().split())) p=[] for i in range(n): a[i+1]+=a[i] for i in range(n+1): for j in range(i): p.append(a[i]-a[j]) p.sort() ans=0 from math import log,ceil r=ceil(log(sum(p))+10**-3) for i in range(r+2,-1,-1): cnt=0 for j in range(len(p)):...
Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside. Big Banban is hesitating over the amount ...
3
k = int(input()); s = ""; while k > 0: if k > 1: s = s + "8"; k = k - 2; else: s = s + "4"; k = k - 1; if len(s) < 19: print(s); else: print(-1);
Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn. You have a sequence of integers a1, a2, ..., an. In on...
3
n=int(input()) a=list(map(int,input().split())) a.sort() c=0 for i in range(n): c=c+abs(i+1-a[i]) print(c)
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
if __name__ == '__main__': for _ in range(int(input().strip(" "))): s = input().strip(" ") if len(s)>10: s = s[0]+str(len(s)-2)+s[len(s)-1] print(s)
Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules. The game is played on the following field. <image> Players are making moves by turns. At first move a player can put his chip in any cell of any sm...
1
gr = [] for i in range(0,11): ar = map(str, raw_input().split()) if len(ar) != 0: st = ar[0]+ar[1]+ar[2] gr.append(st) a = map(int, raw_input().split()) def w( x, y,gr): fl = 0 gg = gr[:] for i in range(x*3, x*3+3): ss = '' for j in range(y*3,y*3+3): if gg[i][j] == '.': ss += '!' fl = 1 el...
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of the...
3
N = int(input()) S = input() E = S.count("E") W = N - E s = N re = E lw = 0 for i in S: if i == "E": re -= 1 s = min(s, re + lw) else: s = min(s, re + lw) lw += 1 print(s)
It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive numbers from 1 to n from the left to the right. Unfortunately, Joe ...
3
n, m, k = map(int, input().split()) a = list(map(int, input().split())) if n % 2 == 0: print('0') else: print(min(m // (n // 2 + 1) * k, min(a[::2]))) # Made By Mostafa_Khaled
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr...
3
n = list(map(int ,input().split())) x = len([i for i in range(max(n),7)]) if x == 1: print('1/6') elif x == 2: print('1/3') elif x == 3: print('1/2') elif x == 4: print('2/3') elif x == 5: print('5/6') else: print('1/1')
You got a job as a marketer in a pet shop, and your current task is to boost sales of cat food. One of the strategies is to sell cans of food in packs with discounts. Suppose you decided to sell packs with a cans in a pack with a discount and some customer wants to buy x cans of cat food. Then he follows a greedy str...
3
for t in range(int(input())): l,r=map(int,input().split()) a=2*l if a>r: print("YES") else: print("NO")
This is the easy version of the problem. The difference between the versions is that in the easy version all prices a_i are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All n ice spheres are placed in a row ...
3
# by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO, IOBase from bisect import bisect_right def main(): n = int(input()) a = sorted(map(int,input().split()),reverse=1) print((n-1)//2) b = [a[0]] for i in range(1,n-1,2): b.extend([a[i+1],a[i]]) ...
Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not. Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindro...
3
s1=input() s2=s1[::-1] s3=s1+s2 print(s3)
Let us call two integers x and y adjacent if (lcm(x, y))/(gcd(x, y)) is a perfect square. For example, 3 and 12 are adjacent, but 6 and 9 are not. Here gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y, and lcm(x, y) denotes the [least comm...
3
import sys input = sys.stdin.readline from collections import Counter Primes=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, ...
There are many freight trains departing from Kirnes planet every day. One day on that planet consists of h hours, and each hour consists of m minutes, where m is an even number. Currently, there are n freight trains, and they depart every day at the same time: i-th train departs at h_i hours and m_i minutes. The gover...
3
import sys import re def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) def solve(): n, h, m, k = mints() m //= 2 a = [0]*n e = [None]*(2*n+2) c = 0 for i in range(n): hh, mm = mints() x = mm % m a[i] = mm e[2*i] = ((x+k)%m, -...
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
# http://codeforces.com/problemset/problem/41/A s1 = input() s2 = input() if s1[::-1] == s2: print("YES") else: print("NO")
Today, the memorable AtCoder Beginner Contest 100 takes place. On this occasion, Takahashi would like to give an integer to Ringo. As the name of the contest is AtCoder Beginner Contest 100, Ringo would be happy if he is given a positive integer that can be divided by 100 exactly D times. Find the N-th smallest intege...
3
D, N = map(int,input().split()) if(N == 100): N = 101 print((100**D)*N)
In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum. For example, for n = 4 the sum is equal to - 1 - 2 + 3 - 4 = - 4, because 1, 2 and 4 are 20, 21 and 22 respectively. Calculate the answer for t values of n. Input The first line of...
3
a=int(input()) if a>=1 and a<=100: total=0 while a>0: num=int(input()) if num>=1 and num<=1000000000: time=0 while True: if num-2**time<0: break time+=1 time=time-1 t=0 while time>=0: ...
There is a robot in a warehouse and n packages he wants to collect. The warehouse can be represented as a coordinate grid. Initially, the robot stays at the point (0, 0). The i-th package is at the point (x_i, y_i). It is guaranteed that there are no two packages at the same point. It is also guaranteed that the point ...
3
t = int(input()) for _ in range(t): n = int(input()) a = sorted([[int(x) for x in input().split()] for _ in range(n)]) ans = [] last_x = 0 last_y = 0 for (x, y) in a: ans.extend(['R'] * (x - last_x)) last_x = x if y < last_y: ans = [] break ...
Let's denote a function <image> You are given an array a consisting of n integers. You have to calculate the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. Input The first line contains one integer n (1 ≤ n ≤ 200000) — the number of elements in a. The second line contains n integers a1, a2, ..., ...
3
from collections import defaultdict n = int(input()) a = [int(x) for x in input().strip().split(' ')] ans = 0 cnt = defaultdict(lambda : 0) for i in range(n): c = i - (cnt[a[i]] + cnt[a[i] + 1] + cnt[a[i] - 1]) ans += c * a[i] cnt[a[i]] += 1 cnt = defaultdict(lambda : 0) for i in reversed(range(n)): ...
Ehab loves number theory, but for some reason he hates the number x. Given an array a, find the length of its longest subarray such that the sum of its elements isn't divisible by x, or determine that such subarray doesn't exist. An array a is a subarray of an array b if a can be obtained from b by deletion of several...
3
import math import itertools mp = lambda: map( int, input().split() ) mod = 998244353 mod = int(mod) def main(): t = int( input() ) while t: t -= 1 input() x = {} for i in list( mp() ): if i not in x.keys(): x[i] = 1 print( len( x ) ) ...
You are given an array of n integers: a_1, a_2, …, a_n. Your task is to find some non-zero integer d (-10^3 ≤ d ≤ 10^3) such that, after each number in the array is divided by d, the number of positive numbers that are presented in the array is greater than or equal to half of the array size (i.e., at least ⌈n/2⌉). Not...
3
n = int(input()) a =[int(x) for x in input().split()] from math import ceil import sys debug = len(sys.argv)-1 p, n, z = 0, 0, a.count(0) for i in a: if i > 0: p += 1 if i < 0: n += 1 if debug > 0: print(p, n, z) if (max(p, n) >= ceil(len(a)/2)): if p > n: print(1) else: print(-1) else: print(0)
For a given polygon g, computes the area of the polygon. g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of g. The line segment connecting pn and p1 is also a side of the polygon. Note that the polygon is not necessarily convex. Constraints ...
3
x=range(int(input())) P=[] for _ in x:P+=[[int(i) for i in input().split()]] _=0 P+=[P[0]] for j in x:_+=P[j][0]*P[j+1][1]-P[j+1][0]*P[j][1] print(_*0.5)
Input The only line of the input contains a 7-digit hexadecimal number. The first "digit" of the number is letter A, the rest of the "digits" are decimal digits 0-9. Output Output a single integer. Examples Input A278832 Output 0 Input A089956 Output 0 Input A089957 Output 1 Input A1440...
3
x = input() a = int(x[len(x) - 1]) print(a % 2)
Today's morning was exceptionally snowy. Meshanya decided to go outside and noticed a huge snowball rolling down the mountain! Luckily, there are two stones on that mountain. Initially, snowball is at height h and it has weight w. Each second the following sequence of events happens: snowball's weights increases by i,...
3
T_ON = 0 DEBUG_ON = 0 MOD = 998244353 def solve(): w, h = read_ints() u1, d1 = read_ints() u2, d2 = read_ints() if d1 < d2: u1, d1, u2, d2 = u2, d2, u1, d1 def hit(w, h, u, d): w += (h + d) * (h - d + 1) // 2 - u h = d - 1 return max(0, w), h w, h = hit(w, h, ...
Everybody knows of [spaghetti sort](https://en.wikipedia.org/wiki/Spaghetti_sort). You decided to implement an analog sorting algorithm yourself, but as you survey your pantry you realize you're out of spaghetti! The only type of pasta you have is ravioli, but you are not going to let this stop you... You come up with...
3
n = int(input()) s =list(map(int, input().split())) for i in range(1, n): if abs(s[i] - s[i-1]) >= 2: print("NO") exit(0) print("YES")
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
angka=int(input()) hasil=0 for i in range(0,angka): kode=input() if kode=="++X" or kode=="X++": hasil+=1 elif kode=="--X" or kode=="X--": hasil-=1 print(hasil)
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
a=int(input()) d=a//2 e=a-d s=0 while d>0: if d%2==0 and e%2==0: print('YES') s=1 break d-=1 e+=1 if s==0: print('NO')
Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with ve...
1
n = input() if int(n**.5)**2==n: print int(n**.5)*2 else: r=int(n**.5) if n<=(r**2+r): print 2*r+1 else: print 2*r+2
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...
3
n1, n2 = [int(x) for x in input().split()] k, m = [int(x) for x in input().split()] a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] if a[k - 1] < b[n2 - m]: print("YES") else: print("NO")
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned...
3
n = int(input()) inf = 1<<30 x1 = inf y1 = inf x2 = -inf y2 = -inf for i in range(n): x, y = map(int, input().split(" ")) x2 = max(x2, x) y2 = max(y2, y) x1 = min(x1, x) y1 = min(y1, y) if n == 1 or (n == 2 and (x1 == x2 or y1 == y2)): print("-1") else: print(abs(x1-x2)*abs(y1-y2))
One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one! Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to...
1
x = int(raw_input()) - 10 if x == 10: print 15 elif x > 0 and x < 12: print 4 else: print 0
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation. The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe...
3
s=input() if (len(s)==1): print(s) elif(len(s)>1): dig="" final="" for i in s: if(i.isdigit()): dig=dig+i sor_dig=sorted(dig) final=sor_dig[0] for i in range(1,len(sor_dig)): final=final+"+"+sor_dig[i] print(final)
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the dista...
1
n=int(input()) d=raw_input() s=map(int,raw_input().split()) ans=1000000000 found=False for i in xrange(n-1) : if d[i]=='R' and d[i+1]=='L' : ans=min(ans,(s[i+1]-s[i])/2) found=True if found : print ans else : print -1
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...
1
take=lambda:raw_input().strip() N,S=take().split() N,S=int(N),int(S) ans,upper=[],[] for i in xrange(N): L,U=take().split() L,U=int(L),int(U) upper.append(U) ans.append(L) S=S-L i=0 while i<N and S>0: temp=ans[i] ans[i]+=min(S,upper[i]-ans[i]) S-=min(S,upper[i]-temp) i+=1 #print S if S<0 or S!=0: print 'NO' e...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. Input The first line contains integer a (1 ≤ a ≤ 1018). The second line contains i...
3
def dig(d): return ord(d) - ord('0') def biggest_left(counts): res = '' for i in range(9, -1, -1): res += str(i) * counts[i] return res def ok(d, _counts, rest): if rest == '': return True counts = _counts.copy() counts[d] -= 1 r = '' for i in range(10): ...
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
from sys import stdin input = stdin.readline n, m = map(int,input().split()) line = list(map(str,input().strip())) for _ in range(m): i = 0 while i < n-1: if line[i+1] == "G" and line[i] == "B": line[i+1], line[i] = line[i], line[i+1] i += 1 i += 1 for l in line: p...
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them. In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 ...
1
n,m = map(int,raw_input().split()) grid = [] no = 0 for i in xrange(n): grid += [raw_input()] for i in xrange(n-1): for j in xrange(m-1): ar = [grid[i][j],grid[i+1][j],grid[i][j+1],grid[i+1][j+1]] if('f' in ar and 'a' in ar and 'c' in ar and 'e' in ar): no += 1 print no
You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N). Your objective is to remove some of the elements in a so that a will be a good sequence. Here, an sequence b is a good sequence when the following condition holds true: * For each element x in b, the value x occurs exactly x times in...
3
#!/usr/bin/env python # -*- coding: utf-8 -*- from collections import defaultdict def solve(): n = int(input()) ad = defaultdict(int) for i in input().split(): ad[int(i)] += 1 ans = 0 for k, v in ad.items(): if k > v: ans += v if v > k: ans += v ...
Dolphin is planning to generate a small amount of a certain chemical substance C. In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b. He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmac...
3
N,Ma,Mb = map(int,input().split()) INF = 10000 dp = [[[INF for b in range(401)] for a in range(401)] for i in range(N+1)] dp[0][0][0] = 0 for i in range(1,N+1): ai,bi,ci = map(int,input().split()) for a in range(401): for b in range(401): if a-ai >= 0 and b-bi >= 0: dp[i]...
Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i (i > 0) has height hi. The goal of the game is to reach n-th pylon...
3
n=int(input()) h=list(map(int,input().split())) e,m=0,0 for i in range(0,n): b=abs(h[i]-h[i-1]) if i==0: m+=h[i] elif h[i]>h[i-1]: if e!=0: if e>=b:e-=b else: b-=e e=0 m+=b else:m+=b elif h[i]<h[i-1]:e+=b pri...
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Т-prime, if t has exactly three distinct positive divisors. You are given an array of n positive integers. For each of them determine whether it is Т-prime or not. Input The f...
3
from math import sqrt n,arr = int(input()),list(map(int,input().split(' '))) M = int(sqrt(max(arr)))+1 def Euler(upper): filters=[False]*(upper+2) prime=[] for num in range(2,upper+1): if not filters[num]: prime.append(num) for each in pr...
Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i (i > 0) has height hi. The goal of the game is to reach n-th pylon...
3
n = int(input()) h = [int(j) for j in input().split()] print(max(h))
One day, Twilight Sparkle is interested in how to sort a sequence of integers a1, a2, ..., an in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning: a1, a2, ..., an → an, a1, a2, ..., an - 1. Help Twi...
3
n=int(input()) li=list(map(int,input().split(" "))) sli=list(sorted(li)) i=0 start=li.index(li[0]) checker=False while i<n: if li[i]==sli[0]: if checker==False: start=i checker=True else: checker=False i+=1 i=start res=n-start if res==n: res=0 for x in sli: ...
Mountaineers Mr. Takahashi and Mr. Aoki recently trekked across a certain famous mountain range. The mountain range consists of N mountains, extending from west to east in a straight line as Mt. 1, Mt. 2, ..., Mt. N. Mr. Takahashi traversed the range from the west and Mr. Aoki from the east. The height of Mt. i is h_i...
3
import sys mod = 10**9 + 7 def nai(): print(0) sys.exit() N = int(input()) T = list(map(int, input().split())) A = list(map(int, input().split())) M = max(A) if M != max(T): nai() iT = T.index(M) iA = N - 1 - A[::-1].index(M) if iA < iT: nai() ans = pow(M, max(0, iA - iT - 1), mod) pre = -1 for t in...
A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly n pixels. Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels a and the number of columns of pixels b, so that: * there are exactly n pixels on the d...
3
import math while True: try: num = int(input()) ans = int(math.sqrt(num)) while True: if num % ans == 0: print(ans, num // ans) break else: ans -= 1 except EOFError: break
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million...
3
n=int(input()) number=int(input()) c=0 for i in range(1,32): if number==n**i: print("YES") c=1 print(f"{i-1}") break if c!=1: print("NO")
You are given an array a of n integers, where n is odd. You can make the following operation with it: * Choose one of the elements of the array (for example a_i) and increase it by 1 (that is, replace it with a_i + 1). You want to make the median of the array the largest possible using at most k operations. The...
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 import operator as op from bisect import bisect_left, bi...
You are given n chips on a number line. The i-th chip is placed at the integer coordinate x_i. Some chips can have equal coordinates. You can perform each of the two following types of moves any (possibly, zero) number of times on any chip: * Move the chip i by 2 to the left or 2 to the right for free (i.e. replace...
3
n=int(input()) a1=0 a2=0 x=list(map(int, list(input().split()))) for i in range(n): x1= x[i] if x1 % 2 == 0: a2 = a2+1 else: a1=a1+1 if a1>a2: print(a2) else: print(a1)
There are N dots in a two-dimensional plane. The coordinates of the i-th dot are (x_i, y_i). We will repeat the following operation as long as possible: * Choose four integers a, b, c, d (a \neq c, b \neq d) such that there are dots at exactly three of the positions (a, b), (a, d), (c, b) and (c, d), and add a dot at...
3
import sys input = sys.stdin.readline sys.setrecursionlimit(1000000) N = int(input()) K = 10**5+1 P = [i for i in range(K)] def par(a): if P[a] == a: return a t = par(P[a]) P[a] = t return t def cb(a, b): P[par(b)] = par(a) X = [[] for _ in range(K)] Y = [[] for _ in range(K)] for _ in ran...
We have a point A with coordinate x = n on OX-axis. We'd like to find an integer point B (also on OX-axis), such that the absolute difference between the distance from O to B and the distance from A to B is equal to k. <image> The description of the first test case. Since sometimes it's impossible to find such point ...
3
for i in range(int(input())): n,k=[int(num) for num in input().split()] if k>=n: print(k-n) else: if (n+k)%2==0: print(0) else: print(1)
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
import sys k = sys.stdin.readline().rstrip() a = int(k.count("a")) A = int(k.count("A")) b = int(k.count("b")) B = int(k.count("B")) c = int(k.count("c")) C = int(k.count("C")) d = int(k.count("d")) D = int(k.count("D")) e = int(k.count("e")) E = int(k.count("E")) f = int(k.count("f")) F = int(k.count("F")) g = int(k.c...
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O...
1
a=(raw_input()+raw_input()) b=set(a) c=raw_input() d=set(c) ans='YES' if b!=d: ans='NO' else: for element in b: if a.count(element)!=c.count(element): ans='NO' print ans
You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below. Fortunately, you are a skilled magician, capable of causing expl...
3
import sys S=sys.stdin.readlines() N,A,B=map(int,S[0].split()) H=[int(S[i+1]) for i in range(N)] L,R=0,10**9 M=0 Z=0 A-=B while R>L: M=(L+R)//2 Z=0 for i in range(N): Z+=max((H[i]-B*M+A-1)//A,0) if Z>M: L=max(L+1,M) else: R=M print(R)
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm × b mm sheet of paper (a > b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting t...
3
a, b = map(int, input().split()) squares = 0 while True: squares += a//b a %= b if(a == 0): break a, b = b, a print(squares)
You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them. You know that you have n bacteria in the Petri dish and size of the i-th bacteria is a_i. Also you know intergalactic positive integer constan...
3
n,k=map(int,input().split()) l=sorted(list(map(int,input().split()))) j=0 for i in l: while l[j]<i: if i<=k+l[j]: n-=1 j+=1 print(n)
Gildong's town has a train system that has 100 trains that travel from the bottom end to the top end and 100 trains that travel from the left end to the right end. The trains starting from each side are numbered from 1 to 100, respectively, and all trains have the same speed. Let's take a look at the picture below. <i...
1
from __future__ import division, print_function ''' Hey stalker :) ''' INF = 10 ** 50 TEST_CASES = True from collections import defaultdict, deque, Counter from functools import reduce from bisect import bisect_left def main(): n, m = get_list() l1 = get_list() l2 = get_list() i = 0 same = 0 ...
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or abo...
3
x=int(input()) a=100 cnt=0 while x>a: a=int(a*1.01) cnt+=1 print(cnt)
Your company was appointed to lay new asphalt on the highway of length n. You know that every day you can either repair one unit of the highway (lay new asphalt over one unit of the highway) or skip repairing. Skipping the repair is necessary because of the climate. The climate in your region is periodical: there are ...
1
def check(mid, n, g, b): req = (n / 2) + (n % 2) p = (mid / (g + b)) * g rem = mid % (g + b) if rem >= g: p += g else: p += rem if p >= req: return True return False t = input() for _ in range(t): n, g, b = map(int, raw_input().split()) s = n e = 10**18 ...
Polycarp decided to relax on his weekend and visited to the performance of famous ropewalkers: Agafon, Boniface and Konrad. The rope is straight and infinite in both directions. At the beginning of the performance, Agafon, Boniface and Konrad are located in positions a, b and c respectively. At the end of the performa...
3
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permut...
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are n drinks in his fridge, the volume fraction of orange juice in the i-th drink equals pi percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of ea...
3
from decimal import * getcontext().prec=12 n=int(input()) lst=list(map(int,input().split())) sum=0 for i in lst: sum+=i print(Decimal(sum)/Decimal(n))
AtCoDeer the deer found two rectangles lying on the table, each with height 1 and width W. If we consider the surface of the desk as a two-dimensional plane, the first rectangle covers the vertical range of [0,1] and the horizontal range of [a,a+W], and the second rectangle covers the vertical range of [1,2] and the ho...
3
W,a,b=map(int, input().split()) dis = max(0, abs(a-b)-W) print(dis)
Recall that the sequence b is a a subsequence of the sequence a if b can be derived from a by removing zero or more elements without changing the order of the remaining elements. For example, if a=[1, 2, 1, 3, 1, 2, 1], then possible subsequences are: [1, 1, 1, 1], [3] and [1, 2, 1, 3, 1, 2, 1], but not [3, 2, 3] and [...
3
import sys cases = int(input()) for t in range(cases): n = int(input()) a = list(map(int,input().split())) prev = a[0] s = 0 m = prev for i in a[1:]: if i*prev > 0: m = max(m,i) else: s+=m m=i prev = i s+=m print(s)
Write a program which calculates the area and perimeter of a given rectangle. Constraints * 1 ≤ a, b ≤ 100 Input The length a and breadth b of the rectangle are given in a line separated by a single space. Output Print the area and perimeter of the rectangle in a line. The two integers should be separated by a si...
3
a,aa = map(int,input().split()) print(a*aa,2*(a+aa))
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
def f1(n): if (n//2)%2: print("NO") return False arr=[] for i in range(n//2): arr.append(i*2+2) for i in range(n//2): arr.append(i*2+1) print("YES") arr[-1]+=n//2 for m in arr: print(m,end=' ') return True T=int(input()) for i ...
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
import collections if __name__ == '__main__': n = int(input()) collect = collections.Counter() for i in range(n): res = input() collect[res]+=1 print(collect.most_common(1)[0][0])
Everybody knows of [spaghetti sort](https://en.wikipedia.org/wiki/Spaghetti_sort). You decided to implement an analog sorting algorithm yourself, but as you survey your pantry you realize you're out of spaghetti! The only type of pasta you have is ravioli, but you are not going to let this stop you... You come up with...
3
n = int(input()) a = list(map(int, input().split())) for i in range(1,len(a)): if abs(a[i] - a[i-1]) > 1: print("NO") exit() print('YES')
Omkar is building a waterslide in his water park, and he needs your help to ensure that he does it as efficiently as possible. Omkar currently has n supports arranged in a line, the i-th of which has height a_i. Omkar wants to build his waterslide from the right to the left, so his supports must be nondecreasing in he...
3
#Codeforces - implementation - 1392C Omkar and Waterslide t = int(input()) while t != 0: n = int(input()) arrN = list(map(int, input().split())) incrementNum = 0 for i in range(n-1): if arrN[i]>arrN[i+1]: incrementNum += arrN[i] - arrN[i+1] print(incrementNum) t -= 1
Given a lowercase English letter c, determine whether it is a vowel. Here, there are five vowels in the English alphabet: `a`, `e`, `i`, `o` and `u`. Constraints * c is a lowercase English letter. Input The input is given from Standard Input in the following format: c Output If c is a vowel, print `vowel`. Oth...
3
c = input() if "aiueo".count(c): print("vowel") else: print("consonant")
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
# http://codeforces.com/problemset/problem/263/A one_row = 0 one_column = 0 for i in range(1, 6): row = input().replace(" ", "") if "1" in row: one_row = i one_column = row.index("1") + 1 minimum_moves = abs(one_row - 3) + abs(one_column - 3) print(minimum_moves)
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that 1. 1 ≤ i, j ≤ N 2. S[i] = S[j], that is the i-th symbol of string S is equal to the j-th. Input The single input line contains S, consisting of lowercase Latin letters and digits. It is ...
3
lis=input() count=dict() for i in lis: count[i] = count.get(i, 0) + 1 sum=0 for i in count.values(): sum=sum+i*i print(sum)
Attention: we lost all the test cases for this problem, so instead of solving the problem, we need you to generate test cases. We're going to give you the answer, and you need to print a test case that produces the given answer. The original problem is in the following paragraph. People don't use cash as often as they...
3
n=int(input()) if n==1: print(1,1) print(1) else: print((n-1)*2,2) print(1,2)