code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 6.82M
181,637B
⌀ | question_pair_id
float64 101M
180,471B
⌀ | code1_group
int64 2
299
| code2_group
int64 2
299
|
---|---|---|---|---|---|---|
k = input()
s = input()
print("Yes" if s[:-1] == k else "No")
|
a = [str(input()) for i in range(2)]
s = a[0]
t = a[1]
s_l = len(s)
S = s + t[s_l]
if S == t:
print('Yes')
else:
print('No')
| 1 | 21,373,084,758,560 | null | 147 | 147 |
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)
def main():
N = int(input().strip())
return (N//2) + N % 2
if __name__ == "__main__":
print(main())
|
N = int(input())
r = (N +2-1)//2
print(r)
| 1 | 58,967,168,091,428 | null | 206 | 206 |
import math
r = input()
l = math.pi*r*2.0
s = r*r*math.pi
print "%f %f" %(s, l)
|
H,N=map(int,input().split())
lst=list(map(int,input().split()))
s=sum(lst)
if s>=H:
print("Yes")
else:
print("No")
| 0 | null | 39,526,907,698,990 | 46 | 226 |
i = [i for i in input().split()]
op = ['+', '*', '-']
stack = []
for j in i:
if j in op:
r = stack.pop()
l = stack.pop()
stack.append(str(eval(l + j + r)))
else:
stack.append(j)
print (stack[0])
|
input_str = input().split(' ')
stack = []
left_num, right_num = 0, 0
for tmp_str in input_str:
if tmp_str == '+':
right_num = stack.pop()
left_num = stack.pop()
stack.append(left_num + right_num)
elif tmp_str == '-':
right_num = stack.pop()
left_num = stack.pop()
stack.append(left_num - right_num)
elif tmp_str == '*':
right_num = stack.pop()
left_num = stack.pop()
stack.append(left_num * right_num)
elif tmp_str == '/':
right_num = stack.pop()
left_num = stack.pop()
stack.append(left_num / right_num)
else:
stack.append(int(tmp_str))
print(stack.pop())
| 1 | 35,561,422,260 | null | 18 | 18 |
import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
N,K=MI()
h=LI()
h.sort()
if K>=N:
print(0)
exit()
for i in range(K):
h[-1-i]=0
ans=sum(h)
print(ans)
main()
|
from string import ascii_lowercase
n = int(input())
def f(l):
if len(l)==n:
print("".join([ascii_lowercase[i] for i in l]))
return
for i in range(max(l)+2):
f(l+[i])
f([0])
| 0 | null | 65,523,148,402,100 | 227 | 198 |
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 9 14:33:00 2020
@author: liang
"""
from math import gcd
N, M = map(int, input().split())
A = [int(i) for i in input().split()]
flag = False
res = 1
for a in A:
a //= 2
res *= a//gcd(res,a)
if res > M:
flag = True
break
#print(res)
"""
存在チェック
2で割り切れる個数同じ?
"""
for a in A:
if int(res/a) == res/a:
flag = True
if flag:
ans = 0
print(ans)
else:
#ans = (M - res(A)//2)//res + 1
#ans = (M-1)//res//2 + 1
ans= (M//res + 1)//2
print(ans)
|
N, M = map(int, input().split())
H = list(map(int, input().split()))
table = []
for i in range(N):
table.append(set())
for i in range(M):
Ai, Bi = map(lambda x: x - 1, map(int, input().split()))
table[Ai].add(Bi)
table[Bi].add(Ai)
answer = 0
for i, h in enumerate(H):
highest = True
for path in table[i]:
if h <= H[path]:
highest = False
if highest:
answer += 1
print(answer)
| 0 | null | 63,182,077,739,612 | 247 | 155 |
def solve(N, S):
ans = 0
R, G, B = 0, 0, 0
for i in range(N):
if S[i] == "R":
R += 1
elif S[i] == "G":
G += 1
else:
B += 1
# print(R, G, B, R*G*B)
ans = R * G * B
dif = 1
while dif <= N//2+1:
idx = 0
while idx + dif + dif < N:
if S[idx] != S[idx + dif] and S[idx+dif] != S[idx+2*dif] and S[idx+2*dif] != S[idx]:
ans -= 1
idx += 1
dif += 1
print(ans)
if __name__ == '__main__':
# N = 4000
# S = 'RGBR' * 1000
N = int(input())
S = input()
solve(N, S)
|
import sys
def main():
input = sys.stdin.buffer.readline
n, m = map(int, input().split())
a_list = list(map(int, input().split()))
for a in a_list:
n -= a
if n < 0:
break
print(n if n >= 0 else -1)
if __name__ == '__main__':
main()
| 0 | null | 34,041,138,703,780 | 175 | 168 |
import sys
from collections import defaultdict
N,S=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())
mod=998244353
cur=defaultdict(lambda: 0)
new=defaultdict(lambda: 0)
cur[0]=1
for a in A:
for i in cur.keys():
if i+a<=S:
new[i+a]+=cur[i]
new[i+a]%=mod
new[i]+=cur[i]*2
new[i]%=mod
cur=new
new=defaultdict(lambda: 0)
print cur[S]
|
import sys
from collections import OrderedDict
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)
def inpl():
return list(map(int, input().split()))
def main():
MOD = 998244353
N, S = inpl()
A = sorted(inpl())
dp = {}
dp[0] = 1
for i, a in enumerate(A):
# print(i, dp)
ks = sorted(dp.keys())
for k in ks[::-1]:
# print(k)
if k + a <= S:
if k + a in dp:
dp[k + a] = (dp[k] + dp[k + a]) % MOD
else:
dp[k + a] = dp[k]
dp[k] = (dp[k] * 2) % MOD
# print(dp)
print(0 if S not in dp else dp[S])
return
if __name__ == '__main__':
main()
| 1 | 17,608,842,650,346 | null | 138 | 138 |
import math
a, b = map(int, input().split())
for i in range(1, 1009):
if a == math.floor(i * 0.08) and b == math.floor(i * 0.1):
print(i)
exit()
print(-1)
|
N = int(input())
P = list(map(int, input().split()))
mini = N + 1
ans = 0
for i in range(N):
if P[i] < mini:
ans += 1
mini = P[i]
print(ans)
| 0 | null | 70,875,395,891,508 | 203 | 233 |
from numpy import cumsum
n,k=map(int,input().split())
p=list(map(int,input().split()))
p.sort()
p=cumsum(p)
print((p[k-1]))
|
n,k = input().split(" ")
cost = input().split(" ")
a = []
for i in cost:
a.append(int(i))
a.sort()
sum = 0
for i in range(int(k)):
sum += int(a[i])
print(sum)
| 1 | 11,564,234,847,238 | null | 120 | 120 |
n=int(input())
x, y=0, 1
for i in range(1, n+1):
x, y=y, x+y
print(y)
|
import sys
A, B = map(int, input().split())
ans = -1
for x in range(1010):
a = int((x*0.08))
b = int(x*0.1)
if a == A and b == B:
print(x)
sys.exit()
print(ans)
| 0 | null | 28,362,278,275,870 | 7 | 203 |
# Nを1位上9以下の2つの整数の積として表せるならYes,できないならNo
N = int(input())
for i in range(1, 9+1):
if N%i == 0 and N//i <= 9:
print('Yes')
exit()
print('No')
|
n = int(input())
ans = 0
flag = 0
for i in range(0, n):
x, y = input().split()
if x == y:
ans = ans + 1
else:
ans = 0
if ans >= 3:
flag = 1
if flag == 1:
print("Yes")
else :
print("No")
| 0 | null | 81,180,651,327,370 | 287 | 72 |
while 1:
x, y =map(int,input().split())
if not x+y:break
if x>y:x,y=y,x
print(x,y)
|
while True:
a= map(int,raw_input().split())
if a[0]==0 and a[1]==0:
break
a.sort()
print a[0],a[1]
| 1 | 514,454,143,672 | null | 43 | 43 |
N=int(input())
a=int(N/100)
b=int((N-100*a)/10)
c=N-100*a-10*b
if a==7 or b==7 or c==7:
print("Yes")
else:
print("No")
|
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
answer = []
for i in range(M):
x, y, c = map(int, input().split())
answer.append(a[x-1]+b[y-1]-c)
print(min(min(answer), min(a)+min(b)))
| 0 | null | 44,223,314,005,180 | 172 | 200 |
N = int(input())
for i in range(1,10):
for j in range(1,10):
temp = i*j
if N == temp:
print("Yes")
exit()
print("No")
|
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)
| 0 | null | 148,862,521,500,472 | 287 | 273 |
N = int(input())
S = input()
ans = ''
for c in S:
i = ord(c) - ord('A')
ans += chr(ord('A') + (i+N)%26)
print(ans)
|
n, a, b = map(int, input().strip().split())
if (b - a) % 2 == 1:
dt1 = a - 1
dt1 += 1
b1 = b - dt1
t1 = dt1 + (b1 - 1) // 2
dt2 = n - b
dt2 += 1
a1 = a + dt2
t2 = dt2 + (n - a1) // 2
print(min(t1, t2))
else:
print((b - a) // 2)
| 0 | null | 122,471,791,425,060 | 271 | 253 |
import math
import sys
H,A = map(int, input().split())
print(math.ceil(H/A))
|
N=int(input())
S="abcdefghijklmnopqrstuvwxyz"
ans=[]
while N>0:
N-=1
ans.append(S[N%26])
N//=26
print(''.join(ans[::-1]))
| 0 | null | 44,654,953,014,740 | 225 | 121 |
from math import*
A,B,H,M = map(int, input().split())
print((A*A+B*B-2*A*B*cos((M*11/360-H/6)*pi))**.5)
|
import math
A, B, H, M = map(int, input().split())
print(math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(abs(30*H + 0.5*M - 6*M)))))
| 1 | 19,990,681,046,908 | null | 144 | 144 |
n, m = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(m)]
ans = -1
for i in range(1000):
s_i = str(i)
if len(s_i) == n and all(int(s_i[s-1])==c for s,c in sc):
ans = i
break
print(ans)
|
import math
N,M,X = map(int,input().split())
#a[i][0]:price of the i-th book
a = [[] for i in range(N)]
for i in range(N):
a[i] = list(map(int,input().split()))
def is_greater(b):
for i in b:
if i < X:
return False
return True
cost = math.inf
for i in range(2**N):
b = [0]*(M+1)
for j in range(N):
if ((i >> j)&1):
for k in range(M+1):
b[k] += a[j][k]
if b[0] < cost and is_greater(b[1:]):
cost = b[0]
if cost == math.inf:
print(-1)
else:
print(cost)
| 0 | null | 41,643,463,152,588 | 208 | 149 |
from itertools import combinations_with_replacement as H
N, M, Q = map(int, input().split())
ans = 0
query = [list(map(int, input().split())) for _ in range(Q)]
for A in H(list(range(1, M+1)), N):
acc = 0
for j in range(Q):
a, b, c, d = query[j]
if A[b - 1] - A[a - 1] == c:
acc += d
ans = max(ans, acc)
print(ans)
|
def mi(): return map(int,input().split())
def lmi(): return list(map(int,input().split()))
def ii(): return int(input())
def isp(): return input().split()
from itertools import combinations_with_replacement
n,m,q=mi()
ll=[i for i in range(1,m+1)]
input_list=[]
for i in range(q):
abcd=lmi()
input_list.append(abcd)
ans=0
la=list(combinations_with_replacement(ll,n))
for i in la:
suma=0
#print(i)
for j in input_list:
a=j[0]
b=j[1]
c=j[2]
d=j[3]
if (i[b-1]-i[a-1])==c:
suma+=d
#print(suma)
ans=max(ans,suma)
print(ans)
| 1 | 27,644,596,173,830 | null | 160 | 160 |
import math
n,D = map(int,input().split())
cnt = 0
for i in range(n):
p,q = map(int,input().split())
d = math.sqrt(p**2 + q ** 2)
if D >= d:
cnt += 1
print(cnt)
|
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
else:
pass
if a < b and b < c:
print('Yes')
else:
print('No')
| 0 | null | 6,435,916,586,748 | 96 | 101 |
n=int(input())
s=input()
if n%2==1:
print("No")
exit()
half=n//2
if s[:half]==s[half:]:
print("Yes")
else:
print("No")
|
n = int( input() )
a = list( map( int, input().split() ) )
cnt = {}
for a_i in a:
try:
cnt[ a_i ]
print( "NO" )
break
except KeyError:
cnt[ a_i ] = 1
else:
print( "YES" )
| 0 | null | 110,679,436,333,358 | 279 | 222 |
n = int(input())
stone = list(input())
l = 0
r = n-1
ans = 0
while l < r:
if stone[l]=='W':
if stone[r]=='R':
ans += 1
l += 1
r -= 1
else:
r -= 1
else:
l += 1
if stone[r]=='W':
r -= 1
print(ans)
|
N = int(input())
words = list(input())
ct_R = words.count('R')
ct_W = words.count('W')
a = words[0:ct_R]
W_in_a_count = a.count('W')
print(W_in_a_count)
| 1 | 6,283,324,895,964 | null | 98 | 98 |
def solve():
N = int(input())
A = list(map(int, input().split()))
ans = 0
p = 1
for a in A:
if a==p:
p += 1
else:
ans += 1
if p==1:
ans = -1
return ans
print(solve())
|
import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
H=I()
ans=0
def f(x):
if x==0:
return 0
return f(x//2)*2 +1
print(f(H))
main()
| 0 | null | 97,731,031,420,682 | 257 | 228 |
def modpow(a,n,m):
res=1
while n>0:
if n&1:res=res*a%m
a=a*a%m
n//=2
return res
class mod_comb_k():
def __init__(self, MAX_N = 10**6, mod = 10**9+7):
self.fact = [1]
self.fact_inv = [0] * (MAX_N + 4)
self.mod = mod
#if MAX_N > mod:print('MAX_N > mod !')
for i in range(MAX_N + 3):
self.fact.append(self.fact[-1] * (i + 1) % self.mod)
self.fact_inv[-1] = pow(self.fact[-1], self.mod - 2, self.mod)
for i in range(MAX_N + 2, -1, -1):
self.fact_inv[i] = self.fact_inv[i + 1] * (i + 1) % self.mod
def comb(self, n, k):
if n < k:
#print('n < k !')
return 0
else:return self.fact[n] * self.fact_inv[k] % self.mod * self.fact_inv[n - k] % self.mod
mod=998244353
c=mod_comb_k(mod=mod)
n,m,k=map(int,input().split())
ans=0
for i in range(k+1):
ans+=modpow(m-1,n-i-1,mod)*c.comb(n-1,i)*m%mod
ans%=mod
print(ans)
|
import sys
sys.setrecursionlimit(1000000000)
from itertools import count
from functools import lru_cache
from collections import defaultdict
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
def meg(f, ok, ng):
while abs(ok-ng)>1:
mid = (ok+ng)//2
if f(mid):
ok=mid
else:
ng=mid
return ok
#
def main():
T1,T2 = mis()
A1,A2 = mis()
B1,B2 = mis()
d1 = T1*A1 - T1*B1
d2 = T2*A2 - T2*B2
if d1 + d2 == 0:
print('infinity')
elif d1 < 0 > d2 or d1 > 0 < d2:
print(0)
else:
if d1 < 0:
d1 *= -1
d2 *= -1
if d1 + d2 > 0:
print(0)
elif d1 % (d1+d2) == 0:
print(d1 // abs(d1+d2) * 2)
else:
print(d1 // abs(d1+d2) * 2 + 1)
main()
| 0 | null | 77,352,444,092,220 | 151 | 269 |
a, b, c, k = map(int,input().split())
if k <= a:
print(k)
elif a < k <= a + b:
print(a)
elif a + b <= k:
print(a*2 - k + b)
|
k =int(input())
seq = '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51'
li = list(map(int,seq.split(', ')))
print(li[k-1])
| 0 | null | 35,782,094,723,760 | 148 | 195 |
#!/usr/bin/env python
def main():
N = int(input())
D = list(map(int, input().split()))
ans = 0
for i in range(N-1):
d1 = D[i]
for d2 in D[i+1:]:
ans += d1 * d2
print(ans)
if __name__ == '__main__':
main()
|
import sys
# input = sys.stdin.readline
def main():
N = int(input())
d = list(map(int,input().split()))
ans = 0
for i in range(N):
for j in range(N):
if i !=j:
ans += d[i]*d[j]
print(int(ans/2))
if __name__ == "__main__":
main()
| 1 | 168,452,845,651,152 | null | 292 | 292 |
n = int( input() )
a = list( map(int, input().split()) )
x = 0
for i in a:
x ^= i
print( * list( map( lambda y: x^y , a ) ) )
|
N = int(input())
A = list(map(int,input().split()))
xor = 0
for i in range(N):
xor ^= A[i]
anslis = []
for i in range(N):
answer = xor^A[i]
anslis.append(answer)
print(' '.join(map(str,anslis)))
| 1 | 12,560,856,272,100 | null | 123 | 123 |
def main():
a = list(map(int, input().split()))
if 500 * a[0] >= a[1]:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
|
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
K, X = map(int, readline().split())
if 500 * K >= X:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main()
| 1 | 97,911,507,678,348 | null | 244 | 244 |
def fib(n):
if n==0 or n==1:
return 1
x=[1,1]
for i in range(2,n+1):
x.append(x[i-1]+x[i-2])
return x[-1]
print(fib(int(input())))
|
def fib2(n):
a1, a2 = 1, 0
while n > 0:
a1, a2 = a1 + a2, a1
n -= 1
return a1
n = int(input())
print(fib2(n))
| 1 | 2,167,302,748 | null | 7 | 7 |
text=input()
n=int(input())
for i in range(n):
order=input().split()
a,b=map(int,order[1:3])
if order[0]=="print":
print(text[a:b+1])
elif order[0]=="reverse":
re_text=text[a:b+1]
text=text[:a]+re_text[::-1]+text[b+1:]
else :
text=text[:a]+order[3]+text[b+1:]
|
import sys
def reverse(str, a, b):
head = str[0:a]
tail = str[b + 1:]
mid = str[a:b + 1]
reversed_str = head + mid[::-1] + tail
return reversed_str
def replace(str, a, b, rstr):
head = str[0:a]
tail = str[b + 1:]
replaced_str = head + rstr + tail
return replaced_str
#fin = open("test.txt", "r")
fin = sys.stdin
str = fin.readline()
q = int(fin.readline())
for i in range(q):
query_list = fin.readline().split()
op = query_list[0]
a = int(query_list[1])
b = int(query_list[2])
if op == "print":
print(str[a:b + 1])
elif op == "reverse":
str = reverse(str, a, b)
else:
str = replace(str, a, b, query_list[3])
| 1 | 2,104,365,029,998 | null | 68 | 68 |
x, y, a, b, c = map(int, input().split())
p = [int(i) for i in input().split()]
q = [int(i) for i in input().split()]
r = [int(i) for i in input().split()]
p = list(reversed(sorted(p)))
q = list(reversed(sorted(q)))
r = list(reversed(sorted(r)))
apple = p[:x] + q[:y] + r
apple = list(reversed(sorted(apple)))
print(sum(apple[:x+y]))
|
X, Y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
p_sum = [0]*(a+1)
q_sum = [0]*(b+1)
for i in range(a):
p_sum[i+1] = p_sum[i] + p[i]
for i in range(b):
q_sum[i+1] = q_sum[i] + q[i]
#print(p_sum)
#print(q_sum)
ans = [0]*(c+1)
ans[0] = p_sum[X] + q_sum[Y]
x, y = X, Y
flag = True
for i in range(c):
if x > 0 and y > 0:
ans[i+1] = max(ans[i]-p[x-1]+r[i], ans[i]-q[y-1]+r[i], ans[i])
if ans[i+1] == ans[i]-p[x-1]+r[i]:
x -= 1
elif ans[i+1] == ans[i]-q[y-1]+r[i]:
y -= 1
elif ans[i+1] == ans[i]:
break
elif x == 0:
ans[i+1] = max(ans[i]-q[y-1]+r[i], ans[i])
if ans[i+1] == ans[i]:
break
else:
y -= 1
elif y == 0:
ans[i+1] = max(ans[i]-p[x-1]+r[i], ans[i])
if ans[i+1] == ans[i]:
break
else:
x -= 1
elif x == 0 and y == 0:
flag = False
if flag:
print(max(ans))
else:
print(sum(r[:x+y-1]))
| 1 | 45,006,817,514,860 | null | 188 | 188 |
while 1 :
a,op,b=raw_input().split()
ai=int(a)
bi=int(b)
if op=='?':break
elif op=='+':print ai+bi
elif op=='-':print ai-bi
elif op=='*':print ai*bi
elif op=='/':print ai/bi
|
while True:
l = input().split()
if l[1] == '?':
break
print(int(eval(l[0]+l[1]+l[2])))
| 1 | 679,262,258,858 | null | 47 | 47 |
while True:
m,f,r=map(int,input().split())
p=m+f
if m+f+r==-3:
break
if m==-1 or f==-1:
print("F")
elif p>=80:
print("A")
elif 65<=p and p<80:
print("B")
elif 50<=p and p<65:
print("C")
elif 30<=p and p<50:
if r>=50:
print("C")
else:
print("D")
else:
print("F")
|
score = []
while True:
(m, f, r) = [int(i) for i in input().split()]
if m == f == r == -1:
break
score.append([m, f, r])
for mc, fc, rc in score:
if mc == -1 or fc == -1:
print('F')
elif mc + fc >= 80:
print('A')
elif mc + fc >= 65:
print('B')
elif mc + fc >= 50 or rc >= 50:
print('C')
elif mc + fc >= 30:
print('D')
else:
print('F')
| 1 | 1,207,583,844,328 | null | 57 | 57 |
import sys
import re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []
def main():
X,K,D = i_map()
if X<=0:
X = -X
tmp1 = X//D
tmp2 = X-(tmp1 * D)
if(tmp1 < K):
if((K-tmp1)%2 == 0):
print(tmp2)
else:
print(D-tmp2)
else:
print(X - K * D)
return
if __name__ == '__main__':
main()
|
from collections import Counter
S = input()
S = S[::-1]
N = len(S)
counter = Counter()
counter[0] = 1
prev = 0
MOD = 2019
for i in range(N):
c = (int(S[i]) * pow(10, i, MOD) )%MOD
prev = (prev+c)%MOD
counter[prev] += 1
ans = 0
for k,v in counter.items():
ans += (v * (v-1))//2
print(ans)
| 0 | null | 18,045,532,693,280 | 92 | 166 |
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 # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
def readInts():
return list(map(int,input().split()))
def main():
a,b = readInts()
print(a - b*2 if a - b*2 >= 0 else 0)
if __name__ == '__main__':
main()
|
n = int(input())
count = 0
room = [int(0) for i in range(4) for j in range(3) for k in range(10)]
while count < n:
x = list(map(lambda k: int(k), input().split(" ")))
room[(x[0]-1)*30+(x[1]-1)*10+(x[2]-1)] += x[3]
count += 1
for i in range(4):
if i != 0:
print("####################")
for j in range(3):
for k in range(10):
print(" %d" % room[30*i+10*j+k], end="")
print("")
| 0 | null | 83,499,059,243,930 | 291 | 55 |
#ABC157E
n = int(input())
s = list(input())
q = int(input())
bits = [[0 for _ in range(n+1)] for _ in range(26)]
sl = []
for alp in s:
alpord = ord(alp) - 97
sl.append(alpord)
#print(bits) #test
#print(sl) #test
#print('クエリ開始') #test
def query(pos):
ret = [0] * 26
p = pos
while p > 0:
for i in range(26):
ret[i] += bits[i][p]
p -= p&(-p)
return ret
def update(pos, a, x):
r = pos
while r <= n:
bits[a][r] += x
r += r&(-r)
for i in range(n):
update(i+1, sl[i], 1)
#print(bits) #test
for _ in range(q):
quer, xx, yy = map(str, input().split())
if quer == '1':
x = int(xx)
y = ord(yy) - 97
if sl[x-1] == y:
continue
else:
update(x, sl[x-1], -1)
update(x, y, 1)
sl[x-1] = y
#print('クエリ1でした') #test
#print(bits) #test
#print(sl) #test
else:
x = int(xx)
y = int(yy)
cnt1 = query(y)
cnt2 = query(x-1)
#print('クエリ2です') #test
#print(cnt1) #test
#print(cnt2) #test
ans = 0
for i in range(26):
if cnt1[i] - cnt2[i] > 0:
ans += 1
print(ans)
|
a,b = input().split()
c = [a*int(b), b*int(a)]
print(sorted(c)[0])
| 0 | null | 73,114,040,218,550 | 210 | 232 |
L = int(input())
r = L / 3
print(r * r * r)
|
l = int(input())
print(l/3 * l/3 * (l - 2*l/3))
| 1 | 47,058,171,083,990 | null | 191 | 191 |
k, y = [int(i) for i in input().split()]
print('Yes' if 500 * k >= y else 'No')
|
def main():
n, k = map(int, input().split())
MOD = 10 ** 9 + 7
ans = 0
cnt = [0] * (k + 1)
for i in range(1, k + 1):
cnt[i] = pow(k // i, n, MOD)
for i in range(k, 0, -1):
for j in range(2, k // i + 1):
cnt[i] -= cnt[i * j]
ans = 0
for i, c in enumerate(cnt):
ans += i * c
ans %= MOD
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 67,577,826,340,074 | 244 | 176 |
#!/usr/bin/env python3
S = input()
total = 0
for i in range(len(S)):
if "R" * (i + 1) in S:
total = i + 1
ans = total
print(ans)
|
import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
s = str(readline().rstrip().decode('utf-8'))
if s == "RRR":
print(3)
elif s == "RRS" or s == "SRR":
print(2)
elif s.count("R") == 0:
print(0)
else:
print(1)
if __name__ == '__main__':
solve()
| 1 | 4,895,905,072,258 | null | 90 | 90 |
x = int(input())
sosu = [int(i) for i in range(2*x)]
sosu[1] = 0
for i in range(2,x):
if sosu[i]!=0:
j = 2
while i * j < 2*x:
sosu[i*j]=0
j += 1
#print(sosu[x])
while sosu[x]==0:
x += 1
print(x)
|
# -*- coding: utf-8 -*-
n = int(raw_input())
dic = set()
for i in range(n):
com, s = map(str, raw_input().split())
if com == "insert":
dic.add(s)
elif com == "find":
if s in dic:
print "yes"
else:
print "no"
| 0 | null | 52,543,391,521,010 | 250 | 23 |
n,m = map(int,input().split())
dic = {}
ac = 0
wa = 0
for _ in range(m):
p,s = map(str,input().split())
p = int(p)
if p not in dic:
if s =='AC':
ac += 1
dic[p] = s
else:
dic[p] = 1
elif dic[p]=='AC':
continue
else:
if s =='AC':
ac += 1
wa +=dic[p]
dic[p] = s
else:
dic[p] += 1
print(str(ac) + ' ' + str(wa))
|
N,M= map(int, input().split())
p = [0] * M
S = [0] * M
for i in range(M):
p[i], S[i] = map(str, input().split())
AC_list=[0]*N
pena=[0]*N
for i in range(M):
if S[i]=='AC':
AC_list[int(p[i])-1]+=1
else:
if AC_list[int(p[i])-1]==0:
pena[int(p[i])-1]+=1
num=0
num1=0
for i in range(N):
if AC_list[i]!=0:
num+=1
num1+=pena[i]
print(num ,num1)
| 1 | 93,837,867,488,190 | null | 240 | 240 |
import sys
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
n, m=ISI()
if(n==m):print("Yes")
else:print("No")
|
from collections import deque
s = list(input())
queue = deque(s)
q = int(input())
rev_count = 0
for i in range(q):
query = list(input().split(" "))
if len(query) == 1:
rev_count += 1
else:
if query[1] == "1":
if rev_count % 2==0:
queue.appendleft(query[2])
else:
queue.append(query[2])
else:
if rev_count % 2==0:
queue.append(query[2])
else:
queue.appendleft(query[2])
queue = "".join(list(queue))
if rev_count % 2 == 0:
print(queue)
else:
print(queue[::-1])
| 0 | null | 70,149,032,365,022 | 231 | 204 |
import math
from functools import reduce
n, m = input().split()
a = list(map(int, input().split()))
b =[0]*int(n)
for i in range(len(a)):
b[i] = a[i]//2
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
c = 0
x = lcm_list(b)
for i in range(int(n)):
if (x // b[i]) % 2 == 0:
c = -1
break
else:
continue
if c == -1:
print(0)
else:
print(math.floor(((int(m)/x)+1)/2))
|
# coding:utf-8
n = int(input())
count = 0
for i in range(n):
d1, d2 = map(int, input().split())
if d1 == d2:
count += 1
else:
count = 0
if count == 3:
print('Yes')
exit()
print('No')
| 0 | null | 52,276,093,993,002 | 247 | 72 |
N,M = map(int,(input().split()))
s = list(input())
s.reverse()
now = 0
me = []
flag = 0
while now != N:
for i in range(1,M+1,)[::-1]:
if now + i <= N and s[now+i] == "0":
now += i
me.append(i)
break
else:
print(-1)
flag = 1
break
if flag == 0:
me.reverse()
print(*me)
|
n,m=map(int,input().split())
s=input()[::-1]
i=0
ans=[]
while i<n:
for j in range(min(n-i,m),0,-1):
if s[i+j]=="0":
ans.append(j)
i+=j
break
if j==1:print(-1);exit()
print(*ans[::-1])
| 1 | 139,477,314,296,070 | null | 274 | 274 |
#from collections import defaultdict, deque
#import itertools
#import numpy as np
#import re
import bisect
def main():
N = int(input())
SS = []
for _ in range(N):
SS.append(input())
S = []
for s in SS:
while '()' in s:
s = s.replace('()', '')
S.append(s)
#print(S)
S = [s for s in S if s != '']
sum_op = 0
sum_cl = 0
S_both_op = []
S_both_cl = []
for s in S:
if not ')' in s:
sum_op += len(s)
elif not '(' in s:
sum_cl += len(s)
else:
pos = s.find('(')
if pos <= len(s) - pos:
S_both_op.append((pos, len(s)-pos)) #closeのほうが少ない、'))((('など -> (2,3)
else:
S_both_cl.append((pos, len(s)-pos)) #closeのほうが多い、')))(('など -> (3,2)
# S_both_opは、耐えられる中でより伸ばす順にしたほうがいい?
#S_both_op.sort(key=lambda x: (x[0], x[0]-x[1])) #closeの数が小さい順にsortかつclose-openが小さい=伸ばす側にsort
#S_both_cl.sort(key=lambda x: (x[0], x[0]-x[1])) #これもcloseの数が小さい順にsortかつclose-openが小さい=あまり縮まない順にsort
S_both_op.sort(key=lambda x: x[0])
S_both_cl.sort(key=lambda x: -x[1])
for p in S_both_op:
sum_op -= p[0]
if(sum_op < 0 ):
print('No')
exit()
sum_op += p[1]
for p in S_both_cl:
sum_op -= p[0]
if(sum_op < 0 ):
print('No')
exit()
sum_op += p[1]
if sum_op == sum_cl:
print('Yes')
else:
print('No')
if __name__ == "__main__":
main()
|
num=int(input())
r_1=int(input())
r_2=int(input())
max_profit=r_2-r_1
if r_1<r_2:
min_value=r_1
else:
min_value=r_2
for i in range(2,num):
x=int(input())
t=x-min_value
if max_profit<t:
max_profit=t
if x<min_value:
min_value=x
print(max_profit)
| 0 | null | 11,757,320,404,180 | 152 | 13 |
a,b=map(int,input().split())
if a-2*b>=0:
print(a-2*b)
else:
print("0")
|
# 159 ########## dbt
n, m = map(int, input().split())
def factorial(a):
p = 1
for i in range(a, 0 , -1):
p *= i
return p
def combo(b, num):
ans = factorial(b) // (factorial(num) * factorial(b - num))
return ans
print(combo(n, 2) + combo(m, 2))
| 0 | null | 105,955,898,727,812 | 291 | 189 |
import math
a,b,c,d=map(int,input().split())
x=math.ceil(c/b)
y=math.ceil(a/d)
print("Yes" if y>=x else "No")
|
n = int(input())
x = list(map(int, input().split()))
result = 0
for i in range(n - 1):
if x[i] > x[i + 1]:
result += (x[i] - x[i + 1])
x[i + 1] = x[i]
print(result)
| 0 | null | 17,112,697,680,298 | 164 | 88 |
X=int(input())
ans=100
count=0
while ans<X:
ans=ans+(ans//100)
count+=1
print(count)
|
x,y=map(int,input().split())
print(str(min(x,y))*max(x,y))
| 0 | null | 55,445,586,737,290 | 159 | 232 |
thp, tak, ahp, aak = map(int, input().split())
judge = 0
while thp > 0 and ahp > 0:
if judge == 0:
ahp -= tak
judge = 1
else:
thp -= aak
judge = 0
if thp <= 0:
print("No")
else:
print("Yes")
|
a, b, c, d = map(int, input().split(" "))
while True:
c -= b
if c <= 0:
print("Yes")
break
a -= d
if a <= 0:
print("No")
break
| 1 | 29,692,529,189,520 | null | 164 | 164 |
N = int(input())
A = input().split()
num_list = [0] * 10**5
ans = 0
for i in range(N):
num_list[int(A[i])-1] += 1
for i in range(10**5):
ans += (i+1) * num_list[i]
Q = int(input())
for i in range(Q):
B, C = map(int, input().split())
ans = ans + C * num_list[B-1] - B * num_list[B-1]
num_list[C-1] += num_list[B-1]
num_list[B-1] = 0
print(ans)
|
n,k,s=map(int,input().split())
a=[s]*k
b=[3]*(n-k)+[s]*k
p=max(s//2-1,1)
for i in range(n-k):
if i%p==0:
a.append(s-1)
else:
a.append(2)
if s!=2 and s!=1:
print(*a)
else:
print(*b)
| 0 | null | 51,404,782,210,844 | 122 | 238 |
import collections, copy
h, w = map(int, input().split())
maze = []
maze.append("#" * (w + 2))
for i in range(h):
maze.append("#" + input() + "#")
maze.append("#" * (w + 2))
dis = []
for i in range(h + 2):
temp = [-1] * (w + 2)
dis.append(temp)
def search(x, y):
dis2 = copy.deepcopy(dis)
move = [[-1, 0], [1, 0], [0, 1], [0, -1]]
queue = collections.deque([[x, y]])
dis2[x][y] = 0
while queue:
test = queue.popleft()
for i in move:
place = [test[0] + i[0], test[1] + i[1]]
if maze[place[0]][place[1]] == ".":
if dis2[place[0]][place[1]] == -1:
dis2[place[0]][place[1]] = dis2[test[0]][test[1]] + 1
queue.append(place)
return max([max([dis2[i][j] for j in range(w + 2)]) for i in range(h + 2)])
ans = 0
for i in range(h):
for j in range(w):
if maze[i + 1][j + 1] == ".":
dist = search(i + 1, j + 1)
ans = max(ans, dist)
print(ans)
|
from collections import deque
def getdistance(row,col,sw,h,w):
maze = deque([[row,col,0]])
marker = [[0]*w for _ in range(h)]
marker[row][col] = 1
while len(maze)!=0:
r, c, d = maze.popleft()
if r!=0:
if sw[r-1][c]!="#" and marker[r-1][c] != 1:
marker[r-1][c] = 1
maze.append([r-1,c,d+1])
if r!=h-1:
if sw[r+1][c]!="#" and marker[r+1][c] != 1:
marker[r+1][c] = 1
maze.append([r+1,c,d+1])
if c!=w-1:
if sw[r][c+1]!="#" and marker[r][c+1] != 1:
marker[r][c+1] = 1
maze.append([r,c+1,d+1])
if c!=0:
if sw[r][c-1]!="#" and marker[r][c-1] != 1:
marker[r][c-1] = 1
maze.append([r,c-1,d+1])
return d
h, w = map(int, input().split())
sw = [input() for _ in range(h)]
ans = 0
for row in range(h):
for col in range(w):
if sw[row][col]=="#":
continue
ans = max(ans,getdistance(row,col,sw,h,w))
print(ans)
| 1 | 94,726,607,045,698 | null | 241 | 241 |
def main():
n, m = map(int, input().split())
a_lst = list(map(int, input().split()))
total = sum(a_lst)
if total > n:
ans = -1
else:
ans = n - total
print(ans)
if __name__ == "__main__":
main()
|
import sys
N,M = map(int,input().split())
array = list(map(int,input().split()))
if not ( 1 <= N <= 10 ** 6 and 1 <= M <= 10 ** 4 ): sys.exit()
if not ( 1 <= min(array) and max(array) <= 10 ** 4 ): sys.exit()
ans = N - sum(array)
print(ans) if ans >= 0 else print(-1)
| 1 | 31,827,290,295,652 | null | 168 | 168 |
S = input()
if(S.endswith('s')):
print(S+'es')
else:
print(S+'s')
|
s = input()
ans = s
if s[-1] == "s":
ans += "e"
print(ans+"s")
| 1 | 2,370,658,821,062 | null | 71 | 71 |
cnt = 0
zorome = 0
num = int(input())
while cnt < num:
mass = input().split()
if(mass[0] == mass[1]):
zorome += 1
if(zorome >= 3):
break
else:
zorome = 0
cnt += 1
print("Yes" if zorome >= 3 else "No")
|
import math
a,b,c = map(float,input().split())
H = b * math.sin(math.radians(c))
S = (a*(b*math.sin(math.radians(c))))/2
L = a + b + ((a**2) + (b**2) -(((2*a)*b)*math.cos(math.radians(c))))**0.5
print(float(S))
print(float(L))
print(float(H))
| 0 | null | 1,325,006,282,340 | 72 | 30 |
K = int(input())
S = input()
s = len(S)
L = []
mod = 10 ** 9 + 7
N = 2 * 10**6
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
def cmb(n, r):
return fac[n] * ( finv[r] * finv[n-r] % mod ) % mod
for i in range(2, N + 1):
fac.append( ( fac[-1] * i ) % mod )
inv.append( mod - ( inv[mod % i] * (mod // i) % mod ) )
finv.append( finv[-1] * inv[-1] % mod )
for i in range(K+1):
L.append( cmb(i+s-1, s-1) * pow(25, i, mod) % mod )
ans = []
for i, x in enumerate(L):
if i == 0:
ans.append(x)
else:
ans.append( ( ans[i-1]*26%mod + x ) % mod )
print(ans[K])
|
import os, sys, re, math
(A, B) = [int(n) for n in input().split()]
print(max(A - B * 2, 0))
| 0 | null | 89,474,819,062,212 | 124 | 291 |
n, m = map(int, input().split())
num = [''] * n
flag = 0
for i in range(m):
s, c = map(int, input().split())
if num[s - 1] == '' or num[s - 1] == c:
num[s - 1] = c
else:
print(-1)
break
else:
if num[0] == '':
if n > 1:
num[0] = 1
else:
num[0] = 0
for i in range(1, n):
if num[i] == '':
num[i] = 0
if n > 1 and num[0] == 0:
print(-1)
else:
print(''.join(map(str, num)))
|
#!/usr/bin python3
# -*- coding: utf-8 -*-
from bisect import bisect_left, bisect_right
n = int(input())
s = list(input())
q = int(input())
al = 'abcdefghijklmnopqrstuvwxyz'
dicq = {i:[] for i in al}
for i, si in enumerate(s):
dicq[si].append(i)
def q1(iq, cq):
#print(iq,cq,s[iq],dicq[s[iq]],bisect_left(dicq[s[iq]], iq))
dicq[s[iq]].pop(bisect_left(dicq[s[iq]], iq)) #更新前から削除
s[iq] = cq
dicq[cq].insert(bisect_left(dicq[cq], iq), iq) #更新後に追加
def q2(l, r):
ret = 0
for ai in al:
if len(dicq[ai])==0: continue
li = bisect_left(dicq[ai], l)
ri = bisect_right(dicq[ai], r)
if li != ri:
ret += 1
elif li == len(dicq[ai]): continue
elif dicq[ai][li] == l:
ret += 1
# print(l,r,ai,dicq[ai],li,ri,ret)
print(ret)
for i in range(q):
fg, x, y = input().split()
if fg == '1':
q1(int(x)-1, y)
else:
q2(int(x)-1, int(y)-1)
| 0 | null | 61,876,290,086,208 | 208 | 210 |
a = str(input().split())
b = list(a)
if b[4] == b[5] and b[7] == b[6]:
print("Yes")
else :
print("No")
|
a = list(str(input()))
if(a[2] == a[3] and a[4] == a[5]):
print("Yes")
else:
print("No")
| 1 | 41,962,663,100,348 | null | 184 | 184 |
def resolve():
N, A, B = [int(i) for i in input().split()]
if (B - A) % 2 == 0:
print((B - A) // 2)
else:
print(min(A, N - B + 1) + ((B - A) // 2))
resolve()
|
from collections import deque
N, M, Q = map(int, input().split())
I = [list(map(int, input().split())) for _ in range(Q)]
que = deque()
ans = 0
for i in range(1, M+1):
que.append([i])
while que:
seq = que.popleft()
if len(seq) == N:
p = 0
for i in range(Q):
if seq[I[i][1]-1] - seq[I[i][0]-1] == I[i][2]:
p += I[i][3]
ans = max(ans, p)
else:
for i in range(seq[-1], M+1):
seq_next = seq + [i]
que.append(seq_next)
print(ans)
| 0 | null | 68,525,905,393,568 | 253 | 160 |
import numpy as np
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
F = sorted(list(map(int, input().split())), reverse=True)
A = np.array(A, np.int64)
F = np.array(F, np.int64)
Asum = sum(A)
def test(X):
return (Asum - np.minimum(A, X//F).sum() <= K)
l = -1
r = 10**12
while (l + 1 < r):
mid = (l + r) // 2
if test(mid):
r = mid
else:
l = mid
ans = r
print(ans)
|
A = str(input())
B = str(input())
c = 0
lenA = len(A)
for i in range(lenA):
if A[i] != B[i]:
c += 1
print(c)
| 0 | null | 87,392,624,775,128 | 290 | 116 |
n=int(input())
dic={}
a=[]
b=[]
for i in range(n):
tmp1,tmp2=input().split()
a.append(tmp1)
b.append(tmp2)
for i in range(n):
if a[i]=='insert':
dic[b[i]]=1
else:
if b[i] in dic:
print("yes")
else:
print("no")
|
import math
A, B = map(int,input().split())
LA = []
LB = []
X = math.ceil(A / 0.08)
Y = math.ceil(B / 0.1)
N = int((A+1) // 0.08)
M = int((B+1) // 0.1)
for i in range(X, N+1):
LA.append(i)
for i in range(Y, M+1):
LB.append(i)
ans = set(LA) & set(LB)
ans_list = list(ans)
if not ans_list:
print(-1)
else:
print(min(ans_list))
| 0 | null | 28,196,673,586,000 | 23 | 203 |
s=list(input())
t=list(input())
x=0
for i in range(len(s)):
if s[i]!=t[i]:
x+=1
else:
pass
print(x)
|
s = str(input())
t = str(input())
num = 0
for i in range(len(s)):
if s[i] != t[i]:
num += 1
print(num)
| 1 | 10,536,970,148,198 | null | 116 | 116 |
'''
Created on 2020/09/10
@author: harurun
'''
def main():
import sys
pin=sys.stdin.readline
pout=sys.stdout.write
perr=sys.stderr.write
N,M=map(int,pin().split())
if N==3:
ans=[1,0,0]
for _ in [0]*M:
s,c=map(int,pin().split())
if s==1 and c==0:
print(-1)
return
if s!=1 and ans[s-1]!=0 and ans[s-1]!=c:
print(-1)
return
ans[s-1]=c
a=""
for i in ans:
a+=str(i)
print(a)
return
elif N==2:
ans=[1,0]
for _ in [0]*M:
s,c=map(int,pin().split())
if s==1 and c==0:
print(-1)
return
if s!=1 and ans[s-1]!=0 and ans[s-1]!=c:
print(-1)
return
ans[s-1]=c
a=""
for i in ans:
a+=str(i)
print(a)
return
else:
if M==0:
print(0)
return
s,c=map(int,pin().split())
ans=c
for j in range(M-1):
s,c=map(int,pin().split())
if c!=ans:
print(-1)
return
print(ans)
return
main()
|
if __name__ == '__main__':
N, M = map(int, input().split())
S = []
C = []
for i in range(M):
s, c = map(int, input().split())
s -= 1
S.append(s)
C.append(c)
for num in range(0, pow(10, N)):
st_num = str(num)
if len(str(st_num))!=N: continue
cnt = 0
for m in range(M):
if int(st_num[S[m]])==C[m]:
cnt += 1
if cnt==M:
print(st_num)
quit()
print(-1)
| 1 | 60,789,394,849,472 | null | 208 | 208 |
# 1???????????? W ??¨?????? T ,T ??????????????? W ?????°???????????????????????°??????
import sys
# ??????W?????????
w = input()
# ??????T?????????
t = []
# ??????T?????????
while 1:
temp = input()
if temp == "END_OF_TEXT":
break
t += temp.strip(".")
t += " "
# ??????????????????
t = "".join(t).split()
# print(t)
# ??????T???????????¨????????????W????????????????????????
count = 0
for i in range(len(t)):
if t[i].lower() == w:
count += 1
print(count)
|
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
def main():
n, p = map(int, input().split())
s = list(input())
if 10 % p == 0:
ans = 0
for i in range(n):
if (ord(s[i])-ord('0')) % p == 0:
ans += i+1
print(ans)
return
d = [0] * (n+1)
ten = 1
for i in reversed(range(n)):
a = (ord(s[i])-ord('0')) * ten % p
d[i] = (d[i+1]+a) % p
ten *= 10
ten %= p
cnt = [0] * p
ans = 0
for i in reversed(range(n+1)):
ans += cnt[d[i]]
cnt[d[i]] += 1
print(ans)
main()
| 0 | null | 30,182,587,518,410 | 65 | 205 |
import sys
R, C, K = map(int, input().split())
item = [[0] * (C + 1) for _ in range(R + 1)] # dp配列と合わせるために, 0行目, 0列目を追加している.
for s in sys.stdin.readlines():
r, c, v = map(int, s.split())
item[r][c] = v
dp = [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)]
for i in range(R + 1):
for j in range(C + 1):
for k in range(4):
here = dp[k][i][j]
# 次の行に移動する場合
if i + 1 <= R:
# 移動先のアイテムを取らない場合
dp[0][i + 1][j] = max(dp[0][i + 1][j], here)
# 移動先のアイテムを取る場合
dp[1][i + 1][j] = max(dp[1][i + 1][j], here + item[i + 1][j])
# 次の列に移動する場合
if j + 1 <= C:
# 移動先のアイテムを取らない場合
dp[k][i][j + 1] = max(dp[k][i][j + 1], here)
# 現在のkが3未満のときのみ, 移動先のアイテムを取ることが可能
if k < 3:
dp[k + 1][i][j + 1] = max(dp[k + 1][i][j + 1], here + item[i][j + 1])
ans = 0
for k in range(4):
ans = max(ans, dp[k][-1][-1])
print(ans)
|
import numpy as np
from numba import njit, prange
#'''
N, K = map(int, input().split())
As = list(map(int, input().split()))
'''
N = 200000
K = 100000
As = [0] * N
#'''
@njit("i8[:](i8[:],)", cache = True)
def update(A_array):
before_csum = np.zeros(N+1, np.int64)
for i, A in enumerate(A_array[:N]):
before_csum[max(0, i-A)] += 1
before_csum[min(N, i+A+1)] -= 1
return np.cumsum(before_csum)
A_array = np.array(As + [0], dtype = np.int64)
for k in range(min(K, 50)):
A_array = update(A_array)
print(*A_array.tolist()[:N])
| 0 | null | 10,514,553,237,248 | 94 | 132 |
n = input()
if n[0]=="7":
print("Yes")
exit()
if n[1]=="7":
print("Yes")
exit()
if n[2]=="7":
print("Yes")
exit()
print("No")
|
N = list(input())
for i in N:
if i == "7":
print("Yes")
exit()
print("No")
| 1 | 34,147,774,576,000 | null | 172 | 172 |
'''
INPUT SHORTCUTS
N, K = map(int,input().split())
N ,A,B = map(int,input().split())
string = str(input())
arr = list(map(int,input().split()))
N = int(input())
'''
n , m = map(int,input().split())
if n>=10:
print(m)
else:
m = m + (100*(10-n))
print(m)
|
import itertools
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
d = list(itertools.permutations(range(1, n + 1)))
d.sort()
a = -1
b = -1
for i in range(len(d)):
if d[i] == p:
a = i
if d[i] == q:
b = i
print(abs(a - b))
| 0 | null | 82,232,126,300,938 | 211 | 246 |
def main():
N = int(input())
ans = 0
if N == 2:
print(2)
return
while True:
flg = True
for i in range(2, ((N + 1) // 2) + 1):
if N % i == 0:
flg = False
break
if flg:
break
else:
N += 1
print(N)
if __name__ == '__main__':
main()
|
X=int(input())
ans=0
for i in range(X,10**5+100):
cond=True
for j in range(2,int(i**0.5)+1):
if i%j==0:
cond=False
break
if cond:
ans=i
break
print(ans)
| 1 | 105,486,188,505,020 | null | 250 | 250 |
# -*- coding: utf-8 -*-
moji=[]
moji.append("eraser")
moji.append("erase")
moji.append("dreamer")
moji.append("dream")
user = "erasedream"
user = int(input())
result = user
count = 1
while result != 0:
result += user
result %= 360
count += 1
print(count,end="")
|
from math import gcd;print(360//gcd(int(input()),360))
| 1 | 13,138,321,205,338 | null | 125 | 125 |
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
from collections import deque
import bisect
n, k = map(int, readline().split())
a = list(map(int, readline().split()))
a.sort()
que = deque()
if n == k:
que.extend(a)
elif a[-1] < 0 and k % 2 == 1:
que.extend(a)
for _ in range(n - k):
que.popleft()
else:
b = [[] for _ in range(n)]
for i in range(n):
b[i] = [abs(a[i]), a[i]]
b.sort(reverse=True)
b = deque(b)
que1 = deque()
que2 = deque()
sign = 1
for i in range(k):
val_abs, val = b.popleft()
if val > 0:
que1.append(val_abs)
elif val < 0:
que2.append(val_abs)
sign *= -1
else:
print(0)
return
if sign == -1:
add1, add2 = 0, 0
rmv1, rmv2 = 10 ** 19, 10 ** 19
if que1:
rmv1 = que1[-1]
for x_abs, x in b:
if x < 0:
add1 = x_abs
break
if que2:
rmv2 = que2[-1]
for x_abs, x in b:
if x > 0:
add2 = x_abs
break
if add1 == add2:
print(0)
return
if add1 * rmv2 > add2 * rmv1:
que2.append(add1)
que1.pop()
else:
que1.append(add2)
que2.pop()
que.extend(que1)
que.extend(que2)
while len(que) > 1:
que.append(que.popleft() * que.popleft())
print(que.popleft() % MOD)
if __name__ == '__main__':
main()
|
import functools
def sign(x):
if x>0:
return 1
elif x==0:
return 0
else:
return -1
def multiply(x,y):
ans = x*y
if ans>=10**9+7 or ans<0:
ans %= (10**9+7)
return ans
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
if (A[-1]<0 and K%2==1):
combi = A[-K:]
if K >1:
answer = functools.reduce(multiply,combi)
elif K == N:
answer = functools.reduce(multiply,A)
else:
signs = 1
i,j = 0,0
for _ in range(K):
if abs(A[i]) > abs(A[N-j-1]):
signs *= sign(A[i])
i += 1
else:
signs *= sign(A[N-j-1])
j += 1
combi = A[N-j:] + A[:i]
del A[N-j:]
del A[:i]
combi = combi[::-1]
if signs == -1:
if A:
if combi[-1]<0:
del combi[0]
combi.append(A[-1])
elif A[0]>=0:
del combi[0]
combi.append(A[-1])
elif A[0]<0 and A[-1] >0:
if combi[0]*A[0] > combi[-1]*A[-1]:
del combi[-1]
combi.insert(0,A[0])
else:
del combi[0]
combi.append(A[-1])
elif A[-1] <= 0:
del combi[-1]
combi.insert(0,A[0])
answer = functools.reduce(multiply,combi)
print(answer)
| 1 | 9,432,179,946,112 | null | 112 | 112 |
N = int(input())
As = list(map(int, input().split()))
P = 10**9 + 7
rlt = 0
pw = 1
for i in range(61):
c0 = 0
c1 = 0
for j in range(N):
a = As[j]
if a % 2 == 0:
c0 += 1
else:
c1 += 1
As[j] = a//2
rlt += c0*c1*pw % P
rlt %= P
pw *= 2
print(rlt)
|
import sys
from io import StringIO
import unittest
import os
from operator import ixor
# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)
# 実装を行う関数
def resolve(test_def_name=""):
# 数値取得サンプル
# 1行1項目 n = int(input())
# 1行2項目 x, y = map(int, input().split())
# 1行N項目 x = [list(map(int, input().split()))]
# N行1項目 x = [int(input()) for i in range(n)]
# N行N項目 x = [list(map(int, input().split())) for i in range(n)]
# 文字取得サンプル
# 1行1項目 x = input()
# 1行1項目(1文字ずつリストに入れる場合) x = list(input())
n = int(input())
a_s = list(map(int, input().split()))
one_counts = [0 for i in range(61)]
zero_counts = [0 for i in range(61)]
# 以下、XORで便利と思われる処理。
# -------------------------------------------
# ループ回数の取得(最大の数値の桁数分、ループ処理を行うようにする)
max_num = max(a_s)
max_loop = 0
for i in range(0, 61):
if max_num < 1 << i:
break
max_loop += 1
# ループ処理にて、各桁の0と1の個数を数え上げる。
# 例:入力[1(01),2(10),3(11)] -> one_count=[2,2,0・・]とzero_counts[1,1,0・・]を得る。
for a in a_s:
for i in range(0, max_loop):
if a & 1 << i:
one_counts[i] += 1
else:
zero_counts[i] += 1
# -------------------------------------------
# 以上、XORで便利と思われる処理。
# 結果を計算する処理
ans = 0
for i in range(0, max_loop):
# 各桁の「0の個数」*「1の個数」*2^(0~桁数-1乗まで) を加算していく
ans += (one_counts[i] * zero_counts[i] * pow(2, i)) % (pow(10, 9) + 7)
ans = ans % (pow(10, 9) + 7)
# 結果を出力
print(ans)
# テストクラス
class TestClass(unittest.TestCase):
def assertIO(self, assert_input, output):
stdout, sat_in = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
resolve(sys._getframe().f_back.f_code.co_name)
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, sat_in
self.assertEqual(out, output)
def test_input_1(self):
test_input = """3
1 2 3"""
output = """6"""
self.assertIO(test_input, output)
def test_input_2(self):
test_input = """10
3 1 4 1 5 9 2 6 5 3"""
output = """237"""
self.assertIO(test_input, output)
def test_input_3(self):
test_input = """10
3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820"""
output = """103715602"""
self.assertIO(test_input, output)
# 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
def tes_t_1original_1(self):
test_input = """データ"""
output = """データ"""
self.assertIO(test_input, output)
# 実装orテストの呼び出し
if __name__ == "__main__":
if os.environ.get("USERNAME") is None:
# AtCoder提出時の場合
resolve()
else:
# 自PCの場合
unittest.main()
| 1 | 122,955,816,061,690 | null | 263 | 263 |
from collections import defaultdict
n=int(input())
d=list(map(int,input().split()))
mod=998244353
if d[0]!=0:
print(0)
exit()
dd=defaultdict(lambda:0)
for di in d:
dd[di]+=1
if dd[0]>1:
print(0)
exit()
ans=1
for i in set(dd.keys()):
if i==0:
continue
ans*=(dd[i-1]**dd[i])%mod
print(ans%mod)
|
while(True):
num = input()
if num == '0':
break
x = 0
for i in num:
x += int(i)
print(x)
| 0 | null | 78,335,157,951,250 | 284 | 62 |
n = int(input())
l = list(map(int, input().split()))
ans = 0
for i in range(n):
for ii in range(i+1, n):
ans += l[i]*l[ii]
print(ans)
|
x1,y1,x2,y2=map(float,input().split())
print('{0:.6f}'.format(((x1-x2)**2 + (y1-y2)**2 )**(.5)))
| 0 | null | 83,983,039,370,076 | 292 | 29 |
def comb(n,r,m):
if 2*r > n:
r = n - r
nume,deno = 1,1
for i in range(1,r+1):
nume *= (n-i+1)
nume %= m
deno *= i
deno %= m
return (nume * pow(deno,m-2,m)) % m
def main():
N,M,K = map(int,input().split())
mod = 998244353
ans,comb_r = pow(M-1,N-1,mod),1
for r in range(1,K+1):
comb_r = (comb_r * (N-r) * pow(r,mod-2,mod)) % mod
ans = (ans + comb_r * pow(M-1,N-r-1,mod)) % mod
ans = (ans * M) % mod
print(ans)
if __name__ == "__main__":
main()
|
count = 1
while True:
x = int(input())
if x == 0:
break
print('Case %d: %d' % (count, x))
count += 1
| 0 | null | 11,872,132,323,648 | 151 | 42 |
a,b,c=sorted(list(map(int, input().split())))
print("Yes" if (a==b and b!=c) or (a!=b and b==c) else "No")
|
def merge(A, left, mid, right):
global count
n1 = mid - left
n2 = right - mid
L=[]
R=[]
# for i in range(n1):
# L.append(A[left + i])
# for i in range(n2):
# R.append(A[mid + i])
L=A[left:mid]
R=A[mid:right]
L.append(10e10)
R.append(10e10)
i = 0
j = 0
for k in range(left , right):
count +=1
if L[i] <= R[j]:
A[k] = L[i]
i = i + 1
else:
A[k] = R[j]
j = j + 1
def mergeSort(A, left, right):
if left+1 < right:
mid = (left + right)//2
mergeSort(A, left, mid)
mergeSort(A, mid, right)
merge(A, left, mid, right)
n = int(input())
A = list(map(int, input().split()))
count = 0
mergeSort(A, 0, n)
print(*A)
print(count)
| 0 | null | 34,038,164,059,960 | 216 | 26 |
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
import copy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)
def lcm(a, b): return a * b / gcd(a, b)
# 1 2 3
# a, b, c = LI()
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# a = I()
def I(): return int(sys.stdin.buffer.readline())
# abc def
# a, b = LS()
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# a = S()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# 2
# 1
# 2
# [1, 2]
def IR(n): return [I() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]
def LIR(n): return [LI() for i in range(n)]
# 2
# abc
# def
# [abc, def]
def SR(n): return [S() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]
def LSR(n): return [LS() for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]
def SRL(n): return [list(S()) for i in range(n)]
n, a, b = map(int, input().split())
MOD = 10**9+7
def comb(n, r):
p, q = 1, 1
for i in range(r):
p = p * (n-i) % MOD
q = q * (i+1) % MOD
return p * pow(q, MOD-2, MOD) % MOD
ans = (pow(2, n, MOD)-1) % MOD
ans = (ans+MOD-comb(n, a)) % MOD
ans = (ans+MOD-comb(n, b)) % MOD
print(ans)
|
def solve():
n, k = map(int, input().split())
h = list(map(int, input().split()))
ans = 0
for i in h:
if i >= k:
ans += 1
print(ans)
return 0
if __name__ == "__main__":
solve()
| 0 | null | 123,089,814,402,240 | 214 | 298 |
ri = lambda S: [int(v) for v in S.split()]
N, A, B = ri(input())
q, r = divmod(N, A+B)
blue = (A * q) + r if r <= A else (A * q) + A
print(blue)
|
n, a, b = map(int, input().split())
div, mod = divmod(n, a + b)
print(div * a + min(a, mod))
| 1 | 55,507,061,832,392 | null | 202 | 202 |
def resolve():
N, M, X = list(map(int, input().split()))
C = []
A = []
for i in range(N):
ins = list(map(int, input().split()))
C.append(ins[0])
A.append(ins[1:])
minprice = float("inf")
for bits in range(1<<N):
comps = [0 for _ in range(M)]
price = 0
for odr in range(N):
if (bits & (1<<odr)):
price += C[odr]
for i in range(M):
comps[i] += A[odr][i]
for i in range(M):
if comps[i] < X:
break
else:
minprice = min(minprice, price)
print(minprice if minprice < float("inf") else -1)
if '__main__' == __name__:
resolve()
|
from itertools import product
[N, M, X] = [int(i) for i in input().split()]
bk = [[int(i) for i in input().split()] for _ in range(N)]
ans = 12*10**5 + 1
for seq in product(range(2), repeat=N):
S = [0]*(M+1)
for i in range(N):
for j in range(M+1):
S[j] += seq[i]*bk[i][j]
if min(S[1:M+1]) >= X:
ans = min(ans, S[0])
if ans == 12*10**5 + 1:
print(-1)
else:
print(ans)
| 1 | 22,095,724,247,040 | null | 149 | 149 |
n=int(input())
arr=[input() for _ in range(n)]
dic={}
for i in range(n): #各単語の出現回数を数える
if arr[i] not in dic:
dic[arr[i]]=1
else:
dic[arr[i]]+=1
largest=max(dic.values()) #最大の出現回数を求める
ans=[]
for keys in dic.keys():
if dic[keys]==largest: #出現回数が最も多い単語を集計する
ans.append(keys)
ans=sorted(ans) #単語を辞書順に並べ替えて出力する
for words in ans:
print(words)
|
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 | 70,024,973,607,862 | null | 218 | 218 |
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
At = [0]*(N+1)
Bt = [0]*(M+1)
for i in range(N):
At[i+1] = At[i] + A[i]
for i in range(M):
Bt[i+1] = Bt[i] + B[i]
j = M
ans = 0
for i in range(N+1):
if At[i] > K:
break
while At[i] + Bt[j] > K:
j = j - 1
if ans < i + j:
ans = i+j
print(ans)
|
def gcd(a,b):
while a!=0 and b!=0:
if a>b:
c = a
a = b
b = c
b %= a
return max(a,b)
a,b = map(int,input().split())
print(a*b//gcd(a,b))
| 0 | null | 62,158,223,816,138 | 117 | 256 |
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)
from heapq import heappush, heappop
def input():
return sys.stdin.readline().strip()
# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
return [ int(s) for s in input().split(" ")]
# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
return [ int(input()) for _ in range(n)]
# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
return map(int, open(0).read().split())
def rangeI(it, l, r):
for i, e in enumerate(it):
if l <= i < r:
yield e
elif l >= r:
break
def log(*args):
print("DEBUG:", *args, file=sys.stderr)
INF = 999999999999999999999999
MOD = 10**9+7
n = int(input())
S = [ input() for _ in range(n)]
left = 0
right = 0
l_ok = [False] * n
r_ok = [False] * n
LMR = [0] * n
MIN_LMR = [0] * n
for i,s in enumerate(S):
l = 0
r = 0
lok = True
for j,c in enumerate(s):
if c == "(":
l += 1
else:
r += 1
if r > l:
lok = False
MIN_LMR[i] = min(MIN_LMR[i], l-r)
LMR[i] = l - r
l = 0
r = 0
rok = True
for j in range(len(s)-1, -1, -1):
if s[j] == "(":
l += 1
if l > r:
rok = False
break
else:
r += 1
left += s.count("(")
right += s.count(")")
l_ok[i] = lok
r_ok[i] = rok
# log(l_ok)
# log(r_ok)
if left != right:
print("No")
exit()
positives = [ (MIN_LMR[i], LMR[i]) for i,x in enumerate(LMR) if x > 0 ]
zeros = [ (MIN_LMR[i], LMR[i]) for i,x in enumerate(LMR) if x == 0 ]
negatives = [ (MIN_LMR[i], LMR[i]) for i,x in enumerate(LMR) if x < 0]
for i in range(len(negatives)):
min_lmr, lmr = negatives[i]
min_lmr = min_lmr - lmr
lmr = -1 * lmr
negatives[i] = (min_lmr, lmr)
positives.sort(reverse=True)
negatives.sort(reverse=True)
h = 0
for min_lmr, lmr in positives + zeros:
if h+min_lmr < 0:
print("No")
exit()
h += lmr
h = 0
for min_lmr, lmr in negatives:
if h+min_lmr < 0:
print("No")
exit()
h += lmr
print("Yes")
|
X,K,D = map(int,input().split())
X = abs(X)
ans = 0
if X>=D and D*K<=X:
ans = X - D*K
if X>=D and D*K>X:
K=K-int(X/D)
X=X%D
if K%2==0:
ans=X
else:
ans = abs(X-D)
if X<D:
if K%2==0:
ans = X
else:
ans = abs(X-D)
print(ans)
| 0 | null | 14,409,238,219,070 | 152 | 92 |
x=int(input())
import math
import bisect
#----エラトステネスの篩--------
def get_primenumber(number):
prime_list = []
#2からnumberまでの数字をsearch_listに入れる
search_list = list(range(2,number+1))
while True:
#search_listの先頭の値が√nの値を超えたら処理終了
if search_list[0] > math.sqrt(number):
#prime_listにsearch_listを結合
prime_list.extend(search_list)
break
else:
#search_listの先頭をprime_listに入れる
head_num = search_list[0]
prime_list.append(head_num)
#search_listの先頭をpopする
search_list.pop(0)
#head_numの倍数を取り除く
search_list = [num for num in search_list if num % head_num != 0]
return prime_list
s=get_primenumber(100500)
i = bisect.bisect_left(s, x)
print(s[i])
|
while True:
H, W = map(int, input().split())
if H == 0 and W == 0:
break
for i in range(H):
if i % 2 == 0:
print("#."*(W//2)+"#"*(W%2))
else:
print(".#"*(W//2)+"."*(W%2))
print()
| 0 | null | 53,162,387,241,840 | 250 | 51 |
n,m = map(int,input().split())
v1 = [ input().split() for _ in range(n) ]
v2 = [ int(input()) for _ in range(m) ]
l = [sum(map(lambda x,y:int(x)*y,v,v2)) for v in v1 ]
print(*l,sep="\n")
|
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [int(input()) for _ in range(m)]
for i in a:
c = 0
for j, k in zip(i, b):
c += j * k
print(c)
| 1 | 1,132,656,446,608 | null | 56 | 56 |
from collections import deque
n, q = map(int, input().split())
queue = deque()
for i in range(n):
name, time = input().split()
queue.append({"name": name, "time": int(time)})
t = 0
while len(queue) != 0:
#print([queue[i]["time"] for i in range(len(queue))])
head = queue.popleft()
if head["time"] <= q:
t += head["time"]
name = head["name"]
print("{} {}".format(name, t))
else:
queue.append({"name": head["name"], "time": head["time"] - q})
t += q
|
class Queue():
def __init__(self):
self.el = []
def add(self, el):
self.el.append(el)
def delete(self):
return self.el.pop(0)
def action(self):
self.el[0]['time'] -= q
tmp = self.delete()
self.el.append(tmp)
n, q = map(int, raw_input().split())
qu = Queue()
for i in range(n):
name, time = raw_input().split()
time = int(time)
qu.add({'name':name, 'time':time})
time = 0
while qu.el:
#print qu.el
if qu.el[0]['time'] > q:
qu.action()
time += q
else:
time += qu.el[0]['time']
print qu.el[0]['name'], time
qu.delete()
| 1 | 43,169,283,740 | null | 19 | 19 |
n = int(input())
cnt = 0
d1, d2 = [0] * n, [0] * n
for i in range(n):
d1[i], d2[i] = map(int, input().split())
for i in range(n):
if d1[i] == d2[i]:
cnt += 1
else:
cnt = 0
if cnt == 3:
print("Yes")
exit()
print("No")
|
n = int(input())
s = 0
for i in range(n):
x,y = map(int,input().split())
if x == y:
s += 1
if s == 3:
print("Yes")
quit()
else:
s = 0
print("No")
| 1 | 2,480,887,901,778 | null | 72 | 72 |
st = str(input())
q = int(input())
com = []
for i in range(q):
com.append(input().split())
for k in com:
if k[0] == "print":
print(st[int(k[1]):int(k[2])+1])
elif k[0] == "reverse":
s = list(st[int(k[1]):int(k[2])+1])
s.reverse()
ss = "".join(s)
st = st[:int(k[1])] + ss + st[int(k[2])+1:]
else:
st = st[:int(k[1])] + k[3] + st[int(k[2])+1:]
|
def main():
N, R = map(int, input().split())
X = R + max(0, 100 * (10 - N))
print(X)
if __name__ == '__main__':
main()
| 0 | null | 32,720,100,763,172 | 68 | 211 |
inp = [i for i in input().split()]
n = int(input())
array = [[i for i in input().split()] for i in range(n)]
for i2 in range(n):
fuck =""
for i in range(1,33):
if (i<=20 and i%5==0) or i==22 or i==27 or i==28:
s = "N"
else:
s = "E"
if s == "E":
a = []
a.append(inp[3])
a.append(inp[1])
a.append(inp[0])
a.append(inp[5])
a.append(inp[4])
a.append(inp[2])
inp = a
if inp[0] == array[i2][0] and inp[1] == array[i2][1] and inp[2] != fuck:
print(inp[2])
fuck = inp[2]
elif s == "N":
a = []
a.append(inp[1])
a.append(inp[5])
a.append(inp[2])
a.append(inp[3])
a.append(inp[0])
a.append(inp[4])
inp = a
if inp[0] == array[i2][0] and inp[1] == array[i2][1] and inp[2] != fuck:
print(inp[2])
fuck = inp[2]
|
class dice:
def __init__(self,label):
self.label = {i+1: l for i,l in enumerate(label)}
def roll(self,op):
l = self.label
if op=='N': self.label = {1:l[2], 2:l[6], 3:l[3], 4:l[4], 5:l[1], 6:l[5]}
elif op=='E': self.label = {1:l[4], 2:l[2], 3:l[1], 4:l[6], 5:l[5], 6:l[3]}
elif op=='W': self.label = {1:l[3], 2:l[2], 3:l[6], 4:l[1], 5:l[5], 6:l[4]}
elif op=='S': self.label = {1:l[5], 2:l[1], 3:l[3], 4:l[4], 5:l[6], 6:l[2]}
def yaw(self,op):
l = self.label
if op=='CW' : self.label = {1:l[1], 2:l[3], 3:l[5], 4:l[2], 5:l[4], 6:l[6]}
elif op=='CCW': self.label = {1:l[1], 2:l[4], 3:l[2], 4:l[5], 5:l[3], 6:l[6]}
def get_label(self,i):
return self.label[i]
if __name__ == '__main__':
d0 = dice(list(map(int,input().split())))
q = int(input())
for _ in range(q):
t,f = list(map(int,input().split()))
for _ in range(3):
if d0.get_label(1) == t: break
d0.roll('E')
if d0.get_label(1) != t:
d0.roll('N')
if d0.get_label(1) != t:
for _ in range(2): d0.roll('N')
if d0.get_label(2) != f:
for _ in range(3):
d0.yaw('CW')
if d0.get_label(2) == f: break
print(d0.get_label(3))
| 1 | 260,363,198,872 | null | 34 | 34 |
n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))
flag = [False] * 2000
for i in range(2 ** n):
total = 0
for j in range(n):
if((i >> j) & 1):
total += A[j]
flag[total] = True
for m in M:
print('yes' if flag[m] else 'no')
|
K = int(input())
id = 1
cnt = 7
while cnt < K:
cnt = cnt * 10 + 7
id += 1
visited = [0] * K
while True:
remz = (cnt % K)
if remz == 0:
break
visited[remz] += 1
if visited[remz] > 1:
id = -1
break
cnt = remz * 10 + 7
id += 1
print(id)
| 0 | null | 3,069,316,984,668 | 25 | 97 |
l = map(int, raw_input().split())
print l[0] * l[1],
print l[0] *2 + l[1] * 2
|
a = input().split()
c = int(a[0]) * int(a[1])
d = (int(a[0])*2) + (int(a[1])*2)
print('%d %d' %(c,d))
| 1 | 308,802,936,320 | null | 36 | 36 |
n = int(input())
s = input()
ans = ''
for c in s:
nc_ord = ord(c) + n
while nc_ord > ord('Z'):
nc_ord -= 26
ans += chr(nc_ord)
print(ans)
|
n=int(input())
p=[int(x) for x in input().split()]
a=1
b=p[0]
for i in range(1,n):
if p[i-1]<b:
b=p[i-1]
if p[i]<=b:
a+=1
print(a)
| 0 | null | 109,829,224,289,498 | 271 | 233 |
[n, k] = map(int, input().split(' '))
wi = list(map(int, [input() for i in range(n)]))
def isAllocatable(p):
kw, ki = 0, 1
for w in wi:
if w > p: return False
kw += w
if kw <= p: continue
ki += 1
if k < ki: return False
kw = w
return True
l = 0
r = sum(wi)
while l + 1 < r:
p = int((l + r) / 2)
if isAllocatable(p): r = p
else: l = p
print(r)
|
def p_is_smaller(p):
total = 0
number_of_track = 1
for w in W:
total += w
if total > p:
number_of_track += 1
if number_of_track > k:
return 1
total = w
return 0
if __name__ == "__main__":
n, k = map(int, input().split())
W = [int(input()) for _ in range(n)]
left, right = max(W), sum(W)
while right > left:
mid = (left + right) // 2
if p_is_smaller(mid):
left = mid + 1
else:
right = mid
print(right)
| 1 | 88,200,164,978 | null | 24 | 24 |
N = int(input())
A = list(map(int, input().split()))
A.sort()
result = 1
for i in range(N):
result *= A[i]
if result > 10**18:
result = -1
break
print(result)
|
N=int(input())
A=[int(x) for x in input().split()]
Q=int(input())
somme=sum(A)
from collections import Counter
D=Counter()
for l in A:
D[l]+=1
for step in range(Q):
b,c=map(int,input().split())
if b not in D:
print(somme)
continue
somme=somme+(c-b)*D[b]
D[c]=D[c]+D[b]
del D[b]
print(somme)
| 0 | null | 14,189,611,967,048 | 134 | 122 |
import bisect, collections, copy, heapq, itertools, math, string
import sys
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 S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
N =I()
if N % 2 == 0:
print(N // 2)
else:
print(N // 2 + 1)
if __name__ == "__main__":
main()
|
n=int(input())
gou=n//2
gou+=n%2
print(gou)
| 1 | 59,085,223,567,620 | null | 206 | 206 |
h, n = map(int, input().split())
ab = []
for _ in range(n):
ab.append(map(int, input().split()))
m = 20010
dp = [1000000000] * m
dp[0] = 0
for a, b in ab:
for i in range(m):
if i - a >= 0:
dp[i] = min(dp[i], dp[i - a] + b)
print(min(dp[h:]))
|
#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, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
return list(map(int,readline().split()))
def readTuples():
return tuple(map(int,readline().split()))
def I():
return int(readline())
h,n = readInts()
A = [readInts() for _ in range(n)]
dp = [INF] * (h+1)
dp[h] = 0
for idx in range(h,-1,-1):
for i in range(n):
a,b = A[i]
dp[max(0,idx-a)] = min(dp[max(0,idx-a)], dp[idx] + b)
print(dp[0])
| 1 | 80,799,188,216,618 | null | 229 | 229 |
n = int(input())
d = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(d[n-1])
|
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()
def main():
l='1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51'
a=l.split(', ')
k=I()
return a[k-1]
# main()
print(main())
| 1 | 50,186,761,161,460 | null | 195 | 195 |
import sys
def main():
_ = int(input())
imps = sys.stdin.readlines()
db = {}
for imp in imps:
c, k = imp.split(' ')
if c == 'insert':
db[k] = 0
elif k in db:
print('yes')
else:
print('no')
main()
|
n=int(input())
dic={}
a=[]
b=[]
for i in range(n):
tmp1,tmp2=input().split()
a.append(tmp1)
b.append(tmp2)
for i in range(n):
if a[i]=='insert':
dic[b[i]]=1
else:
if b[i] in dic:
print("yes")
else:
print("no")
| 1 | 81,559,759,552 | null | 23 | 23 |
D = int(input())
C = [int(x) for x in input().split()]
S = [[int(i) for i in input().split()] for D in range(D)]
T = [0]*D
for i in range(D):
T[i] = int(input())
score = [0]*26
last = [-1]*26
for i in range(D):
score[T[i]-1] += S[i][T[i]-1]
last[T[i]-1] = i
for j in range(26):
score[j] -= C[j]*(i-last[j])
print(sum(score))
|
D = int(input())
c = list(map(int, input().split()))
s = []
for _ in range(D):
s.append(list(map(int, input().split())))
t = []
for _ in range(D):
t.append(int(input()))
# last(d, i)を計算するためのメモ
dp = [0] * 26
def dec(d):
# d日の終わりに起こる満足度の減少計算の関数
s = 0
for j in range(26):
s += c[j] * (d - dp[j])
return s
# vは満足度
v = 0
for i in range(D):
# 初日の満足度
if (i == 0):
v += s[i][t[i] - 1]
# 開催されたコンテストの日付をメモ
dp[t[i] - 1] = (i + 1)
v -= dec(i + 1)
print(v)
continue
# elif (0 < i and i < D - 1):
v += s[i][t[i] - 1]
dp[t[i] - 1] = (i + 1)
v -= dec(i + 1)
print(v)
| 1 | 9,860,740,865,560 | null | 114 | 114 |
from collections import deque
N, M = map(int, input().split())
Graph = [[]for _ in range(N + 1)]
for i in range(M):
a, b = map(int, input().split())
Graph[a].append(b)
Graph[b].append(a)
dist = [-1] * (N + 1)
dist[0] = 0
dist[1] = 0
pre = [-1] * (N + 1)
pre[0] = 0
pre[1] = 1
d = deque()
d.append(1)
while d:
v = d.popleft()
for i in Graph[v]:
if dist[i] != -1:
continue
dist[i] = dist[v] + 1
pre[i] = v
d.append(i)
ans = dist[0:]
print('Yes')
for j in range(2, len(pre)):
print(pre[j])
|
N = int(input())
s_list = []
t_list = []
for i in range(N):
s,t=input().split()
s_list.append(s)
t_list.append(int(t))
X = input()
flag = 0
time = 0
for i, x in enumerate(s_list):
if x == X:
flag = 1
elif flag == 1:
time += t_list[i]
print(time)
| 0 | null | 58,943,491,509,418 | 145 | 243 |
from collections import deque
n,x,y = map(int,input().split())
adj = [[] for i in range(n)]
adj[x-1].append(y-1)
adj[y-1].append(x-1)
for i in range(n-1):
adj[i].append(i+1)
adj[i+1].append(i)
ans = [0]*(n-1)
for i in range(n):
q = deque([])
q.append(i)
dist = [-1]*n
dist[i] = 0
while len(q) > 0:
v = q.popleft()
for nv in adj[v]:
if dist[nv] != -1:
continue
dist[nv] = dist[v] + 1
q.append(nv)
for i in dist:
if i != 0:
ans[i-1] += 1
for i in ans:
print(i//2)
|
N,X,Y =map(int,input().split())
count = [0] * (N-1)
for i in range(1,N):
path = abs(X-i) +1
for j in range(i+1,N+1):
dist = min(j-i, path+abs(Y-j))
count[dist-1] +=1
print(*count, sep="\n")
| 1 | 44,243,682,501,568 | null | 187 | 187 |
n,m=map(int,input().split())
matA=[list(map(int,input().split())) for i in range(n)]
matB=[int(input()) for i in range(m)]
for obj in matA:
print(sum(obj[i] * matB[i] for i in range(m)))
|
import sys
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
sys.setrecursionlimit(10**6)
INF = 10**20
def mint():
return map(int,input().split())
def lint():
return map(int,input().split())
def judge(x, l=['Yes', 'No']):
print(l[0] if x else l[1])
S = input()
N = len(S)+1
L = [0]*N
R = [0]*N
for i in range(N-1):
L[i+1] = L[i]+1 if S[i]=='<' else 0
for i in range(N-2,-1,-1):
R[i] = R[i+1]+1 if S[i]=='>' else 0
ans = [max(l,r) for l,r in zip(L,R)]
print(sum(ans))
| 0 | null | 78,502,582,340,260 | 56 | 285 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.