description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
import sys mod, MOD = 1000000007, 998244353 def get_array(): return list(map(int, sys.stdin.readline().strip().split())) def get_ints(): return map(int, sys.stdin.readline().strip().split()) def input(): return sys.stdin.readline().strip() def check(Arr): come = set() go = set() for i i...
IMPORT ASSIGN VAR VAR NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR NUMBER IF FUNC_C...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
import sys input = sys.stdin.readline n = int(input()) A = list(map(int, input().split())) NOW = set() USED = set() ANS = [0] for i in range(n): if A[i] > 0: if A[i] in NOW or A[i] in USED: print(-1) return else: NOW.add(A[i]) USED.add(A[i]) elif ...
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 ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL ...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) set_ = set([]) set_2 = set([]) ans = [] for i in range(n): if a[i] > 0: if a[i] not in set_2: set_.add(a[i]) else: print(-1) exit() set_2.add(a[i]) elif abs(a[i...
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 ASSIGN VAR FUNC_CALL VAR LIST ASSIGN VAR FUNC_CALL VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
N = int(input()) current = set() entered = set() events = [] A = list(map(int, input().split())) try: n_events = 0 for i, ai in enumerate(A): n_events += 1 if ai < 0: assert -ai in current current.remove(-ai) else: assert ai not in entered ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CAL...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
def main(): n = int(input()) err_ = False array = list(map(int, input().split())) peolpe = {} peolpe_sum = 0 event = 0 ans = [] for i in range(n): a = array[i] if a > 0 and a not in peolpe: peolpe[a] = True peolpe_sum += a elif a < 0 and -a...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR VAR IF VAR NUMBER VAR VAR ...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
def valid(a): s = set() for i in a: if i < 0: if abs(i) not in s: return 0 if i > 0: if i in s: return 0 else: s.add(i) return 1 n = int(input()) a = list(map(int, input().split())) l = a.copy() c = 0 f = 0...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR NUMBER IF FUNC_CALL VAR VAR VAR RETURN NUMBER IF VAR NUMBER IF VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUM...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
def main(n, a): num = 0 num_list = [0] tmp = set() used = set() for elem in a: if elem > 0: if elem not in used: tmp.add(elem) used.add(elem) num_list[-1] += 1 else: print(-1) exit() ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUM...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
n = int(input()) a = list(map(int, input().split())) count = 0 e, l = {}, {} ans = [] for i in a: if i > 0 and i in e: count = -1 break elif i > 0: e[i] = 1 count += 1 elif i in l: count = -1 break else: if -1 * i not in e: count = -1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR DICT DICT ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF BIN_OP NUMBER VAR VAR AS...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
n = int(input()) arr = [int(p) for p in input().split()] preSum = arr.copy() for i in range(1, n): preSum[i] += preSum[i - 1] s = set() size = [] for i in range(len(preSum)): if arr[i] < 0: if -arr[i] not in s: print(-1) exit() if preSum[i] == 0: size.append(len(s) + ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUM...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
vis = [(-1) for i in range(1000005)] val_days = list() def valid_day(mov): tot_sum = 0 if mov[0] < 0: print(-1) return for m in mov: tot_sum += m if tot_sum != 0: print(-1) return curr_sum = 0 curr_cnt = 0 for i in range(len(mov)): if mov[i] ...
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER RETURN FOR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
n = int(input()) ls = [int(x) for x in input().split()] s = set() vis = set() flag = 0 ans = [] count = 0 for i in range(len(ls)): count += 1 if ls[i] > 0: if ls[i] in s or ls[i] in vis: flag = 1 break else: s.add(ls[i]) vis.add(ls[i]) else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUN...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
n = int(input()) a = list(map(int, input().split())) rab = set() office = set() dc = [] end = True d = 0 c = -1 for i in range(len(a)): if a[i] > 0: if a[i] not in office: office.add(a[i]) rab.add(a[i]) else: print(-1) exit() elif -a[i] in office: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VA...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
n = int(input()) logs = list(map(int, input().split())) days = [0] c, p, chk = set(), set(), True for i in range(n): if logs[i] > 0 and logs[i] in c or logs[i] < 0 and -1 * logs[i] not in p: chk = False break if logs[i] < 0: p.remove(-1 * logs[i]) if len(p) == 0: days...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER BIN_OP NUMBER VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER EXPR...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
n = int(input()) a = [int(j) for j in input().split()] days = [] cur_emp = set() day_emp = set() day_cnt = 0 for event in a: emp = abs(event) if event > 0: if emp in day_emp: print(-1) exit(0) day_emp.add(emp) cur_emp.add(emp) else: if emp not in cur_e...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
import sys def main(): n = int(input()) a = list(map(int, input().split())) dp = {} arr = [] cnt = 0 last = 0 for i in range(n): if a[i] > 0: if dp.get(a[i]) != None: print(-1) return dp[a[i]] = 1 cnt += 1 ...
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NONE EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR VAR VAR NUMB...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
n = int(input()) l = list(map(int, input().split(" "))) t = [] t1 = [] a = [0] * 1000001 flag = 0 s = 0 for i in range(0, n): if l[i] > 0: a[l[i]] += 1 if a[l[i]] > 1: flag = 1 break if l[i] < 0: if a[-l[i]] == 0: flag = 1 break if ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
from sys import stdin n = int(stdin.readline().strip()) s = list(map(int, stdin.readline().strip().split())) en = [(0) for i in range(10**6 + 7)] vis = [(0) for i in range(10**6 + 7)] ans = [0] flag = True cnt = 0 v = [] for i in range(n): ans[-1] += 1 vis if s[i] > 0: en[s[i]] += 1 vis[s[i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR ...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
n = int(input()) l = list(map(int, input().split())) d = [] c, s = 0, 0 dd = {} ddd = {} f = 0 for i in range(n): if l[i] > 0: if l[i] not in dd: dd[l[i]] = 1 else: dd[l[i]] += 1 if dd[l[i]] > 1: f = 1 break else: x = abs(l[i]) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR ...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
import sys input = sys.stdin.readline def main(): emp_n = 10**6 N = int(input()) A = [int(x) for x in input().split()] ent = [0] * (emp_n + 1) days = 0 s = set() is_valid = True co = 0 ans = [] for i in range(N): if not s: ans.append(co) co = 0 ...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL ...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
import sys input = sys.stdin.buffer.readline n = int(input()) l = list(map(int, input().split())) entered = 0 left = 0 array = [0] * (10**6 + 1) no_of_days = [] flag = 0 log = [] for i in l: if entered - left < 0: flag = 1 break if i > 0: if array[i] == 0: array[i] += 1 ...
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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR VAR NUMBER ASSI...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
def main(): input() office, table, res, i = set(), set(), [], -1 for j, s in enumerate(input().split()): if s[0] == "-": s = s[1:] if s not in office: return print("-1") office.remove(s) if not office: res.append(j - i) ...
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR LIST NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR VAR NUMBER IF VAR VAR RETURN FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
n = int(input()) A = list(map(int, input().split())) res = [] cnt = 0 employees = set() last = 0 emp_cnt = set() for i in range(n): if A[i] > 0: if A[i] in employees: print("-1") break else: employees.add(A[i]) if A[i] in emp_cnt: print...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR ...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
inside = set() entered = set() n = int(input()) events = list(map(int, input().split())) days = 0 edays = [] currente = 0 for i in range(n): p = events[i] if p > 0: if p not in entered: inside.add(p) entered.add(p) currente += 1 else: days = -1 ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
n = int(input()) list1 = list(map(int, input().split())) list2 = [] set1 = {list1[0]} list2.append(list1[0]) ll = [] f = 0 dict1 = {} if list1[0] > 0: dict1[list1[0]] = 1 else: f = 1 if f == 0: for i in range(1, n): if list1[i] > 0: if list1[i] in set1: f = 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR DICT IF VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_C...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
n = int(input()) a = list(map(int, input().split())) s = set() d = 0 ans = [] c = 0 o = set() for i in range(n): x = a[i] if x > 0: if i == 0: c += 1 s.add(x) o.add(x) elif len(s): if x in s or x in o: d = -1 break ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR ...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
a = int(input()) b = list(map(int, input().split())) def solve(a, b): checkedin = set() blocked = set() ans = [] if a % 2 != 0: return -1 for i in b: if i > 0: if i in blocked or i in checkedin: return -1 else: checkedin.add(i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER FOR VAR VAR IF VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
import sys n = int(input()) array = [int(s) for s in input().split()] a = set() people = [0] * 1000001 used = [] prev = 0 ans = [] for i in range(len(array)): if array[i] < 0 and not -array[i] in a or array[i] > 0 and people[array[i]] == 1: print(-1) sys.exit(0) else: if array[i] < 0 an...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER E...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
n = int(input()) a = list(map(int, input().split())) inside = set() flag = True j = 1 ans = list() b = set() for i in range(len(a)): if a[i] > 0: if a[i] in inside or a[i] in b: flag = False else: inside.add(a[i]) b.add(a[i]) elif -a[i] in inside: insi...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
n = int(input()) l = list(map(int, input().split())) flag = True d = {} for i in l: try: d[i] += 1 except: d[i] = 1 for i in d.keys(): try: if d[i] != d[-1 * i]: flag = False break except: flag = False break if flag: ans = [] d = {}...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR LIST ASSIGN VAR DICT A...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
n = int(input()) s = 0 a = [-1] m = set() tmp = list(map(int, input().split())) for i in range(n): j = tmp[i] s += j if j < 0 and -j not in m or j in m: print("-1") exit() m.add(j) if not s: m = set() a.append(i) if a[-1] != n - 1: print(-1) else: print(len(a)...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR V...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
d = {} input() i = s = 0 r = [0] for x in map(int, input().split()): i += 1 s += x if x > 0: if d.get(x, 0): r = (-1,) break d[x] = 2 else: if d.get(-x, 0) < 2: r = (-1,) break d[-x] = 1 if s == 0: r[0] +...
ASSIGN VAR DICT EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR VAR IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER ...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
n = int(input()) a = [int(j) for j in input().split()] l = [(0) for i in range(int(1000000.0 + 1))] tot = 0 flag = True days = [] so_fa = 0 s = set() for i in range(n): if a[i] > 0: if l[a[i]] == 0 and a[i] not in s: s.add(a[i]) l[a[i]] += 1 tot += 1 so_fa += ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR VAR...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
import sys def input(): str = sys.stdin.readline() return str[:-1] n = int(input()) arr = list(map(int, input().split(" "))) ans = [] rec = {} totRec = {} for j in range(len(arr)): i = arr[j] if i > 0: if i not in rec and i not in totRec: rec[i] = 1 totRec[i] = 1 ...
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR RETURN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER IF VAR VAR VAR VAR ASSIGN V...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
n = int(input()) days = [int(i) for i in input().split()] pos = True soe = set() resA = [] rs = 0 cd = 0 c = 0 oC = 0 for d in days: if d < 0 and -d not in soe or d in soe: pos = False break if d > 0: oC += 1 else: oC -= 1 rs += d c += 1 soe.add(d) if rs == 0:...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMB...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
def solve(l, n): ans = [] d = {} vis = {} s = 0 s_ans = 0 for t in range(n): if l[t] < 0: if d.get(-1 * l[t], 0) == 0: return -1 else: s += l[t] d[-1 * l[t]] = 0 if l[t] > 0: if d.get(l[t], 0) == ...
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP NUMBER VAR VAR NUMBER NUMBER RETURN NUMBER VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR VAR NUMBER IF VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER NUMBER RETURN ...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
ints = lambda: [int(x) for x in input().split()] def solve(arr): p, inside, entered = [], set(), set() for x in arr: if x < 0 and -x not in inside or x > 0 and x in entered: return [] elif x < 0: inside.remove(-x) if len(inside) == 0: p.appen...
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR LIST FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR RETURN LIST IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL ...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
n = int(input()) t = [int(s) for s in input().split()] la = set() pl = set() bon = True las = 0 rep = [] for i in range(n): e = abs(t[i]) if t[i] > 0: if e in la or e in pl: bon = False break else: la.add(e) elif e in la: la.remove(e) pl.ad...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUN...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
from itertools import accumulate n = int(input()) a = [*map(int, input().split())] aa = [*accumulate(a)] empc = 0 day = set() ans = [] for i, j in zip(a, aa): if i in day or i < 0 and -i not in day: print(-1) exit() else: day.add(i) empc += 1 if j == 0: ans.append(em...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VA...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
n = int(input()) A = list(map(int, input().split())) now = set() used = set() pre = -1 ans = [] for i, a in enumerate(A): if a > 0: if a in now or a in used: print(-1) exit() else: now.add(a) used.add(a) elif -a not in now: print(-1) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
n = int(input()) t = list(map(int, input().split(" "))) sum_ = 0 elements = set() err_, events = False, 0 result = [] for index in range(n): element = t[index] if element > 0 and element not in elements: elements.add(element) sum_ += element elif element < 0 and -element in elements: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER VAR VAR...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
n = int(input()) ln = [int(i) for i in input().split(" ")] seen = {} sm = 0 f = True tk = 0 pts = [] for i in range(0, len(ln)): sm += ln[i] if ln[i] < 0 and -ln[i] not in seen: f = False if ln[i] in seen: seen[ln[i]] += 1 f = False break else: seen[ln[i]] = 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR V...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
input() ans = [] cur = 0 status = set() were = set() try: for ai in map(int, input().split()): cur += 1 if ai < 0: status.remove(abs(ai)) if not status: ans.append(cur) cur = 0 were = set() else: assert ai no...
EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR E...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
n = int(input()) a = list(map(int, input().split())) b = [0] * (10**6 + 1) ans = [] num = 0 p = {} poor = 0 start = 0 for i in range(n): if a[i] > 0: if not a[i] in p: p[a[i]] = 1 num += 1 start += 1 else: poor = 1 break elif abs(a[i]) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR VAR ASSI...
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$. The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i...
n = int(input()) a = [int(x) for x in input().split()] b = [0] * (10**6 + 1) tmp = 0 res = [] tmp2 = [] d = True for i in range(n): if a[i] > 0: if b[a[i]] == 0: b[a[i]] += 1 tmp += 1 tmp2.append(a[i]) else: d = False break elif b[-a[i]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NU...
The problem was inspired by Pied Piper story. After a challenge from Hooli's compression competitor Nucleus, Richard pulled an all-nighter to invent a new approach to compression: middle-out. You are given two strings $s$ and $t$ of the same length $n$. Their characters are numbered from $1$ to $n$ from left to right ...
t = int(input()) for h in range(t): ans = 1000000000 n = int(input()) a = str(input()) b = str(input()) if sorted(a) != sorted(b): ans = -1 else: ans = 10000000000000 for i in range(n): k = i count = 0 for j in range(n): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSI...
The problem was inspired by Pied Piper story. After a challenge from Hooli's compression competitor Nucleus, Richard pulled an all-nighter to invent a new approach to compression: middle-out. You are given two strings $s$ and $t$ of the same length $n$. Their characters are numbered from $1$ to $n$ from left to right ...
from sys import stdin, stdout def getminmove(s, t): len1 = len(s) len2 = len(t) if len1 != len2: return -1 sa = [0] * 26 ta = [0] * 26 for c in s: sa[ord(c) - ord("a")] += 1 for c in t: ta[ord(c) - ord("a")] += 1 for i in range(26): if sa[i] != ta[i]: ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CAL...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): st = "" if D * 9 <= S: return -1 for i in range(D, 0, -1): if S == 1: if i == 1: st += "1" else: st += "0" elif S - 1 >= 9: ...
CLASS_DEF FUNC_DEF ASSIGN VAR STRING IF BIN_OP VAR NUMBER VAR RETURN NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER IF VAR NUMBER VAR STRING VAR STRING IF BIN_OP VAR NUMBER NUMBER VAR STRING VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): t = 9 * D if S >= t or D == 1: return -1 else: a = [(9) for i in range(D)] rem = 9 * D - S j = 0 if rem <= 8: a[0] = a[0] - rem + 1 a[1] = a[1] - 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VA...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): l = [] if S < 10 and D == 1: return -1 if S >= 9 * D: return -1 for i in range(1, D): if S > 9: l.append(9) S = S - 9 continue if S <= 9: ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR BIN_OP NUMBER VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NU...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): if D == 1: return -1 res = [0] * D res[0] = 1 t = 1 i = D - 1 while t < S: t += 9 - res[i] res[i] = 9 i -= 1 if i == -1: break if t <= ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, s, d): if d * 9 <= s: return -1 p = [1] for i in range(d - 1): p.append(0) s -= 1 for i in range(d - 1, -1, -1): if s > 9: p[i] += 9 s -= 9 else: ...
CLASS_DEF FUNC_DEF IF BIN_OP VAR NUMBER VAR RETURN NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBE...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): if D == 1: if S < 10: return S num = [(0) for i in range(D)] for i in range(D - 1, 0, -1): num[i] = min(S - 1, 9) S -= num[i] if S > 9: return -1 num[0] = S ...
CLASS_DEF FUNC_DEF IF VAR NUMBER IF VAR NUMBER RETURN VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR N...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): minD = S // 9 + 1 sum = S if D < minD: return -1 digits = "" res = 0 while S > 0: d = min(S, 9) S -= d digits = str(d) + digits n = len(digits) if n < D: ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): a = [0] * D a[0] = 1 val = S - 1 if S >= 9 * D: return -1 for i in range(0, len(a)): a[-(i + 1)] += min(9, val) val -= a[-(i + 1)] for i in range(1, len(a)): if a[-i - 1] ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP NUMBER VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): temp = [None] * D su = S if S >= D * 9: return "-1" if D == 1: return -1 for i in range(D - 1, 0, -1): d = min(su - 1, 9) temp[i] = d su -= d temp[0] = su ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER RETURN STRING IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): if S >= D * 9: return "-1" if D == 1: return str(S) a = "" temp = S - 1 for i in range(D): if temp >= 9: a += "9" temp -= 9 else: a...
CLASS_DEF FUNC_DEF IF VAR BIN_OP VAR NUMBER RETURN STRING IF VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NU...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): if 9 * D <= S: return -1 s = [(0) for i in range(D)] s[0] = 1 i = D - 1 S -= 1 for i in range(D - 1, -1, -1): if S >= 9: s[i] = 9 S -= 9 else: ...
CLASS_DEF FUNC_DEF IF BIN_OP NUMBER VAR VAR RETURN NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): if S == D and D == 1: return -1 if D * 9 <= S: return -1 ans = ["0"] * D S -= 1 ans[0] = "1" idx = -1 while S: if S >= 9: ans[idx] = "9" S -= 9...
CLASS_DEF FUNC_DEF IF VAR VAR VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER VAR RETURN NUMBER ASSIGN VAR BIN_OP LIST STRING VAR VAR NUMBER ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER WHILE VAR IF VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER V...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): d = D arr = [0] * D arr[0] = 1 s = 1 while D > 0 and s != S: arr[D - 1] += min(S - s, 9) s += arr[D - 1] D -= 1 arr = [str(i) for i in arr] temp = arr flag = True ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL V...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): num = S tot = D s = num - 1 flag = 0 num1 = [] if num < 9 and tot == 1: return num if num >= tot * 9: return -1 else: for i in range(tot - 1, 0, -1): i...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST IF VAR NUMBER VAR NUMBER RETURN VAR IF VAR BIN_OP VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): if D == 1 or S == 1: return -1 k = S // 9 if k >= D: return -1 r = S % 9 if r == 0: r = 9 k -= 1 if k == 0: return 1 * 10 ** (D - 1) + 10 + (r - 2) els...
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP BI...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, s, d): if s == d or s == d * 9 or s > d * 9 or s == 1: return -1 ans = "" f = True while s: val = min(9, s - 1) ans += str(val) s -= val d -= 1 if d == 1: ...
CLASS_DEF FUNC_DEF IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR N...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): if S >= 9 * D: return -1 count = 0 result = [0] * D S -= 1 for i in range(D - 1, 0, -1): if S > 9: result[i] = 9 S -= 9 else: result[i] = S ...
CLASS_DEF FUNC_DEF IF VAR BIN_OP NUMBER VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUM...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): if S >= 9 * D: return -1 ans = [(0) for _ in range(D)] ans[0] = 1 S -= 1 for i in range(D - 1, -1, -1): if S == 0: break dif = min(S, 9 - ans[i]) ans[i] += dif ...
CLASS_DEF FUNC_DEF IF VAR BIN_OP NUMBER VAR RETURN NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP ...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): if S >= D * 9: return "-1" if S <= 9 and D == 1: return str(S) if D == 1 and S >= 10: return "-1" dup = D S -= 1 ans = "" for i in range(D - 1, 0, -1): if S > 9: ...
CLASS_DEF FUNC_DEF IF VAR BIN_OP VAR NUMBER RETURN STRING IF VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER RETURN STRING ASSIGN VAR VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR ASS...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def sm_num(self, S, D): kll = S - 1 ioo = "" nu = kll // 9 rem = kll % 9 if nu > 0: rem += 1 ioo = (nu - 1) * "9" ioo = str(rem) + "8" + ioo elif rem > 0: ioo = str(1) + str(rem - 1) if len(ioo) ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP ...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, s, d): if d == 1: return -1 else: if d * 9 < s: return -1 r = "" for i in range(d - 1, -1, -1): e = i * 9 if e - s >= 0 and i == d - 1: r += "...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER VAR RETURN NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR STRING VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR STRING VAR FUNC_CALL VAR BIN_OP VAR...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): if S >= D * 9: return -1 if S <= 9 and D == 1: return S S -= 1 ans = [] while D: if S >= 9: ans += [9] S -= 9 else: ans += [S] ...
CLASS_DEF FUNC_DEF IF VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN VAR VAR NUMBER ASSIGN VAR LIST WHILE VAR IF VAR NUMBER VAR LIST NUMBER VAR NUMBER VAR LIST VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): if S <= 9 and D == 1: return S if S >= 9 * D: return -1 ret = [] while S: if S >= 9: ret.append(9) S -= 9 else: ret.append(S) ...
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN VAR IF VAR BIN_OP NUMBER VAR RETURN NUMBER ASSIGN VAR LIST WHILE VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER ...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, s, D): num = [None] * D for i in range(D - 1, 0, -1): d = min(s - 1, 9) num[i] = d s -= d if s > 9: return "-1" num[0] = s i = D - 1 while i > 0: if num[i] != 0 and n...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR IF VAR NUMBER RETURN STRING ASSIGN VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NU...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): d = [0] * D if S >= 9 * D: return -1 if D == 1: return S d[0] = 1 S -= 1 count = 0 for i in range(D - 1, -1, -1): if S > 0: if S < 9: d[i] ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR BIN_OP NUMBER VAR RETURN NUMBER IF VAR NUMBER RETURN VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER IF VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR ...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): if S >= D * 9 or D == 1: return -1 arr = [] while D > 1: if S == 1: arr.append(0) else: temp = min(9, S - 1) arr.append(temp) S -= temp ...
CLASS_DEF FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR LIST WHILE VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER N...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): if S >= 9 * D: return "-1" num = [0] * D num[0] = 1 S -= 1 for i in range(D - 1, -1, -1): num[i] += min(S, 9) S -= min(S, 9) if S == 0: break for i in rang...
CLASS_DEF FUNC_DEF IF VAR BIN_OP NUMBER VAR RETURN STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR V...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): if D == 1 or S == 1 or S >= 9 * D: return "-1" isChanged = False sb = [] for i in range(0, D): digit = 0 if S > 9: digit = 9 S -= 9 elif i == D - 1: ...
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR RETURN STRING ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR ...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
import sys class Solution: def secondSmallest(self, S, D): if D < 2 or S < 2 or S > 9 * D - 1: return "-1" q, r = divmod(S, 9) digits = [9] * q + [r] + [0] * (D - 1 - q) lnz = q - (r == 0) digits[lnz] -= 1 digits[-1] += 1 if lnz == 0: ...
IMPORT CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST NUMBER VAR LIST VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER NUMBER IF VAR N...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): if D == 1 or S == 1: return "-1" ans = ["0"] * D ans[0] = "1" S -= 1 i = D - 1 while i > 0: if S > 9: ans[i] = "9" S -= 9 else: ans[i] ...
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN STRING ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER STRING VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN STRING IF VAR AS...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): if D < 2 or 9 * D - 1 < S: return -1 t = "" s = 0 for i in range(1, 9): if (S - i) / (D - 1) <= 9.0: t = t + str(i) s = s + i break for i in range(2, D): ...
CLASS_DEF FUNC_DEF IF VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR RETURN NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBE...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): ans = [] if D == 1 or S == 1 or D * 9 <= S: return "-1" for i in range(0, D): if S > 9: ans.append("9") S -= 9 elif S == 1: if i == D - 1: ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST IF VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR RETURN STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): if D == 1 and S <= 9: return S if S == 1 or S >= D * 9: return -1 sumthing = [(0) for i in range(D)] for i in range(D): if i == 0: assign = max(1, S - (D - 1 - i) * 9) els...
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): if S >= D * 9: return -1 ans = [(0) for i in range(D)] ans[0] = 1 S -= 1 D -= 1 ind = len(ans) - 1 for i in range(len(ans) - 1, -1, -1): if S >= 9: ans[i] += 9 ...
CLASS_DEF FUNC_DEF IF VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER VAR NUMBER 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 NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR V...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): if S / 9 > D: return -1 if S == 1: return -1 if S / 9 == D: return -1 if D == 1: return S i = D - 1 curr = S ans = [(0) for _ in range(D)] nines = 0 ...
CLASS_DEF FUNC_DEF IF BIN_OP VAR NUMBER VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER VAR RETURN NUMBER IF VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR ...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): if S >= 9 * D: return -1 dig = [1] + [0] * (D - 1) S = S - 1 for i in range(D - 1, -1, -1): if S >= 9: dig[i] += 9 S = S - 9 if S == 0: dig[i] ...
CLASS_DEF FUNC_DEF IF VAR BIN_OP NUMBER VAR RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUM...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, s, d): if s >= 9 * d or s == 1: return -1 a = [(0) for i in range(d)] a[0] = 1 s = s - 1 i = d - 1 while i >= 0 and s > 0: if s >= 9: a[i] += 9 s -= 9 else: ...
CLASS_DEF FUNC_DEF IF VAR BIN_OP NUMBER VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): if 9 * D < S: return -1 S = S - 1 ans = "" for i in range(D - 1, 0, -1): if S > 9: ans = "9" + ans S = S - 9 elif i == 0: ans = str(S + 1) + ans ...
CLASS_DEF FUNC_DEF IF BIN_OP NUMBER VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP FUN...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): n = [0] * D n[D - 1] = min(S - 2, 8) if n[D - 1] == -1: return -1 S -= n[D - 1] for j in reversed(range(1, D - 1)): if S - 1 > 9: n[j] = 8 n[j + 1] = n[j + 1] + 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_O...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): ans = ["0"] * D if D * 9 <= S: return "-1" S = S - 1 e = D - 1 for i in range(D - 1, 0, -1): if S >= 9: ans[i] = "9" S = S - 9 e = i else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST STRING VAR IF BIN_OP VAR NUMBER VAR RETURN STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASS...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
import sys class Solution: def secondSmallest(self, S, D): if D * 9 <= S or D == 1 or S == 1: return "-1" num = [0] * D num[0] = 1 S = S - 1 for i in range(D - 1, 0, -1): if S > 9: num[i] = 9 S = S - 9 els...
IMPORT CLASS_DEF FUNC_DEF IF BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER RETURN STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN ...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): if S == 1 or D == 1: return -1 digits = [] for i in range(D): digits.append(0) digits[0] = 1 index = D - 1 S -= 1 while S > 0: S -= 9 if S >= 0: if...
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR BIN_OP NUMBER VAR ...
The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas the second smallest is 27. Example 2: Input: S = 16 D = 3 Output: 178 Explana...
class Solution: def secondSmallest(self, S, D): s = S st = "" if S >= 9 * D or D == 1 or S == 0: return -1 d = D S -= 1 for i in range(d - 1): if S > 9 and D > 1: S -= 9 st += str(9) D -= 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR STRING IF VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR ...
Valera loves his garden, where n fruit trees grow. This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in the...
MOD = 1000000007 ii = lambda: int(input()) si = lambda: input() dgl = lambda: list(map(int, input())) f = lambda: map(int, input().split()) il = lambda: list(map(int, input().split())) ls = lambda: list(input()) n, v = f() l = [0] * 3003 for _ in range(n): a, b = f() l[a] += b fromprevDay = 0 currDay = 0 temp =...
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 FUNC_CALL VAR ASSIGN VAR VAR FUNC_CA...
Valera loves his garden, where n fruit trees grow. This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in the...
def main(): n, v = map(int, input().split()) l = [0] * 3002 for _ in range(n): a, b = map(int, input().split()) l[a] += b a = res = 0 for b in l: x = a + b if x < v: res += x a = 0 else: res += v if a < v: ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER VAR VAR IF VAR VAR ASSIGN...
Valera loves his garden, where n fruit trees grow. This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in the...
n, v = map(int, input().split()) f = [0] * 3002 for _ in range(n): a, b = map(int, input().split()) f[a] += b ans = 0 cur = 0 for i in range(1, 3002): if cur + f[i] <= v: ans += cur + f[i] cur = 0 else: ans += v cur = f[i] - max(v - cur, 0) print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR...
Valera loves his garden, where n fruit trees grow. This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in the...
n, limit = map(int, input().split()) arr = [0] * (3000 + 1) for i in range(n): a, b = map(int, input().split()) arr[a] += b next = 0 fruits = 0 for i in range(1, 3001): v = limit temp = min(v, next) fruits += temp v -= temp temp = min(v, arr[i]) fruits += temp next = arr[i] - temp v ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR V...
Valera loves his garden, where n fruit trees grow. This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in the...
n, v = [int(x) for x in input().split()] l = [0] * 3002 for i in range(n): a, b = [int(x) for x in input().split()] l[a] += b ans = 0 for i in range(1, 3002): left = v if l[i - 1]: ans += min(left, l[i - 1]) left -= min(left, l[i - 1]) ans += min(left, l[i]) l[i] -= min(left, l[i...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN...
Valera loves his garden, where n fruit trees grow. This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in the...
rip = [0] * 3050 n, v = [int(x) for x in input().split()] for _ in range(n): d, p = [int(x) for x in input().split()] rip[d] += p ans = 0 for i in range(1, 3050): t = min(v, rip[i - 1] + rip[i]) rip[i] = rip[i] - max(0, t - rip[i - 1]) ans += t print(ans)
ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASS...
Valera loves his garden, where n fruit trees grow. This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in the...
n, v = [int(i) for i in input().split()] a = [0] * n b = [0] * n days1 = [0] * 3001 days2 = [0] * 3001 for i in range(n): a[i], b[i] = [int(j) for j in input().split()] days1[a[i] - 1] += b[i] days2[a[i]] += b[i] res = 0 for i in range(3001): left = max(0, v - days2[i]) res += max(0, min(v, days2[i]...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR VAR NUM...
Valera loves his garden, where n fruit trees grow. This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in the...
n, v = map(int, input().split(" ")) trees = dict() count = 0 b_last = 0 for i in range(n): a, b = map(int, input().split(" ")) if trees.get(a): trees[a] += b else: trees[a] = b m = max(trees.keys()) for i in range(1, m + 2): if trees.get(i): k = min(v, b_last) count += k ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_C...
Valera loves his garden, where n fruit trees grow. This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in the...
read = lambda: map(int, input().split()) n, v = read() N = 3002 p = [0] * N for i in range(n): a, b = read() p[a] += b ans = 0 rem = 0 for i in range(1, N): cur = min(v, rem + p[i]) ans += cur if rem >= v: rem = p[i] else: rem = max(0, p[i] - (v - rem)) print(ans)
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VA...
Valera loves his garden, where n fruit trees grow. This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in the...
n, v = map(int, input().split()) d, s = {}, 0 for i in range(n): a, b = map(int, input().split()) d[a] = d.get(a, 0) + b s += b r = v for i in sorted(d.keys()): d[i] -= min(d[i], r) r, b = v, min(d[i], v) d[i] -= b if i + 1 in d: r -= b print(s - sum(d.values()))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR DICT NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VA...
Valera loves his garden, where n fruit trees grow. This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in the...
n, v = map(int, input().split(" ")) a, b = [], [] for i in range(n): x, y = map(int, input().split(" ")) a.append(x) b.append(y) fi = max(a) li = [0] * 3002 for i in range(n): li[a[i]] += b[i] ans = 0 for i in range(1, 3002): ans += min(v, li[i - 1] + li[i]) li[i] = max(0, li[i] - max(0, v - li[...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR...