message stringlengths 2 23.8k | message_type stringclasses 2
values | message_id int64 0 1 | conversation_id int64 97 109k | cluster float64 0 0 | __index_level_0__ int64 194 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
A and B are preparing themselves for programming contests.
After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes.
A l... | instruction | 0 | 29,531 | 0 | 59,062 |
Tags: data structures, dp, two pointers
Correct Solution:
```
l = list(map(int, input().split()))
s = input()
cs = 0
ans = 0
a = []
for i in range(26): a.append({})
for i in s:
c = ord(i) - 97
x = a[c].get(cs) or 0
ans += x
cs += l[c]
y = a[c].get(cs) or 0
a[c][cs] = y + 1
print(ans)
``` | output | 1 | 29,531 | 0 | 59,063 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A and B are preparing themselves for programming contests.
After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes.
A l... | instruction | 0 | 29,532 | 0 | 59,064 |
Tags: data structures, dp, two pointers
Correct Solution:
```
import sys
read = lambda t=int: list(map(t,sys.stdin.readline().split()))
array = lambda *ds: [array(*ds[1:]) for _ in range(ds[0])] if ds else 0
from collections import Counter
xs = read()
s, = read(str)
cnt = Counter()
a = 0
res = 0
for c in s:
res ... | output | 1 | 29,532 | 0 | 59,065 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A and B are preparing themselves for programming contests.
After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A an... | instruction | 0 | 29,533 | 0 | 59,066 |
Yes | output | 1 | 29,533 | 0 | 59,067 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A and B are preparing themselves for programming contests.
After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A an... | instruction | 0 | 29,534 | 0 | 59,068 |
Yes | output | 1 | 29,534 | 0 | 59,069 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A and B are preparing themselves for programming contests.
After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A an... | instruction | 0 | 29,535 | 0 | 59,070 |
Yes | output | 1 | 29,535 | 0 | 59,071 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A and B are preparing themselves for programming contests.
After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A an... | instruction | 0 | 29,536 | 0 | 59,072 |
Yes | output | 1 | 29,536 | 0 | 59,073 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A and B are preparing themselves for programming contests.
After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A an... | instruction | 0 | 29,537 | 0 | 59,074 |
No | output | 1 | 29,537 | 0 | 59,075 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A and B are preparing themselves for programming contests.
After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A an... | instruction | 0 | 29,538 | 0 | 59,076 |
No | output | 1 | 29,538 | 0 | 59,077 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A and B are preparing themselves for programming contests.
After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A an... | instruction | 0 | 29,539 | 0 | 59,078 |
No | output | 1 | 29,539 | 0 | 59,079 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A and B are preparing themselves for programming contests.
After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A an... | instruction | 0 | 29,540 | 0 | 59,080 |
No | output | 1 | 29,540 | 0 | 59,081 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
String s of length n is called k-palindrome, if it is a palindrome itself, and its prefix and suffix of length <image> are (k - 1)-palindromes. By definition, any string (even empty) is 0-palind... | instruction | 0 | 29,643 | 0 | 59,286 |
No | output | 1 | 29,643 | 0 | 59,287 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
String s of length n is called k-palindrome, if it is a palindrome itself, and its prefix and suffix of length <image> are (k - 1)-palindromes. By definition, any string (even empty) is 0-palind... | instruction | 0 | 29,644 | 0 | 59,288 |
No | output | 1 | 29,644 | 0 | 59,289 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
String s of length n is called k-palindrome, if it is a palindrome itself, and its prefix and suffix of length <image> are (k - 1)-palindromes. By definition, any string (even empty) is 0-palind... | instruction | 0 | 29,645 | 0 | 59,290 |
No | output | 1 | 29,645 | 0 | 59,291 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
String s of length n is called k-palindrome, if it is a palindrome itself, and its prefix and suffix of length <image> are (k - 1)-palindromes. By definition, any string (even empty) is 0-palind... | instruction | 0 | 29,646 | 0 | 59,292 |
No | output | 1 | 29,646 | 0 | 59,293 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string s. You should answer n queries. The i-th query consists of integer k_i and string m_i. The answer for this query is the minimum length of such a string t that t is a subst... | instruction | 0 | 29,727 | 0 | 59,454 |
No | output | 1 | 29,727 | 0 | 59,455 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string s. You should answer n queries. The i-th query consists of integer k_i and string m_i. The answer for this query is the minimum length of such a string t that t is a subst... | instruction | 0 | 29,728 | 0 | 59,456 |
No | output | 1 | 29,728 | 0 | 59,457 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string s. You should answer n queries. The i-th query consists of integer k_i and string m_i. The answer for this query is the minimum length of such a string t that t is a subst... | instruction | 0 | 29,729 | 0 | 59,458 |
No | output | 1 | 29,729 | 0 | 59,459 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string s. You should answer n queries. The i-th query consists of integer k_i and string m_i. The answer for this query is the minimum length of such a string t that t is a subst... | instruction | 0 | 29,730 | 0 | 59,460 |
No | output | 1 | 29,730 | 0 | 59,461 |
Provide a correct Python 3 solution for this coding contest problem.
You have a string A = A_1 A_2 ... A_n consisting of lowercase English letters.
You can choose any two indices i and j such that 1 \leq i \leq j \leq n and reverse substring A_i A_{i+1} ... A_j.
You can perform this operation at most once.
How many... | instruction | 0 | 29,851 | 0 | 59,702 |
"Correct Solution:
```
from collections import Counter
a = input()
n = len(a)
c = Counter()
ans = 1
c[a[0]] = 1
for i in range(1, n):
ans += i - c[a[i]]
c[a[i]] += 1
print(ans)
``` | output | 1 | 29,851 | 0 | 59,703 |
Provide a correct Python 3 solution for this coding contest problem.
You have a string A = A_1 A_2 ... A_n consisting of lowercase English letters.
You can choose any two indices i and j such that 1 \leq i \leq j \leq n and reverse substring A_i A_{i+1} ... A_j.
You can perform this operation at most once.
How many... | instruction | 0 | 29,852 | 0 | 59,704 |
"Correct Solution:
```
import collections
a = list(input())
c = collections.Counter(a)
n = len(a)
ans = n*(n-1)//2 + 1
for v in c.values():
ans -= v*(v-1)//2
print(ans)
``` | output | 1 | 29,852 | 0 | 59,705 |
Provide a correct Python 3 solution for this coding contest problem.
You have a string A = A_1 A_2 ... A_n consisting of lowercase English letters.
You can choose any two indices i and j such that 1 \leq i \leq j \leq n and reverse substring A_i A_{i+1} ... A_j.
You can perform this operation at most once.
How many... | instruction | 0 | 29,853 | 0 | 59,706 |
"Correct Solution:
```
from collections import Counter
s = input()
n = len(s)
print(n * ~-n // 2 + 1 - sum(i * ~-i // 2 for i in Counter(s).values()))
``` | output | 1 | 29,853 | 0 | 59,707 |
Provide a correct Python 3 solution for this coding contest problem.
You have a string A = A_1 A_2 ... A_n consisting of lowercase English letters.
You can choose any two indices i and j such that 1 \leq i \leq j \leq n and reverse substring A_i A_{i+1} ... A_j.
You can perform this operation at most once.
How many... | instruction | 0 | 29,854 | 0 | 59,708 |
"Correct Solution:
```
import collections
A = input()
n = len(A)
c = collections.Counter(A)
ans = 0
for e in c:
ans += c[e] * (n - c[e])
ans = ans // 2 + 1
print(ans)
``` | output | 1 | 29,854 | 0 | 59,709 |
Provide a correct Python 3 solution for this coding contest problem.
You have a string A = A_1 A_2 ... A_n consisting of lowercase English letters.
You can choose any two indices i and j such that 1 \leq i \leq j \leq n and reverse substring A_i A_{i+1} ... A_j.
You can perform this operation at most once.
How many... | instruction | 0 | 29,855 | 0 | 59,710 |
"Correct Solution:
```
a=input()
l=len(a)
b=l*(l-1)//2+1
for i in range(97,123):
c=a.count(chr(i))
d=(c*(c-1))//2
b-=d
print(b)
``` | output | 1 | 29,855 | 0 | 59,711 |
Provide a correct Python 3 solution for this coding contest problem.
You have a string A = A_1 A_2 ... A_n consisting of lowercase English letters.
You can choose any two indices i and j such that 1 \leq i \leq j \leq n and reverse substring A_i A_{i+1} ... A_j.
You can perform this operation at most once.
How many... | instruction | 0 | 29,856 | 0 | 59,712 |
"Correct Solution:
```
A=input()
dp=[0]*26
r=0
for i,a in enumerate(A):
c=ord(a)-97
r+=i-dp[c]
dp[c]+=1
print(r+1)
``` | output | 1 | 29,856 | 0 | 59,713 |
Provide a correct Python 3 solution for this coding contest problem.
You have a string A = A_1 A_2 ... A_n consisting of lowercase English letters.
You can choose any two indices i and j such that 1 \leq i \leq j \leq n and reverse substring A_i A_{i+1} ... A_j.
You can perform this operation at most once.
How many... | instruction | 0 | 29,857 | 0 | 59,714 |
"Correct Solution:
```
A = input()
_memo = {}
ans = 1
for i,a in enumerate(A):
ans += i - _memo.setdefault(a,0)
_memo[a] += 1
#print(ans)
#print(_memo)
print(ans)
``` | output | 1 | 29,857 | 0 | 59,715 |
Provide a correct Python 3 solution for this coding contest problem.
You have a string A = A_1 A_2 ... A_n consisting of lowercase English letters.
You can choose any two indices i and j such that 1 \leq i \leq j \leq n and reverse substring A_i A_{i+1} ... A_j.
You can perform this operation at most once.
How many... | instruction | 0 | 29,858 | 0 | 59,716 |
"Correct Solution:
```
a = list(input())
l = len(a)
alphcnt = [0] * 26
for i in a:
alphcnt[ord(i) - 97] += 1
ans = (l * (l + 1)) // 2 + 1
for i in alphcnt:
ans -= (i * (i + 1)) // 2
print(ans)
``` | output | 1 | 29,858 | 0 | 59,717 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a string A = A_1 A_2 ... A_n consisting of lowercase English letters.
You can choose any two indices i and j such that 1 \leq i \leq j \leq n and reverse substring A_i A_{i+1} ... A_j.... | instruction | 0 | 29,859 | 0 | 59,718 |
Yes | output | 1 | 29,859 | 0 | 59,719 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a string A = A_1 A_2 ... A_n consisting of lowercase English letters.
You can choose any two indices i and j such that 1 \leq i \leq j \leq n and reverse substring A_i A_{i+1} ... A_j.... | instruction | 0 | 29,860 | 0 | 59,720 |
Yes | output | 1 | 29,860 | 0 | 59,721 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a string A = A_1 A_2 ... A_n consisting of lowercase English letters.
You can choose any two indices i and j such that 1 \leq i \leq j \leq n and reverse substring A_i A_{i+1} ... A_j.... | instruction | 0 | 29,861 | 0 | 59,722 |
Yes | output | 1 | 29,861 | 0 | 59,723 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a string A = A_1 A_2 ... A_n consisting of lowercase English letters.
You can choose any two indices i and j such that 1 \leq i \leq j \leq n and reverse substring A_i A_{i+1} ... A_j.... | instruction | 0 | 29,862 | 0 | 59,724 |
Yes | output | 1 | 29,862 | 0 | 59,725 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a string A = A_1 A_2 ... A_n consisting of lowercase English letters.
You can choose any two indices i and j such that 1 \leq i \leq j \leq n and reverse substring A_i A_{i+1} ... A_j.... | instruction | 0 | 29,863 | 0 | 59,726 |
No | output | 1 | 29,863 | 0 | 59,727 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a string A = A_1 A_2 ... A_n consisting of lowercase English letters.
You can choose any two indices i and j such that 1 \leq i \leq j \leq n and reverse substring A_i A_{i+1} ... A_j.... | instruction | 0 | 29,864 | 0 | 59,728 |
No | output | 1 | 29,864 | 0 | 59,729 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a string A = A_1 A_2 ... A_n consisting of lowercase English letters.
You can choose any two indices i and j such that 1 \leq i \leq j \leq n and reverse substring A_i A_{i+1} ... A_j.... | instruction | 0 | 29,865 | 0 | 59,730 |
No | output | 1 | 29,865 | 0 | 59,731 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's define a multiplication operation between a string a and a positive integer x: a ⋅ x is the string that is a result of writing x copies of a one after another. For example, "abc" ⋅~2~= "abcabc", "a" ⋅~5~= "aaaaa".
A string a is divisi... | instruction | 0 | 30,297 | 0 | 60,594 |
Tags: brute force, math, number theory, strings
Correct Solution:
```
for _ in range(int(input())):
s1=input()
s2=input()
st1=""
st2=""
if len(s1) == len(s2):
if s1==s2:
print(s1)
else:
print(-1)
continue
if len(s1)<len(s2):
st1 = s1
... | output | 1 | 30,297 | 0 | 60,595 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's define a multiplication operation between a string a and a positive integer x: a ⋅ x is the string that is a result of writing x copies of a one after another. For example, "abc" ⋅~2~= "abcabc", "a" ⋅~5~= "aaaaa".
A string a is divisi... | instruction | 0 | 30,298 | 0 | 60,596 |
Tags: brute force, math, number theory, strings
Correct Solution:
```
def qu(s):
l = len(s)
for i in range(1, l + 1):
if l % i != 0: continue
if s[:i] * (l // i) == s: return s[:i]
def gcd(a, b):
return a if b == 0 else gcd(b, a % b)
def lcm(a, b):
return a // gcd(a, b) * b
t = int(in... | output | 1 | 30,298 | 0 | 60,597 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's define a multiplication operation between a string a and a positive integer x: a ⋅ x is the string that is a result of writing x copies of a one after another. For example, "abc" ⋅~2~= "abcabc", "a" ⋅~5~= "aaaaa".
A string a is divisi... | instruction | 0 | 30,299 | 0 | 60,598 |
Tags: brute force, math, number theory, strings
Correct Solution:
```
def gcd(a,b):
if a == 0:
return b
return gcd(b % a, a)
def lcm(a,b):
return (a / gcd(a,b))* b
t = int(input())
for _ in range(t):
s = input()
t = input()
l = int(lcm(len(s),len(t)))
a1 = s*(l//len(s))
a2... | output | 1 | 30,299 | 0 | 60,599 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's define a multiplication operation between a string a and a positive integer x: a ⋅ x is the string that is a result of writing x copies of a one after another. For example, "abc" ⋅~2~= "abcabc", "a" ⋅~5~= "aaaaa".
A string a is divisi... | instruction | 0 | 30,300 | 0 | 60,600 |
Tags: brute force, math, number theory, strings
Correct Solution:
```
#from math import *
def lcm(x, y):
"""This function takes two
integers and returns the L.C.M."""
# Choose the greater number
if x > y:
greater = x
else:
greater = y
while(True):
if((greater % x == 0) and (grea... | output | 1 | 30,300 | 0 | 60,601 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's define a multiplication operation between a string a and a positive integer x: a ⋅ x is the string that is a result of writing x copies of a one after another. For example, "abc" ⋅~2~= "abcabc", "a" ⋅~5~= "aaaaa".
A string a is divisi... | instruction | 0 | 30,301 | 0 | 60,602 |
Tags: brute force, math, number theory, strings
Correct Solution:
```
import sys,collections,math
sys.setrecursionlimit(1000)
#######################################3
def in_out():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
# in_out()
#######################################
for _ in ra... | output | 1 | 30,301 | 0 | 60,603 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's define a multiplication operation between a string a and a positive integer x: a ⋅ x is the string that is a result of writing x copies of a one after another. For example, "abc" ⋅~2~= "abcabc", "a" ⋅~5~= "aaaaa".
A string a is divisi... | instruction | 0 | 30,302 | 0 | 60,604 |
Tags: brute force, math, number theory, strings
Correct Solution:
```
def gcd(a,b):
if a == 0:
return b
return gcd(b % a, a)
# Function to return LCM of two numbers
def compute_lcm(a,b):
return (a / gcd(a,b))* b
def main():
T = int(input())
for c in range(T):
s1 = input().rstrip()... | output | 1 | 30,302 | 0 | 60,605 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's define a multiplication operation between a string a and a positive integer x: a ⋅ x is the string that is a result of writing x copies of a one after another. For example, "abc" ⋅~2~= "abcabc", "a" ⋅~5~= "aaaaa".
A string a is divisi... | instruction | 0 | 30,303 | 0 | 60,606 |
Tags: brute force, math, number theory, strings
Correct Solution:
```
"""
#If FastIO not needed, use this and don't forget to strip
#import sys, math
#input = sys.stdin.readline
"""
import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
import time
from typ... | output | 1 | 30,303 | 0 | 60,607 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's define a multiplication operation between a string a and a positive integer x: a ⋅ x is the string that is a result of writing x copies of a one after another. For example, "abc" ⋅~2~= "abcabc", "a" ⋅~5~= "aaaaa".
A string a is divisi... | instruction | 0 | 30,304 | 0 | 60,608 |
Tags: brute force, math, number theory, strings
Correct Solution:
```
import sys
from math import gcd
zz=1
sys.setrecursionlimit(10**5)
if zz:
input=sys.stdin.readline
else:
sys.stdin=open('input.txt', 'r')
sys.stdout=open('all.txt','w')
di=[[-1,0],[1,0],[0,1],[0,-1]]
def fori(n):
return [fi() for i in range(n)... | output | 1 | 30,304 | 0 | 60,609 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's define a multiplication operation between a string a and a positive integer x: a ⋅ x is the string that is a result of writing x copies of a one after another. For example, "abc" ⋅~2~= "ab... | instruction | 0 | 30,305 | 0 | 60,610 |
Yes | output | 1 | 30,305 | 0 | 60,611 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's define a multiplication operation between a string a and a positive integer x: a ⋅ x is the string that is a result of writing x copies of a one after another. For example, "abc" ⋅~2~= "ab... | instruction | 0 | 30,306 | 0 | 60,612 |
Yes | output | 1 | 30,306 | 0 | 60,613 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's define a multiplication operation between a string a and a positive integer x: a ⋅ x is the string that is a result of writing x copies of a one after another. For example, "abc" ⋅~2~= "ab... | instruction | 0 | 30,307 | 0 | 60,614 |
Yes | output | 1 | 30,307 | 0 | 60,615 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's define a multiplication operation between a string a and a positive integer x: a ⋅ x is the string that is a result of writing x copies of a one after another. For example, "abc" ⋅~2~= "ab... | instruction | 0 | 30,308 | 0 | 60,616 |
Yes | output | 1 | 30,308 | 0 | 60,617 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's define a multiplication operation between a string a and a positive integer x: a ⋅ x is the string that is a result of writing x copies of a one after another. For example, "abc" ⋅~2~= "ab... | instruction | 0 | 30,309 | 0 | 60,618 |
No | output | 1 | 30,309 | 0 | 60,619 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's define a multiplication operation between a string a and a positive integer x: a ⋅ x is the string that is a result of writing x copies of a one after another. For example, "abc" ⋅~2~= "ab... | instruction | 0 | 30,310 | 0 | 60,620 |
No | output | 1 | 30,310 | 0 | 60,621 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's define a multiplication operation between a string a and a positive integer x: a ⋅ x is the string that is a result of writing x copies of a one after another. For example, "abc" ⋅~2~= "ab... | instruction | 0 | 30,311 | 0 | 60,622 |
No | output | 1 | 30,311 | 0 | 60,623 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's define a multiplication operation between a string a and a positive integer x: a ⋅ x is the string that is a result of writing x copies of a one after another. For example, "abc" ⋅~2~= "ab... | instruction | 0 | 30,312 | 0 | 60,624 |
No | output | 1 | 30,312 | 0 | 60,625 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a string s of length n consisting only of the characters 0 and 1.
You perform the following operation until the string becomes empty: choose some consecutive substring of equal characters, erase it from the string and glue the... | instruction | 0 | 30,333 | 0 | 60,666 |
Tags: greedy, math
Correct Solution:
```
for _ in range(int(input())):
n, a, b = map(int, input().split())
prev, cnt = 0, 0
for c in input().rstrip():
if c != prev:
prev, cnt = c, cnt+1
cnt = cnt // 2 + 1
if b < 0:
print(n*a + cnt*b)
else:
print(n * (a + b))
... | output | 1 | 30,333 | 0 | 60,667 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.