input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
from collections import Counter N = int(eval(input())) A = Counter(list(map(int,input().split()))).most_common() S = 0 for i,c in A: if i == c: continue elif i > c: S += c else: S += c-i print(S)
N = int(eval(input())) A = list(map(int,input().split())) from collections import Counter C = Counter(A).most_common() ans = 0 for (k,v) in C: if v<k: ans += v elif v>k: ans += v-k print(ans)
p03487
n = int(eval(input())) a = list(map(int, input().split())) b = list(set(a)) ans = 0 for i in range(len(b)): if a.count(b[i]) > b[i]: ans += a.count(b[i]) - b[i] elif a.count(b[i]) < b[i]: ans += a.count(b[i]) print(ans)
n = int(eval(input())) a = list(map(int, input().split())) n = len(a) a.sort() a.append(-1) ans = 0 i = 0 while i < n: cnt = 1 while a[i] == a[i+1]: cnt += 1 i += 1 if i == len(a)-1: break if cnt > a[i]: ans += cnt - a[i] elif cnt < a[i]: ans += cnt i += 1 print(ans)
p03487
from collections import Counter n = int(eval(input())) A = [int(i) for i in input().split()] D = Counter(A) res = 0 for i in list(D.items()): if i[0] < i[1]: res += i[1]-i[0] elif i[0] > i[1]: res += i[1] print(res)
from collections import Counter n = int(eval(input())) A = list(map(int,input().split())) D = Counter(A) res = 0 for i,v in list(D.items()): if i > v: res += v elif i < v: res += v-i print(res)
p03487
n=int(eval(input())) a = list(map(int,input().split())) a.sort() c = 0 d = 0 #i while d <= n-1: s = a.count(a[d]) if a[d] > s: c += s else: c += s-a[d] d = d + s print(c)
import bisect n=int(eval(input())) a = list(map(int,input().split())) a.sort() c = 0 d = 0 #i while d <= n-1: s2 = bisect.bisect_right(a,a[d]) s = s2-d if a[d] > s: c += s else: c += s-a[d] d = d + s print(c)
p03487
import collections N=int(eval(input())) a=list(map(int,input().split())) a_counter=collections.Counter(a) answer = 0 # print(a_counter) # print(a_counter[0]) # print(a_counter[1]) # print(a_counter[2]) # print(a_counter[3]) for i in a_counter: # print(i) # print(i == a_counter[i]) if i != a_counter[i]: if i < a_counter[i]: answer += a_counter[i] - i else: answer += a_counter[i] print(answer)
import collections N = int(eval(input())) a = list(map(int, input().split())) a_count = collections.Counter(a) # print(a_count) ans = 0 for i, j in list(a_count.items()): # print(i, j) if i <= j: ans += j - i else: ans += j print(ans)
p03487
N = int(eval(input())) a = list(map(int, input().split())) list_a = list(set(a)) result = 0 for i in list_a: cnt = a.count(i) if cnt != i: result = result + cnt if cnt < i else result + cnt - i print(result)
N = int(eval(input())) a = list(map(int, input().split())) count_a = {} for n in range(N): if a[n] in list(count_a.keys()): count_a[a[n]] += 1 else: count_a[a[n]] = 1 result = 0 for n in list(count_a.keys()): if count_a[n] != n: result = result + count_a[n] if count_a[n] < n else result + count_a[n] - n print(result)
p03487
N=int(eval(input())) L=list(map(int,input().split())) S=set(L) ans=0 for s in S: tmp=L.count(s) if tmp>s: ans+=tmp-s elif tmp<s: ans+=tmp print(ans)
N=int(eval(input())) L=list(map(int,input().split())) S=set(L) ans=0 dict={} for s in S: dict[s]=0 for l in L: dict[l]+=1 for d in list(dict.items()): num=d[0] amount=d[1] if amount>num: ans+=amount-num elif amount<num: ans+=amount print(ans)
p03487
n = int(eval(input())) a = list(map(int, input().split())) b = list(set(a)) ans = 0 for i in b: c = a.count(i) if c < i: ans += c if c > i: ans += c - i print(ans)
n = int(eval(input())) a = list(map(int, input().split())) d = {} for i in range(n): if a[i] in d: d[a[i]] += 1 else: d[a[i]] = 1 ans = 0 for i in d: if d[i] < i: ans += d[i] if d[i] > i: ans += d[i] - i print(ans)
p03487
n = int(eval(input())) aList = list(map(int, input().split())) aSet = list(set(aList)) aSum = 0 for a in aSet: aCount = aList.count(a) if aCount > a: aSum += aCount - a continue if aCount == a: continue if aCount < a: aSum += aCount continue print(aSum)
n = int(eval(input())) aList = list(map(int, input().split())) aLen = len(aList) aSet = sorted(list(set(aList))) aSum = 0 for a in aSet: aCount = aList.count(a) if aCount > a: aSum += aCount - a if aCount < a: aSum += aCount aLen -= aCount if a > aLen: aSum += aLen break print(aSum)
p03487
import collections N=int(eval(input())) List=sorted(list(map(int, input().split()))) c = collections.Counter(List) #要素と出現回数の辞書 value, count = list(zip(*c.most_common())) newList=[] for i in range(len(value)): if N-len(newList)>=value[i] and count[i]>=value[i]: for j in range(value[i]): newList.append(value[i]) else: continue #print(newList) Ans=len(List)-len(newList) print(Ans)
import collections N = int(eval(input())) A = list(map(int, input().split())) c = collections.Counter(A) #要素と出現回数の辞書 #print(c) ans = 0 for k,v in list(c.items()): ans += v if v<k else v-k print(ans)
p03487
N=int(eval(input())) a=list(map(int,input().split())) ans=0 aa=list(set(a)) for i in aa: cnt=a.count(i) if cnt>i: ans+=cnt-i elif cnt<i: ans+=cnt print((str(ans)))
N=int(eval(input())) a=list(map(int,input().split())) ans=0 aa=list(set(a)) dict={} for s in aa: dict[s]=0 for l in a: dict[l]+=1 for i in list(dict.items()): num=i[0] amount=i[1] """ cnt=a.count(i) if cnt>i: ans+=cnt-i elif cnt<i: ans+=cnt """ if amount>num: ans+=amount-num elif amount<num: ans+=amount print((str(ans)))
p03487
#!usr/bin/env python3 from collections import defaultdict from heapq import heappush, heappop import sys import math import bisect def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return list(sys.stdin.readline()) def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] mod = 1000000007 #A """ a, b = LI() print((a+b+1)//2) """ #B """ a = S() a = a[:-1] b = S() b = b[:-1] a.sort() b.sort(reverse=True) if a < b: print("Yes") else: print("No") """ #C n = I() a = LI() seta = set(a) ans = 0 for i in seta: x = a.count(i) if x != 0 and x >= i: ans += x - i else: ans += x print(ans)
#!usr/bin/env python3 from collections import defaultdict from heapq import heappush, heappop import sys import math import bisect def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return list(sys.stdin.readline()) def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] mod = 1000000007 #A """ a, b = LI() print((a+b+1)//2) """ #B """ a = S() a = a[:-1] b = S() b = b[:-1] a.sort() b.sort(reverse=True) if a < b: print("Yes") else: print("No") """ #C n = I() a = LI() a.sort() seta = set(a) ans = 0 for i in seta: x = bisect.bisect_right(a,i) - bisect.bisect_left(a,i) if x != 0 and x >= i: ans += x - i else: ans += x print(ans)
p03487
n = int(eval(input())) l = list(map(int, input().split())) dic = {} count = 0 for i in range(n): dic.setdefault(l[i],0) dic[l[i]] += 1 for x,y in list(dic.items()): if x <= y: count += y - x else: count += y print(count)
n = int(eval(input())) l = list(map(int,input().split())) d = {} ans = 0 for i in l: if i not in d: d[i] = 1 else: d[i] += 1 for k,v in list(d.items()): if k != v: if k < v: ans += v - k else: ans += v print(ans)
p03487
from itertools import groupby n, s = eval(input()), sorted(map(int, input().split())) v, ans = [(i, len(list(t))) for i, t in groupby(s)], 0 for i, t in v: if i == t: continue ans += ((t - i) if i < t else t) print(ans)
from itertools import groupby n, s = eval(input()), sorted(map(int, input().split())) v, ans = [(i, len(list(t))) for i, t in groupby(s)], 0 for i, t in v: if i != t: ans += ((t - i) if i < t else t) print(ans)
p03487
n = int(eval(input())) a = [int(_) for _ in input().split()] res = 0 for i in set(a): tmp = a.count(i) if tmp < i: res += tmp else: res += tmp - i print(res)
import bisect n = int(eval(input())) a = [int(_) for _ in input().split()] a.sort() res = 0 for i in set(a): tmp = bisect.bisect_right(a,i)-bisect.bisect_left(a,i) if tmp < i: res += tmp else: res += tmp - i print(res)
p03487
from collections import Counter N=int(eval(input())) A=list(map(int,input().split())) d=Counter(A) ans=0 for i in d: if d[i]>=i: ans+=d[i]-i else: ans+=d[i] print(ans)
from collections import Counter n=int(eval(input())) a=Counter(input().split()) ans=0 for i,j in list(a.items()): i=int(i) if i>j: ans+=j elif i<j: ans+=j-i print(ans)
p03487
n=int(eval(input())) a=list(map(int,input().split())) ctr=0 el=[] for i in range(n): if a[i] not in el: num=a.count(a[i]) el.append(a[i]) if a[i]>num: ctr+=num else: ctr+=num-a[i] print(ctr)
n=int(eval(input())) a=list(map(int,input().split())) a.sort() ctr=1 ln=[] for i in range(n-1): if a[i]==a[i+1]: ctr+=1 elif a[i]!=a[i+1]: ln.append([a[i],ctr]) ctr=1 ln.append([a[n-1],ctr]) ans=0 for k in range(len(ln)): if ln[k][0]>ln[k][1]: ans+=ln[k][1] else: ans+=ln[k][1]-ln[k][0] print(ans)
p03487
import collections ans = 0 N = int(eval(input())) a = [int(i) for i in input().split()] dic = collections.Counter(a).most_common() for a, b in dic: if a <= b: ans += b-a else: ans += b print(ans)
import collections N = int(eval(input())) a = [int(i) for i in input().split()] ans = 0 num = collections.Counter(a).most_common() for a, b in num: if b < a: ans += b elif a < b: ans += b-a print(ans)
p03487
from collections import Counter N = int(eval(input())) A = Counter(list(map(int, input().split()))) ans = 0 for x, y in list(A.items()): if y >= x: ans += y - x else: ans += y print(ans)
from collections import Counter n = int(eval(input())) A = Counter(list(map(int, input().split()))) ans = 0 for k, v in list(A.items()): if k > v: ans += v elif k < v: ans += v - k print(ans)
p03487
n = int(eval(input())) a = list(map(int, input().split())) d = {} for ai in a: if not ai in d: d[ai] = a.count(ai) cnt = 0 for key, value in list(d.items()): if key > value: cnt = cnt + value elif key < value: cnt = cnt + value - key print(cnt)
n = int(eval(input())) a = list(map(int, input().split())) d = {} for ai in a: if ai in d: d[ai] = d[ai] + 1 else: d[ai] = 1 cnt = 0 for key, value in list(d.items()): if key > value: cnt = cnt + value elif key < value: cnt = cnt + value - key print(cnt)
p03487
n = int(eval(input())) a = list(map(int, input().split())) for i in set(a): if i <= a.count(i): n -= i print(n)
n = int(eval(input())) a = list(map(int, input().split())) d = {} for i in a: if i in d: d[i] += 1 else: d[i] = 1 for k,v in list(d.items()): if k <= v: n -= k print(n)
p03487
N=int(eval(input())) a=list(map(int,input().split())) s=set(a) count=0 for i in s: if a.count(i)-i<0: count+=a.count(i) else: count+=a.count(i)-i print(count)
N=int(eval(input())) a=list(map(int,input().split())) a=sorted(a) s=set(a) count=0 base=0 judge=0 for i in a: if base!=i: #print(judge,base) if judge>=base: count+=judge-base else: count+=judge base=i judge=1 else: judge+=1 if judge>=base: count+=judge-base else: count+=judge print(count)
p03487
import collections N = int(eval(input())) a = list(map(int,input().split())) a.sort() array = list(set(a)) sum = 0 for i in range(len(array)): if a.count(array[i]) >= array[i]: sum += a.count(array[i]) - array[i] else: sum += a.count(array[i]) print(sum)
N = int(eval(input())) a = list(map(int,input().split())) A = a.sort() array = list(set(a)) array.sort() sum = 0 n = 0 for i in range(len(array)): cnt = 0 for j in range(n,len(a)): if array[i] == a[j]: cnt += 1 else: break n += cnt if cnt >= array[i]: sum += cnt - array[i] else: sum += cnt print(sum)
p03487
N = int(eval(input())) a = sorted([int(x) for x in input().split()]) i,ans = 0,0 while i < N: c = a.count(a[i]) if c > a[i]: ans += c-a[i] elif c < a[i]: ans += c i += c print(ans)
N = int(eval(input())) a = sorted([int(x) for x in input().split()]) i,ans = 0,0 while i < N: if a[i] > N: ans += N-i break c = a.count(a[i]) if c > a[i]: ans += c-a[i] elif c < a[i]: ans += c i += c print(ans)
p03487
N=int(eval(input())) st=input().split() a=[0 for i in range(N)] M=set([]) for i in range(N): a[i]=int(st[i]) M.add(a[i]) Numlist=list(M) b=[0 for i in range(len(M))] def search(num): for k in range(len(M)): if Numlist[k]==num: return k return -1 for i in range(N): b[search(a[i])]+=1 count=0 for i in range(len(M)): if Numlist[i]<=b[i]: count+=b[i]-Numlist[i] else: count+=b[i] print(count)
N=int(eval(input())) a=[0 for i in range(N)] st=input().split() for i in range(N): a[i]=int(st[i]) aa=sorted(a) count=0 nowp=aa[0] aa.append(10**9+1) nowcount=1 for i in range(1,N+1): if aa[i-1]==aa[i]: nowcount+=1 else: nowp=aa[i] if nowcount<aa[i-1]: count+=nowcount else: count+=nowcount-aa[i-1] nowcount=1 print(count)
p03487
N=int(eval(input())) a=[0 for i in range(N)] st=input().split() for i in range(N): a[i]=int(st[i]) aa=sorted(a) count=0 nowp=aa[0] aa.append(10**9+1) nowcount=1 for i in range(1,N+1): if aa[i-1]==aa[i]: nowcount+=1 else: nowp=aa[i] if nowcount<aa[i-1]: count+=nowcount else: count+=nowcount-aa[i-1] nowcount=1 print(count)
N=int(eval(input())) a=[int(i) for i in input().split()] D=dict() for i in range(N): if a[i] in D: D[a[i]]+=1 else: D[a[i]]=1 ans=0 for num in D: if num<=D[num]: ans+=D[num]-num else: ans+=D[num] print(ans)
p03487
n=int(eval(input())) a=list(map(int,input().split())) a.sort() amax=a[-1] amin=a[0] dn=0 for i in range(amin,amax+1): ni=a.count(i) if ni>i: dn=dn+(ni-i) elif ni<i: dn=dn+ni print(dn)
n=int(eval(input())) a=list(map(int,input().split())) a.sort() amax=a[-1] amin=a[0] s=[] ai=a[0] acnt=-1 for i in range(n): if a[i]>ai: s.append([ai,acnt+1]) acnt=0 ai=a[i] else: acnt=acnt+1 s.append([ai,acnt+1]) # print(s) dn=0 for i in range(len(s)): ni=s[i][1] if ni>s[i][0]: dn=dn+(ni-s[i][0]) elif ni<s[i][0]: dn=dn+ni print(dn)
p03487
n=int(eval(input())) a=list(map(int,input().split())) a.sort() amax=a[-1] amin=a[0] s=[] ai=a[0] acnt=-1 for i in range(n): if a[i]>ai: s.append([ai,acnt+1]) acnt=0 ai=a[i] else: acnt=acnt+1 s.append([ai,acnt+1]) # print(s) dn=0 for i in range(len(s)): ni=s[i][1] if ni>s[i][0]: dn=dn+(ni-s[i][0]) elif ni<s[i][0]: dn=dn+ni print(dn)
n=int(eval(input())) a=list(map(int,input().split())) d=dict() for i in range(n): if a[i] in d: d[a[i]]=d[a[i]]+1 else: d[a[i]]=1 xsum=0 for x in list(d.keys()): if d[x]<x: xsum=xsum+d[x] elif d[x]>x: xsum=xsum+d[x]-x print(xsum)
p03487
n=int(eval(input())) a=list(map(int,input().split())) b=set() ans=0 for i in a: if i not in b: b.add(i) x=a.count(i) if x>=i: ans+=x-i else: ans+=x print(ans)
n=int(eval(input())) a=sorted(list(map(int,input().split()))) b=set() ans=0 d={} cnt=0 for i in range(n): if i!=0 and a[i]!=a[i-1]: d[a[i-1]]=cnt cnt=0 cnt+=1 if i==n-1: x=a.count(a[i]) d[a[i]]=x for i in list(d.keys()): if d[i]>=i: ans+=d[i]-i else: ans+=d[i] print(ans)
p03487
#!usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS():return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l = [None for i in range(n)] for i in range(n):l[i] = I() return l def LIR(n): l = [None for i in range(n)] for i in range(n):l[i] = LI() return l def SR(n): l = [None for i in range(n)] for i in range(n):l[i] = S() return l def LSR(n): l = [None for i in range(n)] for i in range(n):l[i] = SR() return l mod = 1000000007 #A def A(): a,b = LI() print((math.ceil((a+b)/2))) #B def B(): s = S() t = S() s.sort() t.sort() t = t[::-1] l = [s,t] l.sort() if s == t: print("No") elif l[0] == s: print("Yes") else: print("No") #C def C(): n = I() d = defaultdict(int) a = LI() for i in a: d[i] += 1 ans = 0 for i in list(d.keys()): if i <= d[i]: ans += d[i]-i else: ans += d[i] print(ans) #D def D(): return #E def E(): return #F def F(): return #G def G(): return #H def H(): return #Solve if __name__ == "__main__": C()
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()] def I(): return int(sys.stdin.buffer.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): n = I() a = LI() d = defaultdict(lambda : 0) for i in a: d[i] += 1 ans = 0 for i in set(a): if d[i] < i: ans += d[i] else: ans += d[i]-i print(ans) return #Solve if __name__ == "__main__": solve()
p03487
from collections import Counter N = int(eval(input())) a = list(map(int, input().split())) c = Counter(a) ans = 0 for key in c: if c[key] >= key: ans += (c[key] - key) else: ans += c[key] print(ans)
N = int(eval(input())) a = list(map(int, input().split())) d = {} for ai in a: if ai in d: d[ai] += 1 else: d[ai] = 1 ans = 0 for key in d: if d[key] >= key: ans += (d[key] - key) else: ans += d[key] print(ans)
p03487
import sys stdin = sys.stdin ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) ns = lambda: stdin.readline().strip() n = ni() a = na() a_lis = list(set(a)) count = 0 ans = [0]*len(a_lis) for i in range(len(a_lis)): count = a.count(a_lis[i]) if count > a_lis[i]: ans[i] = count - a_lis[i] elif count < a_lis[i]: ans[i] = count if sum(ans) < n: print((sum(ans))) else: print(n)
import sys stdin = sys.stdin ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) ns = lambda: stdin.readline().strip() n = ni() a = na() dic = {} for num in a: if num in dic: dic[num] += 1 else: dic[num] = 1 ans = 0 for key,value in list(dic.items()): if key > value: ans += value else: ans += (value - key) print(ans)
p03487
n = int(eval(input())) a = tuple(map(int, input().split(" "))) sum_num = 0 for a_i in set(a): a_count_a_i = a.count(a_i) sum_num += a_count_a_i - a_i if a_i <= a_count_a_i else a_count_a_i print(sum_num)
n = int(eval(input())) a = tuple(map(int, input().split(" "))) a_count = dict() for a_i in a: if a_i not in a_count: a_count[a_i] = 0 a_count[a_i] += 1 sum_num = 0 for a_i in a_count: a_count_a_i = a_count[a_i] sum_num += a_count_a_i - a_i if a_i <= a_count_a_i else a_count_a_i print(sum_num)
p03487
from collections import Counter N = int(eval(input())) A = [int(i) for i in input().split()] ans = 0 for k, v in list(Counter(A).items()): if k > v: ans += v else: ans += v - k print(ans)
from collections import * eval(input()) print((sum(v if k>v else v-k for k,v in list(Counter(list(map(int,input().split()))).items()))))
p03487
from collections import defaultdict N = int(eval(input())) A = [int(i) for i in input().split()] D = defaultdict(int) for i in range(N): D[A[i]] += 1 delete = 0 for d in D: if d < D[d]: delete += D[d] - d elif d > D[d]: delete += D[d] print(delete)
import sys def solve(): input = sys.stdin.readline N = int(eval(input())) A = [int(a) for a in input().split()] AD = dict() for a in A: if a in AD: AD[a] += 1 else: AD[a] = 1 count = 0 for key in AD: if AD[key] == key: continue elif AD[key] > key: count += AD[key] - key else: count += AD[key] print(count) return 0 if __name__ == "__main__": solve()
p03487
n = int(eval(input())) a = list(map(int, input().split())) s = set(a) ans = 0 for i in s: c = a.count(i) if c < i: ans += c elif c >= i: ans += c - i print(ans)
n = int(eval(input())) a = list(map(int, input().split())) s = set(a) d = {} for i in s: d[i] = 0 for i in a: d[i] += 1 ans = 0 for i in d: c = d[i] if c < i: ans += c elif c >= i: ans += c - i print(ans)
p03487
N = int(eval(input())) a = list(map(int,input().split())) a.sort() b = list(set(a)) cnt = 0 for i in range(len(b)): c = a.count(b[i]) if b[i] <= c: cnt += c - b[i] else: cnt += c print(cnt)
N = int(eval(input())) a = list(map(int,input().split())) a.sort(reverse = True) b = list(set(a)) ans = 0 for i in range(len(b)): cnt = 1 while len(a) > 1 and a[-1] == a[-2]: a.pop() cnt += 1 c = a.pop() if c <= cnt: ans += cnt - c else: ans += cnt print(ans)
p03487
N = int(eval(input())) A = list(map(int, input().split())) A.sort() ans = 0 b = 0 for i in range(N): if i == b: a = A.count(A[i]) b = i + a if A[i] > a: ans += a elif A[i] < a: ans += a - A[i] print(ans)
N = int(eval(input())) A = list(map(int, input().split())) A.sort() old = A[0] a = 1 ans = 0 for i in range(1, N): cur = A[i] if cur == old: a += 1 else: if old <= a: ans += a - old else: ans += a a = 1 old = cur if old <= a: ans += a - old else: ans += a print(ans)
p03487
import sys import os import math import bisect import collections import itertools ii = lambda: int(sys.stdin.buffer.readline().rstrip()) il = lambda: list(map(int, sys.stdin.buffer.readline().split())) fl = lambda: list(map(float, sys.stdin.buffer.readline().split())) iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] iss = lambda: sys.stdin.buffer.readline().decode().rstrip() sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] lcm = lambda x, y: x * y / math.gcd(x, y) MOD = 10 ** 9 + 7 MAX = float('inf') def main(): if os.getenv("LOCAL"): sys.stdin = open("input.txt", "r") X = ii() A = collections.Counter(il()) ret = 0 for k, v in list(A.items()): if k > v: ret += v if k < v: ret += abs(k-v) print(ret) if __name__ == '__main__': main()
import sys import os import math import bisect import collections import itertools import heapq ii = lambda: int(sys.stdin.buffer.readline().rstrip()) il = lambda: list(map(int, sys.stdin.buffer.readline().split())) fl = lambda: list(map(float, sys.stdin.buffer.readline().split())) iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] iss = lambda: sys.stdin.buffer.readline().decode().rstrip() sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] lcm = lambda x, y: x * y / math.gcd(x, y) MOD = 10 ** 9 + 7 MAX = float('inf') def main(): if os.getenv("LOCAL"): sys.stdin = open("input.txt", "r") N = ii() A = collections.Counter(il()) ret = 0 for k in A: v = A[k] if k <= v: ret += abs(k-v) else: ret += v print(ret) if __name__ == '__main__': main()
p03487
import sys import collections input=sys.stdin.readline n=int(eval(input())) l=list(map(int,input().split())) li=collections.Counter(l) #print(li) a=0 for k,v in list(li.items()): if k>v: a+=v else: a+=v-k print(a)
import sys import collections input=sys.stdin.readline n=int(eval(input())) l=list(map(int,input().split())) s=collections.Counter(l) #print(s) a=0 for k,v in list(s.items()): if k>v: a+=v else: a+=v-k print(a)
p03487
import collections N=int(eval(input())) A=list(map(int,input().split())) C=collections.Counter(A) ans=0 for i,j in list(C.items()): if i!=j: a=j-i if j>=i else j ans+=a print(ans)
import collections N=int(eval(input())) A=list(map(int,input().split())) C=collections.Counter(A) ans=0 for i,j in list(C.items()): a=j-i if j>=i else j ans+=a print(ans)
p03487
# -*- coding: utf-8 -*- #https://atcoder.jp/contests/abc082/tasks/abc082_c length = int(eval(input())) a = [int(i) for i in input().split()] count = 0 for i in range(length): if(i+1 <= a.count(i+1)): count += i+1 print((length - count))
# -*- coding: utf-8 -*- #https://atcoder.jp/contests/abc082/tasks/abc082_c length = int(eval(input())) a = [int(i) for i in input().split()] set_a = set(a) count = 0 for i in set(a): if (i > length): continue if(i <= a.count(i)): count += i print((length - count))
p03487
# coding: utf-8 # Your code here! import collections N=int(eval(input())) A=list(map(int,input().split())) c = collections.Counter(A) ans=0 n=len(set(A)) for i in range(n): a=int(c.most_common()[i][0]) b=c.most_common()[i][1] if a <= b: ans+=b-a else: ans+=b print(ans)
import collections N=int(eval(input())) A=list(map(int,input().split())) c = collections.Counter(A) ans=0 n=len(set(A)) c_=c.most_common() for i in range(n): a=int(c_[i][0]) b=c_[i][1] if a <= b: ans+=b-a else: ans+=b print(ans)
p03487
import collections N=int(eval(input())) A=list(map(int,input().split())) c = collections.Counter(A) ans=0 n=len(set(A)) c_=c.most_common() for i in range(n): a=int(c_[i][0]) b=c_[i][1] if a <= b: ans+=b-a else: ans+=b print(ans)
# coding: utf-8 import collections N = int(eval(input())) A= list(map(int,input().split())) A.sort() c = collections.Counter(A) A_ = list(set(A)) ans = 0 for a in A_: #print(c[a],a) if a > c[a]: ans += c[a] else: ans += c[a]-a print(ans)
p03487
import collections N = int(eval(input())) A = list(map(int, input().split())) c = collections.Counter(A) ans = 0 for i in set(A): if i > c[i]: ans += c[i] if i < c[i]: ans += (c[i] -i) print(ans)
from collections import Counter N = int(eval(input())) a = list(map(int, input().split())) c = Counter(a) ans = 0 for k, v in list(c.items()): if k > v: ans += v else: ans += (v-k) print(ans)
p03487
#coding:utf-8 from collections import Counter n = int(eval(input())) A = list(map(int,input().split())) c = Counter(A) ans = 0 for i in list(c.items()): if i[1]>=i[0]: ans += i[1]-i[0] else: ans += i[1] print (ans)
#coding:utf-8 from collections import Counter N = int(eval(input())) A = list(map(int, input().split())) c = Counter(A) ans = 0 for it in list(c.items()): if it[0] <= it[1]: ans += (it[1]-it[0]) else: ans += it[1] print (ans)
p03487
from collections import Counter n=int(eval(input())) nums=input().split() counter=Counter(nums).most_common() k=0 for num, c in counter: num=int(num) if num==c: continue elif num>c: for v in range(c): nums.remove(str(num)) k+=1 else: for v in range(c-num): nums.remove(str(num)) k+=1 print(k)
from collections import Counter n=int(eval(input())) counter=Counter(list(map(int,input().split()))) print((sum(c-num if c>=num else c for num,c in list(counter.items()))))
p03487
n=int(eval(input())) a=list(map(int,input().split())) b=set(a) ans=0 for i in b: if a.count(i)-i>=0: ans+=a.count(i)-i else: ans+=a.count(i) print(ans)
n=int(eval(input())) a=list(map(int,input().split())) count = {} ans = 0 for i in a: if i not in count: count[i] = 1 else: count[i] += 1 for i,c in list(count.items()): if i > c: ans += c elif i < c: ans += c - i print(ans)
p03487
N = int(eval(input())) #put a_i into list list_a_i = list(sorted(map(int, input().split()))) remove = 0 while len(list_a_i) >=1: #count number of list_a_i[1] x = list_a_i.count(list_a_i[0]) if x > list_a_i[0]: remove += x - list_a_i[0] elif x < list_a_i[0]: remove += x for i in range(x): list_a_i.remove(int(list_a_i[0])) print(remove)
N = int(eval(input())) a = list(map(int, input().split())) dic = {} for elem in a: if elem not in dic: dic[elem] = 1 else: dic[elem] += 1 ans = 0 for k in list(dic.keys()): if dic[k] > k: ans += dic[k] - k elif dic[k] < k: ans += dic[k] print(ans)
p03487
from collections import Counter n = int(eval(input())) a = Counter(list(map(int, input().split()))) cnt = 0 for i in range(len(a)): k,v=a.most_common()[i][0],a.most_common()[i][1] if v-k < 0: cnt += v else: cnt += v-k print(cnt)
from collections import Counter n = int(eval(input())) a = Counter(list(map(int, input().split()))) cnt = 0 for k, v in list(Counter(a).items()): if k > v: cnt += v else: cnt += (v-k) print(cnt)
p03487
n = int(eval(input())) A = list(map(int, input().split())) c = 0 for i in set(A): if A.count(i) >= i: c += A.count(i)-i else: c += A.count(i) print(c)
import bisect n = int(eval(input())) A = sorted(list(map(int, input().split()))) c = 0 temp = 0 for i in sorted(list(set(A))): d = bisect.bisect_right(A, i) if d-temp >= i: c += d-temp - i else: c += d-temp temp = d print(c)
p03487
N = int(eval(input())) A = list(map(int,input().split())) B = (10**5+1)*[0] ans = 0 for a in A: if a<=10**5: B[a]+=1 else: ans+=1 for n in range(10**5): if B[n]<n: ans+=B[n] elif n<B[n]: ans+=B[n]-n print(ans)
from collections import * N = int(eval(input())) C = Counter(list(map(int,input().split()))) ans = 0 for k,v in list(C.items()): if k<v: ans+=v-k elif v<k: ans+=v print(ans)
p03487
from collections import Counter N = int(eval(input())) src = list(map(int,input().split())) ctr = Counter(src) ans = 0 for k,v in list(ctr.items()): if k < v: ans += v-k elif k > v: ans += v print(ans)
from collections import Counter N = int(eval(input())) src = list(map(int,input().split())) ctr = Counter(src) ans = 0 for k,v in list(ctr.items()): ans += v if v<k else v-k print(ans)
p03487
n = int(eval(input())) a = list(map(int, input().split())) aset = set(a) ans = 0 for i in aset: if a.count(i) < i: ans += a.count(i) else: ans += a.count(i) - i print(ans)
n = int(eval(input())) a = list(map(int, input().split())) d = dict() for i in a: d[i] = d.get(i, 0) + 1 ans = 0 for i in list(d.items()): if i[0] > i[1]: ans += i[1] elif i[0] < i[1]: ans += i[1] - i[0] print(ans)
p03487
N = int(eval(input())) S = list(int(i) for i in input().split()) list = [] count = 0 for i in range(N): if S[i] not in list: num = S[i:].count(S[i]) if num < S[i]: count += num elif num > S[i]: count += (num-S[i]) list.append(S[i]) print(count)
N = int(eval(input())) S = list(int(i) for i in input().split()) dict = {} count = 0 for i in range(N): if S[i] not in dict: dict[S[i]] = 1 else: dict[S[i]] += 1 for key, value in list(dict.items()): if key < value: count += (value-key) elif key > value: count += value print(count)
p03487
n=int(eval(input())) a=list(map(int,input().split())) b=set(a) ans =0 for i in b: c=a.count(i) if c>i: ans += c-i elif c<i: ans += c print(ans)
n=int(eval(input())) a=list(map(int,input().split())) a=sorted(a) a.append(-1) count=1 ans=0 for i in range(0,n): if a[i+1]==a[i]: count += 1 else: if count > a[i]: ans += count - a[i] elif count < a[i]: ans += count count = 1 print(ans)
p03487
from collections import Counter n = int(eval(input())) l = list(map(int, input().split())) c = Counter(l) ans = 0 for k, v in list(c.items()): if k < v: ans += v - k elif k > v: ans += v print(ans)
from collections import Counter N = int(eval(input())) a = list(map(int, input().split())) ca = Counter(a) ans = 0 for k, v in list(ca.items()): if v < k: ans += v elif v > k: ans += v-k print(ans)
p03487
n = int(eval(input())) a = list(map(int, input().split())) b = list(set(a)) m = len(b) ans = 0 for i in range(m): c = a.count(b[i]) if b[i] > c: ans += c if b[i] < c: ans += c - b[i] print(ans)
n = int(eval(input())) a = list(map(int, input().split())) b = [0 for _ in range(n+1)] ans = 0 for i in range(n): if a[i] > n: ans += 1 else: b[a[i]] += 1 for i in range(n+1): if b[i] > i: ans += b[i] - i if b[i] < i: ans += b[i] print(ans)
p03487
from collections import Counter a = int(eval(input())) l = list(map(int, input().split())) #i = 1 c=Counter(l) d = dict(c) kv = [] for k,v in list(d.items()): if k>v: kv.append(v) elif k<v: t = v-k kv.append(t) s = sum(kv) print(s)
n = int(eval(input())) a = list(map(int, input().split())) ans = 0 cnt = [0] * n + [0] for i in a: if i > n: ans += 1 else: cnt[i] += 1 for i in range(n + 1): ans += cnt[i] - i if cnt[i] >= i else cnt[i] print(ans)
p03487
from collections import Counter from collections import deque n = int(eval(input())) a = list(map(int, input().split())) c = Counter(a) c = c.most_common() ans = 0 for num, cnt in c: if cnt>=num: ans += cnt - num else: ans += cnt print(ans)
from collections import Counter n = int(eval(input())) a = list(map(int, input().split())) c = Counter(a) ans = 0 for num, cnt in list(c.items()): if cnt>=num: ans += cnt - num else: ans += cnt print(ans)
p03487
N = int(eval(input())) A = list(map(int,input().split())) T = list(set(A)) L = [] for i in range(len(T)) : ti = T[i] t = A.count(ti) if t < ti : L.append(t) else : L.append(t - ti) print((sum(L)))
N = int(eval(input())) A = list(map(int,input().split())) D = {} for i in A : if i in D : D[i] += 1 else : D[i] = 1 answer = 0 for key, value in list(D.items()) : if key > value : answer += value else : answer += value-key print(answer)
p03487
N = int(eval(input())) A = list(map(int,input().split())) cnt = 0 ind = 1 while A != []: A = list([x - 1 for x in A]) if(0 in A): zero = A.count(0) if(zero > ind): cnt += abs(zero - ind) elif(zero < ind): cnt += zero A = [n for n in A if n != 0] ind += 1 print(cnt)
N = int(eval(input())) a = list(map(int,input().split())) d = {} for i in range(N): if(a[i] not in d): d[a[i]] = 1 else: d[a[i]] += 1 cnt = 0 for k, v in list(d.items()): if(k > v): cnt += v elif(k < v): cnt += v - k print(cnt)
p03487
n = int(eval(input())) a = list(map(int,input().split())) ans = 0 c19 = 0 for i in range(1,100001): ca = a.count(i) if ca >= i: ans += ca - i else: ans += ca c19 += ca print((ans + n-c19))
n = int(eval(input())) a = list(map(int,input().split())) d = {} count = 0 for i in range(n): if not a[i] in list(d.keys()) and (n-count)>=a[i]: ac = a.count(a[i]) d.update({a[i]:ac}) count += ac ans = 0 for i in sorted(d.keys()): if i <= d[i]: ans += d[i]-i else: ans += d[i] print((ans + n-count))
p03487
n = int(eval(input())) a = list(map(int,input().split())) c_num = set(a) c_num = list(c_num) c_cnt = [0]*(len(c_num)) for i in a: index = c_num.index(i) c_cnt[index] += 1 for i, x in enumerate(c_num): c_cnt[i] -= x ans = 0 for i, x in zip(c_num, c_cnt): if x > 0: ans += x elif x < 0: ans += i + x print(ans)
def count(list): dict = {} for i in range(len(list)): dict[list[i]] = dict.get(list[i], 0) + 1 return dict n = int(eval(input())) a = list(map(int,input().split())) dic = count(a) ans = 0 for i, x in list(dic.items()): differ = x - i if differ>0: ans += differ elif differ<0: ans += x print(ans)
p03487
N = int(eval(input())) a = input().split() a_n = [int(s) for s in a] list = [] for x in a_n: if list == []: list.append([x,1]) else: counter = 0 for y in list: if y[0] == x: y[1] += 1 counter = 1220 if counter == 0: list.append([x,1]) counter = 0 for y in list: if y[0] > y[1]: counter += y[1] elif y[0] < y[1]: counter += y[1] - y[0] print(counter)
N = int(eval(input())) a = input().split() a_n = [int(s) for s in a] dict = {} for i in range(N): if a_n[i] in dict: dict[a_n[i]] += 1 else: dict[a_n[i]] = 1 cnt = 0 for i in dict: if dict[i] > i: cnt += dict[i] - i elif dict[i] < i: cnt += dict[i] print(cnt)
p03487
N = int(eval(input())) A_LI = sorted(map(int, input().split())) A_SET = set(A_LI) ans = 0 for a in A_SET: cnt = A_LI.count(a) if cnt < a: ans += cnt else: ans += cnt - a print(ans)
N = int(eval(input())) A_LI = sorted(map(int, input().split())) a_dict = {} ans = 0 pre = None for a in A_LI: if a not in a_dict: if pre in a_dict: # 出揃った値について取り除く個数を求める if a_dict[pre] < pre: ans += a_dict[pre] else: ans += a_dict[pre] - pre pre = a a_dict[a] = 1 else: a_dict[a] += 1 # 最後の値について取り除く個数を求める if a_dict[pre] < pre: ans += a_dict[pre] else: ans += a_dict[pre] - pre print(ans)
p03487
from collections import Counter N = int(eval(input())) counter = Counter(list(map(int, input().split()))) sum = 0 for a, cnt in counter.most_common(): if a > cnt: sum += cnt else: sum += cnt - a print(sum)
from collections import Counter N = int(eval(input())) counter = Counter(list(map(int, input().split()))) sum = 0 for a, cnt in list(counter.items()): if a > cnt: sum += cnt else: sum += cnt - a print(sum)
p03487
n = int(eval(input())) A = [int(i) for i in input().split()] setA = list(set(A)) d = {a: A.count(a) for a in setA} #print(d) r = 0 for k, v in list(d.items()): if v > k: r += v - k elif k > v: r += v print(r)
n = int(eval(input())) A = [int(i) for i in input().split()] r = 0 d = {} pass_list = [] for a in A: if a in pass_list: r += 1 continue r += 1 if a in d: d[a] += 1 if d[a] == a: r -= a pass_list.append(a) else: d[a] = 1 if d[a] == a: r -= a pass_list.append(a) print(r)
p03487
N = int(eval(input())) a = [int(i) for i in input().split()] a.sort() a_key = list(set(a)) ans = 0 for num in a_key: if a.count(num) < num: ans += a.count(num) else: ans += a.count(num) - num print(ans)
N = int(eval(input())) a = [int(i) for i in input().split()] b = [0] * (N + 1) ans = 0 for i in range(N): if a[i] <= N: b[a[i]] += 1 else: ans += 1 for i in range(N + 1): if b[i] < i: ans += b[i] else: ans+= b[i] - i print(ans)
p03487
N = int(eval(input())) A = sorted(list(map(int, input().split()))) ans = 0 for a in A[::-1]: if A.count(a) != a: A.remove(a) ans += 1 print(ans)
N = int(eval(input())) A = list(map(int, input().split())) B = set(A) result = {} for b in B: result[b] = 0 for a in A: result[a] += 1 count = N for b in B: if result[b] >= b: count -= b print(count)
p03487
n = int(eval(input())) a = list(map(int,input().split())) a.sort() count = 1 ans = 0 for i in range(1,n): if a[i] != a[i-1]: if a[i-1] < count: ans += count - a[i-1] elif a[i-1] > count: ans += count count = 1 else: count+=1 if a[n-1] < count: ans += count - a[n-1] elif a[n-1] > count: ans += count print(ans)
n = int(eval(input())) a = list(map(int,input().split())) a.sort() count = 1 ans = 0 for i in range(n-1): if a[i+1] != a[i]: if count >= a[i]: ans += count-a[i] else: ans += count count = 1 else: count+=1 if count >= a[-1]: ans += count-a[-1] else: ans += count print(ans)
p03487
N = int(eval(input())) A = [int(i) for i in input().split()] a = A.count cnt = 0 for i in set(A): if i < a(i): cnt += a(i)-i elif i > a(i): cnt += a(i) print(cnt)
N = int(eval(input())) A = sorted(int(i) for i in input().split())+[0] cnt, ans = 0, 0 a = A[0] for i in range(len(A)): if a == A[i]: cnt += 1 elif a != A[i]: if cnt < a: ans += cnt elif cnt > a: ans += cnt-a a = A[i] cnt = 1 print(ans)
p03487
n=int(eval(input())) a=list(map(int,input().split())) a=sorted(a) b=list(set(a)) ans=0 for i in range(len(b)): if a.count(b[i])>=b[i]: ans+=a.count(b[i])-b[i] else: ans+=a.count(b[i]) print(ans)
N=int(eval(input())) a=list(map(int,input().split())) a=sorted(a) l=a[0] cnt=0 b=[] for i in range(N): if a[i]==l: cnt+=1 else: b.append([l,cnt]) l=a[i] cnt=1 if cnt>0: b.append([l,cnt]) ans=0 for i in range(len(b)): if b[i][0]>b[i][1]: ans+=b[i][1] else: ans+=b[i][1]-b[i][0] print(ans)
p03487
from collections import Counter n = int(eval(input())) a = list(map(int,input().split())) ac = Counter(a) an = len(ac) cnt = 0 for i in range(an): num, count = ac.most_common()[i] if count > num: cnt += count - num elif count < num: cnt += count print(cnt)
from collections import Counter n = int(eval(input())) a = list(map(int,input().split())) ac = Counter(a) an = len(ac) a_mostcommon = ac.most_common() cnt = 0 for i in range(an): num, count = a_mostcommon[i] if count > num: cnt += count - num elif count < num: cnt += count print(cnt)
p03487
N = int(eval(input())) A = list(map(int, input().split())) ans = 0 set_A = set(A) for num in set_A: count_num = A.count(num) #望ましい数より大きい場合 if count_num >= num: ans += count_num - num #望ましい数より小さい場合は0まで削る。 else: ans += count_num print(ans)
N = int(eval(input())) A = sorted(list(map(int, input().split()))) ans = 0 before_num = A[0] num_count = 1 A.append(-1)#一番大きい数を計算するとき用 for num in A[1:]: if num == before_num: num_count += 1 else: if num_count >= before_num: ans += num_count - before_num else: ans += num_count num_count = 1 before_num = num print(ans)
p03487
# Good Sequence n = int(eval(input())) a = list(map(int, input().split())) a_ = set(a) p = 0 for i in a_: if a.count(i) < i: p += a.count(i) elif a.count(i) > i: p += a.count(i) - i print(p)
# Good Sequence n = int(eval(input())) a = list(map(int, input().split())) count = {} ans = 0 for i in a: if i not in count: count[i] = 1 else: count[i] += 1 for i, c in list(count.items()): if i > c: ans += c elif i < c: ans += c - i print(ans)
p03487
from collections import defaultdict def dfs(v): global ret if ret: return if v == 2: if len(used) == cnt: ret = True return for idx, u in enumerate(edges[v]): tmp = tuple(sorted((u, v)) + [idx]) if tmp in used: continue used.add(tmp) dfs(u) used.discard(tmp) while 1: edges = defaultdict(list) cnt = 0 try: a, b = list(map(int, input().split())) edges[a].append(b) edges[b].append(a) cnt += 1 except EOFError: break while 1: a, b = list(map(int, input().split())) if a == b == 0: break edges[a].append(b) edges[b].append(a) cnt += 1 stack = [] ret = False used = set() dfs(1) if ret: print("OK") else: print("NG")
while 1: edges = [0] * 101 try: a, b = list(map(int, input().split())) edges[a] += 1 edges[b] += 1 except EOFError: break while 1: a, b = list(map(int, input().split())) if a == b == 0: break edges[a] += 1 edges[b] += 1 if edges[1] % 2 and edges[2] % 2 and all([a % 2 == 0 for a in edges[3:]]): print("OK") else: print("NG")
p00086
x=int(input()) x-=1 ans=6 for i in range(x): ans=ans+ans+2 print(ans)
x=int(input()) ans=2 for i in range(x): ans=ans+ans+2 print(ans)
p03893
from collections import deque import sys sys.setrecursionlimit(10**6) input = sys.stdin.readline n = int(eval(input())) edge = [[] for _ in range(n)] mat = [[1000] * n for _ in range(n)] for i in range(n): s = input().rstrip() for j, ch in enumerate(s): if ch == "1": mat[i][j] = 1 if j > i: edge[i].append(j) edge[j].append(i) for i in range(n): mat[i][i] = 0 for k in range(n): for i in range(n): for j in range(n): mat[i][j] = min(mat[i][j], mat[i][k] + mat[k][j]) ans = 0 dq = deque() dist = [-1] * n dq.append((i, 0)) ok = True while dq: v, d = dq.popleft() if dist[v] == -1: dist[v] = d elif dist[v] != d: ok = False break for item in edge[v]: if dist[item] == -1: dq.append((item, d+1)) if ok: ans = 0 for line in mat: ans = max(ans, max(line)) print((ans + 1)) else: print((-1))
from collections import deque import sys sys.setrecursionlimit(10**6) input = sys.stdin.readline n = int(eval(input())) edge = [[] for _ in range(n)] mat = [[1000] * n for _ in range(n)] for i in range(n): s = input().rstrip() for j, ch in enumerate(s): if ch == "1": mat[i][j] = 1 if j > i: edge[i].append(j) edge[j].append(i) for i in range(n): mat[i][i] = 0 for k in range(n): for i in range(n): for j in range(n): mat[i][j] = min(mat[i][j], mat[i][k] + mat[k][j]) ans = 0 dq = deque() dist = [-1] * n dq.append((0, 0)) ok = True while dq: v, d = dq.popleft() if dist[v] == d: continue if dist[v] == -1: dist[v] = d else: ok = False break for item in edge[v]: if dist[item] == -1: dq.append((item, d+1)) if ok: ans = 0 for line in mat: ans = max(ans, max(line)) print((ans + 1)) else: print((-1))
p02892
# AGC039B - Graph Partition from collections import deque def is_bipartite() -> bool: stack = [(1, 1)] color = [-1] * (N + 1) color[1] = 1 while stack: v, cur_color = stack.pop() next_color = cur_color ^ 1 for u in E[v]: if color[u] == cur_color: return False if color[u] == -1: color[u] = next_color stack.append((u, next_color)) return True def bfs(start) -> int: que = deque([start]) dist = [0] * (N + 1) # dist[i] := distance from V_start to V_i dist[start] = 1 while que: v = que.popleft() cur = dist[v] for u in E[v]: if not dist[u]: dist[u] = cur + 1 que.append(u) return max(dist) def main(): # if bipartite graph -> diameter of the graph + 1 global N, E N, *S = open(0).read().split() N = int(N) E = [0] + [[i for i, flg in enumerate(s, 1) if flg == "1"] for s in S] if is_bipartite(): ans = max(bfs(i) for i in range(1, N + 1)) print(ans) else: print((-1)) if __name__ == "__main__": main()
# AGC039B - Graph Partition (156ms) from collections import deque def is_bipartite() -> bool: stack = [(1, 1)] color = [0] * (N + 1) color[1] = 1 while stack: v, cur_color = stack.pop() next_color = -cur_color for u in E[v]: if color[u] == cur_color: return False if not color[u]: color[u] = next_color stack.append((u, next_color)) return True def bfs(start) -> int: que = deque([start]) dist = [0] * (N + 1) # dist[i] := distance from V_start to V_i dist[start] = 1 while que: v = que.popleft() cur = dist[v] for u in E[v]: if not dist[u]: dist[u] = cur + 1 que.append(u) return max(dist) def main(): # if bipartite graph -> diameter of the graph + 1 global N, E N, *S = open(0).read().split() N = int(N) E = [0] + [[i for i, flg in enumerate(s, 1) if flg == "1"] for s in S] if is_bipartite(): ans = max(bfs(i) for i in range(1, N + 1)) print(ans) else: print((-1)) if __name__ == "__main__": main()
p02892
n = str(eval(input())) rn = ''.join(list(reversed(list(n)))) print(('Yes' if n == rn else 'No'))
n = str(eval(input())) rn = ''.join(reversed(list(n))) print(('Yes' if n == rn else 'No'))
p03631
n = str(eval(input())) if n[0] == n[2]: print("Yes") else: print("No")
n = int(eval(input())) x = list(str(n)) if x == x[::-1]: print("Yes") else: print("No")
p03631
n, a, b = list(map(int, input().split())) x = list(map(int, input().split())) ans = 0 for i in range(n-1): ans += min(a * (x[i+1] - x[i]), b) print(ans)
N,A,B = list(map(int, input().split())) X = list(map(int, input().split())) ans = 0 for i in range(1,N): if (X[i] - X[i-1]) * A <= B: ans += (X[i] - X[i-1]) * A else: ans += B print(ans)
p03829
def main(): n, a, b, *x = list(map(int, open(0).read().split())) ans = 0 for i, j in zip(x, x[1:]): if a * (j - i) > b: ans += b else: ans += a * (j - i) print(ans) if __name__ == '__main__': main()
def main(): n, a, b, *x = list(map(int, open(0).read().split())) ans = 0 it = iter(x) nw = it.__next__() for nx in it: c = (nx - nw) * a if c > b: ans += b else: ans += c nw = nx print(ans) if __name__ == '__main__': main()
p03829
N, A, B = list(map(int, input().split())) X = list(map(int, input().split())) X.sort() group=[[X[0]]] for i in range(N-1): if (X[i+1] - X[i]) * A > B: group.append([X[i+1]]) else: group[-1].append(X[i+1]) #print(group) ans = (len(group) - 1) * B for g in group: ans += (max(g) - min(g)) * A print(ans)
N, A, B = list(map(int, input().split())) X = list(map(int, input().split())) X.sort() ans = 0 for i in range(N-1): ans += min((X[i+1] - X[i]) * A, B) print(ans)
p03829
N,A,B=list(map(int,input().split())) X=list(map(int,input().split())) from collections import deque X=deque(X) cost=0 now=X.popleft() while len(X)>0: if (X[0]-now)*A<=B: cost+=(X[0]-now)*A else:cost+=B now=X.popleft() print(cost)
N,A,B=list(map(int,input().split())) now=0 ans=0 for x in map(int,input().split()): if now!=0: if (x-now)*A>B: ans+=B else: ans+=(x-now)*A now=x print(ans)
p03829
n,a,b = list(map(int, input().split())) x = list(map(int, input().split())) ans = 0 for i in range(n-1): ans += min(a*(x[i+1]-x[i]), b) print(ans)
n,a,b = list(map(int, input().split())) x = list(map(int, input().split())) ans = 0 for i in range(1,n): ans += min(b, a*(x[i]-x[i-1])) print(ans)
p03829
# python3 (3.4.3) import sys input = sys.stdin.readline # main N,A,B = list(map(int,input().split())) X = list(map(int,input().split())) ans = 0 for i in range(N-1): ans += min(B, A*(X[i+1]-X[i])) print(ans)
# Python3 (3.4.3) import sys input = sys.stdin.readline # ------------------------------------------------------------- # function # ------------------------------------------------------------- # ------------------------------------------------------------- # main # ------------------------------------------------------------- N,A,B = list(map(int,input().split())) X = list(map(int,input().split())) ans = 0 for i in range(N-1): d = X[i+1] - X[i] if d*A > B: ans += B else: ans += d*A print(ans)
p03829
N, A, B = list(map(int, input().split())) X= list(map(int, input().split())) I = [] for i in range(N-1): I.append(X[i+1]-X[i]) M = X[N-1]-X[0] I_srt = sorted(I) I_srt.reverse() ans = min([(M-sum(I_srt[:i]))*A + B*i for i in range(N)]) print(ans)
N, A, B = list(map(int, input().split())) X= list(map(int, input().split())) I = [] for i in range(N-1): I.append(X[i+1]-X[i]) M = X[N-1]-X[0] I_srt = sorted(I) I_srt.reverse() I_sum = [0] for i in range(N-1): I_sum.append(I_srt[i]+I_sum[i]) ans = min([(M-I_sum[i])*A + B*i for i in range(N)]) print(ans)
p03829
N, A, B = list(map(int, input().split())) town = list(map(int, input().split())) diff = [0]*(N+1) for i in range(1, N): diff[i] = town[i] - town[i-1] sumz = 0 for i in range(1, N+1): if diff[i]*A > B: sumz += B else: sumz += diff[i]*A print(sumz)
N, A, B = list(map(int, input().split())) num = list(map(int, input().split())) ans = 0 for i in range(1, N): d = num[i] - num[i-1] if d*A < B: ans += d*A else: ans += B print(ans)
p03829
N,A,B=list(map(int,input().split())) *X,=list(map(int,input().split())) ans = 0 for i in range(N-1): ans += min(B,A*(X[i+1]-X[i])) print(ans)
m=lambda:list(map(int,input().split())) N,A,B=m();*X,=m() print((sum(min(B,A*(X[i+1]-X[i]))for i in range(N-1))))
p03829
from collections import deque N,A,B = list(map(int, input().split())) X = list(map(int, input().split())) INF = float("inf") dist = deque(X) next_x = +1 i = 0 ans = 0 while len(dist) != 1: if A*abs(dist[i+next_x] - dist[i]) <= B: ans += A*abs(dist[i+next_x] - dist[i]) if next_x == 1: dist.popleft() i = 0 else: dist.pop() i = len(dist)-1 else: ans += B if next_x == 1: dist.popleft() i = len(dist)-1 else: dist.pop() i = 0 next_x = -next_x print(ans)
# 入力 import sys stdin = sys.stdin def li(): return [int(x) for x in stdin.readline().split()] def li_(): return [int(x)-1 for x in stdin.readline().split()] def lf(): return [float(x) for x in stdin.readline().split()] def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(ns()) def nf(): return float(ns()) n,a,b = li() x = li() ans = 0 for i in range(n-1): if a*(x[i+1]-x[i]) > b: ans += b else: ans += a*(x[i+1]-x[i]) print(ans)
p03829
n,a,b = list(map(int,input().split())) lst = list(map(int,input().split())) ans = 0 for i in range(1,n): if (lst[i] - lst[i-1]) * a >= b: ans += b else: ans += (lst[i] - lst[i-1]) * a print(ans)
n,a,b = list(map(int,input().split())) X = list(map(int,input().split())) pos = X[0] ans = 0 for i in range(1, n): ans += min(b, (X[i] - pos)*a) pos = X[i] print(ans)
p03829
N,A,B = list(map(int,input().split())) X = list(map(int,input().split())) ans = 0 for i in range(N-1): ans += min((X[i+1]-X[i])*A,B) print(ans)
N, A, B = list(map(int, input().split())) X = list(map(int, input().split())) ans = 0 pos = X[0] for i in range(1, N): ans += min(A * (X[i] - pos), B) pos = X[i] print(ans)
p03829
n,a,b=list(map(int,input().split())) X=list(map(int,input().split())) D=[] for i in range(n-1): D.append(X[i+1]-X[i]) ans=0 for i in range(n-1): ans+=min(a*D[i],b) print(ans)
n,a,b=list(map(int,input().split())) X=list(map(int,input().split())) ans=0 for i in range(n-1): ans+=min(a*(X[i+1]-X[i]),b) print(ans)
p03829
from math import factorial def comb (x,y): return factorial(x)//factorial(x-y)//factorial(y) w,h,ax,ay,bx,by=list(map(int,input().split())) dx=abs(ax-bx) dx=min(dx,w-dx) dy=abs(ay-by) dy=min(dy,h-dy) ans=1 if dx*2==w:ans*=2 if dy*2==h:ans*=2 ans*=comb(dx+dy,dx) print((ans%100000007))
from math import factorial def comb (x,y): return factorial(x)//factorial(x-y)//factorial(y) w,h,ax,ay,bx,by=list(map(int,input().split())) dx=abs(ax-bx) dx=min(dx,w-dx) dy=abs(ay-by) dy=min(dy,h-dy) an=1 if dx*2==w:an*=2 if dy*2==h:an*=2 an*=comb(dx+dy,dx) print((an%int(1E8+7)))
p00991
# AOJ 1501: Grid # Python3 2018.7.13 bal4u MOD = 100000007 def dp(n, k): if tbl[n][k]: return tbl[n][k] if (k << 1) > n: k = n-k if k == 0: ans = 1 elif k == 1: ans = n else: ans = dp(n-1, k) + dp(n-1, k-1) tbl[n][k] = ans % MOD return tbl[n][k] tbl = [[0 for j in range(1001)] for i in range(1001)] k = 0 r, c, a1, a2, b1, b2 = list(map(int, input().split())) dr = abs(a1-b1) if dr > r-dr: dr = r-dr if (dr << 1) == r: k += 1 dc = abs(a2-b2) if dc > c-dc: dc = c-dc if (dc << 1) == c: k += 1 print(((dp(dr+dc, min(dr, dc)) << k) % MOD))
# AOJ 1501: Grid # Python3 2018.7.13 bal4u from math import factorial def comb (n, k): return factorial(n)//factorial(n-k)//factorial(k) k = 0 r, c, a1, a2, b1, b2 = list(map(int, input().split())) dr = abs(a1-b1) if dr > r-dr: dr = r-dr if (dr << 1) == r: k += 1 dc = abs(a2-b2) if dc > c-dc: dc = c-dc if (dc << 1) == c: k += 1 print(((comb(dr+dc, min(dr, dc)) << k) % 100000007))
p00991
h, w, n = list(map(int, input().split())) li = [] l = [w] * h for _ in range(n): x, y = list(map(int, input().split())) li.append((x - 1, y - 1)) li.sort() cnt = 0 ans = h for x, y in li: if x - cnt == y: cnt += 1 elif x - cnt > y: ans = min(ans, x) print(ans)
h, w, n = list(map(int, input().split())) l = [list(map(int, input().split())) for _ in range(n)] l.sort(key=lambda x: (x[1], x[0])) t = 0 a = [h + 1] for x, y in l: if x > y + t: a.append(x) elif x == y + t: t += 1 print((min(a) - 1))
p03203
H,W,N=list(map(int,input().split())) XY=[] for i in range(N): XY.append(list(map(int,input().split()))) XY.sort() conditions=[i-1 for i in range(H+1)] for xy in XY: if conditions[xy[0]]>=xy[1]: print(xy[0]-1) break if xy[1]==conditions[xy[0]]+1: conditions=[conditions[i] if i<=xy[0] \ else conditions[i]-1 for i in range(H+1)] else: print(H)
H,W,N=list(map(int,input().split())) XY=[] for i in range(N): XY.append(list(map(int,input().split()))) XY.sort() conditions=[2,1] for xy in XY: if xy[0]>conditions[0]: conditions=[xy[0],conditions[1]+xy[0]-conditions[0]] if conditions[1]>=xy[1]: print(xy[0]-1) break if xy[1]==conditions[1]+1: conditions=[conditions[0],conditions[1]-1] else: print(H)
p03203
H, W, N = list(map( int, input().split())) V = [H-1]*W X = [ tuple( map( int, input().split())) for _ in range(N)] X.sort() d = 0 for i in range(N): x, y = X[i] x, y = x-1, y-1 if x == y+d: d += 1 elif x > y+d: V[y] = min( V[y], x-1) print(( min(V)+1))
H, W, N = list(map( int, input().split())) X = [ tuple( map( int, input().split())) for _ in range(N)] X.sort() d = 0 ans = H for i in range(N): if X[i][1]+d == X[i][0]: d += 1 if X[i][1] + d < X[i][0]: ans = X[i][0]-1 break print(ans)
p03203