code1
stringlengths 16
24.5k
| code2
stringlengths 16
24.5k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,628B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
ans=[]
for i in range (0,10):
ans.append(int(input()))
ans.sort(reverse=True)
for i in range (0,3):
print(ans[i])
|
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *
N = INT()
L = LIST()
L.sort()
ans = 0
for i in range(N-2):
a = L[i]
for j in range(i+1, N-1):
b = L[j]
idx = bisect_left(L, a+b) - 1
if j < idx:
ans += idx - j
print(ans)
| 0 | null | 85,626,182,004,842 | 2 | 294 |
N = int(input())
C = input()
T = 'R' * C.count('R') + 'W' * C.count('W')
ans = sum([1 for a, b in zip(C, T) if a != b]) // 2
print(ans)
|
def main():
n, k = map(int, input().split())
a = list(map(int, input().split()))
to = [[None]*n for _ in range(60)]
to[0] = a[:]
for i in range(1, 60):
for j in range(n):
to[i][j] = to[i-1][to[i-1][j]-1]
p = 1
for i in range(59, -1, -1):
num = 1 << i
if k >= num:
k -= num
p = to[i][p-1]
print(p)
if __name__ == "__main__":
main()
| 0 | null | 14,465,349,949,270 | 98 | 150 |
X, N=map(int, input().split())
if N==0:print(X);exit()
p=sorted(list(map(int, input().split())))
m=X;i=0
for i in range(m,min(p)-2,-1):
if i not in p:break
M=X;j=0
for j in range(M,max(p)+2):
if j not in p:break
if abs(i-X)==abs(j-X):print(min(i,j))
elif abs(i-X)<abs(j-X):
print(i)
else:print(j)
|
ch = input().rstrip()
ans = chr(ord(ch) + 1)
print(ans)
| 0 | null | 53,345,181,429,028 | 128 | 239 |
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
return list(map(int,input().split()))
def m(): #複数文字
return map(int,input().split())
def onem(): #Nとかの取得
return int(input())
def s(x): #圧縮
a = []
if len(x) == 0:
return []
aa = x[0]
su = 1
for i in range(len(x)-1):
if aa != x[i+1]:
a.append([aa,su])
aa = x[i+1]
su = 1
else:
su += 1
a.append([aa,su])
return a
def jo(x): #listをスペースごとに分ける
return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
return max(map(max,x))
def In(x,a): #aがリスト(sorted)
k = bs.bisect_left(a,x)
if k != len(a) and a[k] == x:
return True
else:
return False
def pow_k(x, n):
ans = 1
while n:
if n % 2:
ans *= x
x *= x
n >>= 1
return ans
"""
def nibu(x,n,r):
ll = 0
rr = r
while True:
mid = (ll+rr)//2
if rr == mid:
return ll
if (ここに評価入れる):
rr = mid
else:
ll = mid+1
"""
n = onem()
a = l()
if n % 2 == 0:
po = [a[i] for i in range(n)]
for i in range(n-3,-1,-1):
po[i] += po[i+2]
ans = sum(a[0::2])
ans = max(ans,sum(a[1::2]))
co = 0
for i in range(0,n,2):
if i+1 <= n-1:
ans = max(ans,co+po[i+1])
else:
ans = max(ans,co)
co += a[i]
print(ans)
else:
po = [a[i] for i in range(n)]
mi = [-Max for i in range(n)]
for i in range(n-3,-1,-1):
po[i] += po[i+2]
ans = sum(a[1::2])
ans = max(ans,sum(a[0::2]) - a[-1])
#print(ans)
l1 = [-Max for i in range(n)]
for i in range(n):
if i != n-1:
l1[i] = po[i+1]
"""
co = 0
for i in range(0,n,2):
if i != n-1:
l1[i] = co + po[i+1]
else:
l1[i] = co
co += a[i]
co = 0
for i in range(1,n,2):
if i != n-1:
l1[i] = co + po[i+1]
else:
l1[i] = co
co += a[i]
"""
for i in range(n-1,-1,-1):
if i == n-1:
continue
elif i == n-2:
mi[i] = l1[i]
else:
mi[i] = max(mi[i+2]+a[i],l1[i])
l1 = mi
"""
for i in range(n-1,-1,-1):
if i <= n-3:
mi[i] = min(mi[i+2],a[i])
else:
mi[i] = a[i]
print(mi)
"""
l2 = [-Max for i in range(n)]
for i in range(n-1,-1,-1):
l2[i] = po[i]
#print(l1)
#print(l2)
co = 0
for i in range(0,n,2):
if i + 2 <= n-1:
#print(ans,co+l1[i+1],co+l2[i+2])
ans = max(ans,co+l1[i+1],co+l2[i+2])
elif i+1 <= n-1:
ans = max(ans,co+l1[i+1])
else:
ans = max(ans,co)
co += a[i]
co = 0
#print(ans)
for i in range(1,n,2):
#print(ans,co+l1[i+1])
ans = max(ans,co+po[i+1])
#ans = max(ans,co+l1[i+1])
co += a[i]
#print("po:"+str(mi[1]))
print(ans)
|
n=int(input())
a=list(map(int,input().split()))
if n//2==1:
print(max(a))
exit()
if n%2==0:
#iは桁数、jはそれまでに余計に飛ばした数
#dp[i][j]
dp=[[-10**9]*2 for _ in range(n)]
for i in range(n):
if i<2:
dp[i][0]=a[i]
if i>=2:
dp[i][0]=dp[i-2][0]+a[i]
if i>=3:
dp[i][1]=max(dp[i-2][1]+a[i],dp[i-3][0]+a[i])
#print(dp)
print(max([dp[-1][1],dp[-1][0],dp[n-2][0]]))
else:
#iは桁数、jはそれまでに余計に飛ばした数
#dp[i][j]
dp=[[-10**9]*3 for _ in range(n)]
for i in range(n):
if i<2:
dp[i][0]=a[i]
if i>=2:
dp[i][0]=dp[i-2][0]+a[i]
if i>=3:
dp[i][1]=max(dp[i-2][1]+a[i],dp[i-3][0]+a[i])
if i>=4:
dp[i][2]=max([dp[i-2][2]+a[i],dp[i-3][1]+a[i],dp[i-4][0]+a[i]])
#print(dp)
print(max([dp[-1][2],dp[-1][1],dp[-1][0]-a[0],dp[-1][0]-a[-1]]))
| 1 | 37,348,077,906,600 | null | 177 | 177 |
n = int(input())
mod = 10**9 + 7
contain_zero = 0
contain_nine = 0
not_contain_zero_and_nine = 0
all_per = pow(10,n,mod)
if n < 2:
print(0)
else:
contain_zero = all_per - pow(9,n,mod)
contain_nine = all_per - pow(9,n,mod)
not_contain_zero_and_nine = pow(8,n,mod)
print((-(all_per - not_contain_zero_and_nine -contain_nine - contain_zero))%mod)
|
mod = 10 ** 9 + 7
N = int(input())
result = 0
ten = pow(10, N, mod)
nine = pow(9, N, mod)
eight = pow(8, N, mod)
result = (ten - 2 * nine + eight) % mod
print(result)
| 1 | 3,150,552,014,430 | null | 78 | 78 |
#!/usr/bin/env python3
def next_line():
return input()
def next_int():
return int(input())
def next_int_array_one_line():
return list(map(int, input().split()))
def next_int_array_multi_lines(size):
return [int(input()) for _ in range(size)]
def next_str_array(size):
return [input() for _ in range(size)]
def main():
a = next_line()
if 'A' <= a[0] and a[0] <= 'Z':
print("A")
else:
print("a")
if __name__ == '__main__':
main()
|
num = list(map(int,input().split()))
count = 0
while count < 2:
for i in range(2):
j = 0
if num[i] > num[i+1]:
j = num[i]
num[i] = num[i+1]
num[i+1] = j
else:
continue
count += 1
out = ''
for i in num:
out += str(i) + ' '
print(out[:-1])
| 0 | null | 5,865,442,559,028 | 119 | 40 |
n = int(input())
S = input()
beforeChara = ""
cnt = 0
for s in S:
if s != beforeChara:
cnt += 1
beforeChara = s
print(cnt)
|
def main():
N = input_int()
S = input()
count = 1
for i in range(1, N):
if S[i-1] != S[i]:
count += 1
print(count)
def input_int():
return int(input())
# def input_int_tuple():
# return map(int, input().split())
# def input_int_list():
# return list(map(int, input().split()))
main()
| 1 | 170,368,038,104,000 | null | 293 | 293 |
mod=998244353
N,M,K=map(int,input().split())
MAX_N=N+1
Fact=[0 for i in range(MAX_N+1)]
Finv=[0 for i in range(MAX_N+1)]
Fact[0]=1
for i in range(MAX_N):
Fact[i+1]=(i+1)*Fact[i]
Fact[i+1]%=mod
Finv[-1]=pow(Fact[-1],mod-2,mod)
for i in range(MAX_N-1,-1,-1):
Finv[i]=(i+1)*Finv[i+1]
Finv[i]%=mod
def C(n,k):
return (Fact[n]*Finv[k]*Finv[n-k])%mod
'''
i in range(K+1)で総和を取る
隣り合うブロックの色が同じ色なのはi通り
隣り合うブロックの色が異なるのはN-1-i通り
|の選び方はN-1Ci
同じものをつなげてN-i個のブロックと見なせる
これに対してM*((M-1)のN-1-i)乗だけある
0<=i<=K
よりN-1-i>=N-1-K>=0
問題なし
'''
ans=0
for i in range(K+1):
ans+=(C(N-1,i)*M*pow(M-1,N-1-i,mod))%mod
ans%=mod
print(ans)
|
s = input()
l = len(s)
print('x'*l)
| 0 | null | 48,170,568,893,502 | 151 | 221 |
import math
n = int(input())
print((math.floor((n - 1) / 1000) + 1) * 1000 - n)
|
N = int(input())
while N > 0:
N -= 1000
if N < 0:
N *= -1
print(N)
| 1 | 8,513,391,785,060 | null | 108 | 108 |
def rle(t):
tmp2, count_, ans_ = t[0], 1, []
for i_ in range(1, len(t)):
if tmp2 == t[i_]:
count_ += 1
else:
ans_.append([tmp2, count_])
tmp2 = t[i_]
count_ = 1
ans_.append([tmp2, count_])
return ans_
S = list(input())
l = rle(S)
ans = [0] * (len(S) + 1)
count = 0
for i in range(len(l)):
if l[i][0] == '<':
for j in range(l[i][1] + 1):
ans[count + j] = max(ans[count + j], j)
elif l[i][0] == '>':
for k in range(l[i][1] + 1):
ans[count + k] = max(ans[count + k], l[i][1] - k)
count += l[i][1]
print(sum(ans))
|
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 10 ** 9 + 7
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rf(): return float(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]
def rf_(): return [float(_) for _ in rs().split()]
def divisors(n, sortedresult=True):
div = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
div.append(i)
if i != n // i:
div.append(n//i)
if sortedresult:
div.sort()
return div
# endregion
S = list(rs())
ans = 0
tmp = 0
cnt = 0
f = 1
for i in range(len(S)):
if S[i] == '<':
if f:
cnt += 1
else:
ans += cnt * (cnt - 1) // 2
ans += max(tmp, cnt)
cnt = 1
f = 1
else:
if f:
ans += cnt * (cnt - 1) // 2
tmp = cnt
cnt = 1
f = 0
else:
cnt += 1
ans += cnt * (cnt - 1) // 2
if f:
ans += cnt
else:
ans += max(tmp, cnt)
print(ans)
| 1 | 156,663,015,412,798 | null | 285 | 285 |
a, b = list(map(int, input().split()))
s = sum(list(map(int, input().split())))
print(max(a-s, -1))
|
# B - Homework
# N M
N, M = map(int, input().split())
my_list = list(map(int, input().split(maxsplit=M)))
if N < sum(my_list):
answer = -1
else:
answer = N - sum(my_list)
print(answer)
| 1 | 32,105,257,793,108 | null | 168 | 168 |
from sys import stdin
X = int(stdin.readline().rstrip())
print(10-X//200)
|
num = int(input())
if 400 <= num and num <= 599:
print("8")
elif num <= 799:
print("7")
elif num <= 999:
print("6")
elif num <= 1199:
print("5")
elif num <= 1399:
print("4")
elif num <= 1599:
print("3")
elif num <= 1799:
print("2")
elif num <= 1999:
print("1")
| 1 | 6,663,332,991,042 | null | 100 | 100 |
def solve():
n = int(input())
print((n+1)//2)
solve()
|
N = int(input())
print(N//2 + N % 2)
| 1 | 58,881,419,568,428 | null | 206 | 206 |
import sys
def m():
d={};input()
for e in sys.stdin:
if'f'==e[0]:print('yes'if e[5:]in d else'no')
else:d[e[7:]]=0
if'__main__'==__name__:m()
|
import sys
n = int(input())
s = set()
for i in range(n):
ins = input().split()
if ins[0] == "insert":
s.add(ins[1])
elif ins[0] == "find":
if ins[1] in s:
print("yes")
else:
print("no")
| 1 | 74,921,918,848 | null | 23 | 23 |
k = int(input())
s = input()
n = len(s)
MOD = 10**9+7
ans = 0
def comb(n, r, MOD):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % MOD
N = 2 * (10 ** 6) + 100
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, N + 1):
fact.append((fact[-1] * i) % MOD)
inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
factinv.append((factinv[-1] * inv[-1]) % MOD)
for i in range(k+1):
b = pow(26, k-i, MOD)
b *= pow(25, i, MOD)
b *= comb(i+n-1, n-1, MOD)
ans += (b % MOD)
print(ans%MOD)
|
K = int(input())
S = input()
mod = 10**9 + 7
class Combination:
def __init__(self, n):
self.facts = [1 for i in range(n+1)]
self.invs = [1 for i in range(n+1)]
for i in range(1, n+1):
self.facts[i] = self.facts[i-1] * i % mod
self.invs[i] = pow(self.facts[i], mod-2, mod)
def ncr(self, n, r):
if n < r:
return 0
if n < 0 or r < 0:
return 0
else:
return self.facts[n] * self.invs[r] * self.invs[n-r] % mod
def nhr(self, n, r):
if n < r:
return 0
if n < 0 or r < 0:
return 0
else:
return self.ncr(n+r-1, n-1)
N = K+len(S)
comb = Combination(K+len(S))
ans = 0
for i in range(K+1):
ans = (ans + comb.ncr(N-i-1, len(S)-1) * pow(25, N-i-len(S), mod) * pow(26, i, mod)) % mod
print(ans)
| 1 | 12,917,517,600,548 | null | 124 | 124 |
K = int(input())
string = "ACL"
print(string * K)
|
def is_prime(x):
if x == 1:
return 0
l = x ** 0.5
n = 2
while n <= l:
if x % n == 0:
return 0
n += 1
return 1
import sys
def solve():
N = int(input())
cnt = 0
for i in range(N):
cnt += is_prime(int(input()))
print(cnt)
solve()
| 0 | null | 1,084,747,719,172 | 69 | 12 |
x,y=map(int,input().split())
print(str(min(x,y))*max(x,y))
|
a,b = map(int,input().split())
l = [str(a)*b, str(b)*a]
l.sort()
print(l[0])
| 1 | 84,190,433,542,446 | null | 232 | 232 |
import sys
def gcd(a, b):
return gcd(b, a % b) if a % b else b
def lcm(a, b):
return a * b / gcd(a, b)
for line in sys.stdin:
data = map(int, line.split())
a, b = data
print "%d %d" % (gcd(a, b), lcm(a, b))
|
N = int(input())
C = input()
a = 0
rr = 0
lw = 0
for i in range(N):
if C[i] == 'R':
rr += 1
a = rr
for i in range(0, N):
if C[i] == 'W':
lw = lw+1
else:
rr = rr-1
a = min(a, max(lw, rr))
print(a)
| 0 | null | 3,132,373,711,900 | 5 | 98 |
#!/usr/bin/env python3
import sys
from itertools import chain
def solve(N: int, A: "List[int]"):
cnt = 0
for a in A:
if a == cnt + 1:
cnt += 1
if cnt == 0:
return -1
return N - cnt
def main():
tokens = chain(*(line.split() for line in sys.stdin))
N = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
answer = solve(N, A)
print(answer)
if __name__ == "__main__":
main()
|
if __name__ == '__main__':
A, B = map(int, input().split())
print(A*B)
| 0 | null | 65,097,063,181,180 | 257 | 133 |
import sys
K = int(sys.stdin.readline())
S = sys.stdin.readline().rstrip('\n')
# ## COMBINATION (MOD) ###
N_MAX = 10**6 # 問題サイズに合わせて変えておく
MOD = 10**9 + 7
inv = [0] * (N_MAX + 2)
inv[0] = 0 # 逆元テーブル計算用テーブル
inv[1] = 1
for i in range(2, N_MAX + 2):
inv[i] = -inv[MOD % i] * (MOD // i) % MOD
# K 文字追加
ans = 0
ln = len(S)
p1 = 1
p2 = 1
s2 = pow(26, K, MOD)
for i in range(1, K + 2):
ans += (p1 * p2 * s2) % MOD
ans %= MOD
# print(p1, p2, s2)
# pre
p1 = (p1 * (ln + i - 1) * inv[i]) % MOD
p2 = (p2 * 25) % MOD
# suf
s2 = (s2 * inv[26]) % MOD
print(ans)
|
from collections import defaultdict
# ----------
INF = float("inf")
MOD = 10 ** 9 + 7
# ----------
def combination(a, b):
if b > a - b:
return combination(a, a - b)
return fact[a] * ifact[b] * ifact[a-b]
K = int(input())
S = input().strip()
N = len(S)
# 階乗を前処理
fact = defaultdict(int)
fact[0] = 1
for i in range(1, N+K+1):
fact[i] = fact[i-1] * i
fact[i] %= MOD
# 階乗の逆元を前処理
ifact = defaultdict(int)
ifact[N+K] = pow(fact[N+K], MOD-2, MOD)
for i in reversed(range(1, N+K+1)):
ifact[i-1] = ifact[i] * i
ifact[i-1] %= MOD
ans = 0
for i in range(K+1):
now = pow(26, K-i, MOD)
now *= pow(25, i, MOD)
now %= MOD
now *= combination(i+N-1, N-1)
now %= MOD
ans += now
ans %= MOD
print(ans)
| 1 | 12,702,308,399,580 | null | 124 | 124 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
N,T,*ab = map(int, read().split())
AB = []
for a, b in zip(*[iter(ab)]*2):
AB.append((a, b))
AB.sort()
dp = [[0] * (T+1) for _ in range(N+1)]
ans = 0
for i in range(N):
w_i, v_i = AB[i]
for j in range(T):
if j < w_i:
dp[i+1][j] = dp[i][j]
else:
dp[i+1][j] = max(dp[i][j - w_i] + v_i, dp[i][j])
ans = max(ans, dp[i][T-1] + v_i)
print(ans)
if __name__ == "__main__":
main()
|
# https://note.nkmk.me/python-union-find/
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
N, M, K = map(int, input().split())
par = [-1]*N
#直接友達になっている人数とブロックしている人数をカウント
num = [0]*N
uf = UnionFind(N)
for _ in range(M):
a, b = map(int, input().split())
a -= 1
b -= 1
#友達関係をつなげる
uf.union(a, b)
#直接友達なのでカウントする
num[a] += 1
num[b] += 1
for _ in range(K):
c, d = map(int, input().split())
c -= 1
d -= 1
# print(f"c{c}, d{d}, uf.same(c, d) {uf.same(c, d)}")
#同じグループに属している場合、size()にカウントされるのでnumを増やす
if uf.same(c, d):
num[c] += 1
num[d] += 1
# print(num)
for i in range(N):
#直接友達関係の人と同じグループでブロックしている人、自分自身を除く人数が候補となる
print(uf.size(i)-1-num[i], end=" ")
| 0 | null | 106,114,120,243,418 | 282 | 209 |
print('10'[int(input())])
|
from functools import lru_cache
import sys
sys.setrecursionlimit(10 ** 8)
h,n=map(int,input().split())
ab=[tuple(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda abi:(abi[1]/abi[0],abi[0]))
@lru_cache(maxsize=None)
def dp(i):
if i<=0:
return 0
else:
ans=float('inf')
for a,b in ab:
val=b+dp(i-a)
if val<ans:
ans=val
else:
break
return ans
print(dp(h))
| 0 | null | 42,131,573,557,678 | 76 | 229 |
N = int(input())
X = int(input(),2)
def popcount(n):
return bin(n).count('1')
def f(n):
if n== 0:
return 1
count = 1
while n!=0:
n = n%popcount(n)
count += 1
return count
X_popcount = popcount(X)
X_mod_p = X%(X_popcount+1)
if X_popcount != 1:
X_mod_m = X%(X_popcount-1)
for i in range(N):
X_i = X ^ (1<<(N-i-1))
if X_i == 0:
ans = 0
elif X>>(N-i-1)&1 == 1:
if X_popcount == 1:
ans = 1
else:
ans = f((X_mod_m-pow(2, N-i-1, X_popcount-1))%(X_popcount-1))
else:
ans = f((X_mod_p+pow(2, N-i-1, X_popcount+1))%(X_popcount+1))
print(ans)
|
nums = [int(e) for e in input().split()]
a=nums[0]
b=nums[1]
c=nums[2]
d=nums[3]
max = a*c
if a * d > max:
max = a * d
if b * c > max:
max = b * c
if b * d > max:
max = b * d
print(max)
| 0 | null | 5,681,131,281,952 | 107 | 77 |
def main():
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split())
B1,B2 = map(int,input().split())
move = T1*(A1-B1) + T2*(A2-B2)
mid = T1*(A1-B1)
if move==0:
return -1
if move*mid > 0:
return 0
if move < 0:
move *= -1
else:
mid *= -1
if mid%move == 0:
return 2*(mid//move)
else:
return 2*(mid//move)+1
if __name__ == "__main__":
ans = main()
if ans==-1:
print("infinity")
else:
print(ans)
|
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
T1, T2 = MAP()
A1, A2 = MAP()
B1, B2 = MAP()
if T1*A1+T2*A2 == T1*B1+T2*B2:
print("infinity")
exit()
if (A1 < B1 and A2 < B2) or (B1 < A1 and B2 < A2):
print(0)
exit()
if A1 > B1:
A1, B1 = B1, A1
A2, B2 = B2, A2
if A1*T1+A2*T2 < B1*T1+B2*T2:
print(0)
exit()
F = A1*T1-B1*T1
L = A2*T2-B2*T2
S, T = divmod(-F, F+L)
if T == 0:
print(2*S)
else:
print(2*S+1)
| 1 | 131,472,734,258,320 | null | 269 | 269 |
n = int(input())
output = 'ACL'*n
print(output)
|
n, m = map(int, input().split())
c = list(map(int, input().split()))
INF = float("inf")
dp = [INF]*(n+1)
dp[0] = 0
for i in range(m):
for j in range(n+1):
if j + c[i] > n:
break
else:
dp[j + c[i]] = min(dp[j + c[i]], dp[j] + 1)
print(dp[n])
| 0 | null | 1,154,979,014,400 | 69 | 28 |
n, m = map(int, input().split())
A = [list(map(int, input().split())) for _ in [None] * n]
b = [int(input()) for _ in [None] * m]
for a in A:
print(sum([i * j for i, j in zip(a, b)]))
|
s=list(input())
k=0
bef="x"
n=[]
ans=0
def kai(n):
if n==0:
return 0
ret=0
for i in range(1,n+1):
ret+=i
return ret
for i in s:
if bef!=i:
if bef=="x":
st=i
bef=i
k+=1
continue
bef=i
n.append(k)
k=0
k+=1
n.append(k)
n.reverse()
if st==">":
ans+=kai(n.pop())
while len(n)!=0:
if len(n)==1:
ans+=kai(n.pop())
else:
f=n.pop()
s=n.pop()
if f>s:
ans+=kai(f)+kai(s-1)
else:
ans+=kai(f-1)+kai(s)
#print("{} {}".format(f,s))
print(ans)
| 0 | null | 79,053,058,116,648 | 56 | 285 |
hillheight = []
for i in range(0, 10):
hillheight.append(int(raw_input()))
hillheight.sort()
for i in range(0, 3):
print(hillheight[-1-i])
|
import sys,math,collections,itertools
input = sys.stdin.readline
N,K=list(map(int,input().split()))
R,S,P=list(map(int,input().split()))
T = input().rstrip()
s =T.replace('r','P') #P
ss=s.replace('s','R') #R
sss=ss.replace('p','S') #S
sl = list(sss)
for i in range(K,N):
if sl[i]==sl[i-K]:
sl[i] = '0'
sc = collections.Counter(sl)
print(sc['R']*R + sc['P']*P + sc['S']*S)
| 0 | null | 53,153,149,397,426 | 2 | 251 |
import sys
#+++++
def main():
n, m = map(int, input().split())
s=input()
s=s[::-1]
#arch=[len(s)+100]*len(s)
pos=0
ret=[]
while pos < len(s)-1:
for mi in range(m,0,-1):
if pos+mi >= len(s):
pass
elif s[pos+mi]=='0':
pos += mi
ret.append(mi)
#print(pos)
break
else:
pass
else:
return -1
r=ret[::-1]
print(*r)
'''
def main2():
n, m = map(int, input().split())
s = input()
tt=[-1]*len(s)
t_parent=[-1]*len(s)
rs=s[::-1]
open_list=[0]
max_dist = 0
while True#len(open_list) > 0:
st, parent, count = open_list.pop()
for i in range(m, 0, -1):
aa = st + i
if aa > n+1:
pass
#gmマス
if rs[aa] == 1:
continue
#アクセス済み
if tt[aa] > 0:
break
tt[aa] = count+1
t_parent[aa] = st
open_list.append(aa, st, count+1)
print(1)
'''
#+++++
isTest=False
def pa(v):
if isTest:
print(v)
if __name__ == "__main__":
if sys.platform =='ios':
sys.stdin=open('inputFile.txt')
isTest=True
else:
pass
#input = sys.stdin.readline
ret = main()
if ret is not None:
print(ret)
|
n, m = map(int, input().split())
s = list(str(input()))
s = list(reversed(s))
#print(s)
ds = []
d = 1
for i in range(1, n+1):
if s[i] == '0':
ds.append(d)
d = 1
else:
d += 1
#print(ds)
temp0 = 0
ans = []
for i in range(len(ds)):
if ds[i] > m:
print(-1)
exit()
temp1 = temp0 + ds[i]
#print(temp1)
if temp1 > m:
ans.append(temp0)
temp0 = ds[i]
elif temp1 == m:
ans.append(temp1)
temp0 = 0
else:
temp0 = temp1
else:
if temp0 != 0:
ans.append(temp0)
ans = list(reversed(ans))
print(*ans)
| 1 | 139,553,573,694,180 | null | 274 | 274 |
while True:
try:
a=input().split()
except:
break
b=int(a[0])+int(a[1])
print(len(str(b)))
|
import sys
for line in sys.stdin:
print(len(str(sum(list(map(int, line.split()))))))
| 1 | 115,870,690 | null | 3 | 3 |
import sys
def gcd(a,b):
r= b % a
while r != 0:
a,b = r,a
r = b % a
return a
def lcm(a,b):
return int(a*b/gcd(a,b))
for line in sys.stdin:
a,b = sorted(map(int, line.rstrip().split(' ')))
print("{} {}".format(gcd(a,b),lcm(a,b)))
|
import sys
def gcd(inta, intb):
large = max(inta, intb)
small = min(inta,intb)
mod = large % small
if mod ==0:
return small
else:
return gcd(small, mod)
def lcm(inta, intb, intgcd):
return (inta * intb // intgcd)
sets = sys.stdin.readlines()
for line in sets:
a, b = map(int, line.split())
c = gcd(a, b)
print(c, lcm(a, b, c))
| 1 | 781,767,950 | null | 5 | 5 |
N, K = map(int, input().split())
def sub_sum(l, r):
return (l + r) * (r - l + 1) / 2
ans = 0
for i in range(K, N+2):
l = sub_sum(0, i-1)
r = sub_sum(N-i+1, N)
ans += r - l + 1
ans = ans % (10**9+7)
print(int(ans))
|
n,K = list(map(int,input().split()))
mod = 10**9+7
ans = 0
for k in range(K,n+2):
#ans += (n+1)*n//2 -(n+1-k)*(n-k)//2-k*(k-1)//2 + 1
#ans += (n**2+n)//2 - (n**2-n*k+n-k-n*k+k**2)//2 - (k**2-k)//2 + 1
#ans += (n**2+n - (n**2-n*k+n-k-n*k+k**2) -k**2 + k)//2 + 1
#ans += (n**2 + n - n**2 + n*k - n + k + n*k - k**2 - k**2 + k)//2 + 1
#ans += (2*n*k + 2*k - 2*k**2)//2 + 1
ans += n*k - k**2 + k + 1
print(ans%mod)
| 1 | 33,262,339,698,588 | null | 170 | 170 |
n=int(input())
k=int(input())
if n<10:
if k==0:
print(1)
elif k==1:
print(n)
else:
print(0)
exit()
#10
#0の数は高々3つまでなので、jは0,1,2,3の配列だけ持てば良い
#i桁目までは高々100
#
#dp[i][j][smaller]=
lenn=len(str(n))
dp=[[[0]*2 for _ in range(4)] for _ in range(lenn)]
#smallerは、0::通常、1:未満の2パターン
if int(str(n)[0])==1:
dp[0][0][0]=1
dp[0][1][1]=1
else:
dp[0][0][0]=1
dp[0][1][0]=int(str(n)[0])-1
dp[0][1][1]=1
#print(dp)
for i in range(lenn-1):
dp[i+1][0][0]+=dp[i][0][0]
dp[i+1][1][0]+=dp[i][0][0]*9+dp[i][1][0] #+dp[i][0][1]*max(0,(int(str(n)[i])-1))
dp[i+1][2][0]+=dp[i][1][0]*9+dp[i][2][0] #+dp[i][1][1]*max(0,(int(str(n)[i])-1))
dp[i+1][3][0]+=dp[i][2][0]*9+dp[i][3][0] #+dp[i][2][1]*max(0,(int(str(n)[i])-1))
#print(dp)
if int(str(n)[i+1])==0:
dp[i+1][0][1]+=dp[i][0][1]
dp[i+1][1][1]+=dp[i][1][1]
dp[i+1][2][1]+=dp[i][2][1]
dp[i+1][3][1]+=dp[i][3][1]
elif int(str(n)[i+1])==1:
dp[i+1][1][1]+=dp[i][0][1]
dp[i+1][2][1]+=dp[i][1][1]
dp[i+1][3][1]+=dp[i][2][1]
dp[i+1][1][0]+=dp[i][1][1]
dp[i+1][2][0]+=dp[i][2][1]
dp[i+1][3][0]+=dp[i][3][1]
else:
dp[i+1][1][1]+=dp[i][0][1]
dp[i+1][2][1]+=dp[i][1][1]
dp[i+1][3][1]+=dp[i][2][1]
dp[i+1][1][0]+=dp[i][1][1]
dp[i+1][2][0]+=dp[i][2][1]
dp[i+1][3][0]+=dp[i][3][1]
dp[i+1][1][0]+=dp[i][0][1]*(int(str(n)[i+1])-1)
dp[i+1][2][0]+=dp[i][1][1]*(int(str(n)[i+1])-1)
dp[i+1][3][0]+=dp[i][2][1]*(int(str(n)[i+1])-1)
#print(dp)
print(sum(dp[-1][k]))
|
nn = list(map(int, list(input())))
L = len(nn)
K = int(input())
dp = [[[0] * (4) for _ in range(2)] for __ in range(L + 1)]
dp[0][0][0] = 1
for i, n in enumerate(nn):
for x in range(0, 10):
if x == 0:
dp[i + 1][1][0] += dp[i][1][0]
dp[i + 1][1][1] += dp[i][1][1]
dp[i + 1][1][2] += dp[i][1][2]
dp[i + 1][1][3] += dp[i][1][3]
else:
dp[i + 1][1][1] += dp[i][1][0]
dp[i + 1][1][2] += dp[i][1][1]
dp[i + 1][1][3] += dp[i][1][2]
for x in range(0, n + 1):
if x == 0:
dp[i + 1][0 if x == n else 1][0] += dp[i][0][0]
dp[i + 1][0 if x == n else 1][1] += dp[i][0][1]
dp[i + 1][0 if x == n else 1][2] += dp[i][0][2]
dp[i + 1][0 if x == n else 1][3] += dp[i][0][3]
else:
dp[i + 1][0 if x == n else 1][1] += dp[i][0][0]
dp[i + 1][0 if x == n else 1][2] += dp[i][0][1]
dp[i + 1][0 if x == n else 1][3] += dp[i][0][2]
print(dp[-1][0][K] + dp[-1][1][K])
| 1 | 75,558,399,715,708 | null | 224 | 224 |
import math
x1,y1,x2,y2=map(float,raw_input().split())
print "%.5f"%(float(math.sqrt((x1-x2)**2+(y1-y2)**2)))
|
N = int(input())
A = list(map(int, input().split()))
ans = 0
B = []
C = []
maA = max(A) + N -1
for k in range(N):
if A[k] + k <= maA:
B.append(A[k]+k)
if -A[k] + k >0:
C.append(-A[k]+k)
B.sort()
C.sort()
c = 0
b = 0
while b < len(B) and c < len(C):
if B[b] == C[c]:
s = 0
t = 0
j = float('inf')
k = float('inf')
for j in range(b, len(B)):
if B[b] == B[j]:
s += 1
else:
break
for k in range(c, len(C)):
if C[c] == C[k]:
t +=1
else:
break
ans += s*t
b = j
c = k
continue
elif B[b] > C[c]:
c += 1
else:
b += 1
#print(B)
#print(C)
print(ans)
| 0 | null | 13,113,296,409,422 | 29 | 157 |
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10**9 + 7
ans = 1
if k == n:
for i in range(n):
ans *= a[i]
ans %= mod
print(ans)
exit()
if max(a) < 0 and k%2 == 1:
a.sort(reverse=True)
for i in range(k):
ans *= a[i]
ans %= mod
print(ans)
exit()
a.sort(key=lambda x: abs(x))
cnt = 0
for i in range(1, k+1):
ans *= a[-i]
ans %= mod
if a[-i] < 0:
cnt += 1
if cnt%2 == 0:
print(ans)
else:
a_plus = None
a_minus = None
b_plus = None
b_minus = None
for i in range(k, 0, -1):
if a[-i] >= 0 and a_plus == None:
a_plus = a[-i]
if a[-i] < 0 and a_minus == None:
a_minus = a[-i]
for i in range(k+1, n+1):
if a[-i] >= 0 and b_plus == None:
b_plus = a[-i]
if a[-i] < 0 and b_minus == None:
b_minus = a[-i]
if a_plus == None or b_minus == None:
ans *= pow(a_minus, mod-2, mod)
ans %= mod
ans *= b_plus
ans %= mod
elif a_minus == None or b_plus == None:
ans *= pow(a_plus, mod-2, mod)
ans %= mod
ans *= b_minus
ans %= mod
else:
if abs(a_plus*b_plus) > abs(a_minus*b_minus):
ans *= pow(a_minus, mod-2, mod)
ans %= mod
ans *= b_plus
ans %= mod
else:
ans *= pow(a_plus, mod-2, mod)
ans %= mod
ans *= b_minus
ans %= mod
print(ans)
|
class dice:
def __init__(self, numlist):
self._men = {"T": numlist[0],
"B": numlist[5],
"N": numlist[4],
"S": numlist[1],
"W": numlist[3],
"E": numlist[2]}
def roll(self, direction):
t = dict(self._men)
if direction == "N":
self._men["T"] = t["S"]
self._men["B"] = t["N"]
self._men["N"] = t["T"]
self._men["S"] = t["B"]
elif direction == "S":
self._men["T"] = t["N"]
self._men["B"] = t["S"]
self._men["S"] = t["T"]
self._men["N"] = t["B"]
elif direction == "W":
self._men["T"] = t["E"]
self._men["B"] = t["W"]
self._men["W"] = t["T"]
self._men["E"] = t["B"]
elif direction == "E":
self._men["T"] = t["W"]
self._men["B"] = t["E"]
self._men["W"] = t["B"]
self._men["E"] = t["T"]
def gettop(self):
return self._men["T"]
def decode():
numlist = [int(x) for x in input().split()]
dlist = input()
return numlist, dlist
if __name__ == '__main__':
numlist, dlist = decode()
d1 = dice(numlist)
for c in dlist:
d1.roll(c)
print(d1.gettop())
| 0 | null | 4,895,284,603,498 | 112 | 33 |
H, W = map(int, input().split())
S = []
for _ in range(H):
S.append(input())
import queue, itertools
dxy = ((1,0), (-1,0), (0,1), (0,-1))
ans = 0
for s in itertools.product(range(H), range(W)):
if S[s[0]][s[1]] == '#': continue
q = queue.Queue()
dist = [[-1]*W for _ in range(H)]
q.put(s)
dist[s[0]][s[1]] = 0
while not q.empty():
y, x = q.get()
for dx, dy in dxy:
nx, ny = x+dx, y+dy
if nx<0 or ny<0 or nx>=W or ny>=H or S[ny][nx] == '#' or dist[ny][nx] >= 0:
continue
dist[ny][nx] = dist[y][x] + 1
q.put((ny, nx))
ans = max(ans, max(map(max, dist)))
print(ans)
|
N = int(input())
a = list(map(int,input().split()))
num = 1
for i in range(N):
if a[i] == num:
num += 1
if num == 1:
print(-1)
exit()
print(N - num + 1)
| 0 | null | 104,455,143,808,620 | 241 | 257 |
n = int(input())
# cs = ['W' for i in range(200000)]
cs = input()
w_count = 0
for c in cs:
if c == 'W':
w_count += 1
if w_count == 0:
print(0)
exit()
rest = cs[-w_count:]
answer = 0
for c in rest:
if c == 'R':
answer += 1
print(answer)
|
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq
def ri():
return int(input())
def rl():
return list(map(int, input().split()))
def solve():
n = ri()
C = input()
if C[0] == "R":
R = [1]
W = [0]
else:
R = [0]
W = [1]
for c in C[1:]:
if c == "R":
R.append(1 + R[-1])
W.append(W[-1])
else:
W.append(1 + W[-1])
R.append(R[-1])
best_cost = min(R[-1], W[-1])
for i in range(n):
rl = R[i]
wl = W[i]
rr = R[-1] - rl
wr = W[-1] - wl
swaps = min(wl, rr)
flips = wl + rr - 2 * swaps
best_cost = min(best_cost, flips + swaps)
print (best_cost)
mode = 's'
if mode == 'T':
t = ri()
for i in range(t):
solve()
else:
solve()
| 1 | 6,361,554,056,402 | null | 98 | 98 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *
N = INT()
L = LIST()
L.sort()
ans = 0
for i in range(N-2):
a = L[i]
for j in range(i+1, N-1):
b = L[j]
idx = bisect_left(L, a+b) - 1
if j < idx:
ans += idx - j
print(ans)
|
T1, T2 = map(int,input().split())
A1, A2 = map(int,input().split())
B1, B2 = map(int,input().split())
T = T1*A1+T2*A2
A = T1*B1+T2*B2
if T == A:
print("infinity")
exit()
if T > A:
if A1 > B1:
print(0)
exit()
else:
tdif = T-A #7-5
pdif = T1*(B1-A1) #5
if pdif%tdif == 0:
ans = 2*(pdif//tdif)+1
else:
ans = 2*(1+pdif//tdif)
ans -=1 #原点の分を引く
else:
if B1 > A1:
print(0)
exit()
else:
tdif = A-T #7-5
pdif = T1*(A1-B1) #5
if pdif%tdif == 0:
ans = 2*(pdif//tdif)+1
else:
ans = 2*(1+pdif//tdif)
ans -=1 #原点の分を引く
print(ans)
| 0 | null | 151,047,768,687,530 | 294 | 269 |
w = input()
count = 0 # ????????????????????´?????°.
while True:
line = input()
if line == "END_OF_TEXT":
break
for word in line.split():
if word.lower() == w.lower():
count += 1
print(count)
|
n = int(input())
A = []
B = []
for i in range(n):
a, b = map(int, input().split())
z = a + b
w = a - b
A.append(z)
B.append(w)
P = abs(max(A) - min(A))
Q = abs(max(B) - min(B))
print(max(P, Q))
| 0 | null | 2,611,494,807,778 | 65 | 80 |
h,w,k = map(int,input().split())
ls = [str(input()) for _ in range(h)]
a = [[] for _ in range(2**h)]
b = [[] for _ in range(2**w)]
for i in range(2**h):
for j in range(h):
if (i>>j)&1:
a[i].append(j)
for s in range(2**w):
for l in range(w):
if (s>>l)&1:
b[s].append(l)
p = 0
for e in range(2**h):
for f in range(2**w):
cnt = 0
for g in range(len(ls)):
if g not in a[e]:
di = list(ls[g])
for t in range(len(di)):
if t not in b[f]:
if di[t] == "#":
cnt += 1
if cnt == k:
p += 1
print(p)
|
H, W, K = [int(v) for v in input().split()]
G = []
for _ in range(H):
G.append(input())
ans = 0
for mask_r in range(1 << H):
for mask_c in range(1 << W):
black = 0
for i in range(H):
for j in range(W):
if ((mask_r >> i) & 1 == 0) and ((mask_c >> j) & 1 == 0) and G[i][j] == "#":
black += 1
if black == K:
ans += 1
print(ans)
| 1 | 8,991,640,442,958 | null | 110 | 110 |
def main():
input()
in_a = list(map(int, input().split()))
leaves = [0] * len(in_a)
leaves[-1] = in_a[-1]
if in_a[0] > 1:
print(-1)
return
#for i in range(len(in_a)-2, -1, -1):
# leaves[i] = leaves[i+1] + in_a[i]
for i in range(len(in_a) - 1, 1, -1):
leaves[i-1] = leaves[i] + in_a[i-1]
node = 1
total = 1
for i in range(1, len(in_a)):
n = (node - in_a[i-1]) * 2
if n < in_a[i]:
print(-1)
return
node = min(n, leaves[i])
total += node
print(total)
if __name__ == '__main__':
main()
|
import numpy as np
import random
rand = False
if rand:
N = 10 ** 5
A = random.choices(range(1, 10**6), k=N)
else:
N = int(input())
A = list(map(int, input().split()))
A.sort()
MX = max(A)
ret = np.zeros(MX+1, dtype=np.bool)
A = np.array(A, dtype=np.int32)
ret[ A ] = True
for i in range(N-1):
m = A[i] * 2
if A[i] == A[i+1]: m = A[i]
ret[ np.arange(m, MX+1, A[i]) ] = False
print(np.sum(ret))
| 0 | null | 16,699,857,624,604 | 141 | 129 |
S=input()
Week=['SUN','MON','TUE','WED','THU','FRI','SAT']
for i in range(7):
if S==Week[i]:
today=i
print(7-today)
|
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
# from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
n,m = inpm()
way = [[] for _ in range(n+1)]
for i in range(m):
a,b = inpm()
way[a].append(b)
way[b].append(a)
ans = [0 for i in range(n+1)]
q = queue.Queue()
q.put((1,0))
while not q.empty():
room,sign = q.get()
if ans[room] != 0:
continue
ans[room] = sign
for i in way[room]:
q.put((i,room))
print('Yes')
for i in range(2,n+1):
print(ans[i])
| 0 | null | 76,361,110,270,996 | 270 | 145 |
string = ''
while True:
hoge = input().strip()
if hoge == '-':
print (string)
break
if hoge.isalpha():
if string:
print (string)
string = hoge
count = 0
else:
if count == 0:
count = hoge
continue
else:
string = string[int(hoge):] + string[:int(hoge)]
|
while True:
string = input()
if string == "-":
break
else:
s = 0
for i in range(int(input())):
s += int(input())
s = s % len(string)
print(string[s:] + string[:s])
| 1 | 1,881,528,977,984 | null | 66 | 66 |
N = [int(_) for _ in input()]
dp = [[0, 0] for _ in range(len(N))]
dp[0][0] = min(N[0], 11 - N[0])
dp[0][1] = min(N[0] + 1, 10 - N[0])
for i in range(1, len(N)):
dp[i][0] = min(dp[i - 1][0] + N[i], dp[i - 1][1] + 10 - N[i])
dp[i][1] = min(dp[i - 1][0] + N[i] + 1, dp[i - 1][1] + 9 - N[i])
print(dp[-1][0])
|
n = list(map(int,input()))[::-1]
n.append(0)
for i in range(len(n)):
if n[i] >= 6 or (n[i] == 5 and n[i+1] >= 5):
n[i] = 10 - n[i]
n[i+1] += 1
print(sum(n))
| 1 | 71,219,336,856,408 | null | 219 | 219 |
import math
r = input()
print "%0.6f %0.6f"%(r*r*math.pi,r*2*math.pi)
|
from math import pi # 円周率
# 浮動小数点数で読む
r = float(input())
area = r * r * pi
cir =(r+r) * pi
print(f'{(area):.6f} {(cir):.6f}')
| 1 | 635,703,021,238 | null | 46 | 46 |
import sys
sys.setrecursionlimit(10**6)
N, u, v = map(int, input().split())
tree = [[] for _ in range(N)]
for _ in range(N-1):
a, b = map(int, input().split())
tree[a-1].append(b-1)
tree[b-1].append(a-1)
#print(tree)
def calc_dist(dlist, n, dist, nnode):
for c in tree[n]:
if c == nnode:
continue
dlist[c] = dist
calc_dist(dlist, c, dist+1, n)
u_dist_list = [0] * N
calc_dist(u_dist_list, u-1, 1, -1)
#print(u_dist_list)
v_dist_list = [0] * N
calc_dist(v_dist_list, v-1, 1, -1)
#print(v_dist_list)
ans = 0
for i in range(N):
if (v_dist_list[i] - u_dist_list[i]) > 0 and v_dist_list[i] > ans:
ans = v_dist_list[i] - 1
print(ans)
|
import sys
input = sys.stdin.readline
N,u,v=map(int,input().split())
E=[tuple(map(int,input().split())) for i in range(N-1)]
EDGE=[[] for i in range(N+1)]
for x,y in E:
EDGE[x].append(y)
EDGE[y].append(x)
from collections import deque
T=[-1]*(N+1)
Q=deque()
Q.append(u)
T[u]=0
while Q:
x=Q.pop()
for to in EDGE[x]:
if T[to]==-1:
T[to]=T[x]+1
Q.append(to)
A=[-1]*(N+1)
Q=deque()
Q.append(v)
A[v]=0
while Q:
x=Q.pop()
for to in EDGE[x]:
if A[to]==-1:
A[to]=A[x]+1
Q.append(to)
OK=[0]*(N+1)
for i in range(N+1):
if T[i]<A[i]:
OK[i]=1
ANS=0
for i in range(N+1):
if OK[i]==1:
ANS=max(ANS,A[i])
print(max(0,ANS-1))
| 1 | 117,550,879,280,462 | null | 259 | 259 |
class Combination:
def __init__(self, mod, max_n):
self.MOD = mod
self.MAX_N = max_n
self.f = self.factorial(self.MAX_N)
self.f_inv = [self.inv(x) for x in self.f]
def inv(self,x):
return pow(x, self.MOD-2, self.MOD)
def factorial(self, n):
res = [1]
for i in range(1,n+1):
res.append(res[-1] * i % self.MOD)
return res
def comb(self, n, r):
return (self.f[n] * self.f_inv[r] % self.MOD) * self.f_inv[n-r] % self.MOD
X, Y = map(int,input().split())
k, l = (2*Y-X)//3, (2*X-Y)//3
if (X + Y) % 3 != 0 or k < 0 or l < 0:
print(0)
exit()
CB = Combination(10**9+7, k+l)
print(CB.comb(k+l,k))
|
import sys
A, B = (int(x) for x in input().split())
num=0
while int(num*0.08)<=A:
if int(num*0.08)==A and int(num*0.1)==B:
print(num)
sys.exit(0)
num+=1
print(-1)
| 0 | null | 103,296,978,596,350 | 281 | 203 |
tp = hp = 0
for i in range(int(input())):
taro, hana = map(list, input().split())
short = min(len(taro), len(hana))
result = 0
for k in range(short):
if ord(taro[k]) != ord(hana[k]):
result = ord(taro[k]) - ord(hana[k])
break
if not result:
if len(taro) < len(hana):
result = -1
elif len(taro) > len(hana):
result = 1
if result > 0:
tp += 3
elif result < 0:
hp += 3
else:
tp += 1
hp += 1
print(tp, hp)
|
import sys
input = sys.stdin.readline
N, P = map(int, input().split())
S = list(input().rstrip())
if P in {2, 5}:
ans = 0
for i, s in enumerate(S):
if int(s) % P == 0:
ans += i+1
else:
ans = 0
T = [0]*P
T[0] = 1
tmp = 0
k = 1
for s in reversed(S):
tmp = (tmp + k * int(s)) % P
k = k * 10 % P
ans += T[tmp]
T[tmp] += 1
print(ans)
| 0 | null | 30,223,669,156,512 | 67 | 205 |
import itertools
def check(targets):
if targets[1] > targets[0] and targets[2] > targets[1]:
return True
else:
return False
if __name__ == "__main__":
A, B, C = map(int, input().split())
K = int(input())
targets = [A, B, C]
answer = 'No'
cases = itertools.product([0, 1, 2], repeat=K)
for case in cases:
copy_targets = targets.copy()
for i in case:
copy_targets[i] = copy_targets[i] * 2
if check(copy_targets):
answer = 'Yes'
break
print(answer)
|
def main():
A, B, C = map(int, input().split())
K = int(input())
for i in range(K):
if A >= B:
B *= 2
elif B >= C:
C *= 2
return (A < B) and (B < C)
if main():
print('Yes')
else:
print('No')
| 1 | 6,821,128,462,230 | null | 101 | 101 |
"""from collections import *
from itertools import *
from bisect import *
from heapq import *
import math
from fractions import gcd"""
T1,T2=map(int,input().split())
A1,A2=map(int,input().split())
B1,B2=map(int,input().split())
A1*=T1
A2*=T2
B1*=T1
B2*=T2
if A1+A2==B1+B2:
print("infinity")
else:
if A1+A2<B1+B2:
A1,B1=B1,A1
A2,B2=B2,A2
if A1>B1:
print(0)
else:
print(((B1-A1)//(A1+A2-(B1+B2)))*2 +1-(((B1-A1)%(A1+A2-(B1+B2)))==0)*1)
|
s,t = map(str, input().split())
a,b = map(int, input().split())
u = input()
print(a-1 if s==u else a, b if s==u else b-1)
| 0 | null | 102,183,548,670,488 | 269 | 220 |
try:
inp = input().split()
L = int(inp[0])
R = int(inp[1])
d = int(inp[2])
if L >= 1 and R >= 1 and L <= R and L<=100 and R<=100 and d>=1 and d<=100:
counter = 0
for i in range(L,R+1):
if i%d == 0:
counter += 1
print(counter)
except Exception as e:
print(e)
|
# coding: utf-8
def main():
s = input()
t = input()
ans = len(t)
for i in range(len(s) - len(t) + 1):
a = s[i:i+len(t)]
# print(a, t)
ans_list = [1 for x, y in zip(a, t) if x!=y]
tmp_ans = sum(ans_list)
ans = min(ans, tmp_ans)
if ans == 0:
break
print(ans)
main()
| 0 | null | 5,613,378,777,228 | 104 | 82 |
N,K = map(int,input().split())
for i in range(10*10):
num = N // (K**i)
if num < 1:
print(i)
exit()
|
N,K=list(map(int, input().split()))
ct=0
while N>0:
N=N//K
ct+=1
print(ct)
| 1 | 64,369,908,076,362 | null | 212 | 212 |
import collections
n = int(input())
adj_list = []
for _ in range(n):
adj = list(map(int, input().split(" ")))
adj_list.append([c - 1 for c in adj[2:]])
distances = [-1 for _ in range(n)]
queue = collections.deque()
queue.append(0)
distances[0] = 0
while queue:
p = queue.popleft()
for next_p in adj_list[p]:
if distances[next_p] == -1:
distances[next_p] = distances[p] + 1
queue.append(next_p)
for i in range(n):
print(i+1, distances[i])
|
from collections import deque
n = int(input())
G = []
for _ in range(n):
u, k, *v = map(int, input().split())
u -= 1
G.append(v)
q = deque()
seen = [False] * n
dist = [-1] * n
def main():
q.append(0)
seen[0] = True
dist[0] = 0
while len(q) > 0:
now_v = q.popleft()
for new_v in G[now_v]:
new_v -= 1
if seen[new_v] is True:
continue
seen[new_v] = True
q.append(new_v)
# print(now_v, new_v)
dist[new_v] = dist[now_v] + 1
for i in range(n):
print(i+1, dist[i])
if __name__ == '__main__':
main()
| 1 | 3,789,377,900 | null | 9 | 9 |
N = int(input())
music = []
for i in range(N):
music.append(input().split())
X = (input())
Time = 0
kama = False
for s,t in music:
if kama:
Time += int(t)
if s == X:
kama = True
print(Time)
|
import math
a = float(input())
b = math.acos(-1)
print "%f %f" % (a * a * b , 2 * a * b)
| 0 | null | 48,861,377,570,500 | 243 | 46 |
dict = {'ABC':'ARC', 'ARC':'ABC'}
print(dict[input()])
|
def resolve():
S = str(input())
if S =='ABC':
print('ARC')
else:
print('ABC')
return
resolve()
| 1 | 24,125,285,163,776 | null | 153 | 153 |
s=input()
t=input()
if len(s)+1==len(t) and s==t[:len(s)]:
print('Yes')
else:print('No')
|
# -*- coding: utf-8 -*-
import itertools
N, K = map(int, input().split())
a = [0] * (N+1)
for i in range(N+1):
a[i] = i
max_total = 0
min_total = 0
ans = 0
for k in range(K, N+2):
# 和の最大(10**100 は無視): 大きい順にk個選んだ場合
max_total = k * ((N-k+1) + N) // 2
# 和の最小(10**100 は無視): 小さい順にk個選んだ場合
min_total = k * (0 + (k-1)) // 2
# 最小と最大の間は全パターン取り得るので差が個数になる
ans += (max_total - min_total + 1)
print(ans % (10**9 + 7))
| 0 | null | 27,107,779,074,108 | 147 | 170 |
n=int(input())
a=[int(j) for j in input().split()]
p=[0]*n
d=[0]*n
for i in range(n):
p[i]=a[i]+p[i-2]
if (i&1):
d[i]=max(p[i-1],a[i]+d[i-2])
else:
d[i]=max(d[i-1],a[i]+d[i-2])
print(d[-1])
|
from collections import defaultdict
N = int(input())
*A, = map(int, input().split())
INF = 10**20
dp = [[defaultdict(lambda :-INF) for _ in range(N+1)] for _ in range(2)]
dp[0][0][0] = 0
for i in range(1, N+1):
for j in range(i//2-1, i//2+2):
dp[1][i][j] = max(dp[1][i][j], dp[0][i-1][j-1]+A[i-1])
dp[0][i][j] = max(dp[1][i-1][j], dp[0][i-1][j])
ans = max(dp[1][N][N//2], dp[0][N][N//2])
print(ans)
| 1 | 37,168,762,438,192 | null | 177 | 177 |
# -*- coding: utf-8 -*-
n, m= [int(i) for i in input().split()]
for i in range(0,m):
if n-2*i-1>n/2 or n%2==1:
print(i+1,n-i)
else:
print(i+1,n-i-1)
|
n, m = map(int, input().split())
if n % 2 or m < n//4:
for i in range(m):
print(i+1, n-i)
else:
for i in range(n//4):
print(i+1, n-i)
for i in range(n//4, m):
print(i+1, n-i-1)
| 1 | 28,740,473,005,632 | null | 162 | 162 |
def main():
import re
n = int(input())
s = input()
rindex = set()
gindex = set()
bindex = set()
for i in range(n):
if s[i] == "R":
rindex.add(i)
elif s[i] == "G":
gindex.add(i)
else:
bindex.add(i)
ans = len(rindex) * len(gindex) * len(bindex)
for r in rindex:
for g in gindex:
if r > g:
gap = r - g
b1 = r + gap
b2 = g - gap
b3 = g + (gap/2)
elif r < g:
gap = g - r
b1 = g + gap
b2 = r - gap
b3 = r + (gap/2)
if b1 in bindex:
ans -= 1
if b2 in bindex:
ans -= 1
if b3 in bindex:
ans -= 1
print(ans)
if __name__ == "__main__":
main()
|
s = input()
print('Yes') if s[2:3] == s[3:4] and s[4:5] == s[5:6] else print('No')
| 0 | null | 39,221,509,014,518 | 175 | 184 |
n= int(input())
ans=(n+1)//2
print(ans)
|
n = int(input())
ans = (n//2) + (n%2)
print (ans)
| 1 | 58,847,184,969,008 | null | 206 | 206 |
n=int(input());l=list(map(int,input().split()));p=[0]*n;d=[0]*n;p[0]=l[0]
for i in range(1,n):p[i]=l[i]+p[i-2];d[i]=max(p[i-1]if(i&1)else d[i-1],l[i]+(d[i-2]if i>1else 0))
print(d[-1])
|
#!/usr/bin/env python3
# coding: utf-8
import collections
def debug(arg):
if __debug__:
pass
else:
import sys
print(arg, file=sys.stderr)
def main():
pass
N, *A = map(int, open(0).read().split())
a = dict(enumerate(A, 1))
dp = collections.defaultdict(lambda: -float("inf"))
dp[0, 0] = 0
dp[1, 0] = 0
dp[1, 1] = a[1]
for i in range(2, N + 1):
jj = range(max(i // 2 - 1, 1), (i + 1) // 2 + 1)
for j in jj:
x = dp[i - 2, j - 1] + a[i]
y = dp[i - 1, j]
dp[i, j] = max(x, y)
print(dp[N, N // 2])
if __name__ == "__main__":
main()
| 1 | 37,504,419,876,880 | null | 177 | 177 |
MOD = 10 ** 9 + 7
X, Y = map(int, input().split())
if (X + Y) % 3 or Y > 2 * X or Y < X // 2:
print(0)
exit()
n = (X + Y) // 3
r = X - (X + Y) // 3
num, den = 1, 1
if n - r < r:
r = n - r
for i in range(1, r + 1):
num *= n - i + 1
num %= MOD
den *= i
den %= MOD
print((num * pow(den, MOD - 2, MOD)) % MOD)
|
mod=10**9+7
def fact(n):
ans=1
for i in range(1,n+1):
ans*=i
ans%=mod
return ans
x,y=map(int,input().split())
if (x+y)%3!=0: print(0)
else:
temp=(x+y)//3
if x<temp or x>2*temp: print(0)
else:
dx=x-temp
fc_temp=fact(temp)
fc_dx=fact(dx)
fc_temp_dx=fact(temp-dx)
fc_dx=pow(fc_dx,mod-2,mod)
fc_temp_dx=pow(fc_temp_dx,mod-2,mod)
ans=fc_temp*fc_dx%mod*fc_temp_dx%mod
print(ans)
| 1 | 150,399,374,716,700 | null | 281 | 281 |
from sys import stdin
input = stdin.readline
def solve():
n = int(input())
r = n % 1000
res = 0 if r == 0 else 1000 - r
print(res)
if __name__ == '__main__':
solve()
|
s = input()
t = input()
n = len(s) - len(t)
l = len(t)
res = 0
for i in range(n+1):
cnt = 0
for j in range(l):
if s[i+j] == t[j]:
cnt += 1
res = max(res, cnt)
print(l - res)
| 0 | null | 6,108,045,479,900 | 108 | 82 |
#!/usr/bin/env python3
def main():
N = input()
l = len(N)
K = int(input())
ans = 0
# 最上位K桁が0の場合
# l-K_C_K * 9^K
if K == 1:
ans += (l-1) * 9
elif K == 2:
ans += (l-1) * (l-2) * 81 // 2
else:
ans += (l-1) * (l-2) * (l-3) * 729 // 6
if K == 1:
# 最上位の数以外0
ans += int(N[0])
elif K == 2:
# 最上位1桁が0ではなく,残りl-1桁中1桁だけ0以外(Nより大きくならないように注意)
if l >= 2:
# ans += int(N[0]) * (l-1) * 9 - (9 - int(N[1]))
for a in range(1,int(N[0])+1):
for b in range(l-1):
for p in range(1,10):
tmp = a * 10**(l-1) + p * 10**b
if tmp <= int(N):
ans += 1
else:
# 最上位1桁が0ではなく,残りl-1桁中2桁だけ0以外(Nより大きくならないように注意)
if l >= 3:
NN = int(N)
N0 = int(N[0])
L = 10**(l-1)
ans += (N0-1) * (l-1) * (l-2) * 81 // 2
for p in range(1,10):
for q in range(1,10):
for b in range(l-1):
for c in range(b+1,l-1):
tmp = N0 * L + p * 10**b + q * 10**c
if tmp <= NN:
ans += 1
else:
break
print(ans)
if __name__ == "__main__":
main()
|
h,n = map(int,input().split())
ab_input = [list(map(int,input().split())) for i in range(n)]
max_d = max(a for a,b in ab_input)
dp =[0]*(h+max_d)
for i in range(1,h+max_d):#dp[i-a]でi-a<0のとき影響がでないようにmax_dを足す
dp[i]=min(dp[i-a]+b for a,b in ab_input)#モンスターの体力を i 減らすため消耗する魔力の最小値
print(dp[h])
| 0 | null | 78,269,690,215,626 | 224 | 229 |
N = int(input())
A = [[[0] * 10, [0] * 10, [0] * 10], [[0] * 10, [0] * 10, [0] * 10], [[0] * 10, [0] * 10, [0] * 10], [[0] * 10, [0] * 10, [0] * 10]]
for i in range(N):
b, f, r, v = [int(j) for j in input().split()]
A[b-1][f-1][r-1] += v
for a, b in enumerate(A):
for f in b:
print(' ' + ' '.join([str(i) for i in f]))
else:
if a != len(A) - 1:
print('#' * 20)
|
n = input()
arr = [map(int,raw_input().split()) for _ in range(n)]
tou = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for line in arr:
b,f,r,v = line
tou[b-1][f-1][r-1] = tou[b-1][f-1][r-1] + v
for i in range(4):
for j in range(3):
print ' '+' '.join(map(str,tou[i][j]))
if i < 3 :
print '#'*20
| 1 | 1,100,047,269,732 | null | 55 | 55 |
N = int(input())
A = list(map(int, input().split()))
temp = 0
for a in A:
temp ^= a
ans =[]
for a in A:
ans.append(temp^a)
print(*ans)
|
N=int(input())
a=list(map(int,input().split()))
a_all=0
for i in range(N):
a_all^=a[i]
ans=[]
for j in range(N):
ans.append(a_all^a[j])
print(*ans)
| 1 | 12,554,754,372,732 | null | 123 | 123 |
N,S=int(input()),input()
r,g,b=0,0,0
for i in list(S):
if i=='R':r+=1
if i=='G':g+=1
if i=='B':b+=1
ans=r*g*b
for i in range(N-2):
for j in range(i+1,N-1):
if j-i>N-j-1:break
if S[i]!=S[j]and S[j]!=S[2*j-i]and S[2*j-i]!=S[i]:
ans-=1
print(ans)
|
import sys
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18
def main():
#n = int(stdin.readline().rstrip())
h1,m1,h2,m2,k = map(int, stdin.readline().rstrip().split())
#l = list(map(int, stdin.readline().rstrip().split()))
#numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
#word = [stdin.readline().rstrip() for _ in range(n)]
#number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
#zeros = [[0] * w for i in range(h)]
wake = (h2-h1)*60 + m2-m1
ans = wake - k
print(ans)
main()
| 0 | null | 27,096,857,034,546 | 175 | 139 |
n,a,b=map(int,input().split())
p=a+b
c=n%p
d=n//p
if c<a:
print(d*a+c)
else:
print((d+1)*a)
|
N, A, B = map(int, input().split())
temp = N // (A+B)
temp2 = N % (A + B)
temp2 = min(temp2, A)
print(temp*A + temp2)
| 1 | 55,548,277,518,176 | null | 202 | 202 |
in_str = raw_input().split()
num = []
for s in in_str:
num.append(int(s))
if(num[0] < num[2] or num[1] < num[3] or num[2] < 0 or num[3] < 0):
print "No"
elif(num[0] < num[2]+num[4] or num[1] < num[3]+num[4] or num[2]-num[4] < 0 or num[3]-num[4] < 0):
print "No"
else:
print "Yes"
|
w,h,x,y,r=map(int,raw_input().split())
if min(x,y,w-x,h-y)<r:
print 'No'
else:
print 'Yes'
| 1 | 448,973,293,442 | null | 41 | 41 |
n,m = map(int,input().split())
if n % 2 == 1:ans = [[1+i,n-i] for i in range(n//2)]
else:ans = [[1+i,n-i] for i in range(n//4)]+[[n//2+1+i,n//2-1-i] for i in range(n//2-n//4-1)]
for i in range(m):print(ans[i][0],ans[i][1])
|
A,B,M=map(int,input().split())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
answer=min(alist)+min(blist)
for _ in range(M):
x,y,c=map(int,input().split())
disc=alist[x-1]+blist[y-1]-c
answer=min(answer,disc)
print(answer)
| 0 | null | 41,226,083,959,398 | 162 | 200 |
n = int(input())
s = input()
if n % 2 == 1:
print("No")
else:
t = s[:n//2]
if t * 2 == s:
print("Yes")
else:
print("No")
|
N=int(input())
S=input()
if N%2==0 and S[:int(N/2)]==S[int(N/2):]:
print("Yes")
else:
print("No")
| 1 | 147,283,669,081,912 | null | 279 | 279 |
a, b = map(int, input().split(' '))
if a > b:
print(str(b) * a)
else:
print(str(a) * b)
|
[a, b] = [str(i) for i in input().split()]
A = a*int(b)
B = b*int(a)
s = [A, B]
S = sorted(s)
print(S[0])
| 1 | 84,484,825,941,828 | null | 232 | 232 |
A,B = map(int, input().split())
A1,B1 = str(A), str(B)
A2 = int(str(A)*B)
B2 = int(str(B)*A)
if A2 >= B2:
print(A2)
else:
print(B2)
|
def f(x, m):
return x * x % m
def main():
N, X, M = map(int, input().split())
pre = set()
pre.add(X)
cnt = 1
while cnt < N:
X = f(X, M)
if X in pre: break
cnt += 1
pre.add(X)
if cnt == N:
return sum(pre)
ans = sum(pre)
N -= cnt
loop = set()
loop.add(X)
while cnt < N:
X = f(X, M)
if X in loop: break
loop.add(X)
left = N % len(loop)
ans += sum(loop) * (N // len(loop))
for i in range(left):
ans += X
X = f(X, M)
return ans
print(main())
| 0 | null | 43,528,068,482,108 | 232 | 75 |
a,b,c,d=map(int,input().split())
e=max(a*c,a*d)
f=max(b*c,b*d)
print(max(e,f))
|
from bisect import bisect_left
N = int(input())
S = input()
d = {"R": [], "G": [], "B": []}
for i in range(N):
d[S[i]].append(i)
def find(x, y, z):
total = len(z)
res = 0
for i in x:
for j in y:
if i > j:
continue
# Find k > j
k = bisect_left(z, j)
# Find k == 2 * j - i
k0 = bisect_left(z, 2 * j - i)
flag = int(k0 >= k and k0 < total and z[k0] == 2 * j - i)
res += total - k - flag
return res
ans = 0
ans += find(d["R"], d["G"], d["B"])
ans += find(d["R"], d["B"], d["G"])
ans += find(d["G"], d["R"], d["B"])
ans += find(d["G"], d["B"], d["R"])
ans += find(d["B"], d["R"], d["G"])
ans += find(d["B"], d["G"], d["R"])
print(ans)
| 0 | null | 19,626,545,399,520 | 77 | 175 |
import sys
from collections import deque
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, *AB = map(int, read().split())
G = [[] for _ in range(N)]
for i, (a, b) in enumerate(zip(*[iter(AB)] * 2)):
G[a - 1].append((i, b - 1))
G[b - 1].append((i, a - 1))
queue = deque([0])
color = [0] * (N - 1)
color_from_parent = [0] * N
color_from_parent[0] = -1
while queue:
v = queue.popleft()
c = 1
for i, nv in G[v]:
if color_from_parent[nv] != 0:
continue
if c == color_from_parent[v]:
c += 1
color_from_parent[nv] = c
color[i] = c
c += 1
queue.append(nv)
print(max(color))
print(*color, sep='\n')
return
if __name__ == '__main__':
main()
|
while True:
n = input()
if n == '0':
break
print(sum([int(x) for x in n]))
| 0 | null | 68,978,261,571,108 | 272 | 62 |
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations
def main():
X = int(input())
if X <= 599:
print('8')
elif X <= 799:
print('7')
elif X <= 999:
print('6')
elif X <= 1199:
print('5')
elif X <= 1399:
print('4')
elif X <= 1599:
print('3')
elif X <= 1799:
print('2')
else:
print('1')
if __name__ == '__main__':
main()
|
x=float(input())
for i in range(8):
if 400+200*i<=x<400+200*(i+1):
print(8-i)
| 1 | 6,695,192,150,500 | null | 100 | 100 |
N, K, *A = map(int, open(0).read().split())
for a, b in zip(A[K:], A):
if a > b:
print("Yes")
else:
print("No")
|
A = int(input())
B = int(input())
ans = 6-A-B
print(ans)
| 0 | null | 59,056,635,903,670 | 102 | 254 |
A,B,C,K=map(int,input().split())
cnt=0
if A>=K:
print(K)
else:
if A+B>=K:
print(A)
else:
if A+B+C<=K:
print(A-C)
else:
print(A-(K-(A+B)))
|
import os, sys, re, math
N = int(input())
print(((N + 1) // 2) / N)
| 0 | null | 99,325,072,272,828 | 148 | 297 |
a = int(input())
print(a//2-(a%2==0))
|
n = int(input())
lst = []
for i in range(n):
tmp = input().split()
lst.append(tmp)
d = {}
for i in range(n):
if lst[i][0] == 'insert':
d[lst[i][1]] = d.get(lst[i][1], 0) + 1
elif lst[i][0] == 'find':
print('yes') if lst[i][1] in d else print('no')
| 0 | null | 76,770,376,839,618 | 283 | 23 |
#!/usr/bin/env python3
from math import ceil
import heapq
def main():
n, d, a = map(int, input().split())
q = []
for i in range(n):
x, h = map(int, input().split())
heapq.heappush(q, (x, -(h // a + (1 if (h % a) else 0))))
bomb = 0
res = 0
while q:
x, h = heapq.heappop(q)
if h < 0:
h *= -1
if h > bomb:
heapq.heappush(q, (x + 2 * d, h - bomb))
res += h - bomb
bomb = h
else:
bomb -= h
print(res)
if __name__ == "__main__":
main()
|
n = int(input())
a = [0 for _ in range(n)]
a = [int(s) for s in input().split()]
st_num = 0
mny = 1000
for i in range(n-1):
now_mn = a[i]
next_mn = a[i+1]
#print(st_num,mny)
if(next_mn > now_mn):
st_num += mny//now_mn
mny = mny%now_mn
else:
mny += st_num*now_mn
st_num = 0
if(a[n-1] > a[n-2] and st_num > 0):
mny += st_num*a[n-1]
st_num = 0
print(mny)
| 0 | null | 45,011,394,056,450 | 230 | 103 |
N = int(input())
X = list(map(int, input().split()))
X.sort()
ans = 0
data = []
for p in range(X[N-1] + 1):
sum = 0
for i in range(len(X)):
sum += (X[i]-p)**2
ans = sum
p += 1
data.append(ans)
print(min(data))
|
#coding: UTF-8
N=int(input())
p=[int(input()) for i in range(0,N)]
maxv=p[1]-p[0]
buy=p[0]
for i in range(1,N):
if p[i]-buy>maxv:
maxv=p[i]-buy
if p[i]<buy:
buy=p[i]
print(maxv)
| 0 | null | 32,701,719,399,492 | 213 | 13 |
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, K, R, S, P, T):
k_list = [[] for _ in range(K)]
for i in range(len(T)):
k_list[i % K].append(T[i])
ans = 0
for kl in k_list:
dp = [[0, 0, 0] for _ in range(len(kl) + 1)]
for i in range(len(kl)):
# rock
dp[i + 1][0] = max(dp[i][1], dp[i][2])
dp[i + 1][0] += R if kl[i] == 's' else 0
# scissors
dp[i + 1][1] = max(dp[i][0], dp[i][2])
dp[i + 1][1] += S if kl[i] == 'p' else 0
# paper
dp[i + 1][2] = max(dp[i][0], dp[i][1])
dp[i + 1][2] += P if kl[i] == 'r' else 0
ans += max(dp[-1])
print(ans)
if __name__ == '__main__':
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
# N, K = 10 ** 5, 10 ** 3
# R, S, P = 100, 90, 5
# T = 'r' * 10 ** 5
solve(N, K, R, S, P, T)
|
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.append(0)
s=input()
ans=0
for i in range(k,n):
if s[i]==s[i-k]:
s=s[:i]+'z'+s[i+1:]
for i in range(n):
ans+=a['sprz'.index(s[i])]
print(ans)
| 1 | 107,118,400,258,192 | null | 251 | 251 |
def merge(a, left, mid, right):
L = a[left:mid] + [INF]
R = a[mid:right] + [INF]
i = 0
j = 0
for k in range(left, right):
global idx
idx += 1
if( L[i] <= R[j] ):
a[k] = L[i]
i += 1
else:
a[k] = R[j]
j += 1
def merge_sort(a, left, right):
if( left + 1 < right ):
mid = (left + right) // 2
merge_sort(a, left, mid)
merge_sort(a, mid, right)
merge(a, left, mid, right)
INF = 1000000000
idx = 0
n = int(input())
a = [int(i) for i in input().split()]
merge_sort(a,0,len(a))
print(*a)
print(idx)
|
import math
n = int(input())
if n==0:
a=100000
else:
c = int(100)
for i in range(n):
num = c*1.05
c = math.ceil(num)
a = c*1000
print(a)
| 0 | null | 59,988,321,080 | 26 | 6 |
#!/usr/bin/env python3
def main():
N = input()
l = len(N)
K = int(input())
ans = 0
# 最上位K桁が0の場合
# l-K_C_K * 9^K
if K == 1:
ans += (l-1) * 9
elif K == 2:
ans += (l-1) * (l-2) * 81 // 2
else:
ans += (l-1) * (l-2) * (l-3) * 729 // 6
if K == 1:
# 最上位の数以外0
ans += int(N[0])
elif K == 2:
# 最上位1桁が0ではなく,残りl-1桁中1桁だけ0以外(Nより大きくならないように注意)
if l >= 2:
# ans += int(N[0]) * (l-1) * 9 - (9 - int(N[1]))
for a in range(1,int(N[0])+1):
for b in range(l-1):
for p in range(1,10):
tmp = a * 10**(l-1) + p * 10**b
if tmp <= int(N):
ans += 1
else:
# 最上位1桁が0ではなく,残りl-1桁中2桁だけ0以外(Nより大きくならないように注意)
if l >= 3:
NN = int(N)
N0 = int(N[0])
L = 10**(l-1)
ans += (N0-1) * (l-1) * (l-2) * 81 // 2
for p in range(1,10):
for q in range(1,10):
for b in range(l-1):
for c in range(b+1,l-1):
tmp = N0 * L + p * 10**b + q * 10**c
if tmp <= NN:
ans += 1
else:
break
print(ans)
if __name__ == "__main__":
main()
|
input_number = int(raw_input())
answer = input_number * input_number * input_number
print answer
| 0 | null | 37,899,659,551,620 | 224 | 35 |
def prime(p):
flag = True
for i in range(2,(int(p**0.5)+1)):
if p%i==0:
flag = False
break
return flag
X = int(input())
while True:
result = prime(X)
if result:
break
else:
X += 1
print(X)
|
s = input()
t = input()
print(sum(si != ti for si, ti in zip(s, t)))
| 0 | null | 57,958,084,014,112 | 250 | 116 |
N = int(input())
ST = []
cnt = 0
for _ in range(N):
s, t = input().split()
ST.append([s, t])
cnt += int(t)
X = input()
for i in range(N):
s, t = ST[i]
cnt -= int(t)
if s == X:
break
print(cnt)
|
import collections
n = int(input())
s_ls = []
dic = collections.defaultdict(int)
for i in range(n):
[s,t] = [j for j in input().split()]
s_ls.append(s)
dic[s] = int(t)
x = input()
f = 0
ans = 0
for i in range(n):
if f:
ans += dic[s_ls[i]]
if x == s_ls[i]:
f = 1
print(ans)
| 1 | 96,863,209,852,078 | null | 243 | 243 |
xy = [map(int,input().split()) for i in range(2)]
x,y = [list(j) for j in zip(*xy)]
if (y[0] + 1) == y[1] :
ans = 0
else:
ans = 1
print(ans)
|
p = 998244353
max = 2 * (10**5)
fact = [1,1]
facti = [1,1]
inv = [0,1]
for i in range(2, max + 1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // i)) % p)
facti.append((facti[-1] * inv[-1]) % p)
def comb(n,r):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * facti[r] * facti[n-r] % p
n,m,k = map(int, input().split())
ans = 0
for i in range(k+1):
a = comb(n-1,i)
b = m * pow(m-1,n-1-i,998244353)
ans += (a * b)% 998244353
print(ans%998244353)
| 0 | null | 73,501,036,339,306 | 264 | 151 |
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
INF = float("inf")
import bisect
S = input()
if S == "SUN":
print(7)
elif S == "MON":
print(6)
elif S == "TUE":
print(5)
elif S == "WED":
print(4)
elif S == "THU":
print(3)
elif S == "FRI":
print(2)
elif S == "SAT":
print(1)
|
a = int(input())
ans = 0
for i in [1, 2, 3]:
ans += a ** i
print(ans)
| 0 | null | 71,973,601,442,680 | 270 | 115 |
# -*- coding: utf-8 -*-
import sys
import os
import math
a, b = list(map(int, input().split()))
# a?????§?????????????????????
if b > a:
a, b = b, a
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
result = gcd(a, b)
print(result)
|
a, b = map(int, raw_input().split())
def gcd(a,b):
c = a%b
if c==0:
return b
elif c == 1:
return c
else:
return gcd(b, c)
if a > b:
print gcd(a, b)
elif a < b:
print gcd(b, a)
else:
print a
| 1 | 7,473,577,254 | null | 11 | 11 |
N, K = list(map(int, input().split()))
if abs(N - K) > N:
print(N)
else:
if N % K == 0:
N = 0
else:
N = abs(N % K - K)
print(N)
|
from sys import stdin
import math
from functools import reduce
n,k = [int(x) for x in stdin.readline().rstrip().split()]
m = n % k
print(min([m, k-m]))
| 1 | 39,571,938,716,252 | null | 180 | 180 |
a, b = map(int, input().split())
answer = (a * b)
print(answer)
|
from sys import stdin
def main():
for line in stdin:
factors = line.split()
break
print(int(factors[0]) * int(factors[1]))
main()
| 1 | 15,741,136,217,586 | null | 133 | 133 |
K,N = map(int,input().split())
A = list(map(int,input().split()))
tmin = 2*K
for i in range(1,N):
tmin = min(tmin,K-(A[i]-A[i-1]))
tmin = min(tmin,A[N-1]-A[0])
print(tmin)
|
# Python3 implementation of the approach
# Function to find the number of divisors
# of all numbers in the range [1,n]
def findDivisors(n):
# List to store the count
# of divisors
div = [0 for i in range(n + 1)]
# For every number from 1 to n
for i in range(1, n + 1):
# Increase divisors count for
# every number divisible by i
for j in range(1, n + 1):
if j * i <= n:
div[i * j] += 1
else:
break
# Print the divisors
return div
# Driver Code
if __name__ == "__main__":
n = int(input())
print(sum(findDivisors(n-1)))
# This code is contributed by
# Vivek Kumar Singh
| 0 | null | 22,847,104,763,702 | 186 | 73 |
number = int(input())
print(number**3)
|
import sys
from numba import njit
readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')
@njit(cache=True)
def solve(n, k, a):
if k == 0:
return a
b = [0]*n
for _ in range(k):
for i in range(n):
if i > a[i]:
b[i-a[i]] += 1
else:
b[0] += 1
if i + a[i] + 1 < n:
b[i + a[i] + 1] -= 1
for i in range(n-1):
b[i+1] += b[i]
a[i] = 0
a[-1] = 0
b, a = a, b
if min(a) >= n:
break
return a
solve(0, 0, [0, 1, 2])
n, k = nm()
a = nl()
print(*solve(n, k, a))
| 0 | null | 7,884,546,554,080 | 35 | 132 |
import sys
l = sys.stdin.readlines()
minv = int(l[1])
maxv = -1000000000
for r in map(int,l[2:]):
m = r-minv
if maxv < m:
maxv = m
if m < 0: minv = r
elif m < 0: minv = r
print(maxv)
|
n = int(input())
minv = int(input())
maxv = (10**9)*(-1)
for j in range(1,n):
r = int(input())
if maxv < (r - minv):
maxv = r - minv
if minv > r:
minv = r
print(maxv)
| 1 | 12,278,664,028 | null | 13 | 13 |
#!/usr/bin/env python3
def main():
N, M = map(int, input().split())
A = [int(x) for x in input().split()]
if N >= sum(A):
print(N - sum(A))
else:
print(-1)
if __name__ == '__main__':
main()
|
n,m = map(int,input().split())
alist = list(map(int,input().split()))
d = n - sum(alist)
if d < 0:
print(-1)
else:
print(d)
| 1 | 32,112,821,506,528 | null | 168 | 168 |
n = int(input())
a = list(map(int,input().split()));
b = [0]*n
for i in range(n-1):
b[a[i]-1] += 1;
for v in range(n):
print(b[v]);
|
#
import sys
import math
import numpy as np
import itertools
n = int(input())
# n行の複数列ある数値をそれぞれの配列へ
a, b = [0]*n, [0]*n
for i in range(n): a[i], b[i] = map(int, input().split())
#print(a,b)
a.sort()
b.sort()
if n % 2 == 0:
t = a[n//2-1] + a[n//2]
s = b[n//2-1] + b[n//2]
print(s-t+1)
else:
t = a[n//2]
s = b[n//2]
print(s-t+1)
| 0 | null | 24,859,974,883,600 | 169 | 137 |
#!/usr/bin/env python3
import sys
import numpy as np
input = sys.stdin.readline
def S():
return input().rstrip()
def I():
return int(input())
def MI():
return map(int, input().split())
H, W, M = MI()
R = np.zeros(H + 1)
C = np.zeros(W + 1)
bombs = []
for _ in range(M):
h, w = MI()
bombs.append((h, w))
R[h] += 1
C[w] += 1
R_max = [R == max(R)]
ans = max(R) + max(C)
C_max = [C == max(C)]
cnt = 0
for h, w in bombs:
if R_max[0][h] and C_max[0][w]:
cnt += 1
if cnt == np.count_nonzero(R_max) * np.count_nonzero(C_max):
print(int(ans - 1))
else:
print(int(ans))
|
X,Y,Z = (int(X) for X in input().split())
Y,X = X,Y
Z,X = X,Z
print('{} {} {}'.format(X,Y,Z))
| 0 | null | 21,504,315,360,992 | 89 | 178 |
debt=100000
week=input()
for i in range(week):
debt=debt*1.05
if debt%1000!=0:
debt=int(debt/1000)*1000+1000
print debt
|
# coding: utf-8
a, b = map(int, input().split(' '))
menseki = a * b
print(menseki, a*2 + b*2)
| 0 | null | 155,135,596,134 | 6 | 36 |
a,b=map(int,input().split())
dic={1:3*10**5,2:2*10**5,3:1*10**5}
c=0
if a in dic and b in dic:
if a==1 and b==1:
c+=dic[a]+dic[b]+4*10**5
print(c)
else:
c+=dic[a]+dic[b]
print(c)
elif a in dic and b not in dic:
c+=dic[a]
print(c)
elif b in dic and a not in dic:
c+=dic[b]
print(c)
else:
print(c)
|
x = list(map(int, input().split()))
ans = 0
for i in x:
if i == 1:
ans += 300000
elif i == 2:
ans += 200000
elif i == 3:
ans += 100000
if sum(x) == 2:
ans += 400000
print(ans)
| 1 | 140,649,858,998,932 | null | 275 | 275 |
n = input()
if n >= 'A' and n <= 'Z':
print('A')
if n >= 'a' and n <= 'z':
print('a')
|
import math
from collections import Counter
N = int(input())
c = Counter()
ans = 0
for n in range(1, N + 1):
left = n // (10 ** int(math.log10(n)))
right = n % 10
c[(left, right)] += 1
for left, right in c.keys():
ans += c[(left, right)] * c[(right, left)]
print(ans)
| 0 | null | 49,119,601,470,220 | 119 | 234 |
import collections
def searchRoot(n):
par = parList[n]
if n == par:
if len(q) > 0:
rootIn(q,n)
return n
else:
q.append(n)
return(searchRoot(par))
def rootIn(q,root):
while len(q) > 0:
parList[q.popleft()] = root
n,m = list(map(int,input().split()))
q = collections.deque()
parList = [i for i in range(n+1)]
for i in range(m):
a,b = list(map(int,input().split()))
aRoot = searchRoot(a)
bRoot = searchRoot(b)
if aRoot != bRoot:
parList[max(aRoot,bRoot)] = min(aRoot,bRoot)
#print(parList)
ansDic = dict()
rootSet = set()
for i in range(1,n+1):
root = searchRoot(i)
if root in rootSet:
ansDic[root] += 1
else:
rootSet.add(root)
ansDic[root] = 1
ans = 1
for i in rootSet:
if ansDic[i] > ans:
ans = ansDic[i]
print(ans)
|
from collections import Counter
N = int(input())
A = [int(_) for _ in input().split()]
cnt = Counter(A)
s = 0
for a in cnt:
s += cnt[a] * (cnt[a] - 1) // 2
for a in A:
print(s - cnt[a] + 1)
| 0 | null | 25,864,989,368,008 | 84 | 192 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.