code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
N = int(input())
a = list(map(int, input().split()))
x = 0
for r in a:
x ^= r
a = [str(x^r) for r in a]
a = ' '.join(a)
print(a) | N = int(input())
a = list(map(int,input().split()))
S = 0
for i in range(N):
S ^= a[i]
Ans = ""
for i in range(N):
print(S^a[i]) | 1 | 12,555,789,029,210 | null | 123 | 123 |
#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) | N =int(input())
A = sorted(list(map(int,input().split())))
B = 1
C = 10 ** 18
for i in range(N):
B = B * A[i]
if B == 0:
break
elif B > C:
B = -1
break
print(B)
| 1 | 16,252,121,467,842 | null | 134 | 134 |
n=int(input(''))
p=0
for i in range(n-1):
a=i+1
p=p+(n-1)//a
print(p) | N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]
li = [-1] * N
for s, c in SC:
if li[s - 1] == -1:
li[s - 1] = c
else:
if not li[s - 1] == c:
print(-1)
exit()
ans = ""
if N == 1:
print(max(0, li[0]))
exit()
for i in range(N):
if i == 0:
if li[i] == 0:
print(-1)
exit()
else:
ans += str(max(li[i], 1))
else:
ans += str(max(0, li[i]))
print(ans) | 0 | null | 31,803,272,422,348 | 73 | 208 |
n = list(map(int,input().split()))
a = list(map(int,input().split()))
for i in range(n[1],n[0]):
if a[i-n[1]] < a[i]:
print("Yes")
else:
print("No") | #E
H,N=map(int,input().split())
A=[0 for i in range(N)]
dp=[float("inf") for i in range(10**4+1)]
dp[0]=0
for i in range(N):
a,b=map(int,input().split())
A[i]=a
for j in range(10**4+1):
if j+a>10**4:
break
dp[j+a]=min(dp[j]+b,dp[j+a])
if H+max(A)>10**4:
print(min(dp[H:]))
else:
print(min(dp[H:H+max(A)])) | 0 | null | 43,946,717,153,618 | 102 | 229 |
#ABC147 C やってる途中
n=int(input())
l=[]
for i in range(n):
a=int(input())
l_=[]
for j in range(a):
xy=list(map(int,input().split()))
l_.append(xy)
l.append(l_)
ans=0
for i in range(2**n):
table=[0]*n
flag=False
for j in range(n):
if (i>>j)&1:
table[j]=1
for j in range(n):
for k in l[j]:
if k[1]!=table[k[0]-1] and table[j]==1:
flag=True
break
if flag:
break
if flag==True:
continue
ans = max(ans, table.count(1))
print(ans) | stack = []
res = []
area = input()
for i, terrain in enumerate(area):
if terrain == '\\':
stack.append(i)
elif terrain == '/' and len(stack)>0:
left = stack.pop()
pond = i - left
if len(res) == 0 or left >= res[-1][0]:
res.append([left,pond])
else:
while len(res) > 0 and left < res[-1][0] :
pond += res[-1][1]
res.pop()
res.append([left,pond])
total = 0
ponds = []
for i in res:
ponds.append(i[1])
total += i[1]
ans = [len(res)]
ans += ponds
ans_new = " ".join(map(str,ans))
print(total)
print(ans_new)
| 0 | null | 60,612,140,341,710 | 262 | 21 |
N,K = map(int,input().split())
# from scipy.special import comb
# a = comb(n, r)
MOD = 10**9 + 7
ans = 0
for k in range(K,N+2):
# print(k)
right = (N+N-k+1)*k // 2
left = (k-1)*k // 2
ans += right - left + 1
ans %= MOD
# print(ans)
# ans += comb(N+1, k, exact=True)
# print(ans)
print(ans) | S=0
a,b=map(int,input().split())
for N in range(b,a+2):
S+=(((a-N+1)*N)+1)
print(S%(10**9+7)) | 1 | 32,993,337,935,232 | null | 170 | 170 |
import sys
if __name__ == "__main__":
n = int(sys.stdin.readline())
inp = sys.stdin.readlines()
lis = set()
for i in range(n):
com = inp[i].split()
if com[0] == "insert":
lis.add(com[1])
elif com[1] in lis:
print("yes")
else:
print("no") | op = "$"
while op != "?":
a, op, c = map(str, raw_input().split())
a = int(a)
c = int(c)
if op == "+":
print u"%d" % (a+c)
elif op == "-":
print u"%d" % (a-c)
elif op == "*":
print u"%d" % (a*c)
elif op == "/":
print u"%d" % (a/c)
else:
break | 0 | null | 381,545,589,672 | 23 | 47 |
N = input()
print("Yes" if N.count("7") > 0 else "No") | n = input()
if '7' in n :
print('Yes')
else :
print('No') | 1 | 34,293,683,162,892 | null | 172 | 172 |
k = int(input())
s = list(input())
an_lis = []
if len(s) <= k:
ans = "".join(s)
print(ans)
else:
for i in range(k):
an_lis.append(s[i])
an_lis.append("...")
ans = "".join(an_lis)
print(ans)
| k=int(input())
s=input()
l=len(s)
if l<=k:
print(s)
else:
s=list(s)
t=[]
for i in range(k):
t.append(s[i])
t.append('...')
print(''.join(t))
| 1 | 19,603,436,444,828 | null | 143 | 143 |
N, M = map(int, input().split())
A = [int(i) for i in input().split()]
print(N-sum(A) if N-sum(A) >= 0 else -1) | N = int(input())
# 最後の数字+1以下じゃないとだめ
# abc -> 次はa,b,c,d
dic = ["a","b","c","d","e","f","g","h","i","j"]
strs = ["a"]
cnt = 1
while cnt < N:
tmps = []
for s in strs:
for i,d in enumerate(dic[::-1]):
if d in s:
ind = len(dic)-i-1
break
# print(s,ind,dic[i])
for i in range(ind+2):
tmps.append(s+dic[i])
cnt += 1
strs = tmps[:]
for s in strs:
print(s) | 0 | null | 42,357,238,175,644 | 168 | 198 |
import math
a, b = input().split(" ")
a = int(a)
b = int(b)
print(int(a * b / math.gcd(a, b))) | N = int(input())
S = input()
A = ['']
for i in S:
if i != A[-1]:
A.append(i)
print(len(''.join(A))) | 0 | null | 141,263,301,712,608 | 256 | 293 |
s = input()
print(s[:3].lower()) | S = str(input())
ans = S[0:3]
print(ans) | 1 | 14,786,445,632,420 | null | 130 | 130 |
R = int(input())
print(R**2) | r=int(input())
print(r*r)
| 1 | 145,070,714,545,062 | null | 278 | 278 |
inf = 10**9 + 7
def merge(A, left, mid, right):
cnt = 0
L = A[left:mid]
R = A[mid:right]
L.append(inf)
R.append(inf)
i, j = 0, 0
for k in range(left, right):
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
cnt += 1
return cnt
def merge_sort(A, left, right):
cnt = 0
if left + 1 < right:
mid = (left + right) // 2
cnt += merge_sort(A, left, mid)
cnt += merge_sort(A, mid, right)
cnt += merge(A, left, mid, right)
return cnt
n = int(input())
*A, = map(int, input().split())
cnt = merge_sort(A, 0, n)
print(*A)
print(cnt)
| def merge(A, left, mid, right):
global count
n1 = mid - left
n2 = right - mid
L=[]
R=[]
# for i in range(n1):
# L.append(A[left + i])
# for i in range(n2):
# R.append(A[mid + i])
L=A[left:mid]
R=A[mid:right]
L.append(10e10)
R.append(10e10)
i = 0
j = 0
for k in range(left , right):
count +=1
if L[i] <= R[j]:
A[k] = L[i]
i = i + 1
else:
A[k] = R[j]
j = j + 1
def mergeSort(A, left, right):
if left+1 < right:
mid = (left + right)//2
mergeSort(A, left, mid)
mergeSort(A, mid, right)
merge(A, left, mid, right)
n = int(input())
A = list(map(int, input().split()))
count = 0
mergeSort(A, 0, n)
print(*A)
print(count)
| 1 | 111,048,395,352 | null | 26 | 26 |
def read_n_lows_input(n):
Alist=[int(input()) for i in range(n)]
return Alist
def print_list(A):
print(*A, sep=" ")
def print_list_multi_low(A):
for i in A:
print(i)
def insertion_sort(A, n, g, cnt):
for i in range(g-1, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j -= g
cnt += 1
A[j+g] = v
return A, cnt
def shell_sort(A, n):
cnt = 0
G0 = [797161, 265720, 88573, 29524, 9841, 3280, 1093, 364, 121, 40, 13, 4, 1]
G = [i for i in G0 if i <= n]
m = len(G)
print(m)
print_list(G)
for i in range(m):
A, cnt = insertion_sort(A, n, G[i], cnt)
print(cnt)
print_list_multi_low(A)
n=int(input())
A = read_n_lows_input(n)
shell_sort(A, n)
| import sys
readline = sys.stdin.readline
def insertionSort(A, n, g, cnt):
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 -= g
cnt += 1
A[j + g] = v
return cnt
def shellSort(A, n):
cnt = 0
h = 4
G = [1]
while h < n:
G += [h]
h = 3 * h + 1
m = len(G)
for i in range(m - 1, -1, -1):
cnt = insertionSort(A, n, G[i], cnt)
print(m)
print(*G[::-1])
print(cnt)
print(*A, sep="\n")
n = int(input())
A = [int(readline()) for _ in range(n)]
shellSort(A, n)
| 1 | 30,320,750,240 | null | 17 | 17 |
S = input()
ans = 0
tmp = 0
for i in range(len(S)):
if S[i] == "R":
tmp += 1
ans = max(ans, tmp)
else:
tmp = 0
print(ans)
| def main():
s = input()
if s in ["hi", "hihi", "hihihi", "hihihihi", "hihihihihi"]:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
| 0 | null | 28,852,119,320,964 | 90 | 199 |
import sys
input = sys.stdin.readline
r,c,k = map(int,input().split())
l = [[0]*c for i in range(r)]
for i in range(k):
x,y,v = map(int,input().split())
l[x-1][y-1] = v
dp = [[0]*4 for i in range(c+1)]
for i in range(r):
ndp = [[0]*4 for i in range(c+1)]
for j in range(c):
M = max(dp[j+1])
if l[i][j]>0:
v = l[i][j]
ndp[j+1][0] = max(M,dp[j][0],ndp[j][0])
ndp[j+1][1] = max(M+v,dp[j][0]+v,ndp[j][0]+v,dp[j][1],ndp[j][1])
ndp[j+1][2] = max(dp[j][1]+v,ndp[j][1]+v,dp[j][2],ndp[j][2])
ndp[j+1][3] = max(dp[j][2]+v,ndp[j][2]+v,dp[j][3],ndp[j][3])
else:
ndp[j+1][0] = max(M,dp[j][0],ndp[j][0])
ndp[j+1][1] = max(dp[j][1],ndp[j][1])
ndp[j+1][2] = max(dp[j][2],ndp[j][2])
ndp[j+1][3] = max(dp[j][3],ndp[j][3])
dp = ndp
print(max(dp[-1])) | R,C,K=map(int,input().split())
l=[[0] * C for i in range(R)]
for i in range(K):
a,b,c=map(int,input().split())
a-=1
b-=1
l[a][b]=c
dp=[0]*C
for i in range(R):
ndp=[0]*C
kdp=[0]*4
for j in range(0,C):
kdp[0]=max(kdp[0],dp[j])
for k in range(2,-1,-1):
kdp[k+1]=max(kdp[k+1],kdp[k]+l[i][j])
ndp[j]=max(kdp)
dp=ndp
print(dp[C-1])
| 1 | 5,511,629,352,040 | null | 94 | 94 |
def solve(l):
e = l.pop()
if e == '*':
return solve(l) * solve(l)
elif e == '+':
return solve(l) + solve(l)
elif e == '-':
return - solve(l) + solve(l)
else:
return int(e)
formula = input().split()
print(solve(formula)) | # coding: utf-8
stack = []
f = input().split()
for s in f:
if s in ('+', '-', '*'):
stack.append(str(eval("{1}{2}{0}".format(stack.pop(), stack.pop(), s))))
else:
stack.append(s)
print(*stack) | 1 | 35,429,007,640 | null | 18 | 18 |
def resolve():
S = input()
Q = int(input())
reverse = False
import collections
left = collections.deque([])
right = collections.deque([])
for i in range(Q):
query = input().split()
if query[0] == "1":
reverse = (not reverse)
continue
if query[1] == "1":
if reverse:
right.append(query[2])
else:
left.appendleft(query[2])
elif query[1] == "2":
if reverse:
left.appendleft(query[2])
else:
right.append(query[2])
if reverse:
ans = "{}{}{}".format("".join(reversed(right)), "".join(reversed(S)), "".join(reversed(left)))
else:
ans = "{}{}{}".format("".join(left), S, "".join(right))
print(ans)
if '__main__' == __name__:
resolve() | #!/usr/bin/env python3
from sys import stdin, stdout
def solve():
n = int(stdin.readline().strip())
seqA = []
seqB = []
for i in range(n):
a,b = map(int, stdin.readline().split())
seqA.append(a)
seqB.append(b)
seqA = sorted(seqA)
seqB = sorted(seqB)
mA = seqA[n//2]
mB = seqB[n//2]
if n%2==0:
mA += seqA[n//2-1]
mB += seqB[n//2-1]
print(mB-mA+1)
solve() | 0 | null | 37,543,108,725,628 | 204 | 137 |
r = int(input())
print(2*r*3.1415926535) | if __name__ == '__main__':
from sys import stdin
input = stdin.readline
from collections import deque, defaultdict
from copy import deepcopy
INFTY = -1 # 探索しなかったやつを-1としてprintしやすくするために-1とした。
n = int(input())
M = [[0]*n for _ in range(n)]
def bfs(s):
q = deque()
q.append(s)
d = [INFTY]*n
d[s] = 0
while q: # qが空だとwhileループから抜ける
u = q.popleft() # pythonのdequeはpopleft関数で戻り値がpopした要素になる
for v in range(n):
if M[u][v] == 0:
continue
if d[v] != INFTY:
continue
d[v] = d[u] + 1
q.append(v)
for i in range(n):
print(str(i+1) + ' ' + str(d[i]))
for _ in range(n):
u, k, *vv = map(int, input().split())
u -= 1
for v in vv:
v -= 1
M[u][v] = 1
bfs(0)
| 0 | null | 15,779,112,970,390 | 167 | 9 |
n = int(input())
a = list(map(int, input().split()))
cnt = [0] * (10 ** 6 + 1)
for i in range(n):
cnt[a[i]] += 1
a_uniq = []
for i in range(10 ** 6 + 1):
if cnt[i] == 1:
a_uniq.append(i)
cnt = [0] * (10 ** 6 + 1)
for i in list(set(a)):
for j in range(2 * i, 10 ** 6 + 1, i):
cnt[j] = 1
ans = 0
for i in a_uniq:
if cnt[i] == 0:
ans += 1
print(ans) | def main():
S = input()
def an_area(S):
ans = 0
stack_in = []
stack_out = []
for i,ch in enumerate(S):
if ch == '\\':
stack_in.append(i)
elif stack_in and ch == '/':
j = stack_in.pop()
cur = i - j
stack_out.append((j,i,cur))
ans += cur
return ans,stack_out
ans, l = an_area(S)
if ans == 0:
print(ans)
print(len(l))
return
l.sort()
pre_le, pre_ri = l[0][0], l[0][1]
pre_ar = 0
areas = []
for le,ri,ar in l:
if pre_le <= ri <= pre_ri:
pre_ar += ar
else:
areas.append(pre_ar)
pre_ar = ar
pre_le, pre_ri = le, ri
else:
areas.append(pre_ar)
print(ans)
print(len(areas),*areas)
if __name__ == '__main__':
main()
| 0 | null | 7,165,101,119,058 | 129 | 21 |
x,n = map(int, input().split())
p = list(map(int, input().split()))
l = [i for i in range(102)]
for j in p:
l.remove(j)
m = []
for k in l:
m.append(abs(k-x))
print(l[m.index(min(m))]) | X, N = list(map(int, input().split()))
if N == 0:
print(X)
exit()
P = list(map(int, input().split()))
up_min = 0
low_min = 0
arr = [0] * 102
for i in P:
arr[i] = 1
lower = arr[:X]
lower.reverse()
upper = arr[X:]
for i, num in enumerate(lower):
if num == 0:
low_min = len(lower) - 1 - i
break
for i, num in enumerate(upper):
if num == 0:
up_min = len(lower) + i
break
if abs(up_min - X) >= abs(X - low_min):
print(low_min)
else:
print(up_min)
| 1 | 14,062,240,109,440 | null | 128 | 128 |
def solve():
import math
K = int(input())
ans = 0
for i in range(1, K+1):
for j in range(1, K+1):
for k in range(1, K+1):
ans += math.gcd(math.gcd(i,j), k)
print(ans)
if __name__ == "__main__":
solve() | import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
import numpy as np
def main():
k = int(input())
k2 = np.arange(1, k+1)
k2gcd = np.gcd.outer(k2, np.gcd.outer(k2, k2))
print(k2gcd.sum())
if __name__ == '__main__':
main() | 1 | 35,586,104,313,200 | null | 174 | 174 |
from itertools import combinations
if __name__ == '__main__':
# ??????????????\???
num1 = int(input())
A = [int(x) for x in input().split(' ')]
num2 = int(input())
M = [int(x) for x in input().split(' ')]
#A = [1, 5, 7, 10, 21]
#pick = 4
#M = [2, 4, 17, 8]
# ????????????
results = ['no' for x in range(len(M))] # M?????¨??????????´?????????????????????????????????§????????????????????±???(no)??¨????????????
for p in range(1, len(A)+1): # A????????????1????????¨????????°?????????????????¢????????????
combi = combinations(A, p) # n??????????????¢??????????????´????????¨?????????????????????
for choice in combi:
total = sum(choice)
while total in M:
i = M.index(total)
results[i] = 'yes'
M[i] = 'Done'
# ???????????????
for txt in results:
print(txt) | #!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
from itertools import combinations
def enum_sum_numbers(sets, s_range, r):
for cmb in combinations(sets, r):
yield sum(cmb)
if r <= s_range:
for s in enum_sum_numbers(sets, s_range, r+1):
yield s
stdin.readline()
a = [int(s) for s in stdin.readline().split()]
stdin.readline()
ms = [int(s) for s in stdin.readline().split()]
sets = {s for s in enum_sum_numbers(a, len(a), 1)}
for m in ms:
print('yes' if m in sets else 'no') | 1 | 100,687,544,672 | null | 25 | 25 |
x=input().split()
n=int(x[0])
k=int(x[1])
def fact_inverse(n,p):
fact=[1]*(n+1)
inv=[1]*(n+1)
inv_fact=[1]*(n+1)
inv[0]=0
inv_fact[0]=0
for i in range(2,n+1):
fact[i]=(fact[i-1]*i)%p
#compute the inverse of i mod p
inv[i]=(-inv[p%i]*(p//i))%p
inv_fact[i]=(inv_fact[i-1]*inv[i])%p
return fact,inv_fact
def combi2(n,p):
f,inv=fact_inverse(n,p)
combis=[1]*(n+1)
for k in range(1,n+1):
if k >=n//2+1:
combis[k]=combis[n-k]
else:
combis[k]=(((f[n]*inv[n-k])%p)*inv[k])%p
return combis
p=10**9+7
combis1=combi2(n,p)
combis2=combi2(n-1,p)
s=0
L=min(n,k+1)
for i in range(L):
s=(s+(combis1[i]*combis2[i])%p)%p
print(s)
| # --*-coding:utf-8-*--
MOD = 10**9 + 7
def getModInv(a, b):
return 1 if (a == 1) else (1-b*getModInv(b%a, a))//a%b
N, K = map(int, input().split())
t1, t2 = 1,1
s1, s2 = 1,1
for m in range(1, min(K, N-1)+1):
t1 = t1*(N-m)*(N-m+1)%MOD
t2 = t2*m**2%MOD
s1 = (s1*t2 + s2*t1)%MOD
s2 = s2*t2%MOD
print(s1*getModInv(s2, MOD)%MOD)
| 1 | 66,928,155,220,100 | null | 215 | 215 |
n = int(input())
s = str(input())
a = 0
c = len(s)//2
if n % 2 == 0:
for i in range(c):
if s[i] == s[c+i]:
a += 1
if a == n/2 :
print("Yes")
else :
print("No")
else :
print("No") | x = list(map(int, input().split()))
ans = 0
for i in x:
if i == 1:
ans += 300000
elif i == 2:
ans += 200000
elif i == 3:
ans += 100000
if ans == 600000:
print(1000000)
else:
print(ans)
| 0 | null | 144,174,338,513,732 | 279 | 275 |
n = int(raw_input())
for i in range(n):
num = map(int, raw_input().split())
num.sort(reverse=True)
if num[0]**2 == num[1]**2 + num[2]**2:
print "YES"
else:
print "NO"
| N = int(input())
for i in range(N):
sides = list(map(int, input().split()))
longestSide = max(sides)
sides.remove(longestSide)
if (longestSide ** 2) == (sides[0] ** 2 + sides[1] ** 2):
print('YES')
else:
print('NO') | 1 | 291,092,608 | null | 4 | 4 |
s = input()
k = int(input())
import collections
co = collections.Counter(list(s))
n = len(s)
if len(co.values())==1:
print(n*k//2)
exit()
prev = ""
cnt = 0
for i in range(n):
if s[i] == prev:
cnt+=1
prev=""
else:
prev=s[i]
bf = 0
af = 0
if s[0] == s[-1]:
for i in range(n):
if s[i] ==s[0]:
bf+=1
else:break
for i in range(n):
if s[-i-1] ==s[-1]:
af+=1
else:break
cnt = cnt - (bf//2 + af//2)
print(cnt*k + (bf+af)//2 *(k-1) +bf//2 + af//2)
| s = list(input())
k = int(input())
if len(set(s)) == 1:
print((len(s)*k)//2)
exit()
def n_change(sss):
s = sss.copy()
x = 0
for i in range(1, len(s)):
if s[i] == s[i-1]:
s[i] = "X"
x += 1
return x
print(n_change(s) + (k-1) * (n_change(2*s) - n_change(s))) | 1 | 175,761,719,298,088 | null | 296 | 296 |
N=int(input())
*A,=map(int,input().split())
M=max(A)
B=[1]*(M+1)
B[0]=B[1]=1
i=2
while i<=M:
if B[i]:
j=2
while i*j<=M:
B[i*j]=0
j+=1
i+=1
C=[0]*(M+1)
for a in A:
C[a]=1
from math import*
now=A[0]
for a in A:
now=gcd(now,a)
if now==1:
ans='pairwise coprime'
i=2
while i<=M:
if B[i]:
count=0
j=1
while i*j<=M:
count+=C[i*j]
j+=1
if count>1:
ans='setwise coprime'
i+=1
print(ans)
else:
print('not coprime') | from sys import stdin
from collections import defaultdict
# from bisect import *
# from heapq import *
# import math
# mod = 10**9+7
N = input()
A = list(map(int, input().split()))
M = 10**6+1
spf = [i for i in range(M)]
for i in range(2, M):
if spf[i] == i:
for j in range(i+i, M, i):
spf[j] = i
cnt = defaultdict(int)
for a in A:
ps = set()
while a != 1:
ps.add(spf[a])
a = a // spf[a]
for p in ps:
cnt[p] += 1
if all([x < 2 for x in cnt.values()]):
print("pairwise coprime")
exit()
gcd = lambda x, y : x if y == 0 else gcd(y, x % y)
x = A[0]
for a in A[1:]:
x = gcd(x, a)
if x == 1:
print("setwise coprime")
else:
print("not coprime") | 1 | 4,086,149,593,220 | null | 85 | 85 |
a= int(input())
ans_list = []
for i in range(a):
ans_list.append(input())
print(len(list(set(ans_list)))) | import collections
N = int(input())
S = [input() for _ in range(N)]
c = collections.Counter(S)
print(len(c)) | 1 | 30,175,071,608,780 | null | 165 | 165 |
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right
import sys,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()))
n = inp()
s,t = input().split()
print(''.join([s[i] + t[i] for i in range(n)])) | import sys
n = int(input())
r0 = int(input())
r1 = int(input())
mx = r1-r0
mn = min(r1,r0)
l = map(int,sys.stdin.readlines())
for i in l:
if mx < i - mn:
mx = i - mn
elif mn > i:
mn = i
print(mx) | 0 | null | 56,092,554,189,532 | 255 | 13 |
from queue import Queue
n = int(input())
A = [[0 for i in range(n)] for j in range(n)]
d = [-1 for i in range(n)]
for i in range(n):
u, k, *v = list(map(int, input().split()))
for j in v:
A[int(u)-1][int(j)-1] = 1
q = Queue()
q.put(0)
d[0] = 0
while not q.empty():
u = q.get()
# print('visited:', u)
for v in range(n):
# print(u, v)
if A[u][v] == 1 and d[v] == -1:
q.put(v)
d[v] = d[u] + 1
# print('-========')
for i in range(n):
print(i+1, d[i])
| a = input()
if a == 'SUN':
print(7)
elif a == 'MON':
print(6)
elif a == 'TUE':
print(5)
elif a == 'WED':
print(4)
elif a == 'THU':
print(3)
elif a == 'FRI':
print(2)
else:
print(1)
| 0 | null | 66,466,352,202,492 | 9 | 270 |
from bisect import bisect_left,bisect_right
TO_ACII = 97
N = int(input())
S = ["0"] + list(input())
Q = int(input())
ABC = [[]for i in range(0,26,1)]#該当文字a:0 b:1 ...z:26 が何文字目に出てきたかを保持する配列
for i in range(1,N+1,1):
ABC[ord(S[i])-TO_ACII].append(i)
ans = []
for i in range(0,Q,1):
q = list(input().split())
if q[0]=="1":#文字変更
changed = S[int(q[1])]
ABC[ord(changed)-TO_ACII].pop(bisect_left(ABC[ord(changed)-TO_ACII],int(q[1])))
ABC[ord(q[2])-TO_ACII].insert(bisect_left(ABC[ord(q[2])-TO_ACII],int(q[1])),int(q[1]))
S[int(q[1])]=q[2]
else:
tmpans = 0
for i in range(0,26,1):
if bisect_right(ABC[i],int(q[1])-1)<len(ABC[i]) and int(q[2]) >= ABC[i][bisect_right(ABC[i],int(q[1])-1)]:
tmpans+=1
ans.append(tmpans)
for i in range(0,len(ans),1):
print(ans[i])
| # test!!!!!!!!!!!
from bisect import bisect_left, bisect_right
N = int(input())
S = list(input())
Q = int(input())
memo = {chr(ord('a') + i): [] for i in range(26)}
for key,val in enumerate(S):
memo[val].append(key)
for q in range(Q):
query = list(input().split())
if query[0] == '1':
i, x = int(query[1])-1, query[2]
now = S[i]
if now == x:
continue
memo[now].remove(i)
next_i = bisect_left(memo[x], i)
memo[x].insert(next_i, i)
S[i] = x
else:
start, end = int(query[1])-1, int(query[2])-1
tmp_cout = 0
for alf_array in memo.values():
if len(alf_array) == 0:
continue
ss = bisect_left(alf_array, start)
gg = bisect_right(alf_array, end)
if gg- ss > 0:
tmp_cout += 1
print(tmp_cout)
| 1 | 62,639,895,618,926 | null | 210 | 210 |
N, M = map(int, input().split())
A = list(map(int, input().split()))
w = sum(A)
ans = N - w
if ans >= 0:
print(ans)
else:
print(-1) | import sys
N, M = map(int, input().split())
A = list(map(int, input().split()))
sum_day = sum(A)
ans = N - sum_day
if ans < 0:
print(-1)
else:
print(ans) | 1 | 32,016,077,934,340 | null | 168 | 168 |
def modz( x, n):
a = x / n
return x - a*n
if __name__ == "__main__":
n = int(raw_input())
s = ""
i = 1
while True:
# print "i:{0}".format(i)
x = i;
if modz(x , 3) == 0:
s += " " + str(i)
else:
ex = 0
while True:
if modz(x , 10) == 3:
s += " " + str(i)
ex = 1
break
x /= 10
if x == 0:
ex = 1
break
if (i+1) > n:
i += 1
break
i += 1
print s | n = int(input())
ans = ""
for i in range(1, n + 1):
if(i % 3 == 0):
ans += " " + str(i)
continue
x = i
while(x):
if(x % 10 == 3):
ans += " " + str(i)
break
x //= 10
print(ans) | 1 | 925,051,109,350 | null | 52 | 52 |
import sys
S = input()
for i in range(1,6):
if S == "hi" * i:
print("Yes")
sys.exit()
print("No")
| S = input()
l = len(S)
x = [0]*(l+1)
y = [0]*(l+1)
for i in range(l):
if S[i] == "<":
x[i+1] = x[i]+1
for i in range(l):
if S[l-i-1] == ">":
y[l-i-1] = y[l-i]+1
res = 0
for a, b in zip(x, y):
res += max(a, b)
print(res) | 0 | null | 104,855,334,506,988 | 199 | 285 |
N = int(input())
ans = N // 1000
if N % 1000 == 0:
print(0)
else:
print(1000*(ans+1) - N) | s = int(input())
print((1000-s%1000)%1000) | 1 | 8,417,685,432,772 | null | 108 | 108 |
S,W=map(int,input().split())
if S>W:
print("safe")
elif S<W:
print("unsafe")
elif S==W:
print("unsafe") | time = 0
def dfs_visit(g, u):
global time
time += 1
u[2] = time
u[1] = 'g'
for v in u[0]:
ch = g[v]
if ch[1] == 'w':
ch[4] = u[5]
dfs_visit(g, ch)
u[1] = 'b'
time += 1
u[3] = time
n = int(input())
g = {}
s = 0
stack = []
for i in range(n):
x = list(map(int, input().split()))
g[x[0]] = [x[2:], 'w', 0, 0, None, x[0]]
if i == 0:
s = x[0]
for k, v in g.items():
if v[1] == 'w':
dfs_visit(g, v)
for i in range(n):
node = g[i+1]
print("{} {} {}".format(i+1, node[2], node[3])) | 0 | null | 14,613,920,004,930 | 163 | 8 |
a, b = map(int,input().split())
while a != 0:
for i in range(a):
print('#'*b)
print()
a, b = map(int,input().split())
| array = []
while True:
n = input()
if n == "0 0":
break
array.append(n.split())
for i in range(len(array)):
for i2 in range(int(array[i][0])):
for i3 in range(int(array[i][1])):
if i3 == int(array[i][1])-1:
print("#")
else:
print("#",end="")
print("") | 1 | 778,039,314,400 | null | 49 | 49 |
from collections import deque # BFSはこいつを使え!
def dfs(n):
adj = 'abcdefghij'
stack = deque(['a'])
while stack:
# node = stack.pop(0) # pop(0)がO(n)かかっているのでとても遅い!
node = stack.popleft()
if len(node) == n:
print(node)
else:
for child in adj[:len(set(node))+1]:
stack.append(node+child)
return -1
# 再帰での実装
# def dfs(s,n,adj):
# if len(s) == n:
# print(s)
# else:
# for child in adj[:len(set(s))+1]:
# dfs(s+child,n,adj)
# return -1
def main():
import sys
def input(): return sys.stdin.readline().rstrip()
n = int(input())
# adj = 'abcdefghij'
# dfs('a',n,adj)
dfs(n)
if __name__ == '__main__':
main() | n, k = map(int, input().split())
MOD = 1000000007
ans = 0
c = {}
for i in range(k, 0, -1):
t = pow(k // i, n, MOD)
m = 2
while i * m <= k:
t -= c[i * m]
m += 1
c[i] = t % MOD
print(sum([k * v for k, v in c.items()]) % MOD)
| 0 | null | 44,800,371,979,678 | 198 | 176 |
N = list(map(int,input().split()))
print(N[0]*N[1]) | import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9
def main():
n = int(input())
S = input()
if n%2 == 0:
if S[:n//2] == S[n//2:]:
print('Yes')
return
print('No')
if __name__ == '__main__':
main()
| 0 | null | 81,095,931,425,278 | 133 | 279 |
def main():
from functools import lru_cache
import sys
input=sys.stdin.readline
sys.setrecursionlimit(100000000)
n,u,v=map(int,input().split())
u-=1
v-=1
tree=[[] for i in range(n)]
for i in range(n-1):
a,b=map(int,input().split())
a-=1
b-=1
tree[a].append(b)
tree[b].append(a)
depth=[0]*n
depth[v]=0
def dfs(i,before=-1):
for e in tree[i]:
if e!=before:
depth[e]=depth[i]+1
dfs(e,i)
dfs(v)
#print(depth)
max_depth=[-1]*n
max_depth[v]=0
@lru_cache(maxsize=None)
def dfs2(i,before=-1):
t=-1
for e in tree[i]:
if e!=before:
t=max(t,dfs2(e,i))
if t!=-1:
max_depth[i]=t
return max_depth[i]
else:
max_depth[i]=depth[i]
return max_depth[i]
dfs2(v)
#print(max_depth)
lim=depth[u]
i,key=u,u
while i!=v:
if 2*depth[i]>lim and max_depth[key] < max_depth[i]:
key=i
for e in tree[i]:
if depth[e]<depth[i]:
i=e
break
print(max_depth[key]-1)
if __name__=='__main__':
main()
| # import bisect
# import heapq
# from copy import deepcopy
# from collections import deque
# from collections import Counter
# from itertools import accumulate
# from itertools import permutations
# import numpy as np
import math
# mod = 10**9 + 7
# n = int(input())
# a = list(map(int, input().split()))
# n = int(input())z
a,b = map(int,input().split())
print(a-2*b if a-2*b>=0 else 0) | 0 | null | 141,924,260,628,230 | 259 | 291 |
N=int(input())
ans=0
if ~N%2:
for i in range(1,30):
ans+=N//(10*5**i)
ans+=N//10
print(ans) | N=int(input())
if N%2:
print(0)
else:
ans=0
tmp=10
while tmp<=N:
ans+=N//tmp
tmp*=5
print(ans) | 1 | 115,943,709,162,280 | null | 258 | 258 |
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()
n,r = na()
print(r+max(0,100*(10-n))) | def main():
n, r = map(int, input().split())
inner = 0
if n >= 10:
inner = r
else:
inner = r + 100*(10-n)
print(inner)
main()
| 1 | 63,667,948,851,250 | null | 211 | 211 |
import math
gun_list = [1]
for i in range(11):
gun_list.append(gun_list[-1]+26**(i+1))
#print(gun_list)
#郡の始まりのnumをしまったリスト
a =int(input())
#print()
gun_sum = 12
for i in range(13):
if gun_list[i] <= a and gun_list[i+1] > a:
gun_num = i
break
#print(gun_num)
b = a-gun_list[gun_num]
#print(b)
x_list = [26**i for i in range(gun_num+1)]
x_list = x_list[::-1]
#print(x_list)
ans_list = []
for i in range(len(x_list)):
if i > 0:
b -= x_list[i-1]*ans_list[i-1]
ans_list.append(math.floor(b/x_list[i]))
else:
ans_list.append(math.floor(b/x_list[0]))
#print(ans_list)
ans = ''
for i in range(len(ans_list)):
ans += chr(97+ans_list[i])
#print(ans)
print(ans) | n = int(input())
ans = set()
for _ in range(n):
ans.add(input())
print(len(ans)) | 0 | null | 21,224,499,410,310 | 121 | 165 |
#!/usr/bin/env python3
#xy = [map(int, input().split()) for _ in range(5)]
#x, y = zip(*xy)
def main():
nd = list(map(int, input().split()))
ans = 0
for i in range(nd[0]):
xy = list(map(int, input().split()))
if xy[0] * xy[0] + xy[1] * xy[1] <= nd[1] * nd[1]:
ans += 1
print(ans)
if __name__ == '__main__':
main()
| N,D = map(int, input().split())
XY_s = [list(map(int,input().split())) for _ in range(N)]
D**=2
answer = 0
for i in range(N):
if D >= XY_s[i][0]**2 + XY_s[i][1]**2:
answer+=1
print(answer) | 1 | 5,991,911,333,248 | null | 96 | 96 |
N, K = map(int, input().split())
d = []
A = [[] for i in range(K)]
for i in range(K):
d.append(int(input()))
A[i] = list(map(int, input().split()))
hold = set()
for i in range(len(A)):
hold = hold | set(A[i])
print(N - len(hold)) | #!/usr/bin/env python3
# coding: utf-8
import collections
import math
def debug(arg):
if __debug__:
pass
else:
import sys
print(arg, file=sys.stderr)
def main():
pass
N, *A = map(int, open(0).read().split())
a = dict(enumerate(A, 1))
dp = collections.defaultdict(lambda: -float("inf"))
dp[0, 0] = 0
dp[1, 0] = 0
dp[1, 1] = a[1]
for i in range(2, N + 1):
jj = range(max(math.floor(i // 2 - 1), 1), math.ceil((i + 1) // 2) + 1)
for j in jj:
x = dp[i - 2, j - 1] + a[i]
y = dp[i - 1, j]
dp[i, j] = max(x, y)
print(dp[N, N // 2])
if __name__ == "__main__":
main() | 0 | null | 30,987,651,646,500 | 154 | 177 |
import math
def main():
a,b,c = map(int,input().split())
left = 4*a*b
right = (c-a-b)**2
if (c-a-b)<0:
return 'No'
if left < right:
return 'Yes'
else:
return 'No'
print(main())
| T1,T2=map(int,input().split())
a,b=map(int,input().split())
c,d=map(int,input().split())
e=T1*a
f=T1*c
if e>f:
g=e-f
e=T2*b
f=T2*d
if e>f:
print(0)
else:
h=f-e
if g==h:
print("infinity")
elif g>h:
print(0)
else:
k=h-g
if k>g:
print(1)
elif (g/k)%1!=0:
print(1+(g//k)*2)
else:
print((g//k)*2)
elif e<f:
g=f-e
e=T2*b
f=T2*d
if e<f:
print(0)
else:
h=e-f
if g==h:
print("infinity")
elif g>h:
print(0)
else:
k=h-g
if k>g:
print(1)
elif (g/k)%1!=0:
print(1+(g//k)*2)
else:
print((g//k)*2) | 0 | null | 91,984,373,956,242 | 197 | 269 |
import math
k = int(input())
ab = []
ans = 0
for a in range(1,k+1):
for b in range(1,k+1):
if a % b == 0:
ab.append(b)
elif b % a == 0:
ab.append(a)
else:
ab.append(math.gcd(a, b))
for i in ab:
for c in range(1,k+1):
if i % c == 0:
ans += c
elif c % i == 0:
ans += i
else:
ans += math.gcd(i, c)
print(ans) | n, k = map(int, input().split())
s = []
mod = 998244353
for i in range(k):
l, r = map(int, input().split())
s.append([l, r])
dp = [0 for _ in range(n+1)]
dp[1] = 1
dpsum = [0 for _ in range(n+1)]
dpsum[1] = 1
for i in range(2,n+1):
for l, r in s:
li = max(i-r,1)
ri = max(i-l,0)
dp[i] += (dpsum[ri] - dpsum[li-1])%mod
dpsum[i] = (dpsum[i-1] + dp[i])%mod
print(dp[n]%mod) | 0 | null | 19,159,906,565,120 | 174 | 74 |
def gcd(a, b):
for i in range(min(a, b), 0, -1):
if a%i == 0 and b%i == 0:
return i
A, B = map(int, input().split())
print((A*B) // gcd(A, B)) | import numpy as np
a, b, x = map(int, input().split())
ans = 0
if (a*a*b/2) <= x:
ans = np.rad2deg(np.arctan((2*(a*a*b-x))/(a*a*a)))
else:
ans = np.rad2deg(np.arctan((a*b*b)/(2*x)))
print('{:.10f}'.format(ans))
| 0 | null | 138,132,374,138,952 | 256 | 289 |
from sys import stdin
import sys, math
n,m,x = [int(x) for x in stdin.readline().rstrip().split()]
c = []
for i in range(n):
c.append([int(x) for x in stdin.readline().rstrip().split()])
money = []
for i in range(2**n):
b = bin(i)
d = [0 for i in range(m + 1)]
for j in range(n):
if b[-1] == "1": d = [p+q for (p,q) in zip(d,c[j])]
b = str(bin(int(b, 2) // 2))
if min(d[1:]) >= x: money.append(d[0])
if len(money) == 0:
print(-1)
else:
print(min(money))
| n, m, x = map(int, input().split())
books = [list(map(int, input().split())) for _ in range(n)]
INF = 10 ** 9 + 7
ans = INF
for bits in range(2 ** n):
cost = 0
score = [0] * m
for i, book in enumerate(books):
if bits >> i & 1:
cost += book[0]
score = [s + b for s, b in zip(score, book[1:])]
if all(s >= x for s in score):
ans = min(ans, cost)
if ans == INF:
print(-1)
else:
print(ans) | 1 | 22,138,878,770,446 | null | 149 | 149 |
_ = input()
l = reversed(input().split())
print(' '.join(l)) | #!/usr/bin/env python3
n = int(input())
n /= 3
print(n**3) | 0 | null | 24,182,710,241,630 | 53 | 191 |
import math
a,b,x = map(int,input().split())
if x <= a*a*b/2:
print(math.atan((a*b*b/2/x))*180/math.pi)
else:
print(math.atan((a*a*b-x)/(a**3)*2)*180/math.pi) | import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
a, b, x = map(int, readline().split())
if a*a*b/2 < x:
tan = 2 * b / a - 2 * x / (a ** 3)
ans = math.degrees(math.atan(tan))
print(ans)
else:
tan = a * b * b / x / 2
ans = math.degrees(math.atan(tan))
print(ans)
if __name__ == '__main__':
solve() | 1 | 162,917,616,430,460 | null | 289 | 289 |
def black_jack():
# 入力
A1, A2, A3 = map(int, input().split())
# 初期処理
sum = A1 + A2 + A3
# 判別処理
if sum >= 22:
return 'bust'
elif sum <= 21:
return 'win'
result = black_jack()
print(result) | def main():
n = input()
A = []
for i in xrange(n):
A.append(map(int,raw_input().split()))
c,d = bfs(n,A)
for i in xrange(n):
if c[i] == -1:
print i+1, -1
else:
print i+1, d[i]
def bfs(n,A):
color = [-1]*n
d = [-1]*n
Q = []
d[0] = 0
Q.append(0)
while(True):
if len(Q)==0:
break
u = Q.pop(0)
for i in A[u][2:]:
if color[i-1] == -1:
color[i-1] = 0
d[i-1] = d[u]+1
Q.append(i-1)
color[u] = 1
return color, d
if __name__ == '__main__':
main() | 0 | null | 59,284,466,042,740 | 260 | 9 |
K = int(input())
for i in range(0, K):
print("ACL", end="")
| n = int(input())
s_l = [ input() for _ in range(n) ]
d = {}
for s in s_l:
try:
d[s] += 1
except:
d[s] = 1
max_c = max([ v for _,v in d.items() ])
ans = [ i for i, v in d.items() if v == max_c ]
for i in sorted(ans):
print(i) | 0 | null | 35,927,232,267,460 | 69 | 218 |
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import deque
n,u,v=nii()
u-=1
v-=1
tree=[[] for i in range(n)]
for i in range(n-1):
a,b=nii()
a-=1
b-=1
tree[a].append(b)
tree[b].append(a)
def BFS(s):
dist=[-1 for i in range(n)]
dist[s]=0
que=deque()
que.append(s)
while que:
x=que.popleft()
for i in tree[x]:
if dist[i]==-1:
que.append(i)
dist[i]=dist[x]+1
return dist
dist_t=BFS(u)
dist_a=BFS(v)
ans=0
for i in range(n):
if dist_a[i]>dist_t[i]:
ans=max(ans,dist_a[i]-1)
print(ans) | S = int(input())
a = (S // 2) + (S % 2)
print(int(a)) | 0 | null | 88,288,684,202,110 | 259 | 206 |
n = int(input())
a = list(map(int,input().split(" ")))
answer = 0
for i in range(1,n):
if a[i] < a[i - 1]:
answer += a[i-1] - a[i]
a[i]= a[i - 1]
print(answer) | number = int(input())
tall = list(map(int, input().split()))
addition = 0
for each in range(1, number):
difference = tall[each - 1] - tall[each]
if difference >= 0:
addition += difference
tall[each] += difference
print(addition) | 1 | 4,521,507,110,548 | null | 88 | 88 |
# coding: UTF-8
n,m,l = map(int,raw_input().split(" "))
a_matrix = [map(int,raw_input().split()) for i in range(n)]
b_matrix = [map(int,raw_input().split()) for i in range(m)]
tmp3_matrix = []
c_matrix = []
for i in range(n):
tmp2_matrix = []
for j in range(l):
sum = 0
for k in range(m):
sum += a_matrix[i][k] * b_matrix[k][j]
tmp2_matrix.append(sum)
tmp3_matrix.extend([tmp2_matrix])
c_matrix.extend(tmp3_matrix)
for x in range(n):
print " ".join(map(str,c_matrix[x]))
| N, X, T = map(int, input().split())
if N % X == 0:
print(int(N / X) * T)
else:
print(int(N / X + 1) * T) | 0 | null | 2,830,323,786,780 | 60 | 86 |
import math
a,b,c=map(float,input().split())
if c<90:
e=c*math.pi/180
S=a*b*1/2*math.sin(e)
t=a**2+b**2-2*a*b*math.cos(e)
r=math.sqrt(t)
L=a+b+r
h=b*math.sin(e)
print(S)
print(L)
print(h)
if c==90:
e=c*math.pi/180
S=a*b*1/2*math.sin(e)
t=a**2+b**2-2*a*b*math.cos(e)
r=math.sqrt(t)
L=a+b+r
h=b
print(S)
print(L)
print(h)
if c>90:
e=c*math.pi/180
d=180*math.pi/180
f=d-e
S=a*b*1/2*math.sin(e)
t=a**2+b**2-2*a*b*math.cos(e)
r=math.sqrt(t)
L=a+b+r
h=b*math.sin(f)
print(S)
print(L)
print(h)
| #coding = utf-8
import math
a, b, c = map(float, raw_input().split())
h = b * math.sin(math.pi*c/180)
s = a * h / 2
x = math.sqrt(h**2 + (a-b*math.sin(math.pi*(90-c)/180))**2)
l = a + b + x
#print "%.8f, %.8f, %.8f" % (s, l, h)
print "\n".join([str(s), str(l), str(h)])
#print "%.1f, %.1f, %.1f" % (s, l, h) | 1 | 174,521,184,278 | null | 30 | 30 |
N=int(input())
A=[int(i) for i in input().split()]
S=set(A)
ans=1
for i in A:
ans*=i
if ans>10**18:
ans=-1
break
if 0 in S:
ans=0
print(ans)
| import copy
from collections import deque
n, m, q = list(map(int, input().split()))
abcd = []
for _ in range(q):
abcd.append(list(map(int, input().split())))
ans = 0
def dfs(A, low, high, n):
global ans
if len(A) >= n:
result = 0
for a,b,c,d in abcd:
if A[b-1]-A[a-1] == c:
result += d
ans = max(ans, result)
return
for i in range(low, high+1):
A.append(i)
dfs(A, i, high, n)
A.pop()
dfs([], 1, m, n)
print(ans)
| 0 | null | 21,741,547,389,302 | 134 | 160 |
import math
n = int(raw_input())
def isPrime(a):
if a==2 or a==3:
return 1
if a<2 or a%2==0:
return 0
i = int(math.sqrt(a))+1
for x in xrange(3,i):
if a%x==0:
return 0
return 1
cnt = 0
for _ in xrange(n):
a = int(raw_input())
cnt += isPrime(a)
print cnt | def is_prime(num):
i = 2
while i * i <= num:
if num % i == 0:
return False
i += 1
return True
N = int(input())
num_list = [int(input()) for _ in range(N)]
print(sum(is_prime(num) for num in num_list))
| 1 | 9,776,189,826 | null | 12 | 12 |
n,r = input().split()
if int(n) >= 10:
print(r)
else:
k = (-int(r) - 100 * (10 - int(n) )) * -1
print(k)
| #!/usr/bin python3
# -*- coding: utf-8 -*-
from collections import deque
def main():
N = int(input())
Node = [set() for _ in range(N)]
Edge = {}
for i in range(N-1):
a , b = map(int, input().split())
a-=1
b-=1
if b<a:
a, b = b, a
Edge[(a, b)]=i
Node[a].add(b)
Node[b].add(a)
K = 0
for i, x in enumerate(Node):
if len(x)>K:
K = len(x)
top = i
q = deque()
seen = [False]*(N-1)
used = [set() for _ in range(N)]
q.append(top)
while len(q)>0:
cur = q.popleft()
col = 1
for i in Node[cur]:
if cur>i:
ed = (i, cur)
else:
ed = (cur, i)
if seen[Edge[ed]]==False:
while col in used[cur] or col in used[i]:
col+=1
seen[Edge[ed]] = col
used[cur].add(col)
used[i].add(col)
q.append(i)
print(K)
print('\n'.join(map(str, seen)))
if __name__ == '__main__':
main()
| 0 | null | 99,429,050,054,520 | 211 | 272 |
a = input()[::-1]
add = 0
ans = [1] + [0] * 2018
ans_int = 0
d = 1
for i in range(len(a)):
add = (add + int(a[i]) * d) % 2019
d = (10 * d) %2019
ans[add] += 1
for i in range(len(ans)):
a =((ans[i] - 1) * ans[i]) /2
ans_int += a
print(int(ans_int))
| d,t,s= map(int,input().split(" "))
print("Yes" if t>=d*1.0/s else "No") | 0 | null | 17,190,593,167,526 | 166 | 81 |
from decimal import Decimal
a, b = map(float, input().split())
a = Decimal(str(a))
b = Decimal(str(b))
print(int(a * b))
| MOD = 10**9 + 7
S = int(input())
dp = [0] * (S+1)
dp[0] = 1
for i in range(1, S+1):
for j in range(0, (i-3)+1):
dp[i] += dp[j]
dp[i] %= MOD
print(dp[S]) | 0 | null | 9,562,075,098,670 | 133 | 79 |
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
memo = defaultdict(int)
ans = 0
for i, x in enumerate(a, 1):
ans += memo[i - x]
memo[x + i] += 1
print(ans)
| N = int(input())
clips = [input().split() for _ in range(N)]
X = input()
FLG = 0
ans = 0
for title,time in clips:
if FLG:
ans += int(time)
if title == X:
FLG = 1
print(ans) | 0 | null | 61,424,658,807,556 | 157 | 243 |
import math
def main():
n, x, t = map(int, input().split())
print(math.ceil(n / x) * t)
if __name__ == '__main__':
main() | l = list(map(int, input().split()))
n = l[0] # no of things he has to make
x = l[1] # no of things he can make at a time
t = l[2] # time taken for each set to be made = t
# 20 12 6 = 12
count = 0
while n > 0:
n -= x
count += t
print(count)
| 1 | 4,269,500,408,928 | null | 86 | 86 |
a, b = map(int, input().split())
print(a == b and "Yes" or "No") | n,m=input().split()
if n==m:
print("Yes")
else:
print("No") | 1 | 83,275,202,660,320 | null | 231 | 231 |
from collections import deque
s = deque(input())
q = int(input())
flag = 0
for _ in range(q):
query = list(map(str, input().split()))
if query[0] == "1": flag = 1 - flag
else:
if query[1] == "1":
if flag == 0: s.appendleft(query[2])
else: s.append(query[2])
else:
if flag == 0: s.append(query[2])
else: s.appendleft(query[2])
if flag == 1: s.reverse()
print(*s, sep="") | S = input()
Q= int(input())
r = False
h = []
t = []
for i in range(Q):
Query = input().split()
if int(Query[0]) == 1:
r = not r
else:
if int(Query[1]) == 1 and not r or int(Query[1]) == 2 and r:
h.append(Query[2])
else:
t.append(Query[2])
if not r:
print(''.join(reversed(h))+S+''.join(t))
else:
print(''.join(reversed(t))+S[::-1]+''.join(h))
| 1 | 57,282,768,967,400 | null | 204 | 204 |
from itertools import combinations
n=int(input())
D=list(map(int,input().split()))
ans=0
for a,b in combinations(range(n),2):
ans+=D[a]*D[b]
print(ans) | import sys
# input = sys.stdin.readline
def main():
N = int(input())
d = list(map(int,input().split()))
ans = 0
for i in range(N):
for j in range(N):
if i !=j:
ans += d[i]*d[j]
print(int(ans/2))
if __name__ == "__main__":
main() | 1 | 168,107,715,587,172 | null | 292 | 292 |
N=int(input())
S=input()
while True:
x=''
ans=''
for i in S:
if (x==''):
x=i
continue
if x!=i:
#print("p:",x,i,ans)
ans+=x
x=i
#print("a:",x,i,ans)
ans+=x
#print('ans:',ans)
if ans==S:
break
else:
S=ans
print(len(ans)) | n=int(input())
s=input()
ans=0
for i in range(n-1):
if s[i]!=s[i+1]:
ans+=1
ans+=1
print(ans) | 1 | 170,212,198,206,572 | null | 293 | 293 |
#ALDS1_3-C Elementary data structures - Doubly Linked List
import collections
q = collections.deque()
cmds={"insert":lambda cmd: q.appendleft(cmd[1]),
"delete":lambda cmd: q.remove(cmd[1]) if (q.count(cmd[1]) > 0) else "none",
"deleteFirst":lambda cmd: q.popleft(),
"deleteLast": lambda cmd: q.pop()
}
n=int(input())
for i in range(n):
cmd=input().split()
cmds[cmd[0]](cmd)
print(*q) | from collections import deque
n = int(input())
l = deque()
for _ in range(n):
command = input().split()
if command[0] == "insert":
l.appendleft(command[1])
elif command[0] == "delete":
try:
ind = l.remove(command[1])
except ValueError:
pass
elif command[0] == "deleteFirst":
l.popleft()
elif command[0] == "deleteLast":
l.pop()
print (" ".join(l)) | 1 | 51,714,606,332 | null | 20 | 20 |
import sys
s = sys.stdin.readline().rstrip()
k = int(sys.stdin.readline())
cnt = 0
i = 0
l = len(s)
if len(set(s)) == 1:
print(int(l*k/2))
exit()
while i < l-1:
if s[i] == s[i+1]:
cnt += 1
i += 2
continue
i += 1
cnt1 = 0
i1 = 0
s *= 2
while i1 < l*2-1:
if s[i1] == s[i1+1]:
cnt1 += 1
i1 += 2
continue
i1 += 1
print((cnt1 - cnt)*(k-1) + cnt)
| S=input()
K=int(input())
N=len(S)
ans=None
if len(set(S))==1:
ans=N*K//2
else:
li=[]
i=0
while(i<N):
j=i
c=S[i]
cnt=0
while(j<N and c==S[j]):
cnt+=1
j+=1
li.append((c,cnt))
i=j
res=0
if li[0][0]!=li[-1][0]:
for x,y in li:
res+=y//2
ans=res*K
else:
for i in range(1,len(li)-1):
res+=li[i][1]//2
ans=res*K+li[0][1]//2+li[-1][1]//2+(li[0][1]+li[-1][1])//2*(K-1)
print(ans) | 1 | 176,218,488,423,968 | null | 296 | 296 |
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())
S=[]
for i in range(n):
S.append(input())
print('AC', 'x', S.count('AC'))
print('WA', 'x', S.count('WA'))
print('TLE', 'x', S.count('TLE'))
print('RE', 'x', S.count('RE'))
| 1 | 8,639,223,475,808 | null | 109 | 109 |
a,b,c = sorted(map(int,raw_input().split()))
print a,b,c | list = [int(a) for a in input().split()]
list.sort()
print(*list) | 1 | 431,677,613,610 | null | 40 | 40 |
k = int(input())
a = [0] * (10**6+1)
a[1] = 7 % k
for i in range(2, k+1):
a[i] = (a[i-1]*10+7) % k
for i in range(1, k+1):
if a[i] == 0:
print(i)
break
else:
print(-1)
| import sys
k = int(input())
a = dict()
cnt = 0
base = 0
while True:
cnt += 1
base = (base*10+7)%k
if base == 0:
break
if base in a:
cnt = -1
break
else:
a[base] = 1
print(cnt) | 1 | 6,117,648,704,288 | null | 97 | 97 |
m1,d1 = map(int,input().split())
m2,d2 = map(int,input().split())
if m1 in [1,3,5,7,8,10,12] and d1==31:
print(1)
elif m1 in [4,6,9,11] and d1==30:
print(1)
elif m1==2 and d1 in [28,29]:
print(1)
else:
print(0) | m,d=map(int,input().split())
n,e=map(int,input().split())
print(1 if m!=n else 0) | 1 | 124,320,632,520,868 | null | 264 | 264 |
#!/usr/bin/env python3
import sys
import numpy as np
input = sys.stdin.readline
def ST():
return input().rstrip()
def I():
return int(input())
def MI():
return map(int, input().split())
def LI():
return list(MI())
S = ST()
cnt = np.zeros(2019)
cnt[0] = 1
res = 0
tmp = 1
for s in S[::-1]:
res += int(s) * tmp
res %= 2019
cnt[res] += 1
tmp *= 10
tmp %= 2019
ans = 0
for c in cnt[cnt >= 2]:
ans += c * (c - 1) // 2
print(int(ans))
| N=int(input())
s=input()
ans=s.count('ABC')
print(ans) | 0 | null | 65,191,724,379,572 | 166 | 245 |
n=int(input())
a=[int(x) for x in input().rstrip().split()]
now=1
mod=10**9+7
def lcm(a,b):#最小公倍数
ori_a=a
ori_b=b
while b!=0:
a,b=b,a%b
return (ori_a*ori_b)//a
for i in a:
now=lcm(i,now)
# print(now)
print(sum([now//i for i in a])%mod)
| MOD = 10**9 + 7
class modint():
def __init__(self, value):
self.value = value % MOD
def __int__(self):
return int(self.value)
def __float__(self):
return float(self.value)
def __str__(self):
return str(self.value)
def __repr__(self):
return str(self.value)
def __add__(self, other):
return (modint(self.value + other.value) if isinstance(other, modint)
else modint(self.value + other))
def __sub__(self, other):
return (modint(self.value - other.value) if isinstance(other, modint)
else modint(self.value - other))
def __mul__(self, other):
return (modint(self.value * other.value) if isinstance(other, modint)
else modint(self.value * other))
def __truediv__(self, other):
return (modint(self.value * pow(other.value, MOD - 2, MOD))
if isinstance(other, modint)
else modint(self.value * pow(other, MOD - 2, MOD)))
def __pow__(self, other):
return (modint(pow(self.value, other.value, MOD))
if isinstance(other, modint)
else modint(pow(self.value, other, MOD)))
def __eq__(self, other):
return (self.value == other.value if isinstance(other, modint)
else self.value == (other % MOD))
def __ne__(self, other):
return (self.value == other.value if isinstance(other, modint)
else self.value == (other % MOD))
def __radd__(self, other):
return (modint(other.value + self.value) if isinstance(other, modint)
else modint(other + self.value))
def __rsub__(self, other):
return (modint(other.value - self.value) if isinstance(other, modint)
else modint(other - self.value))
def __rmul__(self, other):
return (modint(other.value * self.value) if isinstance(other, modint)
else modint(other * self.value))
def __rtruediv__(self, other):
return (modint(other.value * pow(self.value, MOD - 2, MOD))
if isinstance(other, modint)
else modint(other * pow(self.value, MOD - 2, MOD)))
def __rpow__(self, other):
return (modint(pow(other.value, self.value, MOD))
if isinstance(other, modint)
else modint(pow(other, self.value, MOD)))
def modinv(self):
return modint(pow(self.value, MOD - 2, MOD))
def main():
import sys
input = sys.stdin.buffer.readline
N = int(input())
A = [int(i) for i in input().split()]
def gcd(x, y):
if y == 0:
return x
while y != 0:
x, y = y, x % y
return x
def lcm(x, y):
return x*y//gcd(x, y)
num = 1
for a in A:
num = lcm(num, a)
n = modint(num)
ans = 0
for i, a in enumerate(A):
ans += n/a
print(ans)
if __name__ == '__main__':
main()
| 1 | 87,772,384,920,668 | null | 235 | 235 |
import math
N= int(input())
ans = math.ceil(N/2)-1
print(ans) | print((int(input())-1)>>1) | 1 | 152,746,988,589,120 | null | 283 | 283 |
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')
N, K = map(int, input().split())
d = [0]*(K+1)
for i in range(1, K+1):
val = K//i
d[i] = pow(val, N, MOD)
# print(d)
for i in range(K, 0, -1):
# print('i', i)
for j in range(K//i, 1, -1):
# print(' j', j)
# print(i, i*j)
d[i] -= d[i*j]
# print(d)
res = 0
for i, v in enu(d):
res += i*v
res %= MOD
print(res)
| N, K = list(map(int, input().split()))
mod = 10**9+7
ans = [0]*(K+1)
s = 0
for i in range(K, 0, -1):
ans[i] = pow(K//i, N, mod)
for j in range(2*i, K+1, i):
ans[i] -= ans[j]
s += ans[i]*i%mod
print(s%mod)
| 1 | 36,617,947,518,402 | null | 176 | 176 |
n,k = map(int,input().split())
a = list(map(int,input().split()))
l=0
r=10**9
def check(x):
now = 0
for i in range(n):
now += (a[i] - 1 )// x
return now <= k
while r-l > 1:
x = (l+r) //2
if check(x):
r = x
else:
l = x
print(r)
| import sys, math
from functools import lru_cache
import numpy as np
import heapq
from collections import defaultdict
sys.setrecursionlimit(10**9)
MOD = 10**9+7
def input():
return sys.stdin.readline()[:-1]
def mi():
return map(int, input().split())
def ii():
return int(input())
def i2(n):
tmp = [list(mi()) for i in range(n)]
return [list(i) for i in zip(*tmp)]
def sieve(n):
res = [i for i in range(n)]
i = 2
while i*i < n:
if res[i] < i:
i += 1
continue
j = i*i
while j < n:
if res[j] == j:
res[j] = i
j += i
i += 1
return res
def factor(n, min_factor):
res = set()
while n > 1:
res.add(min_factor[n])
n //= min_factor[n]
return res
def main():
N = ii()
A = np.array(list(mi()))
m = max(A)
s = sieve(m+1)
d = defaultdict(bool)
g = np.gcd.reduce(A)
if g > 1:
print('not coprime')
return
for a in A:
f = factor(a, s)
for v in f:
if d[v]:
print('setwise coprime')
return
d[v] = True
print('pairwise coprime')
if __name__ == '__main__':
main()
| 0 | null | 5,324,647,815,718 | 99 | 85 |
class Dice:
def __init__(self, top, front, right, left, back, bottom):
self.TOP = top
self.BOTTOM = bottom
self.FRONT = front
self.BACK = back
self.LEFT = left
self.RIGHT = right
def move(self, direction):
if direction == "N":
self.move_N()
elif direction == "E":
self.move_E()
elif direction == "S":
self.move_S()
elif direction == "W":
self.move_W()
elif direction == "SIDE":
self.move_SIDE()
else:
raise Exception
def move_N(self):
tmp = self.TOP
self.TOP = self.FRONT
self.FRONT = self.BOTTOM
self.BOTTOM = self.BACK
self.BACK = tmp
def move_S(self):
tmp = self.TOP
self.TOP = self.BACK
self.BACK = self.BOTTOM
self.BOTTOM = self.FRONT
self.FRONT = tmp
def move_W(self):
tmp = self.TOP
self.TOP = self.RIGHT
self.RIGHT = self.BOTTOM
self.BOTTOM = self.LEFT
self.LEFT = tmp
def move_E(self):
tmp = self.TOP
self.TOP = self.LEFT
self.LEFT = self.BOTTOM
self.BOTTOM = self.RIGHT
self.RIGHT = tmp
def move_SIDE(self):
tmp = self.FRONT
self.FRONT = self.RIGHT
self.RIGHT = self.BACK
self.BACK = self.LEFT
self.LEFT = tmp
def get_right(t, f):
dice = Dice(top, front, right, left, back, bottom)
has_top = False
for _ in range(4):
dice.move("N")
if dice.TOP == t:
has_top = True
break
if not has_top:
for _ in range(4):
dice.move("E")
if dice.TOP == t:
has_top = True
break
for _ in range(4):
dice.move("SIDE")
if dice.FRONT == f:
return dice.RIGHT
top, front, right, left, back, bottom = map(int,input().split())
dice = Dice(top, front, right, left, back, bottom)
n = int(input())
for _ in range(n):
t, f = map(int, input().split())
l = None
if top == t and front == f:
r = right
else:
r = get_right(t, f)
print(r)
| def memolize(f):
cache = {}
def helper(x):
if x not in cache:
cache[x] = f(x)
return cache[x]
return helper
@memolize
def fib(n):
if n == 0:
return 1
elif n == 1:
return 1
return fib(n - 1) + fib(n - 2)
n = int(input())
print(fib(n))
| 0 | null | 132,281,718,460 | 34 | 7 |
import sys
import math
def gcd(x,y):
if(x%y==0):
return y
else:
return(gcd(y,x%y))
try:
while True:
a,b= map(int, input().split())
max1=gcd(a,b)
min1=(a*b)//gcd(a,b)
print(str(max1)+' '+str(min1))
except EOFError:
pass
| n = int(input())
low = [0]*n
high = [0]*n
for i in range(n):
a, b = [int(x) for x in input().split(" ")]
low[i] = a
high[i] = b
low.sort()
high.sort()
if n%2 == 1:
print(high[n//2]-low[n//2]+1)
else:
x = (low[(n-1)//2] + low[n//2])/2
y = (high[(n-1)//2] + high[n//2])/2
print(int(2*y - 2*x + 1))
| 0 | null | 8,594,012,151,452 | 5 | 137 |
import sys
# \n
def input():
return sys.stdin.readline().rstrip()
def main():
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort(reverse=True) # 0(NlogN)
F.sort() # O(NlogN)
def train(X, Y, T): # O(N) ans: 回数
ans = 0
for i in range(len(X)):
ans += max(0, X[i] - T // Y[i])
return ans
ok = 10**18+1 #時間
ng = -1
while ok - ng > 1:
mid = (ok + ng) // 2 #時間
ans = train(A,F,mid) #kaisuu
if ans >K:
ng =mid
else:
ok =mid
print(ok)
if __name__ == "__main__":
main()
| N,K=map(int,input().split())
A=list(map(int,input().split()))
F=list(map(int,input().split()))
A.sort()
F.sort(reverse=True)
l=-1
r=10**13
while r-l!=1:
m=(l+r)//2
x=0
for i in range(N):
x+=max(0,A[i]-m//F[i])
if x<=K:
r=m
else:
l=m
print(r)
| 1 | 165,205,461,894,300 | null | 290 | 290 |
data = []
for i in range(10):
data.append(int(raw_input()))
data.sort(reverse = True)
print data[0]
print data[1]
print data[2] | import itertools
n = int(input())
l = list(map(int, input().split()))
p_list = list(itertools.permutations(l, 3))
results = [x for x in p_list if max(x) < (sum(x) - max(x)) and len(x) == len(set(x))]
print(int(len(results) / 6)) | 0 | null | 2,563,482,338,232 | 2 | 91 |
#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,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ar=[0]*(n+1)
br=[0]*(m+1)
ans=0
for i in range(n):
ar[i+1]=ar[i]+a[i]
for i in range(m):
br[i+1]=br[i]+b[i]
for i in range(m+1):
sup=k-br[i]
if sup<0:
break
res=bisect.bisect_right(ar,sup)+i-1
ans=max(res,ans)
print(ans) | N=list(map(int,input().split()))
temp = sum(N)
if temp%9 == 0:print("Yes")
else:print("No") | 0 | null | 7,548,077,322,930 | 117 | 87 |
n, k = map(int, input().split())
lists = []
for _ in range(k):
d = int(input())
having = list(map(int, input().split()))
for i in having:
lists.append(i)
sets = set(lists)
ans = n - len(sets)
print(ans) | n = input()
n = n.split()
k = int(n[1])
n = int(n[0])
c = [0]
for f in range(n-1):
c.append(0)
for b in range(k):
d = int(input())
a = input()
a = a.split()
for e in range(d):
c[int(a[e])-1] = 1
h = 0
for g in range(n):
if c[g] == 0:
h = h + 1
print(h) | 1 | 24,612,903,499,900 | null | 154 | 154 |
n = int(input())
num = [int(i) for i in input().split()]
print("{0} {1} {2}".format(min(num),max(num),sum(num)))
| a,b = map(int, input().split())
print("%d %d %0.10f" %(a//b, a%b, a/b) )
| 0 | null | 657,758,385,478 | 48 | 45 |
from itertools import accumulate
N, K = list(map(int, input().split()))
P = list(map(lambda x: int(x) - 1, input().split()))
C = list(map(int, input().split()))
ans = -10**18-1
seen = [False]*N
for i in range(N):
if seen[i]:
continue
loop = []
now = i
while seen[now] == False:
seen[now] = True
loop.append(C[now])
now = P[now]
loop_size = len(loop)
loop_score = sum(loop)
cumsum = list(accumulate(loop+loop))
for j in range(1, min(K, loop_size)+1):
for l in range(loop_size):
r = l+j
subseq = cumsum[r] - cumsum[l]
ans = max(ans, subseq, subseq+loop_score*((K-j)//loop_size))
print(ans) | def mod_max(loop, mod):
if mod == 0:
return 0
loop_len = len(loop)
mm = min(loop)
for start in range(loop_len):
current_sum = 0
for i in range(mod):
current_sum += loop[(start + i) % loop_len]
mm = max(current_sum, mm)
return mm
def main():
n, k = map(int, input().split())
p = [int(i) - 1 for i in input().split()]
c = [int(i) for i in input().split()]
seen = set()
loop_list = []
for start in range(n):
v = start
loop = []
while v not in seen:
seen.add(v)
loop.append(c[v])
v = p[v]
seen.add(v)
if loop:
loop_list.append(loop)
ans = min(c)
for loop in loop_list:
loop_len = len(loop)
loop_num = k // loop_len
loop_mod = k % loop_len
loop_sum = sum(loop)
ans = max(mod_max(loop, min(loop_len, k)), ans)
if loop_num > 0:
ans = max(loop_sum * loop_num + mod_max(loop, loop_mod), ans)
ans = max(loop_sum * (loop_num - 1) + mod_max(loop, loop_len), ans)
print(ans)
if __name__ == '__main__':
main()
| 1 | 5,446,358,323,120 | null | 93 | 93 |
import sys
n, m, l = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
matrixA = [ [ int( val ) for val in sys.stdin.readline().split( " " ) ] for row in range( n ) ]
matrixB = [ [ int( val ) for val in sys.stdin.readline().split( " " ) ] for row in range( m ) ]
matrixC = [ [ 0 for row in range( l ) ] for row in range( n ) ]
output = []
for i in range( n ):
for j in range( l ):
for k in range( m ):
matrixC[i][j] += ( matrixA[i][k] * matrixB[k][j] )
output.append( "{:d}".format( matrixC[i][j] ) )
output.append( " " )
output.pop()
output.append( "\n" )
output.pop()
print( "".join( output ) ) | n,m,l=map(int,input().split())
A=[list(map(int,input().split())) for i in range(n)]
B=[list(map(int,input().split())) for i in range(m)]
C=[[0]*l for i in range(n)]
for x in range(n):
for y in range(l):
for z in range(m):
C[x][y] += A[x][z]*B[z][y]
for row in range(n):
print("%d"%(C[row][0]),end="")
for col in range(1,l):
print(" %d"%(C[row][col]),end="")
print()
| 1 | 1,437,243,838,628 | null | 60 | 60 |
x=int(input())
y=str(input())
if len(y) > x:
print(y[:x] + '...')
else:
print(y) | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from time import time
from random import randint
from copy import deepcopy
start_time = time()
def calcScore(t, s, c):
scores = [0]*26
lasts = [0]*26
for i in range(1, len(t)):
scores[t[i]] += s[i][t[i]]
dif = i - lasts[t[i]]
scores[t[i]] -= c[t[i]] * dif * (dif-1) // 2
lasts[t[i]] = i
for i in range(26):
dif = len(t) - lasts[i]
scores[i] -= c[i] * dif * (dif-1) // 2
return scores
def greedy(c, s):
day_lim = len(s)
socres = [0]*26
t = [0]*day_lim
lasts = [0]*26
for i in range(1, day_lim):
pls = [v for v in socres]
mns = [v for v in socres]
for j in range(26):
pls[j] += s[i][j]
mns[j] -= c[j] * (i - lasts[j])
sum_mns = sum(mns)
pt = sum_mns - mns[0] + pls[0]
idx = 0
for j in range(1, 26):
tmp = sum_mns - mns[j] + pls[j]
if pt < tmp:
pt = tmp
idx = j
t[i] = idx
lasts[idx] = i
for j in range(26):
if j == idx:
socres[j] = pls[j]
else:
socres[j] = mns[j]
return socres, t
def subGreedy(c, s, t, day):
day_lim = len(s)
socres = [0]*26
t = [0]*day_lim
lasts = [0]*26
for i in range(1, day_lim):
if day <= i:
pls = [v for v in socres]
mns = [v for v in socres]
for j in range(26):
pls[j] += s[i][j]
mns[j] -= c[j] * (i - lasts[j])
sum_mns = sum(mns)
pt = sum_mns - mns[0] + pls[0]
idx = 0
for j in range(1, 26):
tmp = sum_mns - mns[j] + pls[j]
if pt < tmp:
pt = tmp
idx = j
t[i] = idx
lasts[idx] = i
for j in range(26):
if j == idx:
socres[j] = pls[j]
else:
socres[j] = mns[j]
else:
scores[t[i]] += s[i][t[i]]
lasts[t[i]] = i
for j in range(26):
dif = i - lasts[j]
scores[j] -= c[j] * dif
return socres, t
D = int(input())
c = list(map(int, input().split()))
s = [[0]*26 for _ in range(D+1)]
for i in range(1, D+1):
s[i] = list(map(int, input().split()))
scores, t = greedy(c, s)
sum_score = sum(scores)
while time() - start_time < 1.86:
typ = randint(1, 90)
if typ <= 70:
for _ in range(100):
tmp_t = deepcopy(t)
tmp_t[randint(1, D)] = randint(0, 25)
tmp_scores = calcScore(tmp_t, s, c)
sum_tmp_score = sum(tmp_scores)
if sum_score < sum_tmp_score:
sum_score = sum_tmp_score
t = deepcopy(tmp_t)
scores = deepcopy(tmp_scores)
elif typ <= 90:
for _ in range(30):
tmp_t = deepcopy(t)
dist = randint(1, 20)
p = randint(1, D-dist)
q = p + dist
tmp_t[p], tmp_t[q] = tmp_t[q], tmp_t[p]
tmp_scores = calcScore(tmp_t, s, c)
sum_tmp_score = sum(tmp_scores)
if sum_score < sum_tmp_score:
sum_score = sum_tmp_score
t = deepcopy(tmp_t)
scores = deepcopy(tmp_scores)
elif typ <= 100:
tmp_t = deepcopy(t)
day = randint(D//4*3, D)
tmp_scores, tmp_t = subGreedy(c, s, tmp_t, day)
sum_tmp_score = sum(tmp_scores)
if sum_score < sum_tmp_score:
sum_score = sum_tmp_score
t = tmp_t
scores = tmp_scores
for v in t[1:]:
print(v+1)
| 0 | null | 14,723,290,690,208 | 143 | 113 |
S = str(input())
l = ['SUN','MON','TUE','WED','THU','FRI','SAT']
for i in range(7):
if S == l[i]:
print(7-i) | s = input()
days = ["", "SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"]
print(days.index(s)) | 1 | 132,949,092,152,772 | null | 270 | 270 |
alps = 'abcdefghijklmnopqrstuvwxyz'
n = int(input())
if n == 1:
print('a')
exit()
ansl = []
curr_n = n
for i in range(15, -1, -1):
if n <= pow(26,i):
continue
val = curr_n//pow(26,i)
ansl.append(val)
curr_n -= val*pow(26,i)
for j in range(100):
for i in range(len(ansl)-1):
if ansl[i+1] == 0:
ansl[i+1] = 26
ansl[i] -= 1
ans = ''
for a in ansl:
if a == 0: continue
ans += alps[a-1]
print(ans) | n=int(input())
def ans(x):
a=26
b=1
k=1
ch=0
while ch==0:
if b<= x <= b+a**k-1:
ch+=1
return k,x-(b-1)
else:
b=b+a**k
k+=1
s,t=ans(n)
ans1=''
c='abcdefghijklmnopqrstuvwxyz'
for i in range(1,s+1):
q=0
f=26**(s-i)
if i!=s:
cc=0
while cc==0:
e=t-f*(q+1)
if e>0:
q+=1
else:
cc+=1
if q==25:
break
t-=f*q
g=c[q]
ans1=ans1+g
else:
g=c[t-1]
ans1=ans1+g
print(ans1) | 1 | 11,859,521,240,800 | null | 121 | 121 |
n, x, t = map(int, input().split())
answer = -(-n // x) * t
print(answer) | X, K, D = map(int,input().split())
X = abs(X)
if X > K*D:
print( X - K*D )
else:
a = X//D
K -= a
X -= D*a
if K%2 == 0:
print(X)
else:
print(abs(X-D)) | 0 | null | 4,714,917,812,812 | 86 | 92 |
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()
def resolve():
S = SS()
len_S = len(S)
ans = 0
for i in range(len_S // 2):
if S[i] != S[len_S-1-i]:
ans += 1
print(ans)
if __name__ == '__main__':
resolve()
| S=list(input())
T=S.copy()
T.reverse()
count=0
for i in range(len(S)):
if S[i]!=T[i]:count+=1
print(count//2) | 1 | 120,284,500,415,278 | null | 261 | 261 |
N = int(input())
if N%2 ==1:
print(0)
else:
ans = 0
cnt = 10
while N >= cnt:
ans += N//cnt
cnt *= 5
print(ans)
| import math
r = float(input())
pi =math.pi
print('%.10f %.10f'%(r*r*pi,2*r*pi))
| 0 | null | 58,128,942,315,518 | 258 | 46 |
N,K=list(map(int, input().split()))
H=list(map(int, input().split()))
if K>=N:
print(0)
exit()
H.sort(reverse=True)
H=H[K:]
print(sum(H)) | N, K = map(int, input().split())
H = map(int, input().split())
if K >= N:
print(0)
exit()
H = list(H)
H.sort()
print(sum(x for x in H[0 : N - K])) | 1 | 79,209,646,409,096 | null | 227 | 227 |
t=input()
tla=list(t)
tlb=list(t)
pd1=0
pd2=0
for i in range(len(tla)):
if tla[i]=="?":
if i==0:
pass
elif i==len(tla)-1:
tla[i]="D"
elif tla[i-1]=="P":
tla[i]="D"
elif tla[i+1]=="D":
tla[i]="P"
elif tla[i+1]=="?":
tla[i]="P"
else:
tla[i]="D"
if tla[i]=="D":
if i==0:
pass
elif tla[i-1]=="P":
pd1+=1
d1=tla.count('D')
s1=d1+pd1
for i in range(len(tlb)):
if tlb[i]=="?":
tlb[i]="D"
if tlb[i]=="D":
if i==0:
pass
elif tlb[i-1]=="P":
pd2+=1
d2=tlb.count('D')
s2=d2+pd2
if s1>s2:
print(''.join(tla))
else:
print(''.join(tlb)) | import sys
input=sys.stdin.readline
count=0
res=""
str=input()
list=[]
for i in range(len(str)):
list.append(str[i])
for i in range(len(str)):
if str[i]=="?":
if i==0:
if list[1]=="D":
list[0]="P"
else:
list[0]="D"
elif i+1==len(str):
list[i]="D"
else:
if list[i-1]=="P":
list[i]="D"
else:
if list[i+1]=="D" or list[i+1]=="?":
list[i]="P"
else:
list[i]="D"
for i in range(len(str)):
res+=list[i]
print(res)
| 1 | 18,474,416,001,600 | null | 140 | 140 |
import sys
input = sys.stdin.readline
INF = 10**18
sys.setrecursionlimit(10**6)
def li():
return [int(x) for x in input().split()]
N, X, MOD = li()
n = X
nums = [X]
loop_start_i = -INF
for i in range(1, N):
n = pow(n, 2, MOD)
if n in nums:
loop_start_i = nums.index(n)
break
nums.append(n)
# total %= MOD
loop_length = len(nums) - loop_start_i
loop_cnt = (N - loop_start_i) // loop_length
r = (N - loop_start_i) % loop_length
sum_per_loop = sum(nums[loop_start_i:])
ans = sum(nums[:loop_start_i]) + sum_per_loop * loop_cnt + sum(nums[loop_start_i:loop_start_i+r])
print(ans) | import sys
def input(): return sys.stdin.readline().rstrip()
N, X, M = map(int, input().split())
numlist = [-1] * M
num = X
ans = num
roop_start = -1
for i in range(N-1):
new_num = (num * num) % M
if numlist[num] == -1:
numlist[num] = new_num
ans += new_num
num = new_num
else:
roop_start = num
break
num = roop_start
if roop_start == -1:
print(ans)
else:
roop_sum = [num]
for i in range(N-1):
new_num = numlist[num]
numlist[num] = -1
if numlist[new_num] == -1:
break
else:
roop_sum.append(roop_sum[-1] + new_num)
num = new_num
if numlist[X] != -1:
count = 0
ans = 0
for i in range(M):
if numlist[i] != -1:
ans += i
count += 1
N -= count
else:
ans = 0
size = len(roop_sum)
div = N // size
rest = N % size
ans += div * roop_sum[-1]
if rest != 0:
ans += roop_sum[rest-1]
print(ans) | 1 | 2,830,258,933,828 | null | 75 | 75 |
def A():
s = input()
if s == 'SSS': print(3)
elif s=='RSS' or s=='SSR': print(2)
elif s=='RRR': print(0)
else: print(1)
def B():
n = int(input())
a = list(map(int, input().split()))
cnt = 0
for i in range(n):
for j in range(i+1, n):
if a[i] == a[j]: continue
for k in range(j+1, n):
if a[i]==a[k] or a[j] == a[k]: continue
s = a[i] + a[j] + a[k]
if s > 2 * max(a[i], a[j], a[k]):
cnt += 1
print(cnt)
def C():
x, k, d = map(int, input().split())
if abs(x) > k * d:
print(abs(x) - k*d)
else:
tm = abs(x) // d
x = abs(x) % d
k -= tm
if k % 2 == 0:
print(x)
else:
print(d-x)
B()
| v=input()
v=int(v)
print(v**3) | 0 | null | 2,660,778,829,888 | 91 | 35 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.