input
stringlengths 20
127k
| target
stringlengths 20
119k
| problem_id
stringlengths 6
6
|
---|---|---|
n, k = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))
#print(a)
fr = 0
ba = n+1
while ba-fr > 1:
mi = (ba+fr+1) // 2
x = a[mi-1]
if x >= k:
ba = mi
continue
#print(mi)
dp = [False] * (k+1)
dp[0] = True
for i in range(n):
if i == mi-1:
continue
y = a[i]
for j in range(k, -1, -1):
if j >= y:
dp[j] = dp[j] | dp[j-y]
#print(dp)
if sum(dp[k-x:k]):
ba = mi
else:
fr = mi
print(fr)
|
import sys
n, k = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))
#print(a)
fr = 0
ba = n+1
def check(mi):
x = a[mi-1]
if x >= k:
return True
#print(mi)
dp = [False] * (k+1)
dp[0] = True
for i in range(n):
if i == mi-1:
continue
y = a[i]
for j in range(k, -1, -1):
if j >= y:
dp[j] = dp[j] | dp[j-y]
if sum(dp[k-x:k]):
return True
else:
return False
if check(1):
print((0))
sys.exit()
if not check(n):
print(n)
sys.exit()
while ba-fr > 1:
mi = (ba+fr+1) // 2
if check(mi):
ba = mi
else:
fr = mi
print(fr)
|
p03782
|
from bisect import bisect_left, bisect_right
def solve():
N, K = list(map(int, input().split()))
As = list(map(int, input().split()))
As.sort()
i = bisect_left(As, K)
Bs = As[:i]
M = len(Bs)
def isOK(x):
isFounds = [False] * K
isFounds[0] = True
for i, B in enumerate(Bs):
if i == x: continue
for s in reversed(list(range(K-B))):
if isFounds[s]:
isFounds[s+B] = True
return any(isFounds[K-Bs[x]:])
ng, ok = -1, M
while abs(ok-ng) > 1:
mid = (ng+ok) // 2
if isOK(mid):
ok = mid
else:
ng = mid
print(ok)
solve()
|
from bisect import bisect_left, bisect_right
def solve():
N, K = list(map(int, input().split()))
As = list(map(int, input().split()))
As.sort()
i = bisect_left(As, K)
Bs = As[:i]
M = len(Bs)
def isOK(x):
bitset = 1<<(K-1)
for i, B in enumerate(Bs):
if i == x: continue
bitset |= bitset>>B
return bitset & ((1<<Bs[x])-1)
ng, ok = -1, M
while abs(ok-ng) > 1:
mid = (ng+ok) // 2
if isOK(mid):
ok = mid
else:
ng = mid
print(ok)
solve()
|
p03782
|
from bisect import bisect_left, bisect_right
from itertools import accumulate
def solve():
N, K = list(map(int, input().split()))
As = list(map(int, input().split()))
As.sort()
i = bisect_left(As, K)
Bs = As[:i]
M = len(Bs)
setSums = [{0}]
setSum = {0}
for B in Bs:
for s in list(setSum):
if s+B < K:
setSum.add(s+B)
setSums.append(setSum.copy())
setSumRevs = [{0}]
setSum = {0}
for B in reversed(Bs):
for s in list(setSum):
if s+B < K:
setSum.add(s+B)
setSumRevs.append(setSum.copy())
setSumRevs.reverse()
def isOK(x):
B = Bs[x]
numRevs = [0] * K
for s in setSumRevs[x+1]:
numRevs[s] = 1
accNumRevs = list(accumulate([0]+numRevs))
for s in setSums[x]:
if accNumRevs[K-s] - accNumRevs[max(0, K-s-B)] > 0:
return True
return False
ng, ok = -1, M
while abs(ok-ng) > 1:
mid = (ng+ok) // 2
if isOK(mid):
ok = mid
else:
ng = mid
print(ok)
solve()
|
from bisect import bisect_left, bisect_right
from itertools import accumulate
def solve():
N, K = list(map(int, input().split()))
As = list(map(int, input().split()))
As.sort()
i = bisect_left(As, K)
Bs = As[:i]
M = len(Bs)
bitsets = [1<<(K-1)]
bitset = 1<<(K-1)
for B in Bs:
bitset |= bitset>>B
bitsets.append(bitset)
bitsetRevs = [1<<(K-1)]
bitset = 1<<(K-1)
for B in reversed(Bs):
bitset |= bitset>>B
bitsetRevs.append(bitset)
bitsetRevs.reverse()
def isOK(x):
B = Bs[x]
numRevs = [0] * K
bitset = bitsetRevs[x+1]
for s in range(K):
if bitset & (1<<(K-1-s)):
numRevs[s] = 1
accNumRevs = list(accumulate([0]+numRevs))
bitset = bitsets[x]
for s in range(K):
if bitset & (1<<(K-1-s)):
if accNumRevs[K-s] - accNumRevs[max(0, K-s-B)] > 0:
return True
return False
ng, ok = -1, M
while abs(ok-ng) > 1:
mid = (ng+ok) // 2
if isOK(mid):
ok = mid
else:
ng = mid
print(ok)
solve()
|
p03782
|
import bisect
def preliminary(k, aaa):
dp = [False] * k
dp[0] = True
curr_max = 0
fwd = []
for a in aaa:
for i in range(min(curr_max, k - a - 1), -1, -1):
if dp[i]:
dp[i + a] = True
fwd.append(dp[:])
curr_max += a
dp = [False] * k
dp[0] = True
curr_max = 0
bwd = []
for a in reversed(aaa):
for i in range(min(curr_max, k - a - 1), -1, -1):
if dp[i]:
dp[i + a] = True
bwd.append([i for i, v in enumerate(dp) if v][1:])
curr_max += a
bwd.reverse()
dummy = [False] * k
dummy[0] = True
fwd.append(dummy)
bwd.append([])
return fwd, bwd
def get_judge(k, aaa):
fwd, bwd = preliminary(k, aaa)
cache = [None] * k
def judge(m):
am = aaa[m]
if cache[am] is None:
dp = fwd[m - 1]
ndp = dp[:]
for i in bwd[m + 1]:
for j in range(k - i - 1, -1, -1):
if dp[j]:
ndp[i + j] = True
cache[am] = any(ndp[-am:])
return cache[am]
return judge
def solve(k, aaa):
if sum(aaa) < k:
return n
aaa.sort()
aaa = aaa[:bisect.bisect_left(aaa, k)]
judge = get_judge(k, aaa)
l = 0
r = len(aaa) - 1
m = (l + r) // 2
while l <= r:
if judge(m):
r = m - 1
else:
l = m + 1
m = (l + r) // 2
return l
n, k = list(map(int, input().split()))
aaa = list(map(int, input().split()))
print((solve(k, aaa)))
|
import bisect
def solve(k, aaa):
aaa = aaa[:bisect.bisect_left(aaa, k)]
dp = [False] * k
dp[0] = True
curr_max = 0
ans = len(aaa)
for i, a in reversed(list(enumerate(aaa))):
if curr_max + a >= k:
ans = i
f = True
for j in range(min(curr_max, k - a - 1), -1, -1):
if dp[j]:
dp[j + a] = True
if f:
curr_max = max(curr_max, j + a)
f = False
return ans
n, k = list(map(int, input().split()))
aaa = list(map(int, input().split()))
aaa.sort()
print((solve(k, aaa)))
|
p03782
|
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
a.sort(reverse=True)
dp = [False] * (k)
dp[0] = True
min_n = 10**10
for i in a:
for j in range(k-1,-1,-1):
if(dp[j]):
if(j+i >= k):
min_n = i
else:
dp[j+i] = True
ans = 0
for i in a:
ans += (i < min_n)
print(ans)
|
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
a.sort(reverse=True)
mask = (1<<k)-1
dp = 1
min_n = 10**10
for i in a:
if(i >= k):
min_n = i
continue
dp |= (dp<<i)
if(dp > mask):
min_n = i
dp &= mask
ans = 0
for i in a:
ans += (i < min_n)
print(ans)
|
p03782
|
import sys
stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: list(map(int, stdin.readline().split()))
nl = lambda: list(map(int, stdin.readline().split()))
def solve():
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
def trans(v):
l = [0] * (k + 1)
for i in range(k + 1):
l[i] = (v & 1)
v >>= 1
return l
a.sort()
lef = [1] * n
rig = [1] * n
mask = (1 << (k + 1)) - 1
for i in range(n - 1):
lef[i + 1] = lef[i] | (lef[i] << a[i]) & mask
rig[-i - 2] = rig[-i - 1] | (rig[-i - 1] << a[-i - 1]) & mask
ok = -1
ng = n
while ng - ok > 1:
mid = (ng + ok) // 2
lc = trans(lef[mid])
rc = trans(rig[mid])
# print(a[mid], lc, rc)
rcs = [0] * (k + 2)
for i in range(k + 1):
rcs[i + 1] = rcs[i] + rc[i]
for i in range(k + 1):
if lc[i] and rcs[k - i] - rcs[max(k - a[mid] - i, 0)] > 0:
ng = mid
break
else:
ok = mid
print((ok + 1))
if __name__ == '__main__':
solve()
|
n, k = list(map(int,input().split()))
a = [k+1 if x > k else x for x in map(int,input().split())]
a.sort()
lef = [1]*n
rig = [1]*n
mask = (1 << (k+1)) - 1
for i in range(n-1):
lef[i+1] = lef[i] | (lef[i] << a[i]) & mask
rig[-i-2] = rig[-i-1] | (rig[-i-1] << a[-i-1]) & mask
ok = -1
ng = n
while ng - ok > 1:
mid = (ng + ok) // 2
if a[mid] >= k:
ng = mid
continue
lc = lef[mid]
rc = rig[mid]
cov = ((1 << k) - 1) ^ ((1 << (k - a[mid])) - 1)
for i in range(k):
if lc & 1 and rc & cov:
ng = mid
break
lc >>= 1
cov >>= 1
else:
ok = mid
print((ok + 1))
|
p03782
|
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())
from collections import Counter
n,k = li()
a = li()
a = [ai for ai in a if ai <= k]
a.sort()
cnt = Counter(a)
ans = 0
for ai in a:
ai_pass = True
a_wo_ai = [aj for aj in a]
a_wo_ai.remove(ai)
dp = [[0 for _ in range(k)] for _ in range(len(a_wo_ai)+1)]
dp[0][0] = 1
for i, aj in enumerate(a_wo_ai):
for sm in range(k):
dp[i+1][sm] += dp[i][sm]
if sm-aj >= 0:
dp[i+1][sm] += dp[i][sm-aj]
if sum(dp[len(a_wo_ai)][k-ai:]) == 0:
ans += 1
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())
from collections import Counter
n,k = li()
a = li()
a = [ai for ai in a if ai <= k]
a.sort()
cnt = Counter(a)
ans = 0
left = 0
right = len(a)+1
while right - left > 1:
mid = (right+left) // 2
ai = a[mid-1]
ai_pass = True
a_wo_ai = [aj for aj in a]
a_wo_ai.remove(ai)
dp = [[0 for _ in range(k)] for _ in range(len(a_wo_ai)+1)]
dp[0][0] = 1
for i, aj in enumerate(a_wo_ai):
for sm in range(k):
dp[i+1][sm] += dp[i][sm]
if sm-aj >= 0:
dp[i+1][sm] += dp[i][sm-aj]
if sum(dp[len(a_wo_ai)][k-ai:]) == 0:
left = mid
else:
right = mid
print(left)
|
p03782
|
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
from copy import deepcopy
N, K = inpl()
A = sorted(inpl())
S = []
s = 0
for a in A:
s += a
S.append(s)
A = A[::-1]
DP = [False for _ in range(K)]
DP[0] = 1
OK = [False for _ in range(N)]
for i, a in enumerate(A):
DP0 = deepcopy(DP)
if a >= K:
OK[i] = True
continue
for j, d in enumerate(DP0[-S[::-1][i]:], max(0, K-S[::-1][i])):
if d:
if j + a >= K:
OK[i] = True
break
else:
DP[j+a] = True
if sum(OK) == 0:
print(N)
else:
print((OK[::-1].index(True)))
|
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
N, K = inpl()
A = sorted(inpl())
S = []
s = 0
for a in A:
s += a
S.append(s)
A = A[::-1]
DP = [True]+[False for _ in range(K-1)]
OK = [False for _ in range(N)]
for i, a in enumerate(A):
DP1 = [False] * K
if a >= K:
OK[i] = True
continue
for j, d in enumerate(DP[-S[::-1][i]:], max(0, K-S[::-1][i])):
if d:
DP1[j] = True
if j + a >= K:
OK[i] = True
break
else:
DP1[j+a] = True
DP = DP1
if sum(OK) == 0:
print(N)
else:
print((OK[::-1].index(True)))
|
p03782
|
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
N, K = inpl()
A = sorted(inpl())
S = []
s = 0
for a in A:
s += a
S.append(s)
A = A[::-1]
DP = [True]+[False for _ in range(K-1)]
OK = [False for _ in range(N)]
for i, a in enumerate(A):
DP1 = [False] * K
if a >= K:
OK[i] = True
continue
for j, d in enumerate(DP[-S[::-1][i]:], max(0, K-S[::-1][i])):
if d:
DP1[j] = True
if j + a >= K:
OK[i] = True
break
else:
DP1[j+a] = True
DP = DP1
if sum(OK) == 0:
print(N)
else:
print((OK[::-1].index(True)))
|
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
N, K = inpl()
A = sorted(inpl())
S = []
s = 0
for a in A:
s += a
S.append(s)
A = A[::-1]
DP = [True]+[False for _ in range(K-1)]
OK = [False for _ in range(N)]
for i, a in enumerate(A):
DP1 = [False for _ in range(K)]
if a >= K:
OK[i] = True
continue
for j, d in enumerate(DP):
if d:
DP1[j] = True
if j + a >= K:
OK[i] = True
else:
DP1[j+a] = True
DP = DP1
if sum(OK) == 0:
print(N)
else:
print((OK[::-1].index(True)))
|
p03782
|
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
dp = [[0]*(k + 1) for i in range(n + 1)]
dp[0][0] = 1
for i in range(n):
for j in range(k+1):
if j - a[i] < 0:
dp[i+1][j] = dp[i][j]
else:
dp[i+1][j] = dp[i][j] + dp[i][j - a[i]]
dp = dp[n]
ans = 0
for i in range(n):
tmp = dp[0:]
if a[i] > k:
continue
for j in range(a[i], k + 1):
tmp[j] = dp[j] - tmp[j - a[i]]
if max(tmp[k-a[i]:k]) <= 0:
ans += 1
print(ans)
|
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a = [0] + sorted(a) + [k]
def subset_sum(mid):
if a[mid] > k:
return False
li = a[0:mid] + a[mid+1:]
n = len(li)
dp = [False]*(k + 1)
dp[0] = True
for i in range(n):
for j in range(k+1)[::-1]:
if j - li[i] < 0:
break
else:
dp[j] = dp[j] or dp[j - li[i]]
if not any(dp[k-a[mid]:k]):
return True
else:
return False
ok = 0
ng = n+2
while abs(ng - ok) > 1:
mid = (ok + ng) // 2
if subset_sum(mid):
ok = mid
else:
ng = mid
print(ok)
|
p03782
|
N,K = list(map(int,input().split()))
a = list(map(int,input().split()))
ans = [False] * N
able = [False] * (2*K+1)
able[0] = True
lis = [ [False] * N for i in range(2*K+1) ]
for i,na in enumerate(a):
if na >= K:
ans[i] = True
continue
nable = able.copy()
for j in range(K):
if able[j]:
for nown in range(N):
if not lis[j+na][nown] and lis[j][nown]:
lis[j + na][nown] = True
lis[j+na][i] = True
nable[j+na] = True
able = nable
for i,na in enumerate(a):
if na < K:
for j in range(K,K+na,1):
if lis[j][i]:
ans[i] = True
#print (able)
r = N
for i in ans:
if i:
r -= 1
print (r)
|
N,K = list(map(int,input().split()))
a = list(map(int,input().split()))
ans = N
q = 0
a.sort()
a.reverse()
nmax = 0
for i in range(N):
q += 1
if nmax + a[i] >= K:
ans -= q
q = 0
else:
nmax = nmax + a[i]
print (ans)
|
p03782
|
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline
n,k,*a = list(map(int,read().split()))
a = [i for i in a if i<k]
n = len(a)
mask = (1<<k)-1
dpl = [1]
dp = 1
for i in a:
dp |= dp<<i
dp &= mask
dpl.append(dp)
dpr = [1]
dp = 1
for i in a[::-1]:
dp |= dp<<i
dp &= mask
dpr.append(dp)
ans = 0
for i in range(n):
l = dpl[i]
r = dpr[n-1-i]
#print(bin(l),bin(r))
mask = ((1<<a[i])-1)<<(k-a[i])
#print(bin(mask))
for j in range(k):
if l>>j&1 and r&mask:
break
mask >>= 1
else:
#print(i)
ans += 1
print(ans)
|
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline
n,k,*a = list(map(int,read().split()))
a = [i for i in a if i<k]
n = len(a)
a.sort(reverse=True)
K = 2*k+1
mask = (1<<K)-1
dpl = [1]
dp = 1
for i in a:
dp |= (dp<<i)&mask
dpl.append(dp)
#print(dpl)
for i in range(n):
x = dpl[n-1-i]<<a[n-1-i]
mask = ((1<<a[n-1-i])-1)<<(k)
#print(bin(x)[::-1])
#print(bin(mask)[::-1])
if x&mask:
print(i)
break
else: print(n)
|
p03782
|
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A = [a for a in A if a <K]
N = len(A)
dpm = [[0]*(K+1) for _ in range(N+1)]
dpm[0][0] = 1
for i, a in enumerate(A):
for j in range(K, -1, -1):
dpm[i+1][j] = dpm[i][max(0, j-a)] + dpm[i][j]
r = 0
dp2 = 1
for i, a in enumerate(A[::-1]):
for j in range(K, -1, -1):
# 後ろiこの合計がjのもの
if dp2&(1<<j) and dpm[N-i-1][max(0, K-j-a)] > dpm[N-i-1][K-j]:
# K-j > x >= K-j-a
break
else:
r += 1
dp2 |= dp2<<a
dp2 &= (1<<(K+1))-1
print(r)
|
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A = [a for a in A if a <K]
N = len(A)
#dpm = [+1) for _ in range(N+1)]
dpm = [0]*(N+1)
dpm[0] = 1<<(K-1)
for i, a in enumerate(A):
dpm[i+1] = dpm[i] | (dpm[i] >> a)
#print(bin(dpm[-1]))
r = 0
dp2 = 1
for i, a in enumerate(A[::-1]):
# print(bin(dpm[N-i-1]))
tmp = dpm[N-i-1]
for j in range(1, a):
tmp |= tmp>>1
# print(bin(tmp), bin(dp2), len(bin(tmp)))
if not dp2&tmp:
# print("aa")
r += 1
# for j in range(K, -1, -1):
# 後ろiこの合計がjのもの
# if dp2&(1<<j) and dpm[N-i-1][max(0, K-j-a)] > dpm[N-i-1][K-j]:
# K-j > x >= K-j-a
# break
# else:
# r += 1
dp2 |= dp2<<a
dp2 &= (1<<K)-1
print(r)
|
p03782
|
while True:
a, l = list(map(int, input().split()))
if((a|l) == 0): break
dic = {}
cnt = 0
dic[a] = cnt
while True:
cnt+=1
Sa = str(a)
Sa = [ x for x in list(Sa) if x is not '0']
if len(Sa) is 0: Sa.append('0')
Sa.sort()
S = int("".join(Sa))
La = [x for x in Sa]
La.reverse()
while len(La) < l: La.append('0')
L = int("".join(La))
a = L - S
if a in dic:
print(dic[a], a, cnt - dic[a])
break
else:
dic[a] = cnt
|
while True:
a, l = list(map(int, input().split()))
if((a|l) == 0): break
dic = {}
cnt = 0
dic[a] = cnt
while True:
cnt+=1
La = list(str(a).zfill(l))
La.sort()
a = int(''.join(La[::-1])) - int(''.join(La))
if a in dic:
print(dic[a], a, cnt-dic[a])
break
else:
dic[a] = cnt
|
p00761
|
def is_unique2(seq):
seen = []
unique_list = [x for x in seq if x not in seen and not seen.append(x)]
return len(seq) == len(unique_list)
while True:
iCount = 0
n = input().split()
if int(n[1]) == 0:
break
num = n.pop(0)
m = int(n[0])
numStr = list(num)
while len(numStr) < m:
numStr.insert(0, "0")
numSub = [int(numStr[l]) for l in range(m)]
num0 = "".join([str(k) for k in numSub])
count = []
count.append(num0)
answer = "False"
while answer:
numSub.sort()
#print(numSub)
Min = "".join([str(j) for j in numSub])
numSub.reverse()
#print(numSub)
Max = "".join([str(i) for i in numSub])
num1 = int(Max) - int(Min)
num1 = str(num1)
xxx = list(num1)
while len(xxx) < m:
xxx.insert(0, "0")
numSub = [int(xxx[g]) for g in range(m)]
xxxx = "".join([str(h) for h in xxx])
count.append(str(xxxx))
answer = is_unique2(count)
iCount += 1
print(count.index(count[-1]) ,end=" ")
print(int(count[-1]) ,end=" ")
print(str(iCount - count.index(count[-1])))
|
def is_unique2(seq):#後のwhile文でのループ脱出のため
seen = []
unique_list = [x for x in seq if x not in seen and not seen.append(x)]
return len(seq) == len(unique_list)
while True:
iCount = 0#問のiの部分の値です
n = input().split()
if int(n[1]) == 0:#入力の終わりを受けとった時breakする
break
a0 = n.pop(0)#a0は問のa0の値を受け取ってます
L = int(n[0])#Lは問のLの値を受け取ってます
numStr = list(a0)#a0を一文字ずつ分けてnumStrのリストに入れてます
while len(numStr) < L:#桁数が足りないとき、一番大きな位に0を入れてます
numStr.insert(0, "0")
numInt = [int(numStr[l]) for l in range(L)]#strからintへ型を変えてnumStrをnumIntに入れてます
A0 = "".join([str(k) for k in numInt])#numIntのリストの一文字ずつの数字を全部繋げてstr型としてA0に入れます(数値的にはa0と同値です)
count = []#a0,a1,a2,a3...ai(i < 20)の値を入れるcountリストを作ります
count.append(A0)#そのcountリストの中にまずA0を入れます
answer = "False"
while answer:#answerがTrueを受け取ったときこのループを抜けます
numInt.sort()#numIntのリストの中の数字が昇順に並び替えられます
Min = "".join([str(j) for j in numInt])#numIntのリストの一文字ずつの数字を全部繋げてstr型としてMinに入れます(数値的には並び替えてできる最小の整数)
numInt.reverse()#numIntのリストの中の数字が降順に並び替えられます
Max = "".join([str(i) for i in numInt])#numIntのリストの一文字ずつの数字を全部繋げてstr型としてMaxに入れます(数値的には並び替えてできる最大の整数)
ax = str(int(Max) - int(Min))#MaxからMinを引いてAx(x=1~20)の値をstr型でaxに入れます
numStr = list(ax)#axを一文字ずつ分けてnumStrのリストに入れてます(numStrではなく別の関数でも良いが、解りやすい為numStrに入れてます)
while len(numStr) < L:#桁数が足りないとき、一番大きな位に0を入れてます
numStr.insert(0, "0")
numInt = [int(numStr[g]) for g in range(L)]#strからintへ型を変えてnumStrをnumIntに入れてます(whileのループ処理のためnumIntに入れてます)
Ax = "".join([str(h) for h in numInt])#numIntのリストの一文字ずつの数字を全部繋げてstr型としてAx(x=1~20)に入れます(数値的にはax(x=1~20)と同値です)
count.append(str(Ax))#a0,a1,a2...aiの値を入れるcountリストの中にAxを入れます
answer = is_unique2(count)#countリスト内に同じ値が二つあるとき、answerはTrueを受け取り、while文のループから抜け出します
iCount += 1#今Ax番目の計算を行ったことを示し、answerがTrueを受け取った際は、それがAi番目となる
print(count.index(count[-1]) ,end=" ")#Ajのjの値を出力(スペース開けて改行しない)
print(int(count[-1]) ,end=" ")#Aiの値を出力(スペース開けて改行しない)
print(str(iCount - count.index(count[-1])))#Aiのi-Ajのjの値を出力
|
p00761
|
N = int(eval(input()))
s = [0]*N
l = [0]*N
for i in range(N):
a, b = list(map(int, input().split()))
s[i] = (a, b)
for i in range(N):
c, d = list(map(int, input().split()))
l[i] = (c, d)
V = N*2 # 頂点数
MAX_V = V
G = [0]*MAX_V # グラフの隣接リスト表現
for i in range(MAX_V):
G[i] = []
match = [0]*MAX_V # マッチングのペア
used = [False]*MAX_V # DFSで既に調べたかのフラグ
# uとvを結ぶ辺をグラフに追加する
def addEdge(u, v):
G[u].append(v)
G[v].append(u)
##
for a in range(N):
(rx, ry) = s[a]
for b in range(N):
(bx, by) = l[b]
if rx < bx and ry < by:
addEdge(a, b+N)
# 増加パスをDFSで探す
def dfs(v):
used[v] = True
for i in range(len(G[v])):
u = G[v][i]
w = match[u]
if w < 0 or (not used[w]) and dfs(w):
match[v] = u
match[u] = v
return True
return False
# 二部グラフの最大マッチングを求める
def bipartiteMatching():
res = 0
for i in range(len(match)):
match[i] = -1
for v in range(V):
if match[v] < 0:
for i in range(len(used)):
used[i] = False
if dfs(v):
res += 1
return res
#print(G)
#print(match)
print((bipartiteMatching()))
|
N = int(eval(input()))
s = [0]*N
l = [0]*N
for i in range(N):
a, b = list(map(int, input().split()))
s[i] = (a, b)
for i in range(N):
c, d = list(map(int, input().split()))
l[i] = (c, d)
V = N*2 # 頂点数
MAX_V = V
G = [0]*MAX_V # グラフの隣接リスト表現
for i in range(MAX_V):
G[i] = []
match = [0]*MAX_V # マッチングのペア
used = [False]*MAX_V # DFSで既に調べたかのフラグ
# uとvを結ぶ辺をグラフに追加する
def addEdge(u, v):
G[u].append(v)
G[v].append(u)
##
for a in range(N):
(rx, ry) = s[a]
for b in range(N):
(bx, by) = l[b]
if rx < bx and ry < by:
addEdge(a, b+N)
# 増加パスをDFSで探す
def dfs(v):
used[v] = True
for i in range(len(G[v])):
u = G[v][i]
w = match[u]
if w < 0 or not used[w] and dfs(w):
match[v] = u
match[u] = v
return True
return False
# 二部グラフの最大マッチングを求める
def bipartiteMatching():
res = 0
for i in range(len(match)):
match[i] = -1
for v in range(V):
if match[v] < 0:
for i in range(len(used)):
used[i] = False
if dfs(v):
res += 1
return res
print((bipartiteMatching()))
|
p03411
|
n = int(eval(input()))
ab = set(tuple(map(int, input().split())) for _ in range(n))
cd = sorted(tuple(map(int, input().split())) for _ in range(n))
ab |= {(-1, -1)}
for c, d in cd:
tmp = max((b, a) for a, b in ab if (a < c and b < d))[::-1]
if tmp != (-1, -1):
ab.remove(tmp)
print((n - (len(ab) - 1)))
|
n = int(eval(input()))
ab = set(tuple(map(int, input().split())) for _ in range(n))
cd = sorted(tuple(map(int, input().split())) for _ in range(n))
ab |= {(-1, -1)}
for c, d in cd:
tmp = max((b, a) for a, b in ab if (a < c and b < d))
if tmp != (-1, -1):
ab.remove(tmp[::-1])
print((n - (len(ab) - 1)))
|
p03411
|
n = int(eval(input()))
ab = set(tuple(map(int, input().split())) for _ in range(n))
cd = sorted(tuple(map(int, input().split())) for _ in range(n))
ab |= {(-1, -1)}
ans = 0
for c, d in cd:
tmp = max((b, a) for a, b in ab if (a < c and b < d))
if tmp != (-1, -1):
ab.remove(tmp[::-1])
ans += 1
print((n - (len(ab) - 1)))
|
n = int(eval(input()))
ab = set(tuple(map(int, input().split())) for _ in range(n))
cd = sorted(tuple(map(int, input().split())) for _ in range(n))
ab |= {(-1, -1)}
ans = 0
for c, d in cd:
tmp = max((b, a) for a, b in ab if (a < c and b < d))
if tmp != (-1, -1):
ab.remove(tmp[::-1])
ans += 1
print(ans)
|
p03411
|
N = int(eval(input()))
R = [tuple(map(int, input().split())) for _ in range(N)]
B = [tuple(map(int, input().split())) for _ in range(N)]
dp = {}
def check(v, p):
return p & (1 << v)
def visit(v, p):
return p ^ (1 << v)
def count(p):
return bin(p).count('1')
def solve(i, p):
if i == N:
return count(p)
k = (i, p)
if k in dp:
return dp[k]
a, b = R[i]
# ペアにならなかった
m = solve(i+1, p)
for j, (c, d) in enumerate(B):
# すでにペアを持つ要素は無視
if check(j, p):
continue
# ペアになった
if a < c and b < d:
m = max(m, solve(i+1, visit(j, p)))
dp[k] = m
return m
print((solve(0, 0)))
|
N = int(eval(input()))
R = [tuple(map(int, input().split())) for _ in range(N)]
B = [tuple(map(int, input().split())) for _ in range(N)]
R.sort(reverse=True, key=lambda k: k[1])
B.sort()
p = []
q = []
for c, d in B:
for a, b in R:
if (a, b) in p:
continue
if a < c and b < d:
p.append((a, b))
q.append((c, d))
break
print((len(p)))
|
p03411
|
N=int(eval(input()))
a=[0 for i in range(N)]
b=[0 for i in range(N)]
c=[0 for i in range(N)]
d=[0 for i in range(N)]
for i in range(N):
a[i], b[i] = list(map(int, input().split()))
for i in range(N):
c[i], d[i] = list(map(int, input().split()))
m=[[0 for i in range(N)] for i in range(N)]
s=[set() for i in range(N)]
for i in range(N):
for j in range(N):
if a[i]<c[j] and b[i]<d[j]:
m[i][j]+=1
s[i].add(j)
ans=0
import itertools
q=list(itertools.permutations(list(range(N))))
for sg in q:
z=0
for i in range(N):
z+=m[i][sg[i]]
if ans<z:
ans=z
print(ans)
|
N=int(eval(input()))
r=[(0,0) for i in range(N)]
b=[(0,0) for i in range(N)]
for i in range(N):
x,y=list(map(int,input().split()))
r[i]=(x,y)
for i in range(N):
x,y=list(map(int,input().split()))
b[i]=(x,y)
b.sort()
ru=[0 for i in range(N)]
ans=0
for i in range(N):
k=-1
for j in range(N):
if b[i][0]>r[j][0] and b[i][1]>r[j][1]:
if k==-1 and ru[j]==0:
k=j
elif r[k][1]<r[j][1] and ru[j]==0:
k=j
if k!=-1:
ru[k]=1
ans+=1
print(ans)
|
p03411
|
#!python3
INF = 10 ** 15
# input
N = int(eval(input()))
a, b, c, d = [None] * N, [None] * N, [None] * N, [None] * N
for i in range(N):
a[i], b[i] = list(map(int, input().split()))
for i in range(N):
c[i], d[i] = list(map(int, input().split()))
class MaxFlow():
def __init__(self, n):
self.n = n
self.c = [[0] * n for _ in range(n)]
self.visit = [False] * n
self.link = [set() for _ in range(n)]
def add_link(self, x, y, capa):
self.c[x][y] += capa
self.link[x].add(y)
def solve(self, t, v, f):
if v == t:
return f
self.visit[v] = True
w = 0
for i in self.link[v]:
if self.visit[i] or self.c[v][i] == 0:
continue
d = self.solve(t, i, min(f - w, self.c[v][i]))
if d > 0:
self.c[v][i] -= d
self.c[i][v] += d
self.link[i].add(v)
w += d
if w == f:
break
self.visit[v] = False
return w
def main():
w = MaxFlow(2 * N + 2)
for i in range(N):
w.add_link(0, i + 1, 1)
w.add_link(N + i + 1, 2 * N + 1, 1)
for j in range(N):
if a[i] < c[j] and b[i] < d[j]:
w.add_link(i + 1, N + j + 1, 1)
ans = w.solve(2 * N + 1, 0, INF)
print(ans)
if __name__ == "__main__":
main()
|
#!python3
INF = 10 ** 15
# input
N = int(eval(input()))
a, b, c, d = [None] * N, [None] * N, [None] * N, [None] * N
for i in range(N):
a[i], b[i] = list(map(int, input().split()))
for i in range(N):
c[i], d[i] = list(map(int, input().split()))
class MaxFlow():
def __init__(self, n):
self.n = n
self.c = [[0] * n for _ in range(n)]
self.visit = [False] * n
def add_link(self, x, y, capa):
self.c[x][y] += capa
def dfs(self, v, t, f):
if v == t:
return f
self.visit[v] = True
for i in range(self.n):
if self.visit[i] or self.c[v][i] == 0:
continue
d = self.dfs(i, t, min(f, self.c[v][i]))
if d > 0:
self.c[v][i] -= d
self.c[i][v] += d
return d
return 0
def max_flow(self, s, t):
ans = 0
while True:
f = self.dfs(s, t, INF)
self.visit = [False] * self.n
if f == 0:
return ans
else:
ans += f
def main():
w = MaxFlow(2 * N + 2)
for i in range(N):
w.add_link(0, i + 1, 1)
w.add_link(N + i + 1, 2 * N + 1, 1)
for j in range(N):
if a[i] < c[j] and b[i] < d[j]:
w.add_link(i + 1, N + j + 1, 1)
ans = w.max_flow(0, 2 * N + 1)
print(ans)
if __name__ == "__main__":
main()
|
p03411
|
N=int(eval(input()))
RED=[tuple(map(int, input().split())) for _ in range(N)]
BLUE=[tuple(map(int, input().split())) for _ in range(N)]
RED.sort(key=lambda x:x[1], reverse=True)
BLUE.sort(key=lambda x:x[0])
ans=0
r_used=[False]*N
for b in BLUE:
for j,r in enumerate(RED):
if r_used[j]: continue
if r[0]<b[0] and r[1]<b[1]:
ans+=1
r_used[j]=True
break
print(ans)
|
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, AB, CD):
ans = 0
AB.sort(key=lambda x: x[0], reverse=True)
for a, b in AB:
CD.sort(key=lambda x: x[1])
idx = 0
while idx < len(CD):
c, d = CD[idx]
if a < c and b < d:
break
idx += 1
else:
continue
ans += 1
del CD[idx]
print(ans)
if __name__ == '__main__':
input = sys.stdin.readline
N = int(eval(input()))
AB = [tuple(map(int, input().split())) for _ in range(N)]
CD = [tuple(map(int, input().split())) for _ in range(N)]
main(N, AB, CD)
|
p03411
|
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return list(map(int,input().split()))
def lmp(): return list(map(int,input().split()))
a=int(eval(input()))
print((a+a**2+a**3))
|
a=int(eval(input()))
print((a+a**2+a**3))
|
p02621
|
#!/usr/bin/python3
a = int(eval(input()))
ans = a + a**2 + a**3
print(ans)
|
a = int(eval(input()));print((a + a**2 + a**3))
|
p02621
|
a = int(eval(input()))
print((a + a * a + a * a * a))
|
a = int(eval(input()))
print((a + a ** 2 + a ** 3))
|
p02621
|
a=int(eval(input()))
print((a+(a**2)+(a**3)))
|
a=int(eval(input()))
print((a+a**2+a**3))
|
p02621
|
#!/usr/bin python3
# -*- coding: utf-8 -*-
def main():
N = int(eval(input()))
print((N+N*N+N*N*N))
if __name__ == '__main__':
main()
|
#!/usr/bin python3
# -*- coding: utf-8 -*-
def main():
a = int(eval(input()))
print((a+a*a+a*a*a))
if __name__ == '__main__':
main()
|
p02621
|
import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
a = I()
print((a+a**2+a**3))
|
import sys
def I(): return int(sys.stdin.readline().rstrip())
a = I()
print((a+a**2+a**3))
|
p02621
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
in_n = lambda: int(readline())
in_nn = lambda: list(map(int, readline().split()))
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: list(map(int, read().split()))
in_s = lambda: readline().rstrip().decode('utf-8')
def main():
a = in_n()
print((a + a**2 + a**3))
if __name__ == '__main__':
main()
|
a=int(eval(input()))
print((a+a*a+a**3))
|
p02621
|
N = 10**7
M = 10**5
arr = list(range(M))
def f(x):
return x
for i in range(N):
b = arr[i % M]
b = f(b)
a = int(eval(input()))
print((a + a**2 + a**3))
|
N = 10**7
# M = 10**5
# arr = list(range(M))
# def f(x):
# return x
for i in range(N):
pass
# 答え
a = int(eval(input()))
print((a + a**2 + a**3))
|
p02621
|
N = 10**7
M = 10**5
arr = list(range(M))
for i in range(N):
t = arr[i % M]
# 答え
a = int(eval(input()))
print((a + a**2 + a**3))
|
N = 10**7
arr = [0]
for i in range(N):
t = arr[0]
# 答え
a = int(eval(input()))
print((a + a**2 + a**3))
|
p02621
|
N = 10**7
def f(x):
return x
M = 10**5
arr = list(range(M))
for i in range(N):
t = (i + i * i - i) % M # 四則演算
b = arr[t] # 配列ランダムアクセス
b = f(b) # 関数呼び出し
# 答え
a = int(eval(input()))
print((a + a**2 + a**3))
|
N = 10**6
def f(x):
return x
M = 10**5
arr = list(range(M))
for i in range(N):
t = (i + i * i - i) % M # 四則演算
b = arr[t] # 配列ランダムアクセス
b = f(b) # 関数呼び出し
# 答え
a = int(eval(input()))
print((a + a**2 + a**3))
|
p02621
|
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
def inp(): return int(eval(input()))
def inpm(): return list(map(int,input().split()))
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(eval(input())) for _ in range(n))
def inplL(n): return [list(eval(input())) for _ in range(n)]
def inplT(n): return [tuple(eval(input())) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplt(n): return [tuple(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
a = inp()
print((a+a**2+a**3))
|
a = int(eval(input()))
print((a+a**2+a**3))
|
p02621
|
a = int(eval(input()))
print((a + a ** 2 + a ** 3))
|
#!/usr/bin/env pypy3
def main():
a = int(eval(input()))
print((a + a ** 2 + a ** 3))
if __name__ == '__main__':
main()
|
p02621
|
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
a = int(readline())
print((a + a ** 2 + a ** 3))
if __name__ == '__main__':
main()
|
a = int(eval(input()))
print((a + a ** 2 + a ** 3))
|
p02621
|
a = int(eval(input()))
print((a + (a * a) + (a * a * a)))
|
a = int(eval(input()))
print((a + a**2 + a**3))
|
p02621
|
a = int(eval(input()))
print((int(a+a**2+a**3)))
|
a = int(eval(input()))
print((a+a**2+a**3))
|
p02621
|
a = int(eval(input()))
ans = a + a**2 + a**3
print(ans)
|
a = int(eval(input()))
print((a+a**2+a**3))
|
p02621
|
a = int(eval(input()))
print((a+a**2+a**3))
|
a = int(eval(input()))
print((a + a*a + a**3))
|
p02621
|
a=int(eval(input()))
print((a+a**2+a**3))
|
import math
a=int(eval(input()))
print((round((a*(a-(-1+math.sqrt(3)*(1j))/2)*(a-(-1-math.sqrt(3)*(1j))/2)).real)))
|
p02621
|
num = int(eval(input()))
result = num + num**2 + num**3
print(result)
|
a=int(eval(input()))
print((a+a**2+a**3))
|
p02621
|
a = int(eval(input()))
print((a+a**2+a**3))
|
a = int(eval(input()))
if a == 1:
print((3))
elif a == 2:
print((14))
elif a == 3:
print((39))
elif a == 4:
print((84))
elif a == 5:
print((155))
elif a == 6:
print((258))
elif a == 7:
print((399))
elif a == 8:
print((584))
elif a == 9:
print((819))
elif a == 10:
print((1110))
|
p02621
|
def main():
a = int(eval(input()))
ret = a
ret += a * a
ret += a * a * a
print(ret)
if __name__ == '__main__':
main()
|
def main():
N = int(eval(input()))
print((N + N * N + N * N * N))
if __name__ == '__main__':
main()
# import sys
# input = sys.stdin.readline
#
# sys.setrecursionlimit(10 ** 7)
#
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
# while abs(ok - ng) > 1:
# mid = (ok + ng) // 2
# if func(mid):
# ok = mid
# else:
# ng = mid
# return ok
|
p02621
|
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline ####
def int1(x): return int(x) - 1
def II(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def MI1(): return list(map(int1, input().split()))
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(eval(input()))
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print((k.join(list(map(str, lst)))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum # accumulate
def solve():
a = II()
print((a + a**2 + a**3))
if __name__ == '__main__':
solve()
|
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline ####
def int1(x): return int(x) - 1
def II(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def MI1(): return list(map(int1, input().split()))
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(eval(input()))
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print((k.join(list(map(str, lst)))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np # cumsum
# from bisect import bisect_left, bisect_right
def solve():
a = II()
print((a + a**2 + a**3))
if __name__ == '__main__':
solve()
|
p02621
|
a = int(eval(input()))
print((a+a*a+a*a*a))
|
a = int(eval(input()))
print((a+a**2+a**3))
|
p02621
|
a = int(eval(input()))
print((a+a*a+a**3))
|
a = int(eval(input()))
print((a + a*a + a*a*a))
|
p02621
|
x=int(eval(input()))
print((x+x*x+x*x*x))
|
a=int(eval(input()))
print((a+a**2+a**3))
|
p02621
|
a = int(eval(input()))
result = a + (a*a) + (a*a*a)
print(result)
|
a = int(eval(input()))
result = a + (a**2) + (a**3)
print(result)
|
p02621
|
a = int(eval(input()))
print((a*((a+1)*(a+1)-a)))
|
a = int(eval(input()))
print((a+a*a+a*a*a))
|
p02621
|
number = int(eval(input()))
print((number + number**2 + number**3))
|
num = int(eval(input()))
print((num +num**2+ num**3))
|
p02621
|
a=int(eval(input()))
print((int(a+a**2+a**3)))
|
a=int(eval(input()))
print((a+a**2+a**3))
|
p02621
|
a = int(eval(input()))
b = [3, 14, 39, 84, 155, 258, 399, 584, 819, 1110]
print((b[a-1]))
|
def main():
a = int(eval(input()))
print((int(a+a*a+a**3)))
if __name__ == "__main__":
main()
|
p02621
|
def main():
a = int(eval(input()))
print((int(a+a*a+a**3)))
if __name__ == "__main__":
main()
|
a = int(eval(input()))
print((a*(a*a+a+1)))
|
p02621
|
s = int(input())
print(s + s ** 2 + s ** 3)
|
s = input()
s = int(s)
print(s + s ** 2 + s ** 3)
|
p02621
|
a=int(eval(input()))
s=a+a**2+a**3
print(s)
|
a=int(eval(input()))
print((a+a**2+a**3))
|
p02621
|
a = int(eval(input()))
b = a**2
c = a**3
print((a+b+c))
|
a = int(eval(input()))
print((a+a**2+a**3))
|
p02621
|
a = int(eval(input()))
print((a + a * a + a * a * a))
|
N = int(eval(input()))
print((N + N*N + N*N*N))
|
p02621
|
a = eval(input())
b = int(a)
print((b+b**2+b**3))
|
a=int(eval(input()))
print((a+a**2+a**3))
|
p02621
|
a = int(eval(input()))
a2 = a*a
a3 = a2 * a
print((a + a2 + a3))
|
a = int(eval(input()))
print((a+a**2+a**3))
|
p02621
|
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
def main():
a = INT()
print((a+a**2+a**3))
return
if __name__ == '__main__':
main()
|
#!/usr/bin/env python3
import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
def main():
sys.setrecursionlimit(10**8)
INF = float("inf")
a = INT()
print((a + a**2 + a**3))
return
if __name__ == '__main__':
main()
|
p02621
|
a = int(eval(input()))
print(((a**3)+(a**2)+a))
|
a = int(eval(input()))
print((a**3+a**2+a))
|
p02621
|
a,b=list(map(int,input().split()))
if a>b:
print((str(b)*a))
if a<=b:
print((str(a)*b))
|
a,b=list(map(int,input().split()))
print((str(min(a,b))*max(a,b)))
|
p02790
|
a,b=input().split();print(([b*int(a),a*int(b)][a<b]))
|
a,b=input().split();print((min(b*int(a),a*int(b))))
|
p02790
|
def main():
a, b = input().split(" ")
i = int(a * int(b))
j = int(b * int(a))
numbers = [k for k in range(1, (max(i, j) + 1))]
i_index = numbers.index(i)
j_index = numbers.index(j)
if i_index > j_index:
print(i)
else:
print(j)
if __name__ == '__main__':
main()
|
def main():
a, b = list(map(int, input().split(" ")))
if a < b:
print((str(a) * b))
else:
print((str(b) * a))
if __name__ == '__main__':
main()
|
p02790
|
def main():
a, b = input().split()
aa = a*int(b)
bb = b*int(a)
if aa < bb:
return aa
return bb
if __name__ == '__main__':
print((main()))
|
def main():
a, b = input().split()
s = a * int(b)
t = b * int(a)
if s < t:
return s
return t
if __name__ == '__main__':
print((main()))
|
p02790
|
def main():
a, b = input().split()
s = a * int(b)
t = b * int(a)
if s < t:
return s
return t
if __name__ == '__main__':
print((main()))
|
def main():
a, b = list(map(int, input().split()))
s = str(a) * b
t = str(b) * a
if s < t:
return s
return t
if __name__ == '__main__':
print((main()))
|
p02790
|
a,b=list(map(str,input().split()))
if int(a*int(b))>=int(b*int(a)):
print((int(a*int(b))))
else:
print((int(b*int(a))))
|
a,b=list(map(int,input().split()))
print((str(min(a,b))*max(a,b)))
|
p02790
|
a_str, b_str = input().split()
a = int(a_str)
b = int(b_str)
A = a_str*b
B = b_str*a
print((min(A, B)))
|
a, b = list(map(int, input().split()))
if a > b:
print((str(b) * a))
elif a < b:
print((str(a) * b))
else:
print((str(a) * a))
|
p02790
|
a, b = list(map(int, input().split()))
ans = min(str(a) * b, str(b) * a)
print(ans)
|
a, b = list(map(int, input().split()))
x = str(a) * b
y = str(b) * a
ans = min(x, y)
print(ans)
|
p02790
|
a, b = input().split()
ab, ba = a*int(b), b*int(a)
print((ab if ab < ba else ba))
|
a, b = input().split()
print((a*int(b) if a < b else b*int(a)))
|
p02790
|
a, b = list(map(int, input().split()))
str_a = str(a) * b
str_b = str(b) * a
if str_a<str_b:
print(str_a)
else:
print(str_b)
|
# Problem B - Comparing Strings
# input process
a, b = input().split()
str_a = a * int(b)
str_b = b * int(a)
# output process
if str_a>=str_b:
print(str_b)
else:
print(str_a)
|
p02790
|
a,b=input().split()
e=[str(a*int(b)),str(b*int(a))]
e.sort()
print((e[0]))
|
a=sorted(list(map(int,input().split())))
print((str(a[0])*a[1]))
|
p02790
|
a,b=list(map(int,input().split()))
if a>=b:
print((str(b)*a))
else:
print((str(a)*b))
|
a,b=input().split()
if a<b:
print((a*int(b)))
else:
print((b*int(a)))
|
p02790
|
A,B=map(int,input().split())
if A<B:
for i in range (B):
print(A,end="")
print()
else:
for i in range (A):
print(B,end="")
print()
|
A,B=list(map(int,input().split()))
C=int(str(A)*B)
D=int(str(B)*A)
E=[C,D]
F=sorted(E)
print((int(F[1])))
|
p02790
|
a,b = list(map(int,input().split()))
a_l = ""
b_l = ""
for i in range(b):
a_l += str(a)
for j in range(a):
b_l += str(b)
if a>b:
print(b_l)
elif b<a:
print(a_l)
else:
print(a_l)
|
a,b = list(map(int,input().split()))
k = str(a)
l = str(b)
X = k*b
Y = l*a
if (X < Y):
print(X)
else:
print(Y)
|
p02790
|
a,b = list(map(int,input().split()))
if a>=b:
print((str(b)*a))
else:
print((str(a)*b))
|
a,b=list(map(int,input().split()))
if a==b:
print((str(a)*b))
else:
print((str(min(a,b))*max(a,b)))
|
p02790
|
a,b=input().split()
print((min(a*int(b),b*int(a))))
|
a, b = input().split()
print((a*int(b) if a < b else b*int(a)))
|
p02790
|
a, b = input().split()
print((a*int(b) if a < b else b*int(a)))
|
a, b = input().split()
print((min(a*int(b), b*int(a))))
|
p02790
|
a,b = list(map(int,input().split()))
words = []
a_word = ""
b_word = ""
for i in range(a):
b_word += str(b)
for i in range(b):
a_word += str(a)
words.append(a_word)
words.append(b_word)
words.sort()
print((words[0]))
|
a,b = list(map(int,input().split()))
word = ""
for i in range(max(a,b)):
word += str(min(a,b))
print(word)
|
p02790
|
a, b = input().split()
print((a*int(b) if a<=b else b*int(a)))
|
A, B = input().split()
print((min(A*int(B), B*int(A))))
|
p02790
|
import sys
def solve():
input = sys.stdin.readline
mod = 10 ** 9 + 7
a, b = list(map(int, input().rstrip('\n').split()))
ls = []
ls.append(str(b) * a)
ls.append(str(a) * b)
ls.sort()
print((ls[0]))
if __name__ == '__main__':
solve()
|
import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
a, b = list(map(str, readline().rstrip().decode('utf-8').split()))
if a * int(b) < b * int(a):
print((a * int(b)))
else:
print((b * int(a)))
if __name__ == '__main__':
solve()
|
p02790
|
a, b = list(map(int, input().split()))
a_l = []
b_l = []
for i in range(a):
a_l += str(b)
for i in range(b):
b_l += str(a)
a_l = ''.join(a_l)
b_l = ''.join(b_l)
all = []
all.append(a_l)
all.append(b_l)
all.sort()
print((all[0]))
|
a, b = list(map(int, input().split()))
list_a = []
list_b = []
for i in range(a):
list_a.append(str(b))
for i in range(b):
list_b.append(str(a))
A = ''.join(list_a)
B = ''.join(list_b)
if a >= b:
print(A)
else:
print(B)
|
p02790
|
a = [int(i) for i in input().split()]
if (a[0] <= a[1]):
print((str(a[0])*a[1]))
elif (a[1] < a[0]):
print((str(a[1])*a[0]))
|
a,b=list(map(int,input().split()))
print((str(min(a,b))*max(a,b)))
|
p02790
|
# ABC 152 B
si = lambda: eval(input())
ni = lambda: int(eval(input()))
nm = lambda: list(map(int, input().split()))
snm = lambda: list(map(str, input().split()))
nl = lambda: list(map(int, input().split()))
a,b=nm()
s=''
t=''
for i in range(b):
s+=str(a)
for i in range(a):
t+=str(b)
l=[]
l.append(s)
l.append(t)
l.sort()
print((l[0]))
|
a,b=list(map(int,input().split()))
l=[]
l.append(str(a)*b)
l.append(str(b)*a)
l.sort()
print((l[0]))
|
p02790
|
args = int(input().rstrip())
def snuke(n):
s = 0
while n:
s += n % 10
n //= 10
return s
def find_snuke(args):
result = []
i = 1
while len(result) < args:
push = True
p = 0
for power in range(0,len(str(i))):
if((i+10**power)/snuke(i+10**power))<(i/snuke(i)):
push = False
p = power
if push:
result.append(i)
i=i+10**p
return result
arr = find_snuke(args)
for a in arr:
print(a)
|
args = int(input().rstrip())
def snuke(n):
s = 0
while n:
s += n % 10
n //= 10
return s
def find_snuke(args):
result = []
i = 1
while len(result) < args:
push = True
p = 0
for power in range(0,len(str(i))):
if((i+10**power)/snuke(i+10**power))<(i/snuke(i)):
push = False
p = power
break
if push:
result.append(i)
i=i+10**p
return result
arr = find_snuke(args)
for a in arr:
print(a)
|
p03320
|
K = int(input())
S = lambda n: sum(map(int,str(n)))
R = lambda n: n/S(n)
arr = []
for i in range(1,10000):
for j in range(1,15):
arr.append(int(str(i) + '9'*j))
arr.sort(reverse=True)
min_r = arr[0]
snukes = []
for a in arr:
r = R(a)
if r < min_r:
min_r = r
snukes.append(a)
for i in range(min(9,K)):
print(i+1)
if K <= 9:
exit()
K -= 9
print(*snukes[:-K-1:-1],sep='\n')
|
K = int(input())
S = lambda n: sum(map(int,str(n)))
R = lambda n: n/S(n)
arr = []
for i in range(1,1000):
for j in range(1,15):
arr.append(int(str(i) + '9'*j))
arr.sort(reverse=True)
min_r = arr[0]
snukes = []
for a in arr:
r = R(a)
if r < min_r:
min_r = r
snukes.append(a)
for i in range(min(9,K)):
print(i+1)
if K <= 9:
exit()
K -= 9
print(*snukes[:-K-1:-1],sep='\n')
|
p03320
|
K = int(input())
S = lambda n: sum(map(int,str(n)))
R = lambda n: n/S(n)
arr = []
for i in range(1,1000):
for j in range(1,15):
arr.append(int(str(i) + '9'*j))
arr.sort(reverse=True)
min_r = arr[0]
snukes = []
for a in arr:
r = R(a)
if r < min_r:
min_r = r
snukes.append(a)
for i in range(min(9,K)):
print(i+1)
if K <= 9:
exit()
K -= 9
print(*snukes[:-K-1:-1],sep='\n')
|
K = int(input())
S = lambda n: sum(map(int,str(n)))
R = lambda n: n/S(n)
arr = []
for i in range(1,200):
for j in range(1,15):
arr.append(int(str(i) + '9'*j))
arr.sort(reverse=True)
min_r = arr[0]
snukes = []
for a in arr:
r = R(a)
if r < min_r:
min_r = r
snukes.append(a)
for i in range(min(9,K)):
print(i+1)
if K <= 9:
exit()
K -= 9
print(*snukes[:-K-1:-1],sep='\n')
|
p03320
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys
def S(k):
return sum(int(x) for x in str(k))
def T(k):
return k / S(k)
d = {}
MAX = int(1e15) + 1e9
for i in range(1, 99999):
t = i
while t < MAX:
d[t] = T(t)
t = t * 10 + 9
keys = sorted(list(d.keys()))
# for k in keys:
# print(k, d[k])
mn = None
ans = []
for k in reversed(keys):
if mn == None:
mn = d[k]
else:
if mn >= d[k]:
ans.append(k)
mn = min(mn, d[k])
ans.reverse()
K = int(eval(input()))
ans = ans[:K]
for a in ans:
print(a)
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys
def T(k):
orig_k = k
sk = 0
while k > 0:
sk += k % 10
k //= 10
return orig_k / sk
d = {}
MAX = int(1e15) + 1e9
for i in range(1, 99999):
t = i
while t < MAX:
d[t] = T(t)
t = t * 10 + 9
keys = sorted(list(d.keys()))
# for k in keys:
# print(k, d[k])
mn = None
ans = []
for k in reversed(keys):
if mn == None:
ans.append(k)
mn = d[k]
else:
if mn >= d[k]:
ans.append(k)
mn = min(mn, d[k])
ans.reverse()
K = int(eval(input()))
ans = ans[:K]
for a in ans:
print(a)
|
p03320
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys
def T(k):
orig_k = k
sk = 0
while k > 0:
sk += k % 10
k //= 10
return orig_k / sk
d = {}
MAX = int(1e15) + 1e9
for i in range(1, 99999):
t = i
while t < MAX:
d[t] = T(t)
t = t * 10 + 9
keys = sorted(list(d.keys()))
# for k in keys:
# print(k, d[k])
mn = None
ans = []
for k in reversed(keys):
if mn == None:
ans.append(k)
mn = d[k]
else:
if mn >= d[k]:
ans.append(k)
mn = min(mn, d[k])
ans.reverse()
K = int(eval(input()))
ans = ans[:K]
for a in ans:
print(a)
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys
def T(k):
orig_k = k
sk = 0
while k > 0:
sk += k % 10
k //= 10
return orig_k / sk
d = {}
MAX = int(1e15) + 1e9
for i in range(1, 9999):
t = i
while t < MAX:
d[t] = T(t)
t = t * 10 + 9
keys = sorted(list(d.keys()))
# for k in keys:
# print(k, d[k])
mn = None
ans = []
for k in reversed(keys):
if mn == None:
ans.append(k)
mn = d[k]
else:
if mn >= d[k]:
ans.append(k)
mn = min(mn, d[k])
ans.reverse()
K = int(eval(input()))
ans = ans[:K]
for a in ans:
print(a)
|
p03320
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys
def T(k):
orig_k = k
sk = 0
while k > 0:
sk += k % 10
k //= 10
return orig_k / sk
d = {}
MAX = int(1e15) + 1e9
for i in range(1, 9999):
t = i
while t < MAX:
d[t] = T(t)
t = t * 10 + 9
keys = sorted(list(d.keys()))
# for k in keys:
# print(k, d[k])
mn = None
ans = []
for k in reversed(keys):
if mn == None:
ans.append(k)
mn = d[k]
else:
if mn >= d[k]:
ans.append(k)
mn = min(mn, d[k])
ans.reverse()
K = int(eval(input()))
ans = ans[:K]
for a in ans:
print(a)
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys
def T(k):
orig_k = k
sk = 0
while k > 0:
sk += k % 10
k //= 10
return orig_k / sk
d = {}
MAX = int(1e15) + 1e9
for i in range(1, 999):
t = i
while t < MAX:
d[t] = T(t)
t = t * 10 + 9
keys = sorted(list(d.keys()))
# for k in keys:
# print(k, d[k])
mn = None
ans = []
for k in reversed(keys):
if mn == None:
ans.append(k)
mn = d[k]
else:
if mn >= d[k]:
ans.append(k)
mn = min(mn, d[k])
ans.reverse()
K = int(eval(input()))
ans = ans[:K]
for a in ans:
print(a)
|
p03320
|
# _*_ coding:utf-8 _*_
# Atcoder_Beginners_Contest083-B
# https://atcoder.jp/contests/abc080/tasks/abc080_b
def sumKeta(number):
number2Str = str(number)
numberLength=len(number2Str)
thisNumberSum = 0
ketaRange = list(range(0,numberLength,1))
for i in ketaRange:
thisNumberKeta = int(number2Str[i])
thisNumberSum = thisNumberKeta + thisNumberSum
return thisNumberSum
def isThisHarshadNumber(objectNumber):
digitSumNumber=sumKeta(objectNumber)
modNumber = objectNumber % digitSumNumber
if modNumber == 0:
answer = "Yes"
else:
answer = "No"
return answer
if __name__ == '__main__':
N = int(input().strip())
solution=isThisHarshadNumber(N)
print(solution)
|
# Problem: https://atcoder.jp/contests/abc080/tasks/abc080_b
# Python 1st Try
import sys
# from collections import defaultdict
# import heapq,copy
# from collections import deque
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def solver(inputNum):
result = "No"
# algorithm
strNum = str(inputNum)
divisorNum = 0
for j in range(0, len(strNum), +1):
divisorNum = divisorNum + int(strNum[j])
if inputNum % divisorNum == 0:
result = "Yes"
return result
if __name__ == "__main__":
print("{}".format(solver(II())))
|
p03502
|
N=int(eval(input()))
N_list=list(str(N))
if len(N_list)==1:
M=int(N_list[0])
if N%M==0:
print("Yes")
else:
print("No")
elif len(N_list)==2:
I=int(N_list[0])+int(N_list[1])
if N%I==0:
print("Yes")
else:
print("No")
elif len(N_list)==3:
U=int(N_list[0])+int(N_list[1])+int(N_list[2])
if N%U==0:
print("Yes")
else:
print("No")
elif len(N_list)==4:
K=int(N_list[0])+int(N_list[1])+int(N_list[2])+int(N_list[3])
if N%K==0:
print("Yes")
else:
print("No")
elif len(N_list)==5:
O=int(N_list[0])+int(N_list[1])+int(N_list[2])+int(N_list[3])+int(N_list[4])
if N%O==0:
print("Yes")
else:
print("No")
elif len(N_list)==6:
G=int(N_list[0])+int(N_list[1])+int(N_list[2])+int(N_list[3])+int(N_list[4])+int(N_list[5])
if N%G==0:
print("Yes")
else:
print("No")
elif len(N_list)==7:
W=int(N_list[0])+int(N_list[1])+int(N_list[2])+int(N_list[3])+int(N_list[4])+int(N_list[5])+int(N_list[6])
if N%W==0:
print("Yes")
else:
print("No")
elif len(N_list)==8:
S=int(N_list[0])+int(N_list[1])+int(N_list[2])+int(N_list[3])+int(N_list[4])+int(N_list[5])+int(N_list[6])+int(N_list[7])
if N%S==0:
print("Yes")
else:
print("No")
|
N=int(eval(input()))
f_x=sum(map(int,str(N)))
if N%f_x==0:
print("Yes")
else:
print("No")
|
p03502
|
n = int(eval(input()))
def sum_digits(n):
result = n % 10
while n // 10 != 0:
n //= 10
result += (n % 10)
return result
if n % sum_digits(n) == 0:
print("Yes")
else:
print("No")
|
def calculate_summary_of_digits(n):
result = 0
while n != 0:
result += (n % 10)
n //= 10
return result
n = int(eval(input()))
sum_of_digits = calculate_summary_of_digits(n)
print(("Yes" if n % sum_of_digits == 0 else "No"))
|
p03502
|
N=int(eval(input()))
N_sum=list(str(N))
fN=0
for n in range(len(N_sum)):
fN+=int(N_sum[n])
if N%fN==0:
print('Yes')
else:
print('No')
|
n = int(eval(input()))
x = sum([int(s) for s in str(n)])
print(('Yes' if n%x == 0 else 'No'))
|
p03502
|
n=input()
fx=0
for i in n:
fx+=int(i)
print('Yes') if int(n)%fx==0 else print('No')
|
n=i=int(input())
sum=0
while i/10>0:
sum+=int(i%10)
i=int(i/10)
print('Yes') if n%sum==0 else print('No')
|
p03502
|
while 1:
k=int(eval(input()))
if k==0:break
print((sum(map(int,input().split()))//(k-1)))
|
while 1:
k=int(eval(input()))-1
if k<0:break
print((sum(map(int,input().split()))//k))
|
p00613
|
import sys
def solve():
while(1):
n = int(input())
if n == 0:
break
score_a, score_b = 0, 0
while(n > 0):
a, b = list(map(int, input().split()))
if a > b:
score_a += a + b
elif b > a:
score_b += a + b
else:
score_a += a
score_b += b
n -= 1
print(score_a, score_b)
if __name__ == '__main__':
solve()
|
def solve():
while(1):
n = int(input())
if n == 0:
break
score_a, score_b = 0, 0
while(n > 0):
a, b = list(map(int, input().split()))
if a > b:
score_a += a + b
elif b > a:
score_b += a + b
else:
score_a += a
score_b += b
n -= 1
print(score_a, score_b)
if __name__ == '__main__':
solve()
|
p00423
|
import sys
def main():
n, s = sys.stdin.read().split()
n = int(n)
left, right = 0, 0
for char in s:
if char == '(':
right += 1
# これ以前に出現している')'の数が'('の数より多い可能せがあるのでleftを削ることはできないため、ペアになる可能性としての')'を追加
elif char == ')':
if right:
# rightがあるならこれより前に必ずペア未確定の'('が存在するのでrightの可能性を一つ削ってこれを代わりにその'('とペアにする
right -= 1
else:
# rightがない場合はペア未確定の'('がこれ以前に出現していないということので'('を追加してこれとペアにするしかない
left += 1
ans = '(' * left + s + ')' * right
print(ans)
if __name__ == "__main__":
main()
|
import sys
n = int(sys.stdin.readline().rstrip())
s = sys.stdin.readline().rstrip()
def main():
l = r = 0
for char in s:
if char == '(':
r += 1
elif char == ')':
if r:
r -= 1
else:
l += 1
return '(' * l + s + ')' * r
if __name__ == '__main__':
ans = main()
print(ans)
|
p03696
|
eval(input())
s = input().strip()
ans = s
depth = 0
for c in s:
if c == '(':
depth += 1
else:
if depth:
depth -= 1
else:
ans = '(' + ans
ans += ')' * depth
print(ans)
|
eval(input())
s = input().strip()
stock, depth = 0, 0
for c in s:
if c == '(':
depth += 1
else:
if depth:
depth -= 1
else:
stock += 1
print(('(' * stock + s + ')' * depth))
|
p03696
|
N = int(eval(input()))
S = input().strip()
S1 = S
cur = 0
for i in range(len(S)):
if S[i]=="(":
cur += 1
else:
cur -= 1
if cur<0:
S1 = "("+S1
cur += 1
S1 = S1+")"*cur
print(S1)
|
N = int(eval(input()))
S = input().strip()
while True:
lv = 0
lmin = len(S)
for i in range(len(S)):
if S[i]=="(":
lv += 1
else:
lv -= 1
lmin = min(lmin,lv)
if lmin<0:
S = "("*(-lmin)+S
else:break
lv = 0
for i in range(len(S)):
if S[i]=="(":
lv += 1
else:
lv -= 1
if lv>0:
S = S+")"*lv
print(S)
|
p03696
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.