input
stringlengths 20
127k
| target
stringlengths 20
119k
| problem_id
stringlengths 6
6
|
---|---|---|
n = int(eval(input()))
ls = list(map(int, input().split(' ')))
ans = 1
if ls[0] != 0:
ans = 0
m = max(set(ls))
d = {i: ls.count(i) for i in range(m+1)}
for i in range(1, m+1):
ans = (ans * (d[i-1] ** d[i]) % 998244353) % 998244353
print(ans)
|
n = int(eval(input()))
ls = list(map(int, input().split(' ')))
m = max(set(ls))
d = {}
for l in ls:
d[l] = d.get(l, 0) + 1
ans = 0 if (ls[0] != 0 or d.get(0) >= 2) else 1
for i in range(1, m+1):
if i not in d:
ans = 0
ans = (ans * (d.get(i-1, 0) ** d.get(i, 0))) % 998244353
print(ans)
|
p02866
|
n,*a=list(map(int,open(0).read().split()))
mod=998244353
d={}
for i in a:
d[i]=d.get(i,0)+1
b=list(d.items())
b.sort()
ans=1
if a[0]!=0 or len(b)!=b[-1][0]+1 or b[0][1]!=1:
ans=0
for i in range(1,len(b)):
ans*=b[i-1][1]**b[i][1]
ans%=mod
print(ans)
|
n,*a=list(map(int,open(0).read().split()))
mod=998244353
b=[0]*n
for i in a:
b[i]+=1
ans=0
if a[0]==0 and 1==b[0]:
ans=1
for i,j in zip(b,b[1:]):
ans=ans*i**j%mod
print(ans)
|
p02866
|
N=int(eval(input()))
D=list(map(int,input().split()))
mod=998244353
if D[0]!=0:
print((0))
exit()
n=[0]*N
n[0]=1
for i in range(1,N):
if D[i]==0:
print((0))
exit()
n[D[i]]+=1
ans=1
cnt=n[0]+n[1]
for i in range(2,N):
if n[i]==0:
if cnt!=N:
print((0))
exit()
else:
break
ans=ans*n[i-1]**n[i]
ans=ans%mod
cnt=cnt+n[i]
print(ans)
|
N=int(eval(input()))
D=list(map(int,input().split()))
mod=998244353
if D[0]!=0:
print((0))
exit()
B=[0]*N
for d in D:
B[d]+=1
if B[0]!=1:
print((0))
exit()
ans=1
total=1
for i in range(1,N):
if B[i]==0:
if total!=N:
print((0))
exit()
else:break
total+=B[i]
ans*=(B[i-1]**B[i])
ans%=mod
print(ans)
|
p02866
|
while 1:
n,w,d = list(map(int,input().split()))
if w == 0: break
cake = [[w,d]]
for loop in range(n):
p,s = list(map(int,input().split()))
x,y = cake.pop(p-1)
s %= (x+y)
if s < x:
x1,x2 = sorted([s,x-s])
cake.append([x1,y])
cake.append([x2,y])
else:
s -= x
y1,y2 = sorted([s,y-s])
cake.append([x,y1])
cake.append([x,y2])
print(" ".join(map(str,sorted([x*y for x,y in cake]))))
|
while 1:
n,w,d = list(map(int,input().split()))
if w == 0: break
cake = [[w,d]]
for loop in range(n):
p,s = list(map(int,input().split()))
x,y = cake.pop(p-1)
s %= (x+y)
if s < x:
x1,x2 = sorted([s,x-s])
cake += [[x1,y],[x2,y]]
else:
s -= x
y1,y2 = sorted([s,y-s])
cake += [[x,y1],[x,y2]]
print(" ".join(map(str,sorted([x*y for x,y in cake]))))
|
p00730
|
#!/usr/bin/env python3
import sys
import collections
def solve(N: int, A: "List[int]"):
counter = sorted(list(collections.Counter(A).values()),reverse=True)
for i in range(1,N+1):
if len(counter)<i:
print((0))
continue
c_index = 0
n = N
k = i
while counter[c_index]*k > n and c_index<len(counter)-1:
n-=counter[c_index]
c_index+=1
k-=1
print((n//k))
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, A)
if __name__ == '__main__':
main()
|
#!/usr/bin/env python3
import sys
import collections
def solve(N: int, A: "List[int]"):
counter = sorted(list(collections.Counter(A).values()),reverse=True)
c_index = 0
k=0
for i in range(1,N+1):
k+=1
if len(counter)<i:
print((0))
continue
while counter[c_index]*k > N and c_index<len(counter)-1:
N-=counter[c_index]
c_index+=1
k-=1
print((N//k))
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, A)
if __name__ == '__main__':
main()
|
p02890
|
import bisect
import sys
input = sys.stdin.readline
n = int(eval(input()))
a = [int(item) for item in input().split()]
cnt = [0] * (n + 1)
for item in a:
cnt[item] += 1
cnt.sort()
cumsum = [0] * (n + 2)
for i in range(n+1):
cumsum[i+1] = cumsum[i] + cnt[i]
ans = []
for i in range(n):
if cnt[i+1] == 0:
ans.append(0)
continue
l = 0; r = n+1
while r - l > 1:
mid = (l + r) // 2
index = bisect.bisect_left(cnt, mid) - 1
if index <= i:
l = mid
continue
num = index - i
if mid * num <= cumsum[index + 1]:
l = mid
else:
r = mid
ans.append(l)
ans.reverse()
print(("\n".join([str(item) for item in ans])))
|
import bisect
import sys
input = sys.stdin.readline
n = int(eval(input()))
a = [int(item) for item in input().split()]
cnt = [0] * (n + 1)
for item in a:
cnt[item] += 1
cnt.sort()
cumsum = [0] * (n + 2)
for i in range(n+1):
cumsum[i+1] = cumsum[i] + cnt[i]
indexes = [0] * (n+1)
for i in range(n+1):
indexes[i] = bisect.bisect_left(cnt, i) - 1
ans = []
for i in range(n):
if cnt[i+1] == 0:
ans.append(0)
continue
l = 0; r = n+1
while r - l > 1:
mid = (l + r) // 2
index = indexes[mid]
if index <= i:
l = mid
continue
num = index - i
if mid * num <= cumsum[index + 1]:
l = mid
else:
r = mid
ans.append(l)
ans.reverse()
print(("\n".join([str(item) for item in ans])))
|
p02890
|
import collections
import heapq
def main():
N = int(input())
A = list(map(int, input().split()))
# print(N, A)
# 整数ごとに何枚あるか数える
c = collections.Counter(A)
v = [-x for x in c.values()]
# print(c, v)
_max = len(v)
ans = [N]
for K in range(2, N+1):
# Kがカードの種類より大きい場合は1回も食べれない
if K > _max:
ans.append(0)
continue
q = v[:]
heapq.heapify(q)
cnt = 0
while len(q) >= K:
eat = []
# 枚数の多い順にK個取り出す
for k in range(K):
eat.append(heapq.heappop(q))
cnt += 1
for e in eat:
if e < -1:
heapq.heappush(q, e + 1)
ans.append(cnt)
print(*ans, sep='\n')
if __name__ == '__main__':
main()
|
def main():
N = int(input())
A = list(map(int, input().split()))
# C[x]: 書かれている整数がxであるカードの枚数
C = [0] * (N + 1)
D = [0] * (N + 1)
for a in A:
C[a] += 1
D[C[a]] += 1
# AからK(1<=K<=N)枚ずつカードを抜いてったときに、
# x回以上抜くことができるか判定する。
# 抜くことができると判定されたxの最大値が答えになる。
# 例えば、A = [1 1 1 1 1 2 2 3] とする。
# -> C = [5 2 1 0 0 0 0 0]
# ここから2枚ずつカードを抜ける回数を考えるとき、
# 「3回抜く」とすると、数字の1は、どうやっても2個は絶対余る
# そこで、絶対余る部分を捨ててCを作り直す(=Eとする)と、
# E = [3 2 1 0 0 0 0 0]
# ここから2枚ずつ3回抜けるか判定するなら、
# sum(E) >= 2 * 3 = 6
# であるか見ればよい。今回の場合ちょうど6なので、2枚ずつ3回は抜ける。
# 3枚ずつ2回ぬけるか調べる場合、
# E = [2 2 1] となり、sum(E) = 5 < 3 * 2 = 6 なので、抜けないことが分かる
# よって、
# sum(min(C[i], x)) >= K * x であれば抜くことができる
# S(x) = sum(min(C[i], x)) とすると、
# S(x) = S(x-1) + [Cの中でC[i] >= x であるものの個数]
# となることから、Cの中でC[i] >= x であるものの個数 = D(x) とすると、
# S(x) = sum_(1~x) D(i) となる。
# つまり、S(x)は、D(x) を最初に全部計算しておいて、累積和をとることで高速に計算できる。
# S(x) >= K * x となるxの最大値を、kを1からNまで動かして見つければよい。
# ここで、xを左辺にもっていって、
# S(x) / x >= Kとなるxの最大値を見つけるようにする。
# また、S(x) / x = f(x) とおく。
# 最大値を見つけるために2分探索してもいいが、
# Kが増えると、答えは以前の値以下になるはずなので、
# K+1のとき、Kでの答えの位置から0へと探索していけば、O(N)で答えが見つかる
S = [0] * (N + 1)
f = [0] * (N + 1)
for x in range(1, N+1):
S[x] = S[x-1] + D[x]
f[x] = S[x] // x
ans = []
prev_ans = N
for K in range(1, N+1):
a = prev_ans
while True:
if f[a] >= K or a == 0:
break
a -= 1
ans.append(a)
prev_ans = a
print(*ans, sep='\n')
if __name__ == '__main__':
main()
|
p02890
|
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(eval(input()))
inl = lambda: list(map(int, input().split()))
inm = lambda: list(map(int, input().split()))
DBG = True # and False
BIG = 999999999
R = 10**9 + 7
def ddprint(x):
if DBG:
print(x)
def f(k,p):
acc = n
for i in range(len(b)):
if b[i]>p:
acc -= b[i]-p
else:
break
return (acc >= k*p)
n = inn()
a = inl()
h = {}
for x in a:
if x in h:
h[x] += 1
else:
h[x] = 1
b = []
for x in h:
b.append(h[x])
b.sort(reverse=True)
#ddprint(b)
for k in range(1,n+1):
mn = 0
mx = n//k + 1
while mx > mn+1:
mid = (mn+mx)//2
if f(k,mid):
mn = mid
else:
mx = mid
print(mn)
|
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(eval(input()))
inl = lambda: list(map(int, input().split()))
inm = lambda: list(map(int, input().split()))
DBG = True # and False
BIG = 999999999
R = 10**9 + 7
def ddprint(x):
if DBG:
print(x)
def f(k,p):
return (c[p] >= k*p)
def ff(k,p):
acc = n
for i in range(len(b)):
if b[i]>p:
acc -= b[i]-p
else:
break
return (acc >= k*p)
n = inn()
a = inl()
h = {}
for x in a:
if x in h:
h[x] += 1
else:
h[x] = 1
b = []
for x in h:
b.append(h[x])
b.sort(reverse=True)
#ddprint(b)
c = [0]*(n+1)
for p in range(1,n+1):
acc = n
for i in range(len(b)):
if b[i]>p:
acc -= b[i]-p
else:
break
c[p] = acc
for k in range(1,n+1):
mn = 0
mx = n//k + 1
while mx > mn+1:
mid = (mn+mx)//2
if f(k,mid):
mn = mid
else:
mx = mid
print(mn)
|
p02890
|
N = int(eval(input()))
A = list(map(int, input().split()))
types = {}
for i in A: types[i] = types.get(i, 0) + 1
A = sorted([types[k] for k in types], reverse=True)
L = len(A)
cumsum = [0 for i in range(L+1)]
for i in range(L-1, -1, -1):
cumsum[i] = A[i] + cumsum[i+1]
# Highest K for given O
def calc(O):
def getMidPoint(lo, hi):
if lo >= hi: return lo
mid = lo + (hi - lo+1) // 2
if A[mid] > O:
return getMidPoint(mid, hi)
else:
return getMidPoint(lo, mid-1)
mid = getMidPoint(0, L-1)
if A[mid] < O: mid = - 1
return (mid+1) + cumsum[mid+1] // O
for K in range(1, N+1):
def getO(lo, hi):
if lo >= hi: return lo
mid = lo + (hi - lo+1) // 2
if calc(mid) < K:
return getO(lo, mid - 1)
else:
return getO(mid, hi)
print((getO(0, N)))
|
N = int(eval(input()))
A = list(map(int, input().split()))
types = {}
for i in A: types[i] = types.get(i, 0) + 1
A = sorted([types[k] for k in types], reverse=True)
L = len(A)
cumsum = [0 for i in range(L+1)]
for i in range(L-1, -1, -1):
cumsum[i] = A[i] + cumsum[i+1]
def getMidPoint(lo, hi, O):
if lo >= hi: return lo
mid = lo + (hi - lo+1) // 2
if A[mid] > O:
return getMidPoint(mid, hi, O)
else:
return getMidPoint(lo, mid-1, O)
getMid = [getMidPoint(0, L - 1, o) for o in range(N+1)]
# Highest K for given O
def calc(O):
mid = getMid[O]
if A[mid] < O: mid = - 1
return (mid+1) + cumsum[mid+1] // O
for K in range(1, N+1):
def getO(lo, hi):
if lo >= hi: return lo
mid = lo + (hi - lo+1) // 2
if calc(mid) < K:
return getO(lo, mid - 1)
else:
return getO(mid, hi)
print((getO(0, N)))
|
p02890
|
from collections import Counter
from itertools import accumulate
import bisect
n = int(eval(input()))
a = list(map(int, input().split()))
b = sorted(Counter(a).values())
b = [0]*(n-len(b))+b
c = list(accumulate([0]+b))
for k in range(1,n+1):
l = 0
r = n+1
while r-l>1:
x = (r+l)//2
i = bisect.bisect_left(b,x)
if c[i]+(n-i)*x>=x*k:
l = x
else:
r = x
print(l)
|
from collections import Counter
from itertools import accumulate
import bisect
n = int(eval(input()))
a = list(map(int, input().split()))
b = sorted(Counter(a).values())
exist = len(b)
b = [0]*(n-exist)+b
c = list(accumulate([0]+b))
print(n)
for k in range(2,n//2+1):
l = 0
r = n+1
while r-l>1:
x = (r+l)//2
i = bisect.bisect_left(b,x)
if c[i]+(n-i)*x>=x*k:
l = x
else:
r = x
print(l)
for k in range(max(n//2+1,2),n+1):
if exist>=k:
print((1))
else:
print((0))
|
p02890
|
from collections import Counter
from itertools import accumulate
import bisect
printRows = lambda x:print('\n'.join(map(str,x)))
n = int(input())
a = list(map(int, input().split()))
b = sorted(Counter(a).values())
exist = len(b)
b = [0]*(n-exist)+b
c = list(accumulate([0]+b))
ans = [n]
for k in range(2,n+1):
l = 0
r = n//k+1
while r-l>1:
x = (r+l)//2
i = bisect.bisect_left(b,x)
if c[i]+(n-i)*x>=x*k:
l = x
else:
r = x
ans.append(l)
printRows(ans)
|
from collections import Counter
from itertools import accumulate
import bisect
printRows = lambda x:print('\n'.join(map(str,x)))
n = int(input())
a = list(map(int, input().split()))
b = sorted(Counter(a).values())
exist = len(b)
b = [0]*(n-exist)+b
c = list(accumulate([0]+b))
ans = [n]
for k in range(2,exist+1):
l = 0
r = n//k+1
while r-l>1:
x = (r+l)//2
i = bisect.bisect_left(b,x)
if c[i]+(n-i)*x>=x*k:
l = x
else:
r = x
ans.append(l)
printRows(ans+[0]*(n-exist))
|
p02890
|
from collections import Counter
from itertools import accumulate
import bisect
printRows = lambda x:print('\n'.join(map(str,x)))
n = int(input())
a = list(map(int, input().split()))
b = sorted(Counter(a).values())
exist = len(b)
b = [0]*(n-exist)+b
c = list(accumulate([0]+b))
ans = [n]
for k in range(2,exist+1):
l = 0
r = n//k+1
while r-l>1:
x = (r+l)//2
i = bisect.bisect_left(b,x)
if c[i]+(n-i)*x>=x*k:
l = x
else:
r = x
ans.append(l)
printRows(ans+[0]*(n-exist))
|
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print(('\n'.join(map(str,x))))
from collections import Counter
from itertools import accumulate
import bisect
n = readint()
a = readints()
b = sorted(Counter(a).values())
exist = len(b)
b = [0]*(n-exist)+b
c = list(accumulate([0]+b))
ans = [n]
for k in range(2,exist+1):
l = 0
r = n//k+1
while r-l>1:
x = (r+l)//2
i = bisect.bisect_left(b,x)
if c[i]+(n-i)*x>=x*k:
l = x
else:
r = x
ans.append(l)
printrows(ans+[0]*(n-exist))
|
p02890
|
from bisect import bisect_left
N = int(eval(input()))
A = list(map(int, input().split()))
lst = [0] * (N + 1)
for a in A:
lst[a - 1] += 1
lst.sort() #頻度列
s = [0] * (N + 1)
for i in range(N):
s[i + 1] = s[i] + lst[i + 1]
# print (lst)
# print (s)
def check(x, k):
i = bisect_left(lst, x) - 1
total = x * (N - i) + s[i]
return total >= x * k
for k in range(1, N + 1):
l = 0 #OK
r = N // k + 1 #NG
while l + 1 < r:
c = (l + r) // 2
if check(c, k):
l = c
else:
r = c
print (l)
|
from bisect import bisect_left
N = int(eval(input()))
A = list(map(int, input().split()))
lst = [0] * (N + 1)
for a in A:
lst[a - 1] += 1
lst.sort() #頻度列
s = [0] * (N + 1)
for i in range(N):
s[i + 1] = s[i] + lst[i + 1]
# print (lst)
# print (s)
def check(x, k):
i = bisect_left(lst, x) - 1
total = x * (N - i) + s[i]
return total >= x * k
ans = N
for k in range(1, N + 1):
while True:
if check(ans, k):
break
ans -= 1
print (ans)
|
p02890
|
n=int(eval(input()))
a=[int(j) for j in input().split()]
from collections import Counter
c=Counter(a)
l=c.most_common()
ll=[]
for i,j in l:
ll.append(-j)
import heapq
import copy
for k in range(1,1+n):
if k==1:
print(n)
else:
ans=0
q=copy.deepcopy(ll)
heapq.heapify(q)
while True:
if len(q)<k:
break
t=[]
for i in range(k):
t.append(-heapq.heappop(q))
m=min(t)
ans+=m
for i in t:
if i-m!=0:
heapq.heappush(q,-(i-m))
print(ans)
|
import sys
input = sys.stdin.readline
n=int(eval(input()))
a=[int(j) for j in input().split()]
from collections import Counter
c=Counter(a)
l=c.most_common()
ll=[]
for i,j in l:
ll.append(j)
ll.sort()
s=sum(ll)
rem=0
for k in range(1,n+1):
rest=k-rem
while ll and ll[-1]>s//rest:
s-=ll[-1]
ll.pop()
rem+=1
rest-=1
print((s//rest))
|
p02890
|
import sys
from collections import Counter
from bisect import bisect_left
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
class BitSum:
def __init__(self, n):
self.n = n
self.table = [0] * (n + 1)
def update(self, i, x):
i += 1
while i <= self.n:
self.table[i] += x
i += i & -i
def sum(self, i):
i += 1
res = 0
while i > 0:
res += self.table[i]
i -= i & -i
return res
def main():
n = int(eval(input()))
aa = list(map(int, input().split()))
aa = list(Counter(aa).values())
aa.sort()
bit = BitSum(len(aa))
for i, a in enumerate(aa):
bit.update(i, a)
# print(aa)
l = n + 1
pi=len(aa)
for k in range(1, n + 1):
r = l + 1
l = 0
while l + 1 < r:
m = (l + r) // 2
i = bisect_left(aa[:pi + 1], m)
s = bit.sum(i - 1) + m * (len(aa) - i)
if s >= m * k:
l = m
else:
r = m
pi = i
print(l)
main()
|
import sys
from collections import Counter
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
def main():
n = int(eval(input()))
aa = list(map(int, input().split()))
aa = list(Counter(aa).values())
aa.sort()
cs = [0]
s = 0
for a in aa:
s += a
cs += [s]
# print(aa)
# print(cs)
ans = n + 1
i = len(aa)
for k in range(1, n + 1):
while 1:
while i > 0 and aa[i - 1] >= ans:
i -= 1
s = cs[i] + ans * (len(aa) - i)
if s >= ans * k:
break
else:
ans -= 1
print(ans)
main()
|
p02890
|
import copy
import bisect
N = int(eval(input()))
A = list(map(int, input().split()))
C = [0]*(N + 1)
for a in A:
C[a] += 1
sorted_C = sorted(C)
def h(L, i):
"""
sorted_C[N - i : N]の最小の所に、sorted_C[ : N - i]を順番に積み上げるイメージ
"""
if i == 1:
return N
if i > N//2:
if L[N - i + 1] == 0:
return 0
else:
return 1
for j in range(N - i, 0, - 1):
if L[j] == 0:
return L[N - i + 1]
L[N - i + 1] += L[j]
a = bisect.bisect_right(L[N - i + 2: ], L[N - i + 1])
L[N - i + 1:] = L[N - i + 2: N - i + 2 + a] + [L[N - i + 1]] + L[N - i + 2 + a :]
# L[i -1]が大きくなったからソートし直す
# これはL[0 : i - 2]はソート済みだからbisectでL[0 : i - 2]にL[i - 1]が入るいちを見つければ良い。下の解答参照
return L[N - i + 1]
for i in range(N):
L = copy.copy(sorted_C)
print((h(L, i + 1)))
|
N = int(eval(input()))
A = list(map(int, input().split()))
C = [0]*N
for a in A:
C[a - 1] += 1
D = [0]*(N + 1)
for c in C:
D[c] += 1
Dk_accum = [0]*(N + 1)
for i in range(1, N + 1):
Dk_accum[i] = Dk_accum[i - 1] + i*D[i]
D_sum = sum(D)
D_accum = [0]*(N + 2)
D_accum[0] = D_sum
for i in range(1, N + 1):
D_accum[i] = D_accum[i - 1] - D[i - 1]
F = [0]*(N + 1)
for i in range(1, N + 1):
F[i] = (Dk_accum[i]//i + D_accum[i + 1])
i = N
for K in range(1, N + 1):
while i > 0 and K > F[i]:
i -= 1
print(i)
|
p02890
|
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
from collections import Counter
n=int(eval(input()))
A=list(Counter(list(map(int,input().split()))).values())
A.sort()
m=len(A)
S=[0]*(m+1) # cumulative distribution
for i in range(m): S[i+1]=S[i]+A[i]
# output
p=n
i=m
from bisect import bisect_left
for k in range(1,n+1):
while(1):
# pに対して先にi_pを求めておく
while(1):
if(i<=0 or A[i-1]<p): break
i-=1
if(S[i]+p*(m-i)>=k*p): break # p<0 or を書く必要はない
p-=1 # pの条件が真になるまで減らし続ける
print(p)
resolve()
|
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def bin_sort(A,n_min=None,n_max=None):
if(n_min is None): n_min=min(A)
if(n_max is None): n_max=max(A)
bin=[0]*(n_max-n_min+1)
for a in A: bin[a-n_min]+=1
B=[]
for i in range(n_min,n_max+1): B+=[i]*bin[i-n_min]
return B
def resolve():
n=int(eval(input()))
A=[0]*n
for a in map(int,input().split()): A[a-1]+=1
A=bin_sort(A,0,n)
S=[0]*(n+1)
for i in range(n): S[i+1]=S[i]+A[i]
# output
p=n; i=n
for k in range(1,n+1):
while(1):
while(1):
if(i<=0 or A[i-1]<p): break
i-=1
if(S[i]+p*(n-i)>=k*p): break
p-=1
print(p)
resolve()
|
p02890
|
import collections
import bisect
n=int(eval(input()))
a=collections.Counter(list(map(int,input().split())))
a=list(a.values())
a.sort()
b=[0]*len(a)
b[0]=a[0]
for i in range(len(a)-1):
b[i+1]=b[i]+a[i+1]
s=sum(a)
#print(a,b)
ans=[i for i in range(0,n+1)]
ans=ans[::-1]
for t in range(1,n+1):
ANS=ans[n+(-n//t):]
#print(ANS)
for A in ANS:
z=bisect.bisect_right(a,A)
#print(z)
if A*t<=(b[z-1] if z>=1 else 0)+A*(len(b)-z):
print(A)
break
|
import collections
import bisect
n=int(eval(input()))
a=collections.Counter(list(map(int,input().split())))
a=list(a.values())
a.sort()
b=[0]*len(a)
b[0]=a[0]
for i in range(len(a)-1):
b[i+1]=b[i]+a[i+1]
s=sum(a)
ans=[i for i in range(0,n+1)]
ans=ans[::-1]
for t in range(1,n+1):
ANS=ans[n+(-n//t):]
for A in ANS:
z=bisect.bisect_right(a,A)
if A*t<=(b[z-1] if z>=1 else 0)+A*(len(b)-z):
print(A)
break
|
p02890
|
from collections import Counter
from copy import deepcopy
n = int(eval(input()))
a = list(map(int, input().split()))
c = Counter(a)
for k in range(1, n + 1):
cx = deepcopy(c)
count = 0
while k <= len(cx):
# print(cx)
mc = cx.most_common()
for key, _ in mc[:k]:
cx[key] -= 1
if cx[key] < 1:
del cx[key]
count += 1
print(count)
|
from collections import Counter
from itertools import accumulate
# from copy import deepcopy
n = int(eval(input()))
a = list(map(int, input().split()))
c = Counter(a)
# for k in range(1, n + 1):
# cx = deepcopy(c)
# count = 0
# while k <= len(cx):
# # print(cx)
# mc = cx.most_common()
# for key, _ in mc[:k]:
# cx[key] -= 1
# if cx[key] < 1:
# del cx[key]
# count += 1
# print(count)
cv = Counter(list(c.values()))
max_take = max(cv.keys())
lx = list(accumulate(cv[i] for i in range(max_take + 1)))
rx = list(accumulate(cv[i] * i for i in range(max_take + 1)))
ax = [rx[i] + (lx[-1] - lx[i]) * i for i in range(max_take + 1)]
def bisec(l0, r0, predicate):
l, r = l0, r0
while abs(l - r) > 1:
mid = (l + r) // 2
if predicate(mid):
r = mid
else:
l = mid
return r
for k in range(1, n + 1):
print((bisec(n + 1, 0, lambda x: x * k <= ax[min(x, max_take)])))
|
p02890
|
import bisect
n = int(eval(input()))
k = sorted(map(int, input().split()))
hist = []
count = 0
for i in range(n):
count += 1
if i == n - 1 or k[i] != k[i + 1]:
hist.append(count)
count = 0
hist.sort()
sumh = [0]
for i in range(len(hist)):
sumh.append(sumh[-1] + hist[i])
def ok(h, d):
i = bisect.bisect_left(hist, h)
s = sumh[i] + h * (len(hist) - i)
return s >= h * d
def binary_search(d):
lo, hi = 0, 10 ** 10
while hi - lo > 1:
mid = (lo + hi) // 2
if ok(mid, d):
lo = mid
else:
hi = mid
return lo
for d in range(1, n + 1):
print((binary_search(d)))
|
import bisect
n = int(eval(input()))
k = sorted(map(int, input().split()))
hist = []
count = 0
for i in range(n):
count += 1
if i == n - 1 or k[i] != k[i + 1]:
hist.append(count)
count = 0
hist.sort()
sumh = [0]
for i in range(len(hist)):
sumh.append(sumh[-1] + hist[i])
def ok(h, d):
i = bisect.bisect_left(hist, h)
s = sumh[i] + h * (len(hist) - i)
return s >= h * d
def binary_search(d):
lo, hi = 0, n // d + 1
while hi - lo > 1:
mid = (lo + hi) // 2
if ok(mid, d):
lo = mid
else:
hi = mid
return lo
for d in range(1, n + 1):
print((binary_search(d)))
|
p02890
|
import sys
input = sys.stdin.readline
from collections import Counter
from copy import deepcopy
from heapq import heapify, heappush, heappop
def main():
n = int(eval(input()))
a = list(map(int, input().split()))
#n = 3 * 10 ** 5
#a = list(range(1, n + 1))
c = Counter(a)
c = list(c.values())
heapify(c)
k_mx = len(c)
for k in range(1, n + 1):
if k > k_mx:
print((0))
continue
cp = deepcopy(c)
for _ in range(k_mx - k):
cnt = heappop(cp)
while cnt:
mn = heappop(cp)
cnt -= 1
heappush(cp, mn + 1)
ans = heappop(cp)
print(ans)
if __name__ == "__main__":
main()
|
import sys
input = sys.stdin.readline
from collections import Counter
from itertools import accumulate
from math import floor
from bisect import bisect_left
def main():
n = int(eval(input()))
a = list(map(int, input().split()))
c = Counter(a)
c = list(c.values())
d = Counter(c)
d_li = [0] * (n + 1)
for k, v in list(d.items()):
d_li[k] = v
dk_acm = list(accumulate(d_li))
kdk_acm = [0]
for k, e in enumerate(d_li[1:], 1):
kdk_acm.append(kdk_acm[-1] + k * e)
def f(x):
kdk_sm = kdk_acm[x]
dk_sm = dk_acm[n] - dk_acm[x]
return floor((kdk_sm + x * dk_sm) / x)
fs = [float("inf")] + [f(x) for x in range(1, n + 1)]
fs = fs[::-1]
for k in range(1, n + 1):
print((n - bisect_left(fs, k)))
if __name__ == "__main__":
main()
|
p02890
|
N = int(eval(input()))
A = list(map(int, input().split()))
C = [0] * N
D = [0] * (N + 1)
for a in A:
C[a-1] += 1
D[C[a-1]] += 1
S = [0] * (N + 1)
for i in range(N):
S[i+1] = S[i] + D[i+1]
for K in range(1,N+1):
l = 0
r = N + 1
while(r-l>1):
m = int((l+r)/2)
if S[m] >= K * m:
l = m
else:
r = m
print(l)
|
N = int(eval(input()))
A = list(map(int, input().split()))
C = [0] * N
D = [0] * (N + 1)
for a in A:
C[a - 1] += 1
D[C[a - 1]] += 1
S = [0] * (N + 1)
for i in range(N):
S[i + 1] = S[i] + D[i + 1]
ans = N
for K in range(1, N + 1):
while ans > 0 and S[ans] < K * ans:
ans -= 1
print(ans)
|
p02890
|
I = int(eval(input()))
from collections import Counter
from itertools import accumulate
As = list(map(int, input().split()))
xs = sorted([x for x in list(Counter(As).values())]) + [10**18]
Xs = accumulate(xs)
def bsearch(target, min_i, max_i, func):
# func(index) <= target < func(index+1) となるindexを返す
if func(max_i) <= target:
return max_i
if target < func(min_i):
return min_i - 1
index = (max_i + min_i)//2
while True:
if func(index) <= target:
if target < func(index+1):
return index
index, min_i = (index+1 + max_i)//2, index+1
continue
index, max_i = (index-1 + min_i)//2, index-1
#for x in xs:
N = len(xs) - 1
rs = [0]*I
mny = N+1
for l, (x, X) in enumerate(zip(xs[1:], Xs)):
l += 2
y = bsearch(0, N-l+2, N+1, lambda k: x > X//(k-(N-l+1)))
y+=1
#print(l, y, X//(y-(N-l+1)))
for i in range(y, mny):
rs[i-1] = X//(i-(N-l+1))
mny = min(y, mny)
for r in rs:
print(r)
|
I = int(eval(input()))
from collections import Counter
from itertools import accumulate
As = list(map(int, input().split()))
xs = sorted([x for x in list(Counter(As).values())]) + [10**18]
Xs = accumulate(xs)
N = len(xs) - 1
rs = [0]*I
mny = N+1
for l, (x, X) in enumerate(zip(xs[1:], Xs)):
l += 2
y = X//(x+1) + (N-l+1) + 1
if y-(N-l+1) > 0 and x <= X//(y-(N-l+1)):
y+=1
for i in range(y, mny):
rs[i-1] = X//(i-(N-l+1))
mny = min(y, mny)
for r in rs:
print(r)
|
p02890
|
I = int(eval(input()))
from collections import Counter
from itertools import accumulate
As = list(map(int, input().split()))
xs = sorted([x for x in list(Counter(As).values())]) + [10**18]
Xs = accumulate(xs)
N = len(xs) - 1
rs = [0]*I
mny = N+1
for l, (x, X) in enumerate(zip(xs[1:], Xs)):
l += 2
y = X//(x+1) + (N-l+1) + 1
if y-(N-l+1) > 0 and x <= X//(y-(N-l+1)):
y+=1
for i in range(y, mny):
rs[i-1] = X//(i-(N-l+1))
mny = min(y, mny)
for r in rs:
print(r)
|
I = int(eval(input()))
from collections import Counter
from itertools import accumulate
As = list(map(int, input().split()))
xs = sorted([x for x in list(Counter(As).values())]) + [10**18]
Xs = accumulate(xs)
N = len(xs) - 1
rs = [0]*I
mny = N+1
for l, (x, X) in enumerate(zip(xs[1:], Xs)):
l += 2
y = X//(x+1) + (N-l+1) + 1
for i in range(y, mny):
rs[i-1] = X//(i-(N-l+1))
mny = min(y, mny)
for r in rs:
print(r)
|
p02890
|
import sys
import collections as cl
N=int(eval(input()))
A=list(map(int,sys.stdin.readline().split()))
c=cl.Counter(A)
NumberTupleList=c.most_common()
NumberList=[x[1] for x in NumberTupleList[::-1]]
LengthOfNumberList=len(NumberList)
FormulaList=[sum([min(NumberList[i],x) for i in range(LengthOfNumberList)])/x for x in range(1,N+1)]
pin=N-1
for K in range(1,N+1):
while pin>=0 and K>FormulaList[pin]:
pin-=1
print((pin+1))
|
import sys
import collections as cl
N=int(eval(input()))
A=list(map(int,sys.stdin.readline().split()))
c=cl.Counter(A)
NumberTupleList=c.most_common()
NumberList=[x[1] for x in NumberTupleList[::-1]]
LengthOfNumberList=len(NumberList)
FormulaList=[0 for i in range(N)]
flag=0
S=sum(NumberList)
for x in range(1,N+1):
while flag<LengthOfNumberList and NumberList[flag]<=x:
flag+=1
if flag<LengthOfNumberList:
FormulaList[x-1]=(sum(NumberList[:flag])+x*(LengthOfNumberList-flag))/x
else:
FormulaList[x-1]=S/x
pin=N-1
for K in range(1,N+1):
while pin>=0 and K>FormulaList[pin]:
pin-=1
print((pin+1))
|
p02890
|
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')
N = int(eval(input()))
import collections
d = collections.defaultdict(list)
for i in range(N):
S, P = input().split()
P = int(P)
d[S].append((i+1, P))
ordered = list(d.keys())
ordered.sort()
for city in ordered:
mises = d[city]
mises = sorted(mises, key=lambda x: x[1], reverse=True)
for mise in mises:
print((mise[0]))
|
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')
N = int(eval(input()))
SP = []
for i in range(N):
s,p = input().split()
SP.append((s,-int(p),i+1))
SP.sort()
for s,p,i in SP:
print(i)
|
p03030
|
N = int(eval(input()))
Book = [0] * N
for i in range(N):
s,q = input().split()
p = int(q)
Book[i] = (s, 100-p, i)
Book.sort()
for i in range(N):
print((Book[i][2]+1))
|
N = int(eval(input()))
L = []
for _ in range(N):
s, p = input().split()
p = int(p)
L.append((s, 100 - p, _))
L.sort()
for _ in range(N):
print((L[_][2]+1))
|
p03030
|
N = int(eval(input()))
S = [None]*N
P = [None]*N
I = [None]*N
for i in range(N):
tmp = input().split()
S[i] = tmp[0]
P[i] = int(tmp[1])
I[i] = i+1
def less(a, b):
if a[0] == b[0]:
if a[1] == b[1]:
return a[2] < b[2]
return a[1] > b[1]
return a[0] < b[0]
for i in range(N):
for j in range(i+1, N):
if not less([S[i], P[i], I[i]], [S[j], P[j], I[j]]):
S[i], S[j] = S[j], S[i]
P[i], P[j] = P[j], P[i]
I[i], I[j] = I[j], I[i]
for i in range(N):
print((I[i]))
|
N = int(eval(input()))
T = [None]*N
for i in range(N):
tmp = input().split()
T[i] = (tmp[0], -int(tmp[1]), i+1)
T.sort()
for t in T:
print((t[2]))
|
p03030
|
import operator as op
n = int(eval(input()))
s = []
for i in range(n):
a , b = input().split()
s.append((a,int(b),i+1))
s1 = sorted(s,key = op.itemgetter(1),reverse=True)
s2 = sorted(s1,key = op.itemgetter(0))
for i in range(n):
print((s2[i][2]))
|
n = int(eval(input()))
s = []
for i in range(n):
a , b = input().split()
s.append((a,int(b),i+1))
s1 = sorted(s,key = lambda S:S[1],reverse=True)
s2 = sorted(s1,key = lambda S:S[0])
for i in range(n):
print((s2[i][2]))
|
p03030
|
n = int(eval(input()))
dat = []
for i in range(n):
s,p = input().split()
p = int(p)
dat.append((s, p, i+1))
res = sorted(dat, key=lambda x: (x[0], -x[1]))
for i in range(len(res)):
print((res[i][2]))
|
n = int(eval(input()))
dat = []
for i in range(n):
s,p = input().split()
dat.append((s, int(p), i+1))
res = sorted(dat, key=lambda x: (x[0], -x[1]))
for i in range(len(res)):
print((res[i][2]))
|
p03030
|
n=int(eval(input()))
l={}
for i in range(n):
s,p=input().split()
p=int(p)
if s in l:
l[s].append([p,i+1])
else:
l[s]=[[p,i+1]]
dk=sorted(l.keys())
for i in dk:
l[i].sort(reverse=True, key=lambda x:x[0])
for j,k in l[i]:
print(k)
|
n=int(eval(input()))
l=[]
for i in range(n):
s,p=input().split()
p=int(p)*-1
l.append([s,p,i+1])
l.sort()
for i in l:
print((i[2]))
|
p03030
|
n = int(eval(input()))
S = []
count = [0] * n
for i in range(n):
a, b = input().split()
S.append([a, -int(b), i + 1])
S.sort()
for i in range(n):
print((S[i][2]))
|
n = int(eval(input()))
S = []
count = [0] * n
for i in range(n):
a, b = input().split()
S.append([a, -int(b), i + 1])
S.sort(key=lambda x:(x[0], x[1]))
for i in range(n):
print((S[i][2]))
|
p03030
|
n=int(eval(input()))
c,m=[],[]
d={}
t={}
for i in range(n):
s,p=list(map(str,input().split()))
m.append((s,int(p)))
if s not in c:
c.append(s)
d[s]=[int(p)]
else:
d[s].append(int(p))
t[(s,int(p))]=i+1
c.sort()
ans={}
cnt=1
for i in c:
d[i].sort(reverse=True)
for j in d[i]:
ans[cnt]=(i,j)
cnt+=1
for i in range(1,n+1):
print((t[ans[i]]))
|
n=int(eval(input()))
ans=[]
for i in range(n):
s,p=list(map(str,input().split()))
ans.append((s,int(p)*-1,i+1))
ans.sort()
for i in ans: print((i[2]))
|
p03030
|
n = int(eval(input()))
lt = []
for i in range(n):
s, p = input().split()
lt.append((s, -int(p)))
lts = sorted(lt)
for t in lts:
print((lt.index(t)+1))
|
ll=[]
for i in range(int(eval(input()))):
s,p=input().split()
ll.append([s,-int(p),i+1])
for l in sorted(ll):
print((l[2]))
|
p03030
|
n = int(input())
s_p = []
for i in range(n):
s,p = input().split()
s_p.append([s,-int(p),i+1])
s_p.sort(key=lambda x:(x[0],x[1]))
[print(s_p[i][2]) for i in range(n)]
|
n = int(eval(input()))
r = []
for i in range(n):
s,p = input().split()
r.append([s,-int(p),i+1])
r.sort(key=lambda x:(x[0],x[1]))
for i in r:
print((i[2]))
|
p03030
|
n = int(eval(input()))
d = {}
for i in range(n):
s ,p = input().split()
p = int(p)
if not(s in d):
d[s] = {}
d[s][p*-1] = i+1
for i in sorted(d.keys()):
for j in sorted(d[i].keys()):
print((d[i][j]))
|
n = int(eval(input()))
s = []
p = [0] * 101
d = {}
for i in range(n):
a,b = input().split()
b = int(b)
s.append(a)
p[b] = i+1
if a in list(d.keys()):
d[a].append(b)
continue
d[a] = [b]
s = sorted(set(s))
for i in s:
c = sorted(d[i],reverse=True)
for j in c:
print((p[j]))
|
p03030
|
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
import math
import string
import fractions
import re
import array
import copy
import functools
import operator
import collections
import itertools
import bisect
import heapq
from heapq import heappush
from heapq import heappop
# from itertools import accumulate
# from collections import deque
import random
def main():
n = int(eval(input()))
dict={}
for i in range(n):
name, score= input().split()
if not(name in dict):
dict[name]=[((int(score),i+1))]
else:
dict[name].append((int(score),i+1))
dict[name].sort(reverse=True)
eprint(dict)
ll=list(dict.items())
eprint(ll)
ll.sort()
eprint(ll)
for x in ll:
for y in x[1]:
print(y[1])
if __name__ == '__main__':
main()
|
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
# import math
# import string
# import fractions
# from fractions import Fraction
# from fractions import gcd
# def lcm(n,m):
# return int(n*m/gcd(n,m))
# import re
# # import array
# import copy
# import functools
# import operator
# import collections
# import itertools
# import bisect
# import heapq
# from heapq import heappush
# from heapq import heappop
# # from itertools import accumulate
# # from collections import deque
# import random
from queue import PriorityQueue as pq
# class ReversePriorityQueue(PriorityQueue):
# def __cmp__(self, other):
# return -cmp(self.degree, other.degree)
# # def put(self, tup):
# newtup = tup[0] * -1, tup[1]
# PriorityQueue.put(self, newtup)
# def get(self):
# tup = PriorityQueue.get(self)
# newtup = tup[0] * -1, tup[1]
# return newtup
def main():
n = int(eval(input()))
dict={}
for i in range(1,n+1):
str_x,num = input().split()
num =int(num)
if (str_x in dict):
dict[str_x].put((-num,i))
# dict[str_x].sort(key = lambda x : x[1])
else:
a=pq()
dict[str_x]=a
dict[str_x].put((-num,i))
# a.put([num,i])
eprint(dict)
ll = sorted(list(dict.items()))
eprint(ll)
# for i in ll:
# for j in i[1]:
# print(j[1])
for item in ll:
while item[1].qsize():
print((item[1].get())[1])
if __name__ == '__main__':
main()
|
p03030
|
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
# import math
# import string
# import fractions
# from fractions import Fraction
# from fractions import gcd
# def lcm(n,m):
# return int(n*m/gcd(n,m))
# import re
# import array
# import copy
# import functools
# import operator
# import collections
# import itertools
# import bisect
# import heapq
# from heapq import heappush
# from heapq import heappop
# from queue import PriorityQueue as pq
# # from itertools import accumulate
# # from collections import deque
# import random
def main():
n = int(eval(input()))
l=[["",0,0] for i in range(n)]
# eprint(l)
for i in range(n):
s,m=input().split()
m=-int(m)
l[i][0]=s
l[i][1]=m
l[i][2]=i+1
# eprint(l)
l.sort()
# eprint(l)
for x in l:
print(x[2])
if __name__ == '__main__':
main()
|
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
# import math
# import string
# import fractions
# from fractions import Fraction
# from fractions import gcd
# def lcm(n,m):
# return int(n*m/gcd(n,m))
# import re
# import array
# import copy
# import functools
# import operator
# import collections
# import itertools
# import bisect
# import heapq
# from heapq import heappush
# from heapq import heappop
# from queue import PriorityQueue as pq
# # from itertools import accumulate
# # from collections import deque
# import random
def main():
n = int(eval(input()))
# l=[["",0,0] for i in range(n)]
l=[]
# eprint(l)
for i in range(n):
s,m=input().split()
m = -int(m)
l.append([s,m,i+1])
# l[i][0]=s
# l[i][1]=m
# l[i][2]=i+1
# eprint(l)
l.sort()
# eprint(l)
for x in l:
print(x[2])
if __name__ == '__main__':
main()
|
p03030
|
n = int(eval(input()))
X = []
for i in range(n):
s, p = list(map(str, input().split()))
p = int(p)
X.append((s, p, i+1))
X.sort(key= lambda x: (x[0], -x[1]))
for s, p, i in X:
print(i)
|
n = int(eval(input()))
SP = []
for i in range(n):
s, p = list(map(str, input().split()))
p = int(p)
SP.append((s, p, i+1))
SP.sort(key=lambda x: (x[0], -x[1]))
for s, p, j in SP:
print(j)
|
p03030
|
#!/usr/bin/env python3
#ABC128 B
import sys
import math
import bisect
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
mod = 10**9 + 7
n = int(eval(input()))
sp = [list(input().split()) for _ in range(n)]
for i in range(n):
sp[i].append(i+1)
sp.sort(key = lambda x:(x[0],-int(x[1])))
for i in range(n):
print((sp[i][2]))
|
#!/usr/bin/env python3
#ABC128 B
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
n = I()
lst = []
for i in range(n):
s,p = input().split()
lst.append((s,int(p),i+1))
lst.sort(key = lambda x:(x[0],-x[1]))
for i,j,k in lst:
print(k)
|
p03030
|
N=int(eval(input()))
rest_list = []
for i in range(N):
Si, Pi = input().split()
Pi = int(Pi)
rest_list.append((i+1,Si,Pi))
for i in range(N-1):
for j in range(i+1,N):
ii,Si,Pi = rest_list[i]
jj,Sj,Pj = rest_list[j]
if Si > Sj or (Si == Sj and Pi < Pj):
rest_list[i], rest_list[j] = (jj,Sj,Pj),(ii,Si,Pi)
for i in range(N):
i,Si,Pi = rest_list[i]
print(i)
|
N=int(eval(input()))
rest_list=[]
for i in range(N):
S,P=input().split()
rest_list.append((S,-int(P),i+1))
rest_list.sort()
for s,p,i in rest_list:
print(i)
|
p03030
|
n=int(eval(input()))
s=[[j for j in input().split()] for i in range(n)]
for i in range(n):
s[i][1]=int(s[i][1])
s[i].append(i)
s.sort(reverse=True,key=lambda x: x[1])
s.sort(key=lambda x: x[0])
for i in range(n):
print((s[i][2]+1))
|
n=int(eval(input()))
a=[list(input().split())+[i] for i in range(n)]
for i in range(n):
a[i][1]=-int(a[i][1])
a.sort()
for _,_,i in a:
print((i+1))
|
p03030
|
n=int(eval(input()))
l=[]
for i in range(n):
s,p=[x for x in input().rstrip().split()]
l.append([s,int(p),i+1])
l.sort(key=lambda x:x[1],reverse=True)
l.sort(key=lambda x:x[0])
for i,x,z in l:
print(z)
|
n=int(eval(input()))
l=[]
for i in range(n):
s,p=[x for x in input().rstrip().split()]
l.append([s,int(p),i+1])
l.sort(key=lambda x:x[1],reverse=True)
l.sort(key=lambda x:x[0])
for s,p,i in l:
print(i)
|
p03030
|
n = int(eval(input()))
sp = [input().split() for _ in range(n)]
a = []
for s,p in sp:
a.append([s, 100-int(p)])
A = sorted(a)
for i in range(n):
print((a.index(A[i])+1))
|
n = int(eval(input()))
sp = []
for i in range(n):
s,p = input().split()
sp.append([s, int(p), i+1])
sp.sort()
b = sp[0][0]
I = 0
ans = []
for s,p,i in sp:
if b == s:
ans.insert(I, i)
else:
ans.append(i)
b = s
I = len(ans)-1
print(("\n".join(map(str, ans))))
|
p03030
|
n = int(eval(input()))
spi = []
for i in range(n):
s,p = input().split()
spi.append([s,int(p), i+1])
spi.sort()
before = spi[0][0]
ans = [spi[0][2]]
for s,p,i in spi[1:]:
if s == before:
ans.append(i)
else:
for x in ans[::-1]:
print(x)
before = s
ans = [i]
for x in ans[::-1]:
print(x)
|
n = int(eval(input()))
spi = sorted([list(input().split())+[i+1] for i in range(n)])
ans = []
before = ""
for s,p,i in spi:
if ans == []:
ans = [[int(p),i]]
before = s
else:
if before == s:
ans.append([int(p),i])
else:
for j in sorted(ans)[::-1]: print((j[1]))
ans = [[int(p),i]]
before = s
if ans:
for i in sorted(ans)[::-1]: print((i[1]))
|
p03030
|
import collections
from operator import itemgetter
N = int(eval(input()))
SP = []
for i in range(N):
s,p = input().split()
SP.append([0,0])
SP[i][0] = s
SP[i][1] = int(p)
SP_new = sorted(SP)
t = 0
for i in range(N):
if t > 0:
t -= 1
continue
s = SP_new[i][0]
t = 0
for j in range(i+1, N):
if s == SP_new[j][0]:
t += 1
else:
break
SP_new_new = SP_new[i:i+t+1]
SP_new_new.sort(key = itemgetter(1))
for k in range(1,len(SP_new_new)+1):
u = SP_new_new[-k]
print((SP.index(u)+1))
|
N = int(eval(input()))
SP = []
for i in range(N):
s,p = input().split()
SP.append([0,0])
SP[i][0] = s
SP[i][1] = -int(p)
SP_new = sorted(SP)
for i in SP_new:
print((SP.index(i)+1))
|
p03030
|
# ABC 128: B – Guidebook
from operator import itemgetter
n = int(eval(input()))
s = []
p = []
for _ in range(n):
tmp = [s for s in input().split()]
s.append(tmp[0])
p.append(int(tmp[1]))
restaurants = []
for i in range(n):
restaurants.append([i + 1, s[i], p[i]])
restaurants.sort(key=itemgetter(2), reverse=True)
restaurants.sort(key=itemgetter(1))
for i in range(n):
print((restaurants[i][0]))
|
# ABC 128: B – Guidebook
N = int(eval(input()))
shops = []
for i in range(N):
s = input().split()
shops.append([i + 1, s[0], int(s[1])])
shops.sort(key = lambda x:x[2], reverse = True)
shops.sort(key = lambda x:x[1])
for k in [shop[0] for shop in shops]:
print(k)
|
p03030
|
N = int(eval(input()))
xy = []
for i in range(N):
x, y = list(map(str, input().split()))
y = int(y)
xy.append([x, y])
sort_xy = sorted(sorted(xy), key=lambda x: (x[0],-x[1]))
for i in range(N):
for j in range(N):
if sort_xy[i][0] == xy[j][0]:
if sort_xy[i][1] == xy[j][1]:
print((j + 1))
|
N = int(eval(input()))
xy = []
for i in range(N):
x, y = input().split()
xy.append([i + 1, x, int(y)])
sort_xy = sorted(sorted(xy), key=lambda x: (x[1],-x[2]))
for i in range(N):
print((sort_xy[i][0]))
|
p03030
|
n = int(eval(input()))
l = []
for i in range(n):
s, p = input().split()
p = int(p)
l.append([s, -p, i + 1])
l.sort()
for i in l:
print((i[2]))
|
n = int(eval(input()))
l = []
for i in range(n):
s, p = input().split()
p = -int(p)
l.append([s, p, i + 1])
l.sort()
for i in l:
print((i[2]))
|
p03030
|
N = int(eval(input()))
S = [""] * N
P = [0] * N
for i in range(N):
S[i], P[i] = input().split()
P[i] = int(P[i])
new_S = sorted(S)
same_v = []
same_i = []
for i, name in enumerate(new_S):
for k in range(N):
if new_S[i] == S[k]:
same_v.append(P[k])
same_i.append(k)
x = same_i[same_v.index(max(same_v))]
print((x + 1))
same_v = []
same_i = []
P[x] = -1
|
N = int(eval(input()))
SP = []
for i in range(N):
s, p = input().split()
SP.append([s] + [int(p)] + [i + 1])
new_SP = sorted(SP, key=lambda x: (x[0], -x[1]))
for _, _, i in new_SP:
print(i)
|
p03030
|
n = int(eval(input()))
dic = [[x for x in input().split()] for i in range(n)]
for i in range(n):
dic[i][1] = int(dic[i][1])
dic[i].append(i + 1)
dic.sort(key= lambda x: x[1], reverse= True)
dic.sort(key= lambda x: x[0])
for i in range(n):
print((dic[i][2]))
|
n = int(eval(input()))
dic = []
for i in range(n):
tmp = input().split()
dic.append([tmp[0], int(tmp[1]), i + 1])
dic.sort(key= lambda x: x[1], reverse= True)
dic.sort(key= lambda x: x[0])
for i in range(n):
print((dic[i][2]))
|
p03030
|
n = int(eval(input()))
dic = []
for i in range(n):
a, b = list(map(str, input().split()))
dic.append([a, int(b), i + 1])
dic.sort(key= lambda x: x[1], reverse= True)
dic.sort(key= lambda x: x[0])
for i in range(n):
print((dic[i][2]))
|
n = int(eval(input()))
dic = []
for i in range(n):
a, b = input().split()
dic.append([a, -int(b), i + 1])
dic.sort()
for i in range(n):
print((dic[i][2]))
|
p03030
|
def main(N, lst):
L = []
for i in range(len(lst)):
target = lst[i]
L.append({"id":i+1, "store":target[0], "point":int(target[1])})
L.sort(key = lambda x:x["point"], reverse = True)
L.sort(key = lambda x:x["store"])
for i in range(len(L)):
print((L[i]["id"]))
N = int(eval(input()))
lst = list(list(map(str, input().split())) for _ in range(N))
main(N, lst)
|
def main(N, lst):
L = []
for i in range(len(lst)):
target = lst[i]
L.append({"id":i+1, "store":target[0], "point":int(target[1])})
L.sort(key = lambda x:x["point"], reverse = True)
L.sort(key = lambda x:x["store"])
for i in range(len(L)):
print((L[i]["id"]))
N = int(eval(input()))
lst = list(list(map(str, input().split())) for _ in range(N))
main(N, lst)
|
p03030
|
n = int(eval(input()))
d = [list(map(str, input().split())) for i in range(n)]
for i in range(1, n+1):
d[i-1].append(i)
d[i-1][1] = int(d[i-1][1])
d.sort()
ans = []
tmp = []
now_city = d[0][0]
for i in range(n):
if now_city == d[i][0]:
tmp.append(d[i])
else:
tmp.sort(key=lambda x: x[1], reverse=True)
for j in range(len(tmp)):
ans.append(tmp[j][2])
tmp = []
tmp.append(d[i])
now_city = d[i][0]
tmp.sort(key=lambda x: x[1], reverse=True)
for j in range(len(tmp)):
ans.append(tmp[j][2])
for i in ans:
print(i)
|
n = int(eval(input()))
ans = []
for i in range(n):
c, p = input().split()
p = int(p)
ans.append([c, -p, i+1])
ans.sort()
for _ in ans:
print((_[2]))
|
p03030
|
N = int(eval(input()))
MAIN = []
for i in range(N):
S,P = list(map(str,input().split()))
MAIN.append([i+1,S,int(P)])
def swap(i,j):
x = MAIN[i]
MAIN[i] = MAIN[j]
MAIN[j] = x
update = True
while update == True:
update = False
for i in range(1,N):
if MAIN[i][1] > MAIN[i-1][1]:
continue
elif MAIN[i][1] == MAIN[i-1][1]:
if MAIN[i][2] > MAIN[i-1][2]:
swap(i,i-1)
update = True
else:
swap(i,i-1)
update = True
for m in MAIN:
print((m[0]))
|
N = int(eval(input()))
MAIN = []
for i in range(N):
S,P = list(map(str,input().split()))
MAIN.append([S,-int(P)])
ans = sorted(MAIN)
for m in ans:
print((MAIN.index(m) + 1))
|
p03030
|
#!/usr/bin/env python3
import sys
def solve(N: int, S: "List[str]", P: "List[int]"):
SP =[]
for i in range(N):
SP.append([S[i],P[i]])
t = sorted(SP, key=lambda x:(x[0],-x[1]))
# print(t)
ans = []
for x in t:
for j in range(N):
x1,x2 = x
if(x1 == S[j] and x2 == P[j]):
ans.append(j+1)
for i in ans:
print(i)
return
# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
S = [str()] * (N) # type: "List[str]"
P = [int()] * (N) # type: "List[int]"
for i in range(N):
S[i] = next(tokens)
P[i] = int(next(tokens))
solve(N, S, P)
if __name__ == '__main__':
main()
|
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000)
INF = 1<<32
def solve(N: int, S: "List[str]", P: "List[int]"):
sp = [[i, S[i], P[i]] for i in range(N)]
sp = sorted(sp, key=lambda x:(x[1],-x[2]))
for i in range(N):
print((sp[i][0]+1))
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
S = [str()] * (N) # type: "List[str]"
P = [int()] * (N) # type: "List[int]"
for i in range(N):
S[i] = next(tokens)
P[i] = int(next(tokens))
solve(N, S, P)
if __name__ == '__main__':
main()
|
p03030
|
n = int(eval(input()))
ls = []
for i in range(1,n+1):
s,p = input().split()
ls.append([i,s,int(p)])
ls.sort(key=lambda x: (x[1], -x[2]))
for j in range(len(ls)):
print((ls[j][0]))
|
n = int(eval(input()))
ls = []
for i in range(1,n+1):
s,p = input().split()
ls.append([i, s, int(p)])
ans = sorted(ls, key=lambda x: (x[1], -x[2]))
for j in range(n):
print((ans[j][0]))
|
p03030
|
n = int(eval(input()))
l = []
ans = []
for i in range(1, n+1):
s, p = input().split()
l.append([s, int(p), i])
ans = sorted(l, key=lambda x:(x[0],-x[1]))
for j in ans:
print((j[2]))
|
n = int(eval(input()))
l = []
for i in range(1, n+1):
s, p = input().split()
l.append([s, int(p), i])
l = sorted(l, key=lambda x: x[1],reverse=True)
l = sorted(l, key=lambda x: x[0])
for j in l:
print((j[2]))
|
p03030
|
N = int(eval(input()))
SP = [input().split() for _ in range(N)]
L = []
for i in range(N):
L.append([SP[i][0], int(SP[i][1]), i + 1])
L.sort(key = lambda x: x[1], reverse = True)
L.sort(key = lambda x: x[0])
for i in L:
print((i[2]))
|
N = int(eval(input()))
SP = [list(input().split()) + [i + 1] for i in range(N)]
for i in range(N):
SP[i][1] = -int(SP[i][1])
SP.sort()
for i in range(N):
print((SP[i][2]))
|
p03030
|
N = int(eval(input()))
SP = [[x+1] + list(input().split()) for x in range(N)]
SP2 = sorted(sorted(SP, key=lambda x:int(x[2]), reverse=True), key=lambda x:x[1])
for i in range(N):
print((SP2[i][0]))
|
N = int(eval(input()))
S = sorted((list((lambda y: (y[0], -int(y[1]), x))(input().split()))) for x in range(1, N+1))
for x in S:
print((x[2]))
|
p03030
|
n = int(eval(input()))
s = []
p = []
ans = [0]*n
for i in range(n):
s1,p1 = [str(i) for i in input().split()]
s.append(s1)
p.append(p1)
ans[i] = i + 1
for i in range(n):
p[i] = int(p[i])
flag = 1
while flag:
flag = 0
for i in range(n-1,0,-1):
if s[i] < s[i-1]:
s[i],s[i-1] = s[i-1],s[i]
p[i],p[i-1] = p[i-1],p[i]
ans[i],ans[i-1] = ans[i-1],ans[i]
flag = 1
flag = 1
while flag:
flag = 0
for i in range(n-1):
if s[i] == s[i+1] and p[i] < p[i+1]:
p[i],p[i+1] = p[i+1],p[i]
ans[i],ans[i+1] = ans[i+1],ans[i]
flag = 1
for i in range(n):
print((ans[i]))
|
n = int(eval(input()))
ans = [[] for i in range(n)]
for i in range(n):
ss,pp = list(map(str,input().split()))
ans[i].append(ss)
ans[i].append(int(pp))
ans[i].append(i+1)
ans.sort(key=lambda x: (x[0],-x[1]))
for i in range(n):
print((ans[i][2]))
|
p03030
|
def irekae(array2):
return [array2[1],array2[0],array2[2]]
n=int(eval(input()))
l=[input().split() for i in range(n)]
"""
# print(l)
for i in range(len(l)):
l[i].append(i+1)
l[i][1]=int(l[i][1])
# print(l)
l.sort()
# print(l)
for i in range(len(l)):
l[i]=irekae(l[i])
# print(l)
lsort=[]
while l!=[]:
"""
for i in range(len(l)):
l[i].append(i+1)
l[i][1]=int(l[i][1])
for i in range(len(l)):
l[i]=irekae(l[i])
#print(l)
l.sort(reverse=True)
#print(l)
for i in range(len(l)):
l[i]=irekae(l[i])
#print(l)
lx=sorted(l,key=lambda x: x[0])
#print(lx)
for i in range(len(lx)):
print((lx[i][2]))
|
def irekae(array2):
return [array2[1],array2[0],array2[2]]
n=int(eval(input()))
l=[input().split() for i in range(n)]
for i in range(len(l)):
l[i].append(i+1)
l[i][1]=int(l[i][1])
for i in range(len(l)):
l[i]=irekae(l[i])
l.sort(reverse=True)
for i in range(len(l)):
l[i]=irekae(l[i])
lx=sorted(l,key=lambda x: x[0])
for i in range(len(lx)):
print((lx[i][2]))
|
p03030
|
#B
from operator import itemgetter
n = int(eval(input()))
sp=[]
for i in range(n):
s,p=list(map(str,input().split()))
sp.append([s, int(p), i + 1])
# print(sp)
#itemgetter:呼び出し可能なオブジェクトを返す ex…f=itemgetter(2) f(a)>>a[2]
# sp = sorted(sp, key=lambda f: f[1], reverse=True)
# sp = sorted(sp, key=lambda f: f[0])
# print(sp)
sp.sort(key=itemgetter(1), reverse=True)
sp.sort(key=itemgetter(0))
# print(sp)
for i in range(n):
print((sp[i][2]))
|
#B
n = int(eval(input()))
sp = [list(input().split()) for i in range(n)]
for i in range(n):
sp[i].append(i + 1)
# print(sp)
sspp = sorted(sp, key=lambda x: int(x[1]), reverse=True)
sspp.sort(key=lambda x: x[0])
for i in range(n):
print((sspp[i][2]))
|
p03030
|
n=int(eval(input()))
l=[]
for i in range(n):
s,p=list(map(str,input().split()))
l.append([s,int(p),i+1])
l=sorted(l,reverse=True,key=lambda x:x[1])
l = sorted(l, key=lambda x:x[0])
for i in range(n):
print((l[i][-1]))
|
n=int(eval(input()))
l=[]
for i in range(n):
s,p=input().split()
p=int(p)*-1
l.append([s,p,i+1])
l.sort()
for i in l:
print((i[2]))
|
p03030
|
n=int(eval(input()))
rest=[input().split() for i in range(n)]
rest=[[rest[i][0],int(rest[i][1])] for i in range(n)]
for i in range(n):
rest[i].append(i+1)
rest.sort(key=lambda i:i[0])
#print(rest)
cnt=0
for i in range(1,n):
if rest[i-1][0]==rest[i][0]:
continue
else:
res=rest[cnt:i]
res.sort(key=lambda i:i[1],reverse=True)
#print(res)
for j in range(i-cnt):
print((res[j][2]))
cnt=i
#print(str(cnt)+'がcntです')
res=rest[cnt:n]
#print(res)
res.sort(key=lambda i:i[1],reverse=True)
for i in range(n-cnt):
print((res[i][2]))
|
n=int(input())
rest=[input().split()+[i+1] for i in range(n)]
rest.sort(key=lambda i:(i[0],-int(i[1])))
ans=[rest[i][2] for i in range(n)]
print(*ans,sep='\n')
|
p03030
|
n = int(eval(input()))
a= []
for i in range(n):
city, score = input().split()
score = int(score)
a.append((city, score, i+1))
a.sort(key=lambda k : (k[0], -k[1]))
for i in range(n):
print((a[i][2]))
|
n = eval(input())
n = int(n)
a= []
for i in range(n):
city, score = input().split()
score = int(score)
a.append((city, score, i+1))
a.sort(key=lambda k : (k[0], -k[1]))
for i in range(n):
print((a[i][2]))
|
p03030
|
from operator import itemgetter
N = int(input())
SP = []
d = {}
for i in range(1, N+1):
s, p = input().split()
SP.append([s, -int(p), i])
d[int(p)] = i
# SP.sort(key= lambda x:x[0])
# SP.sort(key=lambda x:x[1])
SP.sort()
[print(i[2]) for i in SP]
|
N = int(eval(input()))
SP = []
for i in range(1, N + 1):
s, p = input().split()
SP.append((s, int(p), i))
sp = sorted(SP, key=lambda x: x[1], reverse=True)
for i in sorted(sp, key=lambda x: x[0]):
print((i[2]))
|
p03030
|
#!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] = LS()
return l
sys.setrecursionlimit(1000000)
mod = 1000000007
#A
def A():
a,p = LI()
print(((a*3+p)//2))
return
#B
def B():
n = I()
s = [None for i in range(n)]
for i in range(n):
l = input().split()
s[i] = l+[i]
s.sort(key = lambda x:(x[0],-int(x[1])))
for i,a,b in s:
print((b+1))
return
#C
def C():
n = I()
return
#D
def D():
n = I()
return
#E
def E():
n = I()
return
#F
def F():
n = I()
return
#Solve
if __name__ == "__main__":
B()
|
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.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()
g = []
for i in range(n):
s,p = input().split()
p = int(p)
g.append((s,-p,i+1))
g.sort()
for a,b,i in g:
print(i)
return
#Solve
if __name__ == "__main__":
solve()
|
p03030
|
n = int(eval(input()))
ss = []
ps = []
sps = []
for i in range(n):
temp = input().split()
ss.append(temp[0])
ps.append(temp[1])
sps.append(temp[0] + ' ' + temp[1] + ' ' + str(i))
def check(sps):
city = sps[0].split()[0]
score = int(sps[0].split()[1])
# score = sps[0].split()[1]
index = int(sps[0].split()[2])
target = 0
for i in range(1, len(sps)):
# print(sps[i].split()[1])
# print(score)
if sps[i].split()[0] == city and score < int(sps[i].split()[1]):
# if sps[i].split()[0] == city and score < sps[i].split()[1]:
city = sps[i].split()[0]
score = int(sps[i].split()[1])
index = int(sps[i].split()[2])
target = i
elif sps[i].split()[0] < city:
city = sps[i].split()[0]
score = int(sps[i].split()[1])
index = int(sps[i].split()[2])
target = i
# print(index + 1)
# del sps[i]
# return index
return target, index
for i in range(n):
target, index = check(sps)
print((index + 1))
del sps[target]
|
n = int(eval(input()))
sps = []
for i in range(n):
line = input().split()
sps.append([line[0], -(int(line[1])), i + 1])
sps.sort()
for i in range(n):
print((sps[i][2]))
|
p03030
|
from collections import defaultdict
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
n = int(eval(input()))
SP = [[x for x in input().split()] for _ in range(n)]
ans_list = defaultdict(list)
for i, sp in enumerate(SP):
ans_list[sp[1]] = i
li = sorted(SP, key=lambda x: -int(x[1]))
li = sorted(li, key=lambda x: x[0])
#print(li)
#print(ans_list)
for x in li:
print((ans_list[x[1]]+1))
|
N = int(eval(input()))
SP = []
for i in range(N):
s, p = list(input().split())
SP.append([s, int(p), i+1])
SP.sort(key=lambda SP:(SP[0], -SP[1]))
for x in SP:
print((x[2]))
|
p03030
|
n=int(eval(input()))
sp=[]
for i in range(n):
x,y=input().split()
sp.append([x,int(y),i+1])
sp.sort(key=lambda x:(x[0],-x[1]))
for i in range(n):
print((sp[i][2]))
|
n = int(eval(input()))
l = []
for i in range(n):
x,y = list(map(str,input().split()))
l.append((x,y, i))
L = []
for i in range(n):
L.append((l[i][0], int(l[i][1]), l[i][2]))
L.sort(key = lambda L:(L[0],-L[1]))
for i in range(n):
print((L[i][2] + 1))
|
p03030
|
from operator import itemgetter
N = int(eval(input()))
L = []
for i in range(N):
S, P = input().split()
L.append((S, int(P), i + 1))
L = sorted(L, key=itemgetter(1), reverse=True)
L = sorted(L, key=itemgetter(0))
for l in L:
print((l[2]))
|
N = int(eval(input()))
L = []
for i in range(N):
S, P = input().split()
L.append((S, int(P), i + 1))
L.sort(key=lambda x: x[1], reverse=True)
L.sort(key=lambda x: x[0])
for l in L:
print((l[2]))
|
p03030
|
n = int(eval(input()))
s, p = [], []
for i in range(n):
inp = input().split()
s.append(inp[0])
p.append(int(inp[1]))
ans_list = list(i for i in range(1, n + 1))
for i in range(n):
index = i
for j in range(i, n):
if s[index] > s[j] or (s[index] == s[j] and p[index] < p[j]):
index = j
s[i], s[index] = s[index], s[i]
p[i], p[index] = p[index], p[i]
ans_list[i], ans_list[index] = ans_list[index], ans_list[i]
for i in ans_list:
print(i)
|
n = int(eval(input()))
sp = []
for i in range(n):
inp = input().split()
sp.append((inp[0], int(inp[1]), i + 1))
sp.sort(key=lambda x:(x[0], -x[1]))
for i in sp:
print((i[2]))
|
p03030
|
N = int(eval(input()))
A = [list(input().split()) for _ in range(N)]
A = sorted([(A[i][0],int(A[i][1]),i+1) for i in range(N)],key=lambda x:x[1],reverse=True)
A = sorted(A,key=lambda x:x[0])
for i in range(N):
print((A[i][2]))
|
N = int(eval(input()))
A = [list(input().split()) for _ in range(N)]
A = [(A[i][0],int(A[i][1]),i+1) for i in range(N)]
A = sorted(A,key=lambda x:x[1],reverse=True)
A = sorted(A,key=lambda x:x[0])
for i in range(N):
print((A[i][2]))
|
p03030
|
N = int(eval(input()))
data = []
for i in range(N):
name, point = input().split()
data.append((name, int(point), i))
data.sort(key=lambda x:(x[0], -x[1]))
for d in data:
print((d[2] + 1))
|
N = int(eval(input()))
data = []
for i in range(N):
name, point = input().split()
data.append((name, int(point), i))
data.sort(key=lambda x:-x[1])
data.sort(key=lambda x:x[0])
for d in data:
print((d[2] + 1))
|
p03030
|
N = int(eval(input()))
sp = [list(input().split()) for i in range(N)]
for i in range(N):
sp[i].append(i+1)
sorted_data = sorted(sp, key=lambda x:(x[0], -int(x[1])))
for i in range(N):
print((sorted_data[i][2]))
|
N = int(eval(input()))
D = [list(map(str,input().split())) for _ in range(N)]
for i in range(N):
D[i].append(i+1)
sorted_d = sorted(D, key = lambda x: (x[0], -int(x[1])))
for i in range(N):
print((sorted_d[i][2]))
|
p03030
|
import math
import itertools
import statistics
#import collections
#n = list(map(int, input().split()))
n = int(eval(input()))
data = []
for i in range(n):
s, p = input().split()
data.append((i+1, s, int(p)))
data.sort(key=lambda x:(x[1], -x[2]))
for i in range(n):
print((data[i][0]))
|
n = int(eval(input()))
s = []
for i in range(n):
x, y = list(input().split())
s.append([x, int(y), i+1])
ans = sorted(s, key=lambda x: (x[0], -x[1]))
for x, y, a in ans:
print(a)
|
p03030
|
n = int(eval(input()))
sp = [None]*n
for i in range(n):
sp[i] = [input().split(" "), i+1]
sp = list([[[x[0][0], int(x[0][1])], x[1]] for x in sp])
sl = list([x[0][0] for x in sp])
sp2 = []
for s in sorted(list(set(sl))):
l = list([x for x in sp if x[0][0] == s])
sp2.extend(sorted(l, key=lambda x:x[0][1], reverse=True))
for x in sp2:
print((x[1]))
|
n = int(eval(input()))
sp = [None]*n
for i in range(n):
sp[i] = input().split(" ")
sp = list([[x[0], int(x[1])] for x in sp])
sl = list([x[0] for x in sp])
sp2 = []
for s in sorted(list(set(sl))):
l = list([x for x in sp if x[0] == s])
sp2.extend(sorted(l, key=lambda x:x[1], reverse=True))
for x in sp2:
print((sp.index(x)+1))
|
p03030
|
n = int(eval(input()))
d1 = dict()
for i in range(n):
s, p = [x for x in input().split()]
if (s not in list(d1.keys())):
d1[s] = []
d1[s].append((int(p), i + 1))
else:
d1[s].append((int(p), i + 1))
for v in list(d1.values()):
v.sort(reverse = True)
l1 = list()
for k, v in list(d1.items()):
l1.append((k, v))
l1.sort()
for i in range(len(l1)):
for j in l1[i][1]:
print((j[1]))
|
from sys import stdin, stdout
n = int(stdin.readline().rstrip())
l = list()
for i in range(n):
s, p = [x for x in stdin.readline().rstrip().split()]
l.append((s, int(p)*(-1), i + 1))
l.sort()
for i in range(n):
print((l[i][2]))
|
p03030
|
import sys
sys.setrecursionlimit(10 ** 5)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return eval(input())
N = int(eval(input()))
X = {}
for i in range(1, N+1):
s, p = input().split()
if s in X:
X[s] += [(int(p), i)]
else:
X[s] = [(int(p), i)]
X = sorted(X.items())
for v in X:
a = sorted(v[1], reverse=True)
for i in a:
print((i[1]))
|
N = int(eval(input()))
A = []
for i in range(1,N+1):
c, s = input().split()
s = 100 - int(s)
A.append((c, s, i))
A.sort()
for a in A:
print((a[2]))
|
p03030
|
rests = {}
for i in range(int(eval(input()))):
S,P = input().split()
P = int(P)
if S in rests:
rests[S] += [[P,i]]
else:
rests[S] = [[P,i]]
r = sorted(rests.items()) #市の名前でソート
for city in r:
city[1].sort()
city[1].reverse()
for score,i in city[1]:
print((i+1))
|
lst = []
for i in range(int(eval(input()))):
S,P = input().split()
lst.append([S,int(P),i+1])
lst2 = sorted(lst, key=lambda x:x[1],reverse=True)
lst3 = sorted(lst2, key=lambda x:x[0],reverse=False)
for i in lst3:
print((i[2]))
|
p03030
|
n = int(eval(input()))
SP = []
for i in range(n):
s, p = input().split()
SP += [[s,int(p),i+1]]
SP.sort(key=lambda A:(A[0],-A[1]))
for sp in SP:
print((sp[2]))
|
N = int(eval(input()))
SP = []
for i in range(N):
s,p = input().split()
SP.append((s,-int(p),i+1))
SP.sort()
for s,p,i in SP:
print(i)
|
p03030
|
from operator import itemgetter
N = int(eval(input()))
SP = [input().split() for i in range(N)]
for k, v in enumerate(SP):
v.insert(0, str(k + 1))
v[2] = int(v[2])
# 降順
SP.sort(key=itemgetter(2), reverse=True)
# 昇順
SP.sort(key=itemgetter(1))
for sp in SP:
print((sp[0]))
|
N = int(eval(input()))
SP = {i+1: input().split() for i in range(N)}
for v in list(SP.values()):
v[1] = int(v[1])
# 降順
SP = sorted(list(SP.items()), key=lambda x: x[1][1], reverse=True)
# 昇順
SP = sorted(SP, key=lambda x: x[1][0])
for sp in SP:
print((sp[0]))
|
p03030
|
import copy
n = int(eval(input()))
l = [input().split() for i in range(n)]
index = copy.deepcopy(l)
for i in range(n):
l[i][1] = int(l[i][1])
index[i][1] = int(index[i][1])
l.sort(key=lambda x: x[1], reverse=True)
l.sort(key=lambda x: x[0], reverse=False)
for i in range(n):
for j in range(n):
if l[i] == index[j]:
print((j+1))
break
|
import copy
res_list = []
n = int(eval(input()))
for i in range(n):
name, score = input().split()
score = int(score)
res_list.append([name,score,i+1])
res_list.sort(key=lambda x: x[1],reverse=True)
res_list.sort(key=lambda x: x[0],reverse=False)
for i in res_list:
print((i[2]))
|
p03030
|
n = int(eval(input()))
sp = [input().split() for _ in range(n)]
for i in sorted(list(range(n)), key=lambda i: (sp[i][0], -int(sp[i][1]))):
print((i + 1))
|
n = int(eval(input()))
sp = [input().split() for _ in range(n)]
for (s, p), i in sorted(zip(sp, list(range(1, n + 1))), key=lambda x: (x[0][0], -int(x[0][1]))):
print(i)
|
p03030
|
from operator import itemgetter
N=int(eval(input()))
listA=[[] for i in range(N)]
listANS=[]
for i in range(N):
S,P=input().split()
listA[i]+=[S,int(P),i+1]
listA.sort()
before=0
if N!=1:
for i in range(1,N):
if listA[i-1][0]!=listA[i][0]:
listN=listA[before:i]
listN.sort(key=itemgetter(1),reverse=True)
listANS+=listN
before=i
if i==N-1:
listN=listA[before:N]
listN.sort(key=itemgetter(1),reverse=True)
listANS+=listN
else:
listANS=listA
for i in range(N):
print((listANS[i][2]))
|
N = int(eval(input()))
a = [input().split() +[i+1] for i in range(N)]
a = sorted(a ,key=lambda x:(x[0], -int(x[1])))
for i in range(N):
print((a[i][2]))
|
p03030
|
N = int(eval(input()))
ss = dict()
sss = dict()
for i in range(N):
s, p = input().split()
sss[s, p] = i + 1
if s in ss:
ss[s] = ss[s] + ',' + p
else:
ss[s] = p
ss_sorted = sorted(ss.items())
for tmp_ss in ss_sorted:
s = tmp_ss[0]
ps = list(map(int, tmp_ss[1].split(',')))
ps.sort(reverse=True)
for p in ps:
print((sss[s, str(p)]))
|
N = int(eval(input()))
ss = list()
for i in range(N):
s, p = input().split()
ss.append([s, int(p), i])
ss_sorted = sorted(ss, key=lambda x: (x[0], -x[1]))
for out in ss_sorted:
print((out[2] + 1))
|
p03030
|
n = int(eval(input()))
a = []
for i in range(1,n+1):
s, p = input().split()
p = int(p)
a.append((s, -p, i))
a.sort()
for s, p, i in a:
print(i)
|
n = int(eval(input()))
a = []
for i in range(1,n+1):
s, p = input().split()
a.append((s, -1*int(p), i))
a.sort()
for i in a:
print((i[2]))
|
p03030
|
n=int(eval(input()))
List=[]
for i in range(n):
s,p=input().split()
p=int(p)
List.append([s,p,i+1])
List.sort()
S=List[0][0]
k=[]
for i in List:
if i[0]==S:
k.append([i[1],i[2]])
else:
k.sort(reverse=True)
for j in k:
print((j[1]))
S=i[0]
k=[]
k.append([i[1],i[2]])
k.sort(reverse=True)
for j in k:
print((j[1]))
|
n=int(eval(input()))
List=[]
for i in range(n):
s,p=input().split()
p=-int(p)
List.append([s,p,i+1])
List.sort()
for i in List:
print((i[2]))
|
p03030
|
import math
import copy
class Score:
def set_data(self, town, score, idx):
self.town = set_town
self.score = set_score
self.idx = set_idx
inputa = input().split()
# inputb = input().split()
a = int(inputa[0])
# b = int(inputa[1])
# c = int(inputa[2])
# x = int(inputb[0])
# y = int(inputb[1])
# inputList=[]
# for i in range(a):
# inputNum = input()
# inputList.append(inputNum)
inputList=[]
for i in range(a):
inputItem = input().split()
inputItem.append(i+1)
inputList.append(inputItem)
# listb = []
# listb = [int(n) for n in inputb]
inputNameListSorted = []
tmp = sorted(inputList, key=lambda x:int(x[1]), reverse = True)
inputNameListSorted = sorted(tmp, key=lambda x:x[0])
for i in range(len(inputNameListSorted)):
print((inputNameListSorted[i][2]))
|
import sys
# import math
# import bisect
# import copy
# import heapq
# from collections import deque
# import decimal
# sys.setrecursionlimit(100001)
# INF = sys.maxsize
# MOD = 10 ** 9 + 7
ni = lambda: int(sys.stdin.readline())
ns = lambda: list(map(int, sys.stdin.readline().split()))
na = lambda: list(map(int, sys.stdin.readline().split()))
# ===CODE===
def main():
n = ni()
d = []
for i in range(n):
s, p = input().split()
d.append((s, int(p), i + 1))
tmp = sorted(d, key=lambda x: x[1], reverse=True)
tmp1 = sorted(tmp, key=lambda x: x[0])
for t in tmp1:
print((t[2]))
if __name__ == '__main__':
main()
|
p03030
|
n=int(eval(input()))
ls=[]
for i in range(1,n+1):
s,p=input().split()
ls.append([s,int(p),i])
ls.sort(key=lambda x: (x[0],-x[1]))
for i in range(len(ls)):
print((ls[i][2]))
##
|
n=int(eval(input()))
ans=[]
for i in range(n):
s,p=input().split()
ans.append([s,p,i+1])
ans.sort(key=lambda x:(x[0],-int(x[1])))
for i in range(n):
print((ans[i][2]))
|
p03030
|
N = int(eval(input()))
rests = {}
cities = []
lst = []
for i in range(N):
S, P = input().split()
cities.append(S)
lst.append((S, int(P)))
try:
rests[S].append(int(P))
rests[S].sort()
except KeyError:
rests[S] = [int(P)]
cities.sort()
order = [(city, rests[city].pop()) for city in cities]
for rest in order:
print((lst.index(rest) + 1))
|
N = int(eval(input()))
rests = []
for i in range(1, N+1):
S, P = input().split()
rests.append((S, int(P), i))
rests.sort(key=lambda x: x[0]+chr(100-x[1]))
for rest in rests:
print((rest[2]))
|
p03030
|
import operator
n = int(eval(input()))
s = []
p = []
for i in range(n):
x, y = input().split()
s.append((x, int(y), i+1))
s = sorted(s, key=lambda x:(x[0], -x[1]))
for c in s:
print((c[2]))
|
N = int(eval(input()))
points = []
for i in range(N):
city, point = input().split()
points.append((city, -int(point), i+1))
points.sort(key=lambda x:(x[0],x[1]))
for xs in points:
print((xs[2]))
|
p03030
|
n=int(eval(input()))
lists=[]
for x in range(n):
a,b=input().split()
lists.append([a,int(b),x+1])
lists.sort(key=lambda t:t[1],reverse=True)
lists.sort(key=lambda t:t[0])
for x in range(n):
print((lists[x][2]))
|
n=int(eval(input()))
l=[]
for i in range(n):
s,p=input().split()
l.append([i+1,s,int(p)])
l.sort(key=lambda x:x[2],reverse=True)
l.sort(key=lambda x:x[1])
for ll in l:
print((ll[0]))
|
p03030
|
n=int(eval(input()))
gr=[]
for i in range(n):
s,p=input().split()
p=int(p)
gr.append([[s,p],i])
gr=sorted(gr,key=lambda x:(x[0][0],-x[0][1]))
for i in range(len(gr)):
print((gr[i][1]+1))
|
N=int(eval(input()))
data = [None] * N
for i in range(N):
data[i] = list(input().split()) + [i+1]
data = sorted(data,key=lambda x:(x[0],-int(x[1])))
for d in data:
print((d[2]))
|
p03030
|
N = int(eval(input()))
l = []
for i in range(N):
s,p = input().split(" ")
l.append([s,-int(p),i+1])
l.sort()
for s,p,i in l:
print(i)
|
N = int(eval(input()))
l = []
for i in range(N):
s,p = input().split(" ")
l.append([s,-int(p),i+1])
l.sort()
for i in l:
print((i[2]))
|
p03030
|
a = int(eval(input()))
l = [list(input().split()) for i in range(a)]
b = sorted(l, key=lambda x:(x[0], -int(x[1])))
for i in b:
for k, j in enumerate(l, 1):
if j == i:
print(k)
|
n = int(eval(input()))
sp = []
for i in range(n):
s, p = input().split()
sp.append([s, int(p), i+1])
sp.sort(key=lambda sp:(sp[0],-sp[1]))
for i in sp:
print((i[2]))
|
p03030
|
def comp_rest(a,b):
if a[0] > b[0]:
return True
elif a[0] < b[0]:
return False
elif a[0] == b[0]:
return a[1] < b[1]
def solve():
N = int(input())
SP = []
for i in range(N):
SiPi = input().split()
Si = SiPi[0]
Pi = int(SiPi[1])
SP.append([Si, Pi, i+1])
for i in range(N):
for j in range(i+1, N):
if comp_rest(SP[i], SP[j]):
SP[i], SP[j] = SP[j], SP[i]
for i in range(N):
print(SP[i][2])
if __name__ == '__main__':
solve()
|
def solve():
N = int(input())
SP = []
for i in range(N):
SiPi = input().split()
Si = SiPi[0]
Pi = int(SiPi[1])
SP.append([Si, - Pi, i+1])
SP.sort()
for i in range(N):
print(SP[i][2])
if __name__ == '__main__':
solve()
|
p03030
|
import sys
from collections import defaultdict
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
def main():
N = int(readline())
d = defaultdict(list)
for i in range(N):
s, p = readline().strip().split()
p = int(p)
d[s].append((p, i+1))
for city, points in sorted(d.items()):
points = sorted(points, reverse=True)
for _, i in points:
print(i)
return
if __name__ == '__main__':
main()
|
import sys
from operator import itemgetter
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
def main():
N = int(readline())
A = [0] * N
for i in range(N):
s, p = readline().strip().split()
p = int(p)
A[i] = (s, p, i + 1)
A.sort(key=itemgetter(1), reverse=True)
A.sort(key=itemgetter(0))
for s, p, i in A:
print(i)
return
if __name__ == '__main__':
main()
|
p03030
|
print(('\n'.join([l[2] for l in sorted(sorted([[l[0], -int(l[1]), str(l[2] + 1)] for l in (input().split() + [i] for i in range(int(eval(input()))))], key=lambda x: x[1]), key=lambda x: x[0])])))
|
print(*[s[2] for s in sorted([input().split() + [i + 1] for i in range(int(input()))],key=lambda x:(x[0], -int(x[1])))],sep='\n')
|
p03030
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.