Expand It.
Practice
3.9 (402 votes)
Brute Force search
Easy Medium
Greedy algorithm
Problem
48% Success 7294 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Ma5termind and Subway are bored of their normal life.They want to do something interesting so that they can enjoy their last sem of college life.As usual Ma5termind comes up with a simple and interesting game.

Ma5termind gives Subway a compressed string. A compressed String is composed of characters and numbers.Every character in a compressed string contains a number. Ex a3b1c2 it represents aaabcc. Other compressed string could be a22b2a1 , z5c2x36. Each number in the compressed string indicates the number of times the corresponding character occurs in the string. The final string is 1 indexed. Ma5termind wants Subway to sort the compressed string and tell him the kth character in the sorted compressed string.Since subway got speed Ma5termind asks him various such questions.

Help Subway in answering Ma5termind's question.

Input:

The first line contains the compressed string.This is followed by Q that indicates the number of questions Ma5termind shoots on Subway.Follows Q lines each line contain an integer K.

Output:

For every question output the Kth character if it exists else print -1 .

Constraints:

2 <= Length of Compressed String <= 10^4

1<= Length of Final String <= 10^18

1<= Q <= 10^5

1<= K <= 10^18

Every character in the string is lowercase English letter.

Note:

The number for a character may contain leading zeroes.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
5 votes
Tags:
AlgorithmsApprovedMathMediumOpen
Points:30
8 votes
Tags:
AlgorithmsApprovedMediumOpen
Points:50
6 votes
Tags:
AlgorithmsApprovedArraysData StructuresHardOpen