code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
n = input()
d = [0 for i in range(n)]
f = [0 for i in range(n)]
G = [0 for i in range(n)]
M = [[0 for i in range(n)] for j in range(n)]
color = [0 for i in range(n)]
tt = [0]
WHITE = 0
GRAY = 1
BLACK = 2
def dfs_visit(u):
color[u] = GRAY
tt[0] = tt[0] + 1
d[u] = tt[0]
for v in range(n):
if M[u][v] == 0:
continue
if color[v] == WHITE:
dfs_visit(v)
color[u] == BLACK
tt[0] = tt[0] + 1
f[u] = tt[0]
def dfs():
for u in range(n):
if color[u] == WHITE:
dfs_visit(u)
for u in range(n):
print "%d %d %d" %(u + 1, d[u], f[u])
### MAIN
for i in range(n):
G = map(int, raw_input().split())
for j in range(G[1]):
M[G[0]-1][G[2+j]-1] = 1
dfs() | import math
a, b = list(map(int, input().split()))
c = math.gcd(a, b)
d = a * b / c
d = math.floor(d)
print(d) | 0 | null | 56,553,939,888,950 | 8 | 256 |
h,w,K=map(int,input().split())
s=[list(input()) for i in range(h)]
from itertools import groupby
ans=10**18
for i in range(1<<h):
pre=-1
c=[]
t_cnt=0
op=[-1]*h
for j in range(h):
if i&(1<<j):op[j]=1
else:op[j]=0
gr=groupby(op)
l=[]
for key,g in gr:
l.append(len(list(g)))
c=[[0]*w for _ in range(len(l))]
idx=0
jdx=0
for idx,li in enumerate(l):
for k in range(li):
for a in range(w):
c[idx][a]+=int(s[jdx][a])
jdx+=1
# print(c)
t_cnt=len(c)-1
t_cnt1=0
c_mx=[0]*len(c)
ok=True
for a in range(w):
for b in range(len(c)):
if c[b][a]>K:
ok=False
c_mx[b]+=c[b][a]
if c_mx[b]>K:
t_cnt1+=1
c_mx=[0]*len(c)
for b in range(len(c)):
c_mx[b]+=c[b][a]
break
if ok:
ans=min(ans,t_cnt+t_cnt1)
if ans==10**18:
print(0)
else:
print(ans)
| import sys
input = sys.stdin.readline
h, w, kk = map(int, input().split())
ss = [[0 for _ in range(h)] for _ in range(w)]
for i in range(h):
for j, c in enumerate(list(input().strip())):
if c == '1':
ss[j][i] = 1
ans = 100000
for i in range(2 ** (h - 1)):
end = []
for j in range(h - 1):
if i & 2 ** j:
end.append(j + 1)
end.append(h)
start = [0]
for j in end:
start.append(j)
start.pop()
sums = [0] * len(start)
tans = len(start) - 1
imp = False
for j in range(w):
reset = False
for k, (s, e) in enumerate(zip(start, end)):
sums[k] += sum(ss[j][s:e])
if sums[k] > kk:
reset = True
break
if reset:
tans += 1
for k, (s, e) in enumerate(zip(start, end)):
sums[k] = sum(ss[j][s:e])
if sums[k] > kk:
imp = True
if imp:
break
if not imp:
ans = min(ans, tans)
print(ans)
| 1 | 48,546,603,838,336 | null | 193 | 193 |
N, M = map(int, input().split())
a = [[0, 0] for i in range(N)]
for i in range(M):
IN = list(input().split())
p = int(IN[0])
S = IN[1]
if S == "AC":
a[p-1][1] = 1
else:
if a[p-1][1] == 0:
a[p-1][0] += 1
m = 0
n = 0
for i in range(N):
if a[i][1] == 1:
m += 1
n += a[i][0]
print(m)
print(n) | def main():
n, m = map(int, input().split())
ac_list = [0 for _ in range(n + 1)] # 1: 正解済 0: 未正解
wa_list = [0 for _ in range(n + 1)]
for _ in range(m):
p, s = input().split()
p = int(p)
if ac_list[p] == 1: # 正解済
continue
if s == "AC":
ac_list[p] = 1
else:
wa_list[p] += 1
ac_count = 0
wa_count = 0
for i in range(1, n + 1):
if ac_list[i] == 1:
ac_count += 1
wa_count += wa_list[i]
print(ac_count, wa_count)
if __name__ == "__main__":
main()
| 1 | 93,553,269,112,294 | null | 240 | 240 |
n, m = map(int, input().split())
if n % 2 == 1:
for i in range(m):
print(i + 1, n - i)
else:
for i in range(m):
if 2 * (i + 1) <= m + 1:
print(i + 1, n - i)
else:
print(i + 1, n - i - 1) | import sys
input = sys.stdin.readline
N, M = map(int, input().split())
if M%2:
cnt = 0
for i in range(1, M//2 + 1):
cnt += 1
print(i, M + 2 - i)
print(M + 1 + i, 2*M + 2 - i)
i = cnt + 1
print(i, M + 2 - i)
else:
for i in range(1, M//2 + 1):
print(i, M + 2 - i)
print(M + 1 + i, 2*M + 2 - i) | 1 | 28,643,699,371,990 | null | 162 | 162 |
N = int(input())
*d, = map(int, input().split())
sum = 0
for i in range(len(d)):
for j in range(i+1, len(d)):
sum+=d[i]*d[j]
print(sum) | import itertools
N = int(input())
d = list(map(int, input().split()))
lst = list(itertools.combinations(d, 2))
total = 0
for n in lst:
c = n[0] * n[1]
total += c
print(total) | 1 | 168,378,559,152,232 | null | 292 | 292 |
import sys
input = sys.stdin.readline
def main():
N = int(input())
c = input()
cnt_r = 0
cnt_w = 0
for i in c:
if i == 'R':
cnt_r += 1
else:
cnt_w += 1
w_left = 0
r_right = cnt_r
ans = N
for i in range(N):
ans = min(ans, max(w_left, r_right))
if c[i] == 'W':
w_left += 1
else:
r_right -= 1
print(min(ans, max(w_left, r_right)))
main() | N = int(input())
A = list(map(int, input().split()))
A_set = set(A)
if len(A) == len(A_set):
print('YES')
else:
print('NO') | 0 | null | 40,000,580,553,100 | 98 | 222 |
s=[]
p=[]
a=i=0
for c in input():
if"\\"==c:s+=[i]
elif"/"==c and s:
j=s.pop()
t=i-j
a+=t
while p and p[-1][0]>j:t+=p[-1][1];p.pop()
p+=[(j,t)]
i+=1
print(a)
if p:print(len(p),*list(zip(*p))[1])
else:print(0)
| teki, hissatsu = list(map(int, input().split(' ')))
l = sorted(list(map(int, input().split(' '))))[:max(0, teki-hissatsu)]
print(sum(l)) | 0 | null | 39,670,888,950,432 | 21 | 227 |
N = int(input())
a = [int(x) for x in input().split()]
MOD = 10**9 + 7
ans = 1
lst = [0] * 3
for aa in a:
cnt = 0
j = -1
for i, l in enumerate(lst):
if l == aa:
cnt += 1
j = i
if j == -1:
ans = 0
break
ans *= cnt
ans %= MOD
lst[j] += 1
print(ans) | W=input()
num=0
while True:
T=input()
t=str.lower(T)
if (T == 'END_OF_TEXT'):break
t_split=(t.split())
for i in range(len(t_split)):
if t_split[i] == W:
num+=1
print(num)
| 0 | null | 66,002,553,380,828 | 268 | 65 |
H,W,M=map(int,input().split())
HSum=[0 for _ in range(H)]
WSum=[0 for _ in range(W)]
bombs = set()
for _ in range(M):
hi,wi = map(lambda x:int(x)-1,input().split())
HSum[hi] += 1
WSum[wi] += 1
bombs.add( (hi,wi) )
# print(HSum)
# print(WSum)
curMax = 0
## 計算量多すぎ。。
# for h in range(H):
# for w in range(W):
# tmp = HSum[h] + WSum[w]
# if curMax <= tmp:
# if (h,w) in bombs:
# tmp -= 1
# curMax = max( curMax, tmp )
hMax = max(HSum)
wMax = max(WSum)
tmpMax = hMax + wMax
ans = 0
hSumMaxOnly = [h for h, x in enumerate(HSum) if x == hMax]
wSumMaxOnly = [w for w, y in enumerate(WSum) if y == wMax]
for h in hSumMaxOnly:
if ans == tmpMax:
break
for w in wSumMaxOnly:
if (h,w) in bombs:
ans = tmpMax - 1
else:
ans = tmpMax
break
print(ans)
| N = int(input())
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
L1 = factorization(N - 1)
s = 1
# print(L1)
for [a, b] in L1:
s *= (b + 1)
# print(s)
def make_divisors(n):
lower_divisors, upper_divisors = [], []
i = 1
while i*i <= n:
if n % i == 0:
lower_divisors.append(i)
if i != n // i:
upper_divisors.append(n//i)
i += 1
return lower_divisors + upper_divisors[::-1]
for i in set(make_divisors(N))-{1}:
temp = N
while temp % i == 0:
temp //= i
if (temp-1) % i == 0:
s += 1
s -= 1
if N == 2:
print(1)
else:
print(s) | 0 | null | 22,947,596,802,208 | 89 | 183 |
from collections import defaultdict
it = lambda: list(map(int, input().strip().split()))
def solve():
N, X, M = it()
if N == 1: return X % M
cur = 0
cnt = 0
value = defaultdict(int)
history = defaultdict(int)
for i in range(N):
if X in history: break
value[X] = cur
history[X] = i
cnt += 1
cur += X
X = X * X % M
loop = cur - value[X]
period = i - history[X]
freq, rem = divmod(N - cnt, period)
cur += freq * loop
for i in range(rem):
cur += X
X = X * X % M
return cur
if __name__ == '__main__':
print(solve()) | from copy import deepcopy
# 多次元配列を作成する
def make_multi_list(initial, degree):
ans = [initial for _ in range(degree[-1])]
for d in reversed(degree[:-1]):
ans = [deepcopy(ans) for _ in range(d)]
return ans
N, T = map(int, input().split())
AB = []
for i in range(N):
a, b = map(int, input().split())
AB.append((a, b))
AB.sort()
ans = 0
dp = make_multi_list(0, [3005, 3005])
for i in range(N):
a, b = AB[i]
for j in range(T):
# iを使わないパターン
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
# iを使うパターン
nj = j + a
if nj < T:
dp[i + 1][nj] = max(dp[i + 1][nj], dp[i][j] + b)
now = dp[i][T - 1] + b
ans = max(ans, now)
print(ans)
| 0 | null | 77,383,881,567,324 | 75 | 282 |
n=int(input())
s=[str(input()) for _ in range(n)]
print(len(set(s))) | n = int(input())
S,T = input().split()
result = ''
for s,t in zip(S,T):
result += s
result += t
print(result) | 0 | null | 71,380,714,485,888 | 165 | 255 |
s=input()
dict1={7:'SUN',6:'MON',5:'TUE',4:'WED',3:'THU',2:'FRI',1:'SAT'}
keys = [k for k, v in dict1.items() if v == s]
print(keys[0]) | # AOJ ALDS1_4_C Dictionary
# Python3 2018.7.3 bal4u
dic = {}
n = int(input())
for i in range(n):
id, s = input().split()
if id == "insert": dic[s] = 1
else: print("yes" if s in dic else "no")
| 0 | null | 66,781,393,404,440 | 270 | 23 |
N = int(input())
flag = 0
ans = "No"
for i in range(N):
A,B = input().split()
if A == B:
flag += 1
else:
flag = 0
if flag == 3:
ans = "Yes"
break
print(ans) | N=int(input())
ans=0
ke=0
for i in range(N):
D,E=map(int,input().split())
if D==E:
ans+=1
else:
ans=0
if ans>=3:
ke=1
if ke==1:
print("Yes")
else:
print("No") | 1 | 2,483,343,736,088 | null | 72 | 72 |
import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
d, t, s = list(map(int, readline().split()))
print("Yes" if d <= t * s else "No")
if __name__ == '__main__':
solve()
|
def main():
d,t,s = map(int, input().split())
if s*t >= d:
print("Yes")
else:
print("No")
if __name__ == '__main__':
main()
| 1 | 3,579,750,662,642 | null | 81 | 81 |
import sys
def input(): return sys.stdin.readline().rstrip()
import math
X = int(input())
ans = False
money = 100
year = 0
while money < X:
money += money // 100
year += 1
print(year)
| from collections import Counter
N = int(input())
S = input()
counter = Counter(list(S))
ans = counter['R'] * counter['G'] * counter['B']
for d in range(1, N // 2 + 1):
for a, b, c in zip(S, S[d:], S[2 * d:]):
if a != b and b != c and c != a:
ans -= 1
print(ans)
| 0 | null | 31,571,165,949,048 | 159 | 175 |
S = str(input())
K = int(input())
li = []
cnt = 1
for i in range(len(S)-1):
if S[i] == S[i+1]:
cnt += 1
else:
li.append(cnt)
cnt = 1
li.append(cnt)
ans = 0
first = li[0]
last = li[-1]
if (S[0]==S[-1]) and (len(li)>1):
li[-1] += first
li.pop(0)
for l in li:
ans += l // 2
ans *= K
ans -= li[-1] // 2
ans += first//2 + last//2
elif S[0] == S[-1]:
ans = li[0] * K // 2
else:
for l in li:
ans += l // 2
ans *= K
print(ans) | rc=list(map(int,input().split()))
a=[[0 for x in range(rc[1]+1)]for x in range(rc[0]+1)]
for x in range(rc[0]):
code=list(map(int,input().split()))
result=0
for y in range(rc[1]):
a[x][y]=code[y]
result+=code[y]
a[x][rc[1]]=result
for y in range(rc[1]+1):
result=0
for x in range(rc[0]):
result+=a[x][y]
a[rc[0]][y]=result
for x in range(rc[0]+1):
string=""
for y in range(rc[1]+1):
string+=str(a[x][y])
if (y!=rc[1]):
string+=" "
print(string) | 0 | null | 88,456,905,712,868 | 296 | 59 |
# -*- coding:utf-8 -*-
import math
def insertion_sort(num_list, length, interval):
cnt = 0
for i in range(interval, length):
v = num_list[i]
j = i - interval
while j >= 0 and num_list[j] > v:
num_list[j+interval] = num_list[j]
j = j - interval
cnt = cnt + 1
num_list[j+interval] = v
return cnt
def shell_sort(num_list, length):
cnt = 0
h = 4
intervals = [1,]
while length > h:
intervals.append(h)
h = 3 * h + 1
for i in reversed(range(len(intervals))):
cnt = cnt + insertion_sort(num_list, length, intervals[i])
print(len(intervals))
print(*reversed(intervals))
print(cnt)
input_num = int(input())
input_list = list()
for i in range(input_num):
input_list.append(int(input()))
shell_sort(input_list, input_num)
for num in input_list:
print(num) | N = int(input())
purchase_price = int(input())
profit = -2000000000
for _ in range(N-1):
price = int(input())
profit = max(profit, (price-purchase_price))
purchase_price = min(price, purchase_price)
print(profit)
| 0 | null | 22,956,272,392 | 17 | 13 |
n=int(input())
l=list(map(int,input().split()))
prod=0
for i in range(n):
for j in range(i+1,n):
prod=prod+(l[i]*l[j])
print(prod)
| import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
N, K = map(int, input().split())
A = list(map(int, input().split()))
acc = [0] * (N + 1)
for i in range(1, N + 1):
acc[i] = acc[i - 1] + A[i - 1] - 1
acc[i] %= K
mp = defaultdict(int)
ans = 0
for j in range(N + 1):
if j >= K:
mp[acc[j - K]] -= 1
ans += mp[acc[j]]
mp[acc[j]] += 1
print(ans) | 0 | null | 153,455,274,003,022 | 292 | 273 |
import math
n = int(input())
ans = 0
for i in range(1,n+1):
ans += (i + i * (n // i)) * (n // i) / 2
print(int(ans)) | n = int(open(0).readline())
ans = 0
for i in range(1,n+1):
count = n//i
end = count*i
ans += count * (i+end)//2
print(ans) | 1 | 11,083,009,931,840 | null | 118 | 118 |
str1 = list(input())
str2 = list(input())
answer = len(str2)
for i in range(len(str1)-len(str2)+1):
count = 0
for j in range(len(str2)):
if not str1[i+j] == str2[j]:
count += 1
if count < answer:
answer = count
print(answer)
| S, T = [input() for i in range(2)]
ans = float("inf")
for start in range(len(S) - len(T) + 1):
diff = 0
for t, s in zip(T, S[start:]):
if t != s:
diff += 1
ans = min(ans, diff)
print(ans)
| 1 | 3,696,649,104,512 | null | 82 | 82 |
from collections import deque
from sys import stdin
input = stdin.readline
N = int(input())
neighborlist = [None for _ in range(N+1)]
for _ in range(1, N+1):
node, _, *L = list(map(int, input().split()))
neighborlist[node] = L
distancelist = [-1]*(N+1)
queue = deque()
queue.append(1)
distancelist[1] = 0
while queue:
node = queue.popleft()
distance = distancelist[node]
for neighbor in neighborlist[node]:
if distancelist[neighbor] == -1:
distancelist[neighbor] = distance + 1
queue.append(neighbor)
for i in range(1, N+1):
print(i, distancelist[i])
| import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
def readints():
return list(map(int, input().split()))
def nCr(n, r):
return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))
def has_duplicates2(seq):
seen = []
for item in seq:
if not(item in seen):
seen.append(item)
return len(seq) != len(seen)
def divisor(n):
divisor = []
for i in range(1, n+1):
if n % i == 0:
divisor.append(i)
return divisor
# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
g = [None]*n
for i in range(n):
g[i] = readints()
# print(g)
G = [None]*n
for i in range(n):
G[i] = []
# print(G)
for i in range(n):
if len(g[i]) >= 3:
for j in range(2, len(g[i])):
# print(g[i][j])
G[i].append(g[i][j])
#print('G', G)
dist = [-1]*n
dist[0] = 0
d = deque()
d.append(0)
# print(d)
while(len(d) != 0):
v = d.popleft()
if G[v] != []:
for nv in G[v]:
if dist[nv-1] != -1:
continue
dist[nv-1] = dist[v]+1
d.append(nv-1)
for i in range(n):
print(i+1, dist[i])
| 1 | 4,083,145,340 | null | 9 | 9 |
L = list(map(int,input().split()))
for i in range(5):
if L[i] != (i+1):
print(i+1)
| def main():
n = int(input())
P = [int(x) for x in input().split()]
minv = 2 * 10 ** 5 + 1
cnt = 0
for i in range(n):
if minv > P[i]:
minv = P[i]
cnt += 1
print(cnt)
if __name__ == '__main__':
main() | 0 | null | 49,211,265,120,860 | 126 | 233 |
n = int(input())
s = input()
from collections import Counter
a = [None] * n
for i in range(n):
if s[i] == "R":
a[i] = 0
if s[i] == "G":
a[i] = 1
if s[i] == "B":
a[i] = 2
c = [0] * 3
for v in a:
c[v] += 1
ans = 1
for v in c:
ans *= v
cnt = 0
for i in range(n - 2):
for j in range(i + 1, n - 1):
k = 2 * j - i
if j < k and k < n:
if s[i] == s[j]:
continue
if s[i] == s[k]:
continue
if s[j] == s[k]:
continue
cnt += 1
ans -= cnt
print(ans)
| N = int(input())
S = list(input())
R = []
G = []
B = [0 for _ in range(N)]
b_cnt = 0
for i in range(N):
if S[i] == 'R':
R.append(i)
elif S[i] == 'G':
G.append(i)
else:
B[i] = 1
b_cnt += 1
answer = 0
for r in R:
for g in G:
answer += b_cnt
if (g-r)%2 == 0 and B[(r+g)//2] == 1:
answer -= 1
if 0 <= 2*g-r < N and B[2*g-r] == 1:
answer -= 1
if 0 <= 2*r-g < N and B[2*r-g] == 1:
answer -= 1
print(answer) | 1 | 36,126,600,949,248 | null | 175 | 175 |
#もらうDP + 累積和
n, k = map(int, input().split())
mod = 998244353
li = []
for _ in range(k):
l, r = map(int, input().split())
li.append((l, r))
li.sort()
dp = [0]*(2*n+1)
s = [0] * (2*n+1)
dp[1] = 1
s[1] = 1
for i in range(2, n+1):
for t in li:
l, r = t
dp[i] += s[max(i-l, 0)]
dp[i] -= s[max(i-r-1, 0)]
dp[i] %= mod
s[i] = s[i-1] + dp[i]
s[i] %= mod
print(dp[i]%mod) | N, K = map(int, input().split())
L = [0] * K
R = [0] * K
for i in range(0, K):
L[i], R[i] = map(int, input().split())
moves = [0] * N
moves[0] = 1
rui_wa = [0] * N
rui_wa[0] = 1
for i in range(1, N):
for j in range(0, K):
l = max(i - L[j], 0)
r = max(i - R[j], 0)
if i - L[j] < 0:
continue
moves[i] += (rui_wa[l] - rui_wa[r - 1]) % 998244353
rui_wa[i] = (moves[i] + rui_wa[i - 1]) % 998244353
print(moves[N - 1] % 998244353)
| 1 | 2,702,508,749,708 | null | 74 | 74 |
import numpy as np
n=int(input())
d_i = list(map(int, input().split()))
d=np.array(d_i)
out=0
for i in range(1,n):
a=d_i.pop(0)
d_i.append(a)
out+=np.dot(d,np.array(d_i))
print(int(out/2)) |
N = int(input())
A = map(int, input().split())
AI = sorted(((a, i) for i, a in enumerate(A, 1)), reverse=True)
def solve(a, i, prev):
pl, pr, ps = i, 0, 0
for l, r, s in prev:
yield l, r-1, max(s+abs(r-i)*a, ps+abs(i-pl)*a)
pl, pr, ps = l, r, s
yield pl+1, pr, ps+abs(i-pl)*a
prev = [(1, N, 0)]
for a,i in AI:
prev = [*solve(a,i, prev)]
print(max(s for l, r, s in prev))
| 0 | null | 100,903,067,916,400 | 292 | 171 |
arr = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]
n = int(input())
for _ in range(n):
b, f, r, v = map(int, input().split())
arr[b-1][f-1][r-1] += v
for b in range(4):
for f in range(3):
print(' '+' '.join(str(x) for x in arr[b][f]))
if(b < 3):
print('#' * 20) | import sys
n = input()
a = [[[0]*10 for i in range(3)] for i in range(4)]
for i in xrange(n):
b = map(int, raw_input().split())
a[b[0]-1][b[1]-1][b[2]-1] += b[3]
for i in range(4):
for j in range(3):
for k in range(10):
sys.stdout.write(' %s' % a[i][j][k])
print ""
if i != 3:
print '#'*20 | 1 | 1,089,678,871,710 | null | 55 | 55 |
N = int(input())
A = {int(x): key for key, x in enumerate(input().split(), 1)}
sort_a = sorted(A.items(), key=lambda x: x[0])
print(' '.join([str(key) for x, key in sort_a]))
| n=int(input())
a=list(map(int,input().split()))
import numpy as np
x = np.argsort(a)
for i in range(n):
print(x[i]+1)
| 1 | 180,682,084,137,232 | null | 299 | 299 |
import sys
from math import log10, floor
print('\n'.join(map(str, [floor(log10(sum(map(int, ab.split())))) + 1 for ab in sys.stdin]))) | import sys,math
for x,y in (line.split() for line in sys.stdin):print(int(math.log10(int(x)+int(y))+1)) | 1 | 128,193,120 | null | 3 | 3 |
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7
# 個数制限なしナップサック問題
W,N = map(int,readline().split())
dp = [INF]*(W+1)
dp[0] = 0
for i in range(N):
w,v = map(int,readline().split())
# dp[j] = 重さj以下でつくれる最大の価値
for j in range(W+1):
dp[j] = min(dp[j],dp[max(j-w,0)] + v)
print(dp[W])
| N,K=map(int, raw_input().split())
mod=10**9+7
fact, inv_fact = [1], [1]
fact_tmp = 1
for i in range(1,N+1):
fact_tmp *= i
fact_tmp %= mod
fact.append(fact_tmp)
inv_fact.append(pow(fact_tmp, mod-2, mod))
def ncr(n,r):
if n < 0 or r < 0 or n < r: return 0
else: return (fact[n] * inv_fact[r] * inv_fact[n-r]) %mod
can_zero_num=min(N-1,K)
ans=0
for zero_num in range(can_zero_num+1):
ans+=ncr(N,zero_num)*ncr(N-1,N-zero_num-1)
print ans%mod | 0 | null | 74,362,435,760,690 | 229 | 215 |
import sys
import math
#from queue import *
import random
#sys.setrecursionlimit(int(1e6))
input = sys.stdin.readline
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
return(int(input()))
def inara():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
################################################################
############ ---- THE ACTUAL CODE STARTS BELOW ---- ############
n=inp()
print("ACL"*n)
| l = "abcdefghij"
def dfs(a, mx):
if len(a) == n:
print(a)
return
for i, s in enumerate(l):
if i == mx+1:
dfs(a+s, mx+1)
break
else:
dfs(a+s, mx)
n = int(input())
dfs("a", 0)
| 0 | null | 27,400,805,522,328 | 69 | 198 |
S = input()
h = S/3600
m = S%3600 / 60
s = S%60
print'%d:%d:%d' % (h,m,s) | #10_B
import math
a,b,C=map(int,input().split())
S=a*b*math.sin((C*2*math.pi)/360)/2
c=math.sqrt(a**2+b**2-2*a*b*math.cos((C*2*math.pi)/360))
L=a+b+c
h=2*float(S)/a
print(str(S)+'\n'+str(L)+'\n'+str(h)+'\n')
| 0 | null | 247,589,870,682 | 37 | 30 |
A, B = map(int, input().split())
C = A - (B*2)
C = 0 if C < 0 else C
print(C) | X=int(input())
if X<=599:
k=8
elif 600<=X<=799:
k=7
elif 800<=X<=999:
k=6
elif 1000<=X<=1199:
k=5
elif 1200<=X<=1399:
k=4
elif 1400<=X<=1599:
k=3
elif 1600<=X<=1799:
k=2
else:
k=1
print(k) | 0 | null | 86,800,853,634,738 | 291 | 100 |
n = int(input())
A = sorted(list(map(int, input().split())))
from collections import Counter
c = Counter(A)
MAX = 10 ** 6 + 1000
dp = [True] * MAX
for k, v in c.items():
if dp[k] == False: continue
if v > 1: dp[k] = False
for x in range(k + k, MAX, k):
dp[x] = False
res = 0
for x in range(n):
if dp[A[x]]: res += 1
print(res) | def resolve():
N, D = map(int, input().split())
P = [list(map(int, input().split())) for x in range(N)]
cnt = 0
for p in P:
d = (p[0] ** 2 + p[1] ** 2) ** 0.5
if d <= D:
cnt += 1
print(cnt)
resolve() | 0 | null | 10,248,614,513,020 | 129 | 96 |
def insertion_sort(l, g):
cnt = 0
for i in range(g, len(l)):
tmp = l[i]
j = i - g
while j >= 0 and l[j] > tmp:
l[j+g] = l[j]
cnt += 1
j -= g
l[j+g] = tmp
return l, cnt
def shell_sort(l, lg):
tot = 0
for g in lg:
sl, cnt = insertion_sort(l, g)
tot += cnt
return sl, tot
if __name__ == '__main__':
N = int(input())
l = []
for _ in range(N):
l.append(int(input()))
lg = [1]
while True:
gc = 3 * lg[-1] + 1
if gc > N:
break
lg.append(gc)
lg = lg[::-1]
print(len(lg))
print(' '.join(map(str, lg)))
sl, tot = shell_sort(l, lg)
print(tot)
for e in sl:
print(e)
| n=int(input())
dept=100000
for i in range(n):
dept*=1.05
if dept%1000!=0:
dept=dept-dept%1000+1000
print(int(dept)) | 0 | null | 14,892,422,688 | 17 | 6 |
#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() | n = int(input())
left = []
midplus = []
midzero = []
midminus = []
right = []
L = []
R = []
for i in range(n):
s = input()
l = 0
r = 0
for x in s:
if x == '(':
l += 1
else:
if l > 0:
l -= 1
else:
r += 1
if l > 0 and r == 0:
left.append((l, r))
elif l > 0 and r > 0:
if l > r:
midplus.append((r, l)) # a,b-a
elif l == r:
midzero.append((r,l))
else:
midminus.append((r, l))
elif l == 0 and r > 0:
right.append((l, r))
L.append(l)
R.append(r)
if sum(L) != sum(R):
print('No')
exit()
A = 0
B = 0
for x in left:
A += x[0]
for x in right:
B += x[1]
midplus = sorted(midplus, key=lambda x: (x[0], -x[1]))
midminus = sorted(midminus, key=lambda x: -x[1])
mid = midplus + midzero + midminus
l = A
r = 0
for a, b in mid:
if l < a:
print('No')
exit()
l -= a
l += b
print('Yes')
| 1 | 23,684,904,095,170 | null | 152 | 152 |
n = int(input())
sum = 0
for _ in range(n):
a = int(input())
if a == 2:
continue
for i in range(a):
x = i + 2
if a%x == 0:
sum += 1
break
if x > a ** 0.5:
break
print(n - sum)
| a,b,c,k=[int(i) for i in input().split()]
if a>=k:
print(k)
elif a+b>=k:
print(a)
else:
print(a-(k-a-b)) | 0 | null | 10,944,422,130,048 | 12 | 148 |
x = int(input())
cnt = 0
m_500 = x // 500
m_5 = (x - m_500*500) // 5
print(m_500*1000 + m_5*5) | n = int(input())
a = sorted(list(map(int, input().split())))
q = int(input())
l = [0]*(10**5+10)
for i in a:
l[i] += 1
s = sum(a)
for _ in range(q):
b, c = map(int, input().split())
s += (c - b) * l[b]
l[c] += l[b]
l[b] = 0
print(s)
| 0 | null | 27,528,756,707,022 | 185 | 122 |
def isPrime(x):
if x==2:
return True
if x<2 or x%2==0:
return False
for n in range(3,int(x**0.5)+1,2):
if x%n==0:
return False
return True
n=int(input())
num=[int(input()) for i in range(n)]
i=0
for nm in num:
if isPrime(nm):
i+=1
print(i) | data = []
for i in range(10):
data.append(int(input()))
data = sorted(data)
print(data[-1])
print(data[-2])
print(data[-3]) | 0 | null | 5,228,574,290 | 12 | 2 |
x,y = list(map(int,input().split()))
print(x*y) | n=int(input())-1;print(sum(n//-~i for i in range(n))) | 0 | null | 9,184,445,759,278 | 133 | 73 |
def main():
n = int(input())
plus = []
minus = []
for _ in range(n):
x, y = map(int, input().split())
plus.append(x + y)
minus.append(x - y)
plus_max = max(plus)
plus_min = min(plus)
minus_max = max(minus)
minus_min = min(minus)
print(max(plus_max - plus_min, minus_max - minus_min))
if __name__ == "__main__":
main() | n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
xy.sort(key=lambda x: x[0] + x[1])
mn1, mx1 = xy[0], xy[-1]
xy.sort(key=lambda x: x[0] - x[1])
mn2, mx2 = xy[0], xy[-1]
li = [mn1, mx1, mn2, mx2]
ans = 0
for x1, y1 in li:
for x2, y2 in li:
dist = abs(x1 - x2) + abs(y1 - y2)
ans = max(ans, dist)
print(ans)
| 1 | 3,357,165,600,612 | null | 80 | 80 |
import itertools
n, x, y = map(int, input().split())
k = [0] * n
for v in itertools.combinations(list(range(1,n+1)), 2):
k[min(abs(v[1]-v[0]),abs(x-min(v))+1+abs(y-max(v)))] += 1
for item in k[1:]:
print(item) | input()
A = list(map(int, input().split()))
sum = 0
for i in range(1, len(A)):
if A[i] < A[i-1]:
sum += A[i-1] - A[i]
A[i] = A[i-1]
print(sum)
| 0 | null | 24,392,607,399,158 | 187 | 88 |
n = int(input())
for a in range(1,50001):
if int(a*1.08) == n:
print(a)
exit()
print(':(') | n = int(input())
import math
a = n*100/108
b = (n*100+100)/108
ans = math.ceil(a) if math.ceil(a) < b else ":("
print(ans) | 1 | 125,980,381,892,350 | null | 265 | 265 |
import math
a,b,C=list(map(int,input().split()))
C_radian=math.radians(C)
S=a*b*math.sin(C_radian)/2
L=a+b+(a**2+b**2-2*a*b*math.cos(C_radian))**0.5
h=b*math.sin(C_radian)
print(S)
print(L)
print(h) | import math
a, b, C = [int(x) for x in input().split()]
C = math.radians(C)
l = a + b + math.sqrt(a * a + b * b - 2 * a * b * math.cos(C))
h = b * math.sin(C)
s = a * h / 2
print(s)
print(l)
print(h) | 1 | 173,235,386,368 | null | 30 | 30 |
n = int(raw_input())
S = map(int, raw_input().split())
q = int(raw_input())
T = map(int, raw_input().split())
ans = 0
for i in T:
if i in S:
ans += 1
print ans | N,X,T = map(int,input().split())
res = N*T//X
div = res//T
mod = res%T
if mod == 0:
print (res)
else :
print ((div+1)*T)
| 0 | null | 2,178,266,918,630 | 22 | 86 |
import sys
input = sys.stdin.buffer.readline
n = int(input())
l = list(map(int,input().split()))
l.sort()
mx = l[-1]+l[-2]
length = [0]*(mx+1)
for i in range(n):
for j in range(i+1,n):
length[l[i]+l[j]] -= 1
length[l[j]-l[i]+1] += 1
for i in range(1,mx+1):
length[i] += length[i-1]
minus = [0]*n
for i in range(n):
a = i
for j in range(i+1,n):
if l[i]*2 - 1 >= l[j]:
a += 1
minus[i] = a
#print(length)
#print(minus)
ans = 0
for i in range(n):
ans += length[l[i]] - minus[i]
print(ans//3) | import itertools
import bisect
n = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
for i in range(len(l)-2):
for j in range(i+1,len(l)):
k = bisect.bisect_left(l, l[i]+l[j])
if k > j:
ans += k - j -1
print(ans) | 1 | 172,356,384,878,502 | null | 294 | 294 |
S=str(input())
a=S.count('hi')
if a*2==len(S):
print('Yes')
else:
print("No") | s = input()
p = list(s)
if p[len(p) - 1] == "?": #最後が?だったら
p[len(p) - 1] = "D" # Dにする
for i in range(len(p) - 1):
if p[i] == "?": # ?だったら
if i == 0: # 最初の文字
if p[i + 1] == "D" or p[i + 1] == "?": # 二番目の文字がDか?
p[i] = "P"
else: # 二番目の文字がDか?でなかったら
p[i] = "D"
else:
p[i] = "D" # D
print("".join(p)) | 0 | null | 35,842,259,341,466 | 199 | 140 |
A,B,C,K=map(int,input().split())
print(1*min(A,K)-1*max(0,K-A-B))
| # A - Range Flip Find Route
h,w=map(int,input().split())
s=[input() for i in range(h)]
inf=10**18
dp=[[inf]*(w+1) for i in range(h+1)]
if s[0][0]=="#":
dp[0][0]=1
else:
dp[0][0]=0
for i in range(h):
for j in range(w):
for y,x in ([1,0],[0,1]):
ni,nj=i+y,j+x
if ni>=h or nj>=w:continue
c=0
if s[ni][nj]=="#" and s[i][j]==".":c=1
dp[ni][nj]=min(dp[ni][nj],dp[i][j]+c)
print(dp[h-1][w-1])
| 0 | null | 35,629,655,806,770 | 148 | 194 |
n = int(input())
S = list(map(int, input().split()))
def merge(A, left, mid, right):
cnt = 0
n1 = mid - left
n2 = right - mid
L = [0]*(n1+1)
R = [0]*(n2+1)
for i in range(n1):
L[i] = A[left + i]
for i in range(n2):
R[i] = A[mid + i]
L[n1] = float("inf")
R[n2] = float("inf")
i = 0
j = 0
for k in range(left, right):
cnt += 1
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
return cnt
def merge_sort(A, left, right):
if left + 1 < right:
mid = (left + right)//2
cnt_left = merge_sort(A, left, mid)
cnt_right = merge_sort(A, mid, right)
cnt_merge = merge(A, left, mid, right)
cnt = cnt_left + cnt_right + cnt_merge
else:
cnt = 0
return cnt
cnt = merge_sort(S, 0, n)
print(' '.join( map(str, S) ))
print(cnt)
| def merge(A, left, mid, right):
inf = float('inf')
L = A[left:mid]+[inf]
R = A[mid:right] + [inf]
i = j = 0
for k in range(left,right):
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
return right - left
def mergeSort(A, left, right, count = 0):
if left+1 < right:
mid = (left + right)//2
count = mergeSort(A, left, mid, count)
count = mergeSort(A, mid, right, count)
count += merge(A, left, mid, right)
return count
n = int(input())
A = list(map(int, input().split()))
ans = mergeSort(A, 0, n)
s = list(map(str, A))
print(' '.join(s))
print(ans)
| 1 | 111,775,618,460 | null | 26 | 26 |
N = int(input())
S = input()
T = ""
for s in S:
a = ord(s) + N
if a > ord("Z"):
a -= 26
T += chr(a)
print(T) | from collections import deque
import sys
input = sys.stdin.readline
class DoublyLinkedList:
def __init__(self):
self.doubly_linked_list = deque()
def insert(self, item):
self.doubly_linked_list.appendleft(item)
def delete(self, item):
if item in self.doubly_linked_list:
self.doubly_linked_list.remove(item)
def delete_first(self):
if self.doubly_linked_list:
self.doubly_linked_list.popleft()
def delete_last(self):
if self.doubly_linked_list:
self.doubly_linked_list.pop()
doubly_linked_list = DoublyLinkedList()
def command_controller(command, n):
global doubly_linked_list
if command == 'insert':
doubly_linked_list.insert(n)
if command == 'deleteFirst':
doubly_linked_list.delete_first()
if command == 'deleteLast':
doubly_linked_list.delete_last()
if command == 'delete':
doubly_linked_list.delete(n)
n = int(input())
for _ in range(n):
command = list(input().split())
command_controller(command[0], command[-1])
print(*doubly_linked_list.doubly_linked_list)
| 0 | null | 67,140,924,248,988 | 271 | 20 |
a, b = map(int, input().split())
if a > b: a, b = b, a
while True:
if b % a == 0:
print(a)
break
else:
b = b % a
if a > b: a, b = b, a | import sys
import math
(a, b) = tuple([int(s) for s in input().split()])
if a==b:
print(a)
sys.exit(0)
min = a if a < b else b
divisor = 1
i = 2
while i < math.sqrt(min):
if a % i == 0 and b % i == 0:
a = a / i
b = b / i
divisor = divisor * i
else:
i = i + 1
print(divisor) | 1 | 8,378,376,030 | null | 11 | 11 |
mark = ["S","H","C","D"]
numbers = ["1","2","3","4","5","6","7","8","9","10","11","12","13"]
cardlist = {}
for m in mark:
for n in numbers:
key = m + " " + n
cardlist[key] = 0
n = int(input())
for _ in range(n):
card = input()
cardlist[card] = 1
for card in cardlist:
if cardlist[card] == 0:
print(card)
| n = input()
cards = []
for i in range(n):
cards.append(raw_input().split())
marks = ['S', 'H', 'C', 'D']
for i in marks:
for j in range(1, 14):
if [i, str(j)] not in cards:
print i, j | 1 | 1,037,144,168,580 | null | 54 | 54 |
A,B = input().split()
if len(A)==2 or len(B)==2:
print(-1)
exit(0)
print(int(A)*int(B)) | text = ''
key= input().lower()
while True:
s = input()
if s.find("END_OF_TEXT") >= 0: break
try:
text += s + ' '
except:
break
print([x.lower() for x in text.split(" ")].count(key) ) | 0 | null | 80,282,391,836,962 | 286 | 65 |
from sys import stdin
readline = stdin.readline
def i_input(): return int(readline().rstrip())
def i_map(): return map(int, readline().rstrip().split())
def i_list(): return list(i_map())
def main():
N = i_input()
x, y = i_map()
z = x + y
w = x - y
z_max = z
z_min = z
w_max = w
w_min = w
for i in range(1, N):
x, y = i_map()
z = x + y
w = x - y
z_max = max(z_max, z)
z_min = min(z_min, z)
w_max = max(w_max, w)
w_min = min(w_min, w)
ans = max([z_max - z_min, w_max - w_min])
print(ans)
if __name__ == "__main__":
main()
| N = int(input())
plus = []
minus = []
for _ in range(N):
x, y = map(int, input().split())
plus.append(x + y)
minus.append(x - y)
print(max(max(plus) - min(plus), max(minus) - min(minus)))
| 1 | 3,453,840,923,870 | null | 80 | 80 |
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
oldp = min(a)+min(b)
for _ in range(M):
x, y, cp = map(int,input().split())
p = a[x-1]+b[y-1]-cp
if oldp > p:
oldp = p
print(oldp) | def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(input()) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import fractions
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
A, B, M = getNM()
# それぞれ冷蔵庫の値段
ref_a = getList()
ref_b = getList()
# 一枚だけ使える
ticket = [getList() for i in range(M)]
ans = min(ref_a) + min(ref_b)
for i in ticket:
opt = ref_a[i[0] - 1] + ref_b[i[1] - 1] - i[2]
ans = min(ans, opt)
print(ans) | 1 | 53,965,502,660,494 | null | 200 | 200 |
S = input()
Q = int(input())
T = 0
s = ""
for i in range(Q):
q = list(input().split())
if q[0] == "1":
T = (T+1) % 2
elif (T == 0 and q[1] == "1") or (T == 1 and q[1] == "2"):
s += q[2]
else:
S += q[2]
if T == 0:
S = s[::-1] + S
print(S)
else:
S = S[::-1] + s
print(S) | X, Y = map(int, input().split())
if X == 1 and Y == 1:
print(1000000)
else:
ans = 0
if X == 1:
ans += 300000
elif X == 2:
ans += 200000
elif X == 3:
ans += 100000
if Y == 1:
ans += 300000
elif Y == 2:
ans += 200000
elif Y == 3:
ans += 100000
print(ans)
| 0 | null | 99,538,812,992,972 | 204 | 275 |
for i in sorted([input() for _ in xrange(10)])[:-4:-1]: print i | # coding: utf-8
"""
aizu 0001
"""
import sys
# @profile
def main():
mountaines=[]
for line in sys.stdin:
mountaines.append(int( line ))
mountaines.sort(reverse=True)
for index,x in enumerate( mountaines ):
print x
if index >=2:
break
if __name__ == '__main__':
main() | 1 | 32,763,264 | null | 2 | 2 |
import sys
#input = sys.stdin.readline
def main():
A,B = map(int,input().split())
print(A*B)
if __name__ == "__main__":
main() | n = int(input())
c = input()
cntR = c.count('R')
print(c[:cntR].count('W')) | 0 | null | 11,056,210,605,618 | 133 | 98 |
import sys
for i in sys.stdin.readlines()[:-1]:
h,w = map(int,i.strip().split())
print(("#"*w+"\n")*h) | n=int(input())
if n%2==0:print(n//2)
else:print(n//2+1) | 0 | null | 29,919,713,779,758 | 49 | 206 |
a = int(input())
b = a % 2
if b == 0:
my_result = 0.5
else:
my_result = (a + 1) / (2 * a)
print(my_result) | n = input()
x = 1
print '',
while True:
if x > n:
break
if (x % 3 == 0) or ('3' in str(x)):
print x,
x += 1 | 0 | null | 89,355,244,370,160 | 297 | 52 |
n, k = [int(x) for x in input().split()]
p_list = sorted([int(x) for x in input().split()])
print(sum(p_list[:k])) | H=int(input())
def f(H):
if H==1:
return 1
elif H>1:
return 2*f(H//2)+1
re=0
re=f(H)
print(re) | 0 | null | 45,594,706,530,240 | 120 | 228 |
n, m, x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]
ans = 12*(10**5)+1
for i in range(2**n):
a = [0] * m
cs = 0
for j in range(n):
if (i >> j) & 1:
cs += ca[j][0]
for k in range(1, m+1):
a[k-1] += ca[j][k]
flag = True
for j in range(m):
if a[j] < x:
flag = False
break
if flag:
ans = min(ans, cs)
if ans == 12*(10**5)+1:
ans = -1
print(ans) | n,m,x = map(int,input().split())
ca = [list(map(int,input().split())) for i in range(n)]
c = [0]*n
a = [0]*n
for i in range(n):
c[i],a[i] = ca[i][0],ca[i][1:]
INF = 10**9
ans = INF
for i in range(1<<n):
understanding = [0]*m
cost = 0
for j in range(n):
if ((i>>j)&1):
cost += c[j]
for k in range(m):
understanding[k] += a[j][k]
ok = True
for s in range(m):
if understanding[s] < x:
ok = False
if ok:
ans = min(ans, cost)
if ans == INF:
ans = -1
print(ans)
| 1 | 22,058,511,940,498 | null | 149 | 149 |
import sys
def input(): return sys.stdin.readline().rstrip()
def per(n, r, mod=10**9+7): # 順列数
per = 1
for i in range(r):
per = per*(n-i) % mod
return per
def com(n, r, mod=10**9+7): # 組み合わせ数
r = min(n-r, r)
bunshi = per(n, r, mod)
bunbo = 1
for i in range(1, r+1):
bunbo = bunbo*i % mod
return bunshi*pow(bunbo, -1, mod) % mod
def comH(n, r, mod=10**9+7): # n種類からr個取る重複組み合わせ数
return com(n+r-1,r,mod)
def main():
s = int(input())
ans = 0
for i in range(1, (s//3)+1):
k = s-3*i
ans += comH(i,k)
#print(com(k+i,k),k+i,i)
print(ans % (10**9+7))
if __name__ == '__main__':
main() | s = int(input())
n = [1,0,0]
if s < 3:
print(n[s])
else:
for i in range(s-2):
n.append(n[-1]+n[-3])
print((n[-1])%1000000007) | 1 | 3,335,194,918,918 | null | 79 | 79 |
a = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]
a = a * 2
c = 0
z = input()
for i in range(0,7):
if z == a[i]:
for j in range(i + 1, 14):
if a[j] == "SUN":
print(j - i )
| d='SUN,MON,TUE,WED,THU,FRI,SAT'.split(',')
s=input()
print(7 - d.index(s)) | 1 | 132,879,942,801,452 | null | 270 | 270 |
print(int(input()[:2] != input()[:2])) | n,m = map(int,input().split())
x,y = map(int,input().split())
if n!=x:
print(1)
else:
print(0) | 1 | 124,184,814,033,984 | null | 264 | 264 |
#!/usr/bin/env python3
n,p = map(int,input().split())
s=input()
ans = 0
l = [0 for i in range(p)]
l[0] = 1
z = 0
ten = 1
tmp = 0
if p == 2 or p == 5:
if p == 2:
for i in range(n):
if int(s[i])%2 == 0:
ans+=i+1
if p == 5:
for i in range(n):
if int(s[i])%5 == 0:
ans+= i+1
else:
for i in s[::-1]:
i = int(i)
tmp=(tmp+i*ten)%p
ten = (ten*10)%p
l[tmp]+=1
for i in l:
ans+= i*(i-1)//2
print(ans)
| import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
N = INT()
A = LIST()
if N == 0:
if A[0] == 1:
print(1)
else:
print(-1)
exit()
cond1 = [0] * (N+1)
cond1[N] = A[N]
for i in range(N-1, -1, -1):
cond1[i] = cond1[i+1] + A[i]
if min(cond1) <= 0:
print(-1)
exit()
cond2 = [0] * (N+1)
cond2[0] = 1
for i in range(1, N+1):
cond2[i] = min(cond1[i], (cond2[i-1]-A[i-1]) * 2)
if min(cond2) <= 0:
print(-1)
exit()
if cond2[N] < A[N]:
print(-1)
exit()
ans = sum(cond2)
print(ans)
| 0 | null | 38,714,175,606,484 | 205 | 141 |
import math
a,b,c=map(int,input().split())
eps = 0.00000000000001
if 4*a*b<(c-a-b)**2 and (c-a-b)>0:
print('Yes')
else:
print('No') | # Begin Header {{{
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement
# }}} End Header
# _________コーディングはここから!!___________
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for x in combinations(l, 3):
if x[0]!=x[1] and x[0]!=x[2] and x[1]!=x[2]:
if x[0] + x[1] > x[2]:
ans+=1
print(ans) | 0 | null | 28,476,216,966,652 | 197 | 91 |
X=int(input())
if X<=599:
k=8
elif 600<=X<=799:
k=7
elif 800<=X<=999:
k=6
elif 1000<=X<=1199:
k=5
elif 1200<=X<=1399:
k=4
elif 1400<=X<=1599:
k=3
elif 1600<=X<=1799:
k=2
else:
k=1
print(k) | import sys
input = sys.stdin.readline
def main():
S = input().rstrip()
N = len(S)
if N % 2 == 0:
is_h = all(s == "h" for s in S[0::2])
is_i = all(s == "i" for s in S[1::2])
ans = "Yes" if is_h and is_i else "No"
else:
ans = "No"
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 29,925,715,160,988 | 100 | 199 |
from operator import itemgetter
N, T = [int(i) for i in input().split()]
data = []
for i in range(N):
data.append([int(i) for i in input().split()])
data.sort(key=itemgetter(0))
dp = [[0]*(T) for i in range(N)]
ans = data[0][1]
for i in range(1, N):
for j in range(T):
if j >= data[i-1][0]:
value1 = dp[i-1][j]
value2 = dp[i-1][j-data[i-1][0]] + data[i-1][1]
dp[i][j] = max(value1, value2)
else:
dp[i][j] = dp[i-1][j]
value3 = dp[i][T-1] + data[i][1]
ans = max(value3, ans)
print(ans)
| def main():
N, T = (int(i) for i in input().split())
AB = [[int(i) for i in input().split()] for j in range(N)]
AB.sort()
A = [a[0] for a in AB]
B = [b[1] for b in AB]
ans = 0
dp1 = [[0]*(T+1) for _ in range(N+1)]
for i in range(N):
for j in range(T):
t = j - A[i]
if 0 <= t:
dp1[i+1][j] = max(dp1[i][j], dp1[i][t] + B[i])
else:
dp1[i+1][j] = dp1[i][j]
ans = max(ans, dp1[i][T-1] + B[i])
print(ans)
if __name__ == '__main__':
main()
| 1 | 151,476,231,412,802 | null | 282 | 282 |
#!/usr/bin/env python3
import sys
from itertools import chain
# import numpy as np
# from itertools import combinations as comb
# from bisect import bisect_left, bisect_right, insort_left, insort_right
# from collections import Counter
MOD = 1000000007 # type: int
OFFSET = 10 ** 100
def k_in_n(k, n):
"""0〜n までの数からちょうど k 個の数を選ぶ時の最大最小"""
minimum = (k * (k - 1)) // 2
maximum = (k * (2 * n - k + 1)) // 2
return (minimum, maximum)
def solve(N: int, K: int):
keep = None # まだ加算されていない範囲
answer = 0
for k in range(K, N + 2):
if keep is None:
keep = k_in_n(k, N)
else:
minmax = k_in_n(k, N)
if minmax[0] + OFFSET <= keep[1]:
keep[0] -= OFFSET
keep[1] = minimum[1]
else:
answer = (answer + keep[1] - keep[0] + 1) % MOD
keep = minmax
if keep is not None:
answer = (answer + keep[1] - keep[0] + 1) % MOD
return answer
def main():
tokens = chain(*(line.split() for line in sys.stdin))
# N, K = map(int, input().split())
# N, K = input().strip()
# N, K = int(input())
N = int(next(tokens)) # type: int
K = int(next(tokens)) # type: int
answer = solve(N, K)
print(answer)
if __name__ == "__main__":
main()
| def main():
n, k = map(int, input().split())
mod = 10 ** 9 + 7
cnt = 0
for i in range(k, n+2):
l = (i-1)*i//2
h = (n+n-i+1)*i//2
cnt += h - l + 1
print(cnt % mod)
if __name__ == '__main__':
main() | 1 | 33,322,974,398,780 | null | 170 | 170 |
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) | N=int(input())
A = list(map(int,input().split()))
h = 0
for i in range(N-1):
if max(A[i], A[i+1]) == A[i]:
h += A[i] - A[i+1]
A[i+1] = A[i]
print(h) | 1 | 4,524,055,622,372 | null | 88 | 88 |
A,B=list(input().split())
A=int(A)
b=B.replace(".","")
print(A*int(b)//100)
| h,w=map(int,input().split())
s=[input() for _ in range(h)]
dp=[[10**9]*w for _ in range(h)]
dp[0][0]=(s[0][0]=='#')+0
for i in range(h):
for j in range(w):
a=dp[i-1][j]
b=dp[i][j-1]
if s[i-1][j] == "." and s[i][j] == "#":
a+=1
if s[i][j-1] == "." and s[i][j] == "#":
b+=1
dp[i][j]=min(a,b,dp[i][j])
print(dp[-1][-1])
| 0 | null | 32,708,400,556,832 | 135 | 194 |
class Combination:
"""
O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる
n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
使用例:
comb = Combination(1000000)
print(comb(5, 3)) # 10
"""
def __init__(self, n_max, mod=10**9+7):
self.mod = mod
self.modinv = self.make_modinv_list(n_max)
self.fac, self.facinv = self.make_factorial_list(n_max)
def __call__(self, n, r):
if n < r:
return 0
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
def make_factorial_list(self, n):
# 階乗のリストと階乗のmod逆元のリストを返す O(n)
# self.make_modinv_list()が先に実行されている必要がある
fac = [1]
facinv = [1]
for i in range(1, n+1):
fac.append(fac[i-1] * i % self.mod)
facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
return fac, facinv
def make_modinv_list(self, n):
# 0からnまでのmod逆元のリストを返す O(n)
modinv = [0] * (n+1)
modinv[1] = 1
for i in range(2, n+1):
modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
return modinv
def main():
n, k = map(int,input().split())
MOD = 10 ** 9 + 7
comb = Combination(10 ** 6)
ans = 0
if n - 1 <= k:
ans = comb(n + n - 1, n)
else:
ans = 1
for i in range(1,k+1):
ans += comb(n,i) * comb(n - 1, i)
ans %= MOD
print(ans)
if __name__ == "__main__":
main() | import sys
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
class CmbMod:
def __init__(self, n, p):
"""
二項係数nCr(n個の区別できるものからr個のものを選ぶ組み合わせの数)をpで割った余りを求める
"""
self.n = n
self.p = p
self.fact = [1, 1]
self.factinv = [1, 1]
self.inv = [0, 1]
def cmb_mod(self, n, r):
"""
二項係数nCr(mod p)をO(r)にて計算。nが大きいがrは小さい時に使用。
"""
numer, denom = 1, 1
for i in range(r):
numer = (numer * (n - i)) % self.p
denom = (denom * (i + 1)) % self.p
return (numer * pow(denom, self.p - 2, self.p)) % self.p
def prep(self):
"""
二項係数nCr(mod p)をO(1)で求める為の前処理をO(N)にて実行。
"""
for i in range(2, self.n + 1):
self.fact.append((self.fact[-1] * i) % self.p)
self.inv.append((-self.inv[self.p % i] * (self.p // i)) % self.p)
self.factinv.append((self.factinv[-1] * self.inv[-1]) % self.p)
def cmb_mod_with_prep(self, n, r):
"""
二項係数nCr(mod p)をO(1)で求める。事前にprepを実行する事。
"""
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return self.fact[n] * self.factinv[r] * self.factinv[n - r] % self.p
def resolve():
n, k = map(int, input().split())
k = min(n - 1, k)
cmb = CmbMod(n, mod)
cmb.prep()
res = 0
for i in range(k + 1):
res += (cmb.cmb_mod_with_prep(n, i) * cmb.cmb_mod_with_prep(n - 1, i)) % mod
res %= mod
print(res)
if __name__ == '__main__':
resolve()
| 1 | 67,262,219,381,178 | null | 215 | 215 |
n = int(input())
alst = list(map(int, input().split()))
if 0 in alst:
print(0)
exit()
else:
ans = 1
for i in range(n):
ans *= alst[i]
if ans > 10**18:
print('-1')
exit()
print(ans) | n=int(input())
an=[int(i) for i in input().split()]
ans=1
for a in an:
ans*=a
if ans>10**18:
ans=-1
break
if 0 in an:
ans=0
print(ans) | 1 | 16,273,951,278,288 | null | 134 | 134 |
def main():
import itertools
n,m,q = map(int,input().split())
Q = []
for i in range(q):
Q.append(list(map(int,input().split())))
cmb = [i for i in range(1,m+1)]
ans = 0
for que in itertools.combinations_with_replacement(cmb,n):
m = 0
for i in range(q):
[a,b,c,d] = Q[i]
if que[b-1]-que[a-1]==c:
m += d
if m>ans:
ans = m
print(ans)
if __name__ == "__main__":
main()
| from collections import deque
d = deque()
n = int(input())
for i in range(n):
s = input()
if s == "deleteFirst":
d.popleft()
elif s == "deleteLast":
d.pop()
elif s[:6] == "insert":
d.appendleft(int(s[7:]))
else:
delkey = int(s[7:])
if delkey in d:
d.remove(delkey)
print(" ".join(map(str,d)))
| 0 | null | 13,744,392,310,950 | 160 | 20 |
n = int(input())
dic = set()
for i in range(n):
cmd = input().split()
if cmd[0] == "insert":
dic.add(cmd[1])
else:
print("yes" if cmd[1] in dic else "no") | # -*- coding: utf-8 -*-
from sys import stdin
Dic = {}
n = int(stdin.readline().rstrip())
for i in range(n):
line = stdin.readline().rstrip()
if line[0] == 'i':
Dic[line[7:]] = 0
else:
print('yes' if line[5:] in Dic else 'no')
| 1 | 78,587,633,190 | null | 23 | 23 |
from sys import exit
N, K = [int(x) for x in input().split()]
H = list([int(x) for x in input().split()])
if len(H) <= K:
print(0)
exit()
H.sort(reverse=True)
H = H[K:]
print(sum(H))
| import math
while True:
try:
a, b = map(int, input().split())
gcd = math.gcd(a, b)
lcm = (a * b) // gcd
print(gcd, lcm)
except Exception:
break
| 0 | null | 39,352,967,476,396 | 227 | 5 |
n = int(input())
S = input()
r = S.count('R')
w = 0
ans = r
for i in range(n):
if S[i] == "W":
w += 1
elif S[i] == "R":
r -= 1
ans = min(ans,max(r,w))
print(ans) | N = int(input())
S = input()
r = S.count('R')
ans = r - S[:r].count('R')
print(ans) | 1 | 6,290,398,001,716 | null | 98 | 98 |
import math
r = int(input())
print(2*r*math.pi)
| import math
def main():
r = int(input())
print(r * math.pi * 2)
main()
| 1 | 31,310,329,044,080 | null | 167 | 167 |
def ABC_142_A():
N = int(input())
guusuu=0
for i in range(N+1):
if i%2 == 0 and i !=0:
guusuu+=1
print(1-(guusuu/N))
if __name__ == '__main__':
ABC_142_A() | n = float(input())
even_num = n // 2;
num = n - even_num
print(num/n)
| 1 | 177,433,074,497,600 | null | 297 | 297 |
a,b=input().split()
print((int(a)*int(b))//1) | a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if a == b:
print("NO")
As = v * t + a
Bs = w * t + b
if v > w:
if abs(a - b)/abs(v - w) <= t:
print("YES")
else:
print("NO")
else:
print("NO") | 0 | null | 15,614,622,065,602 | 133 | 131 |
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
N, M = map(int, readline().split())
if N == M:
print("Yes")
else:
print("No")
if __name__ == '__main__':
main()
| n,m=map(int,raw_input().split())
if m ==n:
print "Yes"
else:
print "No" | 1 | 83,156,394,965,440 | null | 231 | 231 |
N = int(input())
a = [int(x) for x in input().split()]
def selectionSort(A, N):
count = 0
for i in range(0,N):
minj = i
for j in range(i,N):
if A[minj] > A[j]:
minj = j
if i != minj:
tmp = A[minj]
A[minj] = A[i]
A[i] = tmp
count += 1
return A,count
ans,c = selectionSort(a,N)
print(*ans)
print(c) | # -*- coding: utf-8 -*-
def selection_sort(seq, l):
cnt = 0
for head_i in range(l):
flag = False
min_i = head_i
for target_i in range(head_i+1, l):
if seq[target_i] < seq[min_i]:
min_i = target_i
flag = True
if flag:
seq[head_i], seq[min_i] = seq[min_i], seq[head_i]
cnt += 1
print(' '.join([str(n) for n in seq]))
print(cnt)
def to_int(v):
return int(v)
def to_seq(v):
return [int(c) for c in v.split()]
if __name__ == '__main__':
l = to_int(input())
seq = to_seq(input())
selection_sort(seq, l) | 1 | 19,304,601,050 | null | 15 | 15 |
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
n = inp()
s = sorted(inplL(n))
tmp = ''
ans = []
anscnt = -1
for i in range(n):
if tmp == s[i]:
ans[anscnt][1] += 1
else:
ans.append([s[i],1])
anscnt += 1
tmp = s[i]
ans.sort(key=lambda x: x[1],reverse=True)
tmp = 0
ret = []
for i in range(len(ans)):
if i == 0 or tmp == ans[i][1]:
ret.append(''.join(ans[i][0]))
tmp = ans[i][1]
elif tmp != ans[i][1] :
break
ret.sort()
for i in range(len(ret)):
print(ret[i]) | import collections
N = int(input())
S_list = []
for i in range(N):
s = input()
S_list.append(s)
c = collections.Counter(S_list)
c_max = c.most_common()
max_num = c.most_common()[0][1]
ans_list = []
ans_list.append(c.most_common()[0][0])
for i in range(1, len(c_max)):
if c_max[i][1] != max_num:
break
else:
ans_list.append(c_max[i][0])
print(*sorted(ans_list), sep='\n')
| 1 | 70,442,859,662,760 | null | 218 | 218 |
print((int(input())) ** 3 / 27) |
def solve(L):
print((L / 3) ** 3)
if __name__ == '__main__':
L = int(input())
solve(L)
| 1 | 46,993,784,821,972 | null | 191 | 191 |
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.reverse()
ans=[]
for i in range(k,n):
if a[i]<a[i-k]:
ans.append("Yes")
else:
ans.append("No")
ans.reverse()
for s in ans:
print(s)
| #E
N,T=map(int,input().split())
A=[0 for i in range(N+1)]
B=[0 for i in range(N+1)]
for i in range(1,N+1):
A[i],B[i]=map(int,input().split())
dp1=[[0 for i in range(6001)] for j in range(N+1)]
dp2=[[0 for i in range(6001)] for j in range(N+2)]
for i in range(1,N+1):
for j in range(T+1):
if j>=A[i]:
dp1[i][j]=max(dp1[i-1][j],dp1[i-1][j-A[i]]+B[i])
else:
dp1[i][j]=dp1[i-1][j]
for i in range(N,0,-1):
for j in range(T+1):
if j>=A[i]:
dp2[i][j]=max(dp2[i+1][j],dp2[i+1][j-A[i]]+B[i])
else:
dp2[i][j]=dp2[i+1][j]
ans=0
for i in range(1,N+1):
for j in range(T):
ans=max(ans,dp1[i-1][j]+dp2[i+1][T-1-j]+B[i])
print(ans) | 0 | null | 79,078,667,953,970 | 102 | 282 |
S, T = input().split()
A, B = map(int, input().split())
U = input()
if S == U :
print(str(A - 1) + ' ' + str(B))
elif T == U :
print(str(A) + ' ' + str(B - 1)) | S,T = input().split()
N,M = list(map(int, input().split()))
U = input()
if U == S:
N = N - 1
if U == T:
M = M - 1
print(N, M)
| 1 | 71,834,993,436,960 | null | 220 | 220 |
n = int(input())
li = list(map(int, input().split()))
print(min(li), max(li), sum(li)) | #coding: UTF-8
a = raw_input()
l = map(int, raw_input().split())
l.sort()
x =l[0]
l.reverse()
y = l[0]
z = sum(l)
print "%d %d %d" %(x, y, z) | 1 | 726,726,671,178 | null | 48 | 48 |
import sys
import math
def is_prime(x):
if x == 2:
return True
if (x == 1) or (x % 2 == 0):
return False
for i in range(3, math.ceil(math.sqrt(x))+1, 2):
if x % i == 0:
return False
return True
if __name__ == '__main__':
element_number = int(input())
output = 0
for x in map(int, sys.stdin.readlines()):
if(is_prime(x)):
output += 1
print(output) | import math
def checkPrime(n):
for i in range(2, int(math.sqrt(n)) + 1):
if n % i == 0:
return False
return True
if __name__ == "__main__":
N = input()
cnt = 0
for i in range(N):
n = input()
if checkPrime(n):
cnt += 1
print cnt | 1 | 9,705,945,298 | null | 12 | 12 |
import math
def main():
data = []
while 1:
try:
n = input().split()
a = int(n[0])
b = int(n[1])
ans = int(math.log10(a+b)+1)
data.append(ans)
except EOFError:
break
for i in data:
print(i)
if __name__ == "__main__":
main() | while 1:
try:
print(len(str(sum(map(int,input().split())))))
except: break | 1 | 76,076,638 | null | 3 | 3 |
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())
mod = 10 ** 9 + 7
N, K = MI()
def num(self):
return (-2 * pow(self, 3) + 3 * N * pow(self, 2) + (3 * N + 8) * self) // 6
ans = num(N + 1) - num(K - 1)
print(ans % mod) | n,k = map(int,input().split());
kk = n-k+2
a = [0]*kk
for i in range(kk):
ii = i + k
p = ii*(ii-1);
q = ii*(2*n+1-ii);
a[i] = (q//2)-(p//2)+1;
con = 0;
for v in range(kk):
con = (con+a[v]) % 1000000007;
print(con); | 1 | 33,176,454,038,024 | null | 170 | 170 |
class Dice:
def __init__(self, data):
self.data = data
def move(self, direction):
if direction == 'E':
self.data[0],self.data[3],self.data[5],self.data[2] = \
self.data[3],self.data[5],self.data[2],self.data[0]
elif direction == 'N':
self.data[0],self.data[4],self.data[5],self.data[1] = \
self.data[1],self.data[0],self.data[4],self.data[5]
elif direction == 'S':
self.data[0],self.data[1],self.data[5],self.data[4] = \
self.data[4],self.data[0],self.data[1],self.data[5]
elif direction == 'W':
self.data[0],self.data[2],self.data[5],self.data[3] = \
self.data[2],self.data[5],self.data[3],self.data[0]
elif direction == 'LEFT':
self.data[2],self.data[4],self.data[3],self.data[1] = \
self.data[1], self.data[2],self.data[4],self.data[3]
def getTop(self):
return self.data[0]
def getRight(self):
return self.data[2]
def moveTopTo(self, target):
for i in range(4):
if self.data[0] == target:
break
self.move('W')
if self.data[1] == target:
self.move('S')
elif self.data[4] == target:
self.move('N')
def moveFrontTo(self, target):
for i in range(4):
if self.data[1] == target:
break
self.move('LEFT')
dice = Dice(input().split())
count = int(input())
result = []
for i in range(count):
(top, front) = [i for i in input().split()]
dice.moveTopTo(top)
dice.moveFrontTo(front)
result.append(dice.getRight())
for s in result:
print(s) | dice = input().split()
dice.insert(4, dice.pop(3))
right = []
def rightSearch(up, front):
index_up = dice.index(up)
index_front = dice.index(front)
if 1 <= index_up <= 4 and 1 <= index_front <= 4:
if index_up == 4 and index_front == 1:
return dice[0]
if index_up == 1 and index_front == 4:
return dice[5]
if index_up < index_front:
return dice[0]
else:
return dice[5]
elif (index_front == 0 or index_front == 5) and (index_up != 0 or index_up != 5):
if index_front == 0:
if index_up == 1:
return dice[4]
else:
return dice[index_up - 1]
else:
if index_up == 4:
return dice[1]
else:
return dice[index_up + 1]
else:
if index_up == 0:
if index_front == 4:
return dice[1]
else:
return dice[index_front + 1]
else:
if index_front == 1:
return dice[4]
else:
return dice[index_front - 1]
number = int(input())
for i in range(number):
up, front = input().split()
right.append(rightSearch(up, front))
for r in right:
print(r)
| 1 | 254,264,873,952 | null | 34 | 34 |
h, n = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
#(a,b):=(ダメージ,消費魔力)
dp = [float('inf')] * (h + 1)
dp[0] = 0
for i in range(h + 1):
for j in range(n):
if dp[i] == float('inf'):continue
temp_a = i + ab[j][0] if i + ab[j][0] < h else h
temp_b = dp[i] + ab[j][1]
dp[temp_a] = min(dp[temp_a], temp_b)
print(dp[-1])
#print(dp)
| n=int(input())
a=list(map(int,input().split()))
b=[]
for i in range(n):
tmp=[i+1,a[i]]
b.append(tmp)
b=sorted(b,key=lambda x:x[1])
ans=[]
for j in b:
ans.append(j[0])
print(*ans) | 0 | null | 130,372,271,537,880 | 229 | 299 |
# row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()
def make_divisors(n: int):
lower_divisors , upper_divisors = [], []
i = 1
while i*i <= n:
if n % i == 0:
lower_divisors.append(i)
if i != n // i:
upper_divisors.append(n//i)
i += 1
return lower_divisors, upper_divisors[::-1]
def resolve():
import sys
input = sys.stdin.readline
n = int(input().rstrip())
lower_divisors, _ = make_divisors(n)
print(min(lower_divisor + (n // lower_divisor) - 2 for lower_divisor in lower_divisors))
if __name__ == "__main__":
resolve()
| from collections import deque
N = int(input())
p = 1
for i in range(2,int(N ** (1/2)+1)):
if N % i == 0:
p = i
print(int(p+N/p)-2)
| 1 | 161,764,385,552,022 | null | 288 | 288 |
n = int(input())
a = list(map(int, input().split()))
def nim(x):
bx = [format(i,'030b') for i in x]
bz = ''.join([str( sum([int(bx[xi][i]) for xi in range(len(x))]) % 2) for i in range(30)])
return int(bz, 2)
nima = nim(a)
ans = [ str(nim([nima,aa])) for aa in a ]
print(' '.join(ans) ) | def main():
N=int(input())
A=list(map(int,input().split()))
s=sum(A)
Q=int(input())
d=[0]*(10**5 +1)#各数字の個数
for i in A:
d[i]+=1
for i in range(Q):
B,C=map(int,input().split())
s += (C-B)*d[B]
print(s)
d[C]+=d[B]
d[B]=0
if __name__ == "__main__":
main() | 0 | null | 12,310,071,060,720 | 123 | 122 |
n=int(input())
if n<600:
print(8)
exit()
if n<800:
print(7)
exit()
if n<1000:
print(6)
exit()
if n<1200:
print(5)
exit()
if n<1400:
print(4)
exit()
if n<1600:
print(3)
exit()
if n<1800:
print(2)
exit()
if n<2000:
print(1)
exit() | n = int(input())
print(10 - n // 200) | 1 | 6,742,704,268,250 | null | 100 | 100 |
from fractions import gcd
a,b=map(int,input().split())
print(a*b//gcd(a,b)) | N, K, S = map(int, input().split())
ans = []
n = N-K
for i in range(K):
ans.append(S)
for i in range(n):
if S == 10**9:
ans.append(S-1)
else:
ans.append(S+1)
ans=[str(a) for a in ans]
ans=" ".join(ans)
print(ans) | 0 | null | 102,055,726,475,150 | 256 | 238 |
import sys
import math
prime_numbers = [2, 3, 5, 7]
def prime_numbers_under(num):
global prime_numbers
prime_number_max = max(prime_numbers)
if prime_number_max > num:
return prime_numbers
for i in range(prime_number_max + 1, num + 1):
check_max = math.floor(math.sqrt(i))
for j in prime_numbers:
if j <= check_max:
if i % j == 0:
break
else:
prime_numbers.append(i)
return prime_numbers
def main():
amount = 0
length = int(input())
for _ in range(0, length):
i = int(input())
check_max = math.floor(math.sqrt(i))
for j in prime_numbers_under(check_max):
if j <= check_max:
if i % j == 0:
break
else:
amount += 1
print(amount)
return 0
if __name__ == '__main__':
main() | a,b=map(int,input().split())
def gcd(x, y):
while y:
x, y = y, x % y
return x
l=gcd(a,b)
print(int(a*b/l))
| 0 | null | 56,500,403,210,690 | 12 | 256 |
N = int(input())
X = [list(map(int,input().split())) for _ in range(N)]
A = sorted([X[i][0] for i in range(N)])
B = sorted([X[i][1] for i in range(N)])
if N%2==1:
a = A[N//2]
b = B[N//2]
print(b-a+1)
else:
a = (A[(N-1)//2]+A[N//2])/2
b = (B[(N-1)//2]+B[N//2])/2
print(int((b-a)/0.5)+1)
| import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
s = input()
n = len(s)
a = [None]*n
c = 0
v = 1
for i in range(n-1, -1, -1):
c = (c + v*int(s[i])) % 2019
a[i] = c
v *= 10
v %= 2019
from collections import Counter
cc = Counter(a)
ans = 0
for k,v in cc.items():
ans += v*(v-1)//2
ans += cc[0]
print(ans) | 0 | null | 24,166,206,288,032 | 137 | 166 |
n, k = map(int, input().split())
p = list(map(int, input().split()))
sortPrice = sorted(p)
# print(sortPrice)
price = []
for i in range(0, k):
price.append(sortPrice[i])
print(sum(price)) | a,b = map(int,input().split())
s = list(map(int,input().split()))
w = []
for i in range(b):
w.append(min(s))
s.remove(min(s))
print(sum(w)) | 1 | 11,671,825,402,720 | null | 120 | 120 |
list1 = input().split(' ')
list1 = list(map(int, list1))
a = list1[0]
b = list1[1]
c = list1[2]
divisor = []
answer = []
for index in range(0, c):
index += 1
if c % index == 0:
divisor.append(index)
for test_digit in range(a, b + 1):
if test_digit in divisor:
answer.append(test_digit)
print(len(answer)) | x = input().split(" ")
a = 0
for i in range(int(x[0]),int(x[1]) + 1):
if int(x[2]) % int(i) == 0:
a += 1
print(a)
| 1 | 565,930,691,170 | null | 44 | 44 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.