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
|
---|---|---|---|---|---|---|
W=input()
s=0
while True:
T=list(input().split())
if T==['END_OF_TEXT']:
break
else:
for i in T:
if i.lower()==W.lower():
s+=1
print(s)
|
#coding:UTF-8
while True:
a,op,b = map(str,raw_input().split())
a = int(a)
b = int(b)
if op == '+':
print(a+b)
elif op == '-':
print(a-b)
elif op == '*':
print(a*b)
elif op == '/':
print(a/b)
else:
break
| 0 | null | 1,257,759,809,400 | 65 | 47 |
from collections import Counter
def main():
MOD = 2019
s = input()
n = len(s)
t = [0] * (n + 1)
# n-1,n-2,...,0
for i in range(n - 1, -1, -1):
t[i] = t[i + 1] + pow(10, n - i - 1, MOD) * int(s[i])
t[i] %= MOD
c = Counter(t)
cnt = 0
for v in c.values():
cnt += v * (v - 1) // 2
print(cnt)
if __name__ == '__main__':
main()
|
# http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=4647653#1
import sys
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline
class Graph:
def __init__(self, n, dictated=False, decrement=True, edge=[]):
self.n = n
self.dictated = dictated
self.decrement = decrement
self.edge = [set() for _ in range(self.n)]
self.parent = [-1]*self.n
self.info = [-1]*self.n
for x, y in edge:
self.add_edge(x,y)
def add_edge(self,x,y):
if self.decrement:
x -= 1
y -= 1
self.edge[x].add(y)
if self.dictated == False:
self.edge[y].add(x)
def add_adjacent_list(self,i,adjacent_list):
if self.decrement:
self.edge[i] = set(map(lambda x:x-1, adjacent_list))
else:
self.edge[i] = set(adjacent_list)
def path_detector(self, start=0, time=0):
"""
:param p: スタート地点
:return: 各点までの距離と何番目に発見したかを返す
"""
edge2= []
for i in range(self.n):
edge2.append(sorted(self.edge[i], reverse=True))
p, t = start, time
self.parent[p] = -2
full_path = [(p + self.decrement,t)]
while True:
if edge2[p]:
q = edge2[p].pop()
if q == self.parent[p] and not self.dictated:
""" 逆流した時の処理 """
""""""""""""""""""""
continue
if self.parent[q] != -1:
""" サイクルで同一点を訪れた時の処理 """
""""""""""""""""""""
continue
self.parent[q] = p
p, t = q, t + 1
full_path.append((p + self.decrement, t))
else:
""" 探索完了時の処理 """
full_path.append((p + self.decrement, t))
""""""""""""""""""""
if p == start and t == time:
break
p, t = self.parent[p], t-1
""" 二度目に訪問時の処理 """
""""""""""""""""""""
return full_path
def path_list(self):
"""
:return: 探索経路を返す。
"""
self.parent = [-1]*self.n
res = []
for p in range(self.n):
if self.parent[p] == -1:
res.append(self.path_detector(start=p, time=1))
return res
def draw(self):
"""
:return: グラフを可視化
"""
import matplotlib.pyplot as plt
import networkx as nx
if self.dictated:
G = nx.DiGraph()
else:
G = nx.Graph()
for x in range(self.n):
for y in self.edge[x]:
G.add_edge(x + self.decrement, y + self.decrement)
nx.draw_networkx(G)
plt.show()
def make_graph(dictated=False, decrement=True):
"""
自己ループの無いグラフを生成。N>=2
:param dictated: True = 有効グラフ
:param decrement: True = 1-indexed
:return:
"""
import random
N = random.randint(2, 5)
if N > 2:
M_max = (3*N-6)*(1+dictated)
else:
M_max = 1
graph = Graph(N, dictated, decrement)
for _ in range(random.randint(0,M_max)):
graph.add_edge(*random.sample(range(decrement, N+decrement), 2))
return graph
##################################################################
# 入力が隣接リストの場合
##################################################################
N = int(input()) # 頂点数
graph = Graph(N,dictated=True, decrement=True)
for i in range(N): # [[頂点1と連結している頂点の集合], [頂点2と連結している頂点の集合],...]
points = list(map(int, input().split()))[2:]
graph.add_adjacent_list(i, points)
data = graph.path_list()
from itertools import chain
data = list(chain.from_iterable(data))
res = [[i+1,0,0] for i in range(N)]
for time, a in enumerate(data, start=1):
i = a[0] - 1
if res[i][1]:
res[i][2] = time
else:
res[i][1] = time
for a in res:
print(*a)
| 0 | null | 15,320,873,066,712 | 166 | 8 |
N=int(input())
A=list(map(int,input().split()))
L=[[10**10,0]]
for i in range(N):
L.append([A[i],i])
L.sort(reverse=True)
#print(L)
DP=[[0 for i in range(N+1)]for j in range(N+1)]
#j=右に押し込んだ数
for i in range(1,N+1):
for j in range(i+1):
if j==0:
DP[i][j]=DP[i-1][j]+L[i][0]*abs(L[i][1]-(i-1))
#print(DP,DP[i-1][j]+L[i][0]*abs(L[i][1]-(i-1)))
elif j==i:
DP[i][j]=DP[i-1][j-1]+L[i][0]*abs(L[i][1]-(N-j))
#print(DP,DP[i-1][j-1]+L[i][0]*abs(L[i][1]-(N-j)))
else:
DP[i][j]=max(DP[i-1][j]+L[i][0]*abs(L[i][1]-(i-1-j)),DP[i-1][j-1]+L[i][0]*abs(L[i][1]-(N-j)))
#print(DP,DP[i-1][j]+L[i][0]*abs(L[i][1]-(i-1-j)),DP[i-1][j-1]+L[i][0]*abs(L[i][1]-(N-j)))
print(max(DP[-1]))
|
N = int(input())
A = list(map(int, input().split()))
B = sorted(A, reverse=True)
C = [0] * N
i = 0
while(1):
if i >= N:
break
for j in range(N):
if A[j] == B[i]:
C[i] = j
if i != N-1 and B[i] == B[i+1]:
i += 1
i += 1
dp = [[0] * (N+1) for i in range(N+1)]
for i in range(N+1):
for j in range(i+1):
if j > 0 and i-j > 0:
dp[j][i-j] = max([dp[j-1][i-j] + B[i-1] * abs(C[i-1] - (j-1)), dp[j][i-j-1] + B[i-1] * abs(C[i-1] - (N-1-(i-j-1)))])
elif j == 0 and i-j > 0:
dp[j][i-j] = dp[j][i-j-1] + B[i-1] * abs(C[i-1] - (N-1-(i-j-1)))
elif i-j == 0 and j > 0:
dp[j][i-j] = dp[j-1][i-j] + B[i-1] * abs(C[i-1] - (j-1))
ans = 0
for i in range(N+1):
ans = max([ans, dp[i][N-i]])
print(ans)
| 1 | 33,765,243,521,174 | null | 171 | 171 |
N, M = map(int, input().split())
A = list(map(int, input().split()))
days = N - sum(A)
print(days) if days >= 0 else print('-1')
|
from itertools import starmap
(lambda *_: None)(
*map(print,
starmap(lambda h, w: ''.join(['#'*w + '\n'] * h),
map(lambda ss: map(int, ss),
map(str.split, iter(input, '0 0'))))))
| 0 | null | 16,355,202,637,948 | 168 | 49 |
n,m=map(int,input().strip().split(' '))
if n % 2 == 1:
for i in range(1,m+1):
print(i,n-i)
else:
used=set()
prev = n+1
for i in range(1,m+1):
prev-=1
if abs(i-prev)*2==n:
prev-=1
while abs(i-prev) in used:
prev-=1
print(i,prev)
used.add(abs(i-prev))
used.add(n-abs(i-prev))
|
N, M = map(int, input().split())
# if N is odd
if M & 1:
odd_head = 1
odd_tail = M + 1
even_head = M + 2
even_tail = M + 2 + M - 1
while odd_tail - odd_head > 0:
print(odd_head, odd_tail)
odd_head += 1
odd_tail -= 1
while even_tail - even_head > 0:
print(even_head, even_tail)
even_head += 1
even_tail -= 1
else:
odd_head = 1
odd_tail = 1 + (M - 1)
even_head = M + 1
even_tail = M + 1 + M
while odd_tail - odd_head > 0:
print(odd_head, odd_tail)
odd_head += 1
odd_tail -= 1
while even_tail - even_head > 0:
print(even_head, even_tail)
even_head += 1
even_tail -= 1
| 1 | 28,505,283,155,062 | null | 162 | 162 |
N,R = map(int,input().split())
print((R,R +100*(10-N))[N<=10])
|
import math
n=int(input())
a = []
b = []
ans = 0
def z(p,q,r,s):
return ((p-r)**2+(q-s)**2)**0.5
for i in range(n):
x,y=map(int,input().split())
a.append(x)
b.append(y)
for i in range(n):
for j in range(i+1,n):
ans += 2*z(a[i],b[i],a[j],b[j])
ans /= n
print(ans)
| 0 | null | 105,643,712,561,520 | 211 | 280 |
n = int(input())
cnt_ac = 0
cnt_wa = 0
cnt_tle = 0
cnt_re = 0
for i in range(n):
s = input()
if s == 'AC':
cnt_ac += 1
elif s == 'WA':
cnt_wa += 1
elif s == 'TLE':
cnt_tle += 1
elif s == "RE":
cnt_re += 1
print('AC x ', cnt_ac)
print('WA x ', cnt_wa)
print('TLE x ', cnt_tle)
print('RE x ', cnt_re)
|
n = int(input())
lst = [0] *4
for i in range(n):
a = input()
if a == 'AC':
lst[0] += 1
if a == 'WA':
lst[1] += 1
if a == 'TLE':
lst[2] += 1
if a == 'RE':
lst[3] += 1
print('AC x',lst[0])
print('WA x',lst[1])
print('TLE x',lst[2])
print('RE x',lst[3])
| 1 | 8,697,692,031,130 | null | 109 | 109 |
import time as ti
class MyQueue(object):
"""
My Queue class
Attributes:
queue: queue
head
tail
"""
def __init__(self):
"""Constructor
"""
self.length = 50010
self.queue = []
counter = 0
while counter < self.length:
self.queue.append(Process())
counter += 1
self.head = 0
self.tail = 0
def enqueue(self, name, time):
"""enqueue method
Args:
name: enqueued process name
time: enqueued process time
Returns:
None
"""
self.queue[self.tail].name = name
self.queue[self.tail].time = time
self.tail = (self.tail + 1) % self.length
def dequeue(self):
"""dequeue method
Returns:
None
"""
self.queue[self.head].name = ""
self.queue[self.head].time = 0
self.head = (self.head + 1) % self.length
def is_empty(self):
"""check queue is empty or not
Returns:
Bool
"""
if self.head == self.tail:
return True
else:
return False
def is_full(self):
"""chech whether queue is full or not"""
if self.tail - self.head >= len(self.queue):
return True
else:
return False
class Process(object):
"""process class
"""
def __init__(self, name="", time=0):
"""constructor
Args:
name: name
time: time
"""
self.name = name
self.time = time
def forward_time(self, time):
"""time forward method
Args:
time: forward time interval
Returns:
remain time
"""
self.time -= time
return self.time
def time_forward(my_queue, interval, current_time, end_time_list):
"""
Args:
my_queue: queue
interval: time step interval
current_time: current time
"""
value = my_queue.queue[my_queue.head].forward_time(interval)
if value <= 0:
current_time += (interval + value)
end_time_list.append([my_queue.queue[my_queue.head].name, current_time])
# print my_queue.queue[my_queue.head].name, current_time
my_queue.dequeue()
elif value > 0:
current_time += interval
name, time = my_queue.queue[my_queue.head].name, \
my_queue.queue[my_queue.head].time
my_queue.dequeue()
my_queue.enqueue(name, time)
return current_time
my_queue = MyQueue()
n, q = [int(x) for x in raw_input().split()]
counter = 0
while counter < n:
name, time = raw_input().split()
my_queue.enqueue(name, int(time))
counter += 1
end_time_list = []
current_time = 0
while not my_queue.is_empty():
current_time = time_forward(my_queue, q, current_time, end_time_list)
for data in end_time_list:
print data[0], data[1]
|
from collections import deque
nameq = deque()
timeq = deque()
n, q = map(int, raw_input().split())
for _ in xrange(n):
name, time = raw_input().split()
nameq.append(name)
timeq.append(int(time))
t = 0
while nameq:
name = nameq.popleft()
time = timeq.popleft()
if time > q:
time -= q
nameq.append(name)
timeq.append(time)
t += q
else:
t += time
print "%s %d" % (name, t)
| 1 | 43,431,856,678 | null | 19 | 19 |
import sys
import math
from collections import defaultdict
from collections import deque
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def make_grid_int(h, w, num): return [[int(num)] * w for _ in range(h)]
def main():
R, C, K = NMI()
grid = make_grid_int(R, C, 0)
for i in range(K):
r_, c_, v_, = NMI()
grid[r_ - 1][c_ - 1] = v_
dp = [[[0 for _ in range(C + 2)] for _ in range(R + 2)] for _ in range(4)]
for i in range(R + 1):
for j in range(C + 1):
for k in range(4):
a = dp[k][i][j]
try:
v = grid[i][j]
except:
v = 0
if k == 3:
dp[0][i + 1][j] = max(a, dp[0][i + 1][j])
continue
dp[0][i + 1][j] = max(a, a + v, dp[0][i + 1][j])
dp[k][i][j + 1] = max(a, dp[k][i][j + 1])
dp[k + 1][i][j + 1] = max(a + v, dp[k + 1][i][j + 1])
print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C]))
if __name__ == "__main__":
main()
|
r,c,k=map(int,input().split())
lst=[[0]*(c+1) for i in range(r+1)]
for i in range(k):
s,t,u=map(int,input().split())
lst[s][t]=u
dp1=[[0]*(c+1) for i in range(r+1)]
dp2=[[0]*(c+1) for i in range(r+1)]
dp3=[[0]*(c+1) for i in range(r+1)]
for i in range(1,r+1):
for j in range(1,c+1):
dp1[i][j]=max(dp1[i][j-1],dp1[i-1][j]+lst[i][j],dp2[i-1][j]+lst[i][j],dp3[i-1][j]+lst[i][j])
dp2[i][j]=max(dp2[i][j-1],dp1[i][j-1]+lst[i][j])
dp3[i][j]=max(dp3[i][j-1],dp2[i][j-1]+lst[i][j])
print(max(dp1[-1][-1],dp2[-1][-1],dp3[-1][-1],0))
| 1 | 5,544,643,892,480 | null | 94 | 94 |
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))
n=int(input())
a=lmp()
ans=0
for i in range(n-1):
for j in range(i+1,n):
ans+=a[i]*a[j]
print(ans)
|
import itertools
N = int(input())
D = [int(x) for x in input().split()]
ans = 0
for v in itertools.combinations(D,2):
ans += v[0]*v[1]
print(ans)
| 1 | 168,291,580,486,102 | null | 292 | 292 |
x = int(input())
a = 360
for _ in range(360):
if a%x == 0:
print(a//x)
break
else:
a += 360
|
X = int(input())
for i in range(1,1000000000):
if ( X * i ) % 360 == 0:
print(i)
quit()
| 1 | 13,196,286,610,848 | null | 125 | 125 |
n,*a=map(int,open(0).read().split())
a.sort()
m=a[-1]+1
cnt=[0]*m
for ai in a:
if cnt[ai]!=0:
cnt[ai]+=1
continue
for i in range(ai,m,ai):
cnt[i]+=1
ans=0
for ai in a:
ans+=(cnt[ai]==1)
print(ans)
|
def resolve():
n = int(input())
p = list(map(int, input().split()))
m = 1000000000
ans = 0
for i in range(n):
if p[i] <= m:
ans += 1
m = min(m, p[i])
print(ans)
return
if __name__ == "__main__":
resolve()
| 0 | null | 50,120,950,780,760 | 129 | 233 |
x, y = map(int, input().split())
ans = 0
if x + y == 2:
ans += 400000
ans += ((4-min(4, x)) + (4-min(4, y))) * 100000
print(ans)
|
class Combination:
def __init__(self, mod, max_num):
self.mod = mod
self.fac = [0] * max_num
self.finv = [0] * max_num
self.inv = [0] * max_num
self.fac[0], self.fac[1] = 1, 1
self.finv[0], self.finv[1] = 1, 1
self.inv[1] = 1
for i in range(2, max_num):
self.fac[i] = self.fac[i-1] * i % mod
self.inv[i] = mod - self.inv[mod % i] * (mod // i) % mod
self.finv[i] = self.finv[i - 1] * self.inv[i] % mod
def calc(self, n, k):
if n < k:
return 0
if n < 0 or k < 0:
return 0
return self.fac[n] * (
self.finv[k] * self.finv[n - k] % self.mod) % self.mod
n, k = map(int, input().split())
com = Combination(1000000007, 500000)
ret = 1
min_val = min(n, k)
for i in range(1, min_val+1):
if i != n:
ret += com.calc(n, i) * com.calc(n-1, i)
ret %= 10 ** 9 + 7
else:
ret += 0
print(ret)
| 0 | null | 103,863,024,869,312 | 275 | 215 |
import math
while True:
n = int(input());
if n == 0:
break;
A = list(map(int, input().split()));
h = sum(A) / len(A);
k = 0;
for j in range(0,n):
k += (A[j] - h)**2;
print(math.sqrt(k/n));
|
import sys
array = list(map(int,input().split()))
print(array.index(0)+1)
| 0 | null | 6,884,909,499,090 | 31 | 126 |
n = int(input())
arr = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))
result = set()
for i in range(2**n):
tmp = 0
for j in range(n):
if i >> j & 1:
tmp += arr[j]
result.add(tmp)
for x in m:
print("yes" if x in result else "no")
|
n = int(input())
A = list(map(int, input().split()))
q = int(input())
B = list(map(int, input().split()))
s = set()
def check(i, m):
if i == n:
s.add(m)
return
check(i+1, m+A[i])
check(i+1, m)
check(0,0)
for i in B:
if i in s:
print('yes')
else:
print('no')
| 1 | 98,253,569,312 | null | 25 | 25 |
list = []
n = int(raw_input())
list = map(int, raw_input().split(' '))
list.reverse()
for i in range(len(list)):
print list[i],
|
print(['No', 'Yes']['7' in input()])
| 0 | null | 17,539,140,373,052 | 53 | 172 |
d=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split()))for _ in range(d)]
class Score:
def __init__(self,t):
self.x=[d*[0]for _ in range(26)]
self.scor=0
self.ans=[]
for i in range(d):
v=t[i]
self.scor+=s[i][v]
for j in range(26):
if j!=v:
self.x[j][i]+=1
if i!=0:self.x[j][i]+=self.x[j][i-1]
self.scor-=c[j]*self.x[j][i]
self.ans.append(self.scor)
def solve(self):
return [self.scor,self.ans]
t=[int(input())-1 for _ in range(d)]
x=Score(t)
_,ans=x.solve()
for i in ans:print(i)
|
D = int(input())
C = [int(T) for T in input().split()]
S = [[] for TD in range(0,D)]
for TD in range(0,D):
S[TD] = [int(T) for T in input().split()]
Type = 26
Last = [0]*Type
Sats = 0
for TD in range(0,D):
Test = int(input())-1
Last[Test] = TD+1
Sats += S[TD][Test]
for TC in range(0,Type):
Sats -= C[TC]*(TD+1-Last[TC])
print(Sats)
| 1 | 9,978,758,523,400 | null | 114 | 114 |
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9
import itertools
def main():
n = int(input())
D = list(map(int, input().split()))
C = itertools.combinations(D, 2)
ans = 0
for c in C:
ans += c[0]*c[1]
print(ans)
if __name__ == '__main__':
main()
|
def main():
k = int(input())
s = input()
if len(s) <= k:
print(s)
else:
print(f"{s[:k]}...")
if __name__ == "__main__":
main()
| 0 | null | 93,702,722,041,164 | 292 | 143 |
sm=0
for i in range(1,int(input())+1):
if (i%3)*(i%5)>0:
sm+=i
print(sm)
|
N = int(input())
l = [i for i in range(1, N + 1) if i % 3 != 0 and i % 5 != 0]
s = sum(l)
print(s)
| 1 | 35,006,201,713,016 | null | 173 | 173 |
import sys
N=input()
i = 1
for i in range(1,N+1):
if (i % 3) == 0 :
sys.stdout.write(" ")
sys.stdout.write("%d" % i)
else:
if (i % 10 ) == 3 :
sys.stdout.write(' ')
sys.stdout.write("%d" % i)
else:
if (i/10)%10 == 3:
#print (i/10)%10,"a"
sys.stdout.write(' ')
sys.stdout.write("%d" % i)
else:
if (i/100)%10 == 3:
sys.stdout.write(' ')
sys.stdout.write("%d" % i)
else:
if (i/100)%10 == 3:
sys.stdout.write(' ')
sys.stdout.write("%d" % i)
else:
if(i/1000)%10 == 3:
sys.stdout.write(' ')
sys.stdout.write("%d" % i)
print ""
|
teki, hissatsu = list(map(int, input().split(' ')))
l = sorted(list(map(int, input().split(' '))))[:max(0, teki-hissatsu)]
print(sum(l))
| 0 | null | 40,093,634,084,222 | 52 | 227 |
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
n=int(input())
if n%2==1:
print(0)
else:
m=n//2
ans=0
for i in range(1,30):
ans+=m//(5**i)
print(ans)
if __name__=='__main__':
main()
|
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 8 18:25:14 2020
@author: liang
"""
H, W = map(int, input().split())
field = [input() for i in range(H)]
def Init():
return [[-1]*W for _ in range(H)]
ans = -1
from collections import deque
q = deque()
adj = ((1,0), (-1,0), (0,1), (0,-1))
def BFS(y,x):
def isValid(t):
if t[0] < 0 or t[0] >= H or t[1] < 0 or t[1] >= W or field[t[0]][t[1]] == "#":
return False
return True
d = Init()
if field[y][x] == '#':
return -1
d[y][x] = 0
q.append((y,x))
res = 0
while q:
cur = q.popleft()
for a in adj:
nex = (cur[0]+a[0], cur[1]+a[1])
if isValid(nex) and (d[nex[0]][nex[1]]== -1 or d[nex[0]][nex[1]] > d[cur[0]][cur[1]]+1):
d[nex[0]][nex[1]] = d[cur[0]][cur[1]]+1
#if res < d[nex[0]][nex[1]]:
# res = d[nex[0]][nex[1]]
res = max(res, d[nex[0]][nex[1]])
q.append(nex)
return res
for i in range(H):
for j in range(W):
tmp = BFS(i,j)
if tmp > ans:
ans = tmp
print(ans)
| 0 | null | 105,041,087,434,268 | 258 | 241 |
class Dice:
def __init__(self,faces):
self.faces = tuple(faces)
def N(self):
self.faces = (self.faces[1], self.faces[5], self.faces[2],
self.faces[3], self.faces[0], self.faces[4])
def S(self):
self.faces = (self.faces[4], self.faces[0], self.faces[2],
self.faces[3], self.faces[5], self.faces[1])
def W(self):
self.faces = (self.faces[2], self.faces[1], self.faces[5],
self.faces[0], self.faces[4], self.faces[3])
def E(self):
self.faces = (self.faces[3], self.faces[1], self.faces[0],
self.faces[5], self.faces[4], self.faces[2])
def number(self, face_id):
return self.faces[face_id - 1]
dice = Dice(list(map(int, input().split())))
x=input()
for i in x:
if i == "N":
dice.N()
elif i == "S":
dice.S()
elif i == "W":
dice.W()
elif i == "E":
dice.E()
print(dice.number(1))
|
n = int(input())
a = list(map(int, input().split()))
dic = {}
ans = ''
for i in range(n):
dic[a[i]] = i+1
for i in range(n):
ans = ans + str(dic[i+1]) + ' '
print(ans)
| 0 | null | 90,332,847,497,540 | 33 | 299 |
n = int(input())
a = list(map(int, input().split()))
ruiseki = 0
count = 0
for i in range(n-1):
ruiseki += a[i]
count += ruiseki * a[i+1]
mod = 10**9 + 7
if count >= mod:
print(count%mod)
else:
print(count)
|
a, b = 1, 1
for i in range(int(input())):
a, b = b, a + b
print(a)
| 0 | null | 1,945,259,537,860 | 83 | 7 |
x,y = map(int,input().split())
k = [0,3,2,1] + [0]*1000
ans = k[x]+k[y]
if x == y == 1:
ans += 4
print(ans*100000)
|
n = int(input())
arr = [int(x) for x in input().split()]
d = {}
for ele in arr:
if ele in d:
d[ele] += 1
else:
d[ele] = 1
q = int(input())
s = sum(arr)
while(q>0):
a,b = [int(x) for x in input().split()]
if a in d:
x = d[a]
s -= int(x*a)
s += int(x*b)
d.pop(a)
if b in d:
d[b]+=x
else:
d[b] = x
print(s)
q-=1
| 0 | null | 76,439,916,341,760 | 275 | 122 |
x, y = map(int, input().split())
total_money = 0
if x >= 4:
total_money += 0
elif x == 3:
total_money += 100000
elif x == 2:
total_money += 200000
elif x == 1:
total_money += 300000
if y >= 4:
total_money += 0
elif y == 3:
total_money += 100000
elif y == 2:
total_money += 200000
elif y == 1:
total_money += 300000
if x == 1 and y == 1:
total_money += 400000
print(total_money)
|
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10
#solve
def solve():
x, y = LI()
d = defaultdict(int)
d[3] = 100000
d[2] = 200000
d[1] = 300000
print(d[1] * 2 + 400000 if x == y == 1 else d[x] + d[y])
return
#main
if __name__ == '__main__':
solve()
| 1 | 140,440,718,299,968 | null | 275 | 275 |
t = int(input())
h = int(t/3600)
m = int(t%3600/60)
s = int(t%3600%60)
print(str(h) + ":" + str(m) + ":" + str(s))
|
n = int(input())
buf = list(map(int,input().split()))
a = []
for i in range(n):
a.append([buf[i],i])
a = sorted(a,reverse=True)
dp = [[0]*(n+1) for i in range(n+1)]
for i in range(n):
for j in range(n-i):
cur = i+j
temp1 = dp[i][j]+a[cur][0]*abs(n-1-a[cur][1]-j)
temp2 = dp[i][j]+a[cur][0]*abs(a[cur][1]-i)
dp[i+1][j] = max(dp[i+1][j],temp2)
dp[i][j+1] = max(dp[i][j+1],temp1)
print(max([max(i) for i in dp]))
| 0 | null | 16,944,009,285,452 | 37 | 171 |
N, M = map(int, input().split())
if N%2:
for i in range(M):
print(2+i, N-i)
else:
used = set()
s = 1
for i in list(range(2, M+1, 2)[::-1])+list(range(1, M+1, 2)[::-1]):
while 1:
if not s in used and not (s+i) in used:
used.add(s)
used.add(s+i)
print(s, s+i)
break
s += 1
|
def main():
n, m = map(int, input().split())
# マイナスの場合は leader であり、同時にサイズ(*-1)を保持する
uf = [-1] * (n+1)
def uf_leader(a):
if uf[a]<0:
return a
uf[a] = uf_leader(uf[a])
return uf[a]
def uf_unite(a, b):
ua, ub = uf_leader(a), uf_leader(b)
if ua==ub:
return False
if uf[ua] > uf[ub]:
ua, ub = ub, ua
uf[ua] += uf[ub]
uf[ub] = ua
return True
def uf_leaders():
return [v for v in range(1,n+1) if uf[v]<0]
# print(uf[1:])
for _ in range(m):
a, b = map(int, input().split())
uf_unite(a, b)
# print(uf[1:])
# print(uf_leaders())
ans = len(uf_leaders())-1
print(ans)
main()
| 0 | null | 15,447,383,022,588 | 162 | 70 |
a,b = map(int,input().split())
low = a*2
high = a*4
if b%2 != 0:
print("No")
elif b<low or b>high:
print("No")
else:
print("Yes")
|
X,Y=list(map(int,input().split()))
judge=False
for i in range(0,X+1):
if i*2+(X-i)*4==Y:
judge=True
if judge:
print("Yes")
else:
print("No")
| 1 | 13,784,508,295,362 | null | 127 | 127 |
n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))
p=[x-1 for x in p]
mi=set(range(n))
g={}
# g[id]=[ary]
while mi:
x0=mi.pop()
ary=[c[x0]]
x=x0
while p[x]!=x0:
x=p[x]
mi.discard(x)
ary.append(c[x])
cnt=len(ary)
tmp=0
ary*=2
cary=[tmp]
for x in ary:
tmp+=x
cary.append(tmp)
g[x0]=[cnt,cary]
ans=-float('inf')
for cnt,cary in g.values():
x,y=divmod(k,cnt)
tmp1=max(0,cary[cnt]*x)
tmp2=-float('inf')
for i in range(cnt):
for j in range(y):
tmp2=max(tmp2,cary[i+j+1]-cary[i])
ans=max(ans,tmp1+tmp2)
if x:
tmp1=max(0,cary[cnt]*(x-1))
tmp2=-float('inf')
for i in range(cnt):
for j in range(cnt):
tmp2=max(tmp2,cary[i+j+1]-cary[i])
ans=max(ans,tmp1+tmp2)
print(ans)
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
low = 0
top = max(a) + 1
while top - low > 1:
mid = (top + low) // 2
cnt = 0
for i in range(n):
if a[i] % mid == 0:
cnt += (a[i] // mid) - 1
else:
cnt += a[i] // mid
if cnt <= k:
top = mid
else:
low = mid
print(top)
| 0 | null | 5,887,215,496,382 | 93 | 99 |
def main():
x = int(input())
now = 100
ans = 0
while True:
now = now * 101 // 100
ans += 1
if now >= x:
break
print(ans)
if __name__ == "__main__":
main()
|
X = int(input())
money = 100
time = 0
while money < X:
time += 1
money = money * 101 // 100
print(time)
| 1 | 27,039,124,676,980 | null | 159 | 159 |
n=int(input())
x=[0]*n
y=[0]*n
z=[]
w=[]
for i in range(n):
x[i],y[i]= list(map(int, input().strip().split()))
z.append(x[i]+y[i])
w.append(x[i]-y[i])
a=max(z)-min(z)
b=max(w)-min(w)
print(max(a,b))
|
#!/usr/bin/env python3
def main():
A1, A2, A3 = map(int, input().split())
A=A1+A2+A3
if A >=22:
ans='bust'
else:
ans='win'
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 61,425,784,022,020 | 80 | 260 |
X, K, D = map(int, input().split())
if X - K * D >= 0:
ans = abs(X - K * D)
elif X + K * D <= 0:
ans = abs(X + K * D)
else:
n = int(abs(X - K * D) / (2 * D))
ans = min(abs(X - K * D + n * 2 * D), abs(X - K * D + (n + 1) * 2 * D))
print(ans)
|
X,K,D = map(int, input().split())
if X<0:
X = -X
if X - K*D >= 0:
print(X-K*D)
else:
i = 0
while True:
i+=1
X -= D
if X < 0:
break
if (K-i) % 2 == 0:
print(abs(X))
else:
print(D-abs(X))
| 1 | 5,223,809,621,622 | null | 92 | 92 |
n = int(input())
a_ = [int(i) for i in input().split()]
a = [[a_[i], i+1] for i in range(n)]
a.sort(reverse=True)
dp = [[0 for i in range(n+1)] for j in range(n+1)]
x_plus_y = 0
ans = 0
for i in range(n):
if x_plus_y == 0:
dp[0][1] = a[i][0] * abs((n - a[i][1]))
dp[1][0] = a[i][0] * abs((a[i][1] - 1))
else:
for x in range(x_plus_y + 1):
y = x_plus_y - x
dp[x][y+1] = max(dp[x][y+1], a[i][0] * abs((n - y) - a[i][1]) + dp[x][y])
dp[x+1][y] = max(dp[x+1][y] , a[i][0] * abs((a[i][1] - (1+x))) + dp[x][y])
if x_plus_y == n-1:
ans = max(ans, dp[x][y+1], dp[x+1][y])
x_plus_y += 1
print(ans)
|
n = int(input())
a = list(map(int,input().split()))
b = list((x,i) for i,x in enumerate(a))
b.sort(reverse=True)
dp = [[0]*(n+1-i) for i in range(n+1)]
for i in range(n):
x,idx = b[i]
for j in range(i+1):
k = i-j
if dp[j+1][k] < dp[j][k] + x*(idx-j):
dp[j+1][k] = dp[j][k] + x*(idx-j)
if dp[j][k+1] < dp[j][k] + x*((n-1-k)-idx):
dp[j][k+1] = dp[j][k] + x*((n-1-k)-idx)
ans = 0
for i in range(n+1):
if ans < dp[i][n-i]:
ans = dp[i][n-i]
print(ans)
| 1 | 33,698,742,404,040 | null | 171 | 171 |
import math
import numpy as np
k = int(input())
Map = [[0 for j in range(k)] for i in range(k)]
for i in range(1,k+1):
for j in range(1,k+1):
tmp = math.gcd(i,j)
Map[i-1][j-1] = tmp
Map[j-1][i-1] = tmp
ans = 0
for i in range(1,k+1):
for j in range(1,k+1):
tmp_ans = Map[i-1][j-1]
for x in range(1,k+1):
ans += Map[tmp_ans-1][x-1]
print(ans)
|
l, r, d = map(int, input().split())
result=0
for i in range(r-l+1):
if (l+i) % d == 0:
result+=1
print(result)
| 0 | null | 21,648,776,282,630 | 174 | 104 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
N, M, K = map(int, input().split())
result = 0 # max
a_time = list(map(int, input().split()))
b_time = list(map(int, input().split()))
sum = 0
a_num = 0
for i in range(N):
sum += a_time[i]
a_num += 1
if sum > K:
sum -= a_time[i]
a_num -= 1
break
i = a_num
j = 0
while i >= 0:
while sum < K and j < M:
sum += b_time[j]
j += 1
if sum > K:
j -= 1
sum -= b_time[j]
if result < i + j:
result = i + j
i -= 1
sum -= a_time[i]
print(result)
|
x, y = map(int, input().split())
answer = 0
for a in [x, y]:
if a == 3:
answer += 100000
elif a == 2:
answer += 200000
elif a == 1:
answer += 300000
else:
pass
if x == 1 and y == 1:
answer += 400000
print(answer)
| 0 | null | 75,243,395,467,862 | 117 | 275 |
X, Y = map(int, input().split())
if (X+Y) % 3 != 0:
print(0)
else:
# 経路
def C(n, r, mod):
num = 1
den = 1
for i in range(r):
num *= n-i
num %= mod
den *= i+1
den %= mod
return (num * pow(den, mod-2, mod)) % mod
mod = 10**9 + 7
minimun = (X+Y)/3
if X >= minimun and Y >= minimun:
X -= minimun
Y -= minimun
print(C(int(X+Y), int(X), mod))
else:
print(0)
|
x,y=map(int,input().split())
def cmb(n, r, mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7
N = 10**6
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range( 2, N + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
if (-x+2*y)%3!=0:
ans=0
else:
a=(-x+2*y)//3
b=(2*x-y)//3
ans=cmb(a+b,a,mod)
print(ans)
| 1 | 149,929,995,063,330 | null | 281 | 281 |
a,b = raw_input().split(" ")
a = int(a)
b = int(b)
if a < b:
print "a < b"
elif a > b:
print "a > b"
else:
print "a == b"
|
a,b = map(int,input().split())
if a<b:
print("a < b")
elif a==b:
print("a == b")
elif a>b:
print("a > b")
| 1 | 362,261,461,728 | null | 38 | 38 |
N = int(input())
print(int((N + 1) / 2))
|
while True:
num = list(map(int,input().split()))
if(num[0] == 0 and num[1] == 0):
break
else:
if(num[0] > num[1]):
print("%d %d" %(num[1],num[0]))
else:
print("%d %d" %(num[0],num[1]))
| 0 | null | 29,859,108,091,714 | 206 | 43 |
from collections import defaultdict
def main():
_, S = open(0).read().split()
indices, doubled_indices = defaultdict(list), defaultdict(set)
for i, c in enumerate(S):
indices[c].append(i)
doubled_indices[c].add(2 * i)
cnt = S.count("R") * S.count("G") * S.count("B")
for x, y, z in ["RGB", "GBR", "BRG"]:
cnt -= sum(i + j in doubled_indices[z] for i in indices[x] for j in indices[y])
print(cnt)
if __name__ == "__main__":
main()
|
while True:
line = list(map(int, input().split()))
if line==[0,0]: break
print(' '.join(map(str,sorted(line))))
| 0 | null | 18,436,800,075,290 | 175 | 43 |
import sys
input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]
tin=lambda : map(int, input().split())
lin=lambda : list(IN())
mod=1000000007
#+++++
def main():
#a = int(input())
#b , c = tin()
s = input()
if s[0] == '>':
s = '<' + s
if s[-1] == '<':
s = s + '>_'
else:
s = s + '_'
dd = []
pre = '<'
count = [1,0]
for c in s[1:]:
if c == '<' and pre == '<':
count[0] += 1
elif c == '>' and pre == '>':
count[1] += 1
elif c == '>' and pre == '<':
pre = '>'
count[1] = 1
elif c == '<' and pre == '>':
pre = '<'
dd.append(count)
count=[1,0]
else:
dd.append(count)
ret_sum = 0
for l, r in dd:
ret_sum += (r*(r+1)//2) + (l*(l+1)//2) - min(r,l)
print(ret_sum)
#+++++
isTest=False
def pa(v):
if isTest:
print(v)
def input_clipboard():
import clipboard
input_text=clipboard.get()
input_l=input_text.splitlines()
for l in input_l:
yield l
if __name__ == "__main__":
if sys.platform =='ios':
if input_method==input_methods[0]:
ic=input_clipboard()
input = lambda : ic.__next__()
elif input_method==input_methods[1]:
sys.stdin=open('inputFile.txt')
else:
pass
isTest=True
else:
pass
#input = sys.stdin.readline
ret = main()
if ret is not None:
print(ret)
|
def main():
n = int(input())
As = list(map(int, input().split()))
ans = 1
if 0 in As:
print(0)
return
for a in As:
ans *= a
if ans > 10**18:
print(-1)
return
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 86,168,588,475,570 | 285 | 134 |
a,b,c = map(int, input().split())
k = int(input())
for i in range(k):
if a >= b:
b *= 2
continue
if b >= c:
c *= 2
continue
print("Yes" if a < b and b < c else "No")
|
a,b,c= list(map(int,input().split()))
n = int(input())
ans = "No"
for i in range(n):
if b <= a:
b = 2*b
elif c <= b:
c = 2*c
if a<b<c:
ans = "Yes"
print(ans)
| 1 | 6,954,656,222,400 | null | 101 | 101 |
t = int(input())
h = int(t/3600)
m = int(t%3600/60)
s = int(t%3600%60)
print(str(h) + ":" + str(m) + ":" + str(s))
|
s = int(input())
h = s // 3600
m = s % 3600 // 60
s = s % 60
print(f'{h}:{m}:{s}')
| 1 | 333,076,478,272 | null | 37 | 37 |
import sys
input = sys.stdin.readline
d = {}
for _ in range(int(input())):
s = input().replace("\n", "")
if s in d:
d[s] += 1
else:
d[s] = 1
x = max(d.values())
l = sorted(s for (s, i) in d.items() if i == x)
print(*l, sep="\n")
|
X, K, D = map(int, input().split())
X = abs(X)
if X >= K * D:
ans = X - K * D
else:
n, d = divmod(X, D)
ans = d
if (K - n) % 2:
ans = D - d
print(ans)
| 0 | null | 37,346,327,970,378 | 218 | 92 |
#abc145_d
m = 10**9+7
x,y = map(int,input().split())
fac =[0]*(10**6+1)
a = max(x,y)
b = min(x,y)
cnt = 0
fac[0]=1
while a != b:
a -= 2
b -= 1
cnt +=1
fac[cnt] = (fac[cnt-1]*cnt)%m
if a<0 or b <0:
print(0)
exit()
c = a//3
d = cnt
if a%3 != 0:
print(0)
exit()
else:
while a != 0:
a -= 1
b -= 2
cnt +=1
fac[cnt] = (fac[cnt-1]*cnt)%m
a -= 2
b -= 1
cnt +=1
fac[cnt] = (fac[cnt-1]*cnt)%m
n = ((fac[cnt])%m)*(pow(fac[c+d],m-2,m))*(pow(fac[c],m-2,m))
print(n%m)
|
# 726 diff 1000
# 解法 836 XYへ到達する場合はどの経路も合計の長さは同じ = 動き方1,2の合計は同じ.
# なので合計値 L がわかればLについてmove1=i,move2=L-iとして,実際の経路の構成の仕方は,L_C_iなので
move1 = [1,2]
move2 = [2,1]
X,Y = map(int,input().split())
# まず,目的地へ到達できるか?到達できる場合は合計どれだけの移動量が必要かを計算する
max_move1 = int(Y/2)
move2_num = -1
move1_num = -1
for i in range(max_move1+1):
rest = [X-i,Y-2*i]
if (X-i) == 2*(Y-2*i):
move1_num = i
move2_num = (Y-2*i)
if move1_num == -1:
print(0)
exit()
# 到達するのに必要な合計の移動量がわかったので,それらの並べ替えについて考える.
# 求めるのは nCk すなわち,いつもの奴
large = 10**9 + 7
# mod(x^p-1,p) = 1 よってmod(x^p-2,p) = 1/x となる.
ans = 1
for i in range(move1_num):
ans *= (move1_num+move2_num - i)
ans %= large
for j in range(2,move1_num+1):
ans *= pow(j,large-2,large)
ans %= large
print(ans)
| 1 | 149,700,393,767,638 | null | 281 | 281 |
n = int(input())
a = list(map(int, input().split()))
b = [0 for i in range(n)]
cnt = 0
for i in range(n):
if i - a[i] >= 0:
cnt += b[i - a[i]]
if i + a[i] < n:
b[i + a[i]] += 1
print(cnt)
|
#coding: UTF-8
def X_Cubic(x):
return x*x*x
if __name__=="__main__":
x = input()
ans = X_Cubic(int(x))
print(ans)
| 0 | null | 13,155,615,620,290 | 157 | 35 |
height = []
for i in range(10):
height.append(input())
height.sort(reverse=True)
for i in range(3):
print(height[i])
|
m1=m2=m3=0
for i in range(10):
m3=max(m3,int(input()))
if m3>m2:m2,m3=m3,m2
if m2>m1:m1,m2=m2,m1
print(m1)
print(m2)
print(m3)
| 1 | 25,088,490 | null | 2 | 2 |
from scipy.sparse.csgraph import floyd_warshall
N,M,L,*X = map(int, open(0).read().split())
ls = X[:3*M]
Els = [[0]*N for i in range(N)]
Q = X[3*M]
query = X[3*M+1:]
for a,b,c in zip(*[iter(ls)]*3):
if c<=L:
Els[a-1][b-1] = c
Els[b-1][a-1] = c
dist = floyd_warshall(Els)
Els2 = [[0]*N for i in range(N)]
for i in range(N):
for j in range(N):
if dist[i][j]<=L:
Els2[i][j] = 1
ans = floyd_warshall(Els2)
for s,t in zip(*[iter(query)]*2):
if ans[s-1][t-1]==float('inf'):
print(-1)
continue
print(int(ans[s-1][t-1])-1)
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix
INF = 10**12
N, M, L = map(int, readline().split())
ABCQST = np.array(read().split(), dtype=np.int64)
ABC = ABCQST[:3*M]
A = ABC[::3]; B = ABC[1::3]; C = ABC[2::3]
Q = ABCQST[3*M]
ST = ABCQST[3*M + 1:]
S = ST[::2]; T = ST[1::2]
graph = csr_matrix((C, (A, B)), (N + 1, N + 1))
d = floyd_warshall(graph, directed=False)
d[d <= L] = 1
d[d > L] = INF
d = floyd_warshall(d, directed=False).astype(int)
d[d == INF] = 0
d -= 1
print('\n'.join(d.astype(str)[S, T]))
| 1 | 172,760,396,162,340 | null | 295 | 295 |
def my_print(s: str, args: [int]) -> str:
return s[int(args[0]): int(args[1]) + 1]
def my_reverse(s: str, args: list) -> str:
start = int(args[0])
end = int(args[1]) + 1
to_reverse_string = s[start:end]
return s[:start] + to_reverse_string[::-1] + s[end:]
def my_replace(s: str, args: list) -> str:
start = int(args[0])
end = int(args[1]) + 1
return s[:start] + args[2] + s[end:]
def resolve():
s = input()
n = int(input())
for _ in range(n):
f, *args = input().split()
if f == 'print':
print(my_print(s, args))
if f == 'reverse':
s = my_reverse(s, args)
if f == 'replace':
s = my_replace(s, args)
resolve()
|
A, B, K = [int(x) for x in input().split()]
if A >= K:
print("{} {}".format(A-K, B))
exit()
K -= A
A = 0
if B >= K:
print("{} {}".format(A, B-K))
exit()
print("{} {}".format(0, 0))
| 0 | null | 52,939,943,508,434 | 68 | 249 |
string = input()
n = int(input())
for _ in range(n):
query = input().split()
if query[0] == 'replace':
op, a, b, p = query
a, b = int(a), int(b)
string = string[:a] + p + string[b + 1:]
elif query[0] == 'reverse':
op, a, b = query
a, b = int(a), int(b)
string = string[:a] + ''.join(reversed(string[a:b + 1])) + string[b + 1:]
elif query[0] == 'print':
op, a, b = query
a, b = int(a), int(b)
print(string[a: b + 1])
|
print(10 - int(float(input())/200))
| 0 | null | 4,362,571,799,520 | 68 | 100 |
def north(d):
d[0], d[1], d[5], d[4] = d[1], d[5], d[4], d[0]
def west(d):
d[0], d[2], d[5], d[3] = d[2], d[5], d[3], d[0]
def east(d):
d[0], d[3], d[5], d[2] = d[3], d[5], d[2], d[0]
def south(d):
d[0], d[4], d[5], d[1] = d[4], d[5], d[1], d[0]
F = {'N': north, 'W': west, 'E': east, 'S': south}
d, os = list(map(int, input().split())), input()
for o in os:
F[o](d)
print(d[0])
|
n,m=map(int,input().split())
a=[0]*n
ans=0
for i in range(m):
p,s=input().split()
p=int(p)-1
if a[p]!=1:
if s=='WA':a[p]-=1
else:
ans-=a[p]
a[p]=1
for i in range(n):
a[i]=max(a[i],0)
print(sum(a),ans)
| 0 | null | 46,970,727,401,708 | 33 | 240 |
N=int(input())
n= str(N)
total=0
for i in range(len(n)):
k = n[i]
k = int(k)
total += k
if total%9==0:
print("Yes")
else:
print("No")
|
N=list(map(int,input().split()))
temp = sum(N)
if temp%9 == 0:print("Yes")
else:print("No")
| 1 | 4,406,441,895,688 | null | 87 | 87 |
import math
N=int(input())
ans=0
for i in range(1,N+1):
for j in range(i,N+1):
for k in range(j,N+1):
if i==j and j==k:
ans+=i
elif i<j and j<k:
ans+=6*math.gcd(i,math.gcd(j,k))
else:
ans+=3*math.gcd(i,math.gcd(j,k))
print(ans)
|
def main():
N = int(input())
A = (
1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889,
13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857,
71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836,
194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709,
397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712,
709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467,
1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570,
1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104,
2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249,
3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949,
4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008,
5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016,
6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897,
8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813,
10493367, 10611772, 10813692)
print(A[N - 1])
if __name__ == '__main__':
main()
| 1 | 35,412,346,157,472 | null | 174 | 174 |
r,c = map(int,input().split())
matrix = [list(map(int,input().split())) for i in range(r)]
for i in range(r):
matrix[i].append(sum(matrix[i]))
row = []
for i in range (c+1):
row_sum = 0
for j in range(r):
row_sum += matrix[j][i]
row.append(row_sum)
matrix.append(row)
for i in range(r+1):
for j in range(c+1):
print(matrix[i][j],end="")
if j != c:
print(" ",end="")
if j == c :
print("")
|
# B - Papers, Please
# https://atcoder.jp/contests/abc155/tasks/abc155_b
n = int(input())
a = list(map(int, input().split()))
even = 0
cnt = 0
for i in a:
if i % 2 == 0:
even += 1
if i % 3 == 0 or i % 5 == 0:
cnt += 1
if even == cnt:
print('APPROVED')
else:
print('DENIED')
| 0 | null | 34,968,960,650,338 | 59 | 217 |
import sys
def input():
return sys.stdin.readline().rstrip()
def dfs(c, n, G, ans):
count = c
for i, flag in enumerate(G[n]):
if flag == 1 and ans[i][0] == 0:
count += 1
ans[i][0] = i + 1
ans[i][1] = count
ans[i][2] = dfs(count, i, G, ans)
count = ans[i][2]
else:
return count + 1
def main():
n = int(input())
G = [[0] * n for _ in range(n)]
ans = [[0] * 3 for _ in range(n)]
for i in range(n):
u, k, *v = map(int, input().split())
for j in range(k):
G[u-1][v[j]-1] = 1
count = 1
for i in range(n):
if ans[i][0] == 0:
ans[i][0] = i + 1
ans[i][1] = count
ans[i][2] = dfs(count, i, G, ans)
count = ans[i][2] + 1
for i in range(n):
print(*ans[i])
if __name__ == '__main__':
main()
|
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()
| 1 | 3,086,368,232 | null | 8 | 8 |
#!python3.8
# -*- coding: utf-8 -*-
# abc179/abc179_a
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
def main():
S = i2s()
if S[-1] != 's':
print(S + 's')
else:
print(S + 'es')
return
main()
|
day = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]
d = input()
print(7 - day.index(d))
| 0 | null | 67,448,804,771,600 | 71 | 270 |
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)
|
n=int(input())
m=100
y=0
while m < n:
m += m//100
y += 1
print(y)
| 1 | 27,302,130,512,172 | null | 159 | 159 |
#D
N=int(input())
X=str(input())
CNT=0
for i in range(N):
if X[i]=="1":
CNT+=1
NUM=int(X,2)
to0_cnt=[0 for i in range(N)]
for i in range(1,N):
ans=0
num=i
while True:
cnt=0
for j in bin(num)[2:]:
if j=="1":
cnt+=1
if cnt==0:
break
r=num%cnt
ans+=1
if r==0:
break
num=r
to0_cnt[i]=ans
R=[NUM%(CNT+1),NUM%(CNT-1) if CNT!=1 else 0]
for i in range(N):
if X[i]=="0":
cnt=CNT+1
r=(R[0]+pow(2,N-i-1,cnt))%cnt
else:
cnt=CNT-1
if NUM-pow(2,N-i-1)==0:
print(0)
continue
r=(R[1]-pow(2,N-i-1,cnt))%cnt
ans=1+to0_cnt[r]
print(ans)
|
K = int(input())
count =1
x = 7%K
for i in range(0,K+1):
if x== 0:
print(count)
break
count+=1
x = (x*10+7)%K
if i== K:
print(-1)
| 0 | null | 7,182,489,609,180 | 107 | 97 |
import math
X=int(input())
def ans165(X:int):
cash=100#当初の預金額
count=0
while True:
# cash=int(cash*1.01) #元本に1パーセントの利子をつけ小数点以下切り捨て # WA
# cash = cash * 1.01 * 100 // 100 # 1%の利子をつけて100倍した後に100で割って整数部のみ取り出す # WA
# cash += cash * 0.01 * 100 // 100 # 1%の利子を計算して100倍した後に100で割って整数部のみ取り出す # WA
# cash += cash // 100 # 元本に100で割った整数部を足す # AC
# cash += math.floor(cash * 0.01) # WA
# cash += math.floor(cash / 100) # WA
cash += math.floor(cash // 100) # WA
count += 1#利子をつける回数だけcountを増やす
if cash>=X:#cashがXの値以上になったらループ終了
break
return count
print(ans165(X))
|
X=int(input())
x=100
ans=0
while x<X:
x=101*x//100
ans+=1
print(ans)
| 1 | 27,044,708,286,496 | null | 159 | 159 |
#!/usr/bin python3
# -*- coding: utf-8 -*-
from math import gcd #for python3.8
def lcm(a,b):
G = gcd(a, b) #最大公約数
L = (a//G)*b #最小公倍数
return L
def main():
X = int(input())
print(lcm(X,360)//X)
if __name__ == '__main__':
main()
|
# coding: utf-8
import math
import numpy as np
#N = int(input())
#A = list(map(int,input().split()))
x = int(input())
#x, y = map(int,input().split())
for i in range(1,10**5):
if (i*x)%360==0:
print(i)
break
| 1 | 13,216,343,186,072 | null | 125 | 125 |
n=int(input())
s=0
for i in str(n):
s+=int(i)
if(s%9==0):
print("Yes")
else:
print("No")
|
N = int(input())
A = list(map(int, input().split()))
l = [0]*N
for i in A:
l[i-1] += 1
print(*l, sep="\n")
| 0 | null | 18,622,149,258,482 | 87 | 169 |
import bisect
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
B = [0] * N
B[-1] = A[-1]
for i in range(N - 2, -1, -1):
B[i] = B[i+1]+A[i]
def C(mid):
tmp = 0
for a in A:
pos = bisect.bisect_right(A, mid - a)
tmp += N-pos
return tmp > M
lb = 0
rb = 10**6
while rb - lb > 1:
happy = (lb + rb) // 2
if C(happy):
lb = happy
else:
rb = happy
ans = 0
cnt = 0
for a in A:
pos = bisect.bisect_right(A, rb - a)
if pos == N:
continue
ans += B[pos]+(N-pos)*a
cnt += N - pos
ans += (M-cnt)*rb
print(ans)
|
from bisect import bisect_left, bisect_right
n,m = map(int, input().split())
al = list(map(int, input().split()))
al.sort()
ok, ng = 0, 10**18+1
while abs(ok-ng) > 1:
mid = (ok+ng)//2
ok_flag = True
cnt = 0
# print('-----')
# print(ok,ng,mid)
for i,a in enumerate(al):
rem = mid-a
cnt_a = n-bisect_left(al,rem)
# cnt_a = min(n-i-1, cnt_a)
cnt += cnt_a
# print(i,a,cnt_a)
if cnt >= m:
ok = mid
else:
ng = mid
min_sum = ok
cum_sums = [0]
csum = 0
for a in al:
csum += a
cum_sums.append(csum)
# print(min_sum)
ans = 0
cnt = 0
for i,a in enumerate(al):
rem = min_sum - a
ind = bisect_left(al, rem)
# ind = ind if 0 <= ind < n else None
# ind = max(i+1,ind)
csum = cum_sums[n] - cum_sums[ind]
# print(i,a,csum)
ans += csum
ans += a*(n-ind)
cnt += (n-ind)
ans -= (cnt-m)*min_sum
print(ans)
# print(min_sum)
| 1 | 107,831,834,372,288 | null | 252 | 252 |
from sys import stdin
line = stdin.readline()
input = [int(x) for x in line.rstrip().split()]
if input[0] * 500 >= input[1]:
print('Yes')
else:
print('No')
|
from collections import Counter, defaultdict
# n = int(input())
# li = list(map(int, input().split()))
# n = int(input())
a, b = map(int, input().split())
c, d = map(int, input().split())
# d = defaultdict(lambda: 0)
# s = input()
print("1" if c == a+1 else "0")
| 0 | null | 111,153,923,967,770 | 244 | 264 |
import math
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
t1 = t2 = t3 = ti = 0.0
for a, b in zip(x, y):
d1 = abs(a - b)
ti = max(ti, d1)
t1 += d1
t2 += d1**2
t3 += d1**3
print(t1)
print(math.sqrt(t2))
print(t3 ** (1.0/3))
print(ti)
|
import math
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
def p1(x, y, n):
D = []
for i in range(n):
D.append(abs(x[i] - y[i]))
return sum(D)
def p2(x, y, n):
D = []
for i in range(n):
D.append(abs(x[i] - y[i]))
D[i] *= D[i]
Sum = sum(D)
return math.sqrt(Sum)
def p3(x, y, n):
D = []
for i in range(n):
D.append(abs(x[i] - y[i]))
D[i] = D[i] * D[i] * D[i]
Sum = sum(D)
return math.pow(Sum, 1 / 3)
def pX(x, y, n):
D = []
for i in range(n):
D.append(abs(x[i] - y[i]))
return max(D)
print('{:6f}'.format(p1(x, y, n)))
print('{:6f}'.format(p2(x, y, n)))
print('{:6f}'.format(p3(x, y, n)))
print('{:6f}'.format(pX(x, y, n)))
| 1 | 210,419,138,682 | null | 32 | 32 |
import numpy as np
def main(A, B, V, W, T):
if abs(B-A) <= T*(V-W):
return "YES"
return "NO"
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
print(main(A, B, V, W, T))
|
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
gap=abs(a-b)
if v>w:
c=gap/(v-w)
if t>=c:
print('YES')
else:
print('NO')
else:
print('NO')
| 1 | 14,990,059,084,660 | null | 131 | 131 |
K = int(input())
if K%2==0 or K%5==0:
print(-1)
else:
ans = 1
rest = 7%K
while rest != 0:
rest *= 10
rest += 7
rest %= K
ans += 1
print(ans)
|
import sys
from collections import deque
N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for s in sys.stdin.readlines():
a, b = map(lambda x: int(x) - 1, s.split())
edge[a].append(b)
edge[b].append(a)
path = [0] * N
cnt = 0
for i in range(N):
if path[i] == 0:
cnt += 1
q = deque()
path[i] = 1
q.append(i)
while q:
p = q.popleft()
for np in edge[p]:
if path[np] == 0:
path[np] = 1
q.append(np)
print(cnt - 1)
| 0 | null | 4,222,411,039,672 | 97 | 70 |
from collections import OrderedDict
n, x, y = map(int, input().split())
x = x-1
y = y-1
dist_hist = OrderedDict({i: 0 for i in range(1, n)})
for i in range(n-1):
for j in range(i+1, n):
if i<=x and j>=y:
dist = j-i + 1 - (y-x)
elif i<=x and x<j<y:
dist = min(j-i, x-i + 1 + y-j)
elif x<i<y and y<=j:
dist = min(i-x + 1 + j-y, j-i)
elif x<i<y and x<j<y:
dist = min(j-i, i-x + 1 + y-j)
else:
dist = j - i
dist_hist[dist] += 1
[print(value) for value in dist_hist.values()]
|
n,x,y = map(int, input().split())
lis = [0] * n
x -= 1
y -= 1
for i in range(n):
for j in range(i+1, n):
t = min(abs(i-j), abs(i-x)+abs(j-y)+1,abs(i-y)+abs(j-x)+1)
lis[t] += 1
for i in range(1,n):
print(lis[i])
| 1 | 44,106,954,529,022 | null | 187 | 187 |
N,M = map(int,input().split())
num_AC,num_WA = 0,0
res = [list(input().split()) for i in range(M)]
check = ['v']*N
WA_check = [0]*N
for i,j in res:
i = int(i)
if check[i-1] == 'v':
if j == 'WA':
WA_check[i-1] += 1
if j == 'AC':
num_AC += 1
num_WA += WA_check[i-1]
check[i-1] = '.'
print(num_AC,num_WA)
|
from collections import defaultdict as dic
n, m = map(int, input().split())
ac = 0
pena = 0
d = dic(list)
for i in range(m):
pi, si = input().split()
d[pi].append(si)
for (k, v) in d.items():
pe = 0
flag = False
for aw in v:
if aw == 'WA':
pe += 1
else:
ac += 1
flag = True
break
if flag:
pena += pe
print(ac, pena)
| 1 | 93,491,524,535,318 | null | 240 | 240 |
x, n = map(int, input().split())
if n == 0:
print(x)
else:
a = [int(x) for x in input().split()]
ans1 = x
while ans1 in a :
ans1 -= 1
ans2 = x
while ans2 in a :
ans2 += 1
if abs(x - ans1) <= abs(x - ans2):
print(ans1)
else:
print(ans2)
|
x, n = map(int, input().split())
li_p = list(map(int, input().split()))
li_p.sort()
i = 0
while True:
a = x - i
b = x + i
if not a in li_p:
print(a)
break
elif a in li_p and not b in li_p:
print(b)
break
elif a in li_p and b in li_p:
i += 1
| 1 | 14,072,994,191,550 | null | 128 | 128 |
st = list()
while True:
a = list(map(lambda x: int(x),input().split(" ")))
if min(a[0:2]) == -1:
if max(a) == -1:
break
else:
st += {"F"}
else:
if 80 <= sum(a[0:2]):
st += {"A"}
elif 65 <= sum(a[0:2]):
st += {"B"}
elif 50 <= sum(a[0:2]):
st += {"C"}
elif 30 <= sum(a[0:2]):
if 50 <= a[2]:
st += {"C"}
else:
st += {"D"}
else:
st += {"F"}
for s in st:
print(s)
|
from collections import Counter
def CHK():
N = int(input())
A = list(map(int,input().split()))
L=[]
R=[]
cnt = 0
for i in range(N):
L.append(i + A[i])
L_Cnt=Counter(L)
for i in range(N):
chk = i -A[i]
cnt += L_Cnt[chk]
print(cnt)
CHK()
| 0 | null | 13,577,189,196,492 | 57 | 157 |
from collections import deque
graph = []
n = int(input())
dist = [[int(c),-1] for c in range(1,n+1)]
process_q = deque()
for i in range(n):
graph.append([c-1 for c in list(map(int,input().split()))][2:])
def bfs():
while len(process_q) > 0:
parent = process_q.popleft()
for child in graph[parent]:
if dist[child][1] != -1:
continue
process_q.append(child)
dist[child][1] = dist[parent][1] + 1
process_q.append(0)
dist[0][1] = 0
bfs()
for element in dist:
print(*element)
|
l, r, d = [int(x) for x in input().rstrip().split(" ")]
print(r//d-l//d + (l%d==0))
| 0 | null | 3,745,850,911,430 | 9 | 104 |
N = int(input())
check = [0, 0, 0]
for i in range(N):
str = input().split()
check[i%3] = 1 if str[0] == str[1] else 0
if sum(check) == 3:
break
print('Yes') if sum(check) == 3 else print('No')
|
N = int(input())
M = 0
ans = 'No'
for _ in range(N):
d1, d2 = map(int, input().split())
if d1 == d2:
M += 1
if M >= 3:
ans = 'Yes'
else:
M = 0
print(ans)
| 1 | 2,484,601,576,000 | null | 72 | 72 |
nxt = input().split()
#print(nxt)
N = int(nxt[0])
X = int(nxt[1])
T = int(nxt[2])
#print(N,X,T)
tmp = N/X - int(N/X)
if tmp == 0:
counter = int(N/X)
else:
counter = int(N/X) + 1
#print(counter)
print(counter * T)
|
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
D = abs(A - B)
if (V > W) and \
(D / (V - W) <= T):
print("YES")
else:
print("NO")
| 0 | null | 9,702,221,189,348 | 86 | 131 |
N = int(input())
A = list(map(int,input().split()))
b = 1
c = 0
if A.count(0) != 0:
print(0)
else:
for i in range(N):
b = b * A[i]
if b > 10 ** 18:
c = 1
break
if c == 0:
print(b)
else:
print(-1)
|
#template
def inputlist(): return [int(j) for j in input().split()]
#template
N = int(input())
A = inputlist()
A.sort()
ans = 1
if A[0] == 0:
print(0)
exit()
for i in range(N):
ans *= A[i]
if ans > 10**18:
print(-1)
exit()
print(ans)
| 1 | 16,118,154,124,842 | null | 134 | 134 |
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(input())
H = I()
def monster(n):
if n == 1:
return 1
return 1 + 2*(monster(n//2))
print(monster(H))
|
h = int(input())
cnt = 0
while h > 1:
h //= 2
cnt += 1
print(2**(cnt+1)-1)
| 1 | 80,116,312,690,960 | null | 228 | 228 |
s = int(input())
c = s // 500
d = s % 500
e = d //5
h = c*1000 + e*5
print(h)
|
x=int(input())
gohyaku=0
goen=0
while x>5:
x-=500
gohyaku+=1
if x==5:
goen+=1
elif 0<=x<5:
pass
elif x<0:
x+=500
gohyaku-=1
while x>=5:
goen+=1
x-=5
print(gohyaku*1000+goen*5)
| 1 | 42,958,369,580,230 | null | 185 | 185 |
def resolve():
# 最長の辺の長さ < 他の辺の長さの合計 で三角形
N = int(input())
lines = map(int, input().split())
#N = 100
#from random import randint
#lines = [randint(1, 10 ** 9) for x in range(N)]
from itertools import combinations
count = 0
for c in combinations(lines, 3):
if len(set(c)) != 3:
continue
if max(c) < sum(c)-max(c):
count += 1
print(count)
resolve()
|
tmp = input().split(" ")
S = int(tmp[0])
W = int(tmp[1])
if S <= W:
print("unsafe")
else:
print("safe")
| 0 | null | 17,136,060,966,080 | 91 | 163 |
n = int(input())
str = input()
if (n%2 == 0) and (str[:(n//2)] == str[n//2:]):
print("Yes")
else:
print("No")
|
n, x, m = map(int,input().split())
amari = [0]*m
v = [x]
cnt = 0
while True:
xn_1 = x**2%m
cnt += 1
if x == 0:
break
amari[x] = xn_1
if amari[xn_1]:
break
v.append(xn_1)
x = xn_1
#print(v)
if 0 in v:
ans = sum(v)
else:
ind = v.index(xn_1)
rooplen = len(v) - ind
ans = sum(v[0:ind])
l = n-ind
if rooplen:
ans += (l//rooplen)*sum(v[ind:])
nokori = l - rooplen*(l//rooplen)
ans += sum(v[ind:ind+nokori])
#print(v)
print(ans)
| 0 | null | 74,581,617,096,422 | 279 | 75 |
n=int(input())
syakkin=100000
for i in range(n):
syakkin+=syakkin*0.05
if syakkin%1000!=0:
syakkin=(syakkin//1000)*1000+1000
print(int (syakkin))
|
import math
n=int(input())
a=1000000007
print( (pow(10,n)-pow(9,n)*2+pow(8,n))%a)
| 0 | null | 1,582,854,438,880 | 6 | 78 |
while True:
try:
a, b = map(int, input().split())
i = a + b
c = 1
while i:
if int(i/10) == 0:
print(c)
break
c+=1
i /= 10
except Exception:
break
|
import sys
def main():
for line in sys.stdin:
A = list(map(int,line.split()))
C = A[0]+A[1]
count = 0
while True:
C/=10
if C < 1:
break
count += 1
print(count+1)
if __name__ == '__main__':
main()
| 1 | 118,872,780 | null | 3 | 3 |
n = int(input())
times_ls = [0] * (n+1)
for base in range(1,n+1):
for j in range(1,n+1):
if base * j <= n:
times_ls[base * j] += 1
else:
break
ans = 0
for i in range(1,n+1):
ans += i * times_ls[i]
print(ans)
|
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
n = int(input())
ans = 0
for i in range(1, n+1):
ans += i*(1 + n//i)*(n//i)//2
print(ans)
if __name__=='__main__':
main()
| 1 | 10,991,168,433,238 | null | 118 | 118 |
import math
debt = 100
for i in range(int(input())):
debt = math.ceil(debt * 1.05)
print(int(debt) * 1000)
|
x=input()
lst=x.split(" ")
print(int(lst[0])*int(lst[1]))
| 0 | null | 7,882,494,458,464 | 6 | 133 |
import math
import sys
def input():
return sys.stdin.readline().strip()
sys.setrecursionlimit(20000000)
MOD = 10 ** 9 + 7
INF = float("inf")
def main():
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
answer = 0
for i in range(1, N):
answer += A[math.floor(i / 2)]
print(answer)
if __name__ == "__main__":
main()
|
n = int(input())
arr = list(map(int,input().split()))
arr.sort(reverse = True)
ans = arr[0]
odd = False
mult = n-2
if mult%2!=0:
mult-=1
odd = True
mult//=2
ans += sum(arr[1:1+mult])*2
if odd:
ans+=arr[1+mult]
print(ans)
"""
Sample:
7
1 2 3 4 5 6 7
2537146
7+6+6+5+5+4
"""
| 1 | 9,152,138,320,032 | null | 111 | 111 |
# import matplotlib.pyplot as plt
import math
def lcm(x, y):
if x > y:
z = x
else:
z = y
while(True):
if((z % x == 0) and (z % y == 0)):
lcm = z
break
z += 1
return lcm
X = int(input())
print(int(lcm(X, 360) / X))
|
X = int(input())
ret = 0
cur = 0
while True:
ret += 1
cur += X
if cur % 360 == 0:
print(ret)
break
| 1 | 13,041,725,207,820 | null | 125 | 125 |
num = input().split(" ")
a = int(num[0])
b = int(num[1])
c = a/b
print(int(a/b),int(a%b),"%f" % c)
|
def az8():
xs = map(int,raw_input().split())
a,b = xs[0],xs[1]
print (a/b),(a%b), "%5f"%(float(a)/b)
az8()
| 1 | 584,717,642,530 | null | 45 | 45 |
a, b = map(int, input().split(" "))
print("%d %d %.5f" %(a/b, a%b, a/b))
|
import sys
x=int(input())
for a in range(-1000,1000):
for b in range(-1000,1000):
if a**5-b**5==x:
print(a,b)
sys.exit()
| 0 | null | 13,127,022,748,418 | 45 | 156 |
N = int(input())
n =10**9 + 7
a = (10**N) % n
b = (9**N) % n
c = (8**N) % n
x = (a - 2*b + c) % n
print(x)
|
b=int(input())
a=input()
c=[]
for i in range(b):
c.append(a[i])
#a = list(map(int,input().split()))
#b = list(map(int,input().split()))
if b==1:
print("No")
elif c[:int(b/2)]==c[int(b/2):]:
print("Yes")
else:
print("No")
| 0 | null | 75,244,484,052,628 | 78 | 279 |
#N E S W
def move_func(dice_list, dir):
new_dice = []
if dir=="N":
new_dice.append(dice_list[1])
new_dice.append(dice_list[5])
new_dice.append(dice_list[2])
new_dice.append(dice_list[3])
new_dice.append(dice_list[0])
new_dice.append(dice_list[4])
elif dir=="E":
new_dice.append(dice_list[3])
new_dice.append(dice_list[1])
new_dice.append(dice_list[0])
new_dice.append(dice_list[5])
new_dice.append(dice_list[4])
new_dice.append(dice_list[2])
elif dir=="S":
new_dice.append(dice_list[4])
new_dice.append(dice_list[0])
new_dice.append(dice_list[2])
new_dice.append(dice_list[3])
new_dice.append(dice_list[5])
new_dice.append(dice_list[1])
elif dir=="W":
new_dice.append(dice_list[2])
new_dice.append(dice_list[1])
new_dice.append(dice_list[5])
new_dice.append(dice_list[0])
new_dice.append(dice_list[4])
new_dice.append(dice_list[3])
return new_dice
try:
while True:
dice_list = input().split(" ")
move_cmd = input()
for cmd in move_cmd:
dice_list = move_func(dice_list, cmd)
print(dice_list[0])
except EOFError:
pass
|
A, B, M = map(int,input().split())
A = [a for a in map(int,input().split())]
B = [b for b in map(int,input().split())]
C = []
for m in range(M):
C.append([c for c in map(int,input().split())])
ans = min(A) + min(B)
for c in C:
if (A[c[0]-1]+B[c[1]-1]-c[2])<ans:
ans = A[c[0]-1]+B[c[1]-1]-c[2]
print(ans)
| 0 | null | 27,007,235,737,444 | 33 | 200 |
S = input()
Q = int(input())
flag = True
from collections import deque
que=deque(S)
for i in range(Q):
a = input().split()
if a[0]=="1":
flag = not flag
else:
f = a[1]
c = a[2]
if f=="1":
if flag:
que.appendleft(c)
else:
que.append(c)
else:
if flag:
que.append(c)
else:
que.appendleft(c)
if not flag:
que.reverse()
print("".join(que))
|
X = int(input())
for i in range(1,1000000000):
if ( X * i ) % 360 == 0:
print(i)
quit()
| 0 | null | 35,170,495,117,380 | 204 | 125 |
n,k=input().split();print(sum(sorted(list(map(int,input().split())))[:int(k)]))
|
import itertools
N = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
l = []
for i in range(1,N+1):
l.append(i)
tmp = sorted(list(itertools.permutations(l)))
p = tmp.index(P)
q = tmp.index(Q)
print(abs(p-q))
| 0 | null | 55,893,443,355,970 | 120 | 246 |
s=list(input())
print(s[0]+s[1]+s[2])
|
r,c,k = map(int, input().split())
rckl = [ [0]*c for _ in range(r) ]
for _ in range(k):
r_,c_,v_ = map(int, input().split())
rckl[r_-1][c_-1] = v_
dp0 = [ [0]*c for _ in range(r) ]
dp1 = [ [0]*c for _ in range(r) ]
dp2 = [ [0]*c for _ in range(r) ]
dp3 = [ [0]*c for _ in range(r) ]
dp1[0][0] = rckl[0][0]
for i in range(r):
for j in range(c):
if j+1 < c:
dp0[i][j+1] = max(dp0[i][j], dp0[i][j+1])
dp1[i][j+1] = max(dp1[i][j], dp1[i][j+1])
dp2[i][j+1] = max(dp2[i][j], dp2[i][j+1])
dp3[i][j+1] = max(dp3[i][j], dp3[i][j+1])
if rckl[i][j+1] > 0:
v = rckl[i][j+1]
dp1[i][j+1] = max(dp1[i][j+1], dp0[i][j] + v)
dp2[i][j+1] = max(dp2[i][j+1], dp1[i][j] + v)
dp3[i][j+1] = max(dp3[i][j+1], dp2[i][j] + v)
if i+1 < r:
dp0[i+1][j] = max(dp0[i][j], dp1[i][j], dp2[i][j], dp3[i][j], dp0[i+1][j])
if rckl[i+1][j] > 0:
v = rckl[i+1][j]
dp1[i+1][j] = max(dp1[i+1][j], dp0[i][j]+v, dp1[i][j]+v, dp2[i][j]+v, dp3[i][j]+v)
ans = max(dp0[-1][-1], dp1[-1][-1], dp2[-1][-1], dp3[-1][-1])
print(ans)
| 0 | null | 10,188,293,940,640 | 130 | 94 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
n = int(readline())
inc = []
dec = []
for _ in range(n):
s = readline().rstrip().decode()
d, r = 0, 0
for m in s:
d += (1 if m == '(' else -1)
r = max(r, -d)
(dec if d < 0 else inc).append((d, r))
inc.sort(key=lambda x: x[1])
dec.sort(key=lambda x: x[0] + x[1])
p1 = 0
p2 = 0
flag = True
for i in inc:
flag &= i[1] <= p1
p1 += i[0]
for d in dec:
flag &= p2 >= d[0] + d[1]
p2 -= d[0]
flag &= p1 == p2
print('Yes' if flag else 'No')
|
import sys
input=sys.stdin.readline
n=int(input())
cnt=[]
for i in range(n):
s=input().rstrip()
l=s.count("(")
r=s.count(")")
minus=0
now=0
for j in range(len(s)):
if s[j]=="(":
now+=1
else:
now-=1
minus=min(minus,now)
cnt.append((l,r,s,minus))
cnt.sort(key=lambda x:x[1]-x[0])
plus=[]
minus=[]
#x[3]は最小値 x[0]-x[1]が合計値
for x in cnt:
if x[0]-x[1]>0:
plus.append(x)
else:
minus.append(x)
plus.sort(key=lambda x:-x[3])#最小値の少ない(0に近い方から)
minus.sort(key=lambda x:-(x[0]-x[1]-x[3]))
lr=0#l-r
for x in plus+minus:
if lr+x[3]<0:
print("No")
exit()
lr+=x[0]-x[1]
if lr==0:
print("Yes")
else:
print("No")
| 1 | 23,641,519,925,522 | null | 152 | 152 |
import numpy as np
class Combination :
def __init__ (self, N=10**6, mod=10**9+7) :
self.mod = mod
self.fact = [1, 1]
self.factinv = [1, 1]
self.inv = [0, 1]
for i in range(2, N+1) :
self.fact.append( (self.fact[-1] * i) % mod )
self.inv .append( (-self.inv[mod%i] * (mod//i) ) % mod )
self.factinv.append( (self.factinv[-1] * self.inv[-1]) % mod )
def nCr(self, n, r) :
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.mod
def nPr(self, n, r) :
if ( r < 0 ) or ( n < r ) : return 0
return self.fact[n]*self.factinv[n-r] % self.mod
n, k = map(int, input().split())
mod = 10**9+7
comb = Combination(2*10**5+100)
ans = 0
for m in range(min(n+1,k+1)) :
ans = ans%mod + (comb.nCr(n,m) * comb.nCr(n-1, n-m-1))%mod
print(ans%mod)
|
n,k=map(int,input().split())
mod=10**9+7
U = 4*10**5+1
MOD = 10**9+7
fact = [1]*(U+1)
fact_inv = [1]*(U+1)
for i in range(1,U+1):
fact[i] = (fact[i-1]*i)%MOD
fact_inv[U] = pow(fact[U],MOD-2,MOD)
for i in range(U,0,-1):
fact_inv[i-1] = (fact_inv[i]*i)%MOD
def comb(n,k):
if k < 0 or k > n:
return 0
x = fact[n]
x *= fact_inv[k]
x %= MOD
x *= fact_inv[n-k]
x %= MOD
return x
if n-1<=k:
print(comb(2*n-1,n-1))
else:
ans=0
for i in range(1+k):
ans+=comb(n,i)*comb(n-1,n-i-1)
ans%=mod
print(ans)
| 1 | 67,246,413,648,608 | null | 215 | 215 |
import sys
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n = int(input())
A = list(map(int, input().split()))
res = 1
cnt = [3 if i == 0 else 0 for i in range(n + 1)]
for a in A:
res = res * cnt[a] % mod
cnt[a] -= 1
cnt[a + 1] += 1
print(res)
if __name__ == '__main__':
resolve()
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def main():
N = int(input())
A = [(i, v) for i, v in enumerate(map(int, input().split()))]
values = [[0] * (N + 1) for _ in range(N + 1)]
A.sort(key=lambda x:-x[1])
for i, (p, v) in enumerate(A):
for j in range(i + 1):
left = abs((p - j) * v)
right = abs((N - 1 - (i - j) - p) * v)
values[i + 1][j + 1] = max(values[i][j] + left, values[i + 1][j + 1])
values[i + 1][j] = max(values[i][j] + right, values[i + 1][j])
print(max(values[-1]))
if __name__ == '__main__':
main()
| 0 | null | 81,947,501,728,882 | 268 | 171 |
class Factorial():
def __init__(self, mod=10**9 + 7):
self.mod = mod
self._factorial = [1]
self._size = 1
self._factorial_inv = [1]
self._size_inv = 1
def __call__(self, n):
return self.fact(n)
def fact(self, n):
''' n! % mod '''
if n >= self.mod:
return 0
self._make(n)
return self._factorial[n]
def _make(self, n):
if n >= self.mod:
n = self.mod
if self._size < n+1:
for i in range(self._size, n+1):
self._factorial.append(self._factorial[i-1]*i % self.mod)
self._size = n+1
def fact_inv(self, n):
''' n!^-1 % mod '''
if n >= self.mod:
raise ValueError('Modinv is not exist! arg={}'.format(n))
self._make(n)
if self._size_inv < n+1:
self._factorial_inv += [-1] * (n+1-self._size_inv)
self._size_inv = n+1
if self._factorial_inv[n] == -1:
self._factorial_inv[n] = self.modinv(self._factorial[n])
return self._factorial_inv[n]
@staticmethod
def xgcd(a, b):
'''
Return (gcd(a, b), x, y) such that a*x + b*y = gcd(a, b)
'''
x0, x1, y0, y1 = 0, 1, 1, 0
while a != 0:
(q, a), b = divmod(b, a), a
y0, y1 = y1, y0 - q * y1
x0, x1 = x1, x0 - q * x1
return b, x0, y0
def modinv(self, n):
g, x, _ = self.xgcd(n, self.mod)
if g != 1:
raise ValueError('Modinv is not exist! arg={}'.format(n))
return x % self.mod
def comb(self, n, r):
''' nCr % mod '''
if r > n:
return 0
t = self(n)*self.fact_inv(n-r) % self.mod
return t*self.fact_inv(r) % self.mod
def comb_with_repetition(self, n, r):
''' nHr % mod '''
t = self(n+r-1)*self.fact_inv(n-1) % self.mod
return t*self.fact_inv(r) % self.mod
def perm(self, n, r):
''' nPr % mod '''
if r > n:
return 0
return self(n)*self.fact_inv(n-r) % self.mod
x, y = sorted(map(int, input().split()))
q, r = divmod(x+y, 3)
if r != 0:
print(0)
else:
comb = Factorial().comb
print(comb(q, y-q))
|
mod = 10**9 + 7
def cmb(n,r,mod):
a=1
b=1
r = min(r,n-r)
for i in range(r):
a = a*(n-i)%mod
b = b*(i+1)%mod
return a*pow(b,mod-2,mod)%mod
X,Y = map(int,input().split())
if (X+Y)%3 != 0:
ans = 0
else:
n = (2*X-Y)//3
m = (2*Y-X)//3
if n < 0 or m < 0:
ans = 0
else:
ans = cmb(n+m,m,mod)
print(ans)
| 1 | 150,442,154,665,170 | null | 281 | 281 |
# Aizu Problem 0002: Digit Number
#
import sys, math, os
# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
sys.stdin = open("sample-input.txt", "rt")
for line in sys.stdin:
a, b = [int(_) for _ in line.split()]
print(len(str(a + b)))
|
while True:
try:
a,b = map(int,input().split(" "))
print(len(str(a+b)))
except: break
| 1 | 171,556,938 | null | 3 | 3 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, *A = map(int, read().split())
M = 61
C = [0] * M
for a in A:
a = str(format(a, 'b'))
for i, d in enumerate(reversed(a)):
if d == '1':
C[i] += 1
ans = 0
p = 1
for c in C:
ans = (ans + c * (N - c) * p) % MOD
p = p * 2 % MOD
print(ans)
return
if __name__ == '__main__':
main()
|
n=int(input())
a=list(map(int,input().split()))
bit_l=[0 for _ in range(60)]
for x in a:
for i in range(60):
if ((x>>i)&1):
bit_l[i]+=1
ans=0
mod=10**9+7
for y in range(len(bit_l)):
r=2**y
k=(n-bit_l[y])*bit_l[y]
ans+=r*k%mod
print(ans%mod)
| 1 | 122,741,249,319,200 | null | 263 | 263 |
n,x,t=[int(i) for i in input().split()]
k=n//x
if n%x:
print((k+1)*t)
else:
print(k*t)
|
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)
def sub(x):
val = 0
for aa,ff in zip(a,f):
val += max(0, aa - (x//ff))
return val<=k
if sub(0):
ans = 0
else:
l = 0
r = sum(aa*ff for aa,ff in zip(a,f))
while l+1<r:
m = (l+r)//2
if sub(m):
r = m
else:
l = m
ans = r
print(ans)
| 0 | null | 84,927,500,674,940 | 86 | 290 |
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
def ddprint(x):
if DBG:
print(x)
n = inn()
a = inl()
if n<=3:
print(max(a))
exit()
lacc = [0]*n
racc = [0]*n
lacc[0] = a[0]
lacc[1] = a[1]
racc[n-1] = a[n-1]
racc[n-2] = a[n-2]
for i in range(2,n):
if i%2==0:
lacc[i] = lacc[i-2]+a[i]
else:
lacc[i] = max(lacc[i-3],lacc[i-2])+a[i]
if n%2==0:
print(max(lacc[n-2],lacc[n-1]))
exit()
for i in range(n-3,-1,-1):
if (n-1-i)%2==0:
racc[i] = racc[i+2]+a[i]
else:
racc[i] = max(racc[i+3],racc[i+2])+a[i]
mx = max(racc[2],lacc[n-3])
for i in range(1,n-2):
if i%2==0:
mx = max(mx, max(lacc[i-2],lacc[i-1])+racc[i+2])
else:
mx = max(mx, max(racc[i+2],racc[i+3])+lacc[i-1])
print(mx)
|
import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
n = str(readline().rstrip().decode('utf-8'))
d = {"2": "hon", "4": "hon", "5": "hon", "7": "hon", "9": "hon", "0": "pon", "1": "pon", "6": "pon", "8": "pon", "3": "bon"}
print(d[n[-1]])
if __name__ == '__main__':
solve()
| 0 | null | 28,262,000,151,670 | 177 | 142 |
n = int(input())
a = list(map(int, input().split()))
length = len(a)
total = sum(a)
ans = 0
for i in range(0,length):
total -= a[i]
ans += (a[i] * total)
print(ans % (10**9 + 7))
|
N = int(input())
A = list(map(int, input().split()))
s = sum(A)
res = 0
mod = 10**9 + 7
for i in range(N-1):
s -= A[i]
res += s*A[i]
print(res%mod)
| 1 | 3,810,481,088,722 | null | 83 | 83 |
k=int(input())
ans=0
import itertools
import math
for seq in itertools.combinations_with_replacement(range(1,k+1),3):
if seq[0]==seq[1] or seq[1]==seq[2]:
if seq[0]!=seq[2]:
ans+=(math.gcd(seq[0],math.gcd(seq[1],seq[2])))*3
else:
ans+=math.gcd(seq[0],math.gcd(seq[1],seq[2]))
else:
ans+=math.gcd(seq[0],math.gcd(seq[1],seq[2]))*6
print(ans)
|
import math
nums = [int(e) for e in input().split()]
n = nums[0]
m = nums[1]
x = -1
y = -1
ms = []
if n%2 == 0:
x = 1
y = n
count = True
while x < y:
if y-x <= n/2 and count:
y -= 1
count = False
ms += [[x,y]]
x += 1
y -= 1
else:
x = 1
y = n
while x < y:
ms += [[x, y]]
x += 1
y -= 1
# print(ms)
for i in range(m):
print(str(ms[i][0]) + " " + str(ms[i][1]))
| 0 | null | 31,952,365,282,500 | 174 | 162 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.