input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
# coding: utf-8 # Your code here! import sys sys.setrecursionlimit(10**6) readline = sys.stdin.readline #文字列入力のときは注意 n = int(eval(input())) a = [int(i) for i in readline().split()] b = [int(i) for i in readline().split()] def op(b,i): global ans if i == n-1: res = (b[i]-a[i])//(b[i-1]...
# coding: utf-8 # Your code here! import sys sys.setrecursionlimit(10**6) readline = sys.stdin.readline #文字列入力のときは注意 n = int(eval(input())) a = [int(i) for i in readline().split()] b = [int(i) for i in readline().split()] def op(b,i): global ans if i == n-1: res = (b[i]-a[i])//(b[i-1]...
p02941
#!/usr/bin/env python3 import sys # import heapq def solve(N: int, A: "List[int]", B: "List[int]"): count = 0 flag = True while flag: flag = False for i in range(N): a, b, c = B[i-1], B[i], B[(i+1) % N] if b > A[i] and b > a+c: d, m = ...
#!/usr/bin/env python3 import sys # import heapq def solve(N: int, A: "List[int]", B: "List[int]"): count = 0 flag = True while flag: flag = False for i in range(N): a, b, c = B[i-1], B[i], B[(i+1) % N] if b > A[i] and b > a+c: d, m = ...
p02941
#!/usr/bin/env python3 import sys from heapq import heapify, heappush, heappop def solve(N: int, A: "List[int]", B: "List[int]"): lh = [] for i, b in enumerate(B): heappush(lh, [-b, i]) count = 0 while lh: b, i = heappop(lh) a, b = A[i], B[i] c = B[i-1]...
#!/usr/bin/env python3 import sys from heapq import heapify, heappush, heappop def solve(N: int, A: "List[int]", B: "List[int]"): lh = [] for i, b in enumerate(B): heappush(lh, (-b, i)) count = 0 while lh: b, i = heappop(lh) a, b, c = A[i], B[i], B[i-1]+B[(i+1) ...
p02941
import sys input = sys.stdin.readline n=int(eval(input())) A=[int(i) for i in input().split()] B=[int(i) for i in input().split()] from heapq import heappop, heappush push = lambda x,i: heappush(BB,(-x,i)) BB=[] for i,b in enumerate(B): push(b,i) ans=0 while BB: b,ind=heappop(BB) b,ai=-b,A[ind]...
n=int(eval(input())) A=[int(i) for i in input().split()] B=[int(i) for i in input().split()] from heapq import heappop, heappush push = lambda x,i: heappush(BB,(-x,i)) BB=[] for i,b in enumerate(B): push(b,i) ans=0 while BB: b,ind=heappop(BB) b,ai=-b,A[ind] if b<ai: ans=-1 break ...
p02941
n=int(eval(input())) A=[int(i) for i in input().split()] B=[int(i) for i in input().split()] from heapq import heappop, heappush push = lambda x,i: heappush(BB,(-x,i)) BB=[] for i,b in enumerate(B): push(b,i) ans=0 while BB: b,ind=heappop(BB) b=-b if b<A[ind]: ans=-1 break d=B[(...
n=int(eval(input())) A=[int(i) for i in input().split()] B=[int(i) for i in input().split()] from heapq import heappop, heappush push = lambda x,i: heappush(BB,(-x,i)) BB=[] for i,b in enumerate(B): push(b,i) ans=0 while BB: b,ind=heappop(BB) b,ai=-b,A[ind] if b<ai: ans=-1 break i...
p02941
n=int(eval(input())) A=[int(i) for i in input().split()] B=[int(i) for i in input().split()] from heapq import heappop, heappush push = lambda x,i: heappush(BB,(-x,i)) BB=[] for i in range(n): push(B[i],i) ans=0 chk=0 while chk<n: b,ind=heappop(BB) b,ai=-b,A[ind] if b<ai: ans=-1 bre...
n=int(eval(input())) A=[int(i) for i in input().split()] B=[int(i) for i in input().split()] from heapq import heappop, heappush push = lambda x,i: heappush(BB,(-x,i)) BB=[] for i,b in enumerate(B): push(b,i) ans=0 while BB: b,ind=heappop(BB) b,ai=-b,A[ind] if b<ai: ans=-1 break d...
p02941
n=int(eval(input())) A=[int(i) for i in input().split()] B=[int(i) for i in input().split()] from heapq import heappop, heappush push = lambda x,i: heappush(BB,(-x,i)) BB=[] for i,b in enumerate(B): push(b,i) ans=0 while BB: b,ind=heappop(BB) b,ai=-b,A[ind] if b<ai: ans=-1 break d...
n=int(eval(input())) A=[int(i) for i in input().split()] B=[int(i) for i in input().split()] key=2**18 from heapq import heappop, heappush push = lambda x,i: heappush(BB,-(x*key+i)) BB=[] for i,b in enumerate(B): push(b,i) ans=0 while BB: bb=heappop(BB) bb=-bb b,ind=bb//key,bb%key ai=A[ind] ...
p02941
import heapq N = int(eval(input())) A = list(map(int, input().split())) Temp = input().split() B = [] for i in range(N): heapq.heappush(B, (-int(Temp[i]), i)) now = list(map(int, Temp)) complete = [False]*N fin = [True]*N ans = 0 while True: v, i = heapq.heappop(B) if A[i] == now[i]: ...
import heapq N = int(eval(input())) A = list(map(int, input().split())) B = input().split() C = [] for i in range(N): heapq.heappush(C, (A[i] - int(B[i]), i)) B = list(map(int, B)) ans = 0 while True: v, i = heapq.heappop(C) if v == 0: break nv = B[i-1] + B[(i+1) % N] n = -...
p02941
def calc(l): A1=2*(l[1][0]-l[0][0]) B1=2*(l[1][1]-l[0][1]) C1=l[0][0]**2-l[1][0]**2+l[0][1]**2-l[1][1]**2 A2=2*(l[2][0]-l[0][0]) B2=2*(l[2][1]-l[0][1]) C2=l[0][0]**2-l[2][0]**2+l[0][1]**2-l[2][1]**2 X=(B1*C2-B2*C1)/(A1*B2-A2*B1) Y=(C1*A2-C2*A1)/(A1*B2-A2*B1) R=((X-l[0][0])**2+(Y-l[0][1])**2)**0.5 re...
def calc(a,b,c,d,e,f): A1=2*(c-a) B1=2*(d-b) C1=a**2-c**2+b**2-d**2 A2=2*(e-a) B2=2*(f-b) C2=a*a-e*e+b*b-f*f X=(B1*C2-B2*C1)/(A1*B2-A2*B1) Y=(C1*A2-C2*A1)/(A1*B2-A2*B1) R=((X-a)**2+(Y-b)**2)**0.5 return tuple(map(round, [X,Y,R], [3]*3)) l=[list(map(float,input().split())) for i in range(eval(input(...
p00010
for _ in range(int(eval(input()))): x1, y1, x2, y2, x3, y3 = list(map(float, input().split())) d = 2 * (x2 * y3 - x3 * y2 + x3 * y1 - x1 * y3 + x1 * y2 - x2 * y1) px = ((y2 - y3) * (x1 ** 2 + y1 ** 2) + (y3 - y1) * (x2 ** 2 + y2 ** 2) + (y1 - y2) * (x3 ** 2 + y3 ** 2)) / d py = -1 * ((x2 - x3) * (x1...
for _ in[0]*int(eval(input())): a,d,b,e,c,f=list(map(float,input().split())) z=2*(b*f-c*e+c*d-a*f+a*e-b*d) x=((e-f)*(a**2+d**2)+(f-d)*(b**2+e**2)+(d-e)*(c**2+f**2))/z y=((c-b)*(a**2+d**2)+(a-c)*(b**2+e**2)+(b-a)*(c**2+f**2))/z print(('{0:.3f} {1:.3f} {2:.3f}'.format(x,y,((a-x)**2+(d-y)**2)**0.5)))
p00010
from heapq import heappop as pop from heapq import heappush as push INF = 1000000000000 while True: R = int(eval(input())) if not R: break w1, h1, x1, y1 = list(map(int, input().split())) x1 -= 1 y1 -= 1 lst1 = [list(map(int, input().split())) for _ in range(h1)] used1 = [[False] * w1 for _...
from heapq import heappop as pop from heapq import heappush as push INF = 1000000000000 def solve(): while True: R = int(eval(input())) if not R: break w1, h1, x1, y1 = list(map(int, input().split())) x1 -= 1 y1 -= 1 lst1 = [list(map(int, input().split())) for _ in range(h1)...
p00465
from random import randint D = int(input()) C = list(map(int, input().split())) S = [list(map(int, input().split())) for _ in range(D)] T = [] for i in range(D): l = S[i].index(max(S[i])) T.append(l+1) print(*T, sep="\n")
D = int(input()) C = list(map(int, input().split())) S = [list(map(int, input().split())) for _ in range(D)] T = [] for i in range(D): l = S[i].index(max(S[i])) T.append(l+1) print(*T, sep="\n")
p02618
D = int(eval(input())) c = list(map(int, input().split())) last = [0] * 26 ans = [] S = [] prev_score = 0 maxsi_list = [] for d in range(1, D+1): s = list(map(int, input().split())) S += [s] maxs = float('-inf') maxss = float('-inf') maxi = -1 maxii = -1 cumsump = 0 for ...
D = int(eval(input())) c = list(map(int, input().split())) last = [0] * 26 ans = [] S = [] prev_score = 0 maxsi_list = [] for d in range(1, D+1): s = list(map(int, input().split())) S += [s] maxs = float('-inf') maxss = float('-inf') maxi = -1 maxii = -1 cumsump = 0 for ...
p02618
def main(): from builtins import int, map, list, print, len from collections import defaultdict import sys sys.setrecursionlimit(10 ** 6) input = (lambda: (sys.stdin.readline()).rstrip()) input_list = (lambda: input().split()) input_number = (lambda: int(input())) input_number_...
def main(): from builtins import int, map, list, print, len from collections import defaultdict import sys sys.setrecursionlimit(10 ** 6) input = (lambda: (sys.stdin.readline()).rstrip()) input_list = (lambda: input().split()) input_number = (lambda: int(input())) input_number_...
p02618
D = int(eval(input())) A = [[0]*26]*D S = 0 C = list(map(int,input().split())) P = 0 ld =[0]*26#最後に行った日の格納 l = [0]*26#損失の計算 sp = 0#一時格納 for i in range(D): A[i] = list(map(int,input().split())) for j in range(D): maxvalue = max(A[j]) index = A[j].index(maxvalue) for n in range(26): ld[n] = ld[n...
D = int(eval(input())) A = [[0]*26]*D S = 0 C = list(map(int,input().split())) P = 0 ld =[0]*26#最後に行った日の格納 l = [0]*26#損失の計算 sp = 0#一時格納 t = [0]*D for i in range(D): A[i] = list(map(int,input().split())) for j in range(D): maxvalue = max(A[j]) index = A[j].index(maxvalue) for n in range(26): l...
p02618
D = int(eval(input())) C = list(map(int, input().split())) for i in range(D): S = list(map(int, input().split())) print((S.index(max(S))+1))
D = int(eval(input())) C = list(map(int, input().split())) ans = [] for i in range(D): S = list(map(int, input().split())) ans.append(S.index(max(S))+1) for e in ans: print(e)
p02618
import math import fractions #import sys #input = sys.stdin.readline def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) # divisors.sort() return divi...
import math import fractions #import sys #input = sys.stdin.readline def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) # divisors.sort() return divi...
p02618
from time import time start = time() D = int(eval(input())) C = [int(i) for i in input().split()] scores = [[int(i) for i in input().split()] for j in range(D)] t = [] for i in scores: t.append(i.index(max(i))+1) DC = [0]*26 def calcScore(t): score = [] S = 0 last = [0]*26 for d in ...
from time import time start = time() D = int(eval(input())) C = [int(i) for i in input().split()] scores = [[int(i) for i in input().split()] for j in range(D)] t = [] for i in scores: t.append(i.index(max(i))+1) DC = [0]*26 def calcScore(t): score = [] S = 0 last = [0]*26 for d in ...
p02618
from time import time start = time() D = int(eval(input())) C = [int(i) for i in input().split()] scores = [[int(i) for i in input().split()] for j in range(D)] t = [] for i in scores: t.append(i.index(max(i))+1) DC = [0]*26 def calcScore(t): score = [] S = 0 last = [0]*26 for d in ...
from time import time start = time() D = int(eval(input())) C = [int(i) for i in input().split()] scores = [[int(i) for i in input().split()] for j in range(D)] t = [] for i in scores: t.append(i.index(max(i))+1) DC = [0]*26 def calcScore(t): score = [] S = 0 last = [0]*26 for d in ...
p02618
d=int(eval(input())) C=[int(i) for i in input().split()] s=[[int(i) for i in input().split()] for q in range(d)] sco=0 L=[0 for i in range(26)] ans=[] #calc for i in range(d): mayou=0 est=s[i][0]+C[0]*(i+1-L[0]) for p in range(1,26): if s[i][p]+C[p]*(i+1-L[p]) > est: mayo...
d=int(eval(input())) C=[int(i) for i in input().split()] s=[[int(i) for i in input().split()] for q in range(d)] sco=0 L=[0 for i in range(26)] ans=[] #calc for i in range(d): mayou=0 est=s[i][0]+C[0]*(i+1-L[0]) for p in range(1,26): if s[i][p]+C[p]*(i+1-L[p]) > est: mayo...
p02618
def choose(D, c, s, d, last, depth, p): maxpoint = -999999 maxnum = 0 if depth > 0 and d < D: for i in range(26): point = p point += s[d][i] point += changepoint(c, d, i, last) nlast = [] nlast.extend(last) nlast[i] = ...
def choose(D, c, s, d, last, depth, p): maxpoint = -999999 maxnum = 0 if depth > 0 and d < D: for i in range(26): point = p point += s[d][i] point += changepoint(c, d, i, last) nlast = [] nlast.extend(last) nlast[i] ...
p02618
import sys import math from collections import deque import heapq import itertools from decimal import Decimal import bisect from operator import itemgetter MAX_INT = int(10e18) MIN_INT = -MAX_INT mod = 1000000000+7 sys.setrecursionlimit(1000000) def IL(): return list(map(int,input().split())) def SL(): re...
import sys import math from collections import deque import heapq import itertools from decimal import Decimal import bisect from operator import itemgetter MAX_INT = int(10e18) MIN_INT = -MAX_INT mod = 1000000000+7 sys.setrecursionlimit(1000000) def IL(): return list(map(int,input().split())) def SL(): re...
p02618
import sys import math from collections import deque import heapq import itertools from decimal import Decimal import bisect from operator import itemgetter MAX_INT = int(10e18) MIN_INT = -MAX_INT mod = 1000000000+7 sys.setrecursionlimit(1000000) def IL(): return list(map(int,input().split())) def SL(): re...
import sys import math from collections import deque import heapq import itertools from decimal import Decimal import bisect from operator import itemgetter MAX_INT = int(10e18) MIN_INT = -MAX_INT mod = 1000000000+7 sys.setrecursionlimit(1000000) def IL(): return list(map(int,input().split())) def SL(): re...
p02618
D = int(eval(input())) c = list(map(int, input().split())) s = [list(map(int, input().split())) for _ in range(D)] last = [-1]*26 ans = 0 for d in range(D): stack = [] for i in range(26): if (d-last[i])*c[i]<0: stack.append(i) if stack: tmp, res = 0, 0 for i...
D = int(eval(input())) c = list(map(int, input().split())) s = [list(map(int, input().split())) for _ in range(D)] do_list = [-1]*D for i in range(D): tmp, res = s[i][0], 0 for j in range(1,26): if tmp<s[i][j]: tmp, res = s[i][j], j do_list[i] = res for i in do_list: print((i+1...
p02618
import copy D = int(eval(input())) c = list(map(int,input().split())) s = [ [0 for j in range(26)] for i in range(D)] for i in range(D): tmp = list(map(int,input().split())) for j in range(26): s[i][j] = tmp[j] t = [] v = [0] * D last = [ [0 for j in range(26)] for i in range(D)] sum = 0 for...
import copy D = int(eval(input())) c = list(map(int,input().split())) s = [ [0 for j in range(26)] for i in range(D)] for i in range(D): tmp = list(map(int,input().split())) for j in range(26): s[i][j] = tmp[j] t = [] v = [0] * D last = [ [0 for j in range(26)] for i in range(D)] sum = 0 for...
p02618
D = int(eval(input())) C = list(map(int, input().split())) SS = [list(map(int, input().split())) for i in range(D)] Last = [-1] * 26 for d in range(D): S = SS[d] t = -1 x = -1e100 for i, s in enumerate(S): score = s - sum(c * d - (max(last, 0)) for c, last in zip(C, Last)) ...
D = int(eval(input())) C = list(map(int, input().split())) SS = [list(map(int, input().split())) for i in range(D)] Last = [-1] * 26 for d in range(D): S = SS[d] t = -1 x = -1e100 minus=sum(c * (d-max(last, 0)) for c, last in zip(C, Last)) for i, s in enumerate(S): score = s ...
p02618
d = int(eval(input())) clst = list(map(int, input().split())) s = [list(map(int, input().split())) for _ in range(d)] last = [0 for _ in range(26)] def score_minus(d, q): minus = 0 for i, (c, ls) in enumerate(zip(clst, last)): if i == d: continue minus += c * (d - ls) ...
d = int(eval(input())) clst = list(map(int, input().split())) s = [list(map(int, input().split())) for _ in range(d)] last = [0 for _ in range(26)] def score_minus(d, q): minus = 0 for i, (c, ls) in enumerate(zip(clst, last)): if i == d: continue minus += c * (d - ls) ...
p02618
import sys readline = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9+7 #mod = 998244353 INF = 10**18 eps = 10**-7 D = int(readline()) C = list(map(int,readline().split())) S = [list(map(int,readline().split())) for i in range(D)] for s in S: ansidx = 0 anssum = 0 for i,si in en...
import sys readline = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9+7 #mod = 998244353 INF = 10**18 eps = 10**-7 D = int(readline()) C = list(map(int,readline().split())) S = [list(map(int,readline().split())) for i in range(D)] past = -1 for s in S: ansidx = 0 anssum = 0 for...
p02618
from copy import copy d = int(eval(input())) c = [0] + list(map(int, input().split(' '))) s = [[]] + [[0] + list(map(int, input().split(' '))) for _ in range(d)] t = 0 # 算出結果 ca = [0] * (1 + 26) # 放置された不満の数々 cat = [] # 不満度の最適な算出のための一時配列 cat2 = [] dc = 0 # カレントな満足度 #dl = [] # 満足度のログ for i in range(1, d...
from copy import copy d = int(eval(input())) c = [0] + list(map(int, input().split(' '))) s = [[]] + [[0] + list(map(int, input().split(' '))) for _ in range(d)] t = 0 # 算出結果 ca = [0] * (1 + 26) # 放置された不満の数々 cat = [] # 不満度の最適な算出のための一時配列 cat2 = [] for i in range(1, d + 1): cat = [0] for i2 in r...
p02618
#coding:utf-8 import random D = int(eval(input())) C = [int(y) for y in input().split()] S = [] ans = [] def scoring(inp,poi): score = 0 day = 1 last = [0] * 26 for I in inp: score += poi[day-1][I-1] last[I-1] = day for ind,J in enumerate(last):...
#coding:utf-8 import random D = int(eval(input())) C = [int(y) for y in input().split()] S = [] ans = [] def scoring(inp,poi): score = 0 day = 1 last = [0] * 26 for I in inp: score += poi[day-1][I-1] last[I-1] = day for ind,J in enumerate(last):...
p02618
import sys readline = sys.stdin.readline # 0-indexでやる D = int(readline()) C = list(map(int,readline().split())) # 満足度の下がりやすさ S = [None] * D sortS = [None] * D for i in range(D): s = list(map(int,readline().split())) S[i] = s.copy() for j in range(len(s)): s[j] = (s[j],j) sortS[i] = sorted(s,...
import sys readline = sys.stdin.readline # 0-indexでやる D = int(readline()) C = list(map(int,readline().split())) # 満足度の下がりやすさ S = [None] * D sortS = [None] * D for i in range(D): s = list(map(int,readline().split())) S[i] = s.copy() for j in range(len(s)): s[j] = (s[j],j) sortS[i] = sorted(s,...
p02618
D = int(eval(input())) c = [int(_) for _ in input().split()] s = [[int(_) for _ in input().split()] for _ in range(D)] sat = 0 last = [0] * 26 for d in range(D): v = 0 j = 0 for x in range(26): if v < s[d][x]: j = x v = s[d][x] last[j] = d + 1 print((j+...
D = int(eval(input())) c = [int(_) for _ in input().split()] s = [[int(_) for _ in input().split()] for _ in range(D)] for d in range(D): v = -20000 j = 0 for x in range(26): if v < s[d][x]: j = x v = s[d][x] print((j+1))
p02618
def main(): D = int(eval(input())) C = list(map(int, input().split())) S = [list(map(int, input().split()))for _ in range(D)] len_C = len(C) types = [] lasts = [0] * 26 for i in range(D): s = max(S[i]) c = [] c_sum = 0 for j in range(len_C): ...
def main(): D = int(eval(input())) C = list(map(int, input().split())) S = [list(map(int, input().split()))for _ in range(D)] len_C = len(C) types = [] lasts = [0] * 26 for i in range(D): s = max(S[i]) c = [] c_sum = 0 for j in range(len_C): ...
p02618
D = int(eval(input())) cs = list(map(int, input().split())) #s = [input().split() for l in range(D)] S=0 for d in range(D): s=list(map(int, input().split())) max_value = max(s) max_index = s.index(max_value) print((max_index+1)) S+=max_value
D = int(eval(input())) cs = list(map(int, input().split())) #s = [input().split() for l in range(D)] S=0 l=[] for d in range(D): s=list(map(int, input().split())) max_value = max(s) max_index = s.index(max_value) l.append(max_index+1) S+=max_value for i in range(D): print((l[...
p02618
def lackSatisfaction(c, d, last): lack = 0 max = 0 mindex = 0 for i in range(len(c)): tmp = c[i] * (d - last[i]) lack += tmp if (max < tmp): max = tmp mindex = i return max, mindex #365 D = int(eval(input())) c = list(map(int, input().sp...
def lackSatisfaction(c, d, last): lack = 0 max = 0 mindex = 0 for i in range(len(c)): tmp = c[i] * (d - last[i]) lack += tmp if (max < tmp): max = tmp mindex = i return max, mindex #365 D = int(eval(input())) c = list(map(int, input().sp...
p02618
from collections import deque n = int(eval(input())) s = input().rstrip() + "#" dic = {"R": deque(), "G":deque(), "B":deque()} prev_ch = s[0] cnt = 1 ans = 1 for i, ch in enumerate(s[1:]): if ch == prev_ch: cnt += 1 else: dic[prev_ch].append([cnt, i-1]) while dic["R"] and...
#!/usr/bin/env python3 n = int(eval(input())) s = input().rstrip() MOD = 998244353 r = 0; g = 0; b = 0 rg = 0 gb = 0 br = 0 ans = 1 for ch in s: if ch == "R": if gb > 0: ans *= gb gb -= 1 elif g > 0: ans *= g g -= 1 rg +=...
p02940
from functools import reduce n = int(eval(input())) s = input().strip() MOD = 998244353 R = 1 G = 2 B = 4 RG = R + G RB = R + B GB = G + B RGB = R + G + B table = {'R': R, 'G': G, 'B': B} counts = { 0: 0, R: 0, G: 0, B: 0, RG: 0, RB: 0, GB: 0, } patterns = 1 for cv in [table[c] for c...
from functools import reduce n = int(eval(input())) s = input().strip() MOD = 998244353 R = 1 G = 2 B = 4 RG = R + G RB = R + B GB = G + B RGB = R + G + B table = {'R': R, 'G': G, 'B': B} counts = { 0: 0, R: 0, G: 0, B: 0, RG: 0, RB: 0, GB: 0, } patterns = 1 for cv in [table[c] for c...
p02940
inp = [int(n) for n in input().split(" ")] res = inp[0] == inp[1] and inp[0] == inp[2] and 1 <= inp[0] <= 100 if res: print("Yes") else: print("No")
n = [int(x) for x in input().split()] res = 1 <= n[0] <= 100 and n[0] == n[1] == n[2] if res: print("Yes") else: print("No")
p03079
a,b,c=list(map(int,input().split())) if a==b and b==c: print("Yes") else: print("No")
A,B,C=list(map(int,input().split())) if A==B and B==C: print("Yes") else: print("No")
p03079
A, B, C = list(map(int, input().split())) if A == B and B == C: print('Yes') else: print('No')
li = set(map(int, input().split())) print(('Yes' if len(li) == 1 else 'No'))
p03079
A, B, C = [i for i in input().split()] print(('Yes' if A == B and B == C else 'No'))
a, b, c = [int(I) for I in input().split()] print(('YNeos'[not(a == b and b == c)::2]))
p03079
s = input().strip() n = len(s) if s[0]==s[-1]: if n%2==0: print("First") else: print("Second") else: if n%2==0: print("Second") else: print("First")
s = input().strip() N = len(s) if N%2==0 and s[0]==s[-1]: print("First") elif N%2==0 and s[0]!=s[-1]: print("Second") elif N%2==1 and s[0]==s[-1]: print("Second") else: print("First")
p03863
s = input() n = 0 while (len(s) > 2): for i in range(1, len(s)-1): if s[i-1] != s[i+1]: s = s[0:i] + s[i+1:len(s)] n += 1 break if len(s) == 3 and s[0] == s[2]: break if n % 2 == 1: print("First") else: print("Second")
s = input() n = len(s)-2 if s[0] == s[len(s)-1]: n -= 1 if n % 2 == 1: print("First") else: print("Second")
p03863
import sys def main(): s=list(sys.stdin.readline().strip()) t=0 while len(s)>2: ps,cs,f=s[0],s[1],False for i,ns in enumerate(s[2:],1): if ps!=ns: s.pop(i) f,t=True,t^1 break ps,cs=cs,ns if f is False...
import sys def main(): s=list(sys.stdin.readline().strip()) t=0 while len(s)>2: ps,cs,i,f=s[0],s[1],1,False for ns in s[2:]: if ps!=ns: cs,f,t=ns,True,t^1 s.pop(i) else:ps,cs,i=cs,ns,i+1 if f is False:break print...
p03863
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0181 """ import sys from sys import stdin input = stdin.readline def Cond(m, n, mid, books): if max(books) > mid: return False rem = mid while books: while rem >= books[0]: r...
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0181 """ import sys from sys import stdin input = stdin.readline def Cond(m, n, mid, books): if max(books) > mid: return False rem = mid while books: while rem >= books[0]: r...
p00181
a, b, c = input().split() colors = 0 if a == b and b == c: colors = 1 elif a == b or b == c or c == a: colors = 2 else: colors = 3 print(colors)
s = set(input().split()) print((len(s)))
p03962
l=list(map(int,input().split())) ls=[] for i in l: ls.append(i) k=set(ls) print((len(k)))
a,b,c=input().split() if a==b==c: print("1") elif a==b or b==c or c==a: print("2") else: print("3")
p03962
print((len(set(list(map(int,input().split()))))))
print((len(set(input().split()))))
p03962
l = [ int(x) for x in input().split() ] l = set(l) print((len(list(l))))
l = [ int(x) for x in input().split() ] print((len(set(l))))
p03962
from collections import Counter A,B,C = list(map(int,input().split())) print((len(Counter([A,B,C]).most_common())))
A,B,C = list(map(int,input().split())) print((len(set([A,B,C]))))
p03962
A,B,C = list(map(int,input().split())) print((len(set([A,B,C]))))
# python3 (3.4.3) import sys input = sys.stdin.readline # main A,B,C = list(map(int,input().split())) print((len({A,B,C})))
p03962
from collections import Counter a = list(input().split()) print((len(Counter(a))))
a = list(map(int, input().split())) print((len(set(a))))
p03962
import collections p = [int(x) for x in input().split()] c = collections.Counter(p) print((len(c)))
p = [int(x) for x in input().split()] print((len(set(p))))
p03962
a,b,c = list(map(int,input().split())) if a == b == c: print((1)) elif a == c or a == b or b == c: print((2)) else: print((3))
colors = list(map(int,input().split())) print((len(set(colors))))
p03962
s = list(map(int, input().split())) c = set(s) print((len(c)))
p = list(map(int, input().split())) print((len(set(p))))
p03962
a=list(map(int,input().split())) s=set(a) print((len(s)))
a=set(list(map(int,input().split()))) print((len(a)))
p03962
import collections pen = list(map(str,input().split())) print((len(collections.Counter(pen))))
a,b,c = list(map(int,input().split())) if a == b == c: print((1)) elif a == b or b == c or c ==a: print((2)) else: print((3))
p03962
print((len(set([x for x in input().split()]))))
print((len(set(input().split()))))
p03962
a,b,c=list(map(int, input().split())) if a==b and a==c: print((1)) elif a!=b and b!=c and c!=a: print((3)) else: print((2))
a,b,c=list(map(int, input().split())) d={} d[a]=1 d[b]=1 d[c]=1 print((len(d)))
p03962
a,b,c=list(map(int, input().split())) d={} d[a]=1 d[b]=1 d[c]=1 print((len(d)))
print((len(set(input().split()))))
p03962
m=998244353 M=1<<20 f=[0]*M g=[0]*M h=[0]*M f[0]=g[0]=f[1]=g[1]=h[1]=1 for i in range(2,M): f[i]=f[i-1]*i%m h[i]=m-h[m%i]*(m//i)%m g[i]=g[i-1]*h[i]%m A,B=list(map(int,input().split())) if A<B:A,B=B,A a=0 b=1 for j in range(1,B+1): a+=b*f[A+B-j]*g[B-j]*g[A] b=b*2%m print(((a*f[A]*f[B]*g[A+B]+A)%m))
m=998244353 M=1<<20 f=[1]*M g=[1]*M h=[1]*M h[0]=0 for i in range(2,M): f[i]=f[i-1]*i%m h[i]=m-h[m%i]*(m//i)%m g[i]=g[i-1]*h[i]%m A,B=list(map(int,input().split())) if A<B:A,B=B,A a=0 b=1 for j in range(1,B+1): a+=b*f[A+B-j]*g[B-j]*g[A] b=b*2%m print(((a*f[A]*f[B]*g[A+B]+A)%m))
p03622
M=8**7 m,f,g,i,a,b=M*476+1,[1],[1]*M,1,0,1 while i<M:f+=f[-1]*i%m,;i+=1 g[-1]=pow(f[-1],m-2,m) while i>1:i-=1;g[i-1]=g[i]*i%m A,B=list(map(int,input().split())) if A<B:A,B=B,A while i<=B:a+=b*f[A+B-i]*g[B-i];b=b*2%m;i+=1 print(((a*f[B]*g[A+B]+A)%m))
M=8**7 m,f,g,i=M*476+1,[j:=1],[k:=1]*M,1 while i<M:f+=f[-1]*i%m,;i+=1 g+=pow(M*f[-1],m-2,m), while i:g[i-1]=g[i]*i%m;i-=1 A,B=list(map(int,input().split())) if A<B:A,B=B,A while j<=B:i+=k*f[A+B-j]*g[B-j];k=k*2%m;j+=1 print(((i*f[B]*g[A+B]+A)%m))
p03622
while True: n = int(eval(input())) if n == 0: break z = sorted([tuple(map(int, input().split())) for _ in range(n)], key=lambda x: x[1]) cnt = total = 0 for a, b in z: total += a if total > b: break cnt += 1 print(("Yes" if cnt == n else "N...
while True: n = int(eval(input())) if n == 0: break z = sorted([tuple(map(int, input().split())) for _ in range(n)], key=lambda x: x[1]) cnt = total = 0 for a, b in z: total += a if total > b: cnt = 1 break print(("No" if cnt else "Yes"...
p00638
while 1: n = int(input()) if n == 0: break bridge = [0 for i in range(n)] gold = [0 for i in range(n)] for i in range(n): gold[i], bridge[i] = list(map(int,input().split(" "))) dp = {0:0} for i in range(n): tmp_dp = dict() for k,v in dp.items(): for j in range(n): bit = 1 << j if...
while 1: n = int(input()) if n == 0: break land = [list(map(int,input().split(" "))) for i in range(n)] land.sort(key = lambda x:(x[1],x[0])) gold = 0 for i in range(n): gold += land[i][0] if gold > land[i][1]: print("No") break else: print("Yes")
p00638
import sys C = sys.stdin.readlines() print((C[0][0]+C[1][1]+C[2][2]))
print((input()[0]+input()[1]+input()[2]))
p03415
l = [0] * 3 for i in range(3): l[i] = list(input()) for i in range(3): for j in range(3): if i == j: print(l[i][j], end='') print("")
for i in range(3): print(input()[i], end='') print()
p03415
a=input()[0] b=input()[1] c=input()[2] print((a+b+c))
a,b,c=[input()[i] for i in range(3)] print((a+b+c))
p03415
print((''.join(input()[i]for i in range(3))))
print((open(0).read()[::5]))
p03415
N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] if A[0] != 0: print((-1)) exit() ans = 0 tmp = 0 for num in reversed(A): if tmp > 0: if num == tmp-1: tmp = num elif num >= tmp: ans += num tmp = num elif num < tmp...
N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] #先頭は増やせないから0以外なら終わり if A[0] != 0: print((-1)) exit() ans = 0 prev = 0 for n in reversed(A): if prev != 0: # 後ろから見て1ずつ減少する場合 if n == prev - 1: prev = n # 前以上のとき、新たにその数字のために階段を構成する(前の数字を作る仮...
p03347
N = int(eval(input())) A = [int(eval(input())) for i in range(N)] if A[0] != 0: print((-1)) exit() for i in range(N - 1): if A[i] < A[i + 1] and A[i + 1] - A[i] != 1: print((-1)) exit() if A[i] > i + 1: print((-1)) exit() ans = 0 i = 1 old = 0 while i...
N = int(eval(input())) A = [int(eval(input())) for i in range(N)] if A[0] != 0: print((-1)) exit() for i in range(N - 1): if A[i] < A[i + 1] and A[i + 1] - A[i] != 1: print((-1)) exit() if A[i] > i + 1: print((-1)) exit() ans = 0 for i in range(1, N): ...
p03347
# AGC024C - Sequence Growing Easy def main(): N, *A = list(map(int, open(0))) A.append(0) if A[0]: # corner case print((-1)) return ans = 0 for i, j in zip(A[::-1], A[::-1][1:]): if i > j + 1: print((-1)) return if j >= i: ...
# AGC024C - Sequence Growing Easy def main(): N, *A = list(map(int, open(0))) if A[0]: # can't increment A_0 print((-1)) return A.append(0) ans, B = 0, A[::-1] for i, j in zip(B, B[1:]): # check from the last if i > j + 1: # increment from left one must be 0 or 1 ...
p03347
import heapq class Value: def __init__(self, val, f): self.val = val self.key = f(val) def __lt__(self, other): return self.key < other.key def __repr__(self): return repr(self.val) class Heapq: def __init__(self, arr, f=lambda x: x): for i ...
n = int(eval(input())) a = [int(eval(input())) for _ in range(n)] + [0] if a[0] > 0: print((-1)) else: ans = 0 for i in range(n): if a[i] < a[i + 1] - 1: print((-1)) break elif a[i] >= a[i + 1]: ans += a[i] else: print(ans)
p03347
N = int(eval(input())) A = [0]*N for i in range(N): A[i] = int(eval(input())) B = [0]*N possible = True tot = 0 for i in range(N): if A[-(i+1)] > N-i-1: possible = False break elif B[-(i+1)] > A[-(i+1)]: possible = False break elif B[-(i+1)] == A[-(i+1)]: ...
N = int(eval(input())) A = [0]*N for i in range(N): A[i] = int(eval(input())) B = [0]*N possible = True tot = 0 if A[0] == 0: for i in range(N-1): if A[-(i+1)] > N-i-1: possible = False break elif B[-(i+1)] > A[-(i+1)]: possible = False ...
p03347
n=int(eval(input())) l=[int(eval(input())) for _ in range(n)] ans=0 if l[0]!=0: print((-1)) exit() for i in range(n-1): if l[i+1]-l[i]>1: print((-1)) exit() elif (l[i]+1==l[i+1]): ans+=1 else: ans+=l[i+1] print(ans)
n=int(eval(input())) l=[int(eval(input())) for _ in range(n)] ans=0 if l[0]!=0: print((-1)) exit() for i in range(n-1): if (l[i]+1==l[i+1]): ans+=1 elif (l[i]>=l[i+1]): ans+=l[i+1] else: print((-1)) exit() print(ans)
p03347
#!/usr/bin/env python3 #AGC24 C import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(1000000000) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Cou...
#!/usr/bin/env python3 #AGC24 C import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(1000000000) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Cou...
p03347
N = int( eval(input())) A = [ int( eval(input())) for _ in range(N)] now = 0 ans = 0 if A[0] != 0: ans = -1 else: for i in range(1,N): if A[i] > i: ans = -1 break elif now + 1 == A[i]: ans += 1 now += 1 elif now >= A[i]: a...
N = int( eval(input())) A = [ int( eval(input())) for _ in range(N)] now = 0 ans = 0 if A[0] != 0: ans = -1 else: for i in range(1,N): a = A[i] if a > i: ans = -1 break elif now + 1 == a: ans += 1 now += 1 elif now >= a: ...
p03347
N = int( eval(input())) A = [ int( eval(input())) for _ in range(N)] now = 0 ans = 0 if A[0] != 0: ans = -1 else: for i in range(1,N): # if A[i] > i: # ans = -1 # break if now + 1 == A[i]: ans += 1 now += 1 elif now >= A[i]: ...
N = int( eval(input())) A = [ int( eval(input())) for _ in range(N)] now = 0 ans = 0 if A[0] != 0: ans = -1 else: for i in range(1,N): a = A[i] # if a > i: # ans = -1 # break #el if now + 1 == a: ans += 1 now += 1 elif...
p03347
n = int(eval(input())) a = [] for i in range(n): a.append(int(eval(input()))) flag = True for i in range(n - 1): if a[i + 1] - a[i] >= 2: flag = False if a[0] != 0: flag = False count = 0 start = 0 if flag == True: while a != [0] * n: for i in range(start, n - 1): ...
n = int(eval(input())) a = [] for i in range(n): a.append(int(eval(input()))) flag = True for i in range(n - 1): if a[i + 1] - a[i] >= 2: flag = False if a[0] != 0: flag = False count = 0 if flag == True: for i in range(n - 1): if a[i] != 0: count = count + ...
p03347
n = int(eval(input())) a = [int(eval(input())) for _ in range(n)] ans, tmp = 0, 0 for i in range(n - 1, 0, -1): if a[i] - a[i - 1] > 1: print((-1)) break if tmp != a[i]: ans += a[i] tmp = max(a[i] - 1, 0) else: print((ans if a[0] == 0 else - 1))
n = int(eval(input())) a = [int(eval(input())) for _ in range(n)] ans, tmp = 0, 0 for i in range(n - 1, 0, -1): if a[i] - a[i - 1] > 1: print((-1)) break if tmp != a[i]: ans += a[i] tmp = max(a[i] - 1, 0) else: print((-1 if a[0] > 0 else ans))
p03347
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemge...
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemge...
p03347
N = int(eval(input())) A = [[]] for _ in range(N): a = int(eval(input())) if len(A[-1]) > 0 and a < A[-1][-1]: A.append([]) A[-1].append(a) def isOk(): for l, r in zip(A, A[1:]): if l[-1] + 1 < r[0]: return False for grp in A: for l, r in zip(grp, ...
import sys input = sys.stdin.buffer.readline N = int(eval(input())) G = [[]] A = [] for _ in range(N): a = int(eval(input())) if len(G[-1]) > 0 and G[-1][-1] > a: G.append([]) A.append(a) G[-1].append(a) def isOk(): if any(l[-1] + 1 < r[0] for l, r in zip(G, G[1:])): ...
p03347
n = int(eval(input())) a = [int(eval(input())) for _i in range(n)] + [-1] result = -1 for i in range(n): if a[i-1] >= a[i]: result += a[i] elif a[i-1] + 1 == a[i]: result += 1 else: result = -1 break print(result)
n,r=int(eval(input())),-1 a = [int(eval(input())) for _i in range(n)]+[-1] for i in range(n): if a[i-1] >= a[i]:r+=a[i] elif a[i-1]+1==a[i]:r+=1 else:r=-1;break print(r)
p03347
n = int(eval(input())) A = [-1] for _ in range(n): A.append(int(eval(input()))) X = [0]*(n+1) count = 0 if A[1] != 0: print((-1)) else: for i in range(n,0,-1): if A[i] > X[i]: for j in range(A[i]): X[i-j] = A[i] - j count += A[i] elif A...
n = int(eval(input())) A = [-1] for _ in range(n): A.append(int(eval(input()))) num = 0 count = 0 if A[1] != 0: print((-1)) else: for i in range(n,0,-1): if A[i] > num: num = A[i] count += num elif A[i] < num: print((-1)) break...
p03347
n=int(eval(input())) a=[int(eval(input())) for _ in range(n)] #a(n+1)!=0の時、a(n+1)=a(n)+1である cnt=0 if a[0]!=0: print((-1)) exit() b=[0]*n #print(a) for ii in range(1,n): i=n-ii if a[i]==b[i]: continue elif a[i]<b[i] or a[i]>i: print((-1)) exit() els...
n=int(eval(input())) a=[int(eval(input())) for _ in range(n)] #a(n+1)!=0の時、a(n+1)=a(n)+1である cnt=0 if a[0]!=0: print((-1)) exit() #print(" ".join(list(map(str,a)))) for ii in range(1,n): i=n-ii if a[i]==0: continue elif a[i]<=a[i-1]: cnt+=a[i] elif a[i]==a[i-1]...
p03347
N = int(eval(input())) A = [int(eval(input())) for _ in range(N)][::-1] if A[-1] != 0: print((-1)) else: bef = A[0] c, ans = 0, 0 for i in A: if bef!=i: if bef-i > 1: print((-1)) break ans += bef*c c = 1 if bef<i ...
N = int(eval(input())) A = [int(eval(input())) for _ in range(N)][::-1] if A[-1]: print((-1)) else: bef = A[0] c, ans = 0, 0 for i in A: if bef!=i: if bef-i > 1: ans = -1 break ans += bef*c c = 1 if bef<i else 0 ...
p03347
n = int(eval(input())) a = [int(eval(input())) for _ in range(n)] ans = 0 if a[0] != 0: print((-1)) exit() for i in range(n-1): if a[i+1] - a[i] > 1: print((-1)) exit() for _ in range(n): if set(a) == set([-1,0]) or set(a) == set([0]): break i = a.index(max(a)) ...
n = int(eval(input())) prev = ans = -1 a = [int(eval(input())) for _ in range(n)] for i in a: if i - prev > 1: print((-1)) exit() elif i - prev == 1: ans += 1 else: ans += i prev = i print(ans)
p03347
N = int(eval(input())) A = [int(eval(input())) for i in range(N)] if A[0]: print((-1)) exit() ans = 0 for a,b in zip(A,A[1:]): if b-a > 1: print((-1)) exit() if b==0: continue if b-a == 1: ans += 1 else: ans += b print(ans)
N = int(eval(input())) A = [int(eval(input())) for i in range(N)] if A[0]: print((-1)) exit() ans = 0 for a,b in zip(A,A[1:]): if a+1 < b: print((-1)) exit() if a+1 == b: ans += 1 else: ans += b print(ans)
p03347
n = int(eval(input())) A = [int(eval(input()))for _ in range(n)] if A[0] != 0: print((-1)) exit() ans = A[-1] for a, prev_a in reversed(tuple(zip(A, A[1:]))): if a == prev_a-1: continue if a < prev_a-1: print((-1)) break ans += a else: print(ans)
n = int(eval(input())) ans = -1 prev = -1 for _ in range(n): a = int(eval(input())) if prev+1 == a: prev = a ans += 1 continue if prev+1 < a: print((-1)) break ans += a prev = a else: print(ans)
p03347
n = int(eval(input())) a = [] for i in range(n): a.append(int(eval(input()))) if a[0] > 0: print((-1)) exit() for i in range(1, n): if a[i] > i: print((-1)) exit() if a[i] > a[i-1] + 1: print((-1)) exit() result = 0 last = n b = [0 for i in ran...
n = int(eval(input())) a = [] for i in range(n): a.append(int(eval(input()))) if a[0] > 0: print((-1)) exit() for i in range(1, n): if a[i] > i: print((-1)) exit() if a[i] > a[i - 1] + 1: print((-1)) exit() if n == 1: print((0)) exit() ...
p03347
n, *a = list(map(int, open(0).read().split())) # hantei ok = True for i in range(n - 1): if a[i + 1] - a[i] > 1: ok = False if not ok or a[0] != 0: print((-1)) exit() ans = 0 a = list(reversed(a)) i = 0 while i < n: ans += a[i] while i < n - 1 and a[i] - 1 == a[i + 1]: ...
n, *a = list(map(int, open(0).read().split())) # 状態1: iとi+1が1違う # 状態2: iとi+1が同じ # これ以外のiとi+1の関係があったら構築できない # 状態1ではi+1を作る過程でiも作れる。 # 状態2ではi+1を作った後にiを作る必要がある。 # 後ろから見てa[i] - 1 == a[i - 1]となってる数を数えなければおk # check if a[0] != 0: print((-1)) exit() for i in range(n - 1): if a[i + 1] - a[i] > 1: print((-1...
p03347
N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] if A[0]: print((-1)) exit() ans = 0 dp = A[-1] for i in range(N - 1, 0, -1): if A[i - 1] == A[i] - 1: continue elif A[i - 1] >= A[i]: ans += dp dp = A[i - 1] else: print((-1)) exi...
N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] if A[0]: print((-1)) exit() ans = 0 dp = A[-1] for a, b in zip(A[-2::-1], A[-1::-1]): if a == b - 1: continue elif a >= b: ans += dp dp = a else: print((-1)) exit() print((ans + ...
p03347
N=int(eval(input())) A=[int(eval(input())) for _ in range(N)] ans=0 if A[0]!=0: print((-1)) exit() for i in range(N-1,0,-1): l,a=A[i-1],A[i] if a>l+1: print((-1)) exit() elif a==l+1: ans+=1 elif a!=0: ans+=a print(ans)
import sys def main(): input = sys.stdin.readline N=int(eval(input())) A=[int(eval(input())) for _ in range(N)] if A[0]!=0: print((-1)) exit() ans=0 d=0 for i in range(1,N): if A[i]==0: continue if A[i]>d+1: print((-1)) ...
p03347
import sys import math import collections import bisect import copy import itertools # import numpy as np sys.setrecursionlimit(10 ** 7) INF = 10 ** 16 MOD = 10 ** 9 + 7 # MOD = 998244353 ni = lambda: int(sys.stdin.readline()) ns = lambda: list(map(int, sys.stdin.readline().split())) na = lambda: lis...
import sys import math import collections import bisect import copy import itertools # import numpy as np sys.setrecursionlimit(10 ** 7) INF = 10 ** 16 MOD = 10 ** 9 + 7 # MOD = 998244353 ni = lambda: int(sys.stdin.readline()) ns = lambda: list(map(int, sys.stdin.readline().split())) na = lambda: lis...
p03347
n=int(eval(input())) A=[int(eval(input())) for _ in range(n)] if A[0]!=0:print((-1));exit() cnt=0 for i in range(1,n): if A[i-1]+1==A[i]: cnt +=1 elif A[i-1]==A[i]: cnt +=A[i] elif A[i-1]>A[i]: cnt +=A[i] else:print((-1));exit() print(cnt)
n=int(eval(input())) A=[int(eval(input())) for _ in range(n)] if A[0]!=0:print((-1));exit() cnt=0 for i in range(1,n): if A[i-1]+1==A[i]: cnt +=1 elif A[i-1]==A[i] or A[i-1]>A[i]: cnt +=A[i] else:print((-1));exit() print(cnt)
p03347
N, W, H = list(map(int, input().split())) row, col = [0] * (H + 1), [0] * (W + 1) for _ in range(N): x, y, w = list(map(int, input().split())) row[max(0, y - w)] += 1 row[min(H, y + w)] -= 1 col[max(0, x - w)] += 1 col[min(W, x + w)] -= 1 flag1 = flag2 = True for i in range(H): row[i +...
N, W, H = list(map(int, input().split())) row, col = [0] * (H + 1), [0] * (W + 1) for _ in range(N): x, y, w = list(map(int, input().split())) row[max(0, y - w)] += 1 row[min(H, y + w)] -= 1 col[max(0, x - w)] += 1 col[min(W, x + w)] -= 1 for i in range(H): row[i + 1] += row[i] if ...
p01712
N, W, H = [int(x) for x in input().split()] map_x = [False] * W count_x = 0 map_y = [False] * H count_y = 0 wifi_x = [] wifi_y = [] for _ in range(N): x, y, w = [int(x) for x in input().split()] wifi_x.append((x - w, x + w)) wifi_y.append((y - w, y + w)) wifi_x.sort(key=lambda a: a[1], revers...
N, W, H = [int(x) for x in input().split()] map_x = [0] * W map_y = [0] * H for _ in range(N): x, y, w = [int(x) for x in input().split()] map_x[max(0, x - w)] = max(map_x[max(0, x - w)], x + w - max(0, x - w)) map_y[max(0, y - w)] = max(map_y[max(0, y - w)], y + w - max(0, y - w)) def check_...
p01712
N, W, H = [int(x) for x in input().split()] map_x = [0] * W map_y = [0] * H for _ in range(N): x, y, w = [int(x) for x in input().split()] map_x[max(0, x - w)] = max(map_x[max(0, x - w)], x + w - max(0, x - w)) map_y[max(0, y - w)] = max(map_y[max(0, y - w)], y + w - max(0, y - w)) def check_...
N, W, H = [int(x) for x in input().split()] map_x = [0] * W map_y = [0] * H for _ in range(N): x, y, w = [int(x) for x in input().split()] map_x[max(0, x - w)] = max(map_x[max(0, x - w)], x + w - max(0, x - w)) map_y[max(0, y - w)] = max(map_y[max(0, y - w)], y + w - max(0, y - w)) def check_...
p01712
N, W, H = [int(x) for x in input().split()] map_x = [0] * W map_y = [0] * H for _ in range(N): x, y, w = [int(x) for x in input().split()] map_x[max(0, x - w)] = max(map_x[max(0, x - w)], x + w - max(0, x - w)) map_y[max(0, y - w)] = max(map_y[max(0, y - w)], y + w - max(0, y - w)) def check_...
N, W, H = [int(x) for x in input().split()] map_x = [0] * W map_y = [0] * H for _ in range(N): x, y, w = [int(x) for x in input().split()] mx = max(0, x - w) map_x[mx] = max(map_x[mx], x + w - mx) my = max(0, y - w) map_y[my] = max(map_y[my], y + w - my) def check_wifi(wifi): m...
p01712
a = [list(map(int, input().split())) for _ in range(3)] n = int(eval(input())) for _ in range(n): b = int(eval(input())) for i in range(9): if b == a[i // 3][i % 3]: a[i // 3][i % 3] = 0 flag = False if a[0][0] == a[0][1] == a[0][2] == 0: flag = True if a[1][0] == a[1][1] == a[...
a = [list(map(int, input().split())) for _ in range(3)] n = int(eval(input())) for _ in range(n): b = int(eval(input())) for i in range(9): if b == a[i // 3][i % 3]: a[i // 3][i % 3] = 0 flag = True if a[0][0] == a[0][1] == a[0][2] == 0: flag = False if a[1][0] == a[1][1] == a[...
p02760
A = [list(map(int,input().split())) for _ in range(3)] N = int(eval(input())) B = [int(eval(input())) for _ in range(N)] for b in B: for i in range(3): for j in range(3): if A[i][j] == b: A[i][j] = -100 f = False for i in range(3): s = 0 for j in range(3): s += A[i][j] if ...
A = [list(map(int,input().split())) for _ in range(3)] N = int(eval(input())) B = [int(eval(input())) for _ in range(N)] for b in B: for i in range(3): for j in range(3): if A[i][j] == b: A[i][j] = 0 f = False for i in range(3): s = 0 for j in range(3): s += A[i][j] if s == ...
p02760