message
stringlengths
2
43.5k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
853
107k
cluster
float64
24
24
__index_level_0__
int64
1.71k
214k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp wrote on the board a string s containing only lowercase Latin letters ('a'-'z'). This string is known for you and given in the input. After that, he erased some letters from the string s, and he rewrote the remaining letters in any order. As a result, he got some new string t. You have to find it with some additional information. Suppose that the string t has length m and the characters are numbered from left to right from 1 to m. You are given a sequence of m integers: b_1, b_2, …, b_m, where b_i is the sum of the distances |i-j| from the index i to all such indices j that t_j > t_i (consider that 'a'<'b'<...<'z'). In other words, to calculate b_i, Polycarp finds all such indices j that the index j contains a letter that is later in the alphabet than t_i and sums all the values |i-j|. For example, if t = "abzb", then: * since t_1='a', all other indices contain letters which are later in the alphabet, that is: b_1=|1-2|+|1-3|+|1-4|=1+2+3=6; * since t_2='b', only the index j=3 contains the letter, which is later in the alphabet, that is: b_2=|2-3|=1; * since t_3='z', then there are no indexes j such that t_j>t_i, thus b_3=0; * since t_4='b', only the index j=3 contains the letter, which is later in the alphabet, that is: b_4=|4-3|=1. Thus, if t = "abzb", then b=[6,1,0,1]. Given the string s and the array b, find any possible string t for which the following two requirements are fulfilled simultaneously: * t is obtained from s by erasing some letters (possibly zero) and then writing the rest in any order; * the array, constructed from the string t according to the rules above, equals to the array b specified in the input data. Input The first line contains an integer q (1 ≀ q ≀ 100) β€” the number of test cases in the test. Then q test cases follow. Each test case consists of three lines: * the first line contains string s, which has a length from 1 to 50 and consists of lowercase English letters; * the second line contains positive integer m (1 ≀ m ≀ |s|), where |s| is the length of the string s, and m is the length of the array b; * the third line contains the integers b_1, b_2, ..., b_m (0 ≀ b_i ≀ 1225). It is guaranteed that in each test case an answer exists. Output Output q lines: the k-th of them should contain the answer (string t) to the k-th test case. It is guaranteed that an answer to each test case exists. If there are several answers, output any. Example Input 4 abac 3 2 1 0 abc 1 0 abba 3 1 0 1 ecoosdcefr 10 38 13 24 14 11 5 3 24 17 0 Output aac b aba codeforces Note In the first test case, such strings t are suitable: "aac', "aab". In the second test case, such trings t are suitable: "a", "b", "c". In the third test case, only the string t equals to "aba" is suitable, but the character 'b' can be from the second or third position. Submitted Solution: ``` #A,B,C,D = map(int,input().split()) t = int(input()) for i in range(t): D = list(input()) d = sorted(list(D), reverse=True) #print(d) l = int(input()) S = list(map(int,input().split())) s = sorted(S) #print(s) #print(d) out = ['x' for x in range(l)] counter = 0 curl = 'x' while max(S) > -1: ind = [] while S.count(0) > d.count(d[counter]): counter += 1 for j in range(len(S)): if S[j] == 0: out[j] = d[counter] curl = d[counter] S[j] -= 1 ind.append(j) for indd in ind: for j in range(len(S)): S[j] -= abs(j - indd) counter += len(ind) try: while curl == d[counter]: counter += 1 except: pass print(''.join(out)) #print(S) ```
instruction
0
36,989
24
73,978
Yes
output
1
36,989
24
73,979
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp wrote on the board a string s containing only lowercase Latin letters ('a'-'z'). This string is known for you and given in the input. After that, he erased some letters from the string s, and he rewrote the remaining letters in any order. As a result, he got some new string t. You have to find it with some additional information. Suppose that the string t has length m and the characters are numbered from left to right from 1 to m. You are given a sequence of m integers: b_1, b_2, …, b_m, where b_i is the sum of the distances |i-j| from the index i to all such indices j that t_j > t_i (consider that 'a'<'b'<...<'z'). In other words, to calculate b_i, Polycarp finds all such indices j that the index j contains a letter that is later in the alphabet than t_i and sums all the values |i-j|. For example, if t = "abzb", then: * since t_1='a', all other indices contain letters which are later in the alphabet, that is: b_1=|1-2|+|1-3|+|1-4|=1+2+3=6; * since t_2='b', only the index j=3 contains the letter, which is later in the alphabet, that is: b_2=|2-3|=1; * since t_3='z', then there are no indexes j such that t_j>t_i, thus b_3=0; * since t_4='b', only the index j=3 contains the letter, which is later in the alphabet, that is: b_4=|4-3|=1. Thus, if t = "abzb", then b=[6,1,0,1]. Given the string s and the array b, find any possible string t for which the following two requirements are fulfilled simultaneously: * t is obtained from s by erasing some letters (possibly zero) and then writing the rest in any order; * the array, constructed from the string t according to the rules above, equals to the array b specified in the input data. Input The first line contains an integer q (1 ≀ q ≀ 100) β€” the number of test cases in the test. Then q test cases follow. Each test case consists of three lines: * the first line contains string s, which has a length from 1 to 50 and consists of lowercase English letters; * the second line contains positive integer m (1 ≀ m ≀ |s|), where |s| is the length of the string s, and m is the length of the array b; * the third line contains the integers b_1, b_2, ..., b_m (0 ≀ b_i ≀ 1225). It is guaranteed that in each test case an answer exists. Output Output q lines: the k-th of them should contain the answer (string t) to the k-th test case. It is guaranteed that an answer to each test case exists. If there are several answers, output any. Example Input 4 abac 3 2 1 0 abc 1 0 abba 3 1 0 1 ecoosdcefr 10 38 13 24 14 11 5 3 24 17 0 Output aac b aba codeforces Note In the first test case, such strings t are suitable: "aac', "aab". In the second test case, such trings t are suitable: "a", "b", "c". In the third test case, only the string t equals to "aba" is suitable, but the character 'b' can be from the second or third position. Submitted Solution: ``` def solve(s,m,arr,ans): t = [-1]*m letters = [0]*26 for i in s: letters[ord(i)-ord('a')] += 1 #print(letters) limit = 25 indices = [] count = arr.count(0) while True: index = -1 for i in range(limit,-1,-1): if letters[i] >= count: limit = i-1 index = i break #print(index,count) if not indices: for i in range(m): if arr[i] == 0: t[i] = chr(ord('a')+index) indices.append(i) else: for i in good: t[i] = chr(ord('a')+index) indices.extend(good) good = [] for i in range(m): if t[i] != -1: continue count = 0 for index in indices: count += abs(index-i) if count == arr[i]: good.append(i) if not good: break count = len(good) t1 = '' for i in t: t1 += i #print(t1) ans.append(t1) def main(): q = int(input()) ans = [] for i in range(q): s = input() m = int(input()) arr = list(map(int,input().split())) solve(s,m,arr,ans) for i in ans: print(i) main() ```
instruction
0
36,990
24
73,980
Yes
output
1
36,990
24
73,981
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp wrote on the board a string s containing only lowercase Latin letters ('a'-'z'). This string is known for you and given in the input. After that, he erased some letters from the string s, and he rewrote the remaining letters in any order. As a result, he got some new string t. You have to find it with some additional information. Suppose that the string t has length m and the characters are numbered from left to right from 1 to m. You are given a sequence of m integers: b_1, b_2, …, b_m, where b_i is the sum of the distances |i-j| from the index i to all such indices j that t_j > t_i (consider that 'a'<'b'<...<'z'). In other words, to calculate b_i, Polycarp finds all such indices j that the index j contains a letter that is later in the alphabet than t_i and sums all the values |i-j|. For example, if t = "abzb", then: * since t_1='a', all other indices contain letters which are later in the alphabet, that is: b_1=|1-2|+|1-3|+|1-4|=1+2+3=6; * since t_2='b', only the index j=3 contains the letter, which is later in the alphabet, that is: b_2=|2-3|=1; * since t_3='z', then there are no indexes j such that t_j>t_i, thus b_3=0; * since t_4='b', only the index j=3 contains the letter, which is later in the alphabet, that is: b_4=|4-3|=1. Thus, if t = "abzb", then b=[6,1,0,1]. Given the string s and the array b, find any possible string t for which the following two requirements are fulfilled simultaneously: * t is obtained from s by erasing some letters (possibly zero) and then writing the rest in any order; * the array, constructed from the string t according to the rules above, equals to the array b specified in the input data. Input The first line contains an integer q (1 ≀ q ≀ 100) β€” the number of test cases in the test. Then q test cases follow. Each test case consists of three lines: * the first line contains string s, which has a length from 1 to 50 and consists of lowercase English letters; * the second line contains positive integer m (1 ≀ m ≀ |s|), where |s| is the length of the string s, and m is the length of the array b; * the third line contains the integers b_1, b_2, ..., b_m (0 ≀ b_i ≀ 1225). It is guaranteed that in each test case an answer exists. Output Output q lines: the k-th of them should contain the answer (string t) to the k-th test case. It is guaranteed that an answer to each test case exists. If there are several answers, output any. Example Input 4 abac 3 2 1 0 abc 1 0 abba 3 1 0 1 ecoosdcefr 10 38 13 24 14 11 5 3 24 17 0 Output aac b aba codeforces Note In the first test case, such strings t are suitable: "aac', "aab". In the second test case, such trings t are suitable: "a", "b", "c". In the third test case, only the string t equals to "aba" is suitable, but the character 'b' can be from the second or third position. Submitted Solution: ``` from collections import deque q = int(input()) def find_zero_idx(): val ,no = [],0 for i in range(m): if arr[i]==0: val.append(i) arr[i]=1e5 no+=1 return val,no def find_char(count,freq): for i in range(25,-1,-1): if freq[i]>=count: alphabet = chr(i+97) freq[i]=-1 return alphabet def solve(): freq = list(bytearray(26)) for c in s: idx = ord(c)-97 freq[idx]+=1 for i in range(26): if freq[i]==0: freq[i]=-1 ans = [None for i in range(m)] filled = 0 while True: zero_idx,total_zero = find_zero_idx() character = find_char(total_zero,freq) if total_zero==0: break for idx in zero_idx: ans[idx]=character filled+=1 for i in range(m): if ans[i]==None: for idx in zero_idx: arr[i]-=abs(i-idx) return "".join(ans) for _ in range(q): s = list(input()) m = int(input()) arr = list(map(int,input().split())) ans = solve() print(ans) ```
instruction
0
36,991
24
73,982
No
output
1
36,991
24
73,983
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp wrote on the board a string s containing only lowercase Latin letters ('a'-'z'). This string is known for you and given in the input. After that, he erased some letters from the string s, and he rewrote the remaining letters in any order. As a result, he got some new string t. You have to find it with some additional information. Suppose that the string t has length m and the characters are numbered from left to right from 1 to m. You are given a sequence of m integers: b_1, b_2, …, b_m, where b_i is the sum of the distances |i-j| from the index i to all such indices j that t_j > t_i (consider that 'a'<'b'<...<'z'). In other words, to calculate b_i, Polycarp finds all such indices j that the index j contains a letter that is later in the alphabet than t_i and sums all the values |i-j|. For example, if t = "abzb", then: * since t_1='a', all other indices contain letters which are later in the alphabet, that is: b_1=|1-2|+|1-3|+|1-4|=1+2+3=6; * since t_2='b', only the index j=3 contains the letter, which is later in the alphabet, that is: b_2=|2-3|=1; * since t_3='z', then there are no indexes j such that t_j>t_i, thus b_3=0; * since t_4='b', only the index j=3 contains the letter, which is later in the alphabet, that is: b_4=|4-3|=1. Thus, if t = "abzb", then b=[6,1,0,1]. Given the string s and the array b, find any possible string t for which the following two requirements are fulfilled simultaneously: * t is obtained from s by erasing some letters (possibly zero) and then writing the rest in any order; * the array, constructed from the string t according to the rules above, equals to the array b specified in the input data. Input The first line contains an integer q (1 ≀ q ≀ 100) β€” the number of test cases in the test. Then q test cases follow. Each test case consists of three lines: * the first line contains string s, which has a length from 1 to 50 and consists of lowercase English letters; * the second line contains positive integer m (1 ≀ m ≀ |s|), where |s| is the length of the string s, and m is the length of the array b; * the third line contains the integers b_1, b_2, ..., b_m (0 ≀ b_i ≀ 1225). It is guaranteed that in each test case an answer exists. Output Output q lines: the k-th of them should contain the answer (string t) to the k-th test case. It is guaranteed that an answer to each test case exists. If there are several answers, output any. Example Input 4 abac 3 2 1 0 abc 1 0 abba 3 1 0 1 ecoosdcefr 10 38 13 24 14 11 5 3 24 17 0 Output aac b aba codeforces Note In the first test case, such strings t are suitable: "aac', "aab". In the second test case, such trings t are suitable: "a", "b", "c". In the third test case, only the string t equals to "aba" is suitable, but the character 'b' can be from the second or third position. Submitted Solution: ``` #Imports from collections import defaultdict as dc from collections import Counter from heapq import * import math from bisect import bisect_left,bisect #bisect gives x and p[x] is element greater than it and out of bound for last one #p[x-1] gives equal or smaller and no error for any element. import sys from collections import deque as dq from heapq import heapify,heappush,heappop mod=10**9 +7 # How to sort a list using two compare : # instead of defining a function define class as a key '''class key(str): def __lt__(x,y): return int(x+y)>int(y+x)''' def sinp(): p=str(sys,stdin.readline()) return p def seive(n): p=[0]*(n+1) for i in range(2,n): if p[i]==0: for j in range(2*i,n+1,i): p[i]=1 return p def lower_bound(a,i,n): #Number of element is equal or lower than it #return bisect(a,i) #Number of elementt lower than it return bisect_left(a,i) def upper_bound(a,i,n): #Number of element greater than it #return n-bisect(a,i) #Number of element greater than or equal to it return n-bisect_left(a,i) def inp(): p=int(sys.stdin.readline()) return p def line(): p=list(map(int,sys.stdin.readline().split())) return p def read_mat(): n=inp() a=[] for i in range(n): a.append(line()) return a def ind(a): return ord(a)-ord('A') def digit(n): s=str(n) p=0 for i in s: p+=(int(i))**2 return p def solve(s,m,b): t=list('#'*m) p=[] for i in range(m): if b[i]==0: p.append([i+1,'#']) for i in range(len(p)): z=s.pop() t[p[i][0]-1]=z p[i][1]=z def position(b,m,p,x): for i in range(1,m+1): sm=0 for j in range(len(p)): if p[j][1]!=x: sm+=abs(i-p[j][0]) if sm==b[i-1] and t[i-1]=="#": # print(x,i-1) return i-1 return -1 n=len(s) for i in range(n-1,-1,-1): x=s[i] l=position(b,m,p,x) if l==-1: return -1 t[l]=x # print(p) p.append([l+1,x]) return ''.join(t) t=inp() for _ in range(t): s=str(input()) m=inp() b=line() n=len(s) s=sorted(s) if n>=m: for i in range(n-m+1): z=solve(s[i:i+m],m,b) if z==-1: continue print(z) break ```
instruction
0
36,992
24
73,984
No
output
1
36,992
24
73,985
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp wrote on the board a string s containing only lowercase Latin letters ('a'-'z'). This string is known for you and given in the input. After that, he erased some letters from the string s, and he rewrote the remaining letters in any order. As a result, he got some new string t. You have to find it with some additional information. Suppose that the string t has length m and the characters are numbered from left to right from 1 to m. You are given a sequence of m integers: b_1, b_2, …, b_m, where b_i is the sum of the distances |i-j| from the index i to all such indices j that t_j > t_i (consider that 'a'<'b'<...<'z'). In other words, to calculate b_i, Polycarp finds all such indices j that the index j contains a letter that is later in the alphabet than t_i and sums all the values |i-j|. For example, if t = "abzb", then: * since t_1='a', all other indices contain letters which are later in the alphabet, that is: b_1=|1-2|+|1-3|+|1-4|=1+2+3=6; * since t_2='b', only the index j=3 contains the letter, which is later in the alphabet, that is: b_2=|2-3|=1; * since t_3='z', then there are no indexes j such that t_j>t_i, thus b_3=0; * since t_4='b', only the index j=3 contains the letter, which is later in the alphabet, that is: b_4=|4-3|=1. Thus, if t = "abzb", then b=[6,1,0,1]. Given the string s and the array b, find any possible string t for which the following two requirements are fulfilled simultaneously: * t is obtained from s by erasing some letters (possibly zero) and then writing the rest in any order; * the array, constructed from the string t according to the rules above, equals to the array b specified in the input data. Input The first line contains an integer q (1 ≀ q ≀ 100) β€” the number of test cases in the test. Then q test cases follow. Each test case consists of three lines: * the first line contains string s, which has a length from 1 to 50 and consists of lowercase English letters; * the second line contains positive integer m (1 ≀ m ≀ |s|), where |s| is the length of the string s, and m is the length of the array b; * the third line contains the integers b_1, b_2, ..., b_m (0 ≀ b_i ≀ 1225). It is guaranteed that in each test case an answer exists. Output Output q lines: the k-th of them should contain the answer (string t) to the k-th test case. It is guaranteed that an answer to each test case exists. If there are several answers, output any. Example Input 4 abac 3 2 1 0 abc 1 0 abba 3 1 0 1 ecoosdcefr 10 38 13 24 14 11 5 3 24 17 0 Output aac b aba codeforces Note In the first test case, such strings t are suitable: "aac', "aab". In the second test case, such trings t are suitable: "a", "b", "c". In the third test case, only the string t equals to "aba" is suitable, but the character 'b' can be from the second or third position. Submitted Solution: ``` from collections import deque q = int(input()) def find_zero_idx(): val ,no = [],0 for i in range(m): if arr[i]==0: val.append(i) arr[i]=1e5 no+=1 return val,no def find_char(count,freq): for i in range(25,-1,-1): if freq[i]>=count: alphabet = chr(i+97) freq[i]=-1 return alphabet def solve(): freq = list(bytearray(26)) for c in s: idx = ord(c)-97 freq[idx]+=1 for i in range(26): if freq[i]==0: freq[i]=-1 ans = [None for i in range(m)] filled = 0 while filled<m: zero_idx,total_zero = find_zero_idx() character = find_char(total_zero,freq) for idx in zero_idx: ans[idx]=character filled+=1 for i in range(m): if ans[i]==None: for idx in zero_idx: arr[i]-=abs(i-idx) return "".join(ans) for _ in range(q): s = list(input()) m = int(input()) arr = list(map(int,input().split())) ans = solve() print(ans) ```
instruction
0
36,993
24
73,986
No
output
1
36,993
24
73,987
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp wrote on the board a string s containing only lowercase Latin letters ('a'-'z'). This string is known for you and given in the input. After that, he erased some letters from the string s, and he rewrote the remaining letters in any order. As a result, he got some new string t. You have to find it with some additional information. Suppose that the string t has length m and the characters are numbered from left to right from 1 to m. You are given a sequence of m integers: b_1, b_2, …, b_m, where b_i is the sum of the distances |i-j| from the index i to all such indices j that t_j > t_i (consider that 'a'<'b'<...<'z'). In other words, to calculate b_i, Polycarp finds all such indices j that the index j contains a letter that is later in the alphabet than t_i and sums all the values |i-j|. For example, if t = "abzb", then: * since t_1='a', all other indices contain letters which are later in the alphabet, that is: b_1=|1-2|+|1-3|+|1-4|=1+2+3=6; * since t_2='b', only the index j=3 contains the letter, which is later in the alphabet, that is: b_2=|2-3|=1; * since t_3='z', then there are no indexes j such that t_j>t_i, thus b_3=0; * since t_4='b', only the index j=3 contains the letter, which is later in the alphabet, that is: b_4=|4-3|=1. Thus, if t = "abzb", then b=[6,1,0,1]. Given the string s and the array b, find any possible string t for which the following two requirements are fulfilled simultaneously: * t is obtained from s by erasing some letters (possibly zero) and then writing the rest in any order; * the array, constructed from the string t according to the rules above, equals to the array b specified in the input data. Input The first line contains an integer q (1 ≀ q ≀ 100) β€” the number of test cases in the test. Then q test cases follow. Each test case consists of three lines: * the first line contains string s, which has a length from 1 to 50 and consists of lowercase English letters; * the second line contains positive integer m (1 ≀ m ≀ |s|), where |s| is the length of the string s, and m is the length of the array b; * the third line contains the integers b_1, b_2, ..., b_m (0 ≀ b_i ≀ 1225). It is guaranteed that in each test case an answer exists. Output Output q lines: the k-th of them should contain the answer (string t) to the k-th test case. It is guaranteed that an answer to each test case exists. If there are several answers, output any. Example Input 4 abac 3 2 1 0 abc 1 0 abba 3 1 0 1 ecoosdcefr 10 38 13 24 14 11 5 3 24 17 0 Output aac b aba codeforces Note In the first test case, such strings t are suitable: "aac', "aab". In the second test case, such trings t are suitable: "a", "b", "c". In the third test case, only the string t equals to "aba" is suitable, but the character 'b' can be from the second or third position. Submitted Solution: ``` def counter(l,a): count=0 for i in range(len(l)): if l[i]==a: count+=1 return count t=int(input()) for _ in range(t): s=list(input()) n=len(s) m=int(input()) b=list(map(int,input().split())) t=['0']*m while(True): z=[] for i in range(m): if b[i]==0: z.append(i) maxx=max(s) if counter(s,maxx)>=len(z): for i in z: t[i]=maxx for j in range(m): if j not in z: b[j]-=abs(i-j) b[i]=-1 for i in range(n): if s[i]==maxx: s[i]='0' else: for i in range(n): if s[i]==maxx: s[i]='0' if b==[-1]*m or s==['0']*n: break print(*t) ```
instruction
0
36,994
24
73,988
No
output
1
36,994
24
73,989
Provide a correct Python 3 solution for this coding contest problem. Polycarp has a strict daily schedule. He has n alarms set for each day, and the i-th alarm rings each day at the same time during exactly one minute. Determine the longest time segment when Polycarp can sleep, i. e. no alarm rings in that period. It is possible that Polycarp begins to sleep in one day, and wakes up in another. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of alarms. Each of the next n lines contains a description of one alarm. Each description has a format "hh:mm", where hh is the hour when the alarm rings, and mm is the minute of that hour when the alarm rings. The number of hours is between 0 and 23, and the number of minutes is between 0 and 59. All alarm times are distinct. The order of the alarms is arbitrary. Each alarm starts ringing in the beginning of the corresponding minute and rings for exactly one minute (i. e. stops ringing in the beginning of the next minute). Polycarp can start sleeping instantly when no alarm is ringing, and he wakes up at the moment when some alarm starts ringing. Output Print a line in format "hh:mm", denoting the maximum time Polycarp can sleep continuously. hh denotes the number of hours, and mm denotes the number of minutes. The number of minutes should be between 0 and 59. Look through examples to understand the format better. Examples Input 1 05:43 Output 23:59 Input 4 22:00 03:21 16:03 09:59 Output 06:37 Note In the first example there is only one alarm which rings during one minute of a day, and then rings again on the next day, 23 hours and 59 minutes later. Polycarp can sleep all this time.
instruction
0
37,443
24
74,886
"Correct Solution: ``` n = int(input()) a = [] for i in range(n): m, h = input().split(':') m = int(m) h = int(h) a.append(m * 60 + h) a.sort() ans = 0 for i in range(n): ans = max(ans, a[i] - a[i - 1] - 1) ans = max(ans, 1440 + a[0] - a[-1] - 1) if n == 1: print('23:59') else: hh = ans // 60 mm = ans % 60 hh = str(hh) mm = str(mm) if len(hh) == 1: hh = '0' + hh if len(mm) == 1: mm = '0' + mm print(hh + ':' + mm) ```
output
1
37,443
24
74,887
Provide a correct Python 3 solution for this coding contest problem. Polycarp has a strict daily schedule. He has n alarms set for each day, and the i-th alarm rings each day at the same time during exactly one minute. Determine the longest time segment when Polycarp can sleep, i. e. no alarm rings in that period. It is possible that Polycarp begins to sleep in one day, and wakes up in another. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of alarms. Each of the next n lines contains a description of one alarm. Each description has a format "hh:mm", where hh is the hour when the alarm rings, and mm is the minute of that hour when the alarm rings. The number of hours is between 0 and 23, and the number of minutes is between 0 and 59. All alarm times are distinct. The order of the alarms is arbitrary. Each alarm starts ringing in the beginning of the corresponding minute and rings for exactly one minute (i. e. stops ringing in the beginning of the next minute). Polycarp can start sleeping instantly when no alarm is ringing, and he wakes up at the moment when some alarm starts ringing. Output Print a line in format "hh:mm", denoting the maximum time Polycarp can sleep continuously. hh denotes the number of hours, and mm denotes the number of minutes. The number of minutes should be between 0 and 59. Look through examples to understand the format better. Examples Input 1 05:43 Output 23:59 Input 4 22:00 03:21 16:03 09:59 Output 06:37 Note In the first example there is only one alarm which rings during one minute of a day, and then rings again on the next day, 23 hours and 59 minutes later. Polycarp can sleep all this time.
instruction
0
37,444
24
74,888
"Correct Solution: ``` n = int(input()) arr = [] for i in range(n): h, m = map(int, input().split(':')); cur = h * 60 + m; arr.append(cur) arr.sort() arr.append(24 * 60 + arr[0]) maxx = 0 for i in range(1, len(arr)): maxx = max(maxx, arr[i] - arr[i - 1] - 1) m = maxx % 60 h = maxx // 60 if (h < 10): print(0, end =''); print(h, ':', sep = '', end = '') if (m < 10): print(0, end = '') print(m) ```
output
1
37,444
24
74,889
Provide a correct Python 3 solution for this coding contest problem. Polycarp has a strict daily schedule. He has n alarms set for each day, and the i-th alarm rings each day at the same time during exactly one minute. Determine the longest time segment when Polycarp can sleep, i. e. no alarm rings in that period. It is possible that Polycarp begins to sleep in one day, and wakes up in another. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of alarms. Each of the next n lines contains a description of one alarm. Each description has a format "hh:mm", where hh is the hour when the alarm rings, and mm is the minute of that hour when the alarm rings. The number of hours is between 0 and 23, and the number of minutes is between 0 and 59. All alarm times are distinct. The order of the alarms is arbitrary. Each alarm starts ringing in the beginning of the corresponding minute and rings for exactly one minute (i. e. stops ringing in the beginning of the next minute). Polycarp can start sleeping instantly when no alarm is ringing, and he wakes up at the moment when some alarm starts ringing. Output Print a line in format "hh:mm", denoting the maximum time Polycarp can sleep continuously. hh denotes the number of hours, and mm denotes the number of minutes. The number of minutes should be between 0 and 59. Look through examples to understand the format better. Examples Input 1 05:43 Output 23:59 Input 4 22:00 03:21 16:03 09:59 Output 06:37 Note In the first example there is only one alarm which rings during one minute of a day, and then rings again on the next day, 23 hours and 59 minutes later. Polycarp can sleep all this time.
instruction
0
37,445
24
74,890
"Correct Solution: ``` import sys n = int(input()) lst = [] p = -1 mx = 0 while n > 0: str = input() x = 60 * (10 * int(str[0]) + int(str[1])) + 10 * int(str[3]) + int(str[4]) lst.append(x) n -= 1 lst.sort() for i in lst: if p >= 0: mx = max(mx, i - p) p = i x = lst[0] y = lst[-1] mx = max(mx, x + 1440 - y) mx -= 1 if mx // 60 < 10: print(0, end = '') print(mx // 60, end = '') print(':', end = '') if mx % 60 < 10: print(0, end = '') print(mx % 60, end = '') ```
output
1
37,445
24
74,891
Provide a correct Python 3 solution for this coding contest problem. Polycarp has a strict daily schedule. He has n alarms set for each day, and the i-th alarm rings each day at the same time during exactly one minute. Determine the longest time segment when Polycarp can sleep, i. e. no alarm rings in that period. It is possible that Polycarp begins to sleep in one day, and wakes up in another. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of alarms. Each of the next n lines contains a description of one alarm. Each description has a format "hh:mm", where hh is the hour when the alarm rings, and mm is the minute of that hour when the alarm rings. The number of hours is between 0 and 23, and the number of minutes is between 0 and 59. All alarm times are distinct. The order of the alarms is arbitrary. Each alarm starts ringing in the beginning of the corresponding minute and rings for exactly one minute (i. e. stops ringing in the beginning of the next minute). Polycarp can start sleeping instantly when no alarm is ringing, and he wakes up at the moment when some alarm starts ringing. Output Print a line in format "hh:mm", denoting the maximum time Polycarp can sleep continuously. hh denotes the number of hours, and mm denotes the number of minutes. The number of minutes should be between 0 and 59. Look through examples to understand the format better. Examples Input 1 05:43 Output 23:59 Input 4 22:00 03:21 16:03 09:59 Output 06:37 Note In the first example there is only one alarm which rings during one minute of a day, and then rings again on the next day, 23 hours and 59 minutes later. Polycarp can sleep all this time.
instruction
0
37,446
24
74,892
"Correct Solution: ``` n = int(input()) a = [] for i in range(n): h, m = map(int, input().split(":")) a.append((h + 24) * 60 + m) a.append(h * 60 + m) a.sort() j = 0 s = 0 ans = 0 for i in range(0, 48 * 60): if (j < 2 * n and a[j] == i): ans = max(ans, s) s = 0 j += 1 continue else: s += 1 h = ans // 60 m = ans % 60 hans = "" mans = "" if h < 10: hans = "0" + str(h) else: hans = str(h) if m < 10: mans = "0" + str(m) else: mans = str(m) print(hans + ":" + mans) ```
output
1
37,446
24
74,893
Provide a correct Python 3 solution for this coding contest problem. Polycarp has a strict daily schedule. He has n alarms set for each day, and the i-th alarm rings each day at the same time during exactly one minute. Determine the longest time segment when Polycarp can sleep, i. e. no alarm rings in that period. It is possible that Polycarp begins to sleep in one day, and wakes up in another. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of alarms. Each of the next n lines contains a description of one alarm. Each description has a format "hh:mm", where hh is the hour when the alarm rings, and mm is the minute of that hour when the alarm rings. The number of hours is between 0 and 23, and the number of minutes is between 0 and 59. All alarm times are distinct. The order of the alarms is arbitrary. Each alarm starts ringing in the beginning of the corresponding minute and rings for exactly one minute (i. e. stops ringing in the beginning of the next minute). Polycarp can start sleeping instantly when no alarm is ringing, and he wakes up at the moment when some alarm starts ringing. Output Print a line in format "hh:mm", denoting the maximum time Polycarp can sleep continuously. hh denotes the number of hours, and mm denotes the number of minutes. The number of minutes should be between 0 and 59. Look through examples to understand the format better. Examples Input 1 05:43 Output 23:59 Input 4 22:00 03:21 16:03 09:59 Output 06:37 Note In the first example there is only one alarm which rings during one minute of a day, and then rings again on the next day, 23 hours and 59 minutes later. Polycarp can sleep all this time.
instruction
0
37,447
24
74,894
"Correct Solution: ``` n = int(input()) A = [] for i in range(n): s = input() h = s[:2] m = s[3:] A.append((int(h), int(m))) md = -12341234 A = sorted(A) for i in range(n - 1): a, b = A[i] c, d = A[i + 1] g = (c - a) * 60 if(b > d): g += 60 - b + d g -= 60 else: g += d - b if(g > md): md = g a, b = A[0] c, d = A[n - 1] g = (24 - c + a)*60 g += 60 - d + b g -= 60 if(g > md): md = g md -= 1 if(md//60 < 10): print('0', sep = '', end = ''); print(md//60, ':', sep ='', end = '') if(md % 60 < 10): print('0', sep = '', end = ''); print(md % 60) ```
output
1
37,447
24
74,895
Provide a correct Python 3 solution for this coding contest problem. Polycarp has a strict daily schedule. He has n alarms set for each day, and the i-th alarm rings each day at the same time during exactly one minute. Determine the longest time segment when Polycarp can sleep, i. e. no alarm rings in that period. It is possible that Polycarp begins to sleep in one day, and wakes up in another. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of alarms. Each of the next n lines contains a description of one alarm. Each description has a format "hh:mm", where hh is the hour when the alarm rings, and mm is the minute of that hour when the alarm rings. The number of hours is between 0 and 23, and the number of minutes is between 0 and 59. All alarm times are distinct. The order of the alarms is arbitrary. Each alarm starts ringing in the beginning of the corresponding minute and rings for exactly one minute (i. e. stops ringing in the beginning of the next minute). Polycarp can start sleeping instantly when no alarm is ringing, and he wakes up at the moment when some alarm starts ringing. Output Print a line in format "hh:mm", denoting the maximum time Polycarp can sleep continuously. hh denotes the number of hours, and mm denotes the number of minutes. The number of minutes should be between 0 and 59. Look through examples to understand the format better. Examples Input 1 05:43 Output 23:59 Input 4 22:00 03:21 16:03 09:59 Output 06:37 Note In the first example there is only one alarm which rings during one minute of a day, and then rings again on the next day, 23 hours and 59 minutes later. Polycarp can sleep all this time.
instruction
0
37,448
24
74,896
"Correct Solution: ``` b = int(input()) times = [] line = "" a = b while a > 0: a-=1 curr_time = input().split(":") times.append(int(curr_time[0])*60+int(curr_time[1])) times.sort() times.append(times[0]+24*60) max_delta = 0 if times[0] > max_delta: max_delta = times[0] for it in range(1,b+1): if times[it] - times[it - 1] > max_delta: max_delta = times[it] - times[it-1] - 1 if max_delta // 60 < 10: first = "0"+str(max_delta // 60) else: first = str(max_delta // 60) if max_delta - 60 * (max_delta // 60) < 10: second = "0"+str(max_delta - 60 * (max_delta // 60)) else: second = str(max_delta - 60 * (max_delta // 60)) print(first + ":" + second) ```
output
1
37,448
24
74,897
Provide a correct Python 3 solution for this coding contest problem. Polycarp has a strict daily schedule. He has n alarms set for each day, and the i-th alarm rings each day at the same time during exactly one minute. Determine the longest time segment when Polycarp can sleep, i. e. no alarm rings in that period. It is possible that Polycarp begins to sleep in one day, and wakes up in another. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of alarms. Each of the next n lines contains a description of one alarm. Each description has a format "hh:mm", where hh is the hour when the alarm rings, and mm is the minute of that hour when the alarm rings. The number of hours is between 0 and 23, and the number of minutes is between 0 and 59. All alarm times are distinct. The order of the alarms is arbitrary. Each alarm starts ringing in the beginning of the corresponding minute and rings for exactly one minute (i. e. stops ringing in the beginning of the next minute). Polycarp can start sleeping instantly when no alarm is ringing, and he wakes up at the moment when some alarm starts ringing. Output Print a line in format "hh:mm", denoting the maximum time Polycarp can sleep continuously. hh denotes the number of hours, and mm denotes the number of minutes. The number of minutes should be between 0 and 59. Look through examples to understand the format better. Examples Input 1 05:43 Output 23:59 Input 4 22:00 03:21 16:03 09:59 Output 06:37 Note In the first example there is only one alarm which rings during one minute of a day, and then rings again on the next day, 23 hours and 59 minutes later. Polycarp can sleep all this time.
instruction
0
37,449
24
74,898
"Correct Solution: ``` def f(x): if x < 10: return "0" + str(x) return str(x) n = int(input()) times = [] for i in range(0, n): s = input() times.append(60 * int(s[0:2]) + int(s[3:5])) times.append(60 * 24 + 60 * int(s[0:2]) + int(s[3:5])) times.sort() ans = times[1] - times[0] - 1 for i in range(1, len(times)): ans = max(ans , times[i] - times[i - 1] - 1) print("{}:{}".format(f(ans // 60), f(ans % 60))) ```
output
1
37,449
24
74,899
Provide a correct Python 3 solution for this coding contest problem. Polycarp has a strict daily schedule. He has n alarms set for each day, and the i-th alarm rings each day at the same time during exactly one minute. Determine the longest time segment when Polycarp can sleep, i. e. no alarm rings in that period. It is possible that Polycarp begins to sleep in one day, and wakes up in another. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of alarms. Each of the next n lines contains a description of one alarm. Each description has a format "hh:mm", where hh is the hour when the alarm rings, and mm is the minute of that hour when the alarm rings. The number of hours is between 0 and 23, and the number of minutes is between 0 and 59. All alarm times are distinct. The order of the alarms is arbitrary. Each alarm starts ringing in the beginning of the corresponding minute and rings for exactly one minute (i. e. stops ringing in the beginning of the next minute). Polycarp can start sleeping instantly when no alarm is ringing, and he wakes up at the moment when some alarm starts ringing. Output Print a line in format "hh:mm", denoting the maximum time Polycarp can sleep continuously. hh denotes the number of hours, and mm denotes the number of minutes. The number of minutes should be between 0 and 59. Look through examples to understand the format better. Examples Input 1 05:43 Output 23:59 Input 4 22:00 03:21 16:03 09:59 Output 06:37 Note In the first example there is only one alarm which rings during one minute of a day, and then rings again on the next day, 23 hours and 59 minutes later. Polycarp can sleep all this time.
instruction
0
37,450
24
74,900
"Correct Solution: ``` n = int(input()) a = [] def mem(kek): return (int(kek[0])*10 + int(kek[1]))*60 + int(kek[3])*10 + int(kek[4]) def lol(kek): h = str(kek//60) m = str(kek%60) ans = "" if (len(h)<2): ans+="0" ans+=h ans+=":" if (len(m)<2): ans+="0" ans+=m return ans delt = 60*24 for i in range(n): st = input() a.append(mem(st)) a.append(mem(st)+delt ) a.append(mem(st)+2*delt) a = sorted(a) ans = 0 for i in range(1,len(a)): ans = max(ans, a[i] - a[i-1] - 1) print(lol(ans)) ```
output
1
37,450
24
74,901
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp has a strict daily schedule. He has n alarms set for each day, and the i-th alarm rings each day at the same time during exactly one minute. Determine the longest time segment when Polycarp can sleep, i. e. no alarm rings in that period. It is possible that Polycarp begins to sleep in one day, and wakes up in another. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of alarms. Each of the next n lines contains a description of one alarm. Each description has a format "hh:mm", where hh is the hour when the alarm rings, and mm is the minute of that hour when the alarm rings. The number of hours is between 0 and 23, and the number of minutes is between 0 and 59. All alarm times are distinct. The order of the alarms is arbitrary. Each alarm starts ringing in the beginning of the corresponding minute and rings for exactly one minute (i. e. stops ringing in the beginning of the next minute). Polycarp can start sleeping instantly when no alarm is ringing, and he wakes up at the moment when some alarm starts ringing. Output Print a line in format "hh:mm", denoting the maximum time Polycarp can sleep continuously. hh denotes the number of hours, and mm denotes the number of minutes. The number of minutes should be between 0 and 59. Look through examples to understand the format better. Examples Input 1 05:43 Output 23:59 Input 4 22:00 03:21 16:03 09:59 Output 06:37 Note In the first example there is only one alarm which rings during one minute of a day, and then rings again on the next day, 23 hours and 59 minutes later. Polycarp can sleep all this time. Submitted Solution: ``` n = int(input()) times = [] for _ in range(n): time = str(input()) times.append((int(time[:2]), int(time[3:]))) times.sort() def to_minutes(a): return 60*a[0] + a[1] def to_hours(a): return (a // 60, a % 60) def pad(a): return ('0' if a < 10 else '') + str(a) longest = 0 for i in range(1, n): longest = max(longest, to_minutes(times[i]) - to_minutes(times[i - 1])) longest = max(longest, 60*24 + to_minutes(times[0]) - to_minutes(times[n - 1])) longest -= 1 hours, minutes = to_hours(longest) print(pad(hours), ':', pad(minutes), sep='') ```
instruction
0
37,451
24
74,902
Yes
output
1
37,451
24
74,903
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp has a strict daily schedule. He has n alarms set for each day, and the i-th alarm rings each day at the same time during exactly one minute. Determine the longest time segment when Polycarp can sleep, i. e. no alarm rings in that period. It is possible that Polycarp begins to sleep in one day, and wakes up in another. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of alarms. Each of the next n lines contains a description of one alarm. Each description has a format "hh:mm", where hh is the hour when the alarm rings, and mm is the minute of that hour when the alarm rings. The number of hours is between 0 and 23, and the number of minutes is between 0 and 59. All alarm times are distinct. The order of the alarms is arbitrary. Each alarm starts ringing in the beginning of the corresponding minute and rings for exactly one minute (i. e. stops ringing in the beginning of the next minute). Polycarp can start sleeping instantly when no alarm is ringing, and he wakes up at the moment when some alarm starts ringing. Output Print a line in format "hh:mm", denoting the maximum time Polycarp can sleep continuously. hh denotes the number of hours, and mm denotes the number of minutes. The number of minutes should be between 0 and 59. Look through examples to understand the format better. Examples Input 1 05:43 Output 23:59 Input 4 22:00 03:21 16:03 09:59 Output 06:37 Note In the first example there is only one alarm which rings during one minute of a day, and then rings again on the next day, 23 hours and 59 minutes later. Polycarp can sleep all this time. Submitted Solution: ``` n = int(input()) times = [0] * 2880 for _ in range(n): hh, mm = map(int, input().split(':')) t = hh * 60 + mm times[t] = 1 times[t + 1440] = 1 i = 0 res = -1 while i < 1440: for j in range(i, i + 1440): if times[j] == 1: break res = max(res, j - i) i = j + 1 hh, mm = divmod(res, 60) print('{:02d}:{:02d}'.format(hh, mm)) ```
instruction
0
37,452
24
74,904
Yes
output
1
37,452
24
74,905
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp has a strict daily schedule. He has n alarms set for each day, and the i-th alarm rings each day at the same time during exactly one minute. Determine the longest time segment when Polycarp can sleep, i. e. no alarm rings in that period. It is possible that Polycarp begins to sleep in one day, and wakes up in another. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of alarms. Each of the next n lines contains a description of one alarm. Each description has a format "hh:mm", where hh is the hour when the alarm rings, and mm is the minute of that hour when the alarm rings. The number of hours is between 0 and 23, and the number of minutes is between 0 and 59. All alarm times are distinct. The order of the alarms is arbitrary. Each alarm starts ringing in the beginning of the corresponding minute and rings for exactly one minute (i. e. stops ringing in the beginning of the next minute). Polycarp can start sleeping instantly when no alarm is ringing, and he wakes up at the moment when some alarm starts ringing. Output Print a line in format "hh:mm", denoting the maximum time Polycarp can sleep continuously. hh denotes the number of hours, and mm denotes the number of minutes. The number of minutes should be between 0 and 59. Look through examples to understand the format better. Examples Input 1 05:43 Output 23:59 Input 4 22:00 03:21 16:03 09:59 Output 06:37 Note In the first example there is only one alarm which rings during one minute of a day, and then rings again on the next day, 23 hours and 59 minutes later. Polycarp can sleep all this time. Submitted Solution: ``` n = int(input()) alarms = [] for i in range(n): h, m = map(int, input().split(':')) t = h * 60 + m alarms.append(t) alarms.sort() # print(alarms) alarms.append(alarms[0] + 24 * 60) mx = -1 for i in range(1, len(alarms)): if (mx < alarms[i] - alarms[i - 1]): mx = alarms[i] - alarms[i - 1] mx -= 1 print('{:02d}:{:02d}'.format(mx // 60, mx % 60)) ```
instruction
0
37,453
24
74,906
Yes
output
1
37,453
24
74,907
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp has a strict daily schedule. He has n alarms set for each day, and the i-th alarm rings each day at the same time during exactly one minute. Determine the longest time segment when Polycarp can sleep, i. e. no alarm rings in that period. It is possible that Polycarp begins to sleep in one day, and wakes up in another. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of alarms. Each of the next n lines contains a description of one alarm. Each description has a format "hh:mm", where hh is the hour when the alarm rings, and mm is the minute of that hour when the alarm rings. The number of hours is between 0 and 23, and the number of minutes is between 0 and 59. All alarm times are distinct. The order of the alarms is arbitrary. Each alarm starts ringing in the beginning of the corresponding minute and rings for exactly one minute (i. e. stops ringing in the beginning of the next minute). Polycarp can start sleeping instantly when no alarm is ringing, and he wakes up at the moment when some alarm starts ringing. Output Print a line in format "hh:mm", denoting the maximum time Polycarp can sleep continuously. hh denotes the number of hours, and mm denotes the number of minutes. The number of minutes should be between 0 and 59. Look through examples to understand the format better. Examples Input 1 05:43 Output 23:59 Input 4 22:00 03:21 16:03 09:59 Output 06:37 Note In the first example there is only one alarm which rings during one minute of a day, and then rings again on the next day, 23 hours and 59 minutes later. Polycarp can sleep all this time. Submitted Solution: ``` n = int(input()) p = list() for i in range(0, n): g, o = map(int, input().split(':')) p.append(g * 60 + o) p.sort() answ = 1440 - p[n - 1] + p[0] for i in range(1, n): answ = max(answ, p[i] - p[i - 1]) k = str() answ = answ - 1 if (answ // 60 < 10): k = k + "0" + str(answ // 60) + ":" else: k = k + str(answ // 60) + ":" if (answ % 60 < 10): k = k + "0" + str(answ % 60) else: k = k + str(answ % 60) print(k) ```
instruction
0
37,454
24
74,908
Yes
output
1
37,454
24
74,909
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp has a strict daily schedule. He has n alarms set for each day, and the i-th alarm rings each day at the same time during exactly one minute. Determine the longest time segment when Polycarp can sleep, i. e. no alarm rings in that period. It is possible that Polycarp begins to sleep in one day, and wakes up in another. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of alarms. Each of the next n lines contains a description of one alarm. Each description has a format "hh:mm", where hh is the hour when the alarm rings, and mm is the minute of that hour when the alarm rings. The number of hours is between 0 and 23, and the number of minutes is between 0 and 59. All alarm times are distinct. The order of the alarms is arbitrary. Each alarm starts ringing in the beginning of the corresponding minute and rings for exactly one minute (i. e. stops ringing in the beginning of the next minute). Polycarp can start sleeping instantly when no alarm is ringing, and he wakes up at the moment when some alarm starts ringing. Output Print a line in format "hh:mm", denoting the maximum time Polycarp can sleep continuously. hh denotes the number of hours, and mm denotes the number of minutes. The number of minutes should be between 0 and 59. Look through examples to understand the format better. Examples Input 1 05:43 Output 23:59 Input 4 22:00 03:21 16:03 09:59 Output 06:37 Note In the first example there is only one alarm which rings during one minute of a day, and then rings again on the next day, 23 hours and 59 minutes later. Polycarp can sleep all this time. Submitted Solution: ``` def rs(t1, t2): res = [0, 0] if t1[1] - t2[1] < 0: res[1] = t1[1] - t2[1] + 60 - 1 res[0] -= 1 else: res[1] = t1[1] - t2[1] - 1 res[0] += t1[0] - t2[0] return tuple(res) def check(t1, t2, maxi): tmp = rs(t1, t2) if tmp[0] > maxi[0]: return tmp elif tmp[0] == maxi[0]: if tmp[1] > maxi[1]: return tmp return maxi def to_str(item): if item < 10: return '0' + str(item) else: return str(item) n = int(input()) clocks = [] for i in range(n): clocks.append(tuple(map(int, input().split(':')))) clocks = sorted(clocks, key=lambda item: (item[0], item[1])) if n == 1: print('23:59') maxi = rs((clocks[0][0] + 24, clocks[0][1]), clocks[-1]) i = 0 while i < len(clocks) - 1: maxi = check(clocks[i + 1], clocks[i], maxi) i += 1 print(":".join(map(to_str, maxi))) ```
instruction
0
37,455
24
74,910
No
output
1
37,455
24
74,911
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp has a strict daily schedule. He has n alarms set for each day, and the i-th alarm rings each day at the same time during exactly one minute. Determine the longest time segment when Polycarp can sleep, i. e. no alarm rings in that period. It is possible that Polycarp begins to sleep in one day, and wakes up in another. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of alarms. Each of the next n lines contains a description of one alarm. Each description has a format "hh:mm", where hh is the hour when the alarm rings, and mm is the minute of that hour when the alarm rings. The number of hours is between 0 and 23, and the number of minutes is between 0 and 59. All alarm times are distinct. The order of the alarms is arbitrary. Each alarm starts ringing in the beginning of the corresponding minute and rings for exactly one minute (i. e. stops ringing in the beginning of the next minute). Polycarp can start sleeping instantly when no alarm is ringing, and he wakes up at the moment when some alarm starts ringing. Output Print a line in format "hh:mm", denoting the maximum time Polycarp can sleep continuously. hh denotes the number of hours, and mm denotes the number of minutes. The number of minutes should be between 0 and 59. Look through examples to understand the format better. Examples Input 1 05:43 Output 23:59 Input 4 22:00 03:21 16:03 09:59 Output 06:37 Note In the first example there is only one alarm which rings during one minute of a day, and then rings again on the next day, 23 hours and 59 minutes later. Polycarp can sleep all this time. Submitted Solution: ``` n = int(input()) A = [] for i in range(n): s = input() h = s[:2] m = s[3:] A.append((int(h), int(m))) md = -12341234 A = sorted(A) for i in range(n - 1): a, b = A[i] c, d = A[i + 1] g = (c - a) * 60 if(b > d): g += 60 - b + d g -= 60 else: g += d - b if(g > md): md = g a, b = A[0] c, d = A[n - 1] g = (24 - c + a)*60 g += 60 - d + b if(g > md): md = g md -= 1 if(md//60 < 10): print('0', sep = '', end = ''); print(md//60, ':', sep ='', end = '') if(md % 60 < 10): print('0', sep = '', end = ''); print(md % 60) ```
instruction
0
37,456
24
74,912
No
output
1
37,456
24
74,913
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp has a strict daily schedule. He has n alarms set for each day, and the i-th alarm rings each day at the same time during exactly one minute. Determine the longest time segment when Polycarp can sleep, i. e. no alarm rings in that period. It is possible that Polycarp begins to sleep in one day, and wakes up in another. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of alarms. Each of the next n lines contains a description of one alarm. Each description has a format "hh:mm", where hh is the hour when the alarm rings, and mm is the minute of that hour when the alarm rings. The number of hours is between 0 and 23, and the number of minutes is between 0 and 59. All alarm times are distinct. The order of the alarms is arbitrary. Each alarm starts ringing in the beginning of the corresponding minute and rings for exactly one minute (i. e. stops ringing in the beginning of the next minute). Polycarp can start sleeping instantly when no alarm is ringing, and he wakes up at the moment when some alarm starts ringing. Output Print a line in format "hh:mm", denoting the maximum time Polycarp can sleep continuously. hh denotes the number of hours, and mm denotes the number of minutes. The number of minutes should be between 0 and 59. Look through examples to understand the format better. Examples Input 1 05:43 Output 23:59 Input 4 22:00 03:21 16:03 09:59 Output 06:37 Note In the first example there is only one alarm which rings during one minute of a day, and then rings again on the next day, 23 hours and 59 minutes later. Polycarp can sleep all this time. Submitted Solution: ``` class Line: def __init__(self, l, r): self.l = l self.r = r self.left = None self.right = None def max(self): if not self.left: return self.r - self.l else: return max(self.left.max(), self.right.max()) def split(self, x): if not self.left: self.left = Line(self.l, x) self.right = Line(x + 1, self.r) else: if self.left.l < x and self.left.r > x: self.left.split(x) elif self.right.l < x and self.right.r > x: self.right.split(x) n = int(input()) arr = [] for i in range(n): s = input().split(':') m = int(s[0]) * 60 + int(s[1]) arr.append(m) arr.sort() a = Line(1, 60*24 + arr[0]) for i in arr: a.split(i) m = a.max() h = m // 60 m = m % 60 print(h, ':', m, sep='') ```
instruction
0
37,457
24
74,914
No
output
1
37,457
24
74,915
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp has a strict daily schedule. He has n alarms set for each day, and the i-th alarm rings each day at the same time during exactly one minute. Determine the longest time segment when Polycarp can sleep, i. e. no alarm rings in that period. It is possible that Polycarp begins to sleep in one day, and wakes up in another. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of alarms. Each of the next n lines contains a description of one alarm. Each description has a format "hh:mm", where hh is the hour when the alarm rings, and mm is the minute of that hour when the alarm rings. The number of hours is between 0 and 23, and the number of minutes is between 0 and 59. All alarm times are distinct. The order of the alarms is arbitrary. Each alarm starts ringing in the beginning of the corresponding minute and rings for exactly one minute (i. e. stops ringing in the beginning of the next minute). Polycarp can start sleeping instantly when no alarm is ringing, and he wakes up at the moment when some alarm starts ringing. Output Print a line in format "hh:mm", denoting the maximum time Polycarp can sleep continuously. hh denotes the number of hours, and mm denotes the number of minutes. The number of minutes should be between 0 and 59. Look through examples to understand the format better. Examples Input 1 05:43 Output 23:59 Input 4 22:00 03:21 16:03 09:59 Output 06:37 Note In the first example there is only one alarm which rings during one minute of a day, and then rings again on the next day, 23 hours and 59 minutes later. Polycarp can sleep all this time. Submitted Solution: ``` from datetime import datetime from datetime import timedelta n = int(input()) time = sorted([input() for i in range(n)]) FMT = '%H:%M' max_time = timedelta.min for i in range(n - 1): t1 = datetime.strptime(time[i], FMT) t2 = datetime.strptime(time[i + 1], FMT) max_time = max(max_time, t2 - t1 - timedelta(seconds=60)) first = datetime.strptime(time[0], FMT) last = datetime.strptime(time[n-1], FMT) max_time = max(max_time, first - last + timedelta(days=1) - timedelta(seconds=60)) print(':'.join(str(max_time).split(':')[:2])) ```
instruction
0
37,458
24
74,916
No
output
1
37,458
24
74,917
Provide tags and a correct Python 3 solution for this coding contest problem. The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an n Γ— m rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and marked there the districts where the first three robberies had been committed as asterisks. Deduction tells Polycarpus that the fourth robbery will be committed in such district, that all four robbed districts will form the vertices of some rectangle, parallel to the sides of the map. Polycarpus is good at deduction but he's hopeless at math. So he asked you to find the district where the fourth robbery will be committed. Input The first line contains two space-separated integers n and m (2 ≀ n, m ≀ 100) β€” the number of rows and columns in the table, correspondingly. Each of the next n lines contains m characters β€” the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if the corresponding district has been robbed. Otherwise, it equals ".". It is guaranteed that the map has exactly three characters "*" and we can always find the fourth district that meets the problem requirements. Output Print two integers β€” the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. Examples Input 3 2 .* .. ** Output 1 1 Input 3 3 *.* *.. ... Output 2 3
instruction
0
38,933
24
77,866
Tags: brute force, geometry, implementation Correct Solution: ``` #import math n,m=map(int,input().split()) l=[] for i in range(n): s=list(input()) #print(s) k=s.count('*') c=0 for _ in range(k): if '*' in s: j=s.index('*') l.append([i,j+c]) s=s[:j]+s[j+1:] c=c+1 #print(l) xl=[] yl=[] x=999 y=999 for i,j in l: xl.append(i) yl.append(j) for i in (xl): c=xl.count(i) if(c==1): x=i+1 break #print('yl',yl) for i in (yl): c=yl.count(i) if(c==1): y=i+1 break print(x,y) ```
output
1
38,933
24
77,867
Provide tags and a correct Python 3 solution for this coding contest problem. The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an n Γ— m rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and marked there the districts where the first three robberies had been committed as asterisks. Deduction tells Polycarpus that the fourth robbery will be committed in such district, that all four robbed districts will form the vertices of some rectangle, parallel to the sides of the map. Polycarpus is good at deduction but he's hopeless at math. So he asked you to find the district where the fourth robbery will be committed. Input The first line contains two space-separated integers n and m (2 ≀ n, m ≀ 100) β€” the number of rows and columns in the table, correspondingly. Each of the next n lines contains m characters β€” the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if the corresponding district has been robbed. Otherwise, it equals ".". It is guaranteed that the map has exactly three characters "*" and we can always find the fourth district that meets the problem requirements. Output Print two integers β€” the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. Examples Input 3 2 .* .. ** Output 1 1 Input 3 3 *.* *.. ... Output 2 3
instruction
0
38,934
24
77,868
Tags: brute force, geometry, implementation Correct Solution: ``` nm = input().split() n = int(nm[0]) m = int(nm[1]) k = 0 for j in range(n): s = input() for i in range(m): if s[i] == '*': k += 1 if k == 1: pos1 = [i+1, j+1] elif k == 2: pos2 = [i+1, j+1] else: pos3 = [i+1, j+1] if pos1[1] == pos2[1]: pos4 = [pos1[0] + pos2[0] - pos3[0], pos3[1]] else: pos4 = [pos2[0]+pos3[0]-pos1[0], pos1[1]] print(pos4[1], pos4[0]) ```
output
1
38,934
24
77,869
Provide tags and a correct Python 3 solution for this coding contest problem. The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an n Γ— m rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and marked there the districts where the first three robberies had been committed as asterisks. Deduction tells Polycarpus that the fourth robbery will be committed in such district, that all four robbed districts will form the vertices of some rectangle, parallel to the sides of the map. Polycarpus is good at deduction but he's hopeless at math. So he asked you to find the district where the fourth robbery will be committed. Input The first line contains two space-separated integers n and m (2 ≀ n, m ≀ 100) β€” the number of rows and columns in the table, correspondingly. Each of the next n lines contains m characters β€” the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if the corresponding district has been robbed. Otherwise, it equals ".". It is guaranteed that the map has exactly three characters "*" and we can always find the fourth district that meets the problem requirements. Output Print two integers β€” the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. Examples Input 3 2 .* .. ** Output 1 1 Input 3 3 *.* *.. ... Output 2 3
instruction
0
38,935
24
77,870
Tags: brute force, geometry, implementation Correct Solution: ``` n, m = map(int, input().split()) l = [input() for i in range(n)] for i in range(n): if l[i].count('*') == 2: a1 = l[i] if l[i].count('*') == 1: a2 = l[i] b2 = i #print(a1.index('*'), a2.index('*')) if a1.index('*') == a2.index('*'): z = a1[::-1].index('*') c2 = len(a1) - z - 1 else: c2 = a1.index('*') print(b2+1, c2+1) ```
output
1
38,935
24
77,871
Provide tags and a correct Python 3 solution for this coding contest problem. The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an n Γ— m rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and marked there the districts where the first three robberies had been committed as asterisks. Deduction tells Polycarpus that the fourth robbery will be committed in such district, that all four robbed districts will form the vertices of some rectangle, parallel to the sides of the map. Polycarpus is good at deduction but he's hopeless at math. So he asked you to find the district where the fourth robbery will be committed. Input The first line contains two space-separated integers n and m (2 ≀ n, m ≀ 100) β€” the number of rows and columns in the table, correspondingly. Each of the next n lines contains m characters β€” the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if the corresponding district has been robbed. Otherwise, it equals ".". It is guaranteed that the map has exactly three characters "*" and we can always find the fourth district that meets the problem requirements. Output Print two integers β€” the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. Examples Input 3 2 .* .. ** Output 1 1 Input 3 3 *.* *.. ... Output 2 3
instruction
0
38,936
24
77,872
Tags: brute force, geometry, implementation Correct Solution: ``` a,d=map(int,input().split()) p=0 for b in range(a): e=input() if "*" in e: for n in range(d): if e[n]=='*': if p==0: x1=[b,n] p+=1 elif p==1: x2=[b,n] p+=1 elif p==2: x3=[b,n] def f(x,y): return (x[0]-y[0])**2+(x[1]-y[1])**2 g=f(x1,x2) h=f(x1,x3) i=f(x2,x3) if g==(h+i): x4=(x1[0]+x2[0])-x3[0] y4=(x1[1]+x2[1])-x3[1] elif h==(g+i): x4=(x1[0]+x3[0])-x2[0] y4=(x1[1]+x3[1])-x2[1] else: x4=(x2[0]+x3[0])-x1[0] y4=(x2[1]+x3[1])-x1[1] print(x4+1,y4+1) ```
output
1
38,936
24
77,873
Provide tags and a correct Python 3 solution for this coding contest problem. The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an n Γ— m rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and marked there the districts where the first three robberies had been committed as asterisks. Deduction tells Polycarpus that the fourth robbery will be committed in such district, that all four robbed districts will form the vertices of some rectangle, parallel to the sides of the map. Polycarpus is good at deduction but he's hopeless at math. So he asked you to find the district where the fourth robbery will be committed. Input The first line contains two space-separated integers n and m (2 ≀ n, m ≀ 100) β€” the number of rows and columns in the table, correspondingly. Each of the next n lines contains m characters β€” the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if the corresponding district has been robbed. Otherwise, it equals ".". It is guaranteed that the map has exactly three characters "*" and we can always find the fourth district that meets the problem requirements. Output Print two integers β€” the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. Examples Input 3 2 .* .. ** Output 1 1 Input 3 3 *.* *.. ... Output 2 3
instruction
0
38,937
24
77,874
Tags: brute force, geometry, implementation Correct Solution: ``` n,m=map(int,input().split()); l=[] for i in range(n): l.append(input()) for i in range(len(l)): if l[i].count('*')==1: r=i for i in range(n): if l[i].count('*')==2: for j in range(m): if (l[i][j]=='*' and l[r][j]!='*'): c=j print(r+1,c+1,sep=' ') ```
output
1
38,937
24
77,875
Provide tags and a correct Python 3 solution for this coding contest problem. The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an n Γ— m rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and marked there the districts where the first three robberies had been committed as asterisks. Deduction tells Polycarpus that the fourth robbery will be committed in such district, that all four robbed districts will form the vertices of some rectangle, parallel to the sides of the map. Polycarpus is good at deduction but he's hopeless at math. So he asked you to find the district where the fourth robbery will be committed. Input The first line contains two space-separated integers n and m (2 ≀ n, m ≀ 100) β€” the number of rows and columns in the table, correspondingly. Each of the next n lines contains m characters β€” the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if the corresponding district has been robbed. Otherwise, it equals ".". It is guaranteed that the map has exactly three characters "*" and we can always find the fourth district that meets the problem requirements. Output Print two integers β€” the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. Examples Input 3 2 .* .. ** Output 1 1 Input 3 3 *.* *.. ... Output 2 3
instruction
0
38,938
24
77,876
Tags: brute force, geometry, implementation Correct Solution: ``` n,m=map(int,input().split()) x=[] for i in range(n): x.append(input()) l=[] t=[] for i in range(n): for j in range(m): if(x[i][j]=='*'): l.append([i,j]) if(l[0][0]==l[1][0]): t.append(l[2][0]+1) elif(l[2][0]==l[1][0]): t.append(l[0][0]+1) elif(l[0][0]==l[2][0]): t.append(l[1][0]+1) if(l[0][1]==l[1][1]): t.append(l[2][1]+1) elif(l[2][1]==l[1][1]): t.append(l[0][1]+1) elif(l[0][1]==l[2][1]): t.append(l[1][1]+1) print(t[0],t[1]) ```
output
1
38,938
24
77,877
Provide tags and a correct Python 3 solution for this coding contest problem. The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an n Γ— m rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and marked there the districts where the first three robberies had been committed as asterisks. Deduction tells Polycarpus that the fourth robbery will be committed in such district, that all four robbed districts will form the vertices of some rectangle, parallel to the sides of the map. Polycarpus is good at deduction but he's hopeless at math. So he asked you to find the district where the fourth robbery will be committed. Input The first line contains two space-separated integers n and m (2 ≀ n, m ≀ 100) β€” the number of rows and columns in the table, correspondingly. Each of the next n lines contains m characters β€” the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if the corresponding district has been robbed. Otherwise, it equals ".". It is guaranteed that the map has exactly three characters "*" and we can always find the fourth district that meets the problem requirements. Output Print two integers β€” the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. Examples Input 3 2 .* .. ** Output 1 1 Input 3 3 *.* *.. ... Output 2 3
instruction
0
38,939
24
77,878
Tags: brute force, geometry, implementation Correct Solution: ``` # -*- coding: utf-8 -*- """ Created on Thu Apr 9 21:42:13 2020 @author: odraodE """ '''testo dell'esercizio https://codeforces.com/problemset/problem/181/A''' M=[] a=input().split() n=int(a[0]) m=int(a[1]) for x in range(n): l=[] for y in range(m): l.append('.') M.append(l) for x in range(n): col=input() for y in range(len(col)): if col[y]=='*': M[x][y]='*' coord_1=0 coord_2=0 coordinate=[] for x in range(n): for y in range(m): if M[x][y]=='*': for k in range(n): if M[k][y]=='*' and k!=x and coord_1==0: coord_1=(k,y) coord_2=(x,y) for k in range(m): if M[x][k]=='*' and k!=y: coordinate.append((x,y)) coordinate.append((x,k)) lunghezza=coord_1[0]-coord_2[0] a=(coordinate[0][0]+lunghezza,coordinate[0][1]) b=(coordinate[1][0]+lunghezza,coordinate[1][1]) if a[0] < n and b[0] < n: if M[a[0]][a[1]]=='*': ris=(b[0],b[1]) elif M[b[0]][b[1]]=='*': ris=(a[0],a[1]) else: a=(coordinate[0][0]-lunghezza,coordinate[0][1]) b=(coordinate[1][0]-lunghezza,coordinate[1][1]) if M[a[0]][a[1]]=='*': ris=(b[0],b[1]) elif M[b[0]][b[1]]=='*': ris=(a[0],a[1]) else: a=(coordinate[0][0]-lunghezza,coordinate[0][1]) b=(coordinate[1][0]-lunghezza,coordinate[1][1]) if M[a[0]][a[1]]=='*': ris=(b[0],b[1]) elif M[b[0]][b[1]]=='*': ris=(a[0],a[1]) print(ris[0]+1,ris[1]+1) ```
output
1
38,939
24
77,879
Provide tags and a correct Python 3 solution for this coding contest problem. The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an n Γ— m rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and marked there the districts where the first three robberies had been committed as asterisks. Deduction tells Polycarpus that the fourth robbery will be committed in such district, that all four robbed districts will form the vertices of some rectangle, parallel to the sides of the map. Polycarpus is good at deduction but he's hopeless at math. So he asked you to find the district where the fourth robbery will be committed. Input The first line contains two space-separated integers n and m (2 ≀ n, m ≀ 100) β€” the number of rows and columns in the table, correspondingly. Each of the next n lines contains m characters β€” the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if the corresponding district has been robbed. Otherwise, it equals ".". It is guaranteed that the map has exactly three characters "*" and we can always find the fourth district that meets the problem requirements. Output Print two integers β€” the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. Examples Input 3 2 .* .. ** Output 1 1 Input 3 3 *.* *.. ... Output 2 3
instruction
0
38,940
24
77,880
Tags: brute force, geometry, implementation Correct Solution: ``` x = list(map(int, input().split(" "))) y = [] a = [] b = [] for i in range(x[0]): y.append(input().split(" ")) for i in y: for j in i: b.append(list(j)) for i in range(len(b)): for j in range(len(b[0])): if b[i][j] == "*": a.append([i, j]) else: pass if a[0][0] != a[1][0]: if a[0][1] != a[1][1]: print(*[a[0][0]+1, a[1][1]+1]) else: print(*[a[0][0]+1, a[2][1]+1]) else: if a[1][1] != a[2][1]: print(*[a[2][0]+1, a[1][1]+1]) else: print(*[a[2][0]+1, a[0][1]+1]) ```
output
1
38,940
24
77,881
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an n Γ— m rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and marked there the districts where the first three robberies had been committed as asterisks. Deduction tells Polycarpus that the fourth robbery will be committed in such district, that all four robbed districts will form the vertices of some rectangle, parallel to the sides of the map. Polycarpus is good at deduction but he's hopeless at math. So he asked you to find the district where the fourth robbery will be committed. Input The first line contains two space-separated integers n and m (2 ≀ n, m ≀ 100) β€” the number of rows and columns in the table, correspondingly. Each of the next n lines contains m characters β€” the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if the corresponding district has been robbed. Otherwise, it equals ".". It is guaranteed that the map has exactly three characters "*" and we can always find the fourth district that meets the problem requirements. Output Print two integers β€” the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. Examples Input 3 2 .* .. ** Output 1 1 Input 3 3 *.* *.. ... Output 2 3 Submitted Solution: ``` n, m = list(map(int, input().split())) mapa = [] x = -1 achou = 0 yPossivel = set() for i in range(0, n): linha = list(input()) mapa.append(linha) nDistritosRoubados = linha.count('*') if (nDistritosRoubados == 1): achou += 1 x = i + 1 if (nDistritosRoubados == 2): achou += 1 for j in range(0, m): if (linha[j] == '*'): yPossivel.add(j + 1) if (achou == 2): break for y in yPossivel: if (mapa[x - 1][y - 1] != '*'): print(x, y) ```
instruction
0
38,941
24
77,882
Yes
output
1
38,941
24
77,883
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an n Γ— m rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and marked there the districts where the first three robberies had been committed as asterisks. Deduction tells Polycarpus that the fourth robbery will be committed in such district, that all four robbed districts will form the vertices of some rectangle, parallel to the sides of the map. Polycarpus is good at deduction but he's hopeless at math. So he asked you to find the district where the fourth robbery will be committed. Input The first line contains two space-separated integers n and m (2 ≀ n, m ≀ 100) β€” the number of rows and columns in the table, correspondingly. Each of the next n lines contains m characters β€” the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if the corresponding district has been robbed. Otherwise, it equals ".". It is guaranteed that the map has exactly three characters "*" and we can always find the fourth district that meets the problem requirements. Output Print two integers β€” the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. Examples Input 3 2 .* .. ** Output 1 1 Input 3 3 *.* *.. ... Output 2 3 Submitted Solution: ``` l = [] n, m = map(int, input().split()) for _ in range(n): l1 = list(input()) l.append(l1) lp = [] for i in range(n): for j in range(m): if l[i][j] == '*': l1 = [i , j] lp.append(l1) if lp[1][0] == lp[2][0]: x = lp[0][0] elif lp[0][0] == lp[1][0]: x = lp[2][0] else: x = lp[1][0] if lp[1][1] == lp[2][1]: y = lp[0][1] elif lp[0][1] == lp[1][1]: y = lp[2][1] else: y = lp[1][1] print(x + 1, y + 1) ```
instruction
0
38,942
24
77,884
Yes
output
1
38,942
24
77,885
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an n Γ— m rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and marked there the districts where the first three robberies had been committed as asterisks. Deduction tells Polycarpus that the fourth robbery will be committed in such district, that all four robbed districts will form the vertices of some rectangle, parallel to the sides of the map. Polycarpus is good at deduction but he's hopeless at math. So he asked you to find the district where the fourth robbery will be committed. Input The first line contains two space-separated integers n and m (2 ≀ n, m ≀ 100) β€” the number of rows and columns in the table, correspondingly. Each of the next n lines contains m characters β€” the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if the corresponding district has been robbed. Otherwise, it equals ".". It is guaranteed that the map has exactly three characters "*" and we can always find the fourth district that meets the problem requirements. Output Print two integers β€” the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. Examples Input 3 2 .* .. ** Output 1 1 Input 3 3 *.* *.. ... Output 2 3 Submitted Solution: ``` n,m=map(int,input().split()) city=[] for i in range(n): temp=input() city.append(temp) row={} col={} for i in range(n): for j in range(m): if city[i][j]=="*": if i+1 in row: row[i+1]+=1 else: row[i+1]=1 if j+1 in col: col[j+1]+=1 else: col[j+1]=1 for i in row: if row[i]==1: x=i break for i in col: if col[i]==1: y=i break print(x,y) ```
instruction
0
38,943
24
77,886
Yes
output
1
38,943
24
77,887
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an n Γ— m rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and marked there the districts where the first three robberies had been committed as asterisks. Deduction tells Polycarpus that the fourth robbery will be committed in such district, that all four robbed districts will form the vertices of some rectangle, parallel to the sides of the map. Polycarpus is good at deduction but he's hopeless at math. So he asked you to find the district where the fourth robbery will be committed. Input The first line contains two space-separated integers n and m (2 ≀ n, m ≀ 100) β€” the number of rows and columns in the table, correspondingly. Each of the next n lines contains m characters β€” the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if the corresponding district has been robbed. Otherwise, it equals ".". It is guaranteed that the map has exactly three characters "*" and we can always find the fourth district that meets the problem requirements. Output Print two integers β€” the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. Examples Input 3 2 .* .. ** Output 1 1 Input 3 3 *.* *.. ... Output 2 3 Submitted Solution: ``` T_ON = 0 DEBUG_ON = 1 MOD = 998244353 def solve(): n, m = read_ints() A = [] for r in range(n): s = input() for c in range(m): if s[c] == '*': A.append((r + 1, c + 1)) assert(len(A) == 3) r = c = 0 for x, y in A: r ^= x c ^= y print(r, c) def main(): T = read_int() if T_ON else 1 for i in range(T): solve() def debug(*xargs): if DEBUG_ON: print(*xargs) from collections import * import math #---------------------------------FAST_IO--------------------------------------- import os import sys from io import BytesIO, IOBase # region fastio 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.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") #----------------------------------IO_WRAP-------------------------------------- def read_int(): return int(input()) def read_ints(): return list(map(int, input().split())) def print_nums(nums): print(" ".join(map(str, nums))) def YES(): print("YES") def Yes(): print("Yes") def NO(): print("NO") def No(): print("No") def First(): print("First") def Second(): print("Second") #----------------------------------FIB-------------------------------------- def fib(n): """ the nth fib, start from zero """ a, b = 0, 1 for _ in range(n): a, b = b, a + b return a def fib_ns(n): """ the first n fibs, start from zero """ assert n >= 1 f = [0 for _ in range(n + 1)] f[0] = 0 f[1] = 1 for i in range(2, n + 1): f[i] = f[i - 1] + f[i - 2] return f def fib_to_n(n): """ return fibs <= n, start from zero n=8 f=[0,1,1,2,3,5,8] """ f = [] a, b = 0, 1 while a <= n: f.append(a) a, b = b, a + b return f #----------------------------------MOD-------------------------------------- def gcd(a, b): if a == 0: return b return gcd(b % a, a) def xgcd(a, b): """return (g, x, y) such that a*x + b*y = g = gcd(a, b)""" x0, x1, y0, y1 = 0, 1, 1, 0 while a != 0: (q, a), b = divmod(b, a), a y0, y1 = y1, y0 - q * y1 x0, x1 = x1, x0 - q * x1 return b, x0, y0 def lcm(a, b): d = gcd(a, b) return a * b // d def is_even(x): return x % 2 == 0 def is_odd(x): return x % 2 == 1 def modinv(a, m): """return x such that (a * x) % m == 1""" g, x, _ = xgcd(a, m) if g != 1: raise Exception('gcd(a, m) != 1') return x % m def mod_add(x, y): x += y while x >= MOD: x -= MOD while x < 0: x += MOD return x def mod_mul(x, y): return (x * y) % MOD def mod_pow(x, y): if y == 0: return 1 if y % 2: return mod_mul(x, mod_pow(x, y - 1)) p = mod_pow(x, y // 2) return mod_mul(p, p) def mod_inv(y): return mod_pow(y, MOD - 2) def mod_div(x, y): # y^(-1): Fermat little theorem, MOD is a prime return mod_mul(x, mod_inv(y)) #---------------------------------PRIME--------------------------------------- def is_prime(n): if n == 1: return False for i in range(2, int(n ** 0.5) + 1): if n % i: return False return True def gen_primes(n): """ generate primes of [1..n] using sieve's method """ P = [True for _ in range(n + 1)] P[0] = P[1] = False for i in range(int(n ** 0.5) + 1): if P[i]: for j in range(2 * i, n + 1, i): P[j] = False return P #---------------------------------MISC--------------------------------------- def is_lucky(n): return set(list(str(n))).issubset({'4', '7'}) #---------------------------------MAIN--------------------------------------- main() ```
instruction
0
38,944
24
77,888
Yes
output
1
38,944
24
77,889
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an n Γ— m rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and marked there the districts where the first three robberies had been committed as asterisks. Deduction tells Polycarpus that the fourth robbery will be committed in such district, that all four robbed districts will form the vertices of some rectangle, parallel to the sides of the map. Polycarpus is good at deduction but he's hopeless at math. So he asked you to find the district where the fourth robbery will be committed. Input The first line contains two space-separated integers n and m (2 ≀ n, m ≀ 100) β€” the number of rows and columns in the table, correspondingly. Each of the next n lines contains m characters β€” the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if the corresponding district has been robbed. Otherwise, it equals ".". It is guaranteed that the map has exactly three characters "*" and we can always find the fourth district that meets the problem requirements. Output Print two integers β€” the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. Examples Input 3 2 .* .. ** Output 1 1 Input 3 3 *.* *.. ... Output 2 3 Submitted Solution: ``` n,m=map(int,input().split()) co=[] x,y=0,0 for i in range(n): c=input() for j in range(len(c)): if c[j]=='*': x^=j y^=i print(x+1,y+1) ```
instruction
0
38,945
24
77,890
No
output
1
38,945
24
77,891
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an n Γ— m rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and marked there the districts where the first three robberies had been committed as asterisks. Deduction tells Polycarpus that the fourth robbery will be committed in such district, that all four robbed districts will form the vertices of some rectangle, parallel to the sides of the map. Polycarpus is good at deduction but he's hopeless at math. So he asked you to find the district where the fourth robbery will be committed. Input The first line contains two space-separated integers n and m (2 ≀ n, m ≀ 100) β€” the number of rows and columns in the table, correspondingly. Each of the next n lines contains m characters β€” the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if the corresponding district has been robbed. Otherwise, it equals ".". It is guaranteed that the map has exactly three characters "*" and we can always find the fourth district that meets the problem requirements. Output Print two integers β€” the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. Examples Input 3 2 .* .. ** Output 1 1 Input 3 3 *.* *.. ... Output 2 3 Submitted Solution: ``` import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] # def LF(): return [float(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return input() def main(): h,w=LI() field=[list(S()) for _ in range(h)] f='' for i in range(h): for j in range(w): if field[i][j]=='.': continue for dy,dx in dd: ni=i+dy nj=j+dx if 0<=ni<h and 0<=nj<w: if field[ni][nj]=='*': if abs(dy)==1: f='joge' else: f='sayu' field[i][j]='.' field[ni][nj]='.' break if f!='': break if f!='': break if f=='joge': for i in range(h): for j in range(w): if field[i][j]=='.': continue for dy,dx in [(1,0),(-1,0)]: ni=i+dy nj=j+dx if 0<=ni<h and 0<=nj<w: return str(ni+1)+' '+str(nj+1) else: for i in range(h): for j in range(w): if field[i][j]=='.': continue for dy,dx in [(0,1),(0,-1)]: ni=i+dy nj=j+dx if 0<=ni<h and 0<=nj<w: return str(ni+1)+' '+str(nj+1) # main() print(main()) ```
instruction
0
38,946
24
77,892
No
output
1
38,946
24
77,893
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an n Γ— m rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and marked there the districts where the first three robberies had been committed as asterisks. Deduction tells Polycarpus that the fourth robbery will be committed in such district, that all four robbed districts will form the vertices of some rectangle, parallel to the sides of the map. Polycarpus is good at deduction but he's hopeless at math. So he asked you to find the district where the fourth robbery will be committed. Input The first line contains two space-separated integers n and m (2 ≀ n, m ≀ 100) β€” the number of rows and columns in the table, correspondingly. Each of the next n lines contains m characters β€” the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if the corresponding district has been robbed. Otherwise, it equals ".". It is guaranteed that the map has exactly three characters "*" and we can always find the fourth district that meets the problem requirements. Output Print two integers β€” the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. Examples Input 3 2 .* .. ** Output 1 1 Input 3 3 *.* *.. ... Output 2 3 Submitted Solution: ``` x,y = map(int,input().split()) c = 0 z = [] for i in range(x): z.append(input()) for j in range(x): for k in range(y): if z[j].count("*") == 2: a = j+1 if c != 2: break c = c + 1 if c == 1: t = k if z[j].count("*") == 1: a1 = j+1 print(a1,k+c+1) ```
instruction
0
38,947
24
77,894
No
output
1
38,947
24
77,895
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an n Γ— m rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and marked there the districts where the first three robberies had been committed as asterisks. Deduction tells Polycarpus that the fourth robbery will be committed in such district, that all four robbed districts will form the vertices of some rectangle, parallel to the sides of the map. Polycarpus is good at deduction but he's hopeless at math. So he asked you to find the district where the fourth robbery will be committed. Input The first line contains two space-separated integers n and m (2 ≀ n, m ≀ 100) β€” the number of rows and columns in the table, correspondingly. Each of the next n lines contains m characters β€” the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if the corresponding district has been robbed. Otherwise, it equals ".". It is guaranteed that the map has exactly three characters "*" and we can always find the fourth district that meets the problem requirements. Output Print two integers β€” the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. Examples Input 3 2 .* .. ** Output 1 1 Input 3 3 *.* *.. ... Output 2 3 Submitted Solution: ``` n,m=map(int,input().split()) b=0 c='' d=[0,0] for i in range(n): a=input() if '*' in a: if a.find('*')==a.rfind('*'): b=a.find('*') d[0]=i+1 else: if a.find('*')==b: d[1]=a.rfind('*')+1 else: d[1]=a.find('*')+1 print(*d,sep=' ') ```
instruction
0
38,948
24
77,896
No
output
1
38,948
24
77,897
Provide tags and a correct Python 3 solution for this coding contest problem. There are n phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct. There is the latest version of Berdroid OS installed on Polycarp's phone. If some number is entered, is shows up all the numbers in the contacts for which there is a substring equal to the entered sequence of digits. For example, is there are three phone numbers in Polycarp's contacts: 123456789, 100000000 and 100123456, then: * if he enters 00 two numbers will show up: 100000000 and 100123456, * if he enters 123 two numbers will show up 123456789 and 100123456, * if he enters 01 there will be only one number 100123456. For each of the phone numbers in Polycarp's contacts, find the minimum in length sequence of digits such that if Polycarp enters this sequence, Berdroid shows this only phone number. Input The first line contains single integer n (1 ≀ n ≀ 70000) β€” the total number of phone contacts in Polycarp's contacts. The phone numbers follow, one in each line. Each number is a positive 9-digit integer starting with a digit from 1 to 9. All the numbers are distinct. Output Print exactly n lines: the i-th of them should contain the shortest non-empty sequence of digits, such that if Polycarp enters it, the Berdroid OS shows up only the i-th number from the contacts. If there are several such sequences, print any of them. Examples Input 3 123456789 100000000 100123456 Output 9 000 01 Input 4 123456789 193456789 134567819 934567891 Output 2 193 81 91
instruction
0
39,275
24
78,550
Tags: data structures, implementation, sortings Correct Solution: ``` n = int(input()) s, p = {}, [''] * n for k in range(n): p[k] = t = input() for q in [t[i: j] for i in range(9) for j in range(i + 1, 10)]: s[q] = -1 if q in s and s[q] != k else k for q, k in s.items(): if k >= 0 and len(p[k]) > len(q): p[k] = q print('\n'.join(p)) # Made By Mostafa_Khaled ```
output
1
39,275
24
78,551
Provide tags and a correct Python 3 solution for this coding contest problem. There are n phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct. There is the latest version of Berdroid OS installed on Polycarp's phone. If some number is entered, is shows up all the numbers in the contacts for which there is a substring equal to the entered sequence of digits. For example, is there are three phone numbers in Polycarp's contacts: 123456789, 100000000 and 100123456, then: * if he enters 00 two numbers will show up: 100000000 and 100123456, * if he enters 123 two numbers will show up 123456789 and 100123456, * if he enters 01 there will be only one number 100123456. For each of the phone numbers in Polycarp's contacts, find the minimum in length sequence of digits such that if Polycarp enters this sequence, Berdroid shows this only phone number. Input The first line contains single integer n (1 ≀ n ≀ 70000) β€” the total number of phone contacts in Polycarp's contacts. The phone numbers follow, one in each line. Each number is a positive 9-digit integer starting with a digit from 1 to 9. All the numbers are distinct. Output Print exactly n lines: the i-th of them should contain the shortest non-empty sequence of digits, such that if Polycarp enters it, the Berdroid OS shows up only the i-th number from the contacts. If there are several such sequences, print any of them. Examples Input 3 123456789 100000000 100123456 Output 9 000 01 Input 4 123456789 193456789 134567819 934567891 Output 2 193 81 91
instruction
0
39,276
24
78,552
Tags: data structures, implementation, sortings Correct Solution: ``` def podstroki(s): return sorted(set(s[i: i1] for i in range(9) for i1 in range (i+1, 10)), key=len) res = {} spisok = [podstroki(input()) for i in range (int(input()))] for s in spisok: for podstr in s: if podstr in res: res[podstr] += 1 else: res[podstr] = 1 for s in spisok: for podstr in s: if res[podstr] == 1: print(podstr) break ```
output
1
39,276
24
78,553
Provide tags and a correct Python 3 solution for this coding contest problem. There are n phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct. There is the latest version of Berdroid OS installed on Polycarp's phone. If some number is entered, is shows up all the numbers in the contacts for which there is a substring equal to the entered sequence of digits. For example, is there are three phone numbers in Polycarp's contacts: 123456789, 100000000 and 100123456, then: * if he enters 00 two numbers will show up: 100000000 and 100123456, * if he enters 123 two numbers will show up 123456789 and 100123456, * if he enters 01 there will be only one number 100123456. For each of the phone numbers in Polycarp's contacts, find the minimum in length sequence of digits such that if Polycarp enters this sequence, Berdroid shows this only phone number. Input The first line contains single integer n (1 ≀ n ≀ 70000) β€” the total number of phone contacts in Polycarp's contacts. The phone numbers follow, one in each line. Each number is a positive 9-digit integer starting with a digit from 1 to 9. All the numbers are distinct. Output Print exactly n lines: the i-th of them should contain the shortest non-empty sequence of digits, such that if Polycarp enters it, the Berdroid OS shows up only the i-th number from the contacts. If there are several such sequences, print any of them. Examples Input 3 123456789 100000000 100123456 Output 9 000 01 Input 4 123456789 193456789 134567819 934567891 Output 2 193 81 91
instruction
0
39,277
24
78,554
Tags: data structures, implementation, sortings Correct Solution: ``` import math from collections import * a=int(input()) indx=defaultdict(list) done=defaultdict(list) for t in range(a): s=input() for i in range(len(s)): for j in range(i,len(s)): m=s[i:j+1] if(len(done[m])==0): done[m].append(t) indx[t].append(m) else: if(len(done[m])==1 and done[m][0]!=math.inf and t!=done[m][0]): indx[done[m][0]].remove(m) done[m][0]=math.inf for i in range(a): af=indx[i] mini=15 ss='' for i in range(len(af)): if(len(af[i])<mini): mini=len(af[i]) ss=af[i] print(ss) ```
output
1
39,277
24
78,555
Provide tags and a correct Python 3 solution for this coding contest problem. There are n phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct. There is the latest version of Berdroid OS installed on Polycarp's phone. If some number is entered, is shows up all the numbers in the contacts for which there is a substring equal to the entered sequence of digits. For example, is there are three phone numbers in Polycarp's contacts: 123456789, 100000000 and 100123456, then: * if he enters 00 two numbers will show up: 100000000 and 100123456, * if he enters 123 two numbers will show up 123456789 and 100123456, * if he enters 01 there will be only one number 100123456. For each of the phone numbers in Polycarp's contacts, find the minimum in length sequence of digits such that if Polycarp enters this sequence, Berdroid shows this only phone number. Input The first line contains single integer n (1 ≀ n ≀ 70000) β€” the total number of phone contacts in Polycarp's contacts. The phone numbers follow, one in each line. Each number is a positive 9-digit integer starting with a digit from 1 to 9. All the numbers are distinct. Output Print exactly n lines: the i-th of them should contain the shortest non-empty sequence of digits, such that if Polycarp enters it, the Berdroid OS shows up only the i-th number from the contacts. If there are several such sequences, print any of them. Examples Input 3 123456789 100000000 100123456 Output 9 000 01 Input 4 123456789 193456789 134567819 934567891 Output 2 193 81 91
instruction
0
39,278
24
78,556
Tags: data structures, implementation, sortings Correct Solution: ``` import sys from collections import defaultdict N = int(input()) S = [] Subs = defaultdict(int) for i in range(N): s = input() S.append(s) for ff in range(1,10): for ss in range(10-ff): Subs[s[ss:ss+ff]] += 1 for i in range(N): flag = 0 At = S[i] for ff in range(1,10): curr = defaultdict(int) for ss in range(10-ff): curr[At[ss:ss+ff]] += 1 # Here we check for key in curr.keys(): if(curr[key] == Subs[key]): print(key) flag = 1 break if(flag): break ```
output
1
39,278
24
78,557
Provide tags and a correct Python 3 solution for this coding contest problem. There are n phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct. There is the latest version of Berdroid OS installed on Polycarp's phone. If some number is entered, is shows up all the numbers in the contacts for which there is a substring equal to the entered sequence of digits. For example, is there are three phone numbers in Polycarp's contacts: 123456789, 100000000 and 100123456, then: * if he enters 00 two numbers will show up: 100000000 and 100123456, * if he enters 123 two numbers will show up 123456789 and 100123456, * if he enters 01 there will be only one number 100123456. For each of the phone numbers in Polycarp's contacts, find the minimum in length sequence of digits such that if Polycarp enters this sequence, Berdroid shows this only phone number. Input The first line contains single integer n (1 ≀ n ≀ 70000) β€” the total number of phone contacts in Polycarp's contacts. The phone numbers follow, one in each line. Each number is a positive 9-digit integer starting with a digit from 1 to 9. All the numbers are distinct. Output Print exactly n lines: the i-th of them should contain the shortest non-empty sequence of digits, such that if Polycarp enters it, the Berdroid OS shows up only the i-th number from the contacts. If there are several such sequences, print any of them. Examples Input 3 123456789 100000000 100123456 Output 9 000 01 Input 4 123456789 193456789 134567819 934567891 Output 2 193 81 91
instruction
0
39,279
24
78,558
Tags: data structures, implementation, sortings Correct Solution: ``` n = int(input()) m = {} a = [] for i in range(n): s = input() sub = set() for i in range(len(s)): for j in range(i, len(s)): k = s[i:j + 1] if k in sub: continue else: sub.add(k) if k in m: m[k] += 1 else: m[k] = 1 a.append(s) for s in a: ans = s for i in range(len(s)): for j in range(i, len(s)): k = s[i:j + 1] if m[k] == 1 and len(k) < len(ans): ans = k print(ans) ```
output
1
39,279
24
78,559
Provide tags and a correct Python 3 solution for this coding contest problem. There are n phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct. There is the latest version of Berdroid OS installed on Polycarp's phone. If some number is entered, is shows up all the numbers in the contacts for which there is a substring equal to the entered sequence of digits. For example, is there are three phone numbers in Polycarp's contacts: 123456789, 100000000 and 100123456, then: * if he enters 00 two numbers will show up: 100000000 and 100123456, * if he enters 123 two numbers will show up 123456789 and 100123456, * if he enters 01 there will be only one number 100123456. For each of the phone numbers in Polycarp's contacts, find the minimum in length sequence of digits such that if Polycarp enters this sequence, Berdroid shows this only phone number. Input The first line contains single integer n (1 ≀ n ≀ 70000) β€” the total number of phone contacts in Polycarp's contacts. The phone numbers follow, one in each line. Each number is a positive 9-digit integer starting with a digit from 1 to 9. All the numbers are distinct. Output Print exactly n lines: the i-th of them should contain the shortest non-empty sequence of digits, such that if Polycarp enters it, the Berdroid OS shows up only the i-th number from the contacts. If there are several such sequences, print any of them. Examples Input 3 123456789 100000000 100123456 Output 9 000 01 Input 4 123456789 193456789 134567819 934567891 Output 2 193 81 91
instruction
0
39,280
24
78,560
Tags: data structures, implementation, sortings Correct Solution: ``` n = int(input()) maps = {} for i in range(n): string = input() for j in range(len(string)): for a in range(0,j + 1): substr = string[a:j+1] if substr not in maps: maps[substr] = {'index' : i, 'count': 1} else: if i != maps[substr]['index']: maps[substr]['count'] += 1 maps = sorted(maps.items(), key = lambda i: i[1]['index']) count = 0 min_v = '' min_count = 10 for k, value in maps: if count < value['index']: count += 1 print(min_v) min_v = 'idk' min_count = 10 if value['count'] == 1: if len(k) < min_count: min_count = len(k) min_v = k print(min_v) ```
output
1
39,280
24
78,561
Provide tags and a correct Python 3 solution for this coding contest problem. There are n phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct. There is the latest version of Berdroid OS installed on Polycarp's phone. If some number is entered, is shows up all the numbers in the contacts for which there is a substring equal to the entered sequence of digits. For example, is there are three phone numbers in Polycarp's contacts: 123456789, 100000000 and 100123456, then: * if he enters 00 two numbers will show up: 100000000 and 100123456, * if he enters 123 two numbers will show up 123456789 and 100123456, * if he enters 01 there will be only one number 100123456. For each of the phone numbers in Polycarp's contacts, find the minimum in length sequence of digits such that if Polycarp enters this sequence, Berdroid shows this only phone number. Input The first line contains single integer n (1 ≀ n ≀ 70000) β€” the total number of phone contacts in Polycarp's contacts. The phone numbers follow, one in each line. Each number is a positive 9-digit integer starting with a digit from 1 to 9. All the numbers are distinct. Output Print exactly n lines: the i-th of them should contain the shortest non-empty sequence of digits, such that if Polycarp enters it, the Berdroid OS shows up only the i-th number from the contacts. If there are several such sequences, print any of them. Examples Input 3 123456789 100000000 100123456 Output 9 000 01 Input 4 123456789 193456789 134567819 934567891 Output 2 193 81 91
instruction
0
39,281
24
78,562
Tags: data structures, implementation, sortings Correct Solution: ``` cnt = {} n = int(input()) ls = [input() for _ in range(n)] for s in ls: subs = set() for end in range(10): for start in range(end): subs.add(s[start:end]) for sub in subs: if sub not in cnt: cnt[sub] = 1 else: cnt[sub] += 1 for s in ls: subs = set() for end in range(10): for start in range(end): subs.add(s[start:end]) for sub in sorted(subs, key=len): if cnt[sub] == 1: print(sub) break ```
output
1
39,281
24
78,563
Provide tags and a correct Python 3 solution for this coding contest problem. There are n phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct. There is the latest version of Berdroid OS installed on Polycarp's phone. If some number is entered, is shows up all the numbers in the contacts for which there is a substring equal to the entered sequence of digits. For example, is there are three phone numbers in Polycarp's contacts: 123456789, 100000000 and 100123456, then: * if he enters 00 two numbers will show up: 100000000 and 100123456, * if he enters 123 two numbers will show up 123456789 and 100123456, * if he enters 01 there will be only one number 100123456. For each of the phone numbers in Polycarp's contacts, find the minimum in length sequence of digits such that if Polycarp enters this sequence, Berdroid shows this only phone number. Input The first line contains single integer n (1 ≀ n ≀ 70000) β€” the total number of phone contacts in Polycarp's contacts. The phone numbers follow, one in each line. Each number is a positive 9-digit integer starting with a digit from 1 to 9. All the numbers are distinct. Output Print exactly n lines: the i-th of them should contain the shortest non-empty sequence of digits, such that if Polycarp enters it, the Berdroid OS shows up only the i-th number from the contacts. If there are several such sequences, print any of them. Examples Input 3 123456789 100000000 100123456 Output 9 000 01 Input 4 123456789 193456789 134567819 934567891 Output 2 193 81 91
instruction
0
39,282
24
78,564
Tags: data structures, implementation, sortings Correct Solution: ``` class CodeforcesTask860BSolution: def __init__(self): self.result = '' self.n = 0 self.phones = [] def read_input(self): self.n = int(input()) for x in range(self.n): self.phones.append(input()) def process_task(self): phone_book = {} for phone in self.phones: for x in range(1, len(phone) + 1): for y in range(len(phone) - x + 1): subnum = phone[y:y + x] #print(phone, subnum, y, y + x, x) if subnum in phone_book.keys(): if phone_book[subnum] != phone: phone_book[subnum] = False else: phone_book[subnum] = phone results = [] for phone in self.phones: found = False for x in range(1, len(phone) + 1): for y in range(len(phone) - x + 1): subnum = phone[y:y + x] if subnum in phone_book.keys(): if phone_book[subnum]: found = True results.append(subnum) break if found: break self.result = "\n".join([str(x) for x in results]) def get_result(self): return self.result if __name__ == "__main__": Solution = CodeforcesTask860BSolution() Solution.read_input() Solution.process_task() print(Solution.get_result()) ```
output
1
39,282
24
78,565
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct. There is the latest version of Berdroid OS installed on Polycarp's phone. If some number is entered, is shows up all the numbers in the contacts for which there is a substring equal to the entered sequence of digits. For example, is there are three phone numbers in Polycarp's contacts: 123456789, 100000000 and 100123456, then: * if he enters 00 two numbers will show up: 100000000 and 100123456, * if he enters 123 two numbers will show up 123456789 and 100123456, * if he enters 01 there will be only one number 100123456. For each of the phone numbers in Polycarp's contacts, find the minimum in length sequence of digits such that if Polycarp enters this sequence, Berdroid shows this only phone number. Input The first line contains single integer n (1 ≀ n ≀ 70000) β€” the total number of phone contacts in Polycarp's contacts. The phone numbers follow, one in each line. Each number is a positive 9-digit integer starting with a digit from 1 to 9. All the numbers are distinct. Output Print exactly n lines: the i-th of them should contain the shortest non-empty sequence of digits, such that if Polycarp enters it, the Berdroid OS shows up only the i-th number from the contacts. If there are several such sequences, print any of them. Examples Input 3 123456789 100000000 100123456 Output 9 000 01 Input 4 123456789 193456789 134567819 934567891 Output 2 193 81 91 Submitted Solution: ``` n = int(input()) mass = [] for i in range(n): a = input() mass.append(a) # for i in range(len(mass)): # ans = '1' * 11 # for j in range(len(mass[i])): # for k in range(j + 1, len(mass[i]) + 1): # cnt = 0 # for l in range(len(mass)): # if l != i: # if mass[i][j:k] not in mass[l]: # cnt += 1 # else: # break # if cnt == n - 1: # if k - j < len(ans): # ans = mass[i][j:k] # print(ans) a = dict() for i in range(len(mass)): for j in range(len(mass[i])): for k in range(j + 1, len(mass[i]) + 1): if mass[i][j:k] in a: if a[mass[i][j:k]][1] != i: a[mass[i][j:k]][0] += 1 a[mass[i][j:k]][1] = i else: a[mass[i][j:k]] = [1, i] # print(a) for i in range(len(mass)): ans = '1' * 11 for j in range(len(mass[i])): for k in range(j + 1, len(mass[i]) + 1): if a[mass[i][j:k]][0] == 1: if k - j < len(ans): ans = mass[i][j:k] print(ans) ```
instruction
0
39,283
24
78,566
Yes
output
1
39,283
24
78,567
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct. There is the latest version of Berdroid OS installed on Polycarp's phone. If some number is entered, is shows up all the numbers in the contacts for which there is a substring equal to the entered sequence of digits. For example, is there are three phone numbers in Polycarp's contacts: 123456789, 100000000 and 100123456, then: * if he enters 00 two numbers will show up: 100000000 and 100123456, * if he enters 123 two numbers will show up 123456789 and 100123456, * if he enters 01 there will be only one number 100123456. For each of the phone numbers in Polycarp's contacts, find the minimum in length sequence of digits such that if Polycarp enters this sequence, Berdroid shows this only phone number. Input The first line contains single integer n (1 ≀ n ≀ 70000) β€” the total number of phone contacts in Polycarp's contacts. The phone numbers follow, one in each line. Each number is a positive 9-digit integer starting with a digit from 1 to 9. All the numbers are distinct. Output Print exactly n lines: the i-th of them should contain the shortest non-empty sequence of digits, such that if Polycarp enters it, the Berdroid OS shows up only the i-th number from the contacts. If there are several such sequences, print any of them. Examples Input 3 123456789 100000000 100123456 Output 9 000 01 Input 4 123456789 193456789 134567819 934567891 Output 2 193 81 91 Submitted Solution: ``` n = int(input()) a = [] d = {} for b in range(n): s = input() g = set() for i in range(len(s)): for k in range(i, len(s)): w = s[i:k + 1] if w in g: continue else: g.add(w) if w in d: d[w] += 1 else: d[w] = 1 a.append(s) for s in a: ans = s for i in range(len(s)): for j in range(i, len(s)): k = s[i:j + 1] if d[k] == 1 and len(k) < len(ans): ans = k print(ans) ```
instruction
0
39,284
24
78,568
Yes
output
1
39,284
24
78,569
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct. There is the latest version of Berdroid OS installed on Polycarp's phone. If some number is entered, is shows up all the numbers in the contacts for which there is a substring equal to the entered sequence of digits. For example, is there are three phone numbers in Polycarp's contacts: 123456789, 100000000 and 100123456, then: * if he enters 00 two numbers will show up: 100000000 and 100123456, * if he enters 123 two numbers will show up 123456789 and 100123456, * if he enters 01 there will be only one number 100123456. For each of the phone numbers in Polycarp's contacts, find the minimum in length sequence of digits such that if Polycarp enters this sequence, Berdroid shows this only phone number. Input The first line contains single integer n (1 ≀ n ≀ 70000) β€” the total number of phone contacts in Polycarp's contacts. The phone numbers follow, one in each line. Each number is a positive 9-digit integer starting with a digit from 1 to 9. All the numbers are distinct. Output Print exactly n lines: the i-th of them should contain the shortest non-empty sequence of digits, such that if Polycarp enters it, the Berdroid OS shows up only the i-th number from the contacts. If there are several such sequences, print any of them. Examples Input 3 123456789 100000000 100123456 Output 9 000 01 Input 4 123456789 193456789 134567819 934567891 Output 2 193 81 91 Submitted Solution: ``` n = int(input()) l = [] for i in range(n): l.append(input()) d = {} for k in l: for i in range(1, 9 + 1): for j in range(9 - i + 1): a = k[j:j + i] z = d.keys() if a in z: if k != d.get(a)[1]: w = d.get(a) w[0] += 1 w[1] = k d.update({a: w}) else: d.update({a: [1, k]}) r = list(d.items()) ans = [] for i in r: if i[1][0] == 1: ans.append([i[0], i[1][1]]) d1 = {} for i in ans: z = d1.keys() if i[1] in z: if len(str(i[0])) < len(str(d1.get(i[1]))): d1.update({i[1]: i[0]}) else: d1.update({i[1]: i[0]}) for i in l: print(d1.get(i)) ```
instruction
0
39,285
24
78,570
Yes
output
1
39,285
24
78,571
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct. There is the latest version of Berdroid OS installed on Polycarp's phone. If some number is entered, is shows up all the numbers in the contacts for which there is a substring equal to the entered sequence of digits. For example, is there are three phone numbers in Polycarp's contacts: 123456789, 100000000 and 100123456, then: * if he enters 00 two numbers will show up: 100000000 and 100123456, * if he enters 123 two numbers will show up 123456789 and 100123456, * if he enters 01 there will be only one number 100123456. For each of the phone numbers in Polycarp's contacts, find the minimum in length sequence of digits such that if Polycarp enters this sequence, Berdroid shows this only phone number. Input The first line contains single integer n (1 ≀ n ≀ 70000) β€” the total number of phone contacts in Polycarp's contacts. The phone numbers follow, one in each line. Each number is a positive 9-digit integer starting with a digit from 1 to 9. All the numbers are distinct. Output Print exactly n lines: the i-th of them should contain the shortest non-empty sequence of digits, such that if Polycarp enters it, the Berdroid OS shows up only the i-th number from the contacts. If there are several such sequences, print any of them. Examples Input 3 123456789 100000000 100123456 Output 9 000 01 Input 4 123456789 193456789 134567819 934567891 Output 2 193 81 91 Submitted Solution: ``` n = int(input()) numbers = [] for i in range(0,n): number = input() numbers.append(number) telep = {} count = 1 for number in numbers: for l in range(1, len(number)+1): for i in range(0, len(number) - l + 1): key = number[i:i + l] if (key in telep) and (telep[key]!=count): telep[key]=-1 else: telep[key]=count count += 1 reverse = {} for key in telep: if telep[key]==-1: continue elif (telep[key] not in reverse): reverse[telep[key]] = key elif ((len(key))<len(reverse[telep[key]])): reverse[telep[key]]=key for i in range(1, n+1): print(reverse[i]) ```
instruction
0
39,286
24
78,572
Yes
output
1
39,286
24
78,573