message
stringlengths
2
23.4k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
129
108k
cluster
float64
6
6
__index_level_0__
int64
258
216k
Provide tags and a correct Python 3 solution for this coding contest problem. Mahmoud wants to send a message to his friend Ehab. Their language consists of n words numbered from 1 to n. Some words have the same meaning so there are k groups of words such that all the words in some group have the same meaning. Mahmou...
instruction
0
79,666
6
159,332
Tags: dsu, greedy, implementation Correct Solution: ``` def main(): nkm=input() nkm=nkm.split() n = int(nkm[0]) k = int(nkm[1]) m = int(nkm[2]) words = input() words = words.split() costs= input() costs = costs.split() groups = list() dic = dict() for i in range(k): ...
output
1
79,666
6
159,333
Provide tags and a correct Python 3 solution for this coding contest problem. Mahmoud wants to send a message to his friend Ehab. Their language consists of n words numbered from 1 to n. Some words have the same meaning so there are k groups of words such that all the words in some group have the same meaning. Mahmou...
instruction
0
79,667
6
159,334
Tags: dsu, greedy, implementation Correct Solution: ``` #!/usr/bin/python3.6 # -*- coding: utf-8 -*- # @Time : 2020/11/1 3:40 PM # @Author : Songtao Li def init(n): father = [i for i in range(n)] return father def find_father(x): if father[x] == x: return x else: father[x] = find...
output
1
79,667
6
159,335
Provide tags and a correct Python 3 solution for this coding contest problem. Mahmoud wants to send a message to his friend Ehab. Their language consists of n words numbered from 1 to n. Some words have the same meaning so there are k groups of words such that all the words in some group have the same meaning. Mahmou...
instruction
0
79,668
6
159,336
Tags: dsu, greedy, implementation Correct Solution: ``` # https://codeforces.com/problemset/problem/959/B class DSU: def __init__(self,n): self.n = n self.comps = n self.parent = [i for i in range(n)] def FIND(self,x): if x!=self.parent[x]: self.parent[x] =...
output
1
79,668
6
159,337
Provide tags and a correct Python 3 solution for this coding contest problem. Mahmoud wants to send a message to his friend Ehab. Their language consists of n words numbered from 1 to n. Some words have the same meaning so there are k groups of words such that all the words in some group have the same meaning. Mahmou...
instruction
0
79,669
6
159,338
Tags: dsu, greedy, implementation Correct Solution: ``` arr = list(map(int,input().split(" "))) n,k,m = arr[0],arr[1],arr[2] word = list(input().split(" ")) cost = list(map(int,input().split(" "))) dic = {} for i in range(k): tmp = list(map(int,input().split(" "))) if tmp[0] == 1: dic[word[tmp[1]-1]] = ...
output
1
79,669
6
159,339
Provide tags and a correct Python 3 solution for this coding contest problem. Mahmoud wants to send a message to his friend Ehab. Their language consists of n words numbered from 1 to n. Some words have the same meaning so there are k groups of words such that all the words in some group have the same meaning. Mahmou...
instruction
0
79,670
6
159,340
Tags: dsu, greedy, implementation Correct Solution: ``` n, k, m = [int(i) for i in input().split()] origwordarr = input().split() costarr = [int(i) for i in input().split()] for i in range(k): group = [int(i) for i in input().split()] if group[0] == 1: continue minindex = min((i-1 for i in group[1:]...
output
1
79,670
6
159,341
Provide tags and a correct Python 3 solution for this coding contest problem. Mahmoud wants to send a message to his friend Ehab. Their language consists of n words numbered from 1 to n. Some words have the same meaning so there are k groups of words such that all the words in some group have the same meaning. Mahmou...
instruction
0
79,671
6
159,342
Tags: dsu, greedy, implementation Correct Solution: ``` s = input().split() n,k,m = int(s[0]), int(s[1]),int(s[2]) s=input().split() d=dict() for i in range(len(s)): d[s[i]]=i+1 priceold=input().split() price=['ZERONUM'] + list(map(int, priceold)) for i in range(k): sold=input().split() s=list(map(int,sold)...
output
1
79,671
6
159,343
Provide tags and a correct Python 3 solution for this coding contest problem. Mahmoud wants to send a message to his friend Ehab. Their language consists of n words numbered from 1 to n. Some words have the same meaning so there are k groups of words such that all the words in some group have the same meaning. Mahmou...
instruction
0
79,672
6
159,344
Tags: dsu, greedy, implementation Correct Solution: ``` def main(): n, k, m = map(int, input().split()) words = ['Zero'] + input().split() cost = dict(zip(words, [0] + [int(i) for i in input().split()])) for i in range(k): size, *group = map(int, input().split()) l = [cost[words[i]] for ...
output
1
79,672
6
159,345
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mahmoud wants to send a message to his friend Ehab. Their language consists of n words numbered from 1 to n. Some words have the same meaning so there are k groups of words such that all the wor...
instruction
0
79,673
6
159,346
Yes
output
1
79,673
6
159,347
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mahmoud wants to send a message to his friend Ehab. Their language consists of n words numbered from 1 to n. Some words have the same meaning so there are k groups of words such that all the wor...
instruction
0
79,674
6
159,348
Yes
output
1
79,674
6
159,349
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mahmoud wants to send a message to his friend Ehab. Their language consists of n words numbered from 1 to n. Some words have the same meaning so there are k groups of words such that all the wor...
instruction
0
79,675
6
159,350
Yes
output
1
79,675
6
159,351
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mahmoud wants to send a message to his friend Ehab. Their language consists of n words numbered from 1 to n. Some words have the same meaning so there are k groups of words such that all the wor...
instruction
0
79,676
6
159,352
Yes
output
1
79,676
6
159,353
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mahmoud wants to send a message to his friend Ehab. Their language consists of n words numbered from 1 to n. Some words have the same meaning so there are k groups of words such that all the wor...
instruction
0
79,677
6
159,354
No
output
1
79,677
6
159,355
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mahmoud wants to send a message to his friend Ehab. Their language consists of n words numbered from 1 to n. Some words have the same meaning so there are k groups of words such that all the wor...
instruction
0
79,678
6
159,356
No
output
1
79,678
6
159,357
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mahmoud wants to send a message to his friend Ehab. Their language consists of n words numbered from 1 to n. Some words have the same meaning so there are k groups of words such that all the wor...
instruction
0
79,679
6
159,358
No
output
1
79,679
6
159,359
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mahmoud wants to send a message to his friend Ehab. Their language consists of n words numbered from 1 to n. Some words have the same meaning so there are k groups of words such that all the wor...
instruction
0
79,680
6
159,360
No
output
1
79,680
6
159,361
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have obtained the Izua Japanese dictionary, which is the official language of Izua, and the Izua alphabet (list of letters). There are N types of letters in the Izua alphabet. The order of t...
instruction
0
79,853
6
159,706
No
output
1
79,853
6
159,707
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have obtained the Izua Japanese dictionary, which is the official language of Izua, and the Izua alphabet (list of letters). There are N types of letters in the Izua alphabet. The order of t...
instruction
0
79,854
6
159,708
No
output
1
79,854
6
159,709
Provide tags and a correct Python 3 solution for this coding contest problem. Andrey received a postcard from Irina. It contained only the words "Hello, Andrey!", and a strange string consisting of lowercase Latin letters, snowflakes and candy canes. Andrey thought that this string is an encrypted message, and decided...
instruction
0
79,957
6
159,914
Tags: constructive algorithms, implementation Correct Solution: ``` s = input() sn = "" a = int(input()) soma = 0 for i in s: if i != '?' and i != '*': soma+=1 # print(soma) soma -=a for i in s: # flag = False if i == '?': if soma >0: # flag = True # sn +='0' ...
output
1
79,957
6
159,915
Provide tags and a correct Python 3 solution for this coding contest problem. Andrey received a postcard from Irina. It contained only the words "Hello, Andrey!", and a strange string consisting of lowercase Latin letters, snowflakes and candy canes. Andrey thought that this string is an encrypted message, and decided...
instruction
0
79,958
6
159,916
Tags: constructive algorithms, implementation Correct Solution: ``` s=input() k=int(input()) c=0 t1=0 t2=0 for i in range(0,len(s)): if(s[i]!='*' and s[i]!='?'): c=c+1 elif(s[i]=='*'): t2=t2+1 else: t1=t1+1 if(c!=k): if(c<k and t2==0): print('Impossible') elif(c>k and...
output
1
79,958
6
159,917
Provide tags and a correct Python 3 solution for this coding contest problem. Andrey received a postcard from Irina. It contained only the words "Hello, Andrey!", and a strange string consisting of lowercase Latin letters, snowflakes and candy canes. Andrey thought that this string is an encrypted message, and decided...
instruction
0
79,959
6
159,918
Tags: constructive algorithms, implementation Correct Solution: ``` s=input() k=int(input()) n=len(s)-s.count('?')-s.count("*") if n<k: if not "*" in s: print("Impossible") else: x=s.index("*") f=k-n s=s[:x]+s[x-1]*f+s[x:] while '*' in s: s=s[:s.index("*")]+s[...
output
1
79,959
6
159,919
Provide tags and a correct Python 3 solution for this coding contest problem. Andrey received a postcard from Irina. It contained only the words "Hello, Andrey!", and a strange string consisting of lowercase Latin letters, snowflakes and candy canes. Andrey thought that this string is an encrypted message, and decided...
instruction
0
79,960
6
159,920
Tags: constructive algorithms, implementation Correct Solution: ``` s = input() k = int(input()) rem = k - (len(s) - sum(map(lambda x : not x.isalpha(), s)) * 2) if rem < 0 : print('Impossible') exit(0) res = [] for ch in s : if ch.isalpha() : res.append(ch) elif ch == '?': if rem == 0:...
output
1
79,960
6
159,921
Provide tags and a correct Python 3 solution for this coding contest problem. Andrey received a postcard from Irina. It contained only the words "Hello, Andrey!", and a strange string consisting of lowercase Latin letters, snowflakes and candy canes. Andrey thought that this string is an encrypted message, and decided...
instruction
0
79,961
6
159,922
Tags: constructive algorithms, implementation Correct Solution: ``` s = input() k = int(input()) ch7 = s.count("?") # Π»Π΅Π΄Π΅Π½Π΅Ρ†, ΡƒΠ΄Π°Π»ΠΈΡ‚ΡŒ ch8 = s.count("*") # снСТинка, ΠΏΠΎΠ²Ρ‚ΠΎΡ€ΠΈΡ‚ΡŒ ch = "*?" if len(s)-ch7-ch8 > k: if len(s)-ch7-ch8-ch7-ch8 > k: print("Impossible") else: cou = len(s)-ch7-ch8 - k ...
output
1
79,961
6
159,923
Provide tags and a correct Python 3 solution for this coding contest problem. Andrey received a postcard from Irina. It contained only the words "Hello, Andrey!", and a strange string consisting of lowercase Latin letters, snowflakes and candy canes. Andrey thought that this string is an encrypted message, and decided...
instruction
0
79,962
6
159,924
Tags: constructive algorithms, implementation Correct Solution: ``` s = list(str(input())) k = int(input()) letters = len(s) - s.count("*") - s.count("?") if k == letters: while "*" in s: s.remove("*") while "?" in s: s.remove("?") print("".join(s)) elif k > letters: if "*" in s: ...
output
1
79,962
6
159,925
Provide tags and a correct Python 3 solution for this coding contest problem. Andrey received a postcard from Irina. It contained only the words "Hello, Andrey!", and a strange string consisting of lowercase Latin letters, snowflakes and candy canes. Andrey thought that this string is an encrypted message, and decided...
instruction
0
79,963
6
159,926
Tags: constructive algorithms, implementation Correct Solution: ``` from sys import stdin, stdout from math import * from heapq import * from collections import * def main(): s=stdin.readline().rstrip('\n') n=int(stdin.readline()) res=[] lens=0 for c in s: if (('a'<=c) and (c<='z')): ...
output
1
79,963
6
159,927
Provide tags and a correct Python 3 solution for this coding contest problem. Andrey received a postcard from Irina. It contained only the words "Hello, Andrey!", and a strange string consisting of lowercase Latin letters, snowflakes and candy canes. Andrey thought that this string is an encrypted message, and decided...
instruction
0
79,964
6
159,928
Tags: constructive algorithms, implementation Correct Solution: ``` x=input() b=eval(input()) i=0 candys=0 stars=0 while i <len(x): if x[i]=='?': candys+=1 i+=1 elif x[i]=='*': stars+=1 i+=1 else: i+=1 string=len(x)-candys-stars i=0 a='' while i <len(x): if string==b: if x[i]!='?' and x[...
output
1
79,964
6
159,929
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Andrey received a postcard from Irina. It contained only the words "Hello, Andrey!", and a strange string consisting of lowercase Latin letters, snowflakes and candy canes. Andrey thought that t...
instruction
0
79,965
6
159,930
Yes
output
1
79,965
6
159,931
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Andrey received a postcard from Irina. It contained only the words "Hello, Andrey!", and a strange string consisting of lowercase Latin letters, snowflakes and candy canes. Andrey thought that t...
instruction
0
79,966
6
159,932
Yes
output
1
79,966
6
159,933
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Andrey received a postcard from Irina. It contained only the words "Hello, Andrey!", and a strange string consisting of lowercase Latin letters, snowflakes and candy canes. Andrey thought that t...
instruction
0
79,967
6
159,934
Yes
output
1
79,967
6
159,935
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Andrey received a postcard from Irina. It contained only the words "Hello, Andrey!", and a strange string consisting of lowercase Latin letters, snowflakes and candy canes. Andrey thought that t...
instruction
0
79,968
6
159,936
Yes
output
1
79,968
6
159,937
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Andrey received a postcard from Irina. It contained only the words "Hello, Andrey!", and a strange string consisting of lowercase Latin letters, snowflakes and candy canes. Andrey thought that t...
instruction
0
79,969
6
159,938
No
output
1
79,969
6
159,939
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Andrey received a postcard from Irina. It contained only the words "Hello, Andrey!", and a strange string consisting of lowercase Latin letters, snowflakes and candy canes. Andrey thought that t...
instruction
0
79,970
6
159,940
No
output
1
79,970
6
159,941
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Andrey received a postcard from Irina. It contained only the words "Hello, Andrey!", and a strange string consisting of lowercase Latin letters, snowflakes and candy canes. Andrey thought that t...
instruction
0
79,971
6
159,942
No
output
1
79,971
6
159,943
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Andrey received a postcard from Irina. It contained only the words "Hello, Andrey!", and a strange string consisting of lowercase Latin letters, snowflakes and candy canes. Andrey thought that t...
instruction
0
79,972
6
159,944
No
output
1
79,972
6
159,945
Provide tags and a correct Python 3 solution for this coding contest problem. Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as Β«.Β», 1 as Β«-.Β» and 2 as Β«--Β». You are to decode the Borze code, i.e. to find out the ternary number g...
instruction
0
80,287
6
160,574
Tags: expression parsing, implementation Correct Solution: ``` def scan(type): return list(map(type, input().split())) word, = scan(str) sz = len(word) i = 0 while (i < sz): if i+1 < sz and word[i] == '-': if word[i+1] == '-': print(2,end='') i += 1 elif word[i+1] == '.'...
output
1
80,287
6
160,575
Provide tags and a correct Python 3 solution for this coding contest problem. Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with n strings. Then the mechanism should be able to process quer...
instruction
0
80,387
6
160,774
Tags: binary search, data structures, hashing, string suffix structures, strings Correct Solution: ``` M=9999999999879997 def Hash(s): h=0 p=1 for c in s: h=(h+p*ord(c))%M p=(p*197)%M return h n,m=map(int,input().split()) a = set() for i in range(n): s=input() h=Hash(s) p=1 ...
output
1
80,387
6
160,775
Provide tags and a correct Python 3 solution for this coding contest problem. Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with n strings. Then the mechanism should be able to process quer...
instruction
0
80,388
6
160,776
Tags: binary search, data structures, hashing, string suffix structures, strings Correct Solution: ``` n, m = map(int, input().split()) mod = 9999999999999983 v = set() for i in range(n): s = input() l = len(s) pow = 1 h = 0 for i in range(l): h = (h + ord(s[i]) * pow) % mod pow = (pow * 203) % mod pow = 1 f...
output
1
80,388
6
160,777
Provide tags and a correct Python 3 solution for this coding contest problem. Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with n strings. Then the mechanism should be able to process quer...
instruction
0
80,389
6
160,778
Tags: binary search, data structures, hashing, string suffix structures, strings Correct Solution: ``` ''' @author: ChronoCorax ''' seed = 201 div = 9999999999999983 ABC = ['a', 'b', 'c'] def hashi(s): L = len(s) h = 0; pseed = 1 for i in range(L): h, pseed = (h + ord(s[i]) * pseed) % div, (...
output
1
80,389
6
160,779
Provide tags and a correct Python 3 solution for this coding contest problem. Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with n strings. Then the mechanism should be able to process quer...
instruction
0
80,390
6
160,780
Tags: binary search, data structures, hashing, string suffix structures, strings Correct Solution: ``` from sys import stdin from functools import reduce from collections import defaultdict data = stdin.read().split('\n') n, m = [int(x) for x in data[0].split()] B = 10007 MOD = 1000000000000000003 h = lambda s: reduce(...
output
1
80,390
6
160,781
Provide tags and a correct Python 3 solution for this coding contest problem. Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with n strings. Then the mechanism should be able to process quer...
instruction
0
80,391
6
160,782
Tags: binary search, data structures, hashing, string suffix structures, strings Correct Solution: ``` n,m=map(int,input().split()) M=9999999999999999 v=set() for i in range(n): s=input() l=len(s) pow=1 h=0 for i in range(l): h=(h+ord(s[i])*pow)%M pow=(pow*203)%M pow=1 for i in range(l): for j in range(97,...
output
1
80,391
6
160,783
Provide tags and a correct Python 3 solution for this coding contest problem. Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with n strings. Then the mechanism should be able to process quer...
instruction
0
80,392
6
160,784
Tags: binary search, data structures, hashing, string suffix structures, strings Correct Solution: ``` M=9999999999999983 def Hash(s): h=0 p=1 for c in s: h=(h+p*(ord(c)-94))%M p=(p*197)%M return h n,m=map(int,input().split()) a=set() for i in range(n): s=input() h=Hash(s) p=...
output
1
80,392
6
160,785
Provide tags and a correct Python 3 solution for this coding contest problem. Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with n strings. Then the mechanism should be able to process quer...
instruction
0
80,393
6
160,786
Tags: binary search, data structures, hashing, string suffix structures, strings Correct Solution: ``` import os import sys from io import BytesIO, IOBase _print = print BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO...
output
1
80,393
6
160,787
Provide tags and a correct Python 3 solution for this coding contest problem. Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with n strings. Then the mechanism should be able to process quer...
instruction
0
80,394
6
160,788
Tags: binary search, data structures, hashing, string suffix structures, strings Correct Solution: ``` n,m = [int(i) for i in input().split()] memory = set() M = 99999923990274967 d = 2193 for i in range(n): s = input() t = 0 p = 1 for char in s: t = (t+ord(char)*p)%M p = (p*d)%M ...
output
1
80,394
6
160,789
Provide tags and a correct Python 3 solution for this coding contest problem. Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help. Vasiliy is given n strings consisting of lowercase English letters. He wants them to be sorted in lexicographical order ...
instruction
0
80,459
6
160,918
Tags: dp, strings Correct Solution: ``` """ Author - Satwik Tiwari . 4th Oct , 2020 - Sunday """ #=============================================================================================== #importing some useful libraries. from __future__ import division, print_function from fractions import Fraction i...
output
1
80,459
6
160,919
Provide tags and a correct Python 3 solution for this coding contest problem. Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help. Vasiliy is given n strings consisting of lowercase English letters. He wants them to be sorted in lexicographical order ...
instruction
0
80,460
6
160,920
Tags: dp, strings Correct Solution: ``` def b3_hard_problems(n, c, s, t): l = r = '' a = b = 0 for i in range(n): x = y = 10 ** 16 if s[i] >= l: x = a if s[i] >= r: x = min(x, b) if t[i] >= l: y = a + c[i] if t[i] >= r: y = min(y, b + c[i]) l = s[i]; r...
output
1
80,460
6
160,921
Provide tags and a correct Python 3 solution for this coding contest problem. Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help. Vasiliy is given n strings consisting of lowercase English letters. He wants them to be sorted in lexicographical order ...
instruction
0
80,461
6
160,922
Tags: dp, strings Correct Solution: ``` I = input n, C, d = int(I()), list(map(int, I().split())), {'': 0} for i in range(n): if not d: print(-1) break s, tmp = I(), {} for s, c in ((s, 0), (s[::-1], C[i])): for prev, val in d.items(): if prev <= s and (s not ...
output
1
80,461
6
160,923
Provide tags and a correct Python 3 solution for this coding contest problem. Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help. Vasiliy is given n strings consisting of lowercase English letters. He wants them to be sorted in lexicographical order ...
instruction
0
80,462
6
160,924
Tags: dp, strings Correct Solution: ``` from collections import Counter import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or...
output
1
80,462
6
160,925
Provide tags and a correct Python 3 solution for this coding contest problem. Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help. Vasiliy is given n strings consisting of lowercase English letters. He wants them to be sorted in lexicographical order ...
instruction
0
80,463
6
160,926
Tags: dp, strings Correct Solution: ``` import math import sys n=int(input()) c=list(map(int,input().split())) f=[] for i in range(n): f.append(str(input())) INF=10**18 dp=[[0],[c[0]]] for i in range(1,n): dp[0].append(INF) if f[i]>=f[i-1]: dp[0][-1]=dp[0][-2] if f[i]>=f[i-1][::-1]: ...
output
1
80,463
6
160,927
Provide tags and a correct Python 3 solution for this coding contest problem. Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help. Vasiliy is given n strings consisting of lowercase English letters. He wants them to be sorted in lexicographical order ...
instruction
0
80,464
6
160,928
Tags: dp, strings Correct Solution: ``` from math import inf n = int(input()) l = [int(i) for i in input().split()] s = [] for i in range(n): s.append(input()) x,y = 0, l[0] for i in range(1,n): prev = s[i-1] rprev = prev[::-1] curr = s[i] rcurr= curr[::-1] xx, yy = inf, inf if curr >= pr...
output
1
80,464
6
160,929
Provide tags and a correct Python 3 solution for this coding contest problem. Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help. Vasiliy is given n strings consisting of lowercase English letters. He wants them to be sorted in lexicographical order ...
instruction
0
80,465
6
160,930
Tags: dp, strings Correct Solution: ``` n = int(input()) c = list(map(int,input().split())) ver = (0, '') rev = (0, '') for i in range(n): s = input().rstrip('\r\n') r = s[::-1] y = 1e16 n = 1e16 if ver[1] <= s: n = ver[0] if rev[1] <= s: n = min(n, rev[0]) if ver[1] <= r: y = ver[0] + c[i] if rev[1] ...
output
1
80,465
6
160,931
Provide tags and a correct Python 3 solution for this coding contest problem. Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help. Vasiliy is given n strings consisting of lowercase English letters. He wants them to be sorted in lexicographical order ...
instruction
0
80,466
6
160,932
Tags: dp, strings Correct Solution: ``` n = int(input()) v = list(map(int,input().split())) #print(v) s = [] for i in range(n): q = input() l = [] l.append(q) l.append("".join(reversed(q))) s.append(l) dp = [[1e18 for i in range(2)] for j in range(n)] flag = 1 dp[0][0]=0 dp[0][1]=v[0] for i in rang...
output
1
80,466
6
160,933