code1
stringlengths 16
24.5k
| code2
stringlengths 16
24.5k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,628B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
N,M = map(int,input().split())
A = [int(x) for x in input().split()]
if N - sum(A) >= 0 :
print(N-sum(A))
else :
print("-1")
|
a = [int(c) for c in input().split()]
r = a[0]*a[1]
if a[0] == 1 or a[1] == 1:
print(1)
elif r % 2 == 0:
print(int(r/2))
else:
print(int(r/2+1))
| 0 | null | 41,254,387,295,208 | 168 | 196 |
s,t = input().split()
a,b=map(int,input().split())
u=input()
print(a-1, b) if s == u else print(a,b-1)
|
import sys, 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 = []
N,M,K=i_map()
A=i_list()
B=i_list()
cum_A = [0]*(N+1)
cum_B = [0]*(M+1)
for i in range(1, N+1):
cum_A[i] = cum_A[i-1] + A[i-1]
for i in range(1, M+1):
cum_B[i] = cum_B[i-1] + B[i-1]
ans = 0
for i in range(0, N+1):
val = K - cum_A[i]
if val < 0:
continue
idx = bisect_right(cum_B, val) - 1
ans = max(ans, i + idx)
print(ans)
| 0 | null | 41,073,922,851,402 | 220 | 117 |
N = int(input())
d = dict()
for i in range(N):
let = input()
if let in d:
d[let] += 1
else:
d[let] = 0
max = 0
res = []
for i in d:
if d[i] > max:
max = d[i]
res =[i]
elif d[i] == max:
res.append(i)
for i in sorted(res):
print(i)
|
from collections import Counter
N = int(input())
C = Counter([input() for _ in range(N)])
# print(f'{list(C)=}')
max_value = max([value for value in C.values()])
# print(f'{max_value=}')
S = [key for key, value in zip(C.keys(), C.values()) if value == max_value]
# print(f'{S=}')
for s in sorted(S):
print(s)
| 1 | 69,556,918,719,480 | null | 218 | 218 |
from math import *
def calcAngle(h,m):
# validate the input
if (h < 0 or m < 0 or h > 12 or m > 60):
print('Wrong input')
if (h == 12):
h = 0
if (m == 60):
m = 0
h += 1;
if(h>12):
h = h-12;
# Calculate the angles moved by
# hour and minute hands with
# reference to 12:00
hour_angle = 0.5 * (h * 60 + m)
minute_angle = 6 * m
# Find the difference between two angles
angle = abs(hour_angle - minute_angle)
# Return the smaller angle of two
# possible angles
angle = min(360 - angle, angle)
return angle
a,b,h,m=[int(i) for i in input().split()]
theta=calcAngle(h,m)*pi/180
ans=(a**2+b**2-2*a*b*cos(theta))**(1/2)
print("{:.15f}".format(ans))
|
import math
a, b, h, m = map(int, input().split())
x = 6 * m
y = 30 * h + 0.5 * m
C = max(x, y) - min(x, y)
C = min(C, 360 - C)
print(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(C))))
| 1 | 20,129,089,922,218 | null | 144 | 144 |
A, B, C = map(int, input().split())
temp = B
B = A
A = temp
temp = C
C = A
A = temp
print(str(A) + " " + str(B) + " " + str(C))
|
from sys import *
N = int(stdin.readline())
a,b = [],[]
for i in range(N):
tmp = list(map(int, stdin.readline().split()))
a.append(tmp[0] + tmp[1])
b.append(tmp[0] - tmp[1])
a.sort()
b.sort()
print(max(a[-1]-a[0], b[-1]-b[0]))
| 0 | null | 20,660,653,485,028 | 178 | 80 |
N = int(input())
A = list(map(int,input().split()))
# for i in range(N):
# A[i] = int(i)
cMoney = 1000
stock = 0
A.append(0)
for i in range(N):
stock = 0
if A[i] < A[i+1]:
stock = cMoney // A[i]
cMoney -= stock * A[i]
cMoney += A[i+1] * stock
print(cMoney)
# for i in range(N):
# stock = 0
# if A[i] < A[i+1]:
# stock = cMoney // A[i]
# cMoney += (A[i+1] - A[i]) * stock
# print(cMoney)
|
n = int(input())
a = list(map(int, input().split()))
ans = 1000
stock = 0
for i in range(n-1):
if a[i+1] > a[i]:
buy = ans//a[i]
stock += buy
ans -= buy*a[i]
else:
ans += stock*a[i]
stock = 0
ans += stock*a[-1]
print(ans)
| 1 | 7,318,803,856,820 | null | 103 | 103 |
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n+1)]
self.rank = [0]*(n+1)
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def same_check(self, x, y):
return self.find(x) == self.find(y)
N, M = map(int, input().split())
A = [0]*M
B = [0]*M
uf = UnionFind(N)
for i in range(M):
A[i], B[i] = map(int, input().split())
uf.union(A[i], B[i])
cnt = 0 #新しく作った橋の数
for j in range(1,N):
if uf.same_check(j, j+1) == False:
uf.union(j,j+1)
cnt+=1
print(cnt)
#print(uf.par[1:])
#print(uf.rank[1:])
|
class UnionFind():
def __init__(self,size):
self.table = [-1 for _ in range(size)]
self.member_num = [1 for _ in range(size)]
#representative
def find(self,x):
while self.table[x] >= 0:
x = self.table[x]
return x
def union(self,x,y):
s1 = self.find(x)
s2 = self.find(y)
m1=self.member_num[s1]
m2=self.member_num[s2]
if s1 != s2:
if m1 != m2:
if m1 < m2:
self.table[s1] = s2
self.member_num[s2]=m1+m2
return [m1,m2]
else:
self.table[s2] = s1
self.member_num[s1]=m1+m2
return [m1,m2]
else:
self.table[s1] = -1
self.table[s2] = s1
self.member_num[s1] = m1+m2
return [m1,m2]
return [0,0]
N,M = list(map(int,input().split()))
uf = UnionFind(N)
count = 0
for i in range(M):
A,B = list(map(int,input().split()))
A,B = A-1,B-1
if uf.find(A)!=uf.find(B):
uf.union(A,B)
count+=1
B = set()
for i in range(N):
B.add(uf.find(i))
print(len(B)-1)
| 1 | 2,297,144,089,810 | null | 70 | 70 |
n=int(input())
a=list(map(int,input().split()))
b=[]
f=1
for i in a:
if i%2==0:
b.append(i)
for j in b:
if not (j%3==0 or j%5==0):
f=0
if f:
print("APPROVED")
else:
print("DENIED")
|
import math
import numpy as np
N,M=map(int,input().split())
A=list(map(int,input().split()))
c=1
test=A[0]
l=0
while test%2 == 0:
test=test//2
c*=2
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
for i in np.arange(N-1):
if A[i+1]%c!=0:
print(0)
l=1
break
elif A[i+1]%(c*2)==0:
print(0)
l=1
break
else:
k=A[i+1]//c
test=lcm_base(test, k)
if l==0:
k=test*c//2
print(M//k//2 + M//k%2)
| 0 | null | 85,345,594,111,310 | 217 | 247 |
#!/usr/bin/env python3
a=sorted(input().split())
print(a[0]*int(a[1]))
|
import math
import itertools
# 与えられた数値の桁数と桁値の総和を計算する.
def calc_digit_sum(num):
digits = sums = 0
while num > 0:
digits += 1
sums += num % 10
num //= 10
return digits, sums
n = int(input())
distances = []
for _ in range(n):
points = list(map(int, input().split()))
distances.append(points)
total = 0
routes = list(itertools.permutations(range(n), n))
for route in routes:
distance = 0
for index in range(len(route)-1):
idx1 = route[index]
idx2 = route[index+1]
distance += math.sqrt((distances[idx1][0] - distances[idx2][0]) ** 2 + (distances[idx1][1] - distances[idx2][1]) ** 2)
total += distance
print(total / len(routes))
| 0 | null | 115,878,450,398,802 | 232 | 280 |
ans = [f'{x} {y + 1}' for x in "SHCD" for y in range(13)]
n = int(input())
for i in range(n):
a = input()
ans.remove(a)
for v in ans:
print(v)
|
x=int(input())
A=int(x//500)
B=int((x%500)//5)
ans=0
ans=A*1000+B*5
print(ans)
| 0 | null | 21,738,948,243,168 | 54 | 185 |
S = int(input())
h = S//3600
m = (S%3600)//60
s = S%60
print(h,":",m,":",s,sep='')
|
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.readline()[:-1]
mod = 10**9 + 7
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
if row <= 0:
return [[] for _ in range(col)]
elif col == 1:
return [I() for _ in range(row)]
else:
read_all = [LI() for _ in range(row)]
return map(list, zip(*read_all))
#################
N = I()
count = 0
for i in range(N):
val1,val2 = LI()
if val1 == val2:
count += 1
if count == 3:
print('Yes')
exit()
else:
count = 0
print('No')
| 0 | null | 1,384,871,140,192 | 37 | 72 |
N = int(input())
N = N % 10
if N in (2, 4, 5, 7, 9):
print ("hon")
elif N in (0, 1, 6, 8):
print ("pon")
elif N == 3:
print ("bon")
|
import math
def isMore(N,K):#- N以上の数で、0でないのが丁度K個
#-len(N)よりもKがおおきかったら0 埋められない
if len(N) < K:
return 0
#最高位の数字を1つ繰り上げれば、なんでも大きい。ただし、Kは1以上
if K>=1:
tmp = (9-int(N[0]))*fact[len(N)-1]//((fact[len(N)-K])*(fact[K-1]))*(9**(K-1))
#一桁ならtmpを返す
if len(N)==1:
return tmp
#2桁以上あるなら&最高位が0なら、最高桁繰り上げ+最高桁同じ+0でないものがK個
elif len(N)>1 and N[0]=='0':
return tmp + isMore(N[1:],K)
#2桁以上あるなら&最高位が0以外なら、最高桁繰り上げ+最高桁同じ+0でないものがK-1個
elif len(N)>1 and N[0]!='0':
return tmp + isMore(N[1:],K-1)
#Kが0ならどうやってもNより大きいものが作れない0
if K == 0:
return 0
N = input()
K = int(input())
lenN = len(N)
fact = [1]*101
for i in range(1,101):
fact[i] = fact[i-1]*i
ans = fact[lenN]//((fact[lenN-K])*fact[K])*(9**K)
ans -= isMore(N,K)
print(ans)
| 0 | null | 47,588,463,178,668 | 142 | 224 |
n,k_ = map(int,input().split())
a_li = list(map(int,input().split()))
a_li_o = [0]*n
for i in range(k_):
for l in range(n):
a_li_o[l] = a_li[l]
dum_li = [0]*n
for j in range(n):
left = j - a_li[j]
right = j + a_li[j] + 1
if left < 0:
left = 0
dum_li[left] += 1
if right > n-1:
continue
dum_li[right] -= 1
total = 0
for k in range(n):
total += dum_li[k]
dum_li[k] = total
for k in range(n):
a_li[k] = dum_li[k]
if a_li_o == a_li:
break
print(" ".join(map(str,a_li)))
|
import numpy as np
from numba import njit
n, k = map(int, input().split())
a = np.array(list(map(int, input().split())))
@njit('(i8[::1]),', cache=True)
def update(a):
b = np.zeros_like(a)
for i, x in enumerate(a):
l = max(0, i - x)
r = min(n - 1, i + x)
b[l] += 1
if r + 1 < n:
b[r + 1] -= 1
b = np.cumsum(b)
return b
k = min(k, 100)
for i in range(k):
a = update(a)
print(' '.join(a.astype(str)))
| 1 | 15,428,547,573,622 | null | 132 | 132 |
import sys
n, k = list(map(int, input().split()))
if (k == 1):
print(0)
sys.exit()
ans = 0
v_ans = 0
if (n > k):
v_ans = n % k
else:
v_ans = n
if (abs(v_ans - k) < v_ans):
ans = abs(v_ans - k)
else:
ans = v_ans
print(ans)
|
N, K = map(int, input().split(' '))
print(min(N % K, abs(N % K - K)))
| 1 | 39,267,764,203,140 | null | 180 | 180 |
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if a[0] - sum(b) >= 0:
print(a[0] - sum(b))
else:
print(-1)
|
a, b, m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
li = [list(map(int,input().split())) for i in range(m)]
kouho = [min(a)+min(b)]
for l in li:
kouho.append(a[l[0]-1] + b[l[1]-1] -l[2])
print(min(kouho))
| 0 | null | 42,703,651,097,760 | 168 | 200 |
def main():
n, m = map(int, input().split())
# nは偶数、mは奇数
# n+mから2つ選ぶ選び方は
# n:m = 0:2 和は 偶数、選び方はmC2
# n:m = 1:1 和は 奇数 (今回はこれは含めない)
# n:m = 2:0 和は 偶数、選び方はnC2
cnt = 0
if m >= 2:
cnt += m * (m -1) // 2
if n >=2:
cnt += n * (n -1) // 2
print(cnt)
if __name__ == '__main__':
main()
|
N,M = map(int,input().split())
print(sum(range(0,N))+sum(range(0,M)))
| 1 | 45,426,924,145,920 | null | 189 | 189 |
import sys
input = sys.stdin.readline
N = int(input())
ans = 0
for i in range(1,N+1):
if i%3 != 0 and i%5 !=0:
ans += i
print(ans)
|
n = int(input())
ans = 0
for i in range(1,n+1):
if (i % 3 == 0) or (i % 5 == 0):
pass
else:
ans += i
print(ans)
| 1 | 35,085,118,552,958 | null | 173 | 173 |
a,b,c=sorted(map(int,input().split()))
print(a,b,c)
|
s=input()
l=set(s)
if(len(l)==1):
print("No")
else:
print("Yes")
| 0 | null | 27,520,950,176,740 | 40 | 201 |
def run_length(data, init=''):
length = []
tmp = init
cnt = 0
for c in data:
if tmp != c:
length.append(cnt)
cnt = 0
tmp = c
cnt += 1
length.append(cnt)
return length
def resolve():
s = input()
if s[0] != '<':
s = '<' + s
if s[-1] != '>':
s = s + '>'
array = run_length(s)
ans = 0
for i in range(1, len(array), 2):
a,b = array[i], array[i+1]
mn = min(a,b) - 1
mx = max(a,b)
ans += (mn+1) * (mn) // 2 + mx * (mx+1) // 2
# print(a,b, (mn+1) * (mn) // 2 + mx * (mx+1) // 2)
# print(array)
print(ans)
if __name__ == "__main__":
resolve()
|
s = input()
k = len(s)
a = [0]*(k+1)
for i in range(k):
if s[i] == '<':
a[i+1] = a[i]+1
for j in range(k-1,-1,-1):
if s[j] == '>':
a[j] = max(a[j],a[j+1]+1)
print(sum(a))
| 1 | 156,234,926,755,192 | null | 285 | 285 |
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():
S = SS()
len_S = len(S)
ans = 0
for i in range(len_S // 2):
if S[i] != S[len_S-1-i]:
ans += 1
print(ans)
if __name__ == '__main__':
resolve()
|
from sys import exit
import math
import collections
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
s = input()
cnt = 0
for i in range(len(s)//2):
if s[i] != s[-1-i]:
cnt += 1
print(cnt)
| 1 | 119,929,527,405,810 | null | 261 | 261 |
lst = list(input())
v_lakes = []
idx_stack = []
for i, c in enumerate(lst):
if (c == '\\'):
idx_stack.append(i)
elif (idx_stack and c == '/'):
# 対応する'\\'の位置
j = idx_stack.pop()
v = i - j
while (v_lakes and v_lakes[-1][0] > j):
v += v_lakes.pop()[1]
v_lakes.append((j, v))
ans = [len(v_lakes)]
v = [v[1] for v in v_lakes]
ans.extend(v)
print(sum(v))
print(*ans)
|
# l = open('input.txt').readline()
l = input()
k = 0
S1, S2 = [], []
for i in range(len(l)):
if l[i] == '\\':
S1.append(i)
elif l[i] == '/' and S1:
j = S1.pop()
a = i - j
k += i - j
while S2 and S2[-1][0] > j:
a += S2.pop()[1]
S2.append((j, a))
print(k)
print(len(S2), *(a for j, a in S2))
| 1 | 60,018,416,590 | null | 21 | 21 |
house = [[[0 for col in range(10)]for row in range(3)]for layer in range(4)]
n = int(raw_input())
for i in range(n):
input_line = raw_input().split()
house[int(input_line[0])-1][int(input_line[1])-1][int(input_line[2])-1] += int(input_line[3])
for i in range(0,4):
if i != 0:
print "#"*20
for j in range(0,3):
buf = ""
for k in range(0,10):
buf += " " + str(house[i][j][k])
print buf
|
def dfs(S, mx):
if len(S) == N:
print(S)
else:
for i in range(a, mx+2):
if i == mx+1:
dfs(S+chr(i), mx+1)
else:
dfs(S+chr(i), mx)
return
N = int(input())
a = ord('a')
dfs('a', a)
| 0 | null | 26,688,810,770,010 | 55 | 198 |
H,N=map(int,input().split())
A=input()
list_A=A.split()
waza=0
for i in range(0,N):
waza=waza+int(list_A[i])
if waza>=H:
print("Yes")
else:
print("No")
|
dic=set()
n=int(input())
cmd=[list(input().split()) for i in range(n)]
for c, l in cmd:
if c=="insert":
dic.add(l)
if c=="find":
if l in dic:
print("yes")
else:
print("no")
| 0 | null | 39,095,278,471,718 | 226 | 23 |
mod = 10**9 + 7
N = int(input())
A = [int(i) for i in input().split()]
# bitにしてor
# 一桁だけの時、111000なら3 * 3
maxl = 0
textlist = []
for i in range(N):
tmp = str(bin(A[i]))
tmp = tmp[2:]
length = len(tmp)
if maxl < length:
maxl = length
textlist.append(tmp)
zeros = {}
ones = {}
for i in range(maxl):
zeros[i] = 0
ones[i] = 0
for i in range(N):
tmp = textlist[i]
length = len(tmp)
if maxl < length:
maxl = length
for j in range(length):
if tmp[-j-1]== '1':
ones[j] += 1
for i in range(maxl):
zeros[i] = N-ones[i]
result = 0
n2 = 1
for i in range(maxl):
result = (result + n2 * (zeros[i] * ones[i])) % mod
n2 = (n2 * 2) % mod
print(result)
|
n = int(input())
my_dict = {}
for i in range(n):
order, key = input().split(' ')
if order == 'insert':
my_dict[key] = True
elif order== 'find':
if key in my_dict.keys():
print('yes')
else:
print('no')
| 0 | null | 61,349,324,482,810 | 263 | 23 |
D, T, S = list(map(int, input().split()))
print("Yes" if T*S>=D else "No")
|
D,T,S=map(int,input().split(' '))
if (D/S)<=T:
print("Yes")
else:
print("No")
| 1 | 3,540,073,143,620 | null | 81 | 81 |
d, t, s = map(int, input().split())
dist = t * s - d
if dist >= 0:
print("Yes")
elif dist < 0:
print("No")
|
print [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
][int(raw_input())-1]
| 0 | null | 26,901,743,143,858 | 81 | 195 |
def solve():
N = input()
K = int(input())
dp = [[[0]*(K+2) for i in range(2)] for j in range(len(N)+1)]
dp[0][False][0] = 1
for i in range(len(N)):
for k in range(K+1):
dp[i+1][True][k+1] += dp[i][True][k] * 9
dp[i+1][True][k] += dp[i][True][k]
if int(N[i]) > 0:
dp[i+1][True][k+1] += dp[i][False][k] * (int(N[i]) - 1)
dp[i+1][True][k] += dp[i][False][k]
if int(N[i]) > 0:
dp[i+1][False][k+1] = dp[i][0][k]
else:
dp[i+1][False][k] = dp[i][0][k]
print(dp[-1][False][K] + dp[-1][True][K])
if __name__ == '__main__':
solve()
|
import sys
sys.setrecursionlimit(10**7)
def main():
s=input()
k=int(input())
n=len(s)
def dp(i,j,smaller):
# i桁目以降について、0以外の値を残りj個使用可能という状況を考える。i桁目までは決定している。残りn-i桁
# このときi桁目までの部分が「等しい」か「strict に小さくなっている」かを smaller フラグによって分岐する。
if n==i: # 0でない数字をk個つかえなかったパターン。
return 0 if j>0 else 1
if smaller:# 残りのn-i桁の中からj桁選び好きな数字にできる。j桁以外はすべて0
if j==0:
return 1
elif j==1:
return (n-i)*9
elif j==2:
return ((n-i)*(n-i-1))//2*9**2
elif j==3:
return ((n-i)*(n-i-1)*(n-i-2))//6*9**3
if j==0: # i桁目以降はすべて0で決まり
return 1
ret=0
# i+1桁目が0なら0を使うしかない
if s[i]=='0':
ret+=dp(i+1,j,smaller)
else:
ret+=dp(i+1,j-1,smaller) # i+1桁目でsと同じ数字を使う
ret+=(int(s[i])-1)*dp(i+1,j-1,True) # i+1桁目で0より大きくs未満の数字使う
ret+=dp(i+1,j,True) # i+1桁目で0を使う。
return ret
print(dp(0,k,False))
if __name__=='__main__':
main()
| 1 | 75,524,555,136,188 | null | 224 | 224 |
N=int(input())
S=input()
count = 0
for i in range(1000):
if i < 100:
target_1 = "0"
if i < 10:
target_2 = "0"
target_3 = str(i)
else:
target_2 = str(i)[0]
target_3 = str(i)[1]
else:
target_1 = str(i)[0]
target_2 = str(i)[1]
target_3 = str(i)[2]
step = 1
for j in range(N):
if S[j] == target_1 and step == 1:
step = 2
pass
elif S[j] == target_2 and step == 2:
step = 3
elif S[j] == target_3 and step == 3:
count += 1
break
print(count)
|
t=input()
h=t/3600
m=(t%3600)/60
s=t%60
print "%d:%d:%d" %(h,m,s)
| 0 | null | 64,232,421,604,548 | 267 | 37 |
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % p
p = 10 ** 9 + 7
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, N + 1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
ans = 0
for i in range(N - K + 1):
ans -= A[i] * cmb(N - 1 - i, K - 1, p)
A = A[::-1]
for i in range(N - K + 1):
ans += A[i] * cmb(N - 1 - i, K - 1, p)
print(ans % p)
|
H, W = map(int, input().split())
S = [input() for _ in range(H)]
INF = H + W
dp = [[INF] * W for _ in range(H)]
if S[0][0] == '#':
dp[0][0] = 1
else:
dp[0][0] = 0
for i in range(H):
for j in range(W):
if i - 1 >= 0:
if S[i][j] == '#' and S[i-1][j] == '.':
dp[i][j] = min(dp[i][j], dp[i-1][j] + 1)
else:
dp[i][j] = min(dp[i][j], dp[i-1][j])
if j - 1 >= 0:
if S[i][j] == '#' and S[i][j-1] == '.':
dp[i][j] = min(dp[i][j], dp[i][j-1] + 1)
else:
dp[i][j] = min(dp[i][j], dp[i][j-1])
print(dp[H-1][W-1])
| 0 | null | 72,209,825,304,430 | 242 | 194 |
N, K = map(int, input().split())
ans = 1
while N >= K:
N = N // K
ans += 1
print(ans)
|
N, K = map(int, input().split())
for i in range(1000000):
if K ** (i - 1) <= N < K ** i:
print(i)
break
| 1 | 64,643,124,435,612 | null | 212 | 212 |
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import pdb
import sys
F = sys.stdin
N = int(F.readline())
count = 0
A = N // 2
for i in range(1, A+1):
if i*2 != N:
count += 1
print(count)
|
def insertion_sort(seq):
print(' '.join(map(str, seq)))
for i in range(1, len(seq)):
key = seq[i]
j = i - 1
while j >= 0 and seq[j] > key:
seq[j+1] = seq[j]
j -= 1
seq[j+1] = key
print(' '.join(map(str, seq)))
return seq
n = int(input())
seq = list(map(int, input().split()))
insertion_sort(seq)
| 0 | null | 76,621,977,448,068 | 283 | 10 |
pm,pd = map(int,input().split())
nm,nd = map(int,input().split())
print(0 if pm == nm else 1)
|
s = input()
cnt = [1] if s[0] == "<" else [0, 1]
bc = s[0]
for i in range(1, len(s)):
if s[i] == bc:
cnt[-1] += 1
else:
cnt.append(1)
bc = s[i]
if len(cnt) % 2 == 1:
cnt.append(0)
ans = 0
for i in range(0, len(cnt), 2):
ma = max(cnt[i], cnt[i + 1])
mi = min(cnt[i], cnt[i + 1])
ans += max(0, ma * (ma + 1) // 2)
ans += max(0, (mi - 1) * mi // 2)
print(ans)
| 0 | null | 140,228,974,450,796 | 264 | 285 |
#!/usr/bin/python3
#coding: utf-8
S = input()
ret = 0
# 山を下る
i = 0
while i < len(S) and S[i] == ">":
i += 1
ret += i
# 山を登って降りる
n_up = 0
n_down = 0
while i < len(S):
n_up = 0
n_down = 0
while i < len(S) and S[i] == "<":
n_up += 1
i += 1
if i >= len(S):
break
while i < len(S) and S[i] == ">":
n_down += 1
i += 1
if i >= len(S):
break
if n_up < n_down:
n_up, n_down = n_down, n_up
ret += ((n_up+1) * n_up) // 2
ret += (n_down * (n_down-1)) // 2
print(ret)
|
def main():
S = input()
N = len(S)+1
a = [0]*(N)
#右側からみていく
for i in range(N-1):
if S[i] == '<':
a[i+1] = max(a[i]+1,a[i+1])
#print(a)
#左側から見ていく
for i in range(N-2,-1,-1):
#print(i)
if S[i] == '>':
a[i] = max(a[i+1]+1,a[i])
ans = 0
#print(a)
for i in range(N):
ans += a[i]
return ans
print(main())
| 1 | 156,569,657,361,420 | null | 285 | 285 |
a=100000
n=int(input())
for i in range(n):
a=a*1.05
if a%1000 !=0:
a=a-(a%1000)+1000
print(int(a))
|
n = int(input())
x = 100000
for i in range(n):
x *= 1.05
if x % 1000 != 0:
x = x - x % 1000 + 1000
print(int(x))
| 1 | 1,391,275,168 | null | 6 | 6 |
case_index = 0
while True:
case_index += 1
n = int(raw_input())
if 0 == n:
break
print 'Case %d: %d'%(case_index, n)
|
i = 0
d = 0
while d == 0:
x = input()
if x != 0:
i += 1
print("Case %d: %d" %(i, x))
else:
d = 1
| 1 | 477,926,412,012 | null | 42 | 42 |
n = int(input())
p, q = [], []
for _ in range(n):
x, y = map(int, input().split())
p.append(x + y)
q.append(x - y)
p.sort()
q.sort()
print(max(max(p) - min(p), max(q) - min(q)))
|
x = input()
ans = 1 if x == "0" else 0
print(ans)
| 0 | null | 3,215,775,451,560 | 80 | 76 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque, Counter, defaultdict
def getN():
return int(input())
def getList():
return list(map(int, input().split()))
import math
import bisect
from logging import getLogger, StreamHandler, DEBUG, WARNING
logger = getLogger(__name__)
handler = StreamHandler()
handler.setLevel(DEBUG)
logger.setLevel(DEBUG)
# handler.setLevel(WARNING)
# logger.setLevel(WARNING)
logger.addHandler(handler)
def main():
n, k = getList()
nums = getList()
acc = [0]
tmp = 0
for num in nums:
tmp += num - 1
tmp %= k
acc.append(tmp)
ans = 0
df = {}
for i in range(n + 1):
if not acc[i] in df:
df[acc[i]] = 1
else:
df[acc[i]] += 1
ans += (df[acc[i]] - 1)
if i >= k-1:
df[acc[i-k+1]] -= 1
print(ans)
# print(acc)
if __name__ == "__main__":
main()
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
a[0] = (a[0]-1)%k
for i in range(1,n):
a[i] = (a[i]+a[i-1]-1)%k
ans = 0
b = {0:1}
for i in range(n):
if i>0:
b[a[i-1]] = b.get(a[i-1],0) + 1
if i>=k:
b[a[i-k]] -= 1
if i==k-1:
b[0] -= 1
ans += b.get(a[i],0)
print(ans)
| 1 | 137,339,031,293,100 | null | 273 | 273 |
N = int(input())
for i in range(50000):
if N <= i*1.08 < N + 1:
print(i)
break
else:
print(":(")
|
n = int(input())
ans = 0
t = 0
J = 0
for i in range(1,n):
for j in range(i,n):
if i*j >= n:break
if i == j : t+=1
ans +=1
J = j
print(2*ans -t)
| 0 | null | 63,908,113,048,052 | 265 | 73 |
def bisect_left(L,x):
lo=0
hi=N
while lo<hi:
mid=(lo+hi)//2
if L[mid]<x: lo=mid+1
else: hi=mid
return lo
N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
ans=0
for i in range(N-2):
a=L[i]
for j in range(i+1,N-1):
b=L[j]
"""
lo=0
hi=N
x=a+b
while lo<hi:
mid=(lo+hi)//2
if L[mid]<x: lo=mid+1
else: hi=mid
ans+=lo-(j+1)
"""
ans+=bisect_left(L,a+b)-(j+1)
print(ans)
|
import sys
# sys.setrecursionlimit(100000)
import bisect
def input():
return sys.stdin.readline().strip()
def input_int():
return int(input())
def input_int_list():
return [int(i) for i in input().split()]
def main():
n = input_int()
L = sorted(input_int_list())
ans = 0
for i in range(n - 2):
for j in range(i + 1, n - 1):
idx = bisect.bisect_left(L, L[i] + L[j])
ans += idx - j - 1
print(ans)
return
if __name__ == "__main__":
main()
| 1 | 171,783,679,131,212 | null | 294 | 294 |
from math import gcd
from sys import setrecursionlimit
setrecursionlimit(4100000)
mod = 10 ** 9 + 7
n = int(input())
zeros = 0
d = {}
for i in range(n):
x, y = map(int, input().split())
if x == 0 and y == 0:
zeros += 1
else:
g = gcd(x, y)
x, y = x // g, y // g
if (y < 0) or (y == 0 and x < 0):
x, y = -x, -y
else:
pass
if x <= 0:
sq = True #second quadrant
x, y = y, -x
else:
sq = False
if sq == True:
if (x, y) in d:
d[(x, y)][1] += 1
else:
d[(x, y)] = [0, 1]
else:
if (x, y) in d:
d[(x, y)][0] += 1
else:
d[(x, y)] =[1, 0]
#繰り返し2乗法
def mod_pow(a:int, b:int, mod:int)->int:
if b == 0:
return 1 % mod
elif b % 2 == 0:
return (mod_pow(a, b//2, mod) ** 2) % mod
elif b == 1:
return a % mod
else:
return ((mod_pow(a, b//2, mod) ** 2) * a) % mod
#print(d)
ans = 1
for (a, b), (k, l) in d.items():
now = 1
now = (now + mod_pow(2, k, mod) - 1) % mod
now = (now + mod_pow(2, l, mod) - 1) % mod
ans = (ans * now) % mod
ans -= 1
zeros = zeros % mod
ans = (ans + zeros) % mod
print(ans)
|
s = input()
p = input()
ring = s * 2
if p in ring:
print("Yes")
else:
print("No")
| 0 | null | 11,448,229,020,888 | 146 | 64 |
n = int(input())
s = [input() for _ in range(n)]
d = {}
for i in s:
if i not in d:
d[i] = 1
else:
d[i] += 1
m = max(d.values())
l = []
for i in d.keys():
if d[i] == m:
l.append(i)
l_s = sorted(l)
for i in l_s:
print(i)
|
import sys
prm = sys.stdin.readline()
prm = prm.split()
prm.sort()
a = int(prm[0])
b = int(prm[1])
c = int(prm[2])
print a, b, c
| 0 | null | 35,373,853,496,410 | 218 | 40 |
import sys
input = sys.stdin.buffer.readline
from collections import deque
def main():
N,u,v = map(int,input().split())
con = [[] for _ in range(N)]
for _ in range(N-1):
a,b = map(int,input().split())
con[a-1].append(b-1)
con[b-1].append(a-1)
aq = deque([v-1])
adist = [0 for _ in range(N)]
edge = []
go = [True for _ in range(N)]
go[v-1] = False
while aq:
now = aq.pop()
for fol in con[now]:
if go[fol]:
adist[fol] = adist[now] + 1
go[fol] = False
if con[fol] == [now]:
edge.append(fol)
else:
aq.append(fol)
tq = deque([u-1])
tdist = [0 for _ in range(N)]
_go = [True for _ in range(N)]
_go[u-1] = False
while tq:
now = tq.pop()
for fol in con[now]:
if _go[fol]:
tdist[fol] = tdist[now] + 1
_go[fol] = False
tq.append(fol)
ans = 0
for num in edge:
a,t = adist[num],tdist[num]
if a <= t:
continue
else:
ans = max(ans,a-1)
print(ans)
if __name__ == "__main__":
main()
|
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N, u, v = mapint()
query = [[] for _ in range(N)]
for _ in range(N-1):
a, b = mapint()
query[a-1].append(b-1)
query[b-1].append(a-1)
from collections import deque
def dfs(start):
Q = deque([start])
dist = [10**18]*N
dist[start] = 0
while Q:
now = Q.pop()
for nx in query[now]:
if dist[nx]>=10**18:
dist[nx] = dist[now] + 1
Q.append(nx)
return dist
taka = dfs(u-1)
aoki = dfs(v-1)
ans = 0
for i in range(N):
t, a = taka[i], aoki[i]
if t<=a:
ans = max(ans, a-1)
print(ans)
| 1 | 116,935,095,501,000 | null | 259 | 259 |
a,b,m = map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
Min = (min(A)+min(B))
for _ in range(m):
x,y,c = map(int,input().split())
if Min > A[x-1]+B[y-1]-c:
Min=A[x-1]+B[y-1]-c
print(Min)
|
import sys
A, B, M = map(int, input().split())
a = list(map(int, sys.stdin.readline().rsplit()))
b = list(map(int, sys.stdin.readline().rsplit()))
res = min(a) + min(b)
for i in range(M):
x, y, c = map(int, input().split())
res = min(res, a[x - 1] + b[y - 1] - c)
print(res)
| 1 | 54,005,551,625,050 | null | 200 | 200 |
x, n = map(int, input().split())
p = list(map(int, input().split()))
for i in range(n):
if p[i] - x >= 0:
p[i] = 2 * (p[i] - x)
else:
p[i] = (x - p[i]) * 2 - 1
p = sorted(p)
i = 0
while i in p:
i += 1
if i % 2 == 0:
j = round(i / 2) + x
else:
j = x - round((i + 1) / 2)
print(j)
|
X,N = map(int,input().split())
P = list(map(int,input().split()))
a = list(range(102))
for i in range(N):
a[P[i]] = -2
m = 102
for i in range(102):
if m > (abs(X - a[i])):
m = (abs(X - a[i]))
ans = a[i]
print(ans)
| 1 | 14,073,002,239,800 | null | 128 | 128 |
a, b = input().split(" ")
a_str = ""
b_str = ""
for i in range(int(b)):
a_str = a_str + a
for i in range(int(a)):
b_str = b_str + b
if a_str < b_str:
print(a_str)
else:
print(b_str)
|
a, b = map(int, input().split())
print((f"{a}" * b, f"{b}" * a)[b <= a])
| 1 | 84,306,720,584,620 | null | 232 | 232 |
a=map(int,raw_input().split())
a.sort()
while a[1]%a[0]!=0:
a[0],a[1]=a[1]%a[0],a[0]
print(a[0])
|
n = input().split()
x = int(n[0])
y = int(n[1])
if x < y:
bf = x
x = y
y = bf
while y > 0:
r = x % y
x = y
y = r
print(str(x))
| 1 | 8,479,483,350 | null | 11 | 11 |
from bisect import bisect_left
import numpy
def main():
def isOK(score):
count = 0
for a in reversed(A):
border_score = score - a
index = bleft(A, border_score)
count += N - index
if count >= M:
return True
return False
N, M = map(int, input().split())
A = sorted(map(int, input().split()))
ans = 0
ng = A[-1] + A[-1] + 1
ok = A[0] + A[0]
bleft = bisect_left
while(abs(ok-ng) > 1):
#print(ok, ng)
mid = (ok+ng) // 2
f = isOK(mid)
if f:
ok = mid
else:
ng = mid
#print(f)
#print(ok, ng)
C = [0,] + A
C = numpy.cumsum(C[::-1])
#print(C)
min_score = float('inf')
count = 0
for a in reversed(A):
index = bleft(A, ok-a)
if index < N:
min_score = min(a+A[index], min_score)
ans += C[N-index-1] + (N-index) * a
count += N-index
ans -= min_score * (count-M)
print(ans)
if __name__ == '__main__':
main()
|
s = input()
if s == 'hi':
print('Yes')
elif s == 'hihi':
print('Yes')
elif s == 'hihihi':
print('Yes')
elif s == 'hihihihi':
print('Yes')
elif s == 'hihihihihi':
print('Yes')
else:
print('No')
| 0 | null | 80,598,194,746,180 | 252 | 199 |
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
minj=i
for j in range(i,n):
if a[j]<a[minj]:
j,minj=minj,j
if i!=minj:
a[i],a[minj]=a[minj],a[i]
ans+=1
print(' '.join(map(str,a)))
print(ans)
|
n=int(input())
s=list(input())
fa=[n+1]*10
la=[-1]*10
for i in range(n):
s[i]=int(s[i])
if fa[s[i]]>n:
fa[s[i]]=i
la[s[i]]=i
ans=0
for i in range(10):
for j in range(10):
if fa[i]<la[j]:
num=[0]*10
for k in range(fa[i]+1,la[j]):
num[s[k]]=1
ans+=num.count(1)
print(ans)
| 0 | null | 64,230,881,906,812 | 15 | 267 |
n = int(input())
s = ["" for i in range(n)]
t = [0 for i in range(n)]
for i in range(n):
a, b = input().split()
s[i], t[i] = a, int(b)
x = input()
ans = 0
flag = False
for i in range(n):
if s[i] == x:
flag = True
elif flag:
ans += t[i]
print(ans)
|
A,B = map(int,input().split())
print(max(0,A-B*2))
| 0 | null | 131,693,377,727,132 | 243 | 291 |
S=input()[::-1]
ans=0
#支払う枚数
array = list(map(int, S))
L=len(array)
for i,n in enumerate(array):
if n< 5 :
ans+=n
elif n > 5:
ans+= 10-n
if i <L-1:
array[i+1] +=1
else:
ans +=1
else:
ans+=5
if i < L-1:
if array[i+1] >=5:
array[i+1] +=1
print( ans)
|
nl = list(input())
# 繰り上げと繰り下げ
dp = [[0, 10000] for i in range(len(nl) + 1)]
for i, n in enumerate(nl[::-1]):
n = int(n)
dp[i+1][0] = min(dp[i][0] + n, dp[i][1] + n + 1)
dp[i+1][1] = min(10 - n + dp[i][0], 10 - n - 1 + dp[i][1])
print(min(dp[-1][0], dp[-1][1]+1))
| 1 | 70,727,213,491,598 | null | 219 | 219 |
N = int(input())
A = list(map(int, input().split()))
ary = [0]*(N-1)
for i in reversed(range(N-1)):
if i+1 >= (N-1):
ary[i] = A[N-1]
else:
ary[i] = ary[i+1] + A[i+1]
s = 0
for i in range(N-1):
s += A[i]*ary[i]
print(s%(10**9+7))
|
#!/usr/bin/env python3
s = input()
c = 0
a = 0
p = ""
n = 0
for i in s:
if i != p:
if i == "<":
if c < 0:
a -= c * n
else:
a -= c * (n - 1)
n = 2
c = 1
else:
n = 2
c -= 1
else:
if i == "<":
c += 1
n += 1
else:
c -= 1
n += 1
a += c
p = i
if p == ">":
if c < 0:
a -= c * n
else:
a -= c * (n - 1)
print(a)
| 0 | null | 80,540,835,283,460 | 83 | 285 |
N,M = map(int,input().split())
array = list(map(int,input().split()))
ans = [1]*N
for i in range (M):
A,B = map(int,input().split())
if array[A - 1] < array[B - 1]:
ans[A - 1] = 0
elif array[A - 1] > array[B - 1]:
ans[B - 1] = 0
else:
ans[A-1],ans[B-1] = 0,0
print( sum(ans) )
|
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
good = [True]*N
for _ in range(M):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
if H[a] >= H[b]:
good[b] = False
if H[a] <= H[b]:
good[a] = False
print(good.count(True))
| 1 | 24,959,854,016,968 | null | 155 | 155 |
import sys
from fractions import gcd
[print("{} {}".format(gcd(k[0], k[1]), (k[0] * k[1]) // gcd(k[0], k[1]))) for i in sys.stdin for k in [[int(j) for j in i.split()]]]
|
A,B = map(int,input().split())
print(A*B if A<= 9 and B <=9 else "-1")
| 0 | null | 78,854,482,341,362 | 5 | 286 |
N=int(input())
S=['A']*N
T=[0]*N
for i in range(N):
s,t=input().split()
S[i]=s
T[i]=int(t)
print(sum(T[S.index(input())+1:]))
|
n = int(input())
playlists = []
for _ in range(n):
title, playtime = input().split()
playlists.append([title, int(playtime)])
titles, playtimes = list(zip(*playlists))
lastmusic = input()
lastmusic_timing = titles.index(lastmusic)
print(sum(playtimes[lastmusic_timing + 1:]))
| 1 | 96,823,477,500,128 | null | 243 | 243 |
print((int(input()) + 1) // 2)
|
from collections import deque
n = int(input())
d = deque()
cmd = ['com', 0]
for i in range(n):
cmd = input().split()
if cmd[0] == 'insert':
d.appendleft(int(cmd[1]))
elif cmd[0] == 'delete':
try:
d.remove(int(cmd[1]))
except ValueError:
pass
elif cmd[0] == 'deleteFirst':
d.popleft()
elif cmd[0] == 'deleteLast':
d.pop()
print(*list(d))
| 0 | null | 29,549,968,610,462 | 206 | 20 |
n = int(input())
print(sum((n - 1) // i for i in range(1, n)))
|
x = int(input())
q = x // 100
r = x % 100
r -= 5 * q
print(1 if r <= 0 else 0)
| 0 | null | 64,993,800,485,602 | 73 | 266 |
# coding: utf-8
ring = input()
pattern = input()
ring *= 2
if pattern in ring:
print('Yes')
else:
print('No')
|
a, b, c, k = map(int, input().split())
if k <= a:
print(k)
if a < k <= a+b:
print(a)
if a+b < k <= a+b+c:
print(a+(-1)*(k-a-b))
| 0 | null | 11,663,887,086,628 | 64 | 148 |
# coding: utf-8
while True:
a = input()
if a == '0':
exit()
else:
print(sum(list(map(int, a))))
|
while True:
x = list(input())
if x[0] == "0":
break
sum = 0
for i in range(len(x)):
sum += int(x[i])
print(sum)
#print(x)
| 1 | 1,580,744,332,948 | null | 62 | 62 |
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N = int(input())
S = list(input())
from collections import Counter
c = Counter(S)
ans = c['R']*c['G']*c['B']
for i in range(1, N):
for j in range(N):
first, second, third = j, j+i, j+i*2
if third>=N:
break
if len(set((S[first], S[second], S[third])))==3:
ans -= 1
print(ans)
|
N = int(input())
S = input()
d = {
'R': {},
'G': {},
'B': {}
}
for i, s in enumerate(S):
d[s][i] = True
answer = len(d['R']) * len(d['G']) * len(d['B'])
for r in d['R'].keys():
for g in d['G'].keys():
if 2 * r - g in d['B']:
answer -= 1
if 2 * g - r in d['B']:
answer -= 1
if ((r + g) % 2 == 0 and ((r + g) // 2) in d['B']):
answer -= 1
print(answer)
| 1 | 36,020,996,685,900 | null | 175 | 175 |
n,m = map(int, raw_input().split())
a = []
b = [0]*m
for i in xrange(n):
x = map(int,raw_input().split(" "))
a.append(x)
for i in xrange(m):
b[i] = input()
result = [0]*n
for i in xrange(n):
for j in xrange(m):
result[i] += a[i][j]*b[j]
print result[i]
|
import sys
from collections import Counter
input = sys.stdin.readline
N = int(input())
C = list(input().strip())
counter = Counter(C)
if len(counter) == 1:
print(0)
else:
red_n = counter["R"]
ans = 0
for i in range(N):
if red_n <= i:
break
if C[i] == "W":
ans += 1
print(ans)
| 0 | null | 3,720,636,246,458 | 56 | 98 |
T1, T2 = list(map(int, input().split()))
A1, A2 = list(map(int, input().split()))
B1, B2 = list(map(int, input().split()))
a, b = A1 * T1, A2 * T2
c, d = B1 * T1, B2 * T2
if a + b == c+ d:
print("infinity")
exit()
if a + b < c+d:
a,b,c,d = c,d,a,b
if a > c:
print(0)
exit()
else:
num = 0
if (c-a) % (a+b-c-d) == 0:
num = 1
print((c-a-1) // (a+b-c-d) * 2+num+1)
|
h1, m1, h2, m2, k = map(int, input().split())
if m2 >= m1:
print((h2 - h1) * 60 + (m2 - m1) - k)
else:
print((h2-1 - h1) * 60 + (m2 + 60 - m1) - k)
| 0 | null | 74,931,135,482,150 | 269 | 139 |
N = int(input())
S, T = input().split()
answer = []
for s, t in zip(S, T):
answer.append(s)
answer.append(t)
print(*answer, sep='')
|
from collections import defaultdict
N, K = map(int, input().split())
d = defaultdict(int)
for i in range(K):
_ = int(input())
A = [int(x) - 1 for x in input().split()]
for j in range(len(A)):
d[A[j]] += 1
ans = 0
for i in range(N):
if d[i] == 0:
ans += 1
print(ans)
| 0 | null | 68,591,391,825,140 | 255 | 154 |
n = int(input())
s = "abcdefghijklmnopqrstuvwxyz"
ans = ''
while n > 0:
n -= 1
ans = s[n % 26] + ans
#Floor division
n //= 26
print(ans)
|
N,K=map(int,input().split())
result=0
for i in range(10**9):
if (N<K**i):
result+=i
break
print(result)
| 0 | null | 37,913,669,158,410 | 121 | 212 |
a = int(input())
ans = a + (a ** 2) + (a ** 3)
print(ans)
|
x=input()
X=int(x)
y=X+X**2+X**3
print(y)
| 1 | 10,194,657,169,460 | null | 115 | 115 |
import queue
n, quantum = map(int, input().split())
q = queue.Queue()
for _ in range(n):
name, time = input().split()
q.put([name, int(time)])
spend_time = 0
while q.qsize() > 0:
name, time = q.get()
tmp = min(quantum, time)
spend_time += tmp
time -= tmp
if time == 0:
print('{} {}'.format(name, spend_time))
else:
q.put([name, time])
|
#getting input
statements = []
while True:
try:
line = str(input())
except EOFError:
break
statements.append(line)
pair = statements.pop(0).split()
amount = int(pair[0])
quantum = int(pair[1])
#process input
queue = []
for state in statements:
pair = state.split()
name = pair[0]
time = int(pair[1])
queue.append([name,time])
#processing queue
done_list = list()
time_spend = 0
while True:
if not len(queue) > 0:
break
task = queue[0]
if task[1] >= quantum: #time left
time_spend += quantum
task[1] = task[1] - quantum
else:
time_spend += task[1]
task[1] = 0
if task[1] <= 0: #finished
task.append(time_spend) #name,left_time, finished time
done_list.append((task[0],task[2])) #name and finished time
queue.remove(task)
else:
temp = task
queue.remove(task)
queue.append(temp)
for result in done_list:
print(result[0],end=' ')
print(result[1])
| 1 | 44,662,999,040 | null | 19 | 19 |
def main():
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
l = ["" for i in range(K)]
s = 0
for i in range(N):
# print(l)
if l[i%K] == T[i]:
l[i%K]=""
continue
if l[i%K] == "":
if T[i] == "r":
s = s+P
l[i%K] = "r"
elif T[i] == "s":
s = s+R
l[i%K] = "s"
else:
s = s+S
l[i%K] = "p"
elif T[i]=="r":
s = s+P
l[i%K] = "r"
elif T[i]=="s":
s = s+R
l[i%K] = "s"
else:
s = s+S
l[i%K] = "p"
print(s)
if __name__ == "__main__":
main()
|
N, K = map(int, input().split())
ls1 = list(map(int, input().split()))
d = dict()
ls2 = ['r', 's', 'p']
for x, y in zip(ls1, ls2):
d[y] = x
T = input()
S = T.translate(str.maketrans({'r': 'p', 's': 'r', 'p': 's'}))
ans = 0
for i in range(K):
cur = ''
for j in range(i, N, K):
if cur != S[j]:
ans += d[S[j]]
cur = S[j]
else:
cur = ''
print(ans)
| 1 | 106,995,413,059,680 | null | 251 | 251 |
A=["1","2","3"]
A.pop(A.index(input()))
A.pop(A.index(input()))
print(A[0])
|
n_turn = int(input())
t_point = h_point = 0
for i in range(n_turn):
t_card, h_card = input().split()
if t_card > h_card:
t_point += 3
elif t_card == h_card:
t_point += 1
h_point += 1
else:
h_point += 3
print("{} {}".format(t_point, h_point))
| 0 | null | 56,295,770,867,352 | 254 | 67 |
n,k=[int(x) for x in input().split()]
ans=0
l=[0]*(k+1)
i=k
mod=1000000007
while i>0:
l[i]=pow(k//i,n,mod)
j=2*i
while j<=k:
l[i]=(l[i]-l[j]+mod)%mod
j+=i
i-=1
for i in range(1,k+1):
ans+=(l[i]*i)%mod
print(ans%mod)
|
import sys
sys.setrecursionlimit(10**9)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,M,L = map(int,readline().split())
ABC = [list(map(int,readline().split())) for _ in range(M)]
Q = int(readline())
ST = [list(map(int,readline().split())) for _ in range(Q)]
def warshall_floyd(d):
for k in range(N):
for i in range(N):
for j in range(N):
d[i][j] = min(d[i][j],d[i][k] + d[k][j])
return d
INF = 10**11
d = [[INF]*N for i in range(N)]
a = [[INF]*N for i in range(N)]
for x,y,z in ABC:
if z <= L:
d[x-1][y-1] = z
d[y-1][x-1] = z
for i in range(N):
d[i][i] = 0
a[i][i] = 1
chk = warshall_floyd(d)
for i in range(N-1):
for j in range(i+1,N):
if chk[i][j] <= L:
a[i][j] = 1
a[j][i] = 1
ans = warshall_floyd(a)
for s,t in ST:
answer = ans[s-1][t-1]
if answer == INF:
print(-1)
else:
print(answer-1)
| 0 | null | 105,079,171,861,860 | 176 | 295 |
from itertools import accumulate
def main():
N, K = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(K):
arr = [0]*(N+1)
for i, a in enumerate(A):
left = max(0, i-a)
right = min(N, i+a+1)
arr[left] += 1
arr[right] -= 1
A = list(accumulate(arr[:-1]))
if all(a == N for a in A):
break
print(*A, sep=" ")
if __name__ == "__main__":
main()
|
s=input()
l=['SUN','MON','TUE','WED','THU','FRI','SAT']
d=[7,6,5,4,3,2,1]
print(d[l.index(s)])
| 0 | null | 74,059,957,686,118 | 132 | 270 |
#!/usr/bin/env python3
import sys
import heapq
MOD = 1000000007 # type: int
def containPositive(arr):
for a in arr:
if a >= 0:
return True
return False
def solve(N: int, K: int, A: "List[int]"):
if N == K:
m = 1
for a in A:
m = m*a%MOD
print(m)
elif not containPositive(A) and K%2 == 1:
A = list(reversed(sorted(A)))
m = 1
for i in range(K):
m = m*A[i]%MOD
print(m)
else:
m = 1
B = [(abs(a),a) for a in A]
B = list(reversed(sorted(B)))
lastNegative = 0
lastPositive = 1
hadPositive = False
for i in range(K):
a = B[i][1]
if a < 0:
if lastNegative == 0:
lastNegative = a
else:
m = m*lastNegative*a%MOD
lastNegative = 0
else:
if a > 0 and lastPositive != 1:
m = m*lastPositive%MOD
if a > 0:
lastPositive = a
hadPositive = True
else:
m=m*a%MOD
if lastNegative == 0:
print(m*lastPositive%MOD)
else:
nextNegative = 0
for i in range(K,N):
b = B[i][1]
if b < 0:
nextNegative = b
break
if nextNegative == 0:
m = m*B[K][1]
print(m*lastPositive%MOD)
else:
c1 = lastNegative*nextNegative
nextPositive = 0
k = K
while k < N:
a = B[k][1]
if a >=0:
nextPositive = a
break
k+=1
c2 = nextPositive*lastPositive
if not hadPositive: # This array contain some non-negative value. This means the result value could be positive. But if there were no positive values in the first K values sorted by the absolute value, use just next positive value instead of the last negative values.
m = m*nextPositive%MOD
print(m)
exit()
if c1 > c2:
m = m*lastNegative*nextNegative%MOD
print(m)
else:
m =m*nextPositive*lastPositive%MOD
print(m)
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
K = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, K, A)
if __name__ == '__main__':
main()
|
n,k=map(int,input().split())
A=list(map(int,input().split()))
mod=10**9+7
count=k
B,C=[],[]
for i in A:
if i<=0:B.append(i)
else:C.append(i)
B.sort(key=lambda x:abs(x))
C.sort()
ans,flag=1,1
while k!=0:
if k>=2:
if len(B)>=2 and len(C)>=2:
if B[-1]*B[-2]>C[-1]*C[-2]:
ans *=B.pop()*B.pop()
k -=2
else:
ans *=C.pop()
k -=1
elif len(B)>=2:
ans *=B.pop()*B.pop()
k -=2
elif len(C)>=2:
ans *=C.pop()*C.pop()
k -=2
else:flag=0;break
else:
if len(C)>0:
ans *=C.pop()
k -=1
else:flag=0;break
ans %=mod
if flag:print(ans)
else:
ans=1
A.sort(reverse=True)
for i in range(count):
ans *=A[i]
ans %=mod
print(ans)
| 1 | 9,409,801,052,112 | null | 112 | 112 |
h,n = map(int,input().split())
ab = []
for i in range(n):
a,b = map(int,input().split())
ab.append([a,b])
#ab.sort(key=lambda x: x[2], reverse=True)
if h==9999 and n==10:
print(139815)
exit()
#bubble sort
for i in range(n-1,-1,-1):
for j in range(0,i):
if ab[j][0]*ab[j+1][1]<ab[j+1][0]*ab[j][1]:
tmp = ab[j]
ab[j] = ab[j+1]
ab[j+1] = tmp
ans = 0
anslist = []
def indexH(h,arr):
li = []
for i in range(len(arr)):
if arr[i][0]>=h:
li.append(i)
return li[::-1]
while 1:
if len(ab)==0:
break
if max(ab, key=lambda x:x[0])[0]<h:
h-=ab[0][0]
ans+=ab[0][1]
#print(h,ans)
else:
c = 0
index = indexH(h,ab)
#print(h,index,ab,ab)
for i in range(len(index)):
anslist.append(ans+ab[index[i]][1])
ab.pop(index[i])
print(min(anslist))
|
h,n=map(int,input().split())
ans=0
magic=[]
al=[]
bl=[]
for i in range(n):
a,b=map(int,input().split())
magic.append([a,b])
al.append(a)
bl.append(b)
amx=max(al)
bmn=min(bl)
dp=[-1]*(h+amx+1)
dp[0]=0
for i in range(1,h+amx+1):
mn=float("inf")
for j in magic:
mp=j[1]
at=j[0]
if at>i:
cst=mp
else:
cst=dp[i-at]+mp
if cst<mn:
mn=cst
dp[i]=mn
print(min(dp[h:]))
| 1 | 81,365,559,604,900 | null | 229 | 229 |
list1=input().split()
S=list1[0]
T=list1[1]
A,B=map(int,input().split())
U=input()
if U==S:
a=A-1
print(f"{a} {B}")
if U==T:
b=B-1
print(f"{A} {b}")
|
s, t = input().split()
a, b = map(int, input().split())
u = input()
if s == u:
x = a - 1
y = b
else:
x = a
y = b - 1
print(x, y)
| 1 | 71,923,280,049,810 | null | 220 | 220 |
String = input()
A=input()
String+=String[0:len(A)]
#print(String)
for i in range(len(String)-len(A)+1):
if String[i:i+len(A)] == A:
print("Yes")
break
else: print("No")
|
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
Sui=[0]*(H-1)
for t in range(H-1):
if ((s >> t) & 1):
Sui[t]+=1
for m in range(H-1):
E+=Sui[m]
for k in range(H-1):
if Sui[k]==0:
for i in range(W):
CO[H-k-2][i]=DO[H-k-2][i]+CO[H-k-1][i]
else:
for i in range(W):
CO[H-k-2][i]=DO[H-k-2][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)
| 0 | null | 25,081,901,928,882 | 64 | 193 |
input()
xs = input().split()
print(' '.join(list(map(str, reversed(xs)))))
|
import sys
n = int( sys.stdin.readline() )
nums = sys.stdin.readline().rstrip().split( " " )
nums.reverse()
print( " ".join( nums ) )
| 1 | 974,889,135,520 | null | 53 | 53 |
print(('Yes','No')[sum(map(int,input()))%9>0])
|
s = input()
N = [int(c) for c in s]
add = 0
for i in range(len(N)):
num = N[i]
add += num
if add % 9 == 0:
print('Yes')
else:
print('No')
| 1 | 4,379,889,432,884 | null | 87 | 87 |
a, b, c = map(int, input().split())
DivisorCount = 0
DivideNum = a
for var in range(a, b+1):
if c % DivideNum == 0:
DivisorCount += 1
DivideNum += 1
print(DivisorCount)
|
num = list(map(int,input().split()))
c = 0
for i in range(num[0],num[1]+1):
if(num[2]%i == 0): c = c+1
print(c)
| 1 | 558,451,678,080 | null | 44 | 44 |
def g(x):
S=format(x,"22b")
cnt=0
for i in range(20):
if S[-1-i]=="1":
cnt=cnt+1
return x%cnt
n=int(input())
X=input()
a=0
for i in range(n):
if X[i]=="1":
a=a+1
#最初に割るのは a-1 or a+1 -> a==0,1 に注意
if a==0:
for i in range(n):
print(1)
exit()
if a==1:
if X[-1]=="1":
for i in range(n-1):
print(2)
print(0)
exit()
else:
for i in range(n-1):
if X[i]=="1":
print(0)
else:
print(1)
print(2)
exit()
D=[0]*n
E=[0]*n
D[0]=1%(a-1)
E[0]=1%(a+1)
b=int(X[-1])%(a-1)
c=int(X[-1])%(a+1)
for i in range(n-1):
D[i+1]=(D[i]*2)%(a-1)
E[i+1]=(E[i]*2)%(a+1)
if X[-2-i]=="1":
b=(b+D[i+1])%(a-1)
c=(c+E[i+1])%(a+1)
for i in range(n):
if X[i]=="1":
x=(b+a-1-D[-1-i])%(a-1)
ans=1
while x!=0:
x=g(x)
ans=ans+1
print(ans)
else:
x=(c+E[-1-i])%(a+1)
ans=1
while x!=0:
x=g(x)
ans=ans+1
print(ans)
|
N, A, B = map(int, input().split())
distance =(B - A - 1 )//2
if( (A % 2 == 0 and B % 2 ==0) or (A%2==1 and B%2==1)):
ans=(B - A)//2
else:
ans = min(A-1,N - B) + 1 + distance
print(ans)
| 0 | null | 59,004,559,893,718 | 107 | 253 |
L= list(map(int,input().split()))
a=1
for i in range(5):
if L[i]!=0:
a+=1
else:
print(a)
|
l = [int(x.strip()) for x in input().split()]
print(l.index(0)+1)
| 1 | 13,472,726,972,320 | null | 126 | 126 |
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
answer = 0
b_ind = 0
for x in range(N-1):
A[x+1] += A[x]
if A[x+1] > K:
A = A[:x+1]
break
for y in range(M-1):
B[y+1] += B[y]
if B[y+1] > K:
B = B[:y+1]
break
A = [0] + A
B = [0] + B
na = len(A)
nb = len(B)
if A[-1] + B[-1] <= K:
answer = len(A) + len(B) - 2
print(answer)
else:
for i in range(na):
for j in range(nb-b_ind-1, -1, -1):
if A[i] + B[j] <= K:
if answer < i+j:
answer = i+j
b_ind = nb-j-1
break
print(answer)
|
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import accumulate
from bisect import bisect
def main():
n, m, k = map(int, input().split())
a = tuple(accumulate(map(int, input().split())))
b = tuple(accumulate(map(int, input().split())))
r = bisect(b, k)
for i1, ae in enumerate(a):
if k < ae:
break
r = max(r, bisect(b, k - ae) + i1 + 1)
print(r)
if __name__ == '__main__':
main()
| 1 | 10,772,163,856,650 | null | 117 | 117 |
mod = 1000000007
def ff(a, b):
ans = 1
while b:
if b & 1: ans = ans * a % mod
b >>= 1
a = a * a % mod
return ans
n=int(input())
print(((ff(10,n)-2*ff(9,n)+ff(8,n))%mod+mod)%mod)
|
n, k = map(int, input().split()); m = 998244353; a = []
for i in range(k): a.append(list(map(int, input().split())))
b = [0]*n; b.append(1); c = [0]*n; c.append(1)
for i in range(1, n):
d = 0
for j in range(k): d = (d+c[n+i-a[j][0]]-c[n+i-a[j][1]-1])%m
b.append(d); c.append(c[-1]+d)
print(b[-1]%m)
| 0 | null | 2,947,626,073,980 | 78 | 74 |
S = int(input())
if S % 1000 == 0:
W = 0
else:
W = 1000-(S % 1000)
print(W)
190
|
x,n=map(int,input().split())
if n==0:
print(x)
exit()
p=[int(y) for y in input().split()]
a=0
for i in range(101):
if x-a not in p:
print(x-a)
break
elif x+a not in p:
print(x+a)
break
a+=1
| 0 | null | 11,224,961,326,900 | 108 | 128 |
x, k, d = map(int, input().split())
ax = abs(x)
n = ax // d
if n >= k:
ans = ax - k*d
else:
a = ax - n*d
if (k - n) % 2:
ans = abs(a - d)
else:
ans = abs(a)
print(ans)
|
s = input()
inc = 0
dec = 0
increasing = True
ans = 0
for c in s:
if increasing:
if c == '<':
inc += 1
else:
increasing = False
dec += 1
else:
if c == '>':
dec += 1
else:
if inc > dec:
inc, dec = dec, inc
ans += inc * (inc - 1) // 2 + dec * (dec + 1) // 2
increasing = True
inc = 1
dec = 0
else:
if increasing:
ans += inc * (inc + 1) // 2
else:
if inc > dec:
inc, dec = dec, inc
ans += inc * (inc - 1) // 2 + dec * (dec + 1) // 2
print(ans)
| 0 | null | 81,174,363,167,260 | 92 | 285 |
H, W, M = list(map(int, input().split()))
h = [0] * H
w = [0] * W
hw = {}
for _ in range(M):
a, b = list(map(int, input().split()))
h[a - 1] += 1
w[b - 1] += 1
temp = "x" + str(a - 1) + "y" + str(b - 1)
hw[temp] = 1
hm = max(h)
wm = max(w)
hp = [i for i, v in enumerate(h) if v == hm]
wp = [i for i, v in enumerate(w) if v == wm]
for x in hp:
for y in wp:
temp = "x" + str(x) + "y" + str(y)
if temp not in hw:
print(hm + wm)
exit()
else:
print(hm + wm - 1)
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
H, W, M = map(int, readline().split())
bomb = [tuple(map(lambda x: int(x) - 1, s.split())) for s in readlines()]
X = [0] * H
Y = [0] * W
for h, w in bomb:
X[h] += 1
Y[w] += 1
maxX = max(X)
maxY = max(Y)
R = [h for h, x in enumerate(X) if x == maxX]
C = [w for w, y in enumerate(Y) if y == maxY]
bomb = set(bomb)
for r in R:
for c in C:
if (r, c) not in bomb:
print(maxX + maxY)
exit()
print(maxX + maxY - 1)
| 1 | 4,727,603,850,970 | null | 89 | 89 |
import sys
H, W, K = map(int, input().split())
S = [list(sys.stdin.readline().strip()) for _ in range(H)]
i = 0
j = 0
ichigo = False
no = False
for i in range(H):
j = 0
if len(set(S[i])) == 1 and "." in S[i]:
no = True
continue
while j < W:
if S[i][j] == ".":
S[i][j] = str(K)
else:
if ichigo is True:
j -= 1
K -= 1
ichigo = False
else:
S[i][j] = str(K)
ichigo = True
j += 1
ichigo = False
K -= 1
if no is True:
for i in range(H):
if S[i][0] != ".":
tmp = i
for i in reversed(range(tmp)):
if S[i][0] == ".":
for j in range(W):
S[i][j] = S[i + 1][j]
for i in range(tmp + 1, H):
if S[i][0] == ".":
for j in range(W):
S[i][j] = S[i - 1][j]
for i in range(H):
print(*S[i])
|
H, W, K = map(int, input().split())
S = [[f for f in input()]for _ in range(H)]
Ans = [[0] * W for _ in range(H)]
num = 1
Flag = True
first = -1
for i in range(H):
flag = False
for j in range(W):
if (S[i][j] == '#') and flag:
num += 1
if (S[i][j] == '#') and Flag:
first = i
if S[i][j] == '#':
flag = True
Flag = False
Ans[i][j] = num
if not flag:
Ans[i] = Ans[i-1]
else:
num += 1
while first > 0:
Ans[first - 1] = Ans[first]
first -= 1
for ans in Ans:
for i, a in enumerate(ans):
if i == W-1:
print(a)
else:
print(a, end=' ')
| 1 | 143,267,370,044,078 | null | 277 | 277 |
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
N,M,K=map(int,input().split())
uf = UnionFind(N+1)
remove = [0]*(N+1)
for i in range(M):
A,B=map(int,input().split())
uf.union(A,B)
remove[A] +=1
remove[B] +=1
for i in range(K):
A,B=map(int,input().split())
if uf.same(A,B):
remove[A] +=1
remove[B] +=1
ANS = [0]*(N+1)
for i in range(0,N+1):
ANS[i] = uf.size(i) - remove[i] - 1
ANS.pop(0)
print(*ANS)
|
N,M = map(int,input().split())
H = list(map(int,input().split()))
AB = [tuple(map(int,input().split())) for i in range(M)]
ans=0
es = [[] for _ in range(N)]
for a,b in AB:
a,b = a-1,b-1
es[a].append(b)
es[b].append(a)
for i in range(N):
for j in es[i]:
if H[j]>=H[i]:
break
else:
ans+=1
print(ans)
| 0 | null | 43,111,658,360,988 | 209 | 155 |
# -*- coding: utf-8 -*-
def get_input() -> tuple:
"""
標準入力を取得する.
Returns:\n
tuple: 標準入力
"""
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
return N, K, A
def main(N: int, K: int, A: list) -> None:
"""
メイン処理.
Args:\n
N (int): 学期数(2 <= N <= 200000)
K (int): 直近何回分までの点数を考慮するか(1 <= K <= N - 1)
A (list): i学期の期末テストの点数
"""
# 求解処理
for i in range(K, N):
if A[i] > A[i - K]:
print("Yes")
else:
print("No")
if __name__ == "__main__":
# 標準入力を取得
N, K, A = get_input()
# メイン処理
main(N, K, A)
|
N,K = list(map(int, input().split()))
A = [int(i) for i in input().split()]
for i in range(K,N):
if A[i] > A[i-K]:
print("Yes")
else:
print("No")
| 1 | 7,036,821,490,390 | null | 102 | 102 |
import sys
from collections import deque
import copy
def main():
S = input()
print(S[0:3])
if __name__ == '__main__':
main()
|
import random
s = str(input()).lower()
t = random.randint(0, len(s)-3)
print(s[t:t+3])
| 1 | 14,762,549,922,512 | null | 130 | 130 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
15 6
1 2 7 8 12 50
output:
2
"""
import sys
def solve():
rec[0] = 0
for coin in coins:
for current_cost in range(coin, total_cost + 1):
rec[current_cost] = min(rec[current_cost], rec[current_cost - coin * 1] + 1)
return rec
if __name__ == '__main__':
_input = sys.stdin.readlines()
total_cost, c_num = map(int, _input[0].split())
coins = list(map(int, _input[1].split()))
# assert len(coins) == c_num
rec = [float('inf')] * (total_cost + 1)
ans = solve()
print(ans[-1])
|
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15
def main():
K = int(input())
S = input()
M = len(S)
N = M + K
MAXN = N + 2
fact = [1]
for i in range(1,MAXN + 1):
fact.append(fact[-1]*i%MOD)
inv_fact = [-1] * (MAXN + 1)
inv_fact[-1] = pow(fact[-1],MOD - 2,MOD)
for i in range(MAXN - 1,-1,-1):
inv_fact[i] = inv_fact[i + 1]*(i + 1)%MOD
nck = lambda N,K: 0 if K > N or K < 0 else fact[N]*inv_fact[N - K]*inv_fact[K]%MOD
power25 = [1]
power26 = [1]
for i in range(N):
power25.append(power25[-1]*25%MOD)
power26.append(power26[-1]*26%MOD)
ans = 0
for i in range(M,N + 1):
ans += nck(i - 1,M - 1) * power25[i - M] * power26[N - i] % MOD
ans %= MOD
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 6,526,847,085,568 | 28 | 124 |
N = int(input())
a = N % 10
if a == 0 or a == 1 or a == 6 or a == 8:
print("pon")
elif a == 3:
print("bon")
else:
print("hon")
|
N = int(input())
N = N % 10
if N in (2, 4, 5, 7, 9):
print ("hon")
elif N in (0, 1, 6, 8):
print ("pon")
elif N == 3:
print ("bon")
| 1 | 19,202,402,049,536 | null | 142 | 142 |
N = input ()
P = '0168'
H = '24579'
if N[-1] in P:
print ('pon')
elif N[-1] in H:
print ('hon')
else:
print ('bon')
|
import sys
n = int(input())
for i in range(1,10):
mod,ret = divmod(n,i)
if ret == 0 and mod <= 9:
print('Yes')
sys.exit()
print('No')
| 0 | null | 89,859,003,854,760 | 142 | 287 |
import sys
global status, d
status = {}
d=0
def bfs(keys, GRAPH, depth=0):
global status
if depth>10: quit
buf =[]
for e in keys:
if status[e]==-1:
status[e]=depth
for e2 in GRAPH[e]:
try:
if status[e2] == -1:
buf.append(e2)
except:
pass
if buf !=[]:
bfs(buf, GRAPH, depth+1)
return
n = int(raw_input())
x = {}
for i in range(n):
seq = map(int,raw_input().split())
key = seq[0]
if key != 0:
x[key] = seq[2:]
else:
x[key]=[]
status[key] = -1
for e in x.keys():
if e == 1:
bfs([e], x)
for e in x.keys():
print e, status[e]
|
import sys
def a_c(f):
s = f.read().decode().strip()
return 'ABC' if s == 'ARC' else 'ARC'
def main():
ans = a_c(sys.stdin.buffer)
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 12,017,556,974,358 | 9 | 153 |
def readInt():
return int(input())
def readList():
return list(map(int,input().split()))
def readMap():
return map(int,input().split())
def readStr():
return input()
inf=float('inf')
mod = 10**9+7
import math
def solve(N,X,M):
seen=set()
order_seen=[]
while X not in seen:
seen.add(X)
order_seen.append(X)
X=f(X,M)
pos=order_seen.index(X) # Find position of when the cycle begins
if pos>N: # If position is greater than N, then we know we are not going to include any values from the cycle.
return sum(order_seen[:N])
terms_before_cycle=order_seen[:pos]
sum_terms_before_cycle=sum(terms_before_cycle)
ans=sum_terms_before_cycle
terms_in_cycle=order_seen[pos:]
sum_cycle=sum(terms_in_cycle)
length_cycle=len(terms_in_cycle)
number_remaining_terms=N-pos
mult_factor=(number_remaining_terms)//length_cycle
ans+=(sum_cycle*mult_factor)
numb_remain=(number_remaining_terms)%length_cycle
ans+=sum(terms_in_cycle[:numb_remain])
return ans
# The function for the recurrence relation. A_n+1=A_n^2%M
def f(A,M):
return pow(A,2,M)
N,X,M=readMap()
print(solve(N,X,M))
|
n, x, m = map(int, input().split())
A = [0, x]
d = {x:1}
for i in range(2, n+1):
A.append(A[i-1]**2 % m)
if A[i] in d:
j = d[A[i]]
q, r = divmod(n-j+1, i-j)
print(sum(A[:j]) + q*sum(A[j:i]) + sum(A[j:j+r]))
break
else:
d[A[i]] = i
else:
print(sum(A))
| 1 | 2,857,938,540,750 | null | 75 | 75 |
N, M = map(int, input().split())
# 左パート
l, r = 1, N // 2
while M and l < r :
print(l, r)
l += 1
r -= 1
M -= 1
# 右パート
l, r = N // 2 + 2 - N % 2, N
while M :
print(l, r)
l += 1
r -= 1
M -= 1
|
n,m=map(int,input().split())
k=m//2
for i in range (0,k):
a=i+1
b=2*k+1-i
print (a,b)
c=2*k+2
k=(m+1)//2
j=1
#print(c,k)
for i in range (c,c+k):
a=i
b=c+2*k-j
j+=1
print(a,b)
| 1 | 28,588,126,603,106 | null | 162 | 162 |
import sys
for i in sys.stdin.readlines():
nums = list(map(int,i.split()))
h = nums[0]
w = nums[1]
if h == 0 and w == 0:
break
for j in range(1,h+1):
if h == 1 and w == 1:
print("#")
elif j % 2 == 1:
if w % 2 == 1:
x = int((w-1)/2)
print("#."*x +"#")
else:
x = int(w/2)
print("#."*x)
elif j % 2 == 0:
if w % 2 == 1:
x = int((w-1)/2)
print(".#"*x +".")
else:
x = int(w/2)
print(".#"*x)
print("")
|
x, y = map(int, input().split())
for i in range(1, x+1):
if (4*i + 2*(x - i) == y) or (2*i + 4*(x - i) == y):
print("Yes")
exit()
print("No")
| 0 | null | 7,325,855,395,120 | 51 | 127 |
n, m = list(map(int, input().split()))
c = list(map(int, input().split()))
DP = [i for i in range(n + 1)]
for cost in c:
for i in range(cost, n + 1):
DP[i] = min(DP[i], DP[i - cost] + 1)
print(DP[n])
|
INF = 100 ** 7
def main():
n, m = map(int, input().split())
c_list = list(map(int, input().split()))
dp = [INF] * (n + 1)
dp[0] = 0
for c in c_list:
for i in range(len(dp)):
if dp[i] != INF and i + c < len(dp):
dp[i + c] = min(dp[i + c], dp[i] + 1)
print(dp[n])
if __name__ == '__main__':
main()
| 1 | 140,879,478,228 | null | 28 | 28 |
d, t, f = map(int, input().split())
if (d/t) <= f:
print('Yes')
else:
print('No')
|
D,T,S=map(int,input().split(' '))
if (D/S)<=T:
print("Yes")
else:
print("No")
| 1 | 3,522,625,683,900 | null | 81 | 81 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
SS = ['SUN','MON','TUE','WED','THU','FRI','SAT']
S = readline().decode().rstrip()
for i in range(7):
if S == SS[i]:
print(7-i)
sys.exit()
|
def main():
n, k = [int(x) for x in input().split()]
scores = [int(x) for x in input().split()]
# zip にすると2つのリストを作るのか,これよりも少し時間とメモリ増。
print('\n'.join('Yes' if scores[index] < new else 'No'
for index, new in enumerate(scores[k:])))
if __name__ == '__main__':
main()
| 0 | null | 70,397,663,961,872 | 270 | 102 |
a, b = map(int, input().split())
def base10to(n, b):
if (int(n/b)):
return base10to(int(n/b), b) + str(n%b)
return str(n%b)
print(len(base10to(a,b)))
|
W = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]
S = input()
print(len(W) - W.index(S))
| 0 | null | 98,399,803,936,862 | 212 | 270 |
day = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]
d = input()
print(7 - day.index(d))
|
pos = 0
for n in map(int, input().split()):
pos += 1
if n == 0:
break
print(pos)
| 0 | null | 72,952,918,243,340 | 270 | 126 |
K = int(input())
n = 7
c = 0
while c <= K:
n %= K
c += 1
if n == 0:
print(c)
exit()
n = n * 10 + 7
print(-1)
|
from collections import Counter
N,*D = map(int, open(0).read().split())
m = 998244353
if D[0] > 0:
print(0)
else:
dc = Counter(D)
dci = [x for x in dc.items()]
ans = 1
if dc[0] > 1:
print(0)
else:
for i in range(1,max(dci)[0]+1):
if dc[i] == 0:
print(0)
break
else:
ans = (ans*pow(dc[i-1],dc[i],m)) % m
else:
print(ans)
| 0 | null | 80,652,643,814,208 | 97 | 284 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.