code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
S = list(input())
N = len(S)
K = int(input())
old = S[0]
a = 0
c = 1
for i in range(1,N):
if S[i] == old:
c += 1
else:
a += c // 2
old = S[i]
c = 1
b = 0
a += c // 2
for i in range(N):
if S[i] == old:
b += 1
else:
break
ans = a * K + ((b + c) // 2 - b // 2 - c // 2) * (K - 1)
if c == N:
ans = N * K // 2
print(ans) | C = {}
S = input().strip()
N = len(S)
K = int(input())
for i in range(N):
s = S[i]
if s not in C:
C[s]=0
C[s] += 1
if len(C)>1:
a = 0
cnt = 1
for i in range(1,N):
if S[i]==S[i-1]:
cnt += 1
else:
a += cnt//2
cnt = 1
a += cnt//2
X = S+S
b = 0
cnt = 1
for i in range(1,2*N):
if X[i]==X[i-1]:
cnt += 1
else:
b += cnt//2
cnt = 1
b += cnt//2
d = b-a
print(a+d*(K-1))
else:
A = list(C.items())
k = A[0][1]
if k%2==0:
print((k//2)*K)
else:
if K%2==0:
a = k
b = 2*k
d = k
print(a+d*((K//2)-1))
else:
a = k//2
b = (k*3)//2
d = b-a
print(a+d*(K//2)) | 1 | 175,447,660,546,692 | null | 296 | 296 |
def do_calc(data):
from collections import deque
s = deque() # ??????????????¨??????????????????
while data:
elem = data[0]
data = data[1:]
if elem == '+' or elem == '-' or elem == '*':
a = s.pop()
b = s.pop()
if elem == '+':
s.append(b + a)
elif elem == '-':
s.append(b - a)
elif elem == '*':
s.append(b * a)
else:
s.append(int(elem))
return s.pop()
if __name__ == '__main__':
# ??????????????\???
data = [x for x in input().split(' ')]
# data = ['1', '2', '+', '3', '4', '-', '*']
# ???????????????
result = do_calc(data)
# ???????????????
print(result) | n = int(input())
c = {}
m = 0
for i in range(n):
s = input()
if s in c:
c[s] += 1
else:
c[s] = 1
if m < c[s]:
m = c[s]
ans = []
for i in c:
if m == c[i]:
ans.append(i)
ans = sorted(ans)
for i in ans:
print(i)
| 0 | null | 35,038,996,972,990 | 18 | 218 |
from collections import Counter
n = int(input())
c = list(input())
num = Counter(c)
r = num["R"]
ans = ["R"]*r + ["W"]*(n-r)
cnt = 0
for i in range(n):
if c[i] != ans[i]:
cnt += 1
print(cnt//2)
| a,b=map(int,input().split())
total=b-a
if(total==0):
print("Yes")
else:
print("No") | 0 | null | 44,644,965,833,710 | 98 | 231 |
n=int(input())
c=input()
d=c.count("R")
e=c[:d].count("R")
print(d-e) | H=int(input())
def f(H):
if H==1:
return 1
elif H>1:
return 2*f(H//2)+1
re=0
re=f(H)
print(re) | 0 | null | 42,965,376,721,640 | 98 | 228 |
N = int(input())
query = []
ans = 0
for i in range(N):
A = int(input())
query.append([list(map(int, input().split())) for j in range(A)])
for i in range(1<<N):
count = 0
FLG = True
for j in range(N):
if (i >> j) & 1:
count += 1
for x, y in query[j]:
if (i >> (x - 1)) & 1 != y:
FLG = False
break
if not FLG:
break
else:
ans = max(ans, count)
print(ans)
| #!/usr/bin/env python3
n = int(input())
a = []
for _ in range(n):
a.append([[*map(int, input().split())] for _ in range(int(input()))])
ans = 0
for i in range(2**n):
hone = set()
unki = set()
for j in range(n):
if i >> j & 1:
hone |= {j + 1}
for k in a[j]:
if k[1] == 1:
hone |= {k[0]}
else:
unki |= {k[0]}
else:
unki |= {j + 1}
if hone & unki == set():
ans = max(ans, len(hone))
print(ans)
| 1 | 121,512,837,269,000 | null | 262 | 262 |
N=int(input());S,T=map(str,input().split())
for i in range(N):print(S[i],end='');print(T[i],end='') | n, *AB = map(int, open(0).read().split())
a = sorted(AB[::2])
b = sorted(AB[1::2])
if n % 2 == 0:
print(b[n // 2 - 1] + b[n // 2] - a[n // 2 - 1] - a[n // 2] + 1)
else:
print(b[(n + 1) // 2 - 1] - a[(n + 1) // 2 - 1] + 1) | 0 | null | 64,701,597,384,488 | 255 | 137 |
#!/usr/bin/env python
d, t, s = [int(i) for i in input().split(' ')]
if s*t >= d:
print('Yes')
else:
print('No')
| def nCr(n,r,mod):
p=1
q=1
# print(n,r)
for i in range(r):
q *= i+1
q %= mod
p *= n-i
p %= mod
# print(p,q)
return (p * pow(q,mod-2,mod)) % mod
s=int(input())
mod = 10**9+7
ans = 0
for i in range(1,s//3+1):
if i==1:
h=1
else:
h=nCr(s-3*i+i-1 ,i-1, mod)
ans += h
ans %= mod
# print(h)
print(ans) | 0 | null | 3,384,909,579,168 | 81 | 79 |
N=int(input());M=10**9+7
print((pow(10,N,M)-2*pow(9,N,M)+pow(8,N,M))%M)
| num=int(input())
num2=[10, 9 ,8]
def multi(x):
y=x**num
return y
a, b, c=map(multi, num2)
print((a-2*b+c)%(int(1e9+7))) | 1 | 3,134,387,663,992 | null | 78 | 78 |
n,m = map(int, input().split())
AC = [False]*n
WA = [0]*n
for i in range(m):
p,s = input().split()
p = int(p)-1
if AC[p] == False:
if s == 'WA':
WA[p] += 1
else:
AC[p] = True
wa = 0
for i in range(n):
if AC[i]:
wa += WA[i]
print(AC.count(True),wa)
| n, m = map(int, input().split())
wa = [0] * n
ac = [False] * n
for i in range(m):
p, s = input().split()
p = int(p) - 1
if s == 'WA' and not ac[p]:
wa[p] += 1
elif s == 'AC':
ac[p] = True
wa_n = sum(wa[i] if ac[i] else 0 for i in range(n))
print("{} {}".format(sum(ac), wa_n)) | 1 | 93,420,911,815,616 | null | 240 | 240 |
def factorize(n):
tmp = n
for i in range(2, int(n**0.5)+1):
if tmp % i == 0:
cnt = 0
while tmp % i == 0:
cnt += 1
tmp //= i
if i in fact:
fact[i] = max(fact[i],cnt)
else:
fact[i] = cnt
if tmp != 1:
if tmp in fact:
fact[tmp] = max(fact[tmp],1)
else:
fact[tmp] = 1
if len(fact) == 0:
if N in fact:
fact[N] = max(fact[N],1)
else:
fact[N] = 1
def inv(n, p):
return pow(n, p-2, p)
N = int(input())
A = list(map(int, input().split()))
p = 10**9+7
fact = {}
for i in range(N):
if A[i] != 1:
factorize(A[i])
lcm = 1
for key, val in fact.items():
lcm *= pow(key, val, p)
lcm %= p
inv_sum = 0
for i in range(N):
inv_sum += inv(A[i], p)
inv_sum %= p
print(lcm * inv_sum % p) | while 1:
try:
a,b=map(int,input().split())
print(len(str(a+b)))
except:
break | 0 | null | 43,949,645,278,240 | 235 | 3 |
n,s = map(int,input().split())
A = list(map(int,input().split()))
mod = 998244353
dp = [[0 for i in range(s+1)] for j in range(n+1)]
dp[0][0] = 1
for i in range(n):
for j in range(s+1):
if j - A[i] >= 0:
dp[i+1][j]=(dp[i][j]*2+dp[i][j-A[i]])%mod
else:
dp[i+1][j]=(dp[i][j]*2)%mod
print(dp[n][s]) | A,B,C,K = map(int,input().split())
score = 0
if A<K:
K -= A
score += A
else:
score += K
print(score)
exit()
if B<K:
K -= B
else:
print(score)
exit()
score -= min(K,C)
print(score) | 0 | null | 19,657,959,327,972 | 138 | 148 |
s=input()
dic={}
cur=0
power=0
for i in range(0,len(s)+1):
s_int=len(s)-i-1
if cur in dic:
dic[cur]+=1
else:
dic[cur]=1
try:
num=int(s[s_int])
cur+=num*pow(10,power,2019)
cur%=2019
power+=1
except IndexError:
break
res=0
for i in range(len(dic)):
t=dic.popitem()
cc=t[1]
res+=cc*(cc-1)//2
print(res)
| import sys
import math
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')
def LCM(a, b):
return a * b // math.gcd(a, b)
def main():
N, M = in_nn()
a = in_nl()
lcm = 1
for i in range(N):
lcm = LCM(lcm, a[i])
if lcm > M * 2:
print(0)
exit()
for i in range(N):
if lcm // a[i] % 2 == 0:
print(0)
exit()
lcm = lcm // 2
q = M // lcm
if q % 2 == 0:
ans = q // 2
else:
ans = q // 2 + 1
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 66,676,611,575,580 | 166 | 247 |
a, b = map(int, input().split())
d = a // b
r = a % b
f = float(a / b)
print('{0} {1} {2:0.5f}'.format(d, r, f)) | a,b = map(int, input().split())
print(f"{a//b} {a%b} {a/b:.5f}")
| 1 | 603,550,589,290 | null | 45 | 45 |
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
c=Counter(a)
for i in range(1,n+1):
print(c[i])
| def main():
a, b = (int(i) for i in input().split())
print(str(a * b))
if __name__ == '__main__':
main()
| 0 | null | 24,235,597,102,970 | 169 | 133 |
S , T = input().split()
A , B =map(int,input().split())
U = input()
mydict = {S:A, T:B}
mydict[U] -= 1
print ( str( mydict[S] ) + " " +str( mydict[T] ) )
| S,T=map(str,input().split())
a,b=map(int,input().split())
U=input()
if U == S:
a +=-1
elif U == T:
b += -1
print(a,b) | 1 | 71,658,593,813,862 | null | 220 | 220 |
k=int(input())
w=input()
if len(w)<=k:
print(w)
else:
print(w[:k]+"...")
| def solve(x):
cnt = 1
while x > 0:
x %= bin(x).count('1')
cnt += 1
return cnt
n = int(input())
x = input()
one = x.count('1')
num = int(x, 2)
up = num%(one+1)
if one == 1:down = 0
else:down = num%(one-1)
for i in range(n):
if x[i] == '1':
if one == 1:
print(0)
continue
s = (down - pow(2, n-i-1, one-1))%(one-1)
else:
s = (up + pow(2, n-i-1, one+1))%(one+1)
print(solve(s)) | 0 | null | 13,978,457,225,360 | 143 | 107 |
ans = []
for s in open(0).readlines():
if "?" in s:
break
ans.append(eval(s.strip().replace("/", "//")))
print(*ans, sep='\n')
| a = raw_input().split()
while a[1] != '?':
print eval(a[0]+a[1]+a[2])
a = raw_input().split() | 1 | 693,237,115,368 | null | 47 | 47 |
n, k = map(int, input().split())
p = list(map(int, input().split()))
for i, j in enumerate(p):
p[i] = (j*(j+1)/2) / j
t_sum = sum(p[:k])
ans = t_sum
for i in range(n-k):
t_sum = t_sum - p[i] + p[i+k]
if ans < t_sum:
ans = t_sum
print(ans) | n = [int(x) for x in input()]
s = sum(n)
if s % 9 == 0:
print('Yes')
else:
print('No') | 0 | null | 39,748,785,534,162 | 223 | 87 |
import sys
import math
import bisect
import heapq
from collections import Counter
def input():
return sys.stdin.readline().rstrip()
def main():
N, K = map(int, input().split())
A = list(map(int, input().split()))
AS = [0]
it = 0
for i in range(0, N):
it += A[i]
it %= K
sj = (it - i - 1) % K
AS.append(sj)
# 最初だけ作る
C = dict()
C[0] = 1
current = 0
for j in range(1, N + 1):
if j > K-1:
C[AS[j - K]] -= 1
if AS[j] in C:
current += C[AS[j]]
C[AS[j]] += 1
else:
C[AS[j]] = 1
print(current)
if __name__ == "__main__":
main()
| n, m = map(int, input().split())
a = []
for _ in range(n):
a.append(list(map(int, input().split())))
b = []
for _ in range(m):
b.append(int(input()))
c = []
for i in range(n):
c.append(sum([a[i][j] * b[j] for j in range(m)]))
for i in c:
print(i)
| 0 | null | 69,156,651,632,460 | 273 | 56 |
def main():
N, K = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(K)]
MOD = 998244353
dp = [0]*(N+1)
S = [0]*(N+1)
dp[1] = 1
S[1] = 1
for i in range(2, N+1):
for l, r in LR:
if i-l < 0:
continue
else:
dp[i] += S[i-l] - S[max(i-r-1, 0)]
dp[i] %= MOD
S[i] = S[i-1] + dp[i]
print(dp[-1]%MOD)
if __name__ == '__main__':
main()
| def readinput():
n,k=map(int,input().split())
lr=[]
for _ in range(k):
l,r=map(int,input().split())
lr.append((l,r))
return n,k,lr
def main(n,k,lr):
lrs=sorted(lr,key=lambda x:x[0])
MOD=998244353
dp=[0]*(n+1)
dp[1]=1
for i in range(1,n):
#print(i)
if dp[i]==0:
continue
skip=False
for l,r in lrs:
for j in range(l,r+1):
#print('i+j: {}'.format(i+j))
if i+j>n:
skip=True
break
dp[i+j]=(dp[i+j]+dp[i])%MOD
#print(dp)
if skip:
break
return dp[n]
def main2(n,k,lr):
lrs=sorted(lr,key=lambda x:x[0])
MOD=998244353
dp=[0]*(n+1)
ruiseki=[0]*(n+1)
dp[1]=1
ruiseki[1]=1
for i in range(2,n+1):
for l,r in lrs:
if i-l<1:
break
dp[i]+=ruiseki[i-l]-ruiseki[max(1,i-r)-1]
dp[i]=dp[i]%MOD
ruiseki[i]=(ruiseki[i-1]+dp[i])%MOD
return dp[n]
if __name__=='__main__':
n,k,lr=readinput()
ans=main2(n,k,lr)
print(ans)
| 1 | 2,699,979,108,768 | null | 74 | 74 |
def main():
from random import sample
from operator import itemgetter
e=enumerate
n,a=open(0)
n=int(n)
d=[0]+[-2**64]*n
for j,(a,i)in e(sorted(sample([(a,i)for i,a in e(map(int,a.split()))],n),key=itemgetter(0),reverse=1)):
d=[max(t+a*(~i-j+k+n),d[k-1]+a*abs(~i+k))for k,t in e(d)]
print(max(d))
main() | INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
'''
一つの整数
'''
return int(input())
def inpl():
'''
一行に複数の整数
'''
return list(map(int, input().split()))
def inpl_str():
'''
一行に複数の文字
'''
return list(input().split())
n=inp()
a = inpl()
sorted_a = sorted(a,reverse=True)
place=dict()
for i in range(n):
if a[i] not in place:
place[a[i]]=[i+1]
else:
place[a[i]].append(i+1)
ans = 0
dp=[[-INF]*(n+1) for i in range(n+1)]
dp[0][0] = 0
for i in range(n):
if i!=0 and sorted_a[i] == sorted_a[i - 1]:
index += 1
else:
index = 0
for j in range(n):
_place = place[sorted_a[i]][index]
#右
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + sorted_a[i] * abs(n - (i - j) - _place))
#左
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + sorted_a[i] * abs(_place - j - 1))
print(max(dp[n]))
| 1 | 33,690,954,648,802 | null | 171 | 171 |
l = [int(i) for i in input().split()]
a = l[0]
b = l[1]
c = l[2]
yaku = 0
for i in range(b-a+1):
if c % (i+a) == 0:
yaku = yaku + 1
print(yaku) | i = count = 0
a = b = c = ''
line = input()
while line[i] != ' ':
a = a + line[i]
i += 1
i += 1
while line[i] != ' ':
b = b + line[i]
i += 1
i += 1
while i < len(line):
c = c + line[i]
i += 1
a = int(a)
b = int(b)
c = int(c)
while a <= b:
if c%a == 0:
count += 1
a += 1
print(count) | 1 | 567,758,918,048 | null | 44 | 44 |
import queue
from collections import namedtuple
T = namedtuple("T", "u d")
n = int(input())
path = dict()
ans = [-1] * (n + 1)
for i in range(n):
a = [int(x) for x in input().split()]
a.reverse()
u, k = a.pop(), a.pop()
path[u] = set()
for j in range(k):
path[u].add(a.pop())
def bfs(s):
q = queue.Queue()
q.put(s)
while q.qsize() != 0:
p = q.get()
if p.d < ans[p.u] or ans[p.u] < 0:
ans[p.u] = p.d
for r in path[p.u]:
q.put(T(r, p.d + 1))
bfs(T(1, 0))
for i in range(1, n + 1):
print(i, ans[i])
| import sys
def input(): return sys.stdin.readline().rstrip()
def main():
H, W, K = map(int, input().split())
S = [tuple(map(int, list(input()))) for _ in range(H)]
ans = 10 ** 9
for bit in range(1 << (H-1)):
canSolve = True
order = [0] * (H + 1)
tmp_ans = 0
for i in range(H):
if bit & 1 << i:
order[i+1] = order[i] + 1
tmp_ans += 1
else:
order[i+1] = order[i]
sum_block = [0] * (H + 1)
for w in range(W):
one_block = [0] * (H + 1)
overK = False
for h in range(H):
h_index = order[h]
one_block[h_index] += S[h][w]
sum_block[h_index] += S[h][w]
if one_block[h_index] > K:
canSolve = False
if sum_block[h_index] > K:
overK = True
if not canSolve:
break
if overK:
tmp_ans += 1
sum_block = one_block
if tmp_ans >= ans:
canSolve = False
break
if canSolve:
ans = tmp_ans
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 24,406,282,863,080 | 9 | 193 |
S = input()
T = input()
largest = 0
for i in range(len(S) - len(T)+1):
count = 0
for j in range(len(T)):
if S[i+j] == T[j]:
count += 1
if largest < count:
largest = count
print(len(T) - largest)
| N, M = [int(_) for _ in input().split()]
if N == M:
print('Yes')
else:
print('No') | 0 | null | 43,557,002,872,568 | 82 | 231 |
#!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
n, t = LI()
ab = [LI() for _ in range(n)]
ab.sort(key = itemgetter(0))
dp = [[0] * (t+3001) for _ in range(n+1)]
for i in range(1, n+1):
a, b = ab[i-1]
for j in range(t + 3001):
dp[i][j] = dp[i-1][j]
for j in range(t):
dp[i][j+a] = max(dp[i-1][j+a], dp[i-1][j] + b)
ans = 0
for i in range(t-1, t + 3001):
ans = max(ans, dp[n][i])
print(ans) | #coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = True
def main(given = sys.stdin.readline):
input = lambda : given().rstrip()
LMIIS = lambda : list(map(int,input().split()))
II = lambda : int(input())
XLMIIS = lambda x : [LMIIS() for _ in range(x)]
N,T = LMIIS()
AB = []
for i in range(N):
AB.append(LMIIS())
AB.sort()
dp = [-1] * (T+3000)
dp[0] = 0
for a,b in AB:
tmpdp = dp[:]
for j in range(T):
if dp[j] != -1:
tmpdp[j+a] = max(dp[j+a],dp[j]+b)
dp = tmpdp
print(max(dp))
if __name__ == '__main__':
main() | 1 | 152,191,399,530,448 | null | 282 | 282 |
while True:
m,f,r=map(int,input().split())
if m== -1 and f == -1 and r == -1 : break
if m==-1 or f ==-1:
print("F")
elif m + f >=80:
print("A")
elif m+f <<80 and m + f >=65:
print("B")
elif (m+f <<65 and m + f >=50) or (m+f <<50 and m + f >=30 and r >=50):
print("C")
elif m+f <<50 and m + f >=30:
print("D")
else:
print("F")
| while True:
x = []
x = input().split( )
y = [int(s) for s in x]
if sum(y) == -3:
break
if y[0] == -1 or y[1] == -1:
print("F")
elif y[0] + y[1] < 30:
print("F")
elif y[0] + y[1] >= 30 and y[0] + y[1] <50:
if y[2] >= 50:
print("C")
else:
print("D")
elif y[0] + y[1] >= 50 and y[0] + y[1] <65:
print("C")
elif y[0] + y[1] >= 65 and y[0] + y[1] <80:
print("B")
elif y[0] + y[1] >= 80:
print("A")
| 1 | 1,227,442,163,108 | null | 57 | 57 |
input()
A = [int(x) for x in input().split()]
input()
ms = [int(x) for x in input().split()]
enable_create = [False]*2000
for bit in range(1 << len(A)):
n = 0
for i in range(len(A)):
if 1 & (bit >> i) == 1:
n += A[i]
enable_create[n] = True
for m in ms:
print("yes" if enable_create[m] else "no") | H, W, M = map(int, input().split())
hw = []
sh = [0] * H
sw = [0] * W
for i in range(M):
h, w = map(int, input().split())
hw.append((h - 1, w - 1))
sh[h - 1] += 1
sw[w - 1] += 1
mh = max(sh)
mw = max(sw)
count = 0
for i in range(M):
if sh[hw[i][0]] == mh and sw[hw[i][1]] == mw:
count += 1
if sh.count(mh) * sw.count(mw) > count:
print(mh + mw)
else:
print(mh + mw - 1) | 0 | null | 2,446,664,205,040 | 25 | 89 |
X,Y=map(int,input().split())
M=[0]*206
M[0],M[1],M[2]=300000,200000,100000
if X+Y==2:
print(1000000)
else:
print(M[X-1]+M[Y-1]) | # coding=utf-8
import sys
if __name__ == '__main__':
N = int(input())
li_A = list(map(int, input().split()))
ans = li_A[0]
if 0 in li_A:
print('0')
sys.exit()
for i in range(1, N):
if ans * li_A[i] > 1000000000000000000:
print('-1')
sys.exit()
else:
ans *= li_A[i]
print(ans)
| 0 | null | 78,034,927,307,708 | 275 | 134 |
h, n = map(int, input().split())
a = [int(s) for s in input().split()]
a.sort(reverse=True)
ans = 'No'
for s in a:
h -= s
if h <= 0:
ans = 'Yes'
print(ans) | H, N = map(int, input().split())
A = list(map(int, input().split()))
SUM = 0
for i in range(len(A)):
SUM = SUM + A[i]
if SUM >= H:
print('Yes')
else:
print('No') | 1 | 78,044,212,919,750 | null | 226 | 226 |
# coding: utf-8
input()
s = list(map(int,input().split()))
input()
t = list(map(int,input().split()))
cnt = 0
for i in t:
if i in s:
cnt += 1
print(cnt) | import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
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()) #空白なし
N = I()
ST = [LS() for _ in range(N)]
X = S()
ans = 0
for i in range(N):
s,t = ST[i]
ans += int(t)
if s == X:
break
print(sum(int(ST[i][1]) for i in range(N))-ans)
| 0 | null | 48,690,041,369,728 | 22 | 243 |
import sys
from collections import deque
n = int(sys.stdin.readline())
que = deque()
for i in range(n):
line = sys.stdin.readline()
op = line.rstrip().split()
if "insert" == op[0]:
que.appendleft(op[1])
elif "delete" == op[0]:
if op[1] in que:
que.remove(op[1])
elif "deleteFirst" == op[0]:
que.popleft()
else:
que.pop()
print(*que) | while 1:
a, b, c = raw_input().split()
if b == "?":
break
a = int(a)
c = int(c)
if b == "+":
print a+c
elif b == "-":
print a-c
elif b == "*":
print a*c
elif b == "/":
print a//c
| 0 | null | 378,578,345,650 | 20 | 47 |
def yumiri(L, n):
for i in range(len(L)):
if L[i] > n:
return i - 1
def parunyasu(a, b, p, q):
reans = ans
rd1, rq1, d1, nd1, nq1, q1, newans = naobou(a, q, reans)
rd2, rq2, d2, nd2, nq2, q2, newans = naobou(b, p, newans)
if reans <= newans:
t[d1 - 1] = q1
t[d2 - 1] = q2
return newans
else:
ayaneru(rd2, rq2, d2, nd2, nq2)
ayaneru(rd1, rq1, d1, nd1, nq1)
return reans
def ayaneru(rd, rq, d, nd, nq):
ZL[rd].insert(rq, d)
del ZL[nd][nq + 1]
def naobou(d, q, ans):
newans = ans
rd = t[d - 1] - 1
rq = yumiri(ZL[rd], d)
newans += SUMD[ZL[rd][rq] - ZL[rd][rq - 1] - 1] * c[rd]
newans += SUMD[ZL[rd][rq + 1] - ZL[rd][rq] - 1] * c[rd]
newans -= SUMD[ZL[rd][rq + 1] - ZL[rd][rq - 1] - 1] * c[rd]
del ZL[rd][rq]
nd = q - 1
nq = yumiri(ZL[nd], d)
newans += SUMD[ZL[nd][nq + 1] - ZL[nd][nq] - 1] * c[nd]
newans -= SUMD[d - ZL[nd][nq] - 1] * c[nd]
newans -= SUMD[ZL[nd][nq + 1] - d - 1] * c[nd]
ZL[nd].insert(nq + 1, d)
newans -= s[d - 1][rd]
newans += s[d - 1][nd]
return rd, rq, d, nd, nq, q, newans
def rieshon():
ans = 0
for i in range(D):
ans += s[i][t[i] - 1]
for j in range(26):
if t[i] - 1 == j:
L[j] = 0
ZL[j].append(i + 1)
else:
L[j] += 1
ans -= L[j] * c[j]
for i in range(26):
ZL[i].append(D + 1)
return ans
import time
import random
startTime = time.time()
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
L = [0] * 26
ZL = [[0] for _ in range(26)]
SUMD = [0] * (D + 1)
for i in range(1, D + 1):
SUMD[i] = SUMD[i - 1] + i
RD = [0] * 26
t = [0] * D
for i in range(D):
RD[0] += 1
ma = s[i][0] + RD[0] * c[0]
man = 0
for j in range(1, 26):
RD[j] += 1
k = s[i][j] + RD[j] * c[j]
if k > ma:
ma = k
man = j
t[i] = man + 1
RD[man] = 0
ans = rieshon()
while time.time() - startTime < 1.8:
l = random.randrange(min(D - 1, 13)) + 1
d = random.randrange(D - l) + 1
p = t[d - 1]
q = t[d + l - 1]
if p == q: continue
ans = parunyasu(d, d + l, p, q)
for i in range(D):
print(t[i])
| d,t,s = map(int, input().split())
if(d-t*s>0):
print("No")
else:
print("Yes") | 0 | null | 6,635,043,235,524 | 113 | 81 |
# -*- coding:utf-8 -*-
n = int(input())
s=''
for i in range(1,n+1):
if i%3==0 or i%10==3:
s = s + " " + str(i)
continue
else:
x = i
while x >0:
x //= 10
if x%10==3:
s = s + " " + str(i)
break
print(s) | import math
X, N = map(int, input().split())
if N == 0:
print(X)
else:
p = list(map(int, input().split()))
q = [int(i)-10 for i in range(121)]
#print(q)
for i in p:
q.remove(i)
ans = 0
r0 = 100000
for j in q:
r = abs(j-X)
if r0 > r:
r0 = r
ans = j
print(ans) | 0 | null | 7,495,544,472,390 | 52 | 128 |
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()
def resolve():
N, K = LI()
A = LI()
# 最大の長さがxになるような切断回数
def cut_num(x):
ret = sum([math.ceil(i / x) - 1 for i in A])
return ret
ng = 0
ok = max(A)
while abs(ok-ng)>10**(-6):
m = (ng+ok)/2
if cut_num(m) <= K:
ok = m
else:
ng = m
print(math.ceil(ok))
if __name__ == '__main__':
resolve()
| def main():
n, k = map(int, input().split())
a = list(map(int, input().split()))
def value(v):
cnt = 0
for i in a:
cnt += (i-1)//v
if cnt > k:
return False
else:
return True
def b_search(ok, ng, value):
while abs(ok-ng) > 1:
mid = (ok+ng)//2
if value(mid):
ok = mid
else:
ng = mid
return ok
print(b_search(10**16, 0, value))
main()
| 1 | 6,440,313,930,532 | null | 99 | 99 |
import math
N, D= list(map(int,input().split()))
cnt = 0
for i in range(N):
x, y = list(map(int, input().split()))
#print(math.sqrt((x^2)+(y^2)))
if math.sqrt((x*x)+(y*y)) <= D:
cnt+=1
print(cnt) | N,D=map(int,input().split())
ans=0
for _ in range(N):
X,Y=map(int,input().split())
if X*X+Y*Y<=D*D:
ans+=1
print(ans)
| 1 | 5,911,393,600,100 | null | 96 | 96 |
A,B,C=[i for i in input().split(" ")]
print(" ".join([C,A,B]))
| n=int(input())
num_line=list(map(int,input().split()))
num_line.reverse()
print(" ".join(map(str,num_line)))
| 0 | null | 19,613,496,213,220 | 178 | 53 |
from collections import Counter
n = int(input())
s = Counter([input() for _ in range(n)])
before = 0
ans = []
s = s.most_common()
for i in range(len(s)):
if before == 0: before = s[i][1]
elif before != s[i][1]: break
ans.append(s[i][0])
for i in sorted(ans): print(i) | N = int(input())
S = {}
c = 0
for _ in range(N):
s = input()
if s not in S:
S[s] = 1
else:
S[s] += 1
c = max(c, S[s])
ans = []
for k, v in S.items():
if v == c:
ans.append(k)
ans.sort()
for a in ans:
print(a)
| 1 | 69,970,558,159,044 | null | 218 | 218 |
n,m,l = map(int, input().split())
A = [[0 for j in range(m)] for i in range(n)]
B = [[0 for j in range(l)] for i in range(m)]
C = [[0 for j in range(l)] for i in range(n)]
for i in range(n):
A[i] = list(map(int, input().split()))
for i in range(m):
B[i] = list(map(int, input().split()))
for i in range(n):
for j in range(l):
for k in range(m):
C[i][j] += A[i][k] * B[k][j]
for i in range(n):
for j in range(l-1):
print(C[i][j],end=' ')
print(C[i][l-1],sep='')
| n_max, m_max, l_max = (int(x) for x in input().split())
a = []
b = []
c = []
for n in range(n_max):
a.append([int(x) for x in input().split()])
for m in range(m_max):
b.append([int(x) for x in input().split()])
for n in range(n_max):
c.append( [sum(a[n][m] * b[m][l] for m in range(m_max)) for l in range(l_max)])
for n in range(n_max):
print(" ".join(str(c[n][l]) for l in range(l_max))) | 1 | 1,448,548,399,572 | null | 60 | 60 |
main=list(map(int,input().split()));count=0
for i in range(main[0],main[1]+1):
if(i%main[2]==0): count=count+1
print(count) | #!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
r = int(input())
print(r**2)
if __name__ == '__main__':
main()
| 0 | null | 76,141,868,586,952 | 104 | 278 |
#セグ木
from collections import deque
def f(L, R): return L|R # merge
def g(old, new): return old^new # update
zero = 0 #零元
class segtree:
def __init__(self, N, z):
self.M = 1
while self.M<N: self.M *= 2
self.dat = [z] * (self.M*2-1)
self.ZERO = z
def update(self, x, idx, l=0, r=-1):
if r==-1: r = self.M
idx += self.M-1
self.dat[idx] = g(self.dat[idx], x)
while idx > 0:
idx = (idx-1)//2
self.dat[idx] = f(self.dat[idx*2+1], self.dat[idx*2+2])
def query(self, a, b=-1, idx=0, l=0, r=-1):
if r==-1: r = self.M
if b==-1: b = self.M
q = deque([])
q.append([l, r, 0])
ret = self.ZERO
while len(q):
tmp = q.popleft()
L = tmp[0]
R = tmp[1]
if R<=a or b<=L: continue
elif a<=L and R<=b:
ret = f(ret, self.dat[tmp[2]])
else:
q.append([L, (L+R)//2, tmp[2]*2+1])
q.append([(L+R)//2, R, tmp[2]*2+2])
return ret
n = int(input())
s = list(input())
q = int(input())
seg = segtree(n+1, 0)
for i in range(n):
num = ord(s[i]) - ord("a")
seg.update((1<<num), i)
for _ in range(q):
a, b, c = input().split()
b = int(b) - 1
if a == "1":
pre = ord(s[b]) - ord("a")
now = ord(c) - ord("a")
seg.update((1<<pre), b)
seg.update((1<<now), b)
s[b] = c
else:
q = seg.query(b, int(c))
bin(q).count("1")
print(bin(q).count("1"))
| #define S as string
#print S until len is equal to K
#time complexity O(1)
K = int(input())
S = input()
str = S
if len(S) > K:
print (str[0:K]+ "...")
else:
print(str)
| 0 | null | 40,813,527,163,200 | 210 | 143 |
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
s = S()
k = I()
same = len(set(list(s)))==1
ans = None
if same:
ans = len(s)*k//2
else:
if s[0]!=s[-1]:
cnt = 0
change = False
for i in range(1,len(s)):
if s[i] == s[i-1] and not change:
cnt += 1
change = True
else:
change = False
ans = cnt*k
else:
char = s[0]
start = len(s)
goal = -1
cnt = 0
while s[start-1] == char:
start -= 1
while s[goal+1] == char:
goal += 1
lenth = len(s)-start + goal+1
cnt += lenth//2 * (k-1)
ccnt = 0
change = False
for i in range(goal+1+1,start):
if s[i] == s[i-1] and not change:
ccnt += 1
change = True
else:
change = False
cnt += ccnt * (k-2)
ccnt = 0
change = False
for i in range(1,start):
if s[i] == s[i-1] and not change:
ccnt += 1
change = True
else:
change = False
cnt += ccnt
ccnt = 0
change = False
for i in range(goal+1+1, len(s)):
if s[i] == s[i-1] and not change:
ccnt += 1
change = True
else:
change = False
cnt += ccnt
ans = cnt
print(ans)
main()
| from math import floor, ceil
s = input()
k = int(input())
def f(s):
b = ''
ret = 0
for i in s:
if i==b:
b = ''
ret += 1
continue
b = i
return ret
b = f(s*2) - f(s*1)
c = f(s*3) - f(s*2)
print(f(s) + b*floor(k/2) + c*ceil(k/2-1)) | 1 | 175,068,869,314,948 | null | 296 | 296 |
import numpy as np
N,M = map(int,input().split())
A = list(map(int,input().split()))
Amax=max(A)
n0 = 2**int(np.ceil(np.log2(2*Amax+1)))#Amax+1以上となる最小の2のべき乗数
Afre=np.zeros(n0).astype(int)#パワーの頻度(1~Amax+1)
for i in range(N):
Afre[A[i]]+=1
#astype(int)は切り捨てなので,rintで四捨五入してから.
S = np.rint(np.fft.irfft(np.fft.rfft(Afre)*np.fft.rfft(Afre))).astype(int)
Scum =S.cumsum()#累積和
bd = N*N-M#上からM個を取り出したい
i=np.searchsorted(Scum,bd)#価値iを生み出せる組みがM個以上ある
#価値iが生み出せる選び方の余分なものを引きたい
remove=((Scum[-1]-Scum[i])-M)*i
ans=0
for j in range(i+1,n0):
ans+=S[j]*j
print(ans-remove) | n,k = map(int,input().split(' '))
l = list(map(int,input().split(' ')))
count = 0
for i in l:
if i >= k:
count += 1
else:
continue
print(count) | 0 | null | 143,255,399,739,250 | 252 | 298 |
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
n = int(input())
s = input()
ans = 0
aDec = False
bDec = False
for i in range(n):
if s[i] == "A":
aDec = True
bDec = False
elif s[i] == "B":
if (aDec):
bDec = True
else:
bDec = False
aDec = False
elif s[i] == "C":
if (bDec):
ans += 1
bDec = False
aDec = False
else:
bDec = False
aDec = False
print(ans)
| n=int(input())
s=0
for i in range(n+1):
s=(10*s+7)%n
if(s==0):
print(i+1)
exit()
print(-1)
| 0 | null | 52,987,441,968,252 | 245 | 97 |
import sys
N, R = map(int, sys.stdin.readline().split())
print(R if 10 <= N else R + 100 * (10 - N)) | # E - Divisible Substring
N,P = map(int,input().split())
S = input()
ans = 0
if P==2 or P==5:
for i in range(N):
if int(S[i])%P==0:
ans += i+1
else:
l = [1]+[0]*(P-1)
tmp = 0
r10 = 1
for i in range(N-1,-1,-1):
tmp = (r10*int(S[i])+tmp)%P
l[tmp] += 1
r10 = (r10*10)%P
for x in l:
ans += x*(x-1)//2
print(ans) | 0 | null | 60,727,564,895,932 | 211 | 205 |
from collections import defaultdict
N, K = map(int,input().split())
A = list(map(int,input().split()))
a = [0]
for i in A:
a.append((a[-1]+i-1)%K)
d = defaultdict(int)
ans = 0
for i in range(N+1):
if i >= K:
d[a[i-K]] -= 1
ans += d[a[i]]
d[a[i]] += 1
print(ans)
| from collections import defaultdict
N, K = map(int, input().split())
A = [(int(c)%K)-1 for c in input().split()]
B = [0]
for c in A:
B += [B[-1]+c]
dic = defaultdict(int)
ldic = defaultdict(int)
for i in range(min(K,N+1)):
c = B[i]
dic[c%K] += 1
ans = 0
#print(dic)
for i in range(1,N+1):
x = B[i-1]
ldic[x%K] += 1
ans += dic[x%K]-ldic[x%K]
if K+i-1<=N:
dic[B[K+i-1]%K] += 1
"""
print('###############')
print(i,x, ans)
print(dic)
print(ldic)
"""
print(ans)
| 1 | 137,107,032,483,382 | null | 273 | 273 |
n = input()
num = map(int, raw_input().split())
for i in range(n):
if i == n-1:
print num[n-i-1]
break
print num[n-i-1], | N = int(input())
tracks = [tuple(input().split()) for _ in range(N)]
X = input()
sleep = False
ans = 0
for s, t in tracks:
t = int(t)
if sleep:
ans += t
if s == X:
sleep = True
print(ans) | 0 | null | 48,902,415,339,942 | 53 | 243 |
n=int(input())
l=[list(input().split()) for _ in range(n)]
x=input()
ans=0
for i in range(n):
s,t=l[i]
t=int(t)
ans+=t
if s==x:
c=ans
print(ans-c)
| l = ['SUN','MON','TUE','WED','THU','FRI','SAT']
s = input()
if s in l:
print(7-l.index(s))
else:
pass | 0 | null | 114,867,104,020,292 | 243 | 270 |
def resolve():
N, X, M = map(int,input().split())
A_list = [X]
preA = X
A_set = set(A_list)
for i in range(N-1):
A = preA**2%M
if A == 0:
answer = sum(A_list)
break
elif A in A_set:
finished_count = len(A_list)
# 何番目か確認
same_A_index = A_list.index(A)
one_loop = A_list[same_A_index:]
loop_count, part_loop = divmod(N-finished_count, len(one_loop))
answer = sum(A_list) + sum(one_loop)*loop_count + sum(one_loop[:part_loop])
break
A_list.append(A)
A_set.add(A)
preA = A
else:
answer = sum(A_list)
print(answer)
resolve() | from itertools import combinations_with_replacement
n, m, q = map(int, input().split())
a = [0] * q
b = [0] * q
c = [0] * q
d = [0] * q
for i in range(q):
a[i], b[i], c[i], d[i] = map(int, input().split())
ans = 0
for v in combinations_with_replacement(list(range(1, m + 1)), n):
sm = 0
for i in range(q):
if v[b[i] - 1] - v[a[i] - 1] == c[i]:
sm += d[i]
ans = max(ans, sm)
print(ans)
| 0 | null | 15,182,805,171,560 | 75 | 160 |
import math
from itertools import permutations
N=int(input())
XYlist=[]
indexlist=[i for i in range(N)]
for _ in range(N):
XYlist.append(tuple(map(int,input().split())))
ans=0
num=0
for indexes in permutations(indexlist,N):
for i in range(N-1):
ans+=math.sqrt((XYlist[indexes[i]][0]-XYlist[indexes[i+1]][0])**2+
(XYlist[indexes[i]][1]-XYlist[indexes[i+1]][1])**2)
num+=1
print(ans/num) | import math
n=int(input())
XY=[list(map(int,input().split())) for _ in range(n)]
ans=0
for i in range(n-1):
for j in range(i+1,n):
disx=XY[i][0]-XY[j][0]
disy=XY[i][1]-XY[j][1]
dis=math.sqrt(disx**2+disy**2)
ans+=dis
print(2*ans/n) | 1 | 148,493,763,077,580 | null | 280 | 280 |
import sys
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7
K, X = rl()
if K*500 >= X:
print('Yes')
else:
print('No') | import math
import collections
def prime_diviation(n):
factors = []
i = 2
while i <= math.floor(math.sqrt(n)):
if n%i == 0:
factors.append(int(i))
n //= i
else:
i += 1
if n > 1:
factors.append(n)
return factors
N = int(input())
if N == 1:
print(0)
exit()
#pr:素因数分解 prs:集合にしたやつ prcnt:counter
pr = prime_diviation(N)
prs = set(pr)
prcnt = collections.Counter(pr)
#print(pr, prs, prcnt)
ans = 0
for a in prs:
i = 1
cnt = 2*prcnt[a]
#2*prcnt >= n(n+1)となる最大のnを探すのが楽そう
# print(cnt)
while cnt >= i*(i+1):
i += 1
ans += i - 1
print(ans) | 0 | null | 57,514,584,403,568 | 244 | 136 |
import math
X = int(input())
year = 0
money = 100
while(money < X):
money = money * 101//100
year += 1
print(year)
| A, B, C = map(int, input().split())
K = int(input())
for i in range((K + 1)):
for j in range((K + 1) - i):
for k in range((K + 1) - i - j):
if A * (2 ** i) < B * (2 ** j) < C * (2 ** k):
print("Yes")
exit()
print("No")
| 0 | null | 17,038,235,130,542 | 159 | 101 |
def main():
r = int(input())
print(r**2)
return 0
if __name__ == '__main__':
main() | def main():
mountain=[]
for i in range(10):
num=int(input())
mountain.append(num)
mountain=sorted(mountain)
mountain=mountain[::-1]
for i in range(3):
print(mountain[i])
if __name__=='__main__':
main() | 0 | null | 72,558,677,697,828 | 278 | 2 |
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
D = {}
for a in A:
bit = bin(a)[2:][::-1]
for i in range(len(bit)):
if bit[i] == '1':
if i not in D:
D[i] = 1
else:
D[i] += 1
ans = 0
for k, v in D.items():
ans += (N-v)*v*2**k % mod
ans = ans % mod
print(ans) | n = int(input())
a = [int(s) for s in input().split(" ")]
cnt = 0
for i in range(n):
mi = min(a[i:])
if a[i] > mi:
j = a[i:].index(mi)+i
a[i], a[j] = a[j], a[i]
cnt += 1
print(" ".join([str(i) for i in a]))
print(cnt) | 0 | null | 61,715,416,368,202 | 263 | 15 |
n = int(input())
if n % 2 != 0:
print(0)
else:
ans = 0
t = 10
while n >= t:
ans += n//t
t *= 5
print(ans) | n=int(input())
if n%2==1:
print(0)
exit(0)
n//=2
from math import floor,factorial
ans=0
deno=5
while deno<=n:
ans+=n//deno
deno*=5
print(ans) | 1 | 115,966,235,474,660 | null | 258 | 258 |
N = int(input())
s = input()
ans = min(s.count('R'), s.count('W'), s[N-s.count('W'):].count('R'))
print(ans) | from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
import random
sys.setrecursionlimit(4100000)
def gcd(a,b):
if(a%b==0):return(b)
return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()
N=int(input())
mod=10**9+7
dp=[[8,1,1,0] for i in range(N)]#1,2~8,9,both
for i in range(1,N):
dp[i][0]=dp[i-1][0]*8
dp[i][1]=dp[i-1][0]+dp[i-1][1]*9
dp[i][2]=dp[i-1][0]+dp[i-1][2]*9
dp[i][3]=dp[i-1][1]+dp[i-1][2]+dp[i-1][3]*10
for n in range(4):
dp[i][n]%=mod
print(dp[-1][3]%mod)
| 0 | null | 4,715,225,219,970 | 98 | 78 |
n,m = list(map(int,input().split()))
A = [map(int,input().split()) for i in range(n)]
b = [int(input()) for i in range(m)]
for a in A:
print(sum([x*y for (x,y) in zip(a,b)])) | n, m = map(int, raw_input().split())
a, b, result = list(), list(), list()
for _ in range(n):
a.append(map(int, raw_input().split()))
for _ in range(m):
b.append(int(raw_input()))
for i in range(n):
temp = 0
for j in range(m):
temp += a[i][j] * b[j]
result.append(temp)
for i in result:
print(i) | 1 | 1,147,298,909,540 | null | 56 | 56 |
def abc169c_multiplication3():
a, b = input().split()
a = int(a)
b = int(b[0] + b[2] + b[3])
print(a * b // 100)
abc169c_multiplication3()
| A,B,C,D,E=map(int,input().split())
if A==0 :
print(1)
elif B==0:
print(2)
elif C==0:
print(3)
elif D==0:
print(4)
else :
print(5)
| 0 | null | 14,965,708,056,520 | 135 | 126 |
import sys
n,m=map(int,input().split())
if n==3:
ans=["1","0","0"]
elif n==2:
ans=["1","0"]
else:
ans=["0"]
cnt=[0,0,0]
for i in range(m):
s,c=map(int,input().split())
if s==1 and c==0 and n!=1:
print(-1)
sys.exit()
elif ans[s-1]!=str(c):
if cnt[s-1]==0:
ans[s-1]=str(c)
cnt[s-1]=1
else:
print(-1)
sys.exit()
print("".join(ans))
| #from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(input())
n,m = readInts()
base = []
if n == 1 and m == 0:
print(0)
exit()
elif n == 2 and m == 0:
print(10)
exit()
elif n == 3 and m == 0:
print(100)
exit()
if n >= 1:
base.append('1')
if n >= 2:
base.append('0')
if n == 3:
base.append('0')
dic = defaultdict(int)
for i in range(m):
s,c = readInts()
s -= 1
if dic[s] != 0:
if int(base[s]) == c:
pass
else:
print(-1)
exit()
else:
dic[s] = 1
base[s] = str(c)
if s == 0 and c == 0 and n >= 2:
print(-1)
exit()
print(*base,sep='')
| 1 | 60,751,423,106,682 | null | 208 | 208 |
N = int(input())
#INF = float('inf')
def check(A):
th = 0 #高さの合計
for i in range(len(A)):
b = A[i][0]
h = A[i][1]
if th + b < 0:
return False
else:
th += h
return True
L = []
R = []
goukei = 0
for i in range(N):
temp = str(input())
b= 0 #最下点
h = 0 #ゴールの位置
for j in range(len(temp)):
if temp[j] == "(":
h += 1
else:
h -= 1
b = min(b,h)
if h > 0:
L.append([b,h])
else:
R.append([b-h,-h])
goukei += h
L.sort(reverse=True)
R.sort(reverse=True)
#print(L,R)
if check(L) and check(R) and goukei == 0:
print("Yes")
else:
print("No") | n=int(input())
s=input()
R=[]
G={}
B=[]
for i in range(n):
if s[i]=='R':
R.append(i+1)
elif s[i]=='G':
G[i+1]=G.get(i+1,0)+1
else:
B.append(i+1)
res=len(R)*len(G)*len(B)
for i in R:
for j in B:
if ((i+j)%2==0 and G.get((i+j)//2,0)==1):
res-=1
if G.get(2*max(i,j)-min(i,j),0)==1:
res-=1
if G.get(2*min(i,j)-max(i,j),0)==1:
res-=1
print(res) | 0 | null | 30,074,420,101,700 | 152 | 175 |
import sys
input = sys.stdin.readline
def main():
N, M, X = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(N)]
ans = sys.maxsize
for mask in range(2 ** N):
C = 0
A = [0] * N
for i in range(N):
if ((mask >> i) & 1):
C += ca[i][0]
A = [a + c for a, c in zip(A, ca[i][1:])]
if all([i >= X for i in A]):
ans = min(ans, C)
if ans != sys.maxsize:
print(ans)
else:
print("-1")
main() | S=input()
if S[-1]=='s':
Ans=S+'es'
else:
Ans=S+'s'
print(Ans) | 0 | null | 12,236,308,729,190 | 149 | 71 |
import sys
r = int(sys.stdin.readline().rstrip())
def main():
print(r ** 2)
if __name__ == '__main__':
main() | import os, sys, re, math
r = int(input())
print(r * r)
| 1 | 145,080,835,101,628 | null | 278 | 278 |
s=int(input())
if s==1:
print(0)
exit()
mod=10**9+7
dp=[0]*(s+1)
dp[1]=0
dp[2]=0
for i in range(3,s+1):
for j in range(3,i+1):
dp[i]+=(dp[i-j])%mod
dp[i]+=1
print(dp[s]%mod) | def main():
s = int(input())
mod = 10**9+7
dp = [0] * (s+1)
dp[0] = 1
x = 0
for i in range(1, s+1):
if i-3 >= 0:
x += dp[i-3]
x %= mod
dp[i] = x
print(dp[s])
if __name__ == "__main__":
main()
| 1 | 3,299,451,748,880 | null | 79 | 79 |
import itertools
import math
n = int(input())
x = []
num = []
for i in range(n):
x.append([int(t) for t in input().split()])
num.append(i)
s = 0
for i in itertools.permutations(num):
i = list(i)
#print(x,i)
for j in range(n-1):
s += math.sqrt((x[i[j]][0] - x[i[j+1]][0])**2 + (x[i[j]][1] - x[i[j+1]][1])**2)
#print(s)
s /= math.factorial(n)
print(s) | import sys
alpha = 'abcdefghijklmnopqrstuvwxyz'
m = {k:0 for k in alpha}
q = ''
for line in sys.stdin:
q += line
for s in q:
s = s.lower()
if s in m:
m[s] += 1
for s in alpha:
print('%s : %d' % (s, m[s])) | 0 | null | 75,136,298,199,172 | 280 | 63 |
import sys
s = 'ACL'
n = int(sys.stdin.readline().rstrip("\n"))
print(s*n) | #! /usr/bin/python3
k = int(input())
print('ACL'*k)
| 1 | 2,149,375,591,612 | null | 69 | 69 |
a = int(input())
b = int(input())
if (a == 1 and b == 2) or (a == 2 and b == 1):
print(3)
elif (a == 1 and b == 3) or (a == 3 and b == 1):
print(2)
else:
print(1) | A = int(input())
B = int(input())
print(3 if A+B==3 else 2 if A+B==4 else 1) | 1 | 110,434,231,526,060 | null | 254 | 254 |
import itertools
import math
N = int(input())
citys = []
for i in range(N):
citys.append([int(x) for x in input().split()])
a = list(itertools.permutations(range(N), N))
ans = 0
for i in a:
b = 0
for j in range(N-1):
b += math.sqrt((citys[i[j]][0] - citys[i[j+1]][0])**2 + (citys[i[j]][1] - citys[i[j+1]][1])**2)
ans += b
print(ans/len(a))
| class XCubic:
def exe(self, x):
return x*x*x
if __name__ == "__main__":
x = int(raw_input())
xc = XCubic()
print(xc.exe(x)) | 0 | null | 74,306,155,378,488 | 280 | 35 |
def main():
X = int(input())
fifth_power = [x ** 5 for x in range(201)]
for i in range(len(fifth_power)):
p = fifth_power[i]
q1 = abs(X - p)
q2 = abs(X + p)
if q1 in fifth_power:
if p + q1 == X:
print(fifth_power.index(p), -fifth_power.index(q1))
elif p - q1 == X:
print(fifth_power.index(p), fifth_power.index(q1))
return 0
if q2 in fifth_power:
print(fifth_power.index(q2), fifth_power.index(p))
return 0
main() | x=int(input())
for i in range(-200,200):
for j in range(-200,200):
if i**5-j**5==x:
print("{} {}".format(i,j))
exit() | 1 | 25,437,493,950,130 | null | 156 | 156 |
A, B, C, D = list(map(int, input().split()))
a = A // D
b = C // B
N = max(a, b) + 1
for i in range(N):
if C > 0:
C -= B
if C <= 0:
break
if A > 0:
A -= D
if A <= 0:
break
ans = "No"
if A > C:
ans = "Yes"
print(ans) | A,B,C,D = (int(x) for x in input().split())
while True:
C -= B
if C <= 0:
print('Yes')
break
else:
A -= D
if A <= 0:
print('No')
break | 1 | 29,745,280,159,360 | null | 164 | 164 |
n = int(input())
L = list(map(int, input().split()))
ans = 0
for i in range(n):
for j in range(i+1, n):
for k in range(j+1, n):
if L[i] == L[j] or L[j] == L[k] or L[k] == L[i]:
pass
elif L[i] + L[j] > L[k] and L[j] + L[k] > L[i] and L[k] + L[i] > L[j]:
ans += 1
print(ans) | import itertools
N = int(input())
A = list(map(int,input().split()))
A.sort()
Acomb = list(itertools.combinations(A, 3))
ans = 0
for tri in Acomb:
if tri[0] < tri[1] and tri[1] < tri[2] and tri[0] + tri[1] > tri[2]:
ans += 1
print(ans) | 1 | 5,049,617,532,886 | null | 91 | 91 |
N = int(input())
a = list(map(int,input().split()))
flag = True
for a_i in a:
if a_i%2==0:
if not (a_i%3==0 or a_i%5==0):
flag=False
print("APPROVED" if flag else "DENIED")
| n = int(input())
a = list(map(int, input().split()))
ch = 0
for i in range(n):
if a[i] % 2 == 0:
if a[i] % 3 != 0 and a[i] % 5 != 0:
ch = 1
if ch == 0:
ans = 'APPROVED'
else:
ans = 'DENIED'
print(ans)
| 1 | 68,941,895,889,820 | null | 217 | 217 |
#created by nit1n
N, S = map(int,input().split())
A = list(map(int,input().split()))
mod = 998244353
dp = [[0 for j in range(S + 1)] for i in range(N + 1)]
dp[0][0] = 1
for i in range(N) :
for j in range (S+1) :
dp[i+1][j] += 2*dp[i][j]
dp[i+1][j] = dp[i+1][j]%mod
if j +A[i] <= S :
dp[i+1][j+A[i]] += dp[i][j]
dp[i+1][j+A[i]] %= mod
print(dp[N][S])
| n = int(raw_input())
dp = {}
def fib(n):
if n in dp: return dp[n]
if n == 0:
dp[n] = 1
return 1
elif n == 1:
dp[n] = 1
return 1
else:
dp[n] = fib(n-1)+fib(n-2)
return dp[n]
print fib(n) | 0 | null | 8,755,488,443,940 | 138 | 7 |
while True:
L = map(int,raw_input().split())
H = (L[0])
W = (L[1])
if H == 0 and W == 0:break
for x in range(0,H):print "#" * W
print "" | while True:
a=[int(x) for x in input().split()]
if a[0]==a[1]==0:
break
else:
for i in range(a[0]):
print("#"*a[1])
print("") | 1 | 786,082,389,650 | null | 49 | 49 |
import sys
from collections import deque
def main():
h, w = map(int, input().split())
area = [[s for s in sys.stdin.readline().strip()] for _ in range(h)]
start_point = {0:set(), 1:set(), 2:set(), 3:set(), 4:set()}
min_neighbor = 4
for i in range(h):
for j in range(w):
if area[i][j] == '#':
continue
roads = 0
if i > 0 and area[i - 1][j] == '.':
roads += 1
if i < h - 1 and area[i + 1][j] == '.':
roads += 1
if j > 0 and area[i][j - 1] == '.':
roads += 1
if j < w - 1 and area[i][j + 1] == '.':
roads += 1
min_neighbor = min(min_neighbor, roads)
start_point[roads].add((i, j))
max_cost = 0
for start in start_point[min_neighbor]:
queue = deque()
queue.append(start)
cost = 0
visited = set()
while len(queue) > 0:
roads = len(queue)
found = False
for i in range(roads):
s = queue.popleft()
if s in visited:
continue
found = True
visited.add(s)
i = s[0]
j = s[1]
if i > 0 and area[i - 1][j] == '.':
queue.append((i - 1, j))
if i < h - 1 and area[i + 1][j] == '.':
queue.append((i + 1, j))
if j > 0 and area[i][j - 1] == '.':
queue.append((i, j - 1))
if j < w - 1 and area[i][j + 1] == '.':
queue.append((i, j + 1))
if not found:
cost -= 1
max_cost = max(cost, max_cost)
if found:
cost += 1
print(max_cost)
if __name__ == '__main__':
main() | s=raw_input()
t=[]
for x in s:
if x=='?':
t.append('D')
else:
t.append(x)
print "".join(t) | 0 | null | 56,381,558,969,860 | 241 | 140 |
def insertionSort(A, n, g):
global cnt
for i in range(g,n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt+=1
A[j+g] = v
def shellSort(A, n):
global cnt
cnt = 0
g = 1
G = [1]
m = 1
for i in range(1,101):
tmp = G[i-1]+(3)**i
if tmp <= n:
m = i+1
G.append(tmp)
g += 1
else:
break
G.reverse()
print(m) # 1行目
print(" ".join(list(map(str,G)))) # 2行目
for i in range(0,m):
insertionSort(A, n, G[i])
print(cnt) # 3行目
for i in range(0,len(A)):
print(A[i]) # 4行目以降
cnt = 0
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
shellSort(A,n)
| # ALDS1_2_D: Shell Sort
#N = 5
#A = [5, 1, 4, 3, 2]
#N = 3
#A = [3, 2, 1]
A = []
N = int(input())
for i in range(N):
A.append(int(input()))
def insertionSort(A, N, g, cnt):
#print(" ".join(map(str, A)))
for i in range(g, N):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
#print(" ".join(map(str, A)))
return cnt
def shellSort(A, N):
cnt = 0
#m = 2
#listG = [4, 1]
h = 1
listG = []
while h <= N:
listG.append(h)
h = 3*h + 1
listG = listG[::-1]
m = len(listG)
for g in listG:
cnt = insertionSort(A, N, g, cnt)
#print(A)
print(m)
print(" ".join(map(str, listG)))
print(cnt)
for v in A:
print(v)
shellSort(A, N)
| 1 | 28,362,731,578 | null | 17 | 17 |
K = input(str())
a = 'ACL'
if K == '1':
print(a)
if K == '2':
print(a * 2)
if K == '3':
print(a * 3)
if K == '4':
print(a * 4)
if K == '5':
print(a * 5)
| K = int(input())
K1 = "ACL"
print(K*K1)
| 1 | 2,216,199,226,072 | null | 69 | 69 |
x, y = map(int, input().split())
for a in range(0, 101):
for b in range(0, 101):
if a + b == x and 2*a + 4*b == y:
print('Yes')
exit()
print('No') | N=int(input())
count=0
for A in range(1,N):
count+=(N-1)//A
print(count) | 0 | null | 8,191,558,870,660 | 127 | 73 |
a,b=map(int,input().split())
s=[''.join([str(a)]*b),''.join([str(b)]*a)]
print(sorted(s)[0]) | import itertools
n,m,q=map(int,input().split())
array=[list(map(int,input().split())) for _ in range(q)]
a=list(range(1,m+1))
A=[]
for i in itertools.combinations_with_replacement(a,n):
A.append(list(i))
ans=[0]
for j in range(len(A)):
AA=A[j]
count=0
for i in range(q):
if AA[array[i][1]-1]-AA[array[i][0]-1]==array[i][2]:
count+=array[i][3]
else:
pass
ans.append(count)
print(max(ans)) | 0 | null | 56,155,459,537,492 | 232 | 160 |
import sys
import math
from collections import deque
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]
def main():
H, W, K = NMI()
choco = [SI() for _ in range(H)]
ans = 100000
for case in range(2**(H-1)):
groups = [[0]]
for i in range(H-1):
if (case >> i) & 1:
groups[-1].append(i+1)
else:
groups.append([i+1])
white = [0] * len(groups)
is_badcase = False
cut = len(groups) - 1
for w in range(W):
diff = [0] * len(groups)
for gi, group in enumerate(groups):
for h in group:
if choco[h][w] == "1":
white[gi] += 1
diff[gi] += 1
if max(white) <= K:
is_cont = True
continue
if max(diff) > K:
is_badcase = True
break
cut += 1
white = diff[:]
continue
if not is_badcase:
ans = min(ans, cut)
print(ans)
if __name__ == "__main__":
main() | import sys
input = sys.stdin.readline
H,W,K=map(int,input().split())
CO=[[0 for i in [0]*W] for j in [0]*H]
DO=[[0 for i in [0]*W] for j in [0]*H]
for i in range(H):
C=input()
for j in range(W):
DO[i][j]=int(C[j])
CO[H-1]=DO[H-1]
F=1000000
for s in range(2**(H-1)):
D=0
E=0
for k in range(H-1):
if ((s >> k) & 1):
for i in range(W):
CO[H-k-2][i]=DO[H-k-2][i]
E+=1
else:
for i in range(W):
CO[H-k-2][i]=DO[H-k-2][i]+CO[H-k-1][i]
lst=[0]*H
for h in range(W):
c=max(CO[x][h] for x in range(H))
d=max(lst[y]+CO[y][h] for y in range(H))
if c>K:
E=1000000
break
elif d>K:
D+=1
lst=[0]*H
for z in range(H):
lst[z]+=CO[z][h]
F=min(F,D+E)
print(F) | 1 | 48,788,117,811,748 | null | 193 | 193 |
i=1
while True:
a=int(input())
if a == 0:
break
print("Case {0}: {1}".format(i,a))
i=i+1 | import math
a, b, c = map(float, input().split())
r = math.radians(c)
S = (a * b * math.sin(r)) / 2
print(S)
d = (a**2 + b**2 - 2 * a * b * math.cos(r))
d = math.sqrt(d)
L = a + b + d
print(L)
h = 2 * S / a
print(h) | 0 | null | 330,147,239,620 | 42 | 30 |
N, M = map(int, input().split())
A = list(map(int, input().split()))
A1 = sum(A)
if N - A1 >= 0:
print(N - A1)
else:
print("-1") | #!/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()
| 1 | 31,901,797,365,460 | null | 168 | 168 |
s = input()
q = int(input())
for i in range(q):
command = input().split()
command[1] = int(command[1])
command[2] = int(command[2])
if command[0] == 'print':
print(s[command[1]:command[2]+1])
elif command[0] == 'reverse':
s = s[command[1]:command[2]+1][::-1].join([s[:command[1]], s[command[2]+1:]])
elif command[0] == 'replace':
s = command[3].join([s[:command[1]], s[command[2]+1:]]) |
string = [str(i) for i in input()]
for _ in range(int(input())):
n = input().split()
order = n.pop(0)
if order == 'replace':
string = string[:int(n[0])] + \
[i for i in n[2]] + string[int(n[1])+1:]
elif order == 'reverse':
string = string[:int(n[0])] + \
string[int(n[0]):int(n[1])+1][::-1] + \
string[int(n[1])+1:]
else :
out = string[ int(n[0]) : int(n[1])+1 ]
print(''.join(out)) | 1 | 2,097,551,588,480 | null | 68 | 68 |
m,n,p = map(int, input().split())
l=[]
for i in range(m,n+1):
if i % p == 0:
l.append(i)
print(len(l)) | N = int(input())
i = input().split()
S = i[0]
T = i[1]
ans=S
for i in range(N):
print(S[i], end='')
print(T[i], end='') | 0 | null | 59,716,136,959,910 | 104 | 255 |
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
if(a%b==0):return(b)
return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()
N,S=map(int,input().split())
A=list(map(int,input().split()))
mod=998244353
gyaku=pow(2,mod-2,mod)
N2=pow(2,N-1,mod)
dp=[0 for n in range(3001)]
for n in range(N):
a=A[n]
for s in range(0,S+1)[::-1]:
if s+a<=S:
dp[s+a]+=dp[s]*gyaku%mod
dp[s+a]%=mod
dp[a]+=N2
dp[a]%=mod
print(dp[S])
| from collections import deque
import numpy as np
H,W = map(int,input().split())
Maze=[list(input()) for i in range(H)]
ans=0
for hi in range(0,H):
for wi in range(0,W):
if Maze[hi][wi]=="#":
continue
maze1=[[0]*W for _ in range(H)]
stack=deque([[hi,wi]])
while stack:
h,w=stack.popleft()
for i,j in [[1,0],[-1,0],[0,1],[0,-1]]:
new_h,new_w=h+i,w+j
if new_h <0 or new_w <0 or new_h >=H or new_w >=W:
continue
elif Maze[new_h][new_w]!="#" and maze1[new_h][new_w]==0:
maze1[new_h][new_w]=maze1[h][w]+1
stack.append([new_h,new_w])
maze1[hi][wi]=0
ans=max(ans,np.max(maze1))
print(ans) | 0 | null | 56,445,542,598,176 | 138 | 241 |
import sys
n = sys.stdin.readlines()
for i in n:
a = [int(x) for x in i.split()]
if a[0] == 0 and a[1] == 0:
break
print(*sorted(a)) | n, k = map(int, input().split())
# from collections import OrderedDict
# d = OrderedDict()
# a = list(input().split())
# b = list(map(int, input().split()))
# print(r + max(0, 100*(10-n)))
# print("Yes" if 500*n >= k else "No")
# s = input()
# a = int(input())
# b = int(input())
# c = int(input())
print("Yes" if n == k else "No") | 0 | null | 42,082,544,729,200 | 43 | 231 |
from bisect import bisect_right
import string
N=int(input())
L=[0]*13
for i in range(1,13):
L[i]=(L[i-1]+1)*26
# print(L)
# やるべきことは26進数
def bisectsearch_right(L,a):
i=bisect_right(L,a)
return(i)
S=string.ascii_lowercase
l=bisectsearch_right(L,N-1)
s=['']*l
tmp=N-1-L[l-1]
# print(l,tmp)
j=l-1
while j>=0:
s[j]=S[tmp%26]
tmp//=26
j-=1
print(''.join(s)) | N = int(input())
ans = ""
letter = "abcdefghijklmnopqrstuvwxyz"
while N != 0:
N -= 1
ans = letter[N % 26] + ans
N = N // 26
print(ans)
| 1 | 11,866,629,325,248 | null | 121 | 121 |
x, n = list(map(int, input().split()))
q = list(map(int, input().split()))
p = [i for i in range(0, 102) if i not in q]
for i in range(len(p)):
if p[i] < x:
continue
# p[i] >= x
break
if p[i] == x:
print(p[i])
else:
if p[i] - x < x - p[i - 1]:
print(p[i])
else:
print(p[i - 1]) | from sys import stdin
from math import sin, cos, pi, sqrt
a, b, C = [float(x) for x in stdin.readline().rstrip().split()]
S = a*b*sin(C*pi/180)/2
c = sqrt(a**2 + b**2 - 2*a*b*cos(C*pi/180))
L = a+b+c
h = 2*S/a
print(*[S, L, h], sep = "\n")
| 0 | null | 7,164,185,453,920 | 128 | 30 |
n = int(input())
p = n // 500 * 1000
n %= 500
p += n // 5 * 5
print(p) | X = int(input())
n500 = int(X / 500)
n5 = int((X % 500) / 5)
print(n500 * 1000 + n5 * 5)
| 1 | 42,671,781,327,422 | null | 185 | 185 |
N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))
dummy=set()
loop=[]
X=set(range(N))
while len(dummy)!=N:
a=[]
k=min(X-dummy)
a.append(k)
dummy.add(k)
l=P[k]-1
while l!=k:
a.append(l)
dummy.add(l)
l=P[l]-1
loop.append(a)
ans=-(10**300)
for l in loop:
temp=0
s=len(l)
ssum=0
k=0
for i in range(s):
ssum+=C[l[i]]
if ssum>0:
temp+=((K-1)//s)*ssum
k=K-((K-1)//s)*s
else:
k=min(K,s)
kmax=-(10**300)
for ii in range(s):
tempscore=temp
for jj in range(1,k+1):
tempscore+=C[l[(ii+jj)%s]]
if tempscore>kmax:
kmax=tempscore
if kmax>ans:
ans=kmax
print(ans)
| f=lambda:[*map(int,input().split())]
n,k=f()
p,c=f(),f()
p=[i-1 for i in p]
a=-10**9
for i in range(n):
x,l,s,t=i,[],0,0
while 1:
x=p[x]
l+=[c[x]]
s+=c[x]
if x==i: break
m=len(l)
for j in range(m):
if j+1>k: break
t+=l[j]
a=max(a,t+(k-j-1)//m*s*(s>0))
print(a) | 1 | 5,370,667,613,168 | null | 93 | 93 |
import numpy as np
N = int(input())
X = int(np.ceil(N/1.08))
if np.floor(X*1.08)!=N:
X = ':('
print(X) | n, k = map(int, input().split())
ans = 0
for i in range(k, n + 2):
l = int(i * (i - 1) / 2)
r = n * i - l
ans += r - l + 1
ans %= 10 ** 9 + 7
print(ans) | 0 | null | 79,476,412,427,190 | 265 | 170 |
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n = int(input())
a = list(map(int, input().split()))
aa = [(num,i) for i,num in enumerate(a)]
aa.sort()
write(" ".join(map(str, [item[1]+1 for item in aa]))) | def main():
N = input()
a = [input() for y in range(N)]
a_max = -10**9
a_min = a[0]
for j in xrange(1,len(a)):
if a[j] - a_min > a_max:
a_max = a[j] - a_min
if a[j] < a_min:
a_min = a[j]
print a_max
main() | 0 | null | 90,568,629,570,910 | 299 | 13 |
import sys
input = sys.stdin.readline
def solve(N):
res = 0
flg = 0
for n in reversed(N):
if flg == 2:
if n >= 5:
flg = 1
else:
flg = 0
m = flg + n
if m == 5:
res += 5
flg = 2
elif m < 5:
res += m
flg = 0
else:
res += (10 - m)
flg = 1
return res + flg%2
N = list(map(int, input().strip()))
print(solve(N))
# N = 1
# q = 0
# while True:
# p = solve(list(map(int, str(N))))
# if abs(p-q) > 1:
# print(N, "OK")
# exit()
# q = p
# N += 1 | kuri_now = False
cost = [0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0]
kuri = [0, 0, 0, 0, 0, 0.5, 1, 1, 1, 1, 1]
result = 0
for digit in reversed(input()):
digit = int(digit)
if kuri_now == 0:
result += cost[digit]
kuri_now = kuri[digit]
elif kuri_now == 1:
result += cost[digit + 1]
kuri_now = kuri[digit + 1]
else:
if cost[digit] <= cost[digit + 1]:
result += cost[digit]
kuri_now = kuri[digit]
else:
result += cost[digit + 1]
kuri_now = kuri[digit + 1]
if kuri_now == 1:
result += 1
print(result) | 1 | 70,940,478,349,820 | null | 219 | 219 |
# -*- coding: utf-8 -*-
import math
N, M = map(int, input().split())
A = list(map(int, input().split()))
for i in range(M):
N -= A[i]
if N >= 0:
print(N)
else:
print(-1) | n = int(input())
rooms = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for rec in range(n):
b, f, r, v = map(int, input().split())
rooms[b-1][f-1][r-1] += v
for i, b in enumerate(rooms):
for f in b:
print("",*f)
if i != 3:
print("####################") | 0 | null | 16,638,568,753,950 | 168 | 55 |
import sys
import math
from math import ceil
input = sys.stdin.readline
print(ceil(int(input()) / 2)) | def main():
n = int(input())
print((n + 1) // 2)
main() | 1 | 58,924,257,521,180 | null | 206 | 206 |
x=input()
ret = ''
for a in x:
if a.islower() : a = a.upper()
elif a.isupper(): a = a.lower()
ret += a
print(ret) | from string import ascii_lowercase, ascii_uppercase
s = input()
t = ''
for i in s:
if i in ascii_uppercase:
t += i.lower()
elif i in ascii_lowercase:
t += i.upper()
else:
t += i
print(t)
| 1 | 1,486,440,499,348 | null | 61 | 61 |
n = int(input())
s = str(input())
r = 0
g = 0
b = 0
for i in range(n):
if s[i] == "R":
r += 1
elif s[i] == "G":
g += 1
else:
b += 1
p = r*g*b
for i in range(n-2):
for j in range(int(n/2)+1):
if i + 2*j >n-1:
break
if s[i] != s[i+j] and s[i] != s[i+2*j] and s[i+2*j] != s[i+j]:
p -= 1
print(p) | n = int(input())
a = sorted([int(i) for i in input().split()])
cnt = 1
for ai in a:
cnt *= ai
if cnt > 10 ** 18:
print(-1)
exit()
print(cnt) | 0 | null | 26,267,494,944,272 | 175 | 134 |
N = int(input())
A = list(map(int,input().split()))
ma = max(A)
l = [0 for _ in range(ma + 10)]
for i in range(N):
temp = A[i]
while(temp <= ma + 5):
l[temp] += 1
temp += A[i]
ans = 0
for i in range(N):
if l[A[i]] == 1: ans += 1
print(ans) | nums = input().split()
W = int( nums[0])
H = int( nums[1])
x = int( nums[2])
y = int( nums[3])
r = int( nums[4])
if (x - r) >= 0 and (x + r) <= W:
if (y - r) >= 0 and (y + r) <= H:
print( "Yes")
else:
print( "No")
else:
print( "No") | 0 | null | 7,469,186,723,420 | 129 | 41 |
from collections import deque
n = int(input())
dlist = deque()
for i in range(n):
code = input().split()
if code[0] == "insert":
dlist.insert(0,code[1])
if code[0] == "delete":
try:
dlist.remove(code[1])
except:
continue
if code[0] == "deleteFirst":
dlist.popleft()
if code[0] == "deleteLast":
dlist.pop()
print(*dlist,sep=" ") | from collections import deque
n = int(input())
dll = deque([])
for _ in range(n):
p = input().split()
if p[0] == "insert":
dll.appendleft(p[1])
elif p[0] == "delete":
try:
dll.remove(p[1])
except:
pass
elif p[0] == "deleteFirst":
dll.popleft()
else:
dll.pop()
print(" ".join(dll))
| 1 | 53,274,501,060 | null | 20 | 20 |
def is_prime(x):
if x == 1:
return False
l = x ** 0.5
n = 2
while n <= l:
if x % n == 0:
return False
n += 1
return True
import sys
def solve():
file_input = sys.stdin
N = file_input.readline()
cnt = 0
for l in file_input:
x = int(l)
if is_prime(x):
cnt += 1
print(cnt)
solve() | from itertools import combinations
n = int(input())
d = list(map(int, input().split()))
ans = 0
sum = sum(d)
for i in d:
sum -= i
ans += i*sum
print(ans) | 0 | null | 84,229,211,413,728 | 12 | 292 |
a,b,c= (int(x) for x in input().split())
A = int(a)
B = int(b)
C = int(c)
if A+B+C >= 22:
print("bust")
else:
print("win") | import numba
@numba.njit
def main(N):
x = 0
for i in range(1,N+1):
for j in range(i,N+1,i):
x += j
return x
N = int(input())
print(main(N)) | 0 | null | 64,804,581,561,160 | 260 | 118 |
N = int(input())
c = list(str(input()))
r = c.count('R')
w = 0
for i in range(r):
if c[i] == 'W':
w += 1
print(w) | n, s = input(), input()
print(s[:s.count("R")].count("W")) | 1 | 6,289,974,030,158 | null | 98 | 98 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.