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
|
---|---|---|---|---|---|---|
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 )
| n = int(input())
a = list(map(int,input().split()))
ans = "APPROVED"
for i in range(n):
if(a[i]%2==0)and((a[i]%3!=0)and(a[i]%5!=0)):
ans = "DENIED"
break
print(ans)
| 0 | null | 100,735,400,364,430 | 270 | 217 |
n=int(input())
a=list(map(int,input().split()))
ans=0
tempi=[0]*n
tempj=[0]*n
for i in range(n):
tempi[i]=a[i]+i+1
for i in range(n):
tempj[i]=-a[i]+i+1
import collections
tempid=collections.Counter(tempi)
tempjd=collections.Counter(tempj)
for k in tempid.keys():
a=tempid[k]
b=tempjd[k]
ans=ans+a*b
print(ans) | N = int(input())
A = list(map(int, input().split()))
L = {}
R = {}
ans = 0
for i in range(N):
t = i + 1 + A[i]
if t in L:
L[t] += 1
else:
L[t] = 1
t = i + 1 - A[i]
if t > 0:
if t in R:
R[t] += 1
else:
R[t] = 1
for i in R:
if i in L:
ans += R[i] * L[i]
print(ans) | 1 | 26,185,077,404,122 | null | 157 | 157 |
from collections import deque
n = int(input())
Ps = []
for _ in range(n):
lis = list(map(int, input().split()))
if len(lis)>2:
Ps.append(lis[2:])
else:
Ps.append([])
ans = [-1]*n
ans[0] = 0
queue = deque()
checked = deque()
[queue.append([p, 1]) for p in Ps[0]]
checked.append(1)
while queue:
t, pa = queue.popleft()
if not t in checked:
for i in Ps[t-1]:
queue.append([i, t])
ans[t-1] = ans[pa-1]+1
checked.append(t)
for i, a in enumerate(ans):
print(i+1, a)
| N, M = map(int, input().split())
A = map(int, input().split())
A_sum = sum(A)
if (N - A_sum) >= 0:
print(N - A_sum)
else:
print(-1) | 0 | null | 15,919,184,675,052 | 9 | 168 |
def sprint(str, a, b):
print(str[a:b+1])
def reverse(str, a, b):
str1 = str[:a]
str2 = str[a: b+1]
str3 = str[b+1:]
str = str1 + str2[::-1] + str3
return str
def replace(str, a, b, p):
str1 = str[:a]
str3 = str[b+1:]
str = str1 + p + str3
return str
str = input()
q = int(input())
for i in range(q):
L = input().split()
if L[0] == "replace":
str = replace(str, int(L[1]), int(L[2]), L[3])
if L[0] == "reverse":
str = reverse(str, int(L[1]), int(L[2]))
if L[0] == "print":
sprint(str, int(L[1]), int(L[2])) | n = int(input())
h_list = list(map(int,input().split()))
a_dict = dict()
b_dict = dict()
for i in range(n):
a = h_list[i]+i
b = i-h_list[i]
if not a in a_dict:
a_dict[a] = 1
else:
a_dict[a] += 1
if not b in b_dict:
b_dict[b] = 1
else:
b_dict[b] += 1
count = 0
for a in a_dict:
if a in b_dict:
count += a_dict[a]*b_dict[a]
print(count)
| 0 | null | 14,187,275,047,242 | 68 | 157 |
n = int(input())
a = list(map(int, input().split()))
l = [0] * n
for i in a:
l[i - 1] += 1
for k in range(n):
print(l[k]) | n=int(input())
a=list(map(int,input().split()))
if n==1:
print(1)
else:
min1=a[0]
ans=1
for x in range(1,n):
if min1>=a[x]:
ans+=1
min1=min(min1,a[x])
print(ans) | 0 | null | 59,029,886,571,710 | 169 | 233 |
n, m = map(int, input().split())
wa = [0] * n
ac = [False] * n
for i in range(m):
p, s = input().split()
p = int(p) - 1
if s == 'WA' and not ac[p]:
wa[p] += 1
elif s == 'AC':
ac[p] = True
wa_n = sum(wa[i] if ac[i] else 0 for i in range(n))
print("{} {}".format(sum(ac), wa_n)) | n,m=map(int,input().split())
data=[0]*n
s=set()
sum_wa=0
for i in range(m):
p,a=input().split()
p=int(p)-1
if p in s:
continue
else:
if a=='WA':
data[p]+=1
else:
sum_wa+=data[p]
s.add(p)
print(len(s),sum_wa) | 1 | 93,494,859,760,858 | null | 240 | 240 |
from collections import deque
def bfs(G,dist,s):
q = deque([])
dist[s] = 0
q.append(s)
while len(q) > 0:
v = q.popleft()
for nv in G[v]:
if dist[nv] != -1:
continue
dist[nv] = dist[v] + 1
q.append(nv)
n,m = map(int,input().split())
G = [[] for _ in range(n)]
for i in range(m):
a,b = map(int,input().split())
G[a-1].append(b-1)
G[b-1].append(a-1)
dist = [-1]*n
cnt = 0
for v in range(n):
if dist[v] != -1:
continue
bfs(G,dist,v)
cnt += 1
print(cnt-1) | code = r"""
# distutils: language=c++
# distutils: include_dirs=/opt/ac-library
from libcpp cimport bool
from libcpp.vector cimport vector
cdef extern from "<atcoder/dsu>" namespace "atcoder":
cdef cppclass dsu:
dsu(int n)
int merge(int a, int b)
bool same(int a, int b)
int leader(int a)
int size(int a)
vector[vector[int]] groups()
from libc.stdio cimport getchar, printf
cdef inline int read() nogil:
cdef int b, c = 0
while 1:
b = getchar() - 48
if b < 0: return c
c = c * 10 + b
cdef int n = read(), i
cdef dsu *u = new dsu(n)
for i in range(read()): u.merge(read() - 1, read() - 1)
printf('%lu\n', u.groups().size() - 1)
"""
import os, sys
if sys.argv[-1] == 'ONLINE_JUDGE':
open('solve.pyx', 'w').write(code)
os.system('cythonize -i -3 -b solve.pyx')
import solve | 1 | 2,273,177,806,184 | null | 70 | 70 |
m = 100000
rate = 0.05
n = int(input())
for i in range(n):
m += m*rate
x = m%1000
m -= x
while(x % 1000 != 0):
x += 1
m += x
print(str(int(m)))
| base, rate = 100, 0.05
for _ in range(int(input())):
increment = base * rate
base += round(increment + (0 if increment.is_integer() else 0.5))
print(base * 1000) | 1 | 1,001,710,400 | null | 6 | 6 |
from copy import deepcopy
n, m, q = map(int, input().split())
tuples = [tuple(map(int, input().split())) for i in range(q)]
As = [[1]*n]
def next(A, i):
if i == 0 and A[i] == m:
return
if A[i] == m:
next(A, i-1)
elif A[i] < m:
if (i < n - 1 and A[i] < A[i+1]) or (i == n-1):
A1 = deepcopy(A)
A1[i] += 1
As.append(A1)
next(A1, i)
if i > 0 and A[i] > A[i-1]:
A2 = deepcopy(A)
next(A2, i-1)
elif i == 0:
A1 = deepcopy(A)
next(A1, n-1)
next([1]*(n), n-1)
def check(A):
score = 0
for a, b, c, d in tuples:
if A[b-1] - A[a-1] == c:
score += d
return score
ans = 0
for A in As:
score = check(A)
ans = max(ans, score)
print (ans) | import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
idx = 1
def resolve():
def dfs(v):
global idx
begin[v] = idx
idx += 1
for u in edge[v]:
if begin[u] != 0:
continue
else:
dfs(u)
end[v] = idx
idx += 1
n = int(input())
edge = [[] for _ in range(n)]
for _ in range(n):
u, k, *V = map(int, input().split())
for v in V:
edge[u - 1].append(v - 1)
begin = [0] * n
end = [0] * n
for i in range(n):
if begin[i] == 0:
dfs(i)
for i in range(n):
print(i + 1, begin[i], end[i])
if __name__ == '__main__':
resolve()
| 0 | null | 13,877,469,788,472 | 160 | 8 |
X=int(input())
A=0
B=0
for i in range(-120,120):
for k in range(-120,120):
if i**5==X+k**5:
A=i
B=k
break
print(A,B) | n = int(input())
fib = [1]*2 + [0]*(n-1)
for i in range(2, n+1):
fib[i] = fib[i-1] + fib[i-2]
print(fib[n]) | 0 | null | 12,785,894,588,578 | 156 | 7 |
x = int(input())
if -40 <= x and x <= 40:
if x >= 30:
print("Yes")
else:
print("No") | print(f'{"Yes" if int(input()) >= 30 else "No"}') | 1 | 5,738,081,995,140 | null | 95 | 95 |
H, N = map(int,input().split())
X = [list(map(int, input().split())) for i in range(N)]
X = sorted(X, key = lambda x:x[0])
DP = [float("inf")]*(H+X[-1][0]+X[-1][0])
DP[X[-1][0]-1] = 0
for i in range(X[-1][0], H+2*X[-1][0]):
min = float("inf")
for j in range(N):
if min > DP[i-X[j][0]]+X[j][1]:
min = DP[i-X[j][0]]+X[j][1]
DP[i] = min
kouho = DP[H+X[-1][0]-1]
for i in range(X[-1][0]):
if kouho > DP[H+X[-1][0]+i]:
kouho = DP[H+X[-1][0]+i]
print(kouho)
| '''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"
def main():
h,n = map(int,ipt().split())
atks = [tuple(map(int,ipt().split())) for i in range(n)]
dam = [10**18]*(h+1)
dam[0] = 0
for i in range(1,h+1):
for aj,bj in atks:
if aj > i:
if dam[i] > bj:
dam[i] = bj
elif dam[i] > dam[i-aj]+bj:
dam[i] = dam[i-aj]+bj
print(dam[h])
return None
if __name__ == '__main__':
main()
| 1 | 80,855,545,879,780 | null | 229 | 229 |
S, W =map(int, input().split())
print('unsafe') if W >= S else print('safe') | from itertools import permutations
n = int(input())
l = [tuple(map(int,input().split())) for _ in range(2)]
a = list(permutations(range(1,n+1)))
print(abs(a.index(l[0]) - a.index(l[1]))) | 0 | null | 65,034,814,996,448 | 163 | 246 |
S = input()
if(S[len(S)-1] == 's'):print(S + 'es')
else :print(S + 's') | import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
s = input()
if s[-1]=="s":
s += "es"
else:
s += "s"
print(s) | 1 | 2,399,013,076,250 | null | 71 | 71 |
def main():
n, m = map(int, (input().split()))
a = [list(map(int, list(input().split()))) for item in range(n)]
b = [int(input()) for item in range(m)]
c = [sum(a_im * b_m for (a_im, b_m) in zip(a_i, b)) for a_i in a]
for c_i in c:
print(c_i)
main() | def gcd(a,b):
if a%b==0:
return b
else :
return gcd(b,a%b)
def main():
a,b=map(int,raw_input().split())
print(gcd(a,b))
if __name__=='__main__':
main() | 0 | null | 589,514,890,030 | 56 | 11 |
line = list(input())
N = len(line)
i = 1
for i in range(N):
if line[i] == "?":
line[i] = "D"
print("".join(line)) | n = int(input())
d = {}
for i in range(n):
s = str(input())
if s in d.keys():
d[s] += 1
else:
d[s] = 1
max_count = max(d.values())
for i in sorted(d.keys()):
if d[i] == max_count:
print(i) | 0 | null | 44,187,640,783,220 | 140 | 218 |
def main():
N, M = map(int, input().split())
if N == M:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main() | #ライブラリの読み込み
import math
#入力値を格納
n,m = map(int,input().split())
#判定
if n == m:
text = "Yes"
else:
text = "No"
#結果を表示
print(text) | 1 | 83,726,507,862,260 | null | 231 | 231 |
import math
r = float(input())
print(float(r ** 2 * math.pi), float(r * 2 * math.pi))
| import math
r = input()
print '%f %f' % (r * r * math.pi, 2 * r * math.pi) | 1 | 635,136,926,060 | null | 46 | 46 |
X = int(input())
ans = X // 500 * 1000
ans += X % 500 // 5 * 5
print(ans) | from math import sqrt
itl = lambda: list(map(float, input().strip().split()))
def median(N, C):
if N % 2:
return C[N // 2]
else:
return C[N // 2 - 1] + C[N // 2]
def solve():
N = int(input())
A = []
B = []
for _ in range(N):
a, b = itl()
A.append(int(a))
B.append(int(b))
A.sort()
B.sort()
ma = median(N, A)
mb = median(N, B)
return mb - ma + 1
if __name__ == '__main__':
print(solve()) | 0 | null | 30,264,933,977,728 | 185 | 137 |
n,k = map(int,input().split())
t = [0] * n
for _ in range(k):
d = int(input())
a = list(map(int,input().split()))
for e in a:
t[e-1] += 1
ans = 0
l = [i for i in t if i == 0]
# print(l)
print(len(l)) | M1,D1 = [ int(i) for i in input().split() ]
M2,D2 = [ int(i) for i in input().split() ]
print("1" if M1 != M2 else "0")
| 0 | null | 74,696,020,864,740 | 154 | 264 |
h, n = map(int, input().split())
inf = 10 ** 9
dp = [inf for _ in range(h + 1)]
dp[0] = 0
for _ in range(n):
a, b = map(int, input().split())
for i in range(h + 1):
if i < a:
dp[i] = min(dp[i], b)
else:
dp[i] = min(dp[i], dp[i - a] + b)
print(dp[-1]) | h,n=map(int,input().split())
ab=[[] for i in range(n)]
for i in range(n):
ab[i]=list(map(int,input().split()))
dp=[100000000 for i in range(h+1)]
dp[0]=0
for hi in range(h):
for i in range(n):
damage=min(h,hi+ab[i][0])
dp[damage] = min(dp[damage],dp[hi]+ab[i][1])
#print(damage,dp[damage],dp[hi]+ab[i][1])
print(dp[h]) | 1 | 81,411,797,657,388 | null | 229 | 229 |
import sys
input = sys.stdin.readline
class Node:
def __init__(self, val):
self.val = val
self.prev = None
self.next = None
class DoublyLinkedList:
def __init__(self):
self.sentinel = Node(None)
self.sentinel.prev = self.sentinel
self.sentinel.next = self.sentinel
def insert(self, val):
node = Node(val)
node.prev = self.sentinel
node.next = self.sentinel.next
self.sentinel.next.prev = node
self.sentinel.next = node
def delete(self, val):
self.delete_node(self.search(val))
def deleteFirst(self):
self.delete_node(self.sentinel.next)
def deleteLast(self):
self.delete_node(self.sentinel.prev)
def search(self, val):
cursor = self.sentinel.next
while cursor != self.sentinel and cursor.val != val:
cursor = cursor.next
return cursor
def delete_node(self, node):
if node == self.sentinel:
return
node.prev.next = node.next
node.next.prev = node.prev
n = int(input())
linked_list = DoublyLinkedList()
for index in range(n):
command = input().rstrip()
if command[0] == 'i':
linked_list.insert(command[7:])
elif command[6] == 'F':
linked_list.deleteFirst()
elif command[6] == 'L':
linked_list.deleteLast()
else:
linked_list.delete(command[7:])
node = linked_list.sentinel.next
output = []
while node != linked_list.sentinel:
output.append(node.val)
node = node.next
print(" ".join(map(str, output)))
| from collections import deque
from sys import stdin
n = int(input())
line = stdin.readlines()
ddl = deque()
for i in range(n):
inp = line[i].split()
if len(inp) == 2:
op, data = inp
data = int(data)
else: op, data = inp[0], None
if op == 'insert':
ddl.appendleft(data,)
elif op == 'delete':
try:
ddl.remove(data)
except ValueError:
pass
elif op == 'deleteFirst':
ddl.popleft()
elif op == 'deleteLast':
ddl.pop()
print(' '.join([str(item) for item in ddl])) | 1 | 48,696,090,912 | null | 20 | 20 |
# -*- coding: utf-8 -*-
list = map(int, raw_input().split())
a = list[0]
b = list[1]
if a < b:
print "a < b"
elif a > b:
print "a > b"
else:
print "a == b" | inArray = str(input()).split(" ")
if int(inArray[0]) < int(inArray[-1]):
print("a < b")
elif int(inArray[0]) > int(inArray[-1]):
print("a > b")
else:
print("a == b")
| 1 | 366,598,088,598 | null | 38 | 38 |
N, M, X = map(int,input().split())
CA = list(list(map(int,input().split())) for _ in range(N))
cost = (10 ** 5) * 12
for i in range(2 ** N):
total, a = 0, [0] * M
for j in range(N):
if i >> j & 1:
total += CA[j][0]
for k in range(M): a[k] += CA[j][k + 1]
for j in range(M):
if a[j] < X:
if i == 2 ** N - 1: cost = -1
break
else: cost = min(cost, total)
print(cost) | from collections import deque
import numpy
N, M, X = [int(x) for x in input().split()]
stack = deque()
stack.appendleft((numpy.array([0] * M, dtype='int64'), 0, 0))
min_cost = 10**9
book_list = {}
while stack:
info = stack.popleft()
skill = info[0]
cost = info[1]
book_idx = info[2]
if book_idx < N:
if book_idx in book_list:
book = book_list[book_idx]
else:
book = numpy.array([int(x)
for x in input().split()], dtype='int64')
book_list[book_idx] = book
after_skill = skill + book[1:]
after_cost = cost+book[0]
stack.appendleft((after_skill, after_cost, book_idx+1))
stack.appendleft((skill, cost, book_idx+1))
else:
if cost < min_cost:
if numpy.all(skill >= X):
min_cost = cost
if min_cost == 10**9:
print(-1)
else:
print(min_cost)
| 1 | 22,367,866,770,238 | null | 149 | 149 |
import math
PI = math.pi
r = input()
men = r*r * PI
sen = r*2 * PI
print('%.6f %.6f' % (men, sen)) | K = int(input())
S = input()
print(S if len(S) <= K else S[:K] + '...')
| 0 | null | 10,148,600,066,262 | 46 | 143 |
a = [int(c) for c in input().split()]
r = a[0]*a[1]
if a[0] == 1 or a[1] == 1:
print(1)
elif r % 2 == 0:
print(int(r/2))
else:
print(int(r/2+1))
| N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N):
for j in range(N):
for k in range(N):
if i < j < k and L[i] < L[j] < L[k] and L[i] + L[j] > L[k]:
ans += 1
print(ans)
| 0 | null | 27,908,382,498,930 | 196 | 91 |
import sys
from collections import deque
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
n = I()
A = LI()
q = I()
m = LI()
ans = 0
partial_sum = set()
for i in range(2 ** n):
bit = [i>>j&1 for j in range(n)]
partial_sum.add(sum(A[k]*bit[k] for k in range(n)))
for x in m:
print('yes' if x in partial_sum else 'no')
| n = int(input())
a = list(map(int, input().split()))
q = int(input())
m = dict(zip(range(q), list(map(int, input().split()))))
ans = ["no"] * q
for i in range(2**n):
now = 0
for j in range(n):
if i >> j & 1:
now += a[j]
if now in m.values():
key_lst = [key for key, value in m.items() if value==now]
for key in key_lst:
ans[key] = "yes"
for i in range(q):
print(ans[i])
| 1 | 97,930,256,740 | null | 25 | 25 |
n=int(input())
score=[0,0,0]
for _ in range(n):
tc,hc=map(str,input().split())
if tc==hc:
score[1]+=1
score[-1]+=1
continue
i=0
ml=min(len(tc),len(hc))
while tc[i]==hc[i]:
i+=1
if i>=ml:
tc+="0"
hc+="0"
break
r=ord(tc[i])-ord(hc[i])
r=r//abs(r)
score[r]+=3
print("{} {}".format(score[1],score[-1]))
| n = int(input())
count_taro = 0
count_hanako = 0
for i in range(n):
taro,hanako = map(str, input().split())
if taro > hanako:
count_taro += 3
if hanako > taro:
count_hanako += 3
if hanako == taro:
count_hanako += 1
count_taro += 1
print(count_taro, count_hanako)
| 1 | 1,978,784,887,170 | null | 67 | 67 |
def isPrime(n):
for i in range(2, n):
if i * i > n:
return 1
if n % i == 0:
return 0
return 1
ans = 0
n = int(input())
for i in range(n):
x = int(input())
ans = ans + isPrime(x)
print(ans)
| def p(x):
for i in[2,3,5,7,9,11,13,17,19,21,23]:
if x%i==0:return [1,0][x>i]
i=29
while i<=x**.5:
if x%i==0:return 0
i+=2
return 1
n=int(input())
print(sum([p(int(input()))for _ in range(n)])) | 1 | 10,461,955,898 | null | 12 | 12 |
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]
def f():
if m == 0:
if n == 1:
return 0
elif n == 2:
return 10
elif n == 3:
return 100
else:
for i in range(1000):
x = str(i)
if len(x) == n:
cnt = 0
for j in range(m):
if x[sc[j][0] - 1] == str(sc[j][1]):
cnt += 1
if cnt == m:
return x
elif x[sc[j][0] - 1] != str(sc[j][1]):
break
return -1
print(f()) |
try:
inp = input().split()
L = int(inp[0])
R = int(inp[1])
d = int(inp[2])
if L >= 1 and R >= 1 and L <= R and L<=100 and R<=100 and d>=1 and d<=100:
counter = 0
for i in range(L,R+1):
if i%d == 0:
counter += 1
print(counter)
except Exception as e:
print(e) | 0 | null | 34,303,952,923,788 | 208 | 104 |
def resolve():
MOD = 10**9+7
N, K = map(int, input().split())
cnt = [0]*(K+1)
for g in range(K, 0, -1):
cnt[g] = pow(K//g, N, MOD) # (K//g)**N
gg = g*2
while gg <= K:
cnt[g] -= cnt[gg]
gg += g
ans = 0
for g in range(1, K+1):
ans += cnt[g] * g
ans %= MOD
print(ans)
if __name__ == "__main__":
resolve() | import sys
input=lambda :sys.stdin.readline().rstrip()
mod = 10**9+7
n, k = map(int, input().split())
d = [0] * (k+1)
for i in range(1, k+1):
d[i] = pow(k//i, n, mod)
for i in range(k, 0, -1):
for j in range(2*i, k+1, i):
d[i] -= d[j]
d[i] %= mod
ans=0
for i in range(1, k+1):
ans += d[i]*i
ans %= mod
print(ans) | 1 | 36,634,766,265,718 | null | 176 | 176 |
K = int(input())
acl = 'ACL'
op = ''
for k in range(K):
op += acl
print(op) | n=int(input())
a=("")
for _ in range(n):
a=a+"ACL"
print(a) | 1 | 2,197,731,642,470 | null | 69 | 69 |
N = int(input())
A = list(map(int, input().split()))
ans = 1
A.sort()
ans = 1
for a in A:
ans *= a
if ans == 0:
break
if ans > 10 ** 18:
ans = -1
break
print(ans)
| debt = 100000
n=int(raw_input())
for i in range(1,n+1):
debt = debt*1.05
if(debt % 1000) != 0:
debt = (debt - (debt%1000)) + 1000
print int(debt) | 0 | null | 8,104,085,127,984 | 134 | 6 |
import bisect
N=int(input())
rllist=[]
for _ in range(N):
X,L=map(int,input().split())
rllist.append((X+L,X-L))
rllist.sort()
#print(rllist)
dp=[0]*N
dp[0]=1
for i in range(1,N):
r,l=rllist[i]
pos=bisect.bisect(rllist,(l,float("inf")))
#print(i,pos)
if pos==0:
dp[i]=dp[i-1]
else:
dp[i]=max(dp[i-1],dp[pos-1]+1)
#print(dp)
print(dp[-1]) | n=int(input())
itv=[]
for i in range(n):
x,l=map(int,input().split())
itv+=[(x+l,x-l)]
itv=sorted(itv)
l=-10**18
cnt=0
for t,s in itv:
if l<=s:
l=t
cnt+=1
print(cnt) | 1 | 89,887,163,726,752 | null | 237 | 237 |
#coding:UTF-8
n = input()
a = map(int,raw_input().split())
a.reverse()
for i in range(n):
print a[i], | n = input()
a = map(str,raw_input().split())
print ' '.join(a[::-1]) | 1 | 990,810,339,600 | null | 53 | 53 |
def give_grade(m, f, r):
if m == -1 or f == -1:
return "F"
elif m + f < 30:
return "F"
elif m + f < 50:
return "D" if r < 50 else "C"
elif m + f < 65:
return "C"
elif m + f < 80:
return "B"
else:
return "A"
while True:
m, f, r = map(int, input().split())
if m == f == r == -1:
break
else:
print(give_grade(m, f, r)) | while True:
x = []
x = input().split( )
y = [int(s) for s in x]
if sum(y) == -3:
break
if y[0] == -1 or y[1] == -1:
print("F")
elif y[0] + y[1] < 30:
print("F")
elif y[0] + y[1] >= 30 and y[0] + y[1] <50:
if y[2] >= 50:
print("C")
else:
print("D")
elif y[0] + y[1] >= 50 and y[0] + y[1] <65:
print("C")
elif y[0] + y[1] >= 65 and y[0] + y[1] <80:
print("B")
elif y[0] + y[1] >= 80:
print("A")
| 1 | 1,227,012,428,890 | null | 57 | 57 |
N = int(input())
a = [int(i) for i in input().split()]
frag = 1
i = 0
count = 0
while frag:
frag = 0
for j in range(N-1,i,-1):
if a[j] < a[j-1]:
a[j], a[j-1] = a[j-1], a[j]
count += 1
frag = 1
i += 1
print(" ".join(map(str, a)))
print(count) | N=int(input())
A=list(map(int,input().split()))
c=0
flug = 1
while flug:
flug = 0
for j in range(1,N)[::-1]:
if A[j]<A[j-1]:
A[j],A[j-1]=A[j-1],A[j]
flug=1
c+=1
print(*A)
print(c) | 1 | 15,679,500,122 | null | 14 | 14 |
if __name__ == '__main__':
for i in range(1,10):
for j in range(1,10):
print(str(i)+"x"+str(j)+"="+str(i*j)) | S = input()
length = len(S)
if length % 2 == 0:
length = int(length / 2)
S_half_1 = S[:length]
S_half_2 = S[(length):]
S_half_2 = S_half_2[::-1]
else:
length = int(length // 2)
S_half_1 = S[:length]
S_half_2 = S[(length + 1) :]
S_half_2 = S_half_2[::-1]
ans = 0
for i in range(length):
if S_half_1[i] != S_half_2[i]:
ans += 1
print(ans)
| 0 | null | 59,886,613,691,410 | 1 | 261 |
from sys import exit
import math
import collections
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
a,b = mi()
print((a*b)//math.gcd(a,b)) | a,b=map(int,input().split())
if a>b:
if a%b==0:
gcd=b
else:
p=a
q=b
r=p%q
while r!=0:
p=q
q=r
r=p%q
if r==0:
gcd=q
break
elif a<b:
if b%a==0:
gcd=a
else:
p=b
q=a
r=p%q
while r!=0:
p=q
q=r
r=p%q
if r==0:
gcd=q
break
A=a//gcd
B=b//gcd
print(A*B*gcd) | 1 | 113,751,262,305,450 | null | 256 | 256 |
n = int(input())
a = [0] * n
x = [0] * n
y = [0] * n
for i in range(n):
a[i] = int(input())
t = [[int(j) for j in input().split()] for k in range(a[i])]
x[i] = [j[0] for j in t]
y[i] = [j[1] for j in t]
mx = 0
for bit in range(1<<n):
flag = True
tf = [0] * n
for i in range(n):
if bit & (1 << i):
tf[i] = 1
for i in range(n):
if tf[i] == 0:
continue
for j in range(a[i]):
if tf[x[i][j]-1] != y[i][j]:
flag = False
if flag: mx = max(mx, bin(bit).count("1"))
print(mx) | #import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions import gcd
#input=sys.stdin.readline
import bisect
n,m=map(int,input().split())
class UnionFind(): #集合の取り扱い、辺に重み、階層を意識するときは使えない
def __init__(self,n):
self.n=n
self.par = [-1]*n
def find(self,x):
if self.par[x] <0: #負なら親、要素数
return x
else: #正なら親の番号
self.par[x]=self.find(self.par[x]) #一回調べたら根を繋ぎ変える、経路圧縮
return self.par[x]
def union(self,x,y):
x=self.find(x) #x,yの親
y=self.find(y)
if x==y: #親が同じなら何もしない
return
if self.par[x]>self.par[y]: #要素数が大きい方をxにする
x,y=y,x
self.par[x]+=self.par[y] #xがある集合にyが入った集合をくっつける
self.par[y]=x
def size(self,x):
return -self.par[self.find(x)] #親のサイズ
def same(self,x,y): #親が同じ、すなわち同じ集合か
return self.find(x)==self.find(y)
def member(self,x): #同じ木(集合)にある要素全部リストで返す
root = self.find(x)
return [i for i in range(self.n) if self.find(i)==root ]
def roots(self): #集合の根になってる要素をリストで返す
return [i for i , x in enumerate(self.par) if x<0]
def group_count(self): #集合の数、木の数
return len(self.roots())
def all_member(self): #辞書型で返す
return {r: self.member(r) for r in self.roots()}
def __str__(self):
return "\n".join('{}:{}'.format(r,self.member(r)) for r in self.roots)
tree=UnionFind(n)
for i in range(m):
a,b=map(int,input().split())
tree.union(a-1,b-1)
print(tree.group_count()-1) | 0 | null | 62,004,311,946,182 | 262 | 70 |
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
class Combination:
"""
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):
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
co = Combination(200006)
n,m = inpl()
if m >= n:
m = n-1
res = 1
if m == 1:
print(co(n-1,n-2) * n)
quit()
else:
for i in range(m):
tmp = i+1
res += co(n-1,n-tmp-1) * co(n,tmp)
res %= mod
# print(res)
print(res) | a, b, k = map(int, input().split())
if a >= k:
a = a - k
else:
b = b + a - k
a = 0
if b < 0:
b = 0
print(str(a) + " " + str(b))
| 0 | null | 85,575,285,297,108 | 215 | 249 |
s=[]
for p in input().split():
if p in "+-*":
b=s.pop()
a=s.pop()
s.append(str(eval(a+p+b)))
else:
s.append(p)
print(*s)
| import sys
sys.setrecursionlimit(10000)
ERROR_INPUT = 'input is invalid'
OPECODE = ['+', '-', '*']
BUF = []
def main():
stack = get_input()
ans = calc_stack(stack=stack)
print(ans)
def calc_stack(stack):
if stack[-1] in OPECODE:
BUF.append(stack[-1])
stack.pop()
return calc_stack(stack=stack)
else:
right_num = int(stack[-1])
stack.pop()
if stack[-1] in OPECODE:
BUF.append(right_num)
BUF.append(stack[-1])
stack.pop()
return calc_stack(stack=stack)
else:
left_num = int(stack[-1])
stack.pop()
stack.append(calc(left_num, right_num, BUF[-1]))
BUF.pop()
stack.extend(reversed(BUF))
BUF.clear()
if len(stack) == 1:
return stack[0]
else:
return calc_stack(stack=stack)
def calc(left, right, ope):
if ope == '+':
return left + right
elif ope == '-':
return left - right
elif ope == '*':
return left * right
def get_input():
inp = input().split(' ')
opecode_count = 0
OPECODE_count = 0
for i in inp:
if i in OPECODE:
opecode_count += 1
elif int(i) < 0 or int(i) > 10**6:
print(ERROR_INPUT)
sys.exit(1)
else:
OPECODE_count += 1
if opecode_count < 1 or opecode_count > 100:
print(ERROR_INPUT)
sys.exit(1)
if OPECODE_count < 2 or OPECODE_count > 100:
print(ERROR_INPUT)
sys.exit(1)
return inp
main() | 1 | 36,695,083,850 | null | 18 | 18 |
def binary_search(key):
"""二分探索法 O(logN)
Args:
key (int): 基準値
Vars:
ok (int): 条件を満たすindexの上限値/下限値
ng (int): 条件を満たさないindexの下限値-1/上限値+1
Returns:
int: 条件を満たす最小値/最大値
"""
ok = 10 ** 12
ng = -1
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if isOK(mid, key):
ok = mid
else:
ng = mid
return ok
def isOK(i, key):
"""条件判定
Args:
i (int): 判定対象の値
key (int): 基準値
Returns:
bool: iが条件を満たすか否か
"""
cnt = 0
for v, d in l:
if v > i:
cnt += (v - i + d - 1) // d
return cnt <= key
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort(reverse=True)
f.sort()
l = []
for i in range(n):
l.append([a[i]*f[i], f[i]])
print(binary_search(k)) | n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
a=sorted(a)
f=sorted(f,reverse=True)
def is_lessthanK(X):
ans=0
for A,F in zip(a,f):
if A*F>X:
ans+=A-X//F
if ans > k:
return False
return True
ng=-1
ok=a[-1]*f[0]
while ok-ng>1:
mid=(ok+ng)//2
if is_lessthanK(mid):
ok=mid
else:
ng=mid
print(ok)
| 1 | 165,211,218,988,910 | null | 290 | 290 |
N = input()
A = map(int,raw_input().split())
for i in range(N-1):
print A[i],
print A[-1]
for i in range(1,N):
v = A[i]
j = i - 1
while j >= 0 and A[j] > v:
A[j+1] = A[j]
j -= 1
A[j+1] = v
for i in range(N-1):
print A[i],
print A[-1] | n = int(raw_input())
a = map(int, raw_input().split())
print " ".join(map(str, a))
for i in range(1, n):
v = a[i]
j = i -1
while j >= 0 and a[j] > v:
a[j+1] = a[j]
j-=1
a[j+1] = v
print " ".join(map(str, a))
| 1 | 5,934,583,720 | null | 10 | 10 |
from queue import deque
S = input()
Q = int(input())
Query = list(input().split() for _ in range(Q))
count = 0
L, R = deque(), deque()
for i in range(Q):
if Query[i][0] == "1": count += 1
else:
if Query[i][1] == "1":
if count % 2 == 0: L.appendleft(Query[i][2])
else: R.append(Query[i][2])
else:
if count % 2 == 0: R.append(Query[i][2])
else: L.appendleft(Query[i][2])
L, R = "".join(L), "".join(R)
if count % 2 == 0: print(L + S + R)
else: print(R[::-1] + S[::-1] + L[::-1]) | #!/usr/bin/env python3
#import
#import math
#import numpy as np
s = input()
q = int(input())
inv = False
fro = ""
end = ""
for _ in range(q):
query = list(map(str, input().split()))
if query[0] == "1":
inv = not inv
else:
t = int(query[1])
instr = query[2]
if not inv:
if t == 1:
fro = instr + fro
else:
end = end + instr
else:
if t == 1:
end = end + instr[::-1]
else:
fro = instr[::-1] + fro
ans = fro + s + end
if not inv:
print(ans)
else:
print(ans[::-1]) | 1 | 57,586,652,458,400 | null | 204 | 204 |
n,m=map(int,input().split())
d={}
ind=[0]*n
for i in range(n):
d[i+1]='*'
for j in range(m):
s,c=map(int,input().split())
if ind[s-1]==0:
d[s]=c
ind[s-1]=1
else:
if d[s]!=c:
print(-1)
exit(0)
ans=''
if n>=2:
if d[1]==0:
print(-1)
exit(0)
for k in range(n):
if k==0:
if n>=2:
if d[k+1]=='*':
ans+='1'
else:
ans+=str(d[k+1])
else:
if d[k+1]=='*':
ans+='0'
else:
ans+=str(d[k+1])
else:
if d[k+1]=='*':
ans+='0'
else:
ans+=str(d[k+1])
print(ans) | n = int(input())
array = list(map(int, input().split()))
print("{} {} {}".format(min(array), max(array), sum(array)))
| 0 | null | 30,677,581,922,680 | 208 | 48 |
N = [int(i) for i in input()]
n = N[::-1]+[0]
for i in range(len(n)-1):
if n[i] >= 6 or (n[i] == 5 and n[i+1] >= 5):
n[i] = 10 - n[i]
n[i+1] += 1
print(sum(n))
| S = input()
if len(S) % 2 != 0:
print('No')
exit()
tmp = [S[i:i+2] for i in range(0, len(S), 2)]
for s in tmp:
if s != 'hi':
print('No')
exit()
print('Yes')
| 0 | null | 62,296,994,775,666 | 219 | 199 |
import sys
import math
N = int(input())
A = map(int, input().split())
s = [0] * N
for a in A:
s[a-1] += 1
for i in range(N):
print(s[i])
| k = int(input())
a, b = map(int, input().split())
f = False
for i in range(a, b+1):
if i%k == 0:
print('OK')
f = True
break
if f is False:
print('NG')
| 0 | null | 29,463,503,472,242 | 169 | 158 |
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce
rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7
a, b, x = rm()
x /= a
if a*b / 2 >= x:
a = 2*x / b
print(90 - math.degrees(math.atan(a/b)))
else:
x = a*b - x
b = 2*x / a
print(math.degrees(math.atan(b/a)))
| a, b, x = map(int, input().split())
if x > (a**2)*b/2:
t = 2*((a**2)*b-x)/(a**3)
else:
t = a*(b**2)/(2*x)
import math
ans = math.degrees(math.atan(t))
print(ans)
| 1 | 162,641,279,507,730 | null | 289 | 289 |
N = int(input())
ary = [int(_) for _ in input().split()]
def selection_sort(ary, verbose=True):
count = 0
for i in range(0, N):
minj = i
for j in range(i, N):
if ary[j] < ary[minj]:
minj = j
if i != minj:
ary[i], ary[minj] = ary[minj], ary[i]
count += 1
print(' '.join([str(_) for _ in ary]))
if verbose:
print(count)
selection_sort(ary)
| n, m, l = map(int, input().split())
A = []
B = []
C = [[] for i in range(n)]
for i in range(n):
tmp_row = list(map(int, input().split()))
A.append(tmp_row)
for i in range(m):
tmp_row = list(map(int, input().split()))
B.append(tmp_row)
for i in range(n):
for bj in zip(*B):
c = sum(aik * bjk for aik, bjk in zip(A[i], bj))
C[i].append(c)
for i in C:
print(*i) | 0 | null | 729,068,638,552 | 15 | 60 |
import math
r = float(input())
if r > 0 and r < 10000:
circle_length = (r * 2) * math.pi
circle_area = r * r * math.pi
print("{0:f} {1:f}".format(circle_area, circle_length))
else:
pass | N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
loop_flags = [False] * N
loops = []
for i in range(N):
if loop_flags[i]:
continue
next_cell = i
loop = []
while not loop_flags[next_cell]:
loop_flags[next_cell] = True
loop.append(C[next_cell])
next_cell = P[next_cell] - 1
if loop:
loops.append(loop)
# print(loops)
ans = C[0]
for loop in loops:
work_loop_sum = []
now = 0
tmp_ans = 0
one_loop_point = sum(loop)
if one_loop_point <= 0 or K <= len(loop):
for i in range(1, min(K + 1, len(loop) + 1)):
tmp_ans = sum(loop[:i])
for j in range(len(loop)):
ans = max(tmp_ans, ans)
tmp_ans = tmp_ans - loop[j] + loop[(i + j) % len(loop)]
else:
for i in range(min(K + 1, len(loop) + 1)):
tmp_ans = sum(loop[:i]) + ((K - i) // len(loop)) * one_loop_point
for j in range(len(loop)):
ans = max(tmp_ans, ans)
tmp_ans = tmp_ans - loop[j] + loop[(i + j) % len(loop)]
print(ans) | 0 | null | 3,017,560,133,088 | 46 | 93 |
N, M = map(int, input().split())
s = [0] * M
c = [0] * M
for i in range(M):
s[i], c[i] = map(int, input().split())
ran = []
for i in range(10 ** (N - 1), 10 ** N):
ran.append(i)
if N == 1:
ran.append(0)
ran.sort()
minimum = 10 ** N
for r in ran:
st = str(r)
ok = True
for j in range(M):
if st[s[j] - 1] != str(c[j]):
ok = False
if ok == True:
minimum = min(minimum, r)
break
if minimum == 10 ** N:
print(-1)
else:
print(minimum)
| n = int(input())
*bLst, = input().split()
iLst = bLst[:]
for i in range(n):
for j in range(n-1,i,-1):
if bLst[j][1] < bLst[j-1][1]:
bLst[j],bLst[j-1] = bLst[j-1],bLst[j]
print(*bLst)
print("Stable")
for i in range(n):
min = i
for j in range(i,n):
if iLst[j][1] < iLst[min][1]:
min = j
iLst[i],iLst[min] = iLst[min],iLst[i]
print(*iLst)
if bLst == iLst:
print("Stable")
else:
print("Not stable")
| 0 | null | 30,530,227,495,580 | 208 | 16 |
def main():
n = int(input())
inlis = list(map(int, input().split()))
inset = set(inlis)
if len(inlis) == len(inset):
print("YES")
else:
print("NO")
if __name__ == "__main__":
main()
| n=int(input())
m=int(n/1.08)
for i in range(-2,3):
if int((m+i)*1.08)==n:
print(m+i)
exit()
print(":(") | 0 | null | 100,063,338,347,826 | 222 | 265 |
# E - Rem of Sum is Num
import queue
N, K = map(int, input().split())
A = list(map(int, input().split()))
S = [0] * (N + 1)
for i in range(N):
S[i + 1] = (S[i] + A[i] - 1) % K
v_set = set(S)
mp = {v: 0 for v in v_set}
ans = 0
q = queue.Queue()
for i in range(N + 1):
ans += mp[S[i]]
mp[S[i]] += 1
q.put(S[i])
if q.qsize() == K:
mp[q.get()] -= 1
print(ans) | from collections import defaultdict, deque
N, K = map(int, input().split())
A = list(map(int, input().split()))
cumA = [0] * (N + 1)
for i in range(1, N + 1):
cumA[i] = cumA[i - 1] + A[i - 1]
cnt = defaultdict(int)
que = deque([])
ans = 0
for i, c in enumerate(cumA):
while que and que[0][0] <= i - K:
cnt[que.popleft()[1]] -= 1
diff = (i - c) % K
ans += cnt[diff]
cnt[diff] += 1
que.append((i, diff))
print(ans) | 1 | 137,384,380,597,032 | null | 273 | 273 |
n = int(input())
print((n//2)/n if n%2==0 else (n//2+1)/n) | N=int(input())
ans=0
i=1
while i<=N:
if i%2!=0:
ans+=1
i+=1
print(ans/N)
| 1 | 177,290,409,034,328 | null | 297 | 297 |
def ra(a): #圧縮された要素を非保持
ll,l=[],1
for i in range(len(a)-1):
if a[i]==a[i+1]:
l+=1
else:
ll.append(l)
l=1
ll.append(l)
return ll
n=input()
print(len(ra(input()))) | N = int(input())
S = list(input())
n = 1
for i in range(1, N):
if S[i-1] != S[i]:
n += 1
print(n) | 1 | 170,171,212,395,132 | null | 293 | 293 |
def f():
N = int(input())
UP = []
DOWN = []
for _ in range(N):
S = input()
c = 0
minC = 0
for s in S:
if s == '(':
c += 1
else:
c -= 1
minC = min(minC, c)
if c >= 0:
UP.append((minC, c))
else:
DOWN.append((c - minC, c))
c = 0
for up in sorted(UP, reverse=True):
if c + up[0] < 0:
return False
c += up[1]
for down in sorted(DOWN, reverse=True):
if c + down[1] - down[0] < 0:
return False
c += down[1]
if c != 0:
return False
return True
if f():
print('Yes')
else:
print('No')
| def examA():
A, B = LI()
ans = A*B
print(ans)
return
def examB():
N = I()
A = LI()
for a in A:
if a==0:
print(0)
return
ans = 1
for a in A:
ans *= a
if ans>10**18:
print(-1)
return
print(ans)
return
def examC():
A, B = LSI()
ans =math.floor(int(A)*float(B))
print(ans)
return
def examD():
def factorization(n):
arr = defaultdict(int)
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[i] = cnt
if temp != 1:
arr[temp] = 1
if arr == []:
arr[n] = 1
return arr
C = [0,1,3,6,10,15,21,28,36,45]
N = I()
F = factorization(N)
ans = 0
#print(F)
for f in F.values():
for i in range(10):
if C[i]>f:
ans += i-1
break
print(ans)
return
def examE():
N = I()
A = [0]*N
B = [0]*N
for i in range(N):
A[i],B[i] = LI()
A.sort()
B.sort()
if N%2==0:
L = (A[N//2-1] + A[N//2])/2
R = (B[N//2-1] + B[N//2])/2
ans = int((R-L)*2) +1
else:
L = A[N//2]
R = B[N//2]
ans = (R-L)+1
print(ans)
return
def examF():
inv = pow(2,mod2-2,mod2)
N, S = LI()
A = LI()
dp = [[0]*(S+1)for _ in range(N+1)]
dp[0][0] = pow(2,N,mod2)
for i in range(N):
a = A[i]
for s in range(S+1):
dp[i+1][s] += dp[i][s]
dp[i+1][s] %= mod2
if (s+a<=S):
dp[i+1][s+a] += dp[i][s]*inv%mod2
dp[i + 1][s+a] %= mod2
# print(dp)
ans = dp[-1][-1]%mod2
print(ans)
return
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 1<<60
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]
sys.setrecursionlimit(10**7)
if __name__ == '__main__':
examF()
"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
""" | 0 | null | 20,671,018,118,608 | 152 | 138 |
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())
from collections import defaultdict
from collections import Counter
import bisect
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def main():
N = S()
K = I()
dig = len(N)
if dig < K:
print(0)
exit()
ans = 0
for i in range(dig):
if K == 0:
ans += 1
break
if int(N[i]) == 0:
continue
if dig - i - 1 >= K:
ans += combinations_count(dig - i - 1, K) * pow(9, K)
if dig - i - 1 >= K - 1:
ans += (int(N[i]) - 1) * combinations_count(dig - i - 1, K - 1) * pow(9, K - 1)
if i == dig - 1:
ans += 1
K -= 1
print(ans)
if __name__ == "__main__":
main()
| str_n = input()
keta = len(str_n)
not_zero = int(input())
dp = [[[0]*(not_zero+2) for _ in range(2)] for _ in range(keta+1)]
first = int(str_n[0])
dp[1][1][0] = 1
for k in range(1,10):
if first == k:
dp[1][0][1] += 1
elif first > k:
dp[1][1][1] += 1
for i in range(1,keta):
# smallerからsmallerへの遷移
for j in range(not_zero+1):
# i桁目をゼロにする
dp[i+1][1][j] += dp[i][1][j]
# i桁目でゼロ以外を使う
dp[i+1][1][j+1] += (dp[i][1][j])*9
nex = int(str_n[i])
# sameからsmallerへの遷移
if not nex == 0:
for j in range(not_zero+1):
# i桁目をぜろにする
dp[i+1][1][j] += dp[i][0][j]
# i桁目でゼロ以外
dp[i+1][1][j+1] += (dp[i][0][j]) * (nex-1)
# sameからsameへの遷移
if nex == 0:
for j in range(not_zero+1):
dp[i+1][0][j] = dp[i][0][j]
else:
for j in range(not_zero):
dp[i+1][0][j+1] = dp[i][0][j]
print(dp[keta][1][not_zero] + dp[keta][0][not_zero])
| 1 | 75,484,049,144,894 | null | 224 | 224 |
import sys
e=[list(map(int,e.split()))for e in sys.stdin]
n=e[0][0]+1
t=''
for c in e[1:n]:
for l in zip(*e[n:]):t+=f'{sum(s*t for s,t in zip(c,l))} '
t=t[:-1]+'\n'
print(t[:-1])
| n,m,l=map(int,input().split())
A = [tuple(map(int,input().split())) for _ in range(n)]
B = [tuple(map(int,input().split())) for _ in range(m)]
BT = tuple(map(tuple,zip(*B)))
for a in A:
temp=[]
for b in BT:
temp.append(sum([x*y for (x,y) in zip(a,b)]))
print(*temp) | 1 | 1,448,786,845,394 | null | 60 | 60 |
def main():
s,w = list(map(int,input().split()))
if s>w:
print("safe")
else:
print("unsafe")
main()
| # C Marks
N, K = map(int, input().split())
A = list(map(int, input().split())) # リストがうまく作れてない?
j = 0
i = K
ct = 1
while ct <= (N - K):
if A[j] < A[i]:
print("Yes")
else:
print("No")
j += 1
i += 1
ct += 1
| 0 | null | 18,153,977,108,364 | 163 | 102 |
T = list(input())
N = len(T)
count = 0
for i in range(N):
if T[i] == '?':
T[i] = 'D'
if (i < N - 1) and T[i] == 'P' and T[i + 1] == 'D':
count += 1
elif T[i] == 'D':
count += 1
#print(count)
ans = ''.join(T)
print(ans) | t = str(input())
ans = t.replace("?","D")
print(ans) | 1 | 18,366,348,863,740 | null | 140 | 140 |
a,b=map(int, input().split())
if a==b:
print("Yes");
else:
print("No");
| N,M=input().split()
print('NYoe s'[N==M::2]) | 1 | 82,865,063,510,788 | null | 231 | 231 |
n = int(input())
A = list(map(int,input().split()))
xor_sum = 0
for i in range(n):
xor_sum = xor_sum^A[i]
ans = []
for i in range(n):
ans.append(xor_sum^A[i])
print(' '.join(map(str,ans)))
| N=int(input())
for n in range(N):
sides = list(map(int,input().split()))
sides.sort()
if sides[-1]**2 == sides[-2]**2 + sides[-3]**2:
print("YES")
else:
print("NO") | 0 | null | 6,251,022,218,022 | 123 | 4 |
h = int(input())
layer = 0
branch_set = 0
while True :
if h > 1 :
h //= 2
layer += 1
continue
else :
break
for i in range(0, layer) :
branch_set += 2 ** i
print(branch_set + 2**layer)
| n=int(input())
x=list(input())
def str2int(z):
flag=1
a=0
for i in reversed(x):
if i=='1':a+=flag
flag*=2
return a
popc=x.count('1')
z=str2int(x)
if popc-1!=0:
fl_1=z%(popc-1)
fl_0=z%(popc+1)
for i in range(n):
if x[i]=='1':
if popc-1==0:
print(0)
continue
mod=(fl_1-pow(2,n-1-i,popc-1))%(popc-1)
else:mod=(fl_0+pow(2,n-1-i,popc+1))%(popc+1)
#print('mod : %s'%mod)
cnt=1
while mod!=0:
pp=bin(mod).count("1")
mod%=pp
cnt+=1
print(cnt) | 0 | null | 44,183,194,250,868 | 228 | 107 |
x = input()
X = int(x)
Pow = X*X*X
print (Pow) | from collections import deque
dq = deque()
for _ in [None]*int(input()):
s = input()
if s == "deleteFirst":
dq.popleft()
elif s == "deleteLast":
dq.pop()
else:
a, b = s.split()
if a == "insert":
dq.appendleft(b)
else:
if b in dq:
dq.remove(b)
print(" ".join(dq))
| 0 | null | 162,280,484,156 | 35 | 20 |
def insertionSort(A, n, g):
cnt=0
for i in range(g,n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt+=1
A[j+g] = v
return cnt,A
def shellSort(A, n):
cnt = 0
G = [1]
flag=True
while flag:
g = G[0]*3+1
if g < n:
G = [g] + G
else:
flag=False
m = len(G)
for i in range(m):
tmp_cnt,tmp_A = insertionSort(A, n, G[i])
cnt += tmp_cnt
print(m)
G_str = (list(map(lambda x:str(x),list(G))))
print(" ".join(G_str))
print(cnt)
for a in A:
print(a)
#print(A)
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
shellSort(A, n)
| def insertionSort( nums, n, g ):
cnt = 0
for i in range( g, len( nums ) ):
v = nums[i]
j = i - g
while 0 <= j and v < nums[j]:
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
return cnt
def shellSort( nums, n ):
cnt = 0
g = []
val =0
for i in range( 0, n ):
val = 3*val+1
if n < val:
break
g.append( val )
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
for i in range( 0, m ):
cnt += insertionSort( nums, n, g[i] )
print( cnt )
n = int( raw_input( ) )
nums = []
for i in range( 0, n ):
nums.append( int( raw_input( ) ) )
shellSort( nums, n )
for i in nums:
print( i ) | 1 | 32,485,309,460 | null | 17 | 17 |
sent=""
while True:
try:
ex=input().lower()
sent+=ex
except:
break
for i in range(ord("a"),ord("z")+1):
x=sent.count(chr(i))
print(chr(i),":",x) | l = list(map(int, input().split()))
s = input()
for c in s:
if c == "S":
l = [l[4], l[0], l[2], l[3], l[5], l[1]]
elif c == "N":
l = [l[1], l[5], l[2], l[3], l[0], l[4]]
elif c == "E":
l = [l[3], l[1], l[0], l[5], l[4], l[2]]
else:
l = [l[2], l[1], l[5], l[0], l[4], l[3]]
print(l[0])
| 0 | null | 969,197,223,488 | 63 | 33 |
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9
import fractions
def main():
a,b = map(int, input().split())
print(a*b//fractions.gcd(a, b))
if __name__ == '__main__':
main()
| N = input()
lenN = len(N)
sumN = 0
for x in N:
sumN += int(x)
if sumN > 9:
sumN %= 9
if sumN % 9 == 0:
print('Yes')
else:
print('No') | 0 | null | 58,626,305,733,450 | 256 | 87 |
import math
class Triangle():
def __init__(self, edge1, edge2, angle):
self.edge1 = edge1
self.edge2 = edge2
self.angle = angle
self.edge3 = math.sqrt(edge1 ** 2 + edge2 ** 2 - 2 * edge1 * edge2 * math.cos(math.radians(angle)))
self.height = edge2 * math.sin(math.radians(angle))
self.area = edge1 * self.height / 2
a, b, theta = [int(i) for i in input().split()]
triangle = Triangle(a, b, theta)
print(triangle.area)
print(triangle.edge1 + triangle.edge2 + triangle.edge3)
print(triangle.height)
| import math
a, b, c = map(float,input().split())
e = b*math.sin(math.radians(c))
print(a*e/2)
print(((a-b*math.cos(math.radians(c)))**2+e**2)**0.5+a+b)
print(e)
| 1 | 177,059,543,682 | null | 30 | 30 |
#coding: UTF-8
l = raw_input().split()
W = int(l[0])
H = int(l[1])
x = int(l[2])
y = int(l[3])
r = int(l[4])
if x >=r:
if y >=r:
if x <=(H -r):
if y <=(H-r):
print "Yes"
else:
print "No"
else:
print"No"
else:
print "No"
else:
print "No" | n = int(input())
x = list(input())
def popcount(n):
bin_n = bin(n)[2:]
count = 0
for i in bin_n:
count += int(i)
return count
cnt = 0
for i in range(n):
if x[i] == '1':
cnt += 1
plus = [0 for i in range(n)] # 2^index を cnt+1 で割った時のあまり
minus = [0 for i in range(n)] # 2^index を cnt-1 で割った時のあまり
if cnt == 0:
plus[0] = 0
else:
plus[0] = 1
if cnt != 1:
minus[0] = 1
for i in range(1, n):
plus[i] = (plus[i-1]*2) % (cnt+1)
if cnt != 1:
minus[i] = (minus[i-1]*2) % (cnt-1)
origin = int(''.join(x), base=2)
amariplus = origin % (cnt+1)
if cnt != 1:
amariminus = origin % (cnt-1)
for i in range(n):
if x[i] == '0':
amari = (amariplus + plus[n-i-1]) % (cnt+1)
else:
if cnt != 1:
amari = (amariminus - minus[n-i-1]) % (cnt-1)
else:
print(0)
continue
ans = 1
while amari != 0:
ans += 1
amari = amari % popcount(amari)
print(ans) | 0 | null | 4,357,397,626,374 | 41 | 107 |
#coding:utf-8
#1_6_D 2015.4.5
n,m = map(int,input().split())
matrix = [list(map(int,input().split())) for i in range(n)]
vector = [int(input()) for i in range(m)]
for i in range(n):
print(sum([matrix[i][j] * vector[j] for j in range(m)])) | import collections
n,x,y = map(int,input().split())
h = [[] for _ in range(n+1) ]
for i in range(1,n+1):
if i+1<n+1:
h[i].append(i+1)
if i-1>0:
h[i].append(i-1)
h[x].append(y)
h[y].append(x)
k = [0]*n
for i in range(1,n+1):
q = collections.deque([i])
step = [-1]*(n+1)
step[i] = 0
while q:
now = q.popleft()
for hh in h[now]:
if step[hh] == -1:
q.append(hh)
step[hh] = step[now]+1
k[step[now]+1] += 1
for i in range(1,n):
print(k[i]//2) | 0 | null | 22,557,580,870,620 | 56 | 187 |
a5=[]
while True:
x=int(input())
if x==0:
break
a5.append(x)
j = 0
for i in a5:
print("Case " + str(j+1)+": "+ str(i))
j=j+1
| import sys, itertools
for count, input in zip(itertools.count(1), sys.stdin):
if int(input) == 0: break
print('Case {0}: {1}'.format(count, input), end='') | 1 | 487,952,288,338 | null | 42 | 42 |
def check(i,N,Ls):
count=0
for j in range(N):
if (i>>j)%2==1:
for k in Ls[j]:
if ((i>>(k[0]-1))%2)!=k[1]:
return 0
count+=1
return count
N=int(input())
A_ls=[]
Ls=[]
for i in range(N):
A=int(input())
A_ls.append(A)
ls=[]
for j in range(A):
x,y=map(int,input().split())
ls.append((x,y))
Ls.append(ls)
ans=0
for i in range(2**N):
num=check(i,N,Ls)
if num>ans:
ans=num
print(ans) | import collections
N=int(input())
A=list(map(int,input().split()))
A=sorted(A)
c=collections.Counter(A)
if __name__=="__main__":
if 1 in A:
if c[1]==1:
print(1)
else:
print(0)
else:
A=[]
dp=[True for _ in range(10**6+10)]
for key,value in c.items():
if value==1:
A.append(key)
else:
if dp[key]:
i=2
while i*key<=10**6:
dp[i*key]=False
i+=1
if len(A)==0:
print(0)
else:
for a in A:
if dp[a]:
i=2
while i*a<=10**6:
dp[i*a]=False
i+=1
ans=0
for a in A:
if dp[a]:
ans+=1
print(ans)
| 0 | null | 67,731,600,369,412 | 262 | 129 |
N = int(input())
S = input()
A = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
ans = ''
for s in S:
ans += A[(A.index(s)+N)%26]
print(ans) |
def resolve():
x,y=(int(i) for i in input().split())
if x==1 and y==1:
print(1000000)
return
c=0
if x==1:
c+=300000
if x==2:
c+=200000
if x==3:
c+=100000
if y==1:
c+=300000
if y==2:
c+=200000
if y==3:
c+=100000
print(c)
if __name__ == "__main__":
resolve() | 0 | null | 137,919,543,002,528 | 271 | 275 |
import sys
N = int(input())
A = list(map(int, input().split()))
a=1
if 0 in A:
print('0')
sys.exit()
for i in range(N):
a=A[i]*a
if a>10**18:
print('-1')
sys.exit()
print(a) | N = int(input())
A = map(int,input().split())
ans = 1
for x in A:
ans *= x
if ans > 10**18:
ans = 10**18+1
print(-1 if ans > 10**18 else ans) | 1 | 16,177,475,495,528 | null | 134 | 134 |
n,k,c=map(int,input().split())
s=input()
l=len(s)
cand=[]
for i in range(l):
if s[i]=='o':
cand.append(i+1)
cnt1=[0]*(n+c+2)
cnt2=[0]*(n+c+2)
for i in range(l):
if s[i]=='o':
cnt1[i+1]=max(cnt1[i],cnt1[i-c]+1)
else:
cnt1[i+1]=cnt1[i]
for i in range(l-1,-1,-1):
if s[i]=='o':
cnt2[i+1]=max(cnt2[i+2],cnt2[i+c+2]+1)
else:
cnt2[i+1]=cnt2[i+2]
ans=[]
for i in range(len(cand)):##嘘に見える
tmp=cand[i]
if cnt1[tmp-1]+cnt2[tmp+1]<k:
print(tmp)
| coin , mon = map(int,input().split())
if coin*500 >= mon:
print("Yes")
else:
print("No") | 0 | null | 69,169,926,591,260 | 182 | 244 |
S = input()
T = input()
s = len(S)
t = len(T)
ans1 = 10000000
for i in range(s - t + 1):
ans = 0
for j in range(t):
if T[j] != S[i + j]:
ans += 1
ans1 = min(ans, ans1)
print(ans1)
|
def main():
pass
N = int(input())
A = list(map(int, input().split()))
H = [0]*N
for i in range(0,N):
if i >= A[i]:
H[i-A[i]] += 1
ans = 0
for k in range(0,N):
Bk = k+A[k]
if Bk < N:
ans += H[Bk]
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 15,002,371,674,990 | 82 | 157 |
W, H, x, y, r = list(map(int, input().split()))
x_right = x + r
x_left = x - r
y_up = y + r
y_down = y - r
if x_right <= W and x_left >= 0 and y_up <= H and y_down >= 0:
print("Yes")
else:
print("No")
| N,K = map(int,input().split())
P = list(map(int,input().split()))
P.sort()
ans = sum(P[0:K])
print(ans) | 0 | null | 6,065,601,264,800 | 41 | 120 |
import math
k = int(input())
wa = 0
aa = 0
for i in range(1,k+1):
for j in range(1,k+1):
aa =math.gcd(i,j)
for l in range(1,k+1):
wa +=math.gcd(aa,l)
print(wa) | import math
k = int(input())
k += 1
ans = 0
for a in range(1, k):
for b in range(1, k):
for c in range(1, k):
ans += math.gcd(a, math.gcd(b, c))
print(ans) | 1 | 35,449,393,379,130 | null | 174 | 174 |
n, m, l = map(int, input().split())
A = [[int(s) for s in input().split()] for i in range(n)]
B = [[int(s) for s in input().split()] for i in range(m)]
for x in range(n):
o = []
for y in range(l):
sum = 0
for z in range(m):
sum += A[x][z] * B[z][y]
o.append(str(sum))
print(" ".join(o)) | input();l=input().split();x=not'0'in l
for j in l:
x*=int(j);
if x>1e18:x=-1;break
print(x) | 0 | null | 8,846,429,627,332 | 60 | 134 |
while True:
a,b,c = input().split()
if b=='?':
break
elif b =='+':
d = int(a) + int(c)
elif b=='-':
d = int(a) - int(c)
elif b=='*':
d = int(a)*int(c)
else :
d = int(a)/int(c)
print(int(d)) | import numpy as np
h,w=map(int,input().split())
s=[input() for _ in range(h)]
dp=np.zeros((h,w),np.int64)
if s[0][0]=='#':
dp[0,0]=1
for i in range(h):
for j in range(w):
if (i,j)==(0,0):
continue
elif i==0:
if s[i][j-1]=='.' and s[i][j]=='#':
dp[i,j]=dp[i,j-1]+1
else:
dp[i,j]=dp[i,j-1]
elif j==0:
if s[i-1][j]=='.' and s[i][j]=='#':
dp[i,j]=dp[i-1,j]+1
else:
dp[i,j]=dp[i-1,j]
else:
dp[i,j]=min(dp[i,j-1]+1 if s[i][j-1]=='.' and s[i][j]=='#' else dp[i,j-1],dp[i-1,j]+1 if s[i-1][j]=='.' and s[i][j]=='#' else dp[i-1,j])
print(dp[-1,-1])
#print(dp) | 0 | null | 25,078,949,431,982 | 47 | 194 |
N = int(input())
As = list(map(int,input().split()))
As.sort()
M = 1000001
array = [0]*M
for a in As:
if array[a] != 0:
array[a] = 2
continue
for i in range(a,M,a):
array[i] += 1
ans = 0
for a in As:
if array[a] == 1:
ans += 1
print(ans)
| def push(S, top, x):
S.append(x)
top = top + 1
def pop(S, top):
t = int(S[top-1])
del S[top-1]
top = top -1
return t
if __name__ == "__main__":
top = 0
inpt = (input()).split()
n = len(inpt)
S = []
for i in range(0,n):
if inpt[i] == "+":
b = pop(S, top)
a = pop(S, top)
c = a + b
push(S, top, c)
elif inpt[i] == "-":
b = pop(S, top)
a = pop(S, top)
c = a - b
push(S, top, c)
elif inpt[i] == "*":
b = pop(S, top)
a = pop(S, top)
c = a * b
push(S, top, c)
else :
push(S, top, int(inpt[i]))
print(S[top-1]) | 0 | null | 7,161,219,971,228 | 129 | 18 |
# input here
_INPUT = """\
2 5
1 WA
1 AC
2 WA
2 AC
2 WA
2 AC
"""
def main():
n, m= map(int, input().split())
ps = [list(map(str,input().split())) for _ in range(m)]
str_l = ["WA"]*n
int_l = [0]*n
num = 0
ac = 0
for pp, s in ps:
p = int(pp)-1
if s == "AC":
str_l[p] = "AC"
else:
if str_l[p] != "AC":
int_l[p] += 1
for i in range(n):
if str_l[i] == "AC":
num += int_l[i]
ac += 1
print(ac,num)
# n, m = map(int, input().split())
# seikai = [False] * n
# matigai = [0] * n
# for i in range(m):
# p,q = map(str, input().split())
# p = int(p)-1
# if q == "AC":
# seikai[p] = True
# else:
# if seikai[p] != True:
# matigai[p] += 1
# correct = seikai.count(True)
# mistake = sum(matigai)
# print(correct, mistake)
if __name__ == '__main__':
import io
import sys
import math
import itertools
from collections import deque
# sys.stdin = io.StringIO(_INPUT)
main() | N = int(input())
import math
import sys
for i in range(1, 50000+1):
if math.floor(i * 1.08) == N:
print(i)
sys.exit()
print(":(") | 0 | null | 109,690,454,288,730 | 240 | 265 |
import numpy as np
import numpy.linalg as linalg
X, Y = map(int, input().split())
if Y%2 == 1:
print('No')
else:
A = np.array([[1, 1],
[2, 4]])
A_inv = linalg.inv(A)
B = np.array([X , Y])
C = np.dot(A_inv, B)
if C[0] >= 0 and C[1] >= 0 :
print('Yes')
else:
print('No')
| N = int(input())
print(N//2 if N/2 == N//2 else N//2 + 1) | 0 | null | 36,615,398,511,130 | 127 | 206 |
N = int(input())
S, T = input().split()
charac = []
for i in range(N):
charac += S[i]
charac += T[i]
print(''.join(charac))
| n=int(input())
s,t=map(str,input().split())
a=""
for i in range(2*n):
if i%2==0:
a=a+s[(i)//2]
else:
a=a+t[(i-1)//2]
print (a) | 1 | 111,749,026,044,640 | null | 255 | 255 |
from decimal import Decimal
A, B = input().split()
A = int(A)
if len(B) == 1:
B = int(B[0] + '00')
elif len(B) == 3:
B = int(B[0] + B[2] + '0')
else:
B = int(B[0]+B[2]+B[3])
x = str(A*B)
print(x[:-2] if len(x) > 2 else 0)
| n, m = map(int, input().split())
edge = [[] for _ in range(n)]
for _ in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
edge[a].append(b)
edge[b].append(a)
done = [False] * n
s = []
cnt = 0
for i in range(n):
if not done[i]:
s.append(i)
while not s == []:
v = s.pop()
done[v] = True
for nxt in edge[v]:
if not done[nxt]:
s.append(nxt)
cnt += 1
print(cnt - 1) | 0 | null | 9,430,600,843,040 | 135 | 70 |
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()) | """
何回足されるかで考えればよい。
真っ二つに切っていく。
各項は必ずM未満。
M項以内に必ずループが現れる。
"""
N,X,M = map(int,input().split())
memo1 = set()
memo2 = []
ans = 0
a = X
flag = True
rest = N
while rest > 0:
if a in memo1 and flag:
flag = False
for i in range(len(memo2)):
if memo2[i] == a:
loopStart = i
setSum = 0
for i in range(loopStart,len(memo2)):
setSum += memo2[i]**2 % M
loopStep = len(memo2)-loopStart
loopCount = rest // loopStep
ans += loopCount*setSum
rest -= loopCount*loopStep
else:
memo1.add(a)
memo2.append(a)
ans += a
a = a**2%M
rest -= 1
print(ans) | 1 | 2,824,304,918,942 | null | 75 | 75 |
n,*a = map(int,open(0).read().split())
all = 0
for i in a:
all^=i
print(*[all^i for i in a]) | # ABC153 E Crested Ibis vs Monster
f=lambda:map(int,input().split())
H,N=f()
# dp[n][h]:=nthまでで体力をh削るときの最小魔力
INF=10**9
dp=[[INF]*(H+1) for _ in [0]*(N+1)]
for i in range(N+1):
if i!=0:
a,b=f()
else:
a,b=0,0
for j in range(H+1):
if i==0:
if j==0:
dp[i][j]=0
else:
dp[i][j]=INF
else:
dp[i][j]=min(dp[i-1][j],dp[i][max(j-a,0)]+b)
print(dp[N][H]) | 0 | null | 46,855,367,385,398 | 123 | 229 |
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
q = int(input())
ans = sum(a)
count = Counter(a)
for _ in range(q):
b,c = map(int, input().split())
count[c] += count[b]
ans -= b*count[b]
ans += c*count[b]
count[b] = 0
print(ans) | N=int(input())
S=input()
count=0
for i in range(N):
if S[i]=='A':
if S[i+1:i+3]=='BC':
count+=1
print(count)
| 0 | null | 55,847,524,660,004 | 122 | 245 |
import math
while True:
N = int(input())
if N == 0:
break
S = list(map(int, input().split()))
S2 = [x ** 2 for x in S]
V = sum(S2)/N - (sum(S)/N) ** 2
print(math.sqrt(V)) | import statistics
def stddev(values):
""" calculate standard deviation
>>> s = stddev([70, 80, 100, 90, 20])
>>> print('{:.5f}'.format(s))
27.85678
>>> s = stddev([80, 80, 80])
>>> print('{:.5f}'.format(s))
0.00000
"""
return statistics.pstdev(values)
def run():
while True:
c = int(input()) # flake8: noqa
if c == 0:
break
values = [int(i) for i in input().split()]
print(stddev(values))
if __name__ == '__main__':
run()
| 1 | 186,727,366,442 | null | 31 | 31 |
mycode = r'''
# distutils: language=c++
# cython: language_level=3, boundscheck=False, wraparound=False
# cython: cdivision=True
# False:Cython はCの型に対する除算・剰余演算子に関する仕様を、(被演算子間の符号が異なる場合の振る舞いが異なる)Pythonのintの仕様に合わせ、除算する数が0の場合にZeroDivisionErrorを送出します。この処理を行わせると、速度に 35% ぐらいのペナルティが生じます。 True:チェックを行いません。
ctypedef long long LL
from libc.stdio cimport scanf, printf
from libcpp.vector cimport vector
ctypedef vector[LL] vec
cdef class UnionFind:
cdef:
LL N,n_groups
vec parent
def __init__(self, LL N):
self.N = N # ノード数
self.n_groups = N # グループ数
# 親ノードをしめす。負は自身が親ということ。
self.parent = vec(N,-1) # idxが各ノードに対応。
cdef LL root(self, LL A):
# print(A)
# ノード番号を受け取って一番上の親ノードの番号を帰す
if (self.parent[A] < 0):
return A
self.parent[A] = self.root(self.parent[A]) # 経由したノードすべての親を上書き
return self.parent[A]
cdef LL size(self, LL A):
# ノード番号を受け取って、そのノードが含まれている集合のサイズを返す。
return -self.parent[self.root(A)]
cdef bint unite(self,LL A,LL B):
# ノード番号を2つ受け取って、そのノード同士をつなげる処理を行う。
# 引数のノードを直接つなぐ代わりに、親同士を連結する処理にする。
A = self.root(A)
B = self.root(B)
# すでにくっついている場合
if (A == B):
return False
# 大きい方に小さい方をくっつけたほうが処理が軽いので大小比較
if (self.size(A) < self.size(B)):
A, B = B, A
# くっつける
self.parent[A] += self.parent[B] # sizeの更新
self.parent[B] = A # self.rootが呼び出されればBにくっついてるノードもすべて親がAだと上書きされる
self.n_groups -= 1
return True
cdef bint is_in_same(self,LL A,LL B):
return self.root(A) == self.root(B)
cdef LL N,M,_
scanf('%lld %lld',&N, &M)
cdef UnionFind uf = UnionFind(N)
cdef LL a,b
for _ in range(M):
scanf('%lld %lld',&a, &b)
uf.unite(a-1, b-1)
print(-min(uf.parent))
'''
import sys
import os
if sys.argv[-1] == 'ONLINE_JUDGE': # コンパイル時
with open('mycode.pyx', 'w') as f:
f.write(mycode)
os.system('cythonize -i -3 -b mycode.pyx')
import mycode
| class UnionFind:
def __init__(self,n):
self.par = [-1] * n # 負数は友達の数(自分を含む)初期値は自分-1、0と正数は根を示す
def root(self,x): # xの根を返す
if self.par[x] < 0: # xが根の時は、xを返す
return x
self.par[x] = self.root(self.par[x]) # 根でないときは、par[x]に根の根を代入
return self.par[x] # 根の根を返す
def union(self,x,y):
x = self.root(x)
y = self.root(y)
if x == y:
return
if self.par[x] > self.par[y]: # par[x]が小さく(友達が多く)なるように交換
x, y = y, x
self.par[x] += self.par[y] # 友達が多い方に少ない方を加える
self.par[y] = x # yの根をxにする
def size(self):
return -1 * min(self.par)
n, m = map(int, input().split())
uf = UnionFind(n)
for _ in range(m):
a, b = map(int, input().split())
uf.union(a-1,b-1) # 1が0番目、2が1番目・・・
print(uf.size()) | 1 | 3,930,722,732,704 | null | 84 | 84 |
INF = 10**18
N, K, C = map(int, input().split())
S = input()
lt = [-INF for _ in range(K + 1)]
rt = [-INF for _ in range(K + 1)]
j = -1
for i in range(1, K + 1):
while True:
j += 1
if S[j] == 'o' and j - lt[i - 1] > C:
lt[i] = j
break
j = -1
for i in range(1, K + 1):
while True:
j += 1
if S[-1 - j] == 'o' and j - rt[i - 1] > C:
rt[i] = j
break
lt = lt[1:]
rt = rt[1:]
rt = [N - x - 1 for x in rt]
rt = rt[::-1]
res = []
for i in range(K):
if lt[i] == rt[i]:
res.append(lt[i] + 1)
print('\n'.join(map(str, res)))
| import sys
input = sys.stdin.buffer.readline
from operator import itemgetter
import numpy as np
def main():
N,T = map(int,input().split())
food = []
for _ in range(N):
a,b = map(int,input().split())
food.append((a,b))
dp = np.zeros(T,dtype=int)
food.sort(key = itemgetter(0))
ans = 0
for a,b in food:
ans = max(ans,dp[-1]+b)
dp[a:] = np.maximum(dp[a:],dp[:-a]+b)
print(ans)
if __name__ == "__main__":
main() | 0 | null | 96,400,096,574,770 | 182 | 282 |
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=998244353
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1
N,S=map(int,input().split())
A=tuple(map(int,input().split()))
dp=[[0]*3001 for _ in range(N+1)]
dp[0][0]=1
for i in range(N):
for j in range(3001):
dp[i+1][j]+=dp[i][j]*2
dp[i+1][j]%=MOD
if j-A[i]>=0:
dp[i+1][j]+=dp[i][j-A[i]]
dp[i+1][j]%=MOD
print(dp[-1][S]) | def solve(n):
if n <= 1:
print(1)
return
a, b = 1, 1
for _ in range(2, n + 1):
c = a + b
b = a
a = c
print(c)
if __name__ == "__main__":
n = int(input())
solve(n)
| 0 | null | 8,898,814,477,180 | 138 | 7 |
h,w=map(int,input().split())
if h!=1 and w!=1:
print((h*w+2-1)//2)
else:
print(1)
| import time
import random
d = int(input())
dd = d * (d + 1) // 2
*C, = map(int, input().split())
S = [list(map(int, input().split())) for i in range(d)]
T = []
L = [-1 for j in range(26)]
for i in range(d):
max_diff = -10**7
arg_max = 0
for j in range(26):
memo = L[j]
L[j] = i
diff = S[i][j] - sum([C[k] * (i - L[k]) for k in range(26)])
if diff > max_diff:
max_diff = diff
arg_max = j
L[j] = memo
T.append(arg_max)
L[arg_max] = i
def calc_score(T):
L = [-1 for j in range(26)]
X = [0 for j in range(26)]
score = 0
for i in range(d):
score += S[i][T[i]]
X[T[i]] += (d - i) * (i - L[T[i]])
L[T[i]] = i
for j in range(26):
score -= C[j] * (dd - X[j])
return score
score = calc_score(T)
start = time.time()
cnt = 0
while True:
now = time.time()
if now - start > 1.8:
break
p = (cnt // 26) % d
q = cnt % 26
memo = T[p]
T[p] = q
new_score = calc_score(T)
temp = 20000 * (1 - (now - start) / 2)
prob = 2**((new_score - score) / temp)
if random.random() < prob:
score = new_score
else:
T[p] = memo
cnt = (cnt + 1) % (10**9 + 7)
for t in T:
print(t + 1)
| 0 | null | 30,242,285,061,360 | 196 | 113 |
num = int(input())
data = list(map(int, input().split()))
data.sort()
min = data[0]
max = data[-1]
avg = 0
for tmp in data:
avg += tmp
print(min,max,avg)
| N = int(input())
S = input()
Q = int(input())
qs = [input().split() for i in range(Q)]
def ctoi(c):
return ord(c) - ord('a')
class BinaryIndexedTree:
def __init__(self,size):
self.N = size
self.bit = [0]*(size+1)
def add(self,x,w): # 0-indexed
x += 1
while x <= self.N:
self.bit[x] += w
x += (x & -x)
def _sum(self,x): # 1-indexed
ret = 0
while x > 0:
ret += self.bit[x]
x -= (x & -x)
return ret
def sum(self,l,r): # [l,r)
return self._sum(r) - self._sum(l)
def __str__(self): # for debug
arr = [self.sum(i,i+1) for i in range(self.N)]
return str(arr)
bits = [BinaryIndexedTree(N) for i in range(26)]
s = []
for i,c in enumerate(S):
bits[ctoi(c)].add(i,1)
s.append(c)
ans = []
for a,b,c in qs:
if a=='1':
i = int(b)-1
bits[ctoi(s[i])].add(i,-1)
bits[ctoi(c)].add(i,1)
s[i] = c
else:
l,r = int(b)-1,int(c)
a = 0
for i in range(26):
if bits[i].sum(l,r):
a += 1
ans.append(a)
print(*ans,sep='\n') | 0 | null | 31,478,734,531,010 | 48 | 210 |
N,K=map(int,input().split())
P=[1 for i in range(N)]
for i in range(K):
d=int(input())
a=list(map(int,input().split()))
for j in a:
x=j-1
P[x]=0
print(sum(P)) | N, K = map(int, input().split())
ans = []
for i in range(K):
d = int(input())
ans += map(int, input().split())
print(N-len(set(ans))) | 1 | 24,657,996,551,442 | null | 154 | 154 |
import sys
stdin=sys.stdin
ip=lambda: int(sp())
lp=lambda:list(map(int,stdin.readline().split()))
sp=lambda:stdin.readline().rstrip()
a,b=lp()
print(max(0,a-2*b))
| # -*- coding: utf-8 -*-
def main():
A, B = map(int, input().split())
ans = A - 2 * B
if ans < 0:
ans = 0
print(ans)
if __name__ == "__main__":
main() | 1 | 166,614,894,045,248 | null | 291 | 291 |
from scipy import special
S = int(input())
top = S // 3
if top == 0:
print(0)
exit()
ans = 1
mod = 10 ** 9 + 7
for i in range(2, top + 1):
t = S - 3 * i
i -= 1
ans += special.comb(t+i, i, True)
print(ans % (mod))
|
M, N = input().split() # 2つ整数の読み取り
A=int(M)
B=N.replace(".","")
B=int(B)
C=A*B//100
print(C) | 0 | null | 9,960,070,398,600 | 79 | 135 |
t = int(input())
if t >= 30:
print('Yes')
else:
print('No') | now = int(input())
if now <30:
print("No")
else:
print("Yes") | 1 | 5,749,807,044,356 | null | 95 | 95 |
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
if i == 0:
continue
if a[i-1] > a[i]:
ans += a[i-1] - a[i]
a[i] += a[i-1] - a[i]
print(ans)
| N=int(input())
*A,=map(int,input().split())
ans=0
p=A[0]
for i in range(1,N):
if A[i]<p:
ans+=p-A[i]
else:
p=A[i]
print(ans) | 1 | 4,627,172,310,500 | null | 88 | 88 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.