description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
R = lambda: map(int, input().split()) n = int(input()) arr = [list(R()) for i in range(n)] arr.sort(key=lambda x: (-x[1], x[0])) toto = tot = sum(x[0] for x in arr) acc = 0 for req, thr in arr: if tot > thr: taken = min(req, tot - thr) tot -= taken acc += taken print(toto * 2 - acc)
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
n = int(input()) A = [] for i in range(n): a, b = map(int, input().split()) A.append((b, a)) A.sort() l = 0 r = n - 1 c = 0 res = 0 while l <= r: if c < A[l][0]: x = A[l][0] - c if x < A[r][1]: res += x * 2 c += x A[r] = A[r][0], A[r][1] - x else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
price = 2 discounted_price = 1 class sortable: def __init__(self, necessary, qfdp) -> None: self.necessary = necessary self.quantity_for_discounted_price = qfdp def __lt__(self, other): return self.quantity_for_discounted_price < other.quantity_for_discounted_price def buy(products...
ASSIGN VAR NUMBER ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR NONE FUNC_DEF RETURN VAR VAR FUNC_DEF WHILE VAR NUMBER IF VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN V...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
n = int(input()) l = [] needed = 0 for _ in range(n): a, b = map(int, input().split()) needed += a l.append([b, a]) l.sort() items, total = 0, 0 i, j = 0, n - 1 aa = [] bb = [] for a, b in l: aa.append(a) bb.append(b) while items < needed: if aa[i] <= items: buy = bb[i] bb[i] = 0...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR ...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
n = int(input()) item = [] for i in range(n): a, b = map(int, input().split()) item.append([a, b]) item.sort(key=lambda x: x[1]) i = 0 j = n - 1 count = 0 ans = 0 while i <= j: if item[i][1] <= count: temp = item[i][0] item[i][0] = 0 ans += temp count += temp i += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR A...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
n = int(input()) lists = [] for i in range(n): a, req = list(map(int, input().split())) lists.append([a, req]) def last(n): return n[1] qua = sorted(lists, key=last) low = 0 high = n - 1 ans = 0 bought = 0 while low <= high: if qua[low][-1] <= bought: ans += qua[low][0] bought += qua...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR FUNC_DEF RETURN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR ...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
n = int(input()) li = [] for i in range(n): a, b = map(int, input().split()) li.append((b, a)) li.sort() cost = 0 nitems = 0 while len(li) > 0: if li[0][0] <= nitems: cost += li[0][1] nitems += li[0][1] del li[0] elif li[0][0] >= nitems + li[-1][1]: cost += 2 * li[-1][1] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER ...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
n = int(input()) a = [0] * n b = [0] * n bb = [] for i in range(n): a[i], b[i] = map(int, input().split()) bb.append((i, a[i], b[i])) bb.sort(key=lambda x: x[2]) tot = sum(a) lg = n - 1 rm = bb[lg][1] bought = 0 while rm == 0: lg -= 1 rm = bb[lg][1] res = 0 fg = 0 while bb[fg][1] == 0: fg += 1 while...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN V...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
def func(): n = int(input()) arr = [] for _ in range(n): a, b = map(int, input().split()) arr.append([a, b]) arr.sort(key=lambda x: x[1]) cur_prod = 0 ans = 0 i = 0 j = n - 1 while i <= j: while arr[i][1] > cur_prod and arr[i][0] > 0: diff = arr[i]...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR WHILE VAR VAR ...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
n = int(input()) arr = [] for i in range(n): a, b = map(int, input().split()) arr.append([b, a]) arr.sort() last = -1 ans = 0 prod = 0 for i in range(n): if arr[i][0] > prod: while last >= -n and prod < arr[i][0]: if prod + arr[last][1] <= arr[i][0]: prod += arr[last][1] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR WHILE VAR VAR VAR VAR VAR NUM...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
prices = [] for _ in range(int(input())): ai, bi = map(int, input().split()) prices.append([ai, bi]) prices.sort(key=lambda x: x[1]) p, q = 0, len(prices) - 1 count = 0 bought = 0 while p <= q: if bought < prices[p][1]: tmp = min(prices[q][0], prices[p][1] - bought) count += 2 * tmp ...
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER ASSIGN VA...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
import sys input = sys.stdin.readline n = int(input()) a = [] b = 0 for _ in range(n): c, d = map(int, input().split()) a.append((c, d)) b += c a.sort(key=lambda x: x[1]) aa = [a[0]] for i in range(1, n): if a[i][1] == a[i - 1][1]: aa[-1] = aa[-1][0] + a[i][0], a[i][1] else: aa.appe...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
a = sorted([*map(int, s.split())][::-1] for s in [*open(0)][1:]) i = c = r = 0 j = len(a) - 1 while i <= j: x = _, y = a[j] d = min(a[i][0] - c, y) if d > 0: x[1] -= d r += d j -= d == y else: d = a[i][1] i += 1 c += d print(c + r)
ASSIGN VAR FUNC_CALL VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER VAR LIST FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR ...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
n = int(input()) a = [] for i in range(n): temp = [int(x) for x in input().split()] a.append(temp) a = sorted(a, key=lambda x: x[1]) rubels = 0 xp = 0 i = 0 j = n - 1 while i < j: if a[j][1] <= xp or a[j][0] == 0: xp += a[j][0] rubels += a[j][0] j -= 1 elif a[i][1] <= xp: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR ...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
from sys import stdin, stdout n = int(stdin.readline()) products = [] for _ in range(n): products.append([int(x) for x in stdin.readline().split()]) products.sort(key=lambda x: x[1], reverse=True) answer = 0 volume = 0 front_pointer = 0 back_pointer = n - 1 while front_pointer < back_pointer: if volume + produ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR NUM...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
n = int(input()) arr = [] for _ in range(n): arr.append(list(map(int, input().split()))) arr.sort(key=lambda x: x[1]) lo, hi = 0, n - 1 ans, counter = 0, 0 while lo <= hi: to_buy, req = arr[lo] if counter >= req or to_buy == 0: counter += to_buy ans += to_buy lo += 1 else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR VA...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
def answer(): s, ans = 0, 0 a.sort(key=lambda x: x[1], reverse=True) i, j = 0, n - 1 while i <= j: if a[j][1] >= s + a[i][0]: ans += 2 * a[i][0] s += a[i][0] i += 1 else: a[i][0] -= max(0, a[j][1] - s) ans += 2 * max(0, a[j][1] ...
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR BIN_OP NUMBER FUNC...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
try: n = int(input()) arr = [] total = 0 for _ in range(n): tuples = list(map(int, input().split())) total += tuples[0] arr.append(tuples) arr = list(reversed(sorted(arr, key=lambda item: (item[1], -item[0])))) buy = 0 cost = 0 left = 0 right = n - 1 while...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER A...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
import sys n = int(sys.stdin.readline()) data = [] for i in range(n): temp = list(map(int, sys.stdin.readline().split())) data.append(temp) data.sort(key=lambda x: x[1]) left, right = 0, n - 1 ans, cnt = 0, 0 while left <= right: if cnt >= data[left][1]: ans += data[left][0] cnt += data[lef...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER VAR VAR...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
n = int(input()) arr = [] for w in range(n): inp = input().split() arr.append([int(inp[0]), int(inp[1])]) arr.sort(key=lambda x: x[1]) answer = 0 count = 0 i = 0 j = len(arr) - 1 while i <= j: if arr[i][1] <= count: count += arr[i][0] i += 1 elif arr[j][0] + count <= arr[i][1]: a...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHI...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
n = int(input()) al = [] for _ in range(n): ai, bi = map(int, input().split()) al.append([ai, bi]) al = sorted(al, key=lambda x: x[1]) p1 = 0 p2 = len(al) - 1 quan = 0 cost = 0 while p2 >= p1: diff = al[p1][1] - quan while diff > 0: tmp = min(diff, al[p2][0]) diff -= tmp al[p2][0...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
n = int(input()) l = [] for i in range(n): x, y = map(int, input().split()) l.append([x, y]) l.sort(key=lambda l: l[1]) i = 0 j = n - 1 ans = 0 x = 0 while i <= j: if x >= l[i][1]: ans += l[i][0] x += l[i][0] i += 1 elif x + l[j][0] <= l[i][1]: ans += 2 * l[j][0] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER V...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
import sys input = sys.stdin.readline def solve(): n = int(input()) a = [tuple(reversed(tuple(map(int, input().split())))) for i in range(n)] a.sort() b = [0] * n have = 0 j = len(a) - 1 r = 0 for i in range(len(a)): c, d = a[i] while c > have and j > i: if...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER F...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
n = int(input()) a = [] for _ in range(n): x, y = map(int, input().split()) a.append([x, y]) a.sort(key=lambda k: k[1]) needed = a[0][1] items = 0 i = 0 j = n - 1 ans = 0 while True: if i > j: break elif i == j: if items >= a[i][1]: ans += a[i][0] else: ne...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE NU...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
events = [] def solve(): events.sort(key=lambda x: x[1]) l = 0 r = len(events) - 1 moneyNeeded = 0 productsBought = 0 while l <= r: if productsBought < events[l][1]: delta = events[l][1] - productsBought cost = min(events[r][0], delta) * 2 productsBo...
ASSIGN VAR LIST FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR ...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
n = int(input()) m = [] for i in range(n): a = list(map(int, input().split())) m.append([a[1], a[0]]) m.sort() x = 0 for i in range(n): x += m[i][1] ans = x * 2 for i in range(n - 1, -1, -1): y = x - m[i][0] if y >= m[i][1]: ans -= m[i][1] x -= m[i][1] elif y > 0: ans -= ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CA...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
prices = [] count = 0 n = int(input()) for _ in range(n): ai, bi = map(int, input().split()) prices.append([bi, ai]) count += ai prices.sort() discount = 0 for p in range(n - 1, -1, -1): x = prices[p] if x[0] >= count: continue else: discount += min(count - x[0] - discount, x[1])...
ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER ...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
import sys n = int(input()) items = [] total_items = 0 for _ in range(n): c, l = list(map(int, sys.stdin.readline().strip().split())) total_items += c items.append((c, l)) items.sort(key=lambda x: x[1], reverse=True) total_cost = 2 * total_items pos = 0 while pos < total_items: count, start = items.pop...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR ...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
n = int(input()) a = [] b = [] for i in range(n): x, y = map(int, input().split()) a.append(x) b.append(y) ba = zip(b, a) ba = sorted(ba) temp = [] for i in ba: temp.append(list(i)) ba = temp ans = 0 i = 0 j = n - 1 c = 0 while i <= j: if c >= ba[i][0]: c += ba[i][1] ans += ba[i][1] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL V...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
import sys input = sys.stdin.readline n = int(input()) ar = [] for i in range(int(n)): ar.append(list(map(int, input().split()))) ar.sort(key=lambda x: x[1]) j = n - 1 tot = 0 ans = 0 for i in range(n): req = max(ar[i][1] - tot, 0) while req != 0: if j < 0: break a = ar[j][0] ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN ...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
import sys input = sys.stdin.readline n = int(input()) v = [] for i in range(n): a, b = map(int, input().split()) v.append([a, b]) v.sort(key=lambda x: x[1]) ans = 0 l = 0 r = n - 1 now = 0 while True: if v[l][1] <= now: ans += v[l][0] now += v[l][0] l += 1 else: a, b = ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
n = int(input()) li = [] for case in range(n): tp = list(map(int, input().split())) li.append(tp) li.sort(key=lambda x: (x[1], x[0])) l, r = 0, len(li) - 1 totalBought = 0 totalCost = 0 while l <= r: minNeedForDisc = max(li[l][1] - totalBought, 0) if not minNeedForDisc: totalBought += li[l][0] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSI...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
n = int(input()) u = [] for i in range(n): a, b = map(int, input().split()) u.append([a, b]) u.sort(key=lambda x: x[1]) i1 = 0 i2 = -1 ans = 0 k = 0 for _ in range(n): while i2 < len(u) - 1 and u[i2 + 1][1] <= k: i2 += 1 if i1 > i2: if u[-1][0] < u[i2 + 1][1] - k: ans += 2 * ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP FUNC_...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
import sys input = sys.stdin.readline n = int(input()) A = [list(map(int, input().split())) for _ in range(n)] A.sort(key=lambda x: (x[1], x[0])) ans = 0 j = n - 1 cur = 0 for i, (a, b) in enumerate(A): if a == 0: break while j > i and cur < b: d = min(b - cur, A[j][0]) A[j][0] -= d ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER WHILE VAR VAR VA...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
n = int(input()) ab = [] for i in range(n): ab.append([int(x) for x in input().split()]) ab.sort(key=lambda x: x[1]) i = 0 j = n - 1 cnt = 0 ans = 0 while i <= j: if ab[i][1] <= cnt: ans += ab[i][0] cnt += ab[i][0] ab[i][0] = 0 i += 1 else: k = min(ab[j][0], ab[i][1] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VA...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
from sys import stdin input = stdin.readline rn = lambda: int(input()) rns = lambda: map(int, input().split()) rl = lambda: list(map(int, input().split())) rs = lambda: input() YN = lambda x: print("YES") if x else print("NO") mod = 10**9 + 7 n = rn() items = [] t = 0 for i in range(n): items.append(rl()) t +=...
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CA...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
b, a = zip(*sorted([*map(int, s.split())][::-1] for s in [*open(0)][1:])) (*a,) = a i = c = r = 0 j = len(a) - 1 while i <= j: if (d := min(b[i] - c, a[j])) > 0: a[j] -= d c += d r += d j -= a[j] < 1 else: c += a[i] i += 1 print(c + r)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER VAR LIST FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUM...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
n = int(input()) a = [""] * n ans = 0 sm = 0 for i in range(n): g, h = [int(x) for x in input().split()] a[i] = [h, g] sm += g a.sort() for i in range(n - 1, -1, -1): x = a[i] k = min(x[0], sm) ans += min(sm - ans - k, x[1]) print(sm * 2 - ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR ...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
arr = [] for _ in range(int(input())): arr.append(list(map(int, input().split()))) arr = sorted(arr, key=lambda x: x[1], reverse=True) p = 0 c = 0 i = 0 j = len(arr) - 1 while i <= j: need = arr[j][1] if need <= c: p += arr[j][0] c += arr[j][0] j -= 1 continue diff = need...
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR NU...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
import sys input = sys.stdin.readline n = int(input()) ab = [list(map(int, input().split())) for i in range(n)] ab.sort(key=lambda x: x[1]) sa = 0 for i in range(n): sa += ab[i][0] c = 0 for i in range(n)[::-1]: r = sa - ab[i][1] c += max(min(r, ab[i][0]), 0) sa -= max(min(r, ab[i][0]), 0) print(sa * 2...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
n = int(input()) a = [] b = [] d = 0 bl = [] for i in range(n): q = input().split() a.append(int(q[0])) bl.append([int(q[1]), int(q[0])]) sa = sum(a) lb = len(bl) for i in range(lb): if bl[i][0] < sa: b.append(bl[i]) b.sort(reverse=True) sat = sa for i in range(len(b)): x = min(sat - b[i][0]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN ...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
import sys input = sys.stdin.buffer.readline n = int(input()) a = [] for i in range(n): b, c = map(int, input().split()) a.append([c, b]) a.sort(reverse=True) pre_cup = 0 cost = 0 i = 0 j = n - 1 add = 0 while i <= j: if pre_cup >= a[j][0]: cost += a[j][1] pre_cup += a[j][1] j -= 1 ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER W...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
n, p, k, sm, nn = int(input()), [], 0, 0, 0 for i in range(n): a, b = map(int, input().split()) p.append([b, a]) nn += a p.sort() u = 0 d = n - 1 while k < nn: if p[u][0] > k: a = min(p[u][0] - k, p[d][1]) if k >= p[d][0]: sm += a else: sm += 2 * a ...
ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR FUN...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store β€” "PriceFixed". Here are some rules of that store: The store has an infinite number of items of every product. All products have the same price: $2$ rubles per item. For every...
def solve(n: int, a) -> int: a.sort(key=lambda x: x[1]) left = 0 right = n - 1 bought = 0 cost = 0 while left <= right: if bought < a[left][1]: buying = min(a[right][0], a[left][1] - bought) a[right][0] -= buying bought += buying cost += 2 ...
FUNC_DEF VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR BIN_OP NUMBER VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR...
This is the harder version of the problem. In this version, $1 \le n \le 10^6$ and $0 \leq a_i \leq 10^6$. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems Christmas is coming, and our protagonist, Bob, is preparing a spectacular present for his long-ti...
import sys input = sys.stdin.buffer.readline n = int(input()) a = list(map(int, input().split())) if sum(a) == 1: print(-1) exit() sm = sum(a) nmax = 10**6 + 10 eratos = [(0) for i in range(nmax + 1)] prime = [] cnt = 2 while True: while cnt <= nmax and eratos[cnt]: cnt += 1 if cnt > nmax: ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP V...
This is the harder version of the problem. In this version, $1 \le n \le 10^6$ and $0 \leq a_i \leq 10^6$. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems Christmas is coming, and our protagonist, Bob, is preparing a spectacular present for his long-ti...
def simple_div(x): if not x & 1: yield 2 while not x & 1: x >>= 1 i = 3 while i * i <= x: if x % i == 0: yield i while x % i == 0: x //= i i += 2 if x != 1: yield x def __main__(): n = int(input()) a = ...
FUNC_DEF IF BIN_OP VAR NUMBER EXPR NUMBER WHILE BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR VAR WHILE BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER EXPR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_...
This is the harder version of the problem. In this version, $1 \le n \le 10^6$ and $0 \leq a_i \leq 10^6$. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems Christmas is coming, and our protagonist, Bob, is preparing a spectacular present for his long-ti...
import sys def prime_decomposition(n): i = 2 table = [] while i * i <= n: while n % i == 0: n //= i table.append(i) i += 1 if n > 1: table.append(n) return table input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) su = s...
IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE BIN_OP VAR VAR VAR WHILE BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
a = input().strip() b = input().strip() n, m = len(a), len(b) p = m - 1 en = [-1] * m for j in range(n - 1, -1, -1): if a[j] == b[p]: en[p] = j p -= 1 if p == -1: break st = [-1] * m p = 0 for j in range(n): if a[j] == b[p]: st[p] = j p += 1 if p == m: bre...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP L...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
import sys def input(): return sys.stdin.readline().rstrip() def slv(): S = input() T = input() n = len(T) needcntl = [0] * (n + 1) needcntr = [0] * (n + 1) idx = 0 i = 0 while i < n: if T[i] == S[idx]: needcntl[i + 1] = idx + 1 i += 1 idx ...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VA...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
from sys import stdin s = stdin.readline().strip() s1 = stdin.readline().strip() dp = [(-1) for i in range(len(s1) + 1)] dp1 = [(-1) for i in range(len(s1) + 1)] x = 0 for i in range(len(s)): if s[i] == s1[x]: dp[x + 1] = i x += 1 if x >= len(s1): break x = len(s1) - 1 y = 1 dp[...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = " " + input() + " " t = " " + input() + " " f = [0] cnt = 0 for i in range(1, len(s)): f.append(f[i - 1]) if s[i] == t[cnt + 1]: cnt += 1 f[i] += 1 s = s[::-1] t = t[::-1] g = [0] cnt = 0 for i in range(1, len(s)): g.append(g[i - 1]) if s[i] == t[cnt + 1]: cnt += 1 g[...
ASSIGN VAR BIN_OP BIN_OP STRING FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP STRING FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSI...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
from sys import stdin, stdout input = stdin.readline s, t = list(map(str, stdin.read().split())) n, m = len(s), len(t) a = [0] * m b = [0] * m pos = 0 for i in range(n): if s[i] == t[pos]: a[pos] = i pos += 1 if pos == m: break pos = m - 1 for i in range(n - 1, -1, -1): if s...
ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR ...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() t = input() def compute_prefix(s, t): prefix = [(0) for i in range(len(t) + 1)] i = 0 j = 0 while i < len(t): while s[j] != t[i]: j += 1 prefix[i + 1] = j + 1 i += 1 j += 1 return prefix prefix = compute_prefix(s, t) suffix = compute_prefix...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
from sys import stdin input = stdin.readline s = input() t = input() n = len(t) low = [(0) for i in range(len(t))] high = [(0) for i in range(len(t))] acc = 0 for i in range(n): acc_t = t[i] while acc_t != s[acc]: acc += 1 low[i] = acc acc += 1 acc = len(s) - 1 for i in range(len(t)): acc_t...
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUM...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() t = input() i = 0 l = [] for c in t: while s[i] != c: i += 1 l.append(i) i += 1 i = len(s) - 1 r = [] for c in t[::-1]: while s[i] != c: i -= 1 r.append(i) i -= 1 r.reverse() mx = r[0] for i in range(len(t) - 1): mx = max(mx, r[i + 1] - l[i] - 1) mx = max(mx, len(...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR WHILE VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR NUMBER WHILE VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR A...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
from sys import setrecursionlimit as SRL from sys import stdin SRL(10**7) rd = stdin.readline rrd = lambda: map(int, rd().strip().split()) s = str(rd().strip()) t = str(rd().strip()) s = "0" + s canl = [0] * (len(s) + 10) canr = [0] * (len(s) + 10) j = 0 for i, v in enumerate(s): if j < len(t) and v == t[j]: ...
EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BI...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() t = input() s2 = s[::-1] t2 = t[::-1] n = len(s) m = len(t) pos = [0] * m j = 0 for i in range(n): if s[i] == t[j]: pos[j] = i j += 1 if j == m: break pos2 = [0] * m j = 0 for i in range(n): if s2[i] == t2[j]: pos2[j] = i j += 1 if j == m: ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER ...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
import sys input = sys.stdin.readline s = input() t = input() l, r = [0] * len(t), [0] * len(t) li, ri = 0, len(s) - 1 for i in range(len(t)): while s[li] != t[i]: li += 1 while s[ri] != t[-i - 1]: ri -= 1 l[i] = li r[-i - 1] = ri li += 1 ri -= 1 print( max( [r[0], l...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUM...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() t = input() n, m = len(s), len(t) i, j = 0, 0 first = [] last = [] while j < m: if s[i] == t[j]: first.append(i) i += 1 j += 1 else: i += 1 i, j = n - 1, m - 1 while j >= 0: if s[i] == t[j]: last.append(i) j -= 1 i -= 1 last = last[::-1] ans = ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR NUMBER I...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
from sys import setcheckinterval, stdin setcheckinterval(1000) def iin(): return int(stdin.readline()) def lin(): return list(map(int, stdin.readline().split())) s = input() t = input() n = len(s) d1 = {} d1[0] = -1 d2 = {} d2[0] = n l = len(t) ch = 0 for i in range(n): if ch == l: break ...
EXPR FUNC_CALL VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER VAR ASSIGN VAR FUNC_CALL...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
def main(): string = input() substring = input() size = len(substring) string_size = len(string) first = [] last = [] first.append(-1) index = 0 for i in range(string_size): c = string[i] if c == substring[index]: first.append(i) index = index ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() t = input() r = [0] * len(t) for i in range(len(t) - 1, -1, -1): p = len(s) - 1 if i + 1 < len(t): p = r[i + 1] - 1 while t[i] != s[p]: p -= 1 r[i] = p ans = p = 0 for i in range(len(s)): rp = len(s) - 1 if p < len(t): rp = r[p] - 1 ans = max(rp - i + 1, a...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR VAR VAR...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
def find_first(s, t): idx = 0 l = [-1] for i in range(len(s)): if t[idx] == s[i]: l.append(i) idx += 1 if idx == len(t): return l return None def find_last(s, t): idx = len(t) - 1 l = [len(s)] for i in range(len(s) - 1, -1, -1): i...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN VAR RETURN NONE FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR ...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() t = input() j = len(t) - 1 last = [None] * len(t) for _i in range(len(s)): i = len(s) - _i - 1 if j >= 0 and s[i] == t[j]: last[j] = i j -= 1 answer = -1 j = 0 first = [None] * len(t) for i in range(len(s)): if j < len(t): if s[i] == t[j]: first[j] = i ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NONE FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VA...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() t = input() n = len(t) b = [0] * (len(s) + 1) a = [0] * (len(s) + 1) c = 0 for i in range(len(s)): if c == n: b[i + 1] = c elif s[i] == t[c]: c += 1 b[i + 1] = c else: b[i + 1] = c c = n - 1 for i in range(len(s) - 1, -1, -1): if c == -1: a[i] = n ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR ...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
big = input() small = input() pre = [] post = [] i = 0 j = 0 while 1: if j == len(small): break if big[i] == small[j]: pre.append(i) i += 1 j += 1 else: i += 1 big = big[::-1] small = small[::-1] i = 0 j = 0 while 1: if j == len(small): break if big[i]...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUM...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() t = input() n, m = len(s), len(t) ans = 0 max_pos = [(-1) for i in range(m)] max_pos.append(n) j = m - 1 for i in range(n - 1, -1, -1): if j < 0: ans = max(ans, i + 1) break if j >= 0 and s[i] == t[j]: max_pos[j] = i j -= 1 curr = 0 for i in range(n): if curr < m ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR N...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
def solver(): s = input().strip() t = input().strip() left = [len(s)] * len(t) right = [-1] * len(t) cnt = 0 for i in range(len(t)): while s[cnt] != t[i]: cnt += 1 left[i] = cnt cnt += 1 cnt = len(s) - 1 for i in range(len(t) - 1, -1, -1): whil...
FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR BI...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() t = input() s_pos = [len(s) for i in range(len(t))] i, j = len(s) - 1, len(t) - 1 while i > -1 and j > -1: if s[i] == t[j]: s_pos[j] = i j -= 1 i -= 1 p, q = 0, 0 ans = 0 while p < len(s): if q == len(t): ans = max(ans, len(s) - p) break remove = s_pos[q] - p ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VA...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
import sys in_file = sys.stdin s = in_file.readline().strip() t = in_file.readline().strip() L = [0] l = 0 R = [0] r = len(t) - 1 for i in range(len(s)): if l < len(t) and s[i] == t[l]: l += 1 L.append(l) if r >= 0 and s[len(s) - i - 1] == t[r]: r -= 1 R.append(len(t) - r - 1) Lc = [(-1...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = str(input()) t = str(input()) i = 0 j = 0 arr1 = [] while i < len(s): if s[i] == t[j]: arr1.append(i + 1) j += 1 i += 1 if j == len(t): break i = len(s) - 1 j = len(t) - 1 arr2 = [0] * len(t) while i >= 0: if s[i] == t[j]: arr2[j] = i + 1 j -= 1 i -= 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_O...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() t = input() n = len(s) m = len(t) dp1 = [0] * (n + 1) for i in range(n): dp1[i + 1] = dp1[i] if dp1[i] < m and s[i] == t[dp1[i]]: dp1[i + 1] += 1 dp2 = [0] * (n + 1) for i in range(n - 1, -1, -1): dp2[i] = dp2[i + 1] if dp2[i + 1] < m and s[i] == t[-1 - dp2[i + 1]]: dp2[i] +=...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP ...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() n = len(s) t = input() m = len(t) rg = [0] * m j = m - 1 for i in range(n): if s[n - 1 - i] == t[j]: rg[j] = n - 1 - i if j == 0: break j -= 1 lg = [0] * m j = 0 for i in range(n): if s[i] == t[j]: lg[j] = i if j == m - 1: break ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() t = input() n, m = len(s), len(t) l, r, j = [0] * m, [0] * m, 0 for i in range(m): while s[j] != t[i]: j += 1 l[i] = j j += 1 j = n - 1 for i in range(m - 1, -1, -1): while s[j] != t[i]: j -= 1 r[i] = j j -= 1 ans = max(0, r[0], n - 1 - l[-1]) for i in range(m - 1): ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP ...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() t = input() dfirst = {} dlast = {} mx = -99 x = 0 for i in range(len(t)): while s[x] != t[i]: x += 1 dfirst[i] = x if i == len(t) - 1: mx = max(mx, len(s) - x - 1) x += 1 x = len(s) - 1 trev = t[::-1] for i in range(len(trev)): while s[x] != trev[i]: x -= 1 dl...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
def f(n): for i in range(-1, lt): if right[i + 1] - left[i] > n: return True return False s = input() t = input() ls = len(s) lt = len(t) right = dict() left = dict() i = 0 j = 0 ls = len(s) left[-1] = -1 while i < lt: if s[j] == t[i]: left[i] = j i += 1 j += 1 j = ...
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR F...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = list(input()) t = list(input()) fo = [] ti = 0 for i, c in enumerate(s): if c == t[ti]: ti += 1 fo.append(i) if ti == len(t): break lo = [] ti = len(t) - 1 for i in reversed(range(len(s))): c = s[i] if c == t[ti]: ti -= 1 lo.append(i) if ti == ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() t = input() ar1 = [] i = 0 for j in range(len(s)): if i < len(t) and s[j] == t[i]: ar1.append(j) i += 1 i = len(t) - 1 ar2 = [0] * len(t) j = len(s) - 1 while j >= 0: if i >= 0 and s[j] == t[i]: ar2[i] = j i -= 1 j -= 1 ans = ar1[0] ans = max(ans, ar2[0]) ans = ma...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VA...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s1 = list(input()) r_s1 = s1[::-1] s2 = list(input()) r_s2 = s2[::-1] l1 = len(s1) l2 = len(s2) arr1 = [] arr2 = [] i = 0 j = 0 while i < l1 and j < l2: if s1[i] == s2[j]: arr1.append(i) j += 1 i += 1 i = 0 j = 0 while i < l1 and j < l2: if r_s1[i] == r_s2[j]: arr2.append(l1 - 1 - i)...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMB...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() t = input() n = len(s) m = len(t) le = [] ri = [] ans = 0 p = 0 for i in range(n): if p < m: if s[i] == t[p]: le.append(i) if p == m - 1: ans = max(ans, n - 1 - i) p += 1 p = m - 1 for j in range(n - 1, -1, -1): if p >= 0: if s[j] =...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() t = input() pr = [] pospr = [] j = 0 for i in range(len(s)): if j != len(t) and s[i] == t[j]: j += 1 pospr.append(i) pr.append(j) suf = [0] * len(s) j = len(t) - 1 possuf = [0] * len(t) for i in range(len(s) - 1, -1, -1): if j != -1 and s[i] == t[j]: possuf[j] = i ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VA...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
str1 = input() str2 = input() n, m = len(str1), len(str2) pos, i = [], 0 for p in range(n): if i == m: break if str1[p] == str2[i]: pos.append(p) i += 1 pos = [-1] + pos + [n] ans = 0 for i in range(1, m + 2): ans = max(ans, pos[i] - pos[i - 1] - 1) i = 0 for p in range(n - 1, -1, -1...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR LIST VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_O...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
def solve(): s1 = input() s2 = input() i = 0 left = [] for c in s2: while c != s1[i]: i += 1 left.append(i) i += 1 i = -1 right = [] for c in s2[::-1]: while c != s1[i]: i -= 1 right.append(len(s1) + i) i -= 1 ri...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR WHILE VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR NUMBER WHILE VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_C...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() t = input() n = len(t) first = [0] * n last = [0] * n p = 0 i = 0 while p < n: if s[i] == t[p]: first[p] = i p += 1 i += 1 p = n - 1 i = len(s) - 1 while p >= 0: if s[i] == t[p]: last[p] = i p -= 1 i -= 1 ans = max(last[0], len(s) - 1 - first[-1]) for i in ran...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VA...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() t = input() fp = [-1] tp = 0 for i in range(len(s)): if s[i] == t[tp]: fp.append(i) tp += 1 if tp == len(t): break lp = [len(s)] tp = len(t) - 1 for i in range(len(s) - 1, -1, -1): if s[i] == t[tp]: lp.append(i) tp -= 1 if tp == -1: ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() t = input() left = [-1] rightReversed = [len(s)] i = 0 for x in range(len(s)): if t[i] == s[x]: left.append(x) i += 1 if i >= len(t): break i = len(t) - 1 for x in range(len(s) - 1, -1, -1): if t[i] == s[x]: rightReversed.append(x) i -= 1 if i < 0: ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() t = input() pos = [[-1, -1] for i in range(len(t))] ptr = 0 for i, c in enumerate(t): while s[ptr] != c: ptr += 1 pos[i][0] = ptr ptr += 1 ptr = len(s) - 1 for i in range(len(t) - 1, -1, -1): c = t[i] while s[ptr] != c: ptr -= 1 pos[i][1] = ptr ptr -= 1 best = max...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR ...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
from sys import stdin, stdout s = stdin.readline().strip() t = stdin.readline().strip() leftmost = [-1] ptr1 = ptr2 = 0 while ptr2 < len(t): if s[ptr1] == t[ptr2]: leftmost.append(ptr1) ptr1 += 1 ptr2 += 1 else: ptr1 += 1 rightmost = [] ptr1 = len(s) - 1 ptr2 = len(t) - 1 while ...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
big = input() small = input() left = [0] * (len(small) + 1) left[0] = -1 wsk = -1 for i in range(1, len(small) + 1): while True: wsk += 1 if big[wsk] == small[i - 1]: left[i] = wsk break big = big[::-1] small = small[::-1] right = [0] * (len(small) + 1) right[0] = -1 wsk = -1...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
l1 = [i for i in input()] l2 = [i for i in input()] length1 = len(l1) length2 = len(l2) ij = 0 ji = len(l2) - 1 count1 = [] count2 = [] for i in range(length1): if ij < length2: if l1[i] == l2[ij]: ij += 1 count1.append(i) if ji >= 0: if l1[-i - 1] == l2[ji]: ...
ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
def process(s, t): l = [] r = [0] * len(t) j = 0 for i in range(len(t)): while s[j] != t[i]: j += 1 l.append(j) j += 1 j = len(s) - 1 for i in reversed(range(len(t))): while s[j] != t[i]: j -= 1 r[i] = j j -= 1 res = max...
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() t = input() f, b = [], [] cur = len(t) - 1 for i in range(len(s) - 1, -1, -1): if s[i] == t[cur]: b.append(i) cur -= 1 if cur == -1: break b.sort() cur = 0 for i in range(len(s)): if s[i] == t[cur]: f.append(i) cur += 1 if cur == len(t): break ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CAL...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() t = input() n = len(s) m = len(t) l = [-1] r = [n] c = 0 for i in range(n): if s[i] == t[c]: l.append(i) c += 1 if c >= m: break c = 0 for i in range(n): if s[-1 - i] == t[-1 - c]: r.append(n - 1 - i) c += 1 if c >= m: break mx ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP NUM...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() t = input() lastL = [0] * len(t) lastR = [0] * len(t) j = 0 for i in range(len(s)): if s[i] == t[j]: lastL[j] = i j += 1 if j >= len(t): break j = len(t) - 1 for i in range(len(s) - 1, -1, -1): if s[i] == t[j]: lastR[j] = i j -= 1 if j < 0: bre...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() t = input() forward = [] backward = [] rptr = 0 for i in range(len(s)): if rptr == len(t): break if s[i] == t[rptr]: forward.append(i) rptr += 1 rptr = len(t) - 1 for i in range(len(s) - 1, -1, -1): if rptr == -1: break if s[i] == t[rptr]: backward.app...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBE...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
import sys inf = float("inf") mod, MOD = 1000000007, 998244353 def is_subsq(a, b): i = 0 j = 0 while i < len(b) and j < len(a): if a[j] == b[i]: j += 1 i += 1 return j == len(a) def get_array(): return list(map(int, sys.stdin.readline().strip().split())) def get_in...
IMPORT ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
a = input() b = input() n = len(a) m = len(b) i = 0 j = 0 f, bb = [0] * m, [0] * m while j != m: if a[i] == b[j]: f[j] = i i += 1 j += 1 else: i += 1 i = 0 j = 0 while j != m: if a[n - 1 - i] == b[m - 1 - j]: bb[m - 1 - j] = n - 1 - i i += 1 j += 1 ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR WHILE VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR N...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() t = input() sl, tl = len(s), len(t) left = [] right = [] x = 0 for i in range(sl): if x < tl and s[i] == t[x]: left.append(i) x += 1 x = tl - 1 for i in range(sl - 1, -1, -1): if x >= 0 and s[i] == t[x]: right.append(i) x -= 1 right.reverse() if tl == 1: print(max...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() t = input() l = 0 pre = [] suf = [] for i in range(len(s)): if s[i] == t[l]: pre.append(i) l += 1 if l == len(t): break l = len(t) - 1 for i in range(len(s) - 1, -1, -1): if s[i] == t[l]: suf.append(i) l -= 1 if l == -1: break pre.sort() suf.so...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBE...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
import sys s = sys.stdin.readline() t = sys.stdin.readline() sn, tn = len(s), len(t) left, right = [0] * tn, [0] * tn prev, last = -1, sn for i in range(tn): left[i] = prev = s.find(t[i], prev + 1) right[tn - i - 1] = last = s.rfind(t[tn - i - 1], 0, last) ans = max(right[i + 1] - left[i] - 1 for i in range(tn...
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ...