input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
l, m = list(map(int, input().split())) lr = [list(map(int, input().split())) for _ in range(m)] ll, rr = 1, l for l, r in lr: if ll <= l <= rr or l <= ll <= r: ll, rr = max(ll, l), min(rr, r) else: print((0)) exit() print((rr-ll+1))
n, m = list(map(int, input().split())) lr = [list(map(int, input().split())) for _ in range(m)] INF = float('inf') ans_l, ans_r = -INF, INF for l, r in lr: ans_l = max(ans_l, l) ans_r = min(ans_r, r) print((max(0, ans_r-ans_l+1)))
p03037
n,m = list(map(int,input().split())) lst_l = [] lst_r = [] for _ in range(m): l,r = list(map(int,input().split())) lst_l.append(l) lst_r.append(r) count = 0 for i in range(n): if max(lst_l) <= i+1 <= min(lst_r): count += 1 print(count)
n,m = list(map(int,input().split())) lst_l = [] lst_r = [] for _ in range(m): l,r = list(map(int,input().split())) lst_l.append(l) lst_r.append(r) max_l = max(lst_l) min_r = min(lst_r) count = 0 for i in range(n): if max_l <= i+1 <= min_r: count += 1 print(count)
p03037
n,m=list(map(int,input().split())) gate=[] l,r=list(map(int,input().split())) for i in range(l,r+1): gate.append(i) for i in range(m-1): l,r=list(map(int,input().split())) g=[] for i in gate: if l<=i<=r: g.append(i) gate=g print((len(gate)))
n,m=list(map(int,input().split())) card=[] L=1 R=n for i in range(m): card.append([int(i) for i in input().split()]) for j in card: if j[0]<=R: if L<=j[0]: L=j[0] else: print((0)) quit() if L<=j[1]: if j[1]<=R: R=j[1] ...
p03037
from collections import Counter n, m = list(map(int, input().split())) A = [] for i in range(m): l, r = list(map(int, input().split())) A.extend(list(range(l, r + 1))) cnt = 0 for v in list(Counter(A).values()): if v == m: cnt += 1 print(cnt)
n, m = list(map(int, input().split())) left = 0 right = float('inf') for i in range(m): l, r = list(map(int, input().split())) left = max(left, l) right = min(right, r) print((max(0, right - left + 1)))
p03037
# -*- coding: utf-8 -*- n, m = list(map(int,input().split())) lr = [] for i in range(m): lr.append([int(i) for i in input().split()]) if m == 1: print((lr[0][1] - lr[0][0] + 1)) exit() tmp1 = 0 tmp2 = pow(10, 6) for i in range(m - 1): tmp1 = max(lr[i][0], lr[i + 1][0], tmp1) tmp2 = m...
n, m = list(map(int,input().split())) lr = [] for i in range(m): lr.append([int(i) for i in input().split()]) tmp1 = 0 tmp2 = pow(10, 6) for i in range(m): tmp1 = max(lr[i][0], tmp1) tmp2 = min(lr[i][1], tmp2) print((max(0, tmp2 - tmp1 + 1)))
p03037
N,M=list(map(int,input().split())) LR=[] for i in range(M): LR.append(list(map(int,input().split()))) ans=[i+1 for i in range(N)] for i in range(M): for j in range(LR[i][0]): if j in ans: ans.remove(j) for k in range(LR[i][1]+1,N+1): if k in ans: ans.remove(k) print((len(ans)))
N,M=list(map(int,input().split())) LR=[] for i in range(M): LR.append(list(map(int,input().split()))) l,r=LR[0][0],LR[0][1] for i in range(M): if LR[i][1]<=r: r=LR[i][1] if l<=LR[i][0]: l=LR[i][0] ans=r-l+1 if ans>0: print(ans) else: print((0))
p03037
N, M = list(map(int, input().split())) l, r = list(map(int, input().split())) lis = [i for i in range(l, r+1)] for i in range(M-1): l, r = list(map(int, input().split())) tmp_lis = [i for i in range(l, r+1)] lis = set(lis) & set(tmp_lis) lis = [i for i in lis if i <= N] print((len(lis)))
N, M = list(map(int, input().split())) min, max = list(map(int, input().split())) for i in range(M-1): l, r = list(map(int, input().split())) if min < l: min = l if max > r: max = r lis = [i for i in range(min, max+1)] print((len(lis)))
p03037
#ABC-127-C N, M = list(map(int, input().split())) LR = [] for _ in range(M): Li, Ri = list(map(int, input().split())) LR.append((Li, Ri)) possible_card_list = [i for i in range(LR[0][0], LR[0][1]+1)] for Li, Ri in LR: for possible_card in possible_card_list[:]: if Li <= possible_card a...
#ABC-127-C N, M = list(map(int, input().split())) L_list = [] R_list = [] for _ in range(M): Li, Ri = list(map(int, input().split())) L_list.append(Li) R_list.append(Ri) max_L = max(L_list) min_R = min(R_list) if max_L > min_R: print((0)) else: print((min_R-max_L+1))
p03037
n,m = list(map(int,input().split())) l = [] r = [] while True: try: tl,tr = list(map(int,input().split())) l.append(tl) r.append(tr) except: break l = sorted(l) r = sorted(r) cnt = 0 for i in range(1,n+1): if i>=max(l) and i<=min(r): cnt +=1 print(cnt)
n,m = list(map(int,input().split())) l = [] r = [] while True: try: tl,tr = list(map(int,input().split())) l.append(tl) r.append(tr) except: break R = min(r) L = max(l) cnt = 0 for i in range(1,n+1): if i>=L and i<=R: cnt +=1 print(cnt)
p03037
N, M = list(map(int, input().split())) A = [list(map(int, input().split())) for i in range(M)] B = {x for x in range(A[0][0], A[0][1]+1)} for i in range(1,M): C = {x for x in range(A[i][0],A[i][1]+1)} B = B & C ans = len(B) print(ans)
N, M = list(map(int, input().split())) A = [0]*M B = [0]*M for i in range(M): A[i], B[i] = list(map(int, input().split())) a = max(A) b = min(B) if a <= b: print((b+1-a)) else: print((0))
p03037
def resolve(): N,M=list(map(int,input().split())) l, r = list(map(int, input().split())) s = {i for i in range(l, r + 1)} for i in range(1,M): l,r=list(map(int,input().split())) s=s&{i for i in range(l,r+1)} print((len(s))) resolve()
# input = sys.stdin.readline def resolve(): N,M=list(map(int,input().split())) l, r = list(map(int, input().split())) for i in range(1,M): ll,rr=list(map(int,input().split())) l=max(l,ll) r=min(r,rr) print((r-l+1 if r-l+1>=0 else 0)) resolve()
p03037
N,M = list(map(int,input().split())) LR = [[] for i in range(M)] for i in range(M): L,R = list(map(int, input().split())) for j in range(L,R + 1): LR[i].append(j) LR[i] = set(LR[i]) for i in range(M): LR[i] = LR[i] & LR[i-1] print((len(LR[M-1])))
N,M = list(map(int,input().split())) LR = [set([]) for i in range(M)] for i in range(M): L,R = list(map(int, input().split())) for j in range(L,R + 1): LR[i].add(j) for i in range(M): LR[i] = LR[i] & LR[i-1] print((len(LR[M-1])))
p03037
N,M = list(map(int,input().split())) LR = [set([]) for i in range(M)] for i in range(M): L,R = list(map(int, input().split())) for j in range(L,R + 1): LR[i].add(j) for i in range(M): LR[i] = LR[i] & LR[i-1] print((len(LR[M-1])))
N,M = list(map(int,input().split())) inf = [] sup = [] for i in range(0,M): L,R = list(map(int,input().split())) inf.append(L) sup.append(R) inf = max(inf) sup = min(sup) ran = sup - inf if ran >= 0: print((ran + 1)) else:print((0))
p03037
N, M = list(map(int, input().split())) id_list = [0] * N for _ in range(M): L, R = list(map(int, input().split())) for i in range(L, R + 1): id_list[i - 1] += 1 print((sorted(id_list, reverse=True).count(M)))
N, M = list(map(int, input().split())) L, R = 1, N for _ in range(M): Li, Ri = list(map(int, input().split())) if L <= Li: L = Li if Ri <= R: R = Ri print((R - L + 1 if (R >= L) else 0))
p03037
N,M=list(map(int,input().split())) passable=set(range(1,N+1)) for m in range(M): L,R=list(map(int,input().split())) passable=passable&set(range(L,R+1)) print((len(passable)))
N,M=list(map(int,input().split())) L=[] R=[] for m in range(M): Lm,Rm=list(map(int,input().split())) L.append(Lm) R.append(Rm) maxL=max(L) minR=min(R) print((max(minR-maxL+1,0)))
p03037
def island(f,x,y,m): rf = f[:][:] rf[y][x] = m for i in [-1,1]: if 0 <= x+i <= 11 and rf[y][x+i] == 1: rf = island(rf,x+i,y,m) if 0 <= y+i <= 11 and rf[y+i][x] == 1: rf = island(rf,x,y+i,m) return rf while True: f = []; m = 2 for i in range(12...
W,H = 12,12 dxy = [[1,0],[0,1],[-1,0],[0,-1]] def solve(field,w,h): if 0 <= w < W and 0 <= h < H and field[h][w] == "1": field[h][w] = "0" for dx,dy in dxy: solve(field,w+dx,h+dy) while 1: try: field = [list(input()) for i in range(H)] ans = 0 for h in range(H): for w in range(W): i...
p00067
import sys A=list(range(12)) m=[[0 for i in A] for j in A] def f(y,x,d): P=[] x+=d[0] y+=d[1] if 0<=x<12 and 0<=y<12 and m[y][x]==1: m[y][x]=c P=[[y,x]] return P def v1(buf): global c while buf!=[]: y,x=buf.pop() m[y][x]=c for e in [(-1...
import sys A=list(range(14)) m=[[0 for i in A] for j in A] def f(y,x): if m[y][x]==1: m[y][x]=0 f(y,x+1) f(y,x-1) f(y+1,x) f(y-1,x) return def solve(): c=2 for i in A: while m[i].count(1)>0: f(i,m[i].index(1)) c+=1 ...
p00067
import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline N,M = list(map(int,input().split())) L = [] for i in range(N): tmp = list(map(int,input().split())) L.append(tmp[1:]) dicL = {} for i in range(N): for l in L[i]: if l not in dicL: dicL[l] = [i] else: dicL[l].a...
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 9) N,M = list(map(int,input().split())) L = [] for i in range(N): tmp = list(map(int,input().split())) L.append(tmp[1:]) #print(L) # 人(0~N-1)と言語(N~M-1)の間で二部グラフを作る E = [set() for _ in range(N+M)] for i in range(N): for l in L[i]: ...
p03911
from collections import deque N,M = list(map(int, input().split())) es_lang = [[] for _ in range(M+1)] # 各言語の番号がidxで、それを話せる人が中身 es_p = [[] for _ in range(N+1)] # 各人の番号がidxで、その人の話せる言語が中身 for i in range(N): KL = list(map(int, input().split())) es_p[i+1].extend(KL[1:]) for j in KL[1:]: es_l...
from collections import deque N,M = list(map(int, input().split())) es_lang = [[] for _ in range(M+1)] # 各言語の番号がidxで、それを話せる人が中身 es_p = [[] for _ in range(N+1)] # 各人の番号がidxで、その人の話せる言語が中身 for i in range(N): KL = list(map(int, input().split())) es_p[i+1].extend(KL[1:]) for j in KL[1:]: es_l...
p03911
N,M = list(map(int,input().split())) K = [] L = [] for _ in range(N): k,*l = list(map(int,input().split())) K.append(k) L.append(l) graph = [[] for _ in range(N+M)] for i in range(N): for l in L[i]: graph[i].append(N+l-1) graph[N+l-1].append(i) visited = [0 for _ in r...
class UnionFind(): def __init__(self, n): self.n = n self.parents = [i for i in range(n)] self.size = [1 for _ in range(n)] def find(self, x): root = x while self.parents[root] != root: root = self.parents[root] return root def unite(...
p03911
# cf16-finalC - Interpretation class UnionFind: # O(α(N)) def __init__(self, size): # construct a Union-Find tree (1-idx) self.parent = [i for i in range(size + 1)] self.rank = [0] * (size + 1) def find(self, x): # find the group (root) of a vertex if self.parent[x] == x: ...
# cf16-finalC - Interpretation class UnionFind: def __init__(self, size): self.parent = [i for i in range(size + 1)] self.rank = [0] * (size + 1) def find(self, x): if self.parent[x] == x: return x self.parent[x] = self.find(self.parent[x]) return s...
p03911
class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): ...
class UnionFind: # 0-index def __init__(self, n): self.n = n self.parents = [-1] * n # 親の番号 要素が根の場合は-(そのグループの要素数)を格納 def find(self, x): # 要素xが属するグループの根を返す if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) ...
p03911
import sys import collections sys.setrecursionlimit(10 ** 8) ni = lambda: int(sys.stdin.readline()) nm = lambda: list(map(int, sys.stdin.readline().split())) nl = lambda: list(nm()) ns = lambda: sys.stdin.readline().rstrip() def solve(): N, M = nm() uf = UnionFind(M) lang_spoken = set() ...
import sys import collections sys.setrecursionlimit(10 ** 8) ni = lambda: int(sys.stdin.readline()) nm = lambda: list(map(int, sys.stdin.readline().split())) nl = lambda: list(nm()) ns = lambda: sys.stdin.readline().rstrip() def solve(): N, M = nm() uf = UnionFind(M) lang_spoken = set() ...
p03911
N,M = list(map(int,input().split())) KL = [list(map(int,input().split())) for _ in [0]*N ] E = [[[] for _ in [0]*N] , [[] for _ in [0]*M]] for i,kl in enumerate(KL): for l in kl[1:]: E[0][i].append(l-1) E[1][l-1].append(i) Check = [[False]*N,[False]*M] Check[0][0] = True q = [[0,0]] wh...
#二部グラフで連結判定 N,M = list(map(int,input().split())) KL = [list(map(int,input().split())) for _ in [0]*N] c = [False]*(N+M) #d[0] - d[N-1]:人, d[N] - D[N+M-1]:言語 E = [[] for _ in [0]*(N+M)] for i,kl in enumerate(KL): for l in kl[1:]: E[i].append(N+l-1) E[N+l-1].append(i) start = 0 q = [star...
p03911
import heapq N,M = list(map(int,input().split())) KL = [list(map(int,input().split())) for _ in [0]*N] E = [{} for _ in [0]*(N+M)] for i,kl in enumerate(KL): for l in kl[1:]: E[i][N+l-1] = 1 E[N+l-1][i] = 1 def Dijkstra(N,E,start): d = [-1]*N q = [(0,start)] while q: ...
#二部グラフで連結判定 N,M = list(map(int,input().split())) KL = [list(map(int,input().split())) for _ in [0]*N] E = [[] for _ in [0]*(N+M)] #E[0] - E[N-1]:人, E[N] - E[N+M-1]:言語 for i,kl in enumerate(KL): for l in kl[1:]: E[i].append(N+l-1) E[N+l-1].append(i) def connect_bfs(N,E,start): connec...
p03911
#二部グラフで連結判定 N,M = list(map(int,input().split())) KL = [list(map(int,input().split())) for _ in [0]*N] E = [[] for _ in [0]*(N+M)] #E[0] - E[N-1]:人, E[N] - E[N+M-1]:言語 for i,kl in enumerate(KL): for l in kl[1:]: E[i].append(N+l-1) E[N+l-1].append(i) def connect_bfs(N,E,start): connec...
#二部グラフで連結判定 N,M = list(map(int,input().split())) KL = [list(map(int,input().split())) for _ in [0]*N] E = [[] for _ in [0]*(N+M)] #E[0] - E[N-1]:人, E[N] - E[N+M-1]:言語 for i,kl in enumerate(KL): for l in kl[1:]: E[i].append(N+l-1) E[N+l-1].append(i) def dist_bfs(N,E,start): d = [-1]*...
p03911
n, m = list(map(int, input().split())) tree = [[] for _i in range(m+1)] k = [] for i in range(n): x = list(map(int, input().split())) for j in x[1:]: tree[j].append(i) k.append(x[1:]) visit = [0 for _ in range(n)] from collections import deque q = deque([0]) while q: p = q.pop() ...
n, m = list(map(int, input().split())) tree = [[] for _i in range(m+n+1)] for i in range(n): x = list(map(int, input().split())) tree[i].extend([i+n for i in x[1:]]) for j in x[1:]: tree[j+n].append(i) from collections import deque q = deque([1]) visit = [0 for _i in range(m+n+2)] visit[...
p03911
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda:sys.stdin.readline().rstrip() class UnionFind(object): def __init__(self,n): self.__par=list(range(n)) self.__rank=[0]*n self.__size=[1]*n def root(self,k): if(self.__par[k]==k):...
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda:sys.stdin.readline().rstrip() def resolve(): n,m=list(map(int,input().split())) # n,m の bipartite graph E=[[] for _ in range(n+m)] for i in range(n): L=list([int(x)-1 for x in input().split()])[::-1]...
p03911
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): ...
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): def dfs(v): for u in edge[v]: if visited[u]: continue else: visited[u] = True dfs(u) n, ...
p03911
import sys input = sys.stdin.readline sys.setrecursionlimit(10**5) N, M = list(map(int, input().split())) KL = [[int(i) for i in input().split()] for _ in range(N)] lang = [[] for _ in range(M)] for i in range(N) : for j in KL[i][1:] : lang[j-1].append(i) visited = [False] * N visite...
import sys input = sys.stdin.readline sys.setrecursionlimit(10**5) N, M = list(map(int, input().split())) v = [[] for _ in range(N+M)] for i in range(N) : K, *L = list(map(int, input().split())) for l in L : v[N+l-1].append(i) v[i].append(N+l-1) visited = [False] * (N + M) visited...
p03911
class UnionFind: def __init__(self, size): self.data = [-1 for _ in range(size)] def find(self, x): if self.data[x] < 0: return x else: self.data[x] = self.find(self.data[x]) return self.data[x] def union(self, x, y): x, y = self....
class UnionFind: def __init__(self, size): self.data = [-1] * size def find(self, x): if self.data[x] < 0: return x else: self.data[x] = self.find(self.data[x]) return self.data[x] def union(self, x, y): x, y = self.find(x), self.find(y) if x != y: if self.data[y] < self.data[x]: ...
p03911
class UnionFind: def __init__(self, size): self.data = [-1] * size def find(self, x): if self.data[x] < 0: return x else: self.data[x] = self.find(self.data[x]) return self.data[x] def union(self, x, y): x, y = self.find(x), self.find(y) if x != y: if self.data[y] < self.data[x]: ...
class UnionFind: def __init__(self, size): self.data = [-1] * size def find(self, x): if self.data[x] < 0: return x else: self.data[x] = self.find(self.data[x]) return self.data[x] def union(self, x, y): x, y = self.find(x), s...
p03911
class UnionFind: def __init__(self, size): self.data = [-1] * size def find(self, x): if self.data[x] < 0: return x else: self.data[x] = self.find(self.data[x]) return self.data[x] def union(self, x, y): x, y = self.find(x), s...
class UnionFind: def __init__(self, size): self.data = [-1] * size def find(self, x): if self.data[x] < 0: return x else: self.data[x] = self.find(self.data[x]) return self.data[x] def union(self, x, y): x, y = self.find(x), s...
p03911
n,m=map(int,input().split()) class UnionFind: #def -> foo=UnionFind(n,1) <- 1-based index, default is 0 #method -> foo.hoge(huga) __slots__ = ["_size", "_first_idx", "_parents"] def __init__(self, size: int, first_index: int = 0) -> None: self._size = size self._first_idx = fir...
n,m=map(int,input().split()) class UnionFind: #def -> foo=UnionFind(n,1) <- 1-based index, default is 0 #method -> foo.hoge(huga) __slots__ = ["_size", "_first_idx", "_parents"] def __init__(self, size: int, first_index: int = 0) -> None: self._size = size self._first_idx = fir...
p03911
N,M = list(map(int,input().split())) people = [None] * N from collections import defaultdict lang = defaultdict(set) for i in range(N): people[i] = list(map(int,input().split()))[1:] for l in people[i]: lang[l].add(i) # 0番の人からたどって全員に行けるか stack = [0] seen = [False for i in range(N)] while st...
# 人も言語もグラフの頂点と見なす # ある人がある言語を話せる場合連結となる # 頂点のキーは[言語 or 人][番号(人番号 or 言語番号)] # 0:言語 1:人 N,M = list(map(int,input().split())) from collections import defaultdict E = [[],[]] E[0] = [[] for i in range(M)] E[1] = [[] for i in range(N)] for i in range(N): langs = list(map(int,input().split()))[1:] for lang...
p03911
import sys input = sys.stdin.readline # ユニオンファインド class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) ...
import sys input = sys.stdin.readline # ユニオンファインド class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) ...
p03911
while 1: n,p = list(map(int,input().split())) if n==0:break man = [0]*n ball,a = p,0 while p not in man: if ball >0:ball,man[a%n] =ball-1, man[a%n]+1 elif ball == 0:ball,man[a%n] = man[a%n],ball a+=1 print((man.index(max(man))))
while 1: n,p = list(map(int,input().split())) if n==0:break man = [0]*n ball,a = p,0 while 1: if ball >0:ball,man[a%n] =ball-1, man[a%n]+1 elif ball == 0:ball,man[a%n] = man[a%n],ball a+=1 if p in man:break print((man.index(max(man))))
p00740
while 1: n,p = list(map(int,input().split())) if n==0:break man = [0]*n ball,a = p,0 while 1: if ball >0:ball,man[a%n] =ball-1, man[a%n]+1 elif ball == 0:ball,man[a%n] = man[a%n],ball a+=1 if p in man:break print((man.index(max(man))))
while 1: n,p = list(map(int,input().split())) if n==0:break man = [0]*n ball,a = p,0 while 1: a%=n if ball >0:ball,man[a] =ball-1, man[a]+1 elif ball == 0:ball,man[a] = man[a],ball a+=1 if p in man:break print((man.index(max(man)))) ...
p00740
while 1: n,p = list(map(int,input().split())) if n==0:break man = [0]*n ball,a = p,0 while 1: a%=n if ball >0: ball-=1 man[a]+=1 elif ball == 0:ball,man[a] = man[a],ball a+=1 if p in man:break print((man.index(max(man)...
while 1: n,p = list(map(int,input().split())) if n==0:break man = [0]*n ball,a = p,0 while 1: a%=n if ball >0: ball-=1 man[a]+=1 elif ball == 0:ball,man[a] = man[a],ball if man[a]==p:break a+=1 print(a) ...
p00740
while 1: n,p = list(map(int,input().split())) if n==0:break man = [0]*n ball,a = p,0 while 1: a%=n if ball >0: ball-=1 man[a]+=1 elif ball == 0:ball,man[a] = man[a],ball if man[a]==p:break a+=1 print(a) ...
while 1: n,p = list(map(int,input().split())) if n==0:break man = [0]*n ball,a = p,0 while 1: a%=n if ball >0: ball-=1 man[a]+=1 elif ball == 0:ball,man[a] = man[a],ball if man[a]==p:break a+=1 print((man.index(max(man...
p00740
while 1: n,p = list(map(int,input().split())) if n == 0: break have = [0]*n stone = p i = count = 0 while 1: count += 1 if stone > 0: have[i] += 1 stone -= 1 else: stone += have[i] have[i] = 0 if have[i] == p: break i = (i+1)%n print(i)
while 1: n,p = list(map(int,input().split())) if n == 0: break have = [0]*n stone = p i = 0 while 1: if stone > 0: have[i] += 1 stone -= 1 else: stone += have[i] have[i] = 0 if have[i] == p: break i = (i+1)%n print(i)
p00740
while 1: n,p = list(map(int,input().split())) if n == 0: break have = [0]*n stone = p i = 0 while 1: if stone > 0: have[i] += 1 stone -= 1 else: stone += have[i] have[i] = 0 if have[i] == p: break i = (i+1)%n print(i)
while 1: n,p = list(map(int,input().split())) if n == 0: break have = [0]*n cup = p i = 0 while 1: if cup > 0: have[i] += 1 cup -= 1 if have[i] == p: break else: cup += have[i] have[i] = 0 i = (i+1)%n print(i)
p00740
while True: n,p = list(map(int,input().split())) if n==p==0: break s,c = [0]*n,p i = 0 while True: if c: c-=1 s[i%n]+=1 if s[i%n]==p: break else: c+=s[i%n] s[i%n] = 0 i+=1 print((i%n))
while True: n,p = list(map(int,input().split())) if n==p==0: break l = [0]*n i,k = 0,p while True: i %= n if k==0: k,l[i] = l[i],0 else: k-=1 l[i]+=1 if l[i]==p: break i+=1 print(i)
p00740
while True: n, p = list(map(int, input().split())) pp = p if n == p == 0: break stones = [0] * n i = 0 while True: er = i % n if p == 1 and stones[er] == pp - 1: print(er) break if p >= 1: stones[er] += 1 ...
while True: n, p = list(map(int, input().split())) pp = p if n == p == 0: break stones = [0] * n for i in range(1000000): er = i % n if p >= 1: stones[er] += 1 p -= 1 if p == 0 and stones[er] == pp: print(er) ...
p00740
from sys import stdin, stdout, stderr while 1: n, p = list(map(int, stdin.readline().split())) if n + p == 0: break a = [0] * n wan = p for i in range(10**6): if wan > 0: a[i % n] += 1 wan -= 1 else: wan += a[i % n] ...
from sys import stdin, stdout, stderr a = [0] * 50 while 1: n, p = list(map(int, stdin.readline().split())) if n + p == 0: break wan = p i = 0 while a[i] < p: if wan > 0: a[i] += 1 wan -= 1 else: wan += a[i] ...
p00740
N, X = list(map(int, input().split())) m = [int(eval(input())) for _ in range(N)] result = len(m) X -= sum(m) while X >= min(m): result += 1 X -= min(m) print(result)
N, X = list(map(int, input().split())) m = [int(eval(input())) for _ in range(N)] print((len(m)+(X-sum(m))//min(m)))
p03370
n,x = list(map(int,input().split())) y = 1000 for i in range(n): z = int(eval(input())) x -= z y = min(y,z) print((n+x//y))
n,x=list(map(int,input().split())) M=sorted([int(eval(input())) for i in range(n)]) print((len(M)+(x-sum(M))//M[0]))
p03370
n,x = list(map(int,input().split())) m_list = [int(eval(input())) for _ in range(n)] remaining = x - sum(m_list) print((len(m_list) + (remaining//min(m_list))))
n,x = list(map(int,input().split())) m_list = [int(eval(input())) for _ in range(n)] remaining = x - sum(m_list) print((n + (remaining//min(m_list))))
p03370
N, X = list(map(int, input().split())) m = [] for i in range(N): m.append(int(eval(input()))) min_kona = 0 for val in m: min_kona += val min_donut = min(m) cnt = (X - min_kona) // min_donut + len(m) print(cnt)
N, X = list(map(int, input().split())) m = [] for i in range(N): m.append(int(eval(input()))) min_kona = sum(m) min_donut = min(m) cnt = (X - min_kona) // min_donut + len(m) print(cnt)
p03370
N,X = list(map(int,input().split())) m = [int(eval(input())) for i in range(N)] m.sort() ans = 0 for i in range(N): X -= m[i] if X < 0: break ans += 1 if X > 0: ans += X // min(m) print(ans)
N,X = list(map(int,input().split())) m = [int(eval(input())) for i in range(N)] ans = N + (X - sum(m)) // min(m) print(ans)
p03370
n,x=list(map(int, input().split())) m=[int(eval(input())) for _ in range(n)] count=0 for i in range(len(m)): if x>=m[i]: x-=m[i] count+=1 min_donut=min(m) while(x>=min_donut): x-=min_donut count+=1 print(count)
n,x=list(map(int, input().split())) m=[int(eval(input())) for _ in range(n)] print(((x-sum(m))//min(m)+n))
p03370
n,x = list(map(int,input().split())) m = [] for i in range(n): m.append(int(eval(input()))) print((n+int((x-sum(m))/min(m))))
N,X = list(map(int,input().split())) m = [] for _ in range(N): m.append(int(eval(input()))) print(((X-sum(m))//min(m)+N))
p03370
N,X = list(map(int,input().split())) M = [int(eval(input())) for i in range(N)] X -= sum(M) M.sort() ans = -1 while X >= 0: X -= M[0] ans += 1 print((ans+N))
N, X = list(map(int,input().split())) m = [] cnt = 0 for j in range(N): m.append(int(eval(input()))) a = X - sum(m) cnt = a // min(m) + N print(cnt)
p03370
N,X = list(map(int, input().split())) m = [int(eval(input())) for i in range(N)] for x in m: X -= x m.sort() n = int(X/m[0]) print((n + len(m)))
N,X = list(map(int,input().split())) m = [int(eval(input())) for _ in range(N)] ans = N X -= sum(m) m = min(m) ans += X//m print(ans)
p03370
n,x = list(map(int,input().split())) m = [int(eval(input())) for i in range(n)] x -= sum(m) print((x//min(m)+n))
n, x = list(map(int, input().split())) m = [int(eval(input())) for _ in range(n)] x -= sum(m) print((n + x // min(m)))
p03370
n, x, *m = list(map(int, open(0).read().split())) ans = 0 for i in sorted(m): if x>=i: x -= i ans+=1 mx = min(m) print((ans + (x//mx)))
n, x, *m = list(map(int, open(0).read().split())) ans = 0 for i in sorted(m): if x>=i: x -= i ans+=1 print((ans+x//min(m)))
p03370
N, X = list(map(int, input().split())) mn = [0]*N for i in range(N): mn[i] = int(eval(input())) ans = N x = X - sum(mn) while(x >= min(mn)): if x // min(mn) == 0: mn[mn.index(min(mn))] = 1000000 else: if x >= min(mn): x -= min(mn) ans += 1 print(ans)
N, X = list(map(int, input().split())) mn = [0]*N for i in range(N): mn[i] = int(eval(input())) ans = N x = X - sum(mn) while(x >= min(mn)): if x // min(mn) == 0: mn[mn.index(min(mn))] = 1000000 else: x -= min(mn) ans += 1 print(ans)
p03370
n, x = list(map(int, input().split())) m = [] for i in range(n): m.append(int(eval(input()))) count = 0 a = min(m) s = sum(m) x -= s count += n while x >= a: x -= a count += 1 print(count)
n, x = list(map(int, input().split())) m = [int(eval(input())) for _ in range(n)] x -= sum(m) count = n mincost = 10**5 for i in range(n): mincost = min(mincost, m[i]) count += x // mincost print(count)
p03370
n, m = list(map(int, input().split())) ls = [int(eval(input())) for _ in range(n)] ls.sort() m -= sum(ls) cnt = n while True: if m >= ls[0]: m -= ls[0] cnt += 1 else: break print(cnt)
n, m = list(map(int, input().split())) ls = [int(eval(input())) for _ in range(n)] print((n+((m-sum(ls))//min(ls))))
p03370
N,X = list(map(int,input().split())) M = [int(eval(input())) for _ in range(N)] print((N + (X-sum(M))//min(M)))
# Python3 (3.4.3) import sys input = sys.stdin.readline # ------------------------------------------------------------- # function # ------------------------------------------------------------- # ------------------------------------------------------------- # main # --------------------------------------...
p03370
n,x=list(map(int,input().split())) ln=[int(eval(input())) for i in range(n)] print((n+(x-sum(ln))//min(ln)))
n,x=list(map(int,input().split())) ln=[int(eval(input())) for _ in range(n)] print((n+(x-sum(ln))//min(ln)))
p03370
n,x = list(map(int,input().split())) m = list(int(eval(input())) for i in range(n)) m.sort() z = sum(m) s = n while x > z: z += m[0] if x >= z: s += 1 print(s)
n,x = list(map(int,input().split())) m = list(int(eval(input())) for i in range(n)) m.sort() z = sum(m) print((n+(x-z)//m[0]))
p03370
n,x=list(map(int, input().split())) min_cost=float('inf') cnt=0 for i in range(n): mi = int(eval(input())) x -= mi cnt += 1 min_cost = min(min_cost,mi) while x >= min_cost: x -= min_cost cnt += 1 print(cnt)
n,x = list(map(int, input().split())) l = [int(eval(input())) for _ in range(n)] print((len(l)+(x-sum(l))//min(l)))
p03370
N, X = [int(x) for x in input().split()] list01=[] for i in range(N): j = int(eval(input())) list01.append(j) j = 0 mass = sum(list01) while mass <= X: j += 1 mass = sum(list01) + min(list01) * j print((N + j -1))
N, X = [int(x) for x in input().split()] list01 = [] for i in range(N): i = int(eval(input())) list01.append(i) min_01 = 0 for i in range(len(list01)): if min_01 == 0: min_01 = list01[i] elif list01[i] < min_01: min_01 = list01[i] for i in range(len(list01)): X -= list01[i] ...
p03370
N, X = list(map(int, input().split())) M = [int(eval(input())) for _ in range(N)] Ms = sorted(M) print((len(Ms) + (X-sum(Ms))//Ms[0]))
N, X = list(map(int, input().split())) M = [int(eval(input())) for _ in range(N)] print((len(M) + (X-sum(M))//min(M)))
p03370
n,x = list(map(int,input().split())) m = [int(eval(input())) for _ in range(n)] ans = 0 minm = 1000 for i in range(n): x -= m[i] minm = min(minm,m[i]) ans += 1 while x >= minm: x -= minm ans += 1 print(ans)
n,x = list(map(int,input().split())) m = [int(eval(input())) for _ in range(n)] x -= sum(m) ans = n + x//min(m) print(ans)
p03370
from functools import lru_cache import sys sys.setrecursionlimit(1000000) @lru_cache(maxsize=1000000) def dp(rest,score): ansbox=[] scorebox=[] for i in m_list: if (rest-i)>0: ansbox.append(dp(rest-i,score+1)) scorebox.append(dp(rest-i, score+1)[1]) if ansb...
N,X=list(map(int,input().split())) M=[int(eval(input())) for _ in range(N)] print((len(M)+(X-sum(M))//min(M)))
p03370
n,x = list(map(int,input().split())) l = [] s = 0 for i in range(n): l.append(int(eval(input()))) s += l[i] for j in range(0,100000): if (x-s) == 0: print(n) break elif ((x-s)/(min(l)*(j+1))) < 1: print((n+j)) break
n,x = list(map(int,input().split())) l = [] s = 0 for i in range(n): l.append(int(eval(input()))) s += l[i] print((int(n+(x-s)/min(l))))
p03370
num, beaking = list(map(int, input().split())) list_category = [int(eval(input())) for i in range(num)] nokori = beaking - sum(list_category) nokori_num = nokori // min(list_category) total = num + nokori_num print(total)
n, x = list(map(int, input().split())) arr = [int(eval(input())) for i in range(n)] x = x - sum(arr) print(((x // min(arr)) + n))
p03370
n,x = list(map(int,input().split())) m = [int(eval(input())) for i in range(n)] a = n s = sum(m) while s < x: s+=min(m) a += 1 print(([a,a-1][s>x]))
n,x = list(map(int,input().split())) m = list(int(eval(input())) for i in range(n)) x -= sum(m) print((x//min(m)+n))
p03370
n, x = list(map(int, input().split())) M = [] for _ in range(n): M.append(int(eval(input()))) M.sort() cnt = 0 for m in M: x -= m cnt += 1 while x > 0: x -= M[0] if x >= 0: cnt += 1 print(cnt)
n,x=list(map(int, input().split())) m = [int(eval(input())) for _ in range(n)] ans = n m.sort() x -=sum(m) while x > 0: x -= m[0] if x >= 0: ans += 1 print(ans)
p03370
N, X = list(map(int, input().split())) list = [] for i in range(N): m = int(eval(input())) list.append(m) print((N + (X - sum(list)) // min(list)))
N, X = list(map(int, input().split())) m = [int(eval(input())) for _ in range(N)] print((N + (X - sum(m)) // min(m)))
p03370
n, x = list(map(int, input().split())) cnt = 0 m = [int(eval(input())) for _ in range(n)] M = sorted(m) if sum(m) <= x: cnt += (n +(x - sum(m)) // min(m)) else: while x >= 0: for i in range(n): x -= M[i] cnt += 1 print(cnt)
n, x = list(map(int, input().split())) m = [int(eval(input())) for i in range(n)] l = [] for i in range(n): X = (x - sum(m)) // m[i] l.append(X) print((n + max(l)))
p03370
N, X = list(map(int, input().split())) M = [int(eval(input())) for i in range(N)] cnt = 0 for i in M: X -= i cnt += 1 while True: X -= min(M) if X < 0: break cnt += 1 print(cnt)
N, X = list(map(int, input().split())) M = [int(eval(input())) for i in range(N)] cnt = N X -= sum(M) cnt += X // min(M) print(cnt)
p03370
N,X = list(map(int,input().split())) M = [] for i in range(N) : m = int(eval(input())) M.append(m) ans = N X -= sum(M) while X >= min(M) : ans += 1 X -= min(M) print(ans)
N,X = list(map(int,input().split())) M = [] for i in range(N) : M.append(int(eval(input()))) ans = ((X-sum(M))//min(M))+N print(ans)
p03370
N, X = list(map(int,input().split())) M = [int(eval(input())) for _ in range(N)] tmp = X - sum(M) if(tmp == 0): print(N) else: print((tmp//min(M) + N))
N, X = list(map(int,input().split())) M = [int(eval(input())) for _ in range(N)] X = X - sum(M) cnt = N x = X tmp = 0 for m in M: tmp = max(tmp, x//m) print((tmp+cnt))
p03370
n, x = list(map(int, input().split())) ls = [int(eval(input())) for _ in range(n)] x -= sum(ls) print((n + x // min(ls)))
n, x = list(map(int, input().split())) ls = [int(eval(input())) for _ in range(n)] print((n + (x - sum(ls)) // min(ls)))
p03370
n, x = list(map(int, input().split())) m = [int(eval(input())) for i in range(n)] sum = 0 min = 1000000 for i in range(n): sum+=m[i] if min > m[i]: min = m[i] x-=sum print((n+int(x/min)))
n, x = list(map(int, input().split())) m = [int(eval(input())) for i in range(n)] sum = 0 for i in range(n): sum+=m[i] x-=sum print((n+int(x/min(m))))
p03370
N,X = list(map(int,input().split())) a = [int(eval(input())) for i in range(N)] moto = X - sum(a) ans = N while moto >= min(a): ans += 1 moto = moto - min(a) print(ans)
N,X = list(map(int,input().split())) a = [int(eval(input())) for i in range(N)] ans = N + (X - sum(a)) // min(a) print(ans)
p03370
n, x = input().split() n = int(n) x = int (x) m = [] i_min = 0 result = 0 for i in range(n): m.append(int(eval(input()))) for i in range(len(m)): x = x - m[i] result = result + 1 for i in range(len(m)): if m[i_min] > m[i]: i_min = i for i in range(x): if x >= m[i_min]: result = result...
#NとXの読み込み n, x = input().split() n = int(n) x = int (x) m = [] i_min = 0 result = 0 #m1からmnまでの読み込み for i in range(n): m.append(int(eval(input()))) #全種類ひとつずつ作る for i in range(len(m)): x = x - m[i] result = result + 1 #リストの中の最小値を突き止める for i in range(len(m)): if m[i_min] > m[i]: i_min = i #i_mi...
p03370
#NとXの読み込み n, x = input().split() n = int(n) x = int (x) m = [] i_min = 0 result = 0 #m1からmnまでの読み込み for i in range(n): m.append(int(eval(input()))) #全種類ひとつずつ作る for i in range(len(m)): x = x - m[i] result = result + 1 #リストの中の最小値を突き止める for i in range(len(m)): if m[i_min] > m[i]: i_min = i #i_mi...
#データの読み込み n, x = input().split() n = int(n) x = int(x) m = [] i_min = 0 gokei = 0 #n個の入力に対するループ for i in range(n): #問題からの入力をintに変換してリストへ格納 m.append(int(eval(input()))) #全部を1つずつ作った場合の粉量の合計 gokei = gokei + m[i] #使う粉量が一番少ないドーナツを見つける if m[i_min] > m[i]: i_min = i #全部を1つずつ作った後に残る粉量 x = x - g...
p03370
a, b, c = list(map(int, input().split())) n=0 while True: if c%a == 0: n += 1 a += 1 if a == b: break print(n)
a, b, c = list(map(int, input().split())) n=0 while True: if c%a == 0: n += 1 a += 1 if a > b: break print(n)
p02398
a,b,c = [int(x) for x in input().split( )] div = [] for x in range(1,c+1): if c % x == 0: div.append(x) r = [] for x in range(a,b+1): r.append(x) answer = 0 for x in div: for y in r: if x == y: answer += 1 print(answer)
a,b,c = [int(x) for x in input().split( )] count = 0 for number in range(a,b+1): if c % number == 0: count += 1 print(count)
p02398
a,b,c=list(map(int,input().split(" "))) count=0 while(1): if c%a==0: count+=1 a+=1 if a==b: break print(count)
a,b,c=list(map(int,input().split(" "))) count=0 while(a<=b): if c%a==0: count+=1 a+=1 print(count)
p02398
from operator import add from functools import reduce def divisor_generator(a, b, c): for i in range(a, b+1): yield (1 if c%i == 0 else 0) a, b, c = list(map(int, input().split(' '))) print((reduce(add, divisor_generator(a, b, c))))
a, b, c = list(map(int, input().split())) cnt = 0 for n in range(a, b+1): if c % n == 0: cnt += 1 print(cnt)
p02398
import sys a, b, c = [ int( val ) for val in sys.stdin.readline().split( ' ' ) ] cnt = 0 i = a while i <= b: if ( c % i ) == 0: cnt += 1 i += 1 print(( "{}".format( cnt ) ))
import sys a, b, c = [ int( val ) for val in sys.stdin.readline().split( ' ' ) ] cnt = 0 for divisor in range( a, b+1 ): if ( c % divisor ) == 0: cnt += 1 print(( "{}".format( cnt ) ))
p02398
a, b, c = list(map(int, input().split())) cnt = 0 for i in range(a, b+1): if c % i == 0: cnt += 1 print(cnt)
a, b, c = list(map(int, input().split())) divisor = 0 for n in range(a, b+1): if c % n == 0: divisor += 1 print(divisor)
p02398
import math a, b, c = list(map(int, input().split())) l = []; d = int(math.sqrt(c)); e = 0 for i in range(1, d + 1): if i * i == c: l += [i] elif c % i == 0: l += [i, c // i] for x in l: if a <= x <= b: e += 1 print(e)
a, b, c = list(map(int, input().split())) ans = 0 for i in range(a, b + 1): if c % i == 0: ans += 1 print(ans)
p02398
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) from collections import defaultdict from bisect import bisect_left S = input().rstrip() T = input().rstrip() LS = len(S) index = defaultdict(list) # alphabet to indices for i,s in enumerate(S): index[s].append(i) index x ...
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from bisect import bisect_right S = [ord(x)-ord('a') for x in readline().rstrip().decode('utf-8')] T = [ord(x)-ord('a') for x in readline().rstrip().decode('utf-8')] index = [[] for _ in rang...
p02937
S = list([ord(x)-ord('a') for x in input().strip()]) T = list([ord(x)-ord('a') for x in input().strip()]) L = len(S) occ = [[] for i in range(26)] for i, c in enumerate(S): occ[c].append(i) for c in T: if occ[c] == []: print((-1)) quit() total = 0 cur = -1 def getLowest(bou...
S = list([ord(x)-ord('a') for x in input().strip()]) T = list([ord(x)-ord('a') for x in input().strip()]) L = len(S) occ = [[] for i in range(26)] for i, c in enumerate(S): occ[c].append(i) for c in T: if occ[c] == []: print((-1)) quit() total = 0 cur = -1 def getLowest(bou...
p02937
from bisect import bisect_right from collections import defaultdict import sys read = sys.stdin.readline s = read()[:-1] t = read()[:-1] # 即時終了 if set(t) - set(s): print((-1)) exit() # 前処理 # 0based indexにおいてi文字目以降に文字cが出てくるidxを取得する # 前処理の前処理、0文字目から見たときにその文字が何文字目にあるかを記録しておく mojiidx = defaultdic...
from bisect import bisect_right from collections import defaultdict import sys read = sys.stdin.readline s = read()[:-1] t = read()[:-1] # 即時終了 if set(t) - set(s): print((-1)) exit() # 前処理 # 0文字目から見たときにその文字が何文字目にあるかを記録しておく mojiidx = defaultdict(lambda: []) for i, ss in enumerate(s + s): ...
p02937
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys import copy from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replac...
# -*- coding: utf-8 -*- import sys # sys.setrecursionlimit(10**6) # buff_readline = sys.stdin.buffer.readline buff_readline = sys.stdin.readline readline = sys.stdin.readline INF = 2**62-1 def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().spli...
p02937
#ABC138-E Strings of Impurity """ sの好きなだけのループに対する部分文字列tを求める tにあってsにない文字がある時点でno そうでないならば必ず達成可能で、 tに対してループを回し(i)、 sのj文字目に関して、それより後に初めて出てくるt[i+1]の場所をindexで返し,i+=1,j=そのindex にする。 そのようなindexがないならば、j=0とし、またはじめから回す。 """ import sys import bisect readline = sys.stdin.buffer.readline def even(n): return 1 if n%2==0...
#ABC138-E Strings of Impurity """ sの好きなだけのループに対する部分文字列tを求める tにあってsにない文字がある時点でno そうでないならば必ず達成可能で、 tに対してループを回し(i)、 sのj文字目に関して、それより後に初めて出てくるt[i+1]の場所をindexで返し,i+=1,j=そのindex にする。 そのようなindexがないならば、j=0とし、またはじめから回す。 """ import sys import bisect readline = sys.stdin.buffer.readline def even(n): return 1 if n%2==0...
p02937
from collections import defaultdict from bisect import bisect_left S = input().rstrip() T = input().rstrip() LS = len(S) index = defaultdict(list) for i, s in enumerate(S): index[s].append(i) x = -1 for t in T: arr = index[t] if len(arr) == 0: print((-1)) exit() y = (x+1)%LS i...
from collections import defaultdict from bisect import * S = input().rstrip() T = input().rstrip() LS = len(S) index = defaultdict(list) for i, s in enumerate(S): index[s].append(i) x = -1 loop = 0 for t in T: arr = index[t] if len(arr) == 0: print((-1)) exit() i = bisect(a...
p02937
import sys from collections import defaultdict import bisect sys.setrecursionlimit(10 ** 7) sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) S = sr() len_S = len(S) T = sr() dict_S = defaultdict(list) for i, s in enumerate(S): dict_S[s].appe...
import sys from collections import defaultdict import bisect sys.setrecursionlimit(10 ** 7) sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) S = sr() T = sr() len_S = len(S) indexes_S = defaultdict(list) for i, s in enumerate(S): indexes_S[s...
p02937
import sys # 10倍速いらしい input = sys.stdin.readline INF = float('inf') MOD = 10 ** 9 + 7 EPS = 10 ** -7 sys.setrecursionlimit(1000000) S = input().rstrip() T = input().rstrip() sn = len(S) M = [dict() for _ in range(sn)] for i, s in enumerate(S): for j in range(sn): M[(i - j + sn) % sn][s] =...
import sys import bisect # 10倍速いらしい input = sys.stdin.readline INF = float('inf') MOD = 10 ** 9 + 7 EPS = 10 ** -7 sys.setrecursionlimit(1000000) S = input().rstrip() T = input().rstrip() sn = len(S) d = dict() for i, s in enumerate(S): d[s] = d.get(s, []) d[s].append(i) nowidx = -1 lo...
p02937
import sys stdin = sys.stdin sys.setrecursionlimit(10 ** 7) def li(): return list(map(int, stdin.readline().split())) def li_(): return [int(x) - 1 for x in stdin.readline().split()] def lf(): return list(map(float, stdin.readline().split())) def ls(): return stdin.readline().split() def ns(): return stdin.r...
import sys stdin = sys.stdin sys.setrecursionlimit(10 ** 7) def li(): return list(map(int, stdin.readline().split())) def li_(): return [int(x) - 1 for x in stdin.readline().split()] def lf(): return list(map(float, stdin.readline().split())) def ls(): return stdin.readline().split() def ns(): return stdin.r...
p02937
import sys stdin = sys.stdin sys.setrecursionlimit(10 ** 7) def li(): return list(map(int, stdin.readline().split())) def li_(): return [int(x) - 1 for x in stdin.readline().split()] def lf(): return list(map(float, stdin.readline().split())) def ls(): return stdin.readline().split() def ns(): return stdin.r...
import sys stdin = sys.stdin sys.setrecursionlimit(10 ** 7) def li(): return list(map(int, stdin.readline().split())) def li_(): return [int(x) - 1 for x in stdin.readline().split()] def lf(): return list(map(float, stdin.readline().split())) def ls(): return stdin.readline().split() def ns(): return stdin.r...
p02937
import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 LI = lambda : [int(x) for x in sys.stdin.readline().split()] NI = lambda : int(sys.stdin.readline()) SI = lambda : sys.stdin.readline().rstrip() s =...
import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 LI = lambda : [int(x) for x in sys.stdin.readline().split()] NI = lambda : int(sys.stdin.readline()) SI = lambda : sys.stdin.readline().rstrip() s =...
p02937
def slove(): import sys import collections import bisect input = sys.stdin.readline s = str(input().rstrip('\n')) t = str(input().rstrip('\n')) d = collections.defaultdict(list) for i in range(len(s)): d[s[i]] += [i] loop = 0 pos = 0 for i in range(len(t...
import sys import bisect import collections def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 s = str(readline().rstrip().decode('utf-8')) d = collections.defaultdict(list) for i in range(len(s)): d[s[i]] += [i] loop = 0 pos = 0 t = str(readline(...
p02937