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.
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If there are multiple such strings with minimum cost — find any of them.
Input
The only line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5; 1 ≤ k ≤ 26).
Output
Print the string s such that it consists of n characters, each its character is one of the k first Latin letters, and it has the minimum possible cost among all these strings. If there are multiple such strings — print any of them.
Examples
Input
9 4
Output
aabacadbb
Input
5 1
Output
aaaaa
Input
10 26
Output
codeforces
|
instruction
| 0
| 101,439
| 0
| 202,878
|
Tags: brute force, constructive algorithms, graphs, greedy, strings
Correct Solution:
```
n,k=map(int,input().split())
out=[]
for i in range(k):
out.append(chr(97+i))
for j in range(i+1,k):
out.append(chr(97+i))
out.append(chr(97+j))
while len(out)<n:
out+=out
print("".join(out[:n]))
```
|
output
| 1
| 101,439
| 0
| 202,879
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If there are multiple such strings with minimum cost — find any of them.
Input
The only line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5; 1 ≤ k ≤ 26).
Output
Print the string s such that it consists of n characters, each its character is one of the k first Latin letters, and it has the minimum possible cost among all these strings. If there are multiple such strings — print any of them.
Examples
Input
9 4
Output
aabacadbb
Input
5 1
Output
aaaaa
Input
10 26
Output
codeforces
|
instruction
| 0
| 101,440
| 0
| 202,880
|
Tags: brute force, constructive algorithms, graphs, greedy, strings
Correct Solution:
```
n, k = [int(s) for s in input().split(" ")]
s = ""
for i in range(k):
s += chr(i+97)
for j in range(i+1, k):
s += chr(i+97) + chr(j+97)
while len(s) < n:
s *= 2
print(s[:n])
```
|
output
| 1
| 101,440
| 0
| 202,881
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If there are multiple such strings with minimum cost — find any of them.
Input
The only line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5; 1 ≤ k ≤ 26).
Output
Print the string s such that it consists of n characters, each its character is one of the k first Latin letters, and it has the minimum possible cost among all these strings. If there are multiple such strings — print any of them.
Examples
Input
9 4
Output
aabacadbb
Input
5 1
Output
aaaaa
Input
10 26
Output
codeforces
|
instruction
| 0
| 101,441
| 0
| 202,882
|
Tags: brute force, constructive algorithms, graphs, greedy, strings
Correct Solution:
```
import sys,heapq,math
from collections import defaultdict
input=sys.stdin.readline
n,k=map(int,input().split())
countarr=[[0 for _ in range(k)] for _ in range(k)]
res=['a'] #'a'->97
for i in range(1,n):
row=ord(res[-1])-97
mini=float('inf')
col=-1
for j in range(k):
if(countarr[row][j]<=mini):
mini=countarr[row][j]
col=j
res.append(chr(97+col))
countarr[row][col]+=1
print("".join(res))
```
|
output
| 1
| 101,441
| 0
| 202,883
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If there are multiple such strings with minimum cost — find any of them.
Input
The only line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5; 1 ≤ k ≤ 26).
Output
Print the string s such that it consists of n characters, each its character is one of the k first Latin letters, and it has the minimum possible cost among all these strings. If there are multiple such strings — print any of them.
Examples
Input
9 4
Output
aabacadbb
Input
5 1
Output
aaaaa
Input
10 26
Output
codeforces
|
instruction
| 0
| 101,442
| 0
| 202,884
|
Tags: brute force, constructive algorithms, graphs, greedy, strings
Correct Solution:
```
n, k = map(int,input().split())
s = 'abcdefghijklmnopqrstuvwxyz'
s = s[:k]
dic = {}
#for c1 in s:
# for c2 in s:
# dic[c1+c2] = 0
ans = ""
for i in range(k):
ans += chr(97+i)
for j in range(i+1,k):
ans += chr(97+i) + chr(97+j)
m = len(ans)
ans = ans*(n//m) + ans[:n%m]
print(ans)
```
|
output
| 1
| 101,442
| 0
| 202,885
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If there are multiple such strings with minimum cost — find any of them.
Input
The only line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5; 1 ≤ k ≤ 26).
Output
Print the string s such that it consists of n characters, each its character is one of the k first Latin letters, and it has the minimum possible cost among all these strings. If there are multiple such strings — print any of them.
Examples
Input
9 4
Output
aabacadbb
Input
5 1
Output
aaaaa
Input
10 26
Output
codeforces
|
instruction
| 0
| 101,443
| 0
| 202,886
|
Tags: brute force, constructive algorithms, graphs, greedy, strings
Correct Solution:
```
a = list('abcdefghijklmnopqrstuvwxyz')
n, k = map(int, input().split())
if k >= n:
print(*a[0:n], sep = '')
else:
ans = ''
for i in range(k):
ans += a[i]
for j in range(i + 1, k): ans += a[i] + a[j]
while n > len(ans): ans *= 2
print(ans[0:n])
```
|
output
| 1
| 101,443
| 0
| 202,887
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If there are multiple such strings with minimum cost — find any of them.
Input
The only line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5; 1 ≤ k ≤ 26).
Output
Print the string s such that it consists of n characters, each its character is one of the k first Latin letters, and it has the minimum possible cost among all these strings. If there are multiple such strings — print any of them.
Examples
Input
9 4
Output
aabacadbb
Input
5 1
Output
aaaaa
Input
10 26
Output
codeforces
Submitted Solution:
```
import sys
ints = (int(x) for x in sys.stdin.read().split())
sys.setrecursionlimit(3000)
def magic(N=26):
ans = [None]*(N+1)
ans[1] = [(0,0)]
for k in range(2, N+1):
f = [(0,k-1), (k-1,k-1), (k-1,0)]
for i,j in ans[k-1]:
if i==j!=0:
f.append((i, k-1))
f.append((k-1, j))
f.append((i,j))
ans[k] = f
return ans
def main():
n, k = (next(ints) for i in range(2))
f = [i for i,j in magic(k)[k]]
#print(f)
f = ''.join(chr(97+f[i]) for i in range(len(f)))
ans = (f * (1+(n//len(f))))[:n]
assert len(ans)==n
print(ans)
return
main()
```
|
instruction
| 0
| 101,444
| 0
| 202,888
|
Yes
|
output
| 1
| 101,444
| 0
| 202,889
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If there are multiple such strings with minimum cost — find any of them.
Input
The only line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5; 1 ≤ k ≤ 26).
Output
Print the string s such that it consists of n characters, each its character is one of the k first Latin letters, and it has the minimum possible cost among all these strings. If there are multiple such strings — print any of them.
Examples
Input
9 4
Output
aabacadbb
Input
5 1
Output
aaaaa
Input
10 26
Output
codeforces
Submitted Solution:
```
import random
import sys
def input():
return sys.stdin.readline().rstrip()
def slv(n, k):
"""
I feel really sad I could not solve this in time...
However,It's really worthful that I could recognize I'm not good at construction!s
"""
def construct(K):
if K == 1:
return [1, 1]
else:
tmp = [1, K]
for j in range(K - 1, 1, -1):
tmp.append(K)
tmp.append(j)
tmp.append(K)
return tmp + construct(K - 1)
tmpans = construct(k)[:-1] * (n//(k * k) + 10)
assert all(v <= k for v in tmpans)
ans = list(map(lambda x: chr(x + ord('a') - 1), tmpans))[:n]
print("".join(ans))
return
def main():
n, k = map(int, input().split())
slv(n, k)
return
if __name__ == "__main__":
main()
```
|
instruction
| 0
| 101,445
| 0
| 202,890
|
Yes
|
output
| 1
| 101,445
| 0
| 202,891
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If there are multiple such strings with minimum cost — find any of them.
Input
The only line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5; 1 ≤ k ≤ 26).
Output
Print the string s such that it consists of n characters, each its character is one of the k first Latin letters, and it has the minimum possible cost among all these strings. If there are multiple such strings — print any of them.
Examples
Input
9 4
Output
aabacadbb
Input
5 1
Output
aaaaa
Input
10 26
Output
codeforces
Submitted Solution:
```
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
#import io,os; input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline #for pypy
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]
from random import shuffle
n,k = ip()
x = 'abcdefghijklmnopqrstuvwxyz'[:k]
st = []
for i in range(k):
st.append(x[i])
for j in range(i+1,k):
st.append(x[i])
st.append(x[j])
s = ''.join(st)
while len(s) < n:
s += s
print(s[:n])
```
|
instruction
| 0
| 101,446
| 0
| 202,892
|
Yes
|
output
| 1
| 101,446
| 0
| 202,893
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If there are multiple such strings with minimum cost — find any of them.
Input
The only line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5; 1 ≤ k ≤ 26).
Output
Print the string s such that it consists of n characters, each its character is one of the k first Latin letters, and it has the minimum possible cost among all these strings. If there are multiple such strings — print any of them.
Examples
Input
9 4
Output
aabacadbb
Input
5 1
Output
aaaaa
Input
10 26
Output
codeforces
Submitted Solution:
```
n, k = map(int, input().split())
ans = 'a'
cycle = 1
tmp = ''
if k==1:
print('a'*n)
elif k==2:
tmp = 'aabba'
if n<=5:
print(tmp[:n])
else:
ans = tmp
n -= 5
while n>=4:
ans += tmp[1:]
n -= 4
if n>0:
ans += tmp[1:1+n]
print(ans)
else:
tmp = 'aabba'
cnt = 3
while cnt<=k:
cnt2 = 2
while cnt2<=cnt:
tmp += chr(cnt-1+ord('a'))
tmp += chr(cnt2-1+ord('a'))
cnt2 += 1
tmp += 'a'
cnt += 1
if n<=len(tmp):
print(tmp[:n])
else:
ans = tmp
n -= len(tmp)
while n>=len(tmp)-1:
ans += tmp[1:]
n -= len(tmp)-1
if n>0:
ans += tmp[1:1+n]
print(ans)
```
|
instruction
| 0
| 101,447
| 0
| 202,894
|
Yes
|
output
| 1
| 101,447
| 0
| 202,895
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If there are multiple such strings with minimum cost — find any of them.
Input
The only line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5; 1 ≤ k ≤ 26).
Output
Print the string s such that it consists of n characters, each its character is one of the k first Latin letters, and it has the minimum possible cost among all these strings. If there are multiple such strings — print any of them.
Examples
Input
9 4
Output
aabacadbb
Input
5 1
Output
aaaaa
Input
10 26
Output
codeforces
Submitted Solution:
```
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
# from fractions import *
# from heapq import*
from bisect import *
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
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")
ALPHA='abcdefghijklmnopqrstuvwxyz'
M = 10**9 + 7
EPS = 1e-6
def Ceil(a,b): return a//b+int(a%b>0)
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]
#-------------------------code---------------------------#
# vsInput()
for _ in range(1):
n,k = value()
s = input()
have = defaultdict(set)
ans = []
for i in range(k):
ans.extend([ALPHA[i]]*2)
have[ans[-1]].add(ans[-1])
if(i+1<k): have[ans[-1]].add(ALPHA[i+1])
# print(ans)
while(len(ans) < n):
got = False
for i in ALPHA[:k]:
if(i not in have[ans[-1]]):
have[ans[-1]].add(i)
ans.append(i)
got = True
if(not got): break
ans = ans + ans[::-1]
need = Ceil(n,len(ans))
ans = ans * need
print(*ans[:n],sep = "")
```
|
instruction
| 0
| 101,448
| 0
| 202,896
|
No
|
output
| 1
| 101,448
| 0
| 202,897
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If there are multiple such strings with minimum cost — find any of them.
Input
The only line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5; 1 ≤ k ≤ 26).
Output
Print the string s such that it consists of n characters, each its character is one of the k first Latin letters, and it has the minimum possible cost among all these strings. If there are multiple such strings — print any of them.
Examples
Input
9 4
Output
aabacadbb
Input
5 1
Output
aaaaa
Input
10 26
Output
codeforces
Submitted Solution:
```
# cook your dish here
from collections import defaultdict,OrderedDict,Counter
from sys import stdin,stdout
from bisect import bisect_left,bisect_right
# import numpy as np
from queue import Queue,PriorityQueue
from heapq import *
from statistics import *
from math import *
import fractions
import copy
from copy import deepcopy
import sys
import io
sys.setrecursionlimit(10000)
import math
import os
import bisect
import collections
mod=int(pow(10,9))+7
import random
from random import *
from time import time;
def ncr(n, r, p=mod):
num = den = 1
for i in range(r):
num = (num * (n - i)) % p
den = (den * (i + 1)) % p
return (num * pow(den,
p - 2, p)) % p
def normalncr(n,r):
r=min(r,n-r)
count=1;
for i in range(n-r,n+1):
count*=i;
for i in range(1,r+1):
count//=i;
return count
inf=float("inf")
adj=defaultdict(set)
visited=defaultdict(int)
def addedge(a,b):
adj[a].add(b)
adj[b].add(a)
def bfs(v):
q=Queue()
q.put(v)
visited[v]=1
while q.qsize()>0:
s=q.get_nowait()
print(s)
for i in adj[s]:
if visited[i]==0:
q.put(i)
visited[i]=1
def dfs(v,visited):
if visited[v]==1:
return;
visited[v]=1
print(v)
for i in adj[v]:
dfs(i,visited)
# a9=pow(10,6)+10
# prime = [True for i in range(a9 + 1)]
# def SieveOfEratosthenes(n):
# p = 2
# while (p * p <= n):
# if (prime[p] == True):
# for i in range(p * p, n + 1, p):
# prime[i] = False
# p += 1
# SieveOfEratosthenes(a9)
# prime_number=[]
# for i in range(2,a9):
# if prime[i]:
# prime_number.append(i)
def reverse_bisect_right(a, x, lo=0, hi=None):
if lo < 0:
raise ValueError('lo must be non-negative')
if hi is None:
hi = len(a)
while lo < hi:
mid = (lo+hi)//2
if x > a[mid]:
hi = mid
else:
lo = mid+1
return lo
def reverse_bisect_left(a, x, lo=0, hi=None):
if lo < 0:
raise ValueError('lo must be non-negative')
if hi is None:
hi = len(a)
while lo < hi:
mid = (lo+hi)//2
if x >= a[mid]:
hi = mid
else:
lo = mid+1
return lo
def get_list():
return list(map(int,input().split()))
def get_str_list_in_int():
return [int(i) for i in list(input())]
def get_str_list():
return list(input())
def get_map():
return map(int,input().split())
def input_int():
return int(input())
def matrix(a,b):
return [[0 for i in range(b)] for j in range(a)]
def swap(a,b):
return b,a
def find_gcd(l):
a=l[0]
for i in range(len(l)):
a=gcd(a,l[i])
return a;
def is_prime(n):
sqrta=int(sqrt(n))
for i in range(2,sqrta+1):
if n%i==0:
return 0;
return 1;
def prime_factors(n):
while n % 2 == 0:
return [2]+prime_factors(n//2)
sqrta = int(sqrt(n))
for i in range(3,sqrta+1,2):
if n%i==0:
return [i]+prime_factors(n//i)
return [n]
def p(a):
if type(a)==str:
print(a+"\n")
else:
print(str(a)+"\n")
def ps(a):
if type(a)==str:
print(a)
else:
print(str(a))
def kth_no_not_div_by_n(n,k):
return k+(k-1)//(n-1)
def forward_array(l):
n=len(l)
stack = []
forward=[0]*n
for i in range(len(l) - 1, -1, -1):
while len(stack) and l[stack[-1]] < l[i]:
stack.pop()
if len(stack) == 0:
forward[i] = len(l);
else:
forward[i] = stack[-1]
stack.append(i)
return forward;
def backward_array(l):
n=len(l)
stack = []
backward=[0]*n
for i in range(len(l)):
while len(stack) and l[stack[-1]] < l[i]:
stack.pop()
if len(stack) == 0:
backward[i] = -1;
else:
backward[i] = stack[-1]
stack.append(i)
return backward
nc="NO"
yc="YES"
ns="No"
ys="Yes"
# import math as mt
# MAXN=10**7
# spf = [0 for i in range(MAXN)]
# def sieve():
# spf[1] = 1
# for i in range(2, MAXN):
# # marking smallest prime factor
# # for every number to be itself.
# spf[i] = i
#
# # separately marking spf for
# # every even number as 2
# for i in range(4, MAXN, 2):
# spf[i] = 2
#
# for i in range(3, mt.ceil(mt.sqrt(MAXN))):
#
# # checking if i is prime
# if (spf[i] == i):
#
# # marking SPF for all numbers
# # divisible by i
# for j in range(i * i, MAXN, i):
#
# # marking spf[j] if it is
# # not previously marked
# if (spf[j] == j):
# spf[j] = i
# def getFactorization(x):
# ret = list()
# while (x != 1):
# ret.append(spf[x])
# x = x // spf[x]
#
# return ret
# sieve()
# if(os.path.exists('input.txt')):
# sys.stdin = open("input.txt","r") ; sys.stdout = open("output.txt","w")
# input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
# input=stdin.readline
# print=stdout.write
def char(a):
return chr(a+97)
for i in range(1):
n,k=get_map()
# a=[chr(i+97) for i in range(k)]
# b=a[::-1]
# c=a[::2]+a[1::2]
# d=b[::2]+b[1::2]
# arr=[]
# gamma=[]
# for i in range(ceil(n/k)):
# if(i%4==0):
# gamma+=a;
# elif i%4==1:
# gamma+=b;
# elif i%4==2:
# gamma+=c;
# elif i%4==3:
# gamma+=d
# print("".join(gamma[:n]))
arr=[]
if k==1:
print('a'*n)
continue
for i in range(k):
for j in range(i+1,k):
arr.append(char(i))
arr.append(char(j))
arr+=arr[::-1]
while len(arr)<n:
arr+=arr
print("".join(arr[:n]))
```
|
instruction
| 0
| 101,449
| 0
| 202,898
|
No
|
output
| 1
| 101,449
| 0
| 202,899
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If there are multiple such strings with minimum cost — find any of them.
Input
The only line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5; 1 ≤ k ≤ 26).
Output
Print the string s such that it consists of n characters, each its character is one of the k first Latin letters, and it has the minimum possible cost among all these strings. If there are multiple such strings — print any of them.
Examples
Input
9 4
Output
aabacadbb
Input
5 1
Output
aaaaa
Input
10 26
Output
codeforces
Submitted Solution:
```
# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
# import threading
from math import inf, log2
from collections import defaultdict
# threading.stack_size(10**8)
mod = 10 ** 9 + 7
mod1 = 998244353
# ------------------------------warmup----------------------------
import os
import sys
from io import BytesIO, IOBase
# sys.setrecursionlimit(300000)
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")
#----------------------------------------------------------------------------------------------------------------
class LazySegmentTree:
def __init__(self, array, func=max):
self.n = len(array)
self.size = 2**(int(log2(self.n-1))+1) if self.n != 1 else 1
self.func = func
self.default = 0 if self.func != min else inf
self.data = [self.default] * (2 * self.size)
self.lazy = [0] * (2 * self.size)
self.process(array)
def process(self, array):
self.data[self.size : self.size+self.n] = array
for i in range(self.size-1, -1, -1):
self.data[i] = self.func(self.data[2*i], self.data[2*i+1])
def push(self, index):
"""Push the information of the root to it's children!"""
self.lazy[2*index] += self.lazy[index]
self.lazy[2*index+1] += self.lazy[index]
self.data[2 * index] += self.lazy[index]
self.data[2 * index + 1] += self.lazy[index]
self.lazy[index] = 0
def build(self, index):
"""Build data with the new changes!"""
index >>= 1
while index:
self.data[index] = self.func(self.data[2*index], self.data[2*index+1]) + self.lazy[index]
index >>= 1
def query(self, alpha, omega):
"""Returns the result of function over the range (inclusive)!"""
res = self.default
alpha += self.size
omega += self.size + 1
for i in range(len(bin(alpha)[2:])-1, 0, -1):
self.push(alpha >> i)
for i in range(len(bin(omega-1)[2:])-1, 0, -1):
self.push((omega-1) >> i)
while alpha < omega:
if alpha & 1:
res = self.func(res, self.data[alpha])
alpha += 1
if omega & 1:
omega -= 1
res = self.func(res, self.data[omega])
alpha >>= 1
omega >>= 1
return res
def update(self, alpha, omega, value):
"""Increases all elements in the range (inclusive) by given value!"""
alpha += self.size
omega += self.size + 1
l, r = alpha, omega
while alpha < omega:
if alpha & 1:
self.data[alpha] += value
self.lazy[alpha] += value
alpha += 1
if omega & 1:
omega -= 1
self.data[omega] += value
self.lazy[omega] += value
alpha >>= 1
omega >>= 1
self.build(l)
self.build(r-1)
#---------------------------------------------------------------------------------------------
class SegmentTree:
def __init__(self, data, default=0, func=lambda a, b: a + b):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
# -------------------------------iye ha chutiya zindegi-------------------------------------
class Factorial:
def __init__(self, MOD):
self.MOD = MOD
self.factorials = [1, 1]
self.invModulos = [0, 1]
self.invFactorial_ = [1, 1]
def calc(self, n):
if n <= -1:
print("Invalid argument to calculate n!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.factorials):
return self.factorials[n]
nextArr = [0] * (n + 1 - len(self.factorials))
initialI = len(self.factorials)
prev = self.factorials[-1]
m = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = prev * i % m
self.factorials += nextArr
return self.factorials[n]
def inv(self, n):
if n <= -1:
print("Invalid argument to calculate n^(-1)")
print("n must be non-negative value. But the argument was " + str(n))
exit()
p = self.MOD
pi = n % p
if pi < len(self.invModulos):
return self.invModulos[pi]
nextArr = [0] * (n + 1 - len(self.invModulos))
initialI = len(self.invModulos)
for i in range(initialI, min(p, n + 1)):
next = -self.invModulos[p % i] * (p // i) % p
self.invModulos.append(next)
return self.invModulos[pi]
def invFactorial(self, n):
if n <= -1:
print("Invalid argument to calculate (n^(-1))!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.invFactorial_):
return self.invFactorial_[n]
self.inv(n) # To make sure already calculated n^-1
nextArr = [0] * (n + 1 - len(self.invFactorial_))
initialI = len(self.invFactorial_)
prev = self.invFactorial_[-1]
p = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
self.invFactorial_ += nextArr
return self.invFactorial_[n]
class Combination:
def __init__(self, MOD):
self.MOD = MOD
self.factorial = Factorial(MOD)
def ncr(self, n, k):
if k < 0 or n < k:
return 0
k = min(k, n - k)
f = self.factorial
return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
# --------------------------------------iye ha combinations ka zindegi---------------------------------
def powm(a, n, m):
if a == 1 or n == 0:
return 1
if n % 2 == 0:
s = powm(a, n // 2, m)
return s * s % m
else:
return a * powm(a, n - 1, m) % m
# --------------------------------------iye ha power ka zindegi---------------------------------
def sort_list(list1, list2):
zipped_pairs = zip(list2, list1)
z = [x for _, x in sorted(zipped_pairs)]
return z
# --------------------------------------------------product----------------------------------------
def product(l):
por = 1
for i in range(len(l)):
por *= l[i]
return por
# --------------------------------------------------binary----------------------------------------
def binarySearchCount(arr, n, key):
left = 0
right = n - 1
count = 0
while (left <= right):
mid = int((right + left) / 2)
# Check if middle element is
# less than or equal to key
if (arr[mid] < key):
count = mid + 1
left = mid + 1
# If key is smaller, ignore right half
else:
right = mid - 1
return count
# --------------------------------------------------binary----------------------------------------
def countdig(n):
c = 0
while (n > 0):
n //= 10
c += 1
return c
def binary(x, length):
y = bin(x)[2:]
return y if len(y) >= length else "0" * (length - len(y)) + y
def countGreater(arr, n, k):
l = 0
r = n - 1
# Stores the index of the left most element
# from the array which is greater than k
leftGreater = n
# Finds number of elements greater than k
while (l <= r):
m = int(l + (r - l) / 2)
if (arr[m] >= k):
leftGreater = m
r = m - 1
# If mid element is less than
# or equal to k update l
else:
l = m + 1
# Return the count of elements
# greater than k
return (n - leftGreater)
# --------------------------------------------------binary------------------------------------
class Node:
def __init__(self, data):
self.data = data
self.count = 0
self.left = None # left node for 0
self.right = None # right node for 1
class BinaryTrie:
def __init__(self):
self.root = Node(0)
def insert(self, pre_xor):
self.temp = self.root
k = 1 << 32
for i in range(31, -1, -1):
k //= 2
val = pre_xor & k
if val:
if not self.temp.right:
self.temp.right = Node(0)
self.temp = self.temp.right
self.temp.count += 1
if not val:
if not self.temp.left:
self.temp.left = Node(0)
self.temp = self.temp.left
self.temp.count += 1
self.temp.data = pre_xor
def query(self, p):
ans = 0
self.temp = self.root
k = 1 << 32
for i in range(31, -1, -1):
k //= 2
val = p & k
if val == 0:
if self.temp.right and self.temp.right.count > 0:
self.temp = self.temp.right
ans ^= k
else:
self.temp = self.temp.left
else:
if self.temp.left and self.temp.left.count > 0:
self.temp = self.temp.left
ans ^= k
else:
self.temp = self.temp.right
return ans
# -------------------------bin trie-------------------------------------------
for ik in range(1):
n,k=map(int,input().split())
if k==1:
print('a'*n)
continue
s=[]
c=n
ap=[]
for i in range(k):
ap.append(chr(i+97))
for i in range(k):
for j in range(i+1,k):
s.append(ap[i]+ap[j])
for j in range(i):
s.append(ap[i]+ap[j])
i=0
ans=""
while(c>1):
ans+=s[i%len(s)]
c-=2
i+=1
if c==1:
ans+=s[i%len(s)][0]
print(ans)
```
|
instruction
| 0
| 101,450
| 0
| 202,900
|
No
|
output
| 1
| 101,450
| 0
| 202,901
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If there are multiple such strings with minimum cost — find any of them.
Input
The only line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5; 1 ≤ k ≤ 26).
Output
Print the string s such that it consists of n characters, each its character is one of the k first Latin letters, and it has the minimum possible cost among all these strings. If there are multiple such strings — print any of them.
Examples
Input
9 4
Output
aabacadbb
Input
5 1
Output
aaaaa
Input
10 26
Output
codeforces
Submitted Solution:
```
from sys import stdin,stdout
stdin.readline
def mp(): return list(map(int, stdin.readline().strip().split()))
def it():return int(stdin.readline().strip())
from collections import defaultdict as dd,Counter as C,deque
from math import ceil,gcd,sqrt,factorial
n,k=mp()
v=[]
x = n%k
n = n-x
while n:
for i in range(k):
v.append(str(chr(i+97)))
n -= k
for i in range(x):
v.append(str(chr(i+97)))
print(''.join(v))
```
|
instruction
| 0
| 101,451
| 0
| 202,902
|
No
|
output
| 1
| 101,451
| 0
| 202,903
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya once wrote a sad love song and shared it to Vasya. The song is a string consisting of lowercase English letters. Vasya made up q questions about this song. Each question is about a subsegment of the song starting from the l-th letter to the r-th letter. Vasya considers a substring made up from characters on this segment and repeats each letter in the subsegment k times, where k is the index of the corresponding letter in the alphabet. For example, if the question is about the substring "abbcb", then Vasya repeats letter 'a' once, each of the letters 'b' twice, letter 'c" three times, so that the resulting string is "abbbbcccbb", its length is 10. Vasya is interested about the length of the resulting string.
Help Petya find the length of each string obtained by Vasya.
Input
The first line contains two integers n and q (1≤ n≤ 100 000, 1≤ q ≤ 100 000) — the length of the song and the number of questions.
The second line contains one string s — the song, consisting of n lowercase letters of English letters.
Vasya's questions are contained in the next q lines. Each line contains two integers l and r (1 ≤ l ≤ r ≤ n) — the bounds of the question.
Output
Print q lines: for each question print the length of the string obtained by Vasya.
Examples
Input
7 3
abacaba
1 3
2 5
1 7
Output
4
7
11
Input
7 4
abbabaa
1 3
5 7
6 6
2 4
Output
5
4
1
5
Input
13 7
sonoshikumiwo
1 5
2 10
7 7
1 13
4 8
2 5
3 9
Output
82
125
9
191
62
63
97
Note
In the first example Vasya is interested in three questions. In the first question Vasya considers the substring "aba", that transforms to "abba", so the answer is equal to 4. In the second question Vasya considers "baca", that transforms to "bbaccca", so the answer is 7. In the third question Vasya considers the string "abacaba",that transforms to "abbacccabba" of length 11.
|
instruction
| 0
| 101,452
| 0
| 202,904
|
Tags: dp, implementation, strings
Correct Solution:
```
n, q = map(int, input().split())
s = input()
ps = [0 for i in range(n+1)]
for i in range(n):
ps[i+1] += ps[i]+ord(s[i]) % 96
for _ in range(q):
l, r = map(int, input().split())
print(ps[r]-ps[l-1])
```
|
output
| 1
| 101,452
| 0
| 202,905
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya once wrote a sad love song and shared it to Vasya. The song is a string consisting of lowercase English letters. Vasya made up q questions about this song. Each question is about a subsegment of the song starting from the l-th letter to the r-th letter. Vasya considers a substring made up from characters on this segment and repeats each letter in the subsegment k times, where k is the index of the corresponding letter in the alphabet. For example, if the question is about the substring "abbcb", then Vasya repeats letter 'a' once, each of the letters 'b' twice, letter 'c" three times, so that the resulting string is "abbbbcccbb", its length is 10. Vasya is interested about the length of the resulting string.
Help Petya find the length of each string obtained by Vasya.
Input
The first line contains two integers n and q (1≤ n≤ 100 000, 1≤ q ≤ 100 000) — the length of the song and the number of questions.
The second line contains one string s — the song, consisting of n lowercase letters of English letters.
Vasya's questions are contained in the next q lines. Each line contains two integers l and r (1 ≤ l ≤ r ≤ n) — the bounds of the question.
Output
Print q lines: for each question print the length of the string obtained by Vasya.
Examples
Input
7 3
abacaba
1 3
2 5
1 7
Output
4
7
11
Input
7 4
abbabaa
1 3
5 7
6 6
2 4
Output
5
4
1
5
Input
13 7
sonoshikumiwo
1 5
2 10
7 7
1 13
4 8
2 5
3 9
Output
82
125
9
191
62
63
97
Note
In the first example Vasya is interested in three questions. In the first question Vasya considers the substring "aba", that transforms to "abba", so the answer is equal to 4. In the second question Vasya considers "baca", that transforms to "bbaccca", so the answer is 7. In the third question Vasya considers the string "abacaba",that transforms to "abbacccabba" of length 11.
|
instruction
| 0
| 101,453
| 0
| 202,906
|
Tags: dp, implementation, strings
Correct Solution:
```
n,q=[int(x) for x in input().split()]
l=input()
s=[]
s.append(ord(l[0])-96)
for i in range(1,n):
s.append(s[i-1]+ord(l[i])-96)
while q:
a,b=[int(x) for x in input().split()]
if a!=1:
print(s[b-1]-s[a-2])
else:
print(s[b-1])
q-=1
```
|
output
| 1
| 101,453
| 0
| 202,907
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya once wrote a sad love song and shared it to Vasya. The song is a string consisting of lowercase English letters. Vasya made up q questions about this song. Each question is about a subsegment of the song starting from the l-th letter to the r-th letter. Vasya considers a substring made up from characters on this segment and repeats each letter in the subsegment k times, where k is the index of the corresponding letter in the alphabet. For example, if the question is about the substring "abbcb", then Vasya repeats letter 'a' once, each of the letters 'b' twice, letter 'c" three times, so that the resulting string is "abbbbcccbb", its length is 10. Vasya is interested about the length of the resulting string.
Help Petya find the length of each string obtained by Vasya.
Input
The first line contains two integers n and q (1≤ n≤ 100 000, 1≤ q ≤ 100 000) — the length of the song and the number of questions.
The second line contains one string s — the song, consisting of n lowercase letters of English letters.
Vasya's questions are contained in the next q lines. Each line contains two integers l and r (1 ≤ l ≤ r ≤ n) — the bounds of the question.
Output
Print q lines: for each question print the length of the string obtained by Vasya.
Examples
Input
7 3
abacaba
1 3
2 5
1 7
Output
4
7
11
Input
7 4
abbabaa
1 3
5 7
6 6
2 4
Output
5
4
1
5
Input
13 7
sonoshikumiwo
1 5
2 10
7 7
1 13
4 8
2 5
3 9
Output
82
125
9
191
62
63
97
Note
In the first example Vasya is interested in three questions. In the first question Vasya considers the substring "aba", that transforms to "abba", so the answer is equal to 4. In the second question Vasya considers "baca", that transforms to "bbaccca", so the answer is 7. In the third question Vasya considers the string "abacaba",that transforms to "abbacccabba" of length 11.
|
instruction
| 0
| 101,454
| 0
| 202,908
|
Tags: dp, implementation, strings
Correct Solution:
```
import sys
import math
import random
from queue import PriorityQueue as PQ
from bisect import bisect_left as BSL
from bisect import bisect_right as BSR
from collections import OrderedDict as OD
from collections import Counter
from itertools import permutations
from decimal import Decimal as BIGFLOAT
from copy import deepcopy
# mod = 998244353
mod = 1000000007
MOD = mod
sys.setrecursionlimit(1000000)
try:
sys.stdin = open("actext.txt", "r")
OPENFILE = 1
except:
pass
def get_ints():
return map(int,input().split())
def palindrome(s):
mid = len(s)//2
for i in range(mid):
if(s[i]!=s[len(s)-i-1]):
return False
return True
def check(i,n):
if(0<=i<n):
return True
else:
return False
# -----------------------------------------------------------------------------------------
n,q= get_ints()
s = input()
mp = {}
for num,i in enumerate('abcdefghijklmnopqrstuvwxyz'):
mp[i] = num+1
# print(mp)
# count = 0
# for i in s:
# if(i not in mp):
# count+=1
# mp[i] = count
arr = []
for i in s:
arr.append(mp[i])
pre = [0]
for i in arr:
pre.append(pre[-1]+i)
for qq in range(q):
l,r = get_ints()
print(pre[r]-pre[l-1])
```
|
output
| 1
| 101,454
| 0
| 202,909
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya once wrote a sad love song and shared it to Vasya. The song is a string consisting of lowercase English letters. Vasya made up q questions about this song. Each question is about a subsegment of the song starting from the l-th letter to the r-th letter. Vasya considers a substring made up from characters on this segment and repeats each letter in the subsegment k times, where k is the index of the corresponding letter in the alphabet. For example, if the question is about the substring "abbcb", then Vasya repeats letter 'a' once, each of the letters 'b' twice, letter 'c" three times, so that the resulting string is "abbbbcccbb", its length is 10. Vasya is interested about the length of the resulting string.
Help Petya find the length of each string obtained by Vasya.
Input
The first line contains two integers n and q (1≤ n≤ 100 000, 1≤ q ≤ 100 000) — the length of the song and the number of questions.
The second line contains one string s — the song, consisting of n lowercase letters of English letters.
Vasya's questions are contained in the next q lines. Each line contains two integers l and r (1 ≤ l ≤ r ≤ n) — the bounds of the question.
Output
Print q lines: for each question print the length of the string obtained by Vasya.
Examples
Input
7 3
abacaba
1 3
2 5
1 7
Output
4
7
11
Input
7 4
abbabaa
1 3
5 7
6 6
2 4
Output
5
4
1
5
Input
13 7
sonoshikumiwo
1 5
2 10
7 7
1 13
4 8
2 5
3 9
Output
82
125
9
191
62
63
97
Note
In the first example Vasya is interested in three questions. In the first question Vasya considers the substring "aba", that transforms to "abba", so the answer is equal to 4. In the second question Vasya considers "baca", that transforms to "bbaccca", so the answer is 7. In the third question Vasya considers the string "abacaba",that transforms to "abbacccabba" of length 11.
|
instruction
| 0
| 101,455
| 0
| 202,910
|
Tags: dp, implementation, strings
Correct Solution:
```
from string import ascii_lowercase as asc
alphabet = {asc[i]:i+1 for i in range(len(asc))}
n,q = [int(x) for x in input().split()]
stroke = input()
sums = []
for i in stroke:
sums.append(sums[-1]+alphabet[i] if sums != [] else alphabet[i])
for i in range(q):
l,r = [int(x)-1 for x in input().split()]
l -= 1
if l < 0:
print(sums[r])
else:
print(sums[r]-sums[l])
```
|
output
| 1
| 101,455
| 0
| 202,911
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya once wrote a sad love song and shared it to Vasya. The song is a string consisting of lowercase English letters. Vasya made up q questions about this song. Each question is about a subsegment of the song starting from the l-th letter to the r-th letter. Vasya considers a substring made up from characters on this segment and repeats each letter in the subsegment k times, where k is the index of the corresponding letter in the alphabet. For example, if the question is about the substring "abbcb", then Vasya repeats letter 'a' once, each of the letters 'b' twice, letter 'c" three times, so that the resulting string is "abbbbcccbb", its length is 10. Vasya is interested about the length of the resulting string.
Help Petya find the length of each string obtained by Vasya.
Input
The first line contains two integers n and q (1≤ n≤ 100 000, 1≤ q ≤ 100 000) — the length of the song and the number of questions.
The second line contains one string s — the song, consisting of n lowercase letters of English letters.
Vasya's questions are contained in the next q lines. Each line contains two integers l and r (1 ≤ l ≤ r ≤ n) — the bounds of the question.
Output
Print q lines: for each question print the length of the string obtained by Vasya.
Examples
Input
7 3
abacaba
1 3
2 5
1 7
Output
4
7
11
Input
7 4
abbabaa
1 3
5 7
6 6
2 4
Output
5
4
1
5
Input
13 7
sonoshikumiwo
1 5
2 10
7 7
1 13
4 8
2 5
3 9
Output
82
125
9
191
62
63
97
Note
In the first example Vasya is interested in three questions. In the first question Vasya considers the substring "aba", that transforms to "abba", so the answer is equal to 4. In the second question Vasya considers "baca", that transforms to "bbaccca", so the answer is 7. In the third question Vasya considers the string "abacaba",that transforms to "abbacccabba" of length 11.
|
instruction
| 0
| 101,456
| 0
| 202,912
|
Tags: dp, implementation, strings
Correct Solution:
```
n,q=input().split()
string=str(input())
L=[]
answer=0
for i in range(len(string)):
answer+=(ord(string[i])-96)
L.append(answer)
for i in range(int(q)):
a,b=input().split()
if(int(a)==1):
print(L[int(b)-1])
else:
print(L[int(b)-1]-L[int(a)-2])
```
|
output
| 1
| 101,456
| 0
| 202,913
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya once wrote a sad love song and shared it to Vasya. The song is a string consisting of lowercase English letters. Vasya made up q questions about this song. Each question is about a subsegment of the song starting from the l-th letter to the r-th letter. Vasya considers a substring made up from characters on this segment and repeats each letter in the subsegment k times, where k is the index of the corresponding letter in the alphabet. For example, if the question is about the substring "abbcb", then Vasya repeats letter 'a' once, each of the letters 'b' twice, letter 'c" three times, so that the resulting string is "abbbbcccbb", its length is 10. Vasya is interested about the length of the resulting string.
Help Petya find the length of each string obtained by Vasya.
Input
The first line contains two integers n and q (1≤ n≤ 100 000, 1≤ q ≤ 100 000) — the length of the song and the number of questions.
The second line contains one string s — the song, consisting of n lowercase letters of English letters.
Vasya's questions are contained in the next q lines. Each line contains two integers l and r (1 ≤ l ≤ r ≤ n) — the bounds of the question.
Output
Print q lines: for each question print the length of the string obtained by Vasya.
Examples
Input
7 3
abacaba
1 3
2 5
1 7
Output
4
7
11
Input
7 4
abbabaa
1 3
5 7
6 6
2 4
Output
5
4
1
5
Input
13 7
sonoshikumiwo
1 5
2 10
7 7
1 13
4 8
2 5
3 9
Output
82
125
9
191
62
63
97
Note
In the first example Vasya is interested in three questions. In the first question Vasya considers the substring "aba", that transforms to "abba", so the answer is equal to 4. In the second question Vasya considers "baca", that transforms to "bbaccca", so the answer is 7. In the third question Vasya considers the string "abacaba",that transforms to "abbacccabba" of length 11.
|
instruction
| 0
| 101,457
| 0
| 202,914
|
Tags: dp, implementation, strings
Correct Solution:
```
n, t = map(int, input().split())
s = input()
arr = [0]
for x in s:
arr.append(arr[-1] + (ord(x) - ord('a') + 1))
for _ in range(t):
a, b = map(int, input().split())
print(arr[b] - arr[a - 1])
```
|
output
| 1
| 101,457
| 0
| 202,915
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya once wrote a sad love song and shared it to Vasya. The song is a string consisting of lowercase English letters. Vasya made up q questions about this song. Each question is about a subsegment of the song starting from the l-th letter to the r-th letter. Vasya considers a substring made up from characters on this segment and repeats each letter in the subsegment k times, where k is the index of the corresponding letter in the alphabet. For example, if the question is about the substring "abbcb", then Vasya repeats letter 'a' once, each of the letters 'b' twice, letter 'c" three times, so that the resulting string is "abbbbcccbb", its length is 10. Vasya is interested about the length of the resulting string.
Help Petya find the length of each string obtained by Vasya.
Input
The first line contains two integers n and q (1≤ n≤ 100 000, 1≤ q ≤ 100 000) — the length of the song and the number of questions.
The second line contains one string s — the song, consisting of n lowercase letters of English letters.
Vasya's questions are contained in the next q lines. Each line contains two integers l and r (1 ≤ l ≤ r ≤ n) — the bounds of the question.
Output
Print q lines: for each question print the length of the string obtained by Vasya.
Examples
Input
7 3
abacaba
1 3
2 5
1 7
Output
4
7
11
Input
7 4
abbabaa
1 3
5 7
6 6
2 4
Output
5
4
1
5
Input
13 7
sonoshikumiwo
1 5
2 10
7 7
1 13
4 8
2 5
3 9
Output
82
125
9
191
62
63
97
Note
In the first example Vasya is interested in three questions. In the first question Vasya considers the substring "aba", that transforms to "abba", so the answer is equal to 4. In the second question Vasya considers "baca", that transforms to "bbaccca", so the answer is 7. In the third question Vasya considers the string "abacaba",that transforms to "abbacccabba" of length 11.
|
instruction
| 0
| 101,458
| 0
| 202,916
|
Tags: dp, implementation, strings
Correct Solution:
```
import sys
input=sys.stdin.readline
n,q=map(int,input().split())
s=input()
temp=[0]
for i in range(len(s)):
temp.append(temp[-1]+ord(s[i])-ord('a')+1)
while q>0:
q-=1
l,r=map(int,input().split())
print(temp[r]-temp[l-1])
```
|
output
| 1
| 101,458
| 0
| 202,917
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya once wrote a sad love song and shared it to Vasya. The song is a string consisting of lowercase English letters. Vasya made up q questions about this song. Each question is about a subsegment of the song starting from the l-th letter to the r-th letter. Vasya considers a substring made up from characters on this segment and repeats each letter in the subsegment k times, where k is the index of the corresponding letter in the alphabet. For example, if the question is about the substring "abbcb", then Vasya repeats letter 'a' once, each of the letters 'b' twice, letter 'c" three times, so that the resulting string is "abbbbcccbb", its length is 10. Vasya is interested about the length of the resulting string.
Help Petya find the length of each string obtained by Vasya.
Input
The first line contains two integers n and q (1≤ n≤ 100 000, 1≤ q ≤ 100 000) — the length of the song and the number of questions.
The second line contains one string s — the song, consisting of n lowercase letters of English letters.
Vasya's questions are contained in the next q lines. Each line contains two integers l and r (1 ≤ l ≤ r ≤ n) — the bounds of the question.
Output
Print q lines: for each question print the length of the string obtained by Vasya.
Examples
Input
7 3
abacaba
1 3
2 5
1 7
Output
4
7
11
Input
7 4
abbabaa
1 3
5 7
6 6
2 4
Output
5
4
1
5
Input
13 7
sonoshikumiwo
1 5
2 10
7 7
1 13
4 8
2 5
3 9
Output
82
125
9
191
62
63
97
Note
In the first example Vasya is interested in three questions. In the first question Vasya considers the substring "aba", that transforms to "abba", so the answer is equal to 4. In the second question Vasya considers "baca", that transforms to "bbaccca", so the answer is 7. In the third question Vasya considers the string "abacaba",that transforms to "abbacccabba" of length 11.
|
instruction
| 0
| 101,459
| 0
| 202,918
|
Tags: dp, implementation, strings
Correct Solution:
```
n,q = map(int,input().split())
s = input()
dp = []
ans = 0
for i in range(1,n+1):
dp.append(ans)
ans+=ord(s[i-1])-96
dp.append(ans)
for _ in range(q):
left,right = map(int,input().split())
print(dp[right]-dp[left-1])
```
|
output
| 1
| 101,459
| 0
| 202,919
|
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' <image> 'y' <image> 'x' <image> 'b' <image> 'a' <image> 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.
What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Input
The only line of the input contains the string s (1 ≤ |s| ≤ 100 000) consisting of lowercase English letters.
Output
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
Examples
Input
codeforces
Output
bncdenqbdr
Input
abacaba
Output
aaacaba
Note
String s is lexicographically smaller than some other string t of the same length if there exists some 1 ≤ i ≤ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si < ti.
|
instruction
| 0
| 101,657
| 0
| 203,314
|
Tags: constructive algorithms, greedy, implementation, strings
Correct Solution:
```
x=input()
y=list(x)
i=0
d=-1
for c in x:
if c=='a':
if d!=-1:
break
i+=1
continue
if d==-1:
d=i
y[i]=chr(ord(y[i])-1)
i+=1
if d==-1:
y[-1]='z'
print("".join(y))
```
|
output
| 1
| 101,657
| 0
| 203,315
|
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' <image> 'y' <image> 'x' <image> 'b' <image> 'a' <image> 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.
What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Input
The only line of the input contains the string s (1 ≤ |s| ≤ 100 000) consisting of lowercase English letters.
Output
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
Examples
Input
codeforces
Output
bncdenqbdr
Input
abacaba
Output
aaacaba
Note
String s is lexicographically smaller than some other string t of the same length if there exists some 1 ≤ i ≤ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si < ti.
|
instruction
| 0
| 101,658
| 0
| 203,316
|
Tags: constructive algorithms, greedy, implementation, strings
Correct Solution:
```
from sys import stdin
phrase=input()
i=0
while i<len(phrase) and phrase[i]=='a':
i+=1
j=i
while j<len(phrase) and phrase[j]!='a':
j+=1
if i>=len(phrase):
print(phrase[:-1]+"z")
else:
nouvellePhrase=phrase[:i]
for indice in range(i,j):
caractere=phrase[indice]
nouvelIndice= (ord(caractere)-ord('a')-1)%26
car=chr(nouvelIndice+ord('a'))
nouvellePhrase+=car
nouvellePhrase+=phrase[j:]
print(nouvellePhrase)
```
|
output
| 1
| 101,658
| 0
| 203,317
|
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' <image> 'y' <image> 'x' <image> 'b' <image> 'a' <image> 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.
What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Input
The only line of the input contains the string s (1 ≤ |s| ≤ 100 000) consisting of lowercase English letters.
Output
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
Examples
Input
codeforces
Output
bncdenqbdr
Input
abacaba
Output
aaacaba
Note
String s is lexicographically smaller than some other string t of the same length if there exists some 1 ≤ i ≤ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si < ti.
|
instruction
| 0
| 101,659
| 0
| 203,318
|
Tags: constructive algorithms, greedy, implementation, strings
Correct Solution:
```
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g','h', 'i', 'j', 'k', 'l', 'm', 'n', \
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
dataIn = str(input())
data = []
for i in dataIn:
data.append(i)
count = 0
begin = 0
if len(data) == 1:
if data[0] == 'a':
data[0] = 'z'
else:
for j in range(len(letters)):
if letters[j] == data[0]:
data[0] = letters[j-1]
else:
i = 0
begin = False
while i < len(data) - 1:
if data[i] == 'a':
i += 1
else:
break
for k in range(i, len(data)):
if data[k] == 'a' and k != len(data) - 1:
break
elif data[k] == 'a' and k == len(data) -1:
if not begin: data[k] = 'z'
else:
begin = True
for j in range(len(letters)):
if letters[j] == data[k]:
data[k] = letters[j-1]
result = ''.join(data)
print(result)
```
|
output
| 1
| 101,659
| 0
| 203,319
|
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' <image> 'y' <image> 'x' <image> 'b' <image> 'a' <image> 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.
What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Input
The only line of the input contains the string s (1 ≤ |s| ≤ 100 000) consisting of lowercase English letters.
Output
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
Examples
Input
codeforces
Output
bncdenqbdr
Input
abacaba
Output
aaacaba
Note
String s is lexicographically smaller than some other string t of the same length if there exists some 1 ≤ i ≤ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si < ti.
|
instruction
| 0
| 101,660
| 0
| 203,320
|
Tags: constructive algorithms, greedy, implementation, strings
Correct Solution:
```
s1=input()
s=list(s1)
start=-1
end=-1
for i in range(len(s)):
if(s[i]>'a' and start==-1):
start=i
elif(s[i]=='a' and start!=-1):
end=i
break;
if(end==-1):
end=len(s)
if(start==-1):
s[len(s)-1]='z'
else:
for i in range(start,end):
p=ord(s[i])-1
s[i]= chr(p)
s1="".join(s)
print(s1)
```
|
output
| 1
| 101,660
| 0
| 203,321
|
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' <image> 'y' <image> 'x' <image> 'b' <image> 'a' <image> 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.
What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Input
The only line of the input contains the string s (1 ≤ |s| ≤ 100 000) consisting of lowercase English letters.
Output
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
Examples
Input
codeforces
Output
bncdenqbdr
Input
abacaba
Output
aaacaba
Note
String s is lexicographically smaller than some other string t of the same length if there exists some 1 ≤ i ≤ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si < ti.
|
instruction
| 0
| 101,661
| 0
| 203,322
|
Tags: constructive algorithms, greedy, implementation, strings
Correct Solution:
```
s = input()
i = 0; b = False
while i < len(s) and s[i] == 'a': i += 1
while i < len(s) and s[i] != 'a':
s = s[:i] + chr(ord(s[i]) - 1) + s[i + 1:]
i += 1
b = True
print(s if b else 'a' * (len(s) - 1) + 'z')
```
|
output
| 1
| 101,661
| 0
| 203,323
|
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' <image> 'y' <image> 'x' <image> 'b' <image> 'a' <image> 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.
What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Input
The only line of the input contains the string s (1 ≤ |s| ≤ 100 000) consisting of lowercase English letters.
Output
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
Examples
Input
codeforces
Output
bncdenqbdr
Input
abacaba
Output
aaacaba
Note
String s is lexicographically smaller than some other string t of the same length if there exists some 1 ≤ i ≤ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si < ti.
|
instruction
| 0
| 101,662
| 0
| 203,324
|
Tags: constructive algorithms, greedy, implementation, strings
Correct Solution:
```
def findNot(string, char):
for i in range(len(string)):
if string[i] != char:
return i
return len(string) - 1
s = input()
beg = findNot(s, "a")
res = s[0:beg]
for i in range(beg, len(s)):
if i != beg and s[i] == "a":
res += s[i:]
break
if s[i] == "a":
res += "z"
else:
res += chr(ord(s[i]) - 1)
print(res)
```
|
output
| 1
| 101,662
| 0
| 203,325
|
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' <image> 'y' <image> 'x' <image> 'b' <image> 'a' <image> 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.
What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Input
The only line of the input contains the string s (1 ≤ |s| ≤ 100 000) consisting of lowercase English letters.
Output
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
Examples
Input
codeforces
Output
bncdenqbdr
Input
abacaba
Output
aaacaba
Note
String s is lexicographically smaller than some other string t of the same length if there exists some 1 ≤ i ≤ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si < ti.
|
instruction
| 0
| 101,663
| 0
| 203,326
|
Tags: constructive algorithms, greedy, implementation, strings
Correct Solution:
```
# You lost the game.
s = str(input())
n = len(s)
i = 0
A = "abcdefghijklmnopqrstuvwxyz"
while i < n and s[i] == 'a':
i += 1
if i == n:
print(s[:n-1]+"z")
else:
d = i
while i < n and s[i] != 'a':
i += 1
r = ""
for j in range(d,i):
if s[j] == "a":
r += "z"
else:
r += A[A.index(s[j])-1]
print(s[:d]+r+s[i:])
```
|
output
| 1
| 101,663
| 0
| 203,327
|
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' <image> 'y' <image> 'x' <image> 'b' <image> 'a' <image> 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.
What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Input
The only line of the input contains the string s (1 ≤ |s| ≤ 100 000) consisting of lowercase English letters.
Output
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
Examples
Input
codeforces
Output
bncdenqbdr
Input
abacaba
Output
aaacaba
Note
String s is lexicographically smaller than some other string t of the same length if there exists some 1 ≤ i ≤ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si < ti.
|
instruction
| 0
| 101,664
| 0
| 203,328
|
Tags: constructive algorithms, greedy, implementation, strings
Correct Solution:
```
s = [i for i in input()]
flag = False
for i in range(len(s)):
if s[i] > "a":
flag = True
s[i] = chr(ord(s[i])-1)
elif flag:
break
if not flag:
s[-1] = "z"
print(*s, sep="")
```
|
output
| 1
| 101,664
| 0
| 203,329
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' <image> 'y' <image> 'x' <image> 'b' <image> 'a' <image> 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.
What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Input
The only line of the input contains the string s (1 ≤ |s| ≤ 100 000) consisting of lowercase English letters.
Output
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
Examples
Input
codeforces
Output
bncdenqbdr
Input
abacaba
Output
aaacaba
Note
String s is lexicographically smaller than some other string t of the same length if there exists some 1 ≤ i ≤ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si < ti.
Submitted Solution:
```
import sys
s = input()
L = len(s)
#chr(48) = '0'
#ord('a') = 97
t = ""
i = 0
while i < L and s[i] == 'a':
t += s[i]
i += 1
if len(t) == L:
print(s[:L-1]+'z')
sys.exit()
while i < L and s[i] != 'a':
t += chr(ord(s[i])-1)
i += 1
t += s[i:]
print(t)
```
|
instruction
| 0
| 101,665
| 0
| 203,330
|
Yes
|
output
| 1
| 101,665
| 0
| 203,331
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' <image> 'y' <image> 'x' <image> 'b' <image> 'a' <image> 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.
What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Input
The only line of the input contains the string s (1 ≤ |s| ≤ 100 000) consisting of lowercase English letters.
Output
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
Examples
Input
codeforces
Output
bncdenqbdr
Input
abacaba
Output
aaacaba
Note
String s is lexicographically smaller than some other string t of the same length if there exists some 1 ≤ i ≤ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si < ti.
Submitted Solution:
```
s=list(input())
count=0
count1=0
y=0
if s.count('a')==len(s):
print('a'*(len(s)-1)+'z')
elif s[0]!='a' or s[1]!='a':
for i in range(len(s)):
if s[i]=='a' and i!=0:
count=1
print('a',end='')
break
elif s[i]=='a' and i==0:
print('a',end='')
else:
print((chr(ord(s[i]) - 1)),end='')
if count==1:
for i in range(i+1,len(s)):
print(s[i],end='')
else:
for i in range(len(s)):
if s[i]=='a':
print('a',end='')
count1+=1
else:
break
for j in range(i,len(s)):
if s[j]!='a':
print(chr(ord(s[j])-1),end='')
count1+=1
else:
break
for i in range(j,len(s)):
if count1<len(s):
print(s[i],end='')
```
|
instruction
| 0
| 101,666
| 0
| 203,332
|
Yes
|
output
| 1
| 101,666
| 0
| 203,333
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' <image> 'y' <image> 'x' <image> 'b' <image> 'a' <image> 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.
What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Input
The only line of the input contains the string s (1 ≤ |s| ≤ 100 000) consisting of lowercase English letters.
Output
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
Examples
Input
codeforces
Output
bncdenqbdr
Input
abacaba
Output
aaacaba
Note
String s is lexicographically smaller than some other string t of the same length if there exists some 1 ≤ i ≤ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si < ti.
Submitted Solution:
```
s = input()
start = -1
end = -1
for i in range(len(s)):
if s[i] != 'a':
if start < 0:
start = i
end = i
else:
end = i
if s[i] == 'a' and start >= 0:
break
if start < 0:
print(s[0:len(s)-1], end="")
print('z')
else:
for i in range(len(s)):
if start <= i <= end:
if s[i] == 'a':
print('z', end="")
else:
print(chr(ord(s[i]) - 1), end="")
else:
print(s[i], end="")
```
|
instruction
| 0
| 101,667
| 0
| 203,334
|
Yes
|
output
| 1
| 101,667
| 0
| 203,335
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' <image> 'y' <image> 'x' <image> 'b' <image> 'a' <image> 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.
What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Input
The only line of the input contains the string s (1 ≤ |s| ≤ 100 000) consisting of lowercase English letters.
Output
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
Examples
Input
codeforces
Output
bncdenqbdr
Input
abacaba
Output
aaacaba
Note
String s is lexicographically smaller than some other string t of the same length if there exists some 1 ≤ i ≤ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si < ti.
Submitted Solution:
```
s = list(input())
n = len(s)
L = 0
while L < n and s[L] == 'a': L += 1
R = L
while R < n and s[R] != 'a': R += 1
for i in range(L, R):
if s[i] == 'a': s[i] = 'z'
else: s[i] = chr(ord(s[i]) - 1)
if L == R == n:
s[-1] = 'z'
print(''.join(s))
```
|
instruction
| 0
| 101,668
| 0
| 203,336
|
Yes
|
output
| 1
| 101,668
| 0
| 203,337
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' <image> 'y' <image> 'x' <image> 'b' <image> 'a' <image> 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.
What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Input
The only line of the input contains the string s (1 ≤ |s| ≤ 100 000) consisting of lowercase English letters.
Output
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
Examples
Input
codeforces
Output
bncdenqbdr
Input
abacaba
Output
aaacaba
Note
String s is lexicographically smaller than some other string t of the same length if there exists some 1 ≤ i ≤ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si < ti.
Submitted Solution:
```
s=input()
if s[0]!="a":
r=""
for i in range(len(s)):
if s[i]=="a":
y="z"
else:
x=ord(s[i])
y=chr(x-1)
if y>s[i]:
r+=s[i:]
break
else:
r+=y
print(r)
else:
b=0;flag=0
for i in range(1,len(s)):
if s[i]<s[i-1]:
b=i-1
flag=1
break
if flag:
r=""
r+=s[:b]
f=0
for i in range(b,len(s)):
if s[i]=="a":
y="z"
else:
x=ord(s[i])
y=chr(x-1)
if y>s[i]:
r+=s[i:]
break
else:
r+=y
print(r)
else:
r=""
r+=s[:b]
f=0
for i in range(b,len(s)):
if s[i]=="a":
y="z"
else:
x=ord(s[i])
y=chr(x-1)
if y>s[i]:
r+=s[i:]
break
else:
r+=y
print(r)
```
|
instruction
| 0
| 101,669
| 0
| 203,338
|
No
|
output
| 1
| 101,669
| 0
| 203,339
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' <image> 'y' <image> 'x' <image> 'b' <image> 'a' <image> 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.
What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Input
The only line of the input contains the string s (1 ≤ |s| ≤ 100 000) consisting of lowercase English letters.
Output
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
Examples
Input
codeforces
Output
bncdenqbdr
Input
abacaba
Output
aaacaba
Note
String s is lexicographically smaller than some other string t of the same length if there exists some 1 ≤ i ≤ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si < ti.
Submitted Solution:
```
s = input()
z = 0
while z < len(s) and s[z] == 'a':
print('a', end='')
z += 1
while z < len(s) and s[z] != 'a':
print(chr(ord(s[z]) - 1), end='')
z += 1
while z < len(s):
print(s[z], end='')
z += 1
```
|
instruction
| 0
| 101,670
| 0
| 203,340
|
No
|
output
| 1
| 101,670
| 0
| 203,341
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' <image> 'y' <image> 'x' <image> 'b' <image> 'a' <image> 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.
What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Input
The only line of the input contains the string s (1 ≤ |s| ≤ 100 000) consisting of lowercase English letters.
Output
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
Examples
Input
codeforces
Output
bncdenqbdr
Input
abacaba
Output
aaacaba
Note
String s is lexicographically smaller than some other string t of the same length if there exists some 1 ≤ i ≤ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si < ti.
Submitted Solution:
```
s = list(input())
n = len(s)
strat , end = -1 , -1
for i in range(n):
if s[i] > 'a' and strat == -1:
strat = i
elif s[i] == 'a' and strat != -1:
end = i
break
#print(strat , end)
if end == -1:
end = n - 1
if strat == -1:
s[n - 1] = 'z'
print(''.join(s))
else:
for i in range(strat , end):
x = ord(s[i]) - 1
s[i] = chr(x)
print(''.join(s))
```
|
instruction
| 0
| 101,671
| 0
| 203,342
|
No
|
output
| 1
| 101,671
| 0
| 203,343
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' <image> 'y' <image> 'x' <image> 'b' <image> 'a' <image> 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.
What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Input
The only line of the input contains the string s (1 ≤ |s| ≤ 100 000) consisting of lowercase English letters.
Output
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
Examples
Input
codeforces
Output
bncdenqbdr
Input
abacaba
Output
aaacaba
Note
String s is lexicographically smaller than some other string t of the same length if there exists some 1 ≤ i ≤ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si < ti.
Submitted Solution:
```
s = input()
l = 'abcdefghijklmnopqrstuvwxyz'
k = ''
i = 0
while s[i] == 'a' and i < len(s)-1:
i = i+1
k = s[:i]
for j in range(i,len(s)):
if s[j] != 'a':
k+=(l[l.find(s[j])-1])
else:
break
for f in range(len(k),len(s)):
k+=s[f]
if s == 'a':
print('z')
else:
print(k)
```
|
instruction
| 0
| 101,672
| 0
| 203,344
|
No
|
output
| 1
| 101,672
| 0
| 203,345
|
Provide a correct Python 3 solution for this coding contest problem.
Find places where a string P is found within a text T. Print all indices of T where P found. The indices of T start with 0.
Constraints
* 1 ≤ length of T ≤ 1000000
* 1 ≤ length of P ≤ 10000
* The input consists of alphabetical characters and digits
Input
In the first line, a text T is given. In the second line, a string P is given.
Output
Print an index of T where P found in a line. Print the indices in ascending order.
Examples
Input
aabaaa
aa
Output
0
3
4
Input
xyzz
yz
Output
1
Input
abc
xyz
Output
|
instruction
| 0
| 102,003
| 0
| 204,006
|
"Correct Solution:
```
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
def Z_algorithm(s):
n = len(s)
z = [0]*n
z[0] = n
c = 1
for i in range(1,n):
if i+z[i-c] < c+z[c]:
z[i] = z[i-c]
else:
j = max(0,c+z[c]-i)
while i+j < n and s[j] == s[i+j]:
j += 1
z[i] = j
c = i
return z
s = input()
t = input()
z = Z_algorithm(t+s)[len(t):]
for i in range(len(s)):
if z[i] >= len(t):
print(i)
return
#Solve
if __name__ == "__main__":
solve()
```
|
output
| 1
| 102,003
| 0
| 204,007
|
Provide a correct Python 3 solution for this coding contest problem.
Find places where a string P is found within a text T. Print all indices of T where P found. The indices of T start with 0.
Constraints
* 1 ≤ length of T ≤ 1000000
* 1 ≤ length of P ≤ 10000
* The input consists of alphabetical characters and digits
Input
In the first line, a text T is given. In the second line, a string P is given.
Output
Print an index of T where P found in a line. Print the indices in ascending order.
Examples
Input
aabaaa
aa
Output
0
3
4
Input
xyzz
yz
Output
1
Input
abc
xyz
Output
|
instruction
| 0
| 102,006
| 0
| 204,012
|
"Correct Solution:
```
t = input()
p = input()
t_len = len(t)
p_len = len(p)
for i in range(0, t_len - p_len + 1):
if t[i:i + p_len] == p:
print(i)
```
|
output
| 1
| 102,006
| 0
| 204,013
|
Provide tags and a correct Python 3 solution for this coding contest problem.
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value wc. For each special string s = s1s2... s|s| (|s| is the length of the string) he represents its value with a function f(s), where
<image>
Now DZY has a string s. He wants to insert k lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
Input
The first line contains a single string s (1 ≤ |s| ≤ 103).
The second line contains a single integer k (0 ≤ k ≤ 103).
The third line contains twenty-six integers from wa to wz. Each such number is non-negative and doesn't exceed 1000.
Output
Print a single integer — the largest possible value of the resulting string DZY could get.
Examples
Input
abc
3
1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
41
Note
In the test sample DZY can obtain "abcbbc", value = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
|
instruction
| 0
| 102,425
| 0
| 204,850
|
Tags: greedy, implementation
Correct Solution:
```
S = input()
N = int(input())
X = list(map(int, input().split()))
MAX = max(X)
SUM = 0
for i in range(len(S)):
SUM += X[ord(S[i]) - 97] * (i + 1)
for i in range(1, N + 1):
SUM += (len(S) + i) * MAX
print(SUM)
```
|
output
| 1
| 102,425
| 0
| 204,851
|
Provide tags and a correct Python 3 solution for this coding contest problem.
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value wc. For each special string s = s1s2... s|s| (|s| is the length of the string) he represents its value with a function f(s), where
<image>
Now DZY has a string s. He wants to insert k lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
Input
The first line contains a single string s (1 ≤ |s| ≤ 103).
The second line contains a single integer k (0 ≤ k ≤ 103).
The third line contains twenty-six integers from wa to wz. Each such number is non-negative and doesn't exceed 1000.
Output
Print a single integer — the largest possible value of the resulting string DZY could get.
Examples
Input
abc
3
1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
41
Note
In the test sample DZY can obtain "abcbbc", value = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
|
instruction
| 0
| 102,426
| 0
| 204,852
|
Tags: greedy, implementation
Correct Solution:
```
s=input()
k=int(input())
n=len(s)
l=list(map(int,input().split()))
m=max(l)
c=0
for i in range(n):
x=ord(s[i])-97
c=c+l[x]*(i+1)
for i in range(n+1,n+k+1):
c=c+(i*m)
print(c)
```
|
output
| 1
| 102,426
| 0
| 204,853
|
Provide tags and a correct Python 3 solution for this coding contest problem.
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value wc. For each special string s = s1s2... s|s| (|s| is the length of the string) he represents its value with a function f(s), where
<image>
Now DZY has a string s. He wants to insert k lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
Input
The first line contains a single string s (1 ≤ |s| ≤ 103).
The second line contains a single integer k (0 ≤ k ≤ 103).
The third line contains twenty-six integers from wa to wz. Each such number is non-negative and doesn't exceed 1000.
Output
Print a single integer — the largest possible value of the resulting string DZY could get.
Examples
Input
abc
3
1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
41
Note
In the test sample DZY can obtain "abcbbc", value = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
|
instruction
| 0
| 102,427
| 0
| 204,854
|
Tags: greedy, implementation
Correct Solution:
```
a=input()
n=int(input())
l=list(map(int,input().split()))
letters='abcdefghijklmnopqrstuvwxyz'
b=l.index(max(l))
a+=n*letters[b]
t=[]
for i in a:
t.append(l[letters.index(i)])
s=0
for i in range(1,len(a)+1):
s+=i*t[i-1]
print(s)
```
|
output
| 1
| 102,427
| 0
| 204,855
|
Provide tags and a correct Python 3 solution for this coding contest problem.
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value wc. For each special string s = s1s2... s|s| (|s| is the length of the string) he represents its value with a function f(s), where
<image>
Now DZY has a string s. He wants to insert k lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
Input
The first line contains a single string s (1 ≤ |s| ≤ 103).
The second line contains a single integer k (0 ≤ k ≤ 103).
The third line contains twenty-six integers from wa to wz. Each such number is non-negative and doesn't exceed 1000.
Output
Print a single integer — the largest possible value of the resulting string DZY could get.
Examples
Input
abc
3
1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
41
Note
In the test sample DZY can obtain "abcbbc", value = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
|
instruction
| 0
| 102,428
| 0
| 204,856
|
Tags: greedy, implementation
Correct Solution:
```
str = list(input())
N = int(input())
A = list(map(int, input().split()))
total = 0
maxu = max(A)
for i in range(len(str)):
total += (i+1) * (A[ord(str[i]) - 97])
for j in range(N):
total += (j+len(str)+1)*maxu
print(total)
```
|
output
| 1
| 102,428
| 0
| 204,857
|
Provide tags and a correct Python 3 solution for this coding contest problem.
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value wc. For each special string s = s1s2... s|s| (|s| is the length of the string) he represents its value with a function f(s), where
<image>
Now DZY has a string s. He wants to insert k lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
Input
The first line contains a single string s (1 ≤ |s| ≤ 103).
The second line contains a single integer k (0 ≤ k ≤ 103).
The third line contains twenty-six integers from wa to wz. Each such number is non-negative and doesn't exceed 1000.
Output
Print a single integer — the largest possible value of the resulting string DZY could get.
Examples
Input
abc
3
1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
41
Note
In the test sample DZY can obtain "abcbbc", value = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
|
instruction
| 0
| 102,429
| 0
| 204,858
|
Tags: greedy, implementation
Correct Solution:
```
s=str(input())
k=int(input())
wlist=[int(w) for w in input().split()]
letter=max(wlist)
alphabet='abcdefghijklmnopqrstuvwxyz'
summ=0
for i in range(len(s)):
summ+=wlist[alphabet.index(s[i])]*(i+1)
print(summ+letter*(k*len(s)+(k+k**2)//2))
```
|
output
| 1
| 102,429
| 0
| 204,859
|
Provide tags and a correct Python 3 solution for this coding contest problem.
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value wc. For each special string s = s1s2... s|s| (|s| is the length of the string) he represents its value with a function f(s), where
<image>
Now DZY has a string s. He wants to insert k lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
Input
The first line contains a single string s (1 ≤ |s| ≤ 103).
The second line contains a single integer k (0 ≤ k ≤ 103).
The third line contains twenty-six integers from wa to wz. Each such number is non-negative and doesn't exceed 1000.
Output
Print a single integer — the largest possible value of the resulting string DZY could get.
Examples
Input
abc
3
1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
41
Note
In the test sample DZY can obtain "abcbbc", value = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
|
instruction
| 0
| 102,430
| 0
| 204,860
|
Tags: greedy, implementation
Correct Solution:
```
import sys
import math
def fn(s,k,w):
l = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
x = [[0]*2]*26
for i in range(len(x)):
x[i] = [l[i],int(w[i])]
y = x.copy()
x.sort(key = lambda x: x[1], reverse = True)
s = list(s)
sum=0
first_tuple_elements = []
second_tuple_elements = []
for a_tuple in y:
first_tuple_elements.append(a_tuple[0])
for b in y:
second_tuple_elements.append(b[1])
for i in range(len(s)):
sum = sum + (i+1)*int(second_tuple_elements[first_tuple_elements.index(s[i])])
z = x[0][1]
sum1 = sum + (k*(k+1)/2 + k*len(s))*z
return int(sum1)
if __name__ == '__main__':
input = sys.stdin.read()
data = list(map(str, input.split()))
s = data[0]
k = int(data[1])
w = (data[2:])
print(fn(s,k,w))
```
|
output
| 1
| 102,430
| 0
| 204,861
|
Provide tags and a correct Python 3 solution for this coding contest problem.
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value wc. For each special string s = s1s2... s|s| (|s| is the length of the string) he represents its value with a function f(s), where
<image>
Now DZY has a string s. He wants to insert k lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
Input
The first line contains a single string s (1 ≤ |s| ≤ 103).
The second line contains a single integer k (0 ≤ k ≤ 103).
The third line contains twenty-six integers from wa to wz. Each such number is non-negative and doesn't exceed 1000.
Output
Print a single integer — the largest possible value of the resulting string DZY could get.
Examples
Input
abc
3
1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
41
Note
In the test sample DZY can obtain "abcbbc", value = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
|
instruction
| 0
| 102,431
| 0
| 204,862
|
Tags: greedy, implementation
Correct Solution:
```
# Description of the problem can be found at http://codeforces.com/problemset/problem/447/B
s = input()
k = int(input())
l_n = list(map(int, input().split()))
m = max(l_n)
t = 0
for i in range(len(s)):
t += (i + 1)*l_n[ord(s[i]) - ord('a')]
print(m * ((len(s) + k) * (len(s) + k + 1) // 2 - len(s)*(len(s) + 1) // 2) + t)
```
|
output
| 1
| 102,431
| 0
| 204,863
|
Provide tags and a correct Python 3 solution for this coding contest problem.
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value wc. For each special string s = s1s2... s|s| (|s| is the length of the string) he represents its value with a function f(s), where
<image>
Now DZY has a string s. He wants to insert k lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
Input
The first line contains a single string s (1 ≤ |s| ≤ 103).
The second line contains a single integer k (0 ≤ k ≤ 103).
The third line contains twenty-six integers from wa to wz. Each such number is non-negative and doesn't exceed 1000.
Output
Print a single integer — the largest possible value of the resulting string DZY could get.
Examples
Input
abc
3
1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
41
Note
In the test sample DZY can obtain "abcbbc", value = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
|
instruction
| 0
| 102,432
| 0
| 204,864
|
Tags: greedy, implementation
Correct Solution:
```
s = input()
n = eval(input())
value = list(map(eval,input().split()))
ans = 0
for i in range(len(s)):
ans += value[ord(s[i])-ord('a')]*(i+1)
maxn = max(map(lambda x:x,value))
ans += (len(s)*2+n+1)*n*maxn/2
print(int(ans))
```
|
output
| 1
| 102,432
| 0
| 204,865
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value wc. For each special string s = s1s2... s|s| (|s| is the length of the string) he represents its value with a function f(s), where
<image>
Now DZY has a string s. He wants to insert k lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
Input
The first line contains a single string s (1 ≤ |s| ≤ 103).
The second line contains a single integer k (0 ≤ k ≤ 103).
The third line contains twenty-six integers from wa to wz. Each such number is non-negative and doesn't exceed 1000.
Output
Print a single integer — the largest possible value of the resulting string DZY could get.
Examples
Input
abc
3
1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
41
Note
In the test sample DZY can obtain "abcbbc", value = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
Submitted Solution:
```
# Aditya Morankar
# lsta = list(map(int,input().split()))
def main():
string = input()
k = int(input())
wgt = list(map(int, input().split()))
ans= 0
for i,char in enumerate(string):
ans += (i+1)*wgt[ord(char)-97]
maxw = max(wgt)
n = len(string)+1
for i in range(k):
ans += n*maxw
n+=1
print(ans)
if __name__ == '__main__':
t = 1
while t!=0:
main()
t-=1
```
|
instruction
| 0
| 102,433
| 0
| 204,866
|
Yes
|
output
| 1
| 102,433
| 0
| 204,867
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value wc. For each special string s = s1s2... s|s| (|s| is the length of the string) he represents its value with a function f(s), where
<image>
Now DZY has a string s. He wants to insert k lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
Input
The first line contains a single string s (1 ≤ |s| ≤ 103).
The second line contains a single integer k (0 ≤ k ≤ 103).
The third line contains twenty-six integers from wa to wz. Each such number is non-negative and doesn't exceed 1000.
Output
Print a single integer — the largest possible value of the resulting string DZY could get.
Examples
Input
abc
3
1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
41
Note
In the test sample DZY can obtain "abcbbc", value = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
Submitted Solution:
```
s, k = input(), int(input())
w = dict(zip('abcdefghijklmnopqrstuvwxyz', map(int,input().split())))
print(sum(i * w[ch] for i, ch in enumerate(s, 1)) +
max(w.values()) * k * (2 * len(s) + k + 1) // 2)
```
|
instruction
| 0
| 102,434
| 0
| 204,868
|
Yes
|
output
| 1
| 102,434
| 0
| 204,869
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value wc. For each special string s = s1s2... s|s| (|s| is the length of the string) he represents its value with a function f(s), where
<image>
Now DZY has a string s. He wants to insert k lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
Input
The first line contains a single string s (1 ≤ |s| ≤ 103).
The second line contains a single integer k (0 ≤ k ≤ 103).
The third line contains twenty-six integers from wa to wz. Each such number is non-negative and doesn't exceed 1000.
Output
Print a single integer — the largest possible value of the resulting string DZY could get.
Examples
Input
abc
3
1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
41
Note
In the test sample DZY can obtain "abcbbc", value = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
Submitted Solution:
```
s = input().strip()
k = int(input().strip())
arr = list(map(int, input().strip().split()))
n = len(s)
x = max(arr)
ans = 0
for i in range(1, n+1):
ans += i*arr[ord(s[i-1])-97]
for i in range(n+1, n+k+1):
ans += i*x
print(ans)
```
|
instruction
| 0
| 102,435
| 0
| 204,870
|
Yes
|
output
| 1
| 102,435
| 0
| 204,871
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.